15 #include "llvm/Support/LEB128.h"
42 m_offset = *offset_ptr;
45 const uint64_t abbr_idx = data.
GetULEB128(offset_ptr);
47 m_abbr_idx = abbr_idx;
52 if (m_abbr_idx == 0) {
53 m_tag = llvm::dwarf::DW_TAG_null;
54 m_has_children =
false;
59 const auto *abbrevDecl = GetAbbreviationDeclarationPtr(cu);
60 if (abbrevDecl ==
nullptr) {
62 "{0x%8.8x}: invalid abbreviation code %u, please file a bug and "
63 "attach the file at the start of this error message",
64 m_offset, (
unsigned)abbr_idx);
69 m_tag = abbrevDecl->Tag();
70 m_has_children = abbrevDecl->HasChildren();
72 const uint32_t numAttributes = abbrevDecl->NumAttributes();
75 for (i = 0; i < numAttributes; ++i) {
76 form = abbrevDecl->GetFormByIndexUnchecked(i);
77 llvm::Optional<uint8_t> fixed_skip_size =
80 offset += *fixed_skip_size;
82 bool form_is_indirect =
false;
84 form_is_indirect =
false;
112 case DW_FORM_ref_addr:
120 case DW_FORM_flag_present:
158 case DW_FORM_ref_sig8:
164 case DW_FORM_loclistx:
165 case DW_FORM_rnglistx:
168 case DW_FORM_ref_udata:
169 case DW_FORM_GNU_addr_index:
170 case DW_FORM_GNU_str_index:
175 case DW_FORM_indirect:
176 form_is_indirect =
true;
181 case DW_FORM_line_strp:
182 case DW_FORM_sec_offset:
186 case DW_FORM_implicit_const:
192 "{0x%8.8x}: Unsupported DW_FORM_0x%x, please file a bug and "
193 "attach the file at the start of this error message",
194 m_offset, (
unsigned)form);
195 *offset_ptr = m_offset;
200 }
while (form_is_indirect);
203 *offset_ptr = offset;
210 llvm::Expected<DWARFRangeList> expected_ranges =
211 (value.
Form() == DW_FORM_rnglistx)
215 return std::move(*expected_ranges);
217 "{0x%8.8x}: DIE has DW_AT_ranges(%s 0x%" PRIx64
") attribute, but "
218 "range extraction failed (%s), please file a bug "
219 "and attach the file at the start of this error message",
221 llvm::dwarf::FormEncodingString(value.
Form()).str().c_str(),
231 DWARFUnit *cu,
const char *&name,
const char *&mangled,
232 DWARFRangeList &ranges,
int &decl_file,
int &decl_line,
int &decl_column,
233 int &call_file,
int &call_line,
int &call_column,
237 std::vector<DWARFDIE> dies;
238 bool set_frame_base_loclist_addr =
false;
240 const auto *abbrevDecl = GetAbbreviationDeclarationPtr(cu);
243 lldb::ModuleSP module =
dwarf.GetObjectFile()->GetModule();
252 const uint32_t numAttributes = abbrevDecl->NumAttributes();
253 bool do_offset =
false;
255 for (
uint32_t i = 0; i < numAttributes; ++i) {
258 abbrevDecl->GetAttrAndFormValueByIndex(i, attr, form_value);
275 if (form_value.
Form() == DW_FORM_addr ||
276 form_value.
Form() == DW_FORM_addrx ||
277 form_value.
Form() == DW_FORM_GNU_addr_index) {
298 case DW_AT_MIPS_linkage_name:
299 case DW_AT_linkage_name:
300 if (mangled ==
nullptr)
304 case DW_AT_abstract_origin:
308 case DW_AT_specification:
312 case DW_AT_decl_file:
317 case DW_AT_decl_line:
322 case DW_AT_decl_column:
323 if (decl_column == 0)
324 decl_column = form_value.
Unsigned();
327 case DW_AT_call_file:
332 case DW_AT_call_line:
337 case DW_AT_call_column:
338 if (call_column == 0)
339 call_column = form_value.
Unsigned();
342 case DW_AT_frame_base:
349 module,
DataExtractor(data, block_offset, block_length), cu);
361 set_frame_base_loclist_addr =
true;
384 if (set_frame_base_loclist_addr) {
390 if (ranges.
IsEmpty() || name ==
nullptr || mangled ==
nullptr) {
393 die.GetDIE()->GetDIENamesAndRanges(die.GetCU(), name, mangled, ranges,
394 decl_file, decl_line, decl_column,
395 call_file, call_line, call_column);
410 const auto *abbrevDecl = GetAbbreviationDeclarationPtr(cu);
415 const uint32_t num_attributes = abbrevDecl->NumAttributes();
416 for (
uint32_t i = 0; i < num_attributes; ++i) {
419 abbrevDecl->GetAttrAndFormValueByIndex(i, attr, form_value);
427 case DW_AT_declaration:
428 if (curr_depth > 0) {
436 attributes.
Append(form_value, offset, attr);
440 if (recurse == Recurse::yes &&
441 ((attr == DW_AT_specification) || (attr == DW_AT_abstract_origin))) {
446 recurse, curr_depth + 1);
451 offset += *fixed_skip_size;
459 return attributes.
Size();
471 bool check_specification_or_abstract_origin)
const {
472 if (
const auto *abbrevDecl = GetAbbreviationDeclarationPtr(cu)) {
473 uint32_t attr_idx = abbrevDecl->FindAttributeIndex(attr);
480 while (idx < attr_idx)
486 form_value.
SetForm(abbrevDecl->GetFormByIndex(idx));
488 if (end_attr_offset_ptr)
489 *end_attr_offset_ptr = offset;
495 if (check_specification_or_abstract_origin) {
496 if (GetAttributeValue(cu, DW_AT_specification, form_value)) {
500 die.
GetCU(), attr, form_value, end_attr_offset_ptr,
false);
506 if (GetAttributeValue(cu, DW_AT_abstract_origin, form_value)) {
510 die.
GetCU(), attr, form_value, end_attr_offset_ptr,
false);
527 bool check_specification_or_abstract_origin)
const {
529 if (GetAttributeValue(cu, attr, form_value,
nullptr,
530 check_specification_or_abstract_origin))
540 bool check_specification_or_abstract_origin)
const {
542 if (GetAttributeValue(cu, attr, form_value,
nullptr,
543 check_specification_or_abstract_origin))
554 bool check_specification_or_abstract_origin)
const {
556 if (GetAttributeValue(cu, attr, form_value,
nullptr,
557 check_specification_or_abstract_origin))
564 bool check_specification_or_abstract_origin)
const {
566 if (GetAttributeValue(cu, attr, form_value,
nullptr,
567 check_specification_or_abstract_origin))
580 bool check_specification_or_abstract_origin)
const {
582 if (GetAttributeValue(cu, DW_AT_high_pc, form_value,
nullptr,
583 check_specification_or_abstract_origin)) {
585 if (form == DW_FORM_addr || form == DW_FORM_addrx ||
586 form == DW_FORM_GNU_addr_index)
590 return lo_pc + form_value.
Unsigned();
603 uint64_t fail_value,
bool check_specification_or_abstract_origin)
const {
604 lo_pc = GetAttributeValueAsAddress(cu, DW_AT_low_pc, fail_value,
605 check_specification_or_abstract_origin);
606 if (lo_pc != fail_value) {
607 hi_pc = GetAttributeHighPC(cu, lo_pc, fail_value,
608 check_specification_or_abstract_origin);
609 if (hi_pc != fail_value)
619 bool check_specification_or_abstract_origin)
const {
623 if (GetAttributeValue(cu, DW_AT_ranges, form_value)) {
625 }
else if (check_hi_lo_pc) {
629 check_specification_or_abstract_origin)) {
642 return GetAttributeValueAsString(cu, DW_AT_name,
nullptr,
true);
651 bool substitute_name_allowed)
const {
652 const char *name =
nullptr;
654 name = GetAttributeValueAsString(cu, DW_AT_MIPS_linkage_name,
nullptr,
true);
658 name = GetAttributeValueAsString(cu, DW_AT_linkage_name,
nullptr,
true);
662 if (!substitute_name_allowed)
665 name = GetAttributeValueAsString(cu, DW_AT_name,
nullptr,
true);
674 const char *name =
nullptr;
678 name = GetAttributeValueAsString(cu, DW_AT_MIPS_linkage_name,
nullptr,
true);
682 name = GetAttributeValueAsString(cu, DW_AT_linkage_name,
nullptr,
true);
686 name = GetAttributeValueAsString(cu, DW_AT_name,
nullptr,
true);
696 if (m_tag == DW_TAG_subprogram) {
698 GetAttributeAddressRanges(cu, ranges,
700 for (
const auto &r : ranges) {
701 debug_aranges->
AppendRange(GetOffset(), r.GetRangeBase(),
720 if (tag == DW_TAG_compile_unit || tag == DW_TAG_partial_unit)
721 return dwarf_decl_ctx;
724 if (!parent_decl_ctx_die || parent_decl_ctx_die.
GetDIE() == die)
725 return dwarf_decl_ctx;
726 if (parent_decl_ctx_die.
Tag() == DW_TAG_compile_unit ||
727 parent_decl_ctx_die.
Tag() == DW_TAG_partial_unit)
728 return dwarf_decl_ctx;
729 die = parent_decl_ctx_die.
GetDIE();
730 cu = parent_decl_ctx_die.
GetCU();
735 return GetDWARFDeclContextStatic(
this, cu);
741 GetAttributes(cu, attributes, Recurse::yes);
742 return GetParentDeclContextDIE(cu, attributes);
754 if (die.
GetDIE() !=
this) {
756 case DW_TAG_compile_unit:
757 case DW_TAG_partial_unit:
758 case DW_TAG_namespace:
759 case DW_TAG_structure_type:
760 case DW_TAG_union_type:
761 case DW_TAG_class_type:
791 GetAttributes(cu, attributes, Recurse::yes);
792 return GetQualifiedName(cu, attributes, storage);
800 const char *name =
GetName(cu);
803 DWARFDIE parent_decl_ctx_die = GetParentDeclContextDIE(cu);
806 while (parent_decl_ctx_die) {
807 const dw_tag_t parent_tag = parent_decl_ctx_die.
Tag();
808 switch (parent_tag) {
809 case DW_TAG_namespace: {
810 const char *namespace_name = parent_decl_ctx_die.
GetName();
811 if (namespace_name) {
812 storage.insert(0,
"::");
813 storage.insert(0, namespace_name);
815 storage.insert(0,
"(anonymous namespace)::");
820 case DW_TAG_class_type:
821 case DW_TAG_structure_type:
822 case DW_TAG_union_type: {
823 const char *class_union_struct_name = parent_decl_ctx_die.
GetName();
825 if (class_union_struct_name) {
826 storage.insert(0,
"::");
827 storage.insert(0, class_union_struct_name);
833 parent_decl_ctx_die.
Clear();
839 storage.append(
"::");
841 storage.append(name);
845 return storage.c_str();
849 return GetOffset() + llvm::getULEB128Size(m_abbr_idx);
863 if (Tag() != DW_TAG_variable)
866 while (parent_die !=
nullptr) {
867 switch (parent_die->
Tag()) {
868 case DW_TAG_subprogram:
869 case DW_TAG_lexical_block:
870 case DW_TAG_inlined_subroutine:
873 case DW_TAG_compile_unit:
874 case DW_TAG_partial_unit:
893 return !(*
this == rhs);