LLVM 18.0.0git
LVELFReader.cpp
Go to the documentation of this file.
1//===-- LVELFReader.cpp ---------------------------------------------------===//
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 implements the LVELFReader class.
10// It supports ELF and Mach-O formats.
11//
12//===----------------------------------------------------------------------===//
13
22#include "llvm/Object/Error.h"
23#include "llvm/Object/MachO.h"
25
26using namespace llvm;
27using namespace llvm::object;
28using namespace llvm::logicalview;
29
30#define DEBUG_TYPE "ElfReader"
31
32LVElement *LVELFReader::createElement(dwarf::Tag Tag) {
33 CurrentScope = nullptr;
34 CurrentSymbol = nullptr;
35 CurrentType = nullptr;
36 CurrentRanges.clear();
37
38 if (!options().getPrintSymbols()) {
39 switch (Tag) {
40 // As the command line options did not specify a request to print
41 // logical symbols (--print=symbols or --print=all or --print=elements),
42 // skip its creation.
43 case dwarf::DW_TAG_formal_parameter:
44 case dwarf::DW_TAG_unspecified_parameters:
45 case dwarf::DW_TAG_member:
46 case dwarf::DW_TAG_variable:
47 case dwarf::DW_TAG_inheritance:
48 case dwarf::DW_TAG_constant:
49 case dwarf::DW_TAG_call_site_parameter:
50 case dwarf::DW_TAG_GNU_call_site_parameter:
51 return nullptr;
52 default:
53 break;
54 }
55 }
56
57 switch (Tag) {
58 // Types.
59 case dwarf::DW_TAG_base_type:
60 CurrentType = createType();
61 CurrentType->setIsBase();
62 if (options().getAttributeBase())
63 CurrentType->setIncludeInPrint();
64 return CurrentType;
65 case dwarf::DW_TAG_const_type:
66 CurrentType = createType();
67 CurrentType->setIsConst();
68 CurrentType->setName("const");
69 return CurrentType;
70 case dwarf::DW_TAG_enumerator:
71 CurrentType = createTypeEnumerator();
72 return CurrentType;
73 case dwarf::DW_TAG_imported_declaration:
74 CurrentType = createTypeImport();
75 CurrentType->setIsImportDeclaration();
76 return CurrentType;
77 case dwarf::DW_TAG_imported_module:
78 CurrentType = createTypeImport();
79 CurrentType->setIsImportModule();
80 return CurrentType;
81 case dwarf::DW_TAG_pointer_type:
82 CurrentType = createType();
83 CurrentType->setIsPointer();
84 CurrentType->setName("*");
85 return CurrentType;
86 case dwarf::DW_TAG_ptr_to_member_type:
87 CurrentType = createType();
88 CurrentType->setIsPointerMember();
89 CurrentType->setName("*");
90 return CurrentType;
91 case dwarf::DW_TAG_reference_type:
92 CurrentType = createType();
93 CurrentType->setIsReference();
94 CurrentType->setName("&");
95 return CurrentType;
96 case dwarf::DW_TAG_restrict_type:
97 CurrentType = createType();
98 CurrentType->setIsRestrict();
99 CurrentType->setName("restrict");
100 return CurrentType;
101 case dwarf::DW_TAG_rvalue_reference_type:
102 CurrentType = createType();
103 CurrentType->setIsRvalueReference();
104 CurrentType->setName("&&");
105 return CurrentType;
106 case dwarf::DW_TAG_subrange_type:
107 CurrentType = createTypeSubrange();
108 return CurrentType;
109 case dwarf::DW_TAG_template_value_parameter:
110 CurrentType = createTypeParam();
111 CurrentType->setIsTemplateValueParam();
112 return CurrentType;
113 case dwarf::DW_TAG_template_type_parameter:
114 CurrentType = createTypeParam();
115 CurrentType->setIsTemplateTypeParam();
116 return CurrentType;
117 case dwarf::DW_TAG_GNU_template_template_param:
118 CurrentType = createTypeParam();
119 CurrentType->setIsTemplateTemplateParam();
120 return CurrentType;
121 case dwarf::DW_TAG_typedef:
122 CurrentType = createTypeDefinition();
123 return CurrentType;
124 case dwarf::DW_TAG_unspecified_type:
125 CurrentType = createType();
126 CurrentType->setIsUnspecified();
127 return CurrentType;
128 case dwarf::DW_TAG_volatile_type:
129 CurrentType = createType();
130 CurrentType->setIsVolatile();
131 CurrentType->setName("volatile");
132 return CurrentType;
133
134 // Symbols.
135 case dwarf::DW_TAG_formal_parameter:
136 CurrentSymbol = createSymbol();
137 CurrentSymbol->setIsParameter();
138 return CurrentSymbol;
139 case dwarf::DW_TAG_unspecified_parameters:
140 CurrentSymbol = createSymbol();
141 CurrentSymbol->setIsUnspecified();
142 CurrentSymbol->setName("...");
143 return CurrentSymbol;
144 case dwarf::DW_TAG_member:
145 CurrentSymbol = createSymbol();
146 CurrentSymbol->setIsMember();
147 return CurrentSymbol;
148 case dwarf::DW_TAG_variable:
149 CurrentSymbol = createSymbol();
150 CurrentSymbol->setIsVariable();
151 return CurrentSymbol;
152 case dwarf::DW_TAG_inheritance:
153 CurrentSymbol = createSymbol();
154 CurrentSymbol->setIsInheritance();
155 return CurrentSymbol;
156 case dwarf::DW_TAG_call_site_parameter:
157 case dwarf::DW_TAG_GNU_call_site_parameter:
158 CurrentSymbol = createSymbol();
159 CurrentSymbol->setIsCallSiteParameter();
160 return CurrentSymbol;
161 case dwarf::DW_TAG_constant:
162 CurrentSymbol = createSymbol();
163 CurrentSymbol->setIsConstant();
164 return CurrentSymbol;
165
166 // Scopes.
167 case dwarf::DW_TAG_catch_block:
168 CurrentScope = createScope();
169 CurrentScope->setIsCatchBlock();
170 return CurrentScope;
171 case dwarf::DW_TAG_lexical_block:
172 CurrentScope = createScope();
173 CurrentScope->setIsLexicalBlock();
174 return CurrentScope;
175 case dwarf::DW_TAG_try_block:
176 CurrentScope = createScope();
177 CurrentScope->setIsTryBlock();
178 return CurrentScope;
179 case dwarf::DW_TAG_compile_unit:
180 case dwarf::DW_TAG_skeleton_unit:
181 CurrentScope = createScopeCompileUnit();
182 CompileUnit = static_cast<LVScopeCompileUnit *>(CurrentScope);
183 return CurrentScope;
184 case dwarf::DW_TAG_inlined_subroutine:
185 CurrentScope = createScopeFunctionInlined();
186 return CurrentScope;
187 case dwarf::DW_TAG_namespace:
188 CurrentScope = createScopeNamespace();
189 return CurrentScope;
190 case dwarf::DW_TAG_template_alias:
191 CurrentScope = createScopeAlias();
192 return CurrentScope;
193 case dwarf::DW_TAG_array_type:
194 CurrentScope = createScopeArray();
195 return CurrentScope;
196 case dwarf::DW_TAG_call_site:
197 case dwarf::DW_TAG_GNU_call_site:
198 CurrentScope = createScopeFunction();
199 CurrentScope->setIsCallSite();
200 return CurrentScope;
201 case dwarf::DW_TAG_entry_point:
202 CurrentScope = createScopeFunction();
203 CurrentScope->setIsEntryPoint();
204 return CurrentScope;
205 case dwarf::DW_TAG_subprogram:
206 CurrentScope = createScopeFunction();
207 CurrentScope->setIsSubprogram();
208 return CurrentScope;
209 case dwarf::DW_TAG_subroutine_type:
210 CurrentScope = createScopeFunctionType();
211 return CurrentScope;
212 case dwarf::DW_TAG_label:
213 CurrentScope = createScopeFunction();
214 CurrentScope->setIsLabel();
215 return CurrentScope;
216 case dwarf::DW_TAG_class_type:
217 CurrentScope = createScopeAggregate();
218 CurrentScope->setIsClass();
219 return CurrentScope;
220 case dwarf::DW_TAG_structure_type:
221 CurrentScope = createScopeAggregate();
222 CurrentScope->setIsStructure();
223 return CurrentScope;
224 case dwarf::DW_TAG_union_type:
225 CurrentScope = createScopeAggregate();
226 CurrentScope->setIsUnion();
227 return CurrentScope;
228 case dwarf::DW_TAG_enumeration_type:
229 CurrentScope = createScopeEnumeration();
230 return CurrentScope;
231 case dwarf::DW_TAG_GNU_formal_parameter_pack:
232 CurrentScope = createScopeFormalPack();
233 return CurrentScope;
234 case dwarf::DW_TAG_GNU_template_parameter_pack:
235 CurrentScope = createScopeTemplatePack();
236 return CurrentScope;
237 default:
238 // Collect TAGs not implemented.
239 if (options().getInternalTag() && Tag)
240 CompileUnit->addDebugTag(Tag, CurrentOffset);
241 break;
242 }
243 return nullptr;
244}
245
246void LVELFReader::processOneAttribute(const DWARFDie &Die, LVOffset *OffsetPtr,
247 const AttributeSpec &AttrSpec) {
248 uint64_t OffsetOnEntry = *OffsetPtr;
249 DWARFUnit *U = Die.getDwarfUnit();
250 const DWARFFormValue &FormValue =
251 DWARFFormValue::createFromUnit(AttrSpec.Form, U, OffsetPtr);
252
253 // We are processing .debug_info section, implicit_const attribute
254 // values are not really stored here, but in .debug_abbrev section.
255 auto GetAsUnsignedConstant = [&]() -> int64_t {
256 return AttrSpec.isImplicitConst() ? AttrSpec.getImplicitConstValue()
257 : *FormValue.getAsUnsignedConstant();
258 };
259
260 auto GetFlag = [](const DWARFFormValue &FormValue) -> bool {
261 return FormValue.isFormClass(DWARFFormValue::FC_Flag);
262 };
263
264 auto GetBoundValue = [](const DWARFFormValue &FormValue) -> int64_t {
265 switch (FormValue.getForm()) {
266 case dwarf::DW_FORM_ref_addr:
267 case dwarf::DW_FORM_ref1:
268 case dwarf::DW_FORM_ref2:
269 case dwarf::DW_FORM_ref4:
270 case dwarf::DW_FORM_ref8:
271 case dwarf::DW_FORM_ref_udata:
272 case dwarf::DW_FORM_ref_sig8:
273 return *FormValue.getAsReferenceUVal();
274 case dwarf::DW_FORM_data1:
275 case dwarf::DW_FORM_flag:
276 case dwarf::DW_FORM_data2:
277 case dwarf::DW_FORM_data4:
278 case dwarf::DW_FORM_data8:
279 case dwarf::DW_FORM_udata:
280 case dwarf::DW_FORM_ref_sup4:
281 case dwarf::DW_FORM_ref_sup8:
282 return *FormValue.getAsUnsignedConstant();
283 case dwarf::DW_FORM_sdata:
284 return *FormValue.getAsSignedConstant();
285 default:
286 return 0;
287 }
288 };
289
290 LLVM_DEBUG({
291 dbgs() << " " << hexValue(OffsetOnEntry)
292 << formatv(" {0}", AttrSpec.Attr) << "\n";
293 });
294
295 switch (AttrSpec.Attr) {
296 case dwarf::DW_AT_accessibility:
297 CurrentElement->setAccessibilityCode(*FormValue.getAsUnsignedConstant());
298 break;
299 case dwarf::DW_AT_artificial:
300 CurrentElement->setIsArtificial();
301 break;
302 case dwarf::DW_AT_bit_size:
303 CurrentElement->setBitSize(*FormValue.getAsUnsignedConstant());
304 break;
305 case dwarf::DW_AT_call_file:
306 CurrentElement->setCallFilenameIndex(GetAsUnsignedConstant());
307 break;
308 case dwarf::DW_AT_call_line:
309 CurrentElement->setCallLineNumber(IncrementFileIndex
310 ? GetAsUnsignedConstant() + 1
311 : GetAsUnsignedConstant());
312 break;
313 case dwarf::DW_AT_comp_dir:
314 CompileUnit->setCompilationDirectory(dwarf::toStringRef(FormValue));
315 break;
316 case dwarf::DW_AT_const_value:
317 if (FormValue.isFormClass(DWARFFormValue::FC_Block)) {
318 ArrayRef<uint8_t> Expr = *FormValue.getAsBlock();
319 // Store the expression as a hexadecimal string.
320 CurrentElement->setValue(
321 llvm::toHex(llvm::toStringRef(Expr), /*LowerCase=*/true));
322 } else if (FormValue.isFormClass(DWARFFormValue::FC_Constant)) {
323 // In the case of negative values, generate the string representation
324 // for a positive value prefixed with the negative sign.
325 if (FormValue.getForm() == dwarf::DW_FORM_sdata) {
326 std::stringstream Stream;
327 int64_t Value = *FormValue.getAsSignedConstant();
328 if (Value < 0) {
329 Stream << "-";
330 Value = std::abs(Value);
331 }
332 Stream << hexString(Value, 2);
333 CurrentElement->setValue(Stream.str());
334 } else
335 CurrentElement->setValue(
336 hexString(*FormValue.getAsUnsignedConstant(), 2));
337 } else
338 CurrentElement->setValue(dwarf::toStringRef(FormValue));
339 break;
340 case dwarf::DW_AT_count:
341 CurrentElement->setCount(*FormValue.getAsUnsignedConstant());
342 break;
343 case dwarf::DW_AT_decl_line:
344 CurrentElement->setLineNumber(GetAsUnsignedConstant());
345 break;
346 case dwarf::DW_AT_decl_file:
347 CurrentElement->setFilenameIndex(IncrementFileIndex
348 ? GetAsUnsignedConstant() + 1
349 : GetAsUnsignedConstant());
350 break;
351 case dwarf::DW_AT_enum_class:
352 if (GetFlag(FormValue))
353 CurrentElement->setIsEnumClass();
354 break;
355 case dwarf::DW_AT_external:
356 if (GetFlag(FormValue))
357 CurrentElement->setIsExternal();
358 break;
359 case dwarf::DW_AT_GNU_discriminator:
360 CurrentElement->setDiscriminator(*FormValue.getAsUnsignedConstant());
361 break;
362 case dwarf::DW_AT_inline:
363 CurrentElement->setInlineCode(*FormValue.getAsUnsignedConstant());
364 break;
365 case dwarf::DW_AT_lower_bound:
366 CurrentElement->setLowerBound(GetBoundValue(FormValue));
367 break;
368 case dwarf::DW_AT_name:
369 CurrentElement->setName(dwarf::toStringRef(FormValue));
370 break;
371 case dwarf::DW_AT_linkage_name:
372 case dwarf::DW_AT_MIPS_linkage_name:
373 CurrentElement->setLinkageName(dwarf::toStringRef(FormValue));
374 break;
375 case dwarf::DW_AT_producer:
376 if (options().getAttributeProducer())
377 CurrentElement->setProducer(dwarf::toStringRef(FormValue));
378 break;
379 case dwarf::DW_AT_upper_bound:
380 CurrentElement->setUpperBound(GetBoundValue(FormValue));
381 break;
382 case dwarf::DW_AT_virtuality:
383 CurrentElement->setVirtualityCode(*FormValue.getAsUnsignedConstant());
384 break;
385
386 case dwarf::DW_AT_abstract_origin:
387 case dwarf::DW_AT_call_origin:
388 case dwarf::DW_AT_extension:
389 case dwarf::DW_AT_import:
390 case dwarf::DW_AT_specification:
391 case dwarf::DW_AT_type:
392 updateReference(AttrSpec.Attr, FormValue);
393 break;
394
395 case dwarf::DW_AT_low_pc:
396 if (options().getGeneralCollectRanges()) {
397 FoundLowPC = true;
398 // For toolchains that support the removal of unused code, the linker
399 // marks functions that have been removed, by setting the value for the
400 // low_pc to the max address.
401 if (std::optional<uint64_t> Value = FormValue.getAsAddress()) {
402 CurrentLowPC = *Value;
403 } else {
404 uint64_t UValue = FormValue.getRawUValue();
405 if (U->getAddrOffsetSectionItem(UValue)) {
406 CurrentLowPC = *FormValue.getAsAddress();
407 } else {
408 FoundLowPC = false;
409 // We are dealing with an index into the .debug_addr section.
410 LLVM_DEBUG({
411 dbgs() << format("indexed (%8.8x) address = ", (uint32_t)UValue);
412 });
413 }
414 }
415 if (FoundLowPC) {
416 if (CurrentLowPC == MaxAddress)
417 CurrentElement->setIsDiscarded();
418 if (CurrentElement->isCompileUnit())
419 setCUBaseAddress(CurrentLowPC);
420 }
421 }
422 break;
423
424 case dwarf::DW_AT_high_pc:
425 if (options().getGeneralCollectRanges()) {
426 FoundHighPC = true;
427 if (std::optional<uint64_t> Address = FormValue.getAsAddress())
428 // High PC is an address.
429 CurrentHighPC = *Address;
430 if (std::optional<uint64_t> Offset = FormValue.getAsUnsignedConstant())
431 // High PC is an offset from LowPC.
432 CurrentHighPC = CurrentLowPC + *Offset;
433 // Store the real upper limit for the address range.
434 if (UpdateHighAddress && CurrentHighPC > 0)
435 --CurrentHighPC;
436 if (CurrentElement->isCompileUnit())
437 setCUHighAddress(CurrentHighPC);
438 }
439 break;
440
441 case dwarf::DW_AT_ranges:
442 if (RangesDataAvailable && options().getGeneralCollectRanges()) {
443 auto GetRanges = [](const DWARFFormValue &FormValue,
445 if (FormValue.getForm() == dwarf::DW_FORM_rnglistx)
446 return U->findRnglistFromIndex(*FormValue.getAsSectionOffset());
447 return U->findRnglistFromOffset(*FormValue.getAsSectionOffset());
448 };
450 GetRanges(FormValue, U);
451 if (!RangesOrError) {
452 LLVM_DEBUG({
453 std::string TheError(toString(RangesOrError.takeError()));
454 dbgs() << format("error decoding address ranges = ",
455 TheError.c_str());
456 });
457 consumeError(RangesOrError.takeError());
458 break;
459 }
460 // The address ranges are absolute. There is no need to add any addend.
461 DWARFAddressRangesVector Ranges = RangesOrError.get();
463 // This seems to be a tombstone for empty ranges.
464 if (Range.LowPC == Range.HighPC)
465 continue;
466 // Store the real upper limit for the address range.
467 if (UpdateHighAddress && Range.HighPC > 0)
468 --Range.HighPC;
469 // Add the pair of addresses.
470 CurrentScope->addObject(Range.LowPC, Range.HighPC);
471 // If the scope is the CU, do not update the ranges set.
472 if (!CurrentElement->isCompileUnit())
473 CurrentRanges.emplace_back(Range.LowPC, Range.HighPC);
474 }
475 }
476 break;
477
478 // Get the location list for the symbol.
479 case dwarf::DW_AT_data_member_location:
480 if (options().getAttributeAnyLocation())
481 processLocationMember(AttrSpec.Attr, FormValue, Die, OffsetOnEntry);
482 break;
483
484 // Get the location list for the symbol.
485 case dwarf::DW_AT_location:
486 case dwarf::DW_AT_string_length:
487 case dwarf::DW_AT_use_location:
488 if (options().getAttributeAnyLocation() && CurrentSymbol)
489 processLocationList(AttrSpec.Attr, FormValue, Die, OffsetOnEntry);
490 break;
491
492 case dwarf::DW_AT_call_data_value:
493 case dwarf::DW_AT_call_value:
494 case dwarf::DW_AT_GNU_call_site_data_value:
495 case dwarf::DW_AT_GNU_call_site_value:
496 if (options().getAttributeAnyLocation() && CurrentSymbol)
497 processLocationList(AttrSpec.Attr, FormValue, Die, OffsetOnEntry,
498 /*CallSiteLocation=*/true);
499 break;
500
501 default:
502 break;
503 }
504}
505
506LVScope *LVELFReader::processOneDie(const DWARFDie &InputDIE, LVScope *Parent,
507 DWARFDie &SkeletonDie) {
508 // If the input DIE corresponds to the compile unit, it can be:
509 // a) Simple DWARF: a standard DIE. Ignore the skeleton DIE (is empty).
510 // b) Split DWARF: the DIE for the split DWARF. The skeleton is the DIE
511 // for the skeleton DWARF. Process both DIEs.
512 const DWARFDie &DIE = SkeletonDie.isValid() ? SkeletonDie : InputDIE;
513 DWARFDataExtractor DebugInfoData =
514 DIE.getDwarfUnit()->getDebugInfoExtractor();
516
517 // Reset values for the current DIE.
518 CurrentLowPC = 0;
519 CurrentHighPC = 0;
520 CurrentOffset = Offset;
521 CurrentEndOffset = 0;
522 FoundLowPC = false;
523 FoundHighPC = false;
524
525 // Process supported attributes.
526 if (DebugInfoData.isValidOffset(Offset)) {
527
528 LLVM_DEBUG({
529 dbgs() << "DIE: " << hexValue(Offset) << formatv(" {0}", DIE.getTag())
530 << "\n";
531 });
532
533 // Create the logical view element for the current DIE.
535 CurrentElement = createElement(Tag);
536 if (!CurrentElement)
537 return CurrentScope;
538
539 CurrentElement->setTag(Tag);
540 CurrentElement->setOffset(Offset);
541
542 if (options().getAttributeAnySource() && CurrentElement->isCompileUnit())
544 static_cast<LVScopeCompileUnit *>(CurrentElement));
545
546 // Insert the newly created element into the element symbol table. If the
547 // element is in the list, it means there are previously created elements
548 // referencing this element.
549 if (ElementTable.find(Offset) == ElementTable.end()) {
550 // No previous references to this offset.
551 ElementTable.emplace(std::piecewise_construct,
552 std::forward_as_tuple(Offset),
553 std::forward_as_tuple(CurrentElement));
554 } else {
555 // There are previous references to this element. We need to update the
556 // element and all the references pointing to this element.
557 LVElementEntry &Reference = ElementTable[Offset];
558 Reference.Element = CurrentElement;
559 // Traverse the element set and update the elements (backtracking).
560 for (LVElement *Target : Reference.References)
561 Target->setReference(CurrentElement);
562 for (LVElement *Target : Reference.Types)
563 Target->setType(CurrentElement);
564 // Clear the pending elements.
565 Reference.References.clear();
566 Reference.Types.clear();
567 }
568
569 // Add the current element to its parent as there are attributes
570 // (locations) that require the scope level.
571 if (CurrentScope)
572 Parent->addElement(CurrentScope);
573 else if (CurrentSymbol)
574 Parent->addElement(CurrentSymbol);
575 else if (CurrentType)
576 Parent->addElement(CurrentType);
577
578 // Process the attributes for the given DIE.
579 auto ProcessAttributes = [&](const DWARFDie &TheDIE,
580 DWARFDataExtractor &DebugData) {
581 CurrentEndOffset = Offset;
582 uint32_t abbrCode = DebugData.getULEB128(&CurrentEndOffset);
583 if (abbrCode) {
584 if (const DWARFAbbreviationDeclaration *AbbrevDecl =
586 if (AbbrevDecl)
588 AbbrevDecl->attributes())
589 processOneAttribute(TheDIE, &CurrentEndOffset, AttrSpec);
590 }
591 };
592
593 ProcessAttributes(DIE, DebugInfoData);
594
595 // If the input DIE is for a compile unit, process its attributes in
596 // the case of split DWARF, to override any common attribute values.
597 if (SkeletonDie.isValid()) {
598 DWARFDataExtractor DebugInfoData =
600 LVOffset Offset = InputDIE.getOffset();
601 if (DebugInfoData.isValidOffset(Offset))
602 ProcessAttributes(InputDIE, DebugInfoData);
603 }
604 }
605
606 if (CurrentScope) {
607 if (CurrentScope->getCanHaveRanges()) {
608 // If the scope has ranges, they are already added to the scope.
609 // Add any collected LowPC/HighPC values.
610 bool IsCompileUnit = CurrentScope->getIsCompileUnit();
611 if (FoundLowPC && FoundHighPC) {
612 CurrentScope->addObject(CurrentLowPC, CurrentHighPC);
613 if (!IsCompileUnit) {
614 // If the scope is a function, add it to the public names.
615 if ((options().getAttributePublics() ||
616 options().getPrintAnyLine()) &&
617 CurrentScope->getIsFunction() &&
618 !CurrentScope->getIsInlinedFunction())
619 CompileUnit->addPublicName(CurrentScope, CurrentLowPC,
620 CurrentHighPC);
621 }
622 }
623
624 // Look for scopes with ranges and no linkage name information that
625 // are referencing another scopes via DW_AT_specification. They are
626 // possible candidates for a comdat scope.
627 if (CurrentScope->getHasRanges() &&
628 !CurrentScope->getLinkageNameIndex() &&
629 CurrentScope->getHasReferenceSpecification()) {
630 // Get the linkage name in order to search for a possible comdat.
631 std::optional<DWARFFormValue> LinkageDIE =
632 DIE.findRecursively(dwarf::DW_AT_linkage_name);
633 if (LinkageDIE.has_value()) {
634 StringRef Name(dwarf::toStringRef(LinkageDIE));
635 if (!Name.empty())
636 CurrentScope->setLinkageName(Name);
637 }
638 }
639
640 // If the current scope is in the 'LinkageNames' table, update its
641 // logical scope. For other scopes, always we will assume the default
642 // ".text" section index.
643 LVSectionIndex SectionIndex = updateSymbolTable(CurrentScope);
644 if (CurrentScope->getIsComdat())
645 CompileUnit->setHasComdatScopes();
646
647 // Update section index contained ranges.
648 if (SectionIndex) {
649 if (!CurrentRanges.empty()) {
650 for (LVAddressRange &Range : CurrentRanges)
651 addSectionRange(SectionIndex, CurrentScope, Range.first,
652 Range.second);
653 CurrentRanges.clear();
654 }
655 // If the scope is the CU, do not update the ranges set.
656 if (FoundLowPC && FoundHighPC && !IsCompileUnit) {
657 addSectionRange(SectionIndex, CurrentScope, CurrentLowPC,
658 CurrentHighPC);
659 }
660 }
661 }
662 // Mark member functions.
663 if (Parent->getIsAggregate())
664 CurrentScope->setIsMember();
665 }
666
667 // Keep track of symbols with locations.
668 if (options().getAttributeAnyLocation() && CurrentSymbol &&
669 CurrentSymbol->getHasLocation())
670 SymbolsWithLocations.push_back(CurrentSymbol);
671
672 // If we have template parameters, mark the parent as template.
673 if (CurrentType && CurrentType->getIsTemplateParam())
674 Parent->setIsTemplate();
675
676 return CurrentScope;
677}
678
679void LVELFReader::traverseDieAndChildren(DWARFDie &DIE, LVScope *Parent,
680 DWARFDie &SkeletonDie) {
681 // Process the current DIE.
682 LVScope *Scope = processOneDie(DIE, Parent, SkeletonDie);
683 if (Scope) {
685 LVOffset Upper = CurrentEndOffset;
686 DWARFDie DummyDie;
687 // Traverse the children chain.
688 DWARFDie Child = DIE.getFirstChild();
689 while (Child) {
690 traverseDieAndChildren(Child, Scope, DummyDie);
691 Upper = Child.getOffset();
692 Child = Child.getSibling();
693 }
694 // Calculate contributions to the debug info section.
695 if (options().getPrintSizes() && Upper)
696 CompileUnit->addSize(Scope, Lower, Upper);
697 }
698}
699
700void LVELFReader::processLocationGaps() {
701 if (options().getAttributeAnyLocation())
702 for (LVSymbol *Symbol : SymbolsWithLocations)
703 Symbol->fillLocationGaps();
704}
705
706void LVELFReader::createLineAndFileRecords(
708 if (!Lines)
709 return;
710
711 // Get the source filenames.
712 if (!Lines->Prologue.FileNames.empty())
713 for (const DWARFDebugLine::FileNameEntry &Entry :
714 Lines->Prologue.FileNames) {
715 std::string Directory;
716 if (Lines->getDirectoryForEntry(Entry, Directory))
717 Directory = transformPath(Directory);
718 if (Directory.empty())
719 Directory = std::string(CompileUnit->getCompilationDirectory());
720 std::string File = transformPath(dwarf::toStringRef(Entry.Name));
721 std::string String;
722 raw_string_ostream(String) << Directory << "/" << File;
723 CompileUnit->addFilename(String);
724 }
725
726 // In DWARF5 the file indexes start at 0;
727 bool IncrementIndex = Lines->Prologue.getVersion() >= 5;
728
729 // Get the source lines if requested by command line option.
730 if (options().getPrintLines() && Lines->Rows.size())
731 for (const DWARFDebugLine::Row &Row : Lines->Rows) {
732 // Here we collect logical debug lines in CULines. Later on,
733 // the 'processLines()' function will move each created logical line
734 // to its enclosing logical scope, using the debug ranges information
735 // and they will be released when its scope parent is deleted.
736 LVLineDebug *Line = createLineDebug();
738 Line->setAddress(Row.Address.Address);
739 Line->setFilename(
740 CompileUnit->getFilename(IncrementIndex ? Row.File + 1 : Row.File));
741 Line->setLineNumber(Row.Line);
742 if (Row.Discriminator)
743 Line->setDiscriminator(Row.Discriminator);
744 if (Row.IsStmt)
745 Line->setIsNewStatement();
746 if (Row.BasicBlock)
747 Line->setIsBasicBlock();
748 if (Row.EndSequence)
749 Line->setIsEndSequence();
750 if (Row.EpilogueBegin)
751 Line->setIsEpilogueBegin();
752 if (Row.PrologueEnd)
753 Line->setIsPrologueEnd();
754 LLVM_DEBUG({
755 dbgs() << "Address: " << hexValue(Line->getAddress())
756 << " Line: " << Line->lineNumberAsString(/*ShowZero=*/true)
757 << "\n";
758 });
759 }
760}
761
764 // The 'prettyPrintRegisterOp' function uses the DWARFUnit to support
765 // DW_OP_regval_type. At this point we are operating on a logical view
766 // item, with no access to the underlying DWARF data used by LLVM.
767 // We do not support DW_OP_regval_type here.
768 if (Opcode == dwarf::DW_OP_regval_type)
769 return {};
770
771 std::string string;
772 raw_string_ostream Stream(string);
773 DIDumpOptions DumpOpts;
774 auto *MCRegInfo = MRI.get();
775 auto GetRegName = [&MCRegInfo](uint64_t DwarfRegNum, bool IsEH) -> StringRef {
776 if (!MCRegInfo)
777 return {};
778 if (std::optional<unsigned> LLVMRegNum =
779 MCRegInfo->getLLVMRegNum(DwarfRegNum, IsEH))
780 if (const char *RegName = MCRegInfo->getName(*LLVMRegNum))
781 return StringRef(RegName);
782 return {};
783 };
784 DumpOpts.GetNameForDWARFReg = GetRegName;
785 DWARFExpression::prettyPrintRegisterOp(/*U=*/nullptr, Stream, DumpOpts,
786 Opcode, Operands);
787 return Stream.str();
788}
789
791 LLVM_DEBUG({
792 W.startLine() << "\n";
793 W.printString("File", Obj.getFileName().str());
794 W.printString("Format", FileFormatName);
795 });
796
797 if (Error Err = LVReader::createScopes())
798 return Err;
799
800 // As the DwarfContext object is valid only during the scopes creation,
801 // we need to create our own Target information, to be used during the
802 // logical view printing, in the case of instructions being requested.
803 std::unique_ptr<DWARFContext> DwarfContext = DWARFContext::create(Obj);
804 if (!DwarfContext)
806 "Could not create DWARF information: %s",
807 getFilename().str().c_str());
808
809 if (Error Err = loadTargetInfo(Obj))
810 return Err;
811
812 // Create a mapping for virtual addresses.
814
815 // Select the correct compile unit range, depending if we are dealing with
816 // a standard or split DWARF object.
818 DwarfContext->getNumCompileUnits() ? DwarfContext->compile_units()
819 : DwarfContext->dwo_compile_units();
820 for (const std::unique_ptr<DWARFUnit> &CU : CompileUnits) {
821
822 // Deduction of index used for the line records.
823 //
824 // For the following test case: test.cpp
825 // void foo(void ParamPtr) { }
826
827 // Both GCC and Clang generate DWARF-5 .debug_line layout.
828
829 // * GCC (GNU C++17 11.3.0) - All DW_AT_decl_file use index 1.
830 //
831 // .debug_info:
832 // format = DWARF32, version = 0x0005
833 // DW_TAG_compile_unit
834 // DW_AT_name ("test.cpp")
835 // DW_TAG_subprogram ("foo")
836 // DW_AT_decl_file (1)
837 // DW_TAG_formal_parameter ("ParamPtr")
838 // DW_AT_decl_file (1)
839 // .debug_line:
840 // Line table prologue: format (DWARF32), version (5)
841 // include_directories[0] = "..."
842 // file_names[0]: name ("test.cpp"), dir_index (0)
843 // file_names[1]: name ("test.cpp"), dir_index (0)
844
845 // * Clang (14.0.6) - All DW_AT_decl_file use index 0.
846 //
847 // .debug_info:
848 // format = DWARF32, version = 0x0005
849 // DW_AT_producer ("clang version 14.0.6")
850 // DW_AT_name ("test.cpp")
851 //
852 // DW_TAG_subprogram ("foo")
853 // DW_AT_decl_file (0)
854 // DW_TAG_formal_parameter ("ParamPtr")
855 // DW_AT_decl_file (0)
856 // .debug_line:
857 // Line table prologue: format (DWARF32), version (5)
858 // include_directories[0] = "..."
859 // file_names[0]: name ("test.cpp"), dir_index (0)
860
861 // From DWARFDebugLine::getFileNameByIndex documentation:
862 // In Dwarf 4, the files are 1-indexed.
863 // In Dwarf 5, the files are 0-indexed.
864 // Additional discussions here:
865 // https://www.mail-archive.com/dwarf-discuss@lists.dwarfstd.org/msg00883.html
866
867 // The ELF Reader is expecting the files are 1-indexed, so using
868 // the .debug_line header information decide if the indexed require
869 // an internal adjustment.
870
871 // For the case of GCC (DWARF5), if the entries[0] and [1] are the
872 // same, do not perform any adjustment.
873 auto DeduceIncrementFileIndex = [&]() -> bool {
874 if (CU->getVersion() < 5)
875 // DWARF-4 or earlier -> Don't increment index.
876 return false;
877
878 if (const DWARFDebugLine::LineTable *LT =
879 CU->getContext().getLineTableForUnit(CU.get())) {
880 // Check if there are at least 2 entries and if they are the same.
881 if (LT->hasFileAtIndex(0) && LT->hasFileAtIndex(1)) {
882 const DWARFDebugLine::FileNameEntry &EntryZero =
883 LT->Prologue.getFileNameEntry(0);
884 const DWARFDebugLine::FileNameEntry &EntryOne =
885 LT->Prologue.getFileNameEntry(1);
886 // Check directory indexes.
887 if (EntryZero.DirIdx != EntryOne.DirIdx)
888 // DWARF-5 -> Increment index.
889 return true;
890 // Check filename.
891 std::string FileZero;
892 std::string FileOne;
894 LT->getFileNameByIndex(
895 0, None, DILineInfoSpecifier::FileLineInfoKind::RawValue,
896 FileZero);
897 LT->getFileNameByIndex(
898 1, None, DILineInfoSpecifier::FileLineInfoKind::RawValue,
899 FileOne);
900 return FileZero.compare(FileOne);
901 }
902 }
903
904 // DWARF-5 -> Increment index.
905 return true;
906 };
907 // The ELF reader expects the indexes as 1-indexed.
908 IncrementFileIndex = DeduceIncrementFileIndex();
909
910 DWARFDie UnitDie = CU->getUnitDIE();
911 SmallString<16> DWOAlternativeLocation;
912 if (UnitDie) {
913 std::optional<const char *> DWOFileName =
914 CU->getVersion() >= 5
915 ? dwarf::toString(UnitDie.find(dwarf::DW_AT_dwo_name))
916 : dwarf::toString(UnitDie.find(dwarf::DW_AT_GNU_dwo_name));
917 StringRef From(DWOFileName.value_or(""));
918 DWOAlternativeLocation = createAlternativePath(From);
919 }
920
921 // The current CU can be a normal compile unit (standard) or a skeleton
922 // compile unit (split). For both cases, the returned die, will be used
923 // to create the logical scopes.
924 DWARFDie CUDie = CU->getNonSkeletonUnitDIE(
925 /*ExtractUnitDIEOnly=*/false,
926 /*DWOAlternativeLocation=*/DWOAlternativeLocation);
927 if (!CUDie.isValid())
928 continue;
929
930 // The current unit corresponds to the .dwo file. We need to get the
931 // skeleton unit and query for any ranges that will enclose any ranges
932 // in the non-skeleton unit.
933 DWARFDie DummyDie;
934 DWARFDie SkeletonDie =
935 CUDie.getDwarfUnit()->isDWOUnit() ? CU->getUnitDIE(false) : DummyDie;
936 // Disable the ranges processing if we have just a single .dwo object,
937 // as any DW_AT_ranges will access not available range information.
938 RangesDataAvailable =
939 (!CUDie.getDwarfUnit()->isDWOUnit() ||
940 (SkeletonDie.isValid() ? !SkeletonDie.getDwarfUnit()->isDWOUnit()
941 : true));
942
943 traverseDieAndChildren(CUDie, Root, SkeletonDie);
944
945 createLineAndFileRecords(DwarfContext->getLineTableForUnit(CU.get()));
946 if (Error Err = createInstructions())
947 return Err;
948
949 // Process the compilation unit, as there are cases where enclosed
950 // functions have the same ranges values. Insert the compilation unit
951 // ranges at the end, to allow enclosing ranges to be first in the list.
953 addSectionRange(SectionIndex, CompileUnit);
954 LVRange *ScopesWithRanges = getSectionRanges(SectionIndex);
955 ScopesWithRanges->sort();
956
957 processLines(&CULines, SectionIndex);
958 processLocationGaps();
959
960 // These are per compile unit.
961 ScopesWithRanges->clear();
962 SymbolsWithLocations.clear();
963 CULines.clear();
964 }
965
966 return Error::success();
967}
968
969// Get the location information for the associated attribute.
970void LVELFReader::processLocationList(dwarf::Attribute Attr,
971 const DWARFFormValue &FormValue,
972 const DWARFDie &Die,
973 uint64_t OffsetOnEntry,
974 bool CallSiteLocation) {
975
976 auto ProcessLocationExpression = [&](const DWARFExpression &Expression) {
978 CurrentSymbol->addLocationOperands(Op.getCode(), Op.getRawOperands());
979 };
980
981 DWARFUnit *U = Die.getDwarfUnit();
982 DWARFContext &DwarfContext = U->getContext();
983 bool IsLittleEndian = DwarfContext.isLittleEndian();
984 if (FormValue.isFormClass(DWARFFormValue::FC_Block) ||
987 ArrayRef<uint8_t> Expr = *FormValue.getAsBlock();
988 DataExtractor Data(StringRef((const char *)Expr.data(), Expr.size()),
989 IsLittleEndian, 0);
990 DWARFExpression Expression(Data, U->getAddressByteSize(),
991 U->getFormParams().Format);
992
993 // Add location and operation entries.
994 CurrentSymbol->addLocation(Attr, /*LowPC=*/0, /*HighPC=*/-1,
995 /*SectionOffset=*/0, OffsetOnEntry,
996 CallSiteLocation);
997 ProcessLocationExpression(Expression);
998 return;
999 }
1000
1003 uint64_t Offset = *FormValue.getAsSectionOffset();
1004 if (FormValue.getForm() == dwarf::DW_FORM_loclistx) {
1005 std::optional<uint64_t> LoclistOffset = U->getLoclistOffset(Offset);
1006 if (!LoclistOffset)
1007 return;
1008 Offset = *LoclistOffset;
1009 }
1010 uint64_t BaseAddr = 0;
1011 if (std::optional<SectionedAddress> BA = U->getBaseAddress())
1012 BaseAddr = BA->Address;
1013 LVAddress LowPC = 0;
1014 LVAddress HighPC = 0;
1015
1016 auto ProcessLocationEntry = [&](const DWARFLocationEntry &Entry) {
1017 if (Entry.Kind == dwarf::DW_LLE_base_address) {
1018 BaseAddr = Entry.Value0;
1019 return;
1020 }
1021 if (Entry.Kind == dwarf::DW_LLE_offset_pair) {
1022 LowPC = BaseAddr + Entry.Value0;
1023 HighPC = BaseAddr + Entry.Value1;
1024 DWARFAddressRange Range{LowPC, HighPC, Entry.SectionIndex};
1025 if (Range.SectionIndex == SectionedAddress::UndefSection)
1026 Range.SectionIndex = Entry.SectionIndex;
1027 DWARFLocationExpression Loc{Range, Entry.Loc};
1028 DWARFDataExtractor Data(Loc.Expr, IsLittleEndian,
1029 U->getAddressByteSize());
1030 DWARFExpression Expression(Data, U->getAddressByteSize());
1031
1032 // Store the real upper limit for the address range.
1033 if (UpdateHighAddress && HighPC > 0)
1034 --HighPC;
1035 // Add location and operation entries.
1036 CurrentSymbol->addLocation(Attr, LowPC, HighPC, Offset, OffsetOnEntry,
1037 CallSiteLocation);
1038 ProcessLocationExpression(Expression);
1039 }
1040 };
1041 Error E = U->getLocationTable().visitLocationList(
1042 &Offset, [&](const DWARFLocationEntry &E) {
1043 ProcessLocationEntry(E);
1044 return true;
1045 });
1046 if (E)
1047 consumeError(std::move(E));
1048 }
1049}
1050
1051void LVELFReader::processLocationMember(dwarf::Attribute Attr,
1052 const DWARFFormValue &FormValue,
1053 const DWARFDie &Die,
1054 uint64_t OffsetOnEntry) {
1055 // Check if the value is an integer constant.
1057 // Add a record to hold a constant as location.
1058 CurrentSymbol->addLocationConstant(Attr, *FormValue.getAsUnsignedConstant(),
1059 OffsetOnEntry);
1060 else
1061 // This is a location description, or a reference to one.
1062 processLocationList(Attr, FormValue, Die, OffsetOnEntry);
1063}
1064
1065// Update the current element with the reference.
1066void LVELFReader::updateReference(dwarf::Attribute Attr,
1067 const DWARFFormValue &FormValue) {
1068 // FIXME: We are assuming that at most one Reference (DW_AT_specification,
1069 // DW_AT_abstract_origin, ...) and at most one Type (DW_AT_import, DW_AT_type)
1070 // appear in any single DIE, but this may not be true.
1071 uint64_t Reference = *FormValue.getAsReference();
1072 // Get target for the given reference, if already created.
1073 LVElement *Target = getElementForOffset(
1074 Reference, CurrentElement,
1075 /*IsType=*/Attr == dwarf::DW_AT_import || Attr == dwarf::DW_AT_type);
1076 // Check if we are dealing with cross CU references.
1077 if (FormValue.getForm() == dwarf::DW_FORM_ref_addr) {
1078 if (Target) {
1079 // The global reference is ready. Mark it as global.
1080 Target->setIsGlobalReference();
1081 // Remove global reference from the unseen list.
1082 removeGlobalOffset(Reference);
1083 } else
1084 // Record the unseen cross CU reference.
1085 addGlobalOffset(Reference);
1086 }
1087
1088 // At this point, 'Target' can be null, in the case of the target element
1089 // not being seen. But the correct bit is set, to indicate that the target
1090 // is being referenced by (abstract_origin, extension, specification) or
1091 // (import, type).
1092 // We must differentiate between the kind of reference. This is needed to
1093 // complete inlined function instances with dropped abstract references,
1094 // in order to facilitate a logical comparison.
1095 switch (Attr) {
1096 case dwarf::DW_AT_abstract_origin:
1097 case dwarf::DW_AT_call_origin:
1098 CurrentElement->setReference(Target);
1099 CurrentElement->setHasReferenceAbstract();
1100 break;
1101 case dwarf::DW_AT_extension:
1102 CurrentElement->setReference(Target);
1103 CurrentElement->setHasReferenceExtension();
1104 break;
1105 case dwarf::DW_AT_specification:
1106 CurrentElement->setReference(Target);
1107 CurrentElement->setHasReferenceSpecification();
1108 break;
1109 case dwarf::DW_AT_import:
1110 case dwarf::DW_AT_type:
1111 CurrentElement->setType(Target);
1112 break;
1113 default:
1114 break;
1115 }
1116}
1117
1118// Get an element given the DIE offset.
1119LVElement *LVELFReader::getElementForOffset(LVOffset Offset, LVElement *Element,
1120 bool IsType) {
1121 auto Iter = ElementTable.try_emplace(Offset).first;
1122 // Update the element and all the references pointing to this element.
1123 LVElementEntry &Entry = Iter->second;
1124 if (!Entry.Element) {
1125 if (IsType)
1126 Entry.Types.insert(Element);
1127 else
1128 Entry.References.insert(Element);
1129 }
1130 return Entry.Element;
1131}
1132
1133Error LVELFReader::loadTargetInfo(const ObjectFile &Obj) {
1134 // Detect the architecture from the object file. We usually don't need OS
1135 // info to lookup a target and create register info.
1136 Triple TT;
1137 TT.setArch(Triple::ArchType(Obj.getArch()));
1138 TT.setVendor(Triple::UnknownVendor);
1139 TT.setOS(Triple::UnknownOS);
1140
1141 // Features to be passed to target/subtarget
1143 SubtargetFeatures FeaturesValue;
1144 if (!Features) {
1145 consumeError(Features.takeError());
1146 FeaturesValue = SubtargetFeatures();
1147 }
1148 FeaturesValue = *Features;
1149 return loadGenericTargetInfo(TT.str(), FeaturesValue.getString());
1150}
1151
1152void LVELFReader::mapRangeAddress(const ObjectFile &Obj) {
1153 for (auto Iter = Obj.symbol_begin(); Iter != Obj.symbol_end(); ++Iter) {
1154 const SymbolRef &Symbol = *Iter;
1155
1156 Expected<SymbolRef::Type> TypeOrErr = Symbol.getType();
1157 if (!TypeOrErr) {
1158 consumeError(TypeOrErr.takeError());
1159 continue;
1160 }
1161
1162 // Process only symbols that represent a function.
1163 SymbolRef::Type Type = *TypeOrErr;
1165 continue;
1166
1167 // In the case of a Mach-O STAB symbol, get its section only if
1168 // the STAB symbol's section field refers to a valid section index.
1169 // Otherwise the symbol may error trying to load a section that
1170 // does not exist.
1171 const MachOObjectFile *MachO = dyn_cast<const MachOObjectFile>(&Obj);
1172 bool IsSTAB = false;
1173 if (MachO) {
1174 DataRefImpl SymDRI = Symbol.getRawDataRefImpl();
1175 uint8_t NType =
1176 (MachO->is64Bit() ? MachO->getSymbol64TableEntry(SymDRI).n_type
1177 : MachO->getSymbolTableEntry(SymDRI).n_type);
1178 if (NType & MachO::N_STAB)
1179 IsSTAB = true;
1180 }
1181
1182 Expected<section_iterator> IterOrErr = Symbol.getSection();
1183 if (!IterOrErr) {
1184 consumeError(IterOrErr.takeError());
1185 continue;
1186 }
1187 section_iterator Section = IsSTAB ? Obj.section_end() : *IterOrErr;
1188 if (Section == Obj.section_end())
1189 continue;
1190
1191 // Get the symbol value.
1192 Expected<uint64_t> AddressOrErr = Symbol.getAddress();
1193 if (!AddressOrErr) {
1194 consumeError(AddressOrErr.takeError());
1195 continue;
1196 }
1197 uint64_t Address = *AddressOrErr;
1198
1199 // Get symbol name.
1201 Expected<StringRef> NameOrErr = Symbol.getName();
1202 if (!NameOrErr) {
1203 consumeError(NameOrErr.takeError());
1204 continue;
1205 }
1206 Name = *NameOrErr;
1207
1208 // Check if the symbol is Comdat.
1209 Expected<uint32_t> FlagsOrErr = Symbol.getFlags();
1210 if (!FlagsOrErr) {
1211 consumeError(FlagsOrErr.takeError());
1212 continue;
1213 }
1214 uint32_t Flags = *FlagsOrErr;
1215
1216 // Mark the symbol as 'comdat' in any of the following cases:
1217 // - Symbol has the SF_Weak flag or
1218 // - Symbol section index different from the DotTextSectionIndex.
1219 LVSectionIndex SectionIndex = Section->getIndex();
1220 bool IsComdat =
1221 (Flags & SymbolRef::SF_Weak) || (SectionIndex != DotTextSectionIndex);
1222
1223 // Record the symbol name (linkage) and its loading address.
1224 addToSymbolTable(Name, Address, SectionIndex, IsComdat);
1225 }
1226}
1227
1229
1231 OS << "LVType\n";
1232 LLVM_DEBUG(dbgs() << "CreateReaders\n");
1233}
BlockVerifier::State From
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_DEBUG(X)
Definition: Debug.h:101
#define RegName(no)
mir Rename Register Operands
raw_pwrite_stream & OS
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
const T * data() const
Definition: ArrayRef.h:162
Stores all information relating to a compile unit, be it in its original instance in the object file ...
A structured debug information entry.
Definition: DIE.h:819
unsigned getOffset() const
Get the compile/type unit relative offset of this DIE.
Definition: DIE.h:857
dwarf::Tag getTag() const
Definition: DIE.h:855
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
Definition: DWARFContext.h:48
DWARFUnitVector::compile_unit_range compile_unit_range
Definition: DWARFContext.h:165
bool isLittleEndian() const
Definition: DWARFContext.h:391
static std::unique_ptr< DWARFContext > create(const object::ObjectFile &Obj, ProcessDebugRelocations RelocAction=ProcessDebugRelocations::Process, const LoadedObjectInfo *L=nullptr, std::string DWPName="", std::function< void(Error)> RecoverableErrorHandler=WithColor::defaultErrorHandler, std::function< void(Error)> WarningHandler=WithColor::defaultWarningHandler, bool ThreadSafe=false)
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
Definition: DWARFDie.h:42
uint64_t getOffset() const
Get the absolute offset into the debug info or types section.
Definition: DWARFDie.h:66
std::optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
Definition: DWARFDie.cpp:247
DWARFUnit * getDwarfUnit() const
Definition: DWARFDie.h:53
DWARFDie getSibling() const
Get the sibling of this DIE object.
Definition: DWARFDie.cpp:628
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
Get the abbreviation declaration for this DIE.
Definition: DWARFDie.h:58
bool isValid() const
Definition: DWARFDie.h:50
This class represents an Operation in the Expression.
ArrayRef< uint64_t > getRawOperands() const
static bool prettyPrintRegisterOp(DWARFUnit *U, raw_ostream &OS, DIDumpOptions DumpOpts, uint8_t Opcode, const ArrayRef< uint64_t > Operands)
std::optional< ArrayRef< uint8_t > > getAsBlock() const
std::optional< uint64_t > getAsSectionOffset() const
std::optional< uint64_t > getAsReference() const
getAsFoo functions below return the extracted value as Foo if only DWARFFormValue has form class is s...
bool isFormClass(FormClass FC) const
std::optional< uint64_t > getAsReferenceUVal() const
std::optional< int64_t > getAsSignedConstant() const
std::optional< uint64_t > getAsAddress() const
std::optional< uint64_t > getAsUnsignedConstant() const
static DWARFFormValue createFromUnit(dwarf::Form F, const DWARFUnit *Unit, uint64_t *OffsetPtr)
dwarf::Form getForm() const
uint64_t getRawUValue() const
DWARFDataExtractor getDebugInfoExtractor() const
Definition: DWARFUnit.cpp:202
bool isDWOUnit() const
Definition: DWARFUnit.h:316
bool isValidOffset(uint64_t offset) const
Test the validity of offset.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:154
static ErrorSuccess success()
Create a success value.
Definition: Error.h:328
Tagged union holding either a T or a Error.
Definition: Error.h:468
Error takeError()
Take ownership of the stored error.
Definition: Error.h:595
reference get()
Returns a reference to the stored T value.
Definition: Error.h:565
Class representing an expression and its matching format.
virtual void printString(StringRef Value)
virtual raw_ostream & startLine()
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
void push_back(const T &Elt)
Definition: SmallVector.h:416
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
Manages the enabling and disabling of subtarget specific features.
std::string getString() const
Returns features as a string.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
@ UnknownVendor
Definition: Triple.h:168
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
LVSectionIndex updateSymbolTable(LVScope *Function)
LVSectionIndex getSectionIndex(LVScope *Scope) override
void addToSymbolTable(StringRef Name, LVScope *Function, LVSectionIndex SectionIndex=0)
void processLines(LVLines *DebugLines, LVSectionIndex SectionIndex)
void mapVirtualAddress(const object::ObjectFile &Obj)
std::unique_ptr< const MCRegisterInfo > MRI
LVRange * getSectionRanges(LVSectionIndex SectionIndex)
Error loadGenericTargetInfo(StringRef TheTriple, StringRef TheFeatures)
void addSectionRange(LVSectionIndex SectionIndex, LVScope *Scope)
void print(raw_ostream &OS) const
std::string getRegisterName(LVSmall Opcode, ArrayRef< uint64_t > Operands) override
void setCUHighAddress(LVAddress Address)
Definition: LVELFReader.h:142
void setCUBaseAddress(LVAddress Address)
Definition: LVELFReader.h:140
virtual void setCount(int64_t Value)
Definition: LVElement.h:246
virtual void setCallLineNumber(uint32_t Number)
Definition: LVElement.h:230
virtual void setBitSize(uint32_t Size)
Definition: LVElement.h:243
virtual void setLinkageName(StringRef LinkageName)
Definition: LVElement.h:225
virtual void setProducer(StringRef ProducerName)
Definition: LVElement.h:215
virtual void setUpperBound(int64_t Value)
Definition: LVElement.h:250
virtual void setDiscriminator(uint32_t Value)
Definition: LVElement.h:256
virtual void setLowerBound(int64_t Value)
Definition: LVElement.h:248
virtual void setValue(StringRef Value)
Definition: LVElement.h:260
void setInlineCode(uint32_t Code)
Definition: LVElement.h:278
virtual void setReference(LVElement *Element)
Definition: LVElement.h:220
void setName(StringRef ElementName) override
Definition: LVElement.cpp:96
virtual bool isCompileUnit() const
Definition: LVElement.h:217
void setAccessibilityCode(uint32_t Access)
Definition: LVElement.h:265
void setVirtualityCode(uint32_t Virtuality)
Definition: LVElement.h:283
void setType(LVElement *Element=nullptr)
Definition: LVElement.h:301
void setFilenameIndex(size_t Index)
Definition: LVElement.h:234
virtual void setCallFilenameIndex(size_t Index)
Definition: LVElement.h:232
virtual size_t getLinkageNameIndex() const
Definition: LVElement.h:227
void setOffset(LVOffset DieOffset)
Definition: LVObject.h:240
void setLineNumber(uint32_t Number)
Definition: LVObject.h:277
void setTag(dwarf::Tag Tag)
Definition: LVObject.h:232
void addCompileUnitOffset(LVOffset Offset, LVScopeCompileUnit *CompileUnit)
Definition: LVReader.h:136
std::string FileFormatName
Definition: LVReader.h:127
std::string createAlternativePath(StringRef From)
Definition: LVReader.h:155
StringRef getFilename() const
Definition: LVReader.h:236
LVSectionIndex DotTextSectionIndex
Definition: LVReader.h:133
virtual Error createScopes()
Definition: LVReader.h:141
void addElement(LVElement *Element)
Definition: LVScope.cpp:112
void addObject(LVLocation *Location)
Definition: LVScope.cpp:151
void addLocation(dwarf::Attribute Attr, LVAddress LowPC, LVAddress HighPC, LVUnsigned SectionOffset, uint64_t LocDescOffset, bool CallSiteLocation=false)
Definition: LVSymbol.cpp:65
void addLocationOperands(LVSmall Opcode, ArrayRef< uint64_t > Operands)
Definition: LVSymbol.cpp:85
void addLocationConstant(dwarf::Attribute Attr, LVUnsigned Constant, uint64_t LocDescOffset)
Definition: LVSymbol.cpp:92
StringRef getFileName() const
Definition: Binary.cpp:41
MachO::nlist getSymbolTableEntry(DataRefImpl DRI) const
MachO::nlist_64 getSymbol64TableEntry(DataRefImpl DRI) const
This class is the base class for all object file types.
Definition: ObjectFile.h:229
virtual section_iterator section_end() const =0
virtual Expected< SubtargetFeatures > getFeatures() const =0
virtual Triple::ArchType getArch() const =0
This is a value type class that represents a single symbol in the list of symbols in the object file.
Definition: ObjectFile.h:168
virtual basic_symbol_iterator symbol_begin() const =0
virtual basic_symbol_iterator symbol_end() const =0
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:642
std::string & str()
Returns the string's reference.
Definition: raw_ostream.h:660
@ N_STAB
Definition: MachO.h:307
Attribute
Attributes.
Definition: Dwarf.h:123
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
StringRef toStringRef(const std::optional< DWARFFormValue > &V, StringRef Default={})
Take an optional DWARFFormValue and try to extract a string value from it.
FormattedNumber hexValue(uint64_t N, unsigned Width=HEX_WIDTH, bool Upper=false)
Definition: LVSupport.h:104
std::string hexString(uint64_t Value, size_t Width=HEX_WIDTH)
Definition: LVSupport.h:110
uint8_t LVSmall
Definition: LVObject.h:43
const LVAddress MaxAddress
Definition: LVObject.h:87
std::string transformPath(StringRef Path)
Definition: LVSupport.cpp:33
constexpr bool UpdateHighAddress
std::pair< LVAddress, LVAddress > LVAddressRange
Definition: LVRange.h:23
LVOptions & options()
Definition: LVOptions.h:445
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
SmallVectorImpl< T >::const_pointer c_str(SmallVectorImpl< T > &str)
std::vector< DWARFAddressRange > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1238
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:125
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1035
Container for dump options that control which debug information will be dumped.
Definition: DIContext.h:193
std::function< llvm::StringRef(uint64_t DwarfRegNum, bool IsEH)> GetNameForDWARFReg
Definition: DIContext.h:208
static bool mayHaveLocationList(dwarf::Attribute Attr)
Identify DWARF attributes that may contain a pointer to a location list.
Definition: DWARFDie.cpp:704
static bool mayHaveLocationExpr(dwarf::Attribute Attr)
Identifies DWARF attributes that may contain a reference to a DWARF expression.
Definition: DWARFDie.cpp:721
Standard .debug_line state machine structure.
A single location within a location list.
Definition: DWARFDebugLoc.h:30
Represents a single DWARF expression, whose value is location-dependent.
uint8_t n_type
Definition: MachO.h:1017
static const uint64_t UndefSection
Definition: ObjectFile.h:146