LLVM 23.0.0git
DwarfCompileUnit.cpp
Go to the documentation of this file.
1//===- llvm/CodeGen/DwarfCompileUnit.cpp - Dwarf Compile Units ------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains support for constructing a dwarf compile unit.
10//
11//===----------------------------------------------------------------------===//
12
13#include "DwarfCompileUnit.h"
14#include "AddressPool.h"
15#include "DwarfExpression.h"
16#include "llvm/ADT/STLExtras.h"
20#include "llvm/CodeGen/DIE.h"
26#include "llvm/IR/DataLayout.h"
27#include "llvm/IR/DebugInfo.h"
29#include "llvm/MC/MCAsmInfo.h"
30#include "llvm/MC/MCSection.h"
31#include "llvm/MC/MCStreamer.h"
32#include "llvm/MC/MCSymbol.h"
39#include <optional>
40#include <string>
41#include <utility>
42
43using namespace llvm;
44
45/// Query value using AddLinkageNamesToDeclCallOriginsForTuning.
47 "add-linkage-names-to-declaration-call-origins", cl::Hidden,
48 cl::desc("Add DW_AT_linkage_name to function declaration DIEs "
49 "referenced by DW_AT_call_origin attributes. Enabled by default "
50 "for -gsce debugger tuning."));
51
53 "emit-func-debug-line-table-offsets", cl::Hidden,
54 cl::desc("Include line table offset in function's debug info and emit end "
55 "sequence after each function's line data."),
56 cl::init(false));
57
59 bool EnabledByDefault = DD->tuneForSCE();
60 if (EnabledByDefault)
63}
64
66
67 // According to DWARF Debugging Information Format Version 5,
68 // 3.1.2 Skeleton Compilation Unit Entries:
69 // "When generating a split DWARF object file (see Section 7.3.2
70 // on page 187), the compilation unit in the .debug_info section
71 // is a "skeleton" compilation unit with the tag DW_TAG_skeleton_unit"
72 if (DW->getDwarfVersion() >= 5 && Kind == UnitKind::Skeleton)
73 return dwarf::DW_TAG_skeleton_unit;
74
75 return dwarf::DW_TAG_compile_unit;
76}
77
80 DwarfFile *DWU, UnitKind Kind)
81 : DwarfUnit(GetCompileUnitType(Kind, DW), Node, A, DW, DWU, UID) {
83 MacroLabelBegin = Asm->createTempSymbol("cu_macro_begin");
84}
85
86/// addLabelAddress - Add a dwarf label attribute data and value using
87/// DW_FORM_addr or DW_FORM_GNU_addr_index.
89 const MCSymbol *Label) {
90 if ((Skeleton || !DD->useSplitDwarf()) && Label)
91 DD->addArangeLabel(SymbolCU(this, Label));
92
93 // Don't use the address pool in non-fission or in the skeleton unit itself.
94 if ((!DD->useSplitDwarf() || !Skeleton) && DD->getDwarfVersion() < 5)
95 return addLocalLabelAddress(Die, Attribute, Label);
96
97 bool UseAddrOffsetFormOrExpressions =
98 DD->useAddrOffsetForm() || DD->useAddrOffsetExpressions();
99
100 const MCSymbol *Base = nullptr;
101 if (Label->isInSection() && UseAddrOffsetFormOrExpressions)
102 Base = DD->getSectionLabel(&Label->getSection());
103
104 if (!Base || Base == Label) {
105 unsigned idx = DD->getAddressPool().getIndex(Label);
107 DD->getDwarfVersion() >= 5 ? dwarf::DW_FORM_addrx
108 : dwarf::DW_FORM_GNU_addr_index,
109 DIEInteger(idx));
110 return;
111 }
112
113 // Could be extended to work with DWARFv4 Split DWARF if that's important for
114 // someone. In that case DW_FORM_data would be used.
115 assert(DD->getDwarfVersion() >= 5 &&
116 "Addr+offset expressions are only valuable when using debug_addr (to "
117 "reduce relocations) available in DWARFv5 or higher");
118 if (DD->useAddrOffsetExpressions()) {
119 auto *Loc = new (DIEValueAllocator) DIEBlock();
120 addPoolOpAddress(*Loc, Label);
121 addBlock(Die, Attribute, dwarf::DW_FORM_exprloc, Loc);
122 } else
123 addAttribute(Die, Attribute, dwarf::DW_FORM_LLVM_addrx_offset,
125 DD->getAddressPool().getIndex(Base), Label, Base));
126}
127
130 const MCSymbol *Label) {
131 if (Label)
132 addAttribute(Die, Attribute, dwarf::DW_FORM_addr, DIELabel(Label));
133 else
134 addAttribute(Die, Attribute, dwarf::DW_FORM_addr, DIEInteger(0));
135}
136
138 // If we print assembly, we can't separate .file entries according to
139 // compile units. Thus all files will belong to the default compile unit.
140
141 // FIXME: add a better feature test than hasRawTextSupport. Even better,
142 // extend .file to support this.
143 unsigned CUID = Asm->OutStreamer->hasRawTextSupport() ? 0 : getUniqueID();
144 if (!File)
145 return Asm->OutStreamer->emitDwarfFileDirective(0, "", "", std::nullopt,
146 std::nullopt, CUID);
147
148 if (LastFile != File) {
149 LastFile = File;
150 LastFileID = Asm->OutStreamer->emitDwarfFileDirective(
151 0, File->getDirectory(), File->getFilename(), DD->getMD5AsBytes(File),
152 File->getSource(), CUID);
153 }
154 return LastFileID;
155}
156
158 const DIGlobalVariable *GV, ArrayRef<GlobalExpr> GlobalExprs) {
159 // Check for pre-existence.
160 if (DIE *Die = getDIE(GV))
161 return Die;
162
163 assert(GV);
164
165 auto *GVContext = GV->getScope();
166 const DIType *GTy = GV->getType();
167
168 auto *CB = GVContext ? dyn_cast<DICommonBlock>(GVContext) : nullptr;
169 DIE *ContextDIE = CB ? getOrCreateCommonBlock(CB, GlobalExprs)
170 : getOrCreateContextDIE(GVContext);
171
172 // Add to map.
173 DIE *VariableDIE = &createAndAddDIE(GV->getTag(), *ContextDIE, GV);
175 if (auto *SDMDecl = GV->getStaticDataMemberDeclaration()) {
176 DeclContext = SDMDecl->getScope();
177 assert(SDMDecl->isStaticMember() && "Expected static member decl");
178 assert(GV->isDefinition());
179 // We need the declaration DIE that is in the static member's class.
180 DIE *VariableSpecDIE = getOrCreateStaticMemberDIE(SDMDecl);
181 addDIEEntry(*VariableDIE, dwarf::DW_AT_specification, *VariableSpecDIE);
182 // If the global variable's type is different from the one in the class
183 // member type, assume that it's more specific and also emit it.
184 if (GTy != SDMDecl->getBaseType())
185 addType(*VariableDIE, GTy);
186 } else {
187 DeclContext = GV->getScope();
188 // Add name and type.
189 StringRef DisplayName = GV->getDisplayName();
190 if (!DisplayName.empty())
191 addString(*VariableDIE, dwarf::DW_AT_name, GV->getDisplayName());
192 if (GTy)
193 addType(*VariableDIE, GTy);
194
195 // Add scoping info.
196 if (!GV->isLocalToUnit())
197 addFlag(*VariableDIE, dwarf::DW_AT_external);
198
199 // Add line number info.
200 addSourceLine(*VariableDIE, GV);
201 }
202
203 if (!GV->isDefinition())
204 addFlag(*VariableDIE, dwarf::DW_AT_declaration);
205 else
206 addGlobalName(GV->getName(), *VariableDIE, DeclContext);
207
208 addAnnotation(*VariableDIE, GV->getAnnotations());
209
210 if (uint32_t AlignInBytes = GV->getAlignInBytes())
211 addUInt(*VariableDIE, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
212 AlignInBytes);
213
214 if (MDTuple *TP = GV->getTemplateParams())
215 addTemplateParams(*VariableDIE, DINodeArray(TP));
216
217 // Add location.
218 addLocationAttribute(VariableDIE, GV, GlobalExprs);
219
220 return VariableDIE;
221}
222
224 DIE *VariableDIE, const DIGlobalVariable *GV, ArrayRef<GlobalExpr> GlobalExprs) {
225 bool addToAccelTable = false;
226 DIELoc *Loc = nullptr;
227 std::optional<unsigned> TargetAddrSpace;
228 std::unique_ptr<DIEDwarfExpression> DwarfExpr;
229 const GlobalVariable *LastGlobal = nullptr;
230 for (const auto &GE : GlobalExprs) {
231 const GlobalVariable *Global = GE.Var;
232 const DIExpression *Expr = GE.Expr;
233
234 // For compatibility with DWARF 3 and earlier,
235 // DW_AT_location(DW_OP_constu, X, DW_OP_stack_value) or
236 // DW_AT_location(DW_OP_consts, X, DW_OP_stack_value) becomes
237 // DW_AT_const_value(X).
238 if (GlobalExprs.size() == 1 && Expr && Expr->isConstant()) {
239 addToAccelTable = true;
241 *VariableDIE,
243 *Expr->isConstant(),
244 Expr->getElement(1));
245 break;
246 }
247
248 // We cannot describe the location of dllimport'd variables: the
249 // computation of their address requires loads from the IAT.
250 if (Global && Global->hasDLLImportStorageClass())
251 continue;
252
253 // Nothing to describe without address or constant.
254 if (!Global && (!Expr || !Expr->isConstant()))
255 continue;
256
257 if (Global && Global->isThreadLocal() &&
258 !Asm->getObjFileLowering().supportDebugThreadLocalLocation())
259 continue;
260
261 if (!Loc) {
262 addToAccelTable = true;
264 DwarfExpr = std::make_unique<DIEDwarfExpression>(*Asm, *this, *Loc);
265 }
266
267 if (Expr) {
268 Expr = DD->adjustExpressionForTarget(Expr, TargetAddrSpace);
269 DwarfExpr->addFragmentOffset(Expr);
270 }
271
272 if (Global) {
273 const MCSymbol *Sym = Asm->getSymbol(Global);
274 // 16-bit platforms like MSP430 and AVR take this path, so sink this
275 // assert to platforms that use it.
276 auto GetPointerSizedFormAndOp = [this]() {
277 unsigned PointerSize = Asm->MAI->getCodePointerSize();
278 assert((PointerSize == 4 || PointerSize == 8) &&
279 "Add support for other sizes if necessary");
280 struct FormAndOp {
281 dwarf::Form Form;
283 };
284 return PointerSize == 4
285 ? FormAndOp{dwarf::DW_FORM_data4, dwarf::DW_OP_const4u}
286 : FormAndOp{dwarf::DW_FORM_data8, dwarf::DW_OP_const8u};
287 };
288 if (Global->isThreadLocal()) {
289 if (Asm->TM.getTargetTriple().isWasm()) {
290 // FIXME This is not guaranteed, but in practice, in static linking,
291 // if present, __tls_base's index is 1. This doesn't hold for dynamic
292 // linking, so TLS variables used in dynamic linking won't have
293 // correct debug info for now. See
294 // https://github.com/llvm/llvm-project/blob/19afbfe33156d211fa959dadeea46cd17b9c723c/lld/wasm/Driver.cpp#L786-L823
295 addWasmRelocBaseGlobal(Loc, "__tls_base", 1);
296 addOpAddress(*Loc, Sym);
297 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
298 } else if (Asm->TM.useEmulatedTLS()) {
299 // TODO: add debug info for emulated thread local mode.
300 } else {
301 // FIXME: Make this work with -gsplit-dwarf.
302 // Based on GCC's support for TLS:
303 if (!DD->useSplitDwarf()) {
304 auto FormAndOp = GetPointerSizedFormAndOp();
305 // 1) Start with a constNu of the appropriate pointer size
306 addUInt(*Loc, dwarf::DW_FORM_data1, FormAndOp.Op);
307 // 2) containing the (relocated) offset of the TLS variable
308 // within the module's TLS block.
309 addExpr(*Loc, FormAndOp.Form,
310 Asm->getObjFileLowering().getDebugThreadLocalSymbol(Sym));
311 } else {
312 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_const_index);
313 addUInt(*Loc, dwarf::DW_FORM_udata,
314 DD->getAddressPool().getIndex(Sym, /* TLS */ true));
315 }
316 // 3) followed by an OP to make the debugger do a TLS lookup.
317 addUInt(*Loc, dwarf::DW_FORM_data1,
318 DD->useGNUTLSOpcode() ? dwarf::DW_OP_GNU_push_tls_address
319 : dwarf::DW_OP_form_tls_address);
320 }
321 } else if (Asm->TM.getTargetTriple().isWasm() &&
322 Asm->TM.getRelocationModel() == Reloc::PIC_) {
323 // FIXME This is not guaranteed, but in practice, if present,
324 // __memory_base's index is 1. See
325 // https://github.com/llvm/llvm-project/blob/19afbfe33156d211fa959dadeea46cd17b9c723c/lld/wasm/Driver.cpp#L786-L823
326 addWasmRelocBaseGlobal(Loc, "__memory_base", 1);
327 addOpAddress(*Loc, Sym);
328 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
329 } else if ((Asm->TM.getRelocationModel() == Reloc::RWPI ||
330 Asm->TM.getRelocationModel() == Reloc::ROPI_RWPI) &&
331 !Asm->getObjFileLowering()
332 .getKindForGlobal(Global, Asm->TM)
333 .isReadOnly()) {
334 auto FormAndOp = GetPointerSizedFormAndOp();
335 // Constant
336 addUInt(*Loc, dwarf::DW_FORM_data1, FormAndOp.Op);
337 // Relocation offset
338 addExpr(*Loc, FormAndOp.Form,
339 Asm->getObjFileLowering().getIndirectSymViaRWPI(Sym));
340 // Base register
341 Register BaseReg = Asm->getObjFileLowering().getStaticBase();
342 unsigned DwarfBaseReg =
343 Asm->TM.getMCRegisterInfo()->getDwarfRegNum(BaseReg, false);
344 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + DwarfBaseReg);
345 // Offset from base register
346 addSInt(*Loc, dwarf::DW_FORM_sdata, 0);
347 // Operation
348 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
349 } else {
350 DD->addArangeLabel(SymbolCU(this, Sym));
351 addOpAddress(*Loc, Sym);
352 }
353 LastGlobal = Global;
354 }
355 // Global variables attached to symbols are memory locations.
356 // It would be better if this were unconditional, but malformed input that
357 // mixes non-fragments and fragments for the same variable is too expensive
358 // to detect in the verifier.
359 if (DwarfExpr->isUnknownLocation())
360 DwarfExpr->setMemoryLocationKind();
361 DwarfExpr->addExpression(Expr);
362 }
363 DD->addTargetVariableAttributes(*this, *VariableDIE, TargetAddrSpace,
365 LastGlobal);
366 if (Loc)
367 addBlock(*VariableDIE, dwarf::DW_AT_location, DwarfExpr->finalize());
368
369 if (DD->useAllLinkageNames())
370 addLinkageName(*VariableDIE, GV->getLinkageName());
371
372 if (addToAccelTable) {
373 DD->addAccelName(*this, CUNode->getNameTableKind(), GV->getName(),
374 *VariableDIE);
375
376 // If the linkage name is different than the name, go ahead and output
377 // that as well into the name table.
378 if (GV->getLinkageName() != "" && GV->getName() != GV->getLinkageName() &&
379 DD->useAllLinkageNames())
380 DD->addAccelName(*this, CUNode->getNameTableKind(), GV->getLinkageName(),
381 *VariableDIE);
382 }
383}
384
386 const DICommonBlock *CB, ArrayRef<GlobalExpr> GlobalExprs) {
387 // Check for pre-existence.
388 if (DIE *NDie = getDIE(CB))
389 return NDie;
390 DIE *ContextDIE = getOrCreateContextDIE(CB->getScope());
391 DIE &NDie = createAndAddDIE(dwarf::DW_TAG_common_block, *ContextDIE, CB);
392 StringRef Name = CB->getName().empty() ? "_BLNK_" : CB->getName();
393 addString(NDie, dwarf::DW_AT_name, Name);
394 addGlobalName(Name, NDie, CB->getScope());
395 if (CB->getFile())
396 addSourceLine(NDie, CB->getLineNo(), /*Column*/ 0, CB->getFile());
397 if (DIGlobalVariable *V = CB->getDecl())
398 getCU().addLocationAttribute(&NDie, V, GlobalExprs);
399 return &NDie;
400}
401
403 DD->insertSectionLabel(Range.Begin);
404
405 auto *PrevCU = DD->getPrevCU();
406 bool SameAsPrevCU = this == PrevCU;
407 DD->setPrevCU(this);
408 // If we have no current ranges just add the range and return, otherwise,
409 // check the current section and CU against the previous section and CU we
410 // emitted into and the subprogram was contained within. If these are the
411 // same then extend our current range, otherwise add this as a new range.
412 if (CURanges.empty() || !SameAsPrevCU ||
413 (&CURanges.back().End->getSection() !=
414 &Range.End->getSection())) {
415 // Before a new range is added, always terminate the prior line table.
416 if (PrevCU)
417 DD->terminateLineTable(PrevCU);
418 CURanges.push_back(Range);
419 return;
420 }
421
422 CURanges.back().End = Range.End;
423}
424
426 if (CUNode->isDebugDirectivesOnly())
427 return;
428
429 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
430 if (DD->useSectionsAsReferences()) {
431 LineTableStartSym = TLOF.getDwarfLineSection()->getBeginSymbol();
432 } else {
433 LineTableStartSym =
434 Asm->OutStreamer->getDwarfLineTableSymbol(getUniqueID());
435 }
436
437 // DW_AT_stmt_list is a offset of line number information for this
438 // compile unit in debug_line section. For split dwarf this is
439 // left in the skeleton CU and so not included.
440 // The line table entries are not always emitted in assembly, so it
441 // is not okay to use line_table_start here.
442 addSectionLabel(getUnitDie(), dwarf::DW_AT_stmt_list, LineTableStartSym,
444}
445
447 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
448 addSectionLabel(D, dwarf::DW_AT_stmt_list, LineTableStartSym,
450}
451
453 const MCSymbol *End) {
454 assert(Begin && "Begin label should not be null!");
455 assert(End && "End label should not be null!");
456 assert(Begin->isDefined() && "Invalid starting label");
457 assert(End->isDefined() && "Invalid end label");
458
459 addLabelAddress(D, dwarf::DW_AT_low_pc, Begin);
460 if (DD->getDwarfVersion() >= 4 &&
461 (!isDwoUnit() || !llvm::isRangeRelaxable(Begin, End))) {
462 addLabelDelta(D, dwarf::DW_AT_high_pc, End, Begin);
463 return;
464 }
465 addLabelAddress(D, dwarf::DW_AT_high_pc, End);
466}
467
468// Add info for Wasm-global-based relocation.
469// 'GlobalIndex' is used for split dwarf, which currently relies on a few
470// assumptions that are not guaranteed in a formal way but work in practice.
471void DwarfCompileUnit::addWasmRelocBaseGlobal(DIELoc *Loc, StringRef GlobalName,
472 uint64_t GlobalIndex) {
473 // FIXME: duplicated from Target/WebAssembly/WebAssembly.h
474 // don't want to depend on target specific headers in this code?
475 const unsigned TI_GLOBAL_RELOC = 3;
476 unsigned PointerSize = Asm->getDataLayout().getPointerSize();
477 auto *Sym =
478 static_cast<MCSymbolWasm *>(Asm->GetExternalSymbolSymbol(GlobalName));
479 // FIXME: this repeats what WebAssemblyMCInstLower::
480 // GetExternalSymbolSymbol does, since if there's no code that
481 // refers to this symbol, we have to set it here.
483 Sym->setGlobalType(wasm::WasmGlobalType{
484 static_cast<uint8_t>(PointerSize == 4 ? wasm::WASM_TYPE_I32
486 true});
487 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_WASM_location);
488 addSInt(*Loc, dwarf::DW_FORM_sdata, TI_GLOBAL_RELOC);
489 if (!isDwoUnit()) {
490 addLabel(*Loc, dwarf::DW_FORM_data4, Sym);
491 } else {
492 // FIXME: when writing dwo, we need to avoid relocations. Probably
493 // the "right" solution is to treat globals the way func and data
494 // symbols are (with entries in .debug_addr).
495 // For now we hardcode the indices in the callsites. Global indices are not
496 // fixed, but in practice a few are fixed; for example, __stack_pointer is
497 // always index 0.
498 addUInt(*Loc, dwarf::DW_FORM_data4, GlobalIndex);
499 }
500}
501
502// Find DIE for the given subprogram and attach appropriate DW_AT_low_pc
503// and DW_AT_high_pc attributes. If there are global variables in this
504// scope then create and insert DIEs for these variables.
506 const Function &F,
507 MCSymbol *LineTableSym) {
510 // If basic block sections are on, ranges for each basic block section has
511 // to be emitted separately.
512 for (const auto &R : Asm->MBBSectionRanges)
513 BB_List.push_back({R.second.BeginLabel, R.second.EndLabel});
514
515 attachRangesOrLowHighPC(*SPDie, BB_List);
516
517 if (DD->useAppleExtensionAttributes() &&
518 !DD->getCurrentFunction()->getTarget().Options.DisableFramePointerElim(
519 *DD->getCurrentFunction()))
520 addFlag(*SPDie, dwarf::DW_AT_APPLE_omit_frame_ptr);
521
522 if (emitFuncLineTableOffsets() && LineTableSym) {
524 *SPDie, dwarf::DW_AT_LLVM_stmt_sequence, LineTableSym,
525 Asm->getObjFileLowering().getDwarfLineSection()->getBeginSymbol());
526 }
527
528 // Only include DW_AT_frame_base in full debug info
530 const TargetFrameLowering *TFI = Asm->MF->getSubtarget().getFrameLowering();
532 TFI->getDwarfFrameBase(*Asm->MF);
533 switch (FrameBase.Kind) {
536 MachineLocation Location(FrameBase.Location.Reg);
537 addAddress(*SPDie, dwarf::DW_AT_frame_base, Location);
538 }
539 break;
540 }
543 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_call_frame_cfa);
544 if (FrameBase.Location.Offset != 0) {
545 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_consts);
546 addSInt(*Loc, dwarf::DW_FORM_sdata, FrameBase.Location.Offset);
547 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
548 }
549 addBlock(*SPDie, dwarf::DW_AT_frame_base, Loc);
550 break;
551 }
553 // FIXME: duplicated from Target/WebAssembly/WebAssembly.h
554 const unsigned TI_GLOBAL_RELOC = 3;
555 if (FrameBase.Location.WasmLoc.Kind == TI_GLOBAL_RELOC) {
556 // These need to be relocatable.
558 assert(FrameBase.Location.WasmLoc.Index == 0); // Only SP so far.
559 // For now, since we only ever use index 0, this should work as-is.
560 addWasmRelocBaseGlobal(Loc, "__stack_pointer",
561 FrameBase.Location.WasmLoc.Index);
562 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value);
563 addBlock(*SPDie, dwarf::DW_AT_frame_base, Loc);
564 } else {
566 DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
567 DIExpressionCursor Cursor({});
568 DwarfExpr.addWasmLocation(FrameBase.Location.WasmLoc.Kind,
569 FrameBase.Location.WasmLoc.Index);
570 DwarfExpr.addExpression(std::move(Cursor));
571 addBlock(*SPDie, dwarf::DW_AT_frame_base, DwarfExpr.finalize());
572 }
573 break;
574 }
575 }
576 }
577
578 // Add name to the name table, we do this here because we're guaranteed
579 // to have concrete versions of our DW_TAG_subprogram nodes.
580 DD->addSubprogramNames(*this, CUNode->getNameTableKind(), SP, *SPDie);
581
582 return *SPDie;
583}
584
585// Construct a DIE for this scope.
587 DIE &ParentScopeDIE) {
588 if (!Scope || !Scope->getScopeNode())
589 return;
590
591 auto *DS = Scope->getScopeNode();
592
593 assert((Scope->getInlinedAt() || !isa<DISubprogram>(DS)) &&
594 "Only handle inlined subprograms here, use "
595 "constructSubprogramScopeDIE for non-inlined "
596 "subprograms");
597
598 // Emit inlined subprograms.
599 if (Scope->getParent() && isa<DISubprogram>(DS)) {
600 DIE *ScopeDIE = constructInlinedScopeDIE(Scope, ParentScopeDIE);
601 assert(ScopeDIE && "Scope DIE should not be null.");
602 createAndAddScopeChildren(Scope, *ScopeDIE);
603 return;
604 }
605
606 // Early exit when we know the scope DIE is going to be null.
607 if (DD->isLexicalScopeDIENull(Scope))
608 return;
609
610 // Emit lexical blocks.
611 DIE *ScopeDIE = getOrCreateLexicalBlockDIE(Scope, ParentScopeDIE);
612 assert(ScopeDIE && "Scope DIE should not be null.");
613
614 createAndAddScopeChildren(Scope, *ScopeDIE);
615}
616
619
620 HasRangeLists = true;
621
622 // Add the range list to the set of ranges to be emitted.
623 auto IndexAndList =
624 (DD->getDwarfVersion() < 5 && Skeleton ? Skeleton->DU : DU)
625 ->addRange(*(Skeleton ? Skeleton : this), std::move(Range));
626
627 uint32_t Index = IndexAndList.first;
628 auto &List = *IndexAndList.second;
629
630 // Under fission, ranges are specified by constant offsets relative to the
631 // CU's DW_AT_GNU_ranges_base.
632 // FIXME: For DWARF v5, do not generate the DW_AT_ranges attribute under
633 // fission until we support the forms using the .debug_addr section
634 // (DW_RLE_startx_endx etc.).
635 if (DD->getDwarfVersion() >= 5)
636 addUInt(ScopeDIE, dwarf::DW_AT_ranges, dwarf::DW_FORM_rnglistx, Index);
637 else {
638 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
639 const MCSymbol *RangeSectionSym =
641 if (isDwoUnit())
642 addSectionDelta(ScopeDIE, dwarf::DW_AT_ranges, List.Label,
643 RangeSectionSym);
644 else
645 addSectionLabel(ScopeDIE, dwarf::DW_AT_ranges, List.Label,
646 RangeSectionSym);
647 }
648}
649
651 DIE &Die, SmallVector<RangeSpan, 2> Ranges) {
652 assert(!Ranges.empty());
653 if (!DD->useRangesSection() ||
654 (Ranges.size() == 1 &&
655 (!DD->alwaysUseRanges(*this) ||
656 DD->getSectionLabel(&Ranges.front().Begin->getSection()) ==
657 Ranges.front().Begin))) {
658 const RangeSpan &Front = Ranges.front();
659 const RangeSpan &Back = Ranges.back();
660 attachLowHighPC(Die, Front.Begin, Back.End);
661 } else
662 addScopeRangeList(Die, std::move(Ranges));
663}
664
666 DIE &Die, const SmallVectorImpl<InsnRange> &Ranges) {
668 List.reserve(Ranges.size());
669 for (const InsnRange &R : Ranges) {
670 auto *BeginLabel = DD->getLabelBeforeInsn(R.first);
671 auto *EndLabel = DD->getLabelAfterInsn(R.second);
672
673 const auto *BeginMBB = R.first->getParent();
674 const auto *EndMBB = R.second->getParent();
675
676 const auto *MBB = BeginMBB;
677 // Basic block sections allows basic block subsets to be placed in unique
678 // sections. For each section, the begin and end label must be added to the
679 // list. If there is more than one range, debug ranges must be used.
680 // Otherwise, low/high PC can be used.
681 // FIXME: Debug Info Emission depends on block order and this assumes that
682 // the order of blocks will be frozen beyond this point.
683 do {
684 if (MBB->sameSection(EndMBB) || MBB->isEndSection()) {
685 auto MBBSectionRange = Asm->MBBSectionRanges[MBB->getSectionID()];
686 List.push_back(
687 {MBB->sameSection(BeginMBB) ? BeginLabel
688 : MBBSectionRange.BeginLabel,
689 MBB->sameSection(EndMBB) ? EndLabel : MBBSectionRange.EndLabel});
690 }
691 if (MBB->sameSection(EndMBB))
692 break;
693 MBB = MBB->getNextNode();
694 } while (true);
695 }
696 attachRangesOrLowHighPC(Die, std::move(List));
697}
698
700 DIE &ParentScopeDIE) {
701 assert(Scope->getScopeNode());
702 auto *DS = Scope->getScopeNode();
703 auto *InlinedSP = getDISubprogram(DS);
704 // Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram
705 // was inlined from another compile unit.
706 DIE *OriginDIE = getAbstractScopeDIEs()[InlinedSP];
707 assert(OriginDIE && "Unable to find original DIE for an inlined subprogram.");
708
709 auto ScopeDIE = DIE::get(DIEValueAllocator, dwarf::DW_TAG_inlined_subroutine);
710 ParentScopeDIE.addChild(ScopeDIE);
711 addDIEEntry(*ScopeDIE, dwarf::DW_AT_abstract_origin, *OriginDIE);
712
713 attachRangesOrLowHighPC(*ScopeDIE, Scope->getRanges());
714
715 // Add the call site information to the DIE.
716 const DILocation *IA = Scope->getInlinedAt();
717 addUInt(*ScopeDIE, dwarf::DW_AT_call_file, std::nullopt,
718 getOrCreateSourceID(IA->getFile()));
719 addUInt(*ScopeDIE, dwarf::DW_AT_call_line, std::nullopt, IA->getLine());
720 if (IA->getColumn())
721 addUInt(*ScopeDIE, dwarf::DW_AT_call_column, std::nullopt, IA->getColumn());
722 if (IA->getDiscriminator() && DD->getDwarfVersion() >= 4)
723 addUInt(*ScopeDIE, dwarf::DW_AT_GNU_discriminator, std::nullopt,
724 IA->getDiscriminator());
725
726 // Add name to the name table, we do this here because we're guaranteed
727 // to have concrete versions of our DW_TAG_inlined_subprogram nodes.
728 DD->addSubprogramNames(*this, CUNode->getNameTableKind(), InlinedSP,
729 *ScopeDIE);
730
731 return ScopeDIE;
732}
733
735 DIE &ParentScopeDIE) {
736 if (DD->isLexicalScopeDIENull(Scope))
737 return nullptr;
738 const auto *DS = Scope->getScopeNode();
739
740 auto ScopeDIE = DIE::get(DIEValueAllocator, dwarf::DW_TAG_lexical_block);
741 ParentScopeDIE.addChild(ScopeDIE);
742
743 if (Scope->isAbstractScope()) {
744 assert(!getAbstractScopeDIEs().count(DS) &&
745 "Abstract DIE for this scope exists!");
746 getAbstractScopeDIEs()[DS] = ScopeDIE;
747 return ScopeDIE;
748 }
749 if (!Scope->getInlinedAt()) {
750 assert(!LexicalBlockDIEs.count(DS) &&
751 "Concrete out-of-line DIE for this scope exists!");
752 LexicalBlockDIEs[DS] = ScopeDIE;
753 } else {
754 InlinedLocalScopeDIEs[DS].push_back(ScopeDIE);
755 }
756
757 attachRangesOrLowHighPC(*ScopeDIE, Scope->getRanges());
758
759 return ScopeDIE;
760}
761
763 auto *VariableDie = DIE::get(DIEValueAllocator, DV.getTag());
764 insertDIE(DV.getVariable(), VariableDie);
765 DV.setDIE(*VariableDie);
766 // Abstract variables don't get common attributes later, so apply them now.
767 if (Abstract) {
768 applyCommonDbgVariableAttributes(DV, *VariableDie);
769 } else {
770 std::visit(
771 [&](const auto &V) {
772 applyConcreteDbgVariableAttributes(V, DV, *VariableDie);
773 },
774 DV.asVariant());
775 }
776 return VariableDie;
777}
778
779void DwarfCompileUnit::applyConcreteDbgVariableAttributes(
780 const Loc::Single &Single, const DbgVariable &DV, DIE &VariableDie) {
781 const DbgValueLoc *DVal = &Single.getValueLoc();
782 if (!Single.getExpr())
783 DD->addTargetVariableAttributes(*this, VariableDie, std::nullopt,
785 if (!DVal->isVariadic()) {
786 const DbgValueLocEntry *Entry = DVal->getLocEntries().begin();
787 if (Entry->isLocation()) {
788 addVariableAddress(DV, VariableDie, Entry->getLoc());
789 } else if (Entry->isInt()) {
790 auto *Expr = Single.getExpr();
791 if (Expr && Expr->getNumElements()) {
793 DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
794 // If there is an expression, emit raw unsigned bytes.
795 DwarfExpr.addFragmentOffset(Expr);
796 DwarfExpr.addUnsignedConstant(Entry->getInt());
797 DwarfExpr.addExpression(Expr);
798 addBlock(VariableDie, dwarf::DW_AT_location, DwarfExpr.finalize());
799 if (DwarfExpr.TagOffset)
800 addUInt(VariableDie, dwarf::DW_AT_LLVM_tag_offset,
801 dwarf::DW_FORM_data1, *DwarfExpr.TagOffset);
802 } else
803 addConstantValue(VariableDie, Entry->getInt(), DV.getType());
804 } else if (Entry->isConstantFP()) {
805 addConstantFPValue(VariableDie, Entry->getConstantFP());
806 } else if (Entry->isConstantInt()) {
807 addConstantValue(VariableDie, Entry->getConstantInt(), DV.getType());
808 } else if (Entry->isTargetIndexLocation()) {
809 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
810 DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
811 const DIBasicType *BT = dyn_cast<DIBasicType>(
812 static_cast<const Metadata *>(DV.getVariable()->getType()));
813 DwarfDebug::emitDebugLocValue(*Asm, BT, *DVal, DwarfExpr);
814 addBlock(VariableDie, dwarf::DW_AT_location, DwarfExpr.finalize());
815 }
816 return;
817 }
818 // If any of the location entries are registers with the value 0,
819 // then the location is undefined.
820 if (any_of(DVal->getLocEntries(), [](const DbgValueLocEntry &Entry) {
821 return Entry.isLocation() && !Entry.getLoc().getReg();
822 }))
823 return;
824 const DIExpression *Expr = Single.getExpr();
825 assert(Expr && "Variadic Debug Value must have an Expression.");
826 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
827 DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
828 DwarfExpr.addFragmentOffset(Expr);
829 DIExpressionCursor Cursor(Expr);
830 const TargetRegisterInfo &TRI = *Asm->MF->getSubtarget().getRegisterInfo();
831
832 auto AddEntry = [&](const DbgValueLocEntry &Entry,
833 DIExpressionCursor &Cursor) {
834 if (Entry.isLocation()) {
835 if (!DwarfExpr.addMachineRegExpression(TRI, Cursor,
836 Entry.getLoc().getReg()))
837 return false;
838 } else if (Entry.isInt()) {
839 // If there is an expression, emit raw unsigned bytes.
840 DwarfExpr.addUnsignedConstant(Entry.getInt());
841 } else if (Entry.isConstantFP()) {
842 // DwarfExpression does not support arguments wider than 64 bits
843 // (see PR52584).
844 // TODO: Consider chunking expressions containing overly wide
845 // arguments into separate pointer-sized fragment expressions.
846 APInt RawBytes = Entry.getConstantFP()->getValueAPF().bitcastToAPInt();
847 if (RawBytes.getBitWidth() > 64)
848 return false;
849 DwarfExpr.addUnsignedConstant(RawBytes.getZExtValue());
850 } else if (Entry.isConstantInt()) {
851 APInt RawBytes = Entry.getConstantInt()->getValue();
852 if (RawBytes.getBitWidth() > 64)
853 return false;
854 DwarfExpr.addUnsignedConstant(RawBytes.getZExtValue());
855 } else if (Entry.isTargetIndexLocation()) {
856 TargetIndexLocation Loc = Entry.getTargetIndexLocation();
857 // TODO TargetIndexLocation is a target-independent. Currently
858 // only the WebAssembly-specific encoding is supported.
859 assert(Asm->TM.getTargetTriple().isWasm());
860 DwarfExpr.addWasmLocation(Loc.Index, static_cast<uint64_t>(Loc.Offset));
861 } else {
862 llvm_unreachable("Unsupported Entry type.");
863 }
864 return true;
865 };
866
867 if (!DwarfExpr.addExpression(
868 std::move(Cursor),
869 [&](unsigned Idx, DIExpressionCursor &Cursor) -> bool {
870 return AddEntry(DVal->getLocEntries()[Idx], Cursor);
871 }))
872 return;
873
874 // Now attach the location information to the DIE.
875 addBlock(VariableDie, dwarf::DW_AT_location, DwarfExpr.finalize());
876 if (DwarfExpr.TagOffset)
877 addUInt(VariableDie, dwarf::DW_AT_LLVM_tag_offset, dwarf::DW_FORM_data1,
878 *DwarfExpr.TagOffset);
879}
880
881void DwarfCompileUnit::applyConcreteDbgVariableAttributes(
882 const Loc::Multi &Multi, const DbgVariable &DV, DIE &VariableDie) {
883 addLocationList(VariableDie, dwarf::DW_AT_location,
884 Multi.getDebugLocListIndex());
885 auto TagOffset = Multi.getDebugLocListTagOffset();
886 if (TagOffset)
887 addUInt(VariableDie, dwarf::DW_AT_LLVM_tag_offset, dwarf::DW_FORM_data1,
888 *TagOffset);
889}
890
891void DwarfCompileUnit::applyConcreteDbgVariableAttributes(const Loc::MMI &MMI,
892 const DbgVariable &DV,
893 DIE &VariableDie) {
894 std::optional<unsigned> TargetAddrSpace;
895 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
896 DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
897 for (const auto &Fragment : MMI.getFrameIndexExprs()) {
898 Register FrameReg;
899 const DIExpression *Expr = Fragment.Expr;
900 const TargetFrameLowering *TFI = Asm->MF->getSubtarget().getFrameLowering();
901 StackOffset Offset =
902 TFI->getFrameIndexReference(*Asm->MF, Fragment.FI, FrameReg);
903 DwarfExpr.addFragmentOffset(Expr);
904
905 auto *TRI = Asm->MF->getSubtarget().getRegisterInfo();
906 SmallVector<uint64_t, 8> Ops;
907 TRI->getOffsetOpcodes(Offset, Ops);
908
909 Expr = DD->adjustExpressionForTarget(Expr, TargetAddrSpace);
910 if (Expr)
911 Ops.append(Expr->elements_begin(), Expr->elements_end());
912 DIExpressionCursor Cursor(Ops);
913 DwarfExpr.setMemoryLocationKind();
914 if (const MCSymbol *FrameSymbol = Asm->getFunctionFrameSymbol())
915 addOpAddress(*Loc, FrameSymbol);
916 else
917 DwarfExpr.addMachineRegExpression(
918 *Asm->MF->getSubtarget().getRegisterInfo(), Cursor, FrameReg);
919 DwarfExpr.addExpression(std::move(Cursor));
920 }
921 DD->addTargetVariableAttributes(*this, VariableDie, TargetAddrSpace,
923 addBlock(VariableDie, dwarf::DW_AT_location, DwarfExpr.finalize());
924 if (DwarfExpr.TagOffset)
925 addUInt(VariableDie, dwarf::DW_AT_LLVM_tag_offset, dwarf::DW_FORM_data1,
926 *DwarfExpr.TagOffset);
927}
928
929void DwarfCompileUnit::applyConcreteDbgVariableAttributes(
930 const Loc::EntryValue &EntryValue, const DbgVariable &DV,
931 DIE &VariableDie) {
932 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
933 DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
934 // Emit each expression as: EntryValue(Register) <other ops> <Fragment>.
935 for (auto [Register, Expr] : EntryValue.EntryValues) {
936 DwarfExpr.addFragmentOffset(&Expr);
937 DIExpressionCursor Cursor(Expr.getElements());
938 DwarfExpr.beginEntryValueExpression(Cursor);
939 DwarfExpr.addMachineRegExpression(
940 *Asm->MF->getSubtarget().getRegisterInfo(), Cursor, Register);
941 DwarfExpr.addExpression(std::move(Cursor));
942 }
943 addBlock(VariableDie, dwarf::DW_AT_location, DwarfExpr.finalize());
944}
945
946void DwarfCompileUnit::applyConcreteDbgVariableAttributes(
947 const std::monostate &, const DbgVariable &DV, DIE &VariableDie) {}
948
950 const LexicalScope &Scope,
951 DIE *&ObjectPointer) {
952 auto Var = constructVariableDIE(DV, Scope.isAbstractScope());
953 if (DV.isObjectPointer())
954 ObjectPointer = Var;
955 return Var;
956}
957
959 const LexicalScope &Scope) {
960 auto LabelDie = DIE::get(DIEValueAllocator, DL.getTag());
961 insertDIE(DL.getLabel(), LabelDie);
962 DL.setDIE(*LabelDie);
963
964 if (Scope.isAbstractScope())
965 applyLabelAttributes(DL, *LabelDie);
966
967 return LabelDie;
968}
969
970/// Return all DIVariables that appear in count: expressions.
973 auto *Array = dyn_cast<DICompositeType>(Var->getType());
974 if (!Array || Array->getTag() != dwarf::DW_TAG_array_type)
975 return Result;
976 if (auto *DLVar = Array->getDataLocation())
977 Result.push_back(DLVar);
978 if (auto *AsVar = Array->getAssociated())
979 Result.push_back(AsVar);
980 if (auto *AlVar = Array->getAllocated())
981 Result.push_back(AlVar);
982 for (auto *El : Array->getElements()) {
983 if (auto *Subrange = dyn_cast<DISubrange>(El)) {
984 if (auto Count = Subrange->getCount())
985 if (auto *Dependency = dyn_cast_if_present<DIVariable *>(Count))
986 Result.push_back(Dependency);
987 if (auto LB = Subrange->getLowerBound())
988 if (auto *Dependency = dyn_cast_if_present<DIVariable *>(LB))
989 Result.push_back(Dependency);
990 if (auto UB = Subrange->getUpperBound())
991 if (auto *Dependency = dyn_cast_if_present<DIVariable *>(UB))
992 Result.push_back(Dependency);
993 if (auto ST = Subrange->getStride())
994 if (auto *Dependency = dyn_cast_if_present<DIVariable *>(ST))
995 Result.push_back(Dependency);
996 } else if (auto *GenericSubrange = dyn_cast<DIGenericSubrange>(El)) {
997 if (auto Count = GenericSubrange->getCount())
998 if (auto *Dependency = dyn_cast_if_present<DIVariable *>(Count))
999 Result.push_back(Dependency);
1000 if (auto LB = GenericSubrange->getLowerBound())
1001 if (auto *Dependency = dyn_cast_if_present<DIVariable *>(LB))
1002 Result.push_back(Dependency);
1003 if (auto UB = GenericSubrange->getUpperBound())
1004 if (auto *Dependency = dyn_cast_if_present<DIVariable *>(UB))
1005 Result.push_back(Dependency);
1006 if (auto ST = GenericSubrange->getStride())
1007 if (auto *Dependency = dyn_cast_if_present<DIVariable *>(ST))
1008 Result.push_back(Dependency);
1009 }
1010 }
1011 return Result;
1012}
1013
1014/// Sort local variables so that variables appearing inside of helper
1015/// expressions come first.
1020 // Map back from a DIVariable to its containing DbgVariable.
1022 // Set of DbgVariables in Result.
1024 // For cycle detection.
1026
1027 // Initialize the worklist and the DIVariable lookup table.
1028 for (auto *Var : reverse(Input)) {
1029 DbgVar.insert({Var->getVariable(), Var});
1030 WorkList.push_back({Var, 0});
1031 }
1032
1033 // Perform a stable topological sort by doing a DFS.
1034 while (!WorkList.empty()) {
1035 auto Item = WorkList.back();
1036 DbgVariable *Var = Item.getPointer();
1037 bool visitedAllDependencies = Item.getInt();
1038 WorkList.pop_back();
1039
1040 assert(Var);
1041
1042 // Already handled.
1043 if (Visited.count(Var))
1044 continue;
1045
1046 // Add to Result if all dependencies are visited.
1047 if (visitedAllDependencies) {
1048 Visited.insert(Var);
1049 Result.push_back(Var);
1050 continue;
1051 }
1052
1053 // Detect cycles.
1054 auto Res = Visiting.insert(Var);
1055 if (!Res.second) {
1056 assert(false && "dependency cycle in local variables");
1057 return Result;
1058 }
1059
1060 // Push dependencies and this node onto the worklist, so that this node is
1061 // visited again after all of its dependencies are handled.
1062 WorkList.push_back({Var, 1});
1063 for (const auto *Dependency : dependencies(Var)) {
1064 // Don't add dependency if it is in a different lexical scope or a global.
1065 if (const auto *Dep = dyn_cast<const DILocalVariable>(Dependency))
1066 if (DbgVariable *Var = DbgVar.lookup(Dep))
1067 WorkList.push_back({Var, 0});
1068 }
1069 }
1070 return Result;
1071}
1072
1074 const Function &F,
1075 LexicalScope *Scope,
1076 MCSymbol *LineTableSym) {
1077 DIE &ScopeDIE = updateSubprogramScopeDIE(Sub, F, LineTableSym);
1078
1079 if (Scope) {
1080 assert(!Scope->getInlinedAt());
1081 assert(!Scope->isAbstractScope());
1082 // Collect lexical scope children first.
1083 // ObjectPointer might be a local (non-argument) local variable if it's a
1084 // block's synthetic this pointer.
1085 if (DIE *ObjectPointer = createAndAddScopeChildren(Scope, ScopeDIE))
1086 addDIEEntry(ScopeDIE, dwarf::DW_AT_object_pointer, *ObjectPointer);
1087 }
1088
1089 // If this is a variadic function, add an unspecified parameter.
1090 auto *SPTy = Sub->getType();
1091 if (!SPTy)
1092 return ScopeDIE;
1093
1094 DITypeArray FnArgs = SPTy->getTypeArray();
1095
1096 // If we have a single element of null, it is a function that returns void.
1097 // If we have more than one elements and the last one is null, it is a
1098 // variadic function.
1099 if (FnArgs.size() > 1 && !FnArgs[FnArgs.size() - 1] &&
1101 ScopeDIE.addChild(
1102 DIE::get(DIEValueAllocator, dwarf::DW_TAG_unspecified_parameters));
1103
1104 return ScopeDIE;
1105}
1106
1108 DIE &ScopeDIE) {
1109 DIE *ObjectPointer = nullptr;
1110
1111 // Emit function arguments (order is significant).
1112 auto Vars = DU->getScopeVariables().lookup(Scope);
1113 for (auto &DV : Vars.Args)
1114 ScopeDIE.addChild(constructVariableDIE(*DV.second, *Scope, ObjectPointer));
1115
1116 // Emit local variables.
1117 auto Locals = sortLocalVars(Vars.Locals);
1118 for (DbgVariable *DV : Locals)
1119 ScopeDIE.addChild(constructVariableDIE(*DV, *Scope, ObjectPointer));
1120
1121 // Emit labels.
1122 for (DbgLabel *DL : DU->getScopeLabels().lookup(Scope))
1123 ScopeDIE.addChild(constructLabelDIE(*DL, *Scope));
1124
1125 // Track other local entities (skipped in gmlt-like data).
1126 // This creates mapping between CU and a set of local declarations that
1127 // should be emitted for subprograms in this CU.
1128 if (!includeMinimalInlineScopes() && !Scope->getInlinedAt()) {
1129 auto &LocalDecls = DD->getLocalDeclsForScope(Scope->getScopeNode());
1130 DeferredLocalDecls.insert_range(LocalDecls);
1131 }
1132
1133 // Emit inner lexical scopes.
1134 auto skipLexicalScope = [this](LexicalScope *S) -> bool {
1135 if (isa<DISubprogram>(S->getScopeNode()))
1136 return false;
1137 auto Vars = DU->getScopeVariables().lookup(S);
1138 if (!Vars.Args.empty() || !Vars.Locals.empty())
1139 return false;
1140 return includeMinimalInlineScopes() ||
1141 DD->getLocalDeclsForScope(S->getScopeNode()).empty();
1142 };
1143 for (LexicalScope *LS : Scope->getChildren()) {
1144 // If the lexical block doesn't have non-scope children, skip
1145 // its emission and put its children directly to the parent scope.
1146 if (skipLexicalScope(LS))
1147 createAndAddScopeChildren(LS, ScopeDIE);
1148 else
1149 constructScopeDIE(LS, ScopeDIE);
1150 }
1151
1152 return ObjectPointer;
1153}
1154
1156 const DISubprogram *SP) {
1157 if (auto *AbsDef = getAbstractScopeDIEs().lookup(SP))
1158 return *AbsDef;
1159
1160 auto [ContextDIE, ContextCU] = getOrCreateAbstractSubprogramContextDIE(SP);
1161 return createAbstractSubprogramDIE(SP, ContextDIE, ContextCU);
1162}
1163
1164DIE &DwarfCompileUnit::createAbstractSubprogramDIE(
1165 const DISubprogram *SP, DIE *ContextDIE, DwarfCompileUnit *ContextCU) {
1166 // Passing null as the associated node because the abstract definition
1167 // shouldn't be found by lookup.
1168 DIE &AbsDef = ContextCU->createAndAddDIE(dwarf::DW_TAG_subprogram,
1169 *ContextDIE, nullptr);
1170
1171 // Store the DIE before creating children.
1172 ContextCU->getAbstractScopeDIEs()[SP] = &AbsDef;
1173
1174 ContextCU->applySubprogramAttributesToDefinition(SP, AbsDef);
1175 ContextCU->addSInt(AbsDef, dwarf::DW_AT_inline,
1176 DD->getDwarfVersion() <= 4 ? std::optional<dwarf::Form>()
1177 : dwarf::DW_FORM_implicit_const,
1179
1180 return AbsDef;
1181}
1182
1183std::pair<DIE *, DwarfCompileUnit *>
1184DwarfCompileUnit::getOrCreateAbstractSubprogramContextDIE(
1185 const DISubprogram *SP) {
1186 bool Minimal = includeMinimalInlineScopes();
1187 bool IgnoreScope = shouldPlaceInUnitDIE(SP, Minimal);
1188 DIE *ContextDIE = getOrCreateSubprogramContextDIE(SP, IgnoreScope);
1189
1190 if (auto *SPDecl = SP->getDeclaration())
1191 if (!Minimal)
1192 getOrCreateSubprogramDIE(SPDecl, nullptr);
1193
1194 // The scope may be shared with a subprogram that has already been
1195 // constructed in another CU, in which case we need to construct this
1196 // subprogram in the same CU.
1197 auto *ContextCU = IgnoreScope ? this : DD->lookupCU(ContextDIE->getUnitDie());
1198
1199 return std::make_pair(ContextDIE, ContextCU);
1200}
1201
1203 LexicalScope *Scope) {
1204 auto *SP = cast<DISubprogram>(Scope->getScopeNode());
1205
1206 // Populate subprogram DIE only once.
1207 if (!getFinalizedAbstractSubprograms().insert(SP).second)
1208 return;
1209
1210 auto [ContextDIE, ContextCU] = getOrCreateAbstractSubprogramContextDIE(SP);
1211 DIE *AbsDef = getAbstractScopeDIEs().lookup(SP);
1212 if (!AbsDef)
1213 AbsDef = &createAbstractSubprogramDIE(SP, ContextDIE, ContextCU);
1214
1215 if (DIE *ObjectPointer = ContextCU->createAndAddScopeChildren(Scope, *AbsDef))
1216 ContextCU->addDIEEntry(*AbsDef, dwarf::DW_AT_object_pointer,
1217 *ObjectPointer);
1218}
1219
1221 return DD->getDwarfVersion() <= 4 && !DD->tuneForLLDB();
1222}
1223
1226 return Tag;
1227 switch (Tag) {
1228 case dwarf::DW_TAG_call_site:
1229 return dwarf::DW_TAG_GNU_call_site;
1230 case dwarf::DW_TAG_call_site_parameter:
1231 return dwarf::DW_TAG_GNU_call_site_parameter;
1232 default:
1233 llvm_unreachable("DWARF5 tag with no GNU analog");
1234 }
1235}
1236
1240 return Attr;
1241 switch (Attr) {
1242 case dwarf::DW_AT_call_all_calls:
1243 return dwarf::DW_AT_GNU_all_call_sites;
1244 case dwarf::DW_AT_call_target:
1245 return dwarf::DW_AT_GNU_call_site_target;
1246 case dwarf::DW_AT_call_target_clobbered:
1247 return dwarf::DW_AT_GNU_call_site_target_clobbered;
1248 case dwarf::DW_AT_call_origin:
1249 return dwarf::DW_AT_abstract_origin;
1250 case dwarf::DW_AT_call_return_pc:
1251 return dwarf::DW_AT_low_pc;
1252 case dwarf::DW_AT_call_value:
1253 return dwarf::DW_AT_GNU_call_site_value;
1254 case dwarf::DW_AT_call_tail_call:
1255 return dwarf::DW_AT_GNU_tail_call;
1256 default:
1257 llvm_unreachable("DWARF5 attribute with no GNU analog");
1258 }
1259}
1260
1264 return Loc;
1265 switch (Loc) {
1266 case dwarf::DW_OP_entry_value:
1267 return dwarf::DW_OP_GNU_entry_value;
1268 default:
1269 llvm_unreachable("DWARF5 location atom with no GNU analog");
1270 }
1271}
1272
1274 DIE &ScopeDIE, const DISubprogram *CalleeSP, const Function *CalleeF,
1275 bool IsTail, const MCSymbol *PCAddr, const MCSymbol *CallAddr,
1276 MachineLocation CallTarget, int64_t Offset, DIType *AllocSiteTy) {
1277 // Insert a call site entry DIE within ScopeDIE.
1278 DIE &CallSiteDIE = createAndAddDIE(getDwarf5OrGNUTag(dwarf::DW_TAG_call_site),
1279 ScopeDIE, nullptr);
1280
1281 // A valid register in CallTarget indicates an indirect call.
1282 if (CallTarget.getReg()) {
1283 // Add a DW_AT_call_target location expression describing the location of
1284 // the address of the target function. If any register in the expression
1285 // (i.e., the single register we currently handle) is volatile we must use
1286 // DW_AT_call_target_clobbered instead.
1287 const TargetRegisterInfo &TRI = *Asm->MF->getSubtarget().getRegisterInfo();
1289 TRI.isCalleeSavedPhysReg(CallTarget.getReg(), *Asm->MF)
1290 ? dwarf::DW_AT_call_target
1291 : dwarf::DW_AT_call_target_clobbered);
1292
1293 // CallTarget is the location of the address of an indirect call. The
1294 // location may be indirect, modified by Offset.
1295 if (CallTarget.isIndirect())
1296 addMemoryLocation(CallSiteDIE, Attribute, CallTarget, Offset);
1297 else
1298 addAddress(CallSiteDIE, Attribute, CallTarget);
1299 } else if (CalleeSP) {
1300 DIE *CalleeDIE = getOrCreateSubprogramDIE(CalleeSP, CalleeF);
1301 assert(CalleeDIE && "Could not create DIE for call site entry origin");
1302 addLinkageNamesToDeclarations(*DD, *CalleeSP, *CalleeDIE);
1303
1304 addDIEEntry(CallSiteDIE, getDwarf5OrGNUAttr(dwarf::DW_AT_call_origin),
1305 *CalleeDIE);
1306 }
1307
1308 if (IsTail) {
1309 // Attach DW_AT_call_tail_call to tail calls for standards compliance.
1310 addFlag(CallSiteDIE, getDwarf5OrGNUAttr(dwarf::DW_AT_call_tail_call));
1311
1312 // Attach the address of the branch instruction to allow the debugger to
1313 // show where the tail call occurred. This attribute has no GNU analog.
1314 //
1315 // GDB works backwards from non-standard usage of DW_AT_low_pc (in DWARF4
1316 // mode -- equivalently, in DWARF5 mode, DW_AT_call_return_pc) at tail-call
1317 // site entries to figure out the PC of tail-calling branch instructions.
1318 // This means it doesn't need the compiler to emit DW_AT_call_pc, so we
1319 // don't emit it here.
1320 //
1321 // There's no need to tie non-GDB debuggers to this non-standardness, as it
1322 // adds unnecessary complexity to the debugger. For non-GDB debuggers, emit
1323 // the standard DW_AT_call_pc info.
1325 addLabelAddress(CallSiteDIE, dwarf::DW_AT_call_pc, CallAddr);
1326 }
1327
1328 // Attach the return PC to allow the debugger to disambiguate call paths
1329 // from one function to another.
1330 //
1331 // The return PC is only really needed when the call /isn't/ a tail call, but
1332 // GDB expects it in DWARF4 mode, even for tail calls (see the comment above
1333 // the DW_AT_call_pc emission logic for an explanation).
1334 if (!IsTail || useGNUAnalogForDwarf5Feature()) {
1335 assert(PCAddr && "Missing return PC information for a call");
1336 addLabelAddress(CallSiteDIE,
1337 getDwarf5OrGNUAttr(dwarf::DW_AT_call_return_pc), PCAddr);
1338 }
1339
1340 if (AllocSiteTy)
1341 addType(CallSiteDIE, AllocSiteTy, dwarf::DW_AT_LLVM_alloc_type);
1342
1343 return CallSiteDIE;
1344}
1345
1347 DIE &CallSiteDIE, SmallVector<DbgCallSiteParam, 4> &Params) {
1348 for (const auto &Param : Params) {
1349 unsigned Register = Param.getRegister();
1350 auto CallSiteDieParam =
1352 getDwarf5OrGNUTag(dwarf::DW_TAG_call_site_parameter));
1353 insertDIE(CallSiteDieParam);
1354 addAddress(*CallSiteDieParam, dwarf::DW_AT_location,
1356
1358 DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
1359 DwarfExpr.setCallSiteParamValueFlag();
1360
1361 DwarfDebug::emitDebugLocValue(*Asm, nullptr, Param.getValue(), DwarfExpr);
1362
1363 addBlock(*CallSiteDieParam, getDwarf5OrGNUAttr(dwarf::DW_AT_call_value),
1364 DwarfExpr.finalize());
1365
1366 CallSiteDIE.addChild(CallSiteDieParam);
1367 }
1368}
1369
1371 const DIImportedEntity *Module) {
1372 DIE *IMDie = DIE::get(DIEValueAllocator, Module->getTag());
1373 insertDIE(Module, IMDie);
1374 DIE *EntityDie;
1375 auto *Entity = Module->getEntity();
1376 if (auto *NS = dyn_cast<DINamespace>(Entity))
1377 EntityDie = getOrCreateNameSpace(NS);
1378 else if (auto *M = dyn_cast<DIModule>(Entity))
1379 EntityDie = getOrCreateModule(M);
1380 else if (auto *SP = dyn_cast<DISubprogram>(Entity)) {
1381 // If there is an abstract subprogram, refer to it. Note that this assumes
1382 // that all the abstract subprograms have been already created (which is
1383 // correct until imported entities get emitted in DwarfDebug::endModule()).
1384 if (auto *AbsSPDie = getAbstractScopeDIEs().lookup(SP))
1385 EntityDie = AbsSPDie;
1386 else
1387 EntityDie = getOrCreateSubprogramDIE(SP, nullptr);
1388 } else if (auto *T = dyn_cast<DIType>(Entity))
1389 EntityDie = getOrCreateTypeDIE(T);
1390 else if (auto *GV = dyn_cast<DIGlobalVariable>(Entity))
1391 EntityDie = getOrCreateGlobalVariableDIE(GV, {});
1392 else if (auto *IE = dyn_cast<DIImportedEntity>(Entity))
1393 EntityDie = getOrCreateImportedEntityDIE(IE);
1394 else
1395 EntityDie = getDIE(Entity);
1396 assert(EntityDie);
1397 addSourceLine(*IMDie, Module->getLine(), /*Column*/ 0, Module->getFile());
1398 addDIEEntry(*IMDie, dwarf::DW_AT_import, *EntityDie);
1399 StringRef Name = Module->getName();
1400 if (!Name.empty()) {
1401 addString(*IMDie, dwarf::DW_AT_name, Name);
1402
1403 // FIXME: if consumers ever start caring about handling
1404 // unnamed import declarations such as `using ::nullptr_t`
1405 // or `using namespace std::ranges`, we could add the
1406 // import declaration into the accelerator table with the
1407 // name being the one of the entity being imported.
1408 DD->addAccelNamespace(*this, CUNode->getNameTableKind(), Name, *IMDie);
1409 }
1410
1411 // This is for imported module with renamed entities (such as variables and
1412 // subprograms).
1413 DINodeArray Elements = Module->getElements();
1414 for (const auto *Element : Elements) {
1415 if (!Element)
1416 continue;
1417 IMDie->addChild(
1419 }
1420
1421 return IMDie;
1422}
1423
1425 const DIImportedEntity *IE) {
1426
1427 // Check for pre-existence.
1428 if (DIE *Die = getDIE(IE))
1429 return Die;
1430
1431 DIE *ContextDIE = getOrCreateContextDIE(IE->getScope());
1432 assert(ContextDIE && "Empty scope for the imported entity!");
1433
1434 DIE *IMDie = constructImportedEntityDIE(IE);
1435 ContextDIE->addChild(IMDie);
1436 return IMDie;
1437}
1438
1440 DIE *D = getDIE(SP);
1441 if (DIE *AbsSPDIE = getAbstractScopeDIEs().lookup(SP)) {
1442 if (D)
1443 // If this subprogram has an abstract definition, reference that
1444 addDIEEntry(*D, dwarf::DW_AT_abstract_origin, *AbsSPDIE);
1445 } else {
1447 if (D)
1448 // And attach the attributes
1450 }
1451}
1452
1454 DbgEntity *AbsEntity = getExistingAbstractEntity(Entity->getEntity());
1455
1456 auto *Die = Entity->getDIE();
1457 /// Label may be used to generate DW_AT_low_pc, so put it outside
1458 /// if/else block.
1459 const DbgLabel *Label = nullptr;
1460 if (AbsEntity && AbsEntity->getDIE()) {
1461 addDIEEntry(*Die, dwarf::DW_AT_abstract_origin, *AbsEntity->getDIE());
1462 Label = dyn_cast<const DbgLabel>(Entity);
1463 } else {
1464 if (const DbgVariable *Var = dyn_cast<const DbgVariable>(Entity))
1466 else if ((Label = dyn_cast<const DbgLabel>(Entity)))
1467 applyLabelAttributes(*Label, *Die);
1468 else
1469 llvm_unreachable("DbgEntity must be DbgVariable or DbgLabel.");
1470 }
1471
1472 if (!Label)
1473 return;
1474
1475 const auto *Sym = Label->getSymbol();
1476 if (!Sym)
1477 return;
1478
1479 addLabelAddress(*Die, dwarf::DW_AT_low_pc, Sym);
1480
1481 // A TAG_label with a name and an AT_low_pc must be placed in debug_names.
1482 if (StringRef Name = Label->getName(); !Name.empty())
1483 getDwarfDebug().addAccelName(*this, CUNode->getNameTableKind(), Name, *Die);
1484}
1485
1487 auto AttachAO = [&](const DILocalScope *LS, DIE *ScopeDIE) {
1488 if (auto *AbsLSDie = getAbstractScopeDIEs().lookup(LS))
1489 addDIEEntry(*ScopeDIE, dwarf::DW_AT_abstract_origin, *AbsLSDie);
1490 };
1491
1492 for (auto [LScope, ScopeDIE] : LexicalBlockDIEs)
1493 AttachAO(LScope, ScopeDIE);
1494 for (auto &[LScope, ScopeDIEs] : InlinedLocalScopeDIEs)
1495 for (auto *ScopeDIE : ScopeDIEs)
1496 AttachAO(LScope, ScopeDIE);
1497}
1498
1500 auto &AbstractEntities = getAbstractEntities();
1501 auto I = AbstractEntities.find(Node);
1502 if (I != AbstractEntities.end())
1503 return I->second.get();
1504 return nullptr;
1505}
1506
1508 LexicalScope *Scope) {
1509 assert(Scope && Scope->isAbstractScope());
1510 auto &Entity = getAbstractEntities()[Node];
1512 Entity = std::make_unique<DbgVariable>(cast<const DILocalVariable>(Node),
1513 nullptr /* IA */);
1514 DU->addScopeVariable(Scope, cast<DbgVariable>(Entity.get()));
1515 } else if (isa<const DILabel>(Node)) {
1516 Entity = std::make_unique<DbgLabel>(
1517 cast<const DILabel>(Node), nullptr /* IA */);
1518 DU->addScopeLabel(Scope, cast<DbgLabel>(Entity.get()));
1519 }
1520}
1521
1522void DwarfCompileUnit::emitHeader(bool UseOffsets) {
1523 // Don't bother labeling the .dwo unit, as its offset isn't used.
1524 if (!Skeleton && !DD->useSectionsAsReferences()) {
1525 LabelBegin = Asm->createTempSymbol("cu_begin");
1526 Asm->OutStreamer->emitLabel(LabelBegin);
1527 }
1528
1529 dwarf::UnitType UT = Skeleton ? dwarf::DW_UT_split_compile
1530 : DD->useSplitDwarf() ? dwarf::DW_UT_skeleton
1531 : dwarf::DW_UT_compile;
1532 DwarfUnit::emitCommonHeader(UseOffsets, UT);
1533 if (DD->getDwarfVersion() >= 5 && UT != dwarf::DW_UT_compile)
1534 Asm->emitInt64(getDWOId());
1535}
1536
1538 switch (CUNode->getNameTableKind()) {
1540 return false;
1541 // Opting in to GNU Pubnames/types overrides the default to ensure these are
1542 // generated for things like Gold's gdb_index generation.
1544 return true;
1546 return false;
1548 return DD->tuneForGDB() && !includeMinimalInlineScopes() &&
1549 !CUNode->isDebugDirectivesOnly() &&
1550 DD->getAccelTableKind() != AccelTableKind::Apple &&
1551 DD->getDwarfVersion() < 5;
1552 }
1553 llvm_unreachable("Unhandled DICompileUnit::DebugNameTableKind enum");
1554}
1555
1556/// addGlobalName - Add a new global name to the compile unit.
1558 const DIScope *Context) {
1559 if (!hasDwarfPubSections())
1560 return;
1561 std::string FullName = getParentContextString(Context) + Name.str();
1562 GlobalNames[FullName] = &Die;
1563}
1564
1566 const DIScope *Context) {
1567 if (!hasDwarfPubSections())
1568 return;
1569 std::string FullName = getParentContextString(Context) + Name.str();
1570 // Insert, allowing the entry to remain as-is if it's already present
1571 // This way the CU-level type DIE is preferred over the "can't describe this
1572 // type as a unit offset because it's not really in the CU at all, it's only
1573 // in a type unit"
1574 GlobalNames.insert(std::make_pair(std::move(FullName), &getUnitDie()));
1575}
1576
1577/// Add a new global type to the unit.
1579 const DIScope *Context) {
1580 if (!hasDwarfPubSections())
1581 return;
1582 std::string FullName = getParentContextString(Context) + Ty->getName().str();
1583 GlobalTypes[FullName] = &Die;
1584}
1585
1587 const DIScope *Context) {
1588 if (!hasDwarfPubSections())
1589 return;
1590 std::string FullName = getParentContextString(Context) + Ty->getName().str();
1591 // Insert, allowing the entry to remain as-is if it's already present
1592 // This way the CU-level type DIE is preferred over the "can't describe this
1593 // type as a unit offset because it's not really in the CU at all, it's only
1594 // in a type unit"
1595 GlobalTypes.insert(std::make_pair(std::move(FullName), &getUnitDie()));
1596}
1597
1599 MachineLocation Location) {
1600 auto *Single = std::get_if<Loc::Single>(&DV);
1601 if (Single && Single->getExpr())
1602 addComplexAddress(Single->getExpr(), Die, dwarf::DW_AT_location, Location);
1603 else
1604 addAddress(Die, dwarf::DW_AT_location, Location);
1605}
1606
1607void DwarfCompileUnit::addLocationWithExpr(DIE &Die, dwarf::Attribute Attribute,
1608 const MachineLocation &Location,
1609 ArrayRef<uint64_t> Expr) {
1611 DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
1612 if (Location.isIndirect())
1613 DwarfExpr.setMemoryLocationKind();
1614
1615 DIExpressionCursor Cursor(Expr);
1617 if (!DwarfExpr.addMachineRegExpression(TRI, Cursor, Location.getReg()))
1618 return;
1619 DwarfExpr.addExpression(std::move(Cursor));
1620
1621 // Now attach the location information to the DIE.
1622 addBlock(Die, Attribute, DwarfExpr.finalize());
1623
1624 if (DwarfExpr.TagOffset)
1625 addUInt(Die, dwarf::DW_AT_LLVM_tag_offset, dwarf::DW_FORM_data1,
1626 *DwarfExpr.TagOffset);
1627}
1628
1629/// Add an address attribute to a die based on the location provided.
1631 const MachineLocation &Location) {
1632 addLocationWithExpr(Die, Attribute, Location, {});
1633}
1634
1635/// Add a memory location exprloc to \p DIE with attribute \p Attribute
1636/// at \p Location + \p Offset.
1638 const MachineLocation &Location,
1639 int64_t Offset) {
1640 assert(Location.isIndirect() && "Memory loc should be indirect");
1643 addLocationWithExpr(Die, Attribute, Location, Ops);
1644}
1645
1646/// Start with the address based on the location provided, and generate the
1647/// DWARF information necessary to find the actual variable given the extra
1648/// address information encoded in the DbgVariable, starting from the starting
1649/// location. Add the DWARF information to the die.
1652 const MachineLocation &Location) {
1654 DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
1655 DwarfExpr.addFragmentOffset(DIExpr);
1656 DwarfExpr.setLocation(Location, DIExpr);
1657
1658 DIExpressionCursor Cursor(DIExpr);
1659
1660 if (DIExpr->isEntryValue())
1661 DwarfExpr.beginEntryValueExpression(Cursor);
1662
1663 const TargetRegisterInfo &TRI = *Asm->MF->getSubtarget().getRegisterInfo();
1664 if (!DwarfExpr.addMachineRegExpression(TRI, Cursor, Location.getReg()))
1665 return;
1666 DwarfExpr.addExpression(std::move(Cursor));
1667
1668 // Now attach the location information to the DIE.
1669 addBlock(Die, Attribute, DwarfExpr.finalize());
1670
1671 if (DwarfExpr.TagOffset)
1672 addUInt(Die, dwarf::DW_AT_LLVM_tag_offset, dwarf::DW_FORM_data1,
1673 *DwarfExpr.TagOffset);
1674}
1675
1676/// Add a Dwarf loclistptr attribute data and value.
1678 unsigned Index) {
1679 dwarf::Form Form = (DD->getDwarfVersion() >= 5)
1680 ? dwarf::DW_FORM_loclistx
1681 : DD->getDwarfSectionOffsetForm();
1682 addAttribute(Die, Attribute, Form, DIELocList(Index));
1683}
1684
1686 DIE &VariableDie) {
1687 StringRef Name = Var.getName();
1688 if (!Name.empty())
1689 addString(VariableDie, dwarf::DW_AT_name, Name);
1690 const auto *DIVar = Var.getVariable();
1691 if (DIVar) {
1692 if (uint32_t AlignInBytes = DIVar->getAlignInBytes())
1693 addUInt(VariableDie, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1694 AlignInBytes);
1695 addAnnotation(VariableDie, DIVar->getAnnotations());
1696 }
1697
1698 addSourceLine(VariableDie, DIVar);
1699 addType(VariableDie, Var.getType());
1700 if (Var.isArtificial())
1701 addFlag(VariableDie, dwarf::DW_AT_artificial);
1702}
1703
1705 DIE &LabelDie) {
1706 StringRef Name = Label.getName();
1707 if (!Name.empty())
1708 addString(LabelDie, dwarf::DW_AT_name, Name);
1709 const auto *DILabel = Label.getLabel();
1710 addSourceLine(LabelDie, DILabel);
1711 if (DILabel->isArtificial())
1712 addFlag(LabelDie, dwarf::DW_AT_artificial);
1714 addUInt(LabelDie, dwarf::DW_AT_LLVM_coro_suspend_idx, std::nullopt,
1716}
1717
1718/// Add a Dwarf expression attribute data and value.
1720 const MCExpr *Expr) {
1721 addAttribute(Die, (dwarf::Attribute)0, Form, DIEExpr(Expr));
1722}
1723
1725 const DISubprogram *SP, DIE &SPDie) {
1726 auto *SPDecl = SP->getDeclaration();
1727 auto *Context = SPDecl ? SPDecl->getScope() : SP->getScope();
1729 addGlobalName(SP->getName(), SPDie, Context);
1730}
1731
1732bool DwarfCompileUnit::isDwoUnit() const {
1733 return DD->useSplitDwarf() && Skeleton;
1734}
1735
1736void DwarfCompileUnit::finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) {
1737 constructTypeDIE(D, CTy);
1738}
1739
1742 (DD->useSplitDwarf() && !Skeleton);
1743}
1744
1748
1750 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
1751 MCSymbol *Label = DD->getAddressPool().getLabel();
1753 DD->getDwarfVersion() >= 5 ? dwarf::DW_AT_addr_base
1754 : dwarf::DW_AT_GNU_addr_base,
1755 Label, TLOF.getDwarfAddrSection()->getBeginSymbol());
1756}
1757
1759 addAttribute(Die, (dwarf::Attribute)0, dwarf::DW_FORM_udata,
1760 new (DIEValueAllocator) DIEBaseTypeRef(this, Idx));
1761}
1762
1764 // Insert the base_type DIEs directly after the CU so that their offsets will
1765 // fit in the fixed size ULEB128 used inside the location expressions.
1766 // Maintain order by iterating backwards and inserting to the front of CU
1767 // child list.
1768 for (auto &Btr : reverse(ExprRefedBaseTypes)) {
1769 DIE &Die = getUnitDie().addChildFront(
1770 DIE::get(DIEValueAllocator, dwarf::DW_TAG_base_type));
1771 SmallString<32> Str;
1772 addString(Die, dwarf::DW_AT_name,
1774 "_" + Twine(Btr.BitSize)).toStringRef(Str));
1775 addUInt(Die, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, Btr.Encoding);
1776 // Round up to smallest number of bytes that contains this number of bits.
1777 // ExprRefedBaseTypes is populated with types referenced by
1778 // DW_OP_LLVM_convert operations in location expressions. These are often
1779 // byte-sized, but one common counter-example is 1-bit sized conversions
1780 // from `i1` types. TODO: Should these use DW_AT_bit_size? See
1781 // DwarfUnit::constructTypeDIE.
1782 addUInt(Die, dwarf::DW_AT_byte_size, std::nullopt,
1783 divideCeil(Btr.BitSize, 8));
1784 Btr.Die = &Die;
1785 }
1786}
1787
1789 // Assume if there is an abstract tree all the DIEs are already emitted.
1790 bool isAbstract = getAbstractScopeDIEs().count(LB->getSubprogram());
1791 if (isAbstract) {
1792 auto &DIEs = getAbstractScopeDIEs();
1793 if (auto It = DIEs.find(LB); It != DIEs.end())
1794 return It->second;
1795 }
1796 assert(!isAbstract && "Missed lexical block DIE in abstract tree!");
1797
1798 // Check if we have a concrete DIE.
1799 if (auto It = LexicalBlockDIEs.find(LB); It != LexicalBlockDIEs.end())
1800 return It->second;
1801
1802 // If nothing available found, we cannot just create a new lexical block,
1803 // because it isn't known where to put it into the DIE tree.
1804 // So, we may only try to find the most close avaiable parent DIE.
1806}
1807
1809 if (isa_and_nonnull<DILocalScope>(Context)) {
1810 if (auto *LFScope = dyn_cast<DILexicalBlockFile>(Context))
1811 Context = LFScope->getNonLexicalBlockFileScope();
1812 if (auto *LScope = dyn_cast<DILexicalBlock>(Context))
1813 return getLocalContextDIE(LScope);
1814
1815 // Otherwise the context must be a DISubprogram.
1816 auto *SPScope = cast<DISubprogram>(Context);
1817 const auto &DIEs = getAbstractScopeDIEs();
1818 if (auto It = DIEs.find(SPScope); It != DIEs.end())
1819 return It->second;
1820 }
1821 return DwarfUnit::getOrCreateContextDIE(Context);
1822}
1823
1825 const Function *F,
1826 bool Minimal) {
1827 if (!F && SP->isDefinition()) {
1828 F = DD->getLexicalScopes().getFunction(SP);
1829
1830 if (!F) {
1831 // SP may belong to another CU. Determine the CU similarly
1832 // to DwarfDebug::constructAbstractSubprogramScopeDIE.
1833 return &DD->getOrCreateAbstractSubprogramCU(SP, *this)
1834 .getOrCreateAbstractSubprogramDIE(SP);
1835 }
1836 }
1837
1838 return DwarfUnit::getOrCreateSubprogramDIE(SP, F, Minimal);
1839}
1840
1842 const DwarfDebug &DD, const DISubprogram &CalleeSP, DIE &CalleeDIE) {
1844 !CalleeSP.isDefinition() &&
1845 !CalleeDIE.findAttribute(dwarf::DW_AT_linkage_name)) {
1846 addLinkageName(CalleeDIE, CalleeSP.getLinkageName());
1847 }
1848}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
BitTracker BT
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
dxil translate DXIL Translate Metadata
static SmallVector< DbgVariable *, 8 > sortLocalVars(SmallVectorImpl< DbgVariable * > &Input)
Sort local variables so that variables appearing inside of helper expressions come first.
static SmallVector< const DIVariable *, 2 > dependencies(DbgVariable *Var)
Return all DIVariables that appear in count: expressions.
static cl::opt< bool > EmitFuncLineTableOffsetsOption("emit-func-debug-line-table-offsets", cl::Hidden, cl::desc("Include line table offset in function's debug info and emit end " "sequence after each function's line data."), cl::init(false))
static bool AddLinkageNamesToDeclCallOriginsForTuning(const DwarfDebug *DD)
static dwarf::Tag GetCompileUnitType(UnitKind Kind, DwarfDebug *DW)
static cl::opt< cl::boolOrDefault > AddLinkageNamesToDeclCallOrigins("add-linkage-names-to-declaration-call-origins", cl::Hidden, cl::desc("Add DW_AT_linkage_name to function declaration DIEs " "referenced by DW_AT_call_origin attributes. Enabled by default " "for -gsce debugger tuning."))
Query value using AddLinkageNamesToDeclCallOriginsForTuning.
This file contains constants used for implementing Dwarf debug support.
static bool lookup(const GsymReader &GR, DataExtractor &Data, uint64_t &Offset, uint64_t BaseAddr, uint64_t Addr, SourceLocations &SrcLocs, llvm::Error &Err)
A Lookup helper functions.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define T
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallString class.
The Input class is used to parse a yaml document into in-memory structs and vectors.
uint64_t getZExtValue() const
Get zero extended value.
Definition APInt.h:1555
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition APInt.h:1503
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
size - Get the array size.
Definition ArrayRef.h:142
This class is intended to be used as a driving class for all asm writers.
Definition AsmPrinter.h:91
MachineFunction * MF
The current machine function.
Definition AsmPrinter.h:109
const DataLayout & getDataLayout() const
Return information about data layout.
MCSymbol * GetExternalSymbolSymbol(const Twine &Sym) const
Return the MCSymbol for the specified ExternalSymbol.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:105
Debug common block.
DIFile * getFile() const
unsigned getLineNo() const
StringRef getName() const
DIScope * getScope() const
DIGlobalVariable * getDecl() const
static LLVM_ABI std::optional< DebugEmissionKind > getEmissionKind(StringRef Str)
A BaseTypeRef DIE.
Definition DIE.h:363
A BaseTypeRef DIE.
Definition DIE.h:244
DIEBlock - Represents a block of values.
Definition DIE.h:1056
DwarfExpression implementation for singular DW_AT_location.
An expression DIE.
Definition DIE.h:208
An integer value DIE.
Definition DIE.h:169
A label DIE.
Definition DIE.h:226
Represents a pointer to a location list in the debug_loc section.
Definition DIE.h:344
DIELoc - Represents an expression location.
Definition DIE.h:1020
DIE & getUnitDie()
Definition DIE.h:1009
A list of DIE values.
Definition DIE.h:698
A structured debug information entry.
Definition DIE.h:828
LLVM_ABI DIEValue findAttribute(dwarf::Attribute Attribute) const
Find a value in the DIE with the attribute given.
Definition DIE.cpp:210
DIE & addChild(DIE *Child)
Add a child to the DIE.
Definition DIE.h:944
DIE & addChildFront(DIE *Child)
Definition DIE.h:951
static DIE * get(BumpPtrAllocator &Alloc, dwarf::Tag Tag)
Definition DIE.h:858
LLVM_ABI const DIE * getUnitDie() const
Climb up the parent chain to get the compile unit or type unit DIE that this DIE belongs to.
Definition DIE.cpp:191
Holds a DIExpression and keeps track of how many operands have been consumed so far.
DWARF expression.
element_iterator elements_end() const
LLVM_ABI bool isEntryValue() const
Check if the expression consists of exactly one entry value operand.
static LLVM_ABI void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
element_iterator elements_begin() const
ArrayRef< uint64_t > getElements() const
uint64_t getElement(unsigned I) const
LLVM_ABI std::optional< SignedOrUnsignedConstant > isConstant() const
Determine whether this represents a constant value, if so.
DIDerivedType * getStaticDataMemberDeclaration() const
MDTuple * getTemplateParams() const
StringRef getLinkageName() const
StringRef getDisplayName() const
DINodeArray getAnnotations() const
An imported module (C++ using directive or similar).
bool isArtificial() const
std::optional< unsigned > getCoroSuspendIdx() const
DILocalScope * getScope() const
Debug lexical block.
A scope for locals.
LLVM_ABI DISubprogram * getSubprogram() const
Get the subprogram for this scope.
LLVM_ABI DILocalScope * getNonLexicalBlockFileScope() const
Get the first non DILexicalBlockFile scope of this scope.
Tagged DWARF-like metadata node.
LLVM_ABI dwarf::Tag getTag() const
Base class for scope-like contexts.
Subprogram description. Uses SubclassData1.
Base class for types.
uint32_t getAlignInBytes() const
DIScope * getScope() const
DIType * getType() const
StringRef getName() const
LLVM_ABI unsigned getPointerSize(unsigned AS=0) const
The pointer representation size in bytes, rounded up to a whole number of bytes.
This class is defined as the common parent of DbgVariable and DbgLabel such that it could levarage po...
Definition DwarfDebug.h:66
const DINode * getEntity() const
Accessors.
Definition DwarfDebug.h:86
void setDIE(DIE &D)
Definition DwarfDebug.h:92
DIE * getDIE() const
Definition DwarfDebug.h:88
This class is used to track label information.
Definition DwarfDebug.h:290
A single location or constant within a variable location description, with either a single entry (wit...
The location of a single variable, composed of an expression and 0 or more DbgValueLocEntries.
ArrayRef< DbgValueLocEntry > getLocEntries() const
bool isVariadic() const
This class is used to track local variable information.
Definition DwarfDebug.h:215
bool isArtificial() const
Return true if DbgVariable is artificial.
Definition DwarfDebug.h:263
dwarf::Tag getTag() const
Definition DwarfDebug.h:254
bool isObjectPointer() const
Definition DwarfDebug.h:271
const DILocalVariable * getVariable() const
Definition DwarfDebug.h:247
StringRef getName() const
Definition DwarfDebug.h:251
const DIType * getType() const
Loc::Variant & asVariant()
To workaround P2162R0 https://github.com/cplusplus/papers/issues/873 the base class subobject needs t...
Definition DwarfDebug.h:221
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition DenseMap.h:205
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition DenseMap.h:241
bool useGNUAnalogForDwarf5Feature() const
Whether to use the GNU analog for a DWARF5 tag, attribute, or location atom.
void constructCallSiteParmEntryDIEs(DIE &CallSiteDIE, SmallVector< DbgCallSiteParam, 4 > &Params)
Construct call site parameter DIEs for the CallSiteDIE.
void addLinkageNamesToDeclarations(const DwarfDebug &DD, const DISubprogram &CalleeSP, DIE &CalleeDIE)
void attachLowHighPC(DIE &D, const MCSymbol *Begin, const MCSymbol *End)
void emitHeader(bool UseOffsets) override
Emit the header for this unit, not including the initial length field.
dwarf::Tag getDwarf5OrGNUTag(dwarf::Tag Tag) const
This takes a DWARF 5 tag and returns it or a GNU analog.
void constructAbstractSubprogramScopeDIE(LexicalScope *Scope)
bool includeMinimalInlineScopes() const
DIE * getOrCreateImportedEntityDIE(const DIImportedEntity *IE)
Get or create a DIE for an imported entity.
void addBaseTypeRef(DIEValueList &Die, int64_t Idx)
void addGlobalNameForTypeUnit(StringRef Name, const DIScope *Context)
Add a new global name present in a type unit to this compile unit.
void finishEntityDefinition(const DbgEntity *Entity)
void addMemoryLocation(DIE &Die, dwarf::Attribute Attribute, const MachineLocation &Location, int64_t Offset)
Add a memory location exprloc to DIE with attribute Attribute at Location + Offset.
void addRange(RangeSpan Range)
addRange - Add an address range to the list of ranges for this unit.
void addAddrTableBase()
Add the DW_AT_addr_base attribute to the unit DIE.
std::vector< BaseTypeRef > ExprRefedBaseTypes
DIE * constructInlinedScopeDIE(LexicalScope *Scope, DIE &ParentScopeDIE)
This scope represents an inlined body of a function.
void addScopeRangeList(DIE &ScopeDIE, SmallVector< RangeSpan, 2 > Range)
A helper function to construct a RangeSpanList for a given lexical scope.
uint64_t getDWOId() const
DIE * getOrCreateCommonBlock(const DICommonBlock *CB, ArrayRef< GlobalExpr > GlobalExprs)
void addVariableAddress(const DbgVariable &DV, DIE &Die, MachineLocation Location)
Add DW_AT_location attribute for a DbgVariable based on provided MachineLocation.
DIE & constructCallSiteEntryDIE(DIE &ScopeDIE, const DISubprogram *CalleeSP, const Function *CalleeF, bool IsTail, const MCSymbol *PCAddr, const MCSymbol *CallAddr, MachineLocation CallTarget, int64_t Offset, DIType *AllocSiteTy)
Construct a call site entry DIE describing a call within Scope to a callee described by CalleeSP and ...
DIE & getOrCreateAbstractSubprogramDIE(const DISubprogram *SP)
Create an abstract subprogram DIE, that should later be populated by constructAbstractSubprogramScope...
DIE & constructSubprogramScopeDIE(const DISubprogram *Sub, const Function &F, LexicalScope *Scope, MCSymbol *LineTableSym)
Construct a DIE for this subprogram scope.
void addGlobalName(StringRef Name, const DIE &Die, const DIScope *Context) override
Add a new global name to the compile unit.
DIE & updateSubprogramScopeDIE(const DISubprogram *SP, const Function &F, MCSymbol *LineTableSym)
Find DIE for the given subprogram and attach appropriate DW_AT_low_pc, DW_AT_high_pc and DW_AT_LLVM_s...
void createAbstractEntity(const DINode *Node, LexicalScope *Scope)
void applyStmtList(DIE &D)
Apply the DW_AT_stmt_list from this compile unit to the specified DIE.
DIE * getOrCreateSubprogramDIE(const DISubprogram *SP, const Function *F, bool Minimal=false) override
DIE * getOrCreateContextDIE(const DIScope *Ty) override
Construct a DIE for a given scope.
void applyCommonDbgVariableAttributes(const DbgVariable &Var, DIE &VariableDie)
Add attributes to Var which reflect the common attributes of VariableDie, namely those which are not ...
DIE * constructVariableDIE(DbgVariable &DV, bool Abstract=false)
Construct a DIE for the given DbgVariable.
dwarf::LocationAtom getDwarf5OrGNULocationAtom(dwarf::LocationAtom Loc) const
This takes a DWARF 5 location atom and either returns it or a GNU analog.
DIE * getLocalContextDIE(const DILexicalBlock *LB)
Get DW_TAG_lexical_block for the given DILexicalBlock if available, or the most close parent DIE,...
DIE * getOrCreateGlobalVariableDIE(const DIGlobalVariable *GV, ArrayRef< GlobalExpr > GlobalExprs)
Get or create global variable DIE.
void addLocationAttribute(DIE *ToDIE, const DIGlobalVariable *GV, ArrayRef< GlobalExpr > GlobalExprs)
void applySubprogramAttributesToDefinition(const DISubprogram *SP, DIE &SPDie)
DIE * createAndAddScopeChildren(LexicalScope *Scope, DIE &ScopeDIE)
void addExpr(DIELoc &Die, dwarf::Form Form, const MCExpr *Expr)
Add a Dwarf expression attribute data and value.
DIE * getOrCreateLexicalBlockDIE(LexicalScope *Scope, DIE &ParentDIE)
Get if available or create a new DW_TAG_lexical_block for the given LexicalScope and attach DW_AT_low...
dwarf::Attribute getDwarf5OrGNUAttr(dwarf::Attribute Attr) const
This takes a DWARF 5 attribute and returns it or a GNU analog.
void addAddress(DIE &Die, dwarf::Attribute Attribute, const MachineLocation &Location)
Add an address attribute to a die based on the location provided.
void applyLabelAttributes(const DbgLabel &Label, DIE &LabelDie)
void addLocalLabelAddress(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Label)
addLocalLabelAddress - Add a dwarf label attribute data and value using DW_FORM_addr only.
void addGlobalTypeImpl(const DIType *Ty, const DIE &Die, const DIScope *Context) override
Add a new global type to the compile unit.
unsigned getOrCreateSourceID(const DIFile *File) override
Look up the source ID for the given file.
void constructScopeDIE(LexicalScope *Scope, DIE &ParentScopeDIE)
DwarfCompileUnit(unsigned UID, const DICompileUnit *Node, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU, UnitKind Kind=UnitKind::Full)
DIE * constructLabelDIE(DbgLabel &DL, const LexicalScope &Scope)
Construct a DIE for the given DbgLabel.
void addGlobalTypeUnitType(const DIType *Ty, const DIScope *Context)
Add a new global type present in a type unit to this compile unit.
DbgEntity * getExistingAbstractEntity(const DINode *Node)
void addLabelAddress(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Label)
addLabelAddress - Add a dwarf label attribute data and value using either DW_FORM_addr or DW_FORM_GNU...
void addLocationList(DIE &Die, dwarf::Attribute Attribute, unsigned Index)
Add a Dwarf loclistptr attribute data and value.
void addComplexAddress(const DIExpression *DIExpr, DIE &Die, dwarf::Attribute Attribute, const MachineLocation &Location)
Start with the address based on the location provided, and generate the DWARF information necessary t...
DIE * constructImportedEntityDIE(const DIImportedEntity *IE)
DwarfCompileUnit & getCU() override
void attachRangesOrLowHighPC(DIE &D, SmallVector< RangeSpan, 2 > Ranges)
void finishSubprogramDefinition(const DISubprogram *SP)
Collects and handles dwarf debug information.
Definition DwarfDebug.h:352
uint16_t getDwarfVersion() const
Returns the Dwarf Version.
DwarfCompileUnit * lookupCU(const DIE *Die)
Find the matching DwarfCompileUnit for the given CU DIE.
Definition DwarfDebug.h:949
static void emitDebugLocValue(const AsmPrinter &AP, const DIBasicType *BT, const DbgValueLoc &Value, DwarfExpression &DwarfExpr)
bool useSplitDwarf() const
Returns whether or not to change the current debug info for the split dwarf proposal support.
Definition DwarfDebug.h:869
virtual void addTargetVariableAttributes(DwarfCompileUnit &CU, DIE &Die, std::optional< unsigned > TargetAddrSpace, VariableLocationKind VarLocKind, const GlobalVariable *GV=nullptr) const
Add target-specific attributes to a variable DIE (e.g.
Definition DwarfDebug.h:766
void addAccelName(const DwarfUnit &Unit, const DICompileUnit::DebugNameTableKind NameTableKind, StringRef Name, const DIE &Die)
void setLocation(const MachineLocation &Loc, const DIExpression *DIExpr)
Set the location (Loc) and DIExpression (DIExpr) to describe.
void addFragmentOffset(const DIExpression *Expr)
If applicable, emit an empty DW_OP_piece / DW_OP_bit_piece to advance to the fragment described by Ex...
std::optional< uint8_t > TagOffset
void setCallSiteParamValueFlag()
Lock this down to become a call site parameter location.
bool addMachineRegExpression(const TargetRegisterInfo &TRI, DIExpressionCursor &Expr, llvm::Register MachineReg, unsigned FragmentOffsetInBits=0)
Emit a machine register location.
void addExpression(DIExpressionCursor &&Expr)
Emit all remaining operations in the DIExpressionCursor.
void addWasmLocation(unsigned Index, uint64_t Offset)
Emit location information expressed via WebAssembly location + offset The Index is an identifier for ...
void beginEntryValueExpression(DIExpressionCursor &ExprCursor)
Begin emission of an entry value dwarf operation.
virtual DIE * getOrCreateTypeDIE(const MDNode *TyNode)
Find existing DIE or create new DIE for the given type.
DwarfDebug & getDwarfDebug() const
Definition DwarfUnit.h:113
void addAnnotation(DIE &Buffer, DINodeArray Annotations)
Add DW_TAG_LLVM_annotation.
void addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Loc)
Add block data.
void addTemplateParams(DIE &Buffer, DINodeArray TParams)
Add template parameters in buffer.
virtual DIE * getOrCreateContextDIE(const DIScope *Context)
Get context owner's DIE.
void addAttribute(DIEValueList &Die, dwarf::Attribute Attribute, dwarf::Form Form, T &&Value)
Definition DwarfUnit.h:85
void addOpAddress(DIELoc &Die, const MCSymbol *Sym)
Add a dwarf op address data and value using the form given and an op of either DW_FORM_addr or DW_FOR...
void addUInt(DIEValueList &Die, dwarf::Attribute Attribute, std::optional< dwarf::Form > Form, uint64_t Integer)
Add an unsigned integer attribute data and value.
void addString(DIE &Die, dwarf::Attribute Attribute, StringRef Str)
Add a string attribute data and value.
void addConstantValue(DIE &Die, const ConstantInt *CI, const DIType *Ty)
Add constant value entry in variable DIE.
DIE * getOrCreateNameSpace(const DINamespace *NS)
void insertDIE(const DINode *Desc, DIE *D)
Insert DIE into the map.
void addSectionDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo)
addSectionDelta - Add a label delta attribute data and value.
bool shouldPlaceInUnitDIE(const DISubprogram *SP, bool Minimal)
Definition DwarfUnit.h:352
DwarfDebug * DD
Definition DwarfUnit.h:56
const DICompileUnit * CUNode
MDNode for the compile unit.
Definition DwarfUnit.h:41
virtual DIE * getOrCreateSubprogramDIE(const DISubprogram *SP, const Function *FnHint, bool Minimal=false)
DIE * getOrCreateSubprogramContextDIE(const DISubprogram *SP, bool IgnoreScope)
Definition DwarfUnit.h:357
DIE * getDIE(const DINode *D) const
Returns the DIE map slot for the specified debug variable.
MCSymbol * LabelBegin
The start of the unit within its section.
Definition DwarfUnit.h:50
void addSInt(DIEValueList &Die, dwarf::Attribute Attribute, std::optional< dwarf::Form > Form, int64_t Integer)
Add an signed integer attribute data and value.
DwarfUnit(dwarf::Tag, const DICompileUnit *Node, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU, unsigned UniqueID=0)
Definition DwarfUnit.cpp:82
void addLabelDelta(DIEValueList &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo)
Add a label delta attribute data and value.
void addLinkageName(DIE &Die, StringRef LinkageName)
Add a linkage name, if it isn't empty.
std::string getParentContextString(const DIScope *Context) const
Get string containing language specific context for a global name.
void addSourceLine(DIE &Die, unsigned Line, unsigned Column, const DIFile *File)
Add location information to specified debug information entry.
void emitCommonHeader(bool UseOffsets, dwarf::UnitType UT)
Emit the common part of the header for this unit.
BumpPtrAllocator DIEValueAllocator
Definition DwarfUnit.h:44
DIE * getOrCreateModule(const DIModule *M)
const DICompileUnit * getCUNode() const
Definition DwarfUnit.h:112
DIE & createAndAddDIE(dwarf::Tag Tag, DIE &Parent, const DINode *N=nullptr)
Create a DIE with the given Tag, add the DIE to its parent, and call insertDIE if MD is not null.
DwarfFile * DU
Definition DwarfUnit.h:57
DIE * getOrCreateStaticMemberDIE(const DIDerivedType *DT)
Create new static data member DIE.
void addLabel(DIEValueList &Die, dwarf::Attribute Attribute, dwarf::Form Form, const MCSymbol *Label)
Add a Dwarf label attribute data and value.
void addConstantFPValue(DIE &Die, const ConstantFP *CFP)
Add constant value entry in variable DIE.
void addSectionLabel(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Label, const MCSymbol *Sec)
Add a Dwarf section label attribute data and value.
void addPoolOpAddress(DIEValueList &Die, const MCSymbol *Label)
void constructTypeDIE(DIE &Buffer, const DICompositeType *CTy)
MCSymbol * EndLabel
Emitted at the end of the CU and used to compute the CU Length field.
Definition DwarfUnit.h:53
void addFlag(DIE &Die, dwarf::Attribute Attribute)
Add a flag that is true to the DIE.
AsmPrinter * Asm
Target of Dwarf emission.
Definition DwarfUnit.h:47
unsigned getUniqueID() const
Gets Unique ID for this unit.
Definition DwarfUnit.h:102
void addType(DIE &Entity, const DIType *Ty, dwarf::Attribute Attribute=dwarf::DW_AT_type)
Add a new type attribute to the specified entity.
void applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie, bool SkipSPAttributes=false)
void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry)
Add a DIE attribute data and value.
This class is used to track scope information.
Multi-value location description.
Definition DwarfDebug.h:143
unsigned getDebugLocListIndex() const
Definition DwarfDebug.h:154
std::optional< uint8_t > getDebugLocListTagOffset() const
Definition DwarfDebug.h:155
Single value location description.
Definition DwarfDebug.h:132
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
MCSection * getDwarfRangesSection() const
MCSection * getDwarfAddrSection() const
MCSection * getDwarfLineSection() const
MCSymbol * getBeginSymbol()
Definition MCSection.h:589
void setType(wasm::WasmSymbolType type)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition MCSymbol.h:233
Tuple of metadata.
Definition Metadata.h:1500
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
unsigned getReg() const
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
StringRef getName() const
Get a short "name" for the module.
Definition Module.h:269
Wrapper class representing virtual and physical registers.
Definition Register.h:20
static constexpr bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
Definition Register.h:60
Implements a dense probed hash-table based set with some number of buckets stored inline.
Definition DenseSet.h:291
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h:140
Information about stack frame layout on the target.
virtual DwarfFrameBase getDwarfFrameBase(const MachineFunction &MF) const
Return the frame base information to be encoded in the DWARF subprogram debug info.
virtual StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const
getFrameIndexReference - This method should return the base register and offset used to reference a f...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
Definition Twine.h:461
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:202
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition DenseSet.h:180
A DeclContext is a named program scope that is used for ODR uniquing of types.
bool tuneForSCE() const
Definition DwarfDebug.h:974
LLVM_ABI StringRef AttributeEncodingString(unsigned Encoding)
Definition Dwarf.cpp:263
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ Entry
Definition COFF.h:862
initializer< Ty > init(const Ty &Val)
@ DW_INL_inlined
Definition Dwarf.h:777
Attribute
Attributes.
Definition Dwarf.h:125
UnitType
Constants for unit types in DWARF v5.
Definition Dwarf.h:896
@ WASM_TYPE_I64
Definition Wasm.h:57
@ WASM_TYPE_I32
Definition Wasm.h:56
@ WASM_SYMBOL_TYPE_GLOBAL
Definition Wasm.h:231
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
Definition Casting.h:732
bool isRangeRelaxable(const MCSymbol *Begin, const MCSymbol *End)
Definition MCSymbol.cpp:94
bool isa_and_nonnull(const Y &Val)
Definition Casting.h:676
std::pair< const MachineInstr *, const MachineInstr * > InsnRange
This is used to track range of instructions with identical lexical scope.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1746
auto reverse(ContainerTy &&C)
Definition STLExtras.h:408
@ Apple
.apple_names, .apple_namespaces, .apple_types, .apple_objc.
Definition DwarfDebug.h:347
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
@ Global
Append to llvm.global_dtors.
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
Definition MathExtras.h:394
@ Sub
Subtraction of integers.
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
Definition STLExtras.h:2012
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
LLVM_ABI DISubprogram * getDISubprogram(const MDNode *Scope)
Find subprogram that is enclosing this scope.
Single location defined by (potentially multiple) EntryValueInfo.
Definition DwarfDebug.h:173
std::set< EntryValueInfo > EntryValues
Definition DwarfDebug.h:174
Single location defined by (potentially multiple) MMI entries.
Definition DwarfDebug.h:160
const std::set< FrameIndexExpr > & getFrameIndexExprs() const
Get the FI entries, sorted by fragment offset.
const MCSymbol * End
Definition DwarfFile.h:41
const MCSymbol * Begin
Definition DwarfFile.h:40
Helper used to pair up a symbol and its DWARF compile unit.
Definition DwarfDebug.h:336
union llvm::TargetFrameLowering::DwarfFrameBase::@004076321055032247336074224075335064105264310375 Location
enum llvm::TargetFrameLowering::DwarfFrameBase::FrameBaseKind Kind