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