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