blob: 11bfe767a27b25f16a8b564322602604545b39f2 [file] [log] [blame]
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +00001//===-- llvm/lib/CodeGen/AsmPrinter/WinCodeViewLineTables.cpp --*- C++ -*--===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains support for writing line tables info into COFF files.
11//
12//===----------------------------------------------------------------------===//
13
14#include "WinCodeViewLineTables.h"
15#include "llvm/MC/MCExpr.h"
16#include "llvm/MC/MCSymbol.h"
17#include "llvm/Support/COFF.h"
18
19namespace llvm {
20
21StringRef WinCodeViewLineTables::getFullFilepath(const MDNode *S) {
22 assert(S);
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000023 assert((isa<DICompileUnit>(S) || isa<DIFile>(S) || isa<DISubprogram>(S) ||
24 isa<DILexicalBlockBase>(S)) &&
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000025 "Unexpected scope info");
26
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000027 auto *Scope = cast<DIScope>(S);
Duncan P. N. Exon Smithb273d062015-04-16 01:37:00 +000028 StringRef Dir = Scope->getDirectory(),
29 Filename = Scope->getFilename();
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000030 char *&Result = DirAndFilenameToFilepathMap[std::make_pair(Dir, Filename)];
Craig Topper353eda42014-04-24 06:44:33 +000031 if (Result)
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000032 return Result;
33
34 // Clang emits directory and relative filename info into the IR, but CodeView
35 // operates on full paths. We could change Clang to emit full paths too, but
36 // that would increase the IR size and probably not needed for other users.
37 // For now, just concatenate and canonicalize the path here.
38 std::string Filepath;
39 if (Filename.find(':') == 1)
40 Filepath = Filename;
41 else
Yaron Keren75e0c4b2015-03-27 17:51:30 +000042 Filepath = (Dir + "\\" + Filename).str();
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000043
44 // Canonicalize the path. We have to do it textually because we may no longer
45 // have access the file in the filesystem.
46 // First, replace all slashes with backslashes.
47 std::replace(Filepath.begin(), Filepath.end(), '/', '\\');
48
49 // Remove all "\.\" with "\".
50 size_t Cursor = 0;
51 while ((Cursor = Filepath.find("\\.\\", Cursor)) != std::string::npos)
52 Filepath.erase(Cursor, 2);
53
54 // Replace all "\XXX\..\" with "\". Don't try too hard though as the original
55 // path should be well-formatted, e.g. start with a drive letter, etc.
56 Cursor = 0;
57 while ((Cursor = Filepath.find("\\..\\", Cursor)) != std::string::npos) {
58 // Something's wrong if the path starts with "\..\", abort.
59 if (Cursor == 0)
60 break;
61
62 size_t PrevSlash = Filepath.rfind('\\', Cursor - 1);
63 if (PrevSlash == std::string::npos)
64 // Something's wrong, abort.
65 break;
66
67 Filepath.erase(PrevSlash, Cursor + 3 - PrevSlash);
68 // The next ".." might be following the one we've just erased.
69 Cursor = PrevSlash;
70 }
71
72 // Remove all duplicate backslashes.
73 Cursor = 0;
74 while ((Cursor = Filepath.find("\\\\", Cursor)) != std::string::npos)
75 Filepath.erase(Cursor, 1);
76
77 Result = strdup(Filepath.c_str());
78 return StringRef(Result);
79}
80
81void WinCodeViewLineTables::maybeRecordLocation(DebugLoc DL,
82 const MachineFunction *MF) {
Duncan P. N. Exon Smith9dffcd02015-03-30 19:14:47 +000083 const MDNode *Scope = DL.getScope();
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000084 if (!Scope)
85 return;
86 StringRef Filename = getFullFilepath(Scope);
87
88 // Skip this instruction if it has the same file:line as the previous one.
89 assert(CurFn);
90 if (!CurFn->Instrs.empty()) {
91 const InstrInfoTy &LastInstr = InstrInfo[CurFn->Instrs.back()];
92 if (LastInstr.Filename == Filename && LastInstr.LineNumber == DL.getLine())
93 return;
94 }
95 FileNameRegistry.add(Filename);
96
Jim Grosbach6f482002015-05-18 18:43:14 +000097 MCSymbol *MCL = Asm->MMI->getContext().createTempSymbol();
Lang Hames9ff69c82015-04-24 19:11:51 +000098 Asm->OutStreamer->EmitLabel(MCL);
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000099 CurFn->Instrs.push_back(MCL);
100 InstrInfo[MCL] = InstrInfoTy(Filename, DL.getLine());
101}
102
103WinCodeViewLineTables::WinCodeViewLineTables(AsmPrinter *AP)
Craig Topper353eda42014-04-24 06:44:33 +0000104 : Asm(nullptr), CurFn(nullptr) {
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000105 MachineModuleInfo *MMI = AP->MMI;
106
107 // If module doesn't have named metadata anchors or COFF debug section
108 // is not available, skip any debug info related stuff.
109 if (!MMI->getModule()->getNamedMetadata("llvm.dbg.cu") ||
110 !AP->getObjFileLowering().getCOFFDebugSymbolsSection())
111 return;
112
113 // Tell MMI that we have debug info.
114 MMI->setDebugInfoAvailability(true);
115 Asm = AP;
116}
117
Timur Iskhodzhanov2cf8a1d2014-10-10 16:05:32 +0000118void WinCodeViewLineTables::endModule() {
119 if (FnDebugInfo.empty())
120 return;
121
122 assert(Asm != nullptr);
Lang Hames9ff69c82015-04-24 19:11:51 +0000123 Asm->OutStreamer->SwitchSection(
Timur Iskhodzhanov2cf8a1d2014-10-10 16:05:32 +0000124 Asm->getObjFileLowering().getCOFFDebugSymbolsSection());
125 Asm->EmitInt32(COFF::DEBUG_SECTION_MAGIC);
126
127 // The COFF .debug$S section consists of several subsections, each starting
128 // with a 4-byte control code (e.g. 0xF1, 0xF2, etc) and then a 4-byte length
129 // of the payload followed by the payload itself. The subsections are 4-byte
130 // aligned.
131
132 // Emit per-function debug information. This code is extracted into a
133 // separate function for readability.
134 for (size_t I = 0, E = VisitedFunctions.size(); I != E; ++I)
135 emitDebugInfoForFunction(VisitedFunctions[I]);
136
137 // This subsection holds a file index to offset in string table table.
Lang Hames9ff69c82015-04-24 19:11:51 +0000138 Asm->OutStreamer->AddComment("File index to string table offset subsection");
Timur Iskhodzhanov2cf8a1d2014-10-10 16:05:32 +0000139 Asm->EmitInt32(COFF::DEBUG_INDEX_SUBSECTION);
140 size_t NumFilenames = FileNameRegistry.Infos.size();
141 Asm->EmitInt32(8 * NumFilenames);
142 for (size_t I = 0, E = FileNameRegistry.Filenames.size(); I != E; ++I) {
143 StringRef Filename = FileNameRegistry.Filenames[I];
144 // For each unique filename, just write its offset in the string table.
145 Asm->EmitInt32(FileNameRegistry.Infos[Filename].StartOffset);
146 // The function name offset is not followed by any additional data.
147 Asm->EmitInt32(0);
148 }
149
150 // This subsection holds the string table.
Lang Hames9ff69c82015-04-24 19:11:51 +0000151 Asm->OutStreamer->AddComment("String table");
Timur Iskhodzhanov2cf8a1d2014-10-10 16:05:32 +0000152 Asm->EmitInt32(COFF::DEBUG_STRING_TABLE_SUBSECTION);
153 Asm->EmitInt32(FileNameRegistry.LastOffset);
154 // The payload starts with a null character.
155 Asm->EmitInt8(0);
156
157 for (size_t I = 0, E = FileNameRegistry.Filenames.size(); I != E; ++I) {
158 // Just emit unique filenames one by one, separated by a null character.
Lang Hames9ff69c82015-04-24 19:11:51 +0000159 Asm->OutStreamer->EmitBytes(FileNameRegistry.Filenames[I]);
Timur Iskhodzhanov2cf8a1d2014-10-10 16:05:32 +0000160 Asm->EmitInt8(0);
161 }
162
163 // No more subsections. Fill with zeros to align the end of the section by 4.
Lang Hames9ff69c82015-04-24 19:11:51 +0000164 Asm->OutStreamer->EmitFill((-FileNameRegistry.LastOffset) % 4, 0);
Timur Iskhodzhanov2cf8a1d2014-10-10 16:05:32 +0000165
166 clear();
167}
168
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000169static void EmitLabelDiff(MCStreamer &Streamer,
Timur Iskhodzhanov2bc90fd2014-10-24 01:27:45 +0000170 const MCSymbol *From, const MCSymbol *To,
171 unsigned int Size = 4) {
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000172 MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
173 MCContext &Context = Streamer.getContext();
Jim Grosbach13760bd2015-05-30 01:25:56 +0000174 const MCExpr *FromRef = MCSymbolRefExpr::create(From, Variant, Context),
175 *ToRef = MCSymbolRefExpr::create(To, Variant, Context);
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000176 const MCExpr *AddrDelta =
Jim Grosbach13760bd2015-05-30 01:25:56 +0000177 MCBinaryExpr::create(MCBinaryExpr::Sub, ToRef, FromRef, Context);
Timur Iskhodzhanov2bc90fd2014-10-24 01:27:45 +0000178 Streamer.EmitValue(AddrDelta, Size);
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000179}
180
181void WinCodeViewLineTables::emitDebugInfoForFunction(const Function *GV) {
182 // For each function there is a separate subsection
183 // which holds the PC to file:line table.
184 const MCSymbol *Fn = Asm->getSymbol(GV);
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000185 assert(Fn);
Timur Iskhodzhanov8499a122014-03-26 09:50:36 +0000186
187 const FunctionInfo &FI = FnDebugInfo[GV];
188 if (FI.Instrs.empty())
189 return;
190 assert(FI.End && "Don't know where the function ends?");
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000191
Duncan P. N. Exon Smith23e56ec2015-03-20 19:50:00 +0000192 StringRef GVName = GV->getName();
193 StringRef FuncName;
Duncan P. N. Exon Smith2fbe1352015-04-20 22:10:08 +0000194 if (auto *SP = getDISubprogram(GV))
Duncan P. N. Exon Smith537b4a82015-04-14 03:40:37 +0000195 FuncName = SP->getDisplayName();
Duncan P. N. Exon Smith23e56ec2015-03-20 19:50:00 +0000196
Timur Iskhodzhanov0e76a162014-11-12 20:21:20 +0000197 // FIXME Clang currently sets DisplayName to "bar" for a C++
198 // "namespace_foo::bar" function, see PR21528. Luckily, dbghelp.dll is trying
199 // to demangle display names anyways, so let's just put a mangled name into
200 // the symbols subsection until Clang gives us what we need.
201 if (GVName.startswith("\01?"))
202 FuncName = GVName.substr(1);
Timur Iskhodzhanov2bc90fd2014-10-24 01:27:45 +0000203 // Emit a symbol subsection, required by VS2012+ to find function boundaries.
Jim Grosbach6f482002015-05-18 18:43:14 +0000204 MCSymbol *SymbolsBegin = Asm->MMI->getContext().createTempSymbol(),
205 *SymbolsEnd = Asm->MMI->getContext().createTempSymbol();
Lang Hames9ff69c82015-04-24 19:11:51 +0000206 Asm->OutStreamer->AddComment("Symbol subsection for " + Twine(FuncName));
Timur Iskhodzhanov2bc90fd2014-10-24 01:27:45 +0000207 Asm->EmitInt32(COFF::DEBUG_SYMBOL_SUBSECTION);
Lang Hames9ff69c82015-04-24 19:11:51 +0000208 EmitLabelDiff(*Asm->OutStreamer, SymbolsBegin, SymbolsEnd);
209 Asm->OutStreamer->EmitLabel(SymbolsBegin);
Timur Iskhodzhanov2bc90fd2014-10-24 01:27:45 +0000210 {
Jim Grosbach6f482002015-05-18 18:43:14 +0000211 MCSymbol *ProcSegmentBegin = Asm->MMI->getContext().createTempSymbol(),
212 *ProcSegmentEnd = Asm->MMI->getContext().createTempSymbol();
Lang Hames9ff69c82015-04-24 19:11:51 +0000213 EmitLabelDiff(*Asm->OutStreamer, ProcSegmentBegin, ProcSegmentEnd, 2);
214 Asm->OutStreamer->EmitLabel(ProcSegmentBegin);
Timur Iskhodzhanov2bc90fd2014-10-24 01:27:45 +0000215
216 Asm->EmitInt16(COFF::DEBUG_SYMBOL_TYPE_PROC_START);
217 // Some bytes of this segment don't seem to be required for basic debugging,
218 // so just fill them with zeroes.
Lang Hames9ff69c82015-04-24 19:11:51 +0000219 Asm->OutStreamer->EmitFill(12, 0);
Timur Iskhodzhanov2bc90fd2014-10-24 01:27:45 +0000220 // This is the important bit that tells the debugger where the function
221 // code is located and what's its size:
Lang Hames9ff69c82015-04-24 19:11:51 +0000222 EmitLabelDiff(*Asm->OutStreamer, Fn, FI.End);
223 Asm->OutStreamer->EmitFill(12, 0);
224 Asm->OutStreamer->EmitCOFFSecRel32(Fn);
225 Asm->OutStreamer->EmitCOFFSectionIndex(Fn);
Timur Iskhodzhanov2bc90fd2014-10-24 01:27:45 +0000226 Asm->EmitInt8(0);
Timur Iskhodzhanova11b32b2014-11-12 20:10:09 +0000227 // Emit the function display name as a null-terminated string.
Lang Hames9ff69c82015-04-24 19:11:51 +0000228 Asm->OutStreamer->EmitBytes(FuncName);
Timur Iskhodzhanov2bc90fd2014-10-24 01:27:45 +0000229 Asm->EmitInt8(0);
Lang Hames9ff69c82015-04-24 19:11:51 +0000230 Asm->OutStreamer->EmitLabel(ProcSegmentEnd);
Timur Iskhodzhanov2bc90fd2014-10-24 01:27:45 +0000231
232 // We're done with this function.
233 Asm->EmitInt16(0x0002);
234 Asm->EmitInt16(COFF::DEBUG_SYMBOL_TYPE_PROC_END);
235 }
Lang Hames9ff69c82015-04-24 19:11:51 +0000236 Asm->OutStreamer->EmitLabel(SymbolsEnd);
Timur Iskhodzhanov2bc90fd2014-10-24 01:27:45 +0000237 // Every subsection must be aligned to a 4-byte boundary.
Lang Hames9ff69c82015-04-24 19:11:51 +0000238 Asm->OutStreamer->EmitFill((-FuncName.size()) % 4, 0);
Timur Iskhodzhanov2bc90fd2014-10-24 01:27:45 +0000239
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000240 // PCs/Instructions are grouped into segments sharing the same filename.
241 // Pre-calculate the lengths (in instructions) of these segments and store
242 // them in a map for convenience. Each index in the map is the sequential
243 // number of the respective instruction that starts a new segment.
244 DenseMap<size_t, size_t> FilenameSegmentLengths;
245 size_t LastSegmentEnd = 0;
246 StringRef PrevFilename = InstrInfo[FI.Instrs[0]].Filename;
247 for (size_t J = 1, F = FI.Instrs.size(); J != F; ++J) {
248 if (PrevFilename == InstrInfo[FI.Instrs[J]].Filename)
249 continue;
250 FilenameSegmentLengths[LastSegmentEnd] = J - LastSegmentEnd;
251 LastSegmentEnd = J;
252 PrevFilename = InstrInfo[FI.Instrs[J]].Filename;
253 }
254 FilenameSegmentLengths[LastSegmentEnd] = FI.Instrs.size() - LastSegmentEnd;
255
Timur Iskhodzhanov2cf8a1d2014-10-10 16:05:32 +0000256 // Emit a line table subsection, requred to do PC-to-file:line lookup.
Lang Hames9ff69c82015-04-24 19:11:51 +0000257 Asm->OutStreamer->AddComment("Line table subsection for " + Twine(FuncName));
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000258 Asm->EmitInt32(COFF::DEBUG_LINE_TABLE_SUBSECTION);
Jim Grosbach6f482002015-05-18 18:43:14 +0000259 MCSymbol *LineTableBegin = Asm->MMI->getContext().createTempSymbol(),
260 *LineTableEnd = Asm->MMI->getContext().createTempSymbol();
Lang Hames9ff69c82015-04-24 19:11:51 +0000261 EmitLabelDiff(*Asm->OutStreamer, LineTableBegin, LineTableEnd);
262 Asm->OutStreamer->EmitLabel(LineTableBegin);
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000263
264 // Identify the function this subsection is for.
Lang Hames9ff69c82015-04-24 19:11:51 +0000265 Asm->OutStreamer->EmitCOFFSecRel32(Fn);
266 Asm->OutStreamer->EmitCOFFSectionIndex(Fn);
Timur Iskhodzhanov5fcaeeb2014-10-08 18:01:49 +0000267 // Insert padding after a 16-bit section index.
268 Asm->EmitInt16(0);
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000269
270 // Length of the function's code, in bytes.
Lang Hames9ff69c82015-04-24 19:11:51 +0000271 EmitLabelDiff(*Asm->OutStreamer, Fn, FI.End);
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000272
273 // PC-to-linenumber lookup table:
Craig Topper353eda42014-04-24 06:44:33 +0000274 MCSymbol *FileSegmentEnd = nullptr;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000275 for (size_t J = 0, F = FI.Instrs.size(); J != F; ++J) {
276 MCSymbol *Instr = FI.Instrs[J];
277 assert(InstrInfo.count(Instr));
278
279 if (FilenameSegmentLengths.count(J)) {
280 // We came to a beginning of a new filename segment.
281 if (FileSegmentEnd)
Lang Hames9ff69c82015-04-24 19:11:51 +0000282 Asm->OutStreamer->EmitLabel(FileSegmentEnd);
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000283 StringRef CurFilename = InstrInfo[FI.Instrs[J]].Filename;
284 assert(FileNameRegistry.Infos.count(CurFilename));
285 size_t IndexInStringTable =
286 FileNameRegistry.Infos[CurFilename].FilenameID;
287 // Each segment starts with the offset of the filename
288 // in the string table.
Lang Hames9ff69c82015-04-24 19:11:51 +0000289 Asm->OutStreamer->AddComment(
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000290 "Segment for file '" + Twine(CurFilename) + "' begins");
Jim Grosbach6f482002015-05-18 18:43:14 +0000291 MCSymbol *FileSegmentBegin = Asm->MMI->getContext().createTempSymbol();
Lang Hames9ff69c82015-04-24 19:11:51 +0000292 Asm->OutStreamer->EmitLabel(FileSegmentBegin);
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000293 Asm->EmitInt32(8 * IndexInStringTable);
294
295 // Number of PC records in the lookup table.
296 size_t SegmentLength = FilenameSegmentLengths[J];
297 Asm->EmitInt32(SegmentLength);
298
299 // Full size of the segment for this filename, including the prev two
300 // records.
Jim Grosbach6f482002015-05-18 18:43:14 +0000301 FileSegmentEnd = Asm->MMI->getContext().createTempSymbol();
Lang Hames9ff69c82015-04-24 19:11:51 +0000302 EmitLabelDiff(*Asm->OutStreamer, FileSegmentBegin, FileSegmentEnd);
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000303 }
304
305 // The first PC with the given linenumber and the linenumber itself.
Lang Hames9ff69c82015-04-24 19:11:51 +0000306 EmitLabelDiff(*Asm->OutStreamer, Fn, Instr);
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000307 Asm->EmitInt32(InstrInfo[Instr].LineNumber);
308 }
309
310 if (FileSegmentEnd)
Lang Hames9ff69c82015-04-24 19:11:51 +0000311 Asm->OutStreamer->EmitLabel(FileSegmentEnd);
312 Asm->OutStreamer->EmitLabel(LineTableEnd);
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000313}
314
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000315void WinCodeViewLineTables::beginFunction(const MachineFunction *MF) {
316 assert(!CurFn && "Can't process two functions at once!");
317
318 if (!Asm || !Asm->MMI->hasDebugInfo())
319 return;
320
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000321 const Function *GV = MF->getFunction();
322 assert(FnDebugInfo.count(GV) == false);
323 VisitedFunctions.push_back(GV);
324 CurFn = &FnDebugInfo[GV];
325
326 // Find the end of the function prolog.
327 // FIXME: is there a simpler a way to do this? Can we just search
328 // for the first instruction of the function, not the last of the prolog?
329 DebugLoc PrologEndLoc;
330 bool EmptyPrologue = true;
Alexey Samsonovf74bde62014-04-30 22:17:38 +0000331 for (const auto &MBB : *MF) {
Duncan P. N. Exon Smith9dffcd02015-03-30 19:14:47 +0000332 if (PrologEndLoc)
Alexey Samsonovf74bde62014-04-30 22:17:38 +0000333 break;
334 for (const auto &MI : MBB) {
335 if (MI.isDebugValue())
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000336 continue;
337
338 // First known non-DBG_VALUE and non-frame setup location marks
339 // the beginning of the function body.
340 // FIXME: do we need the first subcondition?
Duncan P. N. Exon Smith9dffcd02015-03-30 19:14:47 +0000341 if (!MI.getFlag(MachineInstr::FrameSetup) && MI.getDebugLoc()) {
Alexey Samsonovf74bde62014-04-30 22:17:38 +0000342 PrologEndLoc = MI.getDebugLoc();
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000343 break;
344 }
345 EmptyPrologue = false;
346 }
347 }
348 // Record beginning of function if we have a non-empty prologue.
Duncan P. N. Exon Smith9dffcd02015-03-30 19:14:47 +0000349 if (PrologEndLoc && !EmptyPrologue) {
350 DebugLoc FnStartDL = PrologEndLoc.getFnDebugLoc();
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000351 maybeRecordLocation(FnStartDL, MF);
352 }
353}
354
Timur Iskhodzhanovb5b7a612014-03-26 11:24:36 +0000355void WinCodeViewLineTables::endFunction(const MachineFunction *MF) {
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000356 if (!Asm || !CurFn) // We haven't created any debug info for this function.
357 return;
358
Timur Iskhodzhanovb5b7a612014-03-26 11:24:36 +0000359 const Function *GV = MF->getFunction();
Yaron Keren6d3194f2014-06-20 10:26:56 +0000360 assert(FnDebugInfo.count(GV));
Timur Iskhodzhanovb5b7a612014-03-26 11:24:36 +0000361 assert(CurFn == &FnDebugInfo[GV]);
362
363 if (CurFn->Instrs.empty()) {
364 FnDebugInfo.erase(GV);
365 VisitedFunctions.pop_back();
366 } else {
Rafael Espindola07c03d32015-03-05 02:05:42 +0000367 CurFn->End = Asm->getFunctionEnd();
Timur Iskhodzhanov8499a122014-03-26 09:50:36 +0000368 }
Craig Topper353eda42014-04-24 06:44:33 +0000369 CurFn = nullptr;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000370}
371
372void WinCodeViewLineTables::beginInstruction(const MachineInstr *MI) {
373 // Ignore DBG_VALUE locations and function prologue.
374 if (!Asm || MI->isDebugValue() || MI->getFlag(MachineInstr::FrameSetup))
375 return;
376 DebugLoc DL = MI->getDebugLoc();
Duncan P. N. Exon Smith9dffcd02015-03-30 19:14:47 +0000377 if (DL == PrevInstLoc || !DL)
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000378 return;
379 maybeRecordLocation(DL, Asm->MF);
380}
Alexander Kornienko70bc5f12015-06-19 15:57:42 +0000381} // namespace llvm