Thanks to visit codestin.com
Credit goes to llvm.org

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)
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) {
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 =
119 DD->useAddrOffsetForm() || DD->useAddrOffsetExpressions();
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");
139 if (DD->useAddrOffsetExpressions()) {
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() &&
278 !Asm->getObjFileLowering().supportDebugThreadLocalLocation())
279 continue;
280
281 if (!Loc) {
282 addToAccelTable = true;
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,
341 Asm->getObjFileLowering().getDebugThreadLocalSymbol(Sym));
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() &&
353 Asm->TM.getRelocationModel() == Reloc::PIC_) {
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 ||
361 Asm->TM.getRelocationModel() == Reloc::ROPI_RWPI) &&
362 !Asm->getObjFileLowering()
363 .getKindForGlobal(Global, Asm->TM)
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,
370 Asm->getObjFileLowering().getIndirectSymViaRWPI(Sym));
371 // Base register
372 Register BaseReg = Asm->getObjFileLowering().getStaticBase();
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) {
409 DD->addAccelName(*this, CUNode->getNameTableKind(), GV->getName(),
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() &&
415 DD->useAllLinkageNames())
416 DD->addAccelName(*this, CUNode->getNameTableKind(), 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
439 DD->insertSectionLabel(Range.Begin);
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
462 if (CUNode->isDebugDirectivesOnly())
463 return;
464
465 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
466 if (DD->useSectionsAsReferences()) {
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
483 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
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 const Function &F,
541 MCSymbol *LineTableSym) {
544 // If basic block sections are on, ranges for each basic block section has
545 // to be emitted separately.
546 for (const auto &R : Asm->MBBSectionRanges)
547 BB_List.push_back({R.second.BeginLabel, R.second.EndLabel});
548
549 attachRangesOrLowHighPC(*SPDie, BB_List);
550
551 if (DD->useAppleExtensionAttributes() &&
552 !DD->getCurrentFunction()->getTarget().Options.DisableFramePointerElim(
553 *DD->getCurrentFunction()))
554 addFlag(*SPDie, dwarf::DW_AT_APPLE_omit_frame_ptr);
555
556 if (emitFuncLineTableOffsets() && LineTableSym) {
558 *SPDie, dwarf::DW_AT_LLVM_stmt_sequence, LineTableSym,
559 Asm->getObjFileLowering().getDwarfLineSection()->getBeginSymbol());
560 }
561
562 // Only include DW_AT_frame_base in full debug info
564 const TargetFrameLowering *TFI = Asm->MF->getSubtarget().getFrameLowering();
566 TFI->getDwarfFrameBase(*Asm->MF);
567 switch (FrameBase.Kind) {
570 MachineLocation Location(FrameBase.Location.Reg);
571 addAddress(*SPDie, dwarf::DW_AT_frame_base, Location);
572 }
573 break;
574 }
577 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_call_frame_cfa);
578 if (FrameBase.Location.Offset != 0) {
579 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_consts);
580 addSInt(*Loc, dwarf::DW_FORM_sdata, FrameBase.Location.Offset);
581 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
582 }
583 addBlock(*SPDie, dwarf::DW_AT_frame_base, Loc);
584 break;
585 }
587 // FIXME: duplicated from Target/WebAssembly/WebAssembly.h
588 const unsigned TI_GLOBAL_RELOC = 3;
589 if (FrameBase.Location.WasmLoc.Kind == TI_GLOBAL_RELOC) {
590 // These need to be relocatable.
592 assert(FrameBase.Location.WasmLoc.Index == 0); // Only SP so far.
593 // For now, since we only ever use index 0, this should work as-is.
594 addWasmRelocBaseGlobal(Loc, "__stack_pointer",
595 FrameBase.Location.WasmLoc.Index);
596 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value);
597 addBlock(*SPDie, dwarf::DW_AT_frame_base, Loc);
598 } else {
600 DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
601 DIExpressionCursor Cursor({});
602 DwarfExpr.addWasmLocation(FrameBase.Location.WasmLoc.Kind,
603 FrameBase.Location.WasmLoc.Index);
604 DwarfExpr.addExpression(std::move(Cursor));
605 addBlock(*SPDie, dwarf::DW_AT_frame_base, DwarfExpr.finalize());
606 }
607 break;
608 }
609 }
610 }
611
612 // Add name to the name table, we do this here because we're guaranteed
613 // to have concrete versions of our DW_TAG_subprogram nodes.
614 DD->addSubprogramNames(*this, CUNode->getNameTableKind(), SP, *SPDie);
615
616 return *SPDie;
617}
618
619// Construct a DIE for this scope.
621 DIE &ParentScopeDIE) {
622 if (!Scope || !Scope->getScopeNode())
623 return;
624
625 auto *DS = Scope->getScopeNode();
626
627 assert((Scope->getInlinedAt() || !isa<DISubprogram>(DS)) &&
628 "Only handle inlined subprograms here, use "
629 "constructSubprogramScopeDIE for non-inlined "
630 "subprograms");
631
632 // Emit inlined subprograms.
633 if (Scope->getParent() && isa<DISubprogram>(DS)) {
634 DIE *ScopeDIE = constructInlinedScopeDIE(Scope, ParentScopeDIE);
635 assert(ScopeDIE && "Scope DIE should not be null.");
636 createAndAddScopeChildren(Scope, *ScopeDIE);
637 return;
638 }
639
640 // Early exit when we know the scope DIE is going to be null.
641 if (DD->isLexicalScopeDIENull(Scope))
642 return;
643
644 // Emit lexical blocks.
645 DIE *ScopeDIE = constructLexicalScopeDIE(Scope);
646 assert(ScopeDIE && "Scope DIE should not be null.");
647
648 ParentScopeDIE.addChild(ScopeDIE);
649 createAndAddScopeChildren(Scope, *ScopeDIE);
650}
651
654
655 HasRangeLists = true;
656
657 // Add the range list to the set of ranges to be emitted.
658 auto IndexAndList =
659 (DD->getDwarfVersion() < 5 && Skeleton ? Skeleton->DU : DU)
660 ->addRange(*(Skeleton ? Skeleton : this), std::move(Range));
661
662 uint32_t Index = IndexAndList.first;
663 auto &List = *IndexAndList.second;
664
665 // Under fission, ranges are specified by constant offsets relative to the
666 // CU's DW_AT_GNU_ranges_base.
667 // FIXME: For DWARF v5, do not generate the DW_AT_ranges attribute under
668 // fission until we support the forms using the .debug_addr section
669 // (DW_RLE_startx_endx etc.).
670 if (DD->getDwarfVersion() >= 5)
671 addUInt(ScopeDIE, dwarf::DW_AT_ranges, dwarf::DW_FORM_rnglistx, Index);
672 else {
673 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
674 const MCSymbol *RangeSectionSym =
676 if (isDwoUnit())
677 addSectionDelta(ScopeDIE, dwarf::DW_AT_ranges, List.Label,
678 RangeSectionSym);
679 else
680 addSectionLabel(ScopeDIE, dwarf::DW_AT_ranges, List.Label,
681 RangeSectionSym);
682 }
683}
684
686 DIE &Die, SmallVector<RangeSpan, 2> Ranges) {
687 assert(!Ranges.empty());
688 if (!DD->useRangesSection() ||
689 (Ranges.size() == 1 &&
690 (!DD->alwaysUseRanges(*this) ||
691 DD->getSectionLabel(&Ranges.front().Begin->getSection()) ==
692 Ranges.front().Begin))) {
693 const RangeSpan &Front = Ranges.front();
694 const RangeSpan &Back = Ranges.back();
695 attachLowHighPC(Die, Front.Begin, Back.End);
696 } else
697 addScopeRangeList(Die, std::move(Ranges));
698}
699
701 DIE &Die, const SmallVectorImpl<InsnRange> &Ranges) {
703 List.reserve(Ranges.size());
704 for (const InsnRange &R : Ranges) {
705 auto *BeginLabel = DD->getLabelBeforeInsn(R.first);
706 auto *EndLabel = DD->getLabelAfterInsn(R.second);
707
708 const auto *BeginMBB = R.first->getParent();
709 const auto *EndMBB = R.second->getParent();
710
711 const auto *MBB = BeginMBB;
712 // Basic block sections allows basic block subsets to be placed in unique
713 // sections. For each section, the begin and end label must be added to the
714 // list. If there is more than one range, debug ranges must be used.
715 // Otherwise, low/high PC can be used.
716 // FIXME: Debug Info Emission depends on block order and this assumes that
717 // the order of blocks will be frozen beyond this point.
718 do {
719 if (MBB->sameSection(EndMBB) || MBB->isEndSection()) {
720 auto MBBSectionRange = Asm->MBBSectionRanges[MBB->getSectionID()];
721 List.push_back(
722 {MBB->sameSection(BeginMBB) ? BeginLabel
723 : MBBSectionRange.BeginLabel,
724 MBB->sameSection(EndMBB) ? EndLabel : MBBSectionRange.EndLabel});
725 }
726 if (MBB->sameSection(EndMBB))
727 break;
728 MBB = MBB->getNextNode();
729 } while (true);
730 }
731 attachRangesOrLowHighPC(Die, std::move(List));
732}
733
735 DIE &ParentScopeDIE) {
736 assert(Scope->getScopeNode());
737 auto *DS = Scope->getScopeNode();
738 auto *InlinedSP = getDISubprogram(DS);
739 // Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram
740 // was inlined from another compile unit.
741 DIE *OriginDIE = getAbstractScopeDIEs()[InlinedSP];
742 assert(OriginDIE && "Unable to find original DIE for an inlined subprogram.");
743
744 auto ScopeDIE = DIE::get(DIEValueAllocator, dwarf::DW_TAG_inlined_subroutine);
745 ParentScopeDIE.addChild(ScopeDIE);
746 addDIEEntry(*ScopeDIE, dwarf::DW_AT_abstract_origin, *OriginDIE);
747
748 attachRangesOrLowHighPC(*ScopeDIE, Scope->getRanges());
749
750 // Add the call site information to the DIE.
751 const DILocation *IA = Scope->getInlinedAt();
752 addUInt(*ScopeDIE, dwarf::DW_AT_call_file, std::nullopt,
753 getOrCreateSourceID(IA->getFile()));
754 addUInt(*ScopeDIE, dwarf::DW_AT_call_line, std::nullopt, IA->getLine());
755 if (IA->getColumn())
756 addUInt(*ScopeDIE, dwarf::DW_AT_call_column, std::nullopt, IA->getColumn());
757 if (IA->getDiscriminator() && DD->getDwarfVersion() >= 4)
758 addUInt(*ScopeDIE, dwarf::DW_AT_GNU_discriminator, std::nullopt,
759 IA->getDiscriminator());
760
761 // Add name to the name table, we do this here because we're guaranteed
762 // to have concrete versions of our DW_TAG_inlined_subprogram nodes.
763 DD->addSubprogramNames(*this, CUNode->getNameTableKind(), InlinedSP,
764 *ScopeDIE);
765
766 return ScopeDIE;
767}
768
769// Construct new DW_TAG_lexical_block for this scope and attach
770// DW_AT_low_pc/DW_AT_high_pc labels.
772 if (DD->isLexicalScopeDIENull(Scope))
773 return nullptr;
774 const auto *DS = Scope->getScopeNode();
775
776 auto ScopeDIE = DIE::get(DIEValueAllocator, dwarf::DW_TAG_lexical_block);
777 if (Scope->isAbstractScope()) {
778 assert(!getAbstractScopeDIEs().count(DS) &&
779 "Abstract DIE for this scope exists!");
780 getAbstractScopeDIEs()[DS] = ScopeDIE;
781 return ScopeDIE;
782 }
783 if (!Scope->getInlinedAt()) {
784 assert(!LexicalBlockDIEs.count(DS) &&
785 "Concrete out-of-line DIE for this scope exists!");
786 LexicalBlockDIEs[DS] = ScopeDIE;
787 } else {
788 InlinedLocalScopeDIEs[DS].push_back(ScopeDIE);
789 }
790
791 attachRangesOrLowHighPC(*ScopeDIE, Scope->getRanges());
792
793 return ScopeDIE;
794}
795
797 auto *VariableDie = DIE::get(DIEValueAllocator, DV.getTag());
798 insertDIE(DV.getVariable(), VariableDie);
799 DV.setDIE(*VariableDie);
800 // Abstract variables don't get common attributes later, so apply them now.
801 if (Abstract) {
802 applyCommonDbgVariableAttributes(DV, *VariableDie);
803 } else {
804 std::visit(
805 [&](const auto &V) {
806 applyConcreteDbgVariableAttributes(V, DV, *VariableDie);
807 },
808 DV.asVariant());
809 }
810 return VariableDie;
811}
812
813void DwarfCompileUnit::applyConcreteDbgVariableAttributes(
814 const Loc::Single &Single, const DbgVariable &DV, DIE &VariableDie) {
815 const DbgValueLoc *DVal = &Single.getValueLoc();
816 if (Asm->TM.getTargetTriple().isNVPTX() && DD->tuneForGDB() &&
817 !Single.getExpr()) {
818 // cuda-gdb special requirement. See NVPTXAS::DWARF_AddressSpace
819 // Lack of expression means it is a register.
820 addUInt(VariableDie, dwarf::DW_AT_address_class, dwarf::DW_FORM_data1,
822 }
823 if (!DVal->isVariadic()) {
824 const DbgValueLocEntry *Entry = DVal->getLocEntries().begin();
825 if (Entry->isLocation()) {
826 addVariableAddress(DV, VariableDie, Entry->getLoc());
827 } else if (Entry->isInt()) {
828 auto *Expr = Single.getExpr();
829 if (Expr && Expr->getNumElements()) {
830 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
831 DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
832 // If there is an expression, emit raw unsigned bytes.
833 DwarfExpr.addFragmentOffset(Expr);
834 DwarfExpr.addUnsignedConstant(Entry->getInt());
835 DwarfExpr.addExpression(Expr);
836 addBlock(VariableDie, dwarf::DW_AT_location, DwarfExpr.finalize());
837 if (DwarfExpr.TagOffset)
838 addUInt(VariableDie, dwarf::DW_AT_LLVM_tag_offset,
839 dwarf::DW_FORM_data1, *DwarfExpr.TagOffset);
840 } else
841 addConstantValue(VariableDie, Entry->getInt(), DV.getType());
842 } else if (Entry->isConstantFP()) {
843 addConstantFPValue(VariableDie, Entry->getConstantFP());
844 } else if (Entry->isConstantInt()) {
845 addConstantValue(VariableDie, Entry->getConstantInt(), DV.getType());
846 } else if (Entry->isTargetIndexLocation()) {
847 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
848 DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
849 const DIBasicType *BT = dyn_cast<DIBasicType>(
850 static_cast<const Metadata *>(DV.getVariable()->getType()));
851 DwarfDebug::emitDebugLocValue(*Asm, BT, *DVal, DwarfExpr);
852 addBlock(VariableDie, dwarf::DW_AT_location, DwarfExpr.finalize());
853 }
854 return;
855 }
856 // If any of the location entries are registers with the value 0,
857 // then the location is undefined.
858 if (any_of(DVal->getLocEntries(), [](const DbgValueLocEntry &Entry) {
859 return Entry.isLocation() && !Entry.getLoc().getReg();
860 }))
861 return;
862 const DIExpression *Expr = Single.getExpr();
863 assert(Expr && "Variadic Debug Value must have an Expression.");
864 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
865 DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
866 DwarfExpr.addFragmentOffset(Expr);
867 DIExpressionCursor Cursor(Expr);
868 const TargetRegisterInfo &TRI = *Asm->MF->getSubtarget().getRegisterInfo();
869
870 auto AddEntry = [&](const DbgValueLocEntry &Entry,
871 DIExpressionCursor &Cursor) {
872 if (Entry.isLocation()) {
873 if (!DwarfExpr.addMachineRegExpression(TRI, Cursor,
874 Entry.getLoc().getReg()))
875 return false;
876 } else if (Entry.isInt()) {
877 // If there is an expression, emit raw unsigned bytes.
878 DwarfExpr.addUnsignedConstant(Entry.getInt());
879 } else if (Entry.isConstantFP()) {
880 // DwarfExpression does not support arguments wider than 64 bits
881 // (see PR52584).
882 // TODO: Consider chunking expressions containing overly wide
883 // arguments into separate pointer-sized fragment expressions.
884 APInt RawBytes = Entry.getConstantFP()->getValueAPF().bitcastToAPInt();
885 if (RawBytes.getBitWidth() > 64)
886 return false;
887 DwarfExpr.addUnsignedConstant(RawBytes.getZExtValue());
888 } else if (Entry.isConstantInt()) {
889 APInt RawBytes = Entry.getConstantInt()->getValue();
890 if (RawBytes.getBitWidth() > 64)
891 return false;
892 DwarfExpr.addUnsignedConstant(RawBytes.getZExtValue());
893 } else if (Entry.isTargetIndexLocation()) {
894 TargetIndexLocation Loc = Entry.getTargetIndexLocation();
895 // TODO TargetIndexLocation is a target-independent. Currently
896 // only the WebAssembly-specific encoding is supported.
897 assert(Asm->TM.getTargetTriple().isWasm());
898 DwarfExpr.addWasmLocation(Loc.Index, static_cast<uint64_t>(Loc.Offset));
899 } else {
900 llvm_unreachable("Unsupported Entry type.");
901 }
902 return true;
903 };
904
905 if (!DwarfExpr.addExpression(
906 std::move(Cursor),
907 [&](unsigned Idx, DIExpressionCursor &Cursor) -> bool {
908 return AddEntry(DVal->getLocEntries()[Idx], Cursor);
909 }))
910 return;
911
912 // Now attach the location information to the DIE.
913 addBlock(VariableDie, dwarf::DW_AT_location, DwarfExpr.finalize());
914 if (DwarfExpr.TagOffset)
915 addUInt(VariableDie, dwarf::DW_AT_LLVM_tag_offset, dwarf::DW_FORM_data1,
916 *DwarfExpr.TagOffset);
917}
918
919void DwarfCompileUnit::applyConcreteDbgVariableAttributes(
920 const Loc::Multi &Multi, const DbgVariable &DV, DIE &VariableDie) {
921 addLocationList(VariableDie, dwarf::DW_AT_location,
922 Multi.getDebugLocListIndex());
923 auto TagOffset = Multi.getDebugLocListTagOffset();
924 if (TagOffset)
925 addUInt(VariableDie, dwarf::DW_AT_LLVM_tag_offset, dwarf::DW_FORM_data1,
926 *TagOffset);
927}
928
929void DwarfCompileUnit::applyConcreteDbgVariableAttributes(const Loc::MMI &MMI,
930 const DbgVariable &DV,
931 DIE &VariableDie) {
932 std::optional<unsigned> NVPTXAddressSpace;
933 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
934 DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
935 for (const auto &Fragment : MMI.getFrameIndexExprs()) {
936 Register FrameReg;
937 const DIExpression *Expr = Fragment.Expr;
938 const TargetFrameLowering *TFI = Asm->MF->getSubtarget().getFrameLowering();
939 StackOffset Offset =
940 TFI->getFrameIndexReference(*Asm->MF, Fragment.FI, FrameReg);
941 DwarfExpr.addFragmentOffset(Expr);
942
943 auto *TRI = Asm->MF->getSubtarget().getRegisterInfo();
944 SmallVector<uint64_t, 8> Ops;
945 TRI->getOffsetOpcodes(Offset, Ops);
946
947 // cuda-gdb special requirement. See NVPTXAS::DWARF_AddressSpace.
948 // Decode DW_OP_constu <DWARF Address Space> DW_OP_swap
949 // DW_OP_xderef sequence to specify address space.
950 if (Asm->TM.getTargetTriple().isNVPTX() && DD->tuneForGDB()) {
951 unsigned LocalNVPTXAddressSpace;
952 const DIExpression *NewExpr =
953 DIExpression::extractAddressClass(Expr, LocalNVPTXAddressSpace);
954 if (NewExpr != Expr) {
955 Expr = NewExpr;
956 NVPTXAddressSpace = LocalNVPTXAddressSpace;
957 }
958 }
959 if (Expr)
960 Ops.append(Expr->elements_begin(), Expr->elements_end());
961 DIExpressionCursor Cursor(Ops);
962 DwarfExpr.setMemoryLocationKind();
963 if (const MCSymbol *FrameSymbol = Asm->getFunctionFrameSymbol())
964 addOpAddress(*Loc, FrameSymbol);
965 else
966 DwarfExpr.addMachineRegExpression(
967 *Asm->MF->getSubtarget().getRegisterInfo(), Cursor, FrameReg);
968 DwarfExpr.addExpression(std::move(Cursor));
969 }
970 if (Asm->TM.getTargetTriple().isNVPTX() && DD->tuneForGDB()) {
971 // cuda-gdb special requirement. See NVPTXAS::DWARF_AddressSpace.
972 addUInt(VariableDie, dwarf::DW_AT_address_class, dwarf::DW_FORM_data1,
973 NVPTXAddressSpace.value_or(NVPTXAS::DWARF_ADDR_local_space));
974 }
975 addBlock(VariableDie, dwarf::DW_AT_location, DwarfExpr.finalize());
976 if (DwarfExpr.TagOffset)
977 addUInt(VariableDie, dwarf::DW_AT_LLVM_tag_offset, dwarf::DW_FORM_data1,
978 *DwarfExpr.TagOffset);
979}
980
981void DwarfCompileUnit::applyConcreteDbgVariableAttributes(
982 const Loc::EntryValue &EntryValue, const DbgVariable &DV,
983 DIE &VariableDie) {
984 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
985 DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
986 // Emit each expression as: EntryValue(Register) <other ops> <Fragment>.
987 for (auto [Register, Expr] : EntryValue.EntryValues) {
988 DwarfExpr.addFragmentOffset(&Expr);
989 DIExpressionCursor Cursor(Expr.getElements());
990 DwarfExpr.beginEntryValueExpression(Cursor);
991 DwarfExpr.addMachineRegExpression(
992 *Asm->MF->getSubtarget().getRegisterInfo(), Cursor, Register);
993 DwarfExpr.addExpression(std::move(Cursor));
994 }
995 addBlock(VariableDie, dwarf::DW_AT_location, DwarfExpr.finalize());
996}
997
998void DwarfCompileUnit::applyConcreteDbgVariableAttributes(
999 const std::monostate &, const DbgVariable &DV, DIE &VariableDie) {}
1000
1002 const LexicalScope &Scope,
1003 DIE *&ObjectPointer) {
1004 auto Var = constructVariableDIE(DV, Scope.isAbstractScope());
1005 if (DV.isObjectPointer())
1006 ObjectPointer = Var;
1007 return Var;
1008}
1009
1011 const LexicalScope &Scope) {
1012 auto LabelDie = DIE::get(DIEValueAllocator, DL.getTag());
1013 insertDIE(DL.getLabel(), LabelDie);
1014 DL.setDIE(*LabelDie);
1015
1016 if (Scope.isAbstractScope())
1017 applyLabelAttributes(DL, *LabelDie);
1018
1019 return LabelDie;
1020}
1021
1022/// Return all DIVariables that appear in count: expressions.
1025 auto *Array = dyn_cast<DICompositeType>(Var->getType());
1026 if (!Array || Array->getTag() != dwarf::DW_TAG_array_type)
1027 return Result;
1028 if (auto *DLVar = Array->getDataLocation())
1029 Result.push_back(DLVar);
1030 if (auto *AsVar = Array->getAssociated())
1031 Result.push_back(AsVar);
1032 if (auto *AlVar = Array->getAllocated())
1033 Result.push_back(AlVar);
1034 for (auto *El : Array->getElements()) {
1035 if (auto *Subrange = dyn_cast<DISubrange>(El)) {
1036 if (auto Count = Subrange->getCount())
1037 if (auto *Dependency = dyn_cast_if_present<DIVariable *>(Count))
1038 Result.push_back(Dependency);
1039 if (auto LB = Subrange->getLowerBound())
1040 if (auto *Dependency = dyn_cast_if_present<DIVariable *>(LB))
1041 Result.push_back(Dependency);
1042 if (auto UB = Subrange->getUpperBound())
1043 if (auto *Dependency = dyn_cast_if_present<DIVariable *>(UB))
1044 Result.push_back(Dependency);
1045 if (auto ST = Subrange->getStride())
1046 if (auto *Dependency = dyn_cast_if_present<DIVariable *>(ST))
1047 Result.push_back(Dependency);
1048 } else if (auto *GenericSubrange = dyn_cast<DIGenericSubrange>(El)) {
1049 if (auto Count = GenericSubrange->getCount())
1050 if (auto *Dependency = dyn_cast_if_present<DIVariable *>(Count))
1051 Result.push_back(Dependency);
1052 if (auto LB = GenericSubrange->getLowerBound())
1053 if (auto *Dependency = dyn_cast_if_present<DIVariable *>(LB))
1054 Result.push_back(Dependency);
1055 if (auto UB = GenericSubrange->getUpperBound())
1056 if (auto *Dependency = dyn_cast_if_present<DIVariable *>(UB))
1057 Result.push_back(Dependency);
1058 if (auto ST = GenericSubrange->getStride())
1059 if (auto *Dependency = dyn_cast_if_present<DIVariable *>(ST))
1060 Result.push_back(Dependency);
1061 }
1062 }
1063 return Result;
1064}
1065
1066/// Sort local variables so that variables appearing inside of helper
1067/// expressions come first.
1072 // Map back from a DIVariable to its containing DbgVariable.
1074 // Set of DbgVariables in Result.
1076 // For cycle detection.
1078
1079 // Initialize the worklist and the DIVariable lookup table.
1080 for (auto *Var : reverse(Input)) {
1081 DbgVar.insert({Var->getVariable(), Var});
1082 WorkList.push_back({Var, 0});
1083 }
1084
1085 // Perform a stable topological sort by doing a DFS.
1086 while (!WorkList.empty()) {
1087 auto Item = WorkList.back();
1088 DbgVariable *Var = Item.getPointer();
1089 bool visitedAllDependencies = Item.getInt();
1090 WorkList.pop_back();
1091
1092 assert(Var);
1093
1094 // Already handled.
1095 if (Visited.count(Var))
1096 continue;
1097
1098 // Add to Result if all dependencies are visited.
1099 if (visitedAllDependencies) {
1100 Visited.insert(Var);
1101 Result.push_back(Var);
1102 continue;
1103 }
1104
1105 // Detect cycles.
1106 auto Res = Visiting.insert(Var);
1107 if (!Res.second) {
1108 assert(false && "dependency cycle in local variables");
1109 return Result;
1110 }
1111
1112 // Push dependencies and this node onto the worklist, so that this node is
1113 // visited again after all of its dependencies are handled.
1114 WorkList.push_back({Var, 1});
1115 for (const auto *Dependency : dependencies(Var)) {
1116 // Don't add dependency if it is in a different lexical scope or a global.
1117 if (const auto *Dep = dyn_cast<const DILocalVariable>(Dependency))
1118 if (DbgVariable *Var = DbgVar.lookup(Dep))
1119 WorkList.push_back({Var, 0});
1120 }
1121 }
1122 return Result;
1123}
1124
1126 const Function &F,
1127 LexicalScope *Scope,
1128 MCSymbol *LineTableSym) {
1129 DIE &ScopeDIE = updateSubprogramScopeDIE(Sub, F, LineTableSym);
1130
1131 if (Scope) {
1132 assert(!Scope->getInlinedAt());
1133 assert(!Scope->isAbstractScope());
1134 // Collect lexical scope children first.
1135 // ObjectPointer might be a local (non-argument) local variable if it's a
1136 // block's synthetic this pointer.
1137 if (DIE *ObjectPointer = createAndAddScopeChildren(Scope, ScopeDIE))
1138 addDIEEntry(ScopeDIE, dwarf::DW_AT_object_pointer, *ObjectPointer);
1139 }
1140
1141 // If this is a variadic function, add an unspecified parameter.
1142 DITypeRefArray FnArgs = Sub->getType()->getTypeArray();
1143
1144 // If we have a single element of null, it is a function that returns void.
1145 // If we have more than one elements and the last one is null, it is a
1146 // variadic function.
1147 if (FnArgs.size() > 1 && !FnArgs[FnArgs.size() - 1] &&
1149 ScopeDIE.addChild(
1150 DIE::get(DIEValueAllocator, dwarf::DW_TAG_unspecified_parameters));
1151
1152 return ScopeDIE;
1153}
1154
1156 DIE &ScopeDIE) {
1157 DIE *ObjectPointer = nullptr;
1158
1159 // Emit function arguments (order is significant).
1160 auto Vars = DU->getScopeVariables().lookup(Scope);
1161 for (auto &DV : Vars.Args)
1162 ScopeDIE.addChild(constructVariableDIE(*DV.second, *Scope, ObjectPointer));
1163
1164 // Emit local variables.
1165 auto Locals = sortLocalVars(Vars.Locals);
1166 for (DbgVariable *DV : Locals)
1167 ScopeDIE.addChild(constructVariableDIE(*DV, *Scope, ObjectPointer));
1168
1169 // Emit labels.
1170 for (DbgLabel *DL : DU->getScopeLabels().lookup(Scope))
1171 ScopeDIE.addChild(constructLabelDIE(*DL, *Scope));
1172
1173 // Track other local entities (skipped in gmlt-like data).
1174 // This creates mapping between CU and a set of local declarations that
1175 // should be emitted for subprograms in this CU.
1176 if (!includeMinimalInlineScopes() && !Scope->getInlinedAt()) {
1177 auto &LocalDecls = DD->getLocalDeclsForScope(Scope->getScopeNode());
1178 DeferredLocalDecls.insert_range(LocalDecls);
1179 }
1180
1181 // Emit inner lexical scopes.
1182 auto skipLexicalScope = [this](LexicalScope *S) -> bool {
1183 if (isa<DISubprogram>(S->getScopeNode()))
1184 return false;
1185 auto Vars = DU->getScopeVariables().lookup(S);
1186 if (!Vars.Args.empty() || !Vars.Locals.empty())
1187 return false;
1188 return includeMinimalInlineScopes() ||
1189 DD->getLocalDeclsForScope(S->getScopeNode()).empty();
1190 };
1191 for (LexicalScope *LS : Scope->getChildren()) {
1192 // If the lexical block doesn't have non-scope children, skip
1193 // its emission and put its children directly to the parent scope.
1194 if (skipLexicalScope(LS))
1195 createAndAddScopeChildren(LS, ScopeDIE);
1196 else
1197 constructScopeDIE(LS, ScopeDIE);
1198 }
1199
1200 return ObjectPointer;
1201}
1202
1204 const DISubprogram *SP) {
1205 if (auto *AbsDef = getAbstractScopeDIEs().lookup(SP))
1206 return *AbsDef;
1207
1208 auto [ContextDIE, ContextCU] = getOrCreateAbstractSubprogramContextDIE(SP);
1209 return createAbstractSubprogramDIE(SP, ContextDIE, ContextCU);
1210}
1211
1212DIE &DwarfCompileUnit::createAbstractSubprogramDIE(
1213 const DISubprogram *SP, DIE *ContextDIE, DwarfCompileUnit *ContextCU) {
1214 // Passing null as the associated node because the abstract definition
1215 // shouldn't be found by lookup.
1216 DIE &AbsDef = ContextCU->createAndAddDIE(dwarf::DW_TAG_subprogram,
1217 *ContextDIE, nullptr);
1218
1219 // Store the DIE before creating children.
1220 ContextCU->getAbstractScopeDIEs()[SP] = &AbsDef;
1221
1222 ContextCU->applySubprogramAttributesToDefinition(SP, AbsDef);
1223 ContextCU->addSInt(AbsDef, dwarf::DW_AT_inline,
1224 DD->getDwarfVersion() <= 4 ? std::optional<dwarf::Form>()
1225 : dwarf::DW_FORM_implicit_const,
1227
1228 return AbsDef;
1229}
1230
1231std::pair<DIE *, DwarfCompileUnit *>
1232DwarfCompileUnit::getOrCreateAbstractSubprogramContextDIE(
1233 const DISubprogram *SP) {
1234 bool Minimal = includeMinimalInlineScopes();
1235 bool IgnoreScope = shouldPlaceInUnitDIE(SP, Minimal);
1236 DIE *ContextDIE = getOrCreateSubprogramContextDIE(SP, IgnoreScope);
1237
1238 if (auto *SPDecl = SP->getDeclaration())
1239 if (!Minimal)
1240 getOrCreateSubprogramDIE(SPDecl, nullptr);
1241
1242 // The scope may be shared with a subprogram that has already been
1243 // constructed in another CU, in which case we need to construct this
1244 // subprogram in the same CU.
1245 auto *ContextCU = IgnoreScope ? this : DD->lookupCU(ContextDIE->getUnitDie());
1246
1247 return std::make_pair(ContextDIE, ContextCU);
1248}
1249
1251 LexicalScope *Scope) {
1252 auto *SP = cast<DISubprogram>(Scope->getScopeNode());
1253
1254 // Populate subprogram DIE only once.
1255 if (!getFinalizedAbstractSubprograms().insert(SP).second)
1256 return;
1257
1258 auto [ContextDIE, ContextCU] = getOrCreateAbstractSubprogramContextDIE(SP);
1259 DIE *AbsDef = getAbstractScopeDIEs().lookup(SP);
1260 if (!AbsDef)
1261 AbsDef = &createAbstractSubprogramDIE(SP, ContextDIE, ContextCU);
1262
1263 if (DIE *ObjectPointer = ContextCU->createAndAddScopeChildren(Scope, *AbsDef))
1264 ContextCU->addDIEEntry(*AbsDef, dwarf::DW_AT_object_pointer,
1265 *ObjectPointer);
1266}
1267
1269 return DD->getDwarfVersion() <= 4 && !DD->tuneForLLDB();
1270}
1271
1274 return Tag;
1275 switch (Tag) {
1276 case dwarf::DW_TAG_call_site:
1277 return dwarf::DW_TAG_GNU_call_site;
1278 case dwarf::DW_TAG_call_site_parameter:
1279 return dwarf::DW_TAG_GNU_call_site_parameter;
1280 default:
1281 llvm_unreachable("DWARF5 tag with no GNU analog");
1282 }
1283}
1284
1288 return Attr;
1289 switch (Attr) {
1290 case dwarf::DW_AT_call_all_calls:
1291 return dwarf::DW_AT_GNU_all_call_sites;
1292 case dwarf::DW_AT_call_target:
1293 return dwarf::DW_AT_GNU_call_site_target;
1294 case dwarf::DW_AT_call_origin:
1295 return dwarf::DW_AT_abstract_origin;
1296 case dwarf::DW_AT_call_return_pc:
1297 return dwarf::DW_AT_low_pc;
1298 case dwarf::DW_AT_call_value:
1299 return dwarf::DW_AT_GNU_call_site_value;
1300 case dwarf::DW_AT_call_tail_call:
1301 return dwarf::DW_AT_GNU_tail_call;
1302 default:
1303 llvm_unreachable("DWARF5 attribute with no GNU analog");
1304 }
1305}
1306
1310 return Loc;
1311 switch (Loc) {
1312 case dwarf::DW_OP_entry_value:
1313 return dwarf::DW_OP_GNU_entry_value;
1314 default:
1315 llvm_unreachable("DWARF5 location atom with no GNU analog");
1316 }
1317}
1318
1320 DIE &ScopeDIE, const DISubprogram *CalleeSP, const Function *CalleeF,
1321 bool IsTail, const MCSymbol *PCAddr, const MCSymbol *CallAddr,
1322 unsigned CallReg, DIType *AllocSiteTy) {
1323 // Insert a call site entry DIE within ScopeDIE.
1324 DIE &CallSiteDIE = createAndAddDIE(getDwarf5OrGNUTag(dwarf::DW_TAG_call_site),
1325 ScopeDIE, nullptr);
1326
1327 if (CallReg) {
1328 // Indirect call.
1329 addAddress(CallSiteDIE, getDwarf5OrGNUAttr(dwarf::DW_AT_call_target),
1330 MachineLocation(CallReg));
1331 } else if (CalleeSP) {
1332 DIE *CalleeDIE = getOrCreateSubprogramDIE(CalleeSP, CalleeF);
1333 assert(CalleeDIE && "Could not create DIE for call site entry origin");
1335 !CalleeSP->isDefinition() &&
1336 !CalleeDIE->findAttribute(dwarf::DW_AT_linkage_name)) {
1337 addLinkageName(*CalleeDIE, CalleeSP->getLinkageName());
1338 }
1339
1340 addDIEEntry(CallSiteDIE, getDwarf5OrGNUAttr(dwarf::DW_AT_call_origin),
1341 *CalleeDIE);
1342 }
1343
1344 if (IsTail) {
1345 // Attach DW_AT_call_tail_call to tail calls for standards compliance.
1346 addFlag(CallSiteDIE, getDwarf5OrGNUAttr(dwarf::DW_AT_call_tail_call));
1347
1348 // Attach the address of the branch instruction to allow the debugger to
1349 // show where the tail call occurred. This attribute has no GNU analog.
1350 //
1351 // GDB works backwards from non-standard usage of DW_AT_low_pc (in DWARF4
1352 // mode -- equivalently, in DWARF5 mode, DW_AT_call_return_pc) at tail-call
1353 // site entries to figure out the PC of tail-calling branch instructions.
1354 // This means it doesn't need the compiler to emit DW_AT_call_pc, so we
1355 // don't emit it here.
1356 //
1357 // There's no need to tie non-GDB debuggers to this non-standardness, as it
1358 // adds unnecessary complexity to the debugger. For non-GDB debuggers, emit
1359 // the standard DW_AT_call_pc info.
1361 addLabelAddress(CallSiteDIE, dwarf::DW_AT_call_pc, CallAddr);
1362 }
1363
1364 // Attach the return PC to allow the debugger to disambiguate call paths
1365 // from one function to another.
1366 //
1367 // The return PC is only really needed when the call /isn't/ a tail call, but
1368 // GDB expects it in DWARF4 mode, even for tail calls (see the comment above
1369 // the DW_AT_call_pc emission logic for an explanation).
1370 if (!IsTail || useGNUAnalogForDwarf5Feature()) {
1371 assert(PCAddr && "Missing return PC information for a call");
1372 addLabelAddress(CallSiteDIE,
1373 getDwarf5OrGNUAttr(dwarf::DW_AT_call_return_pc), PCAddr);
1374 }
1375
1376 if (AllocSiteTy)
1377 addType(CallSiteDIE, AllocSiteTy, dwarf::DW_AT_LLVM_alloc_type);
1378
1379 return CallSiteDIE;
1380}
1381
1383 DIE &CallSiteDIE, SmallVector<DbgCallSiteParam, 4> &Params) {
1384 for (const auto &Param : Params) {
1385 unsigned Register = Param.getRegister();
1386 auto CallSiteDieParam =
1388 getDwarf5OrGNUTag(dwarf::DW_TAG_call_site_parameter));
1389 insertDIE(CallSiteDieParam);
1390 addAddress(*CallSiteDieParam, dwarf::DW_AT_location,
1392
1394 DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
1395 DwarfExpr.setCallSiteParamValueFlag();
1396
1397 DwarfDebug::emitDebugLocValue(*Asm, nullptr, Param.getValue(), DwarfExpr);
1398
1399 addBlock(*CallSiteDieParam, getDwarf5OrGNUAttr(dwarf::DW_AT_call_value),
1400 DwarfExpr.finalize());
1401
1402 CallSiteDIE.addChild(CallSiteDieParam);
1403 }
1404}
1405
1407 const DIImportedEntity *Module) {
1408 DIE *IMDie = DIE::get(DIEValueAllocator, Module->getTag());
1409 insertDIE(Module, IMDie);
1410 DIE *EntityDie;
1411 auto *Entity = Module->getEntity();
1412 if (auto *NS = dyn_cast<DINamespace>(Entity))
1413 EntityDie = getOrCreateNameSpace(NS);
1414 else if (auto *M = dyn_cast<DIModule>(Entity))
1415 EntityDie = getOrCreateModule(M);
1416 else if (auto *SP = dyn_cast<DISubprogram>(Entity)) {
1417 // If there is an abstract subprogram, refer to it. Note that this assumes
1418 // that all the abstract subprograms have been already created (which is
1419 // correct until imported entities get emitted in DwarfDebug::endModule()).
1420 if (auto *AbsSPDie = getAbstractScopeDIEs().lookup(SP))
1421 EntityDie = AbsSPDie;
1422 else
1423 EntityDie = getOrCreateSubprogramDIE(SP, nullptr);
1424 } else if (auto *T = dyn_cast<DIType>(Entity))
1425 EntityDie = getOrCreateTypeDIE(T);
1426 else if (auto *GV = dyn_cast<DIGlobalVariable>(Entity))
1427 EntityDie = getOrCreateGlobalVariableDIE(GV, {});
1428 else if (auto *IE = dyn_cast<DIImportedEntity>(Entity))
1429 EntityDie = getOrCreateImportedEntityDIE(IE);
1430 else
1431 EntityDie = getDIE(Entity);
1432 assert(EntityDie);
1433 addSourceLine(*IMDie, Module->getLine(), /*Column*/ 0, Module->getFile());
1434 addDIEEntry(*IMDie, dwarf::DW_AT_import, *EntityDie);
1435 StringRef Name = Module->getName();
1436 if (!Name.empty()) {
1437 addString(*IMDie, dwarf::DW_AT_name, Name);
1438
1439 // FIXME: if consumers ever start caring about handling
1440 // unnamed import declarations such as `using ::nullptr_t`
1441 // or `using namespace std::ranges`, we could add the
1442 // import declaration into the accelerator table with the
1443 // name being the one of the entity being imported.
1444 DD->addAccelNamespace(*this, CUNode->getNameTableKind(), Name, *IMDie);
1445 }
1446
1447 // This is for imported module with renamed entities (such as variables and
1448 // subprograms).
1449 DINodeArray Elements = Module->getElements();
1450 for (const auto *Element : Elements) {
1451 if (!Element)
1452 continue;
1453 IMDie->addChild(
1455 }
1456
1457 return IMDie;
1458}
1459
1461 const DIImportedEntity *IE) {
1462
1463 // Check for pre-existence.
1464 if (DIE *Die = getDIE(IE))
1465 return Die;
1466
1467 DIE *ContextDIE = getOrCreateContextDIE(IE->getScope());
1468 assert(ContextDIE && "Empty scope for the imported entity!");
1469
1470 DIE *IMDie = constructImportedEntityDIE(IE);
1471 ContextDIE->addChild(IMDie);
1472 return IMDie;
1473}
1474
1476 DIE *D = getDIE(SP);
1477 if (DIE *AbsSPDIE = getAbstractScopeDIEs().lookup(SP)) {
1478 if (D)
1479 // If this subprogram has an abstract definition, reference that
1480 addDIEEntry(*D, dwarf::DW_AT_abstract_origin, *AbsSPDIE);
1481 } else {
1483 if (D)
1484 // And attach the attributes
1486 }
1487}
1488
1490 DbgEntity *AbsEntity = getExistingAbstractEntity(Entity->getEntity());
1491
1492 auto *Die = Entity->getDIE();
1493 /// Label may be used to generate DW_AT_low_pc, so put it outside
1494 /// if/else block.
1495 const DbgLabel *Label = nullptr;
1496 if (AbsEntity && AbsEntity->getDIE()) {
1497 addDIEEntry(*Die, dwarf::DW_AT_abstract_origin, *AbsEntity->getDIE());
1498 Label = dyn_cast<const DbgLabel>(Entity);
1499 } else {
1500 if (const DbgVariable *Var = dyn_cast<const DbgVariable>(Entity))
1502 else if ((Label = dyn_cast<const DbgLabel>(Entity)))
1503 applyLabelAttributes(*Label, *Die);
1504 else
1505 llvm_unreachable("DbgEntity must be DbgVariable or DbgLabel.");
1506 }
1507
1508 if (!Label)
1509 return;
1510
1511 const auto *Sym = Label->getSymbol();
1512 if (!Sym)
1513 return;
1514
1515 addLabelAddress(*Die, dwarf::DW_AT_low_pc, Sym);
1516
1517 // A TAG_label with a name and an AT_low_pc must be placed in debug_names.
1518 if (StringRef Name = Label->getName(); !Name.empty())
1519 getDwarfDebug().addAccelName(*this, CUNode->getNameTableKind(), Name, *Die);
1520}
1521
1523 auto AttachAO = [&](const DILocalScope *LS, DIE *ScopeDIE) {
1524 if (auto *AbsLSDie = getAbstractScopeDIEs().lookup(LS))
1525 addDIEEntry(*ScopeDIE, dwarf::DW_AT_abstract_origin, *AbsLSDie);
1526 };
1527
1528 for (auto [LScope, ScopeDIE] : LexicalBlockDIEs)
1529 AttachAO(LScope, ScopeDIE);
1530 for (auto &[LScope, ScopeDIEs] : InlinedLocalScopeDIEs)
1531 for (auto *ScopeDIE : ScopeDIEs)
1532 AttachAO(LScope, ScopeDIE);
1533}
1534
1536 auto &AbstractEntities = getAbstractEntities();
1537 auto I = AbstractEntities.find(Node);
1538 if (I != AbstractEntities.end())
1539 return I->second.get();
1540 return nullptr;
1541}
1542
1544 LexicalScope *Scope) {
1545 assert(Scope && Scope->isAbstractScope());
1546 auto &Entity = getAbstractEntities()[Node];
1548 Entity = std::make_unique<DbgVariable>(cast<const DILocalVariable>(Node),
1549 nullptr /* IA */);
1550 DU->addScopeVariable(Scope, cast<DbgVariable>(Entity.get()));
1551 } else if (isa<const DILabel>(Node)) {
1552 Entity = std::make_unique<DbgLabel>(
1553 cast<const DILabel>(Node), nullptr /* IA */);
1554 DU->addScopeLabel(Scope, cast<DbgLabel>(Entity.get()));
1555 }
1556}
1557
1558void DwarfCompileUnit::emitHeader(bool UseOffsets) {
1559 // Don't bother labeling the .dwo unit, as its offset isn't used.
1560 if (!Skeleton && !DD->useSectionsAsReferences()) {
1561 LabelBegin = Asm->createTempSymbol("cu_begin");
1562 Asm->OutStreamer->emitLabel(LabelBegin);
1563 }
1564
1565 dwarf::UnitType UT = Skeleton ? dwarf::DW_UT_split_compile
1566 : DD->useSplitDwarf() ? dwarf::DW_UT_skeleton
1567 : dwarf::DW_UT_compile;
1568 DwarfUnit::emitCommonHeader(UseOffsets, UT);
1569 if (DD->getDwarfVersion() >= 5 && UT != dwarf::DW_UT_compile)
1570 Asm->emitInt64(getDWOId());
1571}
1572
1574 switch (CUNode->getNameTableKind()) {
1576 return false;
1577 // Opting in to GNU Pubnames/types overrides the default to ensure these are
1578 // generated for things like Gold's gdb_index generation.
1580 return true;
1582 return false;
1584 return DD->tuneForGDB() && !includeMinimalInlineScopes() &&
1585 !CUNode->isDebugDirectivesOnly() &&
1586 DD->getAccelTableKind() != AccelTableKind::Apple &&
1587 DD->getDwarfVersion() < 5;
1588 }
1589 llvm_unreachable("Unhandled DICompileUnit::DebugNameTableKind enum");
1590}
1591
1592/// addGlobalName - Add a new global name to the compile unit.
1594 const DIScope *Context) {
1595 if (!hasDwarfPubSections())
1596 return;
1597 std::string FullName = getParentContextString(Context) + Name.str();
1598 GlobalNames[FullName] = &Die;
1599}
1600
1602 const DIScope *Context) {
1603 if (!hasDwarfPubSections())
1604 return;
1605 std::string FullName = getParentContextString(Context) + Name.str();
1606 // Insert, allowing the entry to remain as-is if it's already present
1607 // This way the CU-level type DIE is preferred over the "can't describe this
1608 // type as a unit offset because it's not really in the CU at all, it's only
1609 // in a type unit"
1610 GlobalNames.insert(std::make_pair(std::move(FullName), &getUnitDie()));
1611}
1612
1613/// Add a new global type to the unit.
1615 const DIScope *Context) {
1616 if (!hasDwarfPubSections())
1617 return;
1618 std::string FullName = getParentContextString(Context) + Ty->getName().str();
1619 GlobalTypes[FullName] = &Die;
1620}
1621
1623 const DIScope *Context) {
1624 if (!hasDwarfPubSections())
1625 return;
1626 std::string FullName = getParentContextString(Context) + Ty->getName().str();
1627 // Insert, allowing the entry to remain as-is if it's already present
1628 // This way the CU-level type DIE is preferred over the "can't describe this
1629 // type as a unit offset because it's not really in the CU at all, it's only
1630 // in a type unit"
1631 GlobalTypes.insert(std::make_pair(std::move(FullName), &getUnitDie()));
1632}
1633
1635 MachineLocation Location) {
1636 auto *Single = std::get_if<Loc::Single>(&DV);
1637 if (Single && Single->getExpr())
1638 addComplexAddress(Single->getExpr(), Die, dwarf::DW_AT_location, Location);
1639 else
1640 addAddress(Die, dwarf::DW_AT_location, Location);
1641}
1642
1643/// Add an address attribute to a die based on the location provided.
1645 const MachineLocation &Location) {
1647 DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
1648 if (Location.isIndirect())
1649 DwarfExpr.setMemoryLocationKind();
1650
1651 DIExpressionCursor Cursor({});
1652 const TargetRegisterInfo &TRI = *Asm->MF->getSubtarget().getRegisterInfo();
1653 if (!DwarfExpr.addMachineRegExpression(TRI, Cursor, Location.getReg()))
1654 return;
1655 DwarfExpr.addExpression(std::move(Cursor));
1656
1657 // Now attach the location information to the DIE.
1658 addBlock(Die, Attribute, DwarfExpr.finalize());
1659
1660 if (DwarfExpr.TagOffset)
1661 addUInt(Die, dwarf::DW_AT_LLVM_tag_offset, dwarf::DW_FORM_data1,
1662 *DwarfExpr.TagOffset);
1663}
1664
1665/// Start with the address based on the location provided, and generate the
1666/// DWARF information necessary to find the actual variable given the extra
1667/// address information encoded in the DbgVariable, starting from the starting
1668/// location. Add the DWARF information to the die.
1671 const MachineLocation &Location) {
1673 DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
1674 DwarfExpr.addFragmentOffset(DIExpr);
1675 DwarfExpr.setLocation(Location, DIExpr);
1676
1677 DIExpressionCursor Cursor(DIExpr);
1678
1679 if (DIExpr->isEntryValue())
1680 DwarfExpr.beginEntryValueExpression(Cursor);
1681
1682 const TargetRegisterInfo &TRI = *Asm->MF->getSubtarget().getRegisterInfo();
1683 if (!DwarfExpr.addMachineRegExpression(TRI, Cursor, Location.getReg()))
1684 return;
1685 DwarfExpr.addExpression(std::move(Cursor));
1686
1687 // Now attach the location information to the DIE.
1688 addBlock(Die, Attribute, DwarfExpr.finalize());
1689
1690 if (DwarfExpr.TagOffset)
1691 addUInt(Die, dwarf::DW_AT_LLVM_tag_offset, dwarf::DW_FORM_data1,
1692 *DwarfExpr.TagOffset);
1693}
1694
1695/// Add a Dwarf loclistptr attribute data and value.
1697 unsigned Index) {
1698 dwarf::Form Form = (DD->getDwarfVersion() >= 5)
1699 ? dwarf::DW_FORM_loclistx
1700 : DD->getDwarfSectionOffsetForm();
1701 addAttribute(Die, Attribute, Form, DIELocList(Index));
1702}
1703
1705 DIE &VariableDie) {
1706 StringRef Name = Var.getName();
1707 if (!Name.empty())
1708 addString(VariableDie, dwarf::DW_AT_name, Name);
1709 const auto *DIVar = Var.getVariable();
1710 if (DIVar) {
1711 if (uint32_t AlignInBytes = DIVar->getAlignInBytes())
1712 addUInt(VariableDie, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1713 AlignInBytes);
1714 addAnnotation(VariableDie, DIVar->getAnnotations());
1715 }
1716
1717 addSourceLine(VariableDie, DIVar);
1718 addType(VariableDie, Var.getType());
1719 if (Var.isArtificial())
1720 addFlag(VariableDie, dwarf::DW_AT_artificial);
1721}
1722
1724 DIE &LabelDie) {
1725 StringRef Name = Label.getName();
1726 if (!Name.empty())
1727 addString(LabelDie, dwarf::DW_AT_name, Name);
1728 const auto *DILabel = Label.getLabel();
1729 addSourceLine(LabelDie, DILabel);
1730 if (DILabel->isArtificial())
1731 addFlag(LabelDie, dwarf::DW_AT_artificial);
1733 addUInt(LabelDie, dwarf::DW_AT_LLVM_coro_suspend_idx, std::nullopt,
1735}
1736
1737/// Add a Dwarf expression attribute data and value.
1739 const MCExpr *Expr) {
1740 addAttribute(Die, (dwarf::Attribute)0, Form, DIEExpr(Expr));
1741}
1742
1744 const DISubprogram *SP, DIE &SPDie) {
1745 auto *SPDecl = SP->getDeclaration();
1746 auto *Context = SPDecl ? SPDecl->getScope() : SP->getScope();
1748 addGlobalName(SP->getName(), SPDie, Context);
1749}
1750
1751bool DwarfCompileUnit::isDwoUnit() const {
1752 return DD->useSplitDwarf() && Skeleton;
1753}
1754
1755void DwarfCompileUnit::finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) {
1756 constructTypeDIE(D, CTy);
1757}
1758
1761 (DD->useSplitDwarf() && !Skeleton);
1762}
1763
1767
1769 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
1770 MCSymbol *Label = DD->getAddressPool().getLabel();
1772 DD->getDwarfVersion() >= 5 ? dwarf::DW_AT_addr_base
1773 : dwarf::DW_AT_GNU_addr_base,
1774 Label, TLOF.getDwarfAddrSection()->getBeginSymbol());
1775}
1776
1778 addAttribute(Die, (dwarf::Attribute)0, dwarf::DW_FORM_udata,
1779 new (DIEValueAllocator) DIEBaseTypeRef(this, Idx));
1780}
1781
1783 // Insert the base_type DIEs directly after the CU so that their offsets will
1784 // fit in the fixed size ULEB128 used inside the location expressions.
1785 // Maintain order by iterating backwards and inserting to the front of CU
1786 // child list.
1787 for (auto &Btr : reverse(ExprRefedBaseTypes)) {
1788 DIE &Die = getUnitDie().addChildFront(
1789 DIE::get(DIEValueAllocator, dwarf::DW_TAG_base_type));
1790 SmallString<32> Str;
1791 addString(Die, dwarf::DW_AT_name,
1793 "_" + Twine(Btr.BitSize)).toStringRef(Str));
1794 addUInt(Die, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, Btr.Encoding);
1795 // Round up to smallest number of bytes that contains this number of bits.
1796 addUInt(Die, dwarf::DW_AT_byte_size, std::nullopt,
1797 divideCeil(Btr.BitSize, 8));
1798
1799 Btr.Die = &Die;
1800 }
1801}
1802
1804 // Assume if there is an abstract tree all the DIEs are already emitted.
1805 bool isAbstract = getAbstractScopeDIEs().count(LB->getSubprogram());
1806 if (isAbstract) {
1807 auto &DIEs = getAbstractScopeDIEs();
1808 if (auto It = DIEs.find(LB); It != DIEs.end())
1809 return It->second;
1810 }
1811 assert(!isAbstract && "Missed lexical block DIE in abstract tree!");
1812
1813 // Return a concrete DIE if it exists or nullptr otherwise.
1814 return LexicalBlockDIEs.lookup(LB);
1815}
1816
1818 if (isa_and_nonnull<DILocalScope>(Context)) {
1819 if (auto *LFScope = dyn_cast<DILexicalBlockFile>(Context))
1820 Context = LFScope->getNonLexicalBlockFileScope();
1821 if (auto *LScope = dyn_cast<DILexicalBlock>(Context))
1822 return getLexicalBlockDIE(LScope);
1823
1824 // Otherwise the context must be a DISubprogram.
1825 auto *SPScope = cast<DISubprogram>(Context);
1826 const auto &DIEs = getAbstractScopeDIEs();
1827 if (auto It = DIEs.find(SPScope); It != DIEs.end())
1828 return It->second;
1829 }
1830 return DwarfUnit::getOrCreateContextDIE(Context);
1831}
1832
1834 const Function *F,
1835 bool Minimal) {
1836 if (!F && SP->isDefinition()) {
1837 F = DD->getLexicalScopes().getFunction(SP);
1838
1839 if (!F)
1841 }
1842
1843 return DwarfUnit::getOrCreateSubprogramDIE(SP, F, Minimal);
1844}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
BitTracker BT
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
dxil translate DXIL Translate Metadata
static SmallVector< DbgVariable *, 8 > sortLocalVars(SmallVectorImpl< DbgVariable * > &Input)
Sort local variables so that variables appearing inside of helper expressions come first.
static 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.
static bool lookup(const GsymReader &GR, DataExtractor &Data, uint64_t &Offset, uint64_t BaseAddr, uint64_t Addr, SourceLocations &SrcLocs, llvm::Error &Err)
A Lookup helper functions.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define F(x, y, z)
Definition MD5.cpp:55
#define I(x, y, z)
Definition MD5.cpp:58
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define T
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.
The Input class is used to parse a yaml document into in-memory structs and vectors.
uint64_t getZExtValue() const
Get zero extended value.
Definition APInt.h:1540
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition APInt.h:1488
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
TargetMachine & TM
Target machine description.
Definition AsmPrinter.h:93
const DataLayout & getDataLayout() const
Return information about data layout.
MCSymbol * GetExternalSymbolSymbol(const Twine &Sym) const
Return the MCSymbol for the specified ExternalSymbol.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:69
Debug common block.
DIFile * getFile() const
unsigned getLineNo() const
StringRef getName() const
DIScope * getScope() const
DIGlobalVariable * getDecl() const
static LLVM_ABI std::optional< DebugEmissionKind > getEmissionKind(StringRef Str)
A BaseTypeRef DIE.
Definition DIE.h:363
A BaseTypeRef DIE.
Definition DIE.h:244
DIEBlock - Represents a block of values.
Definition DIE.h:1056
DwarfExpression implementation for singular DW_AT_location.
An expression DIE.
Definition DIE.h:208
An integer value DIE.
Definition DIE.h:169
A label DIE.
Definition DIE.h:226
Represents a pointer to a location list in the debug_loc section.
Definition DIE.h:344
DIELoc - Represents an expression location.
Definition DIE.h:1020
DIE & getUnitDie()
Definition DIE.h:1009
A list of DIE values.
Definition DIE.h:698
A structured debug information entry.
Definition DIE.h:828
LLVM_ABI DIEValue findAttribute(dwarf::Attribute Attribute) const
Find a value in the DIE with the attribute given.
Definition DIE.cpp:210
DIE & addChild(DIE *Child)
Add a child to the DIE.
Definition DIE.h:944
DIE & addChildFront(DIE *Child)
Definition DIE.h:951
static DIE * get(BumpPtrAllocator &Alloc, dwarf::Tag Tag)
Definition DIE.h:858
LLVM_ABI const DIE * getUnitDie() const
Climb up the parent chain to get the compile unit or type unit DIE that this DIE belongs to.
Definition DIE.cpp:191
Holds a DIExpression and keeps track of how many operands have been consumed so far.
DWARF expression.
element_iterator elements_end() const
LLVM_ABI bool isEntryValue() const
Check if the expression consists of exactly one entry value operand.
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 <DWARFAddress Space> DW_OP_swap DW_O...
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.
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.
uint32_t getAlignInBytes() const
DIScope * getScope() const
DIType * getType() const
StringRef getName() const
LLVM_ABI unsigned getPointerSize(unsigned AS=0) const
The pointer representation size in bytes, rounded up to a whole number of bytes.
This class is defined as the common parent of DbgVariable and DbgLabel such that it could levarage po...
Definition DwarfDebug.h: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...
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
Loc::Variant & asVariant()
To workaround P2162R0 https://github.com/cplusplus/papers/issues/873 the base class subobject needs t...
Definition DwarfDebug.h:220
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:187
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition DenseMap.h:214
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.
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 & getOrCreateAbstractSubprogramDIE(const DISubprogram *SP)
Create an abstract subprogram DIE, that should later be populated by constructAbstractSubprogramScope...
DIE & constructSubprogramScopeDIE(const DISubprogram *Sub, const Function &F, LexicalScope *Scope, MCSymbol *LineTableSym)
Construct a DIE for this subprogram scope.
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.
DIE & updateSubprogramScopeDIE(const DISubprogram *SP, const Function &F, MCSymbol *LineTableSym)
Find DIE for the given subprogram and attach appropriate DW_AT_low_pc, DW_AT_high_pc and DW_AT_LLVM_s...
void createAbstractEntity(const DINode *Node, LexicalScope *Scope)
void applyStmtList(DIE &D)
Apply the DW_AT_stmt_list from this compile unit to the specified DIE.
DIE * getOrCreateSubprogramDIE(const DISubprogram *SP, const Function *F, bool Minimal=false) override
DIE * getOrCreateContextDIE(const DIScope *Ty) override
Construct a DIE for a given scope.
void applyCommonDbgVariableAttributes(const DbgVariable &Var, DIE &VariableDie)
Add attributes to Var which reflect the common attributes of VariableDie, namely those which are not ...
DIE & constructCallSiteEntryDIE(DIE &ScopeDIE, const DISubprogram *CalleeSP, const Function *CalleeF, 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 and ...
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.
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
uint16_t getDwarfVersion() const
Returns the Dwarf Version.
DwarfCompileUnit * lookupCU(const DIE *Die)
Find the matching DwarfCompileUnit for the given CU DIE.
Definition DwarfDebug.h:904
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
void addAccelName(const DwarfUnit &Unit, const DICompileUnit::DebugNameTableKind NameTableKind, StringRef Name, const DIE &Die)
void setLocation(const MachineLocation &Loc, const DIExpression *DIExpr)
Set the location (Loc) and DIExpression (DIExpr) to describe.
void addFragmentOffset(const DIExpression *Expr)
If applicable, emit an empty DW_OP_piece / DW_OP_bit_piece to advance to the fragment described by Ex...
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.
virtual DIE * getOrCreateTypeDIE(const MDNode *TyNode)
Find existing DIE or create new DIE for the given type.
DwarfDebug & getDwarfDebug() const
Definition DwarfUnit.h:112
void addAnnotation(DIE &Buffer, DINodeArray Annotations)
Add DW_TAG_LLVM_annotation.
void addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Loc)
Add block data.
void addTemplateParams(DIE &Buffer, DINodeArray TParams)
Add template parameters in buffer.
virtual DIE * getOrCreateContextDIE(const DIScope *Context)
Get context owner's DIE.
void addAttribute(DIEValueList &Die, dwarf::Attribute Attribute, dwarf::Form Form, T &&Value)
Definition DwarfUnit.h: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...
void addUInt(DIEValueList &Die, dwarf::Attribute Attribute, std::optional< dwarf::Form > Form, uint64_t Integer)
Add an unsigned integer attribute data and value.
void addString(DIE &Die, dwarf::Attribute Attribute, StringRef Str)
Add a string attribute data and value.
void addConstantValue(DIE &Die, const ConstantInt *CI, const DIType *Ty)
Add constant value entry in variable DIE.
DIE * getOrCreateNameSpace(const DINamespace *NS)
void insertDIE(const DINode *Desc, DIE *D)
Insert DIE into the map.
void addSectionDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo)
addSectionDelta - Add a label delta attribute data and value.
bool shouldPlaceInUnitDIE(const DISubprogram *SP, bool Minimal)
Definition DwarfUnit.h:348
DwarfDebug * DD
Definition DwarfUnit.h:55
const DICompileUnit * CUNode
MDNode for the compile unit.
Definition DwarfUnit.h:40
virtual DIE * getOrCreateSubprogramDIE(const DISubprogram *SP, const Function *FnHint, bool Minimal=false)
DIE * getOrCreateSubprogramContextDIE(const DISubprogram *SP, bool IgnoreScope)
Definition DwarfUnit.h:353
DIE * getDIE(const DINode *D) const
Returns the DIE map slot for the specified debug variable.
MCSymbol * LabelBegin
The start of the unit within its section.
Definition DwarfUnit.h:49
void addSInt(DIEValueList &Die, dwarf::Attribute Attribute, std::optional< dwarf::Form > Form, int64_t Integer)
Add an signed integer attribute data and value.
DwarfUnit(dwarf::Tag, const DICompileUnit *Node, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU, unsigned UniqueID=0)
Definition DwarfUnit.cpp:83
void addLabelDelta(DIEValueList &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo)
Add a label delta attribute data and value.
void addLinkageName(DIE &Die, StringRef LinkageName)
Add a linkage name, if it isn't empty.
std::string getParentContextString(const DIScope *Context) const
Get string containing language specific context for a global name.
void addSourceLine(DIE &Die, unsigned Line, unsigned Column, const DIFile *File)
Add location information to specified debug information entry.
void emitCommonHeader(bool UseOffsets, dwarf::UnitType UT)
Emit the common part of the header for this unit.
BumpPtrAllocator DIEValueAllocator
Definition DwarfUnit.h:43
DIE * getOrCreateModule(const DIModule *M)
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.
DwarfFile * DU
Definition DwarfUnit.h:56
DIE * getOrCreateStaticMemberDIE(const DIDerivedType *DT)
Create new static data member DIE.
void addLabel(DIEValueList &Die, dwarf::Attribute Attribute, dwarf::Form Form, const MCSymbol *Label)
Add a Dwarf label attribute data and value.
void addConstantFPValue(DIE &Die, const ConstantFP *CFP)
Add constant value entry in variable DIE.
void addSectionLabel(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Label, const MCSymbol *Sec)
Add a Dwarf section label attribute data and value.
void addPoolOpAddress(DIEValueList &Die, const MCSymbol *Label)
void constructTypeDIE(DIE &Buffer, const DICompositeType *CTy)
MCSymbol * EndLabel
Emitted at the end of the CU and used to compute the CU Length field.
Definition DwarfUnit.h:52
void addFlag(DIE &Die, dwarf::Attribute Attribute)
Add a flag that is true to the DIE.
AsmPrinter * Asm
Target of Dwarf emission.
Definition DwarfUnit.h: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.
void applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie, bool SkipSPAttributes=false)
void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry)
Add a DIE attribute data and value.
This class is used to track scope information.
Multi-value location description.
Definition DwarfDebug.h: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
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
MCSection * getDwarfRangesSection() const
MCSection * getDwarfAddrSection() const
MCSection * getDwarfLineSection() const
MCSymbol * getBeginSymbol()
Definition MCSection.h:593
void setType(wasm::WasmSymbolType type)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition MCSymbol.h:233
Tuple of metadata.
Definition Metadata.h:1489
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
Implements a dense probed hash-table based set with some number of buckets stored inline.
Definition DenseSet.h:281
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h: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...
const Triple & getTargetTriple() const
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
bool isNVPTX() const
Tests whether the target is NVPTX (32- or 64-bit).
Definition Triple.h:899
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
Definition Twine.h:461
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h: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.
bool tuneForSCE() const
Definition DwarfDebug.h:925
bool tuneForGDB() const
Definition DwarfDebug.h:923
LLVM_ABI StringRef AttributeEncodingString(unsigned Encoding)
Definition Dwarf.cpp:263
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ Entry
Definition COFF.h:862
initializer< Ty > init(const Ty &Val)
@ DW_INL_inlined
Definition Dwarf.h:770
Attribute
Attributes.
Definition Dwarf.h:125
UnitType
Constants for unit types in DWARF v5.
Definition Dwarf.h:889
@ 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.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:649
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
Definition Casting.h:738
bool isa_and_nonnull(const Y &Val)
Definition Casting.h:682
std::pair< const MachineInstr *, const MachineInstr * > InsnRange
This is used to track range of instructions with identical lexical scope.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1712
auto reverse(ContainerTy &&C)
Definition STLExtras.h:408
@ Apple
.apple_names, .apple_namespaces, .apple_types, .apple_objc.
Definition DwarfDebug.h:346
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:548
@ Global
Append to llvm.global_dtors.
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
Definition MathExtras.h:405
@ 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:1934
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:565
LLVM_ABI DISubprogram * getDISubprogram(const MDNode *Scope)
Find subprogram that is enclosing this scope.
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.
const MCSymbol * End
Definition DwarfFile.h:41
const MCSymbol * Begin
Definition DwarfFile.h:40
Helper used to pair up a symbol and its DWARF compile unit.
Definition DwarfDebug.h:335
union llvm::TargetFrameLowering::DwarfFrameBase::@004076321055032247336074224075335064105264310375 Location
enum llvm::TargetFrameLowering::DwarfFrameBase::FrameBaseKind Kind