Reid Kleckner | 70f5bc9 | 2016-01-14 19:25:04 +0000 | [diff] [blame] | 1 | //===-- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp --*- C++ -*--===// |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 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 | // |
Reid Kleckner | 70f5bc9 | 2016-01-14 19:25:04 +0000 | [diff] [blame] | 10 | // This file contains support for writing Microsoft CodeView debug info. |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Reid Kleckner | 70f5bc9 | 2016-01-14 19:25:04 +0000 | [diff] [blame] | 14 | #include "CodeViewDebug.h" |
Reid Kleckner | 6b3faef | 2016-01-13 23:44:57 +0000 | [diff] [blame] | 15 | #include "llvm/DebugInfo/CodeView/CodeView.h" |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 16 | #include "llvm/DebugInfo/CodeView/Line.h" |
Reid Kleckner | 6b3faef | 2016-01-13 23:44:57 +0000 | [diff] [blame] | 17 | #include "llvm/DebugInfo/CodeView/SymbolRecord.h" |
Reid Kleckner | fbdbe9e | 2016-05-31 18:45:36 +0000 | [diff] [blame] | 18 | #include "llvm/DebugInfo/CodeView/TypeDumper.h" |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 19 | #include "llvm/DebugInfo/CodeView/TypeIndex.h" |
| 20 | #include "llvm/DebugInfo/CodeView/TypeRecord.h" |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCExpr.h" |
Reid Kleckner | 5d122f8 | 2016-05-25 23:16:12 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCSectionCOFF.h" |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCSymbol.h" |
| 24 | #include "llvm/Support/COFF.h" |
Reid Kleckner | fbdbe9e | 2016-05-31 18:45:36 +0000 | [diff] [blame] | 25 | #include "llvm/Support/ScopedPrinter.h" |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 26 | #include "llvm/Target/TargetSubtargetInfo.h" |
| 27 | #include "llvm/Target/TargetRegisterInfo.h" |
| 28 | #include "llvm/Target/TargetFrameLowering.h" |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 29 | |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 30 | using namespace llvm; |
Reid Kleckner | 6b3faef | 2016-01-13 23:44:57 +0000 | [diff] [blame] | 31 | using namespace llvm::codeview; |
| 32 | |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 33 | CodeViewDebug::CodeViewDebug(AsmPrinter *AP) |
| 34 | : DebugHandlerBase(AP), OS(*Asm->OutStreamer), CurFn(nullptr) { |
| 35 | // If module doesn't have named metadata anchors or COFF debug section |
| 36 | // is not available, skip any debug info related stuff. |
| 37 | if (!MMI->getModule()->getNamedMetadata("llvm.dbg.cu") || |
| 38 | !AP->getObjFileLowering().getCOFFDebugSymbolsSection()) { |
| 39 | Asm = nullptr; |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | // Tell MMI that we have debug info. |
| 44 | MMI->setDebugInfoAvailability(true); |
| 45 | } |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 46 | |
Reid Kleckner | 9533af4 | 2016-01-16 00:09:09 +0000 | [diff] [blame] | 47 | StringRef CodeViewDebug::getFullFilepath(const DIFile *File) { |
| 48 | std::string &Filepath = FileToFilepathMap[File]; |
Reid Kleckner | 1f11b4e | 2015-12-02 22:34:30 +0000 | [diff] [blame] | 49 | if (!Filepath.empty()) |
| 50 | return Filepath; |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 51 | |
Reid Kleckner | 9533af4 | 2016-01-16 00:09:09 +0000 | [diff] [blame] | 52 | StringRef Dir = File->getDirectory(), Filename = File->getFilename(); |
| 53 | |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 54 | // Clang emits directory and relative filename info into the IR, but CodeView |
| 55 | // operates on full paths. We could change Clang to emit full paths too, but |
| 56 | // that would increase the IR size and probably not needed for other users. |
| 57 | // For now, just concatenate and canonicalize the path here. |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 58 | if (Filename.find(':') == 1) |
| 59 | Filepath = Filename; |
| 60 | else |
Yaron Keren | 75e0c4b | 2015-03-27 17:51:30 +0000 | [diff] [blame] | 61 | Filepath = (Dir + "\\" + Filename).str(); |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 62 | |
| 63 | // Canonicalize the path. We have to do it textually because we may no longer |
| 64 | // have access the file in the filesystem. |
| 65 | // First, replace all slashes with backslashes. |
| 66 | std::replace(Filepath.begin(), Filepath.end(), '/', '\\'); |
| 67 | |
| 68 | // Remove all "\.\" with "\". |
| 69 | size_t Cursor = 0; |
| 70 | while ((Cursor = Filepath.find("\\.\\", Cursor)) != std::string::npos) |
| 71 | Filepath.erase(Cursor, 2); |
| 72 | |
| 73 | // Replace all "\XXX\..\" with "\". Don't try too hard though as the original |
| 74 | // path should be well-formatted, e.g. start with a drive letter, etc. |
| 75 | Cursor = 0; |
| 76 | while ((Cursor = Filepath.find("\\..\\", Cursor)) != std::string::npos) { |
| 77 | // Something's wrong if the path starts with "\..\", abort. |
| 78 | if (Cursor == 0) |
| 79 | break; |
| 80 | |
| 81 | size_t PrevSlash = Filepath.rfind('\\', Cursor - 1); |
| 82 | if (PrevSlash == std::string::npos) |
| 83 | // Something's wrong, abort. |
| 84 | break; |
| 85 | |
| 86 | Filepath.erase(PrevSlash, Cursor + 3 - PrevSlash); |
| 87 | // The next ".." might be following the one we've just erased. |
| 88 | Cursor = PrevSlash; |
| 89 | } |
| 90 | |
| 91 | // Remove all duplicate backslashes. |
| 92 | Cursor = 0; |
| 93 | while ((Cursor = Filepath.find("\\\\", Cursor)) != std::string::npos) |
| 94 | Filepath.erase(Cursor, 1); |
| 95 | |
Reid Kleckner | 1f11b4e | 2015-12-02 22:34:30 +0000 | [diff] [blame] | 96 | return Filepath; |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 99 | unsigned CodeViewDebug::maybeRecordFile(const DIFile *F) { |
| 100 | unsigned NextId = FileIdMap.size() + 1; |
| 101 | auto Insertion = FileIdMap.insert(std::make_pair(F, NextId)); |
| 102 | if (Insertion.second) { |
| 103 | // We have to compute the full filepath and emit a .cv_file directive. |
| 104 | StringRef FullPath = getFullFilepath(F); |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 105 | NextId = OS.EmitCVFileDirective(NextId, FullPath); |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 106 | assert(NextId == FileIdMap.size() && ".cv_file directive failed"); |
| 107 | } |
| 108 | return Insertion.first->second; |
| 109 | } |
| 110 | |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 111 | CodeViewDebug::InlineSite & |
| 112 | CodeViewDebug::getInlineSite(const DILocation *InlinedAt, |
| 113 | const DISubprogram *Inlinee) { |
Reid Kleckner | fbd7787 | 2016-03-18 18:54:32 +0000 | [diff] [blame] | 114 | auto SiteInsertion = CurFn->InlineSites.insert({InlinedAt, InlineSite()}); |
| 115 | InlineSite *Site = &SiteInsertion.first->second; |
| 116 | if (SiteInsertion.second) { |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 117 | Site->SiteFuncId = NextFuncId++; |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 118 | Site->Inlinee = Inlinee; |
Reid Kleckner | 2280f93 | 2016-05-23 20:23:46 +0000 | [diff] [blame] | 119 | InlinedSubprograms.insert(Inlinee); |
| 120 | recordFuncIdForSubprogram(Inlinee); |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 121 | } |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 122 | return *Site; |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Reid Kleckner | 2280f93 | 2016-05-23 20:23:46 +0000 | [diff] [blame] | 125 | TypeIndex CodeViewDebug::getGenericFunctionTypeIndex() { |
| 126 | if (VoidFnTyIdx.getIndex() != 0) |
| 127 | return VoidFnTyIdx; |
| 128 | |
| 129 | ArrayRef<TypeIndex> NoArgs; |
| 130 | ArgListRecord ArgListRec(TypeRecordKind::ArgList, NoArgs); |
| 131 | TypeIndex ArgListIndex = TypeTable.writeArgList(ArgListRec); |
| 132 | |
| 133 | ProcedureRecord Procedure(TypeIndex::Void(), CallingConvention::NearC, |
| 134 | FunctionOptions::None, 0, ArgListIndex); |
| 135 | VoidFnTyIdx = TypeTable.writeProcedure(Procedure); |
| 136 | return VoidFnTyIdx; |
| 137 | } |
| 138 | |
| 139 | void CodeViewDebug::recordFuncIdForSubprogram(const DISubprogram *SP) { |
| 140 | TypeIndex ParentScope = TypeIndex(0); |
| 141 | StringRef DisplayName = SP->getDisplayName(); |
| 142 | FuncIdRecord FuncId(ParentScope, getGenericFunctionTypeIndex(), DisplayName); |
| 143 | TypeIndex TI = TypeTable.writeFuncId(FuncId); |
| 144 | TypeIndices[SP] = TI; |
| 145 | } |
| 146 | |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 147 | void CodeViewDebug::recordLocalVariable(LocalVariable &&Var, |
| 148 | const DILocation *InlinedAt) { |
| 149 | if (InlinedAt) { |
| 150 | // This variable was inlined. Associate it with the InlineSite. |
| 151 | const DISubprogram *Inlinee = Var.DIVar->getScope()->getSubprogram(); |
| 152 | InlineSite &Site = getInlineSite(InlinedAt, Inlinee); |
| 153 | Site.InlinedLocals.emplace_back(Var); |
| 154 | } else { |
| 155 | // This variable goes in the main ProcSym. |
| 156 | CurFn->Locals.emplace_back(Var); |
| 157 | } |
| 158 | } |
| 159 | |
Reid Kleckner | 829365a | 2016-02-11 19:41:47 +0000 | [diff] [blame] | 160 | static void addLocIfNotPresent(SmallVectorImpl<const DILocation *> &Locs, |
| 161 | const DILocation *Loc) { |
| 162 | auto B = Locs.begin(), E = Locs.end(); |
| 163 | if (std::find(B, E, Loc) == E) |
| 164 | Locs.push_back(Loc); |
| 165 | } |
| 166 | |
Reid Kleckner | 70f5bc9 | 2016-01-14 19:25:04 +0000 | [diff] [blame] | 167 | void CodeViewDebug::maybeRecordLocation(DebugLoc DL, |
Reid Kleckner | 9533af4 | 2016-01-16 00:09:09 +0000 | [diff] [blame] | 168 | const MachineFunction *MF) { |
| 169 | // Skip this instruction if it has the same location as the previous one. |
| 170 | if (DL == CurFn->LastLoc) |
| 171 | return; |
| 172 | |
| 173 | const DIScope *Scope = DL.get()->getScope(); |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 174 | if (!Scope) |
| 175 | return; |
Reid Kleckner | 9533af4 | 2016-01-16 00:09:09 +0000 | [diff] [blame] | 176 | |
David Majnemer | c3340db | 2016-01-13 01:05:23 +0000 | [diff] [blame] | 177 | // Skip this line if it is longer than the maximum we can record. |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 178 | LineInfo LI(DL.getLine(), DL.getLine(), /*IsStatement=*/true); |
| 179 | if (LI.getStartLine() != DL.getLine() || LI.isAlwaysStepInto() || |
| 180 | LI.isNeverStepInto()) |
David Majnemer | c3340db | 2016-01-13 01:05:23 +0000 | [diff] [blame] | 181 | return; |
| 182 | |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 183 | ColumnInfo CI(DL.getCol(), /*EndColumn=*/0); |
| 184 | if (CI.getStartColumn() != DL.getCol()) |
| 185 | return; |
Reid Kleckner | 00d9639 | 2016-01-29 00:13:28 +0000 | [diff] [blame] | 186 | |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 187 | if (!CurFn->HaveLineInfo) |
| 188 | CurFn->HaveLineInfo = true; |
| 189 | unsigned FileId = 0; |
| 190 | if (CurFn->LastLoc.get() && CurFn->LastLoc->getFile() == DL->getFile()) |
| 191 | FileId = CurFn->LastFileId; |
| 192 | else |
| 193 | FileId = CurFn->LastFileId = maybeRecordFile(DL->getFile()); |
| 194 | CurFn->LastLoc = DL; |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 195 | |
| 196 | unsigned FuncId = CurFn->FuncId; |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 197 | if (const DILocation *SiteLoc = DL->getInlinedAt()) { |
Reid Kleckner | 829365a | 2016-02-11 19:41:47 +0000 | [diff] [blame] | 198 | const DILocation *Loc = DL.get(); |
| 199 | |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 200 | // If this location was actually inlined from somewhere else, give it the ID |
| 201 | // of the inline call site. |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 202 | FuncId = |
| 203 | getInlineSite(SiteLoc, Loc->getScope()->getSubprogram()).SiteFuncId; |
Reid Kleckner | 829365a | 2016-02-11 19:41:47 +0000 | [diff] [blame] | 204 | |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 205 | // Ensure we have links in the tree of inline call sites. |
Reid Kleckner | 829365a | 2016-02-11 19:41:47 +0000 | [diff] [blame] | 206 | bool FirstLoc = true; |
| 207 | while ((SiteLoc = Loc->getInlinedAt())) { |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 208 | InlineSite &Site = |
| 209 | getInlineSite(SiteLoc, Loc->getScope()->getSubprogram()); |
Reid Kleckner | 829365a | 2016-02-11 19:41:47 +0000 | [diff] [blame] | 210 | if (!FirstLoc) |
| 211 | addLocIfNotPresent(Site.ChildSites, Loc); |
| 212 | FirstLoc = false; |
| 213 | Loc = SiteLoc; |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 214 | } |
Reid Kleckner | 829365a | 2016-02-11 19:41:47 +0000 | [diff] [blame] | 215 | addLocIfNotPresent(CurFn->ChildSites, Loc); |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 218 | OS.EmitCVLocDirective(FuncId, FileId, DL.getLine(), DL.getCol(), |
| 219 | /*PrologueEnd=*/false, |
| 220 | /*IsStmt=*/false, DL->getFilename()); |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Reid Kleckner | 5d122f8 | 2016-05-25 23:16:12 +0000 | [diff] [blame] | 223 | void CodeViewDebug::emitCodeViewMagicVersion() { |
| 224 | OS.EmitValueToAlignment(4); |
| 225 | OS.AddComment("Debug section magic"); |
| 226 | OS.EmitIntValue(COFF::DEBUG_SECTION_MAGIC, 4); |
| 227 | } |
| 228 | |
Reid Kleckner | 70f5bc9 | 2016-01-14 19:25:04 +0000 | [diff] [blame] | 229 | void CodeViewDebug::endModule() { |
Timur Iskhodzhanov | 2cf8a1d | 2014-10-10 16:05:32 +0000 | [diff] [blame] | 230 | if (FnDebugInfo.empty()) |
| 231 | return; |
| 232 | |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 233 | emitTypeInformation(); |
| 234 | |
Timur Iskhodzhanov | 2cf8a1d | 2014-10-10 16:05:32 +0000 | [diff] [blame] | 235 | assert(Asm != nullptr); |
Timur Iskhodzhanov | 2cf8a1d | 2014-10-10 16:05:32 +0000 | [diff] [blame] | 236 | |
| 237 | // The COFF .debug$S section consists of several subsections, each starting |
| 238 | // with a 4-byte control code (e.g. 0xF1, 0xF2, etc) and then a 4-byte length |
| 239 | // of the payload followed by the payload itself. The subsections are 4-byte |
| 240 | // aligned. |
| 241 | |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 242 | // Make a subsection for all the inlined subprograms. |
Reid Kleckner | 5d122f8 | 2016-05-25 23:16:12 +0000 | [diff] [blame] | 243 | emitInlineeLinesSubsection(); |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 244 | |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 245 | // Emit per-function debug information. |
| 246 | for (auto &P : FnDebugInfo) |
| 247 | emitDebugInfoForFunction(P.first, P.second); |
Timur Iskhodzhanov | 2cf8a1d | 2014-10-10 16:05:32 +0000 | [diff] [blame] | 248 | |
Reid Kleckner | 5d122f8 | 2016-05-25 23:16:12 +0000 | [diff] [blame] | 249 | // Switch back to the generic .debug$S section after potentially processing |
| 250 | // comdat symbol sections. |
| 251 | switchToDebugSectionForSymbol(nullptr); |
| 252 | |
Timur Iskhodzhanov | 2cf8a1d | 2014-10-10 16:05:32 +0000 | [diff] [blame] | 253 | // This subsection holds a file index to offset in string table table. |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 254 | OS.AddComment("File index to string table offset subsection"); |
| 255 | OS.EmitCVFileChecksumsDirective(); |
Timur Iskhodzhanov | 2cf8a1d | 2014-10-10 16:05:32 +0000 | [diff] [blame] | 256 | |
| 257 | // This subsection holds the string table. |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 258 | OS.AddComment("String table"); |
| 259 | OS.EmitCVStringTableDirective(); |
Timur Iskhodzhanov | 2cf8a1d | 2014-10-10 16:05:32 +0000 | [diff] [blame] | 260 | |
| 261 | clear(); |
| 262 | } |
| 263 | |
David Majnemer | b9456a5 | 2016-03-14 05:15:09 +0000 | [diff] [blame] | 264 | static void emitNullTerminatedSymbolName(MCStreamer &OS, StringRef S) { |
| 265 | // Microsoft's linker seems to have trouble with symbol names longer than |
| 266 | // 0xffd8 bytes. |
| 267 | S = S.substr(0, 0xffd8); |
| 268 | SmallString<32> NullTerminatedString(S); |
| 269 | NullTerminatedString.push_back('\0'); |
| 270 | OS.EmitBytes(NullTerminatedString); |
| 271 | } |
| 272 | |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 273 | void CodeViewDebug::emitTypeInformation() { |
Reid Kleckner | 2280f93 | 2016-05-23 20:23:46 +0000 | [diff] [blame] | 274 | // Do nothing if we have no debug info or if no non-trivial types were emitted |
| 275 | // to TypeTable during codegen. |
Reid Kleckner | fbd7787 | 2016-03-18 18:54:32 +0000 | [diff] [blame] | 276 | NamedMDNode *CU_Nodes = |
| 277 | MMI->getModule()->getNamedMetadata("llvm.dbg.cu"); |
| 278 | if (!CU_Nodes) |
| 279 | return; |
Reid Kleckner | 2280f93 | 2016-05-23 20:23:46 +0000 | [diff] [blame] | 280 | if (TypeTable.empty()) |
Reid Kleckner | fbd7787 | 2016-03-18 18:54:32 +0000 | [diff] [blame] | 281 | return; |
| 282 | |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 283 | // Start the .debug$T section with 0x4. |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 284 | OS.SwitchSection(Asm->getObjFileLowering().getCOFFDebugTypesSection()); |
Reid Kleckner | 5d122f8 | 2016-05-25 23:16:12 +0000 | [diff] [blame] | 285 | emitCodeViewMagicVersion(); |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 286 | |
Reid Kleckner | fbdbe9e | 2016-05-31 18:45:36 +0000 | [diff] [blame] | 287 | SmallString<8> CommentPrefix; |
| 288 | if (OS.isVerboseAsm()) { |
| 289 | CommentPrefix += '\t'; |
| 290 | CommentPrefix += Asm->MAI->getCommentString(); |
| 291 | CommentPrefix += ' '; |
| 292 | } |
| 293 | |
| 294 | CVTypeDumper CVTD(nullptr, /*PrintRecordBytes=*/false); |
Reid Kleckner | 2280f93 | 2016-05-23 20:23:46 +0000 | [diff] [blame] | 295 | TypeTable.ForEachRecord( |
Reid Kleckner | fbdbe9e | 2016-05-31 18:45:36 +0000 | [diff] [blame] | 296 | [&](TypeIndex Index, StringRef Record) { |
| 297 | if (OS.isVerboseAsm()) { |
| 298 | // Emit a block comment describing the type record for readability. |
| 299 | SmallString<512> CommentBlock; |
| 300 | raw_svector_ostream CommentOS(CommentBlock); |
| 301 | ScopedPrinter SP(CommentOS); |
| 302 | SP.setPrefix(CommentPrefix); |
| 303 | CVTD.setPrinter(&SP); |
| 304 | bool DumpSuccess = |
| 305 | CVTD.dump({Record.bytes_begin(), Record.bytes_end()}); |
| 306 | (void)DumpSuccess; |
| 307 | assert(DumpSuccess && "produced malformed type record"); |
| 308 | // emitRawComment will insert its own tab and comment string before |
| 309 | // the first line, so strip off our first one. It also prints its own |
| 310 | // newline. |
| 311 | OS.emitRawComment( |
| 312 | CommentOS.str().drop_front(CommentPrefix.size() - 1).rtrim()); |
| 313 | } |
| 314 | OS.EmitBinaryData(Record); |
Reid Kleckner | 2280f93 | 2016-05-23 20:23:46 +0000 | [diff] [blame] | 315 | }); |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 316 | } |
| 317 | |
Reid Kleckner | 5d122f8 | 2016-05-25 23:16:12 +0000 | [diff] [blame] | 318 | void CodeViewDebug::emitInlineeLinesSubsection() { |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 319 | if (InlinedSubprograms.empty()) |
| 320 | return; |
| 321 | |
Reid Kleckner | 5d122f8 | 2016-05-25 23:16:12 +0000 | [diff] [blame] | 322 | // Use the generic .debug$S section. |
| 323 | switchToDebugSectionForSymbol(nullptr); |
| 324 | |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 325 | MCSymbol *InlineBegin = MMI->getContext().createTempSymbol(), |
| 326 | *InlineEnd = MMI->getContext().createTempSymbol(); |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 327 | |
| 328 | OS.AddComment("Inlinee lines subsection"); |
| 329 | OS.EmitIntValue(unsigned(ModuleSubstreamKind::InlineeLines), 4); |
David Majnemer | 30579ec | 2016-02-02 23:18:23 +0000 | [diff] [blame] | 330 | OS.AddComment("Subsection size"); |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 331 | OS.emitAbsoluteSymbolDiff(InlineEnd, InlineBegin, 4); |
| 332 | OS.EmitLabel(InlineBegin); |
| 333 | |
| 334 | // We don't provide any extra file info. |
| 335 | // FIXME: Find out if debuggers use this info. |
David Majnemer | 30579ec | 2016-02-02 23:18:23 +0000 | [diff] [blame] | 336 | OS.AddComment("Inlinee lines signature"); |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 337 | OS.EmitIntValue(unsigned(InlineeLinesSignature::Normal), 4); |
| 338 | |
| 339 | for (const DISubprogram *SP : InlinedSubprograms) { |
Reid Kleckner | 2280f93 | 2016-05-23 20:23:46 +0000 | [diff] [blame] | 340 | assert(TypeIndices.count(SP)); |
| 341 | TypeIndex InlineeIdx = TypeIndices[SP]; |
| 342 | |
David Majnemer | 30579ec | 2016-02-02 23:18:23 +0000 | [diff] [blame] | 343 | OS.AddBlankLine(); |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 344 | unsigned FileId = maybeRecordFile(SP->getFile()); |
| 345 | OS.AddComment("Inlined function " + SP->getDisplayName() + " starts at " + |
| 346 | SP->getFilename() + Twine(':') + Twine(SP->getLine())); |
David Majnemer | 30579ec | 2016-02-02 23:18:23 +0000 | [diff] [blame] | 347 | OS.AddBlankLine(); |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 348 | // The filechecksum table uses 8 byte entries for now, and file ids start at |
| 349 | // 1. |
| 350 | unsigned FileOffset = (FileId - 1) * 8; |
David Majnemer | 30579ec | 2016-02-02 23:18:23 +0000 | [diff] [blame] | 351 | OS.AddComment("Type index of inlined function"); |
Reid Kleckner | 2280f93 | 2016-05-23 20:23:46 +0000 | [diff] [blame] | 352 | OS.EmitIntValue(InlineeIdx.getIndex(), 4); |
David Majnemer | 30579ec | 2016-02-02 23:18:23 +0000 | [diff] [blame] | 353 | OS.AddComment("Offset into filechecksum table"); |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 354 | OS.EmitIntValue(FileOffset, 4); |
David Majnemer | 30579ec | 2016-02-02 23:18:23 +0000 | [diff] [blame] | 355 | OS.AddComment("Starting line number"); |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 356 | OS.EmitIntValue(SP->getLine(), 4); |
| 357 | } |
| 358 | |
| 359 | OS.EmitLabel(InlineEnd); |
| 360 | } |
| 361 | |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 362 | void CodeViewDebug::collectInlineSiteChildren( |
| 363 | SmallVectorImpl<unsigned> &Children, const FunctionInfo &FI, |
| 364 | const InlineSite &Site) { |
| 365 | for (const DILocation *ChildSiteLoc : Site.ChildSites) { |
| 366 | auto I = FI.InlineSites.find(ChildSiteLoc); |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 367 | const InlineSite &ChildSite = I->second; |
| 368 | Children.push_back(ChildSite.SiteFuncId); |
| 369 | collectInlineSiteChildren(Children, FI, ChildSite); |
| 370 | } |
| 371 | } |
| 372 | |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 373 | void CodeViewDebug::emitInlinedCallSite(const FunctionInfo &FI, |
| 374 | const DILocation *InlinedAt, |
| 375 | const InlineSite &Site) { |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 376 | MCSymbol *InlineBegin = MMI->getContext().createTempSymbol(), |
| 377 | *InlineEnd = MMI->getContext().createTempSymbol(); |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 378 | |
Reid Kleckner | 2280f93 | 2016-05-23 20:23:46 +0000 | [diff] [blame] | 379 | assert(TypeIndices.count(Site.Inlinee)); |
| 380 | TypeIndex InlineeIdx = TypeIndices[Site.Inlinee]; |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 381 | |
| 382 | // SymbolRecord |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 383 | OS.AddComment("Record length"); |
Reid Kleckner | eb3bcdd | 2016-02-03 21:24:42 +0000 | [diff] [blame] | 384 | OS.emitAbsoluteSymbolDiff(InlineEnd, InlineBegin, 2); // RecordLength |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 385 | OS.EmitLabel(InlineBegin); |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 386 | OS.AddComment("Record kind: S_INLINESITE"); |
Zachary Turner | 63a2846 | 2016-05-17 23:50:21 +0000 | [diff] [blame] | 387 | OS.EmitIntValue(SymbolKind::S_INLINESITE, 2); // RecordKind |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 388 | |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 389 | OS.AddComment("PtrParent"); |
| 390 | OS.EmitIntValue(0, 4); |
| 391 | OS.AddComment("PtrEnd"); |
| 392 | OS.EmitIntValue(0, 4); |
| 393 | OS.AddComment("Inlinee type index"); |
Reid Kleckner | 2280f93 | 2016-05-23 20:23:46 +0000 | [diff] [blame] | 394 | OS.EmitIntValue(InlineeIdx.getIndex(), 4); |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 395 | |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 396 | unsigned FileId = maybeRecordFile(Site.Inlinee->getFile()); |
| 397 | unsigned StartLineNum = Site.Inlinee->getLine(); |
| 398 | SmallVector<unsigned, 3> SecondaryFuncIds; |
| 399 | collectInlineSiteChildren(SecondaryFuncIds, FI, Site); |
| 400 | |
| 401 | OS.EmitCVInlineLinetableDirective(Site.SiteFuncId, FileId, StartLineNum, |
David Majnemer | c9911f2 | 2016-02-02 19:22:34 +0000 | [diff] [blame] | 402 | FI.Begin, FI.End, SecondaryFuncIds); |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 403 | |
| 404 | OS.EmitLabel(InlineEnd); |
| 405 | |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 406 | for (const LocalVariable &Var : Site.InlinedLocals) |
| 407 | emitLocalVariable(Var); |
| 408 | |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 409 | // Recurse on child inlined call sites before closing the scope. |
| 410 | for (const DILocation *ChildSite : Site.ChildSites) { |
| 411 | auto I = FI.InlineSites.find(ChildSite); |
| 412 | assert(I != FI.InlineSites.end() && |
| 413 | "child site not in function inline site map"); |
| 414 | emitInlinedCallSite(FI, ChildSite, I->second); |
| 415 | } |
| 416 | |
| 417 | // Close the scope. |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 418 | OS.AddComment("Record length"); |
| 419 | OS.EmitIntValue(2, 2); // RecordLength |
| 420 | OS.AddComment("Record kind: S_INLINESITE_END"); |
Zachary Turner | 63a2846 | 2016-05-17 23:50:21 +0000 | [diff] [blame] | 421 | OS.EmitIntValue(SymbolKind::S_INLINESITE_END, 2); // RecordKind |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 422 | } |
| 423 | |
Reid Kleckner | 5d122f8 | 2016-05-25 23:16:12 +0000 | [diff] [blame] | 424 | void CodeViewDebug::switchToDebugSectionForSymbol(const MCSymbol *GVSym) { |
| 425 | // If we have a symbol, it may be in a section that is COMDAT. If so, find the |
| 426 | // comdat key. A section may be comdat because of -ffunction-sections or |
| 427 | // because it is comdat in the IR. |
| 428 | MCSectionCOFF *GVSec = |
| 429 | GVSym ? dyn_cast<MCSectionCOFF>(&GVSym->getSection()) : nullptr; |
| 430 | const MCSymbol *KeySym = GVSec ? GVSec->getCOMDATSymbol() : nullptr; |
| 431 | |
| 432 | MCSectionCOFF *DebugSec = cast<MCSectionCOFF>( |
| 433 | Asm->getObjFileLowering().getCOFFDebugSymbolsSection()); |
| 434 | DebugSec = OS.getContext().getAssociativeCOFFSection(DebugSec, KeySym); |
| 435 | |
| 436 | OS.SwitchSection(DebugSec); |
| 437 | |
| 438 | // Emit the magic version number if this is the first time we've switched to |
| 439 | // this section. |
| 440 | if (ComdatDebugSections.insert(DebugSec).second) |
| 441 | emitCodeViewMagicVersion(); |
| 442 | } |
| 443 | |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 444 | void CodeViewDebug::emitDebugInfoForFunction(const Function *GV, |
| 445 | FunctionInfo &FI) { |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 446 | // For each function there is a separate subsection |
| 447 | // which holds the PC to file:line table. |
| 448 | const MCSymbol *Fn = Asm->getSymbol(GV); |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 449 | assert(Fn); |
Timur Iskhodzhanov | 8499a12 | 2014-03-26 09:50:36 +0000 | [diff] [blame] | 450 | |
Reid Kleckner | 5d122f8 | 2016-05-25 23:16:12 +0000 | [diff] [blame] | 451 | // Switch to the to a comdat section, if appropriate. |
| 452 | switchToDebugSectionForSymbol(Fn); |
| 453 | |
Duncan P. N. Exon Smith | 23e56ec | 2015-03-20 19:50:00 +0000 | [diff] [blame] | 454 | StringRef FuncName; |
Pete Cooper | adebb93 | 2016-03-11 02:14:16 +0000 | [diff] [blame] | 455 | if (auto *SP = GV->getSubprogram()) |
Duncan P. N. Exon Smith | 537b4a8 | 2015-04-14 03:40:37 +0000 | [diff] [blame] | 456 | FuncName = SP->getDisplayName(); |
Duncan P. N. Exon Smith | 23e56ec | 2015-03-20 19:50:00 +0000 | [diff] [blame] | 457 | |
Reid Kleckner | 3c0ff98 | 2016-01-14 00:12:54 +0000 | [diff] [blame] | 458 | // If our DISubprogram name is empty, use the mangled name. |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 459 | if (FuncName.empty()) |
| 460 | FuncName = GlobalValue::getRealLinkageName(GV->getName()); |
Reid Kleckner | 3c0ff98 | 2016-01-14 00:12:54 +0000 | [diff] [blame] | 461 | |
Timur Iskhodzhanov | 2bc90fd | 2014-10-24 01:27:45 +0000 | [diff] [blame] | 462 | // Emit a symbol subsection, required by VS2012+ to find function boundaries. |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 463 | MCSymbol *SymbolsBegin = MMI->getContext().createTempSymbol(), |
| 464 | *SymbolsEnd = MMI->getContext().createTempSymbol(); |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 465 | OS.AddComment("Symbol subsection for " + Twine(FuncName)); |
| 466 | OS.EmitIntValue(unsigned(ModuleSubstreamKind::Symbols), 4); |
| 467 | OS.AddComment("Subsection size"); |
Reid Kleckner | eb3bcdd | 2016-02-03 21:24:42 +0000 | [diff] [blame] | 468 | OS.emitAbsoluteSymbolDiff(SymbolsEnd, SymbolsBegin, 4); |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 469 | OS.EmitLabel(SymbolsBegin); |
Timur Iskhodzhanov | 2bc90fd | 2014-10-24 01:27:45 +0000 | [diff] [blame] | 470 | { |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 471 | MCSymbol *ProcRecordBegin = MMI->getContext().createTempSymbol(), |
| 472 | *ProcRecordEnd = MMI->getContext().createTempSymbol(); |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 473 | OS.AddComment("Record length"); |
Reid Kleckner | eb3bcdd | 2016-02-03 21:24:42 +0000 | [diff] [blame] | 474 | OS.emitAbsoluteSymbolDiff(ProcRecordEnd, ProcRecordBegin, 2); |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 475 | OS.EmitLabel(ProcRecordBegin); |
Timur Iskhodzhanov | 2bc90fd | 2014-10-24 01:27:45 +0000 | [diff] [blame] | 476 | |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 477 | OS.AddComment("Record kind: S_GPROC32_ID"); |
Zachary Turner | 63a2846 | 2016-05-17 23:50:21 +0000 | [diff] [blame] | 478 | OS.EmitIntValue(unsigned(SymbolKind::S_GPROC32_ID), 2); |
Reid Kleckner | 6b3faef | 2016-01-13 23:44:57 +0000 | [diff] [blame] | 479 | |
David Majnemer | 30579ec | 2016-02-02 23:18:23 +0000 | [diff] [blame] | 480 | // These fields are filled in by tools like CVPACK which run after the fact. |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 481 | OS.AddComment("PtrParent"); |
| 482 | OS.EmitIntValue(0, 4); |
| 483 | OS.AddComment("PtrEnd"); |
| 484 | OS.EmitIntValue(0, 4); |
| 485 | OS.AddComment("PtrNext"); |
| 486 | OS.EmitIntValue(0, 4); |
Timur Iskhodzhanov | 2bc90fd | 2014-10-24 01:27:45 +0000 | [diff] [blame] | 487 | // This is the important bit that tells the debugger where the function |
| 488 | // code is located and what's its size: |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 489 | OS.AddComment("Code size"); |
Reid Kleckner | eb3bcdd | 2016-02-03 21:24:42 +0000 | [diff] [blame] | 490 | OS.emitAbsoluteSymbolDiff(FI.End, Fn, 4); |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 491 | OS.AddComment("Offset after prologue"); |
| 492 | OS.EmitIntValue(0, 4); |
| 493 | OS.AddComment("Offset before epilogue"); |
| 494 | OS.EmitIntValue(0, 4); |
| 495 | OS.AddComment("Function type index"); |
| 496 | OS.EmitIntValue(0, 4); |
| 497 | OS.AddComment("Function section relative address"); |
| 498 | OS.EmitCOFFSecRel32(Fn); |
| 499 | OS.AddComment("Function section index"); |
| 500 | OS.EmitCOFFSectionIndex(Fn); |
| 501 | OS.AddComment("Flags"); |
| 502 | OS.EmitIntValue(0, 1); |
Timur Iskhodzhanov | a11b32b | 2014-11-12 20:10:09 +0000 | [diff] [blame] | 503 | // Emit the function display name as a null-terminated string. |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 504 | OS.AddComment("Function name"); |
David Majnemer | 1256125 | 2016-03-13 10:53:30 +0000 | [diff] [blame] | 505 | // Truncate the name so we won't overflow the record length field. |
David Majnemer | b9456a5 | 2016-03-14 05:15:09 +0000 | [diff] [blame] | 506 | emitNullTerminatedSymbolName(OS, FuncName); |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 507 | OS.EmitLabel(ProcRecordEnd); |
Timur Iskhodzhanov | 2bc90fd | 2014-10-24 01:27:45 +0000 | [diff] [blame] | 508 | |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 509 | for (const LocalVariable &Var : FI.Locals) |
| 510 | emitLocalVariable(Var); |
| 511 | |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 512 | // Emit inlined call site information. Only emit functions inlined directly |
| 513 | // into the parent function. We'll emit the other sites recursively as part |
| 514 | // of their parent inline site. |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 515 | for (const DILocation *InlinedAt : FI.ChildSites) { |
| 516 | auto I = FI.InlineSites.find(InlinedAt); |
| 517 | assert(I != FI.InlineSites.end() && |
| 518 | "child site not in function inline site map"); |
| 519 | emitInlinedCallSite(FI, InlinedAt, I->second); |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 520 | } |
| 521 | |
Timur Iskhodzhanov | 2bc90fd | 2014-10-24 01:27:45 +0000 | [diff] [blame] | 522 | // We're done with this function. |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 523 | OS.AddComment("Record length"); |
| 524 | OS.EmitIntValue(0x0002, 2); |
| 525 | OS.AddComment("Record kind: S_PROC_ID_END"); |
Zachary Turner | 63a2846 | 2016-05-17 23:50:21 +0000 | [diff] [blame] | 526 | OS.EmitIntValue(unsigned(SymbolKind::S_PROC_ID_END), 2); |
Timur Iskhodzhanov | 2bc90fd | 2014-10-24 01:27:45 +0000 | [diff] [blame] | 527 | } |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 528 | OS.EmitLabel(SymbolsEnd); |
Timur Iskhodzhanov | 2bc90fd | 2014-10-24 01:27:45 +0000 | [diff] [blame] | 529 | // Every subsection must be aligned to a 4-byte boundary. |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 530 | OS.EmitValueToAlignment(4); |
Timur Iskhodzhanov | 2bc90fd | 2014-10-24 01:27:45 +0000 | [diff] [blame] | 531 | |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 532 | // We have an assembler directive that takes care of the whole line table. |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 533 | OS.EmitCVLinetableDirective(FI.FuncId, Fn, FI.End); |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 534 | } |
| 535 | |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 536 | CodeViewDebug::LocalVarDefRange |
| 537 | CodeViewDebug::createDefRangeMem(uint16_t CVRegister, int Offset) { |
| 538 | LocalVarDefRange DR; |
Aaron Ballman | c6a2f21 | 2016-02-16 15:35:51 +0000 | [diff] [blame] | 539 | DR.InMemory = -1; |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 540 | DR.DataOffset = Offset; |
| 541 | assert(DR.DataOffset == Offset && "truncation"); |
| 542 | DR.StructOffset = 0; |
| 543 | DR.CVRegister = CVRegister; |
| 544 | return DR; |
| 545 | } |
| 546 | |
| 547 | CodeViewDebug::LocalVarDefRange |
| 548 | CodeViewDebug::createDefRangeReg(uint16_t CVRegister) { |
| 549 | LocalVarDefRange DR; |
| 550 | DR.InMemory = 0; |
| 551 | DR.DataOffset = 0; |
| 552 | DR.StructOffset = 0; |
| 553 | DR.CVRegister = CVRegister; |
| 554 | return DR; |
| 555 | } |
| 556 | |
| 557 | void CodeViewDebug::collectVariableInfoFromMMITable( |
| 558 | DenseSet<InlinedVariable> &Processed) { |
| 559 | const TargetSubtargetInfo &TSI = Asm->MF->getSubtarget(); |
| 560 | const TargetFrameLowering *TFI = TSI.getFrameLowering(); |
| 561 | const TargetRegisterInfo *TRI = TSI.getRegisterInfo(); |
| 562 | |
| 563 | for (const MachineModuleInfo::VariableDbgInfo &VI : |
| 564 | MMI->getVariableDbgInfo()) { |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 565 | if (!VI.Var) |
| 566 | continue; |
| 567 | assert(VI.Var->isValidLocationForIntrinsic(VI.Loc) && |
| 568 | "Expected inlined-at fields to agree"); |
| 569 | |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 570 | Processed.insert(InlinedVariable(VI.Var, VI.Loc->getInlinedAt())); |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 571 | LexicalScope *Scope = LScopes.findLexicalScope(VI.Loc); |
| 572 | |
| 573 | // If variable scope is not found then skip this variable. |
| 574 | if (!Scope) |
| 575 | continue; |
| 576 | |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 577 | // Get the frame register used and the offset. |
| 578 | unsigned FrameReg = 0; |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 579 | int FrameOffset = TFI->getFrameIndexReference(*Asm->MF, VI.Slot, FrameReg); |
| 580 | uint16_t CVReg = TRI->getCodeViewRegNum(FrameReg); |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 581 | |
| 582 | // Calculate the label ranges. |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 583 | LocalVarDefRange DefRange = createDefRangeMem(CVReg, FrameOffset); |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 584 | for (const InsnRange &Range : Scope->getRanges()) { |
| 585 | const MCSymbol *Begin = getLabelBeforeInsn(Range.first); |
| 586 | const MCSymbol *End = getLabelAfterInsn(Range.second); |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 587 | End = End ? End : Asm->getFunctionEnd(); |
| 588 | DefRange.Ranges.emplace_back(Begin, End); |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 589 | } |
| 590 | |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 591 | LocalVariable Var; |
| 592 | Var.DIVar = VI.Var; |
| 593 | Var.DefRanges.emplace_back(std::move(DefRange)); |
| 594 | recordLocalVariable(std::move(Var), VI.Loc->getInlinedAt()); |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | void CodeViewDebug::collectVariableInfo(const DISubprogram *SP) { |
| 599 | DenseSet<InlinedVariable> Processed; |
| 600 | // Grab the variable info that was squirreled away in the MMI side-table. |
| 601 | collectVariableInfoFromMMITable(Processed); |
| 602 | |
| 603 | const TargetRegisterInfo *TRI = Asm->MF->getSubtarget().getRegisterInfo(); |
| 604 | |
| 605 | for (const auto &I : DbgValues) { |
| 606 | InlinedVariable IV = I.first; |
| 607 | if (Processed.count(IV)) |
| 608 | continue; |
| 609 | const DILocalVariable *DIVar = IV.first; |
| 610 | const DILocation *InlinedAt = IV.second; |
| 611 | |
| 612 | // Instruction ranges, specifying where IV is accessible. |
| 613 | const auto &Ranges = I.second; |
| 614 | |
| 615 | LexicalScope *Scope = nullptr; |
| 616 | if (InlinedAt) |
| 617 | Scope = LScopes.findInlinedScope(DIVar->getScope(), InlinedAt); |
| 618 | else |
| 619 | Scope = LScopes.findLexicalScope(DIVar->getScope()); |
| 620 | // If variable scope is not found then skip this variable. |
| 621 | if (!Scope) |
| 622 | continue; |
| 623 | |
| 624 | LocalVariable Var; |
| 625 | Var.DIVar = DIVar; |
| 626 | |
| 627 | // Calculate the definition ranges. |
| 628 | for (auto I = Ranges.begin(), E = Ranges.end(); I != E; ++I) { |
| 629 | const InsnRange &Range = *I; |
| 630 | const MachineInstr *DVInst = Range.first; |
| 631 | assert(DVInst->isDebugValue() && "Invalid History entry"); |
| 632 | const DIExpression *DIExpr = DVInst->getDebugExpression(); |
| 633 | |
| 634 | // Bail if there is a complex DWARF expression for now. |
| 635 | if (DIExpr && DIExpr->getNumElements() > 0) |
| 636 | continue; |
| 637 | |
Reid Kleckner | 9a593ee | 2016-02-16 21:49:26 +0000 | [diff] [blame] | 638 | // Bail if operand 0 is not a valid register. This means the variable is a |
| 639 | // simple constant, or is described by a complex expression. |
| 640 | // FIXME: Find a way to represent constant variables, since they are |
| 641 | // relatively common. |
| 642 | unsigned Reg = |
| 643 | DVInst->getOperand(0).isReg() ? DVInst->getOperand(0).getReg() : 0; |
| 644 | if (Reg == 0) |
Reid Kleckner | 6e0d5f5 | 2016-02-16 21:14:51 +0000 | [diff] [blame] | 645 | continue; |
| 646 | |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 647 | // Handle the two cases we can handle: indirect in memory and in register. |
| 648 | bool IsIndirect = DVInst->getOperand(1).isImm(); |
| 649 | unsigned CVReg = TRI->getCodeViewRegNum(DVInst->getOperand(0).getReg()); |
| 650 | { |
| 651 | LocalVarDefRange DefRange; |
| 652 | if (IsIndirect) { |
| 653 | int64_t Offset = DVInst->getOperand(1).getImm(); |
| 654 | DefRange = createDefRangeMem(CVReg, Offset); |
| 655 | } else { |
| 656 | DefRange = createDefRangeReg(CVReg); |
| 657 | } |
| 658 | if (Var.DefRanges.empty() || |
| 659 | Var.DefRanges.back().isDifferentLocation(DefRange)) { |
| 660 | Var.DefRanges.emplace_back(std::move(DefRange)); |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | // Compute the label range. |
| 665 | const MCSymbol *Begin = getLabelBeforeInsn(Range.first); |
| 666 | const MCSymbol *End = getLabelAfterInsn(Range.second); |
| 667 | if (!End) { |
| 668 | if (std::next(I) != E) |
| 669 | End = getLabelBeforeInsn(std::next(I)->first); |
| 670 | else |
| 671 | End = Asm->getFunctionEnd(); |
| 672 | } |
| 673 | |
| 674 | // If the last range end is our begin, just extend the last range. |
| 675 | // Otherwise make a new range. |
| 676 | SmallVectorImpl<std::pair<const MCSymbol *, const MCSymbol *>> &Ranges = |
| 677 | Var.DefRanges.back().Ranges; |
| 678 | if (!Ranges.empty() && Ranges.back().second == Begin) |
| 679 | Ranges.back().second = End; |
| 680 | else |
| 681 | Ranges.emplace_back(Begin, End); |
| 682 | |
| 683 | // FIXME: Do more range combining. |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 684 | } |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 685 | |
| 686 | recordLocalVariable(std::move(Var), InlinedAt); |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 687 | } |
| 688 | } |
| 689 | |
Reid Kleckner | 70f5bc9 | 2016-01-14 19:25:04 +0000 | [diff] [blame] | 690 | void CodeViewDebug::beginFunction(const MachineFunction *MF) { |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 691 | assert(!CurFn && "Can't process two functions at once!"); |
| 692 | |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 693 | if (!Asm || !MMI->hasDebugInfo()) |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 694 | return; |
| 695 | |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 696 | DebugHandlerBase::beginFunction(MF); |
| 697 | |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 698 | const Function *GV = MF->getFunction(); |
| 699 | assert(FnDebugInfo.count(GV) == false); |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 700 | CurFn = &FnDebugInfo[GV]; |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 701 | CurFn->FuncId = NextFuncId++; |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 702 | CurFn->Begin = Asm->getFunctionBegin(); |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 703 | |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 704 | // Find the end of the function prolog. First known non-DBG_VALUE and |
| 705 | // non-frame setup location marks the beginning of the function body. |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 706 | // FIXME: is there a simpler a way to do this? Can we just search |
| 707 | // for the first instruction of the function, not the last of the prolog? |
| 708 | DebugLoc PrologEndLoc; |
| 709 | bool EmptyPrologue = true; |
Alexey Samsonov | f74bde6 | 2014-04-30 22:17:38 +0000 | [diff] [blame] | 710 | for (const auto &MBB : *MF) { |
Alexey Samsonov | f74bde6 | 2014-04-30 22:17:38 +0000 | [diff] [blame] | 711 | for (const auto &MI : MBB) { |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 712 | if (!MI.isDebugValue() && !MI.getFlag(MachineInstr::FrameSetup) && |
| 713 | MI.getDebugLoc()) { |
Alexey Samsonov | f74bde6 | 2014-04-30 22:17:38 +0000 | [diff] [blame] | 714 | PrologEndLoc = MI.getDebugLoc(); |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 715 | break; |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 716 | } else if (!MI.isDebugValue()) { |
| 717 | EmptyPrologue = false; |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 718 | } |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 719 | } |
| 720 | } |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 721 | |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 722 | // Record beginning of function if we have a non-empty prologue. |
Duncan P. N. Exon Smith | 9dffcd0 | 2015-03-30 19:14:47 +0000 | [diff] [blame] | 723 | if (PrologEndLoc && !EmptyPrologue) { |
| 724 | DebugLoc FnStartDL = PrologEndLoc.getFnDebugLoc(); |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 725 | maybeRecordLocation(FnStartDL, MF); |
| 726 | } |
| 727 | } |
| 728 | |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 729 | void CodeViewDebug::emitLocalVariable(const LocalVariable &Var) { |
| 730 | // LocalSym record, see SymbolRecord.h for more info. |
| 731 | MCSymbol *LocalBegin = MMI->getContext().createTempSymbol(), |
| 732 | *LocalEnd = MMI->getContext().createTempSymbol(); |
| 733 | OS.AddComment("Record length"); |
| 734 | OS.emitAbsoluteSymbolDiff(LocalEnd, LocalBegin, 2); |
| 735 | OS.EmitLabel(LocalBegin); |
| 736 | |
| 737 | OS.AddComment("Record kind: S_LOCAL"); |
Zachary Turner | 63a2846 | 2016-05-17 23:50:21 +0000 | [diff] [blame] | 738 | OS.EmitIntValue(unsigned(SymbolKind::S_LOCAL), 2); |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 739 | |
Zachary Turner | 63a2846 | 2016-05-17 23:50:21 +0000 | [diff] [blame] | 740 | LocalSymFlags Flags = LocalSymFlags::None; |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 741 | if (Var.DIVar->isParameter()) |
Zachary Turner | 63a2846 | 2016-05-17 23:50:21 +0000 | [diff] [blame] | 742 | Flags |= LocalSymFlags::IsParameter; |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 743 | if (Var.DefRanges.empty()) |
Zachary Turner | 63a2846 | 2016-05-17 23:50:21 +0000 | [diff] [blame] | 744 | Flags |= LocalSymFlags::IsOptimizedOut; |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 745 | |
| 746 | OS.AddComment("TypeIndex"); |
| 747 | OS.EmitIntValue(TypeIndex::Int32().getIndex(), 4); |
| 748 | OS.AddComment("Flags"); |
Zachary Turner | 63a2846 | 2016-05-17 23:50:21 +0000 | [diff] [blame] | 749 | OS.EmitIntValue(static_cast<uint16_t>(Flags), 2); |
David Majnemer | 1256125 | 2016-03-13 10:53:30 +0000 | [diff] [blame] | 750 | // Truncate the name so we won't overflow the record length field. |
David Majnemer | b9456a5 | 2016-03-14 05:15:09 +0000 | [diff] [blame] | 751 | emitNullTerminatedSymbolName(OS, Var.DIVar->getName()); |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 752 | OS.EmitLabel(LocalEnd); |
| 753 | |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 754 | // Calculate the on disk prefix of the appropriate def range record. The |
| 755 | // records and on disk formats are described in SymbolRecords.h. BytePrefix |
| 756 | // should be big enough to hold all forms without memory allocation. |
| 757 | SmallString<20> BytePrefix; |
| 758 | for (const LocalVarDefRange &DefRange : Var.DefRanges) { |
| 759 | BytePrefix.clear(); |
| 760 | // FIXME: Handle bitpieces. |
| 761 | if (DefRange.StructOffset != 0) |
| 762 | continue; |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 763 | |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 764 | if (DefRange.InMemory) { |
Zachary Turner | a78ecd1 | 2016-05-23 18:49:06 +0000 | [diff] [blame] | 765 | DefRangeRegisterRelSym Sym(DefRange.CVRegister, 0, DefRange.DataOffset, 0, |
| 766 | 0, 0, ArrayRef<LocalVariableAddrGap>()); |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 767 | ulittle16_t SymKind = ulittle16_t(S_DEFRANGE_REGISTER_REL); |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 768 | BytePrefix += |
| 769 | StringRef(reinterpret_cast<const char *>(&SymKind), sizeof(SymKind)); |
Zachary Turner | a78ecd1 | 2016-05-23 18:49:06 +0000 | [diff] [blame] | 770 | BytePrefix += |
| 771 | StringRef(reinterpret_cast<const char *>(&Sym.Header), |
| 772 | sizeof(Sym.Header) - sizeof(LocalVariableAddrRange)); |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 773 | } else { |
| 774 | assert(DefRange.DataOffset == 0 && "unexpected offset into register"); |
Zachary Turner | a78ecd1 | 2016-05-23 18:49:06 +0000 | [diff] [blame] | 775 | // Unclear what matters here. |
| 776 | DefRangeRegisterSym Sym(DefRange.CVRegister, 0, 0, 0, 0, |
| 777 | ArrayRef<LocalVariableAddrGap>()); |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 778 | ulittle16_t SymKind = ulittle16_t(S_DEFRANGE_REGISTER); |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 779 | BytePrefix += |
| 780 | StringRef(reinterpret_cast<const char *>(&SymKind), sizeof(SymKind)); |
Zachary Turner | a78ecd1 | 2016-05-23 18:49:06 +0000 | [diff] [blame] | 781 | BytePrefix += |
| 782 | StringRef(reinterpret_cast<const char *>(&Sym.Header), |
| 783 | sizeof(Sym.Header) - sizeof(LocalVariableAddrRange)); |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 784 | } |
| 785 | OS.EmitCVDefRangeDirective(DefRange.Ranges, BytePrefix); |
| 786 | } |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 787 | } |
| 788 | |
Reid Kleckner | 70f5bc9 | 2016-01-14 19:25:04 +0000 | [diff] [blame] | 789 | void CodeViewDebug::endFunction(const MachineFunction *MF) { |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 790 | if (!Asm || !CurFn) // We haven't created any debug info for this function. |
| 791 | return; |
| 792 | |
Timur Iskhodzhanov | b5b7a61 | 2014-03-26 11:24:36 +0000 | [diff] [blame] | 793 | const Function *GV = MF->getFunction(); |
Yaron Keren | 6d3194f | 2014-06-20 10:26:56 +0000 | [diff] [blame] | 794 | assert(FnDebugInfo.count(GV)); |
Timur Iskhodzhanov | b5b7a61 | 2014-03-26 11:24:36 +0000 | [diff] [blame] | 795 | assert(CurFn == &FnDebugInfo[GV]); |
| 796 | |
Pete Cooper | adebb93 | 2016-03-11 02:14:16 +0000 | [diff] [blame] | 797 | collectVariableInfo(GV->getSubprogram()); |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 798 | |
| 799 | DebugHandlerBase::endFunction(MF); |
| 800 | |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 801 | // Don't emit anything if we don't have any line tables. |
| 802 | if (!CurFn->HaveLineInfo) { |
Timur Iskhodzhanov | b5b7a61 | 2014-03-26 11:24:36 +0000 | [diff] [blame] | 803 | FnDebugInfo.erase(GV); |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 804 | CurFn = nullptr; |
| 805 | return; |
Timur Iskhodzhanov | 8499a12 | 2014-03-26 09:50:36 +0000 | [diff] [blame] | 806 | } |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 807 | |
| 808 | CurFn->End = Asm->getFunctionEnd(); |
| 809 | |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 810 | CurFn = nullptr; |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 811 | } |
| 812 | |
Reid Kleckner | 70f5bc9 | 2016-01-14 19:25:04 +0000 | [diff] [blame] | 813 | void CodeViewDebug::beginInstruction(const MachineInstr *MI) { |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 814 | DebugHandlerBase::beginInstruction(MI); |
| 815 | |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 816 | // Ignore DBG_VALUE locations and function prologue. |
| 817 | if (!Asm || MI->isDebugValue() || MI->getFlag(MachineInstr::FrameSetup)) |
| 818 | return; |
| 819 | DebugLoc DL = MI->getDebugLoc(); |
Duncan P. N. Exon Smith | 9dffcd0 | 2015-03-30 19:14:47 +0000 | [diff] [blame] | 820 | if (DL == PrevInstLoc || !DL) |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 821 | return; |
| 822 | maybeRecordLocation(DL, Asm->MF); |
| 823 | } |