69using std::dynamic_pointer_cast;
70using std::static_pointer_cast;
71using std::unordered_map;
72using std::unordered_set;
79using namespace elf_helpers;
86 NO_DEBUG_INFO_DIE_SOURCE,
87 PRIMARY_DEBUG_INFO_DIE_SOURCE,
88 ALT_DEBUG_INFO_DIE_SOURCE,
90 NUMBER_OF_DIE_SOURCES,
138struct dwarf_offset_pair_hash
141 operator()(
const std::pair<Dwarf_Off, Dwarf_Off>& p)
const
145typedef unordered_set<std::pair<Dwarf_Off,
147 dwarf_offset_pair_hash> dwarf_offset_pair_set_type;
157 : source_(PRIMARY_DEBUG_INFO_DIE_SOURCE),
161 offset_type(
die_source source, Dwarf_Off offset)
166 offset_type(Dwarf_Off offset)
167 : source_(PRIMARY_DEBUG_INFO_DIE_SOURCE),
172 {
return source_ == o.source_ && offset_ == o.offset_;}
174 operator Dwarf_Off()
const
185 operator()(
const offset_type& p)
const
194struct offset_pair_hash
197 operator()(
const std::pair<offset_type, offset_type>& p)
const
202 hash_t(p.second.offset_));
211typedef unordered_set<std::pair<offset_type,
220typedef unordered_map<std::pair<offset_type, offset_type>,
226typedef unordered_map<std::pair<offset_type, offset_type>,
236build_translation_unit_and_add_to_ir(reader& rdr,
241maybe_propagate_canonical_type(
const reader& rdr,
246propagate_canonical_type(
const reader& rdr,
251maybe_set_member_type_access_specifier(decl_base_sptr member_type_declaration,
255cleanup_decl_name(
string&);
295struct imported_unit_point
297 Dwarf_Off offset_of_import;
301 Dwarf_Off imported_unit_die_off;
302 Dwarf_Off imported_unit_cu_off;
303 Dwarf_Off imported_unit_child_off;
306 imported_unit_point()
307 : offset_of_import(),
308 imported_unit_die_source(PRIMARY_DEBUG_INFO_DIE_SOURCE),
309 imported_unit_die_off(),
310 imported_unit_cu_off(),
311 imported_unit_child_off()
318 imported_unit_point(Dwarf_Off import_off)
319 : offset_of_import(import_off),
320 imported_unit_die_source(PRIMARY_DEBUG_INFO_DIE_SOURCE),
321 imported_unit_die_off(),
322 imported_unit_cu_off(),
323 imported_unit_child_off()
334 imported_unit_point(Dwarf_Off import_off,
335 const Dwarf_Die& imported_die,
337 : offset_of_import(import_off),
338 imported_unit_die_source(from),
339 imported_unit_die_off(dwarf_dieoffset
340 (
const_cast<Dwarf_Die*
>(&imported_die))),
341 imported_unit_cu_off(),
342 imported_unit_child_off()
344 Dwarf_Die imported_unit_child;
346 ABG_ASSERT(dwarf_child(
const_cast<Dwarf_Die*
>(&imported_die),
347 &imported_unit_child) == 0);
349 imported_unit_child_off =
350 dwarf_dieoffset(
const_cast<Dwarf_Die*
>(&imported_unit_child));
352 Dwarf_Die cu_die_memory;
355 cu_die = dwarf_diecu(
const_cast<Dwarf_Die*
>(&imported_unit_child),
356 &cu_die_memory, 0, 0);
357 imported_unit_cu_off = dwarf_dieoffset(cu_die);
365typedef unordered_map<Dwarf_Off, imported_unit_points_type>
377operator<(
const imported_unit_point& l,
const imported_unit_point& r)
378{
return l.offset_of_import < r.offset_of_import;}
381get_parent_die(
const reader& rdr,
382 const Dwarf_Die* die,
383 Dwarf_Die& parent_die,
384 size_t where_offset);
387get_scope_die(
const reader& rdr,
388 const Dwarf_Die* die,
390 Dwarf_Die& scope_die);
396die_is_in_c(
const Dwarf_Die *die);
399die_is_in_cplus_plus(
const Dwarf_Die *die);
402die_is_in_c_or_cplusplus(
const Dwarf_Die *die);
405die_is_anonymous(
const Dwarf_Die* die);
408die_is_anonymous_data_member(
const Dwarf_Die* die);
411die_is_type(
const Dwarf_Die* die);
414die_is_decl(
const Dwarf_Die* die);
417die_is_declaration_only(Dwarf_Die* die);
420die_is_variable_decl(
const Dwarf_Die *die);
423die_is_function_decl(
const Dwarf_Die *die);
426die_has_size_attribute(
const Dwarf_Die *die);
429die_has_no_child(
const Dwarf_Die *die);
432die_is_namespace(
const Dwarf_Die* die);
435die_is_unspecified(Dwarf_Die* die);
438die_is_void_type(Dwarf_Die* die);
441die_is_pointer_type(
const Dwarf_Die* die);
444pointer_or_qual_die_of_anonymous_class_type(
const Dwarf_Die* die);
447die_is_reference_type(
const Dwarf_Die* die);
450die_is_pointer_array_or_reference_type(
const Dwarf_Die* die);
453die_is_pointer_or_reference_type(
const Dwarf_Die* die);
456die_is_pointer_reference_or_typedef_type(
const Dwarf_Die* die);
459die_is_class_type(
const Dwarf_Die* die);
462die_is_qualified_type(
const Dwarf_Die* die);
465die_is_function_type(
const Dwarf_Die *die);
468die_has_object_pointer(
const Dwarf_Die* die,
469 Dwarf_Die& object_pointer);
472die_has_children(
const Dwarf_Die* die);
475fn_die_first_parameter_die(
const Dwarf_Die* die, Dwarf_Die& first_parm_die);
478member_fn_die_has_this_pointer(
const reader& rdr,
479 const Dwarf_Die* die,
481 Dwarf_Die& class_die,
482 Dwarf_Die& object_pointer_die);
485die_this_pointer_from_object_pointer(Dwarf_Die* die,
486 Dwarf_Die& this_pointer);
489die_this_pointer_is_const(Dwarf_Die* die);
492die_object_pointer_is_for_const_method(Dwarf_Die* die);
495is_type_die_to_be_canonicalized(
const Dwarf_Die *die);
498die_is_at_class_scope(
const reader& rdr,
499 const Dwarf_Die* die,
501 Dwarf_Die& class_scope_die);
503eval_last_constant_dwarf_sub_expr(Dwarf_Op* expr,
506 bool& is_tls_address);
509dwarf_language_to_tu_language(
size_t l);
512die_unsigned_constant_attribute(
const Dwarf_Die* die,
517die_signed_constant_attribute(
const Dwarf_Die*die,
522die_constant_attribute(
const Dwarf_Die *die,
528die_member_offset(
const reader& rdr,
529 const Dwarf_Die* die,
533form_is_DW_FORM_strx(
unsigned form);
536form_is_DW_FORM_line_strp(
unsigned form);
539die_address_attribute(Dwarf_Die* die,
unsigned attr_name, Dwarf_Addr& result);
542die_name(
const Dwarf_Die* die);
545die_name_and_linkage_name(
const Dwarf_Die* die,
547 string& linkage_name);
549die_location(
const reader& rdr,
const Dwarf_Die* die);
552die_location_address(Dwarf_Die* die,
554 bool& is_tls_address);
557die_die_attribute(
const Dwarf_Die* die,
560 bool recursively =
true);
563die_origin_die(
const Dwarf_Die* die, Dwarf_Die& origin_die);
566subrange_die_indirect_bound_value(
const Dwarf_Die *die,
572subrange_die_indirectly_references_subrange_die(
const Dwarf_Die *die,
574 Dwarf_Die& referenced_subrange);
576get_internal_anonymous_die_prefix_name(
const Dwarf_Die *die);
579build_internal_anonymous_die_name(
const string &base_name,
580 size_t anonymous_type_index);
583die_qualified_type_name(
const reader& rdr,
584 const Dwarf_Die* die,
586 unordered_set<uint64_t>& guard);
589die_qualified_decl_name(
const reader& rdr,
590 const Dwarf_Die* die,
592 unordered_set<uint64_t>& guard);
595die_qualified_name(
const reader& rdr,
596 const Dwarf_Die* die,
598 unordered_set<uint64_t>& guard);
601die_qualified_name(
const reader& rdr,
602 const Dwarf_Die* die,
606die_type_name(
const reader& rdr,
const Dwarf_Die* die,
607 bool qualified_name,
size_t where_offset,
608 unordered_set<uint64_t>& infinite_loop_guard);
611die_type_name(
const reader& rdr,
const Dwarf_Die* die,
612 bool qualified_name,
size_t where_offset);
615die_qualified_type_name_empty(
const reader& rdr,
616 const Dwarf_Die* die,
size_t where,
617 string &qualified_name,
618 unordered_set<uint64_t>& infinite_loop_guard);
621die_return_and_parm_names_from_fn_type_die(
const reader& rdr,
622 const Dwarf_Die* die,
627 string &return_type_name,
629 vector<string>& parm_names,
632 unordered_set<uint64_t>& infinite_loop_guard);
635die_function_signature(
const reader& rdr,
636 const Dwarf_Die *die,
639 unordered_set<uint64_t>& infinite_loop_guard);
642die_peel_qual_ptr(Dwarf_Die *die, Dwarf_Die& peeled_die);
645die_peel_qualified(Dwarf_Die *die, Dwarf_Die& peeled_die);
648die_peel_typedef(Dwarf_Die *die, Dwarf_Die& peeled_die);
651die_function_type_is_method_type(
const reader& rdr,
652 const Dwarf_Die *die,
654 Dwarf_Die& object_pointer_die,
655 Dwarf_Die& class_die,
659die_enum_flat_representation(
const reader& rdr,
660 const Dwarf_Die* die,
661 const string& indent,
663 bool qualified_names,
664 size_t where_offset);
667die_class_flat_representation(
const reader& rdr,
668 const Dwarf_Die* die,
669 const string& indent,
671 bool qualified_names,
673 unordered_set<uint64_t>& infinite_loop_guard);
676die_class_or_enum_flat_representation(
const reader& rdr,
677 const Dwarf_Die* die,
678 const string& indent,
680 bool qualified_names,
682 unordered_set<uint64_t>& infinite_loop_guard);
685die_class_or_enum_flat_representation(
const reader& rdr,
686 const Dwarf_Die* die,
687 const string& indent,
689 bool qualified_names,
690 size_t where_offset);
693die_pretty_print_type(
const reader& rdr,
694 const Dwarf_Die* die,
696 unordered_set<uint64_t>& guard);
699die_pretty_print_decl(
const reader& rdr,
700 const Dwarf_Die* die,
704 unordered_set<uint64_t>& infinite_loop_guard);
707die_pretty_print(reader& rdr,
708 const Dwarf_Die* die,
710 unordered_set<uint64_t>& infinite_loop_guard);
713maybe_canonicalize_type(
const type_base_sptr& t,
722 imported_unit_points_type::const_iterator&);
725build_subrange_type(reader& rdr,
726 const Dwarf_Die* die,
728 bool associate_type_to_die =
true);
731build_subranges_from_array_type_die(
const reader& rdr,
732 const Dwarf_Die* die,
735 bool associate_type_to_die =
true);
738compare_dies(
const reader& rdr,
739 const Dwarf_Die *l,
const Dwarf_Die *r,
740 bool update_canonical_dies_on_the_fly);
743compare_dies_during_canonicalization(reader& rdr,
744 const Dwarf_Die *l,
const Dwarf_Die *r,
745 bool update_canonical_dies_on_the_fly);
748get_member_child_die(
const Dwarf_Die *die, Dwarf_Die *child);
751get_next_member_sibling_die(
const Dwarf_Die *die, Dwarf_Die *member);
764 ABG_ASSERT(dwarf_diecu(
const_cast<Dwarf_Die*
>(die), &cu_die, 0, 0));
767 if (!die_unsigned_constant_attribute(&cu_die, DW_AT_language, l))
770 lang = dwarf_language_to_tu_language(l);
782die_is_in_c(
const Dwarf_Die *die)
785 if (!get_die_language(die, l))
798die_is_in_cplus_plus(
const Dwarf_Die *die)
801 if (!get_die_language(die, l))
814die_is_in_c_or_cplusplus(
const Dwarf_Die *die)
817 if (!get_die_language(die, l))
834compare_symbol_name(
const string& symbol_name,
843 return symbol_name == name;
872lookup_symbol_from_sysv_hash_tab(
const environment& env,
874 const string& sym_name,
876 size_t sym_tab_index,
878 vector<elf_symbol_sptr>& syms_found)
880 Elf_Scn* sym_tab_section = elf_getscn(elf_handle, sym_tab_index);
883 Elf_Data* sym_tab_data = elf_getdata(sym_tab_section, 0);
886 GElf_Shdr sheader_mem;
887 GElf_Shdr* sym_tab_section_header = gelf_getshdr(sym_tab_section,
889 Elf_Scn* hash_section = elf_getscn(elf_handle, ht_index);
894 unsigned long hash = elf_hash(sym_name.c_str());
895 Elf_Data* ht_section_data = elf_getdata(hash_section, 0);
896 Elf32_Word* ht_data =
reinterpret_cast<Elf32_Word*
>(ht_section_data->d_buf);
897 size_t nb_buckets = ht_data[0];
898 size_t nb_chains = ht_data[1];
906 Elf32_Word* ht_buckets = &ht_data[2];
907 Elf32_Word* ht_chains = &ht_buckets[nb_buckets];
910 size_t bucket =
hash % nb_buckets;
911 size_t symbol_index = ht_buckets[bucket];
914 const char* sym_name_str;
923 ABG_ASSERT(gelf_getsym(sym_tab_data, symbol_index, &symbol));
924 sym_name_str = elf_strptr(elf_handle,
925 sym_tab_section_header->sh_link,
928 && compare_symbol_name(sym_name_str, sym_name, demangle))
934 sym_size = symbol.st_size;
935 elf_symbol::version ver;
946 symbol.st_shndx != SHN_UNDEF,
947 symbol.st_shndx == SHN_COMMON,
948 ver, sym_visibility);
949 syms_found.push_back(symbol_found);
952 symbol_index = ht_chains[symbol_index];
953 }
while (symbol_index != STN_UNDEF || symbol_index >= nb_chains);
964get_elf_class_size_in_bytes(Elf* elf_handle)
970 int c = hdr.e_ident[EI_CLASS];
1004bloom_word_at(Elf* elf_handle,
1005 Elf32_Word* bloom_filter,
1008 Elf64_Xword result = 0;
1012 c = h.e_ident[EI_CLASS];
1017 result = bloom_filter[index];
1021 Elf64_Xword* f=
reinterpret_cast<Elf64_Xword*
>(bloom_filter);
1040 Elf32_Word* buckets;
1042 size_t first_sym_index;
1045 Elf32_Word* bloom_filter;
1048 Elf_Scn* sym_tab_section;
1049 GElf_Shdr sym_tab_section_header;
1079setup_gnu_ht(Elf* elf_handle,
1081 size_t sym_tab_index,
1084 ht.sym_tab_section = elf_getscn(elf_handle, sym_tab_index);
1086 ABG_ASSERT(gelf_getshdr(ht.sym_tab_section, &ht.sym_tab_section_header));
1088 ht.sym_tab_section_header.sh_size / ht.sym_tab_section_header.sh_entsize;
1089 Elf_Scn* hash_section = elf_getscn(elf_handle, ht_index);
1094 Elf_Data* ht_section_data = elf_getdata(hash_section, 0);
1095 Elf32_Word* ht_data =
reinterpret_cast<Elf32_Word*
>(ht_section_data->d_buf);
1097 ht.nb_buckets = ht_data[0];
1098 if (ht.nb_buckets == 0)
1102 ht.first_sym_index = ht_data[1];
1105 ht.bf_nwords = ht_data[2];
1107 ht.shift = ht_data[3];
1109 ht.bloom_filter = &ht_data[4];
1114 ht.bf_size = (get_elf_class_size_in_bytes(elf_handle) / 4) * ht.bf_nwords;
1116 ht.buckets = ht.bloom_filter + ht.bf_size;
1118 ht.chain = ht.buckets + ht.nb_buckets;
1149lookup_symbol_from_gnu_hash_tab(
const environment& env,
1151 const string& sym_name,
1153 size_t sym_tab_index,
1155 vector<elf_symbol_sptr>& syms_found)
1158 if (!setup_gnu_ht(elf_handle, ht_index, sym_tab_index, ht))
1164 size_t h1 = elf_gnu_hash(sym_name.c_str());
1165 size_t h2 = h1 >> ht.shift;
1168 int c = get_elf_class_size_in_bytes(elf_handle) * 8;
1169 int n = (h1 / c) % ht.bf_nwords;
1175 Elf64_Xword bitmask = (1ul << (h1 % c)) | (1ul << (h2 % c));
1178 if ((bloom_word_at(elf_handle, ht.bloom_filter, n) & bitmask) != bitmask)
1181 size_t i = ht.buckets[h1 % ht.nb_buckets];
1185 Elf32_Word stop_word, *stop_wordp;
1186 elf_symbol::version ver;
1188 const char* sym_name_str;
1197 for (i = ht.buckets[h1 % ht.nb_buckets],
1198 stop_wordp = &ht.chain[i - ht.first_sym_index];
1201 < ht.chain + (ht.sym_count - ht.first_sym_index));
1204 stop_word = *stop_wordp;
1205 if ((stop_word & ~ 1)!= (h1 & ~1))
1211 ABG_ASSERT(gelf_getsym(elf_getdata(ht.sym_tab_section, 0),
1213 sym_name_str = elf_strptr(elf_handle,
1214 ht.sym_tab_section_header.sh_link,
1217 && compare_symbol_name(sym_name_str, sym_name, demangle))
1235 sym_type, sym_binding,
1236 symbol.st_shndx != SHN_UNDEF,
1237 symbol.st_shndx == SHN_COMMON,
1238 ver, sym_visibility);
1239 syms_found.push_back(symbol_found);
1281lookup_symbol_from_elf_hash_tab(
const environment& env,
1283 hash_table_kind ht_kind,
1285 size_t symtab_index,
1286 const string& symbol_name,
1288 vector<elf_symbol_sptr>& syms_found)
1290 if (elf_handle == 0 || symbol_name.empty())
1293 if (ht_kind == NO_HASH_TABLE_KIND)
1296 if (ht_kind == SYSV_HASH_TABLE_KIND)
1297 return lookup_symbol_from_sysv_hash_tab(env,
1298 elf_handle, symbol_name,
1303 else if (ht_kind == GNU_HASH_TABLE_KIND)
1304 return lookup_symbol_from_gnu_hash_tab(env,
1305 elf_handle, symbol_name,
1338lookup_symbol_from_symtab(
const environment& env,
1340 const string& sym_name,
1341 size_t sym_tab_index,
1343 vector<elf_symbol_sptr>& syms_found)
1348 Elf_Scn* sym_tab_section = elf_getscn(elf_handle, sym_tab_index);
1351 GElf_Shdr header_mem;
1352 GElf_Shdr * sym_tab_header = gelf_getshdr(sym_tab_section,
1355 size_t symcount = sym_tab_header->sh_size / sym_tab_header->sh_entsize;
1356 Elf_Data* symtab = elf_getdata(sym_tab_section, NULL);
1359 elf_symbol::version ver;
1362 for (
size_t i = 0; i < symcount; ++i)
1365 sym = gelf_getsym(symtab, i, &sym_mem);
1366 name_str = elf_strptr(elf_handle,
1367 sym_tab_header->sh_link,
1370 if (name_str && compare_symbol_name(name_str, sym_name, demangle))
1378 bool sym_is_defined = sym->st_shndx != SHN_UNDEF;
1379 bool sym_is_common = sym->st_shndx == SHN_COMMON;
1388 sym_binding, sym_is_defined,
1389 sym_is_common, ver, sym_visibility);
1390 syms_found.push_back(symbol_found);
1429lookup_symbol_from_elf(
const environment& env,
1431 const string& symbol_name,
1433 vector<elf_symbol_sptr>& syms_found)
1435 size_t hash_table_index = 0, symbol_table_index = 0;
1436 hash_table_kind ht_kind = NO_HASH_TABLE_KIND;
1441 symbol_table_index);
1443 if (ht_kind == NO_HASH_TABLE_KIND)
1448 return lookup_symbol_from_symtab(env,
1456 return lookup_symbol_from_elf_hash_tab(env,
1480lookup_public_function_symbol_from_elf(environment& env,
1482 const string& symbol_name,
1483 vector<elf_symbol_sptr>& func_syms)
1485 vector<elf_symbol_sptr> syms_found;
1488 if (lookup_symbol_from_elf(env, elf_handle, symbol_name,
1491 for (vector<elf_symbol_sptr>::const_iterator i = syms_found.begin();
1492 i != syms_found.end();
1498 if ((type == elf_symbol::FUNC_TYPE
1499 || type == elf_symbol::GNU_IFUNC_TYPE
1500 || type == elf_symbol::COMMON_TYPE)
1501 && (binding == elf_symbol::GLOBAL_BINDING
1502 || binding == elf_symbol::WEAK_BINDING))
1504 func_syms.push_back(*i);
1525 int64_t const_value_;
1533 expr_result(
bool is_const)
1534 : is_const_(is_const),
1538 explicit expr_result(int64_t v)
1564 const_value(int64_t& value)
1568 value = const_value_;
1584 return const_value_;
1587 operator int64_t()
const
1588 {
return const_value();}
1591 operator=(
const int64_t v)
1599 {
return const_value_ == o.const_value_ && is_const_ == o.is_const_;}
1602 operator>=(
const expr_result& o)
const
1603 {
return const_value_ >= o.const_value_;}
1606 operator<=(
const expr_result& o)
const
1607 {
return const_value_ <= o.const_value_;}
1610 operator>(
const expr_result& o)
const
1611 {
return const_value_ > o.const_value_;}
1614 operator<(
const expr_result& o)
const
1615 {
return const_value_ < o.const_value_;}
1620 expr_result r(*
this);
1621 r.const_value_ += v.const_value_;
1622 r.is_const_ = r.is_const_ && v.is_const_;
1627 operator+=(int64_t v)
1634 operator-(
const expr_result& v)
const
1636 expr_result r(*
this);
1637 r.const_value_ -= v.const_value_;
1638 r.is_const_ = r.is_const_ && v.is_const_;
1643 operator%(
const expr_result& v)
const
1645 expr_result r(*
this);
1646 r.const_value_ %= v.const_value_;
1647 r.is_const_ = r.is_const_ && v.is_const();
1652 operator*(
const expr_result& v)
const
1654 expr_result r(*
this);
1655 r.const_value_ *= v.const_value_;
1656 r.is_const_ = r.is_const_ && v.is_const();
1663 expr_result r(*
this);
1664 r.const_value_ |= v.const_value_;
1665 r.is_const_ = r.is_const_ && v.is_const_;
1670 operator^(
const expr_result& v)
const
1672 expr_result r(*
this);
1673 r.const_value_ ^= v.const_value_;
1674 r.is_const_ = r.is_const_ && v.is_const_;
1679 operator>>(
const expr_result& v)
const
1681 expr_result r(*
this);
1682 r.const_value_ = r.const_value_ >> v.const_value_;
1683 r.is_const_ = r.is_const_ && v.is_const_;
1690 expr_result r(*
this);
1691 r.const_value_ = r.const_value_ << v.const_value_;
1692 r.is_const_ = r.is_const_ && v.is_const_;
1699 expr_result r(*
this);
1700 r.const_value_ = ~r.const_value_;
1707 expr_result r(*
this);
1708 r.const_value_ = -r.const_value_;
1715 expr_result r = *
this;
1716 r.const_value_ = std::abs(
static_cast<long double>(r.const_value()));
1723 expr_result r(*
this);
1724 r.const_value_ &= o.const_value_;
1725 r.is_const_ = r.is_const_ && o.is_const_;
1730 operator/(
const expr_result& o)
1732 expr_result r(*
this);
1733 r.is_const_ = r.is_const_ && o.is_const_;
1734 return r.const_value() / o.const_value();
1740class expr_result_stack_type
1742 vector<expr_result> elems_;
1746 expr_result_stack_type()
1747 {elems_.reserve(4);}
1750 operator[](
unsigned i)
1752 unsigned s = elems_.size();
1754 return elems_[s - 1 -i];
1758 operator[](
unsigned i)
const
1759 {
return const_cast<expr_result_stack_type*
>(
this)->
operator[](i);}
1763 {
return elems_.size();}
1765 vector<expr_result>::reverse_iterator
1767 {
return elems_.rbegin();}
1769 const vector<expr_result>::reverse_iterator
1771 {
return const_cast<expr_result_stack_type*
>(
this)->begin();}
1773 vector<expr_result>::reverse_iterator
1775 {
return elems_.rend();}
1777 const vector<expr_result>::reverse_iterator
1779 {
return const_cast<expr_result_stack_type*
>(
this)->end();}
1783 {
return elems_.back();}
1787 {
return const_cast<expr_result_stack_type*
>(
this)->front();}
1790 push_front(expr_result e)
1791 {elems_.push_back(e);}
1796 expr_result r = front();
1802 erase(vector<expr_result>::reverse_iterator i)
1803 {elems_.erase(--i.base());}
1811struct dwarf_expr_eval_context
1814 expr_result_stack_type stack;
1819 dwarf_expr_eval_context()
1823 stack.push_front(expr_result(
true));
1830 stack.push_front(expr_result(
true));
1831 accum = expr_result(
false);
1832 set_tls_addr =
false;
1841 set_tls_address(
bool f)
1850 set_tls_address()
const
1851 {
return set_tls_addr;}
1856 expr_result r = stack.front();
1862 push(
const expr_result& v)
1863 {stack.push_front(v);}
1872typedef shared_ptr<reader> reader_sptr;
1879class reader :
public elf_based_reader
1886 template <
typename ContainerType>
1887 class die_source_dependant_container_set
1889 ContainerType primary_debug_info_container_;
1890 ContainerType alt_debug_info_container_;
1891 ContainerType type_unit_container_;
1905 ContainerType *result = 0;
1908 case PRIMARY_DEBUG_INFO_DIE_SOURCE:
1909 result = &primary_debug_info_container_;
1911 case ALT_DEBUG_INFO_DIE_SOURCE:
1912 result = &alt_debug_info_container_;
1914 case TYPE_UNIT_DIE_SOURCE:
1915 result = &type_unit_container_;
1917 case NO_DEBUG_INFO_DIE_SOURCE:
1918 case NUMBER_OF_DIE_SOURCES:
1931 const ContainerType&
1934 return const_cast<die_source_dependant_container_set*
>(
this)->
1935 get_container(source);
1949 get_container(
const reader& rdr,
const Dwarf_Die *die)
1951 const die_source source = rdr.get_die_source(die);
1952 return get_container(source);
1965 const ContainerType&
1966 get_container(
const reader& rdr,
const Dwarf_Die *die)
const
1968 return const_cast<die_source_dependant_container_set*
>(
this)->
1969 get_container(rdr, die);
1976 primary_debug_info_container_.clear();
1977 alt_debug_info_container_.clear();
1978 type_unit_container_.clear();
1985 unsigned number_of_suppressed_functions = 0;
1986 unsigned number_of_suppressed_variables = 0;
1987 unsigned number_of_allowed_functions = 0;
1988 unsigned number_of_allowed_variables = 0;
1994 number_of_suppressed_functions = 0;
1995 number_of_suppressed_variables = 0;
1996 number_of_allowed_functions = 0;
1997 number_of_allowed_variables = 0;
2001 unsigned short dwarf_version_;
2002 Dwarf_Die* cur_tu_die_;
2003 mutable dwarf_expr_eval_context dwarf_expr_eval_context_;
2007 mutable die_source_dependant_container_set<istring_dwarf_offsets_map_type>
2008 decl_die_repr_die_offsets_maps_;
2012 mutable die_source_dependant_container_set<istring_dwarf_offsets_map_type>
2013 type_die_repr_die_offsets_maps_;
2014 mutable die_source_dependant_container_set<die_istring_map_type>
2015 die_qualified_name_maps_;
2016 mutable die_source_dependant_container_set<die_istring_map_type>
2017 die_pretty_repr_maps_;
2018 mutable die_source_dependant_container_set<die_istring_map_type>
2019 die_pretty_type_repr_maps_;
2022 mutable die_source_dependant_container_set<die_artefact_map_type>
2023 decl_die_artefact_maps_;
2026 mutable die_source_dependant_container_set<die_artefact_map_type>
2027 type_die_artefact_maps_;
2030 mutable die_source_dependant_container_set<offset_offset_map_type>
2031 canonical_type_die_offsets_;
2034 mutable die_source_dependant_container_set<offset_offset_map_type>
2035 canonical_decl_die_offsets_;
2041 mutable std::unordered_map<std::pair<offset_type,offset_type>,
2043 dwarf_offset_pair_hash> die_comparison_results_;
2053 vector<type_base_sptr> types_to_canonicalize_;
2072 list<var_decl_sptr> var_decls_to_add_;
2073#ifdef WITH_DEBUG_TYPE_CANONICALIZATION
2074 bool debug_die_canonicalization_is_on_;
2075 bool use_canonical_die_comparison_;
2077 mutable size_t compare_count_;
2078 mutable size_t canonical_propagated_count_;
2079 mutable size_t cancelled_propagation_count_;
2080 mutable optional<bool> leverage_dwarf_factorization_;
2081 mutable stats stats_;
2116 reader(
const string& elf_path,
2118 environment& environment,
2119 bool load_all_types,
2120 bool linux_kernel_mode)
2125 reset(load_all_types, linux_kernel_mode);
2150 reset(
bool load_all_types,
bool linux_kernel_mode)
2154 decl_die_repr_die_offsets_maps_.clear();
2155 type_die_repr_die_offsets_maps_.clear();
2156 die_qualified_name_maps_.clear();
2157 die_pretty_repr_maps_.clear();
2158 die_pretty_type_repr_maps_.clear();
2159 decl_die_artefact_maps_.clear();
2160 type_die_artefact_maps_.clear();
2161 canonical_type_die_offsets_.clear();
2162 canonical_decl_die_offsets_.clear();
2163 die_wip_classes_map_.clear();
2164 alternate_die_wip_classes_map_.clear();
2165 type_unit_die_wip_classes_map_.clear();
2166 die_wip_function_types_map_.clear();
2167 alternate_die_wip_function_types_map_.clear();
2168 type_unit_die_wip_function_types_map_.clear();
2169 die_function_with_no_symbol_map_.clear();
2170 types_to_canonicalize_.clear();
2171 decl_only_classes_map_.clear();
2172 die_tu_map_.clear();
2176 primary_die_parent_map_.clear();
2177 tu_die_imported_unit_points_map_.clear();
2178 alt_tu_die_imported_unit_points_map_.clear();
2179 type_units_tu_die_imported_unit_points_map_.clear();
2180 alternate_die_parent_map_.clear();
2181 type_section_die_parent_map_.clear();
2182 var_decls_to_add_.clear();
2183 clear_per_translation_unit_data();
2184 clear_per_corpus_data();
2185 options().load_in_linux_kernel_mode = linux_kernel_mode;
2186 options().load_all_types = load_all_types;
2187#ifdef WITH_DEBUG_TYPE_CANONICALIZATION
2188 debug_die_canonicalization_is_on_ =
2189 env().debug_die_canonicalization_is_on();
2190 use_canonical_die_comparison_ =
true;
2193 canonical_propagated_count_ = 0;
2194 cancelled_propagation_count_ = 0;
2195 load_in_linux_kernel_mode(linux_kernel_mode);
2219 bool load_all_types,
2220 bool linux_kernel_mode)
2223 reset(load_all_types, linux_kernel_mode);
2243 static dwarf::reader_sptr
2244 create(
const std::string& elf_path,
2246 environment& environment,
2247 bool load_all_types,
2248 bool linux_kernel_mode)
2251 environment, load_all_types,
2252 linux_kernel_mode));
2280 return corpus_sptr();
2299 return corpus_sptr();
2303 corpus_sptr corp = read_debug_info_into_corpus();
2318 read_debug_info_into_corpus()
2323 origin |= corpus::DWARF_ORIGIN;
2324 corpus()->set_origin(origin);
2331 if (origin & corpus::LINUX_KERNEL_BINARY_ORIGIN
2332 && !env().user_set_analyze_exported_interfaces_only())
2339 env().analyze_exported_interfaces_only(
true);
2350 || !
corpus()->get_symtab()
2351 || !
corpus()->get_symtab()->has_symbols())
2354 uint8_t address_size = 0;
2355 size_t header_size = 0;
2357#ifdef WITH_DEBUG_SELF_COMPARISON
2358 if (env().self_comparison_debug_is_on())
2362 env().set_self_comparison_debug_input(g);
2364 env().set_self_comparison_debug_input(
corpus());
2368 env().priv_->do_log(do_log());
2373 tools_utils::timer t;
2376 cerr <<
"building die -> parent maps ...";
2380 build_die_parent_maps();
2385 cerr <<
" DONE@" <<
corpus()->get_path()
2392 env().canonicalization_is_done(
false);
2395 tools_utils::timer t;
2398 cerr <<
"DWARF Reader: building the "
2399 "libabigail internal representation ...\n";
2403 Dwarf_Half dwarf_vers = 0;
2404 for (Dwarf_Off offset = 0, next_offset = 0;
2406 offset, &next_offset, &header_size,
2407 &dwarf_vers, NULL, &address_size, NULL,
2409 offset = next_offset)
2411 Dwarf_Off die_offset = offset + header_size;
2415 || dwarf_tag(&unit) != DW_TAG_compile_unit)
2418 dwarf_version(dwarf_vers);
2425 build_translation_unit_and_add_to_ir(*
this, &unit, address_size);
2431 cerr <<
"DWARF Reader: building "
2432 <<
"the libabigail internal representation "
2433 <<
"DONE for corpus " <<
corpus()->get_path()
2438 cerr <<
"DWARF Reader: Number of aggregate types compared: "
2439 << compare_count_ <<
"\n"
2440 <<
"Number of canonical types propagated: "
2441 << canonical_propagated_count_ <<
"\n"
2442 <<
"Number of cancelled propagated canonical types:"
2443 << cancelled_propagation_count_ <<
"\n"
2444 <<
"Number of suppressed functions: "
2445 << stats_.number_of_suppressed_functions <<
"\n"
2446 <<
"Number of allowed functions: "
2447 << stats_.number_of_allowed_functions <<
"\n"
2448 <<
"Total number of fns in the corpus: "
2449 <<
corpus()->get_functions().size() <<
"\n"
2450 <<
"Total number of variables in the corpus: "
2451 <<
corpus()->get_variables().size() <<
"\n";
2456 tools_utils::timer t;
2459 cerr <<
"DWARF Reader: resolving declaration only classes ...";
2462 resolve_declaration_only_classes();
2466 cerr <<
" DONE@" <<
corpus()->get_path()
2474 tools_utils::timer t;
2477 cerr <<
"resolving declaration only enums ...";
2480 resolve_declaration_only_enums();
2484 cerr <<
" DONE@" <<
corpus()->get_path()
2492 tools_utils::timer t;
2495 cerr <<
"DWARF Reader: fixing up functions with linkage name but "
2496 <<
"no advertised underlying symbols ....";
2499 fixup_functions_with_no_symbols();
2503 cerr <<
" DONE@" <<
corpus()->get_path()
2510 merge_member_functions_and_variables_in_classes_of_same_names();
2524 tools_utils::timer t;
2527 cerr <<
"DWARF Reader: perform late type canonicalizing ...\n";
2531 perform_late_type_canonicalizing();
2535 cerr <<
"DWARF Reader: late type canonicalizing DONE for "
2543 env().canonicalization_is_done(
true);
2546 tools_utils::timer t;
2549 cerr <<
"DWARF Reader: sort functions and variables ...";
2552 corpus()->sort_functions();
2553 corpus()->sort_variables();
2557 cerr <<
" DONE@" <<
corpus()->get_path()
2571 clear_per_translation_unit_data()
2573 while (!scope_stack().empty())
2574 scope_stack().pop();
2575 var_decls_to_re_add_to_tree().clear();
2576 per_tu_repr_to_fn_type_maps().clear();
2582 clear_per_corpus_data()
2584 die_qualified_name_maps_.clear();
2585 die_pretty_repr_maps_.clear();
2586 die_pretty_type_repr_maps_.clear();
2587 clear_types_to_canonicalize();
2602 {
return const_cast<reader*
>(
this)->env();}
2610 drop_undefined_syms()
const
2611 {
return options().drop_undefined_syms;}
2618 drop_undefined_syms(
bool f)
2619 {
options().drop_undefined_syms = f;}
2623 dwarf_version()
const
2624 {
return dwarf_version_;}
2627 dwarf_version(
unsigned short v)
2628 {dwarf_version_ = v;}
2640 dwarf_elf_handle()
const
2651 dwarf_is_splitted()
const
2661 dwarf_per_die_source(
die_source source)
const
2663 const Dwarf *result = 0;
2666 case PRIMARY_DEBUG_INFO_DIE_SOURCE:
2667 case TYPE_UNIT_DIE_SOURCE:
2670 case ALT_DEBUG_INFO_DIE_SOURCE:
2673 case NO_DEBUG_INFO_DIE_SOURCE:
2674 case NUMBER_OF_DIE_SOURCES:
2689 {
return cur_tu_die_;}
2692 cur_tu_die(Dwarf_Die* cur_tu_die)
2693 {cur_tu_die_ = cur_tu_die;}
2695 dwarf_expr_eval_context&
2696 dwarf_expr_eval_ctxt()
const
2697 {
return dwarf_expr_eval_context_;}
2704 const die_source_dependant_container_set<istring_dwarf_offsets_map_type>&
2705 decl_die_repr_die_offsets_maps()
const
2706 {
return decl_die_repr_die_offsets_maps_;}
2713 die_source_dependant_container_set<istring_dwarf_offsets_map_type>&
2714 decl_die_repr_die_offsets_maps()
2715 {
return decl_die_repr_die_offsets_maps_;}
2722 const die_source_dependant_container_set<istring_dwarf_offsets_map_type>&
2723 type_die_repr_die_offsets_maps()
const
2724 {
return type_die_repr_die_offsets_maps_;}
2731 die_source_dependant_container_set<istring_dwarf_offsets_map_type>&
2732 type_die_repr_die_offsets_maps()
2733 {
return type_die_repr_die_offsets_maps_;}
2746 compute_canonical_die_offset(
const Dwarf_Die *die,
2747 Dwarf_Off &canonical_die_offset,
2748 bool die_as_type)
const
2752 ?
const_cast<reader*
>(
this)->canonical_type_die_offsets_.
2753 get_container(*
this, die)
2754 :
const_cast<reader*
>(
this)->canonical_decl_die_offsets_.
2755 get_container(*
this, die);
2757 Dwarf_Die canonical_die;
2758 compute_canonical_die(die, canonical_dies, canonical_die, die_as_type);
2760 canonical_die_offset = dwarf_dieoffset(&canonical_die);
2778 compute_canonical_die(
const Dwarf_Die *die,
2780 Dwarf_Die &canonical_die,
2781 bool die_as_type)
const
2783 const die_source source = get_die_source(die);
2785 Dwarf_Off die_offset = dwarf_dieoffset(
const_cast<Dwarf_Die*
>(die));
2787 compute_canonical_die(die_offset, source,
2789 canonical_die, die_as_type);
2809 compute_canonical_die(Dwarf_Off die_offset,
2812 Dwarf_Die &canonical_die,
2813 bool die_as_type)
const
2819 ? (
const_cast<reader*
>(
this)->
2820 type_die_repr_die_offsets_maps().get_container(source))
2821 : (const_cast<reader*>(this)->
2822 decl_die_repr_die_offsets_maps().get_container(source));
2825 ABG_ASSERT(dwarf_offdie(
const_cast<Dwarf*
>(dwarf_per_die_source(source)),
2834 interned_string name =
2836 ? get_die_pretty_type_representation(&die, 0)
2837 : get_die_pretty_representation(&die, 0);
2839 Dwarf_Off canonical_die_offset = 0;
2840 istring_dwarf_offsets_map_type::iterator i = map.find(name);
2844 offsets.push_back(die_offset);
2845 map[name] = offsets;
2846 set_canonical_die_offset(canonical_dies, die_offset, die_offset);
2847 get_die_from_offset(source, die_offset, &canonical_die);
2851 Dwarf_Off cur_die_offset;
2852 Dwarf_Die potential_canonical_die;
2853 for (dwarf_offsets_type::const_iterator o = i->second.begin();
2854 o != i->second.end();
2857 cur_die_offset = *o;
2858 get_die_from_offset(source, cur_die_offset, &potential_canonical_die);
2859 if (compare_dies(*
this, &die, &potential_canonical_die,
2862 canonical_die_offset = cur_die_offset;
2863 set_canonical_die_offset(canonical_dies, die_offset,
2864 canonical_die_offset);
2865 get_die_from_offset(source, canonical_die_offset, &canonical_die);
2870 canonical_die_offset = die_offset;
2871 i->second.push_back(die_offset);
2872 set_canonical_die_offset(canonical_dies, die_offset, die_offset);
2873 get_die_from_offset(source, canonical_die_offset, &canonical_die);
2892 get_canonical_die(
const Dwarf_Die *die,
2893 Dwarf_Die &canonical_die,
2897 const die_source source = get_die_source(die);
2901 ?
const_cast<reader*
>(
this)->canonical_type_die_offsets_.
2902 get_container(source)
2903 :
const_cast<reader*
>(
this)->canonical_decl_die_offsets_.
2904 get_container(source);
2906 Dwarf_Off die_offset = dwarf_dieoffset(
const_cast<Dwarf_Die*
>(die));
2907 if (Dwarf_Off canonical_die_offset =
2908 get_canonical_die_offset(canonical_dies, die_offset))
2910 get_die_from_offset(source, canonical_die_offset, &canonical_die);
2918 ? (
const_cast<reader*
>(
this)->
2919 type_die_repr_die_offsets_maps().get_container(*
this, die))
2920 : (const_cast<reader*>(this)->
2921 decl_die_repr_die_offsets_maps().get_container(*this, die));
2929 interned_string name =
2931 ? get_die_pretty_type_representation(die, where)
2932 : get_die_pretty_representation(die, where);
2934 istring_dwarf_offsets_map_type::iterator i = map.find(name);
2938 Dwarf_Off cur_die_offset;
2939 for (dwarf_offsets_type::const_iterator o = i->second.begin();
2940 o != i->second.end();
2943 cur_die_offset = *o;
2944 get_die_from_offset(source, cur_die_offset, &canonical_die);
2946 if (compare_dies_during_canonicalization(
const_cast<reader&
>(*
this),
2947 die, &canonical_die,
2950 set_canonical_die_offset(canonical_dies,
2984 get_or_compute_canonical_die(
const Dwarf_Die* die,
2985 Dwarf_Die& canonical_die,
2987 bool die_as_type)
const
2989 const die_source source = get_die_source(die);
2993 ?
const_cast<reader*
>(
this)->canonical_type_die_offsets_.
2994 get_container(source)
2995 :
const_cast<reader*
>(
this)->canonical_decl_die_offsets_.
2996 get_container(source);
2998 Dwarf_Off initial_die_offset = dwarf_dieoffset(
const_cast<Dwarf_Die*
>(die));
3000 if (Dwarf_Off canonical_die_offset =
3001 get_canonical_die_offset(canonical_dies,
3002 initial_die_offset))
3004 get_die_from_offset(source, canonical_die_offset, &canonical_die);
3008 if (!is_type_die_to_be_canonicalized(die))
3015 ? (
const_cast<reader*
>(
this)->
3016 type_die_repr_die_offsets_maps().get_container(*
this, die))
3017 : (const_cast<reader*>(this)->
3018 decl_die_repr_die_offsets_maps().get_container(*this, die));
3026 interned_string name =
3028 ? get_die_pretty_type_representation(die, where)
3029 : get_die_pretty_representation(die, where);
3031 istring_dwarf_offsets_map_type::iterator i = map.find(name);
3035 offsets.push_back(initial_die_offset);
3036 map[name] = offsets;
3037 get_die_from_offset(source, initial_die_offset, &canonical_die);
3038 set_canonical_die_offset(canonical_dies,
3040 initial_die_offset);
3047 dwarf_offsets_type::size_type n = 0, s = i->second.size();
3050 Dwarf_Off die_offset = i->second[n];
3051 get_die_from_offset(source, die_offset, &canonical_die);
3053 if (compare_dies_during_canonicalization(
const_cast<reader&
>(*
this),
3054 die, &canonical_die,
3057 set_canonical_die_offset(canonical_dies,
3067 get_die_from_offset(source, initial_die_offset, &canonical_die);
3068 i->second.push_back(initial_die_offset);
3069 set_canonical_die_offset(canonical_dies,
3071 initial_die_offset);
3088 get_die_source(
const Dwarf_Die *die)
const
3090 die_source source = NO_DEBUG_INFO_DIE_SOURCE;
3111 get_die_source(
const Dwarf_Die &die,
die_source &source)
const
3115 uint8_t address_size = 0, offset_size = 0;
3116 if (!dwarf_diecu(
const_cast<Dwarf_Die*
>(&die),
3117 &cu_die, &address_size,
3121 Dwarf_Half version = 0;
3122 Dwarf_Off abbrev_offset = 0;
3123 uint64_t type_signature = 0;
3124 Dwarf_Off type_offset = 0;
3125 if (!dwarf_cu_die(cu_die.cu, &cu_kind,
3126 &version, &abbrev_offset,
3127 &address_size, &offset_size,
3128 &type_signature, &type_offset))
3131 int tag = dwarf_tag(&cu_kind);
3133 if (tag == DW_TAG_compile_unit
3134 || tag == DW_TAG_partial_unit)
3136 const Dwarf *die_dwarf = dwarf_cu_getdwarf(cu_die.cu);
3138 source = PRIMARY_DEBUG_INFO_DIE_SOURCE;
3140 source = ALT_DEBUG_INFO_DIE_SOURCE;
3144 else if (tag == DW_TAG_type_unit)
3145 source = TYPE_UNIT_DIE_SOURCE;
3161 get_die_from_offset(
die_source source, Dwarf_Off offset, Dwarf_Die *die)
const
3163 if (source == TYPE_UNIT_DIE_SOURCE)
3164 ABG_ASSERT(dwarf_offdie_types(
const_cast<Dwarf*
>(dwarf_per_die_source(source)),
3167 ABG_ASSERT(dwarf_offdie(
const_cast<Dwarf*
>(dwarf_per_die_source(source)),
3194 associate_die_to_decl(Dwarf_Die* die,
3195 decl_base_sptr decl,
3196 size_t where_offset,
3197 bool do_associate_by_repr =
false)
3199 const die_source source = get_die_source(die);
3202 decl_die_artefact_maps().get_container(source);
3205 if (do_associate_by_repr)
3207 Dwarf_Die equiv_die;
3208 if (!get_or_compute_canonical_die(die, equiv_die, where_offset,
3211 die_offset = dwarf_dieoffset(&equiv_die);
3214 die_offset = dwarf_dieoffset(die);
3216 m[die_offset] = decl;
3238 lookup_decl_from_die_offset(Dwarf_Off die_offset,
die_source source)
3240 decl_base_sptr result =
3241 is_decl(lookup_artifact_from_die_offset(die_offset, source,
3266 get_die_qualified_name(Dwarf_Die *die,
size_t where_offset,
3267 unordered_set<uint64_t>& guard)
const
3271 die_qualified_name_maps_.get_container(*
this, die);
3273 size_t die_offset = dwarf_dieoffset(die);
3274 die_istring_map_type::const_iterator i = map.find(die_offset);
3278 reader& rdr = *
const_cast<reader*
>(
this);
3279 string qualified_name = die_qualified_name(rdr, die,
3282 interned_string istr = env().intern(qualified_name);
3283 map[die_offset] = istr;
3314 get_die_qualified_type_name(
const Dwarf_Die *die,
size_t where_offset,
3315 unordered_set<uint64_t>& guard)
const
3320 if (die == cur_tu_die())
3321 return env().intern(
"");
3324 die_qualified_name_maps_.get_container(*
const_cast<reader*
>(
this),
3327 size_t die_offset = dwarf_dieoffset(
const_cast<Dwarf_Die*
>(die));
3328 die_istring_map_type::const_iterator i =
3329 map.find(die_offset);
3333 reader& rdr = *
const_cast<reader*
>(
this);
3334 string qualified_name;
3335 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
3336 if ((tag == DW_TAG_structure_type
3337 || tag == DW_TAG_class_type
3338 || tag == DW_TAG_union_type)
3339 && die_is_anonymous(die))
3341 die_class_or_enum_flat_representation(*
this, die,
"",
3347 qualified_name = die_qualified_type_name(rdr, die,
3351 interned_string istr = env().intern(qualified_name);
3352 map[die_offset] = istr;
3382 get_die_pretty_type_representation(
const Dwarf_Die *die,
3383 size_t where_offset,
3384 unordered_set<uint64_t>& guard)
const
3388 die_pretty_type_repr_maps_.get_container(*
const_cast<reader*
>(
this),
3391 size_t die_offset = dwarf_dieoffset(
const_cast<Dwarf_Die*
>(die));
3392 die_istring_map_type::const_iterator i = map.find(die_offset);
3396 reader& rdr = *
const_cast<reader*
>(
this);
3397 string pretty_representation =
3398 die_pretty_print_type(rdr, die, where_offset, guard);
3399 interned_string istr = env().intern(pretty_representation);
3400 map[die_offset] = istr;
3425 get_die_pretty_type_representation(
const Dwarf_Die *die,
3426 size_t where_offset)
const
3428 unordered_set<uint64_t> guard;
3429 return get_die_pretty_type_representation(die, where_offset, guard);
3451 get_die_pretty_representation(
const Dwarf_Die *die,
size_t where_offset,
3452 unordered_set<uint64_t>& guard)
const
3457 die_pretty_repr_maps_.get_container(*
const_cast<reader*
>(
this),
3460 size_t die_offset = dwarf_dieoffset(
const_cast<Dwarf_Die*
>(die));
3461 die_istring_map_type::const_iterator i = map.find(die_offset);
3465 reader& rdr = *
const_cast<reader*
>(
this);
3466 string pretty_representation =
3467 die_pretty_print(rdr, die, where_offset, guard);
3468 interned_string istr = env().intern(pretty_representation);
3469 map[die_offset] = istr;
3489 get_die_pretty_representation(
const Dwarf_Die *die,
size_t where_offset)
const
3491 unordered_set<uint64_t> guard;
3492 return get_die_pretty_representation(die, where_offset, guard);
3512 lookup_type_artifact_from_die(Dwarf_Die *die)
const
3515 lookup_artifact_from_die(die,
true);
3517 return fn->get_type();
3541 lookup_artifact_from_die(
const Dwarf_Die *die,
bool die_as_type =
false)
const
3543 Dwarf_Die equiv_die;
3544 if (!get_or_compute_canonical_die(die, equiv_die, 0, die_as_type))
3549 ? type_die_artefact_maps().get_container(*
this, &equiv_die)
3550 : decl_die_artefact_maps().get_container(*
this, &equiv_die);
3552 size_t die_offset = dwarf_dieoffset(&equiv_die);
3553 die_artefact_map_type::const_iterator i = m.find(die_offset);
3580 lookup_artifact_from_die_offset(Dwarf_Off die_offset,
3582 bool die_as_type =
false)
const
3586 ? type_die_artefact_maps().get_container(source)
3587 : decl_die_artefact_maps().get_container(source);
3589 die_artefact_map_type::const_iterator i = m.find(die_offset);
3632 ABG_ASSERT(dwarf_offdie(
const_cast<Dwarf*
>(dwarf_per_die_source(source)),
3647 if (!get_die_language(die, lang))
3658 die_source_dependant_container_set<die_artefact_map_type>&
3659 decl_die_artefact_maps()
3660 {
return decl_die_artefact_maps_;}
3667 const die_source_dependant_container_set<die_artefact_map_type>&
3668 decl_die_artefact_maps()
const
3669 {
return decl_die_artefact_maps_;}
3676 die_source_dependant_container_set<die_artefact_map_type>&
3677 type_die_artefact_maps()
3678 {
return type_die_artefact_maps_;}
3685 const die_source_dependant_container_set<die_artefact_map_type>&
3686 type_die_artefact_maps()
const
3687 {
return type_die_artefact_maps_;}
3695 per_tu_repr_to_fn_type_maps()
3696 {
return per_tu_repr_to_fn_type_maps_;}
3704 per_tu_repr_to_fn_type_maps()
const
3705 {
return per_tu_repr_to_fn_type_maps_;}
3715 associate_die_repr_to_fn_type_per_tu(
const Dwarf_Die *die,
3718 if (!die_is_function_type(die))
3721 interned_string repr =
3722 get_die_pretty_type_representation(die, 0);
3725 per_tu_repr_to_fn_type_maps()[repr]= fn_type;
3736 lookup_fn_type_from_die_repr_per_tu(
const Dwarf_Die *die)
3738 if (!die_is_function_type(die))
3741 interned_string repr = die_name(die).empty() ?
3742 get_die_pretty_type_representation(die, 0)
3743 : get_die_pretty_representation(die, 0);
3746 istring_fn_type_map_type::const_iterator i =
3747 per_tu_repr_to_fn_type_maps().find(repr);
3749 if (i == per_tu_repr_to_fn_type_maps().end())
3766 Dwarf_Off die_offset,
3767 Dwarf_Off canonical_die_offset)
const
3769 canonical_dies[die_offset] = canonical_die_offset;}
3785 set_canonical_die_offset(Dwarf_Off die_offset,
3787 Dwarf_Off canonical_die_offset,
3788 bool die_as_type)
const
3792 ?
const_cast<reader*
>(
this)->canonical_type_die_offsets_.
3793 get_container(source)
3794 :
const_cast<reader*
>(
this)->canonical_decl_die_offsets_.
3795 get_container(source);
3797 set_canonical_die_offset(canonical_dies,
3799 canonical_die_offset);
3813 set_canonical_die_offset(
const Dwarf_Die *die,
3814 Dwarf_Off canonical_die_offset,
3815 bool die_as_type)
const
3817 const die_source source = get_die_source(die);
3819 Dwarf_Off die_offset = dwarf_dieoffset(
const_cast<Dwarf_Die*
>(die));
3821 set_canonical_die_offset(die_offset, source,
3822 canonical_die_offset,
3836 Dwarf_Off die_offset)
const
3838 offset_offset_map_type::const_iterator it = canonical_dies.find(die_offset);
3839 if (it == canonical_dies.end())
3856 get_canonical_die_offset(Dwarf_Off die_offset,
3858 bool die_as_type)
const
3862 ?
const_cast<reader*
>(
this)->canonical_type_die_offsets_.
3863 get_container(source)
3864 :
const_cast<reader*
>(
this)->canonical_decl_die_offsets_.
3865 get_container(source);
3867 return get_canonical_die_offset(canonical_dies, die_offset);
3882 erase_canonical_die_offset(Dwarf_Off die_offset,
3884 bool die_as_type)
const
3888 ?
const_cast<reader*
>(
this)->canonical_type_die_offsets_.
3889 get_container(source)
3890 :
const_cast<reader*
>(
this)->canonical_decl_die_offsets_.
3891 get_container(source);
3893 return canonical_dies.erase(die_offset);
3906 associate_die_to_type(
const Dwarf_Die *die,
3907 type_base_sptr type,
3913 Dwarf_Die equiv_die;
3914 if (!get_or_compute_canonical_die(die, equiv_die, where,
3919 type_die_artefact_maps().get_container(*
this, &equiv_die);
3921 size_t die_offset = dwarf_dieoffset(&equiv_die);
3922 m[die_offset] = type;
3936 lookup_type_from_die(
const Dwarf_Die* die)
const
3939 lookup_artifact_from_die(die,
true);
3941 return fn->get_type();
3959 lookup_type_from_die_offset(
size_t die_offset,
die_source source)
const
3961 type_base_sptr result;
3963 type_die_artefact_maps().get_container(source);
3964 die_artefact_map_type::const_iterator i = m.find(die_offset);
3968 return fn->get_type();
3976 die_class_or_union_map_type::const_iterator i = m.find(die_offset);
3986 die_wip_function_types_map(source);
3987 die_function_type_map_type::const_iterator i = m.find(die_offset);
4006 {
return const_cast<reader*
>(
this)->die_wip_classes_map(source);}
4021 case PRIMARY_DEBUG_INFO_DIE_SOURCE:
4023 case ALT_DEBUG_INFO_DIE_SOURCE:
4024 return alternate_die_wip_classes_map_;
4025 case TYPE_UNIT_DIE_SOURCE:
4026 return type_unit_die_wip_classes_map_;
4027 case NO_DEBUG_INFO_DIE_SOURCE:
4028 case NUMBER_OF_DIE_SOURCES:
4031 return die_wip_classes_map_;
4042 die_wip_function_types_map(
die_source source)
const
4043 {
return const_cast<reader*
>(
this)->die_wip_function_types_map(source);}
4053 die_wip_function_types_map(
die_source source)
4057 case PRIMARY_DEBUG_INFO_DIE_SOURCE:
4059 case ALT_DEBUG_INFO_DIE_SOURCE:
4060 return alternate_die_wip_function_types_map_;
4061 case TYPE_UNIT_DIE_SOURCE:
4062 return type_unit_die_wip_function_types_map_;
4063 case NO_DEBUG_INFO_DIE_SOURCE:
4064 case NUMBER_OF_DIE_SOURCES:
4067 return die_wip_function_types_map_;
4078 die_function_decl_with_no_symbol_map()
4079 {
return die_function_with_no_symbol_map_;}
4092 is_wip_class_die_offset(Dwarf_Off offset,
die_source source)
const
4094 die_class_or_union_map_type::const_iterator i =
4095 die_wip_classes_map(source).find(offset);
4096 return (i != die_wip_classes_map(source).end());
4110 is_wip_function_type_die_offset(Dwarf_Off offset,
die_source source)
const
4112 die_function_type_map_type::const_iterator i =
4113 die_wip_function_types_map(source).find(offset);
4114 return (i != die_wip_function_types_map(source).end());
4133 build_name_for_buggy_anonymous_data_member(Dwarf_Die *die)
4139 || dwarf_tag(die) != DW_TAG_member
4140 || !die_name(die).empty())
4146 if (die_is_anonymous_data_member(die))
4152 int64_t offset_in_bits = 0;
4153 bool has_offset = die_member_offset(*
this, die, offset_in_bits);
4157 loc = die_location(*
this, die);
4162 std::ostringstream o;
4163 o <<
"unnamed-dm-@-";
4165 o <<
"offset-" << offset_in_bits <<
"bits";
4167 o <<
"loc-" << loc.expand();
4180 declaration_only_classes()
const
4181 {
return decl_only_classes_map_;}
4191 declaration_only_classes()
4192 {
return decl_only_classes_map_;}
4204 maybe_schedule_declaration_only_class_for_resolution(cou);
4206 maybe_schedule_declaration_only_enum_for_resolution(e);
4215 maybe_schedule_declaration_only_class_for_resolution(
const class_or_union_sptr& cou)
4217 if (cou->get_is_declaration_only()
4218 && cou->get_definition_of_declaration() == 0
4223 && !cou->get_qualified_name().empty())
4225 string qn = cou->get_qualified_name();
4226 string_classes_or_unions_map::iterator record =
4227 declaration_only_classes().find(qn);
4228 if (record == declaration_only_classes().end())
4229 declaration_only_classes()[qn].push_back(cou);
4231 record->second.push_back(cou);
4243 is_decl_only_class_scheduled_for_resolution(
const class_or_union_sptr& cou)
4245 if (cou->get_is_declaration_only())
4246 return ((declaration_only_classes().find(cou->get_qualified_name())
4247 != declaration_only_classes().end())
4248 || (declaration_only_classes().find(cou->get_name())
4249 != declaration_only_classes().end()));
4272 const environment& e = l->get_environment();
4276 && l->
kind() == r->kind()
4277 && ((l->get_corpus() && r->get_corpus()
4278 && (l->get_corpus() == r->get_corpus()))
4279 ||(l->get_translation_unit()
4280 && r->get_translation_unit()
4281 && l->get_translation_unit() == r->get_translation_unit())))
4290 decl_base *ld =
is_decl(l.get());
4291 decl_base *rd =
is_decl(r.get());
4293 if (ld->get_qualified_name() != rd->get_qualified_name())
4296 location ll = ld->get_location(), rl = rd->get_location();
4299 string l1 = ll.expand();
4300 string l2 = rl.expand();
4306 e.priv_->allow_type_comparison_results_caching(
true);
4307 bool s0 = e.decl_only_class_equals_definition();
4308 e.decl_only_class_equals_definition(
true);
4309 bool equal = l == r;
4310 e.decl_only_class_equals_definition(s0);
4311 e.priv_->clear_type_comparison_results_cache();
4312 e.priv_->allow_type_comparison_results_caching(
false);
4319 resolve_declaration_only_classes()
4321 vector<string> resolved_classes;
4323 for (string_classes_or_unions_map::iterator i =
4324 declaration_only_classes().begin();
4325 i != declaration_only_classes().end();
4328 bool to_resolve =
false;
4329 for (classes_or_unions_type::iterator j = i->second.begin();
4330 j != i->second.end();
4332 if ((*j)->get_is_declaration_only()
4333 && ((*j)->get_definition_of_declaration() == 0))
4338 resolved_classes.push_back(i->first);
4383 map<string, class_or_union_sptr> per_tu_class_map;
4384 for (type_base_wptrs_type::const_iterator c = classes->begin();
4385 c != classes->end();
4392 if (klass->get_is_declaration_only())
4395 string tu_path = klass->get_translation_unit()->get_absolute_path();
4396 if (tu_path.empty())
4402 per_tu_class_map[tu_path] = klass;
4405 if (!per_tu_class_map.empty())
4411 for (classes_or_unions_type::iterator j = i->second.begin();
4412 j != i->second.end();
4415 if ((*j)->get_is_declaration_only()
4416 && ((*j)->get_definition_of_declaration() == 0))
4419 (*j)->get_translation_unit()->get_absolute_path();
4420 map<string, class_or_union_sptr>::const_iterator e =
4421 per_tu_class_map.find(tu_path);
4422 if (e != per_tu_class_map.end())
4423 (*j)->set_definition_of_declaration(e->second);
4424 else if (per_tu_class_map.size() == 1)
4425 (*j)->set_definition_of_declaration
4426 (per_tu_class_map.begin()->second);
4436 class_or_union_sptr>::const_iterator it;
4437 class_or_union_sptr first_class =
4438 per_tu_class_map.begin()->second;
4439 bool all_class_definitions_are_equal =
true;
4440 for (it = per_tu_class_map.begin();
4441 it != per_tu_class_map.end();
4444 if (it == per_tu_class_map.begin())
4448 if (!compare_before_canonicalisation(it->second,
4451 all_class_definitions_are_equal =
false;
4456 if (all_class_definitions_are_equal)
4457 (*j)->set_definition_of_declaration(first_class);
4461 resolved_classes.push_back(i->first);
4465 size_t num_decl_only_classes = declaration_only_classes().size(),
4466 num_resolved = resolved_classes.size();
4468 cerr <<
"resolved " << num_resolved
4469 <<
" class declarations out of "
4470 << num_decl_only_classes
4473 for (vector<string>::const_iterator i = resolved_classes.begin();
4474 i != resolved_classes.end();
4476 declaration_only_classes().erase(*i);
4478 if (show_stats() && !declaration_only_classes().empty())
4480 cerr <<
"Here are the "
4481 << num_decl_only_classes - num_resolved
4482 <<
" unresolved class declarations:\n";
4483 for (string_classes_or_unions_map::iterator i =
4484 declaration_only_classes().begin();
4485 i != declaration_only_classes().end();
4487 cerr <<
" " << i->first <<
"\n";
4499 declaration_only_enums()
const
4500 {
return decl_only_enums_map_;}
4510 declaration_only_enums()
4511 {
return decl_only_enums_map_;}
4521 if (enom->get_is_declaration_only()
4522 && enom->get_definition_of_declaration() == 0
4527 && !enom->get_qualified_name().empty())
4529 string qn = enom->get_qualified_name();
4530 string_enums_map::iterator record =
4531 declaration_only_enums().find(qn);
4532 if (record == declaration_only_enums().end())
4533 declaration_only_enums()[qn].push_back(enom);
4535 record->second.push_back(enom);
4549 if (enom->get_is_declaration_only())
4550 return (declaration_only_enums().find(enom->get_qualified_name())
4551 != declaration_only_enums().end());
4564 resolve_declaration_only_enums()
4566 vector<string> resolved_enums;
4568 for (string_enums_map::iterator i =
4569 declaration_only_enums().begin();
4570 i != declaration_only_enums().end();
4573 bool to_resolve =
false;
4574 for (enums_type::iterator j = i->second.begin();
4575 j != i->second.end();
4577 if ((*j)->get_is_declaration_only()
4578 && ((*j)->get_definition_of_declaration() == 0))
4583 resolved_enums.push_back(i->first);
4625 map<string, enum_type_decl_sptr> per_tu_enum_map;
4626 for (type_base_wptrs_type::const_iterator c = enums->begin();
4634 if (enom->get_is_declaration_only())
4637 string tu_path = enom->get_translation_unit()->get_absolute_path();
4638 if (tu_path.empty())
4644 per_tu_enum_map[tu_path] = enom;
4647 if (!per_tu_enum_map.empty())
4653 for (enums_type::iterator j = i->second.begin();
4654 j != i->second.end();
4657 if ((*j)->get_is_declaration_only()
4658 && ((*j)->get_definition_of_declaration() == 0))
4661 (*j)->get_translation_unit()->get_absolute_path();
4662 map<string, enum_type_decl_sptr>::const_iterator e =
4663 per_tu_enum_map.find(tu_path);
4664 if (e != per_tu_enum_map.end())
4665 (*j)->set_definition_of_declaration(e->second);
4666 else if (per_tu_enum_map.size() == 1)
4667 (*j)->set_definition_of_declaration
4668 (per_tu_enum_map.begin()->second);
4680 per_tu_enum_map.begin()->second;
4681 bool all_enum_definitions_are_equal =
true;
4682 for (it = per_tu_enum_map.begin();
4683 it != per_tu_enum_map.end();
4686 if (it == per_tu_enum_map.begin())
4690 if (!compare_before_canonicalisation(it->second,
4693 all_enum_definitions_are_equal =
false;
4698 if (all_enum_definitions_are_equal)
4699 (*j)->set_definition_of_declaration(first_enum);
4703 resolved_enums.push_back(i->first);
4707 size_t num_decl_only_enums = declaration_only_enums().size(),
4708 num_resolved = resolved_enums.size();
4710 cerr <<
"resolved " << num_resolved
4711 <<
" enum declarations out of "
4712 << num_decl_only_enums
4715 for (vector<string>::const_iterator i = resolved_enums.begin();
4716 i != resolved_enums.end();
4718 declaration_only_enums().erase(*i);
4720 if (show_stats() && !declaration_only_enums().empty())
4722 cerr <<
"Here are the "
4723 << num_decl_only_enums - num_resolved
4724 <<
" unresolved enum declarations:\n";
4725 for (string_enums_map::iterator i = declaration_only_enums().begin();
4726 i != declaration_only_enums().end();
4728 cerr <<
" " << i->first <<
"\n";
4744 corpus_sptr corp =
corpus();
4748 interned_string
id = corp->get_environment().intern(fn->get_id_string());
4750 const std::unordered_set<function_decl*> *fns = corp->lookup_functions(
id);
4755 if (f->get_symbol())
4775 fixup_functions_with_no_symbols()
4777 corpus_sptr corp =
corpus();
4782 die_function_decl_with_no_symbol_map();
4785 cerr << fns_with_no_symbol.size()
4786 <<
" functions to fixup, potentially\n";
4788 for (die_function_decl_map_type::iterator i = fns_with_no_symbol.begin();
4789 i != fns_with_no_symbol.end();
4792 corp->lookup_function_symbol(i->second->get_linkage_name()))
4807 if (i->second->get_symbol()
4808 || symbol_already_belongs_to_a_function(sym))
4813 i->second->set_symbol(sym);
4816 cerr <<
"fixed up '"
4817 << i->second->get_pretty_representation()
4818 <<
"' with symbol '"
4819 << sym->get_id_string()
4823 fns_with_no_symbol.clear();
4836 for (
auto method : src_class->get_member_functions())
4837 if (!method->get_linkage_name().empty())
4838 if (!dest_class->find_member_function(method->get_linkage_name()))
4840 method_decl_sptr copied_method =
4843 schedule_type_for_late_canonicalization(copied_method->get_type());
4863 for (
auto var : src_class->get_data_members())
4865 if (!dest_class->find_data_member(var->
get_name()))
4880 template <
typename iterator_type>
4882 contains_anonymous_class(
const iterator_type& begin,
4883 const iterator_type& end)
4885 for (
auto i = begin; i < end; ++i)
4887 type_base_sptr t(*i);
4889 if (c && c->get_is_anonymous())
4905 template <
typename iterator_type>
4907 merge_member_functions_of_classes(
const iterator_type& begin,
4908 const iterator_type& end)
4910 if (contains_anonymous_class(begin, end))
4913 for (
auto i = begin; i < end; ++i)
4915 type_base_sptr t(*i);
4917 if (!reference_class)
4920 string n1 = reference_class->get_pretty_representation(
true,
true);
4922 for (
auto j = begin; j < end; ++j)
4927 type_base_sptr type(*j);
4932 n2 = klass->get_pretty_representation(
true,
true);
4936 copy_missing_member_functions(reference_class, klass);
4937 copy_missing_member_functions(klass, reference_class);
4953 template <
typename iterator_type>
4955 merge_member_variables_of_classes(
const iterator_type& begin,
4956 const iterator_type& end)
4958 if (contains_anonymous_class(begin, end))
4961 for (
auto i = begin; i < end; ++i)
4963 type_base_sptr t(*i);
4965 if (!reference_class)
4968 string n1 = reference_class->get_pretty_representation(
true,
true);
4970 for (
auto j = begin; j < end; ++j)
4975 type_base_sptr type(*j);
4980 n2 = klass->get_pretty_representation(
true,
true);
4984 copy_missing_member_variables(reference_class, klass);
4985 copy_missing_member_variables(klass, reference_class);
4994 merge_member_functions_and_variables_in_classes_of_same_names()
4996 corpus_sptr abi =
corpus();
5001 abi->get_types().class_types();
5003 for (
auto entry : class_types)
5005 auto& classes = entry.second;
5006 type_base_sptr first(classes.front());
5010 bool a_class_has_member_fns =
false;
5011 bool a_class_has_member_vars =
false;
5012 for (
auto& c : classes)
5014 type_base_sptr t(c);
5017 if (!klass->get_member_functions().empty())
5018 a_class_has_member_fns =
true;
5020 if (!klass->get_static_data_members().empty())
5021 a_class_has_member_vars =
true;
5024 if (a_class_has_member_fns)
5025 merge_member_functions_of_classes(classes.begin(),
5027 if (a_class_has_member_vars)
5028 merge_member_variables_of_classes(classes.begin(),
5036 const vector<type_base_sptr>&
5037 types_to_canonicalize()
const
5038 {
return types_to_canonicalize_;}
5042 vector<type_base_sptr>&
5043 types_to_canonicalize()
5044 {
return types_to_canonicalize_;}
5048 clear_types_to_canonicalize()
5050 types_to_canonicalize_.clear();
5058 schedule_type_for_late_canonicalization(
const type_base_sptr &t)
5060 types_to_canonicalize_.push_back(t);
5070 canonicalize_types_scheduled()
5072 tools_utils::timer cn_timer;
5075 cerr <<
"DWARF Reader is going to canonicalize "
5077 << types_to_canonicalize().size()
5079 corpus_sptr c =
corpus();
5081 cerr <<
" from corpus " <<
corpus()->get_path() <<
"\n";
5086 (types_to_canonicalize().begin(),
5087 types_to_canonicalize().end(),
5088 [](
const vector<type_base_sptr>::const_iterator& i)
5089 {
return *i;}, do_log(), show_stats());
5094 const environment& env = types_to_canonicalize().front()->get_environment();
5095 cerr <<
"DWARF Reader finished types "
5096 <<
"sorting, hashing & canonicalizing in: "
5099 << env.priv_->get_number_of_canonical_types()
5117 add_late_canonicalized_types_stats(
size_t& canonicalized,
5118 size_t& missed)
const
5120 for (
auto t : types_to_canonicalize())
5122 if (t->get_canonical_type())
5132 perform_late_type_canonicalizing()
5134 canonicalize_types_scheduled();
5138 size_t num_canonicalized = 0, num_missed = 0, total = 0;
5139 add_late_canonicalized_types_stats(num_canonicalized,
5141 total = num_canonicalized + num_missed;
5145 cerr <<
" # late canonicalized types: "
5146 << num_canonicalized;
5148 cerr <<
" (" << num_canonicalized * 100 / total <<
"%)";
5150 <<
" # missed canonicalization opportunities: "
5153 cerr <<
" (" << num_missed * 100 / total <<
"%)";
5161 {
return die_tu_map_;}
5165 {
return die_tu_map_;}
5174 tu_die_imported_unit_points_map(
die_source source)
const
5175 {
return const_cast<reader*
>(
this)->tu_die_imported_unit_points_map(source);}
5184 tu_die_imported_unit_points_map(
die_source source)
5188 case PRIMARY_DEBUG_INFO_DIE_SOURCE:
5190 case ALT_DEBUG_INFO_DIE_SOURCE:
5191 return alt_tu_die_imported_unit_points_map_;
5192 case TYPE_UNIT_DIE_SOURCE:
5193 return type_units_tu_die_imported_unit_points_map_;
5194 case NO_DEBUG_INFO_DIE_SOURCE:
5195 case NUMBER_OF_DIE_SOURCES:
5199 return tu_die_imported_unit_points_map_;
5217 {
return const_cast<reader*
>(
this)->die_parent_map(source);}
5230 case PRIMARY_DEBUG_INFO_DIE_SOURCE:
5232 case ALT_DEBUG_INFO_DIE_SOURCE:
5233 return alternate_die_parent_map_;
5234 case TYPE_UNIT_DIE_SOURCE:
5235 return type_section_die_parent_map();
5236 case NO_DEBUG_INFO_DIE_SOURCE:
5237 case NUMBER_OF_DIE_SOURCES:
5240 return primary_die_parent_map_;
5244 type_section_die_parent_map()
const
5245 {
return type_section_die_parent_map_;}
5248 type_section_die_parent_map()
5249 {
return type_section_die_parent_map_;}
5255 cur_transl_unit()
const
5279 global_scope()
const
5280 {
return cur_transl_unit()->get_global_scope();}
5287 {
return nil_scope_;}
5291 {
return scope_stack_;}
5295 {
return scope_stack_;}
5300 if (scope_stack().empty())
5302 if (cur_transl_unit())
5305 return scope_stack().top();
5308 list<var_decl_sptr>&
5309 var_decls_to_re_add_to_tree()
5310 {
return var_decls_to_add_;}
5323 is_decl_die_with_exported_symbol(
const Dwarf_Die *die)
const
5325 if (!die || !die_is_decl(die))
5328 bool result =
false, address_found =
false, symbol_is_exported =
false;;
5329 Dwarf_Addr decl_symbol_address = 0;
5331 if (die_is_variable_decl(die))
5333 if ((address_found = get_variable_address(die, decl_symbol_address)))
5334 symbol_is_exported =
5337 else if (die_is_function_decl(die))
5339 if ((address_found = get_function_address(die, decl_symbol_address)))
5340 symbol_is_exported =
5345 result = symbol_is_exported;
5356 is_decl_die_with_undefined_symbol(
const Dwarf_Die *die)
const
5358 if (is_decl_die_with_exported_symbol(die))
5361 string name, linkage_name;
5362 die_name_and_linkage_name(die, name, linkage_name);
5363 if (linkage_name.empty())
5364 linkage_name = name;
5366 bool result =
false;
5367 if ((die_is_variable_decl(die)
5370 (die_is_function_decl(die)
5391 maybe_adjust_address_for_exec_or_dyn(Dwarf_Addr addr)
const
5397 GElf_Ehdr *elf_header = gelf_getehdr(
elf_handle(), &eh_mem);
5399 if (elf_header->e_type == ET_DYN || elf_header->e_type == ET_EXEC)
5401 Dwarf_Addr dwarf_elf_load_address = 0, elf_load_address = 0;
5403 dwarf_elf_load_address)
5406 if (dwarf_is_splitted()
5407 && (dwarf_elf_load_address != elf_load_address))
5418 addr = addr - dwarf_elf_load_address + elf_load_address;
5444 maybe_adjust_fn_sym_address(Dwarf_Addr addr)
const
5451 GElf_Ehdr* elf_header = gelf_getehdr(elf, &eh_mem);
5453 if (elf_header->e_type == ET_REL)
5466 addr = maybe_adjust_address_for_exec_or_dyn(addr);
5491 maybe_adjust_var_sym_address(Dwarf_Addr addr)
const
5495 GElf_Ehdr* elf_header = gelf_getehdr(elf, &eh_mem);
5497 if (elf_header->e_type == ET_REL)
5510 addr = maybe_adjust_address_for_exec_or_dyn(addr);
5529 get_first_exported_fn_address_from_DW_AT_ranges(Dwarf_Die* die,
5530 Dwarf_Addr& address)
const
5533 Dwarf_Addr end_addr;
5534 ptrdiff_t offset = 0;
5538 Dwarf_Addr addr = 0, fn_addr = 0;
5539 if ((offset = dwarf_ranges(die, offset, &base, &addr, &end_addr)) >= 0)
5541 fn_addr = maybe_adjust_fn_sym_address(addr);
5548 }
while (offset > 0);
5566 get_function_address(
const Dwarf_Die* function_die, Dwarf_Addr& address)
const
5568 if (!die_address_attribute(
const_cast<Dwarf_Die*
>(function_die),
5569 DW_AT_low_pc, address))
5575 if (!get_first_exported_fn_address_from_DW_AT_ranges
5576 (
const_cast<Dwarf_Die*
>(function_die),
5580 address = maybe_adjust_fn_sym_address(address);
5599 get_variable_address(
const Dwarf_Die* variable_die,
5600 Dwarf_Addr& address)
const
5602 bool is_tls_address =
false;
5603 if (!die_location_address(
const_cast<Dwarf_Die*
>(variable_die),
5604 address, is_tls_address))
5606 if (!is_tls_address)
5607 address = maybe_adjust_var_sym_address(address);
5614 corpus::exported_decls_builder*
5615 exported_decls_builder()
5616 {
return corpus()->get_exported_decls_builder().get();}
5624 load_all_types()
const
5625 {
return options().load_all_types;}
5633 load_all_types(
bool f)
5634 {
options().load_all_types = f;}
5637 load_in_linux_kernel_mode()
const
5638 {
return options().load_in_linux_kernel_mode;}
5641 load_in_linux_kernel_mode(
bool f)
5642 {
options().load_in_linux_kernel_mode = f;}
5654 load_undefined_interfaces()
const
5665 leverage_dwarf_factorization()
const
5667 if (!leverage_dwarf_factorization_.has_value())
5669 if (
options().leverage_dwarf_factorization
5670 && elf_helpers::find_section_by_name(
elf_handle(),
5671 ".gnu_debugaltlink"))
5672 leverage_dwarf_factorization_ =
true;
5674 leverage_dwarf_factorization_ =
false;
5676 ABG_ASSERT(leverage_dwarf_factorization_.has_value());
5678 return *leverage_dwarf_factorization_;
5689 {
return options().show_stats;}
5738 build_die_parent_relations_under(Dwarf_Die* die,
5748 if (dwarf_child(die, &child) != 0)
5753 parent_of[dwarf_dieoffset(&child)] = dwarf_dieoffset(die);
5754 if (dwarf_tag(&child) == DW_TAG_imported_unit)
5756 Dwarf_Die imported_unit;
5757 if (die_die_attribute(&child, DW_AT_import, imported_unit)
5768 && die_has_children(&imported_unit))
5770 die_source imported_unit_die_source = NO_DEBUG_INFO_DIE_SOURCE;
5771 ABG_ASSERT(get_die_source(imported_unit, imported_unit_die_source));
5772 imported_units.push_back
5773 (imported_unit_point(dwarf_dieoffset(&child),
5775 imported_unit_die_source));
5778 build_die_parent_relations_under(&child, source, imported_units);
5780 while (dwarf_siblingof(&child, &child) == 0);
5812 case translation_unit::LANG_UNKNOWN:
5813#ifdef HAVE_DW_LANG_Mips_Assembler_enumerator
5814 case translation_unit::LANG_Mips_Assembler:
5841 build_die_parent_maps()
5843 bool we_do_have_to_build_die_parent_map =
false;
5844 uint8_t address_size = 0;
5845 size_t header_size = 0;
5850 for (Dwarf_Off offset = 0, next_offset = 0;
5852 offset, &next_offset, &header_size,
5853 NULL, NULL, &address_size, NULL, NULL, NULL) == 0);
5854 offset = next_offset)
5856 Dwarf_Off die_offset = offset + header_size;
5863 die_unsigned_constant_attribute(&cu, DW_AT_language, l);
5865 if (do_we_build_die_parent_maps(lang))
5866 we_do_have_to_build_die_parent_map =
true;
5869 if (!we_do_have_to_build_die_parent_map)
5874 die_source source = ALT_DEBUG_INFO_DIE_SOURCE;
5875 for (Dwarf_Off offset = 0, next_offset = 0;
5877 offset, &next_offset, &header_size,
5878 NULL, NULL, &address_size, NULL, NULL, NULL) == 0);
5879 offset = next_offset)
5881 Dwarf_Off die_offset = offset + header_size;
5889 tu_die_imported_unit_points_map(source)[die_offset] =
5891 build_die_parent_relations_under(&cu, source, imported_units);
5896 source = PRIMARY_DEBUG_INFO_DIE_SOURCE;
5899 for (Dwarf_Off offset = 0, next_offset = 0;
5901 offset, &next_offset, &header_size,
5902 NULL, NULL, &address_size, NULL, NULL, NULL) == 0);
5903 offset = next_offset)
5905 Dwarf_Off die_offset = offset + header_size;
5912 tu_die_imported_unit_points_map(source)[die_offset] =
5914 build_die_parent_relations_under(&cu, source, imported_units);
5919 source = TYPE_UNIT_DIE_SOURCE;
5922 uint64_t type_signature = 0;
5923 Dwarf_Off type_offset;
5924 for (Dwarf_Off offset = 0, next_offset = 0;
5926 offset, &next_offset, &header_size,
5927 NULL, NULL, &address_size, NULL,
5928 &type_signature, &type_offset) == 0);
5929 offset = next_offset)
5931 Dwarf_Off die_offset = offset + header_size;
5939 tu_die_imported_unit_points_map(source)[die_offset] =
5941 build_die_parent_relations_under(&cu, source, imported_units);
5956struct offset_pairs_stack_type
5973 offset_pairs_stack_type(
const reader& rdr)
5999 offset_pair_vector_type::iterator i;
6001 for (i = vect_.begin();i < vect_.end(); ++i)
6005 if (i != vect_.end())
6024 if (set_.find(p) == set_.end())
6051 bool result =
false;
6056 offset_pair_vector_type::const_iterator i;
6057 for (i = vect_.begin(); i != vect_.end(); ++i)
6061 if (i == vect_.end())
6066 for (++i; i != vect_.end(); ++i)
6068 pairs.push_back(*i);
6088 for (
auto type_pair : dependant_types)
6089 dependant_types_[type_pair].push_back(p);
6100 get_pairs_that_depend_on(p, dependant_types);
6103 auto it = redundant_types_.find(p);
6104 if (it == redundant_types_.end())
6106 auto entry = std::make_pair(p, dependant_types);
6107 redundant_types_.insert(entry);
6110 it->second.insert(it->second.end(),
6111 dependant_types.begin(),
6112 dependant_types.end());
6116 record_dependant_types(p, dependant_types);
6127 auto i = redundant_types_.find(p);
6128 if (i != redundant_types_.end())
6141 auto i = dependant_types_.find(p);
6142 if (i == dependant_types_.end())
6160 bool erase_cached_results =
false)
6164 auto redundant_type = redundant_types_.find(p);
6165 if (redundant_type != redundant_types_.end())
6167 for (
auto dependant_type : redundant_type->second)
6171 auto dependant_types_it = dependant_types_.find(dependant_type);
6172 ABG_ASSERT(dependant_types_it != dependant_types_.end());
6176 auto i = dependant_types_it->second.begin();
6177 for (; i!= dependant_types_it->second.end();++i)
6180 if (i != dependant_types_it->second.end())
6181 dependant_types_it->second.erase(i);
6186 if (dependant_types_it->second.empty())
6188 if (erase_cached_results)
6189 rdr_.die_comparison_results_.erase(dependant_type);
6190 dependant_types_.erase(dependant_types_it);
6194 if (erase_cached_results)
6195 rdr_.die_comparison_results_.erase(p);
6196 redundant_types_.erase(p);
6208 {erase_redundant_type_pair_entry(p,
true);}
6221 get_dependant_types(p, dependant_types,
true);
6222 for (
auto dependant_type : dependant_types)
6226 if (rdr_.propagated_types_.find(dependant_type)
6227 != rdr_.propagated_types_.end())
6229 rdr_.erase_canonical_die_offset(dependant_type.first.offset_,
6230 dependant_type.first.source_,
6232 rdr_.propagated_types_.erase(dependant_type);
6233 rdr_.cancelled_propagation_count_++;
6237 auto comp_result_it = rdr_.die_comparison_results_.find(dependant_type);
6238 if (comp_result_it != rdr_.die_comparison_results_.end())
6239 comp_result_it->second= COMPARISON_RESULT_DIFFERENT;
6243 auto comp_result_it = rdr_.die_comparison_results_.find(p);
6244 if (comp_result_it != rdr_.die_comparison_results_.end())
6251 if (comp_result_it->second == COMPARISON_RESULT_UNKNOWN)
6252 comp_result_it->second= COMPARISON_RESULT_DIFFERENT;
6253 ABG_ASSERT(comp_result_it->second == COMPARISON_RESULT_DIFFERENT);
6256 if (rdr_.propagated_types_.find(p) != rdr_.propagated_types_.end())
6258 rdr_.erase_canonical_die_offset(p.first.offset_,
6261 rdr_.propagated_types_.erase(p);
6262 rdr_.cancelled_propagation_count_++;
6281 bool transitive_closure =
false)
6283 auto i = redundant_types_.find(p);
6284 if (i != redundant_types_.end())
6286 for (
auto dependant_type : i->second)
6287 if (result.find(dependant_type) == result.end())
6289 result.insert(dependant_type);
6290 if (transitive_closure)
6291 get_dependant_types(p, result,
true);
6300build_ir_node_from_die(reader& rdr,
6303 bool called_from_public_decl,
6304 size_t where_offset,
6305 bool is_declaration_only =
true,
6306 bool is_required_decl_spec =
false);
6309build_ir_node_from_die(reader& rdr,
6311 bool called_from_public_decl,
6312 size_t where_offset);
6314static decl_base_sptr
6315build_ir_node_for_void_type(reader& rdr);
6318build_ir_node_for_void_pointer_type(reader& rdr);
6321add_or_update_class_type(reader& rdr,
6326 bool called_from_public_decl,
6327 size_t where_offset,
6328 bool is_declaration_only);
6330static union_decl_sptr
6331add_or_update_union_type(reader& rdr,
6334 union_decl_sptr union_type,
6335 bool called_from_public_decl,
6336 size_t where_offset,
6337 bool is_declaration_only);
6339static decl_base_sptr
6340build_ir_node_for_void_type(reader& rdr);
6342static decl_base_sptr
6343build_ir_node_for_variadic_parameter_type(reader &rdr);
6346build_function_decl(reader& rdr,
6348 size_t where_offset,
6352function_is_suppressed(
const reader& rdr,
6353 const scope_decl* scope,
6354 Dwarf_Die *function_die,
6355 bool is_declaration_only);
6358build_or_get_fn_decl_if_not_suppressed(reader& rdr,
6361 size_t where_offset,
6362 bool is_declaration_only,
6366build_var_decl(reader& rdr,
6368 size_t where_offset,
6372build_or_get_var_decl_if_not_suppressed(reader& rdr,
6375 size_t where_offset,
6376 bool is_declaration_only,
6378 bool is_required_decl_spec =
false);
6380variable_is_suppressed(
const reader& rdr,
6381 const scope_decl* scope,
6382 Dwarf_Die *variable_die,
6383 bool is_declaration_only,
6384 bool is_required_decl_spec =
false);
6387finish_member_function_reading(Dwarf_Die* die,
6389 const class_or_union_sptr klass,
6398die_is_anonymous(
const Dwarf_Die* die)
6400 Dwarf_Attribute attr;
6401 if (!dwarf_attr_integrate(
const_cast<Dwarf_Die*
>(die), DW_AT_name, &attr))
6415die_is_anonymous_data_member(
const Dwarf_Die* die)
6418 || dwarf_tag(
const_cast<Dwarf_Die*
>(die)) != DW_TAG_member
6419 || !die_name(die).empty())
6423 if (!die_die_attribute(die, DW_AT_type, type_die))
6426 if (dwarf_tag(&type_die) != DW_TAG_structure_type
6427 && dwarf_tag(&type_die) != DW_TAG_union_type)
6444die_string_attribute(
const Dwarf_Die* die,
unsigned attr_name)
6449 Dwarf_Attribute attr;
6450 if (!dwarf_attr_integrate(
const_cast<Dwarf_Die*
>(die), attr_name, &attr))
6453 const char* str = dwarf_formstring(&attr);
6454 return str ? str :
"";
6468die_char_str_attribute(
const Dwarf_Die* die,
unsigned attr_name)
6473 Dwarf_Attribute attr;
6474 if (!dwarf_attr_integrate(
const_cast<Dwarf_Die*
>(die), attr_name, &attr))
6477 const char* str = dwarf_formstring(&attr);
6497die_unsigned_constant_attribute(
const Dwarf_Die* die,
6504 Dwarf_Attribute attr;
6505 Dwarf_Word result = 0;
6506 if (!dwarf_attr_integrate(
const_cast<Dwarf_Die*
>(die), attr_name, &attr)
6507 || dwarf_formudata(&attr, &result))
6527die_signed_constant_attribute(
const Dwarf_Die *die,
6534 Dwarf_Attribute attr;
6535 Dwarf_Sword result = 0;
6536 if (!dwarf_attr_integrate(
const_cast<Dwarf_Die*
>(die), attr_name, &attr)
6537 || dwarf_formsdata(&attr, &result))
6563die_constant_attribute(
const Dwarf_Die *die,
6566 array_type_def::subrange_type::bound_value &value)
6571 if (!die_unsigned_constant_attribute(die, attr_name, l))
6573 value.set_unsigned(l);
6578 if (!die_signed_constant_attribute(die, attr_name, l))
6580 value.set_signed(l);
6595form_is_DW_FORM_strx(
unsigned form)
6599#if defined HAVE_DW_FORM_strx1 \
6600 && defined HAVE_DW_FORM_strx2 \
6601 && defined HAVE_DW_FORM_strx3 \
6602 && defined HAVE_DW_FORM_strx4
6603 if (form == DW_FORM_strx1
6604 || form == DW_FORM_strx2
6605 || form == DW_FORM_strx3
6606 ||form == DW_FORM_strx4)
6623form_is_DW_FORM_line_strp(
unsigned form)
6627#if defined HAVE_DW_FORM_line_strp
6628 if (form == DW_FORM_line_strp)
6655die_flag_attribute(
const Dwarf_Die* die,
6658 bool recursively =
true)
6660 Dwarf_Attribute attr;
6662 ? !dwarf_attr_integrate(
const_cast<Dwarf_Die*
>(die), attr_name, &attr)
6663 : !dwarf_attr(const_cast<Dwarf_Die*>(die), attr_name, &attr))
6667 if (dwarf_formflag(&attr, &f))
6681die_linkage_name(
const Dwarf_Die* die)
6686 string linkage_name = die_string_attribute(die, DW_AT_linkage_name);
6687 if (linkage_name.empty())
6688 linkage_name = die_string_attribute(die, DW_AT_MIPS_linkage_name);
6689 return linkage_name;
6703die_decl_file_attribute(
const Dwarf_Die* die)
6708 const char* str = dwarf_decl_file(
const_cast<Dwarf_Die*
>(die));
6710 return str ? str :
"";
6731die_die_attribute(
const Dwarf_Die* die,
6736 Dwarf_Attribute attr;
6738 ? !dwarf_attr_integrate(
const_cast<Dwarf_Die*
>(die), attr_name, &attr)
6739 : !dwarf_attr(const_cast<Dwarf_Die*>(die), attr_name, &attr))
6742 return dwarf_formref_die(&attr, &result);
6767die_origin_die(
const Dwarf_Die* die, Dwarf_Die& origin_die)
6769 if (die_die_attribute(die, DW_AT_specification, origin_die,
true)
6770 || die_die_attribute(die, DW_AT_abstract_origin, origin_die,
true))
6772 while (die_die_attribute(&origin_die,
6773 DW_AT_specification,
6775 || die_die_attribute(&origin_die,
6776 DW_AT_abstract_origin,
6814subrange_die_indirectly_references_subrange_die(
const Dwarf_Die *die,
6816 Dwarf_Die& referenced_subrange)
6818 bool result =
false;
6820 if (dwarf_tag(
const_cast<Dwarf_Die*
>(die)) != DW_TAG_subrange_type)
6823 Dwarf_Die referenced_die;
6824 if (die_die_attribute(die, attr_name, referenced_die))
6826 unsigned tag = dwarf_tag(&referenced_die);
6827 if ( tag == DW_TAG_member || tag == DW_TAG_variable)
6830 if (die_die_attribute(&referenced_die, DW_AT_type, type_die))
6832 tag = dwarf_tag(&type_die);
6833 if (tag == DW_TAG_subrange_type)
6835 memcpy(&referenced_subrange, &type_die,
sizeof(type_die));
6871subrange_die_indirect_bound_value(
const Dwarf_Die *die,
6873 array_type_def::subrange_type::bound_value& v,
6876 bool result =
false;
6878 if (dwarf_tag(
const_cast<Dwarf_Die*
>(die)) != DW_TAG_subrange_type)
6881 Dwarf_Die subrange_die;
6882 if (subrange_die_indirectly_references_subrange_die(die, attr_name,
6885 if (die_constant_attribute(&subrange_die, attr_name, is_signed, v))
6903die_address_attribute(Dwarf_Die* die,
unsigned attr_name, Dwarf_Addr& result)
6905 Dwarf_Attribute attr;
6906 if (!dwarf_attr_integrate(die, attr_name, &attr))
6908 return dwarf_formaddr(&attr, &result) == 0;
6919die_location(
const reader& rdr,
const Dwarf_Die* die)
6924 string file = die_decl_file_attribute(die);
6926 die_unsigned_constant_attribute(die, DW_AT_decl_line, line);
6928 if (!file.empty() && line != 0)
6931 location l = tu->get_loc_mgr().create_new_location(file, line, 1);
6943die_name(
const Dwarf_Die* die)
6945 string name = die_string_attribute(die, DW_AT_name);
6961die_loc_and_name(
const reader& rdr,
6965 string& linkage_name)
6967 loc = die_location(rdr, die);
6968 name = die_name(die);
6969 linkage_name = die_linkage_name(die);
6980die_name_and_linkage_name(
const Dwarf_Die* die,
6982 string& linkage_name)
6984 name = die_name(die);
6985 linkage_name = die_linkage_name(die);
6998die_size_in_bits(
const Dwarf_Die* die, uint64_t& size)
7003 uint64_t byte_size = 0, bit_size = 0;
7005 if (!die_unsigned_constant_attribute(die, DW_AT_byte_size, byte_size))
7007 if (!die_unsigned_constant_attribute(die, DW_AT_bit_size, bit_size))
7011 bit_size = byte_size * 8;
7034 if (!die_unsigned_constant_attribute(die, DW_AT_accessibility, a))
7041 case private_access:
7042 result = private_access;
7045 case protected_access:
7046 result = protected_access;
7050 result = public_access;
7069die_is_public_decl(
const Dwarf_Die* die)
7073 bool is_public =
false;
7079 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
7080 if (tag == DW_TAG_subprogram || tag == DW_TAG_variable)
7081 die_flag_attribute(die, DW_AT_external, is_public);
7082 else if (tag == DW_TAG_namespace)
7084 string name = die_name(die);
7085 is_public = !name.empty();
7099die_is_effectively_public_decl(
const reader& rdr,
7100 const Dwarf_Die* die)
7102 if (die_is_public_decl(die))
7105 unsigned tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
7106 if (tag == DW_TAG_variable || tag == DW_TAG_member)
7109 Dwarf_Die parent_die;
7110 size_t where_offset = 0;
7111 if (!get_parent_die(rdr, die, parent_die, where_offset))
7114 tag = dwarf_tag(&parent_die);
7115 if (tag == DW_TAG_compile_unit
7116 || tag == DW_TAG_partial_unit
7117 || tag == DW_TAG_type_unit)
7121 if (tag == DW_TAG_namespace)
7123 string name = die_name(&parent_die);
7142die_is_declaration_only(Dwarf_Die* die)
7144 bool is_declaration =
false;
7145 die_flag_attribute(die, DW_AT_declaration, is_declaration,
false);
7146 if (is_declaration && (!die_has_size_attribute(die)
7147 || !die_has_children(die)))
7158die_is_function_decl(
const Dwarf_Die *die)
7163 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
7164 if (tag == DW_TAG_subprogram)
7175die_is_variable_decl(
const Dwarf_Die *die)
7180 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
7181 if (tag == DW_TAG_variable)
7192die_has_size_attribute(
const Dwarf_Die *die)
7195 if (die_size_in_bits(die, s))
7206die_has_no_child(
const Dwarf_Die *die)
7212 if (dwarf_child(
const_cast<Dwarf_Die*
>(die), &child) == 0)
7225die_is_declaration_only(
const Dwarf_Die* die)
7226{
return die_is_declaration_only(
const_cast<Dwarf_Die*
>(die));}
7234die_is_artificial(Dwarf_Die* die)
7237 return die_flag_attribute(die, DW_AT_artificial, is_artificial);
7244is_type_tag(
unsigned tag)
7246 bool result =
false;
7250 case DW_TAG_array_type:
7251 case DW_TAG_class_type:
7252 case DW_TAG_enumeration_type:
7253 case DW_TAG_pointer_type:
7254 case DW_TAG_reference_type:
7255 case DW_TAG_string_type:
7256 case DW_TAG_structure_type:
7257 case DW_TAG_subroutine_type:
7258 case DW_TAG_typedef:
7259 case DW_TAG_union_type:
7260 case DW_TAG_ptr_to_member_type:
7261 case DW_TAG_set_type:
7262 case DW_TAG_subrange_type:
7263 case DW_TAG_base_type:
7264 case DW_TAG_const_type:
7265 case DW_TAG_file_type:
7266 case DW_TAG_packed_type:
7267 case DW_TAG_thrown_type:
7268 case DW_TAG_volatile_type:
7269 case DW_TAG_restrict_type:
7270 case DW_TAG_interface_type:
7271 case DW_TAG_unspecified_type:
7272 case DW_TAG_shared_type:
7273 case DW_TAG_rvalue_reference_type:
7274 case DW_TAG_coarray_type:
7275 case DW_TAG_atomic_type:
7276 case DW_TAG_immutable_type:
7299is_canon_type_to_be_propagated_tag(
unsigned tag)
7301 bool result =
false;
7305 case DW_TAG_class_type:
7306 case DW_TAG_structure_type:
7307 case DW_TAG_union_type:
7308 case DW_TAG_subroutine_type:
7309 case DW_TAG_subprogram:
7330type_comparison_result_to_be_cached(
unsigned tag)
7335 case DW_TAG_class_type:
7336 case DW_TAG_structure_type:
7337 case DW_TAG_union_type:
7338 case DW_TAG_subroutine_type:
7339 case DW_TAG_subprogram:
7360maybe_cache_type_comparison_result(
const reader& rdr,
7365 if (!type_comparison_result_to_be_cached(tag)
7366 || (result != COMPARISON_RESULT_EQUAL
7367 && result != COMPARISON_RESULT_DIFFERENT))
7370 rdr.die_comparison_results_[p] = result;
7390get_cached_type_comparison_result(
const reader& rdr,
7394 auto i = rdr.die_comparison_results_.find(p);
7395 if (i != rdr.die_comparison_results_.end())
7418maybe_get_cached_type_comparison_result(
const reader& rdr,
7423 if (type_comparison_result_to_be_cached(tag))
7428 if (get_cached_type_comparison_result(rdr, p, result))
7440is_type_die_to_be_canonicalized(
const Dwarf_Die *die)
7442 bool result =
false;
7443 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
7445 if (!is_type_tag(tag))
7450 case DW_TAG_class_type:
7451 case DW_TAG_structure_type:
7452 case DW_TAG_union_type:
7453 result = !die_is_declaration_only(die);
7456 case DW_TAG_subroutine_type:
7457 case DW_TAG_subprogram:
7458 case DW_TAG_array_type:
7474is_decl_tag(
unsigned tag)
7478 case DW_TAG_formal_parameter:
7479 case DW_TAG_imported_declaration:
7481 case DW_TAG_unspecified_parameters:
7482 case DW_TAG_subprogram:
7483 case DW_TAG_variable:
7484 case DW_TAG_namespace:
7485 case DW_TAG_GNU_template_template_param:
7486 case DW_TAG_GNU_template_parameter_pack:
7487 case DW_TAG_GNU_formal_parameter_pack:
7499die_is_type(
const Dwarf_Die* die)
7503 return is_type_tag(dwarf_tag(
const_cast<Dwarf_Die*
>(die)));
7512die_is_decl(
const Dwarf_Die* die)
7516 return is_decl_tag(dwarf_tag(
const_cast<Dwarf_Die*
>(die)));
7525die_is_namespace(
const Dwarf_Die* die)
7529 return (dwarf_tag(
const_cast<Dwarf_Die*
>(die)) == DW_TAG_namespace);
7538die_is_unspecified(Dwarf_Die* die)
7542 return (dwarf_tag(die) == DW_TAG_unspecified_type);
7551die_is_void_type(Dwarf_Die* die)
7553 if (!die || dwarf_tag(die) != DW_TAG_base_type)
7556 string name = die_name(die);
7569die_is_pointer_type(
const Dwarf_Die* die)
7574 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
7575 if (tag == DW_TAG_pointer_type)
7589pointer_or_qual_die_of_anonymous_class_type(
const Dwarf_Die* die)
7591 if (!die_is_pointer_array_or_reference_type(die)
7592 && !die_is_qualified_type(die))
7595 Dwarf_Die underlying_type_die;
7596 if (!die_die_attribute(die, DW_AT_type, underlying_type_die))
7599 if (!die_is_class_type(&underlying_type_die))
7602 string name = die_name(&underlying_type_die);
7604 return name.empty();
7613die_is_reference_type(
const Dwarf_Die* die)
7618 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
7619 if (tag == DW_TAG_reference_type || tag == DW_TAG_rvalue_reference_type)
7631die_is_array_type(
const Dwarf_Die* die)
7636 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
7637 if (tag == DW_TAG_array_type)
7649die_is_pointer_array_or_reference_type(
const Dwarf_Die* die)
7650{
return (die_is_pointer_type(die)
7651 || die_is_reference_type(die)
7652 || die_is_array_type(die));}
7660die_is_pointer_or_reference_type(
const Dwarf_Die* die)
7661{
return (die_is_pointer_type(die) || die_is_reference_type(die));}
7670die_is_pointer_reference_or_typedef_type(
const Dwarf_Die* die)
7671{
return (die_is_pointer_array_or_reference_type(die)
7672 || dwarf_tag(
const_cast<Dwarf_Die*
>(die)) == DW_TAG_typedef);}
7680die_is_class_type(
const Dwarf_Die* die)
7682 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
7684 if (tag == DW_TAG_class_type || tag == DW_TAG_structure_type)
7696die_is_qualified_type(
const Dwarf_Die* die)
7698 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
7699 if (tag == DW_TAG_const_type
7700 || tag == DW_TAG_volatile_type
7701 || tag == DW_TAG_restrict_type)
7713die_is_function_type(
const Dwarf_Die *die)
7715 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
7716 if (tag == DW_TAG_subprogram || tag == DW_TAG_subroutine_type)
7734die_has_object_pointer(
const Dwarf_Die* die, Dwarf_Die& object_pointer)
7739 if (die_die_attribute(die, DW_AT_object_pointer, object_pointer))
7751die_has_children(
const Dwarf_Die* die)
7757 if (dwarf_child(
const_cast<Dwarf_Die*
>(die), &child) == 0)
7777fn_die_first_parameter_die(
const Dwarf_Die* die, Dwarf_Die& first_parm_die)
7782 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
7783 ABG_ASSERT(tag == DW_TAG_subroutine_type || tag == DW_TAG_subprogram);
7786 if (dwarf_child(
const_cast<Dwarf_Die*
>(die), &child) == 0)
7788 int child_tag = dwarf_tag(&child);
7789 if (child_tag == DW_TAG_formal_parameter)
7791 memcpy(&first_parm_die, &child,
sizeof(Dwarf_Die));
7826member_fn_die_has_this_pointer(
const reader& rdr,
7827 const Dwarf_Die* die,
7828 size_t where_offset,
7829 Dwarf_Die& class_die,
7830 Dwarf_Die& object_pointer_die)
7835 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
7836 if (tag != DW_TAG_subprogram && tag != DW_TAG_subroutine_type)
7839 if (tag == DW_TAG_subprogram
7840 && !die_is_at_class_scope(rdr, die, where_offset, class_die))
7843 Dwarf_Die first_parm_die;
7844 Dwarf_Die parm_type_die;
7845 if (die_has_object_pointer(die, object_pointer_die))
7851 memcpy(&first_parm_die, &object_pointer_die,
sizeof(Dwarf_Die));
7852 if (!die_die_attribute(&first_parm_die, DW_AT_type, parm_type_die))
7854 die_peel_qual_ptr(&parm_type_die, parm_type_die);
7855 die_peel_typedef(&parm_type_die, parm_type_die);
7857 else if (fn_die_first_parameter_die(die, first_parm_die))
7859 memcpy(&object_pointer_die, &first_parm_die,
sizeof(Dwarf_Die));
7860 bool is_artificial =
false;
7861 if (die_flag_attribute(&first_parm_die, DW_AT_artificial, is_artificial))
7863 if (die_die_attribute(&first_parm_die, DW_AT_type, parm_type_die))
7865 tag = dwarf_tag(&parm_type_die);
7866 if (tag == DW_TAG_pointer_type)
7868 die_peel_qual_ptr(&parm_type_die, parm_type_die);
7869 die_peel_typedef(&parm_type_die, parm_type_die);
7883 tag = dwarf_tag(&parm_type_die);
7884 if (tag == DW_TAG_class_type || tag == DW_TAG_structure_type)
7886 memcpy(&class_die, &parm_type_die,
sizeof(Dwarf_Die));
7906die_this_pointer_from_object_pointer(Dwarf_Die* die,
7907 Dwarf_Die& this_pointer_die)
7910 ABG_ASSERT(dwarf_tag(die) == DW_TAG_formal_parameter);
7912 if (die_die_attribute(die, DW_AT_type, this_pointer_die))
7927die_this_pointer_is_const(Dwarf_Die* dye)
7932 memcpy(&die, dye,
sizeof(Dwarf_Die));
7933 if (dwarf_tag(&die) == DW_TAG_const_type)
7936 if (dwarf_tag(&die) == DW_TAG_pointer_type)
7938 Dwarf_Die pointed_to_type_die;
7939 if (die_die_attribute(&die, DW_AT_type, pointed_to_type_die))
7940 if (dwarf_tag(&pointed_to_type_die) == DW_TAG_const_type)
7956die_object_pointer_is_for_const_method(Dwarf_Die* die)
7959 ABG_ASSERT(dwarf_tag(die) == DW_TAG_formal_parameter);
7961 Dwarf_Die this_pointer_die;
7962 if (die_this_pointer_from_object_pointer(die, this_pointer_die))
7963 if (die_this_pointer_is_const(&this_pointer_die))
7985die_is_at_class_scope(
const reader& rdr,
7986 const Dwarf_Die* die,
7987 size_t where_offset,
7988 Dwarf_Die& class_scope_die)
7990 if (!get_scope_die(rdr, die, where_offset, class_scope_die))
7993 int tag = dwarf_tag(&class_scope_die);
7995 return (tag == DW_TAG_structure_type
7996 || tag == DW_TAG_class_type
7997 || tag == DW_TAG_union_type);
8010die_peel_qual_ptr(Dwarf_Die *die, Dwarf_Die& peeled_die)
8015 int tag = dwarf_tag(die);
8017 if (tag == DW_TAG_const_type
8018 || tag == DW_TAG_volatile_type
8019 || tag == DW_TAG_restrict_type
8020 || tag == DW_TAG_pointer_type
8021 || tag == DW_TAG_reference_type
8022 || tag == DW_TAG_rvalue_reference_type)
8024 if (!die_die_attribute(die, DW_AT_type, peeled_die))
8030 memcpy(&peeled_die, die,
sizeof(peeled_die));
8032 while (tag == DW_TAG_const_type
8033 || tag == DW_TAG_volatile_type
8034 || tag == DW_TAG_restrict_type
8035 || tag == DW_TAG_pointer_type
8036 || tag == DW_TAG_reference_type
8037 || tag == DW_TAG_rvalue_reference_type)
8039 if (!die_die_attribute(&peeled_die, DW_AT_type, peeled_die))
8041 tag = dwarf_tag(&peeled_die);
8056die_peel_qualified(Dwarf_Die *die, Dwarf_Die& peeled_die)
8061 memcpy(&peeled_die, die,
sizeof(peeled_die));
8063 int tag = dwarf_tag(&peeled_die);
8065 bool result =
false;
8066 while (tag == DW_TAG_const_type
8067 || tag == DW_TAG_volatile_type
8068 || tag == DW_TAG_restrict_type)
8070 if (!die_die_attribute(&peeled_die, DW_AT_type, peeled_die))
8072 tag = dwarf_tag(&peeled_die);
8088die_peel_typedef(Dwarf_Die *die, Dwarf_Die& peeled_die)
8093 int tag = dwarf_tag(die);
8095 memcpy(&peeled_die, die,
sizeof(peeled_die));
8097 if (tag == DW_TAG_typedef)
8099 if (!die_die_attribute(die, DW_AT_type, peeled_die))
8105 while (tag == DW_TAG_typedef)
8107 if (!die_die_attribute(&peeled_die, DW_AT_type, peeled_die))
8109 tag = dwarf_tag(&peeled_die);
8125die_peel_pointer_and_typedef(
const Dwarf_Die *die, Dwarf_Die& peeled_die)
8130 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
8132 if (tag == DW_TAG_pointer_type
8133 || tag == DW_TAG_reference_type
8134 || tag == DW_TAG_rvalue_reference_type
8135 || tag == DW_TAG_typedef)
8137 if (!die_die_attribute(die, DW_AT_type, peeled_die))
8143 while (tag == DW_TAG_pointer_type
8144 || tag == DW_TAG_reference_type
8145 || tag == DW_TAG_rvalue_reference_type
8146 || tag == DW_TAG_typedef)
8148 if (!die_die_attribute(&peeled_die, DW_AT_type, peeled_die))
8150 tag = dwarf_tag(&peeled_die);
8181die_function_type_is_method_type(
const reader& rdr,
8182 const Dwarf_Die *die,
8183 size_t where_offset,
8184 Dwarf_Die& object_pointer_die,
8185 Dwarf_Die& class_die,
8191 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
8192 ABG_ASSERT(tag == DW_TAG_subroutine_type || tag == DW_TAG_subprogram);
8194 if (member_fn_die_has_this_pointer(rdr, die, where_offset, class_die, object_pointer_die))
8199 else if (die_is_at_class_scope(rdr, die, where_offset, class_die))
8210 VIRTUALITY_NOT_VIRTUAL,
8212 VIRTUALITY_PURE_VIRTUAL
8225die_virtuality(
const Dwarf_Die* die, virtuality& virt)
8231 die_unsigned_constant_attribute(die, DW_AT_virtuality, v);
8233 if (v == DW_VIRTUALITY_virtual)
8234 virt = VIRTUALITY_VIRTUAL;
8235 else if (v == DW_VIRTUALITY_pure_virtual)
8236 virt = VIRTUALITY_PURE_VIRTUAL;
8238 virt = VIRTUALITY_NOT_VIRTUAL;
8250die_is_virtual(
const Dwarf_Die* die)
8253 if (!die_virtuality(die, v))
8256 return v == VIRTUALITY_PURE_VIRTUAL || v == VIRTUALITY_VIRTUAL;
8266die_is_declared_inline(Dwarf_Die* die)
8268 uint64_t inline_value = 0;
8269 if (!die_unsigned_constant_attribute(die, DW_AT_inline, inline_value))
8271 return (inline_value == DW_INL_declared_inlined
8272 || inline_value == DW_INL_declared_not_inlined);
8287slowly_compare_strings(
const Dwarf_Die *l,
8291 const char *l_str = die_char_str_attribute(l, attr_name),
8292 *r_str = die_char_str_attribute(r, attr_name);
8293 if (!l_str && !r_str)
8295 return l_str && r_str && !strcmp(l_str, r_str);
8321compare_dies_string_attribute_value(
const Dwarf_Die *l,
const Dwarf_Die *r,
8325 Dwarf_Attribute l_attr, r_attr;
8326 if (!dwarf_attr_integrate(
const_cast<Dwarf_Die*
>(l), attr_name, &l_attr)
8327 || !dwarf_attr_integrate(
const_cast<Dwarf_Die*
>(r), attr_name, &r_attr))
8331 || l_attr.form == DW_FORM_string
8332 || l_attr.form == DW_FORM_GNU_strp_alt
8333 || form_is_DW_FORM_strx(l_attr.form)
8334 || form_is_DW_FORM_line_strp(l_attr.form));
8337 || r_attr.form == DW_FORM_string
8338 || r_attr.form == DW_FORM_GNU_strp_alt
8339 || form_is_DW_FORM_strx(r_attr.form)
8340 || form_is_DW_FORM_line_strp(r_attr.form));
8342 if ((l_attr.form == DW_FORM_strp
8343 && r_attr.form == DW_FORM_strp)
8344 || (l_attr.form == DW_FORM_GNU_strp_alt
8345 && r_attr.form == DW_FORM_GNU_strp_alt)
8346 || (form_is_DW_FORM_strx(l_attr.form)
8347 && form_is_DW_FORM_strx(r_attr.form))
8348 || (form_is_DW_FORM_line_strp(l_attr.form)
8349 && form_is_DW_FORM_line_strp(r_attr.form)))
8356 if (l_attr.valp == r_attr.valp)
8358#if WITH_DEBUG_TYPE_CANONICALIZATION
8359 ABG_ASSERT(slowly_compare_strings(l, r, attr_name));
8370 result = slowly_compare_strings(l, r, attr_name);
8388compare_dies_cu_decl_file(
const Dwarf_Die* l,
const Dwarf_Die *r,
bool &result)
8390 Dwarf_Die l_cu, r_cu;
8391 if (!dwarf_diecu(
const_cast<Dwarf_Die*
>(l), &l_cu, 0, 0)
8392 ||!dwarf_diecu(
const_cast<Dwarf_Die*
>(r), &r_cu, 0, 0))
8396 compare_dies_string_attribute_value(&l_cu, &r_cu,
8399 if (compared && result)
8401 Dwarf_Die peeled_l, peeled_r;
8402 if (die_is_pointer_reference_or_typedef_type(l)
8403 && die_is_pointer_reference_or_typedef_type(r)
8404 && die_peel_pointer_and_typedef(l, peeled_l)
8405 && die_peel_pointer_and_typedef(r, peeled_r))
8407 if (!dwarf_diecu(&peeled_l, &l_cu, 0, 0)
8408 ||!dwarf_diecu(&peeled_r, &r_cu, 0, 0))
8411 compare_dies_string_attribute_value(&l_cu, &r_cu,
8442die_location_expr(
const Dwarf_Die* die,
8450 Dwarf_Attribute attr;
8451 if (!dwarf_attr_integrate(
const_cast<Dwarf_Die*
>(die), attr_name, &attr))
8455 bool result = (dwarf_getlocation(&attr, expr, &len) == 0);
8490op_pushes_constant_value(Dwarf_Op* ops,
8494 dwarf_expr_eval_context& ctxt)
8498 Dwarf_Op& op = ops[index];
8504 value = ops[index].number;
8517 value = ops[index].number;
8621 expr_result r(value);
8624 next_index = index + 1;
8654op_pushes_non_constant_value(Dwarf_Op* ops,
8658 dwarf_expr_eval_context& ctxt)
8661 Dwarf_Op& op = ops[index];
8697 next_index = index + 1;
8732 next_index = index + 1;
8736 next_index = index + 2;
8740 next_index = index + 1;
8744 next_index = index + 1;
8747 case DW_OP_GNU_variable_value:
8748 next_index = index + 1;
8755 expr_result r(
false);
8784op_manipulates_stack(Dwarf_Op* expr,
8788 dwarf_expr_eval_context& ctxt)
8790 Dwarf_Op& op = expr[index];
8796 v = ctxt.stack.front();
8801 v = ctxt.stack.front();
8820 ctxt.stack.erase(ctxt.stack.begin() + 1);
8827 ctxt.stack.erase(ctxt.stack.begin() + 2);
8832 case DW_OP_deref_size:
8840 case DW_OP_xderef_size:
8848 case DW_OP_push_object_address:
8853 case DW_OP_form_tls_address:
8854 case DW_OP_GNU_push_tls_address:
8857 if (op.atom == DW_OP_form_tls_address)
8862 case DW_OP_call_frame_cfa:
8874 if (op.atom == DW_OP_form_tls_address
8875 || op.atom == DW_OP_GNU_push_tls_address)
8876 ctxt.set_tls_address(
true);
8878 ctxt.set_tls_address(
false);
8880 next_index = index + 1;
8908op_is_arith_logic(Dwarf_Op* expr,
8912 dwarf_expr_eval_context& ctxt)
8916 Dwarf_Op& op = expr[index];
8917 expr_result val1, val2;
8918 bool result =
false;
8934 ctxt.push(val1 & val2);
8941 if (!val1.is_const())
8943 ctxt.push(val2 / val1);
8951 ctxt.push(val2 - val1);
8959 ctxt.push(val2 % val1);
8967 ctxt.push(val2 * val1);
8989 ctxt.push(val1 | val2);
8997 ctxt.push(val2 + val1);
9001 case DW_OP_plus_uconst:
9013 ctxt.push(val2 << val1);
9022 ctxt.push(val2 >> val1);
9030 ctxt.push(val2 ^ val1);
9040 if (ctxt.stack.front().is_const())
9041 ctxt.accum = ctxt.stack.front();
9043 next_index = index + 1;
9071op_is_control_flow(Dwarf_Op* expr,
9075 dwarf_expr_eval_context& ctxt)
9079 Dwarf_Op& op = expr[index];
9080 expr_result val1, val2;
9094 if (op.atom == DW_OP_eq)
9095 value = val2 == val1;
9096 else if (op.atom == DW_OP_ge)
9097 value = val2 >= val1;
9098 else if (op.atom == DW_OP_gt)
9099 value = val2 > val1;
9100 else if (op.atom == DW_OP_le)
9101 value = val2 <= val1;
9102 else if (op.atom == DW_OP_lt)
9103 value = val2 < val1;
9104 else if (op.atom == DW_OP_ne)
9105 value = val2 != val1;
9107 val1 = value ? 1 : 0;
9114 index += op.number - 1;
9119 if (val1.const_value() != 0)
9120 index += val1.const_value() - 1;
9125 case DW_OP_call_ref:
9133 if (ctxt.stack.front().is_const())
9134 ctxt.accum = ctxt.stack.front();
9136 next_index = index + 1;
9157eval_quickly(Dwarf_Op* expr,
9161 if (expr_len == 1 && (expr[0].atom == DW_OP_plus_uconst))
9163 value = expr[0].number;
9190eval_last_constant_dwarf_sub_expr(Dwarf_Op* expr,
9193 bool& is_tls_address,
9194 dwarf_expr_eval_context &eval_ctxt)
9200 size_t index = 0, next_index = 0;
9203 if (op_is_arith_logic(expr, expr_len, index,
9204 next_index, eval_ctxt)
9205 || op_pushes_constant_value(expr, expr_len, index,
9206 next_index, eval_ctxt)
9207 || op_manipulates_stack(expr, expr_len, index,
9208 next_index, eval_ctxt)
9209 || op_pushes_non_constant_value(expr, expr_len, index,
9210 next_index, eval_ctxt)
9211 || op_is_control_flow(expr, expr_len, index,
9212 next_index, eval_ctxt))
9215 next_index = index + 1;
9219 }
while (index < expr_len);
9221 is_tls_address = eval_ctxt.set_tls_address();
9222 if (eval_ctxt.accum.is_const())
9224 value = eval_ctxt.accum;
9244eval_last_constant_dwarf_sub_expr(Dwarf_Op* expr,
9247 bool& is_tls_address)
9249 dwarf_expr_eval_context eval_ctxt;
9250 return eval_last_constant_dwarf_sub_expr(expr, expr_len, value,
9251 is_tls_address, eval_ctxt);
9443read_and_convert_DW_at_bit_offset(
const Dwarf_Die* die,
9448 if (!die_unsigned_constant_attribute(die, DW_AT_bit_offset, off))
9461 uint64_t containing_anonymous_object_size = 0;
9462 ABG_ASSERT(die_unsigned_constant_attribute(die, DW_AT_byte_size,
9463 containing_anonymous_object_size));
9464 containing_anonymous_object_size *= 8;
9466 uint64_t bitfield_size = 0;
9467 ABG_ASSERT(die_unsigned_constant_attribute(die, DW_AT_bit_size,
9478 offset = containing_anonymous_object_size - off - bitfield_size;
9494die_constant_data_member_location(
const Dwarf_Die *die,
9500 Dwarf_Attribute attr;
9501 if (!dwarf_attr(
const_cast<Dwarf_Die*
>(die),
9502 DW_AT_data_member_location,
9507 if (dwarf_formudata(&attr, &val) != 0)
9563die_member_offset(
const reader& rdr,
9564 const Dwarf_Die* die,
9567 Dwarf_Op* expr = NULL;
9568 size_t expr_len = 0;
9569 uint64_t bit_offset = 0;
9573 if (die_unsigned_constant_attribute(die, DW_AT_data_bit_offset, bit_offset))
9575 offset = bit_offset;
9587 if (!die_constant_data_member_location(die, offset))
9592 if (!die_location_expr(die, DW_AT_data_member_location,
9599 if (!eval_quickly(expr, expr_len, offset))
9601 bool is_tls_address =
false;
9602 if (!eval_last_constant_dwarf_sub_expr(expr, expr_len,
9603 offset, is_tls_address,
9604 rdr.dwarf_expr_eval_ctxt()))
9622 if (read_and_convert_DW_at_bit_offset(die, is_big_endian, bit_offset))
9623 offset += bit_offset;
9640die_location_address(Dwarf_Die* die,
9641 Dwarf_Addr& address,
9642 bool& is_tls_address)
9644 Dwarf_Op* expr = NULL;
9645 size_t expr_len = 0;
9647 is_tls_address =
false;
9652 Dwarf_Attribute attr;
9653 if (!dwarf_attr_integrate(
const_cast<Dwarf_Die*
>(die), DW_AT_location, &attr))
9656 if (dwarf_getlocation(&attr, &expr, &expr_len))
9663 Dwarf_Attribute result;
9664 if (!dwarf_getlocation_attr(&attr, expr, &result))
9666 return !dwarf_formaddr(&result, &address);
9669 address = expr->number;
9684die_virtual_function_index(Dwarf_Die* die,
9690 Dwarf_Op* expr = NULL;
9691 size_t expr_len = 0;
9692 if (die_is_virtual(die))
9694 if (!die_location_expr(die, DW_AT_vtable_elem_location,
9699 bool is_tls_addr =
false;
9700 if (!eval_last_constant_dwarf_sub_expr(expr, expr_len, i, is_tls_addr))
9718 int tag = dwarf_tag(die);
9720 if (tag == DW_TAG_class_type
9721 || tag == DW_TAG_structure_type
9722 || tag == DW_TAG_union_type
9723 || tag == DW_TAG_enumeration_type)
9724 return die_is_anonymous(die);
9746get_internal_anonymous_die_prefix_name(
const Dwarf_Die *die)
9749 ABG_ASSERT(die_string_attribute(die, DW_AT_name) ==
"");
9751 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
9753 if (tag == DW_TAG_class_type || tag == DW_TAG_structure_type)
9755 else if (tag == DW_TAG_union_type)
9757 else if (tag == DW_TAG_enumeration_type)
9776build_internal_anonymous_die_name(
const string &base_name,
9777 size_t anonymous_type_index)
9779 string name = base_name;
9780 if (anonymous_type_index && !base_name.empty())
9782 std::ostringstream o;
9783 o << base_name << anonymous_type_index;
9812die_qualified_type_name(
const reader& rdr,
9813 const Dwarf_Die* die,
9814 size_t where_offset,
9815 unordered_set<uint64_t>& guard)
9820 int tag = dwarf_tag (
const_cast<Dwarf_Die*
>(die));
9821 if (tag == DW_TAG_compile_unit
9822 || tag == DW_TAG_partial_unit
9823 || tag == DW_TAG_type_unit)
9826 string name = die_name(die);
9828 Dwarf_Die scope_die;
9829 if (!get_scope_die(rdr, die, where_offset, scope_die))
9832 bool colon_colon = die_is_type(die) || die_is_namespace(die);
9833 string separator = colon_colon ?
"::" :
".";
9839 case DW_TAG_unspecified_type:
9842 case DW_TAG_base_type:
9852 case DW_TAG_typedef:
9856 case DW_TAG_enumeration_type:
9857 case DW_TAG_structure_type:
9858 case DW_TAG_class_type:
9859 case DW_TAG_union_type:
9861 if (die_is_anonymous(die))
9862 repr = die_class_or_enum_flat_representation(rdr, die,
"",
9865 where_offset, guard);
9868 string parent_name = die_qualified_name(rdr, &scope_die,
9869 where_offset, guard);
9870 repr = parent_name.empty() ? name : parent_name + separator + name;
9875 case DW_TAG_const_type:
9876 case DW_TAG_volatile_type:
9877 case DW_TAG_restrict_type:
9879 Dwarf_Die underlying_type_die;
9880 bool has_underlying_type_die =
9881 die_die_attribute(die, DW_AT_type, underlying_type_die);
9883 if (has_underlying_type_die && die_is_unspecified(&underlying_type_die))
9886 if (tag == DW_TAG_const_type)
9888 if (has_underlying_type_die
9889 && die_is_reference_type(&underlying_type_die))
9899 else if (!has_underlying_type_die
9900 || die_is_void_type(&underlying_type_die))
9908 else if (tag == DW_TAG_volatile_type)
9910 else if (tag == DW_TAG_restrict_type)
9915 string underlying_type_repr;
9916 if (has_underlying_type_die)
9917 underlying_type_repr =
9918 die_qualified_type_name(rdr, &underlying_type_die,
9919 where_offset, guard);
9921 underlying_type_repr =
"void";
9923 if (underlying_type_repr.empty())
9927 if (has_underlying_type_die)
9930 die_peel_qualified(&underlying_type_die, peeled);
9931 if (die_is_pointer_or_reference_type(&peeled))
9932 repr = underlying_type_repr +
" " + repr;
9934 repr +=
" " + underlying_type_repr;
9937 repr +=
" " + underlying_type_repr;
9942 case DW_TAG_pointer_type:
9943 case DW_TAG_reference_type:
9944 case DW_TAG_rvalue_reference_type:
9946 Dwarf_Die pointed_to_type_die;
9947 if (!die_die_attribute(die, DW_AT_type, pointed_to_type_die))
9949 if (tag == DW_TAG_pointer_type)
9954 if (die_is_unspecified(&pointed_to_type_die))
9957 string pointed_type_repr =
9958 die_qualified_type_name(rdr, &pointed_to_type_die,
9959 where_offset, guard);
9961 repr = pointed_type_repr;
9965 if (tag == DW_TAG_pointer_type)
9967 else if (tag == DW_TAG_reference_type)
9969 else if (tag == DW_TAG_rvalue_reference_type)
9976 case DW_TAG_subrange_type:
9989 build_subrange_type(
const_cast<reader&
>(rdr),
9992 repr += s->as_string();
9996 case DW_TAG_array_type:
9998 Dwarf_Die element_type_die;
9999 if (!die_die_attribute(die, DW_AT_type, element_type_die))
10001 string element_type_name =
10002 die_qualified_type_name(rdr, &element_type_die, where_offset, guard);
10003 if (element_type_name.empty())
10007 build_subranges_from_array_type_die(
const_cast<reader&
>(rdr),
10008 die, subranges, where_offset,
10011 repr = element_type_name;
10016 case DW_TAG_subroutine_type:
10017 case DW_TAG_subprogram:
10019 string return_type_name;
10021 vector<string> parm_names;
10022 bool is_const =
false;
10023 bool is_static =
false;
10025 die_return_and_parm_names_from_fn_type_die(rdr, die, where_offset,
10029 return_type_name, class_name,
10030 parm_names, is_const,
10032 if (return_type_name.empty())
10033 return_type_name =
"void";
10035 repr = return_type_name;
10039 repr +=
" (" + class_name +
"::*)";
10043 for (vector<string>::const_iterator i = parm_names.begin();
10044 i != parm_names.end();
10047 if (i != parm_names.begin())
10056 case DW_TAG_string_type:
10057 case DW_TAG_ptr_to_member_type:
10058 case DW_TAG_set_type:
10059 case DW_TAG_file_type:
10060 case DW_TAG_packed_type:
10061 case DW_TAG_thrown_type:
10062 case DW_TAG_interface_type:
10063 case DW_TAG_shared_type:
10089die_type_name(
const reader& rdr,
10090 const Dwarf_Die* die,
10091 bool qualified_name,
10092 size_t where_offset,
10093 unordered_set<uint64_t>& guard)
10098 int tag = dwarf_tag (
const_cast<Dwarf_Die*
>(die));
10099 if (tag == DW_TAG_compile_unit
10100 || tag == DW_TAG_partial_unit
10101 || tag == DW_TAG_type_unit)
10104 string name = die_name(die);
10106 Dwarf_Die scope_die;
10107 if (!get_scope_die(rdr, die, where_offset, scope_die))
10110 bool colon_colon = die_is_type(die) || die_is_namespace(die);
10111 string separator = colon_colon ?
"::" :
".";
10117 case DW_TAG_unspecified_type:
10120 case DW_TAG_base_type:
10130 case DW_TAG_typedef:
10134 case DW_TAG_enumeration_type:
10135 case DW_TAG_structure_type:
10136 case DW_TAG_class_type:
10137 case DW_TAG_union_type:
10139 if (die_is_anonymous(die))
10140 repr = die_class_or_enum_flat_representation(rdr, die,
"",
10147 string parent_name;
10148 if (qualified_name)
10151 parent_name = die_qualified_name(rdr, &scope_die,
10152 where_offset, guard);
10154 repr = parent_name.empty() ? name : parent_name + separator + name;
10159 case DW_TAG_const_type:
10160 case DW_TAG_volatile_type:
10161 case DW_TAG_restrict_type:
10163 Dwarf_Die underlying_type_die;
10164 bool has_underlying_type_die =
10165 die_die_attribute(die, DW_AT_type, underlying_type_die);
10167 if (has_underlying_type_die && die_is_unspecified(&underlying_type_die))
10170 if (tag == DW_TAG_const_type)
10172 if (has_underlying_type_die
10173 && die_is_reference_type(&underlying_type_die))
10183 else if (!has_underlying_type_die
10184 || die_is_void_type(&underlying_type_die))
10192 else if (tag == DW_TAG_volatile_type)
10194 else if (tag == DW_TAG_restrict_type)
10199 string underlying_type_repr;
10200 if (has_underlying_type_die)
10201 underlying_type_repr =
10202 die_type_name(rdr, &underlying_type_die,
10203 qualified_name, where_offset,
10206 underlying_type_repr =
"void";
10208 if (underlying_type_repr.empty())
10212 if (has_underlying_type_die)
10215 die_peel_qualified(&underlying_type_die, peeled);
10216 if (die_is_pointer_or_reference_type(&peeled))
10217 repr = underlying_type_repr +
" " + repr;
10219 repr +=
" " + underlying_type_repr;
10222 repr +=
" " + underlying_type_repr;
10227 case DW_TAG_pointer_type:
10228 case DW_TAG_reference_type:
10229 case DW_TAG_rvalue_reference_type:
10231 Dwarf_Die pointed_to_type_die;
10232 if (!die_die_attribute(die, DW_AT_type, pointed_to_type_die))
10234 if (tag == DW_TAG_pointer_type)
10239 if (die_is_unspecified(&pointed_to_type_die))
10242 string pointed_type_repr =
10243 die_type_name(rdr, &pointed_to_type_die,
10244 qualified_name, where_offset,
10247 repr = pointed_type_repr;
10251 if (tag == DW_TAG_pointer_type)
10253 else if (tag == DW_TAG_reference_type)
10255 else if (tag == DW_TAG_rvalue_reference_type)
10262 case DW_TAG_subrange_type:
10275 build_subrange_type(
const_cast<reader&
>(rdr),
10278 repr += s->as_string();
10282 case DW_TAG_array_type:
10284 Dwarf_Die element_type_die;
10285 if (!die_die_attribute(die, DW_AT_type, element_type_die))
10287 string element_type_name =
10288 die_type_name(rdr, &element_type_die,
10289 qualified_name, where_offset,
10291 if (element_type_name.empty())
10295 build_subranges_from_array_type_die(
const_cast<reader&
>(rdr),
10296 die, subranges, where_offset,
10299 repr = element_type_name;
10304 case DW_TAG_subroutine_type:
10305 case DW_TAG_subprogram:
10307 string return_type_name;
10309 vector<string> parm_names;
10310 bool is_const =
false;
10311 bool is_static =
false;
10313 die_return_and_parm_names_from_fn_type_die(rdr, die, where_offset,
10319 parm_names, is_const,
10321 if (return_type_name.empty())
10322 return_type_name =
"void";
10324 repr = return_type_name;
10329 repr +=
" (" + class_name +
"::*)";
10334 for (vector<string>::const_iterator i = parm_names.begin();
10335 i != parm_names.end();
10338 if (i != parm_names.begin())
10347 case DW_TAG_string_type:
10348 case DW_TAG_ptr_to_member_type:
10349 case DW_TAG_set_type:
10350 case DW_TAG_file_type:
10351 case DW_TAG_packed_type:
10352 case DW_TAG_thrown_type:
10353 case DW_TAG_interface_type:
10354 case DW_TAG_shared_type:
10375die_type_name(
const reader& rdr,
10376 const Dwarf_Die* die,
10377 bool qualified_name,
10378 size_t where_offset)
10380 unordered_set<uint64_t> guard;
10381 return die_type_name(rdr, die, qualified_name, where_offset, guard);
10402die_qualified_decl_name(
const reader& rdr,
10403 const Dwarf_Die* die,
10404 size_t where_offset,
10405 unordered_set<uint64_t>& guard)
10407 if (!die || !die_is_decl(die))
10410 string name = die_name(die);
10412 Dwarf_Die scope_die;
10413 if (!get_scope_die(rdr, die, where_offset, scope_die))
10416 string scope_name = die_qualified_name(rdr, &scope_die, where_offset, guard);
10417 string separator =
"::";
10421 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
10424 case DW_TAG_namespace:
10425 case DW_TAG_member:
10426 case DW_TAG_variable:
10427 repr = scope_name.empty() ? name : scope_name + separator + name;
10429 case DW_TAG_subprogram:
10430 repr = die_function_signature(rdr, die,
10432 where_offset, guard);
10435 case DW_TAG_unspecified_parameters:
10439 case DW_TAG_formal_parameter:
10440 case DW_TAG_imported_declaration:
10441 case DW_TAG_GNU_template_template_param:
10442 case DW_TAG_GNU_template_parameter_pack:
10443 case DW_TAG_GNU_formal_parameter_pack:
10471die_qualified_name(
const reader& rdr,
const Dwarf_Die* die,
10472 size_t where, unordered_set<uint64_t>& guard)
10474 if (die_is_type(die))
10475 return die_qualified_type_name(rdr, die, where, guard);
10476 else if (die_is_decl(die))
10477 return die_qualified_decl_name(rdr, die, where, guard);
10498die_qualified_name(
const reader& rdr,
const Dwarf_Die* die,
size_t where)
10500 unordered_set<uint64_t> guard;
10501 return die_qualified_name(rdr, die, where, guard);
10527die_qualified_type_name_empty(
const reader& rdr,
10528 const Dwarf_Die* die,
10529 size_t where,
string &qualified_name,
10530 unordered_set<uint64_t>& guard)
10535 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
10538 if (tag == DW_TAG_typedef
10539 || tag == DW_TAG_pointer_type
10540 || tag == DW_TAG_reference_type
10541 || tag == DW_TAG_rvalue_reference_type
10542 || tag == DW_TAG_array_type
10543 || tag == DW_TAG_const_type
10544 || tag == DW_TAG_volatile_type
10545 || tag == DW_TAG_restrict_type)
10547 Dwarf_Die underlying_type_die;
10548 if (die_die_attribute(die, DW_AT_type, underlying_type_die))
10551 die_qualified_type_name(rdr, &underlying_type_die, where, guard);
10558 string name = die_qualified_type_name(rdr, die, where, guard);
10563 qname = die_qualified_type_name(rdr, die, where, guard);
10567 qualified_name = qname;
10619die_return_and_parm_names_from_fn_type_die(
const reader& rdr,
10620 const Dwarf_Die* die,
10621 size_t where_offset,
10623 bool qualified_name,
10625 string &return_type_name,
10626 string &class_name,
10627 vector<string>& parm_names,
10630 unordered_set<uint64_t>& guard)
10632 uint64_t off = dwarf_dieoffset(
const_cast<Dwarf_Die*
>(die));
10633 if (guard.find(off) != guard.end())
10638 Dwarf_Die ret_type_die;
10639 if (!die_die_attribute(die, DW_AT_type, ret_type_die))
10640 return_type_name =
"void";
10645 ? rdr.get_die_pretty_representation(&ret_type_die, where_offset, guard)
10646 : die_type_name(rdr, &ret_type_die, qualified_name,
10647 where_offset, guard);
10650 if (return_type_name.empty())
10651 return_type_name =
"void";
10653 Dwarf_Die object_pointer_die, class_die;
10655 die_function_type_is_method_type(rdr, die, where_offset,
10656 object_pointer_die,
10657 class_die, is_static);
10663 class_name = die_type_name(rdr, &class_die, qualified_name,
10664 where_offset, guard);
10666 Dwarf_Die this_pointer_die;
10667 Dwarf_Die pointed_to_die;
10669 && die_die_attribute(&object_pointer_die, DW_AT_type,
10671 if (die_die_attribute(&this_pointer_die, DW_AT_type, pointed_to_die))
10672 if (dwarf_tag(&pointed_to_die) == DW_TAG_const_type)
10675 string fn_name = die_name(die);
10676 string non_qualified_class_name = die_name(&class_die);
10677 bool is_ctor = fn_name == non_qualified_class_name;
10678 bool is_dtor = !fn_name.empty() && fn_name[0] ==
'~';
10680 if (is_ctor || is_dtor)
10681 return_type_name.clear();
10684 if (dwarf_child(
const_cast<Dwarf_Die*
>(die), &child) == 0)
10687 int child_tag = dwarf_tag(&child);
10688 bool first_parm =
true;
10689 if (child_tag == DW_TAG_formal_parameter)
10694 first_parm =
false;
10698 Dwarf_Die parm_type_die;
10699 if (!die_die_attribute(&child, DW_AT_type, parm_type_die))
10703 ? rdr.get_die_pretty_representation(&parm_type_die,
10704 where_offset, guard)
10705 : die_type_name(rdr, &parm_type_die,
10706 qualified_name, where_offset, guard);
10710 parm_names.push_back(qname);
10712 else if (child_tag == DW_TAG_unspecified_parameters)
10715 parm_names.push_back(rdr.env().get_variadic_parameter_type_name());
10725 while (dwarf_siblingof(&child, &child) == 0);
10727 if (class_name.empty())
10729 Dwarf_Die parent_die;
10730 if (get_parent_die(rdr, die, parent_die, where_offset))
10732 if (die_is_class_type(&parent_die)
10734 class_name = die_type_name(rdr, &parent_die,
10764die_function_signature(
const reader& rdr,
10765 const Dwarf_Die *fn_die,
10766 bool qualified_name,
10767 size_t where_offset,
10768 unordered_set<uint64_t>& guard)
10772 bool has_lang =
false;
10773 if ((has_lang = get_die_language(fn_die, lang)))
10781 string fn_name = die_linkage_name(fn_die);
10782 if (fn_name.empty())
10783 fn_name = die_name(fn_die);
10793 string return_type_name;
10794 Dwarf_Die ret_type_die;
10795 if (die_die_attribute(fn_die, DW_AT_type, ret_type_die))
10796 return_type_name = rdr.get_die_qualified_type_name(&ret_type_die,
10800 if (return_type_name.empty())
10801 return_type_name =
"void";
10803 Dwarf_Die scope_die;
10805 if (qualified_name && get_scope_die(rdr, fn_die, where_offset, scope_die))
10806 scope_name = rdr.get_die_qualified_name(&scope_die, where_offset, guard);
10807 string fn_name = die_name(fn_die);
10808 if (!scope_name.empty())
10809 fn_name = scope_name +
"::" + fn_name;
10812 vector<string> parm_names;
10813 bool is_const =
false;
10814 bool is_static =
false;
10817 die_return_and_parm_names_from_fn_type_die(rdr, fn_die, where_offset,
10820 return_type_name, class_name,
10821 parm_names, is_const, is_static,
10824 bool is_virtual = die_is_virtual(fn_die);
10828 repr +=
" virtual";
10830 if (!return_type_name.empty())
10831 repr +=
" " + return_type_name;
10833 repr +=
" " + fn_name;
10837 bool some_parm_emitted =
false;
10838 for (vector<string>::const_iterator i = parm_names.begin();
10839 i != parm_names.end();
10842 if (i != parm_names.begin())
10844 if (some_parm_emitted)
10853 some_parm_emitted =
true;
10898die_class_flat_representation(
const reader& rdr,
10899 const Dwarf_Die* die,
10900 const string& indent,
10902 bool qualified_names,
10903 size_t where_offset,
10904 unordered_set<uint64_t>& guard)
10906 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
10908 string repr = indent;
10909 string local_indent =
" ";
10910 string real_indent;
10912 if (tag == DW_TAG_union_type)
10914 else if (tag == DW_TAG_structure_type)
10916 else if (tag == DW_TAG_class_type)
10923 if (die_is_anonymous(die))
10925 uint64_t off = dwarf_dieoffset(
const_cast<Dwarf_Die*
>(die));
10926 if (guard.find(off) != guard.end())
10934 if (!die_is_anonymous(die))
10935 repr += die_qualified_name(rdr, die, where_offset, guard);
10942 Dwarf_Die member_child_die;
10943 bool first_sibling =
true;
10944 for (
bool got_it = get_member_child_die(die, &member_child_die);
10946 got_it = get_next_member_sibling_die(&member_child_die,
10947 &member_child_die),
10948 first_sibling =
false)
10952 if (!die_is_decl(&member_child_die)
10953 && !(die_is_type(&member_child_die)
10954 && die_is_anonymous(&member_child_die)))
10958 real_indent = first_sibling ?
"" :
" " ;
10960 real_indent = (first_sibling ?
"":
"\n") + indent + local_indent;
10962 repr += real_indent;
10964 repr += die_pretty_print_decl(rdr, &member_child_die,
10975 repr += indent +
"}";
10977 if (die_is_anonymous(die))
10979 uint64_t off = dwarf_dieoffset(
const_cast<Dwarf_Die*
>(die));
11011die_enum_flat_representation(
const reader& rdr,
11012 const Dwarf_Die* die,
11013 const string& indent,
11015 bool qualified_names,
11016 size_t where_offset)
11018 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
11020 std::ostringstream o;
11021 string local_indent =
" ";
11022 string real_indent;
11024 if (tag == DW_TAG_enumeration_type)
11031 if (!die_is_anonymous(die))
11032 o << (qualified_names
11033 ? die_qualified_name(rdr, die, where_offset)
11043 bool first_enumerator=
true;
11044 if (dwarf_child(
const_cast<Dwarf_Die*
>(die), &child) == 0)
11048 if (dwarf_tag(&child) != DW_TAG_enumerator)
11053 die_loc_and_name(rdr, &child, l, name, m);
11055 die_unsigned_constant_attribute(&child, DW_AT_const_value, val);
11058 real_indent = first_enumerator ?
"" :
", ";
11060 real_indent = first_enumerator ?
"" :
",\n" + indent + local_indent;
11061 o << name +
" = " << val;
11062 first_enumerator =
false;
11064 while (dwarf_siblingof(&child, &child) == 0);
11108die_class_or_enum_flat_representation(
const reader& rdr,
11109 const Dwarf_Die* die,
11110 const string& indent,
11112 bool qualified_names,
11113 size_t where_offset,
11114 unordered_set<uint64_t>& guard)
11120 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
11124 case DW_TAG_class_type:
11125 case DW_TAG_structure_type:
11126 case DW_TAG_union_type:
11127 result = die_class_flat_representation(rdr, die, indent,
11128 one_line, qualified_names,
11132 case DW_TAG_enumeration_type:
11133 result = die_enum_flat_representation(rdr, die, indent,
11134 one_line, qualified_names,
11171die_class_or_enum_flat_representation(
const reader& rdr,
11172 const Dwarf_Die* die,
11173 const string& indent,
11175 bool qualified_names,
11176 size_t where_offset)
11178 unordered_set<uint64_t> guard;
11179 return die_class_or_enum_flat_representation(rdr, die, indent,
11180 one_line, qualified_names,
11181 where_offset, guard);
11207die_pretty_print_type(
const reader& rdr,
11208 const Dwarf_Die* die,
11209 size_t where_offset,
11210 unordered_set<uint64_t>& guard)
11213 || (!die_is_type(die)
11214 && dwarf_tag(
const_cast<Dwarf_Die*
>(die)) != DW_TAG_subprogram))
11219 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
11222 case DW_TAG_string_type:
11231 repr =
"string type";
11233 case DW_TAG_unspecified_type:
11234 case DW_TAG_ptr_to_member_type:
11237 case DW_TAG_namespace:
11238 repr =
"namespace " + rdr.get_die_qualified_type_name(die, where_offset,
11242 case DW_TAG_base_type:
11243 repr = rdr.get_die_qualified_type_name(die, where_offset, guard);
11246 case DW_TAG_typedef:
11248 string qualified_name;
11249 if (!die_qualified_type_name_empty(rdr, die,
11253 repr =
"typedef " + qualified_name;
11257 case DW_TAG_const_type:
11258 case DW_TAG_volatile_type:
11259 case DW_TAG_restrict_type:
11260 case DW_TAG_pointer_type:
11261 case DW_TAG_reference_type:
11262 case DW_TAG_rvalue_reference_type:
11263 repr = rdr.get_die_qualified_type_name(die, where_offset, guard);
11266 case DW_TAG_enumeration_type:
11268 string qualified_name =
11269 rdr.get_die_qualified_type_name(die, where_offset, guard);
11270 repr =
"enum " + qualified_name;
11274 case DW_TAG_structure_type:
11275 case DW_TAG_class_type:
11277 string qualified_name =
11278 rdr.get_die_qualified_type_name(die, where_offset, guard);
11279 repr =
"class " + qualified_name;
11283 case DW_TAG_union_type:
11285 string qualified_name =
11286 rdr.get_die_qualified_type_name(die, where_offset, guard);
11287 repr =
"union " + qualified_name;
11291 case DW_TAG_array_type:
11293 Dwarf_Die element_type_die;
11294 if (!die_die_attribute(die, DW_AT_type, element_type_die))
11296 string element_type_name =
11297 rdr.get_die_qualified_type_name(&element_type_die,
11298 where_offset, guard);
11299 if (element_type_name.empty())
11303 build_subranges_from_array_type_die(rdr, die, subranges, where_offset,
11306 repr = element_type_name;
11311 case DW_TAG_subrange_type:
11321 repr += die_qualified_type_name(rdr, die, where_offset, guard);
11325 case DW_TAG_subroutine_type:
11326 case DW_TAG_subprogram:
11328 string return_type_name;
11330 vector<string> parm_names;
11331 bool is_const =
false;
11332 bool is_static =
false;
11334 die_return_and_parm_names_from_fn_type_die(rdr, die, where_offset,
11338 return_type_name, class_name,
11339 parm_names, is_const,
11342 repr =
"function type";
11344 repr =
"method type";
11345 repr +=
" " + rdr.get_die_qualified_type_name(die, where_offset, guard);
11349 case DW_TAG_set_type:
11350 case DW_TAG_file_type:
11351 case DW_TAG_packed_type:
11352 case DW_TAG_thrown_type:
11353 case DW_TAG_interface_type:
11354 case DW_TAG_shared_type:
11387die_pretty_print_decl(
const reader& rdr,
11388 const Dwarf_Die* die,
11389 bool qualified_name,
11391 size_t where_offset,
11392 unordered_set<uint64_t>& guard)
11394 if (!die || !die_is_decl(die))
11399 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
11402 case DW_TAG_namespace:
11403 repr =
"namespace " + die_qualified_name(rdr, die, where_offset, guard);
11406 case DW_TAG_member:
11407 case DW_TAG_variable:
11409 string type_repr =
"void";
11410 Dwarf_Die type_die;
11411 if (die_die_attribute(die, DW_AT_type, type_die))
11412 type_repr = die_type_name(rdr, &type_die,
11416 repr = (qualified_name
11417 ? die_qualified_name(rdr, die, where_offset, guard)
11423 repr = type_repr +
" " + repr;
11427 case DW_TAG_subprogram:
11429 repr = die_function_signature(rdr, die, qualified_name,
11430 where_offset, guard);
11461die_pretty_print(reader& rdr,
const Dwarf_Die* die,
size_t where_offset,
11462 unordered_set<uint64_t>& guard)
11464 if (die_is_type(die))
11465 return die_pretty_print_type(rdr, die, where_offset, guard);
11466 else if (die_is_decl(die))
11467 return die_pretty_print_decl(rdr, die,
11470 where_offset, guard);
11493compare_as_decl_dies(
const Dwarf_Die *l,
const Dwarf_Die *r)
11497 int l_tag = dwarf_tag(
const_cast<Dwarf_Die*
>(l));
11498 int r_tag = dwarf_tag(
const_cast<Dwarf_Die*
>(r));
11499 if (l_tag != r_tag)
11502 bool result =
false;
11504 if (l_tag == DW_TAG_subprogram || l_tag == DW_TAG_variable)
11507 if (compare_dies_string_attribute_value(l, r, DW_AT_linkage_name,
11509 || compare_dies_string_attribute_value(l, r, DW_AT_MIPS_linkage_name,
11516 if (compare_dies_string_attribute_value(l, r, DW_AT_name,
11526 if (compare_dies_string_attribute_value(l, r, DW_AT_name,
11543at_least_one_decl_only_among_odr_relevant_dies(
const reader &rdr,
11544 const Dwarf_Die *l,
11545 const Dwarf_Die *r)
11547 if (!(rdr.odr_is_relevant(l) && rdr.odr_is_relevant(r)))
11550 if ((die_is_declaration_only(l) && die_has_no_child(l))
11551 || (die_is_declaration_only(r) && die_has_no_child(r)))
11578compare_as_type_dies(
const reader& rdr,
11579 const Dwarf_Die *l,
11580 const Dwarf_Die *r)
11586 if (dwarf_tag(
const_cast<Dwarf_Die*
>(l)) == DW_TAG_string_type
11587 && dwarf_tag(
const_cast<Dwarf_Die*
>(r)) == DW_TAG_string_type
11588 && (dwarf_dieoffset(
const_cast<Dwarf_Die*
>(l))
11589 != dwarf_dieoffset(
const_cast<Dwarf_Die*
>(r))))
11597 if (at_least_one_decl_only_among_odr_relevant_dies(rdr, l, r))
11602 uint64_t l_size = 0, r_size = 0;
11603 die_size_in_bits(l, l_size);
11604 die_size_in_bits(r, r_size);
11606 return l_size == r_size;
11621compare_as_decl_and_type_dies(
const reader &rdr,
11622 const Dwarf_Die *l,
11623 const Dwarf_Die *r)
11625 if (!compare_as_decl_dies(l, r)
11626 || !compare_as_type_dies(rdr, l, r))
11648fn_die_equal_by_linkage_name(
const Dwarf_Die *l,
11649 const Dwarf_Die *r)
11657 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(l));
11659 tag = dwarf_tag(
const_cast<Dwarf_Die*
>(r));
11662 string lname = die_name(l), rname = die_name(r);
11663 string llinkage_name = die_linkage_name(l),
11664 rlinkage_name = die_linkage_name(r);
11666 if (die_is_in_c_or_cplusplus(l)
11667 && die_is_in_c_or_cplusplus(r))
11669 if (!llinkage_name.empty() && !rlinkage_name.empty())
11670 return llinkage_name == rlinkage_name;
11671 else if (!!llinkage_name.empty() != !!rlinkage_name.empty())
11674 return lname == rname;
11677 return (!llinkage_name.empty()
11678 && !rlinkage_name.empty()
11679 && llinkage_name == rlinkage_name);
11711try_canonical_die_comparison(
const reader& rdr,
11712 Dwarf_Off l_offset, Dwarf_Off r_offset,
11714 bool& l_has_canonical_die_offset,
11715 bool& r_has_canonical_die_offset,
11716 Dwarf_Off& l_canonical_die_offset,
11717 Dwarf_Off& r_canonical_die_offset,
11720#ifdef WITH_DEBUG_TYPE_CANONICALIZATION
11721 if (rdr.debug_die_canonicalization_is_on_
11722 && !rdr.use_canonical_die_comparison_)
11727 l_has_canonical_die_offset =
11728 (l_canonical_die_offset =
11729 rdr.get_canonical_die_offset(l_offset, l_die_source,
11732 r_has_canonical_die_offset =
11733 (r_canonical_die_offset =
11734 rdr.get_canonical_die_offset(r_offset, r_die_source,
11737 if (l_has_canonical_die_offset && r_has_canonical_die_offset)
11739 result = (l_canonical_die_offset == r_canonical_die_offset);
11746#ifdef WITH_DEBUG_TYPE_CANONICALIZATION
11759notify_die_comparison_failed(
const Dwarf_Die* ,
const Dwarf_Die* )
11763#define NOTIFY_DIE_COMPARISON_FAILED(l, r) \
11764 notify_die_comparison_failed(l, r)
11766#define NOTIFY_DIE_COMPARISON_FAILED(l, r)
11779#define ABG_RETURN(value) \
11782 if ((value) == COMPARISON_RESULT_DIFFERENT) \
11784 NOTIFY_DIE_COMPARISON_FAILED(l, r); \
11786 return return_comparison_result(l, r, dies_being_compared, \
11787 value, aggregates_being_compared, \
11788 update_canonical_dies_on_the_fly); \
11799#define ABG_RETURN_FALSE \
11802 NOTIFY_DIE_COMPARISON_FAILED(l, r); \
11803 return return_comparison_result(l, r, dies_being_compared, \
11804 COMPARISON_RESULT_DIFFERENT, \
11805 aggregates_being_compared, \
11806 update_canonical_dies_on_the_fly); \
11821#define SET_RESULT_TO_FALSE(result, l , r) \
11824 result = COMPARISON_RESULT_DIFFERENT; \
11825 NOTIFY_DIE_COMPARISON_FAILED(l, r); \
11841#define SET_RESULT_TO(result, value, l , r) \
11844 result = (value); \
11845 if (result == COMPARISON_RESULT_DIFFERENT) \
11847 NOTIFY_DIE_COMPARISON_FAILED(l, r); \
11851#define RETURN_IF_COMPARISON_CYCLE_DETECTED \
11854 if (aggregates_being_compared.contains(dies_being_compared)) \
11856 result = COMPARISON_RESULT_CYCLE_DETECTED; \
11857 aggregates_being_compared.record_redundant_type_die_pair(dies_being_compared); \
11858 ABG_RETURN(result); \
11873get_next_member_sibling_die(
const Dwarf_Die *die, Dwarf_Die *member)
11878 bool found_member =
false;
11879 for (found_member = (dwarf_siblingof(
const_cast<Dwarf_Die*
>(die),
11882 found_member = (dwarf_siblingof(member, member) == 0))
11884 int tag = dwarf_tag(member);
11885 if (tag == DW_TAG_member || tag == DW_TAG_inheritance)
11889 return found_member;
11906get_member_child_die(
const Dwarf_Die *die, Dwarf_Die *child)
11911 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
11913 || tag == DW_TAG_union_type
11914 || tag == DW_TAG_class_type);
11916 bool found_child = (dwarf_child(
const_cast<Dwarf_Die*
>(die), child) == 0);
11921 tag = dwarf_tag(child);
11923 if (!(tag == DW_TAG_member
11924 || tag == DW_TAG_inheritance
11925 || tag == DW_TAG_subprogram))
11926 found_child = get_next_member_sibling_die(child, child);
11928 return found_child;
11951maybe_propagate_canonical_type(
const reader& rdr,
11952 const Dwarf_Die* l,
11953 const Dwarf_Die* r)
11955 int l_tag = dwarf_tag(
const_cast<Dwarf_Die*
>(l)),
11956 r_tag = dwarf_tag(
const_cast<Dwarf_Die*
>(r));
11958 if (l_tag != r_tag)
11961 if (is_canon_type_to_be_propagated_tag(l_tag))
11962 propagate_canonical_type(rdr, l, r);
11980propagate_canonical_type(
const reader& rdr,
11981 const Dwarf_Die* l,
11982 const Dwarf_Die* r)
11991 const die_source l_source = rdr.get_die_source(l);
11992 const die_source r_source = rdr.get_die_source(r);
11994 Dwarf_Off l_offset = dwarf_dieoffset(
const_cast<Dwarf_Die*
>(l));
11995 Dwarf_Off r_offset = dwarf_dieoffset(
const_cast<Dwarf_Die*
>(r));
11996 bool l_has_canonical_die_offset =
false;
11997 bool r_has_canonical_die_offset =
false;
11998 Dwarf_Off l_canonical_die_offset = 0;
11999 Dwarf_Off r_canonical_die_offset = 0;
12001 l_has_canonical_die_offset =
12002 (l_canonical_die_offset =
12003 rdr.get_canonical_die_offset(l_offset, l_source,
12006 r_has_canonical_die_offset =
12007 (r_canonical_die_offset =
12008 rdr.get_canonical_die_offset(r_offset, r_source,
12012 if (!l_has_canonical_die_offset
12013 && r_has_canonical_die_offset
12016 && l_source == r_source)
12019 rdr.set_canonical_die_offset(l, r_canonical_die_offset,
12021 offset_type l_off = {l_source, l_offset}, r_off = {r_source, r_offset};
12022 rdr.propagated_types_.insert(std::make_pair(l_off,r_off));
12023 rdr.canonical_propagated_count_++;
12061return_comparison_result(
const Dwarf_Die* l,
12062 const Dwarf_Die* r,
12065 offset_pairs_stack_type& comparison_stack,
12066 bool do_propagate_canonical_type =
true)
12068 int l_tag = dwarf_tag(
const_cast<Dwarf_Die*
>(l));
12070 if (result == COMPARISON_RESULT_EQUAL)
12075 if (do_propagate_canonical_type)
12078 maybe_propagate_canonical_type(comparison_stack.rdr_, l, r);
12084 else if (result == COMPARISON_RESULT_CYCLE_DETECTED)
12097 else if (result == COMPARISON_RESULT_UNKNOWN)
12138 if (comparison_stack.is_redundant(cur_dies)
12139 && comparison_stack.vect_.back() == cur_dies)
12143 maybe_propagate_canonical_type(comparison_stack.rdr_, l, r);
12144 comparison_stack.confirm_canonical_propagated_type(cur_dies);
12146 result = COMPARISON_RESULT_EQUAL;
12148 else if (is_canon_type_to_be_propagated_tag(l_tag)
12149 && comparison_stack.vect_.back() == cur_dies)
12154 ABG_ASSERT(comparison_stack.depends_on_redundant_types(cur_dies));
12155 maybe_propagate_canonical_type(comparison_stack.rdr_, l, r);
12159 else if (result == COMPARISON_RESULT_DIFFERENT)
12176 if (comparison_stack.is_redundant(cur_dies)
12177 && comparison_stack.vect_.back() == cur_dies)
12178 comparison_stack.cancel_canonical_propagated_type(cur_dies);
12186 if (result == COMPARISON_RESULT_CYCLE_DETECTED)
12187 result = COMPARISON_RESULT_UNKNOWN;
12188 else if (is_canon_type_to_be_propagated_tag(l_tag)
12189 && !comparison_stack.vect_.empty()
12190 && comparison_stack.vect_.back() == cur_dies)
12195 comparison_stack.erase(cur_dies);
12197 maybe_cache_type_comparison_result(comparison_stack.rdr_,
12198 l_tag, cur_dies, result);
12227compare_dies(
const reader& rdr,
12228 const Dwarf_Die *l,
const Dwarf_Die *r,
12229 offset_pairs_stack_type& aggregates_being_compared,
12230 bool update_canonical_dies_on_the_fly)
12235 const die_source l_die_source = rdr.get_die_source(l);
12236 const die_source r_die_source = rdr.get_die_source(r);
12238 offset_type l_offset =
12241 dwarf_dieoffset(
const_cast<Dwarf_Die*
>(l))
12244 offset_type r_offset =
12247 dwarf_dieoffset(
const_cast<Dwarf_Die*
>(r))
12252 int l_tag = dwarf_tag(
const_cast<Dwarf_Die*
>(l)),
12253 r_tag = dwarf_tag(
const_cast<Dwarf_Die*
>(r));
12255 if (l_tag != r_tag)
12258 if (l_offset == r_offset)
12259 return COMPARISON_RESULT_EQUAL;
12261 if (rdr.leverage_dwarf_factorization()
12262 && (l_die_source == ALT_DEBUG_INFO_DIE_SOURCE
12263 && r_die_source == ALT_DEBUG_INFO_DIE_SOURCE))
12264 if (l_offset != r_offset)
12265 return COMPARISON_RESULT_DIFFERENT;
12268 if (maybe_get_cached_type_comparison_result(rdr, l_tag,
12269 dies_being_compared,
12273 Dwarf_Off l_canonical_die_offset = 0, r_canonical_die_offset = 0;
12274 bool l_has_canonical_die_offset =
false, r_has_canonical_die_offset =
false;
12278 if (is_type_die_to_be_canonicalized(l) && is_type_die_to_be_canonicalized(r))
12280 bool canonical_compare_result =
false;
12281 if (try_canonical_die_comparison(rdr, l_offset, r_offset,
12282 l_die_source, r_die_source,
12283 l_has_canonical_die_offset,
12284 r_has_canonical_die_offset,
12285 l_canonical_die_offset,
12286 r_canonical_die_offset,
12287 canonical_compare_result))
12291 (canonical_compare_result
12292 ? COMPARISON_RESULT_EQUAL
12293 : COMPARISON_RESULT_DIFFERENT),
12303 case DW_TAG_base_type:
12304 case DW_TAG_string_type:
12305 case DW_TAG_unspecified_type:
12306 if (!compare_as_decl_and_type_dies(rdr, l, r))
12310 case DW_TAG_typedef:
12311 case DW_TAG_pointer_type:
12312 case DW_TAG_reference_type:
12313 case DW_TAG_rvalue_reference_type:
12314 case DW_TAG_const_type:
12315 case DW_TAG_volatile_type:
12316 case DW_TAG_restrict_type:
12318 if (!compare_as_type_dies(rdr, l, r))
12324 bool from_the_same_tu =
false;
12325 if (!pointer_or_qual_die_of_anonymous_class_type(l)
12326 && compare_dies_cu_decl_file(l, r, from_the_same_tu)
12327 && from_the_same_tu)
12344 Dwarf_Die lu_type_die, ru_type_die;
12345 bool lu_is_void, ru_is_void;
12347 lu_is_void = !die_die_attribute(l, DW_AT_type, lu_type_die);
12348 ru_is_void = !die_die_attribute(r, DW_AT_type, ru_type_die);
12350 if (lu_is_void && ru_is_void)
12351 result = COMPARISON_RESULT_EQUAL;
12352 else if (lu_is_void != ru_is_void)
12355 result = compare_dies(rdr, &lu_type_die, &ru_type_die,
12356 aggregates_being_compared,
12357 update_canonical_dies_on_the_fly);
12361 case DW_TAG_enumeration_type:
12362 if (!compare_as_decl_and_type_dies(rdr, l, r))
12367 Dwarf_Die l_enumtor, r_enumtor;
12368 bool found_l_enumtor =
true, found_r_enumtor =
true;
12370 if (!at_least_one_decl_only_among_odr_relevant_dies(rdr, l, r))
12371 for (found_l_enumtor = dwarf_child(
const_cast<Dwarf_Die*
>(l),
12373 found_r_enumtor = dwarf_child(
const_cast<Dwarf_Die*
>(r),
12375 found_l_enumtor && found_r_enumtor;
12376 found_l_enumtor = dwarf_siblingof(&l_enumtor, &l_enumtor) == 0,
12377 found_r_enumtor = dwarf_siblingof(&r_enumtor, &r_enumtor) == 0)
12379 int l_tag = dwarf_tag(&l_enumtor), r_tag = dwarf_tag(&r_enumtor);
12380 if ( l_tag != r_tag)
12386 if (l_tag != DW_TAG_enumerator)
12389 uint64_t l_val = 0, r_val = 0;
12390 die_unsigned_constant_attribute(&l_enumtor,
12393 die_unsigned_constant_attribute(&r_enumtor,
12396 if (l_val != r_val)
12402 if (found_l_enumtor != found_r_enumtor )
12407 case DW_TAG_structure_type:
12408 case DW_TAG_union_type:
12409 case DW_TAG_class_type:
12411 RETURN_IF_COMPARISON_CYCLE_DETECTED;
12413 rdr.compare_count_++;
12415 if (!compare_as_decl_and_type_dies(rdr, l, r))
12417 else if (rdr.options().assume_odr_for_cplusplus
12418 && rdr.odr_is_relevant(l)
12419 && rdr.odr_is_relevant(r)
12420 && !die_is_anonymous(l)
12421 && !die_is_anonymous(r))
12422 result = COMPARISON_RESULT_EQUAL;
12425 aggregates_being_compared.add(dies_being_compared);
12427 Dwarf_Die l_member, r_member;
12428 bool found_l_member =
true, found_r_member =
true;
12430 if (!at_least_one_decl_only_among_odr_relevant_dies(rdr, l, r))
12431 for (found_l_member = get_member_child_die(l, &l_member),
12432 found_r_member = get_member_child_die(r, &r_member);
12433 found_l_member && found_r_member;
12434 found_l_member = get_next_member_sibling_die(&l_member,
12436 found_r_member = get_next_member_sibling_die(&r_member,
12439 int l_tag = dwarf_tag(&l_member),
12440 r_tag = dwarf_tag(&r_member);
12442 if (l_tag != r_tag)
12449 || l_tag == DW_TAG_variable
12450 || l_tag == DW_TAG_inheritance
12451 || l_tag == DW_TAG_subprogram);
12454 compare_dies(rdr, &l_member, &r_member,
12455 aggregates_being_compared,
12456 update_canonical_dies_on_the_fly);
12458 if (local_result == COMPARISON_RESULT_UNKNOWN)
12467 result = local_result;
12469 if (local_result == COMPARISON_RESULT_DIFFERENT)
12475 if (found_l_member != found_r_member)
12484 case DW_TAG_array_type:
12486 RETURN_IF_COMPARISON_CYCLE_DETECTED;
12488 aggregates_being_compared.add(dies_being_compared);
12490 rdr.compare_count_++;
12492 Dwarf_Die l_child, r_child;
12493 bool found_l_child, found_r_child;
12494 for (found_l_child = dwarf_child(
const_cast<Dwarf_Die*
>(l),
12496 found_r_child = dwarf_child(
const_cast<Dwarf_Die*
>(r),
12498 found_l_child && found_r_child;
12499 found_l_child = dwarf_siblingof(&l_child, &l_child) == 0,
12500 found_r_child = dwarf_siblingof(&r_child, &r_child) == 0)
12502 int l_child_tag = dwarf_tag(&l_child),
12503 r_child_tag = dwarf_tag(&r_child);
12504 if (l_child_tag == DW_TAG_subrange_type
12505 || r_child_tag == DW_TAG_subrange_type)
12507 result = compare_dies(rdr, &l_child, &r_child,
12508 aggregates_being_compared,
12509 update_canonical_dies_on_the_fly);
12517 if (found_l_child != found_r_child)
12520 Dwarf_Die ltype_die, rtype_die;
12521 bool found_ltype = die_die_attribute(l, DW_AT_type, ltype_die);
12522 bool found_rtype = die_die_attribute(r, DW_AT_type, rtype_die);
12525 result = compare_dies(rdr, <ype_die, &rtype_die,
12526 aggregates_being_compared,
12527 update_canonical_dies_on_the_fly);
12533 case DW_TAG_subrange_type:
12535 uint64_t l_lower_bound = 0, r_lower_bound = 0,
12536 l_upper_bound = 0, r_upper_bound = 0;
12537 bool l_lower_bound_set =
false, r_lower_bound_set =
false,
12538 l_upper_bound_set =
false, r_upper_bound_set =
false;
12540 l_lower_bound_set =
12541 die_unsigned_constant_attribute(l, DW_AT_lower_bound, l_lower_bound);
12542 r_lower_bound_set =
12543 die_unsigned_constant_attribute(r, DW_AT_lower_bound, r_lower_bound);
12545 if (!die_unsigned_constant_attribute(l, DW_AT_upper_bound,
12548 uint64_t l_count = 0;
12549 if (die_unsigned_constant_attribute(l, DW_AT_count, l_count))
12551 l_upper_bound = l_lower_bound + l_count;
12552 l_upper_bound_set =
true;
12558 l_upper_bound_set =
true;
12560 if (!die_unsigned_constant_attribute(r, DW_AT_upper_bound,
12563 uint64_t r_count = 0;
12564 if (die_unsigned_constant_attribute(l, DW_AT_count, r_count))
12566 r_upper_bound = r_lower_bound + r_count;
12567 r_upper_bound_set =
true;
12573 r_upper_bound_set =
true;
12575 if ((l_lower_bound_set != r_lower_bound_set)
12576 || (l_upper_bound_set != r_upper_bound_set)
12577 || (l_lower_bound != r_lower_bound)
12578 || (l_upper_bound != r_upper_bound))
12583 case DW_TAG_subroutine_type:
12584 case DW_TAG_subprogram:
12586 RETURN_IF_COMPARISON_CYCLE_DETECTED;
12588 aggregates_being_compared.add(dies_being_compared);
12590 rdr.compare_count_++;
12592 if (l_tag == DW_TAG_subprogram
12593 && !fn_die_equal_by_linkage_name(l, r))
12598 else if (l_tag == DW_TAG_subprogram
12599 && die_is_in_c(l) && die_is_in_c(r))
12601 result = COMPARISON_RESULT_EQUAL;
12604 else if (!die_is_in_c(l) && !die_is_in_c(r))
12610 Dwarf_Die l_return_type, r_return_type;
12611 bool l_return_type_is_void = !die_die_attribute(l, DW_AT_type,
12613 bool r_return_type_is_void = !die_die_attribute(r, DW_AT_type,
12615 if (l_return_type_is_void != r_return_type_is_void
12616 || (!l_return_type_is_void
12617 && !compare_dies(rdr,
12618 &l_return_type, &r_return_type,
12619 aggregates_being_compared,
12620 update_canonical_dies_on_the_fly)))
12624 Dwarf_Die l_child, r_child;
12625 bool found_l_child, found_r_child;
12626 for (found_l_child = dwarf_child(
const_cast<Dwarf_Die*
>(l),
12628 found_r_child = dwarf_child(
const_cast<Dwarf_Die*
>(r),
12630 found_l_child && found_r_child;
12631 found_l_child = dwarf_siblingof(&l_child,
12633 found_r_child = dwarf_siblingof(&r_child,
12636 int l_child_tag = dwarf_tag(&l_child);
12637 int r_child_tag = dwarf_tag(&r_child);
12639 COMPARISON_RESULT_EQUAL;
12640 if (l_child_tag != r_child_tag)
12641 local_result = COMPARISON_RESULT_DIFFERENT;
12642 if (l_child_tag == DW_TAG_formal_parameter)
12644 compare_dies(rdr, &l_child, &r_child,
12645 aggregates_being_compared,
12646 update_canonical_dies_on_the_fly);
12647 if (local_result == COMPARISON_RESULT_DIFFERENT)
12649 result = local_result;
12653 if (local_result == COMPARISON_RESULT_UNKNOWN)
12664 result = local_result;
12666 if (found_l_child != found_r_child)
12676 case DW_TAG_formal_parameter:
12678 Dwarf_Die l_type, r_type;
12679 bool l_type_is_void = !die_die_attribute(l, DW_AT_type, l_type);
12680 bool r_type_is_void = !die_die_attribute(r, DW_AT_type, r_type);
12681 if (l_type_is_void != r_type_is_void)
12683 else if (!l_type_is_void)
12686 compare_dies(rdr, &l_type, &r_type,
12687 aggregates_being_compared,
12688 update_canonical_dies_on_the_fly);
12694 case DW_TAG_variable:
12695 case DW_TAG_member:
12696 if (compare_as_decl_dies(l, r))
12699 if (l_tag == DW_TAG_member)
12701 int64_t l_offset_in_bits = 0, r_offset_in_bits = 0;
12702 die_member_offset(rdr, l, l_offset_in_bits);
12703 die_member_offset(rdr, r, r_offset_in_bits);
12704 if (l_offset_in_bits != r_offset_in_bits)
12710 Dwarf_Die l_type, r_type;
12711 ABG_ASSERT(die_die_attribute(l, DW_AT_type, l_type));
12712 ABG_ASSERT(die_die_attribute(r, DW_AT_type, r_type));
12714 compare_dies(rdr, &l_type, &r_type,
12715 aggregates_being_compared,
12716 update_canonical_dies_on_the_fly);
12724 case DW_TAG_inheritance:
12726 Dwarf_Die l_type, r_type;
12727 ABG_ASSERT(die_die_attribute(l, DW_AT_type, l_type));
12728 ABG_ASSERT(die_die_attribute(r, DW_AT_type, r_type));
12729 result = compare_dies(rdr, &l_type, &r_type,
12730 aggregates_being_compared,
12731 update_canonical_dies_on_the_fly);
12735 uint64_t l_a = 0, r_a = 0;
12736 die_unsigned_constant_attribute(l, DW_AT_accessibility, l_a);
12737 die_unsigned_constant_attribute(r, DW_AT_accessibility, r_a);
12741 die_unsigned_constant_attribute(l, DW_AT_virtuality, l_a);
12742 die_unsigned_constant_attribute(r, DW_AT_virtuality, r_a);
12746 int64_t l_offset_in_bits = 0, r_offset_in_bits = 0;
12747 die_member_offset(rdr, l, l_offset_in_bits);
12748 die_member_offset(rdr, r, r_offset_in_bits);
12749 if (l_offset_in_bits != r_offset_in_bits)
12754 case DW_TAG_ptr_to_member_type:
12756 bool comp_result =
false;
12757 if (compare_dies_string_attribute_value(l, r, DW_AT_name, comp_result))
12761 Dwarf_Die l_type, r_type;
12762 ABG_ASSERT(die_die_attribute(l, DW_AT_type, l_type));
12763 ABG_ASSERT(die_die_attribute(r, DW_AT_type, r_type));
12764 result = compare_dies(rdr, &l_type, &r_type,
12765 aggregates_being_compared,
12766 update_canonical_dies_on_the_fly);
12770 ABG_ASSERT(die_die_attribute(l, DW_AT_containing_type, l_type));
12771 ABG_ASSERT(die_die_attribute(r, DW_AT_containing_type, r_type));
12772 result = compare_dies(rdr, &l_type, &r_type,
12773 aggregates_being_compared,
12774 update_canonical_dies_on_the_fly);
12780 case DW_TAG_enumerator:
12781 case DW_TAG_packed_type:
12782 case DW_TAG_set_type:
12783 case DW_TAG_file_type:
12784 case DW_TAG_thrown_type:
12785 case DW_TAG_interface_type:
12786 case DW_TAG_shared_type:
12787 case DW_TAG_compile_unit:
12788 case DW_TAG_namespace:
12789 case DW_TAG_module:
12790 case DW_TAG_constant:
12791 case DW_TAG_partial_unit:
12792 case DW_TAG_imported_unit:
12793 case DW_TAG_dwarf_procedure:
12794 case DW_TAG_imported_declaration:
12795 case DW_TAG_entry_point:
12797 case DW_TAG_lexical_block:
12798 case DW_TAG_unspecified_parameters:
12799 case DW_TAG_variant:
12800 case DW_TAG_common_block:
12801 case DW_TAG_common_inclusion:
12802 case DW_TAG_inlined_subroutine:
12803 case DW_TAG_with_stmt:
12804 case DW_TAG_access_declaration:
12805 case DW_TAG_catch_block:
12806 case DW_TAG_friend:
12807 case DW_TAG_namelist:
12808 case DW_TAG_namelist_item:
12809 case DW_TAG_template_type_parameter:
12810 case DW_TAG_template_value_parameter:
12811 case DW_TAG_try_block:
12812 case DW_TAG_variant_part:
12813 case DW_TAG_imported_module:
12814 case DW_TAG_condition:
12815 case DW_TAG_type_unit:
12816 case DW_TAG_template_alias:
12817 case DW_TAG_lo_user:
12818 case DW_TAG_MIPS_loop:
12819 case DW_TAG_format_label:
12820 case DW_TAG_function_template:
12821 case DW_TAG_class_template:
12822 case DW_TAG_GNU_BINCL:
12823 case DW_TAG_GNU_EINCL:
12824 case DW_TAG_GNU_template_template_param:
12825 case DW_TAG_GNU_template_parameter_pack:
12826 case DW_TAG_GNU_formal_parameter_pack:
12827 case DW_TAG_GNU_call_site:
12828 case DW_TAG_GNU_call_site_parameter:
12829 case DW_TAG_hi_user:
12830#ifdef WITH_DEBUG_TYPE_CANONICALIZATION
12831 if (rdr.debug_die_canonicalization_is_on_)
12858compare_dies(
const reader& rdr,
12859 const Dwarf_Die *l,
12860 const Dwarf_Die *r,
12861 bool update_canonical_dies_on_the_fly)
12863 offset_pairs_stack_type aggregates_being_compared(rdr);
12864 return compare_dies(rdr, l, r, aggregates_being_compared,
12865 update_canonical_dies_on_the_fly);
12887compare_dies_during_canonicalization(reader& rdr,
12888 const Dwarf_Die *l,
12889 const Dwarf_Die *r,
12890 bool update_canonical_dies_on_the_fly)
12892#ifdef WITH_DEBUG_TYPE_CANONICALIZATION
12893 if (rdr.debug_die_canonicalization_is_on_)
12895 bool canonical_equality =
false, structural_equality =
false;
12896 rdr.use_canonical_die_comparison_ =
false;
12897 structural_equality = compare_dies(rdr, l, r,
12899 rdr.use_canonical_die_comparison_ =
true;
12900 canonical_equality = compare_dies(rdr, l, r,
12901 update_canonical_dies_on_the_fly);
12902 if (canonical_equality != structural_equality)
12904 std::cerr <<
"structural & canonical equality different for DIEs: "
12906 <<
"l: " << dwarf_dieoffset(
const_cast<Dwarf_Die*
>(l))
12907 <<
", r: " << dwarf_dieoffset(
const_cast<Dwarf_Die*
>(r))
12910 << rdr.get_die_pretty_type_representation(l, 0)
12915 return structural_equality;
12918 return compare_dies(rdr, l, r,
12919 update_canonical_dies_on_the_fly);
12961find_import_unit_point_between_dies(
const reader& rdr,
12962 size_t partial_unit_offset,
12963 Dwarf_Off first_die_offset,
12964 Dwarf_Off first_die_cu_offset,
12966 size_t last_die_offset,
12967 size_t& imported_point_offset)
12970 rdr.tu_die_imported_unit_points_map(source);
12972 tu_die_imported_unit_points_map_type::const_iterator iter =
12973 tu_die_imported_unit_points_map.find(first_die_cu_offset);
12975 ABG_ASSERT(iter != tu_die_imported_unit_points_map.end());
12978 if (imported_unit_points.empty())
12981 imported_unit_points_type::const_iterator b = imported_unit_points.begin();
12982 imported_unit_points_type::const_iterator e = imported_unit_points.end();
12984 find_lower_bound_in_imported_unit_points(imported_unit_points,
12988 if (last_die_offset !=
static_cast<size_t>(-1))
12989 find_lower_bound_in_imported_unit_points(imported_unit_points,
12993 if (e != imported_unit_points.end())
12995 for (imported_unit_points_type::const_iterator i = e; i >= b; --i)
12996 if (i->imported_unit_die_off == partial_unit_offset)
12998 imported_point_offset = i->offset_of_import ;
13002 for (imported_unit_points_type::const_iterator i = e; i >= b; --i)
13004 if (find_import_unit_point_between_dies(rdr,
13005 partial_unit_offset,
13006 i->imported_unit_child_off,
13007 i->imported_unit_cu_off,
13008 i->imported_unit_die_source,
13010 imported_point_offset))
13016 for (imported_unit_points_type::const_iterator i = b; i != e; ++i)
13017 if (i->imported_unit_die_off == partial_unit_offset)
13019 imported_point_offset = i->offset_of_import ;
13023 for (imported_unit_points_type::const_iterator i = b; i != e; ++i)
13025 if (find_import_unit_point_between_dies(rdr,
13026 partial_unit_offset,
13027 i->imported_unit_child_off,
13028 i->imported_unit_cu_off,
13029 i->imported_unit_die_source,
13031 imported_point_offset))
13064find_import_unit_point_before_die(
const reader& rdr,
13065 size_t partial_unit_offset,
13066 size_t where_offset,
13067 size_t& imported_point_offset)
13069 size_t import_point_offset = 0;
13070 Dwarf_Die first_die_of_tu;
13072 if (dwarf_child(
const_cast<Dwarf_Die*
>(rdr.cur_tu_die()),
13073 &first_die_of_tu) != 0)
13076 Dwarf_Die cu_die_memory;
13079 cu_die = dwarf_diecu(
const_cast<Dwarf_Die*
>(&first_die_of_tu),
13080 &cu_die_memory, 0, 0);
13082 if (find_import_unit_point_between_dies(rdr, partial_unit_offset,
13083 dwarf_dieoffset(&first_die_of_tu),
13084 dwarf_dieoffset(cu_die),
13085 PRIMARY_DEBUG_INFO_DIE_SOURCE,
13087 import_point_offset))
13089 imported_point_offset = import_point_offset;
13093 if (import_point_offset)
13095 imported_point_offset = import_point_offset;
13123get_parent_die(
const reader& rdr,
13124 const Dwarf_Die* die,
13125 Dwarf_Die& parent_die,
13126 size_t where_offset)
13130 const die_source source = rdr.get_die_source(die);
13133 offset_offset_map_type::const_iterator i =
13134 m.find(dwarf_dieoffset(
const_cast<Dwarf_Die*
>(die)));
13141 case PRIMARY_DEBUG_INFO_DIE_SOURCE:
13142 ABG_ASSERT(dwarf_offdie(
const_cast<Dwarf*
>(rdr.dwarf_debug_info()),
13143 i->second, &parent_die));
13145 case ALT_DEBUG_INFO_DIE_SOURCE:
13146 ABG_ASSERT(dwarf_offdie(
const_cast<Dwarf*
>(rdr.alternate_dwarf_debug_info()),
13147 i->second, &parent_die));
13149 case TYPE_UNIT_DIE_SOURCE:
13150 ABG_ASSERT(dwarf_offdie_types(
const_cast<Dwarf*
>(rdr.dwarf_debug_info()),
13151 i->second, &parent_die));
13153 case NO_DEBUG_INFO_DIE_SOURCE:
13154 case NUMBER_OF_DIE_SOURCES:
13158 if (dwarf_tag(&parent_die) == DW_TAG_partial_unit)
13160 if (where_offset == 0)
13162 parent_die = *rdr.cur_tu_die();
13165 size_t import_point_offset = 0;
13167 find_import_unit_point_before_die(rdr,
13168 dwarf_dieoffset(&parent_die),
13170 import_point_offset);
13176 parent_die = *rdr.cur_tu_die();
13180 Dwarf_Die import_point_die;
13181 ABG_ASSERT(dwarf_offdie(
const_cast<Dwarf*
>(rdr.dwarf_debug_info()),
13182 import_point_offset,
13183 &import_point_die));
13184 return get_parent_die(rdr, &import_point_die,
13185 parent_die, where_offset);
13218get_scope_die(
const reader& rdr,
13219 const Dwarf_Die* dye,
13220 size_t where_offset,
13221 Dwarf_Die& scope_die)
13223 Dwarf_Die origin_die_mem;
13224 Dwarf_Die *die = &origin_die_mem;
13225 if (!die_origin_die(dye, origin_die_mem))
13226 memcpy(&origin_die_mem, dye,
sizeof(origin_die_mem));
13229 get_die_language(die, die_lang);
13231 || rdr.die_parent_map(rdr.get_die_source(die)).empty())
13233 ABG_ASSERT(dwarf_tag(
const_cast<Dwarf_Die*
>(die)) != DW_TAG_member);
13234 return dwarf_diecu(
const_cast<Dwarf_Die*
>(die), &scope_die, 0, 0);
13237 if (!get_parent_die(rdr, die, scope_die, where_offset))
13240 if (dwarf_tag(&scope_die) == DW_TAG_subprogram
13241 || dwarf_tag(&scope_die) == DW_TAG_subroutine_type
13242 || dwarf_tag(&scope_die) == DW_TAG_array_type)
13243 return get_scope_die(rdr, &scope_die, where_offset, scope_die);
13273get_scope_for_die(reader& rdr,
13275 bool called_for_public_decl,
13276 size_t where_offset)
13278 Dwarf_Die origin_die_mem;
13279 Dwarf_Die *die = &origin_die_mem;
13281 if (!die_origin_die(dye, origin_die_mem))
13284 memcpy(&origin_die_mem, dye,
sizeof(origin_die_mem));
13286 const die_source source_of_die = rdr.get_die_source(die);
13289 get_die_language(die, die_lang);
13291 || rdr.die_parent_map(source_of_die).empty())
13296 ABG_ASSERT(dwarf_tag(die) != DW_TAG_member);
13297 return rdr.global_scope();
13300 Dwarf_Die parent_die;
13302 if (!get_parent_die(rdr, die, parent_die, where_offset))
13303 return rdr.nil_scope();
13305 if (dwarf_tag(&parent_die) == DW_TAG_compile_unit
13306 || dwarf_tag(&parent_die) == DW_TAG_partial_unit
13307 || dwarf_tag(&parent_die) == DW_TAG_type_unit)
13309 if (dwarf_tag(&parent_die) == DW_TAG_partial_unit
13310 || dwarf_tag(&parent_die) == DW_TAG_type_unit)
13312 ABG_ASSERT(source_of_die == ALT_DEBUG_INFO_DIE_SOURCE
13313 || source_of_die == TYPE_UNIT_DIE_SOURCE);
13314 return rdr.cur_transl_unit()->get_global_scope();
13323 die_tu_map_type::const_iterator i =
13324 rdr.die_tu_map().find(dwarf_dieoffset(&parent_die));
13325 if (i != rdr.die_tu_map().end())
13326 return i->second->get_global_scope();
13327 return rdr.cur_transl_unit()->get_global_scope();
13332 if (dwarf_tag(&parent_die) == DW_TAG_subprogram
13333 || dwarf_tag(&parent_die) == DW_TAG_array_type
13334 || dwarf_tag(&parent_die) == DW_TAG_lexical_block)
13346 called_for_public_decl,
13355 if (!get_parent_die(rdr, &parent_die, parent_die, where_offset))
13356 return rdr.nil_scope();
13357 s = get_scope_for_die(rdr, &parent_die,
13358 called_for_public_decl,
13364 d = build_ir_node_from_die(rdr, &parent_die,
13365 called_for_public_decl,
13367 s = dynamic_pointer_cast<scope_decl>(d);
13371 return rdr.nil_scope();
13374 if (cl && cl->get_is_declaration_only())
13377 dynamic_pointer_cast<scope_decl>(cl->get_definition_of_declaration());
13394dwarf_language_to_tu_language(
size_t l)
13399 return translation_unit::LANG_C89;
13401 return translation_unit::LANG_C99;
13402#ifdef HAVE_DW_LANG_C11_enumerator
13404 return translation_unit::LANG_C11;
13406#ifdef HAVE_DW_LANG_C17
13408 return translation_unit::LANG_C17;
13410#ifdef HAVE_DW_LANG_C23
13412 return translation_unit::LANG_C23;
13415 return translation_unit::LANG_C;
13416#ifdef HAVE_DW_LANG_C_plus_plus_03_enumerator
13417 case DW_LANG_C_plus_plus_03:
13418 return translation_unit::LANG_C_plus_plus_03;
13421#ifdef HAVE_DW_LANG_C_plus_plus_11_enumerator
13422 case DW_LANG_C_plus_plus_11:
13423 return translation_unit::LANG_C_plus_plus_11;
13426#ifdef HAVE_DW_LANG_C_plus_plus_14_enumerator
13427 case DW_LANG_C_plus_plus_14:
13428 return translation_unit::LANG_C_plus_plus_14;
13430#ifdef HAVE_DW_LANG_C_plus_plus_17
13431 case DW_LANG_C_plus_plus_17:
13432 return translation_unit::LANG_C_plus_plus_17;
13435#ifdef HAVE_DW_LANG_C_plus_plus_20
13436 case DW_LANG_C_plus_plus_20:
13437 return translation_unit::LANG_C_plus_plus_20;
13439#ifdef HAVE_DW_LANG_C_plus_plus_23
13440 case DW_LANG_C_plus_plus_23:
13441 return translation_unit::LANG_C_plus_plus_23;
13443 case DW_LANG_C_plus_plus:
13444 return translation_unit::LANG_C_plus_plus;
13445#ifdef HAVE_DW_LANG_D_enumerator
13447 return translation_unit::LANG_D;
13449#ifdef HAVE_DW_LANG_OCaml_enumerator
13450 case DW_LANG_OCaml:
13451 return translation_unit::LANG_OCaml;
13453#ifdef HAVE_DW_LANG_Go_enumerator
13455 return translation_unit::LANG_Go;
13457#ifdef HAVE_DW_LANG_Rust_enumerator
13459 return translation_unit::LANG_Rust;
13461#ifdef HAVE_DW_LANG_Zig
13463 return translation_unit::LANG_Zig;
13465#ifdef HAVE_DW_LANG_Metal
13466 case DW_LANG_Metal:
13467 return translation_unit::LANG_Metal;
13469 case DW_LANG_Ada83:
13470 return translation_unit::LANG_Ada83;
13471 case DW_LANG_Ada95:
13472 return translation_unit::LANG_Ada95;
13473#ifdef HAVE_DW_LANG_Ada2005
13474 case DW_LANG_Ada2005:
13475 return translation_unit::LANG_Ada2005;
13478#ifdef HAVE_DW_LANG_Ada2012
13479 case DW_LANG_Ada2012:
13480 return translation_unit::LANG_Ada2012;
13482 case DW_LANG_Cobol74:
13483 return translation_unit::LANG_Cobol74;
13484 case DW_LANG_Cobol85:
13485 return translation_unit::LANG_Cobol85;
13486 case DW_LANG_Fortran77:
13487 return translation_unit::LANG_Fortran77;
13488 case DW_LANG_Fortran90:
13489 return translation_unit::LANG_Fortran90;
13490 case DW_LANG_Fortran95:
13491 return translation_unit::LANG_Fortran95;
13492#ifdef HAVE_DW_LANG_Fortran18
13493 case DW_LANG_Fortran18:
13494 return translation_unit::LANG_Fortran18;
13496#ifdef HAVE_DW_LANG_Fortran23
13497 case DW_LANG_Fortran23:
13498 return translation_unit::LANG_Fortran23;
13500 case DW_LANG_Pascal83:
13501 return translation_unit::LANG_Pascal83;
13502 case DW_LANG_Modula2:
13503 return translation_unit::LANG_Modula2;
13505 return translation_unit::LANG_Java;
13506#ifdef HAVE_DW_LANG_Kotlin
13507 case DW_LANG_Kotlin:
13508 return translation_unit::LANG_Kotlin;
13511 return translation_unit::LANG_PLI;
13513 return translation_unit::LANG_ObjC;
13514 case DW_LANG_ObjC_plus_plus:
13515 return translation_unit::LANG_ObjC_plus_plus;
13517#ifdef HAVE_DW_LANG_UPC_enumerator
13519 return translation_unit::LANG_UPC;
13521#ifdef HAVE_DW_LANG_Python_enumerator
13522 case DW_LANG_Python:
13523 return translation_unit::LANG_Python;
13525#ifdef HAVE_DW_LANG_Ruby
13527 return translation_unit::LANG_Ruby;
13529#ifdef HAVE_DW_LANG_Mips_Assembler_enumerator
13530 case DW_LANG_Mips_Assembler:
13531 return translation_unit::LANG_Mips_Assembler;
13533#ifdef HAVE_DW_LANG_Assembly
13534 case DW_LANG_Assembly:
13535 return translation_unit::LANG_Assembly;
13537#ifdef HAVE_DW_LANG_Crystal
13538 case DW_LANG_Crystal:
13539 return translation_unit::LANG_Crystal;
13541#ifdef HAVE_DW_LANG_HIP
13543 return translation_unit::LANG_HIP;
13545#ifdef HAVE_DW_LANG_C_sharp
13546 case DW_LANG_C_sharp:
13547 return translation_unit::LANG_C_sharp;
13549#ifdef HAVE_DW_LANG_Mojo
13551 return translation_unit::LANG_Mojo;
13553#ifdef HAVE_DW_LANG_GLSL
13555 return translation_unit::LANG_GLSL;
13557#ifdef HAVE_DW_LANG_GLSL_ES
13558 case DW_LANG_GLSL_ES:
13559 return translation_unit::LANG_GLSL_ES;
13561#ifdef HAVE_DW_LANG_HLSL
13563 return translation_unit::LANG_HLSL;
13565#ifdef HAVE_DW_LANG_OpenCL_CPP
13566 case DW_LANG_OpenCL_CPP:
13567 return translation_unit::LANG_OpenCL_CPP;
13569#ifdef HAVE_DW_LANG_CPP_for_OpenCL
13570 case DW_LANG_CPP_for_OpenCL:
13571 return translation_unit::LANG_CPP_for_OpenCL;
13573#ifdef HAVE_DW_LANG_SYCL
13575 return translation_unit::LANG_SYCL;
13577#ifdef HAVE_DW_LANG_Odin
13579 return translation_unit::LANG_Odin;
13581#ifdef HAVE_DW_LANG_P4
13583 return translation_unit::LANG_P4;
13585#ifdef HAVE_DW_LANG_Move
13587 return translation_unit::LANG_Move;
13589#ifdef HAVE_DW_LANG_Hylo
13591 return translation_unit::LANG_Hylo;
13595 return translation_unit::LANG_UNKNOWN;
13612 case translation_unit::LANG_UNKNOWN:
13613 case translation_unit::LANG_C89:
13614 case translation_unit::LANG_C99:
13615 case translation_unit::LANG_C11:
13616 case translation_unit::LANG_C17:
13617 case translation_unit::LANG_C23:
13618 case translation_unit::LANG_C:
13619 case translation_unit::LANG_C_plus_plus_03:
13620 case translation_unit::LANG_C_plus_plus_11:
13621 case translation_unit::LANG_C_plus_plus_14:
13622 case translation_unit::LANG_C_plus_plus_17:
13623 case translation_unit::LANG_C_plus_plus_20:
13624 case translation_unit::LANG_C_plus_plus_23:
13625 case translation_unit::LANG_C_plus_plus:
13626 case translation_unit::LANG_OCaml:
13627 case translation_unit::LANG_ObjC:
13628 case translation_unit::LANG_ObjC_plus_plus:
13629 case translation_unit::LANG_D:
13630 case translation_unit::LANG_Rust:
13631 case translation_unit::LANG_Go:
13632 case translation_unit::LANG_Zig:
13633 case translation_unit::LANG_Metal:
13634 case translation_unit::LANG_Java:
13635 case translation_unit::LANG_Kotlin:
13636 case translation_unit::LANG_Python:
13637 case translation_unit::LANG_Ruby:
13638 case translation_unit::LANG_UPC:
13639 case translation_unit::LANG_Mips_Assembler:
13640 case translation_unit::LANG_Assembly:
13641 case translation_unit::LANG_Crystal:
13642 case translation_unit::LANG_HIP:
13643 case translation_unit::LANG_C_sharp:
13644 case translation_unit::LANG_Mojo:
13645 case translation_unit::LANG_GLSL:
13646 case translation_unit::LANG_GLSL_ES:
13647 case translation_unit::LANG_HLSL:
13648 case translation_unit::LANG_Odin:
13649 case translation_unit::LANG_P4:
13650 case translation_unit::LANG_OpenCL_CPP:
13651 case translation_unit::LANG_CPP_for_OpenCL:
13652 case translation_unit::LANG_SYCL:
13653 case translation_unit::LANG_Move:
13654 case translation_unit::LANG_Hylo:
13657 case translation_unit::LANG_Cobol74:
13658 case translation_unit::LANG_Cobol85:
13659 case translation_unit::LANG_Fortran77:
13660 case translation_unit::LANG_Fortran90:
13661 case translation_unit::LANG_Fortran95:
13662 case translation_unit::LANG_Fortran18:
13663 case translation_unit::LANG_Fortran23:
13664 case translation_unit::LANG_Ada83:
13665 case translation_unit::LANG_Ada95:
13666 case translation_unit::LANG_Ada2005:
13667 case translation_unit::LANG_Ada2012:
13668 case translation_unit::LANG_Pascal83:
13669 case translation_unit::LANG_Modula2:
13670 case translation_unit::LANG_PLI:
13697 imported_unit_points_type::const_iterator& r)
13699 imported_unit_point v(val);
13700 imported_unit_points_type::const_iterator result =
13701 std::lower_bound(p.begin(), p.end(), v);
13703 bool is_ok = result != p.end();
13725build_translation_unit_and_add_to_ir(reader& rdr,
13733 ABG_ASSERT(dwarf_tag(die) == DW_TAG_compile_unit);
13737 rdr.clear_per_translation_unit_data();
13739 rdr.cur_tu_die(die);
13741 string path = die_string_attribute(die, DW_AT_name);
13742 if (path ==
"<artificial>")
13748 std::ostringstream o;
13749 o << path <<
"-" << std::hex << dwarf_dieoffset(die);
13752 string compilation_dir = die_string_attribute(die, DW_AT_comp_dir);
13762 const string& abs_path =
13763 compilation_dir.empty() ? path : compilation_dir +
"/" + path;
13764 result = rdr.corpus()->find_translation_unit(abs_path);
13769 result.reset(
new translation_unit(rdr.env(),
13772 result->set_compilation_dir_path(compilation_dir);
13773 rdr.corpus()->add(result);
13775 die_unsigned_constant_attribute(die, DW_AT_language, l);
13776 result->set_language(dwarf_language_to_tu_language(l));
13779 rdr.cur_transl_unit(result);
13780 rdr.die_tu_map()[dwarf_dieoffset(die)] = result;
13783 if (dwarf_child(die, &child) != 0)
13786 result->set_is_constructed(
false);
13787 int tag = dwarf_tag(&child);
13789 if (rdr.load_undefined_interfaces()
13790 && (rdr.is_decl_die_with_undefined_symbol(&child)
13791 || tag == DW_TAG_class_type
13796 || ((tag == DW_TAG_union_type || tag == DW_TAG_structure_type)
13797 && die_is_in_cplus_plus(&child))))
13801 build_ir_node_from_die(rdr, &child,
13806 dwarf_dieoffset(&child));
13808 else if (!rdr.env().analyze_exported_interfaces_only()
13809 || rdr.is_decl_die_with_exported_symbol(&child))
13813 build_ir_node_from_die(rdr, &child,
13814 die_is_public_decl(&child),
13815 dwarf_dieoffset(&child));
13817 while (dwarf_siblingof(&child, &child) == 0);
13819 if (!rdr.var_decls_to_re_add_to_tree().empty())
13820 for (list<var_decl_sptr>::const_iterator v =
13821 rdr.var_decls_to_re_add_to_tree().begin();
13822 v != rdr.var_decls_to_re_add_to_tree().end();
13829 string demangled_name =
13831 if (!demangled_name.empty())
13833 std::list<string> fqn_comps;
13835 string mem_name = fqn_comps.back();
13836 fqn_comps.pop_back();
13839 if (!fqn_comps.empty())
13867 ABG_ASSERT(dynamic_pointer_cast<var_decl>(d));
13873 rdr.var_decls_to_re_add_to_tree().clear();
13875 result->set_is_constructed(
true);
13900build_namespace_decl_and_add_to_ir(reader& rdr,
13902 size_t where_offset)
13909 unsigned tag = dwarf_tag(die);
13910 if (tag != DW_TAG_namespace && tag != DW_TAG_module)
13917 string name, linkage_name;
13919 die_loc_and_name(rdr, die, loc, name, linkage_name);
13921 result.reset(
new namespace_decl(rdr.env(), name, loc));
13923 rdr.associate_die_to_decl(die, result, where_offset);
13926 if (dwarf_child(die, &child) != 0)
13929 rdr.scope_stack().push(result.get());
13931 build_ir_node_from_die(rdr, &child,
13937 die_is_public_decl(die) && die_is_public_decl(&child),
13939 while (dwarf_siblingof(&child, &child) == 0);
13940 rdr.scope_stack().pop();
13955build_type_decl(reader& rdr, Dwarf_Die* die,
size_t where_offset)
13961 ABG_ASSERT(dwarf_tag(die) == DW_TAG_base_type);
13963 uint64_t byte_size = 0, bit_size = 0;
13964 if (!die_unsigned_constant_attribute(die, DW_AT_byte_size, byte_size))
13965 if (!die_unsigned_constant_attribute(die, DW_AT_bit_size, bit_size))
13968 if (bit_size == 0 && byte_size != 0)
13970 bit_size = byte_size * 8;
13972 string type_name, linkage_name;
13974 die_loc_and_name(rdr, die, loc, type_name, linkage_name);
13976 if (byte_size == 0)
13980 if (type_name ==
"void")
13981 result =
is_type_decl(build_ir_node_for_void_type(rdr));
13988 if (corpus_sptr corp = rdr.should_reuse_type_from_corpus_group())
13990 string normalized_type_name = type_name;
13991 real_type real_type;
13993 normalized_type_name = real_type.
to_string();
13998 if (corpus_sptr corp = rdr.corpus())
14001 result.reset(
new type_decl(rdr.env(), type_name, bit_size,
14002 0, loc, linkage_name));
14003 rdr.associate_die_to_type(die, result, where_offset);
14021build_enum_underlying_type(reader& rdr,
14023 uint64_t enum_size,
14024 bool is_anonymous =
true)
14026 string underlying_type_name =
14030 type_decl_sptr result(
new type_decl(rdr.env(), underlying_type_name,
14031 enum_size, enum_size, location()));
14032 result->set_is_anonymous(is_anonymous);
14033 result->set_is_artificial(
true);
14036 result = dynamic_pointer_cast<type_decl>(d);
14038 maybe_canonicalize_type(result, rdr);
14057build_enum_type(reader& rdr,
14060 size_t where_offset,
14061 bool is_declaration_only)
14067 unsigned tag = dwarf_tag(die);
14068 if (tag != DW_TAG_enumeration_type)
14071 string name, linkage_name;
14073 die_loc_and_name(rdr, die, loc, name, linkage_name);
14075 bool is_anonymous =
false;
14079 name = get_internal_anonymous_die_prefix_name(die);
14082 is_anonymous =
true;
14084 scope_decl* sc = scope ? scope : rdr.global_scope().get();
14085 if (
size_t s = sc->get_num_anonymous_member_enums())
14086 name = build_internal_anonymous_die_name(name, s);
14089 bool use_odr = rdr.odr_is_relevant(die);
14101 result = pre_existing_enum;
14103 else if (corpus_sptr corp = rdr.should_reuse_type_from_corpus_group())
14112 if (pre_existing_enum->get_location() == loc)
14113 result = pre_existing_enum;
14118 rdr.associate_die_to_type(die, result, where_offset);
14126 if (die_unsigned_constant_attribute(die, DW_AT_byte_size, size))
14128 bool is_artificial = die_is_artificial(die);
14131 bool enum_underlying_type_is_anonymous=
true;
14135 if (dwarf_child(die, &child) == 0)
14139 if (dwarf_tag(&child) != DW_TAG_enumerator)
14144 die_loc_and_name(rdr, &child, l, n, m);
14146 die_unsigned_constant_attribute(&child, DW_AT_const_value, val);
14147 enms.push_back(enum_type_decl::enumerator(n, val));
14149 while (dwarf_siblingof(&child, &child) == 0);
14157 build_enum_underlying_type(rdr, name, size,
14158 enum_underlying_type_is_anonymous);
14159 t->set_is_declaration_only(is_declaration_only);
14161 result.reset(
new enum_type_decl(name, loc, t, enms, linkage_name));
14162 result->set_is_anonymous(is_anonymous);
14163 result->set_is_declaration_only(is_declaration_only);
14164 result->set_is_artificial(is_artificial);
14165 rdr.associate_die_to_type(die, result, where_offset);
14184finish_member_function_reading(Dwarf_Die* die,
14186 const class_or_union_sptr klass,
14197 size_t is_inline = die_is_declared_inline(die);
14198 bool is_ctor = (f->get_name() == klass->get_name());
14199 bool is_dtor = (!f->get_name().empty()
14200 &&
static_cast<string>(f->get_name())[0] ==
'~');
14201 bool is_virtual = die_is_virtual(die);
14202 int64_t vindex = -1;
14204 die_virtual_function_index(die, vindex);
14207 if (!c->is_struct())
14208 access = private_access;
14209 die_access_specifier(die, access);
14211 m->is_declared_inline(is_inline);
14215 bool is_static = method_t->get_is_for_static_method();
14223 if (is_virtual && !f->get_linkage_name().empty() && !f->get_symbol()
14243 Dwarf_Off die_offset = dwarf_dieoffset(die);
14245 rdr.die_function_decl_with_no_symbol_map();
14246 die_function_decl_map_type::const_iterator i =
14247 fns_with_no_symbol.find(die_offset);
14248 if (i == fns_with_no_symbol.end())
14249 fns_with_no_symbol[die_offset] = f;
14270maybe_finish_function_decl_reading(reader& rdr,
14272 size_t where_offset,
14290static type_base_sptr
14291lookup_class_or_typedef_from_corpus(scope_decl* scope,
const string& type_name)
14294 corpus* corp = scope->get_corpus();
14315static type_base_sptr
14316lookup_class_or_typedef_from_corpus(reader& rdr,
14318 bool called_for_public_decl,
14319 size_t where_offset)
14324 string class_name = die_string_attribute(die, DW_AT_name);
14325 if (class_name.empty())
14329 called_for_public_decl,
14332 return lookup_class_or_typedef_from_corpus(scope.get(), class_name);
14334 return type_base_sptr();
14351static method_decl_sptr
14352is_function_for_die_a_member_of_class(reader& rdr,
14353 Dwarf_Die* function_die,
14354 const class_or_union_sptr& class_type)
14359 return method_decl_sptr();
14365 method_type = method->get_type();
14370 class_or_union_sptr method_class = method_type->get_class_type();
14373 string method_class_name = method_class->get_qualified_name(),
14374 class_type_name = class_type->get_qualified_name();
14376 if (method_class_name == class_type_name)
14382 return method_decl_sptr();
14404static method_decl_sptr
14405add_or_update_member_function(reader& rdr,
14406 Dwarf_Die* function_die,
14407 const class_or_union_sptr& class_type,
14408 bool called_from_public_decl,
14409 size_t where_offset)
14411 method_decl_sptr method =
14412 is_function_for_die_a_member_of_class(rdr, function_die, class_type);
14415 method =
is_method_decl(build_ir_node_from_die(rdr, function_die,
14417 called_from_public_decl,
14420 return method_decl_sptr();
14422 finish_member_function_reading(function_die,
14465add_or_update_class_type(reader& rdr,
14470 bool called_from_public_decl,
14471 size_t where_offset,
14472 bool is_declaration_only)
14478 const die_source source = rdr.get_die_source(die);
14480 unsigned tag = dwarf_tag(die);
14482 if (tag != DW_TAG_class_type && tag != DW_TAG_structure_type)
14486 die_class_or_union_map_type::const_iterator i =
14487 rdr.die_wip_classes_map(source).find(dwarf_dieoffset(die));
14488 if (i != rdr.die_wip_classes_map(source).end())
14496 string name, linkage_name;
14498 die_loc_and_name(rdr, die, loc, name, linkage_name);
14499 cleanup_decl_name(name);
14501 bool is_anonymous =
false;
14506 name = get_internal_anonymous_die_prefix_name(die);
14509 is_anonymous =
true;
14513 s = scope->get_num_anonymous_member_classes();
14515 s = rdr.global_scope()->get_num_anonymous_member_classes();
14516 name = build_internal_anonymous_die_name(name, s);
14521 if (corpus_sptr corp = rdr.should_reuse_type_from_corpus_group())
14537 && (result->get_is_declaration_only() == is_declaration_only
14538 || (!result->get_is_declaration_only()
14539 && is_declaration_only)))
14541 rdr.associate_die_to_type(die, result, where_offset);
14560 klass = pre_existing_class;
14563 die_size_in_bits(die, size);
14564 bool is_artificial = die_is_artificial(die);
14567 bool has_child = (dwarf_child(die, &child) == 0);
14569 decl_base_sptr res;
14572 res = result = klass;
14573 if (has_child && klass->get_is_declaration_only()
14574 && klass->get_definition_of_declaration())
14575 res = result =
is_class_type(klass->get_definition_of_declaration());
14577 result->set_location(loc);
14581 result.reset(
new class_decl(rdr.env(), name, size,
14583 decl_base::VISIBILITY_DEFAULT,
14586 result->set_is_declaration_only(is_declaration_only);
14589 result = dynamic_pointer_cast<class_decl>(res);
14593 if (!klass || klass->get_is_declaration_only())
14594 if (size != result->get_size_in_bits())
14595 result->set_size_in_bits(size);
14600 if (!!result->get_size_in_bits() == result->get_is_declaration_only())
14613 result->set_is_declaration_only(is_declaration_only);
14617 if (!result->get_is_declaration_only() && has_child)
14618 if (result->get_size_in_bits() == 0 && size != 0)
14619 result->set_size_in_bits(size);
14621 result->set_is_artificial(is_artificial);
14623 rdr.associate_die_to_type(die, result, where_offset);
14630 rdr.die_wip_classes_map(source)[dwarf_dieoffset(die)] = result;
14632 bool is_incomplete_type =
false;
14633 if (is_declaration_only && size == 0 && has_child)
14645 is_incomplete_type =
true;
14648 dynamic_pointer_cast<scope_decl>(res);
14650 rdr.scope_stack().push(scop.get());
14652 if (has_child && !is_incomplete_type)
14656 tag = dwarf_tag(&child);
14659 if (tag == DW_TAG_inheritance)
14661 result->set_is_declaration_only(
false);
14663 Dwarf_Die type_die;
14664 if (!die_die_attribute(&child, DW_AT_type, type_die))
14667 string type_name = die_type_name(rdr, &type_die,
14670 type_base_sptr base_type;
14671 if (!type_name.empty())
14673 base_type = result->find_base_class(type_name);
14679 lookup_class_or_typedef_from_corpus(rdr, &type_die,
14680 called_from_public_decl,
14684 is_type(build_ir_node_from_die(rdr, &type_die,
14685 called_from_public_decl,
14699 die_access_specifier(&child, access);
14701 bool is_virt= die_is_virtual(&child);
14702 int64_t offset = 0;
14703 bool is_offset_present =
14704 die_member_offset(rdr, &child, offset);
14708 is_offset_present ? offset : -1,
14710 if (b->get_is_declaration_only()
14717 && !b->get_qualified_name().empty())
14718 ABG_ASSERT(rdr.is_decl_only_class_scheduled_for_resolution(b));
14719 if (result->find_base_class(b->get_qualified_name()))
14721 result->add_base_specifier(base);
14724 else if (tag == DW_TAG_member
14725 || tag == DW_TAG_variable)
14727 Dwarf_Die type_die;
14728 if (!die_die_attribute(&child, DW_AT_type, type_die))
14733 die_loc_and_name(rdr, &child, loc, n, m);
14738 if (n.substr(0, 5) ==
"_vptr"
14740 && !std::isalnum(n.at(5))
14750 int64_t offset_in_bits = 0;
14751 bool is_laid_out = die_member_offset(rdr, &child,
14756 bool is_static = !is_laid_out;
14772 decl_base_sptr ty =
is_decl(build_ir_node_from_die(rdr, &type_die,
14773 called_from_public_decl,
14775 type_base_sptr t =
is_type(ty);
14779 if (n.empty() && !die_is_anonymous_data_member(&child))
14785 n = rdr.build_name_for_buggy_anonymous_data_member(&child);
14802 result->set_is_declaration_only(
false);
14808 die_access_specifier(&child, access);
14816 result->add_data_member(dm, access, is_laid_out,
14817 is_static, offset_in_bits);
14819 rdr.associate_die_to_decl(&child, dm, where_offset,
14823 else if (tag == DW_TAG_subprogram)
14826 add_or_update_member_function(rdr, &child, result,
14827 called_from_public_decl,
14830 rdr.associate_die_to_decl(&child, f, where_offset,
14834 else if (die_is_type(&child))
14839 && !result->find_member_type(die_name(&child)))
14840 build_ir_node_from_die(rdr, &child, result.get(),
14841 called_from_public_decl,
14848 string anonymous_type_name =
14849 die_class_or_enum_flat_representation(rdr, &child,
14854 if (type_base_sptr member_t =
14855 result->find_member_type(anonymous_type_name))
14856 rdr.associate_die_to_decl(&child,
is_decl(member_t),
14862 is_type(build_ir_node_from_die(rdr, &child,
14864 called_from_public_decl,
14869 maybe_set_member_type_access_specifier(result,
14875 }
while (dwarf_siblingof(&child, &child) == 0);
14878 rdr.scope_stack().pop();
14881 die_class_or_union_map_type::const_iterator i =
14882 rdr.die_wip_classes_map(source).find(dwarf_dieoffset(die));
14883 if (i != rdr.die_wip_classes_map(source).end())
14888 rdr.die_wip_classes_map(source).erase(i);
14919static union_decl_sptr
14920add_or_update_union_type(reader& rdr,
14923 union_decl_sptr union_type,
14924 bool called_from_public_decl,
14925 size_t where_offset,
14926 bool is_declaration_only)
14928 union_decl_sptr result;
14932 unsigned tag = dwarf_tag(die);
14934 if (tag != DW_TAG_union_type)
14937 const die_source source = rdr.get_die_source(die);
14939 die_class_or_union_map_type::const_iterator i =
14940 rdr.die_wip_classes_map(source).find(dwarf_dieoffset(die));
14941 if (i != rdr.die_wip_classes_map(source).end())
14949 string name, linkage_name;
14951 die_loc_and_name(rdr, die, loc, name, linkage_name);
14952 cleanup_decl_name(name);
14954 bool is_anonymous =
false;
14959 name = get_internal_anonymous_die_prefix_name(die);
14962 is_anonymous =
true;
14966 s = scope->get_num_anonymous_member_unions();
14968 s = rdr.global_scope()->get_num_anonymous_member_classes();
14969 name = build_internal_anonymous_die_name(name, s);
14979 if (corpus_sptr corp = rdr.should_reuse_type_from_corpus_group())
14988 rdr.associate_die_to_type(die, result, where_offset);
15000 if (union_decl_sptr pre_existing_union =
15002 union_type = pre_existing_union;
15005 die_size_in_bits(die, size);
15006 bool is_artificial = die_is_artificial(die);
15010 result = union_type;
15011 result->set_location(loc);
15015 result.reset(
new union_decl(rdr.env(), name, size, loc,
15016 decl_base::VISIBILITY_DEFAULT,
15018 if (is_declaration_only)
15019 result->set_is_declaration_only(
true);
15026 result->set_size_in_bits(size);
15027 result->set_is_declaration_only(
false);
15030 result->set_is_artificial(is_artificial);
15032 rdr.associate_die_to_type(die, result, where_offset);
15035 bool has_child = (dwarf_child(die, &child) == 0);
15039 rdr.die_wip_classes_map(source)[dwarf_dieoffset(die)] = result;
15042 dynamic_pointer_cast<scope_decl>(result);
15044 rdr.scope_stack().push(scop.get());
15050 tag = dwarf_tag(&child);
15052 if (tag == DW_TAG_member || tag == DW_TAG_variable)
15054 Dwarf_Die type_die;
15055 if (!die_die_attribute(&child, DW_AT_type, type_die))
15060 die_loc_and_name(rdr, &child, loc, n, m);
15069 ssize_t offset_in_bits = 0;
15070 decl_base_sptr ty =
15071 is_decl(build_ir_node_from_die(rdr, &type_die,
15072 called_from_public_decl,
15074 type_base_sptr t =
is_type(ty);
15081 result->set_is_declaration_only(
false);
15084 die_access_specifier(&child, access);
15090 if (n.empty() && result->find_data_member(dm))
15096 result->add_data_member(dm, access,
true,
15100 rdr.associate_die_to_decl(&child, dm, where_offset,
15104 else if (tag == DW_TAG_subprogram)
15107 is_decl(build_ir_node_from_die(rdr, &child,
15109 called_from_public_decl,
15117 finish_member_function_reading(&child, f, result, rdr);
15119 rdr.associate_die_to_decl(&child, f, where_offset,
15123 else if (die_is_type(&child))
15125 string type_name = die_type_name(rdr, &child,
15128 if (type_base_sptr member_t = result->find_member_type(type_name))
15129 rdr.associate_die_to_decl(&child,
is_decl(member_t),
15133 decl_base_sptr td =
15134 is_decl(build_ir_node_from_die(rdr, &child, result.get(),
15135 called_from_public_decl,
15138 }
while (dwarf_siblingof(&child, &child) == 0);
15141 rdr.scope_stack().pop();
15144 die_class_or_union_map_type::const_iterator i =
15145 rdr.die_wip_classes_map(source).find(dwarf_dieoffset(die));
15146 if (i != rdr.die_wip_classes_map(source).end())
15151 rdr.die_wip_classes_map(source).erase(i);
15175static type_base_sptr
15176build_qualified_type(reader& rdr,
15178 bool called_from_public_decl,
15179 size_t where_offset)
15181 type_base_sptr result;
15185 unsigned tag = dwarf_tag(die);
15187 if (tag != DW_TAG_const_type
15188 && tag != DW_TAG_volatile_type
15189 && tag != DW_TAG_restrict_type)
15192 Dwarf_Die underlying_type_die;
15193 decl_base_sptr utype_decl;
15194 if (!die_die_attribute(die, DW_AT_type, underlying_type_die))
15198 utype_decl = build_ir_node_for_void_type(rdr);
15201 utype_decl =
is_decl(build_ir_node_from_die(rdr, &underlying_type_die,
15202 called_from_public_decl,
15209 if (type_base_sptr t = rdr.lookup_type_from_die(die))
15212 rdr.associate_die_to_type(die, result, where_offset);
15216 type_base_sptr utype =
is_type(utype_decl);
15220 if (tag == DW_TAG_const_type)
15221 qual |= qualified_type_def::CV_CONST;
15222 else if (tag == DW_TAG_volatile_type)
15223 qual |= qualified_type_def::CV_VOLATILE;
15224 else if (tag == DW_TAG_restrict_type)
15225 qual |= qualified_type_def::CV_RESTRICT;
15230 result.reset(
new qualified_type_def(utype, qual, location()));
15232 rdr.associate_die_to_type(die, result, where_offset);
15250schedule_array_tree_for_late_canonicalization(
const type_base_sptr& t,
15255 schedule_array_tree_for_late_canonicalization(type->get_underlying_type(),
15257 rdr.schedule_type_for_late_canonicalization(t);
15261 schedule_array_tree_for_late_canonicalization(type->get_underlying_type(),
15263 rdr.schedule_type_for_late_canonicalization(t);
15267 for (vector<array_type_def::subrange_sptr>::const_iterator i =
15268 type->get_subranges().begin();
15269 i != type->get_subranges().end();
15272 if (!(*i)->get_scope())
15274 rdr.schedule_type_for_late_canonicalization(*i);
15277 schedule_array_tree_for_late_canonicalization(type->get_element_type(),
15279 rdr.schedule_type_for_late_canonicalization(type);
15298static decl_base_sptr
15299maybe_strip_qualification(
const qualified_type_def_sptr t,
15305 decl_base_sptr result = t;
15306 type_base_sptr u = t->get_underlying_type();
15310 if (result.get() != t.get())
15316 scope_decl * scope = 0;
15319 scope = array->get_scope();
15322 schedule_array_tree_for_late_canonicalization(array, rdr);
15324 t->set_underlying_type(array);
15325 u = t->get_underlying_type();
15333 schedule_array_tree_for_late_canonicalization(typdef, rdr);
15336 t->set_underlying_type(typdef);
15337 u = t->get_underlying_type();
15346 type_base_sptr element_type = array->get_element_type();
15351 ABG_ASSERT(!qualified->get_canonical_type());
15353 quals |= t->get_cv_quals();
15354 qualified->set_cv_quals(quals);
15360 qualified_type_def_sptr qual_type
15361 (
new qualified_type_def(element_type,
15363 t->get_location()));
15366 array->set_element_type(qual_type);
15367 rdr.schedule_type_for_late_canonicalization(
is_type(qual_type));
15392build_pointer_type_def(reader& rdr,
15394 bool called_from_public_decl,
15395 size_t where_offset)
15402 unsigned tag = dwarf_tag(die);
15403 if (tag != DW_TAG_pointer_type)
15407 Dwarf_Die underlying_type_die;
15408 bool has_underlying_type_die =
false;
15409 if (!die_die_attribute(die, DW_AT_type, underlying_type_die))
15412 utype_decl = build_ir_node_for_void_type(rdr);
15414 has_underlying_type_die =
true;
15416 if (!utype_decl && has_underlying_type_die)
15417 utype_decl = build_ir_node_from_die(rdr, &underlying_type_die,
15418 called_from_public_decl,
15425 if (type_base_sptr t = rdr.lookup_type_from_die(die))
15432 type_base_sptr utype =
is_type(utype_decl);
15438 uint64_t size = rdr.cur_transl_unit()->get_address_size();
15439 if (die_unsigned_constant_attribute(die, DW_AT_byte_size, size))
15446 ABG_ASSERT((
size_t) rdr.cur_transl_unit()->get_address_size() == size);
15448 result.reset(
new pointer_type_def(utype, size, 0, location()));
15454 rdr.associate_die_to_type(die, result, where_offset);
15476build_reference_type(reader& rdr,
15478 bool called_from_public_decl,
15479 size_t where_offset)
15486 unsigned tag = dwarf_tag(die);
15487 if (tag != DW_TAG_reference_type
15488 && tag != DW_TAG_rvalue_reference_type)
15491 Dwarf_Die underlying_type_die;
15492 if (!die_die_attribute(die, DW_AT_type, underlying_type_die))
15496 build_ir_node_from_die(rdr, &underlying_type_die,
15497 called_from_public_decl,
15504 if (type_base_sptr t = rdr.lookup_type_from_die(die))
15511 type_base_sptr utype =
is_type(utype_decl);
15517 uint64_t size = rdr.cur_transl_unit()->get_address_size();
15518 if (die_unsigned_constant_attribute(die, DW_AT_byte_size, size))
15523 ABG_ASSERT((
size_t) rdr.cur_transl_unit()->get_address_size() == size);
15525 bool is_lvalue = tag == DW_TAG_reference_type;
15527 result.reset(
new reference_type_def(utype, is_lvalue, size,
15530 if (corpus_sptr corp = rdr.corpus())
15533 rdr.associate_die_to_type(die, result, where_offset);
15556build_ptr_to_mbr_type(reader& rdr,
15558 bool called_from_public_decl,
15559 size_t where_offset)
15566 unsigned tag = dwarf_tag(die);
15567 if (tag != DW_TAG_ptr_to_member_type)
15570 Dwarf_Die data_member_type_die, containing_type_die;
15572 if (!die_die_attribute(die, DW_AT_type, data_member_type_die)
15573 || !die_die_attribute(die, DW_AT_containing_type, containing_type_die))
15577 build_ir_node_from_die(rdr, &data_member_type_die,
15578 called_from_public_decl, where_offset);
15579 if (!data_member_type)
15583 build_ir_node_from_die(rdr, &containing_type_die,
15584 called_from_public_decl, where_offset);
15585 if (!containing_type)
15592 if (type_base_sptr t = rdr.lookup_type_from_die(die))
15599 uint64_t size_in_bits = rdr.cur_transl_unit()->get_address_size();
15601 result.reset(
new ptr_to_mbr_type(data_member_type->get_environment(),
15608 rdr.associate_die_to_type(die, result, where_offset);
15629build_function_type(reader& rdr,
15631 class_or_union_sptr is_method,
15632 size_t where_offset)
15639 ABG_ASSERT(dwarf_tag(die) == DW_TAG_subroutine_type
15640 || dwarf_tag(die) == DW_TAG_subprogram);
15642 const die_source source = rdr.get_die_source(die);
15645 size_t off = dwarf_dieoffset(die);
15646 auto i = rdr.die_wip_function_types_map(source).find(off);
15647 if (i != rdr.die_wip_function_types_map(source).end())
15655 decl_base_sptr type_decl;
15663 if (type_base_sptr t = rdr.lookup_fn_type_from_die_repr_per_tu(die))
15667 rdr.associate_die_to_type(die, result, where_offset);
15684 rdr.associate_die_to_type(die, fn_type, where_offset);
15692 bool is_const =
false;
15693 bool is_static =
false;
15694 Dwarf_Die object_pointer_die;
15695 Dwarf_Die class_type_die;
15696 bool has_this_parm_die =
15697 die_function_type_is_method_type(rdr, die, where_offset,
15698 object_pointer_die,
15701 if (has_this_parm_die)
15706 if (die_object_pointer_is_for_const_method(&object_pointer_die))
15714 class_or_union_sptr klass_type =
15725 is_method = klass_type;
15734 result.reset(is_method
15735 ?
new method_type(is_method, is_const,
15736 tu->get_address_size(),
15738 : new function_type(rdr.env(), tu->get_address_size(),
15740 rdr.associate_die_to_type(die, result, where_offset);
15741 rdr.die_wip_function_types_map(source)[dwarf_dieoffset(die)] = result;
15743 type_base_sptr return_type;
15744 Dwarf_Die ret_type_die;
15745 if (die_die_attribute(die, DW_AT_type, ret_type_die))
15747 is_type(build_ir_node_from_die(rdr, &ret_type_die,
15751 return_type =
is_type(build_ir_node_for_void_type(rdr));
15752 result->set_return_type(return_type);
15757 if (dwarf_child(die, &child) == 0)
15760 int child_tag = dwarf_tag(&child);
15761 if (child_tag == DW_TAG_formal_parameter)
15764 string name, linkage_name;
15766 die_loc_and_name(rdr, &child, loc, name, linkage_name);
15771 bool is_artificial = die_is_artificial(&child);
15772 type_base_sptr parm_type;
15773 Dwarf_Die parm_type_die;
15774 if (die_die_attribute(&child, DW_AT_type, parm_type_die))
15776 is_type(build_ir_node_from_die(rdr, &parm_type_die,
15783 && function_parms.empty())
15799 (
new function_decl::parameter(parm_type, name, loc,
15802 function_parms.push_back(p);
15804 else if (child_tag == DW_TAG_unspecified_parameters)
15807 bool is_artificial = die_is_artificial(&child);
15809 type_base_sptr parm_type =
15810 is_type(build_ir_node_for_variadic_parameter_type(rdr));
15812 (
new function_decl::parameter(parm_type,
15817 function_parms.push_back(p);
15827 while (dwarf_siblingof(&child, &child) == 0);
15829 result->set_parameters(function_parms);
15831 tu->bind_function_type_life_time(result);
15833 result->set_is_artificial(
true);
15835 rdr.associate_die_repr_to_fn_type_per_tu(die, result);
15838 die_function_type_map_type::const_iterator i =
15839 rdr.die_wip_function_types_map(source).
15840 find(dwarf_dieoffset(die));
15841 if (i != rdr.die_wip_function_types_map(source).end())
15842 rdr.die_wip_function_types_map(source).erase(i);
15845 maybe_canonicalize_type(result, rdr);
15872build_subrange_type(reader& rdr,
15873 const Dwarf_Die* die,
15874 size_t where_offset,
15875 bool associate_type_to_die)
15882 unsigned tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
15883 if (tag != DW_TAG_subrange_type)
15886 string name = die_name(die);
15889 Dwarf_Die underlying_type_die;
15890 type_base_sptr underlying_type;
15892 bool is_signed =
false;
15893 if (die_die_attribute(die, DW_AT_type, underlying_type_die))
15895 is_type(build_ir_node_from_die(rdr,
15896 &underlying_type_die,
15900 if (underlying_type)
15903 if (die_unsigned_constant_attribute (&underlying_type_die,
15906 is_signed = (ate == DW_ATE_signed || ate == DW_ATE_signed_char);
15912 bool has_size_info =
false;
15914 if ((has_size_info = die_unsigned_constant_attribute(die,
15915 DW_AT_byte_size, size)))
15918 has_size_info = die_unsigned_constant_attribute(die,
15919 DW_AT_bit_size, size);
15922 array_type_def::subrange_type::bound_value lower_bound =
15923 get_default_array_lower_bound(language);
15924 array_type_def::subrange_type::bound_value upper_bound;
15925 uint64_t count = 0;
15926 bool is_non_finite =
false;
15927 bool non_zero_count_present =
false;
15938 die_constant_attribute(die, DW_AT_lower_bound, is_signed, lower_bound);
15940 bool found_upper_bound = die_constant_attribute(die, DW_AT_upper_bound,
15941 is_signed, upper_bound);
15942 if (!found_upper_bound)
15943 found_upper_bound = subrange_die_indirect_bound_value(die,
15948 if (!found_upper_bound)
15961 if (die_unsigned_constant_attribute(die, DW_AT_count, count))
15969 non_zero_count_present =
true;
15974 int64_t u = lower_bound.get_signed_value() + count;
15976 upper_bound = u - 1;
15979 if (!non_zero_count_present)
15983 is_non_finite =
true;
15986 if (UINT64_MAX == upper_bound.get_unsigned_value())
15989 is_non_finite =
true;
15992 (
new array_type_def::subrange_type(rdr.env(),
15998 result->is_non_finite(is_non_finite);
16001 result->set_size_in_bits(size);
16008 if (!underlying_type)
16009 result->set_size_in_bits(rdr.cur_transl_unit()->get_address_size());
16014 || (result->get_length() ==
16015 (uint64_t) (result->get_upper_bound()
16016 - result->get_lower_bound() + 1)));
16018 if (associate_type_to_die)
16019 rdr.associate_die_to_type(die, result, where_offset);
16041build_subranges_from_array_type_die(
const reader& rdr,
16042 const Dwarf_Die* die,
16044 size_t where_offset,
16045 bool associate_type_to_die)
16049 if (dwarf_child(
const_cast<Dwarf_Die*
>(die), &child) == 0)
16053 int child_tag = dwarf_tag(&child);
16054 if (child_tag == DW_TAG_subrange_type)
16057 if (associate_type_to_die)
16063 build_ir_node_from_die(
const_cast<reader&
>(rdr), &child,
16072 s = build_subrange_type(
const_cast<reader&
>(rdr), &child,
16076 subranges.push_back(s);
16079 while (dwarf_siblingof(&child, &child) == 0);
16100build_array_type(reader& rdr,
16102 bool called_from_public_decl,
16103 size_t where_offset)
16110 unsigned tag = dwarf_tag(die);
16111 if (tag != DW_TAG_array_type)
16114 decl_base_sptr type_decl;
16115 Dwarf_Die type_die;
16117 if (die_die_attribute(die, DW_AT_type, type_die))
16118 type_decl =
is_decl(build_ir_node_from_die(rdr, &type_die,
16119 called_from_public_decl,
16126 if (type_base_sptr t = rdr.lookup_type_from_die(die))
16133 type_base_sptr type =
is_type(type_decl);
16138 build_subranges_from_array_type_die(rdr, die, subranges, where_offset);
16140 result.reset(
new array_type_def(type, subranges, location()));
16141 rdr.associate_die_to_type(die, result, where_offset);
16162build_typedef_type(reader& rdr,
16164 bool called_from_public_decl,
16165 size_t where_offset)
16172 unsigned tag = dwarf_tag(die);
16173 if (tag != DW_TAG_typedef)
16176 string name, linkage_name;
16178 die_loc_and_name(rdr, die, loc, name, linkage_name);
16180 if (corpus_sptr corp = rdr.should_reuse_type_from_corpus_group())
16186 type_base_sptr utype;
16187 Dwarf_Die underlying_type_die;
16188 if (!die_die_attribute(die, DW_AT_type, underlying_type_die))
16191 utype = rdr.env().get_void_type();
16195 is_type(build_ir_node_from_die(rdr,
16196 &underlying_type_die,
16197 called_from_public_decl,
16203 result.reset(
new typedef_decl(name, utype, loc, linkage_name));
16210 decl_base_sptr decl =
is_decl(utype);
16212 decl->set_naming_typedef(result);
16213 rdr.maybe_schedule_decl_only_type_for_resolution(utype);
16217 rdr.associate_die_to_type(die, result, where_offset);
16254build_or_get_var_decl_if_not_suppressed(reader& rdr,
16257 size_t where_offset,
16258 bool is_declaration_only,
16260 bool is_required_decl_spec)
16263 if (variable_is_suppressed(rdr, scope, die,
16264 is_declaration_only,
16265 is_required_decl_spec))
16267 ++rdr.stats_.number_of_suppressed_variables;
16273 string var_name = die_name(die);
16274 if (!var_name.empty())
16275 if ((var = class_type->find_data_member(var_name)))
16280 ++rdr.stats_.number_of_suppressed_variables;
16282 var = build_var_decl(rdr, die, where_offset, result);
16305build_var_decl(reader& rdr,
16307 size_t where_offset,
16313 int tag = dwarf_tag(die);
16314 ABG_ASSERT(tag == DW_TAG_variable || tag == DW_TAG_member);
16316 if (!die_is_public_decl(die))
16319 type_base_sptr type;
16320 Dwarf_Die type_die;
16321 if (die_die_attribute(die, DW_AT_type, type_die))
16323 decl_base_sptr ty =
16324 is_decl(build_ir_node_from_die(rdr, &type_die,
16333 if (!type && !result)
16336 string name, linkage_name;
16338 die_loc_and_name(rdr, die, loc, name, linkage_name);
16341 result.reset(
new var_decl(name, type, loc, linkage_name));
16347 if (!linkage_name.empty())
16348 result->set_linkage_name(linkage_name);
16351 result->set_type(type);
16357 if (!result->get_symbol())
16360 Dwarf_Addr var_addr;
16362 if (rdr.get_variable_address(die, var_addr))
16365 update_main_symbol(var_addr,
16366 result->get_linkage_name().empty()
16367 ? result->get_name()
16368 : result->get_linkage_name());
16369 var_sym = rdr.variable_symbol_is_exported(var_addr);
16374 result->set_symbol(var_sym);
16377 string linkage_name = result->get_linkage_name();
16378 if (linkage_name.empty()
16379 || !var_sym->get_alias_from_name(linkage_name))
16380 result->set_linkage_name(var_sym->get_name());
16381 result->set_is_in_public_symbol_table(
true);
16384 if (!var_sym && rdr.is_decl_die_with_undefined_symbol(die))
16388 string n = result->get_linkage_name();
16390 n = result->get_name();
16391 var_sym = rdr.symtab()->lookup_undefined_variable_symbol(n);
16394 result->set_symbol(var_sym);
16395 result->set_is_in_public_symbol_table(
false);
16422function_is_suppressed(
const reader& rdr,
16423 const scope_decl* scope,
16424 Dwarf_Die *function_die,
16425 bool is_declaration_only)
16427 if (function_die == 0
16428 || dwarf_tag(function_die) != DW_TAG_subprogram)
16431 string fname = die_string_attribute(function_die, DW_AT_name);
16432 string flinkage_name = die_linkage_name(function_die);
16433 if (flinkage_name.empty() && die_is_in_c(function_die))
16434 flinkage_name = fname;
16444 && (!is_declaration_only || rdr.drop_undefined_syms()))
16446 Dwarf_Addr fn_addr;
16447 if (!rdr.get_function_address(function_die, fn_addr))
16451 rdr.function_symbol_is_exported(fn_addr);
16454 if (symbol->is_suppressed())
16461 if (symbol->has_aliases())
16463 !a->is_main_symbol(); a = a->get_next_alias())
16464 if (a->is_suppressed())
16513build_or_get_fn_decl_if_not_suppressed(reader& rdr,
16516 size_t where_offset,
16517 bool is_declaration_only,
16521 if (function_is_suppressed(rdr, scope, fn_die, is_declaration_only))
16523 ++rdr.stats_.number_of_suppressed_functions;
16527 string name = die_name(fn_die);
16528 string linkage_name = die_linkage_name(fn_die);
16529 bool is_dtor = !name.empty() && name[0]==
'~';
16530 bool is_virtual =
false;
16533 Dwarf_Attribute attr;
16534 if (dwarf_attr_integrate(
const_cast<Dwarf_Die*
>(fn_die),
16535 DW_AT_vtable_elem_location,
16547 if (!result && (!(is_dtor && is_virtual)))
16551 fn = maybe_finish_function_decl_reading(rdr, fn_die, where_offset, fn);
16552 rdr.associate_die_to_decl(fn_die, fn,
true);
16553 rdr.associate_die_to_type(fn_die, fn->get_type(), where_offset);
16559 ++rdr.stats_.number_of_allowed_functions;
16565 string linkage_name = die_linkage_name(fn_die);
16566 fn = klass->find_member_function_sptr(linkage_name);
16573 if (!fn || !fn->get_symbol())
16580 fn = build_function_decl(rdr, fn_die, where_offset, result);
16605variable_is_suppressed(
const reader& rdr,
16606 const scope_decl* scope,
16607 Dwarf_Die *variable_die,
16608 bool is_declaration_only,
16609 bool is_required_decl_spec)
16611 if (variable_die == 0
16612 || (dwarf_tag(variable_die) != DW_TAG_variable
16613 && dwarf_tag(variable_die) != DW_TAG_member))
16616 string name = die_string_attribute(variable_die, DW_AT_name);
16617 string linkage_name = die_linkage_name(variable_die);
16618 if (linkage_name.empty() && die_is_in_c(variable_die))
16619 linkage_name = name;
16628 && !is_required_decl_spec
16632 && (!is_declaration_only || !rdr.load_undefined_interfaces()))
16634 Dwarf_Addr var_addr = 0;
16635 if (!rdr.get_variable_address(variable_die, var_addr))
16639 rdr.variable_symbol_is_exported(var_addr);
16642 if (symbol->is_suppressed())
16649 if (symbol->has_aliases())
16651 !a->is_main_symbol(); a = a->get_next_alias())
16652 if (a->is_suppressed())
16681type_is_suppressed(
const reader& rdr,
16682 const scope_decl* scope,
16683 Dwarf_Die *type_die,
16684 bool &type_is_opaque)
16687 || (dwarf_tag(type_die) != DW_TAG_enumeration_type
16688 && dwarf_tag(type_die) != DW_TAG_class_type
16689 && dwarf_tag(type_die) != DW_TAG_structure_type
16690 && dwarf_tag(type_die) != DW_TAG_union_type))
16693 string type_name, linkage_name;
16694 location type_location;
16695 die_loc_and_name(rdr, type_die, type_location, type_name, linkage_name);
16719type_is_suppressed(
const reader& rdr,
16720 const scope_decl* scope,
16721 Dwarf_Die *type_die)
16723 bool type_is_opaque =
false;
16724 return type_is_suppressed(rdr, scope, type_die, type_is_opaque);
16748get_opaque_version_of_type(reader &rdr,
16750 Dwarf_Die *type_die,
16751 size_t where_offset)
16758 unsigned tag = dwarf_tag(type_die);
16759 if (tag != DW_TAG_class_type
16760 && tag != DW_TAG_structure_type
16761 && tag != DW_TAG_union_type
16762 && tag != DW_TAG_enumeration_type)
16765 string type_name, linkage_name;
16766 location type_location;
16767 die_loc_and_name(rdr, type_die, type_location, type_name, linkage_name);
16776 if (tag == DW_TAG_structure_type || tag == DW_TAG_class_type)
16778 string_classes_or_unions_map::const_iterator i =
16779 rdr.declaration_only_classes().find(qualified_name);
16780 if (i != rdr.declaration_only_classes().end())
16781 result = i->second.back();
16792 tag == DW_TAG_structure_type,
16794 decl_base::VISIBILITY_DEFAULT));
16795 klass->set_is_declaration_only(
true);
16796 klass->set_is_artificial(die_is_artificial(type_die));
16798 rdr.associate_die_to_type(type_die, klass, where_offset);
16799 rdr.maybe_schedule_declaration_only_class_for_resolution(klass);
16804 if (tag == DW_TAG_enumeration_type)
16806 string_enums_map::const_iterator i =
16807 rdr.declaration_only_enums().find(qualified_name);
16808 if (i != rdr.declaration_only_enums().end())
16809 result = i->second.back();
16814 if (die_unsigned_constant_attribute(type_die, DW_AT_byte_size, size))
16817 build_enum_underlying_type(rdr, type_name, size,
16825 enum_type->set_is_artificial(die_is_artificial(type_die));
16827 result = enum_type;
16850 elf_symbol::FUNC_TYPE,
16851 elf_symbol::GLOBAL_BINDING,
16855 elf_symbol::DEFAULT_VISIBILITY);
16873build_function_decl(reader& rdr,
16875 size_t where_offset,
16881 int tag = dwarf_tag(die);
16882 ABG_ASSERT(tag == DW_TAG_subprogram || tag == DW_TAG_inlined_subroutine);
16884 if (!die_is_public_decl(die))
16890 string fname, flinkage_name;
16892 die_loc_and_name(rdr, die, floc, fname, flinkage_name);
16893 cleanup_decl_name(fname);
16895 size_t is_inline = die_is_declared_inline(die);
16896 class_or_union_sptr is_method =
16909 if (!flinkage_name.empty()
16910 && result->get_linkage_name() != flinkage_name)
16911 result->set_linkage_name(flinkage_name);
16913 if (!result->get_location())
16914 result->set_location(floc);
16915 result->is_declared_inline(is_inline);
16924 maybe_canonicalize_type(fn_type, rdr);
16926 result.reset(is_method
16927 ?
new method_decl(fname, fn_type,
16930 : new function_decl(fname, fn_type,
16937 if (!result->get_symbol())
16940 Dwarf_Addr fn_addr;
16941 if (rdr.get_function_address(die, fn_addr))
16944 update_main_symbol(fn_addr,
16945 result->get_linkage_name().empty()
16946 ? result->get_name()
16947 : result->get_linkage_name());
16948 fn_sym = rdr.function_symbol_is_exported(fn_addr);
16951 if (fn_sym && !rdr.symbol_already_belongs_to_a_function(fn_sym))
16953 result->set_symbol(fn_sym);
16954 string linkage_name = result->get_linkage_name();
16955 if (linkage_name.empty())
16956 result->set_linkage_name(fn_sym->get_name());
16957 result->set_is_in_public_symbol_table(
true);
16960 if (!fn_sym && rdr.is_decl_die_with_undefined_symbol(die))
16964 string n = result->get_linkage_name();
16966 n = result->get_name();
16967 fn_sym = rdr.symtab()->lookup_undefined_function_symbol(n);
16970 result->set_symbol(fn_sym);
16971 result->set_is_in_public_symbol_table(
false);
16976 rdr.associate_die_to_type(die, result->get_type(), where_offset);
16978 size_t die_offset = dwarf_dieoffset(die);
16983 && !result->get_linkage_name().empty())
16989 rdr.die_function_decl_with_no_symbol_map().erase(die_offset);
17008maybe_canonicalize_type(
const type_base_sptr& t,
17014 rdr.schedule_type_for_late_canonicalization(t);
17023maybe_set_member_type_access_specifier(decl_base_sptr member_type_declaration,
17026 if (
is_type(member_type_declaration)
17029 class_or_union* scope =
17035 if (!cl->is_struct())
17036 access = private_access;
17038 die_access_specifier(die, access);
17051cleanup_decl_name(
string& str)
17072 const Dwarf_Die *fn_die)
17074 if (!fn || fn->get_scope())
17078 !die_is_virtual(fn_die)
17080 && !fn->get_symbol())
17125build_ir_node_from_die(reader& rdr,
17128 bool called_from_public_decl,
17129 size_t where_offset,
17130 bool is_declaration_only,
17131 bool is_required_decl_spec)
17135 if (!die || !scope)
17138 int tag = dwarf_tag(die);
17140 if (!called_from_public_decl)
17142 if (rdr.load_all_types() && die_is_type(die))
17146 else if (tag != DW_TAG_subprogram
17147 && tag != DW_TAG_variable
17148 && tag != DW_TAG_member
17149 && tag != DW_TAG_namespace)
17153 const die_source source_of_die = rdr.get_die_source(die);
17155 if ((result = rdr.lookup_decl_from_die_offset(dwarf_dieoffset(die),
17158 if (rdr.load_all_types())
17159 if (called_from_public_decl)
17160 if (type_base_sptr t =
is_type(result))
17161 if (corpus *abi_corpus = rdr.corpus().get())
17162 abi_corpus->record_type_as_reachable_from_public_interfaces(*t);
17171 is_declaration_only = is_declaration_only && die_is_declaration_only(die);
17176 case DW_TAG_base_type:
17181 maybe_canonicalize_type(t, rdr);
17185 case DW_TAG_typedef:
17188 called_from_public_decl,
17194 maybe_set_member_type_access_specifier(
is_decl(result), die);
17195 maybe_canonicalize_type(t, rdr);
17200 case DW_TAG_pointer_type:
17203 build_pointer_type_def(rdr, die,
17204 called_from_public_decl,
17211 maybe_canonicalize_type(p, rdr);
17216 case DW_TAG_reference_type:
17217 case DW_TAG_rvalue_reference_type:
17220 build_reference_type(rdr, die,
17221 called_from_public_decl,
17227 maybe_canonicalize_type(r, rdr);
17232 case DW_TAG_ptr_to_member_type:
17235 build_ptr_to_mbr_type(rdr, die, called_from_public_decl,
17241 rdr.cur_transl_unit()->get_global_scope());
17242 maybe_canonicalize_type(p, rdr);
17247 case DW_TAG_const_type:
17248 case DW_TAG_volatile_type:
17249 case DW_TAG_restrict_type:
17252 build_qualified_type(rdr, die,
17253 called_from_public_decl,
17264 type_base_sptr ty =
is_type(d);
17268 rdr.associate_die_to_type(die, ty, where_offset);
17271 maybe_canonicalize_type(
is_type(result), rdr);
17276 case DW_TAG_enumeration_type:
17278 bool type_is_opaque =
false;
17279 bool type_suppressed =
17280 type_is_suppressed(rdr, scope, die, type_is_opaque);
17281 if (type_suppressed && type_is_opaque)
17289 result = get_opaque_version_of_type(rdr, scope, die, where_offset);
17290 maybe_canonicalize_type(
is_type(result), rdr);
17292 else if (!type_suppressed)
17296 is_declaration_only);
17300 maybe_set_member_type_access_specifier(
is_decl(result), die);
17301 maybe_canonicalize_type(
is_type(result), rdr);
17307 case DW_TAG_class_type:
17308 case DW_TAG_structure_type:
17310 bool type_is_opaque =
false;
17311 bool type_suppressed=
17312 type_is_suppressed(rdr, scope, die, type_is_opaque);
17314 if (type_suppressed && type_is_opaque)
17322 result = get_opaque_version_of_type(rdr, scope, die, where_offset);
17323 maybe_canonicalize_type(
is_type(result), rdr);
17325 else if (!type_suppressed)
17328 Dwarf_Die spec_die;
17329 if (die_die_attribute(die, DW_AT_specification, spec_die))
17332 get_scope_for_die(rdr, &spec_die,
17333 called_from_public_decl,
17336 decl_base_sptr cl =
17337 is_decl(build_ir_node_from_die(rdr, &spec_die,
17339 called_from_public_decl,
17341 is_declaration_only,
17344 klass = dynamic_pointer_cast<class_decl>(cl);
17348 add_or_update_class_type(rdr, die,
17350 tag == DW_TAG_structure_type,
17352 called_from_public_decl,
17354 is_declaration_only);
17360 string type_name = die_type_name(rdr, die,
17368 add_or_update_class_type(rdr, die, scope,
17369 tag == DW_TAG_structure_type,
17371 called_from_public_decl,
17373 is_declaration_only);
17377 add_or_update_class_type(rdr, die, scope,
17378 tag == DW_TAG_structure_type,
17380 called_from_public_decl,
17382 is_declaration_only);
17386 maybe_set_member_type_access_specifier(klass, die);
17387 maybe_canonicalize_type(klass, rdr);
17393 case DW_TAG_union_type:
17394 if (!type_is_suppressed(rdr, scope, die))
17396 union_decl_sptr union_type;
17399 string type_name = die_type_name(rdr, die,
17402 if (union_decl_sptr u =
17409 add_or_update_union_type(rdr, die, scope,
17411 called_from_public_decl,
17413 is_declaration_only);
17417 maybe_set_member_type_access_specifier(union_type, die);
17418 maybe_canonicalize_type(union_type, rdr);
17419 result = union_type;
17423 case DW_TAG_string_type:
17425 case DW_TAG_subroutine_type:
17433 result->set_is_artificial(
false);
17434 maybe_canonicalize_type(f, rdr);
17438 case DW_TAG_array_type:
17442 called_from_public_decl,
17448 maybe_canonicalize_type(a, rdr);
17452 case DW_TAG_subrange_type:
17458 build_subrange_type(rdr, die, where_offset,
17464 maybe_canonicalize_type(s, rdr);
17468 case DW_TAG_packed_type:
17470 case DW_TAG_set_type:
17472 case DW_TAG_file_type:
17474 case DW_TAG_thrown_type:
17476 case DW_TAG_interface_type:
17478 case DW_TAG_unspecified_type:
17480 case DW_TAG_shared_type:
17483 case DW_TAG_compile_unit:
17488 case DW_TAG_namespace:
17489 case DW_TAG_module:
17490 result = build_namespace_decl_and_add_to_ir(rdr, die, where_offset);
17493 case DW_TAG_variable:
17494 case DW_TAG_member:
17496 if (tag == DW_TAG_member)
17500 get_scope_for_die(rdr, die,
17502 die_is_effectively_public_decl(rdr, die),
17505 build_or_get_var_decl_if_not_suppressed(rdr, var_scope.get(), die,
17507 is_declaration_only,
17509 is_required_decl_spec);
17517 v = build_var_decl(rdr, die, where_offset, v);
17519 Dwarf_Addr addr = 0;
17520 bool has_data_location =
false;
17521 has_data_location = rdr.get_variable_address(die, addr);
17526 || (v && rdr.is_decl_die_with_undefined_symbol(die))
17527 || (v && rdr.is_decl_die_with_exported_symbol(die))
17541 rdr.var_decls_to_re_add_to_tree().push_back(v);
17542 rdr.add_var_to_exported_or_undefined_decls(v);
17543 rdr.associate_die_to_decl(die, v, where_offset,
17550 case DW_TAG_subprogram:
17551 case DW_TAG_inlined_subroutine:
17553 if (die_is_artificial(die))
17556 Dwarf_Die abstract_origin_die;
17557 bool has_abstract_origin = die_die_attribute(die, DW_AT_abstract_origin,
17558 abstract_origin_die,
17562 scope_decl_sptr s = get_scope_for_die(rdr, die, called_from_public_decl,
17564 scope_decl* interface_scope = scope ? scope : s.get();
17567 string linkage_name = die_linkage_name(die);
17568 string spec_linkage_name;
17575 if (!linkage_name.empty())
17578 class_scope->find_member_function_sptr(linkage_name)))
17583 spec_linkage_name = existing_fn->get_linkage_name();
17584 if (has_abstract_origin
17585 && !spec_linkage_name.empty()
17586 && linkage_name != spec_linkage_name)
17593 existing_fn = existing_fn->clone();
17598 else if (has_abstract_origin)
17602 existing_fn = build_function_decl(rdr, &abstract_origin_die, where_offset,
17605 rdr.scope_stack().push(interface_scope);
17612 build_or_get_fn_decl_if_not_suppressed(rdr, interface_scope,
17614 is_declaration_only,
17617 if (result && !existing_fn)
17623 && !is_required_decl_spec)
17640 sptr_utils::noop_deleter());
17642 finish_member_function_reading(die, fn, klass, rdr);
17653 rdr.add_fn_to_exported_or_undefined_decls(fn.get());
17654 rdr.associate_die_to_decl(die, fn, where_offset,
17656 maybe_canonicalize_type(fn->get_type(), rdr);
17659 rdr.scope_stack().pop();
17663 case DW_TAG_formal_parameter:
17668 case DW_TAG_constant:
17670 case DW_TAG_enumerator:
17673 case DW_TAG_partial_unit:
17674 case DW_TAG_imported_unit:
17681 case DW_TAG_dwarf_procedure:
17682 case DW_TAG_imported_declaration:
17683 case DW_TAG_entry_point:
17685 case DW_TAG_lexical_block:
17686 case DW_TAG_unspecified_parameters:
17687 case DW_TAG_variant:
17688 case DW_TAG_common_block:
17689 case DW_TAG_common_inclusion:
17690 case DW_TAG_inheritance:
17691 case DW_TAG_with_stmt:
17692 case DW_TAG_access_declaration:
17693 case DW_TAG_catch_block:
17694 case DW_TAG_friend:
17695 case DW_TAG_namelist:
17696 case DW_TAG_namelist_item:
17697 case DW_TAG_template_type_parameter:
17698 case DW_TAG_template_value_parameter:
17699 case DW_TAG_try_block:
17700 case DW_TAG_variant_part:
17701 case DW_TAG_imported_module:
17702 case DW_TAG_condition:
17703 case DW_TAG_type_unit:
17704 case DW_TAG_template_alias:
17705 case DW_TAG_lo_user:
17706 case DW_TAG_MIPS_loop:
17707 case DW_TAG_format_label:
17708 case DW_TAG_function_template:
17709 case DW_TAG_class_template:
17710 case DW_TAG_GNU_BINCL:
17711 case DW_TAG_GNU_EINCL:
17712 case DW_TAG_GNU_template_template_param:
17713 case DW_TAG_GNU_template_parameter_pack:
17714 case DW_TAG_GNU_formal_parameter_pack:
17715 case DW_TAG_GNU_call_site:
17716 case DW_TAG_GNU_call_site_parameter:
17717 case DW_TAG_hi_user:
17722 if (result && tag != DW_TAG_subroutine_type)
17723 rdr.associate_die_to_decl(die,
is_decl(result), where_offset,
17727 if (rdr.load_all_types())
17728 if (called_from_public_decl)
17729 if (type_base_sptr t =
is_type(result))
17730 if (corpus *abi_corpus = scope->get_corpus())
17731 abi_corpus->record_type_as_reachable_from_public_interfaces(*t);
17733 rdr.maybe_schedule_decl_only_type_for_resolution(result);
17743static decl_base_sptr
17744build_ir_node_for_void_type(reader& rdr)
17746 const environment& env = rdr.env();
17748 type_base_sptr t = env.get_void_type();
17753 rdr.schedule_type_for_late_canonicalization(t);
17755 return type_declaration;
17770build_ir_node_for_void_pointer_type(reader& rdr)
17772 const environment& env = rdr.env();
17773 type_base_sptr t = env.get_void_pointer_type();
17778 rdr.schedule_type_for_late_canonicalization(t);
17780 return type_declaration;
17788static decl_base_sptr
17789build_ir_node_for_variadic_parameter_type(reader &rdr)
17792 const environment& env = rdr.env();
17793 type_base_sptr t = env.get_variadic_parameter_type();
17798 rdr.schedule_type_for_late_canonicalization(t);
17800 return type_declaration;
17826build_ir_node_from_die(reader& rdr,
17828 bool called_from_public_decl,
17829 size_t where_offset)
17832 return decl_base_sptr();
17842 bool consider_as_called_from_public_decl =
17843 called_from_public_decl || die_is_effectively_public_decl(rdr, die);
17845 consider_as_called_from_public_decl,
17848 scope = rdr.global_scope();
17850 return build_ir_node_from_die(rdr, die, scope.get(),
17851 called_from_public_decl,
17852 where_offset,
true);
17886elf_based_reader_sptr
17888 const vector<string>& debug_info_root_paths,
17890 bool load_all_types,
17891 bool linux_kernel_mode)
17894 reader_sptr r = reader::create(elf_path,
17895 debug_info_root_paths,
17898 linux_kernel_mode);
17899 return static_pointer_cast<elf_based_reader>(r);
17938 const std::string& elf_path,
17939 const vector<string>&debug_info_root_path,
17940 bool read_all_types,
17941 bool linux_kernel_mode)
17943 reader& r =
dynamic_cast<reader&
>(rdr);
17944 r.initialize(elf_path, debug_info_root_path,
17945 read_all_types, linux_kernel_mode);
17982 const vector<string>& debug_info_root_paths,
17984 bool load_all_types,
17987 elf_based_reader_sptr rdr =
17988 dwarf::reader::create(elf_path, debug_info_root_paths,
17992 return rdr->read_corpus(status);
18013 const string& elf_path,
18014 const string& symbol_name,
18016 vector<elf_symbol_sptr>& syms)
18019 if (elf_version(EV_CURRENT) == EV_NONE)
18022 int fd = open(elf_path.c_str(), O_RDONLY);
18030 Elf* elf = elf_begin(fd, ELF_C_READ, 0);
18034 bool value = lookup_symbol_from_elf(env, elf, symbol_name,
18058 const string& path,
18059 const string& symname,
18060 vector<elf_symbol_sptr>& syms)
18062 if (elf_version(EV_CURRENT) == EV_NONE)
18065 int fd = open(path.c_str(), O_RDONLY);
18073 Elf* elf = elf_begin(fd, ELF_C_READ, 0);
18077 bool value = lookup_public_function_symbol_from_elf(env, elf, symname, syms);