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