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