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