1 //===-- llvm/CodeGen/DwarfDebug.cpp - Dwarf Debug Framework ---------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains support for writing dwarf debug info into asm files.
12 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "dwarfdebug"
15 #include "DwarfDebug.h"
17 #include "DwarfCompileUnit.h"
18 #include "llvm/Constants.h"
19 #include "llvm/Module.h"
20 #include "llvm/Instructions.h"
21 #include "llvm/CodeGen/MachineFunction.h"
22 #include "llvm/CodeGen/MachineModuleInfo.h"
23 #include "llvm/MC/MCAsmInfo.h"
24 #include "llvm/MC/MCSection.h"
25 #include "llvm/MC/MCStreamer.h"
26 #include "llvm/MC/MCSymbol.h"
27 #include "llvm/Target/Mangler.h"
28 #include "llvm/Target/TargetData.h"
29 #include "llvm/Target/TargetFrameLowering.h"
30 #include "llvm/Target/TargetLoweringObjectFile.h"
31 #include "llvm/Target/TargetMachine.h"
32 #include "llvm/Target/TargetRegisterInfo.h"
33 #include "llvm/Target/TargetOptions.h"
34 #include "llvm/Analysis/DebugInfo.h"
35 #include "llvm/Analysis/DIBuilder.h"
36 #include "llvm/ADT/Statistic.h"
37 #include "llvm/ADT/STLExtras.h"
38 #include "llvm/ADT/StringExtras.h"
39 #include "llvm/Support/CommandLine.h"
40 #include "llvm/Support/Debug.h"
41 #include "llvm/Support/ErrorHandling.h"
42 #include "llvm/Support/ValueHandle.h"
43 #include "llvm/Support/FormattedStream.h"
44 #include "llvm/Support/Timer.h"
45 #include "llvm/Support/Path.h"
48 static cl::opt<bool> DisableDebugInfoPrinting("disable-debug-info-print",
50 cl::desc("Disable debug info printing"));
52 static cl::opt<bool> UnknownLocations("use-unknown-locations", cl::Hidden,
53 cl::desc("Make an absence of debug location information explicit."),
57 const char *DWARFGroupName = "DWARF Emission";
58 const char *DbgTimerName = "DWARF Debug Writer";
59 } // end anonymous namespace
61 //===----------------------------------------------------------------------===//
63 /// Configuration values for initial hash set sizes (log2).
65 static const unsigned InitAbbreviationsSetSize = 9; // log2(512)
69 DIType DbgVariable::getType() const {
70 DIType Ty = Var.getType();
71 // FIXME: isBlockByrefVariable should be reformulated in terms of complex
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.
81 However, as far as the original *programmer* is concerned, the
82 variable should still have type 'SomeType', as originally declared.
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.
90 The original type 'SomeType' will be the type of the field named
91 'VarName' inside the __Block_byref_x_VarName struct.
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. */
99 unsigned tag = Ty.getTag();
101 if (tag == dwarf::DW_TAG_pointer_type) {
102 DIDerivedType DTy = DIDerivedType(Ty);
103 subType = DTy.getTypeDerivedFrom();
106 DICompositeType blockStruct = DICompositeType(subType);
107 DIArray Elements = blockStruct.getTypeArray();
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());
120 } // end llvm namespace
122 DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
123 : Asm(A), MMI(Asm->MMI), FirstCU(0),
124 AbbreviationsSet(InitAbbreviationsSetSize),
126 NextStringPoolNumber = 0;
128 DwarfInfoSectionSym = DwarfAbbrevSectionSym = 0;
129 DwarfStrSectionSym = TextSectionSym = 0;
130 DwarfDebugRangeSectionSym = DwarfDebugLocSectionSym = 0;
131 FunctionBeginSym = FunctionEndSym = 0;
133 NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
137 DwarfDebug::~DwarfDebug() {
140 MCSymbol *DwarfDebug::getStringPoolEntry(StringRef Str) {
141 std::pair<MCSymbol*, unsigned> &Entry = StringPool[Str];
142 if (Entry.first) return Entry.first;
144 Entry.second = NextStringPoolNumber++;
145 return Entry.first = Asm->GetTempSymbol("string", Entry.second);
149 /// assignAbbrevNumber - Define a unique number for the abbreviation.
151 void DwarfDebug::assignAbbrevNumber(DIEAbbrev &Abbrev) {
152 // Profile the node so that we can make it unique.
156 // Check the set for priors.
157 DIEAbbrev *InSet = AbbreviationsSet.GetOrInsertNode(&Abbrev);
159 // If it's newly added.
160 if (InSet == &Abbrev) {
161 // Add to abbreviation list.
162 Abbreviations.push_back(&Abbrev);
164 // Assign the vector position + 1 as its number.
165 Abbrev.setNumber(Abbreviations.size());
167 // Assign existing abbreviation number.
168 Abbrev.setNumber(InSet->getNumber());
172 /// getRealLinkageName - If special LLVM prefix that is used to inform the asm
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) {
177 if (LinkageName.startswith(StringRef(&One, 1)))
178 return LinkageName.substr(1);
182 /// createSubprogramDIE - Create new DIE using SP.
183 DIE *DwarfDebug::createSubprogramDIE(DISubprogram SP) {
184 CompileUnit *SPCU = getCompileUnit(SP);
185 DIE *SPDie = SPCU->getDIE(SP);
189 SPDie = new DIE(dwarf::DW_TAG_subprogram);
191 // DW_TAG_inlined_subroutine may refer to this DIE.
192 SPCU->insertDIE(SP, SPDie);
194 // Add to context owner.
195 SPCU->addToContextOwner(SPDie, SP.getContext());
197 // Add function template parameters.
198 SPCU->addTemplateParams(*SPDie, SP.getTemplateParams());
200 StringRef LinkageName = SP.getLinkageName();
201 if (!LinkageName.empty())
202 SPCU->addString(SPDie, dwarf::DW_AT_MIPS_linkage_name, dwarf::DW_FORM_string,
203 getRealLinkageName(LinkageName));
205 // If this DIE is going to refer declaration info using AT_specification
206 // then there is no need to add other attributes.
207 if (SP.getFunctionDeclaration().isSubprogram())
210 // Constructors and operators for anonymous aggregates do not have names.
211 if (!SP.getName().empty())
212 SPCU->addString(SPDie, dwarf::DW_AT_name, dwarf::DW_FORM_string,
215 SPCU->addSourceLine(SPDie, SP);
217 if (SP.isPrototyped())
218 SPCU->addUInt(SPDie, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag, 1);
221 DICompositeType SPTy = SP.getType();
222 DIArray Args = SPTy.getTypeArray();
223 unsigned SPTag = SPTy.getTag();
225 if (Args.getNumElements() == 0 || SPTag != dwarf::DW_TAG_subroutine_type)
226 SPCU->addType(SPDie, SPTy);
228 SPCU->addType(SPDie, DIType(Args.getElement(0)));
230 unsigned VK = SP.getVirtuality();
232 SPCU->addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_flag, VK);
233 DIEBlock *Block = SPCU->getDIEBlock();
234 SPCU->addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
235 SPCU->addUInt(Block, 0, dwarf::DW_FORM_udata, SP.getVirtualIndex());
236 SPCU->addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, 0, Block);
237 ContainingTypeMap.insert(std::make_pair(SPDie,
238 SP.getContainingType()));
241 if (!SP.isDefinition()) {
242 SPCU->addUInt(SPDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
244 // Add arguments. Do not add arguments for subprogram definition. They will
245 // be handled while processing variables.
246 DICompositeType SPTy = SP.getType();
247 DIArray Args = SPTy.getTypeArray();
248 unsigned SPTag = SPTy.getTag();
250 if (SPTag == dwarf::DW_TAG_subroutine_type)
251 for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
252 DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
253 DIType ATy = DIType(DIType(Args.getElement(i)));
254 SPCU->addType(Arg, ATy);
255 if (ATy.isArtificial())
256 SPCU->addUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1);
257 SPDie->addChild(Arg);
261 if (SP.isArtificial())
262 SPCU->addUInt(SPDie, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1);
264 if (!SP.isLocalToUnit())
265 SPCU->addUInt(SPDie, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1);
267 if (SP.isOptimized())
268 SPCU->addUInt(SPDie, dwarf::DW_AT_APPLE_optimized, dwarf::DW_FORM_flag, 1);
270 if (unsigned isa = Asm->getISAEncoding()) {
271 SPCU->addUInt(SPDie, dwarf::DW_AT_APPLE_isa, dwarf::DW_FORM_flag, isa);
277 /// isSubprogramContext - Return true if Context is either a subprogram
278 /// or another context nested inside a subprogram.
279 static bool isSubprogramContext(const MDNode *Context) {
282 DIDescriptor D(Context);
283 if (D.isSubprogram())
286 return isSubprogramContext(DIType(Context).getContext());
290 /// updateSubprogramScopeDIE - Find DIE for the given subprogram and
291 /// attach appropriate DW_AT_low_pc and DW_AT_high_pc attributes.
292 /// If there are global variables in this scope then create and insert
293 /// DIEs for these variables.
294 DIE *DwarfDebug::updateSubprogramScopeDIE(const MDNode *SPNode) {
295 CompileUnit *SPCU = getCompileUnit(SPNode);
296 DIE *SPDie = SPCU->getDIE(SPNode);
298 assert(SPDie && "Unable to find subprogram DIE!");
299 DISubprogram SP(SPNode);
301 DISubprogram SPDecl = SP.getFunctionDeclaration();
302 if (SPDecl.isSubprogram())
303 // Refer function declaration directly.
304 SPCU->addDIEEntry(SPDie, dwarf::DW_AT_specification, dwarf::DW_FORM_ref4,
305 createSubprogramDIE(SPDecl));
307 // There is not any need to generate specification DIE for a function
308 // defined at compile unit level. If a function is defined inside another
309 // function then gdb prefers the definition at top level and but does not
310 // expect specification DIE in parent function. So avoid creating
311 // specification DIE for a function defined inside a function.
312 if (SP.isDefinition() && !SP.getContext().isCompileUnit() &&
313 !SP.getContext().isFile() &&
314 !isSubprogramContext(SP.getContext())) {
315 SPCU-> addUInt(SPDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
318 DICompositeType SPTy = SP.getType();
319 DIArray Args = SPTy.getTypeArray();
320 unsigned SPTag = SPTy.getTag();
321 if (SPTag == dwarf::DW_TAG_subroutine_type)
322 for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
323 DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
324 DIType ATy = DIType(DIType(Args.getElement(i)));
325 SPCU->addType(Arg, ATy);
326 if (ATy.isArtificial())
327 SPCU->addUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1);
328 SPDie->addChild(Arg);
330 DIE *SPDeclDie = SPDie;
331 SPDie = new DIE(dwarf::DW_TAG_subprogram);
332 SPCU->addDIEEntry(SPDie, dwarf::DW_AT_specification, dwarf::DW_FORM_ref4,
337 // Pick up abstract subprogram DIE.
338 if (DIE *AbsSPDIE = AbstractSPDies.lookup(SPNode)) {
339 SPDie = new DIE(dwarf::DW_TAG_subprogram);
340 SPCU->addDIEEntry(SPDie, dwarf::DW_AT_abstract_origin,
341 dwarf::DW_FORM_ref4, AbsSPDIE);
345 SPCU->addLabel(SPDie, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
346 Asm->GetTempSymbol("func_begin", Asm->getFunctionNumber()));
347 SPCU->addLabel(SPDie, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr,
348 Asm->GetTempSymbol("func_end", Asm->getFunctionNumber()));
349 const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo();
350 MachineLocation Location(RI->getFrameRegister(*Asm->MF));
351 SPCU->addAddress(SPDie, dwarf::DW_AT_frame_base, Location);
356 /// constructLexicalScope - Construct new DW_TAG_lexical_block
357 /// for this scope and attach DW_AT_low_pc/DW_AT_high_pc labels.
358 DIE *DwarfDebug::constructLexicalScopeDIE(LexicalScope *Scope) {
360 DIE *ScopeDIE = new DIE(dwarf::DW_TAG_lexical_block);
361 if (Scope->isAbstractScope())
364 const SmallVector<InsnRange, 4> &Ranges = Scope->getRanges();
368 CompileUnit *TheCU = getCompileUnit(Scope->getScopeNode());
369 SmallVector<InsnRange, 4>::const_iterator RI = Ranges.begin();
370 if (Ranges.size() > 1) {
371 // .debug_range section has not been laid out yet. Emit offset in
372 // .debug_range as a uint, size 4, for now. emitDIE will handle
373 // DW_AT_ranges appropriately.
374 TheCU->addUInt(ScopeDIE, dwarf::DW_AT_ranges, dwarf::DW_FORM_data4,
375 DebugRangeSymbols.size() * Asm->getTargetData().getPointerSize());
376 for (SmallVector<InsnRange, 4>::const_iterator RI = Ranges.begin(),
377 RE = Ranges.end(); RI != RE; ++RI) {
378 DebugRangeSymbols.push_back(getLabelBeforeInsn(RI->first));
379 DebugRangeSymbols.push_back(getLabelAfterInsn(RI->second));
381 DebugRangeSymbols.push_back(NULL);
382 DebugRangeSymbols.push_back(NULL);
386 const MCSymbol *Start = getLabelBeforeInsn(RI->first);
387 const MCSymbol *End = getLabelAfterInsn(RI->second);
389 if (End == 0) return 0;
391 assert(Start->isDefined() && "Invalid starting label for an inlined scope!");
392 assert(End->isDefined() && "Invalid end label for an inlined scope!");
394 TheCU->addLabel(ScopeDIE, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, Start);
395 TheCU->addLabel(ScopeDIE, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr, End);
400 /// constructInlinedScopeDIE - This scope represents inlined body of
401 /// a function. Construct DIE to represent this concrete inlined copy
403 DIE *DwarfDebug::constructInlinedScopeDIE(LexicalScope *Scope) {
405 const SmallVector<InsnRange, 4> &Ranges = Scope->getRanges();
406 assert (Ranges.empty() == false
407 && "LexicalScope does not have instruction markers!");
409 if (!Scope->getScopeNode())
411 DIScope DS(Scope->getScopeNode());
412 DISubprogram InlinedSP = getDISubprogram(DS);
413 CompileUnit *TheCU = getCompileUnit(InlinedSP);
414 DIE *OriginDIE = TheCU->getDIE(InlinedSP);
416 DEBUG(dbgs() << "Unable to find original DIE for inlined subprogram.");
420 SmallVector<InsnRange, 4>::const_iterator RI = Ranges.begin();
421 const MCSymbol *StartLabel = getLabelBeforeInsn(RI->first);
422 const MCSymbol *EndLabel = getLabelAfterInsn(RI->second);
424 if (StartLabel == 0 || EndLabel == 0) {
425 assert (0 && "Unexpected Start and End labels for a inlined scope!");
428 assert(StartLabel->isDefined() &&
429 "Invalid starting label for an inlined scope!");
430 assert(EndLabel->isDefined() &&
431 "Invalid end label for an inlined scope!");
433 DIE *ScopeDIE = new DIE(dwarf::DW_TAG_inlined_subroutine);
434 TheCU->addDIEEntry(ScopeDIE, dwarf::DW_AT_abstract_origin,
435 dwarf::DW_FORM_ref4, OriginDIE);
437 if (Ranges.size() > 1) {
438 // .debug_range section has not been laid out yet. Emit offset in
439 // .debug_range as a uint, size 4, for now. emitDIE will handle
440 // DW_AT_ranges appropriately.
441 TheCU->addUInt(ScopeDIE, dwarf::DW_AT_ranges, dwarf::DW_FORM_data4,
442 DebugRangeSymbols.size() * Asm->getTargetData().getPointerSize());
443 for (SmallVector<InsnRange, 4>::const_iterator RI = Ranges.begin(),
444 RE = Ranges.end(); RI != RE; ++RI) {
445 DebugRangeSymbols.push_back(getLabelBeforeInsn(RI->first));
446 DebugRangeSymbols.push_back(getLabelAfterInsn(RI->second));
448 DebugRangeSymbols.push_back(NULL);
449 DebugRangeSymbols.push_back(NULL);
451 TheCU->addLabel(ScopeDIE, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, StartLabel);
452 TheCU->addLabel(ScopeDIE, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr, EndLabel);
455 InlinedSubprogramDIEs.insert(OriginDIE);
457 // Track the start label for this inlined function.
458 //.debug_inlined section specification does not clearly state how
459 // to emit inlined scope that is split into multiple instruction ranges.
460 // For now, use first instruction range and emit low_pc/high_pc pair and
461 // corresponding .debug_inlined section entry for this pair.
462 DenseMap<const MDNode *, SmallVector<InlineInfoLabels, 4> >::iterator
463 I = InlineInfo.find(InlinedSP);
465 if (I == InlineInfo.end()) {
466 InlineInfo[InlinedSP].push_back(std::make_pair(StartLabel,
468 InlinedSPNodes.push_back(InlinedSP);
470 I->second.push_back(std::make_pair(StartLabel, ScopeDIE));
472 DILocation DL(Scope->getInlinedAt());
473 TheCU->addUInt(ScopeDIE, dwarf::DW_AT_call_file, 0, TheCU->getID());
474 TheCU->addUInt(ScopeDIE, dwarf::DW_AT_call_line, 0, DL.getLineNumber());
479 /// isUnsignedDIType - Return true if type encoding is unsigned.
480 static bool isUnsignedDIType(DIType Ty) {
481 DIDerivedType DTy(Ty);
483 return isUnsignedDIType(DTy.getTypeDerivedFrom());
487 unsigned Encoding = BTy.getEncoding();
488 if (Encoding == dwarf::DW_ATE_unsigned ||
489 Encoding == dwarf::DW_ATE_unsigned_char)
495 /// constructVariableDIE - Construct a DIE for the given DbgVariable.
496 DIE *DwarfDebug::constructVariableDIE(DbgVariable *DV, LexicalScope *Scope) {
497 StringRef Name = DV->getName();
501 // Translate tag to proper Dwarf tag. The result variable is dropped for
504 switch (DV->getTag()) {
505 case dwarf::DW_TAG_return_variable:
507 case dwarf::DW_TAG_arg_variable:
508 Tag = dwarf::DW_TAG_formal_parameter;
510 case dwarf::DW_TAG_auto_variable: // fall thru
512 Tag = dwarf::DW_TAG_variable;
516 // Define variable debug information entry.
517 DIE *VariableDie = new DIE(Tag);
518 CompileUnit *VariableCU = getCompileUnit(DV->getVariable());
520 DenseMap<const DbgVariable *, const DbgVariable *>::iterator
521 V2AVI = VarToAbstractVarMap.find(DV);
522 if (V2AVI != VarToAbstractVarMap.end())
523 AbsDIE = V2AVI->second->getDIE();
526 VariableCU->addDIEEntry(VariableDie, dwarf::DW_AT_abstract_origin,
527 dwarf::DW_FORM_ref4, AbsDIE);
529 VariableCU->addString(VariableDie, dwarf::DW_AT_name, dwarf::DW_FORM_string,
531 VariableCU->addSourceLine(VariableDie, DV->getVariable());
533 // Add variable type.
534 VariableCU->addType(VariableDie, DV->getType());
537 if (Tag == dwarf::DW_TAG_formal_parameter && DV->getType().isArtificial())
538 VariableCU->addUInt(VariableDie, dwarf::DW_AT_artificial,
539 dwarf::DW_FORM_flag, 1);
540 else if (DIVariable(DV->getVariable()).isArtificial())
541 VariableCU->addUInt(VariableDie, dwarf::DW_AT_artificial,
542 dwarf::DW_FORM_flag, 1);
544 if (Scope->isAbstractScope()) {
545 DV->setDIE(VariableDie);
549 // Add variable address.
551 unsigned Offset = DV->getDotDebugLocOffset();
553 VariableCU->addLabel(VariableDie, dwarf::DW_AT_location, dwarf::DW_FORM_data4,
554 Asm->GetTempSymbol("debug_loc", Offset));
555 DV->setDIE(VariableDie);
556 UseDotDebugLocEntry.insert(VariableDie);
560 // Check if variable is described by a DBG_VALUE instruction.
561 DenseMap<const DbgVariable *, const MachineInstr *>::iterator DVI =
562 DbgVariableToDbgInstMap.find(DV);
563 if (DVI != DbgVariableToDbgInstMap.end()) {
564 const MachineInstr *DVInsn = DVI->second;
565 bool updated = false;
566 if (DVInsn->getNumOperands() == 3) {
567 if (DVInsn->getOperand(0).isReg()) {
568 const MachineOperand RegOp = DVInsn->getOperand(0);
569 const TargetRegisterInfo *TRI = Asm->TM.getRegisterInfo();
570 if (DVInsn->getOperand(1).isImm() &&
571 TRI->getFrameRegister(*Asm->MF) == RegOp.getReg()) {
572 unsigned FrameReg = 0;
573 const TargetFrameLowering *TFI = Asm->TM.getFrameLowering();
575 TFI->getFrameIndexReference(*Asm->MF,
576 DVInsn->getOperand(1).getImm(),
578 MachineLocation Location(FrameReg, Offset);
579 VariableCU->addVariableAddress(DV, VariableDie, Location);
581 } else if (RegOp.getReg())
582 VariableCU->addVariableAddress(DV, VariableDie,
583 MachineLocation(RegOp.getReg()));
586 else if (DVInsn->getOperand(0).isImm())
588 VariableCU->addConstantValue(VariableDie, DVInsn->getOperand(0),
590 else if (DVInsn->getOperand(0).isFPImm())
592 VariableCU->addConstantFPValue(VariableDie, DVInsn->getOperand(0));
593 else if (DVInsn->getOperand(0).isCImm())
595 VariableCU->addConstantValue(VariableDie,
596 DVInsn->getOperand(0).getCImm(),
597 isUnsignedDIType(DV->getType()));
599 VariableCU->addVariableAddress(DV, VariableDie,
600 Asm->getDebugValueLocation(DVInsn));
604 // If variableDie is not updated then DBG_VALUE instruction does not
605 // have valid variable info.
609 DV->setDIE(VariableDie);
613 // .. else use frame index, if available.
615 if (findVariableFrameIndex(DV, &FI)) {
616 unsigned FrameReg = 0;
617 const TargetFrameLowering *TFI = Asm->TM.getFrameLowering();
619 TFI->getFrameIndexReference(*Asm->MF, FI, FrameReg);
620 MachineLocation Location(FrameReg, Offset);
621 VariableCU->addVariableAddress(DV, VariableDie, Location);
624 DV->setDIE(VariableDie);
629 /// constructScopeDIE - Construct a DIE for this scope.
630 DIE *DwarfDebug::constructScopeDIE(LexicalScope *Scope) {
631 if (!Scope || !Scope->getScopeNode())
634 SmallVector <DIE *, 8> Children;
636 // Collect arguments for current function.
637 if (LScopes.isCurrentFunctionScope(Scope))
638 for (unsigned i = 0, N = CurrentFnArguments.size(); i < N; ++i)
639 if (DbgVariable *ArgDV = CurrentFnArguments[i])
640 if (DIE *Arg = constructVariableDIE(ArgDV, Scope))
641 Children.push_back(Arg);
643 // Collect lexical scope childrens first.
644 const SmallVector<DbgVariable *, 8> &Variables = ScopeVariables.lookup(Scope);
645 for (unsigned i = 0, N = Variables.size(); i < N; ++i)
646 if (DIE *Variable = constructVariableDIE(Variables[i], Scope))
647 Children.push_back(Variable);
648 const SmallVector<LexicalScope *, 4> &Scopes = Scope->getChildren();
649 for (unsigned j = 0, M = Scopes.size(); j < M; ++j)
650 if (DIE *Nested = constructScopeDIE(Scopes[j]))
651 Children.push_back(Nested);
652 DIScope DS(Scope->getScopeNode());
653 DIE *ScopeDIE = NULL;
654 if (Scope->getInlinedAt())
655 ScopeDIE = constructInlinedScopeDIE(Scope);
656 else if (DS.isSubprogram()) {
657 ProcessedSPNodes.insert(DS);
658 if (Scope->isAbstractScope()) {
659 ScopeDIE = getCompileUnit(DS)->getDIE(DS);
660 // Note down abstract DIE.
662 AbstractSPDies.insert(std::make_pair(DS, ScopeDIE));
665 ScopeDIE = updateSubprogramScopeDIE(DS);
668 // There is no need to emit empty lexical block DIE.
669 if (Children.empty())
671 ScopeDIE = constructLexicalScopeDIE(Scope);
674 if (!ScopeDIE) return NULL;
677 for (SmallVector<DIE *, 8>::iterator I = Children.begin(),
678 E = Children.end(); I != E; ++I)
679 ScopeDIE->addChild(*I);
681 if (DS.isSubprogram())
682 getCompileUnit(DS)->addPubTypes(DISubprogram(DS));
687 /// GetOrCreateSourceID - Look up the source id with the given directory and
688 /// source file names. If none currently exists, create a new id and insert it
689 /// in the SourceIds map. This can update DirectoryNames and SourceFileNames
692 unsigned DwarfDebug::GetOrCreateSourceID(StringRef FileName,
694 // If FE did not provide a file name, then assume stdin.
695 if (FileName.empty())
696 return GetOrCreateSourceID("<stdin>", StringRef());
698 // MCStream expects full path name as filename.
699 if (!DirName.empty() && !sys::path::is_absolute(FileName)) {
700 SmallString<128> FullPathName = DirName;
701 sys::path::append(FullPathName, FileName);
702 // Here FullPathName will be copied into StringMap by GetOrCreateSourceID.
703 return GetOrCreateSourceID(StringRef(FullPathName), StringRef());
706 StringMapEntry<unsigned> &Entry = SourceIdMap.GetOrCreateValue(FileName);
707 if (Entry.getValue())
708 return Entry.getValue();
710 unsigned SrcId = SourceIdMap.size();
711 Entry.setValue(SrcId);
713 // Print out a .file directive to specify files for .loc directives.
714 Asm->OutStreamer.EmitDwarfFileDirective(SrcId, Entry.getKey());
719 /// constructCompileUnit - Create new CompileUnit for the given
720 /// metadata node with tag DW_TAG_compile_unit.
721 void DwarfDebug::constructCompileUnit(const MDNode *N) {
722 DICompileUnit DIUnit(N);
723 StringRef FN = DIUnit.getFilename();
724 StringRef Dir = DIUnit.getDirectory();
725 unsigned ID = GetOrCreateSourceID(FN, Dir);
727 DIE *Die = new DIE(dwarf::DW_TAG_compile_unit);
728 CompileUnit *NewCU = new CompileUnit(ID, Die, Asm, this);
729 NewCU->addString(Die, dwarf::DW_AT_producer, dwarf::DW_FORM_string,
730 DIUnit.getProducer());
731 NewCU->addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
732 DIUnit.getLanguage());
733 NewCU->addString(Die, dwarf::DW_AT_name, dwarf::DW_FORM_string, FN);
734 // Use DW_AT_entry_pc instead of DW_AT_low_pc/DW_AT_high_pc pair. This
735 // simplifies debug range entries.
736 NewCU->addUInt(Die, dwarf::DW_AT_entry_pc, dwarf::DW_FORM_addr, 0);
737 // DW_AT_stmt_list is a offset of line number information for this
738 // compile unit in debug_line section.
739 if(Asm->MAI->doesDwarfRequireRelocationForSectionOffset())
740 NewCU->addLabel(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4,
741 Asm->GetTempSymbol("section_line"));
743 NewCU->addUInt(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4, 0);
746 NewCU->addString(Die, dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string, Dir);
747 if (DIUnit.isOptimized())
748 NewCU->addUInt(Die, dwarf::DW_AT_APPLE_optimized, dwarf::DW_FORM_flag, 1);
750 StringRef Flags = DIUnit.getFlags();
752 NewCU->addString(Die, dwarf::DW_AT_APPLE_flags, dwarf::DW_FORM_string, Flags);
754 unsigned RVer = DIUnit.getRunTimeVersion();
756 NewCU->addUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers,
757 dwarf::DW_FORM_data1, RVer);
761 CUMap.insert(std::make_pair(N, NewCU));
764 /// getCompileUnit - Get CompileUnit DIE.
765 CompileUnit *DwarfDebug::getCompileUnit(const MDNode *N) const {
766 assert (N && "Invalid DwarfDebug::getCompileUnit argument!");
768 const MDNode *CUNode = NULL;
769 if (D.isCompileUnit())
771 else if (D.isSubprogram())
772 CUNode = DISubprogram(N).getCompileUnit();
774 CUNode = DIType(N).getCompileUnit();
775 else if (D.isGlobalVariable())
776 CUNode = DIGlobalVariable(N).getCompileUnit();
777 else if (D.isVariable())
778 CUNode = DIVariable(N).getCompileUnit();
779 else if (D.isNameSpace())
780 CUNode = DINameSpace(N).getCompileUnit();
782 CUNode = DIFile(N).getCompileUnit();
786 DenseMap<const MDNode *, CompileUnit *>::const_iterator I
787 = CUMap.find(CUNode);
788 if (I == CUMap.end())
793 // Return const expression if value is a GEP to access merged global
795 // i8* getelementptr ({ i8, i8, i8, i8 }* @_MergedGlobals, i32 0, i32 0)
796 static const ConstantExpr *getMergedGlobalExpr(const Value *V) {
797 const ConstantExpr *CE = dyn_cast_or_null<ConstantExpr>(V);
798 if (!CE || CE->getNumOperands() != 3 ||
799 CE->getOpcode() != Instruction::GetElementPtr)
802 // First operand points to a global struct.
803 Value *Ptr = CE->getOperand(0);
804 if (!isa<GlobalValue>(Ptr) ||
805 !isa<StructType>(cast<PointerType>(Ptr->getType())->getElementType()))
808 // Second operand is zero.
809 const ConstantInt *CI = dyn_cast_or_null<ConstantInt>(CE->getOperand(1));
810 if (!CI || !CI->isZero())
813 // Third operand is offset.
814 if (!isa<ConstantInt>(CE->getOperand(2)))
820 /// constructGlobalVariableDIE - Construct global variable DIE.
821 void DwarfDebug::constructGlobalVariableDIE(const MDNode *N) {
822 DIGlobalVariable GV(N);
824 // If debug information is malformed then ignore it.
825 if (GV.Verify() == false)
828 // Check for pre-existence.
829 CompileUnit *TheCU = getCompileUnit(N);
830 if (TheCU->getDIE(GV))
833 DIType GTy = GV.getType();
834 DIE *VariableDIE = new DIE(GV.getTag());
836 bool isGlobalVariable = GV.getGlobal() != NULL;
839 TheCU->addString(VariableDIE, dwarf::DW_AT_name, dwarf::DW_FORM_string,
840 GV.getDisplayName());
841 StringRef LinkageName = GV.getLinkageName();
842 if (!LinkageName.empty() && isGlobalVariable)
843 TheCU->addString(VariableDIE, dwarf::DW_AT_MIPS_linkage_name,
844 dwarf::DW_FORM_string,
845 getRealLinkageName(LinkageName));
847 TheCU->addType(VariableDIE, GTy);
850 if (!GV.isLocalToUnit()) {
851 TheCU->addUInt(VariableDIE, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1);
853 TheCU->addGlobal(GV.getName(), VariableDIE);
855 // Add line number info.
856 TheCU->addSourceLine(VariableDIE, GV);
858 TheCU->insertDIE(N, VariableDIE);
859 // Add to context owner.
860 DIDescriptor GVContext = GV.getContext();
861 TheCU->addToContextOwner(VariableDIE, GVContext);
863 if (isGlobalVariable) {
864 DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
865 TheCU->addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
866 TheCU->addLabel(Block, 0, dwarf::DW_FORM_udata,
867 Asm->Mang->getSymbol(GV.getGlobal()));
868 // Do not create specification DIE if context is either compile unit
870 if (GV.isDefinition() && !GVContext.isCompileUnit() &&
871 !GVContext.isFile() && !isSubprogramContext(GVContext)) {
872 // Create specification DIE.
873 DIE *VariableSpecDIE = new DIE(dwarf::DW_TAG_variable);
874 TheCU->addDIEEntry(VariableSpecDIE, dwarf::DW_AT_specification,
875 dwarf::DW_FORM_ref4, VariableDIE);
876 TheCU->addBlock(VariableSpecDIE, dwarf::DW_AT_location, 0, Block);
877 TheCU->addUInt(VariableDIE, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
878 TheCU->addDie(VariableSpecDIE);
880 TheCU->addBlock(VariableDIE, dwarf::DW_AT_location, 0, Block);
882 } else if (const ConstantInt *CI =
883 dyn_cast_or_null<ConstantInt>(GV.getConstant()))
884 TheCU->addConstantValue(VariableDIE, CI, isUnsignedDIType(GTy));
885 else if (const ConstantExpr *CE = getMergedGlobalExpr(N->getOperand(11))) {
886 // GV is a merged global.
887 DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
888 Value *Ptr = CE->getOperand(0);
889 TheCU->addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
890 TheCU->addLabel(Block, 0, dwarf::DW_FORM_udata,
891 Asm->Mang->getSymbol(cast<GlobalValue>(Ptr)));
892 TheCU->addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
893 SmallVector<Value*, 3> Idx(CE->op_begin()+1, CE->op_end());
894 TheCU->addUInt(Block, 0, dwarf::DW_FORM_udata,
895 Asm->getTargetData().getIndexedOffset(Ptr->getType(), Idx));
896 TheCU->addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
897 TheCU->addBlock(VariableDIE, dwarf::DW_AT_location, 0, Block);
903 /// construct SubprogramDIE - Construct subprogram DIE.
904 void DwarfDebug::constructSubprogramDIE(const MDNode *N) {
907 // Check for pre-existence.
908 CompileUnit *TheCU = getCompileUnit(N);
909 if (TheCU->getDIE(N))
912 if (!SP.isDefinition())
913 // This is a method declaration which will be handled while constructing
917 DIE *SubprogramDie = createSubprogramDIE(SP);
920 TheCU->insertDIE(N, SubprogramDie);
922 // Add to context owner.
923 TheCU->addToContextOwner(SubprogramDie, SP.getContext());
926 TheCU->addGlobal(SP.getName(), SubprogramDie);
931 /// beginModule - Emit all Dwarf sections that should come prior to the
932 /// content. Create global DIEs and emit initial debug info sections.
933 /// This is invoked by the target AsmPrinter.
934 void DwarfDebug::beginModule(Module *M) {
935 if (DisableDebugInfoPrinting)
938 // If module has named metadata anchors then use them, otherwise scan the
939 // module using debug info finder to collect debug info.
940 NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu");
943 NamedMDNode *GV_Nodes = M->getNamedMetadata("llvm.dbg.gv");
944 NamedMDNode *SP_Nodes = M->getNamedMetadata("llvm.dbg.sp");
945 if (!GV_Nodes && !SP_Nodes)
946 // If there are not any global variables or any functions then
947 // there is not any debug info in this module.
950 for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i)
951 constructCompileUnit(CU_Nodes->getOperand(i));
954 for (unsigned i = 0, e = GV_Nodes->getNumOperands(); i != e; ++i)
955 constructGlobalVariableDIE(GV_Nodes->getOperand(i));
958 for (unsigned i = 0, e = SP_Nodes->getNumOperands(); i != e; ++i)
959 constructSubprogramDIE(SP_Nodes->getOperand(i));
963 DebugInfoFinder DbgFinder;
964 DbgFinder.processModule(*M);
966 bool HasDebugInfo = false;
967 // Scan all the compile-units to see if there are any marked as the main
968 // unit. If not, we do not generate debug info.
969 for (DebugInfoFinder::iterator I = DbgFinder.compile_unit_begin(),
970 E = DbgFinder.compile_unit_end(); I != E; ++I) {
971 if (DICompileUnit(*I).isMain()) {
976 if (!HasDebugInfo) return;
978 // Create all the compile unit DIEs.
979 for (DebugInfoFinder::iterator I = DbgFinder.compile_unit_begin(),
980 E = DbgFinder.compile_unit_end(); I != E; ++I)
981 constructCompileUnit(*I);
983 // Create DIEs for each global variable.
984 for (DebugInfoFinder::iterator I = DbgFinder.global_variable_begin(),
985 E = DbgFinder.global_variable_end(); I != E; ++I)
986 constructGlobalVariableDIE(*I);
988 // Create DIEs for each subprogram.
989 for (DebugInfoFinder::iterator I = DbgFinder.subprogram_begin(),
990 E = DbgFinder.subprogram_end(); I != E; ++I)
991 constructSubprogramDIE(*I);
994 // Tell MMI that we have debug info.
995 MMI->setDebugInfoAvailability(true);
997 // Emit initial sections.
1000 //getOrCreateTypeDIE
1001 if (NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.enum"))
1002 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
1003 DIType Ty(NMD->getOperand(i));
1004 getCompileUnit(Ty)->getOrCreateTypeDIE(Ty);
1007 if (NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.ty"))
1008 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
1009 DIType Ty(NMD->getOperand(i));
1010 getCompileUnit(Ty)->getOrCreateTypeDIE(Ty);
1013 // Prime section data.
1014 SectionMap.insert(Asm->getObjFileLowering().getTextSection());
1017 /// endModule - Emit all Dwarf sections that should come after the content.
1019 void DwarfDebug::endModule() {
1020 if (!FirstCU) return;
1021 const Module *M = MMI->getModule();
1022 DenseMap<const MDNode *, LexicalScope *> DeadFnScopeMap;
1023 if (NamedMDNode *AllSPs = M->getNamedMetadata("llvm.dbg.sp")) {
1024 for (unsigned SI = 0, SE = AllSPs->getNumOperands(); SI != SE; ++SI) {
1025 if (ProcessedSPNodes.count(AllSPs->getOperand(SI)) != 0) continue;
1026 DISubprogram SP(AllSPs->getOperand(SI));
1027 if (!SP.Verify()) continue;
1029 // Collect info for variables that were optimized out.
1030 if (!SP.isDefinition()) continue;
1031 StringRef FName = SP.getLinkageName();
1033 FName = SP.getName();
1034 NamedMDNode *NMD = getFnSpecificMDNode(*(MMI->getModule()), FName);
1036 unsigned E = NMD->getNumOperands();
1038 LexicalScope *Scope = new LexicalScope(NULL, DIDescriptor(SP), NULL, false);
1039 DeadFnScopeMap[SP] = Scope;
1040 SmallVector<DbgVariable *, 8> Variables;
1041 for (unsigned I = 0; I != E; ++I) {
1042 DIVariable DV(NMD->getOperand(I));
1043 if (!DV.Verify()) continue;
1044 Variables.push_back(new DbgVariable(DV));
1047 // Construct subprogram DIE and add variables DIEs.
1048 constructSubprogramDIE(SP);
1049 DIE *ScopeDIE = getCompileUnit(SP)->getDIE(SP);
1050 for (unsigned i = 0, N = Variables.size(); i < N; ++i) {
1051 if (DIE *VariableDIE = constructVariableDIE(Variables[i], Scope))
1052 ScopeDIE->addChild(VariableDIE);
1057 // Attach DW_AT_inline attribute with inlined subprogram DIEs.
1058 for (SmallPtrSet<DIE *, 4>::iterator AI = InlinedSubprogramDIEs.begin(),
1059 AE = InlinedSubprogramDIEs.end(); AI != AE; ++AI) {
1061 FirstCU->addUInt(ISP, dwarf::DW_AT_inline, 0, dwarf::DW_INL_inlined);
1064 for (DenseMap<DIE *, const MDNode *>::iterator CI = ContainingTypeMap.begin(),
1065 CE = ContainingTypeMap.end(); CI != CE; ++CI) {
1066 DIE *SPDie = CI->first;
1067 const MDNode *N = dyn_cast_or_null<MDNode>(CI->second);
1069 DIE *NDie = getCompileUnit(N)->getDIE(N);
1070 if (!NDie) continue;
1071 getCompileUnit(N)->addDIEEntry(SPDie, dwarf::DW_AT_containing_type,
1072 dwarf::DW_FORM_ref4, NDie);
1075 // Standard sections final addresses.
1076 Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getTextSection());
1077 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("text_end"));
1078 Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getDataSection());
1079 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("data_end"));
1081 // End text sections.
1082 for (unsigned i = 1, N = SectionMap.size(); i <= N; ++i) {
1083 Asm->OutStreamer.SwitchSection(SectionMap[i]);
1084 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("section_end", i));
1087 // Compute DIE offsets and sizes.
1088 computeSizeAndOffsets();
1090 // Emit all the DIEs into a debug info section
1093 // Corresponding abbreviations into a abbrev section.
1094 emitAbbreviations();
1096 // Emit info into a debug pubnames section.
1097 emitDebugPubNames();
1099 // Emit info into a debug pubtypes section.
1100 emitDebugPubTypes();
1102 // Emit info into a debug loc section.
1105 // Emit info into a debug aranges section.
1108 // Emit info into a debug ranges section.
1111 // Emit info into a debug macinfo section.
1114 // Emit inline info.
1115 emitDebugInlineInfo();
1117 // Emit info into a debug str section.
1121 DeleteContainerSeconds(DeadFnScopeMap);
1122 for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
1123 E = CUMap.end(); I != E; ++I)
1125 FirstCU = NULL; // Reset for the next Module, if any.
1128 /// findAbstractVariable - Find abstract variable, if any, associated with Var.
1129 DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &DV,
1130 DebugLoc ScopeLoc) {
1131 LLVMContext &Ctx = DV->getContext();
1133 // More then one inlined variable corresponds to one abstract variable.
1134 DIVariable Var = cleanseInlinedVariable(DV, Ctx);
1136 DbgVariable *AbsDbgVariable = AbstractVariables.lookup(Var);
1138 return AbsDbgVariable;
1140 LexicalScope *Scope = LScopes.findAbstractScope(ScopeLoc.getScope(Ctx));
1144 AbsDbgVariable = new DbgVariable(Var);
1145 addScopeVariable(Scope, AbsDbgVariable);
1146 AbstractVariables[Var] = AbsDbgVariable;
1147 return AbsDbgVariable;
1150 /// addCurrentFnArgument - If Var is a current function argument then add
1151 /// it to CurrentFnArguments list.
1152 bool DwarfDebug::addCurrentFnArgument(const MachineFunction *MF,
1153 DbgVariable *Var, LexicalScope *Scope) {
1154 if (!LScopes.isCurrentFunctionScope(Scope))
1156 DIVariable DV = Var->getVariable();
1157 if (DV.getTag() != dwarf::DW_TAG_arg_variable)
1159 unsigned ArgNo = DV.getArgNumber();
1163 size_t Size = CurrentFnArguments.size();
1165 CurrentFnArguments.resize(MF->getFunction()->arg_size());
1166 // llvm::Function argument size is not good indicator of how many
1167 // arguments does the function have at source level.
1169 CurrentFnArguments.resize(ArgNo * 2);
1170 CurrentFnArguments[ArgNo - 1] = Var;
1174 /// collectVariableInfoFromMMITable - Collect variable information from
1175 /// side table maintained by MMI.
1177 DwarfDebug::collectVariableInfoFromMMITable(const MachineFunction *MF,
1178 SmallPtrSet<const MDNode *, 16> &Processed) {
1179 MachineModuleInfo::VariableDbgInfoMapTy &VMap = MMI->getVariableDbgInfo();
1180 for (MachineModuleInfo::VariableDbgInfoMapTy::iterator VI = VMap.begin(),
1181 VE = VMap.end(); VI != VE; ++VI) {
1182 const MDNode *Var = VI->first;
1184 Processed.insert(Var);
1186 const std::pair<unsigned, DebugLoc> &VP = VI->second;
1188 LexicalScope *Scope = LScopes.findLexicalScope(VP.second);
1190 // If variable scope is not found then skip this variable.
1194 DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.second);
1195 DbgVariable *RegVar = new DbgVariable(DV);
1196 recordVariableFrameIndex(RegVar, VP.first);
1197 if (!addCurrentFnArgument(MF, RegVar, Scope))
1198 addScopeVariable(Scope, RegVar);
1199 if (AbsDbgVariable) {
1200 recordVariableFrameIndex(AbsDbgVariable, VP.first);
1201 VarToAbstractVarMap[RegVar] = AbsDbgVariable;
1206 /// isDbgValueInDefinedReg - Return true if debug value, encoded by
1207 /// DBG_VALUE instruction, is in a defined reg.
1208 static bool isDbgValueInDefinedReg(const MachineInstr *MI) {
1209 assert (MI->isDebugValue() && "Invalid DBG_VALUE machine instruction!");
1210 return MI->getNumOperands() == 3 &&
1211 MI->getOperand(0).isReg() && MI->getOperand(0).getReg() &&
1212 MI->getOperand(1).isImm() && MI->getOperand(1).getImm() == 0;
1215 /// getDebugLocEntry - Get .debug_loc entry for the instruction range starting
1217 static DotDebugLocEntry getDebugLocEntry(AsmPrinter *Asm,
1218 const MCSymbol *FLabel,
1219 const MCSymbol *SLabel,
1220 const MachineInstr *MI) {
1221 const MDNode *Var = MI->getOperand(MI->getNumOperands() - 1).getMetadata();
1223 if (MI->getNumOperands() != 3) {
1224 MachineLocation MLoc = Asm->getDebugValueLocation(MI);
1225 return DotDebugLocEntry(FLabel, SLabel, MLoc, Var);
1227 if (MI->getOperand(0).isReg() && MI->getOperand(1).isImm()) {
1228 MachineLocation MLoc;
1229 MLoc.set(MI->getOperand(0).getReg(), MI->getOperand(1).getImm());
1230 return DotDebugLocEntry(FLabel, SLabel, MLoc, Var);
1232 if (MI->getOperand(0).isImm())
1233 return DotDebugLocEntry(FLabel, SLabel, MI->getOperand(0).getImm());
1234 if (MI->getOperand(0).isFPImm())
1235 return DotDebugLocEntry(FLabel, SLabel, MI->getOperand(0).getFPImm());
1236 if (MI->getOperand(0).isCImm())
1237 return DotDebugLocEntry(FLabel, SLabel, MI->getOperand(0).getCImm());
1239 assert (0 && "Unexpected 3 operand DBG_VALUE instruction!");
1240 return DotDebugLocEntry();
1243 /// collectVariableInfo - Find variables for each lexical scope.
1245 DwarfDebug::collectVariableInfo(const MachineFunction *MF,
1246 SmallPtrSet<const MDNode *, 16> &Processed) {
1248 /// collection info from MMI table.
1249 collectVariableInfoFromMMITable(MF, Processed);
1251 for (SmallVectorImpl<const MDNode*>::const_iterator
1252 UVI = UserVariables.begin(), UVE = UserVariables.end(); UVI != UVE;
1254 const MDNode *Var = *UVI;
1255 if (Processed.count(Var))
1258 // History contains relevant DBG_VALUE instructions for Var and instructions
1260 SmallVectorImpl<const MachineInstr*> &History = DbgValues[Var];
1261 if (History.empty())
1263 const MachineInstr *MInsn = History.front();
1266 LexicalScope *Scope = NULL;
1267 if (DV.getTag() == dwarf::DW_TAG_arg_variable &&
1268 DISubprogram(DV.getContext()).describes(MF->getFunction()))
1269 Scope = LScopes.getCurrentFunctionScope();
1271 if (DV.getVersion() <= LLVMDebugVersion9)
1272 Scope = LScopes.findLexicalScope(MInsn->getDebugLoc());
1274 if (MDNode *IA = DV.getInlinedAt())
1275 Scope = LScopes.findInlinedScope(DebugLoc::getFromDILocation(IA));
1277 Scope = LScopes.findLexicalScope(cast<MDNode>(DV->getOperand(1)));
1280 // If variable scope is not found then skip this variable.
1284 Processed.insert(DV);
1285 assert(MInsn->isDebugValue() && "History must begin with debug value");
1286 DbgVariable *RegVar = new DbgVariable(DV);
1287 if (!addCurrentFnArgument(MF, RegVar, Scope))
1288 addScopeVariable(Scope, RegVar);
1289 if (DbgVariable *AbsVar = findAbstractVariable(DV, MInsn->getDebugLoc())) {
1290 DbgVariableToDbgInstMap[AbsVar] = MInsn;
1291 VarToAbstractVarMap[RegVar] = AbsVar;
1294 // Simple ranges that are fully coalesced.
1295 if (History.size() <= 1 || (History.size() == 2 &&
1296 MInsn->isIdenticalTo(History.back()))) {
1297 DbgVariableToDbgInstMap[RegVar] = MInsn;
1301 // handle multiple DBG_VALUE instructions describing one variable.
1302 RegVar->setDotDebugLocOffset(DotDebugLocEntries.size());
1304 for (SmallVectorImpl<const MachineInstr*>::const_iterator
1305 HI = History.begin(), HE = History.end(); HI != HE; ++HI) {
1306 const MachineInstr *Begin = *HI;
1307 assert(Begin->isDebugValue() && "Invalid History entry");
1309 // Check if DBG_VALUE is truncating a range.
1310 if (Begin->getNumOperands() > 1 && Begin->getOperand(0).isReg()
1311 && !Begin->getOperand(0).getReg())
1314 // Compute the range for a register location.
1315 const MCSymbol *FLabel = getLabelBeforeInsn(Begin);
1316 const MCSymbol *SLabel = 0;
1319 // If Begin is the last instruction in History then its value is valid
1320 // until the end of the function.
1321 SLabel = FunctionEndSym;
1323 const MachineInstr *End = HI[1];
1324 DEBUG(dbgs() << "DotDebugLoc Pair:\n"
1325 << "\t" << *Begin << "\t" << *End << "\n");
1326 if (End->isDebugValue())
1327 SLabel = getLabelBeforeInsn(End);
1329 // End is a normal instruction clobbering the range.
1330 SLabel = getLabelAfterInsn(End);
1331 assert(SLabel && "Forgot label after clobber instruction");
1336 // The value is valid until the next DBG_VALUE or clobber.
1337 DotDebugLocEntries.push_back(getDebugLocEntry(Asm, FLabel, SLabel, Begin));
1339 DotDebugLocEntries.push_back(DotDebugLocEntry());
1342 // Collect info for variables that were optimized out.
1343 const Function *F = MF->getFunction();
1344 if (NamedMDNode *NMD = getFnSpecificMDNode(*(F->getParent()), F->getName())) {
1345 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
1346 DIVariable DV(cast<MDNode>(NMD->getOperand(i)));
1347 if (!DV || !Processed.insert(DV))
1349 if (LexicalScope *Scope = LScopes.findLexicalScope(DV.getContext()))
1350 addScopeVariable(Scope, new DbgVariable(DV));
1355 /// getLabelBeforeInsn - Return Label preceding the instruction.
1356 const MCSymbol *DwarfDebug::getLabelBeforeInsn(const MachineInstr *MI) {
1357 MCSymbol *Label = LabelsBeforeInsn.lookup(MI);
1358 assert(Label && "Didn't insert label before instruction");
1362 /// getLabelAfterInsn - Return Label immediately following the instruction.
1363 const MCSymbol *DwarfDebug::getLabelAfterInsn(const MachineInstr *MI) {
1364 return LabelsAfterInsn.lookup(MI);
1367 /// beginInstruction - Process beginning of an instruction.
1368 void DwarfDebug::beginInstruction(const MachineInstr *MI) {
1369 // Check if source location changes, but ignore DBG_VALUE locations.
1370 if (!MI->isDebugValue()) {
1371 DebugLoc DL = MI->getDebugLoc();
1372 if (DL != PrevInstLoc && (!DL.isUnknown() || UnknownLocations)) {
1373 unsigned Flags = DWARF2_FLAG_IS_STMT;
1375 if (DL == PrologEndLoc) {
1376 Flags |= DWARF2_FLAG_PROLOGUE_END;
1377 PrologEndLoc = DebugLoc();
1379 if (!DL.isUnknown()) {
1380 const MDNode *Scope = DL.getScope(Asm->MF->getFunction()->getContext());
1381 recordSourceLine(DL.getLine(), DL.getCol(), Scope, Flags);
1383 recordSourceLine(0, 0, 0, 0);
1387 // Insert labels where requested.
1388 DenseMap<const MachineInstr*, MCSymbol*>::iterator I =
1389 LabelsBeforeInsn.find(MI);
1392 if (I == LabelsBeforeInsn.end())
1395 // Label already assigned.
1400 PrevLabel = MMI->getContext().CreateTempSymbol();
1401 Asm->OutStreamer.EmitLabel(PrevLabel);
1403 I->second = PrevLabel;
1406 /// endInstruction - Process end of an instruction.
1407 void DwarfDebug::endInstruction(const MachineInstr *MI) {
1408 // Don't create a new label after DBG_VALUE instructions.
1409 // They don't generate code.
1410 if (!MI->isDebugValue())
1413 DenseMap<const MachineInstr*, MCSymbol*>::iterator I =
1414 LabelsAfterInsn.find(MI);
1417 if (I == LabelsAfterInsn.end())
1420 // Label already assigned.
1424 // We need a label after this instruction.
1426 PrevLabel = MMI->getContext().CreateTempSymbol();
1427 Asm->OutStreamer.EmitLabel(PrevLabel);
1429 I->second = PrevLabel;
1432 /// identifyScopeMarkers() -
1433 /// Each LexicalScope has first instruction and last instruction to mark beginning
1434 /// and end of a scope respectively. Create an inverse map that list scopes
1435 /// starts (and ends) with an instruction. One instruction may start (or end)
1436 /// multiple scopes. Ignore scopes that are not reachable.
1437 void DwarfDebug::identifyScopeMarkers() {
1438 SmallVector<LexicalScope *, 4> WorkList;
1439 WorkList.push_back(LScopes.getCurrentFunctionScope());
1440 while (!WorkList.empty()) {
1441 LexicalScope *S = WorkList.pop_back_val();
1443 const SmallVector<LexicalScope *, 4> &Children = S->getChildren();
1444 if (!Children.empty())
1445 for (SmallVector<LexicalScope *, 4>::const_iterator SI = Children.begin(),
1446 SE = Children.end(); SI != SE; ++SI)
1447 WorkList.push_back(*SI);
1449 if (S->isAbstractScope())
1452 const SmallVector<InsnRange, 4> &Ranges = S->getRanges();
1455 for (SmallVector<InsnRange, 4>::const_iterator RI = Ranges.begin(),
1456 RE = Ranges.end(); RI != RE; ++RI) {
1457 assert(RI->first && "InsnRange does not have first instruction!");
1458 assert(RI->second && "InsnRange does not have second instruction!");
1459 requestLabelBeforeInsn(RI->first);
1460 requestLabelAfterInsn(RI->second);
1465 /// getScopeNode - Get MDNode for DebugLoc's scope.
1466 static MDNode *getScopeNode(DebugLoc DL, const LLVMContext &Ctx) {
1467 if (MDNode *InlinedAt = DL.getInlinedAt(Ctx))
1468 return getScopeNode(DebugLoc::getFromDILocation(InlinedAt), Ctx);
1469 return DL.getScope(Ctx);
1472 /// getFnDebugLoc - Walk up the scope chain of given debug loc and find
1473 /// line number info for the function.
1474 static DebugLoc getFnDebugLoc(DebugLoc DL, const LLVMContext &Ctx) {
1475 const MDNode *Scope = getScopeNode(DL, Ctx);
1476 DISubprogram SP = getDISubprogram(Scope);
1478 return DebugLoc::get(SP.getLineNumber(), 0, SP);
1482 /// beginFunction - Gather pre-function debug information. Assumes being
1483 /// emitted immediately after the function entry point.
1484 void DwarfDebug::beginFunction(const MachineFunction *MF) {
1485 if (!MMI->hasDebugInfo()) return;
1486 LScopes.initialize(*MF);
1487 if (LScopes.empty()) return;
1488 identifyScopeMarkers();
1490 FunctionBeginSym = Asm->GetTempSymbol("func_begin",
1491 Asm->getFunctionNumber());
1492 // Assumes in correct section after the entry point.
1493 Asm->OutStreamer.EmitLabel(FunctionBeginSym);
1495 assert(UserVariables.empty() && DbgValues.empty() && "Maps weren't cleaned");
1497 const TargetRegisterInfo *TRI = Asm->TM.getRegisterInfo();
1498 /// LiveUserVar - Map physreg numbers to the MDNode they contain.
1499 std::vector<const MDNode*> LiveUserVar(TRI->getNumRegs());
1501 for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
1503 bool AtBlockEntry = true;
1504 for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
1506 const MachineInstr *MI = II;
1508 if (MI->isDebugValue()) {
1509 assert (MI->getNumOperands() > 1 && "Invalid machine instruction!");
1511 // Keep track of user variables.
1513 MI->getOperand(MI->getNumOperands() - 1).getMetadata();
1515 // Variable is in a register, we need to check for clobbers.
1516 if (isDbgValueInDefinedReg(MI))
1517 LiveUserVar[MI->getOperand(0).getReg()] = Var;
1519 // Check the history of this variable.
1520 SmallVectorImpl<const MachineInstr*> &History = DbgValues[Var];
1521 if (History.empty()) {
1522 UserVariables.push_back(Var);
1523 // The first mention of a function argument gets the FunctionBeginSym
1524 // label, so arguments are visible when breaking at function entry.
1526 if (DV.Verify() && DV.getTag() == dwarf::DW_TAG_arg_variable &&
1527 DISubprogram(getDISubprogram(DV.getContext()))
1528 .describes(MF->getFunction()))
1529 LabelsBeforeInsn[MI] = FunctionBeginSym;
1531 // We have seen this variable before. Try to coalesce DBG_VALUEs.
1532 const MachineInstr *Prev = History.back();
1533 if (Prev->isDebugValue()) {
1534 // Coalesce identical entries at the end of History.
1535 if (History.size() >= 2 &&
1536 Prev->isIdenticalTo(History[History.size() - 2])) {
1537 DEBUG(dbgs() << "Coalesce identical DBG_VALUE entries:\n"
1539 << "\t" << *History[History.size() - 2] << "\n");
1543 // Terminate old register assignments that don't reach MI;
1544 MachineFunction::const_iterator PrevMBB = Prev->getParent();
1545 if (PrevMBB != I && (!AtBlockEntry || llvm::next(PrevMBB) != I) &&
1546 isDbgValueInDefinedReg(Prev)) {
1547 // Previous register assignment needs to terminate at the end of
1549 MachineBasicBlock::const_iterator LastMI =
1550 PrevMBB->getLastNonDebugInstr();
1551 if (LastMI == PrevMBB->end()) {
1552 // Drop DBG_VALUE for empty range.
1553 DEBUG(dbgs() << "Drop DBG_VALUE for empty range:\n"
1554 << "\t" << *Prev << "\n");
1558 // Terminate after LastMI.
1559 History.push_back(LastMI);
1564 History.push_back(MI);
1566 // Not a DBG_VALUE instruction.
1568 AtBlockEntry = false;
1570 // First known non DBG_VALUE location marks beginning of function
1572 if (PrologEndLoc.isUnknown() && !MI->getDebugLoc().isUnknown())
1573 PrologEndLoc = MI->getDebugLoc();
1575 // Check if the instruction clobbers any registers with debug vars.
1576 for (MachineInstr::const_mop_iterator MOI = MI->operands_begin(),
1577 MOE = MI->operands_end(); MOI != MOE; ++MOI) {
1578 if (!MOI->isReg() || !MOI->isDef() || !MOI->getReg())
1580 for (const unsigned *AI = TRI->getOverlaps(MOI->getReg());
1581 unsigned Reg = *AI; ++AI) {
1582 const MDNode *Var = LiveUserVar[Reg];
1585 // Reg is now clobbered.
1586 LiveUserVar[Reg] = 0;
1588 // Was MD last defined by a DBG_VALUE referring to Reg?
1589 DbgValueHistoryMap::iterator HistI = DbgValues.find(Var);
1590 if (HistI == DbgValues.end())
1592 SmallVectorImpl<const MachineInstr*> &History = HistI->second;
1593 if (History.empty())
1595 const MachineInstr *Prev = History.back();
1596 // Sanity-check: Register assignments are terminated at the end of
1598 if (!Prev->isDebugValue() || Prev->getParent() != MI->getParent())
1600 // Is the variable still in Reg?
1601 if (!isDbgValueInDefinedReg(Prev) ||
1602 Prev->getOperand(0).getReg() != Reg)
1604 // Var is clobbered. Make sure the next instruction gets a label.
1605 History.push_back(MI);
1612 for (DbgValueHistoryMap::iterator I = DbgValues.begin(), E = DbgValues.end();
1614 SmallVectorImpl<const MachineInstr*> &History = I->second;
1615 if (History.empty())
1618 // Make sure the final register assignments are terminated.
1619 const MachineInstr *Prev = History.back();
1620 if (Prev->isDebugValue() && isDbgValueInDefinedReg(Prev)) {
1621 const MachineBasicBlock *PrevMBB = Prev->getParent();
1622 MachineBasicBlock::const_iterator LastMI = PrevMBB->getLastNonDebugInstr();
1623 if (LastMI == PrevMBB->end())
1624 // Drop DBG_VALUE for empty range.
1627 // Terminate after LastMI.
1628 History.push_back(LastMI);
1631 // Request labels for the full history.
1632 for (unsigned i = 0, e = History.size(); i != e; ++i) {
1633 const MachineInstr *MI = History[i];
1634 if (MI->isDebugValue())
1635 requestLabelBeforeInsn(MI);
1637 requestLabelAfterInsn(MI);
1641 PrevInstLoc = DebugLoc();
1642 PrevLabel = FunctionBeginSym;
1644 // Record beginning of function.
1645 if (!PrologEndLoc.isUnknown()) {
1646 DebugLoc FnStartDL = getFnDebugLoc(PrologEndLoc,
1647 MF->getFunction()->getContext());
1648 recordSourceLine(FnStartDL.getLine(), FnStartDL.getCol(),
1649 FnStartDL.getScope(MF->getFunction()->getContext()),
1650 DWARF2_FLAG_IS_STMT);
1654 void DwarfDebug::addScopeVariable(LexicalScope *LS, DbgVariable *Var) {
1655 // SmallVector<DbgVariable *, 8> &Vars = ScopeVariables.lookup(LS);
1656 ScopeVariables[LS].push_back(Var);
1657 // Vars.push_back(Var);
1660 /// endFunction - Gather and emit post-function debug information.
1662 void DwarfDebug::endFunction(const MachineFunction *MF) {
1663 if (!MMI->hasDebugInfo() || LScopes.empty()) return;
1665 // Define end label for subprogram.
1666 FunctionEndSym = Asm->GetTempSymbol("func_end",
1667 Asm->getFunctionNumber());
1668 // Assumes in correct section after the entry point.
1669 Asm->OutStreamer.EmitLabel(FunctionEndSym);
1671 SmallPtrSet<const MDNode *, 16> ProcessedVars;
1672 collectVariableInfo(MF, ProcessedVars);
1674 // Construct abstract scopes.
1675 SmallVector<LexicalScope *, 4> &AList = LScopes.getAbstractScopesList();
1676 for (SmallVector<LexicalScope *, 4>::iterator AI = AList.begin(),
1677 AE = AList.end(); AI != AE; ++AI) {
1678 DISubprogram SP((*AI)->getScopeNode());
1680 // Collect info for variables that were optimized out.
1681 StringRef FName = SP.getLinkageName();
1683 FName = SP.getName();
1684 if (NamedMDNode *NMD =
1685 getFnSpecificMDNode(*(MF->getFunction()->getParent()), FName)) {
1686 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
1687 DIVariable DV(cast<MDNode>(NMD->getOperand(i)));
1688 if (!DV || !ProcessedVars.insert(DV))
1690 if (LexicalScope *Scope = LScopes.findAbstractScope(DV.getContext()))
1691 addScopeVariable(Scope, new DbgVariable(DV));
1695 if (ProcessedSPNodes.count((*AI)->getScopeNode()) == 0)
1696 constructScopeDIE(*AI);
1699 DIE *CurFnDIE = constructScopeDIE(LScopes.getCurrentFunctionScope());
1701 if (!DisableFramePointerElim(*MF)) {
1702 LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
1703 getCompileUnit(FnScope->getScopeNode())->addUInt(CurFnDIE,
1704 dwarf::DW_AT_APPLE_omit_frame_ptr,
1705 dwarf::DW_FORM_flag, 1);
1707 DebugFrames.push_back(FunctionDebugFrameInfo(Asm->getFunctionNumber(),
1708 MMI->getFrameMoves()));
1711 for (DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8> >::iterator
1712 I = ScopeVariables.begin(), E = ScopeVariables.end(); I != E; ++I)
1713 DeleteContainerPointers(I->second);
1714 ScopeVariables.clear();
1715 DeleteContainerPointers(CurrentFnArguments);
1716 DbgVariableToFrameIndexMap.clear();
1717 VarToAbstractVarMap.clear();
1718 DbgVariableToDbgInstMap.clear();
1719 UserVariables.clear();
1721 AbstractVariables.clear();
1722 LabelsBeforeInsn.clear();
1723 LabelsAfterInsn.clear();
1727 /// recordVariableFrameIndex - Record a variable's index.
1728 void DwarfDebug::recordVariableFrameIndex(const DbgVariable *V, int Index) {
1729 assert (V && "Invalid DbgVariable!");
1730 DbgVariableToFrameIndexMap[V] = Index;
1733 /// findVariableFrameIndex - Return true if frame index for the variable
1734 /// is found. Update FI to hold value of the index.
1735 bool DwarfDebug::findVariableFrameIndex(const DbgVariable *V, int *FI) {
1736 assert (V && "Invalid DbgVariable!");
1737 DenseMap<const DbgVariable *, int>::iterator I =
1738 DbgVariableToFrameIndexMap.find(V);
1739 if (I == DbgVariableToFrameIndexMap.end())
1745 /// recordSourceLine - Register a source line with debug info. Returns the
1746 /// unique label that was emitted and which provides correspondence to
1747 /// the source line list.
1748 void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S,
1754 DIDescriptor Scope(S);
1756 if (Scope.isCompileUnit()) {
1757 DICompileUnit CU(S);
1758 Fn = CU.getFilename();
1759 Dir = CU.getDirectory();
1760 } else if (Scope.isFile()) {
1762 Fn = F.getFilename();
1763 Dir = F.getDirectory();
1764 } else if (Scope.isSubprogram()) {
1766 Fn = SP.getFilename();
1767 Dir = SP.getDirectory();
1768 } else if (Scope.isLexicalBlock()) {
1769 DILexicalBlock DB(S);
1770 Fn = DB.getFilename();
1771 Dir = DB.getDirectory();
1773 assert(0 && "Unexpected scope info");
1775 Src = GetOrCreateSourceID(Fn, Dir);
1777 Asm->OutStreamer.EmitDwarfLocDirective(Src, Line, Col, Flags, 0, 0, Fn);
1780 //===----------------------------------------------------------------------===//
1782 //===----------------------------------------------------------------------===//
1784 /// computeSizeAndOffset - Compute the size and offset of a DIE.
1787 DwarfDebug::computeSizeAndOffset(DIE *Die, unsigned Offset, bool Last) {
1788 // Get the children.
1789 const std::vector<DIE *> &Children = Die->getChildren();
1791 // If not last sibling and has children then add sibling offset attribute.
1792 if (!Last && !Children.empty())
1793 Die->addSiblingOffset(DIEValueAllocator);
1795 // Record the abbreviation.
1796 assignAbbrevNumber(Die->getAbbrev());
1798 // Get the abbreviation for this DIE.
1799 unsigned AbbrevNumber = Die->getAbbrevNumber();
1800 const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
1803 Die->setOffset(Offset);
1805 // Start the size with the size of abbreviation code.
1806 Offset += MCAsmInfo::getULEB128Size(AbbrevNumber);
1808 const SmallVector<DIEValue*, 32> &Values = Die->getValues();
1809 const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData();
1811 // Size the DIE attribute values.
1812 for (unsigned i = 0, N = Values.size(); i < N; ++i)
1813 // Size attribute value.
1814 Offset += Values[i]->SizeOf(Asm, AbbrevData[i].getForm());
1816 // Size the DIE children if any.
1817 if (!Children.empty()) {
1818 assert(Abbrev->getChildrenFlag() == dwarf::DW_CHILDREN_yes &&
1819 "Children flag not set");
1821 for (unsigned j = 0, M = Children.size(); j < M; ++j)
1822 Offset = computeSizeAndOffset(Children[j], Offset, (j + 1) == M);
1824 // End of children marker.
1825 Offset += sizeof(int8_t);
1828 Die->setSize(Offset - Die->getOffset());
1832 /// computeSizeAndOffsets - Compute the size and offset of all the DIEs.
1834 void DwarfDebug::computeSizeAndOffsets() {
1835 for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
1836 E = CUMap.end(); I != E; ++I) {
1837 // Compute size of compile unit header.
1839 sizeof(int32_t) + // Length of Compilation Unit Info
1840 sizeof(int16_t) + // DWARF version number
1841 sizeof(int32_t) + // Offset Into Abbrev. Section
1842 sizeof(int8_t); // Pointer Size (in bytes)
1843 computeSizeAndOffset(I->second->getCUDie(), Offset, true);
1847 /// EmitSectionSym - Switch to the specified MCSection and emit an assembler
1848 /// temporary label to it if SymbolStem is specified.
1849 static MCSymbol *EmitSectionSym(AsmPrinter *Asm, const MCSection *Section,
1850 const char *SymbolStem = 0) {
1851 Asm->OutStreamer.SwitchSection(Section);
1852 if (!SymbolStem) return 0;
1854 MCSymbol *TmpSym = Asm->GetTempSymbol(SymbolStem);
1855 Asm->OutStreamer.EmitLabel(TmpSym);
1859 /// EmitSectionLabels - Emit initial Dwarf sections with a label at
1860 /// the start of each one.
1861 void DwarfDebug::EmitSectionLabels() {
1862 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
1864 // Dwarf sections base addresses.
1865 DwarfInfoSectionSym =
1866 EmitSectionSym(Asm, TLOF.getDwarfInfoSection(), "section_info");
1867 DwarfAbbrevSectionSym =
1868 EmitSectionSym(Asm, TLOF.getDwarfAbbrevSection(), "section_abbrev");
1869 EmitSectionSym(Asm, TLOF.getDwarfARangesSection());
1871 if (const MCSection *MacroInfo = TLOF.getDwarfMacroInfoSection())
1872 EmitSectionSym(Asm, MacroInfo);
1874 EmitSectionSym(Asm, TLOF.getDwarfLineSection(), "section_line");
1875 EmitSectionSym(Asm, TLOF.getDwarfLocSection());
1876 EmitSectionSym(Asm, TLOF.getDwarfPubNamesSection());
1877 EmitSectionSym(Asm, TLOF.getDwarfPubTypesSection());
1878 DwarfStrSectionSym =
1879 EmitSectionSym(Asm, TLOF.getDwarfStrSection(), "section_str");
1880 DwarfDebugRangeSectionSym = EmitSectionSym(Asm, TLOF.getDwarfRangesSection(),
1883 DwarfDebugLocSectionSym = EmitSectionSym(Asm, TLOF.getDwarfLocSection(),
1884 "section_debug_loc");
1886 TextSectionSym = EmitSectionSym(Asm, TLOF.getTextSection(), "text_begin");
1887 EmitSectionSym(Asm, TLOF.getDataSection());
1890 /// emitDIE - Recursively emits a debug information entry.
1892 void DwarfDebug::emitDIE(DIE *Die) {
1893 // Get the abbreviation for this DIE.
1894 unsigned AbbrevNumber = Die->getAbbrevNumber();
1895 const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
1897 // Emit the code (index) for the abbreviation.
1898 if (Asm->isVerbose())
1899 Asm->OutStreamer.AddComment("Abbrev [" + Twine(AbbrevNumber) + "] 0x" +
1900 Twine::utohexstr(Die->getOffset()) + ":0x" +
1901 Twine::utohexstr(Die->getSize()) + " " +
1902 dwarf::TagString(Abbrev->getTag()));
1903 Asm->EmitULEB128(AbbrevNumber);
1905 const SmallVector<DIEValue*, 32> &Values = Die->getValues();
1906 const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData();
1908 // Emit the DIE attribute values.
1909 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
1910 unsigned Attr = AbbrevData[i].getAttribute();
1911 unsigned Form = AbbrevData[i].getForm();
1912 assert(Form && "Too many attributes for DIE (check abbreviation)");
1914 if (Asm->isVerbose())
1915 Asm->OutStreamer.AddComment(dwarf::AttributeString(Attr));
1918 case dwarf::DW_AT_sibling:
1919 Asm->EmitInt32(Die->getSiblingOffset());
1921 case dwarf::DW_AT_abstract_origin: {
1922 DIEEntry *E = cast<DIEEntry>(Values[i]);
1923 DIE *Origin = E->getEntry();
1924 unsigned Addr = Origin->getOffset();
1925 Asm->EmitInt32(Addr);
1928 case dwarf::DW_AT_ranges: {
1929 // DW_AT_range Value encodes offset in debug_range section.
1930 DIEInteger *V = cast<DIEInteger>(Values[i]);
1932 if (Asm->MAI->doesDwarfUsesLabelOffsetForRanges()) {
1933 Asm->EmitLabelPlusOffset(DwarfDebugRangeSectionSym,
1937 Asm->EmitLabelOffsetDifference(DwarfDebugRangeSectionSym,
1939 DwarfDebugRangeSectionSym,
1944 case dwarf::DW_AT_location: {
1945 if (UseDotDebugLocEntry.count(Die) != 0) {
1946 DIELabel *L = cast<DIELabel>(Values[i]);
1947 Asm->EmitLabelDifference(L->getValue(), DwarfDebugLocSectionSym, 4);
1949 Values[i]->EmitValue(Asm, Form);
1952 case dwarf::DW_AT_accessibility: {
1953 if (Asm->isVerbose()) {
1954 DIEInteger *V = cast<DIEInteger>(Values[i]);
1955 Asm->OutStreamer.AddComment(dwarf::AccessibilityString(V->getValue()));
1957 Values[i]->EmitValue(Asm, Form);
1961 // Emit an attribute using the defined form.
1962 Values[i]->EmitValue(Asm, Form);
1967 // Emit the DIE children if any.
1968 if (Abbrev->getChildrenFlag() == dwarf::DW_CHILDREN_yes) {
1969 const std::vector<DIE *> &Children = Die->getChildren();
1971 for (unsigned j = 0, M = Children.size(); j < M; ++j)
1972 emitDIE(Children[j]);
1974 if (Asm->isVerbose())
1975 Asm->OutStreamer.AddComment("End Of Children Mark");
1980 /// emitDebugInfo - Emit the debug info section.
1982 void DwarfDebug::emitDebugInfo() {
1983 // Start debug info section.
1984 Asm->OutStreamer.SwitchSection(
1985 Asm->getObjFileLowering().getDwarfInfoSection());
1986 for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
1987 E = CUMap.end(); I != E; ++I) {
1988 CompileUnit *TheCU = I->second;
1989 DIE *Die = TheCU->getCUDie();
1991 // Emit the compile units header.
1992 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("info_begin",
1995 // Emit size of content not including length itself
1996 unsigned ContentSize = Die->getSize() +
1997 sizeof(int16_t) + // DWARF version number
1998 sizeof(int32_t) + // Offset Into Abbrev. Section
1999 sizeof(int8_t); // Pointer Size (in bytes)
2001 Asm->OutStreamer.AddComment("Length of Compilation Unit Info");
2002 Asm->EmitInt32(ContentSize);
2003 Asm->OutStreamer.AddComment("DWARF version number");
2004 Asm->EmitInt16(dwarf::DWARF_VERSION);
2005 Asm->OutStreamer.AddComment("Offset Into Abbrev. Section");
2006 Asm->EmitSectionOffset(Asm->GetTempSymbol("abbrev_begin"),
2007 DwarfAbbrevSectionSym);
2008 Asm->OutStreamer.AddComment("Address Size (in bytes)");
2009 Asm->EmitInt8(Asm->getTargetData().getPointerSize());
2012 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("info_end", TheCU->getID()));
2016 /// emitAbbreviations - Emit the abbreviation section.
2018 void DwarfDebug::emitAbbreviations() const {
2019 // Check to see if it is worth the effort.
2020 if (!Abbreviations.empty()) {
2021 // Start the debug abbrev section.
2022 Asm->OutStreamer.SwitchSection(
2023 Asm->getObjFileLowering().getDwarfAbbrevSection());
2025 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("abbrev_begin"));
2027 // For each abbrevation.
2028 for (unsigned i = 0, N = Abbreviations.size(); i < N; ++i) {
2029 // Get abbreviation data
2030 const DIEAbbrev *Abbrev = Abbreviations[i];
2032 // Emit the abbrevations code (base 1 index.)
2033 Asm->EmitULEB128(Abbrev->getNumber(), "Abbreviation Code");
2035 // Emit the abbreviations data.
2039 // Mark end of abbreviations.
2040 Asm->EmitULEB128(0, "EOM(3)");
2042 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("abbrev_end"));
2046 /// emitEndOfLineMatrix - Emit the last address of the section and the end of
2047 /// the line matrix.
2049 void DwarfDebug::emitEndOfLineMatrix(unsigned SectionEnd) {
2050 // Define last address of section.
2051 Asm->OutStreamer.AddComment("Extended Op");
2054 Asm->OutStreamer.AddComment("Op size");
2055 Asm->EmitInt8(Asm->getTargetData().getPointerSize() + 1);
2056 Asm->OutStreamer.AddComment("DW_LNE_set_address");
2057 Asm->EmitInt8(dwarf::DW_LNE_set_address);
2059 Asm->OutStreamer.AddComment("Section end label");
2061 Asm->OutStreamer.EmitSymbolValue(Asm->GetTempSymbol("section_end",SectionEnd),
2062 Asm->getTargetData().getPointerSize(),
2065 // Mark end of matrix.
2066 Asm->OutStreamer.AddComment("DW_LNE_end_sequence");
2072 /// emitDebugPubNames - Emit visible names into a debug pubnames section.
2074 void DwarfDebug::emitDebugPubNames() {
2075 for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
2076 E = CUMap.end(); I != E; ++I) {
2077 CompileUnit *TheCU = I->second;
2078 // Start the dwarf pubnames section.
2079 Asm->OutStreamer.SwitchSection(
2080 Asm->getObjFileLowering().getDwarfPubNamesSection());
2082 Asm->OutStreamer.AddComment("Length of Public Names Info");
2083 Asm->EmitLabelDifference(
2084 Asm->GetTempSymbol("pubnames_end", TheCU->getID()),
2085 Asm->GetTempSymbol("pubnames_begin", TheCU->getID()), 4);
2087 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubnames_begin",
2090 Asm->OutStreamer.AddComment("DWARF Version");
2091 Asm->EmitInt16(dwarf::DWARF_VERSION);
2093 Asm->OutStreamer.AddComment("Offset of Compilation Unit Info");
2094 Asm->EmitSectionOffset(Asm->GetTempSymbol("info_begin", TheCU->getID()),
2095 DwarfInfoSectionSym);
2097 Asm->OutStreamer.AddComment("Compilation Unit Length");
2098 Asm->EmitLabelDifference(Asm->GetTempSymbol("info_end", TheCU->getID()),
2099 Asm->GetTempSymbol("info_begin", TheCU->getID()),
2102 const StringMap<DIE*> &Globals = TheCU->getGlobals();
2103 for (StringMap<DIE*>::const_iterator
2104 GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) {
2105 const char *Name = GI->getKeyData();
2106 DIE *Entity = GI->second;
2108 Asm->OutStreamer.AddComment("DIE offset");
2109 Asm->EmitInt32(Entity->getOffset());
2111 if (Asm->isVerbose())
2112 Asm->OutStreamer.AddComment("External Name");
2113 Asm->OutStreamer.EmitBytes(StringRef(Name, strlen(Name)+1), 0);
2116 Asm->OutStreamer.AddComment("End Mark");
2118 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubnames_end",
2123 void DwarfDebug::emitDebugPubTypes() {
2124 for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
2125 E = CUMap.end(); I != E; ++I) {
2126 CompileUnit *TheCU = I->second;
2127 // Start the dwarf pubnames section.
2128 Asm->OutStreamer.SwitchSection(
2129 Asm->getObjFileLowering().getDwarfPubTypesSection());
2130 Asm->OutStreamer.AddComment("Length of Public Types Info");
2131 Asm->EmitLabelDifference(
2132 Asm->GetTempSymbol("pubtypes_end", TheCU->getID()),
2133 Asm->GetTempSymbol("pubtypes_begin", TheCU->getID()), 4);
2135 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubtypes_begin",
2138 if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DWARF Version");
2139 Asm->EmitInt16(dwarf::DWARF_VERSION);
2141 Asm->OutStreamer.AddComment("Offset of Compilation Unit Info");
2142 Asm->EmitSectionOffset(Asm->GetTempSymbol("info_begin", TheCU->getID()),
2143 DwarfInfoSectionSym);
2145 Asm->OutStreamer.AddComment("Compilation Unit Length");
2146 Asm->EmitLabelDifference(Asm->GetTempSymbol("info_end", TheCU->getID()),
2147 Asm->GetTempSymbol("info_begin", TheCU->getID()),
2150 const StringMap<DIE*> &Globals = TheCU->getGlobalTypes();
2151 for (StringMap<DIE*>::const_iterator
2152 GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) {
2153 const char *Name = GI->getKeyData();
2154 DIE *Entity = GI->second;
2156 if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DIE offset");
2157 Asm->EmitInt32(Entity->getOffset());
2159 if (Asm->isVerbose()) Asm->OutStreamer.AddComment("External Name");
2160 Asm->OutStreamer.EmitBytes(StringRef(Name, GI->getKeyLength()+1), 0);
2163 Asm->OutStreamer.AddComment("End Mark");
2165 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubtypes_end",
2170 /// emitDebugStr - Emit visible names into a debug str section.
2172 void DwarfDebug::emitDebugStr() {
2173 // Check to see if it is worth the effort.
2174 if (StringPool.empty()) return;
2176 // Start the dwarf str section.
2177 Asm->OutStreamer.SwitchSection(
2178 Asm->getObjFileLowering().getDwarfStrSection());
2180 // Get all of the string pool entries and put them in an array by their ID so
2181 // we can sort them.
2182 SmallVector<std::pair<unsigned,
2183 StringMapEntry<std::pair<MCSymbol*, unsigned> >*>, 64> Entries;
2185 for (StringMap<std::pair<MCSymbol*, unsigned> >::iterator
2186 I = StringPool.begin(), E = StringPool.end(); I != E; ++I)
2187 Entries.push_back(std::make_pair(I->second.second, &*I));
2189 array_pod_sort(Entries.begin(), Entries.end());
2191 for (unsigned i = 0, e = Entries.size(); i != e; ++i) {
2192 // Emit a label for reference from debug information entries.
2193 Asm->OutStreamer.EmitLabel(Entries[i].second->getValue().first);
2195 // Emit the string itself.
2196 Asm->OutStreamer.EmitBytes(Entries[i].second->getKey(), 0/*addrspace*/);
2200 /// emitDebugLoc - Emit visible names into a debug loc section.
2202 void DwarfDebug::emitDebugLoc() {
2203 if (DotDebugLocEntries.empty())
2206 for (SmallVector<DotDebugLocEntry, 4>::iterator
2207 I = DotDebugLocEntries.begin(), E = DotDebugLocEntries.end();
2209 DotDebugLocEntry &Entry = *I;
2210 if (I + 1 != DotDebugLocEntries.end())
2214 // Start the dwarf loc section.
2215 Asm->OutStreamer.SwitchSection(
2216 Asm->getObjFileLowering().getDwarfLocSection());
2217 unsigned char Size = Asm->getTargetData().getPointerSize();
2218 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_loc", 0));
2220 for (SmallVector<DotDebugLocEntry, 4>::iterator
2221 I = DotDebugLocEntries.begin(), E = DotDebugLocEntries.end();
2222 I != E; ++I, ++index) {
2223 DotDebugLocEntry &Entry = *I;
2224 if (Entry.isMerged()) continue;
2225 if (Entry.isEmpty()) {
2226 Asm->OutStreamer.EmitIntValue(0, Size, /*addrspace*/0);
2227 Asm->OutStreamer.EmitIntValue(0, Size, /*addrspace*/0);
2228 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_loc", index));
2230 Asm->OutStreamer.EmitSymbolValue(Entry.Begin, Size, 0);
2231 Asm->OutStreamer.EmitSymbolValue(Entry.End, Size, 0);
2232 DIVariable DV(Entry.Variable);
2233 Asm->OutStreamer.AddComment("Loc expr size");
2234 MCSymbol *begin = Asm->OutStreamer.getContext().CreateTempSymbol();
2235 MCSymbol *end = Asm->OutStreamer.getContext().CreateTempSymbol();
2236 Asm->EmitLabelDifference(end, begin, 2);
2237 Asm->OutStreamer.EmitLabel(begin);
2238 if (Entry.isInt()) {
2239 DIBasicType BTy(DV.getType());
2241 (BTy.getEncoding() == dwarf::DW_ATE_signed
2242 || BTy.getEncoding() == dwarf::DW_ATE_signed_char)) {
2243 Asm->OutStreamer.AddComment("DW_OP_consts");
2244 Asm->EmitInt8(dwarf::DW_OP_consts);
2245 Asm->EmitSLEB128(Entry.getInt());
2247 Asm->OutStreamer.AddComment("DW_OP_constu");
2248 Asm->EmitInt8(dwarf::DW_OP_constu);
2249 Asm->EmitULEB128(Entry.getInt());
2251 } else if (Entry.isLocation()) {
2252 if (!DV.hasComplexAddress())
2254 Asm->EmitDwarfRegOp(Entry.Loc);
2256 // Complex address entry.
2257 unsigned N = DV.getNumAddrElements();
2259 if (N >= 2 && DV.getAddrElement(0) == DIBuilder::OpPlus) {
2260 if (Entry.Loc.getOffset()) {
2262 Asm->EmitDwarfRegOp(Entry.Loc);
2263 Asm->OutStreamer.AddComment("DW_OP_deref");
2264 Asm->EmitInt8(dwarf::DW_OP_deref);
2265 Asm->OutStreamer.AddComment("DW_OP_plus_uconst");
2266 Asm->EmitInt8(dwarf::DW_OP_plus_uconst);
2267 Asm->EmitSLEB128(DV.getAddrElement(1));
2269 // If first address element is OpPlus then emit
2270 // DW_OP_breg + Offset instead of DW_OP_reg + Offset.
2271 MachineLocation Loc(Entry.Loc.getReg(), DV.getAddrElement(1));
2272 Asm->EmitDwarfRegOp(Loc);
2276 Asm->EmitDwarfRegOp(Entry.Loc);
2279 // Emit remaining complex address elements.
2280 for (; i < N; ++i) {
2281 uint64_t Element = DV.getAddrElement(i);
2282 if (Element == DIBuilder::OpPlus) {
2283 Asm->EmitInt8(dwarf::DW_OP_plus_uconst);
2284 Asm->EmitULEB128(DV.getAddrElement(++i));
2285 } else if (Element == DIBuilder::OpDeref)
2286 Asm->EmitInt8(dwarf::DW_OP_deref);
2287 else llvm_unreachable("unknown Opcode found in complex address");
2291 // else ... ignore constant fp. There is not any good way to
2292 // to represent them here in dwarf.
2293 Asm->OutStreamer.EmitLabel(end);
2298 /// EmitDebugARanges - Emit visible names into a debug aranges section.
2300 void DwarfDebug::EmitDebugARanges() {
2301 // Start the dwarf aranges section.
2302 Asm->OutStreamer.SwitchSection(
2303 Asm->getObjFileLowering().getDwarfARangesSection());
2306 /// emitDebugRanges - Emit visible names into a debug ranges section.
2308 void DwarfDebug::emitDebugRanges() {
2309 // Start the dwarf ranges section.
2310 Asm->OutStreamer.SwitchSection(
2311 Asm->getObjFileLowering().getDwarfRangesSection());
2312 unsigned char Size = Asm->getTargetData().getPointerSize();
2313 for (SmallVector<const MCSymbol *, 8>::iterator
2314 I = DebugRangeSymbols.begin(), E = DebugRangeSymbols.end();
2317 Asm->OutStreamer.EmitSymbolValue(const_cast<MCSymbol*>(*I), Size, 0);
2319 Asm->OutStreamer.EmitIntValue(0, Size, /*addrspace*/0);
2323 /// emitDebugMacInfo - Emit visible names into a debug macinfo section.
2325 void DwarfDebug::emitDebugMacInfo() {
2326 if (const MCSection *LineInfo =
2327 Asm->getObjFileLowering().getDwarfMacroInfoSection()) {
2328 // Start the dwarf macinfo section.
2329 Asm->OutStreamer.SwitchSection(LineInfo);
2333 /// emitDebugInlineInfo - Emit inline info using following format.
2335 /// 1. length of section
2336 /// 2. Dwarf version number
2337 /// 3. address size.
2339 /// Entries (one "entry" for each function that was inlined):
2341 /// 1. offset into __debug_str section for MIPS linkage name, if exists;
2342 /// otherwise offset into __debug_str for regular function name.
2343 /// 2. offset into __debug_str section for regular function name.
2344 /// 3. an unsigned LEB128 number indicating the number of distinct inlining
2345 /// instances for the function.
2347 /// The rest of the entry consists of a {die_offset, low_pc} pair for each
2348 /// inlined instance; the die_offset points to the inlined_subroutine die in the
2349 /// __debug_info section, and the low_pc is the starting address for the
2350 /// inlining instance.
2351 void DwarfDebug::emitDebugInlineInfo() {
2352 if (!Asm->MAI->doesDwarfUsesInlineInfoSection())
2358 Asm->OutStreamer.SwitchSection(
2359 Asm->getObjFileLowering().getDwarfDebugInlineSection());
2361 Asm->OutStreamer.AddComment("Length of Debug Inlined Information Entry");
2362 Asm->EmitLabelDifference(Asm->GetTempSymbol("debug_inlined_end", 1),
2363 Asm->GetTempSymbol("debug_inlined_begin", 1), 4);
2365 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_inlined_begin", 1));
2367 Asm->OutStreamer.AddComment("Dwarf Version");
2368 Asm->EmitInt16(dwarf::DWARF_VERSION);
2369 Asm->OutStreamer.AddComment("Address Size (in bytes)");
2370 Asm->EmitInt8(Asm->getTargetData().getPointerSize());
2372 for (SmallVector<const MDNode *, 4>::iterator I = InlinedSPNodes.begin(),
2373 E = InlinedSPNodes.end(); I != E; ++I) {
2375 const MDNode *Node = *I;
2376 DenseMap<const MDNode *, SmallVector<InlineInfoLabels, 4> >::iterator II
2377 = InlineInfo.find(Node);
2378 SmallVector<InlineInfoLabels, 4> &Labels = II->second;
2379 DISubprogram SP(Node);
2380 StringRef LName = SP.getLinkageName();
2381 StringRef Name = SP.getName();
2383 Asm->OutStreamer.AddComment("MIPS linkage name");
2384 if (LName.empty()) {
2385 Asm->OutStreamer.EmitBytes(Name, 0);
2386 Asm->OutStreamer.EmitIntValue(0, 1, 0); // nul terminator.
2388 Asm->EmitSectionOffset(getStringPoolEntry(getRealLinkageName(LName)),
2389 DwarfStrSectionSym);
2391 Asm->OutStreamer.AddComment("Function name");
2392 Asm->EmitSectionOffset(getStringPoolEntry(Name), DwarfStrSectionSym);
2393 Asm->EmitULEB128(Labels.size(), "Inline count");
2395 for (SmallVector<InlineInfoLabels, 4>::iterator LI = Labels.begin(),
2396 LE = Labels.end(); LI != LE; ++LI) {
2397 if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DIE offset");
2398 Asm->EmitInt32(LI->second->getOffset());
2400 if (Asm->isVerbose()) Asm->OutStreamer.AddComment("low_pc");
2401 Asm->OutStreamer.EmitSymbolValue(LI->first,
2402 Asm->getTargetData().getPointerSize(),0);
2406 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_inlined_end", 1));