Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/DwarfDebug.cpp - Dwarf Debug Framework ---------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains support for writing dwarf debug info into asm files. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Chris Lattner | 6cde3e6 | 2010-03-09 00:39:24 +0000 | [diff] [blame] | 13 | |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 14 | #define DEBUG_TYPE "dwarfdebug" |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 15 | #include "DwarfDebug.h" |
Chris Lattner | 74e41f9 | 2010-04-05 05:24:55 +0000 | [diff] [blame] | 16 | #include "DIE.h" |
Eric Christopher | 09ac3d8 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 17 | #include "DwarfAccelTable.h" |
Devang Patel | 8b9df62 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 18 | #include "DwarfCompileUnit.h" |
Bill Wendling | 57fbba4 | 2010-04-05 22:59:21 +0000 | [diff] [blame] | 19 | #include "llvm/Constants.h" |
Bill Wendling | 0bcbd1d | 2012-06-28 00:05:13 +0000 | [diff] [blame] | 20 | #include "llvm/DebugInfo.h" |
Bill Wendling | 16eeb6f | 2012-06-29 08:32:07 +0000 | [diff] [blame] | 21 | #include "llvm/DIBuilder.h" |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 22 | #include "llvm/Module.h" |
Devang Patel | e449d1f | 2011-01-20 00:02:16 +0000 | [diff] [blame] | 23 | #include "llvm/Instructions.h" |
David Greene | b2c66fc | 2009-08-19 21:52:55 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/MachineFunction.h" |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Chris Lattner | b7db733 | 2010-03-09 01:58:53 +0000 | [diff] [blame] | 26 | #include "llvm/MC/MCAsmInfo.h" |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 27 | #include "llvm/MC/MCSection.h" |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 28 | #include "llvm/MC/MCStreamer.h" |
Chris Lattner | b7db733 | 2010-03-09 01:58:53 +0000 | [diff] [blame] | 29 | #include "llvm/MC/MCSymbol.h" |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 30 | #include "llvm/DataLayout.h" |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 31 | #include "llvm/Target/TargetFrameLowering.h" |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 32 | #include "llvm/Target/TargetLoweringObjectFile.h" |
Chris Lattner | 9d1c1ad | 2010-04-04 18:06:11 +0000 | [diff] [blame] | 33 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 34 | #include "llvm/Target/TargetRegisterInfo.h" |
Devang Patel | 2a4a3b7 | 2010-04-19 19:14:02 +0000 | [diff] [blame] | 35 | #include "llvm/Target/TargetOptions.h" |
Devang Patel | 9a31f0f | 2010-10-25 20:45:32 +0000 | [diff] [blame] | 36 | #include "llvm/ADT/Statistic.h" |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 37 | #include "llvm/ADT/STLExtras.h" |
Chris Lattner | 23132b1 | 2009-08-24 03:52:50 +0000 | [diff] [blame] | 38 | #include "llvm/ADT/StringExtras.h" |
Bill Wendling | 16eeb6f | 2012-06-29 08:32:07 +0000 | [diff] [blame] | 39 | #include "llvm/ADT/Triple.h" |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 40 | #include "llvm/Support/CommandLine.h" |
Daniel Dunbar | 6e4bdfc | 2009-10-13 06:47:08 +0000 | [diff] [blame] | 41 | #include "llvm/Support/Debug.h" |
| 42 | #include "llvm/Support/ErrorHandling.h" |
Devang Patel | 3139fcf | 2010-01-26 21:39:14 +0000 | [diff] [blame] | 43 | #include "llvm/Support/ValueHandle.h" |
Chris Lattner | 0ad9c91 | 2010-01-22 22:09:00 +0000 | [diff] [blame] | 44 | #include "llvm/Support/FormattedStream.h" |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 45 | #include "llvm/Support/Timer.h" |
Michael J. Spencer | 1f6efa3 | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 46 | #include "llvm/Support/Path.h" |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 47 | using namespace llvm; |
| 48 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 49 | static cl::opt<bool> DisableDebugInfoPrinting("disable-debug-info-print", |
Devang Patel | 6140962 | 2010-07-07 20:12:52 +0000 | [diff] [blame] | 50 | cl::Hidden, |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 51 | cl::desc("Disable debug info printing")); |
| 52 | |
Dan Gohman | 281d65d | 2010-05-07 01:08:53 +0000 | [diff] [blame] | 53 | static cl::opt<bool> UnknownLocations("use-unknown-locations", cl::Hidden, |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 54 | cl::desc("Make an absence of debug location information explicit."), |
Dan Gohman | 281d65d | 2010-05-07 01:08:53 +0000 | [diff] [blame] | 55 | cl::init(false)); |
| 56 | |
Eric Christopher | 20f47ab | 2012-08-23 22:36:40 +0000 | [diff] [blame] | 57 | namespace { |
| 58 | enum DefaultOnOff { |
| 59 | Default, Enable, Disable |
| 60 | }; |
| 61 | } |
Eric Christopher | 09ac3d8 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 62 | |
Eric Christopher | 20f47ab | 2012-08-23 22:36:40 +0000 | [diff] [blame] | 63 | static cl::opt<DefaultOnOff> DwarfAccelTables("dwarf-accel-tables", cl::Hidden, |
| 64 | cl::desc("Output prototype dwarf accelerator tables."), |
| 65 | cl::values( |
| 66 | clEnumVal(Default, "Default for platform"), |
| 67 | clEnumVal(Enable, "Enabled"), |
| 68 | clEnumVal(Disable, "Disabled"), |
| 69 | clEnumValEnd), |
| 70 | cl::init(Default)); |
| 71 | |
| 72 | static cl::opt<DefaultOnOff> DarwinGDBCompat("darwin-gdb-compat", cl::Hidden, |
Eric Christopher | 10cb744 | 2012-08-23 07:10:46 +0000 | [diff] [blame] | 73 | cl::desc("Compatibility with Darwin gdb."), |
Eric Christopher | 20f47ab | 2012-08-23 22:36:40 +0000 | [diff] [blame] | 74 | cl::values( |
| 75 | clEnumVal(Default, "Default for platform"), |
| 76 | clEnumVal(Enable, "Enabled"), |
| 77 | clEnumVal(Disable, "Disabled"), |
| 78 | clEnumValEnd), |
| 79 | cl::init(Default)); |
Eric Christopher | 10cb744 | 2012-08-23 07:10:46 +0000 | [diff] [blame] | 80 | |
Bill Wendling | 5f017e8 | 2010-04-07 09:28:04 +0000 | [diff] [blame] | 81 | namespace { |
| 82 | const char *DWARFGroupName = "DWARF Emission"; |
| 83 | const char *DbgTimerName = "DWARF Debug Writer"; |
| 84 | } // end anonymous namespace |
| 85 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 86 | //===----------------------------------------------------------------------===// |
| 87 | |
| 88 | /// Configuration values for initial hash set sizes (log2). |
| 89 | /// |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 90 | static const unsigned InitAbbreviationsSetSize = 9; // log2(512) |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 91 | |
| 92 | namespace llvm { |
| 93 | |
Nick Lewycky | 3bbb6f7 | 2011-07-29 03:49:23 +0000 | [diff] [blame] | 94 | DIType DbgVariable::getType() const { |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 95 | DIType Ty = Var.getType(); |
| 96 | // FIXME: isBlockByrefVariable should be reformulated in terms of complex |
| 97 | // addresses instead. |
| 98 | if (Var.isBlockByrefVariable()) { |
| 99 | /* Byref variables, in Blocks, are declared by the programmer as |
| 100 | "SomeType VarName;", but the compiler creates a |
| 101 | __Block_byref_x_VarName struct, and gives the variable VarName |
| 102 | either the struct, or a pointer to the struct, as its type. This |
| 103 | is necessary for various behind-the-scenes things the compiler |
| 104 | needs to do with by-reference variables in blocks. |
| 105 | |
| 106 | However, as far as the original *programmer* is concerned, the |
| 107 | variable should still have type 'SomeType', as originally declared. |
| 108 | |
| 109 | The following function dives into the __Block_byref_x_VarName |
| 110 | struct to find the original type of the variable. This will be |
| 111 | passed back to the code generating the type for the Debug |
| 112 | Information Entry for the variable 'VarName'. 'VarName' will then |
| 113 | have the original type 'SomeType' in its debug information. |
| 114 | |
| 115 | The original type 'SomeType' will be the type of the field named |
| 116 | 'VarName' inside the __Block_byref_x_VarName struct. |
| 117 | |
| 118 | NOTE: In order for this to not completely fail on the debugger |
| 119 | side, the Debug Information Entry for the variable VarName needs to |
| 120 | have a DW_AT_location that tells the debugger how to unwind through |
| 121 | the pointers and __Block_byref_x_VarName struct to find the actual |
| 122 | value of the variable. The function addBlockByrefType does this. */ |
| 123 | DIType subType = Ty; |
| 124 | unsigned tag = Ty.getTag(); |
| 125 | |
| 126 | if (tag == dwarf::DW_TAG_pointer_type) { |
| 127 | DIDerivedType DTy = DIDerivedType(Ty); |
| 128 | subType = DTy.getTypeDerivedFrom(); |
| 129 | } |
| 130 | |
| 131 | DICompositeType blockStruct = DICompositeType(subType); |
| 132 | DIArray Elements = blockStruct.getTypeArray(); |
| 133 | |
| 134 | for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { |
| 135 | DIDescriptor Element = Elements.getElement(i); |
| 136 | DIDerivedType DT = DIDerivedType(Element); |
| 137 | if (getName() == DT.getName()) |
| 138 | return (DT.getTypeDerivedFrom()); |
Devang Patel | 8bd11de | 2010-08-09 21:01:39 +0000 | [diff] [blame] | 139 | } |
Devang Patel | 8bd11de | 2010-08-09 21:01:39 +0000 | [diff] [blame] | 140 | } |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 141 | return Ty; |
| 142 | } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 143 | |
Chris Lattner | ea76186 | 2010-04-05 04:09:20 +0000 | [diff] [blame] | 144 | } // end llvm namespace |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 145 | |
Chris Lattner | 49cd664 | 2010-04-05 05:11:15 +0000 | [diff] [blame] | 146 | DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M) |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 147 | : Asm(A), MMI(Asm->MMI), FirstCU(0), |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 148 | AbbreviationsSet(InitAbbreviationsSetSize), |
Benjamin Kramer | f33a79c | 2012-06-09 10:34:15 +0000 | [diff] [blame] | 149 | SourceIdMap(DIEValueAllocator), StringPool(DIEValueAllocator), |
Eric Christopher | 6635cad | 2012-08-01 18:19:01 +0000 | [diff] [blame] | 150 | PrevLabel(NULL) { |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 151 | NextStringPoolNumber = 0; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 152 | |
Rafael Espindola | f2b0423 | 2011-05-06 14:56:22 +0000 | [diff] [blame] | 153 | DwarfInfoSectionSym = DwarfAbbrevSectionSym = 0; |
Chris Lattner | 4ad1efe | 2010-04-04 23:10:38 +0000 | [diff] [blame] | 154 | DwarfStrSectionSym = TextSectionSym = 0; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 155 | DwarfDebugRangeSectionSym = DwarfDebugLocSectionSym = 0; |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 156 | FunctionBeginSym = FunctionEndSym = 0; |
Eric Christopher | 60777d8 | 2012-04-02 17:58:52 +0000 | [diff] [blame] | 157 | |
Eric Christopher | 10cb744 | 2012-08-23 07:10:46 +0000 | [diff] [blame] | 158 | // Turn on accelerator tables and older gdb compatibility |
| 159 | // for Darwin. |
Eric Christopher | 20f47ab | 2012-08-23 22:36:40 +0000 | [diff] [blame] | 160 | bool isDarwin = Triple(M->getTargetTriple()).isOSDarwin(); |
| 161 | if (DarwinGDBCompat == Default) { |
| 162 | if (isDarwin) |
| 163 | isDarwinGDBCompat = true; |
| 164 | else |
| 165 | isDarwinGDBCompat = false; |
| 166 | } else |
| 167 | isDarwinGDBCompat = DarwinGDBCompat == Enable ? true : false; |
Eric Christopher | c1610fa | 2012-08-23 22:36:36 +0000 | [diff] [blame] | 168 | |
Eric Christopher | 20f47ab | 2012-08-23 22:36:40 +0000 | [diff] [blame] | 169 | if (DwarfAccelTables == Default) { |
| 170 | if (isDarwin) |
| 171 | hasDwarfAccelTables = true; |
| 172 | else |
| 173 | hasDwarfAccelTables = false; |
| 174 | } else |
| 175 | hasDwarfAccelTables = DwarfAccelTables == Enable ? true : false; |
| 176 | |
Dan Gohman | 03c3dc7 | 2010-06-18 15:56:31 +0000 | [diff] [blame] | 177 | { |
| 178 | NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled); |
| 179 | beginModule(M); |
Torok Edwin | 9c42107 | 2010-04-07 10:44:46 +0000 | [diff] [blame] | 180 | } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 181 | } |
| 182 | DwarfDebug::~DwarfDebug() { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Eric Christopher | d8a8752 | 2011-11-07 09:18:38 +0000 | [diff] [blame] | 185 | /// EmitSectionSym - Switch to the specified MCSection and emit an assembler |
| 186 | /// temporary label to it if SymbolStem is specified. |
| 187 | static MCSymbol *EmitSectionSym(AsmPrinter *Asm, const MCSection *Section, |
| 188 | const char *SymbolStem = 0) { |
| 189 | Asm->OutStreamer.SwitchSection(Section); |
| 190 | if (!SymbolStem) return 0; |
| 191 | |
| 192 | MCSymbol *TmpSym = Asm->GetTempSymbol(SymbolStem); |
| 193 | Asm->OutStreamer.EmitLabel(TmpSym); |
| 194 | return TmpSym; |
| 195 | } |
| 196 | |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 197 | MCSymbol *DwarfDebug::getStringPool() { |
| 198 | return Asm->GetTempSymbol("section_str"); |
| 199 | } |
| 200 | |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 201 | MCSymbol *DwarfDebug::getStringPoolEntry(StringRef Str) { |
| 202 | std::pair<MCSymbol*, unsigned> &Entry = StringPool[Str]; |
| 203 | if (Entry.first) return Entry.first; |
| 204 | |
| 205 | Entry.second = NextStringPoolNumber++; |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 206 | return Entry.first = Asm->GetTempSymbol("string", Entry.second); |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 209 | /// assignAbbrevNumber - Define a unique number for the abbreviation. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 210 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 211 | void DwarfDebug::assignAbbrevNumber(DIEAbbrev &Abbrev) { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 212 | // Profile the node so that we can make it unique. |
| 213 | FoldingSetNodeID ID; |
| 214 | Abbrev.Profile(ID); |
| 215 | |
| 216 | // Check the set for priors. |
| 217 | DIEAbbrev *InSet = AbbreviationsSet.GetOrInsertNode(&Abbrev); |
| 218 | |
| 219 | // If it's newly added. |
| 220 | if (InSet == &Abbrev) { |
| 221 | // Add to abbreviation list. |
| 222 | Abbreviations.push_back(&Abbrev); |
| 223 | |
| 224 | // Assign the vector position + 1 as its number. |
| 225 | Abbrev.setNumber(Abbreviations.size()); |
| 226 | } else { |
| 227 | // Assign existing abbreviation number. |
| 228 | Abbrev.setNumber(InSet->getNumber()); |
| 229 | } |
| 230 | } |
| 231 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 232 | /// getRealLinkageName - If special LLVM prefix that is used to inform the asm |
Devang Patel | 351ca33 | 2010-01-05 01:46:14 +0000 | [diff] [blame] | 233 | /// printer to not emit usual symbol prefix before the symbol name is used then |
| 234 | /// return linkage name after skipping this special LLVM prefix. |
| 235 | static StringRef getRealLinkageName(StringRef LinkageName) { |
| 236 | char One = '\1'; |
| 237 | if (LinkageName.startswith(StringRef(&One, 1))) |
| 238 | return LinkageName.substr(1); |
| 239 | return LinkageName; |
| 240 | } |
| 241 | |
Eric Christopher | 0ffe2b4 | 2011-11-10 19:25:34 +0000 | [diff] [blame] | 242 | static bool isObjCClass(StringRef Name) { |
| 243 | return Name.startswith("+") || Name.startswith("-"); |
| 244 | } |
| 245 | |
| 246 | static bool hasObjCCategory(StringRef Name) { |
| 247 | if (!isObjCClass(Name)) return false; |
| 248 | |
| 249 | size_t pos = Name.find(')'); |
| 250 | if (pos != std::string::npos) { |
| 251 | if (Name[pos+1] != ' ') return false; |
| 252 | return true; |
| 253 | } |
| 254 | return false; |
| 255 | } |
| 256 | |
| 257 | static void getObjCClassCategory(StringRef In, StringRef &Class, |
| 258 | StringRef &Category) { |
| 259 | if (!hasObjCCategory(In)) { |
| 260 | Class = In.slice(In.find('[') + 1, In.find(' ')); |
| 261 | Category = ""; |
| 262 | return; |
| 263 | } |
| 264 | |
| 265 | Class = In.slice(In.find('[') + 1, In.find('(')); |
| 266 | Category = In.slice(In.find('[') + 1, In.find(' ')); |
| 267 | return; |
| 268 | } |
| 269 | |
| 270 | static StringRef getObjCMethodName(StringRef In) { |
| 271 | return In.slice(In.find(' ') + 1, In.find(']')); |
| 272 | } |
| 273 | |
| 274 | // Add the various names to the Dwarf accelerator table names. |
| 275 | static void addSubprogramNames(CompileUnit *TheCU, DISubprogram SP, |
| 276 | DIE* Die) { |
| 277 | if (!SP.isDefinition()) return; |
| 278 | |
| 279 | TheCU->addAccelName(SP.getName(), Die); |
| 280 | |
| 281 | // If the linkage name is different than the name, go ahead and output |
| 282 | // that as well into the name table. |
| 283 | if (SP.getLinkageName() != "" && SP.getName() != SP.getLinkageName()) |
| 284 | TheCU->addAccelName(SP.getLinkageName(), Die); |
| 285 | |
| 286 | // If this is an Objective-C selector name add it to the ObjC accelerator |
| 287 | // too. |
| 288 | if (isObjCClass(SP.getName())) { |
| 289 | StringRef Class, Category; |
| 290 | getObjCClassCategory(SP.getName(), Class, Category); |
| 291 | TheCU->addAccelObjC(Class, Die); |
| 292 | if (Category != "") |
| 293 | TheCU->addAccelObjC(Category, Die); |
| 294 | // Also add the base method name to the name table. |
| 295 | TheCU->addAccelName(getObjCMethodName(SP.getName()), Die); |
| 296 | } |
| 297 | } |
| 298 | |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 299 | /// updateSubprogramScopeDIE - Find DIE for the given subprogram and |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 300 | /// attach appropriate DW_AT_low_pc and DW_AT_high_pc attributes. |
| 301 | /// If there are global variables in this scope then create and insert |
| 302 | /// DIEs for these variables. |
Devang Patel | d302434 | 2011-08-15 22:24:32 +0000 | [diff] [blame] | 303 | DIE *DwarfDebug::updateSubprogramScopeDIE(CompileUnit *SPCU, |
| 304 | const MDNode *SPNode) { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 305 | DIE *SPDie = SPCU->getDIE(SPNode); |
Devang Patel | 8aa6147 | 2010-07-07 22:20:57 +0000 | [diff] [blame] | 306 | |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 307 | assert(SPDie && "Unable to find subprogram DIE!"); |
| 308 | DISubprogram SP(SPNode); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 309 | |
Devang Patel | 5e06bb8 | 2011-04-22 23:10:17 +0000 | [diff] [blame] | 310 | DISubprogram SPDecl = SP.getFunctionDeclaration(); |
Rafael Espindola | b052728 | 2011-11-04 19:00:29 +0000 | [diff] [blame] | 311 | if (!SPDecl.isSubprogram()) { |
Devang Patel | 5e06bb8 | 2011-04-22 23:10:17 +0000 | [diff] [blame] | 312 | // There is not any need to generate specification DIE for a function |
| 313 | // defined at compile unit level. If a function is defined inside another |
| 314 | // function then gdb prefers the definition at top level and but does not |
| 315 | // expect specification DIE in parent function. So avoid creating |
| 316 | // specification DIE for a function defined inside a function. |
| 317 | if (SP.isDefinition() && !SP.getContext().isCompileUnit() && |
| 318 | !SP.getContext().isFile() && |
| 319 | !isSubprogramContext(SP.getContext())) { |
Eric Christopher | 873cf0a | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 320 | SPCU->addFlag(SPDie, dwarf::DW_AT_declaration); |
Devang Patel | 5e06bb8 | 2011-04-22 23:10:17 +0000 | [diff] [blame] | 321 | |
| 322 | // Add arguments. |
| 323 | DICompositeType SPTy = SP.getType(); |
| 324 | DIArray Args = SPTy.getTypeArray(); |
| 325 | unsigned SPTag = SPTy.getTag(); |
| 326 | if (SPTag == dwarf::DW_TAG_subroutine_type) |
| 327 | for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) { |
| 328 | DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter); |
Eric Christopher | 5c38de9 | 2012-09-10 23:33:57 +0000 | [diff] [blame] | 329 | DIType ATy = DIType(Args.getElement(i)); |
Devang Patel | 5e06bb8 | 2011-04-22 23:10:17 +0000 | [diff] [blame] | 330 | SPCU->addType(Arg, ATy); |
| 331 | if (ATy.isArtificial()) |
Eric Christopher | 873cf0a | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 332 | SPCU->addFlag(Arg, dwarf::DW_AT_artificial); |
Eric Christopher | e521278 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 333 | if (ATy.isObjectPointer()) |
Eric Christopher | 55c86c6 | 2012-10-02 21:44:12 +0000 | [diff] [blame] | 334 | SPCU->addDIEEntry(SPDie, dwarf::DW_AT_object_pointer, |
| 335 | dwarf::DW_FORM_ref4, Arg); |
Devang Patel | 5e06bb8 | 2011-04-22 23:10:17 +0000 | [diff] [blame] | 336 | SPDie->addChild(Arg); |
| 337 | } |
| 338 | DIE *SPDeclDie = SPDie; |
| 339 | SPDie = new DIE(dwarf::DW_TAG_subprogram); |
| 340 | SPCU->addDIEEntry(SPDie, dwarf::DW_AT_specification, dwarf::DW_FORM_ref4, |
| 341 | SPDeclDie); |
| 342 | SPCU->addDie(SPDie); |
| 343 | } |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 344 | } |
Devang Patel | 8aa6147 | 2010-07-07 22:20:57 +0000 | [diff] [blame] | 345 | // Pick up abstract subprogram DIE. |
| 346 | if (DIE *AbsSPDIE = AbstractSPDies.lookup(SPNode)) { |
| 347 | SPDie = new DIE(dwarf::DW_TAG_subprogram); |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 348 | SPCU->addDIEEntry(SPDie, dwarf::DW_AT_abstract_origin, |
| 349 | dwarf::DW_FORM_ref4, AbsSPDIE); |
Devang Patel | 8aa6147 | 2010-07-07 22:20:57 +0000 | [diff] [blame] | 350 | SPCU->addDie(SPDie); |
| 351 | } |
| 352 | |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 353 | SPCU->addLabel(SPDie, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, |
| 354 | Asm->GetTempSymbol("func_begin", Asm->getFunctionNumber())); |
| 355 | SPCU->addLabel(SPDie, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr, |
| 356 | Asm->GetTempSymbol("func_end", Asm->getFunctionNumber())); |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 357 | const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo(); |
| 358 | MachineLocation Location(RI->getFrameRegister(*Asm->MF)); |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 359 | SPCU->addAddress(SPDie, dwarf::DW_AT_frame_base, Location); |
Devang Patel | b464564 | 2010-02-06 01:02:37 +0000 | [diff] [blame] | 360 | |
Eric Christopher | 0ffe2b4 | 2011-11-10 19:25:34 +0000 | [diff] [blame] | 361 | // Add name to the name table, we do this here because we're guaranteed |
| 362 | // to have concrete versions of our DW_TAG_subprogram nodes. |
| 363 | addSubprogramNames(SPCU, SP, SPDie); |
| 364 | |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 365 | return SPDie; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 368 | /// constructLexicalScope - Construct new DW_TAG_lexical_block |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 369 | /// for this scope and attach DW_AT_low_pc/DW_AT_high_pc labels. |
Devang Patel | d302434 | 2011-08-15 22:24:32 +0000 | [diff] [blame] | 370 | DIE *DwarfDebug::constructLexicalScopeDIE(CompileUnit *TheCU, |
| 371 | LexicalScope *Scope) { |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 372 | DIE *ScopeDIE = new DIE(dwarf::DW_TAG_lexical_block); |
| 373 | if (Scope->isAbstractScope()) |
| 374 | return ScopeDIE; |
| 375 | |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 376 | const SmallVector<InsnRange, 4> &Ranges = Scope->getRanges(); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 377 | if (Ranges.empty()) |
| 378 | return 0; |
| 379 | |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 380 | SmallVector<InsnRange, 4>::const_iterator RI = Ranges.begin(); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 381 | if (Ranges.size() > 1) { |
| 382 | // .debug_range section has not been laid out yet. Emit offset in |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 383 | // .debug_range as a uint, size 4, for now. emitDIE will handle |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 384 | // DW_AT_ranges appropriately. |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 385 | TheCU->addUInt(ScopeDIE, dwarf::DW_AT_ranges, dwarf::DW_FORM_data4, |
Devang Patel | 5bc942c | 2011-08-10 23:58:09 +0000 | [diff] [blame] | 386 | DebugRangeSymbols.size() |
Chandler Carruth | 426c2bf | 2012-11-01 09:14:31 +0000 | [diff] [blame] | 387 | * Asm->getDataLayout().getPointerSize()); |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 388 | for (SmallVector<InsnRange, 4>::const_iterator RI = Ranges.begin(), |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 389 | RE = Ranges.end(); RI != RE; ++RI) { |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 390 | DebugRangeSymbols.push_back(getLabelBeforeInsn(RI->first)); |
| 391 | DebugRangeSymbols.push_back(getLabelAfterInsn(RI->second)); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 392 | } |
| 393 | DebugRangeSymbols.push_back(NULL); |
| 394 | DebugRangeSymbols.push_back(NULL); |
| 395 | return ScopeDIE; |
| 396 | } |
| 397 | |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 398 | const MCSymbol *Start = getLabelBeforeInsn(RI->first); |
| 399 | const MCSymbol *End = getLabelAfterInsn(RI->second); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 400 | |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 401 | if (End == 0) return 0; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 402 | |
Chris Lattner | b7db733 | 2010-03-09 01:58:53 +0000 | [diff] [blame] | 403 | assert(Start->isDefined() && "Invalid starting label for an inlined scope!"); |
| 404 | assert(End->isDefined() && "Invalid end label for an inlined scope!"); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 405 | |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 406 | TheCU->addLabel(ScopeDIE, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, Start); |
| 407 | TheCU->addLabel(ScopeDIE, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr, End); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 408 | |
| 409 | return ScopeDIE; |
| 410 | } |
| 411 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 412 | /// constructInlinedScopeDIE - This scope represents inlined body of |
| 413 | /// a function. Construct DIE to represent this concrete inlined copy |
| 414 | /// of the function. |
Devang Patel | d302434 | 2011-08-15 22:24:32 +0000 | [diff] [blame] | 415 | DIE *DwarfDebug::constructInlinedScopeDIE(CompileUnit *TheCU, |
| 416 | LexicalScope *Scope) { |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 417 | const SmallVector<InsnRange, 4> &Ranges = Scope->getRanges(); |
Nick Lewycky | 746cb67 | 2011-10-26 22:55:33 +0000 | [diff] [blame] | 418 | assert(Ranges.empty() == false && |
| 419 | "LexicalScope does not have instruction markers!"); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 420 | |
Devang Patel | 26a9200 | 2011-07-27 00:34:13 +0000 | [diff] [blame] | 421 | if (!Scope->getScopeNode()) |
| 422 | return NULL; |
| 423 | DIScope DS(Scope->getScopeNode()); |
| 424 | DISubprogram InlinedSP = getDISubprogram(DS); |
Devang Patel | 26a9200 | 2011-07-27 00:34:13 +0000 | [diff] [blame] | 425 | DIE *OriginDIE = TheCU->getDIE(InlinedSP); |
| 426 | if (!OriginDIE) { |
Bill Wendling | e0aae5b | 2012-10-30 17:51:02 +0000 | [diff] [blame] | 427 | DEBUG(dbgs() << "Unable to find original DIE for an inlined subprogram."); |
Devang Patel | 26a9200 | 2011-07-27 00:34:13 +0000 | [diff] [blame] | 428 | return NULL; |
| 429 | } |
| 430 | |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 431 | SmallVector<InsnRange, 4>::const_iterator RI = Ranges.begin(); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 432 | const MCSymbol *StartLabel = getLabelBeforeInsn(RI->first); |
| 433 | const MCSymbol *EndLabel = getLabelAfterInsn(RI->second); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 434 | |
Devang Patel | 0afbf23 | 2010-07-08 22:39:20 +0000 | [diff] [blame] | 435 | if (StartLabel == 0 || EndLabel == 0) { |
Bill Wendling | e0aae5b | 2012-10-30 17:51:02 +0000 | [diff] [blame] | 436 | llvm_unreachable("Unexpected Start and End labels for an inlined scope!"); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 437 | } |
Chris Lattner | b7db733 | 2010-03-09 01:58:53 +0000 | [diff] [blame] | 438 | assert(StartLabel->isDefined() && |
Chris Lattner | a34ec229 | 2010-03-09 01:51:43 +0000 | [diff] [blame] | 439 | "Invalid starting label for an inlined scope!"); |
Chris Lattner | b7db733 | 2010-03-09 01:58:53 +0000 | [diff] [blame] | 440 | assert(EndLabel->isDefined() && |
Chris Lattner | a34ec229 | 2010-03-09 01:51:43 +0000 | [diff] [blame] | 441 | "Invalid end label for an inlined scope!"); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 442 | |
Devang Patel | d96efb8 | 2011-05-05 17:54:26 +0000 | [diff] [blame] | 443 | DIE *ScopeDIE = new DIE(dwarf::DW_TAG_inlined_subroutine); |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 444 | TheCU->addDIEEntry(ScopeDIE, dwarf::DW_AT_abstract_origin, |
| 445 | dwarf::DW_FORM_ref4, OriginDIE); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 446 | |
Devang Patel | 26a9200 | 2011-07-27 00:34:13 +0000 | [diff] [blame] | 447 | if (Ranges.size() > 1) { |
| 448 | // .debug_range section has not been laid out yet. Emit offset in |
| 449 | // .debug_range as a uint, size 4, for now. emitDIE will handle |
| 450 | // DW_AT_ranges appropriately. |
| 451 | TheCU->addUInt(ScopeDIE, dwarf::DW_AT_ranges, dwarf::DW_FORM_data4, |
Devang Patel | 5bc942c | 2011-08-10 23:58:09 +0000 | [diff] [blame] | 452 | DebugRangeSymbols.size() |
Chandler Carruth | 426c2bf | 2012-11-01 09:14:31 +0000 | [diff] [blame] | 453 | * Asm->getDataLayout().getPointerSize()); |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 454 | for (SmallVector<InsnRange, 4>::const_iterator RI = Ranges.begin(), |
Devang Patel | 26a9200 | 2011-07-27 00:34:13 +0000 | [diff] [blame] | 455 | RE = Ranges.end(); RI != RE; ++RI) { |
| 456 | DebugRangeSymbols.push_back(getLabelBeforeInsn(RI->first)); |
| 457 | DebugRangeSymbols.push_back(getLabelAfterInsn(RI->second)); |
| 458 | } |
| 459 | DebugRangeSymbols.push_back(NULL); |
| 460 | DebugRangeSymbols.push_back(NULL); |
| 461 | } else { |
Devang Patel | 5bc942c | 2011-08-10 23:58:09 +0000 | [diff] [blame] | 462 | TheCU->addLabel(ScopeDIE, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, |
| 463 | StartLabel); |
| 464 | TheCU->addLabel(ScopeDIE, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr, |
| 465 | EndLabel); |
Devang Patel | 26a9200 | 2011-07-27 00:34:13 +0000 | [diff] [blame] | 466 | } |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 467 | |
| 468 | InlinedSubprogramDIEs.insert(OriginDIE); |
| 469 | |
| 470 | // Track the start label for this inlined function. |
Devang Patel | 26a9200 | 2011-07-27 00:34:13 +0000 | [diff] [blame] | 471 | //.debug_inlined section specification does not clearly state how |
| 472 | // to emit inlined scope that is split into multiple instruction ranges. |
| 473 | // For now, use first instruction range and emit low_pc/high_pc pair and |
| 474 | // corresponding .debug_inlined section entry for this pair. |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 475 | DenseMap<const MDNode *, SmallVector<InlineInfoLabels, 4> >::iterator |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 476 | I = InlineInfo.find(InlinedSP); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 477 | |
| 478 | if (I == InlineInfo.end()) { |
Nick Lewycky | 746cb67 | 2011-10-26 22:55:33 +0000 | [diff] [blame] | 479 | InlineInfo[InlinedSP].push_back(std::make_pair(StartLabel, ScopeDIE)); |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 480 | InlinedSPNodes.push_back(InlinedSP); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 481 | } else |
Chris Lattner | 6ed0f90 | 2010-03-09 00:31:02 +0000 | [diff] [blame] | 482 | I->second.push_back(std::make_pair(StartLabel, ScopeDIE)); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 483 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 484 | DILocation DL(Scope->getInlinedAt()); |
Eric Christopher | 0821200 | 2012-03-26 21:38:38 +0000 | [diff] [blame] | 485 | TheCU->addUInt(ScopeDIE, dwarf::DW_AT_call_file, 0, |
| 486 | GetOrCreateSourceID(DL.getFilename(), DL.getDirectory())); |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 487 | TheCU->addUInt(ScopeDIE, dwarf::DW_AT_call_line, 0, DL.getLineNumber()); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 488 | |
Eric Christopher | 309bedd | 2011-12-04 06:02:38 +0000 | [diff] [blame] | 489 | // Add name to the name table, we do this here because we're guaranteed |
| 490 | // to have concrete versions of our DW_TAG_inlined_subprogram nodes. |
| 491 | addSubprogramNames(TheCU, InlinedSP, ScopeDIE); |
| 492 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 493 | return ScopeDIE; |
| 494 | } |
| 495 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 496 | /// constructScopeDIE - Construct a DIE for this scope. |
Devang Patel | d0b5a5e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 497 | DIE *DwarfDebug::constructScopeDIE(CompileUnit *TheCU, LexicalScope *Scope) { |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 498 | if (!Scope || !Scope->getScopeNode()) |
| 499 | return NULL; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 500 | |
Nick Lewycky | 746cb67 | 2011-10-26 22:55:33 +0000 | [diff] [blame] | 501 | SmallVector<DIE *, 8> Children; |
Eric Christopher | e521278 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 502 | DIE *ObjectPointer = NULL; |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 503 | |
| 504 | // Collect arguments for current function. |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 505 | if (LScopes.isCurrentFunctionScope(Scope)) |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 506 | for (unsigned i = 0, N = CurrentFnArguments.size(); i < N; ++i) |
| 507 | if (DbgVariable *ArgDV = CurrentFnArguments[i]) |
Devang Patel | d0b5a5e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 508 | if (DIE *Arg = |
Eric Christopher | e521278 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 509 | TheCU->constructVariableDIE(ArgDV, Scope->isAbstractScope())) { |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 510 | Children.push_back(Arg); |
Eric Christopher | e521278 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 511 | if (ArgDV->isObjectPointer()) ObjectPointer = Arg; |
| 512 | } |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 513 | |
Eric Christopher | 1aeb7ac | 2011-10-03 15:49:16 +0000 | [diff] [blame] | 514 | // Collect lexical scope children first. |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 515 | const SmallVector<DbgVariable *, 8> &Variables = ScopeVariables.lookup(Scope); |
Devang Patel | 5bc9fec | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 516 | for (unsigned i = 0, N = Variables.size(); i < N; ++i) |
Devang Patel | d0b5a5e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 517 | if (DIE *Variable = |
Eric Christopher | 7b451cf | 2012-09-21 22:18:52 +0000 | [diff] [blame] | 518 | TheCU->constructVariableDIE(Variables[i], Scope->isAbstractScope())) { |
Devang Patel | 5bc9fec | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 519 | Children.push_back(Variable); |
Eric Christopher | 7b451cf | 2012-09-21 22:18:52 +0000 | [diff] [blame] | 520 | if (Variables[i]->isObjectPointer()) ObjectPointer = Variable; |
| 521 | } |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 522 | const SmallVector<LexicalScope *, 4> &Scopes = Scope->getChildren(); |
Devang Patel | 5bc9fec | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 523 | for (unsigned j = 0, M = Scopes.size(); j < M; ++j) |
Devang Patel | d0b5a5e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 524 | if (DIE *Nested = constructScopeDIE(TheCU, Scopes[j])) |
Devang Patel | 5bc9fec | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 525 | Children.push_back(Nested); |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 526 | DIScope DS(Scope->getScopeNode()); |
| 527 | DIE *ScopeDIE = NULL; |
| 528 | if (Scope->getInlinedAt()) |
Devang Patel | d302434 | 2011-08-15 22:24:32 +0000 | [diff] [blame] | 529 | ScopeDIE = constructInlinedScopeDIE(TheCU, Scope); |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 530 | else if (DS.isSubprogram()) { |
Devang Patel | 0dd4558 | 2010-06-28 20:53:04 +0000 | [diff] [blame] | 531 | ProcessedSPNodes.insert(DS); |
Devang Patel | 8aa6147 | 2010-07-07 22:20:57 +0000 | [diff] [blame] | 532 | if (Scope->isAbstractScope()) { |
Devang Patel | d302434 | 2011-08-15 22:24:32 +0000 | [diff] [blame] | 533 | ScopeDIE = TheCU->getDIE(DS); |
Devang Patel | 8aa6147 | 2010-07-07 22:20:57 +0000 | [diff] [blame] | 534 | // Note down abstract DIE. |
| 535 | if (ScopeDIE) |
| 536 | AbstractSPDies.insert(std::make_pair(DS, ScopeDIE)); |
| 537 | } |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 538 | else |
Devang Patel | d302434 | 2011-08-15 22:24:32 +0000 | [diff] [blame] | 539 | ScopeDIE = updateSubprogramScopeDIE(TheCU, DS); |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 540 | } |
Devang Patel | 5bc9fec | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 541 | else { |
| 542 | // There is no need to emit empty lexical block DIE. |
| 543 | if (Children.empty()) |
| 544 | return NULL; |
Devang Patel | d302434 | 2011-08-15 22:24:32 +0000 | [diff] [blame] | 545 | ScopeDIE = constructLexicalScopeDIE(TheCU, Scope); |
Devang Patel | 5bc9fec | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 546 | } |
| 547 | |
Devang Patel | aead63c | 2010-03-29 22:59:58 +0000 | [diff] [blame] | 548 | if (!ScopeDIE) return NULL; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 549 | |
Devang Patel | 5bc9fec | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 550 | // Add children |
| 551 | for (SmallVector<DIE *, 8>::iterator I = Children.begin(), |
| 552 | E = Children.end(); I != E; ++I) |
| 553 | ScopeDIE->addChild(*I); |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 554 | |
Eric Christopher | e521278 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 555 | if (DS.isSubprogram() && ObjectPointer != NULL) |
| 556 | TheCU->addDIEEntry(ScopeDIE, dwarf::DW_AT_object_pointer, |
| 557 | dwarf::DW_FORM_ref4, ObjectPointer); |
| 558 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 559 | if (DS.isSubprogram()) |
Eric Christopher | 0ffe2b4 | 2011-11-10 19:25:34 +0000 | [diff] [blame] | 560 | TheCU->addPubTypes(DISubprogram(DS)); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 561 | |
Eric Christopher | 0ffe2b4 | 2011-11-10 19:25:34 +0000 | [diff] [blame] | 562 | return ScopeDIE; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 563 | } |
| 564 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 565 | /// GetOrCreateSourceID - Look up the source id with the given directory and |
| 566 | /// source file names. If none currently exists, create a new id and insert it |
| 567 | /// in the SourceIds map. This can update DirectoryNames and SourceFileNames |
| 568 | /// maps as well. |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 569 | unsigned DwarfDebug::GetOrCreateSourceID(StringRef FileName, |
| 570 | StringRef DirName) { |
Devang Patel | 1905a18 | 2010-09-16 20:57:49 +0000 | [diff] [blame] | 571 | // If FE did not provide a file name, then assume stdin. |
| 572 | if (FileName.empty()) |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 573 | return GetOrCreateSourceID("<stdin>", StringRef()); |
| 574 | |
Nick Lewycky | 6c1a703 | 2011-11-02 20:55:33 +0000 | [diff] [blame] | 575 | // TODO: this might not belong here. See if we can factor this better. |
| 576 | if (DirName == CompilationDir) |
| 577 | DirName = ""; |
| 578 | |
Nick Lewycky | 44d798d | 2011-10-17 23:05:28 +0000 | [diff] [blame] | 579 | unsigned SrcId = SourceIdMap.size()+1; |
Devang Patel | 1905a18 | 2010-09-16 20:57:49 +0000 | [diff] [blame] | 580 | |
Benjamin Kramer | 74612c2 | 2012-03-11 14:56:26 +0000 | [diff] [blame] | 581 | // We look up the file/dir pair by concatenating them with a zero byte. |
| 582 | SmallString<128> NamePair; |
| 583 | NamePair += DirName; |
| 584 | NamePair += '\0'; // Zero bytes are not allowed in paths. |
| 585 | NamePair += FileName; |
| 586 | |
| 587 | StringMapEntry<unsigned> &Ent = SourceIdMap.GetOrCreateValue(NamePair, SrcId); |
| 588 | if (Ent.getValue() != SrcId) |
| 589 | return Ent.getValue(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 590 | |
Rafael Espindola | 5c05563 | 2010-11-18 02:04:25 +0000 | [diff] [blame] | 591 | // Print out a .file directive to specify files for .loc directives. |
Benjamin Kramer | 74612c2 | 2012-03-11 14:56:26 +0000 | [diff] [blame] | 592 | Asm->OutStreamer.EmitDwarfFileDirective(SrcId, DirName, FileName); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 593 | |
| 594 | return SrcId; |
| 595 | } |
| 596 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 597 | /// constructCompileUnit - Create new CompileUnit for the given |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 598 | /// metadata node with tag DW_TAG_compile_unit. |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 599 | CompileUnit *DwarfDebug::constructCompileUnit(const MDNode *N) { |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 600 | DICompileUnit DIUnit(N); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 601 | StringRef FN = DIUnit.getFilename(); |
Nick Lewycky | 6c1a703 | 2011-11-02 20:55:33 +0000 | [diff] [blame] | 602 | CompilationDir = DIUnit.getDirectory(); |
| 603 | unsigned ID = GetOrCreateSourceID(FN, CompilationDir); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 604 | |
| 605 | DIE *Die = new DIE(dwarf::DW_TAG_compile_unit); |
Eric Christopher | edf8bc8 | 2012-09-10 23:34:00 +0000 | [diff] [blame] | 606 | CompileUnit *NewCU = new CompileUnit(ID, DIUnit.getLanguage(), Die, |
| 607 | Asm, this); |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 608 | NewCU->addString(Die, dwarf::DW_AT_producer, DIUnit.getProducer()); |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 609 | NewCU->addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2, |
| 610 | DIUnit.getLanguage()); |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 611 | NewCU->addString(Die, dwarf::DW_AT_name, FN); |
Eric Christopher | 6635cad | 2012-08-01 18:19:01 +0000 | [diff] [blame] | 612 | // 2.17.1 requires that we use DW_AT_low_pc for a single entry point |
| 613 | // into an entity. |
| 614 | NewCU->addUInt(Die, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, 0); |
Devang Patel | 4a602ca | 2010-03-22 23:11:36 +0000 | [diff] [blame] | 615 | // DW_AT_stmt_list is a offset of line number information for this |
Devang Patel | af608bd | 2010-08-24 00:06:12 +0000 | [diff] [blame] | 616 | // compile unit in debug_line section. |
Rafael Espindola | 2241e51 | 2012-06-22 13:24:07 +0000 | [diff] [blame] | 617 | if (Asm->MAI->doesDwarfUseRelocationsAcrossSections()) |
Rafael Espindola | 597a766 | 2011-05-04 17:44:06 +0000 | [diff] [blame] | 618 | NewCU->addLabel(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4, |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 619 | Asm->GetTempSymbol("section_line")); |
Devang Patel | ae84d5b | 2010-08-31 23:50:19 +0000 | [diff] [blame] | 620 | else |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 621 | NewCU->addUInt(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4, 0); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 622 | |
Nick Lewycky | 6c1a703 | 2011-11-02 20:55:33 +0000 | [diff] [blame] | 623 | if (!CompilationDir.empty()) |
| 624 | NewCU->addString(Die, dwarf::DW_AT_comp_dir, CompilationDir); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 625 | if (DIUnit.isOptimized()) |
Eric Christopher | 873cf0a | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 626 | NewCU->addFlag(Die, dwarf::DW_AT_APPLE_optimized); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 627 | |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 628 | StringRef Flags = DIUnit.getFlags(); |
| 629 | if (!Flags.empty()) |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 630 | NewCU->addString(Die, dwarf::DW_AT_APPLE_flags, Flags); |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 631 | |
Nick Lewycky | d5d5213 | 2011-10-17 23:27:36 +0000 | [diff] [blame] | 632 | if (unsigned RVer = DIUnit.getRunTimeVersion()) |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 633 | NewCU->addUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers, |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 634 | dwarf::DW_FORM_data1, RVer); |
| 635 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 636 | if (!FirstCU) |
| 637 | FirstCU = NewCU; |
| 638 | CUMap.insert(std::make_pair(N, NewCU)); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 639 | return NewCU; |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 640 | } |
| 641 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 642 | /// construct SubprogramDIE - Construct subprogram DIE. |
Devang Patel | 3655a21 | 2011-08-15 23:36:40 +0000 | [diff] [blame] | 643 | void DwarfDebug::constructSubprogramDIE(CompileUnit *TheCU, |
| 644 | const MDNode *N) { |
Rafael Espindola | b052728 | 2011-11-04 19:00:29 +0000 | [diff] [blame] | 645 | CompileUnit *&CURef = SPMap[N]; |
| 646 | if (CURef) |
| 647 | return; |
| 648 | CURef = TheCU; |
| 649 | |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 650 | DISubprogram SP(N); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 651 | if (!SP.isDefinition()) |
| 652 | // This is a method declaration which will be handled while constructing |
| 653 | // class type. |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 654 | return; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 655 | |
Devang Patel | dbc64af | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 656 | DIE *SubprogramDie = TheCU->getOrCreateSubprogramDIE(SP); |
Stuart Hastings | 639336e | 2010-04-06 21:38:29 +0000 | [diff] [blame] | 657 | |
| 658 | // Add to map. |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 659 | TheCU->insertDIE(N, SubprogramDie); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 660 | |
| 661 | // Add to context owner. |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 662 | TheCU->addToContextOwner(SubprogramDie, SP.getContext()); |
Devang Patel | 0000fad | 2009-12-08 23:21:45 +0000 | [diff] [blame] | 663 | |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 664 | return; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Devang Patel | 02e603f | 2011-08-15 23:47:24 +0000 | [diff] [blame] | 667 | /// collectInfoFromNamedMDNodes - Collect debug info from named mdnodes such |
| 668 | /// as llvm.dbg.enum and llvm.dbg.ty |
| 669 | void DwarfDebug::collectInfoFromNamedMDNodes(Module *M) { |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 670 | if (NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.sp")) |
| 671 | for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { |
| 672 | const MDNode *N = NMD->getOperand(i); |
| 673 | if (CompileUnit *CU = CUMap.lookup(DISubprogram(N).getCompileUnit())) |
| 674 | constructSubprogramDIE(CU, N); |
| 675 | } |
| 676 | |
| 677 | if (NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.gv")) |
| 678 | for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { |
| 679 | const MDNode *N = NMD->getOperand(i); |
| 680 | if (CompileUnit *CU = CUMap.lookup(DIGlobalVariable(N).getCompileUnit())) |
Devang Patel | 28bea08 | 2011-08-18 23:17:55 +0000 | [diff] [blame] | 681 | CU->createGlobalVariableDIE(N); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 682 | } |
| 683 | |
Devang Patel | 02e603f | 2011-08-15 23:47:24 +0000 | [diff] [blame] | 684 | if (NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.enum")) |
| 685 | for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { |
| 686 | DIType Ty(NMD->getOperand(i)); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 687 | if (CompileUnit *CU = CUMap.lookup(Ty.getCompileUnit())) |
| 688 | CU->getOrCreateTypeDIE(Ty); |
Devang Patel | 02e603f | 2011-08-15 23:47:24 +0000 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | if (NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.ty")) |
| 692 | for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { |
| 693 | DIType Ty(NMD->getOperand(i)); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 694 | if (CompileUnit *CU = CUMap.lookup(Ty.getCompileUnit())) |
| 695 | CU->getOrCreateTypeDIE(Ty); |
Devang Patel | 02e603f | 2011-08-15 23:47:24 +0000 | [diff] [blame] | 696 | } |
| 697 | } |
| 698 | |
| 699 | /// collectLegacyDebugInfo - Collect debug info using DebugInfoFinder. |
| 700 | /// FIXME - Remove this when dragon-egg and llvm-gcc switch to DIBuilder. |
| 701 | bool DwarfDebug::collectLegacyDebugInfo(Module *M) { |
| 702 | DebugInfoFinder DbgFinder; |
| 703 | DbgFinder.processModule(*M); |
| 704 | |
| 705 | bool HasDebugInfo = false; |
| 706 | // Scan all the compile-units to see if there are any marked as the main |
| 707 | // unit. If not, we do not generate debug info. |
| 708 | for (DebugInfoFinder::iterator I = DbgFinder.compile_unit_begin(), |
| 709 | E = DbgFinder.compile_unit_end(); I != E; ++I) { |
| 710 | if (DICompileUnit(*I).isMain()) { |
| 711 | HasDebugInfo = true; |
| 712 | break; |
| 713 | } |
| 714 | } |
| 715 | if (!HasDebugInfo) return false; |
| 716 | |
| 717 | // Create all the compile unit DIEs. |
| 718 | for (DebugInfoFinder::iterator I = DbgFinder.compile_unit_begin(), |
| 719 | E = DbgFinder.compile_unit_end(); I != E; ++I) |
| 720 | constructCompileUnit(*I); |
| 721 | |
| 722 | // Create DIEs for each global variable. |
| 723 | for (DebugInfoFinder::iterator I = DbgFinder.global_variable_begin(), |
| 724 | E = DbgFinder.global_variable_end(); I != E; ++I) { |
| 725 | const MDNode *N = *I; |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 726 | if (CompileUnit *CU = CUMap.lookup(DIGlobalVariable(N).getCompileUnit())) |
Devang Patel | 28bea08 | 2011-08-18 23:17:55 +0000 | [diff] [blame] | 727 | CU->createGlobalVariableDIE(N); |
Devang Patel | 02e603f | 2011-08-15 23:47:24 +0000 | [diff] [blame] | 728 | } |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 729 | |
Devang Patel | 02e603f | 2011-08-15 23:47:24 +0000 | [diff] [blame] | 730 | // Create DIEs for each subprogram. |
| 731 | for (DebugInfoFinder::iterator I = DbgFinder.subprogram_begin(), |
| 732 | E = DbgFinder.subprogram_end(); I != E; ++I) { |
| 733 | const MDNode *N = *I; |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 734 | if (CompileUnit *CU = CUMap.lookup(DISubprogram(N).getCompileUnit())) |
| 735 | constructSubprogramDIE(CU, N); |
Devang Patel | 02e603f | 2011-08-15 23:47:24 +0000 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | return HasDebugInfo; |
| 739 | } |
| 740 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 741 | /// beginModule - Emit all Dwarf sections that should come prior to the |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 742 | /// content. Create global DIEs and emit initial debug info sections. |
Nick Lewycky | 3bbb6f7 | 2011-07-29 03:49:23 +0000 | [diff] [blame] | 743 | /// This is invoked by the target AsmPrinter. |
Chris Lattner | 75f5072 | 2010-04-04 07:48:20 +0000 | [diff] [blame] | 744 | void DwarfDebug::beginModule(Module *M) { |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 745 | if (DisableDebugInfoPrinting) |
| 746 | return; |
| 747 | |
Nick Lewycky | 3bbb6f7 | 2011-07-29 03:49:23 +0000 | [diff] [blame] | 748 | // If module has named metadata anchors then use them, otherwise scan the |
| 749 | // module using debug info finder to collect debug info. |
Devang Patel | 30692ab | 2011-05-03 16:45:22 +0000 | [diff] [blame] | 750 | NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu"); |
| 751 | if (CU_Nodes) { |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 752 | for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) { |
| 753 | DICompileUnit CUNode(CU_Nodes->getOperand(i)); |
| 754 | CompileUnit *CU = constructCompileUnit(CUNode); |
| 755 | DIArray GVs = CUNode.getGlobalVariables(); |
| 756 | for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i) |
Devang Patel | 28bea08 | 2011-08-18 23:17:55 +0000 | [diff] [blame] | 757 | CU->createGlobalVariableDIE(GVs.getElement(i)); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 758 | DIArray SPs = CUNode.getSubprograms(); |
| 759 | for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) |
| 760 | constructSubprogramDIE(CU, SPs.getElement(i)); |
| 761 | DIArray EnumTypes = CUNode.getEnumTypes(); |
| 762 | for (unsigned i = 0, e = EnumTypes.getNumElements(); i != e; ++i) |
| 763 | CU->getOrCreateTypeDIE(EnumTypes.getElement(i)); |
| 764 | DIArray RetainedTypes = CUNode.getRetainedTypes(); |
| 765 | for (unsigned i = 0, e = RetainedTypes.getNumElements(); i != e; ++i) |
| 766 | CU->getOrCreateTypeDIE(RetainedTypes.getElement(i)); |
| 767 | } |
Devang Patel | 02e603f | 2011-08-15 23:47:24 +0000 | [diff] [blame] | 768 | } else if (!collectLegacyDebugInfo(M)) |
| 769 | return; |
Devang Patel | 30692ab | 2011-05-03 16:45:22 +0000 | [diff] [blame] | 770 | |
Devang Patel | 02e603f | 2011-08-15 23:47:24 +0000 | [diff] [blame] | 771 | collectInfoFromNamedMDNodes(M); |
Devang Patel | 30692ab | 2011-05-03 16:45:22 +0000 | [diff] [blame] | 772 | |
Chris Lattner | d850ac7 | 2010-04-05 02:19:28 +0000 | [diff] [blame] | 773 | // Tell MMI that we have debug info. |
| 774 | MMI->setDebugInfoAvailability(true); |
Devang Patel | 30692ab | 2011-05-03 16:45:22 +0000 | [diff] [blame] | 775 | |
Chris Lattner | be15beb | 2010-04-04 23:17:54 +0000 | [diff] [blame] | 776 | // Emit initial sections. |
Chris Lattner | d850ac7 | 2010-04-05 02:19:28 +0000 | [diff] [blame] | 777 | EmitSectionLabels(); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 778 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 779 | // Prime section data. |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 780 | SectionMap.insert(Asm->getObjFileLowering().getTextSection()); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 781 | } |
| 782 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 783 | /// endModule - Emit all Dwarf sections that should come after the content. |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 784 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 785 | void DwarfDebug::endModule() { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 786 | if (!FirstCU) return; |
Devang Patel | 4a1cad6 | 2010-06-28 18:25:03 +0000 | [diff] [blame] | 787 | const Module *M = MMI->getModule(); |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 788 | DenseMap<const MDNode *, LexicalScope *> DeadFnScopeMap; |
Devang Patel | 4a1cad6 | 2010-06-28 18:25:03 +0000 | [diff] [blame] | 789 | |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 790 | // Collect info for variables that were optimized out. |
| 791 | if (NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu")) { |
| 792 | for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) { |
| 793 | DICompileUnit TheCU(CU_Nodes->getOperand(i)); |
| 794 | DIArray Subprograms = TheCU.getSubprograms(); |
| 795 | for (unsigned i = 0, e = Subprograms.getNumElements(); i != e; ++i) { |
| 796 | DISubprogram SP(Subprograms.getElement(i)); |
| 797 | if (ProcessedSPNodes.count(SP) != 0) continue; |
| 798 | if (!SP.Verify()) continue; |
| 799 | if (!SP.isDefinition()) continue; |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 800 | DIArray Variables = SP.getVariables(); |
| 801 | if (Variables.getNumElements() == 0) continue; |
| 802 | |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 803 | LexicalScope *Scope = |
| 804 | new LexicalScope(NULL, DIDescriptor(SP), NULL, false); |
| 805 | DeadFnScopeMap[SP] = Scope; |
| 806 | |
| 807 | // Construct subprogram DIE and add variables DIEs. |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 808 | CompileUnit *SPCU = CUMap.lookup(TheCU); |
Nick Lewycky | 746cb67 | 2011-10-26 22:55:33 +0000 | [diff] [blame] | 809 | assert(SPCU && "Unable to find Compile Unit!"); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 810 | constructSubprogramDIE(SPCU, SP); |
| 811 | DIE *ScopeDIE = SPCU->getDIE(SP); |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 812 | for (unsigned vi = 0, ve = Variables.getNumElements(); vi != ve; ++vi) { |
| 813 | DIVariable DV(Variables.getElement(vi)); |
| 814 | if (!DV.Verify()) continue; |
| 815 | DbgVariable *NewVar = new DbgVariable(DV, NULL); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 816 | if (DIE *VariableDIE = |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 817 | SPCU->constructVariableDIE(NewVar, Scope->isAbstractScope())) |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 818 | ScopeDIE->addChild(VariableDIE); |
| 819 | } |
Devang Patel | 4a1cad6 | 2010-06-28 18:25:03 +0000 | [diff] [blame] | 820 | } |
| 821 | } |
| 822 | } |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 823 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 824 | // Attach DW_AT_inline attribute with inlined subprogram DIEs. |
| 825 | for (SmallPtrSet<DIE *, 4>::iterator AI = InlinedSubprogramDIEs.begin(), |
| 826 | AE = InlinedSubprogramDIEs.end(); AI != AE; ++AI) { |
| 827 | DIE *ISP = *AI; |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 828 | FirstCU->addUInt(ISP, dwarf::DW_AT_inline, 0, dwarf::DW_INL_inlined); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 829 | } |
Rafael Espindola | d1ac3a4 | 2011-11-12 01:57:54 +0000 | [diff] [blame] | 830 | for (DenseMap<const MDNode *, DIE *>::iterator AI = AbstractSPDies.begin(), |
| 831 | AE = AbstractSPDies.end(); AI != AE; ++AI) { |
| 832 | DIE *ISP = AI->second; |
| 833 | if (InlinedSubprogramDIEs.count(ISP)) |
| 834 | continue; |
| 835 | FirstCU->addUInt(ISP, dwarf::DW_AT_inline, 0, dwarf::DW_INL_inlined); |
| 836 | } |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 837 | |
Eric Christopher | 6635cad | 2012-08-01 18:19:01 +0000 | [diff] [blame] | 838 | // Emit DW_AT_containing_type attribute to connect types with their |
| 839 | // vtable holding type. |
Devang Patel | dbc64af | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 840 | for (DenseMap<const MDNode *, CompileUnit *>::iterator CUI = CUMap.begin(), |
| 841 | CUE = CUMap.end(); CUI != CUE; ++CUI) { |
| 842 | CompileUnit *TheCU = CUI->second; |
| 843 | TheCU->constructContainingTypeDIEs(); |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 844 | } |
| 845 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 846 | // Standard sections final addresses. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 847 | Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getTextSection()); |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 848 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("text_end")); |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 849 | Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getDataSection()); |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 850 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("data_end")); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 851 | |
| 852 | // End text sections. |
Benjamin Kramer | b4c9d9c | 2012-10-31 13:45:49 +0000 | [diff] [blame] | 853 | for (unsigned I = 0, E = SectionMap.size(); I != E; ++I) { |
| 854 | Asm->OutStreamer.SwitchSection(SectionMap[I]); |
| 855 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("section_end", I+1)); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 856 | } |
| 857 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 858 | // Compute DIE offsets and sizes. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 859 | computeSizeAndOffsets(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 860 | |
| 861 | // Emit all the DIEs into a debug info section |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 862 | emitDebugInfo(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 863 | |
| 864 | // Corresponding abbreviations into a abbrev section. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 865 | emitAbbreviations(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 866 | |
Eric Christopher | 9d9f5a5 | 2012-08-23 07:32:06 +0000 | [diff] [blame] | 867 | // Emit info into the dwarf accelerator table sections. |
Eric Christopher | 20f47ab | 2012-08-23 22:36:40 +0000 | [diff] [blame] | 868 | if (useDwarfAccelTables()) { |
Eric Christopher | 09ac3d8 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 869 | emitAccelNames(); |
| 870 | emitAccelObjC(); |
| 871 | emitAccelNamespaces(); |
| 872 | emitAccelTypes(); |
| 873 | } |
| 874 | |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 875 | // Emit info into a debug pubtypes section. |
Eric Christopher | 360f006 | 2012-08-23 07:10:56 +0000 | [diff] [blame] | 876 | // TODO: When we don't need the option anymore we can |
| 877 | // remove all of the code that adds to the table. |
Eric Christopher | 20f47ab | 2012-08-23 22:36:40 +0000 | [diff] [blame] | 878 | if (useDarwinGDBCompat()) |
Eric Christopher | 360f006 | 2012-08-23 07:10:56 +0000 | [diff] [blame] | 879 | emitDebugPubTypes(); |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 880 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 881 | // Emit info into a debug loc section. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 882 | emitDebugLoc(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 883 | |
| 884 | // Emit info into a debug aranges section. |
| 885 | EmitDebugARanges(); |
| 886 | |
| 887 | // Emit info into a debug ranges section. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 888 | emitDebugRanges(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 889 | |
| 890 | // Emit info into a debug macinfo section. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 891 | emitDebugMacInfo(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 892 | |
| 893 | // Emit inline info. |
Eric Christopher | 9eb1a94 | 2012-08-23 07:32:02 +0000 | [diff] [blame] | 894 | // TODO: When we don't need the option anymore we |
| 895 | // can remove all of the code that this section |
| 896 | // depends upon. |
Eric Christopher | 20f47ab | 2012-08-23 22:36:40 +0000 | [diff] [blame] | 897 | if (useDarwinGDBCompat()) |
Eric Christopher | 9eb1a94 | 2012-08-23 07:32:02 +0000 | [diff] [blame] | 898 | emitDebugInlineInfo(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 899 | |
Eric Christopher | 7550f7d | 2012-03-02 00:30:24 +0000 | [diff] [blame] | 900 | // Emit info into a debug str section. |
| 901 | emitDebugStr(); |
| 902 | |
Devang Patel | e9a1cca | 2010-08-02 17:32:15 +0000 | [diff] [blame] | 903 | // clean up. |
| 904 | DeleteContainerSeconds(DeadFnScopeMap); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 905 | SPMap.clear(); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 906 | for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(), |
| 907 | E = CUMap.end(); I != E; ++I) |
| 908 | delete I->second; |
| 909 | FirstCU = NULL; // Reset for the next Module, if any. |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 910 | } |
| 911 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 912 | /// findAbstractVariable - Find abstract variable, if any, associated with Var. |
Devang Patel | b549bcf | 2011-08-10 21:50:54 +0000 | [diff] [blame] | 913 | DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &DV, |
Chris Lattner | de4845c | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 914 | DebugLoc ScopeLoc) { |
Devang Patel | b549bcf | 2011-08-10 21:50:54 +0000 | [diff] [blame] | 915 | LLVMContext &Ctx = DV->getContext(); |
| 916 | // More then one inlined variable corresponds to one abstract variable. |
| 917 | DIVariable Var = cleanseInlinedVariable(DV, Ctx); |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 918 | DbgVariable *AbsDbgVariable = AbstractVariables.lookup(Var); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 919 | if (AbsDbgVariable) |
| 920 | return AbsDbgVariable; |
| 921 | |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 922 | LexicalScope *Scope = LScopes.findAbstractScope(ScopeLoc.getScope(Ctx)); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 923 | if (!Scope) |
| 924 | return NULL; |
| 925 | |
Devang Patel | 5a1a67c | 2011-08-15 19:01:20 +0000 | [diff] [blame] | 926 | AbsDbgVariable = new DbgVariable(Var, NULL); |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 927 | addScopeVariable(Scope, AbsDbgVariable); |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 928 | AbstractVariables[Var] = AbsDbgVariable; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 929 | return AbsDbgVariable; |
| 930 | } |
| 931 | |
Nick Lewycky | 3bbb6f7 | 2011-07-29 03:49:23 +0000 | [diff] [blame] | 932 | /// addCurrentFnArgument - If Var is a current function argument then add |
| 933 | /// it to CurrentFnArguments list. |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 934 | bool DwarfDebug::addCurrentFnArgument(const MachineFunction *MF, |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 935 | DbgVariable *Var, LexicalScope *Scope) { |
| 936 | if (!LScopes.isCurrentFunctionScope(Scope)) |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 937 | return false; |
| 938 | DIVariable DV = Var->getVariable(); |
| 939 | if (DV.getTag() != dwarf::DW_TAG_arg_variable) |
| 940 | return false; |
| 941 | unsigned ArgNo = DV.getArgNumber(); |
| 942 | if (ArgNo == 0) |
| 943 | return false; |
| 944 | |
Devang Patel | cb3a657 | 2011-03-03 20:02:02 +0000 | [diff] [blame] | 945 | size_t Size = CurrentFnArguments.size(); |
| 946 | if (Size == 0) |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 947 | CurrentFnArguments.resize(MF->getFunction()->arg_size()); |
Devang Patel | bbd0f45 | 2011-03-03 21:49:41 +0000 | [diff] [blame] | 948 | // llvm::Function argument size is not good indicator of how many |
Devang Patel | 6f676be | 2011-03-03 20:08:10 +0000 | [diff] [blame] | 949 | // arguments does the function have at source level. |
| 950 | if (ArgNo > Size) |
Devang Patel | cb3a657 | 2011-03-03 20:02:02 +0000 | [diff] [blame] | 951 | CurrentFnArguments.resize(ArgNo * 2); |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 952 | CurrentFnArguments[ArgNo - 1] = Var; |
| 953 | return true; |
| 954 | } |
| 955 | |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 956 | /// collectVariableInfoFromMMITable - Collect variable information from |
| 957 | /// side table maintained by MMI. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 958 | void |
Nick Lewycky | 3bbb6f7 | 2011-07-29 03:49:23 +0000 | [diff] [blame] | 959 | DwarfDebug::collectVariableInfoFromMMITable(const MachineFunction *MF, |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 960 | SmallPtrSet<const MDNode *, 16> &Processed) { |
Devang Patel | e717faa | 2009-10-06 01:26:37 +0000 | [diff] [blame] | 961 | MachineModuleInfo::VariableDbgInfoMapTy &VMap = MMI->getVariableDbgInfo(); |
| 962 | for (MachineModuleInfo::VariableDbgInfoMapTy::iterator VI = VMap.begin(), |
| 963 | VE = VMap.end(); VI != VE; ++VI) { |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 964 | const MDNode *Var = VI->first; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 965 | if (!Var) continue; |
Devang Patel | 98e1cac | 2010-05-14 21:01:35 +0000 | [diff] [blame] | 966 | Processed.insert(Var); |
Chris Lattner | de4845c | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 967 | DIVariable DV(Var); |
| 968 | const std::pair<unsigned, DebugLoc> &VP = VI->second; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 969 | |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 970 | LexicalScope *Scope = LScopes.findLexicalScope(VP.second); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 971 | |
Devang Patel | fb0ee43 | 2009-11-10 23:20:04 +0000 | [diff] [blame] | 972 | // If variable scope is not found then skip this variable. |
Chris Lattner | de4845c | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 973 | if (Scope == 0) |
Devang Patel | fb0ee43 | 2009-11-10 23:20:04 +0000 | [diff] [blame] | 974 | continue; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 975 | |
Devang Patel | 26c1e56 | 2010-05-20 16:36:41 +0000 | [diff] [blame] | 976 | DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.second); |
Devang Patel | 5a1a67c | 2011-08-15 19:01:20 +0000 | [diff] [blame] | 977 | DbgVariable *RegVar = new DbgVariable(DV, AbsDbgVariable); |
Devang Patel | ff9dd0a | 2011-08-15 21:24:36 +0000 | [diff] [blame] | 978 | RegVar->setFrameIndex(VP.first); |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 979 | if (!addCurrentFnArgument(MF, RegVar, Scope)) |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 980 | addScopeVariable(Scope, RegVar); |
Devang Patel | 5a1a67c | 2011-08-15 19:01:20 +0000 | [diff] [blame] | 981 | if (AbsDbgVariable) |
Devang Patel | ff9dd0a | 2011-08-15 21:24:36 +0000 | [diff] [blame] | 982 | AbsDbgVariable->setFrameIndex(VP.first); |
Devang Patel | e717faa | 2009-10-06 01:26:37 +0000 | [diff] [blame] | 983 | } |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 984 | } |
Devang Patel | 90a48ad | 2010-03-15 18:33:46 +0000 | [diff] [blame] | 985 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 986 | /// isDbgValueInDefinedReg - Return true if debug value, encoded by |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 987 | /// DBG_VALUE instruction, is in a defined reg. |
| 988 | static bool isDbgValueInDefinedReg(const MachineInstr *MI) { |
Nick Lewycky | 746cb67 | 2011-10-26 22:55:33 +0000 | [diff] [blame] | 989 | assert(MI->isDebugValue() && "Invalid DBG_VALUE machine instruction!"); |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 990 | return MI->getNumOperands() == 3 && |
| 991 | MI->getOperand(0).isReg() && MI->getOperand(0).getReg() && |
| 992 | MI->getOperand(1).isImm() && MI->getOperand(1).getImm() == 0; |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 993 | } |
| 994 | |
Nick Lewycky | 3bbb6f7 | 2011-07-29 03:49:23 +0000 | [diff] [blame] | 995 | /// getDebugLocEntry - Get .debug_loc entry for the instruction range starting |
Devang Patel | 90b4041 | 2011-07-08 17:09:57 +0000 | [diff] [blame] | 996 | /// at MI. |
| 997 | static DotDebugLocEntry getDebugLocEntry(AsmPrinter *Asm, |
| 998 | const MCSymbol *FLabel, |
| 999 | const MCSymbol *SLabel, |
| 1000 | const MachineInstr *MI) { |
| 1001 | const MDNode *Var = MI->getOperand(MI->getNumOperands() - 1).getMetadata(); |
| 1002 | |
| 1003 | if (MI->getNumOperands() != 3) { |
| 1004 | MachineLocation MLoc = Asm->getDebugValueLocation(MI); |
| 1005 | return DotDebugLocEntry(FLabel, SLabel, MLoc, Var); |
| 1006 | } |
| 1007 | if (MI->getOperand(0).isReg() && MI->getOperand(1).isImm()) { |
| 1008 | MachineLocation MLoc; |
| 1009 | MLoc.set(MI->getOperand(0).getReg(), MI->getOperand(1).getImm()); |
| 1010 | return DotDebugLocEntry(FLabel, SLabel, MLoc, Var); |
| 1011 | } |
| 1012 | if (MI->getOperand(0).isImm()) |
| 1013 | return DotDebugLocEntry(FLabel, SLabel, MI->getOperand(0).getImm()); |
| 1014 | if (MI->getOperand(0).isFPImm()) |
| 1015 | return DotDebugLocEntry(FLabel, SLabel, MI->getOperand(0).getFPImm()); |
| 1016 | if (MI->getOperand(0).isCImm()) |
| 1017 | return DotDebugLocEntry(FLabel, SLabel, MI->getOperand(0).getCImm()); |
| 1018 | |
Craig Topper | 5e25ee8 | 2012-02-05 08:31:47 +0000 | [diff] [blame] | 1019 | llvm_unreachable("Unexpected 3 operand DBG_VALUE instruction!"); |
Devang Patel | 90b4041 | 2011-07-08 17:09:57 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1022 | /// collectVariableInfo - Find variables for each lexical scope. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1023 | void |
Devang Patel | 78e127d | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 1024 | DwarfDebug::collectVariableInfo(const MachineFunction *MF, |
| 1025 | SmallPtrSet<const MDNode *, 16> &Processed) { |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1026 | |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 1027 | /// collection info from MMI table. |
| 1028 | collectVariableInfoFromMMITable(MF, Processed); |
| 1029 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1030 | for (SmallVectorImpl<const MDNode*>::const_iterator |
| 1031 | UVI = UserVariables.begin(), UVE = UserVariables.end(); UVI != UVE; |
| 1032 | ++UVI) { |
| 1033 | const MDNode *Var = *UVI; |
| 1034 | if (Processed.count(Var)) |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 1035 | continue; |
| 1036 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1037 | // History contains relevant DBG_VALUE instructions for Var and instructions |
| 1038 | // clobbering it. |
| 1039 | SmallVectorImpl<const MachineInstr*> &History = DbgValues[Var]; |
| 1040 | if (History.empty()) |
| 1041 | continue; |
| 1042 | const MachineInstr *MInsn = History.front(); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1043 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1044 | DIVariable DV(Var); |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1045 | LexicalScope *Scope = NULL; |
Devang Patel | d8720f4 | 2010-05-27 20:25:04 +0000 | [diff] [blame] | 1046 | if (DV.getTag() == dwarf::DW_TAG_arg_variable && |
| 1047 | DISubprogram(DV.getContext()).describes(MF->getFunction())) |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1048 | Scope = LScopes.getCurrentFunctionScope(); |
Devang Patel | 40c7e41 | 2011-07-20 22:18:50 +0000 | [diff] [blame] | 1049 | else { |
| 1050 | if (DV.getVersion() <= LLVMDebugVersion9) |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1051 | Scope = LScopes.findLexicalScope(MInsn->getDebugLoc()); |
Devang Patel | 40c7e41 | 2011-07-20 22:18:50 +0000 | [diff] [blame] | 1052 | else { |
| 1053 | if (MDNode *IA = DV.getInlinedAt()) |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1054 | Scope = LScopes.findInlinedScope(DebugLoc::getFromDILocation(IA)); |
Devang Patel | 40c7e41 | 2011-07-20 22:18:50 +0000 | [diff] [blame] | 1055 | else |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1056 | Scope = LScopes.findLexicalScope(cast<MDNode>(DV->getOperand(1))); |
Devang Patel | 40c7e41 | 2011-07-20 22:18:50 +0000 | [diff] [blame] | 1057 | } |
| 1058 | } |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 1059 | // If variable scope is not found then skip this variable. |
Devang Patel | c0c5a26 | 2010-05-21 00:10:20 +0000 | [diff] [blame] | 1060 | if (!Scope) |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 1061 | continue; |
| 1062 | |
| 1063 | Processed.insert(DV); |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1064 | assert(MInsn->isDebugValue() && "History must begin with debug value"); |
Devang Patel | 5a1a67c | 2011-08-15 19:01:20 +0000 | [diff] [blame] | 1065 | DbgVariable *AbsVar = findAbstractVariable(DV, MInsn->getDebugLoc()); |
| 1066 | DbgVariable *RegVar = new DbgVariable(DV, AbsVar); |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 1067 | if (!addCurrentFnArgument(MF, RegVar, Scope)) |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1068 | addScopeVariable(Scope, RegVar); |
Devang Patel | 5a1a67c | 2011-08-15 19:01:20 +0000 | [diff] [blame] | 1069 | if (AbsVar) |
Devang Patel | ff9dd0a | 2011-08-15 21:24:36 +0000 | [diff] [blame] | 1070 | AbsVar->setMInsn(MInsn); |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1071 | |
Eric Christopher | c56e3f0 | 2012-10-08 20:48:54 +0000 | [diff] [blame] | 1072 | // Simplify ranges that are fully coalesced. |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1073 | if (History.size() <= 1 || (History.size() == 2 && |
| 1074 | MInsn->isIdenticalTo(History.back()))) { |
Devang Patel | ff9dd0a | 2011-08-15 21:24:36 +0000 | [diff] [blame] | 1075 | RegVar->setMInsn(MInsn); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1076 | continue; |
| 1077 | } |
| 1078 | |
| 1079 | // handle multiple DBG_VALUE instructions describing one variable. |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1080 | RegVar->setDotDebugLocOffset(DotDebugLocEntries.size()); |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1081 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1082 | for (SmallVectorImpl<const MachineInstr*>::const_iterator |
| 1083 | HI = History.begin(), HE = History.end(); HI != HE; ++HI) { |
| 1084 | const MachineInstr *Begin = *HI; |
| 1085 | assert(Begin->isDebugValue() && "Invalid History entry"); |
Jakob Stoklund Olesen | e17232e | 2011-03-22 00:21:41 +0000 | [diff] [blame] | 1086 | |
Devang Patel | 4ada1d7 | 2011-06-01 23:00:17 +0000 | [diff] [blame] | 1087 | // Check if DBG_VALUE is truncating a range. |
| 1088 | if (Begin->getNumOperands() > 1 && Begin->getOperand(0).isReg() |
| 1089 | && !Begin->getOperand(0).getReg()) |
| 1090 | continue; |
| 1091 | |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1092 | // Compute the range for a register location. |
| 1093 | const MCSymbol *FLabel = getLabelBeforeInsn(Begin); |
| 1094 | const MCSymbol *SLabel = 0; |
| 1095 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1096 | if (HI + 1 == HE) |
| 1097 | // If Begin is the last instruction in History then its value is valid |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 1098 | // until the end of the function. |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1099 | SLabel = FunctionEndSym; |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1100 | else { |
| 1101 | const MachineInstr *End = HI[1]; |
Devang Patel | 476df5f | 2011-07-07 21:44:42 +0000 | [diff] [blame] | 1102 | DEBUG(dbgs() << "DotDebugLoc Pair:\n" |
| 1103 | << "\t" << *Begin << "\t" << *End << "\n"); |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1104 | if (End->isDebugValue()) |
| 1105 | SLabel = getLabelBeforeInsn(End); |
| 1106 | else { |
| 1107 | // End is a normal instruction clobbering the range. |
| 1108 | SLabel = getLabelAfterInsn(End); |
| 1109 | assert(SLabel && "Forgot label after clobber instruction"); |
| 1110 | ++HI; |
| 1111 | } |
| 1112 | } |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1113 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1114 | // The value is valid until the next DBG_VALUE or clobber. |
Eric Christopher | abbb200 | 2011-12-16 23:42:31 +0000 | [diff] [blame] | 1115 | DotDebugLocEntries.push_back(getDebugLocEntry(Asm, FLabel, SLabel, |
| 1116 | Begin)); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1117 | } |
| 1118 | DotDebugLocEntries.push_back(DotDebugLocEntry()); |
Devang Patel | 90a48ad | 2010-03-15 18:33:46 +0000 | [diff] [blame] | 1119 | } |
Devang Patel | 98e1cac | 2010-05-14 21:01:35 +0000 | [diff] [blame] | 1120 | |
| 1121 | // Collect info for variables that were optimized out. |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 1122 | LexicalScope *FnScope = LScopes.getCurrentFunctionScope(); |
| 1123 | DIArray Variables = DISubprogram(FnScope->getScopeNode()).getVariables(); |
| 1124 | for (unsigned i = 0, e = Variables.getNumElements(); i != e; ++i) { |
| 1125 | DIVariable DV(Variables.getElement(i)); |
| 1126 | if (!DV || !DV.Verify() || !Processed.insert(DV)) |
| 1127 | continue; |
| 1128 | if (LexicalScope *Scope = LScopes.findLexicalScope(DV.getContext())) |
| 1129 | addScopeVariable(Scope, new DbgVariable(DV, NULL)); |
Devang Patel | 98e1cac | 2010-05-14 21:01:35 +0000 | [diff] [blame] | 1130 | } |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1131 | } |
Devang Patel | 98e1cac | 2010-05-14 21:01:35 +0000 | [diff] [blame] | 1132 | |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1133 | /// getLabelBeforeInsn - Return Label preceding the instruction. |
| 1134 | const MCSymbol *DwarfDebug::getLabelBeforeInsn(const MachineInstr *MI) { |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1135 | MCSymbol *Label = LabelsBeforeInsn.lookup(MI); |
| 1136 | assert(Label && "Didn't insert label before instruction"); |
| 1137 | return Label; |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | /// getLabelAfterInsn - Return Label immediately following the instruction. |
| 1141 | const MCSymbol *DwarfDebug::getLabelAfterInsn(const MachineInstr *MI) { |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1142 | return LabelsAfterInsn.lookup(MI); |
Devang Patel | e717faa | 2009-10-06 01:26:37 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
Devang Patel | cbbe287 | 2010-10-26 17:49:02 +0000 | [diff] [blame] | 1145 | /// beginInstruction - Process beginning of an instruction. |
| 1146 | void DwarfDebug::beginInstruction(const MachineInstr *MI) { |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1147 | // Check if source location changes, but ignore DBG_VALUE locations. |
| 1148 | if (!MI->isDebugValue()) { |
| 1149 | DebugLoc DL = MI->getDebugLoc(); |
| 1150 | if (DL != PrevInstLoc && (!DL.isUnknown() || UnknownLocations)) { |
Eric Christopher | 60b35f4 | 2012-04-05 20:39:05 +0000 | [diff] [blame] | 1151 | unsigned Flags = 0; |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1152 | PrevInstLoc = DL; |
Devang Patel | 4243e67 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1153 | if (DL == PrologEndLoc) { |
| 1154 | Flags |= DWARF2_FLAG_PROLOGUE_END; |
| 1155 | PrologEndLoc = DebugLoc(); |
| 1156 | } |
Eric Christopher | 60b35f4 | 2012-04-05 20:39:05 +0000 | [diff] [blame] | 1157 | if (PrologEndLoc.isUnknown()) |
| 1158 | Flags |= DWARF2_FLAG_IS_STMT; |
| 1159 | |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1160 | if (!DL.isUnknown()) { |
| 1161 | const MDNode *Scope = DL.getScope(Asm->MF->getFunction()->getContext()); |
Devang Patel | 4243e67 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1162 | recordSourceLine(DL.getLine(), DL.getCol(), Scope, Flags); |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1163 | } else |
Devang Patel | 4243e67 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1164 | recordSourceLine(0, 0, 0, 0); |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1165 | } |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1166 | } |
Devang Patel | aead63c | 2010-03-29 22:59:58 +0000 | [diff] [blame] | 1167 | |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1168 | // Insert labels where requested. |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1169 | DenseMap<const MachineInstr*, MCSymbol*>::iterator I = |
| 1170 | LabelsBeforeInsn.find(MI); |
| 1171 | |
| 1172 | // No label needed. |
| 1173 | if (I == LabelsBeforeInsn.end()) |
| 1174 | return; |
| 1175 | |
| 1176 | // Label already assigned. |
| 1177 | if (I->second) |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1178 | return; |
Devang Patel | 553881b | 2010-03-29 17:20:31 +0000 | [diff] [blame] | 1179 | |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1180 | if (!PrevLabel) { |
Devang Patel | 77051f5 | 2010-05-26 21:23:46 +0000 | [diff] [blame] | 1181 | PrevLabel = MMI->getContext().CreateTempSymbol(); |
| 1182 | Asm->OutStreamer.EmitLabel(PrevLabel); |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1183 | } |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1184 | I->second = PrevLabel; |
Devang Patel | 0d20ac8 | 2009-10-06 01:50:42 +0000 | [diff] [blame] | 1185 | } |
| 1186 | |
Devang Patel | cbbe287 | 2010-10-26 17:49:02 +0000 | [diff] [blame] | 1187 | /// endInstruction - Process end of an instruction. |
| 1188 | void DwarfDebug::endInstruction(const MachineInstr *MI) { |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1189 | // Don't create a new label after DBG_VALUE instructions. |
| 1190 | // They don't generate code. |
| 1191 | if (!MI->isDebugValue()) |
| 1192 | PrevLabel = 0; |
| 1193 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1194 | DenseMap<const MachineInstr*, MCSymbol*>::iterator I = |
| 1195 | LabelsAfterInsn.find(MI); |
| 1196 | |
| 1197 | // No label needed. |
| 1198 | if (I == LabelsAfterInsn.end()) |
| 1199 | return; |
| 1200 | |
| 1201 | // Label already assigned. |
| 1202 | if (I->second) |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1203 | return; |
| 1204 | |
| 1205 | // We need a label after this instruction. |
| 1206 | if (!PrevLabel) { |
| 1207 | PrevLabel = MMI->getContext().CreateTempSymbol(); |
| 1208 | Asm->OutStreamer.EmitLabel(PrevLabel); |
Devang Patel | 1c24635 | 2010-04-08 16:50:29 +0000 | [diff] [blame] | 1209 | } |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1210 | I->second = PrevLabel; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1213 | /// identifyScopeMarkers() - |
Devang Patel | 5bc942c | 2011-08-10 23:58:09 +0000 | [diff] [blame] | 1214 | /// Each LexicalScope has first instruction and last instruction to mark |
| 1215 | /// beginning and end of a scope respectively. Create an inverse map that list |
| 1216 | /// scopes starts (and ends) with an instruction. One instruction may start (or |
| 1217 | /// end) multiple scopes. Ignore scopes that are not reachable. |
Devang Patel | e37b0c6 | 2010-04-08 18:43:56 +0000 | [diff] [blame] | 1218 | void DwarfDebug::identifyScopeMarkers() { |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1219 | SmallVector<LexicalScope *, 4> WorkList; |
| 1220 | WorkList.push_back(LScopes.getCurrentFunctionScope()); |
Devang Patel | 42aafd7 | 2010-01-20 02:05:23 +0000 | [diff] [blame] | 1221 | while (!WorkList.empty()) { |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1222 | LexicalScope *S = WorkList.pop_back_val(); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1223 | |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1224 | const SmallVector<LexicalScope *, 4> &Children = S->getChildren(); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1225 | if (!Children.empty()) |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1226 | for (SmallVector<LexicalScope *, 4>::const_iterator SI = Children.begin(), |
Devang Patel | 42aafd7 | 2010-01-20 02:05:23 +0000 | [diff] [blame] | 1227 | SE = Children.end(); SI != SE; ++SI) |
| 1228 | WorkList.push_back(*SI); |
| 1229 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1230 | if (S->isAbstractScope()) |
| 1231 | continue; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1232 | |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1233 | const SmallVector<InsnRange, 4> &Ranges = S->getRanges(); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1234 | if (Ranges.empty()) |
| 1235 | continue; |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1236 | for (SmallVector<InsnRange, 4>::const_iterator RI = Ranges.begin(), |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1237 | RE = Ranges.end(); RI != RE; ++RI) { |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1238 | assert(RI->first && "InsnRange does not have first instruction!"); |
| 1239 | assert(RI->second && "InsnRange does not have second instruction!"); |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1240 | requestLabelBeforeInsn(RI->first); |
| 1241 | requestLabelAfterInsn(RI->second); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1242 | } |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1243 | } |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1244 | } |
| 1245 | |
Devang Patel | a3f4867 | 2011-05-09 22:14:49 +0000 | [diff] [blame] | 1246 | /// getScopeNode - Get MDNode for DebugLoc's scope. |
| 1247 | static MDNode *getScopeNode(DebugLoc DL, const LLVMContext &Ctx) { |
| 1248 | if (MDNode *InlinedAt = DL.getInlinedAt(Ctx)) |
| 1249 | return getScopeNode(DebugLoc::getFromDILocation(InlinedAt), Ctx); |
| 1250 | return DL.getScope(Ctx); |
| 1251 | } |
| 1252 | |
Devang Patel | 4243e67 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1253 | /// getFnDebugLoc - Walk up the scope chain of given debug loc and find |
Eric Christopher | 6126a1e | 2012-04-03 00:43:49 +0000 | [diff] [blame] | 1254 | /// line number info for the function. |
Devang Patel | 4243e67 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1255 | static DebugLoc getFnDebugLoc(DebugLoc DL, const LLVMContext &Ctx) { |
| 1256 | const MDNode *Scope = getScopeNode(DL, Ctx); |
| 1257 | DISubprogram SP = getDISubprogram(Scope); |
Eric Christopher | 6126a1e | 2012-04-03 00:43:49 +0000 | [diff] [blame] | 1258 | if (SP.Verify()) { |
| 1259 | // Check for number of operands since the compatibility is |
| 1260 | // cheap here. |
Eric Christopher | fa5b050 | 2012-04-03 17:55:42 +0000 | [diff] [blame] | 1261 | if (SP->getNumOperands() > 19) |
Eric Christopher | 6126a1e | 2012-04-03 00:43:49 +0000 | [diff] [blame] | 1262 | return DebugLoc::get(SP.getScopeLineNumber(), 0, SP); |
| 1263 | else |
| 1264 | return DebugLoc::get(SP.getLineNumber(), 0, SP); |
| 1265 | } |
| 1266 | |
Devang Patel | 4243e67 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1267 | return DebugLoc(); |
| 1268 | } |
| 1269 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1270 | /// beginFunction - Gather pre-function debug information. Assumes being |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1271 | /// emitted immediately after the function entry point. |
Chris Lattner | eec791a | 2010-01-26 23:18:02 +0000 | [diff] [blame] | 1272 | void DwarfDebug::beginFunction(const MachineFunction *MF) { |
Chris Lattner | 994cb12 | 2010-04-05 03:52:55 +0000 | [diff] [blame] | 1273 | if (!MMI->hasDebugInfo()) return; |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1274 | LScopes.initialize(*MF); |
| 1275 | if (LScopes.empty()) return; |
| 1276 | identifyScopeMarkers(); |
Devang Patel | 60b35bd | 2009-10-06 18:37:31 +0000 | [diff] [blame] | 1277 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1278 | FunctionBeginSym = Asm->GetTempSymbol("func_begin", |
| 1279 | Asm->getFunctionNumber()); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1280 | // Assumes in correct section after the entry point. |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1281 | Asm->OutStreamer.EmitLabel(FunctionBeginSym); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1282 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1283 | assert(UserVariables.empty() && DbgValues.empty() && "Maps weren't cleaned"); |
| 1284 | |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1285 | const TargetRegisterInfo *TRI = Asm->TM.getRegisterInfo(); |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1286 | /// LiveUserVar - Map physreg numbers to the MDNode they contain. |
| 1287 | std::vector<const MDNode*> LiveUserVar(TRI->getNumRegs()); |
| 1288 | |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1289 | for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1290 | I != E; ++I) { |
| 1291 | bool AtBlockEntry = true; |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1292 | for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end(); |
| 1293 | II != IE; ++II) { |
| 1294 | const MachineInstr *MI = II; |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1295 | |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1296 | if (MI->isDebugValue()) { |
Nick Lewycky | 746cb67 | 2011-10-26 22:55:33 +0000 | [diff] [blame] | 1297 | assert(MI->getNumOperands() > 1 && "Invalid machine instruction!"); |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1298 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1299 | // Keep track of user variables. |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1300 | const MDNode *Var = |
| 1301 | MI->getOperand(MI->getNumOperands() - 1).getMetadata(); |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1302 | |
| 1303 | // Variable is in a register, we need to check for clobbers. |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1304 | if (isDbgValueInDefinedReg(MI)) |
| 1305 | LiveUserVar[MI->getOperand(0).getReg()] = Var; |
| 1306 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1307 | // Check the history of this variable. |
| 1308 | SmallVectorImpl<const MachineInstr*> &History = DbgValues[Var]; |
| 1309 | if (History.empty()) { |
| 1310 | UserVariables.push_back(Var); |
| 1311 | // The first mention of a function argument gets the FunctionBeginSym |
| 1312 | // label, so arguments are visible when breaking at function entry. |
| 1313 | DIVariable DV(Var); |
| 1314 | if (DV.Verify() && DV.getTag() == dwarf::DW_TAG_arg_variable && |
| 1315 | DISubprogram(getDISubprogram(DV.getContext())) |
| 1316 | .describes(MF->getFunction())) |
| 1317 | LabelsBeforeInsn[MI] = FunctionBeginSym; |
| 1318 | } else { |
| 1319 | // We have seen this variable before. Try to coalesce DBG_VALUEs. |
| 1320 | const MachineInstr *Prev = History.back(); |
| 1321 | if (Prev->isDebugValue()) { |
| 1322 | // Coalesce identical entries at the end of History. |
| 1323 | if (History.size() >= 2 && |
Devang Patel | 7986289 | 2011-07-07 00:14:27 +0000 | [diff] [blame] | 1324 | Prev->isIdenticalTo(History[History.size() - 2])) { |
Eric Christopher | 02c1a64 | 2012-10-08 20:48:49 +0000 | [diff] [blame] | 1325 | DEBUG(dbgs() << "Coalescing identical DBG_VALUE entries:\n" |
Devang Patel | 7986289 | 2011-07-07 00:14:27 +0000 | [diff] [blame] | 1326 | << "\t" << *Prev |
| 1327 | << "\t" << *History[History.size() - 2] << "\n"); |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1328 | History.pop_back(); |
Devang Patel | 7986289 | 2011-07-07 00:14:27 +0000 | [diff] [blame] | 1329 | } |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1330 | |
| 1331 | // Terminate old register assignments that don't reach MI; |
| 1332 | MachineFunction::const_iterator PrevMBB = Prev->getParent(); |
| 1333 | if (PrevMBB != I && (!AtBlockEntry || llvm::next(PrevMBB) != I) && |
| 1334 | isDbgValueInDefinedReg(Prev)) { |
| 1335 | // Previous register assignment needs to terminate at the end of |
| 1336 | // its basic block. |
| 1337 | MachineBasicBlock::const_iterator LastMI = |
| 1338 | PrevMBB->getLastNonDebugInstr(); |
Devang Patel | 7986289 | 2011-07-07 00:14:27 +0000 | [diff] [blame] | 1339 | if (LastMI == PrevMBB->end()) { |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1340 | // Drop DBG_VALUE for empty range. |
Eric Christopher | 02c1a64 | 2012-10-08 20:48:49 +0000 | [diff] [blame] | 1341 | DEBUG(dbgs() << "Dropping DBG_VALUE for empty range:\n" |
Devang Patel | 7986289 | 2011-07-07 00:14:27 +0000 | [diff] [blame] | 1342 | << "\t" << *Prev << "\n"); |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1343 | History.pop_back(); |
Devang Patel | 7986289 | 2011-07-07 00:14:27 +0000 | [diff] [blame] | 1344 | } |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1345 | else { |
| 1346 | // Terminate after LastMI. |
| 1347 | History.push_back(LastMI); |
| 1348 | } |
| 1349 | } |
| 1350 | } |
| 1351 | } |
| 1352 | History.push_back(MI); |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1353 | } else { |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1354 | // Not a DBG_VALUE instruction. |
| 1355 | if (!MI->isLabel()) |
| 1356 | AtBlockEntry = false; |
| 1357 | |
Eric Christopher | 0313ced | 2012-10-04 20:46:14 +0000 | [diff] [blame] | 1358 | // First known non-DBG_VALUE and non-frame setup location marks |
| 1359 | // the beginning of the function body. |
| 1360 | if (!MI->getFlag(MachineInstr::FrameSetup) && |
| 1361 | (PrologEndLoc.isUnknown() && !MI->getDebugLoc().isUnknown())) |
Devang Patel | 4243e67 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1362 | PrologEndLoc = MI->getDebugLoc(); |
| 1363 | |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1364 | // Check if the instruction clobbers any registers with debug vars. |
| 1365 | for (MachineInstr::const_mop_iterator MOI = MI->operands_begin(), |
| 1366 | MOE = MI->operands_end(); MOI != MOE; ++MOI) { |
| 1367 | if (!MOI->isReg() || !MOI->isDef() || !MOI->getReg()) |
| 1368 | continue; |
Jakob Stoklund Olesen | 396618b | 2012-06-01 23:28:30 +0000 | [diff] [blame] | 1369 | for (MCRegAliasIterator AI(MOI->getReg(), TRI, true); |
| 1370 | AI.isValid(); ++AI) { |
| 1371 | unsigned Reg = *AI; |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1372 | const MDNode *Var = LiveUserVar[Reg]; |
| 1373 | if (!Var) |
| 1374 | continue; |
| 1375 | // Reg is now clobbered. |
| 1376 | LiveUserVar[Reg] = 0; |
| 1377 | |
| 1378 | // Was MD last defined by a DBG_VALUE referring to Reg? |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1379 | DbgValueHistoryMap::iterator HistI = DbgValues.find(Var); |
| 1380 | if (HistI == DbgValues.end()) |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1381 | continue; |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1382 | SmallVectorImpl<const MachineInstr*> &History = HistI->second; |
| 1383 | if (History.empty()) |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1384 | continue; |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1385 | const MachineInstr *Prev = History.back(); |
| 1386 | // Sanity-check: Register assignments are terminated at the end of |
| 1387 | // their block. |
| 1388 | if (!Prev->isDebugValue() || Prev->getParent() != MI->getParent()) |
| 1389 | continue; |
| 1390 | // Is the variable still in Reg? |
| 1391 | if (!isDbgValueInDefinedReg(Prev) || |
| 1392 | Prev->getOperand(0).getReg() != Reg) |
| 1393 | continue; |
| 1394 | // Var is clobbered. Make sure the next instruction gets a label. |
| 1395 | History.push_back(MI); |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1396 | } |
| 1397 | } |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1398 | } |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1399 | } |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | for (DbgValueHistoryMap::iterator I = DbgValues.begin(), E = DbgValues.end(); |
| 1403 | I != E; ++I) { |
| 1404 | SmallVectorImpl<const MachineInstr*> &History = I->second; |
| 1405 | if (History.empty()) |
| 1406 | continue; |
| 1407 | |
| 1408 | // Make sure the final register assignments are terminated. |
| 1409 | const MachineInstr *Prev = History.back(); |
| 1410 | if (Prev->isDebugValue() && isDbgValueInDefinedReg(Prev)) { |
| 1411 | const MachineBasicBlock *PrevMBB = Prev->getParent(); |
Devang Patel | 5bc942c | 2011-08-10 23:58:09 +0000 | [diff] [blame] | 1412 | MachineBasicBlock::const_iterator LastMI = |
| 1413 | PrevMBB->getLastNonDebugInstr(); |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1414 | if (LastMI == PrevMBB->end()) |
| 1415 | // Drop DBG_VALUE for empty range. |
| 1416 | History.pop_back(); |
| 1417 | else { |
| 1418 | // Terminate after LastMI. |
| 1419 | History.push_back(LastMI); |
| 1420 | } |
| 1421 | } |
| 1422 | // Request labels for the full history. |
| 1423 | for (unsigned i = 0, e = History.size(); i != e; ++i) { |
| 1424 | const MachineInstr *MI = History[i]; |
| 1425 | if (MI->isDebugValue()) |
| 1426 | requestLabelBeforeInsn(MI); |
| 1427 | else |
| 1428 | requestLabelAfterInsn(MI); |
| 1429 | } |
| 1430 | } |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1431 | |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1432 | PrevInstLoc = DebugLoc(); |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1433 | PrevLabel = FunctionBeginSym; |
Devang Patel | 4243e67 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1434 | |
| 1435 | // Record beginning of function. |
| 1436 | if (!PrologEndLoc.isUnknown()) { |
| 1437 | DebugLoc FnStartDL = getFnDebugLoc(PrologEndLoc, |
| 1438 | MF->getFunction()->getContext()); |
| 1439 | recordSourceLine(FnStartDL.getLine(), FnStartDL.getCol(), |
| 1440 | FnStartDL.getScope(MF->getFunction()->getContext()), |
Eric Christopher | 09e4750 | 2012-09-10 23:34:06 +0000 | [diff] [blame] | 1441 | 0); |
Devang Patel | 4243e67 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1442 | } |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1443 | } |
| 1444 | |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1445 | void DwarfDebug::addScopeVariable(LexicalScope *LS, DbgVariable *Var) { |
| 1446 | // SmallVector<DbgVariable *, 8> &Vars = ScopeVariables.lookup(LS); |
| 1447 | ScopeVariables[LS].push_back(Var); |
| 1448 | // Vars.push_back(Var); |
| 1449 | } |
| 1450 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1451 | /// endFunction - Gather and emit post-function debug information. |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1452 | /// |
Chris Lattner | eec791a | 2010-01-26 23:18:02 +0000 | [diff] [blame] | 1453 | void DwarfDebug::endFunction(const MachineFunction *MF) { |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1454 | if (!MMI->hasDebugInfo() || LScopes.empty()) return; |
Devang Patel | 70d75ca | 2009-11-12 19:02:56 +0000 | [diff] [blame] | 1455 | |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1456 | // Define end label for subprogram. |
| 1457 | FunctionEndSym = Asm->GetTempSymbol("func_end", |
| 1458 | Asm->getFunctionNumber()); |
| 1459 | // Assumes in correct section after the entry point. |
| 1460 | Asm->OutStreamer.EmitLabel(FunctionEndSym); |
| 1461 | |
| 1462 | SmallPtrSet<const MDNode *, 16> ProcessedVars; |
| 1463 | collectVariableInfo(MF, ProcessedVars); |
| 1464 | |
Devang Patel | d0b5a5e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1465 | LexicalScope *FnScope = LScopes.getCurrentFunctionScope(); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 1466 | CompileUnit *TheCU = SPMap.lookup(FnScope->getScopeNode()); |
Nick Lewycky | 746cb67 | 2011-10-26 22:55:33 +0000 | [diff] [blame] | 1467 | assert(TheCU && "Unable to find compile unit!"); |
Devang Patel | d0b5a5e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1468 | |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1469 | // Construct abstract scopes. |
Devang Patel | cd9f6c5 | 2011-08-12 18:10:19 +0000 | [diff] [blame] | 1470 | ArrayRef<LexicalScope *> AList = LScopes.getAbstractScopesList(); |
| 1471 | for (unsigned i = 0, e = AList.size(); i != e; ++i) { |
| 1472 | LexicalScope *AScope = AList[i]; |
| 1473 | DISubprogram SP(AScope->getScopeNode()); |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1474 | if (SP.Verify()) { |
| 1475 | // Collect info for variables that were optimized out. |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 1476 | DIArray Variables = SP.getVariables(); |
| 1477 | for (unsigned i = 0, e = Variables.getNumElements(); i != e; ++i) { |
| 1478 | DIVariable DV(Variables.getElement(i)); |
| 1479 | if (!DV || !DV.Verify() || !ProcessedVars.insert(DV)) |
| 1480 | continue; |
Alexey Samsonov | b67bd33 | 2012-07-06 08:45:08 +0000 | [diff] [blame] | 1481 | // Check that DbgVariable for DV wasn't created earlier, when |
| 1482 | // findAbstractVariable() was called for inlined instance of DV. |
| 1483 | LLVMContext &Ctx = DV->getContext(); |
| 1484 | DIVariable CleanDV = cleanseInlinedVariable(DV, Ctx); |
| 1485 | if (AbstractVariables.lookup(CleanDV)) |
| 1486 | continue; |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 1487 | if (LexicalScope *Scope = LScopes.findAbstractScope(DV.getContext())) |
| 1488 | addScopeVariable(Scope, new DbgVariable(DV, NULL)); |
Devang Patel | 78e127d | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 1489 | } |
| 1490 | } |
Devang Patel | cd9f6c5 | 2011-08-12 18:10:19 +0000 | [diff] [blame] | 1491 | if (ProcessedSPNodes.count(AScope->getScopeNode()) == 0) |
Devang Patel | d0b5a5e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1492 | constructScopeDIE(TheCU, AScope); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1493 | } |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1494 | |
Devang Patel | d0b5a5e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1495 | DIE *CurFnDIE = constructScopeDIE(TheCU, FnScope); |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1496 | |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 1497 | if (!MF->getTarget().Options.DisableFramePointerElim(*MF)) |
Eric Christopher | 873cf0a | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1498 | TheCU->addFlag(CurFnDIE, dwarf::DW_AT_APPLE_omit_frame_ptr); |
Devang Patel | d0b5a5e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1499 | |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1500 | DebugFrames.push_back(FunctionDebugFrameInfo(Asm->getFunctionNumber(), |
| 1501 | MMI->getFrameMoves())); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1502 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1503 | // Clear debug info |
Devang Patel | bf47fdb | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1504 | for (DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8> >::iterator |
| 1505 | I = ScopeVariables.begin(), E = ScopeVariables.end(); I != E; ++I) |
| 1506 | DeleteContainerPointers(I->second); |
| 1507 | ScopeVariables.clear(); |
Devang Patel | eac0c9d | 2011-04-22 18:09:57 +0000 | [diff] [blame] | 1508 | DeleteContainerPointers(CurrentFnArguments); |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1509 | UserVariables.clear(); |
| 1510 | DbgValues.clear(); |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 1511 | AbstractVariables.clear(); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1512 | LabelsBeforeInsn.clear(); |
| 1513 | LabelsAfterInsn.clear(); |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 1514 | PrevLabel = NULL; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1515 | } |
| 1516 | |
Chris Lattner | c608784 | 2010-03-09 04:54:43 +0000 | [diff] [blame] | 1517 | /// recordSourceLine - Register a source line with debug info. Returns the |
| 1518 | /// unique label that was emitted and which provides correspondence to |
| 1519 | /// the source line list. |
Devang Patel | 4243e67 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1520 | void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S, |
| 1521 | unsigned Flags) { |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1522 | StringRef Fn; |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 1523 | StringRef Dir; |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 1524 | unsigned Src = 1; |
| 1525 | if (S) { |
| 1526 | DIDescriptor Scope(S); |
Devang Patel | f84548d | 2009-10-05 18:03:19 +0000 | [diff] [blame] | 1527 | |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 1528 | if (Scope.isCompileUnit()) { |
| 1529 | DICompileUnit CU(S); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 1530 | Fn = CU.getFilename(); |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 1531 | Dir = CU.getDirectory(); |
Devang Patel | 3cabc9d | 2010-10-28 17:30:52 +0000 | [diff] [blame] | 1532 | } else if (Scope.isFile()) { |
| 1533 | DIFile F(S); |
Devang Patel | 3cabc9d | 2010-10-28 17:30:52 +0000 | [diff] [blame] | 1534 | Fn = F.getFilename(); |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 1535 | Dir = F.getDirectory(); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 1536 | } else if (Scope.isSubprogram()) { |
| 1537 | DISubprogram SP(S); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 1538 | Fn = SP.getFilename(); |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 1539 | Dir = SP.getDirectory(); |
Eric Christopher | 6618a24 | 2011-10-11 22:59:11 +0000 | [diff] [blame] | 1540 | } else if (Scope.isLexicalBlockFile()) { |
| 1541 | DILexicalBlockFile DBF(S); |
| 1542 | Fn = DBF.getFilename(); |
| 1543 | Dir = DBF.getDirectory(); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 1544 | } else if (Scope.isLexicalBlock()) { |
| 1545 | DILexicalBlock DB(S); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 1546 | Fn = DB.getFilename(); |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 1547 | Dir = DB.getDirectory(); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 1548 | } else |
Craig Topper | 5e25ee8 | 2012-02-05 08:31:47 +0000 | [diff] [blame] | 1549 | llvm_unreachable("Unexpected scope info"); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 1550 | |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 1551 | Src = GetOrCreateSourceID(Fn, Dir); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 1552 | } |
Nick Lewycky | 3bbb6f7 | 2011-07-29 03:49:23 +0000 | [diff] [blame] | 1553 | Asm->OutStreamer.EmitDwarfLocDirective(Src, Line, Col, Flags, 0, 0, Fn); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1554 | } |
| 1555 | |
Bill Wendling | 829e67b | 2009-05-20 23:22:40 +0000 | [diff] [blame] | 1556 | //===----------------------------------------------------------------------===// |
| 1557 | // Emit Methods |
| 1558 | //===----------------------------------------------------------------------===// |
| 1559 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1560 | /// computeSizeAndOffset - Compute the size and offset of a DIE. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1561 | /// |
Jim Grosbach | 7ab38df | 2009-11-22 19:20:36 +0000 | [diff] [blame] | 1562 | unsigned |
| 1563 | DwarfDebug::computeSizeAndOffset(DIE *Die, unsigned Offset, bool Last) { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1564 | // Get the children. |
| 1565 | const std::vector<DIE *> &Children = Die->getChildren(); |
| 1566 | |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1567 | // Record the abbreviation. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1568 | assignAbbrevNumber(Die->getAbbrev()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1569 | |
| 1570 | // Get the abbreviation for this DIE. |
| 1571 | unsigned AbbrevNumber = Die->getAbbrevNumber(); |
| 1572 | const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1]; |
| 1573 | |
| 1574 | // Set DIE offset |
| 1575 | Die->setOffset(Offset); |
| 1576 | |
| 1577 | // Start the size with the size of abbreviation code. |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 1578 | Offset += MCAsmInfo::getULEB128Size(AbbrevNumber); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1579 | |
| 1580 | const SmallVector<DIEValue*, 32> &Values = Die->getValues(); |
| 1581 | const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData(); |
| 1582 | |
| 1583 | // Size the DIE attribute values. |
| 1584 | for (unsigned i = 0, N = Values.size(); i < N; ++i) |
| 1585 | // Size attribute value. |
Chris Lattner | a37d538 | 2010-04-05 00:18:22 +0000 | [diff] [blame] | 1586 | Offset += Values[i]->SizeOf(Asm, AbbrevData[i].getForm()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1587 | |
| 1588 | // Size the DIE children if any. |
| 1589 | if (!Children.empty()) { |
| 1590 | assert(Abbrev->getChildrenFlag() == dwarf::DW_CHILDREN_yes && |
| 1591 | "Children flag not set"); |
| 1592 | |
| 1593 | for (unsigned j = 0, M = Children.size(); j < M; ++j) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1594 | Offset = computeSizeAndOffset(Children[j], Offset, (j + 1) == M); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1595 | |
| 1596 | // End of children marker. |
| 1597 | Offset += sizeof(int8_t); |
| 1598 | } |
| 1599 | |
| 1600 | Die->setSize(Offset - Die->getOffset()); |
| 1601 | return Offset; |
| 1602 | } |
| 1603 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1604 | /// computeSizeAndOffsets - Compute the size and offset of all the DIEs. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1605 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1606 | void DwarfDebug::computeSizeAndOffsets() { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1607 | for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(), |
| 1608 | E = CUMap.end(); I != E; ++I) { |
| 1609 | // Compute size of compile unit header. |
Devang Patel | 513edf6 | 2011-04-12 23:10:47 +0000 | [diff] [blame] | 1610 | unsigned Offset = |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1611 | sizeof(int32_t) + // Length of Compilation Unit Info |
| 1612 | sizeof(int16_t) + // DWARF version number |
| 1613 | sizeof(int32_t) + // Offset Into Abbrev. Section |
| 1614 | sizeof(int8_t); // Pointer Size (in bytes) |
| 1615 | computeSizeAndOffset(I->second->getCUDie(), Offset, true); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1616 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1617 | } |
| 1618 | |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 1619 | /// EmitSectionLabels - Emit initial Dwarf sections with a label at |
| 1620 | /// the start of each one. |
Chris Lattner | fa070b0 | 2010-04-04 22:33:59 +0000 | [diff] [blame] | 1621 | void DwarfDebug::EmitSectionLabels() { |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 1622 | const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 1623 | |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1624 | // Dwarf sections base addresses. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1625 | DwarfInfoSectionSym = |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 1626 | EmitSectionSym(Asm, TLOF.getDwarfInfoSection(), "section_info"); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1627 | DwarfAbbrevSectionSym = |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 1628 | EmitSectionSym(Asm, TLOF.getDwarfAbbrevSection(), "section_abbrev"); |
Chris Lattner | 11b8f30 | 2010-04-04 23:02:02 +0000 | [diff] [blame] | 1629 | EmitSectionSym(Asm, TLOF.getDwarfARangesSection()); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1630 | |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 1631 | if (const MCSection *MacroInfo = TLOF.getDwarfMacroInfoSection()) |
Chris Lattner | 11b8f30 | 2010-04-04 23:02:02 +0000 | [diff] [blame] | 1632 | EmitSectionSym(Asm, MacroInfo); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1633 | |
Devang Patel | af608bd | 2010-08-24 00:06:12 +0000 | [diff] [blame] | 1634 | EmitSectionSym(Asm, TLOF.getDwarfLineSection(), "section_line"); |
Chris Lattner | 11b8f30 | 2010-04-04 23:02:02 +0000 | [diff] [blame] | 1635 | EmitSectionSym(Asm, TLOF.getDwarfLocSection()); |
Chris Lattner | 11b8f30 | 2010-04-04 23:02:02 +0000 | [diff] [blame] | 1636 | EmitSectionSym(Asm, TLOF.getDwarfPubTypesSection()); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1637 | DwarfStrSectionSym = |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 1638 | EmitSectionSym(Asm, TLOF.getDwarfStrSection(), "section_str"); |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 1639 | DwarfDebugRangeSectionSym = EmitSectionSym(Asm, TLOF.getDwarfRangesSection(), |
| 1640 | "debug_range"); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1641 | |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1642 | DwarfDebugLocSectionSym = EmitSectionSym(Asm, TLOF.getDwarfLocSection(), |
| 1643 | "section_debug_loc"); |
| 1644 | |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 1645 | TextSectionSym = EmitSectionSym(Asm, TLOF.getTextSection(), "text_begin"); |
Chris Lattner | 4ad1efe | 2010-04-04 23:10:38 +0000 | [diff] [blame] | 1646 | EmitSectionSym(Asm, TLOF.getDataSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1647 | } |
| 1648 | |
Nick Lewycky | 3bbb6f7 | 2011-07-29 03:49:23 +0000 | [diff] [blame] | 1649 | /// emitDIE - Recursively emits a debug information entry. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1650 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1651 | void DwarfDebug::emitDIE(DIE *Die) { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1652 | // Get the abbreviation for this DIE. |
| 1653 | unsigned AbbrevNumber = Die->getAbbrevNumber(); |
| 1654 | const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1]; |
| 1655 | |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1656 | // Emit the code (index) for the abbreviation. |
Chris Lattner | 3f53c83 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 1657 | if (Asm->isVerbose()) |
Chris Lattner | 894d75a | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 1658 | Asm->OutStreamer.AddComment("Abbrev [" + Twine(AbbrevNumber) + "] 0x" + |
| 1659 | Twine::utohexstr(Die->getOffset()) + ":0x" + |
| 1660 | Twine::utohexstr(Die->getSize()) + " " + |
| 1661 | dwarf::TagString(Abbrev->getTag())); |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 1662 | Asm->EmitULEB128(AbbrevNumber); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1663 | |
Jeffrey Yasskin | 638fe8d | 2010-03-22 18:47:14 +0000 | [diff] [blame] | 1664 | const SmallVector<DIEValue*, 32> &Values = Die->getValues(); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1665 | const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData(); |
| 1666 | |
| 1667 | // Emit the DIE attribute values. |
| 1668 | for (unsigned i = 0, N = Values.size(); i < N; ++i) { |
| 1669 | unsigned Attr = AbbrevData[i].getAttribute(); |
| 1670 | unsigned Form = AbbrevData[i].getForm(); |
| 1671 | assert(Form && "Too many attributes for DIE (check abbreviation)"); |
| 1672 | |
Chris Lattner | 3f53c83 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 1673 | if (Asm->isVerbose()) |
Chris Lattner | a801362 | 2010-01-24 18:54:17 +0000 | [diff] [blame] | 1674 | Asm->OutStreamer.AddComment(dwarf::AttributeString(Attr)); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1675 | |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1676 | switch (Attr) { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1677 | case dwarf::DW_AT_abstract_origin: { |
| 1678 | DIEEntry *E = cast<DIEEntry>(Values[i]); |
| 1679 | DIE *Origin = E->getEntry(); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1680 | unsigned Addr = Origin->getOffset(); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1681 | Asm->EmitInt32(Addr); |
| 1682 | break; |
| 1683 | } |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 1684 | case dwarf::DW_AT_ranges: { |
| 1685 | // DW_AT_range Value encodes offset in debug_range section. |
| 1686 | DIEInteger *V = cast<DIEInteger>(Values[i]); |
Devang Patel | b1fcfbe | 2010-09-02 16:43:44 +0000 | [diff] [blame] | 1687 | |
Nick Lewycky | ffccd92 | 2012-06-22 01:25:12 +0000 | [diff] [blame] | 1688 | if (Asm->MAI->doesDwarfUseRelocationsAcrossSections()) { |
Devang Patel | b1fcfbe | 2010-09-02 16:43:44 +0000 | [diff] [blame] | 1689 | Asm->EmitLabelPlusOffset(DwarfDebugRangeSectionSym, |
| 1690 | V->getValue(), |
| 1691 | 4); |
| 1692 | } else { |
| 1693 | Asm->EmitLabelOffsetDifference(DwarfDebugRangeSectionSym, |
| 1694 | V->getValue(), |
| 1695 | DwarfDebugRangeSectionSym, |
| 1696 | 4); |
| 1697 | } |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 1698 | break; |
| 1699 | } |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1700 | case dwarf::DW_AT_location: { |
Nick Lewycky | ffccd92 | 2012-06-22 01:25:12 +0000 | [diff] [blame] | 1701 | if (DIELabel *L = dyn_cast<DIELabel>(Values[i])) { |
| 1702 | if (Asm->MAI->doesDwarfUseRelocationsAcrossSections()) |
| 1703 | Asm->EmitLabelReference(L->getValue(), 4); |
| 1704 | else |
| 1705 | Asm->EmitLabelDifference(L->getValue(), DwarfDebugLocSectionSym, 4); |
| 1706 | } else { |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1707 | Values[i]->EmitValue(Asm, Form); |
Nick Lewycky | ffccd92 | 2012-06-22 01:25:12 +0000 | [diff] [blame] | 1708 | } |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1709 | break; |
| 1710 | } |
Devang Patel | 2a36160 | 2010-09-29 19:08:08 +0000 | [diff] [blame] | 1711 | case dwarf::DW_AT_accessibility: { |
| 1712 | if (Asm->isVerbose()) { |
| 1713 | DIEInteger *V = cast<DIEInteger>(Values[i]); |
| 1714 | Asm->OutStreamer.AddComment(dwarf::AccessibilityString(V->getValue())); |
| 1715 | } |
| 1716 | Values[i]->EmitValue(Asm, Form); |
| 1717 | break; |
| 1718 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1719 | default: |
| 1720 | // Emit an attribute using the defined form. |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 1721 | Values[i]->EmitValue(Asm, Form); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1722 | break; |
| 1723 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | // Emit the DIE children if any. |
| 1727 | if (Abbrev->getChildrenFlag() == dwarf::DW_CHILDREN_yes) { |
| 1728 | const std::vector<DIE *> &Children = Die->getChildren(); |
| 1729 | |
| 1730 | for (unsigned j = 0, M = Children.size(); j < M; ++j) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1731 | emitDIE(Children[j]); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1732 | |
Chris Lattner | 3f53c83 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 1733 | if (Asm->isVerbose()) |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 1734 | Asm->OutStreamer.AddComment("End Of Children Mark"); |
| 1735 | Asm->EmitInt8(0); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1736 | } |
| 1737 | } |
| 1738 | |
Devang Patel | 8a24114 | 2009-12-09 18:24:21 +0000 | [diff] [blame] | 1739 | /// emitDebugInfo - Emit the debug info section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1740 | /// |
Devang Patel | 8a24114 | 2009-12-09 18:24:21 +0000 | [diff] [blame] | 1741 | void DwarfDebug::emitDebugInfo() { |
| 1742 | // Start debug info section. |
| 1743 | Asm->OutStreamer.SwitchSection( |
| 1744 | Asm->getObjFileLowering().getDwarfInfoSection()); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1745 | for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(), |
| 1746 | E = CUMap.end(); I != E; ++I) { |
| 1747 | CompileUnit *TheCU = I->second; |
| 1748 | DIE *Die = TheCU->getCUDie(); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1749 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1750 | // Emit the compile units header. |
| 1751 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("info_begin", |
| 1752 | TheCU->getID())); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1753 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1754 | // Emit size of content not including length itself |
| 1755 | unsigned ContentSize = Die->getSize() + |
| 1756 | sizeof(int16_t) + // DWARF version number |
| 1757 | sizeof(int32_t) + // Offset Into Abbrev. Section |
Devang Patel | 65705d5 | 2011-04-13 19:41:17 +0000 | [diff] [blame] | 1758 | sizeof(int8_t); // Pointer Size (in bytes) |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1759 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1760 | Asm->OutStreamer.AddComment("Length of Compilation Unit Info"); |
| 1761 | Asm->EmitInt32(ContentSize); |
| 1762 | Asm->OutStreamer.AddComment("DWARF version number"); |
| 1763 | Asm->EmitInt16(dwarf::DWARF_VERSION); |
| 1764 | Asm->OutStreamer.AddComment("Offset Into Abbrev. Section"); |
| 1765 | Asm->EmitSectionOffset(Asm->GetTempSymbol("abbrev_begin"), |
| 1766 | DwarfAbbrevSectionSym); |
| 1767 | Asm->OutStreamer.AddComment("Address Size (in bytes)"); |
Chandler Carruth | 426c2bf | 2012-11-01 09:14:31 +0000 | [diff] [blame] | 1768 | Asm->EmitInt8(Asm->getDataLayout().getPointerSize()); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1769 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1770 | emitDIE(Die); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1771 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("info_end", TheCU->getID())); |
| 1772 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1773 | } |
| 1774 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1775 | /// emitAbbreviations - Emit the abbreviation section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1776 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1777 | void DwarfDebug::emitAbbreviations() const { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1778 | // Check to see if it is worth the effort. |
| 1779 | if (!Abbreviations.empty()) { |
| 1780 | // Start the debug abbrev section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 1781 | Asm->OutStreamer.SwitchSection( |
| 1782 | Asm->getObjFileLowering().getDwarfAbbrevSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1783 | |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 1784 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("abbrev_begin")); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1785 | |
| 1786 | // For each abbrevation. |
| 1787 | for (unsigned i = 0, N = Abbreviations.size(); i < N; ++i) { |
| 1788 | // Get abbreviation data |
| 1789 | const DIEAbbrev *Abbrev = Abbreviations[i]; |
| 1790 | |
| 1791 | // Emit the abbrevations code (base 1 index.) |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 1792 | Asm->EmitULEB128(Abbrev->getNumber(), "Abbreviation Code"); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1793 | |
| 1794 | // Emit the abbreviations data. |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 1795 | Abbrev->Emit(Asm); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | // Mark end of abbreviations. |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 1799 | Asm->EmitULEB128(0, "EOM(3)"); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1800 | |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 1801 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("abbrev_end")); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1802 | } |
| 1803 | } |
| 1804 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1805 | /// emitEndOfLineMatrix - Emit the last address of the section and the end of |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1806 | /// the line matrix. |
| 1807 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1808 | void DwarfDebug::emitEndOfLineMatrix(unsigned SectionEnd) { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1809 | // Define last address of section. |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 1810 | Asm->OutStreamer.AddComment("Extended Op"); |
| 1811 | Asm->EmitInt8(0); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1812 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 1813 | Asm->OutStreamer.AddComment("Op size"); |
Chandler Carruth | 426c2bf | 2012-11-01 09:14:31 +0000 | [diff] [blame] | 1814 | Asm->EmitInt8(Asm->getDataLayout().getPointerSize() + 1); |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 1815 | Asm->OutStreamer.AddComment("DW_LNE_set_address"); |
| 1816 | Asm->EmitInt8(dwarf::DW_LNE_set_address); |
| 1817 | |
| 1818 | Asm->OutStreamer.AddComment("Section end label"); |
Chris Lattner | d85fc6e | 2010-03-10 01:17:49 +0000 | [diff] [blame] | 1819 | |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 1820 | Asm->OutStreamer.EmitSymbolValue(Asm->GetTempSymbol("section_end",SectionEnd), |
Chandler Carruth | 426c2bf | 2012-11-01 09:14:31 +0000 | [diff] [blame] | 1821 | Asm->getDataLayout().getPointerSize(), |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 1822 | 0/*AddrSpace*/); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1823 | |
| 1824 | // Mark end of matrix. |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 1825 | Asm->OutStreamer.AddComment("DW_LNE_end_sequence"); |
| 1826 | Asm->EmitInt8(0); |
Chris Lattner | 0ad9c91 | 2010-01-22 22:09:00 +0000 | [diff] [blame] | 1827 | Asm->EmitInt8(1); |
Chris Lattner | 894d75a | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 1828 | Asm->EmitInt8(1); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
Eric Christopher | 09ac3d8 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1831 | /// emitAccelNames - Emit visible names into a hashed accelerator table |
| 1832 | /// section. |
| 1833 | void DwarfDebug::emitAccelNames() { |
| 1834 | DwarfAccelTable AT(DwarfAccelTable::Atom(DwarfAccelTable::eAtomTypeDIEOffset, |
| 1835 | dwarf::DW_FORM_data4)); |
| 1836 | for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(), |
| 1837 | E = CUMap.end(); I != E; ++I) { |
| 1838 | CompileUnit *TheCU = I->second; |
Eric Christopher | 0ffe2b4 | 2011-11-10 19:25:34 +0000 | [diff] [blame] | 1839 | const StringMap<std::vector<DIE*> > &Names = TheCU->getAccelNames(); |
| 1840 | for (StringMap<std::vector<DIE*> >::const_iterator |
Eric Christopher | 09ac3d8 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1841 | GI = Names.begin(), GE = Names.end(); GI != GE; ++GI) { |
| 1842 | const char *Name = GI->getKeyData(); |
Eric Christopher | fa03db0 | 2012-01-06 23:03:34 +0000 | [diff] [blame] | 1843 | const std::vector<DIE *> &Entities = GI->second; |
Eric Christopher | 0ffe2b4 | 2011-11-10 19:25:34 +0000 | [diff] [blame] | 1844 | for (std::vector<DIE *>::const_iterator DI = Entities.begin(), |
| 1845 | DE = Entities.end(); DI != DE; ++DI) |
| 1846 | AT.AddName(Name, (*DI)); |
Eric Christopher | 09ac3d8 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1847 | } |
| 1848 | } |
| 1849 | |
| 1850 | AT.FinalizeTable(Asm, "Names"); |
| 1851 | Asm->OutStreamer.SwitchSection( |
| 1852 | Asm->getObjFileLowering().getDwarfAccelNamesSection()); |
| 1853 | MCSymbol *SectionBegin = Asm->GetTempSymbol("names_begin"); |
| 1854 | Asm->OutStreamer.EmitLabel(SectionBegin); |
| 1855 | |
| 1856 | // Emit the full data. |
| 1857 | AT.Emit(Asm, SectionBegin, this); |
| 1858 | } |
| 1859 | |
| 1860 | /// emitAccelObjC - Emit objective C classes and categories into a hashed |
| 1861 | /// accelerator table section. |
| 1862 | void DwarfDebug::emitAccelObjC() { |
| 1863 | DwarfAccelTable AT(DwarfAccelTable::Atom(DwarfAccelTable::eAtomTypeDIEOffset, |
| 1864 | dwarf::DW_FORM_data4)); |
| 1865 | for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(), |
| 1866 | E = CUMap.end(); I != E; ++I) { |
| 1867 | CompileUnit *TheCU = I->second; |
| 1868 | const StringMap<std::vector<DIE*> > &Names = TheCU->getAccelObjC(); |
| 1869 | for (StringMap<std::vector<DIE*> >::const_iterator |
| 1870 | GI = Names.begin(), GE = Names.end(); GI != GE; ++GI) { |
| 1871 | const char *Name = GI->getKeyData(); |
Eric Christopher | fa03db0 | 2012-01-06 23:03:34 +0000 | [diff] [blame] | 1872 | const std::vector<DIE *> &Entities = GI->second; |
Eric Christopher | 09ac3d8 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1873 | for (std::vector<DIE *>::const_iterator DI = Entities.begin(), |
| 1874 | DE = Entities.end(); DI != DE; ++DI) |
| 1875 | AT.AddName(Name, (*DI)); |
| 1876 | } |
| 1877 | } |
| 1878 | |
| 1879 | AT.FinalizeTable(Asm, "ObjC"); |
| 1880 | Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering() |
| 1881 | .getDwarfAccelObjCSection()); |
| 1882 | MCSymbol *SectionBegin = Asm->GetTempSymbol("objc_begin"); |
| 1883 | Asm->OutStreamer.EmitLabel(SectionBegin); |
| 1884 | |
| 1885 | // Emit the full data. |
| 1886 | AT.Emit(Asm, SectionBegin, this); |
| 1887 | } |
| 1888 | |
| 1889 | /// emitAccelNamespace - Emit namespace dies into a hashed accelerator |
| 1890 | /// table. |
| 1891 | void DwarfDebug::emitAccelNamespaces() { |
| 1892 | DwarfAccelTable AT(DwarfAccelTable::Atom(DwarfAccelTable::eAtomTypeDIEOffset, |
| 1893 | dwarf::DW_FORM_data4)); |
| 1894 | for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(), |
| 1895 | E = CUMap.end(); I != E; ++I) { |
| 1896 | CompileUnit *TheCU = I->second; |
Eric Christopher | 8bd36ea | 2011-11-10 21:47:55 +0000 | [diff] [blame] | 1897 | const StringMap<std::vector<DIE*> > &Names = TheCU->getAccelNamespace(); |
| 1898 | for (StringMap<std::vector<DIE*> >::const_iterator |
Eric Christopher | 09ac3d8 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1899 | GI = Names.begin(), GE = Names.end(); GI != GE; ++GI) { |
| 1900 | const char *Name = GI->getKeyData(); |
Eric Christopher | fa03db0 | 2012-01-06 23:03:34 +0000 | [diff] [blame] | 1901 | const std::vector<DIE *> &Entities = GI->second; |
Eric Christopher | 8bd36ea | 2011-11-10 21:47:55 +0000 | [diff] [blame] | 1902 | for (std::vector<DIE *>::const_iterator DI = Entities.begin(), |
| 1903 | DE = Entities.end(); DI != DE; ++DI) |
| 1904 | AT.AddName(Name, (*DI)); |
Eric Christopher | 09ac3d8 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1905 | } |
| 1906 | } |
| 1907 | |
| 1908 | AT.FinalizeTable(Asm, "namespac"); |
| 1909 | Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering() |
| 1910 | .getDwarfAccelNamespaceSection()); |
| 1911 | MCSymbol *SectionBegin = Asm->GetTempSymbol("namespac_begin"); |
| 1912 | Asm->OutStreamer.EmitLabel(SectionBegin); |
| 1913 | |
| 1914 | // Emit the full data. |
| 1915 | AT.Emit(Asm, SectionBegin, this); |
| 1916 | } |
| 1917 | |
| 1918 | /// emitAccelTypes() - Emit type dies into a hashed accelerator table. |
| 1919 | void DwarfDebug::emitAccelTypes() { |
Eric Christopher | c36145f | 2012-01-06 04:35:23 +0000 | [diff] [blame] | 1920 | std::vector<DwarfAccelTable::Atom> Atoms; |
| 1921 | Atoms.push_back(DwarfAccelTable::Atom(DwarfAccelTable::eAtomTypeDIEOffset, |
| 1922 | dwarf::DW_FORM_data4)); |
| 1923 | Atoms.push_back(DwarfAccelTable::Atom(DwarfAccelTable::eAtomTypeTag, |
| 1924 | dwarf::DW_FORM_data2)); |
| 1925 | Atoms.push_back(DwarfAccelTable::Atom(DwarfAccelTable::eAtomTypeTypeFlags, |
| 1926 | dwarf::DW_FORM_data1)); |
| 1927 | DwarfAccelTable AT(Atoms); |
Eric Christopher | 09ac3d8 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1928 | for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(), |
| 1929 | E = CUMap.end(); I != E; ++I) { |
| 1930 | CompileUnit *TheCU = I->second; |
Eric Christopher | c36145f | 2012-01-06 04:35:23 +0000 | [diff] [blame] | 1931 | const StringMap<std::vector<std::pair<DIE*, unsigned > > > &Names |
| 1932 | = TheCU->getAccelTypes(); |
| 1933 | for (StringMap<std::vector<std::pair<DIE*, unsigned> > >::const_iterator |
Eric Christopher | 09ac3d8 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1934 | GI = Names.begin(), GE = Names.end(); GI != GE; ++GI) { |
| 1935 | const char *Name = GI->getKeyData(); |
Eric Christopher | fa03db0 | 2012-01-06 23:03:34 +0000 | [diff] [blame] | 1936 | const std::vector<std::pair<DIE *, unsigned> > &Entities = GI->second; |
Eric Christopher | c36145f | 2012-01-06 04:35:23 +0000 | [diff] [blame] | 1937 | for (std::vector<std::pair<DIE *, unsigned> >::const_iterator DI |
| 1938 | = Entities.begin(), DE = Entities.end(); DI !=DE; ++DI) |
| 1939 | AT.AddName(Name, (*DI).first, (*DI).second); |
Eric Christopher | 09ac3d8 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1940 | } |
| 1941 | } |
| 1942 | |
| 1943 | AT.FinalizeTable(Asm, "types"); |
| 1944 | Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering() |
| 1945 | .getDwarfAccelTypesSection()); |
| 1946 | MCSymbol *SectionBegin = Asm->GetTempSymbol("types_begin"); |
| 1947 | Asm->OutStreamer.EmitLabel(SectionBegin); |
| 1948 | |
| 1949 | // Emit the full data. |
| 1950 | AT.Emit(Asm, SectionBegin, this); |
| 1951 | } |
| 1952 | |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1953 | void DwarfDebug::emitDebugPubTypes() { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1954 | for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(), |
| 1955 | E = CUMap.end(); I != E; ++I) { |
| 1956 | CompileUnit *TheCU = I->second; |
Eric Christopher | 6370118 | 2011-11-07 09:18:35 +0000 | [diff] [blame] | 1957 | // Start the dwarf pubtypes section. |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1958 | Asm->OutStreamer.SwitchSection( |
| 1959 | Asm->getObjFileLowering().getDwarfPubTypesSection()); |
| 1960 | Asm->OutStreamer.AddComment("Length of Public Types Info"); |
| 1961 | Asm->EmitLabelDifference( |
| 1962 | Asm->GetTempSymbol("pubtypes_end", TheCU->getID()), |
| 1963 | Asm->GetTempSymbol("pubtypes_begin", TheCU->getID()), 4); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1964 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1965 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubtypes_begin", |
| 1966 | TheCU->getID())); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1967 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1968 | if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DWARF Version"); |
| 1969 | Asm->EmitInt16(dwarf::DWARF_VERSION); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1970 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1971 | Asm->OutStreamer.AddComment("Offset of Compilation Unit Info"); |
| 1972 | Asm->EmitSectionOffset(Asm->GetTempSymbol("info_begin", TheCU->getID()), |
| 1973 | DwarfInfoSectionSym); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1974 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1975 | Asm->OutStreamer.AddComment("Compilation Unit Length"); |
| 1976 | Asm->EmitLabelDifference(Asm->GetTempSymbol("info_end", TheCU->getID()), |
| 1977 | Asm->GetTempSymbol("info_begin", TheCU->getID()), |
| 1978 | 4); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1979 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1980 | const StringMap<DIE*> &Globals = TheCU->getGlobalTypes(); |
| 1981 | for (StringMap<DIE*>::const_iterator |
| 1982 | GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) { |
| 1983 | const char *Name = GI->getKeyData(); |
Nick Lewycky | 3bbb6f7 | 2011-07-29 03:49:23 +0000 | [diff] [blame] | 1984 | DIE *Entity = GI->second; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1985 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1986 | if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DIE offset"); |
| 1987 | Asm->EmitInt32(Entity->getOffset()); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1988 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1989 | if (Asm->isVerbose()) Asm->OutStreamer.AddComment("External Name"); |
Benjamin Kramer | 983c457 | 2011-11-09 18:16:11 +0000 | [diff] [blame] | 1990 | // Emit the name with a terminating null byte. |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1991 | Asm->OutStreamer.EmitBytes(StringRef(Name, GI->getKeyLength()+1), 0); |
| 1992 | } |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1993 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1994 | Asm->OutStreamer.AddComment("End Mark"); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1995 | Asm->EmitInt32(0); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1996 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubtypes_end", |
| 1997 | TheCU->getID())); |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1998 | } |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1999 | } |
| 2000 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2001 | /// emitDebugStr - Emit visible names into a debug str section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2002 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2003 | void DwarfDebug::emitDebugStr() { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2004 | // Check to see if it is worth the effort. |
Chris Lattner | 0d9d70f | 2010-03-09 23:38:23 +0000 | [diff] [blame] | 2005 | if (StringPool.empty()) return; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2006 | |
Chris Lattner | 0d9d70f | 2010-03-09 23:38:23 +0000 | [diff] [blame] | 2007 | // Start the dwarf str section. |
| 2008 | Asm->OutStreamer.SwitchSection( |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2009 | Asm->getObjFileLowering().getDwarfStrSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2010 | |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 2011 | // Get all of the string pool entries and put them in an array by their ID so |
| 2012 | // we can sort them. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2013 | SmallVector<std::pair<unsigned, |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 2014 | StringMapEntry<std::pair<MCSymbol*, unsigned> >*>, 64> Entries; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2015 | |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 2016 | for (StringMap<std::pair<MCSymbol*, unsigned> >::iterator |
| 2017 | I = StringPool.begin(), E = StringPool.end(); I != E; ++I) |
| 2018 | Entries.push_back(std::make_pair(I->second.second, &*I)); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2019 | |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 2020 | array_pod_sort(Entries.begin(), Entries.end()); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2021 | |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 2022 | for (unsigned i = 0, e = Entries.size(); i != e; ++i) { |
Chris Lattner | 0d9d70f | 2010-03-09 23:38:23 +0000 | [diff] [blame] | 2023 | // Emit a label for reference from debug information entries. |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 2024 | Asm->OutStreamer.EmitLabel(Entries[i].second->getValue().first); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2025 | |
Benjamin Kramer | 983c457 | 2011-11-09 18:16:11 +0000 | [diff] [blame] | 2026 | // Emit the string itself with a terminating null byte. |
Benjamin Kramer | 0c45f7d | 2011-11-09 12:12:04 +0000 | [diff] [blame] | 2027 | Asm->OutStreamer.EmitBytes(StringRef(Entries[i].second->getKeyData(), |
| 2028 | Entries[i].second->getKeyLength()+1), |
| 2029 | 0/*addrspace*/); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2030 | } |
| 2031 | } |
| 2032 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2033 | /// emitDebugLoc - Emit visible names into a debug loc section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2034 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2035 | void DwarfDebug::emitDebugLoc() { |
Devang Patel | 8025068 | 2010-05-26 23:55:23 +0000 | [diff] [blame] | 2036 | if (DotDebugLocEntries.empty()) |
| 2037 | return; |
| 2038 | |
Devang Patel | 6c3ea90 | 2011-02-04 22:57:18 +0000 | [diff] [blame] | 2039 | for (SmallVector<DotDebugLocEntry, 4>::iterator |
| 2040 | I = DotDebugLocEntries.begin(), E = DotDebugLocEntries.end(); |
| 2041 | I != E; ++I) { |
| 2042 | DotDebugLocEntry &Entry = *I; |
| 2043 | if (I + 1 != DotDebugLocEntries.end()) |
| 2044 | Entry.Merge(I+1); |
| 2045 | } |
| 2046 | |
Daniel Dunbar | 83320a0 | 2011-03-16 22:16:39 +0000 | [diff] [blame] | 2047 | // Start the dwarf loc section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2048 | Asm->OutStreamer.SwitchSection( |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2049 | Asm->getObjFileLowering().getDwarfLocSection()); |
Chandler Carruth | 426c2bf | 2012-11-01 09:14:31 +0000 | [diff] [blame] | 2050 | unsigned char Size = Asm->getDataLayout().getPointerSize(); |
Devang Patel | 8025068 | 2010-05-26 23:55:23 +0000 | [diff] [blame] | 2051 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_loc", 0)); |
| 2052 | unsigned index = 1; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2053 | for (SmallVector<DotDebugLocEntry, 4>::iterator |
| 2054 | I = DotDebugLocEntries.begin(), E = DotDebugLocEntries.end(); |
Devang Patel | 6140962 | 2010-07-07 20:12:52 +0000 | [diff] [blame] | 2055 | I != E; ++I, ++index) { |
Devang Patel | 6c3ea90 | 2011-02-04 22:57:18 +0000 | [diff] [blame] | 2056 | DotDebugLocEntry &Entry = *I; |
| 2057 | if (Entry.isMerged()) continue; |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2058 | if (Entry.isEmpty()) { |
| 2059 | Asm->OutStreamer.EmitIntValue(0, Size, /*addrspace*/0); |
| 2060 | Asm->OutStreamer.EmitIntValue(0, Size, /*addrspace*/0); |
Devang Patel | 8025068 | 2010-05-26 23:55:23 +0000 | [diff] [blame] | 2061 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_loc", index)); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2062 | } else { |
| 2063 | Asm->OutStreamer.EmitSymbolValue(Entry.Begin, Size, 0); |
| 2064 | Asm->OutStreamer.EmitSymbolValue(Entry.End, Size, 0); |
Devang Patel | c26f544 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 2065 | DIVariable DV(Entry.Variable); |
Rafael Espindola | 5b23b7f | 2011-05-27 22:05:41 +0000 | [diff] [blame] | 2066 | Asm->OutStreamer.AddComment("Loc expr size"); |
| 2067 | MCSymbol *begin = Asm->OutStreamer.getContext().CreateTempSymbol(); |
| 2068 | MCSymbol *end = Asm->OutStreamer.getContext().CreateTempSymbol(); |
| 2069 | Asm->EmitLabelDifference(end, begin, 2); |
| 2070 | Asm->OutStreamer.EmitLabel(begin); |
Devang Patel | 80efd4e | 2011-07-08 16:49:43 +0000 | [diff] [blame] | 2071 | if (Entry.isInt()) { |
Devang Patel | c432907 | 2011-06-01 22:03:25 +0000 | [diff] [blame] | 2072 | DIBasicType BTy(DV.getType()); |
| 2073 | if (BTy.Verify() && |
| 2074 | (BTy.getEncoding() == dwarf::DW_ATE_signed |
| 2075 | || BTy.getEncoding() == dwarf::DW_ATE_signed_char)) { |
| 2076 | Asm->OutStreamer.AddComment("DW_OP_consts"); |
| 2077 | Asm->EmitInt8(dwarf::DW_OP_consts); |
Devang Patel | 80efd4e | 2011-07-08 16:49:43 +0000 | [diff] [blame] | 2078 | Asm->EmitSLEB128(Entry.getInt()); |
Devang Patel | c432907 | 2011-06-01 22:03:25 +0000 | [diff] [blame] | 2079 | } else { |
| 2080 | Asm->OutStreamer.AddComment("DW_OP_constu"); |
| 2081 | Asm->EmitInt8(dwarf::DW_OP_constu); |
Devang Patel | 80efd4e | 2011-07-08 16:49:43 +0000 | [diff] [blame] | 2082 | Asm->EmitULEB128(Entry.getInt()); |
Devang Patel | c432907 | 2011-06-01 22:03:25 +0000 | [diff] [blame] | 2083 | } |
Devang Patel | 80efd4e | 2011-07-08 16:49:43 +0000 | [diff] [blame] | 2084 | } else if (Entry.isLocation()) { |
| 2085 | if (!DV.hasComplexAddress()) |
| 2086 | // Regular entry. |
Devang Patel | c26f544 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 2087 | Asm->EmitDwarfRegOp(Entry.Loc); |
Devang Patel | 80efd4e | 2011-07-08 16:49:43 +0000 | [diff] [blame] | 2088 | else { |
| 2089 | // Complex address entry. |
| 2090 | unsigned N = DV.getNumAddrElements(); |
| 2091 | unsigned i = 0; |
| 2092 | if (N >= 2 && DV.getAddrElement(0) == DIBuilder::OpPlus) { |
| 2093 | if (Entry.Loc.getOffset()) { |
| 2094 | i = 2; |
| 2095 | Asm->EmitDwarfRegOp(Entry.Loc); |
| 2096 | Asm->OutStreamer.AddComment("DW_OP_deref"); |
| 2097 | Asm->EmitInt8(dwarf::DW_OP_deref); |
| 2098 | Asm->OutStreamer.AddComment("DW_OP_plus_uconst"); |
| 2099 | Asm->EmitInt8(dwarf::DW_OP_plus_uconst); |
| 2100 | Asm->EmitSLEB128(DV.getAddrElement(1)); |
| 2101 | } else { |
| 2102 | // If first address element is OpPlus then emit |
| 2103 | // DW_OP_breg + Offset instead of DW_OP_reg + Offset. |
| 2104 | MachineLocation Loc(Entry.Loc.getReg(), DV.getAddrElement(1)); |
| 2105 | Asm->EmitDwarfRegOp(Loc); |
| 2106 | i = 2; |
| 2107 | } |
| 2108 | } else { |
| 2109 | Asm->EmitDwarfRegOp(Entry.Loc); |
| 2110 | } |
| 2111 | |
| 2112 | // Emit remaining complex address elements. |
| 2113 | for (; i < N; ++i) { |
| 2114 | uint64_t Element = DV.getAddrElement(i); |
| 2115 | if (Element == DIBuilder::OpPlus) { |
| 2116 | Asm->EmitInt8(dwarf::DW_OP_plus_uconst); |
| 2117 | Asm->EmitULEB128(DV.getAddrElement(++i)); |
Eric Christopher | 5012076 | 2012-05-08 18:56:00 +0000 | [diff] [blame] | 2118 | } else if (Element == DIBuilder::OpDeref) { |
Eric Christopher | a80f2d1 | 2012-05-08 21:24:39 +0000 | [diff] [blame] | 2119 | if (!Entry.Loc.isReg()) |
Eric Christopher | 5012076 | 2012-05-08 18:56:00 +0000 | [diff] [blame] | 2120 | Asm->EmitInt8(dwarf::DW_OP_deref); |
| 2121 | } else |
| 2122 | llvm_unreachable("unknown Opcode found in complex address"); |
Devang Patel | 80efd4e | 2011-07-08 16:49:43 +0000 | [diff] [blame] | 2123 | } |
Devang Patel | c26f544 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 2124 | } |
Devang Patel | c26f544 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 2125 | } |
Devang Patel | 80efd4e | 2011-07-08 16:49:43 +0000 | [diff] [blame] | 2126 | // else ... ignore constant fp. There is not any good way to |
| 2127 | // to represent them here in dwarf. |
Rafael Espindola | 5b23b7f | 2011-05-27 22:05:41 +0000 | [diff] [blame] | 2128 | Asm->OutStreamer.EmitLabel(end); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2129 | } |
| 2130 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | /// EmitDebugARanges - Emit visible names into a debug aranges section. |
| 2134 | /// |
| 2135 | void DwarfDebug::EmitDebugARanges() { |
| 2136 | // Start the dwarf aranges section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2137 | Asm->OutStreamer.SwitchSection( |
| 2138 | Asm->getObjFileLowering().getDwarfARangesSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2139 | } |
| 2140 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2141 | /// emitDebugRanges - Emit visible names into a debug ranges section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2142 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2143 | void DwarfDebug::emitDebugRanges() { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2144 | // Start the dwarf ranges section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2145 | Asm->OutStreamer.SwitchSection( |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 2146 | Asm->getObjFileLowering().getDwarfRangesSection()); |
Chandler Carruth | 426c2bf | 2012-11-01 09:14:31 +0000 | [diff] [blame] | 2147 | unsigned char Size = Asm->getDataLayout().getPointerSize(); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2148 | for (SmallVector<const MCSymbol *, 8>::iterator |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2149 | I = DebugRangeSymbols.begin(), E = DebugRangeSymbols.end(); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2150 | I != E; ++I) { |
| 2151 | if (*I) |
| 2152 | Asm->OutStreamer.EmitSymbolValue(const_cast<MCSymbol*>(*I), Size, 0); |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 2153 | else |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2154 | Asm->OutStreamer.EmitIntValue(0, Size, /*addrspace*/0); |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 2155 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2156 | } |
| 2157 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2158 | /// emitDebugMacInfo - Emit visible names into a debug macinfo section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2159 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2160 | void DwarfDebug::emitDebugMacInfo() { |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 2161 | if (const MCSection *LineInfo = |
Chris Lattner | 18a4c16 | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 2162 | Asm->getObjFileLowering().getDwarfMacroInfoSection()) { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2163 | // Start the dwarf macinfo section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2164 | Asm->OutStreamer.SwitchSection(LineInfo); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2165 | } |
| 2166 | } |
| 2167 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2168 | /// emitDebugInlineInfo - Emit inline info using following format. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2169 | /// Section Header: |
| 2170 | /// 1. length of section |
| 2171 | /// 2. Dwarf version number |
| 2172 | /// 3. address size. |
| 2173 | /// |
| 2174 | /// Entries (one "entry" for each function that was inlined): |
| 2175 | /// |
| 2176 | /// 1. offset into __debug_str section for MIPS linkage name, if exists; |
| 2177 | /// otherwise offset into __debug_str for regular function name. |
| 2178 | /// 2. offset into __debug_str section for regular function name. |
| 2179 | /// 3. an unsigned LEB128 number indicating the number of distinct inlining |
| 2180 | /// instances for the function. |
| 2181 | /// |
| 2182 | /// The rest of the entry consists of a {die_offset, low_pc} pair for each |
| 2183 | /// inlined instance; the die_offset points to the inlined_subroutine die in the |
| 2184 | /// __debug_info section, and the low_pc is the starting address for the |
| 2185 | /// inlining instance. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2186 | void DwarfDebug::emitDebugInlineInfo() { |
Eric Christopher | b83e2bb | 2012-03-02 02:11:47 +0000 | [diff] [blame] | 2187 | if (!Asm->MAI->doesDwarfUseInlineInfoSection()) |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2188 | return; |
| 2189 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2190 | if (!FirstCU) |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2191 | return; |
| 2192 | |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2193 | Asm->OutStreamer.SwitchSection( |
| 2194 | Asm->getObjFileLowering().getDwarfDebugInlineSection()); |
Chris Lattner | 0ad9c91 | 2010-01-22 22:09:00 +0000 | [diff] [blame] | 2195 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 2196 | Asm->OutStreamer.AddComment("Length of Debug Inlined Information Entry"); |
Chris Lattner | a643718 | 2010-04-04 19:58:12 +0000 | [diff] [blame] | 2197 | Asm->EmitLabelDifference(Asm->GetTempSymbol("debug_inlined_end", 1), |
| 2198 | Asm->GetTempSymbol("debug_inlined_begin", 1), 4); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2199 | |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 2200 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_inlined_begin", 1)); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2201 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 2202 | Asm->OutStreamer.AddComment("Dwarf Version"); |
| 2203 | Asm->EmitInt16(dwarf::DWARF_VERSION); |
| 2204 | Asm->OutStreamer.AddComment("Address Size (in bytes)"); |
Chandler Carruth | 426c2bf | 2012-11-01 09:14:31 +0000 | [diff] [blame] | 2205 | Asm->EmitInt8(Asm->getDataLayout().getPointerSize()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2206 | |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 2207 | for (SmallVector<const MDNode *, 4>::iterator I = InlinedSPNodes.begin(), |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2208 | E = InlinedSPNodes.end(); I != E; ++I) { |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 2209 | |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 2210 | const MDNode *Node = *I; |
| 2211 | DenseMap<const MDNode *, SmallVector<InlineInfoLabels, 4> >::iterator II |
Jim Grosbach | 7ab38df | 2009-11-22 19:20:36 +0000 | [diff] [blame] | 2212 | = InlineInfo.find(Node); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2213 | SmallVector<InlineInfoLabels, 4> &Labels = II->second; |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 2214 | DISubprogram SP(Node); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 2215 | StringRef LName = SP.getLinkageName(); |
| 2216 | StringRef Name = SP.getName(); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2217 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 2218 | Asm->OutStreamer.AddComment("MIPS linkage name"); |
Eric Christopher | 50e2661 | 2012-03-02 01:57:52 +0000 | [diff] [blame] | 2219 | if (LName.empty()) |
| 2220 | Asm->EmitSectionOffset(getStringPoolEntry(Name), DwarfStrSectionSym); |
| 2221 | else |
Chris Lattner | 6189ed1 | 2010-04-04 23:25:33 +0000 | [diff] [blame] | 2222 | Asm->EmitSectionOffset(getStringPoolEntry(getRealLinkageName(LName)), |
| 2223 | DwarfStrSectionSym); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2224 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 2225 | Asm->OutStreamer.AddComment("Function name"); |
Chris Lattner | 6189ed1 | 2010-04-04 23:25:33 +0000 | [diff] [blame] | 2226 | Asm->EmitSectionOffset(getStringPoolEntry(Name), DwarfStrSectionSym); |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 2227 | Asm->EmitULEB128(Labels.size(), "Inline count"); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2228 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2229 | for (SmallVector<InlineInfoLabels, 4>::iterator LI = Labels.begin(), |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2230 | LE = Labels.end(); LI != LE; ++LI) { |
Chris Lattner | 3f53c83 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 2231 | if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DIE offset"); |
Chris Lattner | 6ed0f90 | 2010-03-09 00:31:02 +0000 | [diff] [blame] | 2232 | Asm->EmitInt32(LI->second->getOffset()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2233 | |
Chris Lattner | 3f53c83 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 2234 | if (Asm->isVerbose()) Asm->OutStreamer.AddComment("low_pc"); |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 2235 | Asm->OutStreamer.EmitSymbolValue(LI->first, |
Chandler Carruth | 426c2bf | 2012-11-01 09:14:31 +0000 | [diff] [blame] | 2236 | Asm->getDataLayout().getPointerSize(),0); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2237 | } |
| 2238 | } |
| 2239 | |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 2240 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_inlined_end", 1)); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2241 | } |