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 | 156a723 | 2016-06-22 18:31:14 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/TinyPtrVector.h" |
Reid Kleckner | c92e946 | 2016-07-01 18:05:56 +0000 | [diff] [blame] | 16 | #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h" |
Reid Kleckner | 6b3faef | 2016-01-13 23:44:57 +0000 | [diff] [blame] | 17 | #include "llvm/DebugInfo/CodeView/CodeView.h" |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 18 | #include "llvm/DebugInfo/CodeView/FieldListRecordBuilder.h" |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 19 | #include "llvm/DebugInfo/CodeView/Line.h" |
Reid Kleckner | 6b3faef | 2016-01-13 23:44:57 +0000 | [diff] [blame] | 20 | #include "llvm/DebugInfo/CodeView/SymbolRecord.h" |
Reid Kleckner | fbdbe9e | 2016-05-31 18:45:36 +0000 | [diff] [blame] | 21 | #include "llvm/DebugInfo/CodeView/TypeDumper.h" |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 22 | #include "llvm/DebugInfo/CodeView/TypeIndex.h" |
| 23 | #include "llvm/DebugInfo/CodeView/TypeRecord.h" |
Reid Kleckner | c92e946 | 2016-07-01 18:05:56 +0000 | [diff] [blame] | 24 | #include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h" |
Zachary Turner | a3225b0 | 2016-07-29 20:56:36 +0000 | [diff] [blame] | 25 | #include "llvm/DebugInfo/MSF/ByteStream.h" |
| 26 | #include "llvm/DebugInfo/MSF/StreamReader.h" |
David Majnemer | 9319cbc | 2016-06-30 03:00:20 +0000 | [diff] [blame] | 27 | #include "llvm/IR/Constants.h" |
Reid Kleckner | 46cb48c | 2016-07-27 16:03:57 +0000 | [diff] [blame] | 28 | #include "llvm/MC/MCAsmInfo.h" |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 29 | #include "llvm/MC/MCExpr.h" |
Reid Kleckner | 5d122f8 | 2016-05-25 23:16:12 +0000 | [diff] [blame] | 30 | #include "llvm/MC/MCSectionCOFF.h" |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 31 | #include "llvm/MC/MCSymbol.h" |
| 32 | #include "llvm/Support/COFF.h" |
Reid Kleckner | fbdbe9e | 2016-05-31 18:45:36 +0000 | [diff] [blame] | 33 | #include "llvm/Support/ScopedPrinter.h" |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 34 | #include "llvm/Target/TargetFrameLowering.h" |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 35 | #include "llvm/Target/TargetRegisterInfo.h" |
| 36 | #include "llvm/Target/TargetSubtargetInfo.h" |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 37 | |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 38 | using namespace llvm; |
Reid Kleckner | 6b3faef | 2016-01-13 23:44:57 +0000 | [diff] [blame] | 39 | using namespace llvm::codeview; |
Zachary Turner | bac69d3 | 2016-07-22 19:56:05 +0000 | [diff] [blame] | 40 | using namespace llvm::msf; |
Reid Kleckner | 6b3faef | 2016-01-13 23:44:57 +0000 | [diff] [blame] | 41 | |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 42 | CodeViewDebug::CodeViewDebug(AsmPrinter *AP) |
Zachary Turner | c6d54da | 2016-09-09 17:46:17 +0000 | [diff] [blame] | 43 | : DebugHandlerBase(AP), OS(*Asm->OutStreamer), Allocator(), |
| 44 | TypeTable(Allocator), CurFn(nullptr) { |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 45 | // If module doesn't have named metadata anchors or COFF debug section |
| 46 | // is not available, skip any debug info related stuff. |
| 47 | if (!MMI->getModule()->getNamedMetadata("llvm.dbg.cu") || |
| 48 | !AP->getObjFileLowering().getCOFFDebugSymbolsSection()) { |
| 49 | Asm = nullptr; |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | // Tell MMI that we have debug info. |
| 54 | MMI->setDebugInfoAvailability(true); |
| 55 | } |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 56 | |
Reid Kleckner | 9533af4 | 2016-01-16 00:09:09 +0000 | [diff] [blame] | 57 | StringRef CodeViewDebug::getFullFilepath(const DIFile *File) { |
| 58 | std::string &Filepath = FileToFilepathMap[File]; |
Reid Kleckner | 1f11b4e | 2015-12-02 22:34:30 +0000 | [diff] [blame] | 59 | if (!Filepath.empty()) |
| 60 | return Filepath; |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 61 | |
Reid Kleckner | 9533af4 | 2016-01-16 00:09:09 +0000 | [diff] [blame] | 62 | StringRef Dir = File->getDirectory(), Filename = File->getFilename(); |
| 63 | |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 64 | // Clang emits directory and relative filename info into the IR, but CodeView |
| 65 | // operates on full paths. We could change Clang to emit full paths too, but |
| 66 | // that would increase the IR size and probably not needed for other users. |
| 67 | // For now, just concatenate and canonicalize the path here. |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 68 | if (Filename.find(':') == 1) |
| 69 | Filepath = Filename; |
| 70 | else |
Yaron Keren | 75e0c4b | 2015-03-27 17:51:30 +0000 | [diff] [blame] | 71 | Filepath = (Dir + "\\" + Filename).str(); |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 72 | |
| 73 | // Canonicalize the path. We have to do it textually because we may no longer |
| 74 | // have access the file in the filesystem. |
| 75 | // First, replace all slashes with backslashes. |
| 76 | std::replace(Filepath.begin(), Filepath.end(), '/', '\\'); |
| 77 | |
| 78 | // Remove all "\.\" with "\". |
| 79 | size_t Cursor = 0; |
| 80 | while ((Cursor = Filepath.find("\\.\\", Cursor)) != std::string::npos) |
| 81 | Filepath.erase(Cursor, 2); |
| 82 | |
| 83 | // Replace all "\XXX\..\" with "\". Don't try too hard though as the original |
| 84 | // path should be well-formatted, e.g. start with a drive letter, etc. |
| 85 | Cursor = 0; |
| 86 | while ((Cursor = Filepath.find("\\..\\", Cursor)) != std::string::npos) { |
| 87 | // Something's wrong if the path starts with "\..\", abort. |
| 88 | if (Cursor == 0) |
| 89 | break; |
| 90 | |
| 91 | size_t PrevSlash = Filepath.rfind('\\', Cursor - 1); |
| 92 | if (PrevSlash == std::string::npos) |
| 93 | // Something's wrong, abort. |
| 94 | break; |
| 95 | |
| 96 | Filepath.erase(PrevSlash, Cursor + 3 - PrevSlash); |
| 97 | // The next ".." might be following the one we've just erased. |
| 98 | Cursor = PrevSlash; |
| 99 | } |
| 100 | |
| 101 | // Remove all duplicate backslashes. |
| 102 | Cursor = 0; |
| 103 | while ((Cursor = Filepath.find("\\\\", Cursor)) != std::string::npos) |
| 104 | Filepath.erase(Cursor, 1); |
| 105 | |
Reid Kleckner | 1f11b4e | 2015-12-02 22:34:30 +0000 | [diff] [blame] | 106 | return Filepath; |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 109 | unsigned CodeViewDebug::maybeRecordFile(const DIFile *F) { |
| 110 | unsigned NextId = FileIdMap.size() + 1; |
| 111 | auto Insertion = FileIdMap.insert(std::make_pair(F, NextId)); |
| 112 | if (Insertion.second) { |
| 113 | // We have to compute the full filepath and emit a .cv_file directive. |
| 114 | StringRef FullPath = getFullFilepath(F); |
Reid Kleckner | a5b1eef | 2016-08-26 17:58:37 +0000 | [diff] [blame] | 115 | bool Success = OS.EmitCVFileDirective(NextId, FullPath); |
| 116 | (void)Success; |
| 117 | assert(Success && ".cv_file directive failed"); |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 118 | } |
| 119 | return Insertion.first->second; |
| 120 | } |
| 121 | |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 122 | CodeViewDebug::InlineSite & |
| 123 | CodeViewDebug::getInlineSite(const DILocation *InlinedAt, |
| 124 | const DISubprogram *Inlinee) { |
Reid Kleckner | fbd7787 | 2016-03-18 18:54:32 +0000 | [diff] [blame] | 125 | auto SiteInsertion = CurFn->InlineSites.insert({InlinedAt, InlineSite()}); |
| 126 | InlineSite *Site = &SiteInsertion.first->second; |
| 127 | if (SiteInsertion.second) { |
Reid Kleckner | a9f4cc9 | 2016-09-07 16:15:31 +0000 | [diff] [blame] | 128 | unsigned ParentFuncId = CurFn->FuncId; |
| 129 | if (const DILocation *OuterIA = InlinedAt->getInlinedAt()) |
| 130 | ParentFuncId = |
| 131 | getInlineSite(OuterIA, InlinedAt->getScope()->getSubprogram()) |
| 132 | .SiteFuncId; |
| 133 | |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 134 | Site->SiteFuncId = NextFuncId++; |
Reid Kleckner | a9f4cc9 | 2016-09-07 16:15:31 +0000 | [diff] [blame] | 135 | OS.EmitCVInlineSiteIdDirective( |
| 136 | Site->SiteFuncId, ParentFuncId, maybeRecordFile(InlinedAt->getFile()), |
| 137 | InlinedAt->getLine(), InlinedAt->getColumn(), SMLoc()); |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 138 | Site->Inlinee = Inlinee; |
Reid Kleckner | 2280f93 | 2016-05-23 20:23:46 +0000 | [diff] [blame] | 139 | InlinedSubprograms.insert(Inlinee); |
David Majnemer | 75c3ebf | 2016-06-02 17:13:53 +0000 | [diff] [blame] | 140 | getFuncIdForSubprogram(Inlinee); |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 141 | } |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 142 | return *Site; |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 143 | } |
| 144 | |
David Majnemer | 6bdc24e | 2016-07-01 23:12:45 +0000 | [diff] [blame] | 145 | static StringRef getPrettyScopeName(const DIScope *Scope) { |
| 146 | StringRef ScopeName = Scope->getName(); |
| 147 | if (!ScopeName.empty()) |
| 148 | return ScopeName; |
| 149 | |
| 150 | switch (Scope->getTag()) { |
| 151 | case dwarf::DW_TAG_enumeration_type: |
| 152 | case dwarf::DW_TAG_class_type: |
| 153 | case dwarf::DW_TAG_structure_type: |
| 154 | case dwarf::DW_TAG_union_type: |
| 155 | return "<unnamed-tag>"; |
| 156 | case dwarf::DW_TAG_namespace: |
| 157 | return "`anonymous namespace'"; |
| 158 | } |
| 159 | |
| 160 | return StringRef(); |
| 161 | } |
| 162 | |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 163 | static const DISubprogram *getQualifiedNameComponents( |
| 164 | const DIScope *Scope, SmallVectorImpl<StringRef> &QualifiedNameComponents) { |
| 165 | const DISubprogram *ClosestSubprogram = nullptr; |
| 166 | while (Scope != nullptr) { |
| 167 | if (ClosestSubprogram == nullptr) |
| 168 | ClosestSubprogram = dyn_cast<DISubprogram>(Scope); |
David Majnemer | 6bdc24e | 2016-07-01 23:12:45 +0000 | [diff] [blame] | 169 | StringRef ScopeName = getPrettyScopeName(Scope); |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 170 | if (!ScopeName.empty()) |
| 171 | QualifiedNameComponents.push_back(ScopeName); |
| 172 | Scope = Scope->getScope().resolve(); |
| 173 | } |
| 174 | return ClosestSubprogram; |
| 175 | } |
| 176 | |
| 177 | static std::string getQualifiedName(ArrayRef<StringRef> QualifiedNameComponents, |
| 178 | StringRef TypeName) { |
| 179 | std::string FullyQualifiedName; |
| 180 | for (StringRef QualifiedNameComponent : reverse(QualifiedNameComponents)) { |
| 181 | FullyQualifiedName.append(QualifiedNameComponent); |
| 182 | FullyQualifiedName.append("::"); |
| 183 | } |
| 184 | FullyQualifiedName.append(TypeName); |
| 185 | return FullyQualifiedName; |
| 186 | } |
| 187 | |
| 188 | static std::string getFullyQualifiedName(const DIScope *Scope, StringRef Name) { |
| 189 | SmallVector<StringRef, 5> QualifiedNameComponents; |
| 190 | getQualifiedNameComponents(Scope, QualifiedNameComponents); |
| 191 | return getQualifiedName(QualifiedNameComponents, Name); |
| 192 | } |
| 193 | |
Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 194 | struct CodeViewDebug::TypeLoweringScope { |
| 195 | TypeLoweringScope(CodeViewDebug &CVD) : CVD(CVD) { ++CVD.TypeEmissionLevel; } |
| 196 | ~TypeLoweringScope() { |
| 197 | // Don't decrement TypeEmissionLevel until after emitting deferred types, so |
| 198 | // inner TypeLoweringScopes don't attempt to emit deferred types. |
| 199 | if (CVD.TypeEmissionLevel == 1) |
| 200 | CVD.emitDeferredCompleteTypes(); |
| 201 | --CVD.TypeEmissionLevel; |
| 202 | } |
| 203 | CodeViewDebug &CVD; |
| 204 | }; |
| 205 | |
David Majnemer | 6bdc24e | 2016-07-01 23:12:45 +0000 | [diff] [blame] | 206 | static std::string getFullyQualifiedName(const DIScope *Ty) { |
| 207 | const DIScope *Scope = Ty->getScope().resolve(); |
| 208 | return getFullyQualifiedName(Scope, getPrettyScopeName(Ty)); |
| 209 | } |
| 210 | |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 211 | TypeIndex CodeViewDebug::getScopeIndex(const DIScope *Scope) { |
| 212 | // No scope means global scope and that uses the zero index. |
| 213 | if (!Scope || isa<DIFile>(Scope)) |
| 214 | return TypeIndex(); |
| 215 | |
| 216 | assert(!isa<DIType>(Scope) && "shouldn't make a namespace scope for a type"); |
| 217 | |
| 218 | // Check if we've already translated this scope. |
| 219 | auto I = TypeIndices.find({Scope, nullptr}); |
| 220 | if (I != TypeIndices.end()) |
| 221 | return I->second; |
| 222 | |
| 223 | // Build the fully qualified name of the scope. |
David Majnemer | 6bdc24e | 2016-07-01 23:12:45 +0000 | [diff] [blame] | 224 | std::string ScopeName = getFullyQualifiedName(Scope); |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 225 | TypeIndex TI = |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 226 | TypeTable.writeKnownType(StringIdRecord(TypeIndex(), ScopeName)); |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 227 | return recordTypeIndexForDINode(Scope, TI); |
| 228 | } |
| 229 | |
David Majnemer | 75c3ebf | 2016-06-02 17:13:53 +0000 | [diff] [blame] | 230 | TypeIndex CodeViewDebug::getFuncIdForSubprogram(const DISubprogram *SP) { |
David Majnemer | 67f684e | 2016-07-28 05:03:22 +0000 | [diff] [blame] | 231 | assert(SP); |
Reid Kleckner | 2280f93 | 2016-05-23 20:23:46 +0000 | [diff] [blame] | 232 | |
David Majnemer | 75c3ebf | 2016-06-02 17:13:53 +0000 | [diff] [blame] | 233 | // Check if we've already translated this subprogram. |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 234 | auto I = TypeIndices.find({SP, nullptr}); |
David Majnemer | 75c3ebf | 2016-06-02 17:13:53 +0000 | [diff] [blame] | 235 | if (I != TypeIndices.end()) |
| 236 | return I->second; |
Reid Kleckner | 2280f93 | 2016-05-23 20:23:46 +0000 | [diff] [blame] | 237 | |
Reid Kleckner | ac945e2 | 2016-06-17 16:11:20 +0000 | [diff] [blame] | 238 | // The display name includes function template arguments. Drop them to match |
| 239 | // MSVC. |
| 240 | StringRef DisplayName = SP->getDisplayName().split('<').first; |
David Majnemer | 75c3ebf | 2016-06-02 17:13:53 +0000 | [diff] [blame] | 241 | |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 242 | const DIScope *Scope = SP->getScope().resolve(); |
| 243 | TypeIndex TI; |
| 244 | if (const auto *Class = dyn_cast_or_null<DICompositeType>(Scope)) { |
| 245 | // If the scope is a DICompositeType, then this must be a method. Member |
| 246 | // function types take some special handling, and require access to the |
| 247 | // subprogram. |
| 248 | TypeIndex ClassType = getTypeIndex(Class); |
| 249 | MemberFuncIdRecord MFuncId(ClassType, getMemberFunctionType(SP, Class), |
| 250 | DisplayName); |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 251 | TI = TypeTable.writeKnownType(MFuncId); |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 252 | } else { |
| 253 | // Otherwise, this must be a free function. |
| 254 | TypeIndex ParentScope = getScopeIndex(Scope); |
| 255 | FuncIdRecord FuncId(ParentScope, getTypeIndex(SP->getType()), DisplayName); |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 256 | TI = TypeTable.writeKnownType(FuncId); |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | return recordTypeIndexForDINode(SP, TI); |
Reid Kleckner | 2280f93 | 2016-05-23 20:23:46 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 262 | TypeIndex CodeViewDebug::getMemberFunctionType(const DISubprogram *SP, |
| 263 | const DICompositeType *Class) { |
Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 264 | // Always use the method declaration as the key for the function type. The |
| 265 | // method declaration contains the this adjustment. |
| 266 | if (SP->getDeclaration()) |
| 267 | SP = SP->getDeclaration(); |
| 268 | assert(!SP->getDeclaration() && "should use declaration as key"); |
| 269 | |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 270 | // Key the MemberFunctionRecord into the map as {SP, Class}. It won't collide |
| 271 | // with the MemberFuncIdRecord, which is keyed in as {SP, nullptr}. |
Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 272 | auto I = TypeIndices.find({SP, Class}); |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 273 | if (I != TypeIndices.end()) |
| 274 | return I->second; |
| 275 | |
Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 276 | // Make sure complete type info for the class is emitted *after* the member |
| 277 | // function type, as the complete class type is likely to reference this |
| 278 | // member function type. |
| 279 | TypeLoweringScope S(*this); |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 280 | TypeIndex TI = |
Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 281 | lowerTypeMemberFunction(SP->getType(), Class, SP->getThisAdjustment()); |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 282 | return recordTypeIndexForDINode(SP, TI, Class); |
| 283 | } |
| 284 | |
Amjad Aboud | acee568 | 2016-07-12 12:06:34 +0000 | [diff] [blame] | 285 | TypeIndex CodeViewDebug::recordTypeIndexForDINode(const DINode *Node, |
| 286 | TypeIndex TI, |
| 287 | const DIType *ClassTy) { |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 288 | auto InsertResult = TypeIndices.insert({{Node, ClassTy}, TI}); |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 289 | (void)InsertResult; |
| 290 | assert(InsertResult.second && "DINode was already assigned a type index"); |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 291 | return TI; |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 294 | unsigned CodeViewDebug::getPointerSizeInBytes() { |
| 295 | return MMI->getModule()->getDataLayout().getPointerSizeInBits() / 8; |
| 296 | } |
| 297 | |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 298 | void CodeViewDebug::recordLocalVariable(LocalVariable &&Var, |
| 299 | const DILocation *InlinedAt) { |
| 300 | if (InlinedAt) { |
| 301 | // This variable was inlined. Associate it with the InlineSite. |
| 302 | const DISubprogram *Inlinee = Var.DIVar->getScope()->getSubprogram(); |
| 303 | InlineSite &Site = getInlineSite(InlinedAt, Inlinee); |
| 304 | Site.InlinedLocals.emplace_back(Var); |
| 305 | } else { |
| 306 | // This variable goes in the main ProcSym. |
| 307 | CurFn->Locals.emplace_back(Var); |
| 308 | } |
| 309 | } |
| 310 | |
Reid Kleckner | 829365a | 2016-02-11 19:41:47 +0000 | [diff] [blame] | 311 | static void addLocIfNotPresent(SmallVectorImpl<const DILocation *> &Locs, |
| 312 | const DILocation *Loc) { |
| 313 | auto B = Locs.begin(), E = Locs.end(); |
| 314 | if (std::find(B, E, Loc) == E) |
| 315 | Locs.push_back(Loc); |
| 316 | } |
| 317 | |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 318 | void CodeViewDebug::maybeRecordLocation(const DebugLoc &DL, |
Reid Kleckner | 9533af4 | 2016-01-16 00:09:09 +0000 | [diff] [blame] | 319 | const MachineFunction *MF) { |
| 320 | // Skip this instruction if it has the same location as the previous one. |
| 321 | if (DL == CurFn->LastLoc) |
| 322 | return; |
| 323 | |
| 324 | const DIScope *Scope = DL.get()->getScope(); |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 325 | if (!Scope) |
| 326 | return; |
Reid Kleckner | 9533af4 | 2016-01-16 00:09:09 +0000 | [diff] [blame] | 327 | |
David Majnemer | c3340db | 2016-01-13 01:05:23 +0000 | [diff] [blame] | 328 | // 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] | 329 | LineInfo LI(DL.getLine(), DL.getLine(), /*IsStatement=*/true); |
| 330 | if (LI.getStartLine() != DL.getLine() || LI.isAlwaysStepInto() || |
| 331 | LI.isNeverStepInto()) |
David Majnemer | c3340db | 2016-01-13 01:05:23 +0000 | [diff] [blame] | 332 | return; |
| 333 | |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 334 | ColumnInfo CI(DL.getCol(), /*EndColumn=*/0); |
| 335 | if (CI.getStartColumn() != DL.getCol()) |
| 336 | return; |
Reid Kleckner | 00d9639 | 2016-01-29 00:13:28 +0000 | [diff] [blame] | 337 | |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 338 | if (!CurFn->HaveLineInfo) |
| 339 | CurFn->HaveLineInfo = true; |
| 340 | unsigned FileId = 0; |
| 341 | if (CurFn->LastLoc.get() && CurFn->LastLoc->getFile() == DL->getFile()) |
| 342 | FileId = CurFn->LastFileId; |
| 343 | else |
| 344 | FileId = CurFn->LastFileId = maybeRecordFile(DL->getFile()); |
| 345 | CurFn->LastLoc = DL; |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 346 | |
| 347 | unsigned FuncId = CurFn->FuncId; |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 348 | if (const DILocation *SiteLoc = DL->getInlinedAt()) { |
Reid Kleckner | 829365a | 2016-02-11 19:41:47 +0000 | [diff] [blame] | 349 | const DILocation *Loc = DL.get(); |
| 350 | |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 351 | // If this location was actually inlined from somewhere else, give it the ID |
| 352 | // of the inline call site. |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 353 | FuncId = |
| 354 | getInlineSite(SiteLoc, Loc->getScope()->getSubprogram()).SiteFuncId; |
Reid Kleckner | 829365a | 2016-02-11 19:41:47 +0000 | [diff] [blame] | 355 | |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 356 | // Ensure we have links in the tree of inline call sites. |
Reid Kleckner | 829365a | 2016-02-11 19:41:47 +0000 | [diff] [blame] | 357 | bool FirstLoc = true; |
| 358 | while ((SiteLoc = Loc->getInlinedAt())) { |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 359 | InlineSite &Site = |
| 360 | getInlineSite(SiteLoc, Loc->getScope()->getSubprogram()); |
Reid Kleckner | 829365a | 2016-02-11 19:41:47 +0000 | [diff] [blame] | 361 | if (!FirstLoc) |
| 362 | addLocIfNotPresent(Site.ChildSites, Loc); |
| 363 | FirstLoc = false; |
| 364 | Loc = SiteLoc; |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 365 | } |
Reid Kleckner | 829365a | 2016-02-11 19:41:47 +0000 | [diff] [blame] | 366 | addLocIfNotPresent(CurFn->ChildSites, Loc); |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 369 | OS.EmitCVLocDirective(FuncId, FileId, DL.getLine(), DL.getCol(), |
Reid Kleckner | a9f4cc9 | 2016-09-07 16:15:31 +0000 | [diff] [blame] | 370 | /*PrologueEnd=*/false, /*IsStmt=*/false, |
| 371 | DL->getFilename(), SMLoc()); |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 372 | } |
| 373 | |
Reid Kleckner | 5d122f8 | 2016-05-25 23:16:12 +0000 | [diff] [blame] | 374 | void CodeViewDebug::emitCodeViewMagicVersion() { |
| 375 | OS.EmitValueToAlignment(4); |
| 376 | OS.AddComment("Debug section magic"); |
| 377 | OS.EmitIntValue(COFF::DEBUG_SECTION_MAGIC, 4); |
| 378 | } |
| 379 | |
Reid Kleckner | 70f5bc9 | 2016-01-14 19:25:04 +0000 | [diff] [blame] | 380 | void CodeViewDebug::endModule() { |
Reid Kleckner | 6f3406d | 2016-06-07 00:02:03 +0000 | [diff] [blame] | 381 | if (!Asm || !MMI->hasDebugInfo()) |
Timur Iskhodzhanov | 2cf8a1d | 2014-10-10 16:05:32 +0000 | [diff] [blame] | 382 | return; |
| 383 | |
| 384 | assert(Asm != nullptr); |
Timur Iskhodzhanov | 2cf8a1d | 2014-10-10 16:05:32 +0000 | [diff] [blame] | 385 | |
| 386 | // The COFF .debug$S section consists of several subsections, each starting |
| 387 | // with a 4-byte control code (e.g. 0xF1, 0xF2, etc) and then a 4-byte length |
| 388 | // of the payload followed by the payload itself. The subsections are 4-byte |
| 389 | // aligned. |
| 390 | |
Reid Kleckner | 6f3406d | 2016-06-07 00:02:03 +0000 | [diff] [blame] | 391 | // Use the generic .debug$S section, and make a subsection for all the inlined |
| 392 | // subprograms. |
| 393 | switchToDebugSectionForSymbol(nullptr); |
Reid Kleckner | 5d122f8 | 2016-05-25 23:16:12 +0000 | [diff] [blame] | 394 | emitInlineeLinesSubsection(); |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 395 | |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 396 | // Emit per-function debug information. |
| 397 | for (auto &P : FnDebugInfo) |
David Majnemer | 577be0f | 2016-06-15 00:19:52 +0000 | [diff] [blame] | 398 | if (!P.first->isDeclarationForLinker()) |
| 399 | emitDebugInfoForFunction(P.first, P.second); |
Timur Iskhodzhanov | 2cf8a1d | 2014-10-10 16:05:32 +0000 | [diff] [blame] | 400 | |
Reid Kleckner | 6f3406d | 2016-06-07 00:02:03 +0000 | [diff] [blame] | 401 | // Emit global variable debug information. |
David Majnemer | 3128b10 | 2016-06-15 18:00:01 +0000 | [diff] [blame] | 402 | setCurrentSubprogram(nullptr); |
Reid Kleckner | 6f3406d | 2016-06-07 00:02:03 +0000 | [diff] [blame] | 403 | emitDebugInfoForGlobals(); |
| 404 | |
Hans Wennborg | b510b45 | 2016-06-23 16:33:53 +0000 | [diff] [blame] | 405 | // Emit retained types. |
| 406 | emitDebugInfoForRetainedTypes(); |
| 407 | |
Reid Kleckner | 5d122f8 | 2016-05-25 23:16:12 +0000 | [diff] [blame] | 408 | // Switch back to the generic .debug$S section after potentially processing |
| 409 | // comdat symbol sections. |
| 410 | switchToDebugSectionForSymbol(nullptr); |
| 411 | |
David Majnemer | 3128b10 | 2016-06-15 18:00:01 +0000 | [diff] [blame] | 412 | // Emit UDT records for any types used by global variables. |
| 413 | if (!GlobalUDTs.empty()) { |
| 414 | MCSymbol *SymbolsEnd = beginCVSubsection(ModuleSubstreamKind::Symbols); |
| 415 | emitDebugInfoForUDTs(GlobalUDTs); |
| 416 | endCVSubsection(SymbolsEnd); |
| 417 | } |
| 418 | |
Timur Iskhodzhanov | 2cf8a1d | 2014-10-10 16:05:32 +0000 | [diff] [blame] | 419 | // This subsection holds a file index to offset in string table table. |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 420 | OS.AddComment("File index to string table offset subsection"); |
| 421 | OS.EmitCVFileChecksumsDirective(); |
Timur Iskhodzhanov | 2cf8a1d | 2014-10-10 16:05:32 +0000 | [diff] [blame] | 422 | |
| 423 | // This subsection holds the string table. |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 424 | OS.AddComment("String table"); |
| 425 | OS.EmitCVStringTableDirective(); |
Timur Iskhodzhanov | 2cf8a1d | 2014-10-10 16:05:32 +0000 | [diff] [blame] | 426 | |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 427 | // Emit type information last, so that any types we translate while emitting |
| 428 | // function info are included. |
| 429 | emitTypeInformation(); |
| 430 | |
Timur Iskhodzhanov | 2cf8a1d | 2014-10-10 16:05:32 +0000 | [diff] [blame] | 431 | clear(); |
| 432 | } |
| 433 | |
David Majnemer | b9456a5 | 2016-03-14 05:15:09 +0000 | [diff] [blame] | 434 | static void emitNullTerminatedSymbolName(MCStreamer &OS, StringRef S) { |
Reid Kleckner | bb96df6 | 2016-10-05 22:36:07 +0000 | [diff] [blame] | 435 | // The maximum CV record length is 0xFF00. Most of the strings we emit appear |
| 436 | // after a fixed length portion of the record. The fixed length portion should |
| 437 | // always be less than 0xF00 (3840) bytes, so truncate the string so that the |
| 438 | // overall record size is less than the maximum allowed. |
| 439 | unsigned MaxFixedRecordLength = 0xF00; |
| 440 | SmallString<32> NullTerminatedString( |
| 441 | S.take_front(MaxRecordLength - MaxFixedRecordLength - 1)); |
David Majnemer | b9456a5 | 2016-03-14 05:15:09 +0000 | [diff] [blame] | 442 | NullTerminatedString.push_back('\0'); |
| 443 | OS.EmitBytes(NullTerminatedString); |
| 444 | } |
| 445 | |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 446 | void CodeViewDebug::emitTypeInformation() { |
Reid Kleckner | 2280f93 | 2016-05-23 20:23:46 +0000 | [diff] [blame] | 447 | // Do nothing if we have no debug info or if no non-trivial types were emitted |
| 448 | // to TypeTable during codegen. |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 449 | NamedMDNode *CU_Nodes = MMI->getModule()->getNamedMetadata("llvm.dbg.cu"); |
Reid Kleckner | fbd7787 | 2016-03-18 18:54:32 +0000 | [diff] [blame] | 450 | if (!CU_Nodes) |
| 451 | return; |
Reid Kleckner | 2280f93 | 2016-05-23 20:23:46 +0000 | [diff] [blame] | 452 | if (TypeTable.empty()) |
Reid Kleckner | fbd7787 | 2016-03-18 18:54:32 +0000 | [diff] [blame] | 453 | return; |
| 454 | |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 455 | // Start the .debug$T section with 0x4. |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 456 | OS.SwitchSection(Asm->getObjFileLowering().getCOFFDebugTypesSection()); |
Reid Kleckner | 5d122f8 | 2016-05-25 23:16:12 +0000 | [diff] [blame] | 457 | emitCodeViewMagicVersion(); |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 458 | |
Reid Kleckner | fbdbe9e | 2016-05-31 18:45:36 +0000 | [diff] [blame] | 459 | SmallString<8> CommentPrefix; |
| 460 | if (OS.isVerboseAsm()) { |
| 461 | CommentPrefix += '\t'; |
| 462 | CommentPrefix += Asm->MAI->getCommentString(); |
| 463 | CommentPrefix += ' '; |
| 464 | } |
| 465 | |
| 466 | CVTypeDumper CVTD(nullptr, /*PrintRecordBytes=*/false); |
Reid Kleckner | 2280f93 | 2016-05-23 20:23:46 +0000 | [diff] [blame] | 467 | TypeTable.ForEachRecord( |
Reid Kleckner | fbdbe9e | 2016-05-31 18:45:36 +0000 | [diff] [blame] | 468 | [&](TypeIndex Index, StringRef Record) { |
| 469 | if (OS.isVerboseAsm()) { |
| 470 | // Emit a block comment describing the type record for readability. |
| 471 | SmallString<512> CommentBlock; |
| 472 | raw_svector_ostream CommentOS(CommentBlock); |
| 473 | ScopedPrinter SP(CommentOS); |
| 474 | SP.setPrefix(CommentPrefix); |
| 475 | CVTD.setPrinter(&SP); |
Reid Kleckner | c92e946 | 2016-07-01 18:05:56 +0000 | [diff] [blame] | 476 | Error E = CVTD.dump({Record.bytes_begin(), Record.bytes_end()}); |
| 477 | if (E) { |
| 478 | logAllUnhandledErrors(std::move(E), errs(), "error: "); |
| 479 | llvm_unreachable("produced malformed type record"); |
| 480 | } |
Reid Kleckner | fbdbe9e | 2016-05-31 18:45:36 +0000 | [diff] [blame] | 481 | // emitRawComment will insert its own tab and comment string before |
| 482 | // the first line, so strip off our first one. It also prints its own |
| 483 | // newline. |
| 484 | OS.emitRawComment( |
| 485 | CommentOS.str().drop_front(CommentPrefix.size() - 1).rtrim()); |
Reid Kleckner | c92e946 | 2016-07-01 18:05:56 +0000 | [diff] [blame] | 486 | } else { |
| 487 | #ifndef NDEBUG |
| 488 | // Assert that the type data is valid even if we aren't dumping |
| 489 | // comments. The MSVC linker doesn't do much type record validation, |
| 490 | // so the first link of an invalid type record can succeed while |
| 491 | // subsequent links will fail with LNK1285. |
Zachary Turner | d66889c | 2016-07-28 19:12:28 +0000 | [diff] [blame] | 492 | ByteStream Stream({Record.bytes_begin(), Record.bytes_end()}); |
Reid Kleckner | c92e946 | 2016-07-01 18:05:56 +0000 | [diff] [blame] | 493 | CVTypeArray Types; |
| 494 | StreamReader Reader(Stream); |
| 495 | Error E = Reader.readArray(Types, Reader.getLength()); |
| 496 | if (!E) { |
| 497 | TypeVisitorCallbacks C; |
| 498 | E = CVTypeVisitor(C).visitTypeStream(Types); |
| 499 | } |
| 500 | if (E) { |
| 501 | logAllUnhandledErrors(std::move(E), errs(), "error: "); |
| 502 | llvm_unreachable("produced malformed type record"); |
| 503 | } |
| 504 | #endif |
Reid Kleckner | fbdbe9e | 2016-05-31 18:45:36 +0000 | [diff] [blame] | 505 | } |
| 506 | OS.EmitBinaryData(Record); |
Reid Kleckner | 2280f93 | 2016-05-23 20:23:46 +0000 | [diff] [blame] | 507 | }); |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Adrian McCarthy | c64acfd | 2016-09-20 17:20:51 +0000 | [diff] [blame] | 510 | namespace { |
| 511 | |
| 512 | static SourceLanguage MapDWLangToCVLang(unsigned DWLang) { |
| 513 | switch (DWLang) { |
| 514 | case dwarf::DW_LANG_C: |
| 515 | case dwarf::DW_LANG_C89: |
| 516 | case dwarf::DW_LANG_C99: |
| 517 | case dwarf::DW_LANG_C11: |
| 518 | case dwarf::DW_LANG_ObjC: |
| 519 | return SourceLanguage::C; |
| 520 | case dwarf::DW_LANG_C_plus_plus: |
| 521 | case dwarf::DW_LANG_C_plus_plus_03: |
| 522 | case dwarf::DW_LANG_C_plus_plus_11: |
| 523 | case dwarf::DW_LANG_C_plus_plus_14: |
| 524 | return SourceLanguage::Cpp; |
| 525 | case dwarf::DW_LANG_Fortran77: |
| 526 | case dwarf::DW_LANG_Fortran90: |
| 527 | case dwarf::DW_LANG_Fortran03: |
| 528 | case dwarf::DW_LANG_Fortran08: |
| 529 | return SourceLanguage::Fortran; |
| 530 | case dwarf::DW_LANG_Pascal83: |
| 531 | return SourceLanguage::Pascal; |
| 532 | case dwarf::DW_LANG_Cobol74: |
| 533 | case dwarf::DW_LANG_Cobol85: |
| 534 | return SourceLanguage::Cobol; |
| 535 | case dwarf::DW_LANG_Java: |
| 536 | return SourceLanguage::Java; |
| 537 | default: |
| 538 | // There's no CodeView representation for this language, and CV doesn't |
| 539 | // have an "unknown" option for the language field, so we'll use MASM, |
| 540 | // as it's very low level. |
| 541 | return SourceLanguage::Masm; |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | struct Version { |
| 546 | int Part[4]; |
| 547 | }; |
| 548 | |
| 549 | // Takes a StringRef like "clang 4.0.0.0 (other nonsense 123)" and parses out |
| 550 | // the version number. |
| 551 | static Version parseVersion(StringRef Name) { |
Adrian McCarthy | ad8ac54 | 2016-09-20 17:42:13 +0000 | [diff] [blame] | 552 | Version V = {{0}}; |
Adrian McCarthy | c64acfd | 2016-09-20 17:20:51 +0000 | [diff] [blame] | 553 | int N = 0; |
| 554 | for (const char C : Name) { |
| 555 | if (isdigit(C)) { |
| 556 | V.Part[N] *= 10; |
| 557 | V.Part[N] += C - '0'; |
| 558 | } else if (C == '.') { |
| 559 | ++N; |
| 560 | if (N >= 4) |
| 561 | return V; |
| 562 | } else if (N > 0) |
| 563 | return V; |
| 564 | } |
| 565 | return V; |
| 566 | } |
| 567 | |
| 568 | static CPUType mapArchToCVCPUType(Triple::ArchType Type) { |
| 569 | switch (Type) { |
| 570 | case Triple::ArchType::x86: |
| 571 | return CPUType::Pentium3; |
| 572 | case Triple::ArchType::x86_64: |
| 573 | return CPUType::X64; |
| 574 | case Triple::ArchType::thumb: |
| 575 | return CPUType::Thumb; |
| 576 | default: |
| 577 | report_fatal_error("target architecture doesn't map to a CodeView " |
| 578 | "CPUType"); |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | } // anonymous namespace |
| 583 | |
| 584 | void CodeViewDebug::emitCompilerInformation() { |
| 585 | MCContext &Context = MMI->getContext(); |
| 586 | MCSymbol *CompilerBegin = Context.createTempSymbol(), |
| 587 | *CompilerEnd = Context.createTempSymbol(); |
| 588 | OS.AddComment("Record length"); |
| 589 | OS.emitAbsoluteSymbolDiff(CompilerEnd, CompilerBegin, 2); |
| 590 | OS.EmitLabel(CompilerBegin); |
| 591 | OS.AddComment("Record kind: S_COMPILE3"); |
| 592 | OS.EmitIntValue(SymbolKind::S_COMPILE3, 2); |
| 593 | uint32_t Flags = 0; |
| 594 | |
| 595 | NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("llvm.dbg.cu"); |
| 596 | const MDNode *Node = *CUs->operands().begin(); |
| 597 | const auto *CU = cast<DICompileUnit>(Node); |
| 598 | |
| 599 | // The low byte of the flags indicates the source language. |
| 600 | Flags = MapDWLangToCVLang(CU->getSourceLanguage()); |
| 601 | // TODO: Figure out which other flags need to be set. |
| 602 | |
| 603 | OS.AddComment("Flags and language"); |
| 604 | OS.EmitIntValue(Flags, 4); |
| 605 | |
| 606 | OS.AddComment("CPUType"); |
| 607 | CPUType CPU = |
| 608 | mapArchToCVCPUType(Triple(MMI->getModule()->getTargetTriple()).getArch()); |
| 609 | OS.EmitIntValue(static_cast<uint64_t>(CPU), 2); |
| 610 | |
| 611 | StringRef CompilerVersion = CU->getProducer(); |
| 612 | Version FrontVer = parseVersion(CompilerVersion); |
| 613 | OS.AddComment("Frontend version"); |
| 614 | for (int N = 0; N < 4; ++N) |
| 615 | OS.EmitIntValue(FrontVer.Part[N], 2); |
| 616 | |
| 617 | // Some Microsoft tools, like Binscope, expect a backend version number of at |
| 618 | // least 8.something, so we'll coerce the LLVM version into a form that |
| 619 | // guarantees it'll be big enough without really lying about the version. |
Adrian McCarthy | d1185fc | 2016-09-29 20:28:25 +0000 | [diff] [blame] | 620 | int Major = 1000 * LLVM_VERSION_MAJOR + |
| 621 | 10 * LLVM_VERSION_MINOR + |
| 622 | LLVM_VERSION_PATCH; |
| 623 | // Clamp it for builds that use unusually large version numbers. |
| 624 | Major = std::min<int>(Major, std::numeric_limits<uint16_t>::max()); |
| 625 | Version BackVer = {{ Major, 0, 0, 0 }}; |
Adrian McCarthy | c64acfd | 2016-09-20 17:20:51 +0000 | [diff] [blame] | 626 | OS.AddComment("Backend version"); |
| 627 | for (int N = 0; N < 4; ++N) |
| 628 | OS.EmitIntValue(BackVer.Part[N], 2); |
| 629 | |
| 630 | OS.AddComment("Null-terminated compiler version string"); |
| 631 | emitNullTerminatedSymbolName(OS, CompilerVersion); |
| 632 | |
| 633 | OS.EmitLabel(CompilerEnd); |
| 634 | } |
| 635 | |
Reid Kleckner | 5d122f8 | 2016-05-25 23:16:12 +0000 | [diff] [blame] | 636 | void CodeViewDebug::emitInlineeLinesSubsection() { |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 637 | if (InlinedSubprograms.empty()) |
| 638 | return; |
| 639 | |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 640 | OS.AddComment("Inlinee lines subsection"); |
Reid Kleckner | 6f3406d | 2016-06-07 00:02:03 +0000 | [diff] [blame] | 641 | MCSymbol *InlineEnd = beginCVSubsection(ModuleSubstreamKind::InlineeLines); |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 642 | |
| 643 | // We don't provide any extra file info. |
| 644 | // FIXME: Find out if debuggers use this info. |
David Majnemer | 30579ec | 2016-02-02 23:18:23 +0000 | [diff] [blame] | 645 | OS.AddComment("Inlinee lines signature"); |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 646 | OS.EmitIntValue(unsigned(InlineeLinesSignature::Normal), 4); |
| 647 | |
| 648 | for (const DISubprogram *SP : InlinedSubprograms) { |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 649 | assert(TypeIndices.count({SP, nullptr})); |
| 650 | TypeIndex InlineeIdx = TypeIndices[{SP, nullptr}]; |
Reid Kleckner | 2280f93 | 2016-05-23 20:23:46 +0000 | [diff] [blame] | 651 | |
David Majnemer | 30579ec | 2016-02-02 23:18:23 +0000 | [diff] [blame] | 652 | OS.AddBlankLine(); |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 653 | unsigned FileId = maybeRecordFile(SP->getFile()); |
| 654 | OS.AddComment("Inlined function " + SP->getDisplayName() + " starts at " + |
| 655 | SP->getFilename() + Twine(':') + Twine(SP->getLine())); |
David Majnemer | 30579ec | 2016-02-02 23:18:23 +0000 | [diff] [blame] | 656 | OS.AddBlankLine(); |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 657 | // The filechecksum table uses 8 byte entries for now, and file ids start at |
| 658 | // 1. |
| 659 | unsigned FileOffset = (FileId - 1) * 8; |
David Majnemer | 30579ec | 2016-02-02 23:18:23 +0000 | [diff] [blame] | 660 | OS.AddComment("Type index of inlined function"); |
Reid Kleckner | 2280f93 | 2016-05-23 20:23:46 +0000 | [diff] [blame] | 661 | OS.EmitIntValue(InlineeIdx.getIndex(), 4); |
David Majnemer | 30579ec | 2016-02-02 23:18:23 +0000 | [diff] [blame] | 662 | OS.AddComment("Offset into filechecksum table"); |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 663 | OS.EmitIntValue(FileOffset, 4); |
David Majnemer | 30579ec | 2016-02-02 23:18:23 +0000 | [diff] [blame] | 664 | OS.AddComment("Starting line number"); |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 665 | OS.EmitIntValue(SP->getLine(), 4); |
| 666 | } |
| 667 | |
Reid Kleckner | 6f3406d | 2016-06-07 00:02:03 +0000 | [diff] [blame] | 668 | endCVSubsection(InlineEnd); |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 669 | } |
| 670 | |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 671 | void CodeViewDebug::emitInlinedCallSite(const FunctionInfo &FI, |
| 672 | const DILocation *InlinedAt, |
| 673 | const InlineSite &Site) { |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 674 | MCSymbol *InlineBegin = MMI->getContext().createTempSymbol(), |
| 675 | *InlineEnd = MMI->getContext().createTempSymbol(); |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 676 | |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 677 | assert(TypeIndices.count({Site.Inlinee, nullptr})); |
| 678 | TypeIndex InlineeIdx = TypeIndices[{Site.Inlinee, nullptr}]; |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 679 | |
| 680 | // SymbolRecord |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 681 | OS.AddComment("Record length"); |
Reid Kleckner | eb3bcdd | 2016-02-03 21:24:42 +0000 | [diff] [blame] | 682 | OS.emitAbsoluteSymbolDiff(InlineEnd, InlineBegin, 2); // RecordLength |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 683 | OS.EmitLabel(InlineBegin); |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 684 | OS.AddComment("Record kind: S_INLINESITE"); |
Zachary Turner | 63a2846 | 2016-05-17 23:50:21 +0000 | [diff] [blame] | 685 | OS.EmitIntValue(SymbolKind::S_INLINESITE, 2); // RecordKind |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 686 | |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 687 | OS.AddComment("PtrParent"); |
| 688 | OS.EmitIntValue(0, 4); |
| 689 | OS.AddComment("PtrEnd"); |
| 690 | OS.EmitIntValue(0, 4); |
| 691 | OS.AddComment("Inlinee type index"); |
Reid Kleckner | 2280f93 | 2016-05-23 20:23:46 +0000 | [diff] [blame] | 692 | OS.EmitIntValue(InlineeIdx.getIndex(), 4); |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 693 | |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 694 | unsigned FileId = maybeRecordFile(Site.Inlinee->getFile()); |
| 695 | unsigned StartLineNum = Site.Inlinee->getLine(); |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 696 | |
| 697 | OS.EmitCVInlineLinetableDirective(Site.SiteFuncId, FileId, StartLineNum, |
Reid Kleckner | a9f4cc9 | 2016-09-07 16:15:31 +0000 | [diff] [blame] | 698 | FI.Begin, FI.End); |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 699 | |
| 700 | OS.EmitLabel(InlineEnd); |
| 701 | |
Reid Kleckner | 10dd55c | 2016-06-24 17:55:40 +0000 | [diff] [blame] | 702 | emitLocalVariableList(Site.InlinedLocals); |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 703 | |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 704 | // Recurse on child inlined call sites before closing the scope. |
| 705 | for (const DILocation *ChildSite : Site.ChildSites) { |
| 706 | auto I = FI.InlineSites.find(ChildSite); |
| 707 | assert(I != FI.InlineSites.end() && |
| 708 | "child site not in function inline site map"); |
| 709 | emitInlinedCallSite(FI, ChildSite, I->second); |
| 710 | } |
| 711 | |
| 712 | // Close the scope. |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 713 | OS.AddComment("Record length"); |
| 714 | OS.EmitIntValue(2, 2); // RecordLength |
| 715 | OS.AddComment("Record kind: S_INLINESITE_END"); |
Zachary Turner | 63a2846 | 2016-05-17 23:50:21 +0000 | [diff] [blame] | 716 | OS.EmitIntValue(SymbolKind::S_INLINESITE_END, 2); // RecordKind |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 717 | } |
| 718 | |
Reid Kleckner | 5d122f8 | 2016-05-25 23:16:12 +0000 | [diff] [blame] | 719 | void CodeViewDebug::switchToDebugSectionForSymbol(const MCSymbol *GVSym) { |
| 720 | // If we have a symbol, it may be in a section that is COMDAT. If so, find the |
| 721 | // comdat key. A section may be comdat because of -ffunction-sections or |
| 722 | // because it is comdat in the IR. |
| 723 | MCSectionCOFF *GVSec = |
| 724 | GVSym ? dyn_cast<MCSectionCOFF>(&GVSym->getSection()) : nullptr; |
| 725 | const MCSymbol *KeySym = GVSec ? GVSec->getCOMDATSymbol() : nullptr; |
| 726 | |
| 727 | MCSectionCOFF *DebugSec = cast<MCSectionCOFF>( |
| 728 | Asm->getObjFileLowering().getCOFFDebugSymbolsSection()); |
| 729 | DebugSec = OS.getContext().getAssociativeCOFFSection(DebugSec, KeySym); |
| 730 | |
| 731 | OS.SwitchSection(DebugSec); |
| 732 | |
| 733 | // Emit the magic version number if this is the first time we've switched to |
| 734 | // this section. |
| 735 | if (ComdatDebugSections.insert(DebugSec).second) |
| 736 | emitCodeViewMagicVersion(); |
| 737 | } |
| 738 | |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 739 | void CodeViewDebug::emitDebugInfoForFunction(const Function *GV, |
| 740 | FunctionInfo &FI) { |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 741 | // For each function there is a separate subsection |
| 742 | // which holds the PC to file:line table. |
| 743 | const MCSymbol *Fn = Asm->getSymbol(GV); |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 744 | assert(Fn); |
Timur Iskhodzhanov | 8499a12 | 2014-03-26 09:50:36 +0000 | [diff] [blame] | 745 | |
Reid Kleckner | 5d122f8 | 2016-05-25 23:16:12 +0000 | [diff] [blame] | 746 | // Switch to the to a comdat section, if appropriate. |
| 747 | switchToDebugSectionForSymbol(Fn); |
| 748 | |
Reid Kleckner | ac945e2 | 2016-06-17 16:11:20 +0000 | [diff] [blame] | 749 | std::string FuncName; |
David Majnemer | 3128b10 | 2016-06-15 18:00:01 +0000 | [diff] [blame] | 750 | auto *SP = GV->getSubprogram(); |
David Majnemer | 67f684e | 2016-07-28 05:03:22 +0000 | [diff] [blame] | 751 | assert(SP); |
David Majnemer | 3128b10 | 2016-06-15 18:00:01 +0000 | [diff] [blame] | 752 | setCurrentSubprogram(SP); |
Reid Kleckner | ac945e2 | 2016-06-17 16:11:20 +0000 | [diff] [blame] | 753 | |
| 754 | // If we have a display name, build the fully qualified name by walking the |
| 755 | // chain of scopes. |
David Majnemer | 67f684e | 2016-07-28 05:03:22 +0000 | [diff] [blame] | 756 | if (!SP->getDisplayName().empty()) |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 757 | FuncName = |
| 758 | getFullyQualifiedName(SP->getScope().resolve(), SP->getDisplayName()); |
Duncan P. N. Exon Smith | 23e56ec | 2015-03-20 19:50:00 +0000 | [diff] [blame] | 759 | |
Reid Kleckner | 3c0ff98 | 2016-01-14 00:12:54 +0000 | [diff] [blame] | 760 | // If our DISubprogram name is empty, use the mangled name. |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 761 | if (FuncName.empty()) |
| 762 | FuncName = GlobalValue::getRealLinkageName(GV->getName()); |
Reid Kleckner | 3c0ff98 | 2016-01-14 00:12:54 +0000 | [diff] [blame] | 763 | |
Timur Iskhodzhanov | 2bc90fd | 2014-10-24 01:27:45 +0000 | [diff] [blame] | 764 | // Emit a symbol subsection, required by VS2012+ to find function boundaries. |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 765 | OS.AddComment("Symbol subsection for " + Twine(FuncName)); |
Reid Kleckner | 6f3406d | 2016-06-07 00:02:03 +0000 | [diff] [blame] | 766 | MCSymbol *SymbolsEnd = beginCVSubsection(ModuleSubstreamKind::Symbols); |
Timur Iskhodzhanov | 2bc90fd | 2014-10-24 01:27:45 +0000 | [diff] [blame] | 767 | { |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 768 | MCSymbol *ProcRecordBegin = MMI->getContext().createTempSymbol(), |
| 769 | *ProcRecordEnd = MMI->getContext().createTempSymbol(); |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 770 | OS.AddComment("Record length"); |
Reid Kleckner | eb3bcdd | 2016-02-03 21:24:42 +0000 | [diff] [blame] | 771 | OS.emitAbsoluteSymbolDiff(ProcRecordEnd, ProcRecordBegin, 2); |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 772 | OS.EmitLabel(ProcRecordBegin); |
Timur Iskhodzhanov | 2bc90fd | 2014-10-24 01:27:45 +0000 | [diff] [blame] | 773 | |
Reid Kleckner | 4ad127f | 2016-09-14 21:49:21 +0000 | [diff] [blame] | 774 | if (GV->hasLocalLinkage()) { |
| 775 | OS.AddComment("Record kind: S_LPROC32_ID"); |
| 776 | OS.EmitIntValue(unsigned(SymbolKind::S_LPROC32_ID), 2); |
| 777 | } else { |
| 778 | OS.AddComment("Record kind: S_GPROC32_ID"); |
| 779 | OS.EmitIntValue(unsigned(SymbolKind::S_GPROC32_ID), 2); |
| 780 | } |
Reid Kleckner | 6b3faef | 2016-01-13 23:44:57 +0000 | [diff] [blame] | 781 | |
David Majnemer | 30579ec | 2016-02-02 23:18:23 +0000 | [diff] [blame] | 782 | // 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] | 783 | OS.AddComment("PtrParent"); |
| 784 | OS.EmitIntValue(0, 4); |
| 785 | OS.AddComment("PtrEnd"); |
| 786 | OS.EmitIntValue(0, 4); |
| 787 | OS.AddComment("PtrNext"); |
| 788 | OS.EmitIntValue(0, 4); |
Timur Iskhodzhanov | 2bc90fd | 2014-10-24 01:27:45 +0000 | [diff] [blame] | 789 | // This is the important bit that tells the debugger where the function |
| 790 | // code is located and what's its size: |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 791 | OS.AddComment("Code size"); |
Reid Kleckner | eb3bcdd | 2016-02-03 21:24:42 +0000 | [diff] [blame] | 792 | OS.emitAbsoluteSymbolDiff(FI.End, Fn, 4); |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 793 | OS.AddComment("Offset after prologue"); |
| 794 | OS.EmitIntValue(0, 4); |
| 795 | OS.AddComment("Offset before epilogue"); |
| 796 | OS.EmitIntValue(0, 4); |
| 797 | OS.AddComment("Function type index"); |
David Majnemer | 75c3ebf | 2016-06-02 17:13:53 +0000 | [diff] [blame] | 798 | OS.EmitIntValue(getFuncIdForSubprogram(GV->getSubprogram()).getIndex(), 4); |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 799 | OS.AddComment("Function section relative address"); |
| 800 | OS.EmitCOFFSecRel32(Fn); |
| 801 | OS.AddComment("Function section index"); |
| 802 | OS.EmitCOFFSectionIndex(Fn); |
| 803 | OS.AddComment("Flags"); |
| 804 | OS.EmitIntValue(0, 1); |
Timur Iskhodzhanov | a11b32b | 2014-11-12 20:10:09 +0000 | [diff] [blame] | 805 | // Emit the function display name as a null-terminated string. |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 806 | OS.AddComment("Function name"); |
David Majnemer | 1256125 | 2016-03-13 10:53:30 +0000 | [diff] [blame] | 807 | // Truncate the name so we won't overflow the record length field. |
David Majnemer | b9456a5 | 2016-03-14 05:15:09 +0000 | [diff] [blame] | 808 | emitNullTerminatedSymbolName(OS, FuncName); |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 809 | OS.EmitLabel(ProcRecordEnd); |
Timur Iskhodzhanov | 2bc90fd | 2014-10-24 01:27:45 +0000 | [diff] [blame] | 810 | |
Reid Kleckner | 10dd55c | 2016-06-24 17:55:40 +0000 | [diff] [blame] | 811 | emitLocalVariableList(FI.Locals); |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 812 | |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 813 | // Emit inlined call site information. Only emit functions inlined directly |
| 814 | // into the parent function. We'll emit the other sites recursively as part |
| 815 | // of their parent inline site. |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 816 | for (const DILocation *InlinedAt : FI.ChildSites) { |
| 817 | auto I = FI.InlineSites.find(InlinedAt); |
| 818 | assert(I != FI.InlineSites.end() && |
| 819 | "child site not in function inline site map"); |
| 820 | emitInlinedCallSite(FI, InlinedAt, I->second); |
Reid Kleckner | f3b9ba4 | 2016-01-29 18:16:43 +0000 | [diff] [blame] | 821 | } |
| 822 | |
David Majnemer | 3128b10 | 2016-06-15 18:00:01 +0000 | [diff] [blame] | 823 | if (SP != nullptr) |
| 824 | emitDebugInfoForUDTs(LocalUDTs); |
| 825 | |
Timur Iskhodzhanov | 2bc90fd | 2014-10-24 01:27:45 +0000 | [diff] [blame] | 826 | // We're done with this function. |
Reid Kleckner | dac21b4 | 2016-02-03 21:15:48 +0000 | [diff] [blame] | 827 | OS.AddComment("Record length"); |
| 828 | OS.EmitIntValue(0x0002, 2); |
| 829 | OS.AddComment("Record kind: S_PROC_ID_END"); |
Zachary Turner | 63a2846 | 2016-05-17 23:50:21 +0000 | [diff] [blame] | 830 | OS.EmitIntValue(unsigned(SymbolKind::S_PROC_ID_END), 2); |
Timur Iskhodzhanov | 2bc90fd | 2014-10-24 01:27:45 +0000 | [diff] [blame] | 831 | } |
Reid Kleckner | 6f3406d | 2016-06-07 00:02:03 +0000 | [diff] [blame] | 832 | endCVSubsection(SymbolsEnd); |
Timur Iskhodzhanov | 2bc90fd | 2014-10-24 01:27:45 +0000 | [diff] [blame] | 833 | |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 834 | // 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] | 835 | OS.EmitCVLinetableDirective(FI.FuncId, Fn, FI.End); |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 836 | } |
| 837 | |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 838 | CodeViewDebug::LocalVarDefRange |
| 839 | CodeViewDebug::createDefRangeMem(uint16_t CVRegister, int Offset) { |
| 840 | LocalVarDefRange DR; |
Aaron Ballman | c6a2f21 | 2016-02-16 15:35:51 +0000 | [diff] [blame] | 841 | DR.InMemory = -1; |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 842 | DR.DataOffset = Offset; |
| 843 | assert(DR.DataOffset == Offset && "truncation"); |
Reid Kleckner | 2b3e642 | 2016-10-05 21:21:33 +0000 | [diff] [blame] | 844 | DR.IsSubfield = 0; |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 845 | DR.StructOffset = 0; |
| 846 | DR.CVRegister = CVRegister; |
| 847 | return DR; |
| 848 | } |
| 849 | |
| 850 | CodeViewDebug::LocalVarDefRange |
Reid Kleckner | 2b3e642 | 2016-10-05 21:21:33 +0000 | [diff] [blame] | 851 | CodeViewDebug::createDefRangeGeneral(uint16_t CVRegister, bool InMemory, |
| 852 | int Offset, bool IsSubfield, |
| 853 | uint16_t StructOffset) { |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 854 | LocalVarDefRange DR; |
Reid Kleckner | 2b3e642 | 2016-10-05 21:21:33 +0000 | [diff] [blame] | 855 | DR.InMemory = InMemory; |
| 856 | DR.DataOffset = Offset; |
| 857 | DR.IsSubfield = IsSubfield; |
| 858 | DR.StructOffset = StructOffset; |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 859 | DR.CVRegister = CVRegister; |
| 860 | return DR; |
| 861 | } |
| 862 | |
| 863 | void CodeViewDebug::collectVariableInfoFromMMITable( |
| 864 | DenseSet<InlinedVariable> &Processed) { |
| 865 | const TargetSubtargetInfo &TSI = Asm->MF->getSubtarget(); |
| 866 | const TargetFrameLowering *TFI = TSI.getFrameLowering(); |
| 867 | const TargetRegisterInfo *TRI = TSI.getRegisterInfo(); |
| 868 | |
| 869 | for (const MachineModuleInfo::VariableDbgInfo &VI : |
| 870 | MMI->getVariableDbgInfo()) { |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 871 | if (!VI.Var) |
| 872 | continue; |
| 873 | assert(VI.Var->isValidLocationForIntrinsic(VI.Loc) && |
| 874 | "Expected inlined-at fields to agree"); |
| 875 | |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 876 | Processed.insert(InlinedVariable(VI.Var, VI.Loc->getInlinedAt())); |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 877 | LexicalScope *Scope = LScopes.findLexicalScope(VI.Loc); |
| 878 | |
| 879 | // If variable scope is not found then skip this variable. |
| 880 | if (!Scope) |
| 881 | continue; |
| 882 | |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 883 | // Get the frame register used and the offset. |
| 884 | unsigned FrameReg = 0; |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 885 | int FrameOffset = TFI->getFrameIndexReference(*Asm->MF, VI.Slot, FrameReg); |
| 886 | uint16_t CVReg = TRI->getCodeViewRegNum(FrameReg); |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 887 | |
| 888 | // Calculate the label ranges. |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 889 | LocalVarDefRange DefRange = createDefRangeMem(CVReg, FrameOffset); |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 890 | for (const InsnRange &Range : Scope->getRanges()) { |
| 891 | const MCSymbol *Begin = getLabelBeforeInsn(Range.first); |
| 892 | const MCSymbol *End = getLabelAfterInsn(Range.second); |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 893 | End = End ? End : Asm->getFunctionEnd(); |
| 894 | DefRange.Ranges.emplace_back(Begin, End); |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 895 | } |
| 896 | |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 897 | LocalVariable Var; |
| 898 | Var.DIVar = VI.Var; |
| 899 | Var.DefRanges.emplace_back(std::move(DefRange)); |
| 900 | recordLocalVariable(std::move(Var), VI.Loc->getInlinedAt()); |
| 901 | } |
| 902 | } |
| 903 | |
| 904 | void CodeViewDebug::collectVariableInfo(const DISubprogram *SP) { |
| 905 | DenseSet<InlinedVariable> Processed; |
| 906 | // Grab the variable info that was squirreled away in the MMI side-table. |
| 907 | collectVariableInfoFromMMITable(Processed); |
| 908 | |
| 909 | const TargetRegisterInfo *TRI = Asm->MF->getSubtarget().getRegisterInfo(); |
| 910 | |
| 911 | for (const auto &I : DbgValues) { |
| 912 | InlinedVariable IV = I.first; |
| 913 | if (Processed.count(IV)) |
| 914 | continue; |
| 915 | const DILocalVariable *DIVar = IV.first; |
| 916 | const DILocation *InlinedAt = IV.second; |
| 917 | |
| 918 | // Instruction ranges, specifying where IV is accessible. |
| 919 | const auto &Ranges = I.second; |
| 920 | |
| 921 | LexicalScope *Scope = nullptr; |
| 922 | if (InlinedAt) |
| 923 | Scope = LScopes.findInlinedScope(DIVar->getScope(), InlinedAt); |
| 924 | else |
| 925 | Scope = LScopes.findLexicalScope(DIVar->getScope()); |
| 926 | // If variable scope is not found then skip this variable. |
| 927 | if (!Scope) |
| 928 | continue; |
| 929 | |
| 930 | LocalVariable Var; |
| 931 | Var.DIVar = DIVar; |
| 932 | |
| 933 | // Calculate the definition ranges. |
| 934 | for (auto I = Ranges.begin(), E = Ranges.end(); I != E; ++I) { |
| 935 | const InsnRange &Range = *I; |
| 936 | const MachineInstr *DVInst = Range.first; |
| 937 | assert(DVInst->isDebugValue() && "Invalid History entry"); |
| 938 | const DIExpression *DIExpr = DVInst->getDebugExpression(); |
Reid Kleckner | 2b3e642 | 2016-10-05 21:21:33 +0000 | [diff] [blame] | 939 | bool IsSubfield = false; |
| 940 | unsigned StructOffset = 0; |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 941 | |
Reid Kleckner | 2b3e642 | 2016-10-05 21:21:33 +0000 | [diff] [blame] | 942 | // Handle bitpieces. |
| 943 | if (DIExpr && DIExpr->isBitPiece()) { |
| 944 | IsSubfield = true; |
| 945 | StructOffset = DIExpr->getBitPieceOffset() / 8; |
| 946 | } else if (DIExpr && DIExpr->getNumElements() > 0) { |
| 947 | continue; // Ignore unrecognized exprs. |
| 948 | } |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 949 | |
Reid Kleckner | 9a593ee | 2016-02-16 21:49:26 +0000 | [diff] [blame] | 950 | // Bail if operand 0 is not a valid register. This means the variable is a |
| 951 | // simple constant, or is described by a complex expression. |
| 952 | // FIXME: Find a way to represent constant variables, since they are |
| 953 | // relatively common. |
| 954 | unsigned Reg = |
| 955 | DVInst->getOperand(0).isReg() ? DVInst->getOperand(0).getReg() : 0; |
| 956 | if (Reg == 0) |
Reid Kleckner | 6e0d5f5 | 2016-02-16 21:14:51 +0000 | [diff] [blame] | 957 | continue; |
| 958 | |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 959 | // Handle the two cases we can handle: indirect in memory and in register. |
Reid Kleckner | 2b3e642 | 2016-10-05 21:21:33 +0000 | [diff] [blame] | 960 | unsigned CVReg = TRI->getCodeViewRegNum(Reg); |
| 961 | bool InMemory = DVInst->getOperand(1).isImm(); |
| 962 | int Offset = InMemory ? DVInst->getOperand(1).getImm() : 0; |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 963 | { |
Reid Kleckner | 2b3e642 | 2016-10-05 21:21:33 +0000 | [diff] [blame] | 964 | LocalVarDefRange DR; |
| 965 | DR.CVRegister = CVReg; |
| 966 | DR.InMemory = InMemory; |
| 967 | DR.DataOffset = Offset; |
| 968 | DR.IsSubfield = IsSubfield; |
| 969 | DR.StructOffset = StructOffset; |
| 970 | |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 971 | if (Var.DefRanges.empty() || |
Reid Kleckner | 2b3e642 | 2016-10-05 21:21:33 +0000 | [diff] [blame] | 972 | Var.DefRanges.back().isDifferentLocation(DR)) { |
| 973 | Var.DefRanges.emplace_back(std::move(DR)); |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 974 | } |
| 975 | } |
| 976 | |
| 977 | // Compute the label range. |
| 978 | const MCSymbol *Begin = getLabelBeforeInsn(Range.first); |
| 979 | const MCSymbol *End = getLabelAfterInsn(Range.second); |
| 980 | if (!End) { |
Reid Kleckner | 2b3e642 | 2016-10-05 21:21:33 +0000 | [diff] [blame] | 981 | // This range is valid until the next overlapping bitpiece. In the |
| 982 | // common case, ranges will not be bitpieces, so they will overlap. |
| 983 | auto J = std::next(I); |
| 984 | while (J != E && !piecesOverlap(DIExpr, J->first->getDebugExpression())) |
| 985 | ++J; |
| 986 | if (J != E) |
| 987 | End = getLabelBeforeInsn(J->first); |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 988 | else |
| 989 | End = Asm->getFunctionEnd(); |
| 990 | } |
| 991 | |
| 992 | // If the last range end is our begin, just extend the last range. |
| 993 | // Otherwise make a new range. |
| 994 | SmallVectorImpl<std::pair<const MCSymbol *, const MCSymbol *>> &Ranges = |
| 995 | Var.DefRanges.back().Ranges; |
| 996 | if (!Ranges.empty() && Ranges.back().second == Begin) |
| 997 | Ranges.back().second = End; |
| 998 | else |
| 999 | Ranges.emplace_back(Begin, End); |
| 1000 | |
| 1001 | // FIXME: Do more range combining. |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 1002 | } |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 1003 | |
| 1004 | recordLocalVariable(std::move(Var), InlinedAt); |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 1005 | } |
| 1006 | } |
| 1007 | |
Reid Kleckner | 70f5bc9 | 2016-01-14 19:25:04 +0000 | [diff] [blame] | 1008 | void CodeViewDebug::beginFunction(const MachineFunction *MF) { |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 1009 | assert(!CurFn && "Can't process two functions at once!"); |
| 1010 | |
David Majnemer | 67f684e | 2016-07-28 05:03:22 +0000 | [diff] [blame] | 1011 | if (!Asm || !MMI->hasDebugInfo() || !MF->getFunction()->getSubprogram()) |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 1012 | return; |
| 1013 | |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 1014 | DebugHandlerBase::beginFunction(MF); |
| 1015 | |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 1016 | const Function *GV = MF->getFunction(); |
| 1017 | assert(FnDebugInfo.count(GV) == false); |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 1018 | CurFn = &FnDebugInfo[GV]; |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 1019 | CurFn->FuncId = NextFuncId++; |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 1020 | CurFn->Begin = Asm->getFunctionBegin(); |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 1021 | |
Reid Kleckner | a9f4cc9 | 2016-09-07 16:15:31 +0000 | [diff] [blame] | 1022 | OS.EmitCVFuncIdDirective(CurFn->FuncId); |
| 1023 | |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 1024 | // Find the end of the function prolog. First known non-DBG_VALUE and |
| 1025 | // non-frame setup location marks the beginning of the function body. |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 1026 | // FIXME: is there a simpler a way to do this? Can we just search |
| 1027 | // for the first instruction of the function, not the last of the prolog? |
| 1028 | DebugLoc PrologEndLoc; |
| 1029 | bool EmptyPrologue = true; |
Alexey Samsonov | f74bde6 | 2014-04-30 22:17:38 +0000 | [diff] [blame] | 1030 | for (const auto &MBB : *MF) { |
Alexey Samsonov | f74bde6 | 2014-04-30 22:17:38 +0000 | [diff] [blame] | 1031 | for (const auto &MI : MBB) { |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 1032 | if (!MI.isDebugValue() && !MI.getFlag(MachineInstr::FrameSetup) && |
| 1033 | MI.getDebugLoc()) { |
Alexey Samsonov | f74bde6 | 2014-04-30 22:17:38 +0000 | [diff] [blame] | 1034 | PrologEndLoc = MI.getDebugLoc(); |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 1035 | break; |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 1036 | } else if (!MI.isDebugValue()) { |
| 1037 | EmptyPrologue = false; |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 1038 | } |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 1039 | } |
| 1040 | } |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 1041 | |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 1042 | // 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] | 1043 | if (PrologEndLoc && !EmptyPrologue) { |
| 1044 | DebugLoc FnStartDL = PrologEndLoc.getFnDebugLoc(); |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 1045 | maybeRecordLocation(FnStartDL, MF); |
| 1046 | } |
| 1047 | } |
| 1048 | |
Hans Wennborg | 4b63a98 | 2016-06-23 22:57:25 +0000 | [diff] [blame] | 1049 | void CodeViewDebug::addToUDTs(const DIType *Ty, TypeIndex TI) { |
Reid Kleckner | ad56ea3 | 2016-07-01 22:24:51 +0000 | [diff] [blame] | 1050 | // Don't record empty UDTs. |
| 1051 | if (Ty->getName().empty()) |
| 1052 | return; |
| 1053 | |
Hans Wennborg | 4b63a98 | 2016-06-23 22:57:25 +0000 | [diff] [blame] | 1054 | SmallVector<StringRef, 5> QualifiedNameComponents; |
| 1055 | const DISubprogram *ClosestSubprogram = getQualifiedNameComponents( |
| 1056 | Ty->getScope().resolve(), QualifiedNameComponents); |
| 1057 | |
| 1058 | std::string FullyQualifiedName = |
David Majnemer | 6bdc24e | 2016-07-01 23:12:45 +0000 | [diff] [blame] | 1059 | getQualifiedName(QualifiedNameComponents, getPrettyScopeName(Ty)); |
Hans Wennborg | 4b63a98 | 2016-06-23 22:57:25 +0000 | [diff] [blame] | 1060 | |
| 1061 | if (ClosestSubprogram == nullptr) |
| 1062 | GlobalUDTs.emplace_back(std::move(FullyQualifiedName), TI); |
| 1063 | else if (ClosestSubprogram == CurrentSubprogram) |
| 1064 | LocalUDTs.emplace_back(std::move(FullyQualifiedName), TI); |
| 1065 | |
| 1066 | // TODO: What if the ClosestSubprogram is neither null or the current |
| 1067 | // subprogram? Currently, the UDT just gets dropped on the floor. |
| 1068 | // |
| 1069 | // The current behavior is not desirable. To get maximal fidelity, we would |
| 1070 | // need to perform all type translation before beginning emission of .debug$S |
| 1071 | // and then make LocalUDTs a member of FunctionInfo |
| 1072 | } |
| 1073 | |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1074 | TypeIndex CodeViewDebug::lowerType(const DIType *Ty, const DIType *ClassTy) { |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1075 | // Generic dispatch for lowering an unknown type. |
| 1076 | switch (Ty->getTag()) { |
Adrian McCarthy | f3c3c13 | 2016-06-08 18:22:59 +0000 | [diff] [blame] | 1077 | case dwarf::DW_TAG_array_type: |
| 1078 | return lowerTypeArray(cast<DICompositeType>(Ty)); |
David Majnemer | d065e23 | 2016-06-02 06:21:37 +0000 | [diff] [blame] | 1079 | case dwarf::DW_TAG_typedef: |
| 1080 | return lowerTypeAlias(cast<DIDerivedType>(Ty)); |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1081 | case dwarf::DW_TAG_base_type: |
| 1082 | return lowerTypeBasic(cast<DIBasicType>(Ty)); |
| 1083 | case dwarf::DW_TAG_pointer_type: |
Reid Kleckner | 9dac473 | 2016-08-31 15:59:30 +0000 | [diff] [blame] | 1084 | if (cast<DIDerivedType>(Ty)->getName() == "__vtbl_ptr_type") |
| 1085 | return lowerTypeVFTableShape(cast<DIDerivedType>(Ty)); |
| 1086 | LLVM_FALLTHROUGH; |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1087 | case dwarf::DW_TAG_reference_type: |
| 1088 | case dwarf::DW_TAG_rvalue_reference_type: |
| 1089 | return lowerTypePointer(cast<DIDerivedType>(Ty)); |
| 1090 | case dwarf::DW_TAG_ptr_to_member_type: |
| 1091 | return lowerTypeMemberPointer(cast<DIDerivedType>(Ty)); |
| 1092 | case dwarf::DW_TAG_const_type: |
| 1093 | case dwarf::DW_TAG_volatile_type: |
| 1094 | return lowerTypeModifier(cast<DIDerivedType>(Ty)); |
David Majnemer | 75c3ebf | 2016-06-02 17:13:53 +0000 | [diff] [blame] | 1095 | case dwarf::DW_TAG_subroutine_type: |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 1096 | if (ClassTy) { |
| 1097 | // The member function type of a member function pointer has no |
| 1098 | // ThisAdjustment. |
| 1099 | return lowerTypeMemberFunction(cast<DISubroutineType>(Ty), ClassTy, |
| 1100 | /*ThisAdjustment=*/0); |
| 1101 | } |
David Majnemer | 75c3ebf | 2016-06-02 17:13:53 +0000 | [diff] [blame] | 1102 | return lowerTypeFunction(cast<DISubroutineType>(Ty)); |
David Majnemer | 979cb88 | 2016-06-16 21:32:16 +0000 | [diff] [blame] | 1103 | case dwarf::DW_TAG_enumeration_type: |
| 1104 | return lowerTypeEnum(cast<DICompositeType>(Ty)); |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1105 | case dwarf::DW_TAG_class_type: |
| 1106 | case dwarf::DW_TAG_structure_type: |
| 1107 | return lowerTypeClass(cast<DICompositeType>(Ty)); |
| 1108 | case dwarf::DW_TAG_union_type: |
| 1109 | return lowerTypeUnion(cast<DICompositeType>(Ty)); |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1110 | default: |
| 1111 | // Use the null type index. |
| 1112 | return TypeIndex(); |
| 1113 | } |
| 1114 | } |
| 1115 | |
David Majnemer | d065e23 | 2016-06-02 06:21:37 +0000 | [diff] [blame] | 1116 | TypeIndex CodeViewDebug::lowerTypeAlias(const DIDerivedType *Ty) { |
David Majnemer | d065e23 | 2016-06-02 06:21:37 +0000 | [diff] [blame] | 1117 | DITypeRef UnderlyingTypeRef = Ty->getBaseType(); |
| 1118 | TypeIndex UnderlyingTypeIndex = getTypeIndex(UnderlyingTypeRef); |
David Majnemer | 3128b10 | 2016-06-15 18:00:01 +0000 | [diff] [blame] | 1119 | StringRef TypeName = Ty->getName(); |
| 1120 | |
Hans Wennborg | 4b63a98 | 2016-06-23 22:57:25 +0000 | [diff] [blame] | 1121 | addToUDTs(Ty, UnderlyingTypeIndex); |
David Majnemer | 3128b10 | 2016-06-15 18:00:01 +0000 | [diff] [blame] | 1122 | |
David Majnemer | d065e23 | 2016-06-02 06:21:37 +0000 | [diff] [blame] | 1123 | if (UnderlyingTypeIndex == TypeIndex(SimpleTypeKind::Int32Long) && |
David Majnemer | 3128b10 | 2016-06-15 18:00:01 +0000 | [diff] [blame] | 1124 | TypeName == "HRESULT") |
David Majnemer | d065e23 | 2016-06-02 06:21:37 +0000 | [diff] [blame] | 1125 | return TypeIndex(SimpleTypeKind::HResult); |
David Majnemer | 8c46a4c | 2016-06-04 15:40:33 +0000 | [diff] [blame] | 1126 | if (UnderlyingTypeIndex == TypeIndex(SimpleTypeKind::UInt16Short) && |
David Majnemer | 3128b10 | 2016-06-15 18:00:01 +0000 | [diff] [blame] | 1127 | TypeName == "wchar_t") |
David Majnemer | 8c46a4c | 2016-06-04 15:40:33 +0000 | [diff] [blame] | 1128 | return TypeIndex(SimpleTypeKind::WideCharacter); |
Hans Wennborg | 4b63a98 | 2016-06-23 22:57:25 +0000 | [diff] [blame] | 1129 | |
David Majnemer | d065e23 | 2016-06-02 06:21:37 +0000 | [diff] [blame] | 1130 | return UnderlyingTypeIndex; |
| 1131 | } |
| 1132 | |
Adrian McCarthy | f3c3c13 | 2016-06-08 18:22:59 +0000 | [diff] [blame] | 1133 | TypeIndex CodeViewDebug::lowerTypeArray(const DICompositeType *Ty) { |
| 1134 | DITypeRef ElementTypeRef = Ty->getBaseType(); |
| 1135 | TypeIndex ElementTypeIndex = getTypeIndex(ElementTypeRef); |
| 1136 | // IndexType is size_t, which depends on the bitness of the target. |
| 1137 | TypeIndex IndexType = Asm->MAI->getPointerSize() == 8 |
| 1138 | ? TypeIndex(SimpleTypeKind::UInt64Quad) |
| 1139 | : TypeIndex(SimpleTypeKind::UInt32Long); |
Amjad Aboud | acee568 | 2016-07-12 12:06:34 +0000 | [diff] [blame] | 1140 | |
| 1141 | uint64_t ElementSize = getBaseTypeSize(ElementTypeRef) / 8; |
| 1142 | |
Amjad Aboud | acee568 | 2016-07-12 12:06:34 +0000 | [diff] [blame] | 1143 | |
Reid Kleckner | 1076288 | 2016-09-09 17:29:36 +0000 | [diff] [blame] | 1144 | // We want to assert that the element type multiplied by the array lengths |
| 1145 | // match the size of the overall array. However, if we don't have complete |
| 1146 | // type information for the base type, we can't make this assertion. This |
| 1147 | // happens if limited debug info is enabled in this case: |
| 1148 | // struct VTableOptzn { VTableOptzn(); virtual ~VTableOptzn(); }; |
| 1149 | // VTableOptzn array[3]; |
| 1150 | // The DICompositeType of VTableOptzn will have size zero, and the array will |
| 1151 | // have size 3 * sizeof(void*), and we should avoid asserting. |
| 1152 | // |
| 1153 | // There is a related bug in the front-end where an array of a structure, |
| 1154 | // which was declared as incomplete structure first, ends up not getting a |
| 1155 | // size assigned to it. (PR28303) |
Amjad Aboud | acee568 | 2016-07-12 12:06:34 +0000 | [diff] [blame] | 1156 | // Example: |
| 1157 | // struct A(*p)[3]; |
| 1158 | // struct A { int f; } a[3]; |
Reid Kleckner | 1076288 | 2016-09-09 17:29:36 +0000 | [diff] [blame] | 1159 | bool PartiallyIncomplete = false; |
| 1160 | if (Ty->getSizeInBits() == 0 || ElementSize == 0) { |
| 1161 | PartiallyIncomplete = true; |
Amjad Aboud | acee568 | 2016-07-12 12:06:34 +0000 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | // Add subranges to array type. |
| 1165 | DINodeArray Elements = Ty->getElements(); |
| 1166 | for (int i = Elements.size() - 1; i >= 0; --i) { |
| 1167 | const DINode *Element = Elements[i]; |
| 1168 | assert(Element->getTag() == dwarf::DW_TAG_subrange_type); |
| 1169 | |
| 1170 | const DISubrange *Subrange = cast<DISubrange>(Element); |
| 1171 | assert(Subrange->getLowerBound() == 0 && |
| 1172 | "codeview doesn't support subranges with lower bounds"); |
| 1173 | int64_t Count = Subrange->getCount(); |
| 1174 | |
| 1175 | // Variable Length Array (VLA) has Count equal to '-1'. |
| 1176 | // Replace with Count '1', assume it is the minimum VLA length. |
| 1177 | // FIXME: Make front-end support VLA subrange and emit LF_DIMVARLU. |
| 1178 | if (Count == -1) { |
| 1179 | Count = 1; |
Reid Kleckner | 1076288 | 2016-09-09 17:29:36 +0000 | [diff] [blame] | 1180 | PartiallyIncomplete = true; |
Amjad Aboud | acee568 | 2016-07-12 12:06:34 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
Amjad Aboud | acee568 | 2016-07-12 12:06:34 +0000 | [diff] [blame] | 1183 | // Update the element size and element type index for subsequent subranges. |
| 1184 | ElementSize *= Count; |
Reid Kleckner | 1076288 | 2016-09-09 17:29:36 +0000 | [diff] [blame] | 1185 | |
| 1186 | // If this is the outermost array, use the size from the array. It will be |
| 1187 | // more accurate if PartiallyIncomplete is true. |
| 1188 | uint64_t ArraySize = |
| 1189 | (i == 0 && ElementSize == 0) ? Ty->getSizeInBits() / 8 : ElementSize; |
| 1190 | |
| 1191 | StringRef Name = (i == 0) ? Ty->getName() : ""; |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1192 | ElementTypeIndex = TypeTable.writeKnownType( |
Reid Kleckner | 1076288 | 2016-09-09 17:29:36 +0000 | [diff] [blame] | 1193 | ArrayRecord(ElementTypeIndex, IndexType, ArraySize, Name)); |
Amjad Aboud | acee568 | 2016-07-12 12:06:34 +0000 | [diff] [blame] | 1194 | } |
| 1195 | |
Reid Kleckner | 1076288 | 2016-09-09 17:29:36 +0000 | [diff] [blame] | 1196 | (void)PartiallyIncomplete; |
| 1197 | assert(PartiallyIncomplete || ElementSize == (Ty->getSizeInBits() / 8)); |
Amjad Aboud | acee568 | 2016-07-12 12:06:34 +0000 | [diff] [blame] | 1198 | |
| 1199 | return ElementTypeIndex; |
Adrian McCarthy | f3c3c13 | 2016-06-08 18:22:59 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1202 | TypeIndex CodeViewDebug::lowerTypeBasic(const DIBasicType *Ty) { |
| 1203 | TypeIndex Index; |
| 1204 | dwarf::TypeKind Kind; |
| 1205 | uint32_t ByteSize; |
| 1206 | |
| 1207 | Kind = static_cast<dwarf::TypeKind>(Ty->getEncoding()); |
David Majnemer | afefa67 | 2016-06-02 06:21:42 +0000 | [diff] [blame] | 1208 | ByteSize = Ty->getSizeInBits() / 8; |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1209 | |
| 1210 | SimpleTypeKind STK = SimpleTypeKind::None; |
| 1211 | switch (Kind) { |
| 1212 | case dwarf::DW_ATE_address: |
| 1213 | // FIXME: Translate |
| 1214 | break; |
| 1215 | case dwarf::DW_ATE_boolean: |
| 1216 | switch (ByteSize) { |
David Majnemer | 1c2cb1d | 2016-06-02 07:02:32 +0000 | [diff] [blame] | 1217 | case 1: STK = SimpleTypeKind::Boolean8; break; |
| 1218 | case 2: STK = SimpleTypeKind::Boolean16; break; |
| 1219 | case 4: STK = SimpleTypeKind::Boolean32; break; |
| 1220 | case 8: STK = SimpleTypeKind::Boolean64; break; |
| 1221 | case 16: STK = SimpleTypeKind::Boolean128; break; |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1222 | } |
| 1223 | break; |
| 1224 | case dwarf::DW_ATE_complex_float: |
| 1225 | switch (ByteSize) { |
David Majnemer | 1c2cb1d | 2016-06-02 07:02:32 +0000 | [diff] [blame] | 1226 | case 2: STK = SimpleTypeKind::Complex16; break; |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1227 | case 4: STK = SimpleTypeKind::Complex32; break; |
| 1228 | case 8: STK = SimpleTypeKind::Complex64; break; |
| 1229 | case 10: STK = SimpleTypeKind::Complex80; break; |
| 1230 | case 16: STK = SimpleTypeKind::Complex128; break; |
| 1231 | } |
| 1232 | break; |
| 1233 | case dwarf::DW_ATE_float: |
| 1234 | switch (ByteSize) { |
David Majnemer | 1c2cb1d | 2016-06-02 07:02:32 +0000 | [diff] [blame] | 1235 | case 2: STK = SimpleTypeKind::Float16; break; |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1236 | case 4: STK = SimpleTypeKind::Float32; break; |
| 1237 | case 6: STK = SimpleTypeKind::Float48; break; |
| 1238 | case 8: STK = SimpleTypeKind::Float64; break; |
| 1239 | case 10: STK = SimpleTypeKind::Float80; break; |
| 1240 | case 16: STK = SimpleTypeKind::Float128; break; |
| 1241 | } |
| 1242 | break; |
| 1243 | case dwarf::DW_ATE_signed: |
| 1244 | switch (ByteSize) { |
Reid Kleckner | e45b2c7 | 2016-09-29 17:55:01 +0000 | [diff] [blame] | 1245 | case 1: STK = SimpleTypeKind::SignedCharacter; break; |
| 1246 | case 2: STK = SimpleTypeKind::Int16Short; break; |
| 1247 | case 4: STK = SimpleTypeKind::Int32; break; |
| 1248 | case 8: STK = SimpleTypeKind::Int64Quad; break; |
| 1249 | case 16: STK = SimpleTypeKind::Int128Oct; break; |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1250 | } |
| 1251 | break; |
| 1252 | case dwarf::DW_ATE_unsigned: |
| 1253 | switch (ByteSize) { |
Reid Kleckner | e45b2c7 | 2016-09-29 17:55:01 +0000 | [diff] [blame] | 1254 | case 1: STK = SimpleTypeKind::UnsignedCharacter; break; |
| 1255 | case 2: STK = SimpleTypeKind::UInt16Short; break; |
| 1256 | case 4: STK = SimpleTypeKind::UInt32; break; |
| 1257 | case 8: STK = SimpleTypeKind::UInt64Quad; break; |
| 1258 | case 16: STK = SimpleTypeKind::UInt128Oct; break; |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1259 | } |
| 1260 | break; |
| 1261 | case dwarf::DW_ATE_UTF: |
| 1262 | switch (ByteSize) { |
| 1263 | case 2: STK = SimpleTypeKind::Character16; break; |
| 1264 | case 4: STK = SimpleTypeKind::Character32; break; |
| 1265 | } |
| 1266 | break; |
| 1267 | case dwarf::DW_ATE_signed_char: |
| 1268 | if (ByteSize == 1) |
| 1269 | STK = SimpleTypeKind::SignedCharacter; |
| 1270 | break; |
| 1271 | case dwarf::DW_ATE_unsigned_char: |
| 1272 | if (ByteSize == 1) |
| 1273 | STK = SimpleTypeKind::UnsignedCharacter; |
| 1274 | break; |
| 1275 | default: |
| 1276 | break; |
| 1277 | } |
| 1278 | |
| 1279 | // Apply some fixups based on the source-level type name. |
| 1280 | if (STK == SimpleTypeKind::Int32 && Ty->getName() == "long int") |
| 1281 | STK = SimpleTypeKind::Int32Long; |
| 1282 | if (STK == SimpleTypeKind::UInt32 && Ty->getName() == "long unsigned int") |
| 1283 | STK = SimpleTypeKind::UInt32Long; |
David Majnemer | 8c46a4c | 2016-06-04 15:40:33 +0000 | [diff] [blame] | 1284 | if (STK == SimpleTypeKind::UInt16Short && |
| 1285 | (Ty->getName() == "wchar_t" || Ty->getName() == "__wchar_t")) |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1286 | STK = SimpleTypeKind::WideCharacter; |
| 1287 | if ((STK == SimpleTypeKind::SignedCharacter || |
| 1288 | STK == SimpleTypeKind::UnsignedCharacter) && |
| 1289 | Ty->getName() == "char") |
| 1290 | STK = SimpleTypeKind::NarrowCharacter; |
| 1291 | |
| 1292 | return TypeIndex(STK); |
| 1293 | } |
| 1294 | |
| 1295 | TypeIndex CodeViewDebug::lowerTypePointer(const DIDerivedType *Ty) { |
| 1296 | TypeIndex PointeeTI = getTypeIndex(Ty->getBaseType()); |
| 1297 | |
| 1298 | // Pointers to simple types can use SimpleTypeMode, rather than having a |
| 1299 | // dedicated pointer type record. |
| 1300 | if (PointeeTI.isSimple() && |
| 1301 | PointeeTI.getSimpleMode() == SimpleTypeMode::Direct && |
| 1302 | Ty->getTag() == dwarf::DW_TAG_pointer_type) { |
| 1303 | SimpleTypeMode Mode = Ty->getSizeInBits() == 64 |
| 1304 | ? SimpleTypeMode::NearPointer64 |
| 1305 | : SimpleTypeMode::NearPointer32; |
| 1306 | return TypeIndex(PointeeTI.getSimpleKind(), Mode); |
| 1307 | } |
| 1308 | |
| 1309 | PointerKind PK = |
| 1310 | Ty->getSizeInBits() == 64 ? PointerKind::Near64 : PointerKind::Near32; |
| 1311 | PointerMode PM = PointerMode::Pointer; |
| 1312 | switch (Ty->getTag()) { |
| 1313 | default: llvm_unreachable("not a pointer tag type"); |
| 1314 | case dwarf::DW_TAG_pointer_type: |
| 1315 | PM = PointerMode::Pointer; |
| 1316 | break; |
| 1317 | case dwarf::DW_TAG_reference_type: |
| 1318 | PM = PointerMode::LValueReference; |
| 1319 | break; |
| 1320 | case dwarf::DW_TAG_rvalue_reference_type: |
| 1321 | PM = PointerMode::RValueReference; |
| 1322 | break; |
| 1323 | } |
| 1324 | // FIXME: MSVC folds qualifiers into PointerOptions in the context of a method |
| 1325 | // 'this' pointer, but not normal contexts. Figure out what we're supposed to |
| 1326 | // do. |
| 1327 | PointerOptions PO = PointerOptions::None; |
| 1328 | PointerRecord PR(PointeeTI, PK, PM, PO, Ty->getSizeInBits() / 8); |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1329 | return TypeTable.writeKnownType(PR); |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1330 | } |
| 1331 | |
Reid Kleckner | 6fa1546 | 2016-06-17 22:14:39 +0000 | [diff] [blame] | 1332 | static PointerToMemberRepresentation |
| 1333 | translatePtrToMemberRep(unsigned SizeInBytes, bool IsPMF, unsigned Flags) { |
| 1334 | // SizeInBytes being zero generally implies that the member pointer type was |
| 1335 | // incomplete, which can happen if it is part of a function prototype. In this |
| 1336 | // case, use the unknown model instead of the general model. |
Reid Kleckner | 604105b | 2016-06-17 21:31:33 +0000 | [diff] [blame] | 1337 | if (IsPMF) { |
| 1338 | switch (Flags & DINode::FlagPtrToMemberRep) { |
| 1339 | case 0: |
Reid Kleckner | 6fa1546 | 2016-06-17 22:14:39 +0000 | [diff] [blame] | 1340 | return SizeInBytes == 0 ? PointerToMemberRepresentation::Unknown |
| 1341 | : PointerToMemberRepresentation::GeneralFunction; |
Reid Kleckner | 604105b | 2016-06-17 21:31:33 +0000 | [diff] [blame] | 1342 | case DINode::FlagSingleInheritance: |
| 1343 | return PointerToMemberRepresentation::SingleInheritanceFunction; |
| 1344 | case DINode::FlagMultipleInheritance: |
| 1345 | return PointerToMemberRepresentation::MultipleInheritanceFunction; |
| 1346 | case DINode::FlagVirtualInheritance: |
| 1347 | return PointerToMemberRepresentation::VirtualInheritanceFunction; |
| 1348 | } |
| 1349 | } else { |
| 1350 | switch (Flags & DINode::FlagPtrToMemberRep) { |
| 1351 | case 0: |
Reid Kleckner | 6fa1546 | 2016-06-17 22:14:39 +0000 | [diff] [blame] | 1352 | return SizeInBytes == 0 ? PointerToMemberRepresentation::Unknown |
| 1353 | : PointerToMemberRepresentation::GeneralData; |
Reid Kleckner | 604105b | 2016-06-17 21:31:33 +0000 | [diff] [blame] | 1354 | case DINode::FlagSingleInheritance: |
| 1355 | return PointerToMemberRepresentation::SingleInheritanceData; |
| 1356 | case DINode::FlagMultipleInheritance: |
| 1357 | return PointerToMemberRepresentation::MultipleInheritanceData; |
| 1358 | case DINode::FlagVirtualInheritance: |
| 1359 | return PointerToMemberRepresentation::VirtualInheritanceData; |
| 1360 | } |
| 1361 | } |
| 1362 | llvm_unreachable("invalid ptr to member representation"); |
| 1363 | } |
| 1364 | |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1365 | TypeIndex CodeViewDebug::lowerTypeMemberPointer(const DIDerivedType *Ty) { |
| 1366 | assert(Ty->getTag() == dwarf::DW_TAG_ptr_to_member_type); |
| 1367 | TypeIndex ClassTI = getTypeIndex(Ty->getClassType()); |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1368 | TypeIndex PointeeTI = getTypeIndex(Ty->getBaseType(), Ty->getClassType()); |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1369 | PointerKind PK = Asm->MAI->getPointerSize() == 8 ? PointerKind::Near64 |
| 1370 | : PointerKind::Near32; |
Reid Kleckner | 604105b | 2016-06-17 21:31:33 +0000 | [diff] [blame] | 1371 | bool IsPMF = isa<DISubroutineType>(Ty->getBaseType()); |
| 1372 | PointerMode PM = IsPMF ? PointerMode::PointerToMemberFunction |
| 1373 | : PointerMode::PointerToDataMember; |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1374 | PointerOptions PO = PointerOptions::None; // FIXME |
Reid Kleckner | 6fa1546 | 2016-06-17 22:14:39 +0000 | [diff] [blame] | 1375 | assert(Ty->getSizeInBits() / 8 <= 0xff && "pointer size too big"); |
| 1376 | uint8_t SizeInBytes = Ty->getSizeInBits() / 8; |
| 1377 | MemberPointerInfo MPI( |
| 1378 | ClassTI, translatePtrToMemberRep(SizeInBytes, IsPMF, Ty->getFlags())); |
Reid Kleckner | 604105b | 2016-06-17 21:31:33 +0000 | [diff] [blame] | 1379 | PointerRecord PR(PointeeTI, PK, PM, PO, SizeInBytes, MPI); |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1380 | return TypeTable.writeKnownType(PR); |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 1383 | /// Given a DWARF calling convention, get the CodeView equivalent. If we don't |
| 1384 | /// have a translation, use the NearC convention. |
| 1385 | static CallingConvention dwarfCCToCodeView(unsigned DwarfCC) { |
| 1386 | switch (DwarfCC) { |
| 1387 | case dwarf::DW_CC_normal: return CallingConvention::NearC; |
| 1388 | case dwarf::DW_CC_BORLAND_msfastcall: return CallingConvention::NearFast; |
| 1389 | case dwarf::DW_CC_BORLAND_thiscall: return CallingConvention::ThisCall; |
| 1390 | case dwarf::DW_CC_BORLAND_stdcall: return CallingConvention::NearStdCall; |
| 1391 | case dwarf::DW_CC_BORLAND_pascal: return CallingConvention::NearPascal; |
| 1392 | case dwarf::DW_CC_LLVM_vectorcall: return CallingConvention::NearVector; |
| 1393 | } |
| 1394 | return CallingConvention::NearC; |
| 1395 | } |
| 1396 | |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1397 | TypeIndex CodeViewDebug::lowerTypeModifier(const DIDerivedType *Ty) { |
| 1398 | ModifierOptions Mods = ModifierOptions::None; |
| 1399 | bool IsModifier = true; |
| 1400 | const DIType *BaseTy = Ty; |
Reid Kleckner | b9c80fd | 2016-06-02 17:40:51 +0000 | [diff] [blame] | 1401 | while (IsModifier && BaseTy) { |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1402 | // FIXME: Need to add DWARF tag for __unaligned. |
| 1403 | switch (BaseTy->getTag()) { |
| 1404 | case dwarf::DW_TAG_const_type: |
| 1405 | Mods |= ModifierOptions::Const; |
| 1406 | break; |
| 1407 | case dwarf::DW_TAG_volatile_type: |
| 1408 | Mods |= ModifierOptions::Volatile; |
| 1409 | break; |
| 1410 | default: |
| 1411 | IsModifier = false; |
| 1412 | break; |
| 1413 | } |
| 1414 | if (IsModifier) |
| 1415 | BaseTy = cast<DIDerivedType>(BaseTy)->getBaseType().resolve(); |
| 1416 | } |
| 1417 | TypeIndex ModifiedTI = getTypeIndex(BaseTy); |
Reid Kleckner | dbaa61c | 2016-08-30 21:48:14 +0000 | [diff] [blame] | 1418 | return TypeTable.writeKnownType(ModifierRecord(ModifiedTI, Mods)); |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1419 | } |
| 1420 | |
David Majnemer | 75c3ebf | 2016-06-02 17:13:53 +0000 | [diff] [blame] | 1421 | TypeIndex CodeViewDebug::lowerTypeFunction(const DISubroutineType *Ty) { |
| 1422 | SmallVector<TypeIndex, 8> ReturnAndArgTypeIndices; |
| 1423 | for (DITypeRef ArgTypeRef : Ty->getTypeArray()) |
| 1424 | ReturnAndArgTypeIndices.push_back(getTypeIndex(ArgTypeRef)); |
| 1425 | |
| 1426 | TypeIndex ReturnTypeIndex = TypeIndex::Void(); |
| 1427 | ArrayRef<TypeIndex> ArgTypeIndices = None; |
| 1428 | if (!ReturnAndArgTypeIndices.empty()) { |
| 1429 | auto ReturnAndArgTypesRef = makeArrayRef(ReturnAndArgTypeIndices); |
| 1430 | ReturnTypeIndex = ReturnAndArgTypesRef.front(); |
| 1431 | ArgTypeIndices = ReturnAndArgTypesRef.drop_front(); |
| 1432 | } |
| 1433 | |
| 1434 | ArgListRecord ArgListRec(TypeRecordKind::ArgList, ArgTypeIndices); |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1435 | TypeIndex ArgListIndex = TypeTable.writeKnownType(ArgListRec); |
David Majnemer | 75c3ebf | 2016-06-02 17:13:53 +0000 | [diff] [blame] | 1436 | |
Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 1437 | CallingConvention CC = dwarfCCToCodeView(Ty->getCC()); |
| 1438 | |
Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 1439 | ProcedureRecord Procedure(ReturnTypeIndex, CC, FunctionOptions::None, |
| 1440 | ArgTypeIndices.size(), ArgListIndex); |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1441 | return TypeTable.writeKnownType(Procedure); |
David Majnemer | 75c3ebf | 2016-06-02 17:13:53 +0000 | [diff] [blame] | 1442 | } |
| 1443 | |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1444 | TypeIndex CodeViewDebug::lowerTypeMemberFunction(const DISubroutineType *Ty, |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 1445 | const DIType *ClassTy, |
| 1446 | int ThisAdjustment) { |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1447 | // Lower the containing class type. |
| 1448 | TypeIndex ClassType = getTypeIndex(ClassTy); |
| 1449 | |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1450 | SmallVector<TypeIndex, 8> ReturnAndArgTypeIndices; |
| 1451 | for (DITypeRef ArgTypeRef : Ty->getTypeArray()) |
| 1452 | ReturnAndArgTypeIndices.push_back(getTypeIndex(ArgTypeRef)); |
| 1453 | |
| 1454 | TypeIndex ReturnTypeIndex = TypeIndex::Void(); |
| 1455 | ArrayRef<TypeIndex> ArgTypeIndices = None; |
| 1456 | if (!ReturnAndArgTypeIndices.empty()) { |
| 1457 | auto ReturnAndArgTypesRef = makeArrayRef(ReturnAndArgTypeIndices); |
| 1458 | ReturnTypeIndex = ReturnAndArgTypesRef.front(); |
| 1459 | ArgTypeIndices = ReturnAndArgTypesRef.drop_front(); |
| 1460 | } |
| 1461 | TypeIndex ThisTypeIndex = TypeIndex::Void(); |
| 1462 | if (!ArgTypeIndices.empty()) { |
| 1463 | ThisTypeIndex = ArgTypeIndices.front(); |
| 1464 | ArgTypeIndices = ArgTypeIndices.drop_front(); |
| 1465 | } |
| 1466 | |
| 1467 | ArgListRecord ArgListRec(TypeRecordKind::ArgList, ArgTypeIndices); |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1468 | TypeIndex ArgListIndex = TypeTable.writeKnownType(ArgListRec); |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1469 | |
| 1470 | CallingConvention CC = dwarfCCToCodeView(Ty->getCC()); |
| 1471 | |
| 1472 | // TODO: Need to use the correct values for: |
| 1473 | // FunctionOptions |
| 1474 | // ThisPointerAdjustment. |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1475 | TypeIndex TI = TypeTable.writeKnownType(MemberFunctionRecord( |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1476 | ReturnTypeIndex, ClassType, ThisTypeIndex, CC, FunctionOptions::None, |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 1477 | ArgTypeIndices.size(), ArgListIndex, ThisAdjustment)); |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1478 | |
| 1479 | return TI; |
| 1480 | } |
| 1481 | |
Reid Kleckner | 9dac473 | 2016-08-31 15:59:30 +0000 | [diff] [blame] | 1482 | TypeIndex CodeViewDebug::lowerTypeVFTableShape(const DIDerivedType *Ty) { |
| 1483 | unsigned VSlotCount = Ty->getSizeInBits() / (8 * Asm->MAI->getPointerSize()); |
| 1484 | SmallVector<VFTableSlotKind, 4> Slots(VSlotCount, VFTableSlotKind::Near); |
| 1485 | return TypeTable.writeKnownType(VFTableShapeRecord(Slots)); |
| 1486 | } |
| 1487 | |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1488 | static MemberAccess translateAccessFlags(unsigned RecordTag, unsigned Flags) { |
| 1489 | switch (Flags & DINode::FlagAccessibility) { |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1490 | case DINode::FlagPrivate: return MemberAccess::Private; |
| 1491 | case DINode::FlagPublic: return MemberAccess::Public; |
| 1492 | case DINode::FlagProtected: return MemberAccess::Protected; |
| 1493 | case 0: |
| 1494 | // If there was no explicit access control, provide the default for the tag. |
| 1495 | return RecordTag == dwarf::DW_TAG_class_type ? MemberAccess::Private |
| 1496 | : MemberAccess::Public; |
| 1497 | } |
| 1498 | llvm_unreachable("access flags are exclusive"); |
| 1499 | } |
| 1500 | |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1501 | static MethodOptions translateMethodOptionFlags(const DISubprogram *SP) { |
| 1502 | if (SP->isArtificial()) |
| 1503 | return MethodOptions::CompilerGenerated; |
| 1504 | |
| 1505 | // FIXME: Handle other MethodOptions. |
| 1506 | |
| 1507 | return MethodOptions::None; |
| 1508 | } |
| 1509 | |
| 1510 | static MethodKind translateMethodKindFlags(const DISubprogram *SP, |
| 1511 | bool Introduced) { |
| 1512 | switch (SP->getVirtuality()) { |
| 1513 | case dwarf::DW_VIRTUALITY_none: |
| 1514 | break; |
| 1515 | case dwarf::DW_VIRTUALITY_virtual: |
| 1516 | return Introduced ? MethodKind::IntroducingVirtual : MethodKind::Virtual; |
| 1517 | case dwarf::DW_VIRTUALITY_pure_virtual: |
| 1518 | return Introduced ? MethodKind::PureIntroducingVirtual |
| 1519 | : MethodKind::PureVirtual; |
| 1520 | default: |
| 1521 | llvm_unreachable("unhandled virtuality case"); |
| 1522 | } |
| 1523 | |
| 1524 | // FIXME: Get Clang to mark DISubprogram as static and do something with it. |
| 1525 | |
| 1526 | return MethodKind::Vanilla; |
| 1527 | } |
| 1528 | |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1529 | static TypeRecordKind getRecordKind(const DICompositeType *Ty) { |
| 1530 | switch (Ty->getTag()) { |
| 1531 | case dwarf::DW_TAG_class_type: return TypeRecordKind::Class; |
| 1532 | case dwarf::DW_TAG_structure_type: return TypeRecordKind::Struct; |
| 1533 | } |
| 1534 | llvm_unreachable("unexpected tag"); |
| 1535 | } |
| 1536 | |
Reid Kleckner | e092dad | 2016-07-02 00:11:07 +0000 | [diff] [blame] | 1537 | /// Return ClassOptions that should be present on both the forward declaration |
| 1538 | /// and the defintion of a tag type. |
| 1539 | static ClassOptions getCommonClassOptions(const DICompositeType *Ty) { |
| 1540 | ClassOptions CO = ClassOptions::None; |
| 1541 | |
| 1542 | // MSVC always sets this flag, even for local types. Clang doesn't always |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1543 | // appear to give every type a linkage name, which may be problematic for us. |
| 1544 | // FIXME: Investigate the consequences of not following them here. |
Reid Kleckner | e092dad | 2016-07-02 00:11:07 +0000 | [diff] [blame] | 1545 | if (!Ty->getIdentifier().empty()) |
| 1546 | CO |= ClassOptions::HasUniqueName; |
| 1547 | |
| 1548 | // Put the Nested flag on a type if it appears immediately inside a tag type. |
| 1549 | // Do not walk the scope chain. Do not attempt to compute ContainsNestedClass |
| 1550 | // here. That flag is only set on definitions, and not forward declarations. |
| 1551 | const DIScope *ImmediateScope = Ty->getScope().resolve(); |
| 1552 | if (ImmediateScope && isa<DICompositeType>(ImmediateScope)) |
| 1553 | CO |= ClassOptions::Nested; |
| 1554 | |
| 1555 | // Put the Scoped flag on function-local types. |
| 1556 | for (const DIScope *Scope = ImmediateScope; Scope != nullptr; |
| 1557 | Scope = Scope->getScope().resolve()) { |
| 1558 | if (isa<DISubprogram>(Scope)) { |
| 1559 | CO |= ClassOptions::Scoped; |
| 1560 | break; |
| 1561 | } |
| 1562 | } |
| 1563 | |
| 1564 | return CO; |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1565 | } |
| 1566 | |
David Majnemer | 979cb88 | 2016-06-16 21:32:16 +0000 | [diff] [blame] | 1567 | TypeIndex CodeViewDebug::lowerTypeEnum(const DICompositeType *Ty) { |
Reid Kleckner | e092dad | 2016-07-02 00:11:07 +0000 | [diff] [blame] | 1568 | ClassOptions CO = getCommonClassOptions(Ty); |
David Majnemer | 979cb88 | 2016-06-16 21:32:16 +0000 | [diff] [blame] | 1569 | TypeIndex FTI; |
David Majnemer | da9548f | 2016-06-17 16:13:21 +0000 | [diff] [blame] | 1570 | unsigned EnumeratorCount = 0; |
David Majnemer | 979cb88 | 2016-06-16 21:32:16 +0000 | [diff] [blame] | 1571 | |
David Majnemer | da9548f | 2016-06-17 16:13:21 +0000 | [diff] [blame] | 1572 | if (Ty->isForwardDecl()) { |
David Majnemer | 979cb88 | 2016-06-16 21:32:16 +0000 | [diff] [blame] | 1573 | CO |= ClassOptions::ForwardReference; |
David Majnemer | da9548f | 2016-06-17 16:13:21 +0000 | [diff] [blame] | 1574 | } else { |
| 1575 | FieldListRecordBuilder Fields; |
| 1576 | for (const DINode *Element : Ty->getElements()) { |
| 1577 | // We assume that the frontend provides all members in source declaration |
| 1578 | // order, which is what MSVC does. |
| 1579 | if (auto *Enumerator = dyn_cast_or_null<DIEnumerator>(Element)) { |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1580 | Fields.writeMemberType(EnumeratorRecord( |
David Majnemer | da9548f | 2016-06-17 16:13:21 +0000 | [diff] [blame] | 1581 | MemberAccess::Public, APSInt::getUnsigned(Enumerator->getValue()), |
| 1582 | Enumerator->getName())); |
| 1583 | EnumeratorCount++; |
| 1584 | } |
| 1585 | } |
| 1586 | FTI = TypeTable.writeFieldList(Fields); |
| 1587 | } |
David Majnemer | 979cb88 | 2016-06-16 21:32:16 +0000 | [diff] [blame] | 1588 | |
David Majnemer | 6bdc24e | 2016-07-01 23:12:45 +0000 | [diff] [blame] | 1589 | std::string FullName = getFullyQualifiedName(Ty); |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 1590 | |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1591 | return TypeTable.writeKnownType(EnumRecord(EnumeratorCount, CO, FTI, FullName, |
| 1592 | Ty->getIdentifier(), |
| 1593 | getTypeIndex(Ty->getBaseType()))); |
David Majnemer | 979cb88 | 2016-06-16 21:32:16 +0000 | [diff] [blame] | 1594 | } |
| 1595 | |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1596 | //===----------------------------------------------------------------------===// |
| 1597 | // ClassInfo |
| 1598 | //===----------------------------------------------------------------------===// |
| 1599 | |
| 1600 | struct llvm::ClassInfo { |
| 1601 | struct MemberInfo { |
| 1602 | const DIDerivedType *MemberTypeNode; |
David Majnemer | 08bd744 | 2016-07-01 23:12:48 +0000 | [diff] [blame] | 1603 | uint64_t BaseOffset; |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1604 | }; |
| 1605 | // [MemberInfo] |
| 1606 | typedef std::vector<MemberInfo> MemberList; |
| 1607 | |
Reid Kleckner | 156a723 | 2016-06-22 18:31:14 +0000 | [diff] [blame] | 1608 | typedef TinyPtrVector<const DISubprogram *> MethodsList; |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1609 | // MethodName -> MethodsList |
| 1610 | typedef MapVector<MDString *, MethodsList> MethodsMap; |
| 1611 | |
Reid Kleckner | 9f7f3e1 | 2016-06-24 16:24:24 +0000 | [diff] [blame] | 1612 | /// Base classes. |
| 1613 | std::vector<const DIDerivedType *> Inheritance; |
| 1614 | |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1615 | /// Direct members. |
| 1616 | MemberList Members; |
| 1617 | // Direct overloaded methods gathered by name. |
| 1618 | MethodsMap Methods; |
Adrian McCarthy | 820ca54 | 2016-07-06 19:49:51 +0000 | [diff] [blame] | 1619 | |
Reid Kleckner | 9dac473 | 2016-08-31 15:59:30 +0000 | [diff] [blame] | 1620 | TypeIndex VShapeTI; |
| 1621 | |
Adrian McCarthy | 820ca54 | 2016-07-06 19:49:51 +0000 | [diff] [blame] | 1622 | std::vector<const DICompositeType *> NestedClasses; |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1623 | }; |
| 1624 | |
| 1625 | void CodeViewDebug::clear() { |
| 1626 | assert(CurFn == nullptr); |
| 1627 | FileIdMap.clear(); |
| 1628 | FnDebugInfo.clear(); |
| 1629 | FileToFilepathMap.clear(); |
| 1630 | LocalUDTs.clear(); |
| 1631 | GlobalUDTs.clear(); |
| 1632 | TypeIndices.clear(); |
| 1633 | CompleteTypeIndices.clear(); |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | void CodeViewDebug::collectMemberInfo(ClassInfo &Info, |
| 1637 | const DIDerivedType *DDTy) { |
| 1638 | if (!DDTy->getName().empty()) { |
| 1639 | Info.Members.push_back({DDTy, 0}); |
| 1640 | return; |
| 1641 | } |
Reid Kleckner | 1ab7eac | 2016-06-22 16:06:42 +0000 | [diff] [blame] | 1642 | // An unnamed member must represent a nested struct or union. Add all the |
| 1643 | // indirect fields to the current record. |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1644 | assert((DDTy->getOffsetInBits() % 8) == 0 && "Unnamed bitfield member!"); |
David Majnemer | 08bd744 | 2016-07-01 23:12:48 +0000 | [diff] [blame] | 1645 | uint64_t Offset = DDTy->getOffsetInBits(); |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1646 | const DIType *Ty = DDTy->getBaseType().resolve(); |
Reid Kleckner | 9ff936c | 2016-06-21 14:56:24 +0000 | [diff] [blame] | 1647 | const DICompositeType *DCTy = cast<DICompositeType>(Ty); |
Reid Kleckner | 1ab7eac | 2016-06-22 16:06:42 +0000 | [diff] [blame] | 1648 | ClassInfo NestedInfo = collectClassInfo(DCTy); |
| 1649 | for (const ClassInfo::MemberInfo &IndirectField : NestedInfo.Members) |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1650 | Info.Members.push_back( |
Reid Kleckner | 1ab7eac | 2016-06-22 16:06:42 +0000 | [diff] [blame] | 1651 | {IndirectField.MemberTypeNode, IndirectField.BaseOffset + Offset}); |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1652 | } |
| 1653 | |
Reid Kleckner | 1ab7eac | 2016-06-22 16:06:42 +0000 | [diff] [blame] | 1654 | ClassInfo CodeViewDebug::collectClassInfo(const DICompositeType *Ty) { |
| 1655 | ClassInfo Info; |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1656 | // Add elements to structure type. |
| 1657 | DINodeArray Elements = Ty->getElements(); |
| 1658 | for (auto *Element : Elements) { |
| 1659 | // We assume that the frontend provides all members in source declaration |
| 1660 | // order, which is what MSVC does. |
| 1661 | if (!Element) |
| 1662 | continue; |
| 1663 | if (auto *SP = dyn_cast<DISubprogram>(Element)) { |
Reid Kleckner | 156a723 | 2016-06-22 18:31:14 +0000 | [diff] [blame] | 1664 | Info.Methods[SP->getRawName()].push_back(SP); |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1665 | } else if (auto *DDTy = dyn_cast<DIDerivedType>(Element)) { |
Reid Kleckner | 9f7f3e1 | 2016-06-24 16:24:24 +0000 | [diff] [blame] | 1666 | if (DDTy->getTag() == dwarf::DW_TAG_member) { |
Reid Kleckner | 1ab7eac | 2016-06-22 16:06:42 +0000 | [diff] [blame] | 1667 | collectMemberInfo(Info, DDTy); |
Reid Kleckner | 9f7f3e1 | 2016-06-24 16:24:24 +0000 | [diff] [blame] | 1668 | } else if (DDTy->getTag() == dwarf::DW_TAG_inheritance) { |
| 1669 | Info.Inheritance.push_back(DDTy); |
Reid Kleckner | 9dac473 | 2016-08-31 15:59:30 +0000 | [diff] [blame] | 1670 | } else if (DDTy->getTag() == dwarf::DW_TAG_pointer_type && |
| 1671 | DDTy->getName() == "__vtbl_ptr_type") { |
| 1672 | Info.VShapeTI = getTypeIndex(DDTy); |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1673 | } else if (DDTy->getTag() == dwarf::DW_TAG_friend) { |
| 1674 | // Ignore friend members. It appears that MSVC emitted info about |
| 1675 | // friends in the past, but modern versions do not. |
| 1676 | } |
Adrian McCarthy | 820ca54 | 2016-07-06 19:49:51 +0000 | [diff] [blame] | 1677 | } else if (auto *Composite = dyn_cast<DICompositeType>(Element)) { |
| 1678 | Info.NestedClasses.push_back(Composite); |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1679 | } |
| 1680 | // Skip other unrecognized kinds of elements. |
| 1681 | } |
Reid Kleckner | 1ab7eac | 2016-06-22 16:06:42 +0000 | [diff] [blame] | 1682 | return Info; |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1683 | } |
| 1684 | |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1685 | TypeIndex CodeViewDebug::lowerTypeClass(const DICompositeType *Ty) { |
| 1686 | // First, construct the forward decl. Don't look into Ty to compute the |
| 1687 | // forward decl options, since it might not be available in all TUs. |
| 1688 | TypeRecordKind Kind = getRecordKind(Ty); |
| 1689 | ClassOptions CO = |
Reid Kleckner | e092dad | 2016-07-02 00:11:07 +0000 | [diff] [blame] | 1690 | ClassOptions::ForwardReference | getCommonClassOptions(Ty); |
David Majnemer | 6bdc24e | 2016-07-01 23:12:45 +0000 | [diff] [blame] | 1691 | std::string FullName = getFullyQualifiedName(Ty); |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1692 | TypeIndex FwdDeclTI = TypeTable.writeKnownType(ClassRecord( |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1693 | Kind, 0, CO, HfaKind::None, WindowsRTClassKind::None, TypeIndex(), |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 1694 | TypeIndex(), TypeIndex(), 0, FullName, Ty->getIdentifier())); |
Reid Kleckner | 643dd83 | 2016-06-22 17:15:28 +0000 | [diff] [blame] | 1695 | if (!Ty->isForwardDecl()) |
| 1696 | DeferredCompleteTypes.push_back(Ty); |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1697 | return FwdDeclTI; |
| 1698 | } |
| 1699 | |
| 1700 | TypeIndex CodeViewDebug::lowerCompleteTypeClass(const DICompositeType *Ty) { |
| 1701 | // Construct the field list and complete type record. |
| 1702 | TypeRecordKind Kind = getRecordKind(Ty); |
Reid Kleckner | e092dad | 2016-07-02 00:11:07 +0000 | [diff] [blame] | 1703 | ClassOptions CO = getCommonClassOptions(Ty); |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1704 | TypeIndex FieldTI; |
| 1705 | TypeIndex VShapeTI; |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1706 | unsigned FieldCount; |
Adrian McCarthy | 820ca54 | 2016-07-06 19:49:51 +0000 | [diff] [blame] | 1707 | bool ContainsNestedClass; |
| 1708 | std::tie(FieldTI, VShapeTI, FieldCount, ContainsNestedClass) = |
| 1709 | lowerRecordFieldList(Ty); |
| 1710 | |
| 1711 | if (ContainsNestedClass) |
| 1712 | CO |= ClassOptions::ContainsNestedClass; |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1713 | |
David Majnemer | 6bdc24e | 2016-07-01 23:12:45 +0000 | [diff] [blame] | 1714 | std::string FullName = getFullyQualifiedName(Ty); |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 1715 | |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1716 | uint64_t SizeInBytes = Ty->getSizeInBits() / 8; |
Hans Wennborg | 9a519a0 | 2016-06-22 21:22:13 +0000 | [diff] [blame] | 1717 | |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1718 | TypeIndex ClassTI = TypeTable.writeKnownType(ClassRecord( |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1719 | Kind, FieldCount, CO, HfaKind::None, WindowsRTClassKind::None, FieldTI, |
Reid Kleckner | 0c5d874 | 2016-06-22 01:32:56 +0000 | [diff] [blame] | 1720 | TypeIndex(), VShapeTI, SizeInBytes, FullName, Ty->getIdentifier())); |
Hans Wennborg | 9a519a0 | 2016-06-22 21:22:13 +0000 | [diff] [blame] | 1721 | |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1722 | TypeTable.writeKnownType(UdtSourceLineRecord( |
| 1723 | ClassTI, TypeTable.writeKnownType(StringIdRecord( |
Hans Wennborg | 9a519a0 | 2016-06-22 21:22:13 +0000 | [diff] [blame] | 1724 | TypeIndex(0x0), getFullFilepath(Ty->getFile()))), |
| 1725 | Ty->getLine())); |
| 1726 | |
Hans Wennborg | 4b63a98 | 2016-06-23 22:57:25 +0000 | [diff] [blame] | 1727 | addToUDTs(Ty, ClassTI); |
| 1728 | |
Hans Wennborg | 9a519a0 | 2016-06-22 21:22:13 +0000 | [diff] [blame] | 1729 | return ClassTI; |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | TypeIndex CodeViewDebug::lowerTypeUnion(const DICompositeType *Ty) { |
| 1733 | ClassOptions CO = |
Reid Kleckner | e092dad | 2016-07-02 00:11:07 +0000 | [diff] [blame] | 1734 | ClassOptions::ForwardReference | getCommonClassOptions(Ty); |
David Majnemer | 6bdc24e | 2016-07-01 23:12:45 +0000 | [diff] [blame] | 1735 | std::string FullName = getFullyQualifiedName(Ty); |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1736 | TypeIndex FwdDeclTI = TypeTable.writeKnownType(UnionRecord( |
| 1737 | 0, CO, HfaKind::None, TypeIndex(), 0, FullName, Ty->getIdentifier())); |
Reid Kleckner | 643dd83 | 2016-06-22 17:15:28 +0000 | [diff] [blame] | 1738 | if (!Ty->isForwardDecl()) |
| 1739 | DeferredCompleteTypes.push_back(Ty); |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1740 | return FwdDeclTI; |
| 1741 | } |
| 1742 | |
| 1743 | TypeIndex CodeViewDebug::lowerCompleteTypeUnion(const DICompositeType *Ty) { |
David Majnemer | e1e7372 | 2016-07-06 21:07:42 +0000 | [diff] [blame] | 1744 | ClassOptions CO = ClassOptions::Sealed | getCommonClassOptions(Ty); |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1745 | TypeIndex FieldTI; |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1746 | unsigned FieldCount; |
Adrian McCarthy | 820ca54 | 2016-07-06 19:49:51 +0000 | [diff] [blame] | 1747 | bool ContainsNestedClass; |
| 1748 | std::tie(FieldTI, std::ignore, FieldCount, ContainsNestedClass) = |
| 1749 | lowerRecordFieldList(Ty); |
| 1750 | |
| 1751 | if (ContainsNestedClass) |
| 1752 | CO |= ClassOptions::ContainsNestedClass; |
| 1753 | |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1754 | uint64_t SizeInBytes = Ty->getSizeInBits() / 8; |
David Majnemer | 6bdc24e | 2016-07-01 23:12:45 +0000 | [diff] [blame] | 1755 | std::string FullName = getFullyQualifiedName(Ty); |
Hans Wennborg | 9a519a0 | 2016-06-22 21:22:13 +0000 | [diff] [blame] | 1756 | |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1757 | TypeIndex UnionTI = TypeTable.writeKnownType( |
Hans Wennborg | 9a519a0 | 2016-06-22 21:22:13 +0000 | [diff] [blame] | 1758 | UnionRecord(FieldCount, CO, HfaKind::None, FieldTI, SizeInBytes, FullName, |
| 1759 | Ty->getIdentifier())); |
| 1760 | |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1761 | TypeTable.writeKnownType(UdtSourceLineRecord( |
| 1762 | UnionTI, TypeTable.writeKnownType(StringIdRecord( |
Hans Wennborg | 9a519a0 | 2016-06-22 21:22:13 +0000 | [diff] [blame] | 1763 | TypeIndex(0x0), getFullFilepath(Ty->getFile()))), |
| 1764 | Ty->getLine())); |
| 1765 | |
Hans Wennborg | 4b63a98 | 2016-06-23 22:57:25 +0000 | [diff] [blame] | 1766 | addToUDTs(Ty, UnionTI); |
| 1767 | |
Hans Wennborg | 9a519a0 | 2016-06-22 21:22:13 +0000 | [diff] [blame] | 1768 | return UnionTI; |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1769 | } |
| 1770 | |
Adrian McCarthy | 820ca54 | 2016-07-06 19:49:51 +0000 | [diff] [blame] | 1771 | std::tuple<TypeIndex, TypeIndex, unsigned, bool> |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1772 | CodeViewDebug::lowerRecordFieldList(const DICompositeType *Ty) { |
| 1773 | // Manually count members. MSVC appears to count everything that generates a |
| 1774 | // field list record. Each individual overload in a method overload group |
| 1775 | // contributes to this count, even though the overload group is a single field |
| 1776 | // list record. |
| 1777 | unsigned MemberCount = 0; |
Reid Kleckner | 1ab7eac | 2016-06-22 16:06:42 +0000 | [diff] [blame] | 1778 | ClassInfo Info = collectClassInfo(Ty); |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1779 | FieldListRecordBuilder Fields; |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1780 | |
Reid Kleckner | 9f7f3e1 | 2016-06-24 16:24:24 +0000 | [diff] [blame] | 1781 | // Create base classes. |
| 1782 | for (const DIDerivedType *I : Info.Inheritance) { |
| 1783 | if (I->getFlags() & DINode::FlagVirtual) { |
| 1784 | // Virtual base. |
| 1785 | // FIXME: Emit VBPtrOffset when the frontend provides it. |
| 1786 | unsigned VBPtrOffset = 0; |
| 1787 | // FIXME: Despite the accessor name, the offset is really in bytes. |
| 1788 | unsigned VBTableIndex = I->getOffsetInBits() / 4; |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1789 | Fields.writeMemberType(VirtualBaseClassRecord( |
Reid Kleckner | 9f7f3e1 | 2016-06-24 16:24:24 +0000 | [diff] [blame] | 1790 | translateAccessFlags(Ty->getTag(), I->getFlags()), |
| 1791 | getTypeIndex(I->getBaseType()), getVBPTypeIndex(), VBPtrOffset, |
| 1792 | VBTableIndex)); |
| 1793 | } else { |
| 1794 | assert(I->getOffsetInBits() % 8 == 0 && |
| 1795 | "bases must be on byte boundaries"); |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1796 | Fields.writeMemberType(BaseClassRecord( |
Reid Kleckner | 9f7f3e1 | 2016-06-24 16:24:24 +0000 | [diff] [blame] | 1797 | translateAccessFlags(Ty->getTag(), I->getFlags()), |
| 1798 | getTypeIndex(I->getBaseType()), I->getOffsetInBits() / 8)); |
| 1799 | } |
| 1800 | } |
| 1801 | |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1802 | // Create members. |
| 1803 | for (ClassInfo::MemberInfo &MemberInfo : Info.Members) { |
| 1804 | const DIDerivedType *Member = MemberInfo.MemberTypeNode; |
| 1805 | TypeIndex MemberBaseType = getTypeIndex(Member->getBaseType()); |
David Majnemer | 9319cbc | 2016-06-30 03:00:20 +0000 | [diff] [blame] | 1806 | StringRef MemberName = Member->getName(); |
| 1807 | MemberAccess Access = |
| 1808 | translateAccessFlags(Ty->getTag(), Member->getFlags()); |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1809 | |
| 1810 | if (Member->isStaticMember()) { |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1811 | Fields.writeMemberType( |
David Majnemer | 9319cbc | 2016-06-30 03:00:20 +0000 | [diff] [blame] | 1812 | StaticDataMemberRecord(Access, MemberBaseType, MemberName)); |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1813 | MemberCount++; |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1814 | continue; |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1815 | } |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1816 | |
Reid Kleckner | 9dac473 | 2016-08-31 15:59:30 +0000 | [diff] [blame] | 1817 | // Virtual function pointer member. |
| 1818 | if ((Member->getFlags() & DINode::FlagArtificial) && |
| 1819 | Member->getName().startswith("_vptr$")) { |
| 1820 | Fields.writeMemberType(VFPtrRecord(getTypeIndex(Member->getBaseType()))); |
| 1821 | MemberCount++; |
| 1822 | continue; |
| 1823 | } |
| 1824 | |
David Majnemer | 9319cbc | 2016-06-30 03:00:20 +0000 | [diff] [blame] | 1825 | // Data member. |
David Majnemer | 08bd744 | 2016-07-01 23:12:48 +0000 | [diff] [blame] | 1826 | uint64_t MemberOffsetInBits = |
| 1827 | Member->getOffsetInBits() + MemberInfo.BaseOffset; |
David Majnemer | 9319cbc | 2016-06-30 03:00:20 +0000 | [diff] [blame] | 1828 | if (Member->isBitField()) { |
| 1829 | uint64_t StartBitOffset = MemberOffsetInBits; |
| 1830 | if (const auto *CI = |
| 1831 | dyn_cast_or_null<ConstantInt>(Member->getStorageOffsetInBits())) { |
David Majnemer | 08bd744 | 2016-07-01 23:12:48 +0000 | [diff] [blame] | 1832 | MemberOffsetInBits = CI->getZExtValue() + MemberInfo.BaseOffset; |
David Majnemer | 9319cbc | 2016-06-30 03:00:20 +0000 | [diff] [blame] | 1833 | } |
| 1834 | StartBitOffset -= MemberOffsetInBits; |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1835 | MemberBaseType = TypeTable.writeKnownType(BitFieldRecord( |
David Majnemer | 9319cbc | 2016-06-30 03:00:20 +0000 | [diff] [blame] | 1836 | MemberBaseType, Member->getSizeInBits(), StartBitOffset)); |
| 1837 | } |
| 1838 | uint64_t MemberOffsetInBytes = MemberOffsetInBits / 8; |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1839 | Fields.writeMemberType(DataMemberRecord(Access, MemberBaseType, |
David Majnemer | 9319cbc | 2016-06-30 03:00:20 +0000 | [diff] [blame] | 1840 | MemberOffsetInBytes, MemberName)); |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1841 | MemberCount++; |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1842 | } |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1843 | |
| 1844 | // Create methods |
| 1845 | for (auto &MethodItr : Info.Methods) { |
| 1846 | StringRef Name = MethodItr.first->getString(); |
| 1847 | |
| 1848 | std::vector<OneMethodRecord> Methods; |
Reid Kleckner | 156a723 | 2016-06-22 18:31:14 +0000 | [diff] [blame] | 1849 | for (const DISubprogram *SP : MethodItr.second) { |
| 1850 | TypeIndex MethodType = getMemberFunctionType(SP, Ty); |
| 1851 | bool Introduced = SP->getFlags() & DINode::FlagIntroducedVirtual; |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1852 | |
| 1853 | unsigned VFTableOffset = -1; |
| 1854 | if (Introduced) |
| 1855 | VFTableOffset = SP->getVirtualIndex() * getPointerSizeInBytes(); |
| 1856 | |
| 1857 | Methods.push_back( |
| 1858 | OneMethodRecord(MethodType, translateMethodKindFlags(SP, Introduced), |
| 1859 | translateMethodOptionFlags(SP), |
| 1860 | translateAccessFlags(Ty->getTag(), SP->getFlags()), |
| 1861 | VFTableOffset, Name)); |
| 1862 | MemberCount++; |
| 1863 | } |
| 1864 | assert(Methods.size() > 0 && "Empty methods map entry"); |
| 1865 | if (Methods.size() == 1) |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1866 | Fields.writeMemberType(Methods[0]); |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1867 | else { |
| 1868 | TypeIndex MethodList = |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1869 | TypeTable.writeKnownType(MethodOverloadListRecord(Methods)); |
| 1870 | Fields.writeMemberType( |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1871 | OverloadedMethodRecord(Methods.size(), MethodList, Name)); |
| 1872 | } |
| 1873 | } |
Adrian McCarthy | 820ca54 | 2016-07-06 19:49:51 +0000 | [diff] [blame] | 1874 | |
| 1875 | // Create nested classes. |
| 1876 | for (const DICompositeType *Nested : Info.NestedClasses) { |
| 1877 | NestedTypeRecord R(getTypeIndex(DITypeRef(Nested)), Nested->getName()); |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1878 | Fields.writeMemberType(R); |
Adrian McCarthy | 820ca54 | 2016-07-06 19:49:51 +0000 | [diff] [blame] | 1879 | MemberCount++; |
| 1880 | } |
| 1881 | |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1882 | TypeIndex FieldTI = TypeTable.writeFieldList(Fields); |
Reid Kleckner | 9dac473 | 2016-08-31 15:59:30 +0000 | [diff] [blame] | 1883 | return std::make_tuple(FieldTI, Info.VShapeTI, MemberCount, |
Adrian McCarthy | 820ca54 | 2016-07-06 19:49:51 +0000 | [diff] [blame] | 1884 | !Info.NestedClasses.empty()); |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1885 | } |
| 1886 | |
Reid Kleckner | 9f7f3e1 | 2016-06-24 16:24:24 +0000 | [diff] [blame] | 1887 | TypeIndex CodeViewDebug::getVBPTypeIndex() { |
| 1888 | if (!VBPType.getIndex()) { |
| 1889 | // Make a 'const int *' type. |
| 1890 | ModifierRecord MR(TypeIndex::Int32(), ModifierOptions::Const); |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1891 | TypeIndex ModifiedTI = TypeTable.writeKnownType(MR); |
Reid Kleckner | 9f7f3e1 | 2016-06-24 16:24:24 +0000 | [diff] [blame] | 1892 | |
| 1893 | PointerKind PK = getPointerSizeInBytes() == 8 ? PointerKind::Near64 |
| 1894 | : PointerKind::Near32; |
| 1895 | PointerMode PM = PointerMode::Pointer; |
| 1896 | PointerOptions PO = PointerOptions::None; |
| 1897 | PointerRecord PR(ModifiedTI, PK, PM, PO, getPointerSizeInBytes()); |
| 1898 | |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 1899 | VBPType = TypeTable.writeKnownType(PR); |
Reid Kleckner | 9f7f3e1 | 2016-06-24 16:24:24 +0000 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | return VBPType; |
| 1903 | } |
| 1904 | |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1905 | TypeIndex CodeViewDebug::getTypeIndex(DITypeRef TypeRef, DITypeRef ClassTyRef) { |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1906 | const DIType *Ty = TypeRef.resolve(); |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1907 | const DIType *ClassTy = ClassTyRef.resolve(); |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1908 | |
| 1909 | // The null DIType is the void type. Don't try to hash it. |
| 1910 | if (!Ty) |
| 1911 | return TypeIndex::Void(); |
| 1912 | |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1913 | // Check if we've already translated this type. Don't try to do a |
| 1914 | // get-or-create style insertion that caches the hash lookup across the |
| 1915 | // lowerType call. It will update the TypeIndices map. |
Amjad Aboud | 76c9eb9 | 2016-06-18 10:25:07 +0000 | [diff] [blame] | 1916 | auto I = TypeIndices.find({Ty, ClassTy}); |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1917 | if (I != TypeIndices.end()) |
| 1918 | return I->second; |
| 1919 | |
Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 1920 | TypeLoweringScope S(*this); |
| 1921 | TypeIndex TI = lowerType(Ty, ClassTy); |
| 1922 | return recordTypeIndexForDINode(Ty, TI, ClassTy); |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | TypeIndex CodeViewDebug::getCompleteTypeIndex(DITypeRef TypeRef) { |
| 1926 | const DIType *Ty = TypeRef.resolve(); |
| 1927 | |
| 1928 | // The null DIType is the void type. Don't try to hash it. |
| 1929 | if (!Ty) |
| 1930 | return TypeIndex::Void(); |
| 1931 | |
| 1932 | // If this is a non-record type, the complete type index is the same as the |
| 1933 | // normal type index. Just call getTypeIndex. |
| 1934 | switch (Ty->getTag()) { |
| 1935 | case dwarf::DW_TAG_class_type: |
| 1936 | case dwarf::DW_TAG_structure_type: |
| 1937 | case dwarf::DW_TAG_union_type: |
| 1938 | break; |
| 1939 | default: |
| 1940 | return getTypeIndex(Ty); |
| 1941 | } |
| 1942 | |
| 1943 | // Check if we've already translated the complete record type. Lowering a |
| 1944 | // complete type should never trigger lowering another complete type, so we |
| 1945 | // can reuse the hash table lookup result. |
| 1946 | const auto *CTy = cast<DICompositeType>(Ty); |
| 1947 | auto InsertResult = CompleteTypeIndices.insert({CTy, TypeIndex()}); |
| 1948 | if (!InsertResult.second) |
| 1949 | return InsertResult.first->second; |
| 1950 | |
Reid Kleckner | 643dd83 | 2016-06-22 17:15:28 +0000 | [diff] [blame] | 1951 | TypeLoweringScope S(*this); |
| 1952 | |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 1953 | // Make sure the forward declaration is emitted first. It's unclear if this |
| 1954 | // is necessary, but MSVC does it, and we should follow suit until we can show |
| 1955 | // otherwise. |
| 1956 | TypeIndex FwdDeclTI = getTypeIndex(CTy); |
| 1957 | |
| 1958 | // Just use the forward decl if we don't have complete type info. This might |
| 1959 | // happen if the frontend is using modules and expects the complete definition |
| 1960 | // to be emitted elsewhere. |
| 1961 | if (CTy->isForwardDecl()) |
| 1962 | return FwdDeclTI; |
| 1963 | |
| 1964 | TypeIndex TI; |
| 1965 | switch (CTy->getTag()) { |
| 1966 | case dwarf::DW_TAG_class_type: |
| 1967 | case dwarf::DW_TAG_structure_type: |
| 1968 | TI = lowerCompleteTypeClass(CTy); |
| 1969 | break; |
| 1970 | case dwarf::DW_TAG_union_type: |
| 1971 | TI = lowerCompleteTypeUnion(CTy); |
| 1972 | break; |
| 1973 | default: |
| 1974 | llvm_unreachable("not a record"); |
| 1975 | } |
| 1976 | |
| 1977 | InsertResult.first->second = TI; |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 1978 | return TI; |
| 1979 | } |
| 1980 | |
Reid Kleckner | 643dd83 | 2016-06-22 17:15:28 +0000 | [diff] [blame] | 1981 | /// Emit all the deferred complete record types. Try to do this in FIFO order, |
Amjad Aboud | acee568 | 2016-07-12 12:06:34 +0000 | [diff] [blame] | 1982 | /// and do this until fixpoint, as each complete record type typically |
| 1983 | /// references |
Reid Kleckner | 643dd83 | 2016-06-22 17:15:28 +0000 | [diff] [blame] | 1984 | /// many other record types. |
| 1985 | void CodeViewDebug::emitDeferredCompleteTypes() { |
| 1986 | SmallVector<const DICompositeType *, 4> TypesToEmit; |
| 1987 | while (!DeferredCompleteTypes.empty()) { |
| 1988 | std::swap(DeferredCompleteTypes, TypesToEmit); |
| 1989 | for (const DICompositeType *RecordTy : TypesToEmit) |
| 1990 | getCompleteTypeIndex(RecordTy); |
| 1991 | TypesToEmit.clear(); |
| 1992 | } |
| 1993 | } |
| 1994 | |
Reid Kleckner | 10dd55c | 2016-06-24 17:55:40 +0000 | [diff] [blame] | 1995 | void CodeViewDebug::emitLocalVariableList(ArrayRef<LocalVariable> Locals) { |
| 1996 | // Get the sorted list of parameters and emit them first. |
| 1997 | SmallVector<const LocalVariable *, 6> Params; |
| 1998 | for (const LocalVariable &L : Locals) |
| 1999 | if (L.DIVar->isParameter()) |
| 2000 | Params.push_back(&L); |
| 2001 | std::sort(Params.begin(), Params.end(), |
| 2002 | [](const LocalVariable *L, const LocalVariable *R) { |
| 2003 | return L->DIVar->getArg() < R->DIVar->getArg(); |
| 2004 | }); |
| 2005 | for (const LocalVariable *L : Params) |
| 2006 | emitLocalVariable(*L); |
| 2007 | |
| 2008 | // Next emit all non-parameters in the order that we found them. |
| 2009 | for (const LocalVariable &L : Locals) |
| 2010 | if (!L.DIVar->isParameter()) |
| 2011 | emitLocalVariable(L); |
| 2012 | } |
| 2013 | |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 2014 | void CodeViewDebug::emitLocalVariable(const LocalVariable &Var) { |
| 2015 | // LocalSym record, see SymbolRecord.h for more info. |
| 2016 | MCSymbol *LocalBegin = MMI->getContext().createTempSymbol(), |
| 2017 | *LocalEnd = MMI->getContext().createTempSymbol(); |
| 2018 | OS.AddComment("Record length"); |
| 2019 | OS.emitAbsoluteSymbolDiff(LocalEnd, LocalBegin, 2); |
| 2020 | OS.EmitLabel(LocalBegin); |
| 2021 | |
| 2022 | OS.AddComment("Record kind: S_LOCAL"); |
Zachary Turner | 63a2846 | 2016-05-17 23:50:21 +0000 | [diff] [blame] | 2023 | OS.EmitIntValue(unsigned(SymbolKind::S_LOCAL), 2); |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 2024 | |
Zachary Turner | 63a2846 | 2016-05-17 23:50:21 +0000 | [diff] [blame] | 2025 | LocalSymFlags Flags = LocalSymFlags::None; |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 2026 | if (Var.DIVar->isParameter()) |
Zachary Turner | 63a2846 | 2016-05-17 23:50:21 +0000 | [diff] [blame] | 2027 | Flags |= LocalSymFlags::IsParameter; |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 2028 | if (Var.DefRanges.empty()) |
Zachary Turner | 63a2846 | 2016-05-17 23:50:21 +0000 | [diff] [blame] | 2029 | Flags |= LocalSymFlags::IsOptimizedOut; |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 2030 | |
| 2031 | OS.AddComment("TypeIndex"); |
Reid Kleckner | a8d5740 | 2016-06-03 15:58:20 +0000 | [diff] [blame] | 2032 | TypeIndex TI = getCompleteTypeIndex(Var.DIVar->getType()); |
Reid Kleckner | 5acacbb | 2016-06-01 17:05:51 +0000 | [diff] [blame] | 2033 | OS.EmitIntValue(TI.getIndex(), 4); |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 2034 | OS.AddComment("Flags"); |
Zachary Turner | 63a2846 | 2016-05-17 23:50:21 +0000 | [diff] [blame] | 2035 | OS.EmitIntValue(static_cast<uint16_t>(Flags), 2); |
David Majnemer | 1256125 | 2016-03-13 10:53:30 +0000 | [diff] [blame] | 2036 | // Truncate the name so we won't overflow the record length field. |
David Majnemer | b9456a5 | 2016-03-14 05:15:09 +0000 | [diff] [blame] | 2037 | emitNullTerminatedSymbolName(OS, Var.DIVar->getName()); |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 2038 | OS.EmitLabel(LocalEnd); |
| 2039 | |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 2040 | // Calculate the on disk prefix of the appropriate def range record. The |
| 2041 | // records and on disk formats are described in SymbolRecords.h. BytePrefix |
| 2042 | // should be big enough to hold all forms without memory allocation. |
| 2043 | SmallString<20> BytePrefix; |
| 2044 | for (const LocalVarDefRange &DefRange : Var.DefRanges) { |
| 2045 | BytePrefix.clear(); |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 2046 | if (DefRange.InMemory) { |
Reid Kleckner | 2b3e642 | 2016-10-05 21:21:33 +0000 | [diff] [blame] | 2047 | uint16_t RegRelFlags = 0; |
| 2048 | if (DefRange.IsSubfield) { |
| 2049 | RegRelFlags = DefRangeRegisterRelSym::IsSubfieldFlag | |
| 2050 | (DefRange.StructOffset |
| 2051 | << DefRangeRegisterRelSym::OffsetInParentShift); |
| 2052 | } |
| 2053 | DefRangeRegisterRelSym Sym(DefRange.CVRegister, RegRelFlags, |
| 2054 | DefRange.DataOffset, None); |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 2055 | ulittle16_t SymKind = ulittle16_t(S_DEFRANGE_REGISTER_REL); |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 2056 | BytePrefix += |
| 2057 | StringRef(reinterpret_cast<const char *>(&SymKind), sizeof(SymKind)); |
Zachary Turner | a78ecd1 | 2016-05-23 18:49:06 +0000 | [diff] [blame] | 2058 | BytePrefix += |
| 2059 | StringRef(reinterpret_cast<const char *>(&Sym.Header), |
| 2060 | sizeof(Sym.Header) - sizeof(LocalVariableAddrRange)); |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 2061 | } else { |
| 2062 | assert(DefRange.DataOffset == 0 && "unexpected offset into register"); |
Reid Kleckner | 2b3e642 | 2016-10-05 21:21:33 +0000 | [diff] [blame] | 2063 | if (DefRange.IsSubfield) { |
| 2064 | // Unclear what matters here. |
| 2065 | DefRangeSubfieldRegisterSym Sym(DefRange.CVRegister, 0, |
| 2066 | DefRange.StructOffset, None); |
| 2067 | ulittle16_t SymKind = ulittle16_t(S_DEFRANGE_SUBFIELD_REGISTER); |
| 2068 | BytePrefix += StringRef(reinterpret_cast<const char *>(&SymKind), |
| 2069 | sizeof(SymKind)); |
| 2070 | BytePrefix += |
| 2071 | StringRef(reinterpret_cast<const char *>(&Sym.Header), |
| 2072 | sizeof(Sym.Header) - sizeof(LocalVariableAddrRange)); |
| 2073 | } else { |
| 2074 | // Unclear what matters here. |
| 2075 | DefRangeRegisterSym Sym(DefRange.CVRegister, 0, None); |
| 2076 | ulittle16_t SymKind = ulittle16_t(S_DEFRANGE_REGISTER); |
| 2077 | BytePrefix += StringRef(reinterpret_cast<const char *>(&SymKind), |
| 2078 | sizeof(SymKind)); |
| 2079 | BytePrefix += |
| 2080 | StringRef(reinterpret_cast<const char *>(&Sym.Header), |
| 2081 | sizeof(Sym.Header) - sizeof(LocalVariableAddrRange)); |
| 2082 | } |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 2083 | } |
| 2084 | OS.EmitCVDefRangeDirective(DefRange.Ranges, BytePrefix); |
| 2085 | } |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 2086 | } |
| 2087 | |
Reid Kleckner | 70f5bc9 | 2016-01-14 19:25:04 +0000 | [diff] [blame] | 2088 | void CodeViewDebug::endFunction(const MachineFunction *MF) { |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 2089 | if (!Asm || !CurFn) // We haven't created any debug info for this function. |
| 2090 | return; |
| 2091 | |
Timur Iskhodzhanov | b5b7a61 | 2014-03-26 11:24:36 +0000 | [diff] [blame] | 2092 | const Function *GV = MF->getFunction(); |
Yaron Keren | 6d3194f | 2014-06-20 10:26:56 +0000 | [diff] [blame] | 2093 | assert(FnDebugInfo.count(GV)); |
Timur Iskhodzhanov | b5b7a61 | 2014-03-26 11:24:36 +0000 | [diff] [blame] | 2094 | assert(CurFn == &FnDebugInfo[GV]); |
| 2095 | |
Pete Cooper | adebb93 | 2016-03-11 02:14:16 +0000 | [diff] [blame] | 2096 | collectVariableInfo(GV->getSubprogram()); |
Reid Kleckner | 876330d | 2016-02-12 21:48:30 +0000 | [diff] [blame] | 2097 | |
| 2098 | DebugHandlerBase::endFunction(MF); |
| 2099 | |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 2100 | // Don't emit anything if we don't have any line tables. |
| 2101 | if (!CurFn->HaveLineInfo) { |
Timur Iskhodzhanov | b5b7a61 | 2014-03-26 11:24:36 +0000 | [diff] [blame] | 2102 | FnDebugInfo.erase(GV); |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 2103 | CurFn = nullptr; |
| 2104 | return; |
Timur Iskhodzhanov | 8499a12 | 2014-03-26 09:50:36 +0000 | [diff] [blame] | 2105 | } |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 2106 | |
| 2107 | CurFn->End = Asm->getFunctionEnd(); |
| 2108 | |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 2109 | CurFn = nullptr; |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 2110 | } |
| 2111 | |
Reid Kleckner | 70f5bc9 | 2016-01-14 19:25:04 +0000 | [diff] [blame] | 2112 | void CodeViewDebug::beginInstruction(const MachineInstr *MI) { |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 2113 | DebugHandlerBase::beginInstruction(MI); |
| 2114 | |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 2115 | // Ignore DBG_VALUE locations and function prologue. |
David Majnemer | 67f684e | 2016-07-28 05:03:22 +0000 | [diff] [blame] | 2116 | if (!Asm || !CurFn || MI->isDebugValue() || |
| 2117 | MI->getFlag(MachineInstr::FrameSetup)) |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 2118 | return; |
| 2119 | DebugLoc DL = MI->getDebugLoc(); |
Duncan P. N. Exon Smith | 9dffcd0 | 2015-03-30 19:14:47 +0000 | [diff] [blame] | 2120 | if (DL == PrevInstLoc || !DL) |
Timur Iskhodzhanov | f166f6c | 2014-01-30 01:39:17 +0000 | [diff] [blame] | 2121 | return; |
| 2122 | maybeRecordLocation(DL, Asm->MF); |
| 2123 | } |
Reid Kleckner | 6f3406d | 2016-06-07 00:02:03 +0000 | [diff] [blame] | 2124 | |
| 2125 | MCSymbol *CodeViewDebug::beginCVSubsection(ModuleSubstreamKind Kind) { |
| 2126 | MCSymbol *BeginLabel = MMI->getContext().createTempSymbol(), |
| 2127 | *EndLabel = MMI->getContext().createTempSymbol(); |
| 2128 | OS.EmitIntValue(unsigned(Kind), 4); |
| 2129 | OS.AddComment("Subsection size"); |
| 2130 | OS.emitAbsoluteSymbolDiff(EndLabel, BeginLabel, 4); |
| 2131 | OS.EmitLabel(BeginLabel); |
Adrian McCarthy | c64acfd | 2016-09-20 17:20:51 +0000 | [diff] [blame] | 2132 | if (Kind == ModuleSubstreamKind::Symbols) |
| 2133 | emitCompilerInformation(); |
Reid Kleckner | 6f3406d | 2016-06-07 00:02:03 +0000 | [diff] [blame] | 2134 | return EndLabel; |
| 2135 | } |
| 2136 | |
| 2137 | void CodeViewDebug::endCVSubsection(MCSymbol *EndLabel) { |
| 2138 | OS.EmitLabel(EndLabel); |
| 2139 | // Every subsection must be aligned to a 4-byte boundary. |
| 2140 | OS.EmitValueToAlignment(4); |
| 2141 | } |
| 2142 | |
David Majnemer | 3128b10 | 2016-06-15 18:00:01 +0000 | [diff] [blame] | 2143 | void CodeViewDebug::emitDebugInfoForUDTs( |
| 2144 | ArrayRef<std::pair<std::string, TypeIndex>> UDTs) { |
| 2145 | for (const std::pair<std::string, codeview::TypeIndex> &UDT : UDTs) { |
| 2146 | MCSymbol *UDTRecordBegin = MMI->getContext().createTempSymbol(), |
| 2147 | *UDTRecordEnd = MMI->getContext().createTempSymbol(); |
| 2148 | OS.AddComment("Record length"); |
| 2149 | OS.emitAbsoluteSymbolDiff(UDTRecordEnd, UDTRecordBegin, 2); |
| 2150 | OS.EmitLabel(UDTRecordBegin); |
| 2151 | |
| 2152 | OS.AddComment("Record kind: S_UDT"); |
| 2153 | OS.EmitIntValue(unsigned(SymbolKind::S_UDT), 2); |
| 2154 | |
| 2155 | OS.AddComment("Type"); |
| 2156 | OS.EmitIntValue(UDT.second.getIndex(), 4); |
| 2157 | |
| 2158 | emitNullTerminatedSymbolName(OS, UDT.first); |
| 2159 | OS.EmitLabel(UDTRecordEnd); |
| 2160 | } |
| 2161 | } |
| 2162 | |
Reid Kleckner | 6f3406d | 2016-06-07 00:02:03 +0000 | [diff] [blame] | 2163 | void CodeViewDebug::emitDebugInfoForGlobals() { |
Peter Collingbourne | d4135bb | 2016-09-13 01:12:59 +0000 | [diff] [blame] | 2164 | DenseMap<const DIGlobalVariable *, const GlobalVariable *> GlobalMap; |
| 2165 | for (const GlobalVariable &GV : MMI->getModule()->globals()) { |
| 2166 | SmallVector<MDNode *, 1> MDs; |
| 2167 | GV.getMetadata(LLVMContext::MD_dbg, MDs); |
| 2168 | for (MDNode *MD : MDs) |
| 2169 | GlobalMap[cast<DIGlobalVariable>(MD)] = &GV; |
| 2170 | } |
| 2171 | |
Reid Kleckner | 6f3406d | 2016-06-07 00:02:03 +0000 | [diff] [blame] | 2172 | NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("llvm.dbg.cu"); |
| 2173 | for (const MDNode *Node : CUs->operands()) { |
| 2174 | const auto *CU = cast<DICompileUnit>(Node); |
| 2175 | |
| 2176 | // First, emit all globals that are not in a comdat in a single symbol |
| 2177 | // substream. MSVC doesn't like it if the substream is empty, so only open |
| 2178 | // it if we have at least one global to emit. |
| 2179 | switchToDebugSectionForSymbol(nullptr); |
| 2180 | MCSymbol *EndLabel = nullptr; |
| 2181 | for (const DIGlobalVariable *G : CU->getGlobalVariables()) { |
Peter Collingbourne | d4135bb | 2016-09-13 01:12:59 +0000 | [diff] [blame] | 2182 | if (const auto *GV = GlobalMap.lookup(G)) |
David Majnemer | 577be0f | 2016-06-15 00:19:52 +0000 | [diff] [blame] | 2183 | if (!GV->hasComdat() && !GV->isDeclarationForLinker()) { |
Reid Kleckner | 6f3406d | 2016-06-07 00:02:03 +0000 | [diff] [blame] | 2184 | if (!EndLabel) { |
| 2185 | OS.AddComment("Symbol subsection for globals"); |
| 2186 | EndLabel = beginCVSubsection(ModuleSubstreamKind::Symbols); |
| 2187 | } |
Peter Collingbourne | d4135bb | 2016-09-13 01:12:59 +0000 | [diff] [blame] | 2188 | emitDebugInfoForGlobal(G, GV, Asm->getSymbol(GV)); |
Reid Kleckner | 6f3406d | 2016-06-07 00:02:03 +0000 | [diff] [blame] | 2189 | } |
| 2190 | } |
| 2191 | if (EndLabel) |
| 2192 | endCVSubsection(EndLabel); |
| 2193 | |
| 2194 | // Second, emit each global that is in a comdat into its own .debug$S |
| 2195 | // section along with its own symbol substream. |
| 2196 | for (const DIGlobalVariable *G : CU->getGlobalVariables()) { |
Peter Collingbourne | d4135bb | 2016-09-13 01:12:59 +0000 | [diff] [blame] | 2197 | if (const auto *GV = GlobalMap.lookup(G)) { |
Reid Kleckner | 6f3406d | 2016-06-07 00:02:03 +0000 | [diff] [blame] | 2198 | if (GV->hasComdat()) { |
| 2199 | MCSymbol *GVSym = Asm->getSymbol(GV); |
| 2200 | OS.AddComment("Symbol subsection for " + |
| 2201 | Twine(GlobalValue::getRealLinkageName(GV->getName()))); |
| 2202 | switchToDebugSectionForSymbol(GVSym); |
| 2203 | EndLabel = beginCVSubsection(ModuleSubstreamKind::Symbols); |
Peter Collingbourne | d4135bb | 2016-09-13 01:12:59 +0000 | [diff] [blame] | 2204 | emitDebugInfoForGlobal(G, GV, GVSym); |
Reid Kleckner | 6f3406d | 2016-06-07 00:02:03 +0000 | [diff] [blame] | 2205 | endCVSubsection(EndLabel); |
| 2206 | } |
| 2207 | } |
| 2208 | } |
| 2209 | } |
| 2210 | } |
| 2211 | |
Hans Wennborg | b510b45 | 2016-06-23 16:33:53 +0000 | [diff] [blame] | 2212 | void CodeViewDebug::emitDebugInfoForRetainedTypes() { |
| 2213 | NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("llvm.dbg.cu"); |
| 2214 | for (const MDNode *Node : CUs->operands()) { |
| 2215 | for (auto *Ty : cast<DICompileUnit>(Node)->getRetainedTypes()) { |
| 2216 | if (DIType *RT = dyn_cast<DIType>(Ty)) { |
| 2217 | getTypeIndex(RT); |
| 2218 | // FIXME: Add to global/local DTU list. |
| 2219 | } |
| 2220 | } |
| 2221 | } |
| 2222 | } |
| 2223 | |
Reid Kleckner | 6f3406d | 2016-06-07 00:02:03 +0000 | [diff] [blame] | 2224 | void CodeViewDebug::emitDebugInfoForGlobal(const DIGlobalVariable *DIGV, |
Peter Collingbourne | d4135bb | 2016-09-13 01:12:59 +0000 | [diff] [blame] | 2225 | const GlobalVariable *GV, |
Reid Kleckner | 6f3406d | 2016-06-07 00:02:03 +0000 | [diff] [blame] | 2226 | MCSymbol *GVSym) { |
| 2227 | // DataSym record, see SymbolRecord.h for more info. |
| 2228 | // FIXME: Thread local data, etc |
| 2229 | MCSymbol *DataBegin = MMI->getContext().createTempSymbol(), |
| 2230 | *DataEnd = MMI->getContext().createTempSymbol(); |
| 2231 | OS.AddComment("Record length"); |
| 2232 | OS.emitAbsoluteSymbolDiff(DataEnd, DataBegin, 2); |
| 2233 | OS.EmitLabel(DataBegin); |
David Majnemer | 7abd269 | 2016-07-06 21:07:47 +0000 | [diff] [blame] | 2234 | if (DIGV->isLocalToUnit()) { |
David Majnemer | a54fe1a | 2016-07-07 05:14:21 +0000 | [diff] [blame] | 2235 | if (GV->isThreadLocal()) { |
| 2236 | OS.AddComment("Record kind: S_LTHREAD32"); |
| 2237 | OS.EmitIntValue(unsigned(SymbolKind::S_LTHREAD32), 2); |
| 2238 | } else { |
| 2239 | OS.AddComment("Record kind: S_LDATA32"); |
| 2240 | OS.EmitIntValue(unsigned(SymbolKind::S_LDATA32), 2); |
| 2241 | } |
David Majnemer | 7abd269 | 2016-07-06 21:07:47 +0000 | [diff] [blame] | 2242 | } else { |
David Majnemer | a54fe1a | 2016-07-07 05:14:21 +0000 | [diff] [blame] | 2243 | if (GV->isThreadLocal()) { |
| 2244 | OS.AddComment("Record kind: S_GTHREAD32"); |
| 2245 | OS.EmitIntValue(unsigned(SymbolKind::S_GTHREAD32), 2); |
| 2246 | } else { |
| 2247 | OS.AddComment("Record kind: S_GDATA32"); |
| 2248 | OS.EmitIntValue(unsigned(SymbolKind::S_GDATA32), 2); |
| 2249 | } |
David Majnemer | 7abd269 | 2016-07-06 21:07:47 +0000 | [diff] [blame] | 2250 | } |
Reid Kleckner | 6f3406d | 2016-06-07 00:02:03 +0000 | [diff] [blame] | 2251 | OS.AddComment("Type"); |
| 2252 | OS.EmitIntValue(getCompleteTypeIndex(DIGV->getType()).getIndex(), 4); |
| 2253 | OS.AddComment("DataOffset"); |
| 2254 | OS.EmitCOFFSecRel32(GVSym); |
| 2255 | OS.AddComment("Segment"); |
| 2256 | OS.EmitCOFFSectionIndex(GVSym); |
| 2257 | OS.AddComment("Name"); |
| 2258 | emitNullTerminatedSymbolName(OS, DIGV->getName()); |
| 2259 | OS.EmitLabel(DataEnd); |
| 2260 | } |