71using std::dynamic_pointer_cast;
72using std::static_pointer_cast;
73using std::unordered_map;
74using std::unordered_set;
82using namespace elf_helpers;
89 NO_DEBUG_INFO_DIE_SOURCE,
90 PRIMARY_DEBUG_INFO_DIE_SOURCE,
91 ALT_DEBUG_INFO_DIE_SOURCE,
93 NUMBER_OF_DIE_SOURCES,
115typedef unordered_map<
void*,
120typedef unordered_map<
void*,
125typedef unordered_map<
void*,
146struct dwarf_addr_pair_hash
151 ABG_ASSERT(
sizeof(
void*) <=
sizeof(uint64_t));
153 hash_t(
reinterpret_cast<uint64_t
>(p.second)));
158 dwarf_addr_pair_hash> dwarf_addr_pair_set_type;
172 dwarf_addr_pair_set_type,
181finish_member_function_reading(Dwarf_Die* die,
183 const class_or_union_sptr klass,
187build_translation_unit_and_add_to_ir(reader& rdr,
192maybe_set_member_type_access_specifier(decl_base_sptr member_type_declaration,
196cleanup_decl_name(
string&);
261struct imported_unit_point
263 void* addr_of_import =
nullptr;
264 void* imported_unit_die_addr =
nullptr;
265 void* imported_unit_child_addr =
nullptr;
271 imported_unit_point(
const void* import_addr)
272 : addr_of_import(
const_cast<void*
>(import_addr))
283 imported_unit_point(
void* import_addr,
const Dwarf_Die& imported_die)
284 : addr_of_import(import_addr),
285 imported_unit_die_addr(imported_die.addr)
287 Dwarf_Die imported_unit_child;
289 ABG_ASSERT(dwarf_child(
const_cast<Dwarf_Die*
>(&imported_die),
290 &imported_unit_child) == 0);
292 imported_unit_child_addr = imported_unit_child.addr;
300typedef unordered_map<void*, imported_unit_points_type>
312operator<(
const imported_unit_point& l,
const imported_unit_point& r)
313{
return l.addr_of_import < r.addr_of_import;}
320get_translation_unit_die_for_die(
const Dwarf_Die* die,
324get_path_of_translation_unit_die(
const Dwarf_Die& tu_die,
325 bool absolute =
false);
328get_comp_dir_of_translation_unit_die(
const Dwarf_Die& tu_die);
331die_is_in_c(
const Dwarf_Die *die);
334die_is_anonymous(
const Dwarf_Die* die);
337die_is_anonymous_data_member(
const Dwarf_Die* die);
340die_is_type(
const Dwarf_Die* die);
343die_is_decl(
const Dwarf_Die* die);
346die_is_declaration_only(Dwarf_Die* die);
349die_is_variable_decl(
const Dwarf_Die *die);
352die_is_virtual(
const Dwarf_Die* die);
355die_is_function_decl(
const Dwarf_Die *die);
358die_is_destructor(
const Dwarf_Die *die);
361die_has_size_attribute(
const Dwarf_Die *die);
364die_is_namespace(
const Dwarf_Die* die);
367die_is_unspecified(Dwarf_Die* die);
370die_is_void_type(Dwarf_Die* die);
373die_is_pointer_type(
const Dwarf_Die* die);
376die_is_reference_type(
const Dwarf_Die* die);
379die_is_pointer_or_reference_type(
const Dwarf_Die* die);
382die_is_class_type(
const Dwarf_Die* die);
385die_has_object_pointer(
const Dwarf_Die* die,
386 Dwarf_Die& object_pointer);
389die_has_children(
const Dwarf_Die* die);
392die_string_attribute(
const Dwarf_Die* die,
unsigned attr_name);
395fn_die_first_parameter_die(
const Dwarf_Die* die, Dwarf_Die& first_parm_die);
398get_member_fn_class_die_from_object_pointer(
const Dwarf_Die* die,
399 Dwarf_Die& class_die,
400 Dwarf_Die& object_ptr_die);
403die_this_pointer_from_object_pointer(Dwarf_Die* die,
404 Dwarf_Die& this_pointer);
407die_this_pointer_is_const(Dwarf_Die* die);
410die_object_pointer_is_for_const_method(Dwarf_Die* die);
413eval_last_constant_dwarf_sub_expr(Dwarf_Op* expr,
416 bool& is_tls_address);
419dwarf_language_to_tu_language(
size_t l);
422die_unsigned_constant_attribute(
const Dwarf_Die* die,
427die_signed_constant_attribute(
const Dwarf_Die*die,
432die_constant_attribute(
const Dwarf_Die *die,
438die_member_offset(
const reader& rdr,
439 const Dwarf_Die* die,
443die_address_attribute(Dwarf_Die* die,
unsigned attr_name, Dwarf_Addr& result);
446die_name(
const Dwarf_Die* die);
449die_name_and_linkage_name(
const Dwarf_Die* die,
451 string& linkage_name);
454die_location_address(Dwarf_Die* die,
456 bool& is_tls_address);
459die_die_attribute(
const Dwarf_Die* die,
462 bool recursively =
true);
465die_origin_die(
const Dwarf_Die* die, Dwarf_Die& origin_die);
468subrange_die_indirectly_references_subrange_die(
const Dwarf_Die *die,
470 Dwarf_Die& referenced_subrange);
472get_internal_anonymous_die_prefix_name(
const Dwarf_Die *die);
475die_peel_qual_ptr(Dwarf_Die *die, Dwarf_Die& peeled_die);
478die_peel_qualified(Dwarf_Die *die, Dwarf_Die& peeled_die);
481die_peel_typedef(Dwarf_Die *die, Dwarf_Die& peeled_die);
484maybe_canonicalize_type(
const type_base_sptr& t,
493 imported_unit_points_type::const_iterator&);
496get_member_child_die(
const Dwarf_Die *die, Dwarf_Die *child);
499get_next_member_sibling_die(
const Dwarf_Die *die, Dwarf_Die *member);
512 ABG_ASSERT(dwarf_diecu(
const_cast<Dwarf_Die*
>(die), &cu_die, 0, 0));
515 if (!die_unsigned_constant_attribute(&cu_die, DW_AT_language, l))
518 lang = dwarf_language_to_tu_language(l);
532get_translation_unit_die_for_die(
const Dwarf_Die* die,
535 ABG_ASSERT(dwarf_diecu(
const_cast<Dwarf_Die*
>(die), &cu_die, 0, 0));
537 Dwarf_Die *testing_die =
const_cast<Dwarf_Die*
>(die);
538 if (dwarf_dieoffset(testing_die) == 0xf9)
540 if (dwarf_dieoffset(&cu_die) != 0xb)
542 std::cerr <<
"Got CU DIE offset "
544 <<dwarf_dieoffset(&cu_die)
564get_path_of_translation_unit_die(
const Dwarf_Die& tu_die,
bool absolute)
566 string path = die_string_attribute(&tu_die, DW_AT_name);
567 if (path ==
"<artificial>")
574 std::ostringstream o;
578 << dwarf_dieoffset(
const_cast<Dwarf_Die*
>(&tu_die));
584 string compilation_dir =
585 get_comp_dir_of_translation_unit_die(tu_die);
586 const string& abs_path =
587 compilation_dir.empty() ? path : compilation_dir +
"/" + path;
600get_comp_dir_of_translation_unit_die(
const Dwarf_Die& tu_die)
602 string compilation_dir = die_string_attribute(&tu_die, DW_AT_comp_dir);
603 return compilation_dir;
614die_is_in_c(
const Dwarf_Die *die)
617 if (!get_die_language(die, l))
634compare_symbol_name(
const string& symbol_name,
643 return symbol_name == name;
672lookup_symbol_from_sysv_hash_tab(
const environment& env,
674 const string& sym_name,
676 size_t sym_tab_index,
678 vector<elf_symbol_sptr>& syms_found)
680 Elf_Scn* sym_tab_section = elf_getscn(elf_handle, sym_tab_index);
683 Elf_Data* sym_tab_data = elf_getdata(sym_tab_section, 0);
686 GElf_Shdr sheader_mem;
687 GElf_Shdr* sym_tab_section_header = gelf_getshdr(sym_tab_section,
689 Elf_Scn* hash_section = elf_getscn(elf_handle, ht_index);
694 unsigned long hash = elf_hash(sym_name.c_str());
695 Elf_Data* ht_section_data = elf_getdata(hash_section, 0);
696 Elf32_Word* ht_data =
reinterpret_cast<Elf32_Word*
>(ht_section_data->d_buf);
697 size_t nb_buckets = ht_data[0];
698 size_t nb_chains = ht_data[1];
706 Elf32_Word* ht_buckets = &ht_data[2];
707 Elf32_Word* ht_chains = &ht_buckets[nb_buckets];
710 size_t bucket =
hash % nb_buckets;
711 size_t symbol_index = ht_buckets[bucket];
714 const char* sym_name_str;
723 ABG_ASSERT(gelf_getsym(sym_tab_data, symbol_index, &symbol));
724 sym_name_str = elf_strptr(elf_handle,
725 sym_tab_section_header->sh_link,
728 && compare_symbol_name(sym_name_str, sym_name, demangle))
734 sym_size = symbol.st_size;
735 elf_symbol::version ver;
746 symbol.st_shndx != SHN_UNDEF,
747 symbol.st_shndx == SHN_COMMON,
748 ver, sym_visibility);
749 syms_found.push_back(symbol_found);
752 symbol_index = ht_chains[symbol_index];
753 }
while (symbol_index != STN_UNDEF || symbol_index >= nb_chains);
764get_elf_class_size_in_bytes(Elf* elf_handle)
770 int c = hdr.e_ident[EI_CLASS];
804bloom_word_at(Elf* elf_handle,
805 Elf32_Word* bloom_filter,
808 Elf64_Xword result = 0;
812 c = h.e_ident[EI_CLASS];
817 result = bloom_filter[index];
821 Elf64_Xword* f=
reinterpret_cast<Elf64_Xword*
>(bloom_filter);
842 size_t first_sym_index;
845 Elf32_Word* bloom_filter;
848 Elf_Scn* sym_tab_section;
849 GElf_Shdr sym_tab_section_header;
879setup_gnu_ht(Elf* elf_handle,
881 size_t sym_tab_index,
884 ht.sym_tab_section = elf_getscn(elf_handle, sym_tab_index);
886 ABG_ASSERT(gelf_getshdr(ht.sym_tab_section, &ht.sym_tab_section_header));
888 ht.sym_tab_section_header.sh_size / ht.sym_tab_section_header.sh_entsize;
889 Elf_Scn* hash_section = elf_getscn(elf_handle, ht_index);
894 Elf_Data* ht_section_data = elf_getdata(hash_section, 0);
895 Elf32_Word* ht_data =
reinterpret_cast<Elf32_Word*
>(ht_section_data->d_buf);
897 ht.nb_buckets = ht_data[0];
898 if (ht.nb_buckets == 0)
902 ht.first_sym_index = ht_data[1];
905 ht.bf_nwords = ht_data[2];
907 ht.shift = ht_data[3];
909 ht.bloom_filter = &ht_data[4];
914 ht.bf_size = (get_elf_class_size_in_bytes(elf_handle) / 4) * ht.bf_nwords;
916 ht.buckets = ht.bloom_filter + ht.bf_size;
918 ht.chain = ht.buckets + ht.nb_buckets;
949lookup_symbol_from_gnu_hash_tab(
const environment& env,
951 const string& sym_name,
953 size_t sym_tab_index,
955 vector<elf_symbol_sptr>& syms_found)
958 if (!setup_gnu_ht(elf_handle, ht_index, sym_tab_index, ht))
964 size_t h1 = elf_gnu_hash(sym_name.c_str());
965 size_t h2 = h1 >> ht.shift;
968 int c = get_elf_class_size_in_bytes(elf_handle) * 8;
969 int n = (h1 / c) % ht.bf_nwords;
975 Elf64_Xword bitmask = (1ul << (h1 % c)) | (1ul << (h2 % c));
978 if ((bloom_word_at(elf_handle, ht.bloom_filter, n) & bitmask) != bitmask)
981 size_t i = ht.buckets[h1 % ht.nb_buckets];
985 Elf32_Word stop_word, *stop_wordp;
986 elf_symbol::version ver;
988 const char* sym_name_str;
997 for (i = ht.buckets[h1 % ht.nb_buckets],
998 stop_wordp = &ht.chain[i - ht.first_sym_index];
1001 < ht.chain + (ht.sym_count - ht.first_sym_index));
1004 stop_word = *stop_wordp;
1005 if ((stop_word & ~ 1)!= (h1 & ~1))
1011 ABG_ASSERT(gelf_getsym(elf_getdata(ht.sym_tab_section, 0),
1013 sym_name_str = elf_strptr(elf_handle,
1014 ht.sym_tab_section_header.sh_link,
1017 && compare_symbol_name(sym_name_str, sym_name, demangle))
1035 sym_type, sym_binding,
1036 symbol.st_shndx != SHN_UNDEF,
1037 symbol.st_shndx == SHN_COMMON,
1038 ver, sym_visibility);
1039 syms_found.push_back(symbol_found);
1081lookup_symbol_from_elf_hash_tab(
const environment& env,
1083 hash_table_kind ht_kind,
1085 size_t symtab_index,
1086 const string& symbol_name,
1088 vector<elf_symbol_sptr>& syms_found)
1090 if (elf_handle == 0 || symbol_name.empty())
1093 if (ht_kind == NO_HASH_TABLE_KIND)
1096 if (ht_kind == SYSV_HASH_TABLE_KIND)
1097 return lookup_symbol_from_sysv_hash_tab(env,
1098 elf_handle, symbol_name,
1103 else if (ht_kind == GNU_HASH_TABLE_KIND)
1104 return lookup_symbol_from_gnu_hash_tab(env,
1105 elf_handle, symbol_name,
1138lookup_symbol_from_symtab(
const environment& env,
1140 const string& sym_name,
1141 size_t sym_tab_index,
1143 vector<elf_symbol_sptr>& syms_found)
1148 Elf_Scn* sym_tab_section = elf_getscn(elf_handle, sym_tab_index);
1151 GElf_Shdr header_mem;
1152 GElf_Shdr * sym_tab_header = gelf_getshdr(sym_tab_section,
1155 size_t symcount = sym_tab_header->sh_size / sym_tab_header->sh_entsize;
1156 Elf_Data* symtab = elf_getdata(sym_tab_section, NULL);
1159 elf_symbol::version ver;
1162 for (
size_t i = 0; i < symcount; ++i)
1165 sym = gelf_getsym(symtab, i, &sym_mem);
1166 name_str = elf_strptr(elf_handle,
1167 sym_tab_header->sh_link,
1170 if (name_str && compare_symbol_name(name_str, sym_name, demangle))
1178 bool sym_is_defined = sym->st_shndx != SHN_UNDEF;
1179 bool sym_is_common = sym->st_shndx == SHN_COMMON;
1188 sym_binding, sym_is_defined,
1189 sym_is_common, ver, sym_visibility);
1190 syms_found.push_back(symbol_found);
1229lookup_symbol_from_elf(
const environment& env,
1231 const string& symbol_name,
1233 vector<elf_symbol_sptr>& syms_found)
1235 size_t hash_table_index = 0, symbol_table_index = 0;
1236 hash_table_kind ht_kind = NO_HASH_TABLE_KIND;
1241 symbol_table_index);
1243 if (ht_kind == NO_HASH_TABLE_KIND)
1248 return lookup_symbol_from_symtab(env,
1256 return lookup_symbol_from_elf_hash_tab(env,
1280lookup_public_function_symbol_from_elf(environment& env,
1282 const string& symbol_name,
1283 vector<elf_symbol_sptr>& func_syms)
1285 vector<elf_symbol_sptr> syms_found;
1288 if (lookup_symbol_from_elf(env, elf_handle, symbol_name,
1291 for (vector<elf_symbol_sptr>::const_iterator i = syms_found.begin();
1292 i != syms_found.end();
1298 if ((type == elf_symbol::FUNC_TYPE
1299 || type == elf_symbol::GNU_IFUNC_TYPE
1300 || type == elf_symbol::COMMON_TYPE)
1301 && (binding == elf_symbol::GLOBAL_BINDING
1302 || binding == elf_symbol::WEAK_BINDING))
1304 func_syms.push_back(*i);
1325 int64_t const_value_;
1333 expr_result(
bool is_const)
1334 : is_const_(is_const),
1338 explicit expr_result(int64_t v)
1364 const_value(int64_t& value)
1368 value = const_value_;
1384 return const_value_;
1387 operator int64_t()
const
1388 {
return const_value();}
1391 operator=(
const int64_t v)
1399 {
return const_value_ == o.const_value_ && is_const_ == o.is_const_;}
1402 operator>=(
const expr_result& o)
const
1403 {
return const_value_ >= o.const_value_;}
1406 operator<=(
const expr_result& o)
const
1407 {
return const_value_ <= o.const_value_;}
1410 operator>(
const expr_result& o)
const
1411 {
return const_value_ > o.const_value_;}
1414 operator<(
const expr_result& o)
const
1415 {
return const_value_ < o.const_value_;}
1420 expr_result r(*
this);
1421 r.const_value_ += v.const_value_;
1422 r.is_const_ = r.is_const_ && v.is_const_;
1427 operator+=(int64_t v)
1434 operator-(
const expr_result& v)
const
1436 expr_result r(*
this);
1437 r.const_value_ -= v.const_value_;
1438 r.is_const_ = r.is_const_ && v.is_const_;
1443 operator%(
const expr_result& v)
const
1445 expr_result r(*
this);
1446 r.const_value_ %= v.const_value_;
1447 r.is_const_ = r.is_const_ && v.is_const();
1452 operator*(
const expr_result& v)
const
1454 expr_result r(*
this);
1455 r.const_value_ *= v.const_value_;
1456 r.is_const_ = r.is_const_ && v.is_const();
1463 expr_result r(*
this);
1464 r.const_value_ |= v.const_value_;
1465 r.is_const_ = r.is_const_ && v.is_const_;
1470 operator^(
const expr_result& v)
const
1472 expr_result r(*
this);
1473 r.const_value_ ^= v.const_value_;
1474 r.is_const_ = r.is_const_ && v.is_const_;
1479 operator>>(
const expr_result& v)
const
1481 expr_result r(*
this);
1482 r.const_value_ = r.const_value_ >> v.const_value_;
1483 r.is_const_ = r.is_const_ && v.is_const_;
1490 expr_result r(*
this);
1491 r.const_value_ = r.const_value_ << v.const_value_;
1492 r.is_const_ = r.is_const_ && v.is_const_;
1499 expr_result r(*
this);
1500 r.const_value_ = ~r.const_value_;
1507 expr_result r(*
this);
1508 r.const_value_ = -r.const_value_;
1515 expr_result r = *
this;
1516 r.const_value_ = std::abs(
static_cast<long double>(r.const_value()));
1523 expr_result r(*
this);
1524 r.const_value_ &= o.const_value_;
1525 r.is_const_ = r.is_const_ && o.is_const_;
1530 operator/(
const expr_result& o)
1532 expr_result r(*
this);
1533 r.is_const_ = r.is_const_ && o.is_const_;
1534 return r.const_value() / o.const_value();
1540class expr_result_stack_type
1542 vector<expr_result> elems_;
1546 expr_result_stack_type()
1547 {elems_.reserve(4);}
1550 operator[](
unsigned i)
1552 unsigned s = elems_.size();
1554 return elems_[s - 1 -i];
1558 operator[](
unsigned i)
const
1559 {
return const_cast<expr_result_stack_type*
>(
this)->
operator[](i);}
1563 {
return elems_.size();}
1565 vector<expr_result>::reverse_iterator
1567 {
return elems_.rbegin();}
1569 const vector<expr_result>::reverse_iterator
1571 {
return const_cast<expr_result_stack_type*
>(
this)->begin();}
1573 vector<expr_result>::reverse_iterator
1575 {
return elems_.rend();}
1577 const vector<expr_result>::reverse_iterator
1579 {
return const_cast<expr_result_stack_type*
>(
this)->end();}
1583 {
return elems_.back();}
1587 {
return const_cast<expr_result_stack_type*
>(
this)->front();}
1590 push_front(expr_result e)
1591 {elems_.push_back(e);}
1596 expr_result r = front();
1602 erase(vector<expr_result>::reverse_iterator i)
1603 {elems_.erase(--i.base());}
1611struct dwarf_expr_eval_context
1614 expr_result_stack_type stack;
1619 dwarf_expr_eval_context()
1623 stack.push_front(expr_result(
true));
1630 stack.push_front(expr_result(
true));
1631 accum = expr_result(
false);
1632 set_tls_addr =
false;
1641 set_tls_address(
bool f)
1650 set_tls_address()
const
1651 {
return set_tls_addr;}
1656 expr_result r = stack.front();
1662 push(
const expr_result& v)
1663 {stack.push_front(v);}
1672typedef shared_ptr<reader> reader_sptr;
1674struct die_parent_relations_builder_task :
public task
1681 die_parent_relations_builder_task(reader& r,
1686 imported_units(iprtd_units)
1689 virtual void perform();
1691 void merge_die_parent_maps();
1696typedef shared_ptr<die_parent_relations_builder_task>
1711 unsigned number_of_suppressed_functions = 0;
1712 unsigned number_of_suppressed_variables = 0;
1713 unsigned number_of_allowed_functions = 0;
1714 unsigned number_of_allowed_variables = 0;
1720 number_of_suppressed_functions = 0;
1721 number_of_suppressed_variables = 0;
1722 number_of_allowed_functions = 0;
1723 number_of_allowed_variables = 0;
1728 struct tu_context_type
1733 list<var_decl_sptr> var_decls_to_add_;
1753 : tu_die_(tu_die), tu_(tu)
1770 {
return scope_stack_;}
1774 {
return scope_stack_;}
1779 if (scope_stack().empty())
1782 scope_stack().push(get_tu()->get_global_scope());
1784 return scope_stack().top();
1787 list<var_decl_sptr>&
1788 var_decls_to_re_add_to_tree()
1789 {
return var_decls_to_add_;}
1791 const list<var_decl_sptr>&
1792 var_decls_to_re_add_to_tree()
const
1793 {
return var_decls_to_add_;}
1804 die_wip_classes_map()
const
1805 {
return die_wip_classes_map_;}
1816 die_wip_classes_map()
1817 {
return die_wip_classes_map_;}
1827 die_addr_is_wip_class(
const void* die_addr)
const
1831 const auto i = die_wip_classes_map().find(
const_cast<void*
>(die_addr));
1832 if (i != die_wip_classes_map().end())
1845 die_is_wip_class(
const Dwarf_Die* die)
const
1848 return die_addr_is_wip_class(die->addr);
1860 mark_class_or_union_die_addr_as_wip(
const void* die_addr,
1861 const class_or_union_sptr& wip_class_or_union)
1864 die_wip_classes_map()[
const_cast<void*
>(die_addr)] =
1865 const_cast<class_or_union_sptr&
>(wip_class_or_union);
1877 mark_class_or_union_die_as_wip(
const Dwarf_Die*die,
1878 const class_or_union_sptr& wip_cou)
1881 mark_class_or_union_die_addr_as_wip(die->addr, wip_cou);
1889 unmark_class_or_union_die_addr_as_wip(
const void* die_addr)
1892 die_class_or_union_map_type::iterator i =
1893 die_wip_classes_map().find(
const_cast<void*
>(die_addr));
1894 if (i != die_wip_classes_map().end())
1895 die_wip_classes_map().erase(i);
1903 unmark_class_or_union_die_as_wip(
const Dwarf_Die* die)
1906 return unmark_class_or_union_die_addr_as_wip(die->addr);
1917 die_wip_function_types_map()
const
1918 {
return const_cast<tu_context_type*
>(
this)->die_wip_function_types_map();}
1928 die_wip_function_types_map()
1929 {
return die_wip_function_types_map_;}
1940 is_wip_function_type_die_address(
const void* addr)
const
1942 die_function_type_map_type::const_iterator i =
1943 die_wip_function_types_map().find(
const_cast<void*
>(addr));
1944 if (i != die_wip_function_types_map().end())
1958 is_wip_function_type_die(
const Dwarf_Die& d)
const
1959 {
return is_wip_function_type_die_address(d.addr);}
1970 is_wip_function_type_die(
const Dwarf_Die* d)
const
1974 return is_wip_function_type_die(*d);
1984 auto i = wip_function_types_.find(f);
1985 if (i != wip_function_types_.end())
1998 mark_function_type_die_addr_as_wip(
const void* die_addr,
2002 die_wip_function_types_map()[
const_cast<void*
>(die_addr)] =
2004 wip_function_types_.insert(t);
2014 mark_function_type_die_as_wip(
const Dwarf_Die*die,
2018 mark_function_type_die_addr_as_wip(die->addr, wip_fn_type);
2027 unmark_function_type_die_addr_as_wip(
const void* die_addr)
2031 die_function_type_map_type::iterator i =
2032 die_wip_function_types_map().find(
const_cast<void*
>(die_addr));
2033 if (i != die_wip_function_types_map().end())
2035 wip_function_types_.erase(i->second);
2036 die_wip_function_types_map().erase(i);
2048 unmark_function_type_die_as_wip(
const Dwarf_Die* die)
2051 return unmark_function_type_die_addr_as_wip(die->addr);
2066 lookup_wip_type_from_die_addr(
void* die_addr)
const
2068 type_base_sptr result;
2071 if ((result = die_addr_is_wip_class(die_addr)))
2075 if ((result = is_wip_function_type_die_address(die_addr)))
2091 lookup_wip_type_from_die(
const Dwarf_Die* die)
const
2095 return lookup_wip_type_from_die_addr(die->addr);
2100 typedef shared_ptr<tu_context_type> tu_context_type_sptr;
2103 die_qualified_name(
const reader& rdr,
const Dwarf_Die* die,
void* where,
2104 reader::tu_context_type_sptr& tu_ctxt,
2105 unordered_set<void*>& guard);
2109 const Dwarf_Die* die,
2110 const string& indent,
2112 bool qualified_names,
2114 reader::tu_context_type_sptr& tu_ctxt,
2115 unordered_set<void*>& infinite_loop_guard);
2119 const Dwarf_Die* die,
2120 const string& indent,
2122 bool qualified_names,
2124 reader::tu_context_type_sptr& tu_ctxt);
2128 const Dwarf_Die* die,
2130 reader::tu_context_type_sptr& tu_ctxt,
2131 unordered_set<void*>& guard);
2135 const Dwarf_Die* die,
2137 reader::tu_context_type_sptr& tu_ctxt,
2138 unordered_set<void*>& infinite_loop_guard);
2142 reader::tu_context_type_sptr& tu_ctxt);
2144 mutable recursive_mutex mutex_;
2146 unsigned short dwarf_version_;
2150 mutable mutex die_qualified_name_maps_mutex_;
2153 mutable recursive_mutex die_pretty_repr_maps_mutex_;
2162 mutable recursive_mutex die_artefact_maps_mutex_;
2167 mutable mutex types_to_canonicalize_mutex_;
2170 mutable mutex decl_only_classes_map_mutex_;
2173 mutable mutex decl_only_enums_map_mutex_;
2176 mutable mutex die_tu_map_mutex_;
2185 mutable recursive_mutex methods_to_finish_reading_mutex_;
2187 mutable stats stats_;
2217 reader(
const string& elf_path,
2249 std::lock_guard<recursive_mutex> lock(mutex_);
2254 die_qualified_name_maps().clear();
2255 die_pretty_repr_maps().clear();
2256 decl_die_artefact_maps().clear();
2257 type_die_artefact_maps().clear();
2258 die_function_decl_with_no_symbol_map().clear();
2259 types_to_canonicalize().clear();
2260 declaration_only_classes().clear();
2261 declaration_only_enums().clear();
2262 die_tu_map().clear();
2265 die_parent_map().clear();
2266 tu_die_imported_unit_points_map_.clear();
2267 clear_per_corpus_data();
2268 load_in_linux_kernel_mode(
options().load_in_linux_kernel_mode);
2281 initialize(
const string& elf_path,
2300 static dwarf::reader_sptr
2301 create(
const std::string& elf_path,
2335 return corpus_sptr();
2354 return corpus_sptr();
2358 corpus_sptr corp = read_debug_info_into_corpus();
2374 create_translation_unit_to_be_populated(
const Dwarf_Die& die,
2380 string path = get_path_of_translation_unit_die(die);
2392 lock_guard<recursive_mutex> lock(mutex_);
2398 string compilation_dir =
2399 get_comp_dir_of_translation_unit_die(die);
2400 tu->set_compilation_dir_path(compilation_dir);
2403 die_unsigned_constant_attribute(&die, DW_AT_language, l);
2404 tu->set_language(dwarf_language_to_tu_language(l));
2411 associate_tu_die_with_tu(&die, tu);
2429 create_tu_building_task(
const Dwarf_Die& tu_die,
char address_size)
2436 create_translation_unit_to_be_populated(tu_die, address_size);
2443 *
this, tu_die, tu));
2456 read_debug_info_into_corpus()
2459 read_debug_info_into_corpus_timer.
start();
2464 origin |= corpus::DWARF_ORIGIN;
2472 env().analyze_exported_interfaces_only(
true);
2474 if (load_all_types())
2475 env().load_all_types(
true);
2477 env().load_all_types(
false);
2479 if (load_undefined_interfaces())
2480 env().analyze_exported_interfaces_only(
false);
2482 env().analyze_exported_interfaces_only(
true);
2493 || !
corpus()->get_symtab()
2494 || !
corpus()->get_symtab()->has_symbols())
2497 uint8_t address_size = 0;
2498 size_t header_size = 0;
2500#ifdef WITH_DEBUG_SELF_COMPARISON
2501 if (env().self_comparison_debug_is_on())
2505 env().set_self_comparison_debug_input(g);
2507 env().set_self_comparison_debug_input(
corpus());
2511 env().priv_->do_log(do_log());
2519 cerr <<
"building die -> parent maps ...\n";
2523 build_die_parent_maps();
2539 cerr <<
"DWARF Reader: building the "
2540 "libabigail internal representation ...\n";
2558 cerr <<
"DWARF Reader: Using "
2560 <<
" threads to construct the internal representations ...\n";
2562 Dwarf_Half dwarf_vers = 0;
2563 unsigned nb_tus = 0;
2564 for (Dwarf_Off offset = 0, next_offset = 0;
2566 offset, &next_offset, &header_size,
2567 &dwarf_vers, NULL, &address_size, NULL,
2569 offset = next_offset)
2571 Dwarf_Off die_offset = offset + header_size;
2575 || dwarf_tag(&unit) != DW_TAG_compile_unit)
2578 dwarf_version(dwarf_vers);
2585 create_tu_building_task(unit, address_size);
2603 cerr <<
"DWARF Reader: building "
2604 <<
"the libabigail internal representation for "
2605 << nb_tus <<
" translation units "
2607 <<
" which ended up with "
2609 <<
" translation units in: "
2613 cerr <<
"DWARF Reader: Number of suppressed functions: "
2614 << stats_.number_of_suppressed_functions <<
"\n"
2615 <<
"Number of allowed functions: "
2616 << stats_.number_of_allowed_functions <<
"\n"
2617 <<
"Total number of fns in the corpus: "
2619 <<
"Total number of variables in the corpus: "
2629 cerr <<
"DWARF Reader: finish reading some methods sequentially ...";
2633 finish_reading_scheduled_methods();
2649 cerr <<
"DWARF Reader: resolving declaration only classes ...";
2652 resolve_declaration_only_classes();
2667 cerr <<
"resolving declaration only enums ...";
2670 resolve_declaration_only_enums();
2685 cerr <<
"DWARF Reader: fixing up functions with linkage name but "
2686 <<
"no advertised underlying symbols ....";
2689 fixup_functions_with_no_symbols();
2715 cerr <<
"DWARF Reader: perform late type canonicalizing ...\n";
2719 perform_late_type_canonicalizing();
2724 cerr <<
"DWARF Reader: late type canonicalizing DONE for "
2736 cerr <<
"DWARF Reader: sort functions and variables ...";
2743 corpus()->mark_non_reachable_types();
2748 read_debug_info_into_corpus_timer.
stop();
2754 cerr <<
"DWARF Reader: loaded debug info and built ABI corpus IR in: "
2755 << read_debug_info_into_corpus_timer <<
" \n";
2765 clear_per_corpus_data()
2767 die_qualified_name_maps().clear();
2768 die_pretty_repr_maps().clear();
2769 clear_types_to_canonicalize();
2773 die_qualified_name_maps()
const
2774 {
return die_qualified_name_maps_;}
2777 die_qualified_name_maps()
2778 {
return die_qualified_name_maps_;}
2781 set_die_qualified_name(
const void* die_addr,
interned_string istr)
const
2784 std::lock_guard<mutex> lock(die_qualified_name_maps_mutex_);
2785 die_qualified_name_maps_[
const_cast<void*
>(die_addr)] = istr;
2789 die_pretty_repr_maps()
const
2790 {
return die_pretty_repr_maps_;}
2793 die_pretty_repr_maps()
2794 {
return die_pretty_repr_maps_;}
2800 std::lock_guard<recursive_mutex> lock(die_pretty_repr_maps_mutex_);
2801 die_pretty_repr_maps_[
const_cast<void*
>(die_addr)] = istr;
2816 {
return const_cast<reader*
>(
this)->env();}
2824 drop_undefined_syms()
const
2825 {
return options().drop_undefined_syms;}
2832 drop_undefined_syms(
bool f)
2833 {
options().drop_undefined_syms = f;}
2837 dwarf_version()
const
2839 std::lock_guard<recursive_mutex> lock(mutex_);
2840 return dwarf_version_;
2844 dwarf_version(
unsigned short v)
2846 std::lock_guard<recursive_mutex> lock(mutex_);
2860 dwarf_elf_handle()
const
2871 dwarf_is_splitted()
const
2886 get_die_source(
const Dwarf_Die *die)
const
2888 die_source source = NO_DEBUG_INFO_DIE_SOURCE;
2909 get_die_source(
const Dwarf_Die &die,
die_source &source)
const
2913 uint8_t address_size = 0, offset_size = 0;
2914 if (!dwarf_diecu(
const_cast<Dwarf_Die*
>(&die),
2915 &cu_die, &address_size,
2919 Dwarf_Half version = 0;
2920 Dwarf_Off abbrev_offset = 0;
2921 uint64_t type_signature = 0;
2922 Dwarf_Off type_offset = 0;
2923 if (!dwarf_cu_die(cu_die.cu, &cu_kind,
2924 &version, &abbrev_offset,
2925 &address_size, &offset_size,
2926 &type_signature, &type_offset))
2929 int tag = dwarf_tag(&cu_kind);
2932 if (tag == DW_TAG_compile_unit
2933 || tag == DW_TAG_partial_unit)
2935 const Dwarf *die_dwarf = dwarf_cu_getdwarf(cu_die.cu);
2937 source = PRIMARY_DEBUG_INFO_DIE_SOURCE;
2939 source = ALT_DEBUG_INFO_DIE_SOURCE;
2943 else if (tag == DW_TAG_type_unit)
2944 source = TYPE_UNIT_DIE_SOURCE;
2958 dwarf_per_die_source(
die_source source)
const
2960 const Dwarf *result = 0;
2963 case PRIMARY_DEBUG_INFO_DIE_SOURCE:
2964 case TYPE_UNIT_DIE_SOURCE:
2967 case ALT_DEBUG_INFO_DIE_SOURCE:
2970 case NO_DEBUG_INFO_DIE_SOURCE:
2971 case NUMBER_OF_DIE_SOURCES:
2994 get_die_from_addr(
const void* die_addr, Dwarf_Die& die)
const
2996 Dwarf_Die *result =
nullptr;
2997 void* addr =
const_cast<void*
>(die_addr);
2999 if (!debug_info || !addr)
3002 result = dwarf_die_addr_die(debug_info, addr, &die);
3009 result = dwarf_die_addr_die(debug_info, addr, &die);
3016 int tag = dwarf_tag(&die);
3045 get_parent_die(
const Dwarf_Die* die,
3046 Dwarf_Die& parent_die,
3048 reader::tu_context_type_sptr& tu_ctxt)
const
3053 addr_addr_phmap_type::const_iterator i = m.find(die->addr);
3058 get_die_from_addr(i->second, parent_die);
3060 if (dwarf_tag(&parent_die) == DW_TAG_partial_unit)
3062 if (where_addr ==
nullptr)
3064 parent_die = *tu_ctxt->get_die();
3067 void* import_point_addr =
nullptr;
3068 bool found = find_import_unit_point_before_die(parent_die.addr,
3069 where_addr, tu_ctxt,
3076 parent_die = *tu_ctxt->get_die();
3080 Dwarf_Die import_point_die;
3081 ABG_ASSERT(get_die_from_addr(import_point_addr,
3083 return get_parent_die(&import_point_die,
3084 parent_die, where_addr,
3118 get_scope_die(
const Dwarf_Die* dye,
3120 reader::tu_context_type_sptr& tu_ctxt,
3121 Dwarf_Die& scope_die)
const
3123 Dwarf_Die origin_die_mem;
3124 Dwarf_Die *die = &origin_die_mem;
3125 if (!die_origin_die(dye, origin_die_mem))
3126 memcpy(&origin_die_mem, dye,
sizeof(origin_die_mem));
3129 get_die_language(die, die_lang);
3132 ABG_ASSERT(dwarf_tag(
const_cast<Dwarf_Die*
>(die)) != DW_TAG_member);
3133 return get_translation_unit_die_for_die(die, scope_die);
3136 if (!get_parent_die(die, scope_die, where_addr, tu_ctxt))
3139 if (dwarf_tag(&scope_die) == DW_TAG_array_type)
3142 return get_scope_die(&scope_die, where_addr, tu_ctxt, scope_die);
3182 find_import_unit_point_between_dies(
void* partial_unit_addr,
3183 void* first_die_addr,
3184 void* last_die_addr,
3185 void*& imported_point_addr)
const
3188 tu_die_imported_unit_points_map();
3190 Dwarf_Die first_die, first_die_cu;
3191 ABG_ASSERT(get_die_from_addr(first_die_addr, first_die));
3192 ABG_ASSERT(dwarf_diecu(&first_die, &first_die_cu, 0, 0));
3193 void *first_die_cu_addr = first_die_cu.addr;
3195 tu_die_imported_unit_points_map_type::const_iterator iter =
3196 m.find(first_die_cu_addr);
3201 if (imported_unit_points.empty())
3204 imported_unit_points_type::const_iterator b = imported_unit_points.begin();
3205 imported_unit_points_type::const_iterator e = imported_unit_points.end();
3207 find_lower_bound_in_imported_unit_points(imported_unit_points,
3211 if (last_die_addr !=
nullptr)
3212 find_lower_bound_in_imported_unit_points(imported_unit_points,
3216 if (e != imported_unit_points.end())
3218 for (imported_unit_points_type::const_iterator i = e; i >= b; --i)
3219 if (i->imported_unit_die_addr == partial_unit_addr)
3221 imported_point_addr = i->addr_of_import ;
3225 for (imported_unit_points_type::const_iterator i = e; i >= b; --i)
3227 if (find_import_unit_point_between_dies(partial_unit_addr,
3228 i->imported_unit_child_addr,
3230 imported_point_addr))
3236 for (imported_unit_points_type::const_iterator i = b; i != e; ++i)
3237 if (i->imported_unit_die_addr == partial_unit_addr)
3239 imported_point_addr = i->addr_of_import ;
3243 for (imported_unit_points_type::const_iterator i = b; i != e; ++i)
3245 if (find_import_unit_point_between_dies(partial_unit_addr,
3246 i->imported_unit_child_addr,
3248 imported_point_addr))
3281 find_import_unit_point_before_die(
void* partial_unit_addr,
3283 reader::tu_context_type_sptr& tu_ctxt,
3284 void*& imported_point_addr)
const
3286 void* import_point_addr =
nullptr;
3287 Dwarf_Die first_die_of_tu;
3289 if (dwarf_child(
const_cast<Dwarf_Die*
>(tu_ctxt->get_die()),
3290 &first_die_of_tu) != 0)
3293 if (find_import_unit_point_between_dies(partial_unit_addr,
3294 first_die_of_tu.addr,
3295 where_addr, import_point_addr))
3297 imported_point_addr = import_point_addr;
3301 if (import_point_addr)
3303 imported_point_addr = import_point_addr;
3321 maybe_associate_die_to_decl(Dwarf_Die* die, decl_base_sptr decl)
3326 std::lock_guard<recursive_mutex> lock(die_artefact_maps_mutex_);
3328 void* die_addr = die->addr;
3329 auto it = m.find(die_addr);
3347 lookup_decl_from_die_addr(
void* die_addr)
3349 decl_base_sptr result =
3350 is_decl(lookup_artifact_from_die_addr(die_addr,
false));
3374 get_die_qualified_name(Dwarf_Die *die,
void* where_addr,
3375 reader::tu_context_type_sptr& tu_ctxt,
3376 unordered_set<void*>& guard)
const
3381 void* die_addr = die->addr;
3382 die_istring_map_type::const_iterator i = map.find(die_addr);
3386 reader& rdr = *
const_cast<reader*
>(
this);
3387 string qualified_name = die_qualified_name(rdr, die, where_addr,
3390 set_die_qualified_name(die_addr, istr);
3421 get_die_qualified_type_name(
const Dwarf_Die *die,
void* where_addr,
3422 reader::tu_context_type_sptr& tu_ctxt,
3423 unordered_set<void*>& guard)
const
3428 if (die == tu_ctxt->get_die())
3429 return env().intern(
"");
3432 die_istring_map_type::const_iterator i = map.find(die->addr);
3436 reader& rdr = *
const_cast<reader*
>(
this);
3437 string qualified_name;
3438 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
3439 if ((tag == DW_TAG_structure_type
3440 || tag == DW_TAG_class_type
3441 || tag == DW_TAG_union_type)
3442 && die_is_anonymous(die))
3447 where_addr, tu_ctxt, guard);
3453 set_die_qualified_name(die->addr, istr);
3479 get_die_pretty_representation(
const Dwarf_Die *die,
void* where_addr,
3480 reader::tu_context_type_sptr& tu_ctxt,
3481 unordered_set<void*>& guard)
const
3486 lock_guard<recursive_mutex> lock(die_pretty_repr_maps_mutex_);
3487 die_istring_map_type::const_iterator i = map.find(die->addr);
3491 reader& rdr = *
const_cast<reader*
>(
this);
3492 string pretty_representation =
3495 set_die_pretty_repr(die->addr, istr);
3515 get_die_pretty_representation(
const Dwarf_Die *die,
void* where_offset,
3516 reader::tu_context_type_sptr& tu_ctxt)
const
3518 unordered_set<void*> guard;
3519 return get_die_pretty_representation(die, where_offset, tu_ctxt, guard);
3539 lookup_type_artifact_from_die(Dwarf_Die *die)
const
3542 lookup_artifact_from_die(die,
true);
3544 return fn->get_type();
3565 has_scope_of_die_been_associated(
const Dwarf_Die* die,
3567 reader::tu_context_type_sptr& tu_ctxt)
3571 if (get_scope_die(die, where_addr, tu_ctxt, scope))
3573 if (die_is_type(&scope))
3574 if (lookup_type_artifact_from_die(&scope))
3600 lookup_artifact_from_die(
const Dwarf_Die *die,
bool die_as_type =
false)
const
3602 lock_guard<recursive_mutex> lock(die_artefact_maps_mutex_);
3604 die_as_type ? type_die_artefact_maps() : decl_die_artefact_maps();
3606 die_artefact_map_type::const_iterator i = m.find(die->addr);
3633 lookup_artifact_from_die_addr(
void* die_addr,
3634 bool die_as_type =
false)
const
3636 lock_guard<recursive_mutex> lock(die_artefact_maps_mutex_);
3638 die_as_type ? type_die_artefact_maps() : decl_die_artefact_maps();
3640 die_artefact_map_type::const_iterator i = m.find(die_addr);
3684 odr_is_relevant(
const Dwarf_Die *die, tu_context_type_sptr& tu_ctxt)
const
3687 if (!get_die_language(die, lang))
3699 decl_die_artefact_maps()
3700 {
return decl_die_artefact_maps_;}
3708 decl_die_artefact_maps()
const
3709 {
return decl_die_artefact_maps_;}
3717 type_die_artefact_maps()
3718 {
return type_die_artefact_maps_;}
3726 type_die_artefact_maps()
const
3727 {
return type_die_artefact_maps_;}
3748 maybe_associate_die_to_type(
const Dwarf_Die* die,
const type_base_sptr type)
3753 std::lock_guard<recursive_mutex> lock(die_artefact_maps_mutex_);
3755 auto it = m.find(die->addr);
3758 m[die->addr] = type;
3770 die_function_decl_with_no_symbol_map()
3771 {
return die_function_with_no_symbol_map_;}
3774 record_a_fn_decl_with_no_symbol(
const Dwarf_Die* die,
3777 if (!die || !fn_decl)
3780 std::lock_guard<recursive_mutex> lock(mutex_);
3781 auto i = die_function_decl_with_no_symbol_map().find(die->addr);
3782 if (i == die_function_decl_with_no_symbol_map().end())
3783 die_function_decl_with_no_symbol_map()[die->addr] = fn_decl;
3802 build_name_for_buggy_anonymous_data_member(Dwarf_Die *die,
3803 tu_context_type_sptr& tu_ctxt)
3809 || dwarf_tag(die) != DW_TAG_member
3810 || !die_name(die).empty())
3816 if (die_is_anonymous_data_member(die))
3822 int64_t offset_in_bits = 0;
3823 bool has_offset = die_member_offset(*
this, die, offset_in_bits);
3832 std::ostringstream o;
3833 o <<
"unnamed-dm-@-";
3835 o <<
"offset-" << offset_in_bits <<
"bits";
3837 o <<
"loc-" << loc.
expand();
3850 declaration_only_classes()
const
3851 {
return decl_only_classes_map_;}
3861 declaration_only_classes()
3862 {
return decl_only_classes_map_;}
3865 get_a_declaration_only_class(
const string& qualified_name)
3867 std::lock_guard<mutex> lock(decl_only_classes_map_mutex_);
3869 auto i = declaration_only_classes().find(qualified_name);
3870 if (i != declaration_only_classes().end())
3871 return i->second.back();
3886 maybe_schedule_declaration_only_class_for_resolution(cou);
3888 maybe_schedule_declaration_only_enum_for_resolution(e);
3897 maybe_schedule_declaration_only_class_for_resolution(
const class_or_union_sptr& cou)
3899 if (cou->get_is_declaration_only()
3900 && cou->get_definition_of_declaration() == 0
3905 && !cou->get_qualified_name().empty())
3907 string qn = cou->get_qualified_name();
3909 std::lock_guard<mutex> lock(decl_only_classes_map_mutex_);
3910 string_classes_or_unions_map::iterator record =
3911 declaration_only_classes().find(qn);
3912 if (record == declaration_only_classes().end())
3913 declaration_only_classes()[qn].push_back(cou);
3915 record->second.push_back(cou);
3927 is_decl_only_class_scheduled_for_resolution(
const class_or_union_sptr& cou)
3929 if (cou->get_is_declaration_only())
3931 std::lock_guard<mutex> lock(decl_only_classes_map_mutex_);
3932 return ((declaration_only_classes().find(cou->get_qualified_name())
3933 != declaration_only_classes().end())
3934 || (declaration_only_classes().find(cou->get_name())
3935 != declaration_only_classes().end()));
3960 bool canonicalization_is_done =
false;
3962 auto l_abi = l->get_corpus();
3963 auto r_abi = r->get_corpus();
3965 if ((l_abi && l_abi->priv_->types_are_canonicalized())
3966 || (r_abi && r_abi->priv_->types_are_canonicalized()))
3967 canonicalization_is_done =
true;
3972 && l->
kind() == r->kind()
3974 && (l_abi == r_abi))
3975 ||(l->get_translation_unit()
3976 && r->get_translation_unit()
3977 && l->get_translation_unit() == r->get_translation_unit())))
3996 string l2 = rl.expand();
4002 e.priv_->allow_type_comparison_results_caching(
true);
4005 bool equal = l == r;
4007 e.priv_->clear_type_comparison_results_cache();
4008 e.priv_->allow_type_comparison_results_caching(
false);
4015 resolve_declaration_only_classes()
4017 std::lock_guard<mutex> lock(decl_only_classes_map_mutex_);
4018 vector<string> resolved_classes;
4019 for (string_classes_or_unions_map::iterator i =
4020 declaration_only_classes().begin();
4021 i != declaration_only_classes().end();
4024 bool to_resolve =
false;
4025 for (classes_or_unions_type::iterator j = i->second.begin();
4026 j != i->second.end();
4028 if ((*j)->get_is_declaration_only()
4029 && ((*j)->get_definition_of_declaration() == 0))
4034 resolved_classes.push_back(i->first);
4079 map<string, class_or_union_sptr> per_tu_class_map;
4080 for (type_base_wptrs_type::const_iterator c = classes->begin();
4081 c != classes->end();
4088 if (klass->get_is_declaration_only())
4091 string tu_path = klass->get_translation_unit()->get_absolute_path();
4092 if (tu_path.empty())
4098 per_tu_class_map[tu_path] = klass;
4101 if (!per_tu_class_map.empty())
4107 for (classes_or_unions_type::iterator j = i->second.begin();
4108 j != i->second.end();
4111 if ((*j)->get_is_declaration_only()
4112 && ((*j)->get_definition_of_declaration() == 0))
4115 (*j)->get_translation_unit()->get_absolute_path();
4116 map<string, class_or_union_sptr>::const_iterator e =
4117 per_tu_class_map.find(tu_path);
4118 if (e != per_tu_class_map.end())
4119 (*j)->set_definition_of_declaration(e->second);
4120 else if (per_tu_class_map.size() == 1)
4121 (*j)->set_definition_of_declaration
4122 (per_tu_class_map.begin()->second);
4132 class_or_union_sptr>::const_iterator it;
4133 class_or_union_sptr first_class =
4134 per_tu_class_map.begin()->second;
4135 bool all_class_definitions_are_equal =
true;
4136 for (it = per_tu_class_map.begin();
4137 it != per_tu_class_map.end();
4140 if (it == per_tu_class_map.begin())
4144 if (!compare_before_canonicalisation(it->second,
4147 all_class_definitions_are_equal =
false;
4152 if (all_class_definitions_are_equal)
4153 (*j)->set_definition_of_declaration(first_class);
4157 resolved_classes.push_back(i->first);
4161 size_t num_decl_only_classes = declaration_only_classes().size(),
4162 num_resolved = resolved_classes.size();
4164 cerr <<
"resolved " << num_resolved
4165 <<
" class declarations out of "
4166 << num_decl_only_classes
4169 for (vector<string>::const_iterator i = resolved_classes.begin();
4170 i != resolved_classes.end();
4172 declaration_only_classes().erase(*i);
4174 if (show_stats() && !declaration_only_classes().empty())
4176 cerr <<
"Here are the "
4177 << num_decl_only_classes - num_resolved
4178 <<
" unresolved class declarations:\n";
4179 for (string_classes_or_unions_map::iterator i =
4180 declaration_only_classes().begin();
4181 i != declaration_only_classes().end();
4183 cerr <<
" " << i->first <<
"\n";
4195 declaration_only_enums()
const
4196 {
return decl_only_enums_map_;}
4206 declaration_only_enums()
4207 {
return decl_only_enums_map_;}
4210 get_a_declaration_only_enum(
const string& qualified_name)
4212 auto i = declaration_only_enums().find(qualified_name);
4213 if (i != declaration_only_enums().end())
4214 return i->second.back();
4227 if (enom->get_is_declaration_only()
4228 && enom->get_definition_of_declaration() == 0
4233 && !enom->get_qualified_name().empty())
4235 string qn = enom->get_qualified_name();
4236 std::lock_guard<mutex> lock(decl_only_enums_map_mutex_);
4237 string_enums_map::iterator record =
4238 declaration_only_enums().find(qn);
4239 if (record == declaration_only_enums().end())
4240 declaration_only_enums()[qn].push_back(enom);
4242 record->second.push_back(enom);
4256 if (enom->get_is_declaration_only())
4257 return (declaration_only_enums().find(enom->get_qualified_name())
4258 != declaration_only_enums().end());
4271 resolve_declaration_only_enums()
4273 vector<string> resolved_enums;
4275 std::lock_guard<mutex> lock(decl_only_enums_map_mutex_);
4277 for (string_enums_map::iterator i =
4278 declaration_only_enums().begin();
4279 i != declaration_only_enums().end();
4282 bool to_resolve =
false;
4283 for (enums_type::iterator j = i->second.begin();
4284 j != i->second.end();
4286 if ((*j)->get_is_declaration_only()
4287 && ((*j)->get_definition_of_declaration() == 0))
4292 resolved_enums.push_back(i->first);
4334 map<string, enum_type_decl_sptr> per_tu_enum_map;
4335 for (type_base_wptrs_type::const_iterator c = enums->begin();
4343 if (enom->get_is_declaration_only())
4346 string tu_path = enom->get_translation_unit()->get_absolute_path();
4347 if (tu_path.empty())
4353 per_tu_enum_map[tu_path] = enom;
4356 if (!per_tu_enum_map.empty())
4362 for (enums_type::iterator j = i->second.begin();
4363 j != i->second.end();
4366 if ((*j)->get_is_declaration_only()
4367 && ((*j)->get_definition_of_declaration() == 0))
4370 (*j)->get_translation_unit()->get_absolute_path();
4371 map<string, enum_type_decl_sptr>::const_iterator e =
4372 per_tu_enum_map.find(tu_path);
4373 if (e != per_tu_enum_map.end())
4374 (*j)->set_definition_of_declaration(e->second);
4375 else if (per_tu_enum_map.size() == 1)
4376 (*j)->set_definition_of_declaration
4377 (per_tu_enum_map.begin()->second);
4389 per_tu_enum_map.begin()->second;
4390 bool all_enum_definitions_are_equal =
true;
4391 for (it = per_tu_enum_map.begin();
4392 it != per_tu_enum_map.end();
4395 if (it == per_tu_enum_map.begin())
4399 if (!compare_before_canonicalisation(it->second,
4402 all_enum_definitions_are_equal =
false;
4407 if (all_enum_definitions_are_equal)
4408 (*j)->set_definition_of_declaration(first_enum);
4412 resolved_enums.push_back(i->first);
4416 size_t num_decl_only_enums = declaration_only_enums().size(),
4417 num_resolved = resolved_enums.size();
4419 cerr <<
"resolved " << num_resolved
4420 <<
" enum declarations out of "
4421 << num_decl_only_enums
4424 for (vector<string>::const_iterator i = resolved_enums.begin();
4425 i != resolved_enums.end();
4427 declaration_only_enums().erase(*i);
4429 if (show_stats() && !declaration_only_enums().empty())
4431 cerr <<
"Here are the "
4432 << num_decl_only_enums - num_resolved
4433 <<
" unresolved enum declarations:\n";
4434 for (string_enums_map::iterator i = declaration_only_enums().begin();
4435 i != declaration_only_enums().end();
4437 cerr <<
" " << i->first <<
"\n";
4453 corpus_sptr corp =
corpus();
4457 interned_string id = corp->get_environment().intern(fn->get_id_string());
4459 const std::unordered_set<const function_decl*> *fns = corp->lookup_functions(
id);
4464 if (f->get_symbol())
4488 fixup_functions_with_no_symbols()
4490 corpus_sptr corp =
corpus();
4495 die_function_decl_with_no_symbol_map();
4497 if (fns_with_no_symbol.empty())
4501 cerr << fns_with_no_symbol.size()
4502 <<
" functions to fixup, potentially\n";
4504 std::lock_guard<recursive_mutex> lock(mutex_);
4506 for (die_function_decl_map_type::iterator i = fns_with_no_symbol.begin();
4507 i != fns_with_no_symbol.end();
4510 corp->lookup_function_symbol(i->second->get_linkage_name()))
4528 i->second->set_symbol(sym);
4530 if (do_log() && show_stats())
4531 cerr <<
"fixed up '"
4532 << i->second->get_pretty_representation()
4533 <<
"' with symbol '"
4534 << sym->get_id_string()
4538 fns_with_no_symbol.clear();
4544 types_to_canonicalize()
const
4545 {
return types_to_canonicalize_;}
4550 types_to_canonicalize()
4551 {
return types_to_canonicalize_;}
4555 clear_types_to_canonicalize()
4557 types_to_canonicalize().clear();
4565 schedule_type_for_late_canonicalization(
const type_base_sptr &t)
4567 std::lock_guard<mutex> lock(types_to_canonicalize_mutex_);
4568 types_to_canonicalize().insert(t);
4574 unschedule_type_from_late_canonicalization(
const type_base_sptr &t)
4576 std::lock_guard<mutex> lock(types_to_canonicalize_mutex_);
4577 types_to_canonicalize().erase(t);
4586 canonicalize_types_scheduled()
4591 cerr <<
"DWARF Reader canonicalizing "
4593 << types_to_canonicalize().size()
4595 corpus_sptr c =
corpus();
4601 vector<type_base_sptr> types;
4602 types.reserve(types_to_canonicalize().size());
4606 type_base_sptr t = wt.lock();
4613 corpus()->priv_->types_are_canonicalized(
true);
4618 const environment& env = types.front()->get_environment();
4619 cerr <<
"DWARF Reader finished types "
4620 <<
"sorting, hashing & canonicalizing in: "
4623 << env.priv_->get_number_of_canonical_types()
4641 add_late_canonicalized_types_stats(
size_t& canonicalized,
4642 size_t& missed)
const
4644 std::lock_guard<mutex> lock(types_to_canonicalize_mutex_);
4648 type_base_sptr t = wt.lock();
4649 if (t && t->get_canonical_type())
4651 else if (t && !t->get_canonical_type())
4659 perform_late_type_canonicalizing()
4661 canonicalize_types_scheduled();
4665 size_t num_canonicalized = 0, num_missed = 0, total = 0;
4666 add_late_canonicalized_types_stats(num_canonicalized,
4668 total = num_canonicalized + num_missed;
4672 cerr <<
" # late canonicalized types: "
4673 << num_canonicalized;
4675 cerr <<
" (" << num_canonicalized * 100 / total <<
"%)";
4677 <<
" # missed canonicalization opportunities: "
4680 cerr <<
" (" << num_missed * 100 / total <<
"%)";
4699 get_translation_unit_for_die(
const Dwarf_Die* die)
4705 ABG_ASSERT(dwarf_diecu(
const_cast<Dwarf_Die*
>(die), &cu_die, 0, 0));
4708 result = get_translation_unit_for_tu_die(&cu_die);
4714 get_translation_unit_for_tu_die(
const Dwarf_Die* die)
4719 std::lock_guard<mutex> lock(die_tu_map_mutex_);
4720 auto i = die_tu_map().find(die->addr);
4721 if (i == die_tu_map().end())
4732 if (!get_translation_unit_for_tu_die(die))
4734 std::lock_guard<mutex> lock(die_tu_map_mutex_);
4735 die_tu_map()[die->addr] = tu;
4746 tu_die_imported_unit_points_map()
const
4747 {
return const_cast<reader*
>(
this)->tu_die_imported_unit_points_map();}
4756 tu_die_imported_unit_points_map()
4757 {
return tu_die_imported_unit_points_map_;}
4774 {
return die_parent_map_;}
4783 die_parent_map()
const
4784 {
return die_parent_map_;}
4787 methods_to_finish_reading()
const
4788 {
return methods_to_finish_reading_;}
4791 methods_to_finish_reading()
4792 {
return methods_to_finish_reading_;}
4795 schedule_method_to_finish_reading(Dwarf_Die& method_die,
4798 lock_guard<recursive_mutex> lock(methods_to_finish_reading_mutex_);
4799 methods_to_finish_reading()[method_die.addr] = method;
4803 finish_reading_scheduled_methods()
4805 lock_guard<recursive_mutex> lock(methods_to_finish_reading_mutex_);
4806 for (
auto& entry : methods_to_finish_reading())
4809 ABG_ASSERT(get_die_from_addr(entry.first, die));
4810 auto fn = entry.second;
4813 finish_member_function_reading(&die, entry.second,
4823 {
return tu_ctxt.get_tu()->get_global_scope();}
4826 global_scope(
const tu_context_type_sptr& tu_ctxt)
const
4834 {
return nil_scope_;}
4837 current_scope(tu_context_type& ctxt)
4839 return ctxt.current_scope();
4843 current_scope(tu_context_type_sptr& ctxt)
4844 {
return current_scope(*ctxt);}
4857 is_decl_die_with_exported_symbol(
const Dwarf_Die *die)
const
4859 if (!die || !die_is_decl(die))
4862 bool result =
false, address_found =
false, symbol_is_exported =
false;;
4863 Dwarf_Addr decl_symbol_address = 0;
4865 if (die_is_variable_decl(die))
4867 if ((address_found = get_variable_address(die, decl_symbol_address)))
4868 symbol_is_exported =
4871 else if (die_is_function_decl(die))
4873 if ((address_found = get_function_address(die, decl_symbol_address)))
4874 symbol_is_exported =
4879 result = symbol_is_exported;
4890 is_decl_die_with_undefined_symbol(
const Dwarf_Die *die)
const
4892 if (is_decl_die_with_exported_symbol(die))
4895 string name, linkage_name;
4896 die_name_and_linkage_name(die, name, linkage_name);
4897 if (linkage_name.empty())
4898 linkage_name = name;
4900 bool result =
false;
4901 if ((die_is_variable_decl(die)
4904 (die_is_function_decl(die)
4925 maybe_adjust_address_for_exec_or_dyn(Dwarf_Addr addr)
const
4931 GElf_Ehdr *elf_header = gelf_getehdr(
elf_handle(), &eh_mem);
4933 if (elf_header->e_type == ET_DYN || elf_header->e_type == ET_EXEC)
4935 Dwarf_Addr dwarf_elf_load_address = 0, elf_load_address = 0;
4937 dwarf_elf_load_address)
4940 if (dwarf_is_splitted()
4941 && (dwarf_elf_load_address != elf_load_address))
4952 addr = addr - dwarf_elf_load_address + elf_load_address;
4978 maybe_adjust_fn_sym_address(Dwarf_Addr addr)
const
4985 GElf_Ehdr* elf_header = gelf_getehdr(elf, &eh_mem);
4987 if (elf_header->e_type == ET_REL)
5000 addr = maybe_adjust_address_for_exec_or_dyn(addr);
5025 maybe_adjust_var_sym_address(Dwarf_Addr addr)
const
5029 GElf_Ehdr* elf_header = gelf_getehdr(elf, &eh_mem);
5031 if (elf_header->e_type == ET_REL)
5044 addr = maybe_adjust_address_for_exec_or_dyn(addr);
5063 get_first_exported_fn_address_from_DW_AT_ranges(Dwarf_Die* die,
5064 Dwarf_Addr& address)
const
5067 Dwarf_Addr end_addr;
5068 ptrdiff_t offset = 0;
5072 Dwarf_Addr addr = 0, fn_addr = 0;
5073 if ((offset = dwarf_ranges(die, offset, &base, &addr, &end_addr)) >= 0)
5075 fn_addr = maybe_adjust_fn_sym_address(addr);
5082 }
while (offset > 0);
5100 get_function_address(
const Dwarf_Die* function_die, Dwarf_Addr& address)
const
5102 if (!die_address_attribute(
const_cast<Dwarf_Die*
>(function_die),
5103 DW_AT_low_pc, address))
5109 if (!get_first_exported_fn_address_from_DW_AT_ranges
5110 (
const_cast<Dwarf_Die*
>(function_die),
5114 address = maybe_adjust_fn_sym_address(address);
5125 function_has_address(
const Dwarf_Die* function_die)
const
5127 if (!function_die || dwarf_tag(
const_cast<Dwarf_Die*
>(function_die)) != DW_TAG_subprogram)
5130 Dwarf_Addr address = 0;
5131 if (get_function_address(function_die, address))
5152 get_variable_address(
const Dwarf_Die* variable_die,
5153 Dwarf_Addr& address)
const
5155 bool is_tls_address =
false;
5156 if (!die_location_address(
const_cast<Dwarf_Die*
>(variable_die),
5157 address, is_tls_address))
5159 if (!is_tls_address)
5160 address = maybe_adjust_var_sym_address(address);
5168 exported_decls_builder()
5177 load_all_types()
const
5178 {
return options().load_all_types;}
5186 load_all_types(
bool f)
5187 {
options().load_all_types = f;}
5190 load_in_linux_kernel_mode()
const
5191 {
return options().load_in_linux_kernel_mode;}
5194 load_in_linux_kernel_mode(
bool f)
5195 {
options().load_in_linux_kernel_mode = f;}
5207 load_undefined_interfaces()
const
5218 {
return options().show_stats;}
5267 build_die_parent_relations_under(Dwarf_Die* die,
5275 if (dwarf_child(die, &child) != 0)
5280 parent_of[child.addr] = die->addr;
5281 if (dwarf_tag(&child) == DW_TAG_imported_unit)
5283 Dwarf_Die imported_unit;
5284 if (die_die_attribute(&child, DW_AT_import, imported_unit)
5295 && die_has_children(&imported_unit))
5297 imported_units.push_back(imported_unit_point(child.addr,
5301 build_die_parent_relations_under(&child, parent_of,
5304 while (dwarf_siblingof(&child, &child) == 0);
5336 case translation_unit::LANG_UNKNOWN:
5337#ifdef HAVE_DW_LANG_Mips_Assembler_enumerator
5338 case translation_unit::LANG_Mips_Assembler:
5361 auto n = completed_tasks.size();
5362 cerr <<
"Merging the " << n <<
" DIE -> parent maps ...\n";
5367 for (
auto t : completed_tasks)
5370 dynamic_pointer_cast<die_parent_relations_builder_task>(t);
5371 size += tsk->parent_of.size();
5373 die_parent_map().reserve(size);
5375 for (
auto t : completed_tasks)
5378 dynamic_pointer_cast<die_parent_relations_builder_task>(t);
5380 tsk->merge_die_parent_maps();
5386 cerr <<
"Merged all the DIE -> parent maps in " << t <<
"\n";
5408 build_die_parent_maps()
5410 bool we_do_have_to_build_die_parent_map =
false;
5411 uint8_t address_size = 0;
5412 size_t header_size = 0;
5417 cerr <<
"Do we need to build the DIE -> parent map at all ... ? ";
5425 for (Dwarf_Off offset = 0, next_offset = 0;
5427 offset, &next_offset, &header_size,
5428 NULL, NULL, &address_size, NULL, NULL, NULL) == 0);
5429 offset = next_offset)
5431 Dwarf_Off die_offset = offset + header_size;
5438 die_unsigned_constant_attribute(&cu, DW_AT_language, l);
5440 if (do_we_build_die_parent_maps(lang))
5441 we_do_have_to_build_die_parent_map =
true;
5444 if (!we_do_have_to_build_die_parent_map)
5449 cerr <<
" ... No we don't: (" << t <<
")\n" ;
5457 cerr <<
" ... yes we do: (" << t <<
")\n" ;
5465 cerr <<
"Building several DIE -> parent maps in // ...\n";
5472 for (Dwarf_Off offset = 0, next_offset = 0;
5474 offset, &next_offset, &header_size,
5475 NULL, NULL, &address_size, NULL, NULL, NULL) == 0);
5476 offset = next_offset)
5478 Dwarf_Off die_offset = offset + header_size;
5485 tu_die_imported_unit_points_map()[cu.addr] =
5489 (
new die_parent_relations_builder_task(*
this, cu, imported_units));
5500 for (Dwarf_Off offset = 0, next_offset = 0;
5502 offset, &next_offset, &header_size,
5503 NULL, NULL, &address_size, NULL, NULL, NULL) == 0);
5504 offset = next_offset)
5506 Dwarf_Off die_offset = offset + header_size;
5513 tu_die_imported_unit_points_map()[cu.addr] =
5517 (
new die_parent_relations_builder_task(*
this, cu, imported_units));
5528 uint64_t type_signature = 0;
5529 Dwarf_Off type_offset;
5530 for (Dwarf_Off offset = 0, next_offset = 0;
5532 offset, &next_offset, &header_size,
5533 NULL, NULL, &address_size, NULL,
5534 &type_signature, &type_offset) == 0);
5535 offset = next_offset)
5537 Dwarf_Off die_offset = offset + header_size;
5545 tu_die_imported_unit_points_map()[cu.addr] =
5549 (
new die_parent_relations_builder_task(*
this, cu, imported_units));
5561 cerr <<
"Built " << n <<
" DIE -> parent maps in // in " << t <<
"\n";
5569do_handle_dwarf_die(reader& rdr, reader::tu_context_type_sptr tu_ctxt,
5570 Dwarf_Die& die,
bool die_is_public);
5573potential_member_fn_should_be_dropped(reader& rdr,
5574 reader::tu_context_type_sptr& tu_ctxt,
5575 const Dwarf_Die* fn_die);
5578die_qualified_decl_name(
const reader& rdr,
5579 const Dwarf_Die* die,
5581 reader::tu_context_type_sptr& tu_ctxt,
5582 unordered_set<void*>& guard);
5585die_qualified_name(
const reader& rdr,
const Dwarf_Die* die,
void* where,
5586 reader::tu_context_type_sptr& tu_ctxt);
5589die_type_name(
const reader& rdr,
const Dwarf_Die* die,
5590 bool qualified_name,
void* where_addr,
5591 reader::tu_context_type_sptr& tu_ctxt,
5592 unordered_set<void*>& infinite_loop_guard);
5595die_type_name(
const reader& rdr,
const Dwarf_Die* die,
5596 bool qualified_name,
void* where_addr,
5597 reader::tu_context_type_sptr& tu_ctxt);
5600die_qualified_type_name_empty(
const reader& rdr,
const Dwarf_Die* die,
5601 void* where,
string &qualified_name,
5602 reader::tu_context_type_sptr& tu_ctxt,
5603 unordered_set<void*>& infinite_loop_guard);
5606die_function_signature(
const reader& rdr,
const Dwarf_Die *die,
5607 bool qualified_name,
void* where_addr,
5608 reader::tu_context_type_sptr& tu_ctxt,
5609 unordered_set<void*>& infinite_loop_guard);
5612die_enum_flat_representation(
const reader& rdr,
5613 const Dwarf_Die* die,
5614 const string& indent,
5616 bool qualified_names,
5618 reader::tu_context_type_sptr& tu_ctxt);
5621die_class_flat_representation(
const reader& rdr,
5622 const Dwarf_Die* die,
5623 const string& indent,
5625 bool qualified_names,
5627 reader::tu_context_type_sptr& tu_ctxt,
5628 unordered_set<void*>& infinite_loop_guard);
5631die_pretty_print_type(
const reader& rdr,
const Dwarf_Die* die,
5633 reader::tu_context_type_sptr& tu_ctxt,
5634 unordered_set<void*>& guard);
5637die_pretty_print_decl(
const reader& rdr,
const Dwarf_Die* die,
5638 bool qualified_name,
bool include_fns,
5640 reader::tu_context_type_sptr& tu_ctxt,
5641 unordered_set<void*>& infinite_loop_guard);
5644build_subrange_type(reader& rdr,
5645 const Dwarf_Die* die,
5647 reader::tu_context_type_sptr& tu_ctxt,
5648 bool associate_type_to_die =
true);
5651build_subranges_from_array_type_die(
const reader& rdr,
5652 const Dwarf_Die* die,
5655 reader::tu_context_type_sptr& tu_ctxt,
5656 bool associate_type_to_die =
true);
5658subrange_die_indirect_bound_value(
const Dwarf_Die *die,
5664die_return_and_parm_names_from_fn_type_die(
const reader& rdr,
5665 const Dwarf_Die* die,
5668 bool qualified_name,
5670 string &return_type_name,
5672 vector<string>& parm_names,
5675 reader::tu_context_type_sptr& tu_ctxt,
5676 unordered_set<void*>& infinite_loop_guard);
5679die_is_at_class_scope(
const reader& rdr,
5680 const Dwarf_Die* die,
5682 reader::tu_context_type_sptr& tu_ctxt,
5683 Dwarf_Die& class_scope_die);
5686die_is_member_function(
const reader& rdr,
5687 const Dwarf_Die* die,
5689 reader::tu_context_type_sptr& tu_ctxt,
5690 Dwarf_Die& class_die);
5693member_fn_die_has_this_pointer(
const reader& rdr,
5694 const Dwarf_Die* die,
5696 reader::tu_context_type_sptr& tu_ctxt,
5697 Dwarf_Die& class_die,
5698 Dwarf_Die& object_pointer_die);
5701die_function_type_is_method_type(
const reader& rdr,
5702 const Dwarf_Die *die,
5704 reader::tu_context_type_sptr& tu_ctxt,
5705 Dwarf_Die& object_pointer_die,
5706 Dwarf_Die& class_die,
5710die_loc_and_name(Dwarf_Die* die,
5711 reader::tu_context_type_sptr& tu_ctxt,
5714 string& linkage_name);
5717build_ir_nodes_from_imported_unit(reader& rdr,
5719 reader::tu_context_type_sptr tu_ctxt);
5722build_ir_node_from_die(reader& rdr,
5725 bool called_from_public_decl,
5727 reader::tu_context_type_sptr& tu_ctxt,
5728 bool is_declaration_only =
true,
5729 bool is_required_decl_spec =
false);
5732build_ir_node_from_die(reader& rdr,
5734 bool called_from_public_decl,
5736 reader::tu_context_type_sptr& tu_ctxt,
5737 bool is_required_decl_spec =
false);
5739static decl_base_sptr
5740build_ir_node_for_void_type(reader& rdr,
5741 reader::tu_context_type_sptr& tu_ctxt);
5744build_ir_node_for_void_pointer_type(reader& rdr,
5745 reader::tu_context_type_sptr& tu_ctxt);
5747static decl_base_sptr
5748build_ir_node_for_variadic_parameter_type(reader &rdr,
5749 reader::tu_context_type_sptr& tu_ctxt);
5752add_or_update_class_type(reader& rdr,
5756 bool called_from_public_decl,
5758 bool is_declaration_only,
5759 reader::tu_context_type_sptr& tu_ctxt);
5761static union_decl_sptr
5762add_or_update_union_type(reader& rdr,
5764 union_decl_sptr union_type,
5765 bool called_from_public_decl,
5767 bool is_declaration_only,
5768 reader::tu_context_type_sptr& tu_ctxt);
5771maybe_get_origin_type(reader& rdr,
5772 const Dwarf_Die* die,
5773 Dwarf_Die& origin_die,
5774 type_base_sptr& origin_type);
5777build_function_type(reader& rdr,
5779 class_or_union_sptr is_method,
5781 vector<decl_base_sptr>& decls,
5782 reader::tu_context_type_sptr& tu_ctxt);
5785build_function_decl(reader& rdr, Dwarf_Die* die,
void* where,
5786 reader::tu_context_type_sptr& tu_ctxt,
5790function_is_suppressed(
const reader& rdr,
5792 Dwarf_Die *function_die,
5793 bool is_declaration_only);
5796build_or_get_fn_decl_if_not_suppressed(reader& rdr,
5800 reader::tu_context_type_sptr& tu_ctxt,
5801 bool is_declaration_only,
5805build_var_decl(reader& rdr,
5808 reader::tu_context_type_sptr& tu_ctxt,
5812build_or_get_var_decl_if_not_suppressed(reader& rdr,
5816 reader::tu_context_type_sptr& tu_ctxt,
5817 bool is_declaration_only,
5819 bool is_required_decl_spec =
false);
5821variable_is_suppressed(
const reader& rdr,
5823 Dwarf_Die *variable_die,
5824 bool is_declaration_only,
5825 bool is_required_decl_spec =
false);
5830die_parent_relations_builder_task::perform()
5832 rdr.build_die_parent_relations_under(&tu_die, parent_of, imported_units);
5839die_parent_relations_builder_task::merge_die_parent_maps()
5841 rdr.die_parent_map().merge(parent_of);
5850die_is_anonymous(
const Dwarf_Die* die)
5852 Dwarf_Attribute attr;
5853 if (!dwarf_attr_integrate(
const_cast<Dwarf_Die*
>(die), DW_AT_name, &attr))
5867die_is_anonymous_data_member(
const Dwarf_Die* die)
5870 || dwarf_tag(
const_cast<Dwarf_Die*
>(die)) != DW_TAG_member
5871 || !die_name(die).empty())
5875 if (!die_die_attribute(die, DW_AT_type, type_die))
5878 if (dwarf_tag(&type_die) != DW_TAG_structure_type
5879 && dwarf_tag(&type_die) != DW_TAG_union_type)
5896die_string_attribute(
const Dwarf_Die* die,
unsigned attr_name)
5901 Dwarf_Attribute attr;
5902 if (!dwarf_attr_integrate(
const_cast<Dwarf_Die*
>(die), attr_name, &attr))
5905 const char* str = dwarf_formstring(&attr);
5906 return str ? str :
"";
5925die_unsigned_constant_attribute(
const Dwarf_Die* die,
5932 Dwarf_Attribute attr;
5933 Dwarf_Word result = 0;
5934 if (!dwarf_attr_integrate(
const_cast<Dwarf_Die*
>(die), attr_name, &attr)
5935 || dwarf_formudata(&attr, &result))
5955die_signed_constant_attribute(
const Dwarf_Die *die,
5962 Dwarf_Attribute attr;
5963 Dwarf_Sword result = 0;
5964 if (!dwarf_attr_integrate(
const_cast<Dwarf_Die*
>(die), attr_name, &attr)
5965 || dwarf_formsdata(&attr, &result))
5991die_constant_attribute(
const Dwarf_Die *die,
5994 array_type_def::subrange_type::bound_value &value)
5999 if (!die_unsigned_constant_attribute(die, attr_name, l))
6001 value.set_unsigned(l);
6006 if (!die_signed_constant_attribute(die, attr_name, l))
6008 value.set_signed(l);
6033die_flag_attribute(
const Dwarf_Die* die,
6036 bool recursively =
true)
6038 Dwarf_Attribute attr;
6040 ? !dwarf_attr_integrate(
const_cast<Dwarf_Die*
>(die), attr_name, &attr)
6041 : !dwarf_attr(const_cast<Dwarf_Die*>(die), attr_name, &attr))
6045 if (dwarf_formflag(&attr, &f))
6059die_linkage_name(
const Dwarf_Die* die)
6064 string linkage_name = die_string_attribute(die, DW_AT_linkage_name);
6065 if (linkage_name.empty())
6066 linkage_name = die_string_attribute(die, DW_AT_MIPS_linkage_name);
6067 return linkage_name;
6081die_decl_file_attribute(
const Dwarf_Die* die)
6086 const char* str = dwarf_decl_file(
const_cast<Dwarf_Die*
>(die));
6088 return str ? str :
"";
6109die_die_attribute(
const Dwarf_Die* the_die,
6114 Dwarf_Die *die =
const_cast<Dwarf_Die*
>(the_die);
6115 Dwarf_Attribute attr;
6117 ? !dwarf_attr_integrate(die, attr_name, &attr)
6118 : !dwarf_attr(die, attr_name, &attr))
6121 bool res = dwarf_formref_die(&attr, &result);
6127 int tag = dwarf_tag(&result);
6128 if (tag == DW_TAG_invalid)
6157die_origin_die(
const Dwarf_Die* die, Dwarf_Die& origin_die)
6159 if (die_die_attribute(die, DW_AT_specification, origin_die,
true)
6160 || die_die_attribute(die, DW_AT_abstract_origin, origin_die,
true))
6162 while (die_die_attribute(&origin_die,
6163 DW_AT_specification,
6165 || die_die_attribute(&origin_die,
6166 DW_AT_abstract_origin,
6204subrange_die_indirectly_references_subrange_die(
const Dwarf_Die *die,
6206 Dwarf_Die& referenced_subrange)
6208 bool result =
false;
6210 if (dwarf_tag(
const_cast<Dwarf_Die*
>(die)) != DW_TAG_subrange_type)
6213 Dwarf_Die referenced_die;
6214 if (die_die_attribute(die, attr_name, referenced_die))
6216 unsigned tag = dwarf_tag(&referenced_die);
6217 if ( tag == DW_TAG_member || tag == DW_TAG_variable)
6220 if (die_die_attribute(&referenced_die, DW_AT_type, type_die))
6222 tag = dwarf_tag(&type_die);
6223 if (tag == DW_TAG_subrange_type)
6225 memcpy(&referenced_subrange, &type_die,
sizeof(type_die));
6261subrange_die_indirect_bound_value(
const Dwarf_Die *die,
6263 array_type_def::subrange_type::bound_value& v,
6266 bool result =
false;
6268 if (dwarf_tag(
const_cast<Dwarf_Die*
>(die)) != DW_TAG_subrange_type)
6271 Dwarf_Die subrange_die;
6272 if (subrange_die_indirectly_references_subrange_die(die, attr_name,
6275 if (die_constant_attribute(&subrange_die, attr_name, is_signed, v))
6293die_address_attribute(Dwarf_Die* die,
unsigned attr_name, Dwarf_Addr& result)
6295 Dwarf_Attribute attr;
6296 if (!dwarf_attr_integrate(die, attr_name, &attr))
6298 return dwarf_formaddr(&attr, &result) == 0;
6310 reader::tu_context_type_sptr& tu_ctxt)
6315 string file = die_decl_file_attribute(die);
6317 die_unsigned_constant_attribute(die, DW_AT_decl_line, line);
6319 if (!file.empty() && line != 0)
6322 location l = tu->get_loc_mgr().create_new_location(file, line, 1);
6334die_name(
const Dwarf_Die* die)
6336 string name = die_string_attribute(die, DW_AT_name);
6352die_loc_and_name(Dwarf_Die* die,
6353 reader::tu_context_type_sptr& tu_ctxt,
6356 string& linkage_name)
6359 name = die_name(die);
6360 linkage_name = die_linkage_name(die);
6371die_name_and_linkage_name(
const Dwarf_Die* die,
6373 string& linkage_name)
6375 name = die_name(die);
6376 linkage_name = die_linkage_name(die);
6389die_size_in_bits(
const Dwarf_Die* die, uint64_t& size)
6394 uint64_t byte_size = 0, bit_size = 0;
6396 if (!die_unsigned_constant_attribute(die, DW_AT_byte_size, byte_size))
6398 if (!die_unsigned_constant_attribute(die, DW_AT_bit_size, bit_size))
6402 bit_size = byte_size * 8;
6425 if (!die_unsigned_constant_attribute(die, DW_AT_accessibility, a))
6432 case private_access:
6433 result = private_access;
6436 case protected_access:
6437 result = protected_access;
6441 result = public_access;
6460die_is_public_decl(
const Dwarf_Die* die)
6464 bool is_public =
false;
6470 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
6471 if (tag == DW_TAG_subprogram || tag == DW_TAG_variable)
6473 die_flag_attribute(die, DW_AT_external, is_public);
6477 string n = die_string_attribute(die, DW_AT_MIPS_linkage_name);
6479 n = die_string_attribute(die, DW_AT_linkage_name);
6480 is_public = !n.empty();
6483 else if (tag == DW_TAG_namespace)
6485 string name = die_name(die);
6486 is_public = !name.empty();
6500die_is_effectively_public_decl(
const reader& rdr,
const Dwarf_Die* die,
6501 reader::tu_context_type_sptr& tu_ctxt)
6503 if (die_is_public_decl(die))
6506 unsigned tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
6507 if (tag == DW_TAG_variable || tag == DW_TAG_member)
6510 Dwarf_Die parent_die;
6511 if (!rdr.get_parent_die(die, parent_die,
6516 tag = dwarf_tag(&parent_die);
6517 if (tag == DW_TAG_compile_unit
6518 || tag == DW_TAG_partial_unit
6519 || tag == DW_TAG_type_unit)
6523 if (tag == DW_TAG_namespace)
6525 string name = die_name(&parent_die);
6544die_is_declaration_only(Dwarf_Die* die)
6546 bool is_declaration =
false;
6547 die_flag_attribute(die, DW_AT_declaration, is_declaration,
false);
6548 if (is_declaration && (!die_has_size_attribute(die)
6549 || !die_has_children(die)))
6560die_is_function_decl(
const Dwarf_Die *die)
6565 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
6567 if (tag == DW_TAG_subprogram)
6588die_is_member_function(
const reader& rdr,
6589 const Dwarf_Die* die,
6591 reader::tu_context_type_sptr& tu_ctxt,
6592 Dwarf_Die& class_die)
6594 if (!die_is_function_decl(die))
6597 if (die_is_at_class_scope(rdr, die, where_addr, tu_ctxt, class_die))
6610die_is_destructor(
const Dwarf_Die *die)
6612 if (!die_is_function_decl(die))
6615 string name = die_name(die);
6616 if (!name.empty() && name[0] ==
'~')
6628die_is_variable_decl(
const Dwarf_Die *die)
6633 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
6636 if (tag == DW_TAG_variable)
6647die_has_size_attribute(
const Dwarf_Die *die)
6650 if (die_size_in_bits(die, s))
6661die_is_artificial(Dwarf_Die* die)
6664 return die_flag_attribute(die, DW_AT_artificial, is_artificial);
6671is_type_tag(
unsigned tag)
6673 bool result =
false;
6677 case DW_TAG_array_type:
6678 case DW_TAG_class_type:
6679 case DW_TAG_enumeration_type:
6680 case DW_TAG_pointer_type:
6681 case DW_TAG_reference_type:
6682 case DW_TAG_string_type:
6683 case DW_TAG_structure_type:
6684 case DW_TAG_subroutine_type:
6685 case DW_TAG_typedef:
6686 case DW_TAG_union_type:
6687 case DW_TAG_ptr_to_member_type:
6688 case DW_TAG_set_type:
6689 case DW_TAG_subrange_type:
6690 case DW_TAG_base_type:
6691 case DW_TAG_const_type:
6692 case DW_TAG_file_type:
6693 case DW_TAG_packed_type:
6694 case DW_TAG_thrown_type:
6695 case DW_TAG_volatile_type:
6696 case DW_TAG_restrict_type:
6697 case DW_TAG_interface_type:
6698 case DW_TAG_unspecified_type:
6699 case DW_TAG_shared_type:
6700 case DW_TAG_rvalue_reference_type:
6701 case DW_TAG_coarray_type:
6702 case DW_TAG_atomic_type:
6703 case DW_TAG_immutable_type:
6721is_decl_tag(
unsigned tag)
6725 case DW_TAG_formal_parameter:
6726 case DW_TAG_imported_declaration:
6728 case DW_TAG_unspecified_parameters:
6729 case DW_TAG_subprogram:
6730 case DW_TAG_inlined_subroutine:
6731 case DW_TAG_variable:
6732 case DW_TAG_namespace:
6733 case DW_TAG_GNU_template_template_param:
6734 case DW_TAG_GNU_template_parameter_pack:
6735 case DW_TAG_GNU_formal_parameter_pack:
6747die_is_type(
const Dwarf_Die* die)
6752 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
6755 return is_type_tag(dwarf_tag(
const_cast<Dwarf_Die*
>(die)));
6764die_is_decl(
const Dwarf_Die* die)
6768 return is_decl_tag(dwarf_tag(
const_cast<Dwarf_Die*
>(die)));
6777die_is_namespace(
const Dwarf_Die* die)
6781 return (dwarf_tag(
const_cast<Dwarf_Die*
>(die)) == DW_TAG_namespace);
6790die_is_unspecified(Dwarf_Die* die)
6794 return (dwarf_tag(die) == DW_TAG_unspecified_type);
6803die_is_void_type(Dwarf_Die* die)
6805 if (!die || dwarf_tag(die) != DW_TAG_base_type)
6808 string name = die_name(die);
6821die_is_pointer_type(
const Dwarf_Die* die)
6826 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
6829 if (tag == DW_TAG_pointer_type)
6841die_is_reference_type(
const Dwarf_Die* die)
6846 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
6849 if (tag == DW_TAG_reference_type || tag == DW_TAG_rvalue_reference_type)
6861die_is_pointer_or_reference_type(
const Dwarf_Die* die)
6862{
return (die_is_pointer_type(die) || die_is_reference_type(die));}
6870die_is_class_type(
const Dwarf_Die* die)
6872 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
6875 if (tag == DW_TAG_class_type || tag == DW_TAG_structure_type)
6893die_has_object_pointer(
const Dwarf_Die* die, Dwarf_Die& object_pointer)
6898 if (die_die_attribute(die, DW_AT_object_pointer, object_pointer))
6910die_has_children(
const Dwarf_Die* die)
6916 if (dwarf_child(
const_cast<Dwarf_Die*
>(die), &child) == 0)
6936fn_die_first_parameter_die(
const Dwarf_Die* die, Dwarf_Die& first_parm_die)
6941 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
6944 ABG_ASSERT(tag == DW_TAG_subroutine_type || tag == DW_TAG_subprogram);
6947 if (dwarf_child(
const_cast<Dwarf_Die*
>(die), &child) == 0)
6949 int child_tag = dwarf_tag(&child);
6950 if (child_tag == DW_TAG_formal_parameter)
6952 memcpy(&first_parm_die, &child,
sizeof(Dwarf_Die));
6979get_member_fn_class_die_from_object_pointer(
const Dwarf_Die* die,
6980 Dwarf_Die& class_die,
6981 Dwarf_Die& object_ptr_die)
6986 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
6987 if (tag != DW_TAG_subprogram && tag != DW_TAG_subroutine_type)
6990 Dwarf_Die first_parm_die;
6991 Dwarf_Die parm_type_die;
6992 if (die_has_object_pointer(die, object_ptr_die))
6998 memcpy(&first_parm_die, &object_ptr_die,
sizeof(Dwarf_Die));
6999 if (!die_die_attribute(&first_parm_die, DW_AT_type, parm_type_die))
7001 die_peel_qual_ptr(&parm_type_die, parm_type_die);
7002 die_peel_typedef(&parm_type_die, parm_type_die);
7007 tag = dwarf_tag(&parm_type_die);
7008 if (tag == DW_TAG_class_type || tag == DW_TAG_structure_type)
7010 memcpy(&class_die, &parm_type_die,
sizeof(Dwarf_Die));
7045member_fn_die_has_this_pointer(
const reader& rdr,
7046 const Dwarf_Die* die,
7048 reader::tu_context_type_sptr& tu_ctxt,
7049 Dwarf_Die& class_die,
7050 Dwarf_Die& object_pointer_die)
7055 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
7056 if (tag != DW_TAG_subprogram && tag != DW_TAG_subroutine_type)
7059 if (tag == DW_TAG_subprogram
7060 && !die_is_at_class_scope(rdr, die, where_addr, tu_ctxt, class_die))
7063 if (get_member_fn_class_die_from_object_pointer(die, class_die,
7064 object_pointer_die))
7067 Dwarf_Die first_parm_die;
7068 Dwarf_Die parm_type_die;
7069 if (fn_die_first_parameter_die(die, first_parm_die))
7071 memcpy(&object_pointer_die, &first_parm_die,
sizeof(Dwarf_Die));
7072 bool is_artificial =
false;
7073 if (die_flag_attribute(&first_parm_die, DW_AT_artificial, is_artificial))
7075 if (die_die_attribute(&first_parm_die, DW_AT_type, parm_type_die))
7077 tag = dwarf_tag(&parm_type_die);
7078 if (tag == DW_TAG_pointer_type)
7080 die_peel_qual_ptr(&parm_type_die, parm_type_die);
7081 die_peel_typedef(&parm_type_die, parm_type_die);
7095 tag = dwarf_tag(&parm_type_die);
7096 if (tag == DW_TAG_class_type || tag == DW_TAG_structure_type)
7098 memcpy(&class_die, &parm_type_die,
sizeof(Dwarf_Die));
7118die_this_pointer_from_object_pointer(Dwarf_Die* die,
7119 Dwarf_Die& this_pointer_die)
7122 ABG_ASSERT(dwarf_tag(die) == DW_TAG_formal_parameter);
7124 if (die_die_attribute(die, DW_AT_type, this_pointer_die))
7139die_this_pointer_is_const(Dwarf_Die* dye)
7144 memcpy(&die, dye,
sizeof(Dwarf_Die));
7145 if (dwarf_tag(&die) == DW_TAG_const_type)
7148 if (dwarf_tag(&die) == DW_TAG_pointer_type)
7150 Dwarf_Die pointed_to_type_die;
7151 if (die_die_attribute(&die, DW_AT_type, pointed_to_type_die))
7152 if (dwarf_tag(&pointed_to_type_die) == DW_TAG_const_type)
7168die_object_pointer_is_for_const_method(Dwarf_Die* die)
7171 ABG_ASSERT(dwarf_tag(die) == DW_TAG_formal_parameter);
7173 Dwarf_Die this_pointer_die;
7174 if (die_this_pointer_from_object_pointer(die, this_pointer_die))
7175 if (die_this_pointer_is_const(&this_pointer_die))
7197die_is_at_class_scope(
const reader& rdr,
const Dwarf_Die* die,
void* where,
7198 reader::tu_context_type_sptr& tu_ctxt,
7199 Dwarf_Die& class_scope_die)
7201 if (!rdr.get_scope_die(die, where, tu_ctxt, class_scope_die))
7204 int tag = dwarf_tag(&class_scope_die);
7206 return (tag == DW_TAG_structure_type
7207 || tag == DW_TAG_class_type
7208 || tag == DW_TAG_union_type);
7221die_peel_qual_ptr(Dwarf_Die *die, Dwarf_Die& peeled_die)
7226 int tag = dwarf_tag(die);
7228 if (tag == DW_TAG_const_type
7229 || tag == DW_TAG_volatile_type
7230 || tag == DW_TAG_restrict_type
7231 || tag == DW_TAG_pointer_type
7232 || tag == DW_TAG_reference_type
7233 || tag == DW_TAG_rvalue_reference_type)
7235 if (!die_die_attribute(die, DW_AT_type, peeled_die))
7241 memcpy(&peeled_die, die,
sizeof(peeled_die));
7243 while (tag == DW_TAG_const_type
7244 || tag == DW_TAG_volatile_type
7245 || tag == DW_TAG_restrict_type
7246 || tag == DW_TAG_pointer_type
7247 || tag == DW_TAG_reference_type
7248 || tag == DW_TAG_rvalue_reference_type)
7250 if (!die_die_attribute(&peeled_die, DW_AT_type, peeled_die))
7252 tag = dwarf_tag(&peeled_die);
7267die_peel_qualified(Dwarf_Die *die, Dwarf_Die& peeled_die)
7272 memcpy(&peeled_die, die,
sizeof(peeled_die));
7274 int tag = dwarf_tag(&peeled_die);
7276 bool result =
false;
7277 while (tag == DW_TAG_const_type
7278 || tag == DW_TAG_volatile_type
7279 || tag == DW_TAG_restrict_type)
7281 if (!die_die_attribute(&peeled_die, DW_AT_type, peeled_die))
7283 tag = dwarf_tag(&peeled_die);
7299die_peel_typedef(Dwarf_Die *die, Dwarf_Die& peeled_die)
7304 int tag = dwarf_tag(die);
7306 memcpy(&peeled_die, die,
sizeof(peeled_die));
7308 if (tag == DW_TAG_typedef)
7310 if (!die_die_attribute(die, DW_AT_type, peeled_die))
7316 while (tag == DW_TAG_typedef)
7318 if (!die_die_attribute(&peeled_die, DW_AT_type, peeled_die))
7320 tag = dwarf_tag(&peeled_die);
7353die_function_type_is_method_type(
const reader& rdr,
7354 const Dwarf_Die *die,
7356 reader::tu_context_type_sptr& tu_ctxt,
7357 Dwarf_Die& object_pointer_die,
7358 Dwarf_Die& class_die,
7364 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
7365 ABG_ASSERT(tag == DW_TAG_subroutine_type || tag == DW_TAG_subprogram);
7367 if (member_fn_die_has_this_pointer(rdr, die, where_addr, tu_ctxt,
7368 class_die, object_pointer_die))
7373 else if (die_is_at_class_scope(rdr, die, where_addr, tu_ctxt, class_die))
7384 VIRTUALITY_NOT_VIRTUAL,
7386 VIRTUALITY_PURE_VIRTUAL
7399die_virtuality(
const Dwarf_Die* die, virtuality& virt)
7405 die_unsigned_constant_attribute(die, DW_AT_virtuality, v);
7407 if (v == DW_VIRTUALITY_virtual)
7408 virt = VIRTUALITY_VIRTUAL;
7409 else if (v == DW_VIRTUALITY_pure_virtual)
7410 virt = VIRTUALITY_PURE_VIRTUAL;
7412 virt = VIRTUALITY_NOT_VIRTUAL;
7424die_is_virtual(
const Dwarf_Die* die)
7427 if (!die_virtuality(die, v))
7430 return v == VIRTUALITY_PURE_VIRTUAL || v == VIRTUALITY_VIRTUAL;
7440die_is_declared_inline(Dwarf_Die* die)
7442 uint64_t inline_value = 0;
7443 if (!die_unsigned_constant_attribute(die, DW_AT_inline, inline_value))
7445 return (inline_value == DW_INL_declared_inlined
7446 || inline_value == DW_INL_declared_not_inlined);
7471die_location_expr(
const Dwarf_Die* die,
7479 Dwarf_Attribute attr;
7480 if (!dwarf_attr_integrate(
const_cast<Dwarf_Die*
>(die), attr_name, &attr))
7484 bool result = (dwarf_getlocation(&attr, expr, &len) == 0);
7519op_pushes_constant_value(Dwarf_Op* ops,
7523 dwarf_expr_eval_context& ctxt)
7527 Dwarf_Op& op = ops[index];
7533 value = ops[index].number;
7546 value = ops[index].number;
7650 expr_result r(value);
7653 next_index = index + 1;
7683op_pushes_non_constant_value(Dwarf_Op* ops,
7687 dwarf_expr_eval_context& ctxt)
7690 Dwarf_Op& op = ops[index];
7726 next_index = index + 1;
7761 next_index = index + 1;
7765 next_index = index + 2;
7769 next_index = index + 1;
7773 next_index = index + 1;
7776 case DW_OP_GNU_variable_value:
7777 next_index = index + 1;
7784 expr_result r(
false);
7813op_manipulates_stack(Dwarf_Op* expr,
7817 dwarf_expr_eval_context& ctxt)
7819 Dwarf_Op& op = expr[index];
7825 v = ctxt.stack.front();
7830 v = ctxt.stack.front();
7849 ctxt.stack.erase(ctxt.stack.begin() + 1);
7856 ctxt.stack.erase(ctxt.stack.begin() + 2);
7861 case DW_OP_deref_size:
7869 case DW_OP_xderef_size:
7877 case DW_OP_push_object_address:
7882 case DW_OP_form_tls_address:
7883 case DW_OP_GNU_push_tls_address:
7886 if (op.atom == DW_OP_form_tls_address)
7891 case DW_OP_call_frame_cfa:
7903 if (op.atom == DW_OP_form_tls_address
7904 || op.atom == DW_OP_GNU_push_tls_address)
7905 ctxt.set_tls_address(
true);
7907 ctxt.set_tls_address(
false);
7909 next_index = index + 1;
7937op_is_arith_logic(Dwarf_Op* expr,
7941 dwarf_expr_eval_context& ctxt)
7945 Dwarf_Op& op = expr[index];
7946 expr_result val1, val2;
7947 bool result =
false;
7963 ctxt.push(val1 & val2);
7970 if (!val1.is_const())
7972 ctxt.push(val2 / val1);
7980 ctxt.push(val2 - val1);
7988 ctxt.push(val2 % val1);
7996 ctxt.push(val2 * val1);
8018 ctxt.push(val1 | val2);
8026 ctxt.push(val2 + val1);
8030 case DW_OP_plus_uconst:
8042 ctxt.push(val2 << val1);
8051 ctxt.push(val2 >> val1);
8059 ctxt.push(val2 ^ val1);
8069 if (ctxt.stack.front().is_const())
8070 ctxt.accum = ctxt.stack.front();
8072 next_index = index + 1;
8100op_is_control_flow(Dwarf_Op* expr,
8104 dwarf_expr_eval_context& ctxt)
8108 Dwarf_Op& op = expr[index];
8109 expr_result val1, val2;
8123 if (op.atom == DW_OP_eq)
8124 value = val2 == val1;
8125 else if (op.atom == DW_OP_ge)
8126 value = val2 >= val1;
8127 else if (op.atom == DW_OP_gt)
8128 value = val2 > val1;
8129 else if (op.atom == DW_OP_le)
8130 value = val2 <= val1;
8131 else if (op.atom == DW_OP_lt)
8132 value = val2 < val1;
8133 else if (op.atom == DW_OP_ne)
8134 value = val2 != val1;
8136 val1 = value ? 1 : 0;
8143 index += op.number - 1;
8148 if (val1.const_value() != 0)
8149 index += val1.const_value() - 1;
8154 case DW_OP_call_ref:
8162 if (ctxt.stack.front().is_const())
8163 ctxt.accum = ctxt.stack.front();
8165 next_index = index + 1;
8186eval_quickly(Dwarf_Op* expr,
8190 if (expr_len == 1 && (expr[0].atom == DW_OP_plus_uconst))
8192 value = expr[0].number;
8219eval_last_constant_dwarf_sub_expr(Dwarf_Op* expr,
8222 bool& is_tls_address,
8223 dwarf_expr_eval_context &eval_ctxt)
8229 size_t index = 0, next_index = 0;
8232 if (op_is_arith_logic(expr, expr_len, index,
8233 next_index, eval_ctxt)
8234 || op_pushes_constant_value(expr, expr_len, index,
8235 next_index, eval_ctxt)
8236 || op_manipulates_stack(expr, expr_len, index,
8237 next_index, eval_ctxt)
8238 || op_pushes_non_constant_value(expr, expr_len, index,
8239 next_index, eval_ctxt)
8240 || op_is_control_flow(expr, expr_len, index,
8241 next_index, eval_ctxt))
8244 next_index = index + 1;
8248 }
while (index < expr_len);
8250 is_tls_address = eval_ctxt.set_tls_address();
8251 if (eval_ctxt.accum.is_const())
8253 value = eval_ctxt.accum;
8273eval_last_constant_dwarf_sub_expr(Dwarf_Op* expr,
8276 bool& is_tls_address)
8278 dwarf_expr_eval_context eval_ctxt;
8279 return eval_last_constant_dwarf_sub_expr(expr, expr_len, value,
8280 is_tls_address, eval_ctxt);
8472read_and_convert_DW_at_bit_offset(
const Dwarf_Die* die,
8477 if (!die_unsigned_constant_attribute(die, DW_AT_bit_offset, off))
8490 uint64_t containing_anonymous_object_size = 0;
8491 ABG_ASSERT(die_unsigned_constant_attribute(die, DW_AT_byte_size,
8492 containing_anonymous_object_size));
8493 containing_anonymous_object_size *= 8;
8495 uint64_t bitfield_size = 0;
8496 ABG_ASSERT(die_unsigned_constant_attribute(die, DW_AT_bit_size,
8507 offset = containing_anonymous_object_size - off - bitfield_size;
8523die_constant_data_member_location(
const Dwarf_Die *die,
8529 Dwarf_Attribute attr;
8530 if (!dwarf_attr(
const_cast<Dwarf_Die*
>(die),
8531 DW_AT_data_member_location,
8536 if (dwarf_formudata(&attr, &val) != 0)
8592die_member_offset(
const reader& rdr,
8593 const Dwarf_Die* die,
8596 Dwarf_Op* expr = NULL;
8597 size_t expr_len = 0;
8598 uint64_t bit_offset = 0;
8602 if (die_unsigned_constant_attribute(die, DW_AT_data_bit_offset, bit_offset))
8604 offset = bit_offset;
8616 if (!die_constant_data_member_location(die, offset))
8621 if (!die_location_expr(die, DW_AT_data_member_location,
8628 if (!eval_quickly(expr, expr_len, offset))
8630 bool is_tls_address =
false;
8631 dwarf_expr_eval_context eval_ctxt;
8632 if (!eval_last_constant_dwarf_sub_expr(expr, expr_len,
8633 offset, is_tls_address,
8652 if (read_and_convert_DW_at_bit_offset(die, is_big_endian, bit_offset))
8653 offset += bit_offset;
8670die_location_address(Dwarf_Die* die,
8671 Dwarf_Addr& address,
8672 bool& is_tls_address)
8674 Dwarf_Op* expr = NULL;
8675 size_t expr_len = 0;
8677 is_tls_address =
false;
8682 Dwarf_Attribute attr;
8683 if (!dwarf_attr_integrate(
const_cast<Dwarf_Die*
>(die), DW_AT_location, &attr))
8686 if (dwarf_getlocation(&attr, &expr, &expr_len))
8693 Dwarf_Attribute result;
8694 if (!dwarf_getlocation_attr(&attr, expr, &result))
8696 return !dwarf_formaddr(&result, &address);
8699 address = expr->number;
8714die_virtual_function_index(Dwarf_Die* die,
8720 Dwarf_Op* expr = NULL;
8721 size_t expr_len = 0;
8722 if (die_is_virtual(die))
8724 if (!die_location_expr(die, DW_AT_vtable_elem_location,
8729 bool is_tls_addr =
false;
8730 if (!eval_last_constant_dwarf_sub_expr(expr, expr_len, i, is_tls_addr))
8748 int tag = dwarf_tag(die);
8750 if (tag == DW_TAG_class_type
8751 || tag == DW_TAG_structure_type
8752 || tag == DW_TAG_union_type
8753 || tag == DW_TAG_enumeration_type)
8754 return die_is_anonymous(die);
8776get_internal_anonymous_die_prefix_name(
const Dwarf_Die *die)
8779 ABG_ASSERT(die_string_attribute(die, DW_AT_name) ==
"");
8781 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
8783 if (tag == DW_TAG_class_type || tag == DW_TAG_structure_type)
8785 else if (tag == DW_TAG_union_type)
8787 else if (tag == DW_TAG_enumeration_type)
8817 const Dwarf_Die* die,
8819 reader::tu_context_type_sptr& tu_ctxt,
8820 unordered_set<void*>& guard)
8825 int tag = dwarf_tag (
const_cast<Dwarf_Die*
>(die));
8826 if (tag == DW_TAG_compile_unit
8827 || tag == DW_TAG_partial_unit
8828 || tag == DW_TAG_type_unit)
8831 string name = die_name(die);
8833 Dwarf_Die scope_die;
8834 if (!rdr.get_scope_die(die, where, tu_ctxt, scope_die))
8837 bool colon_colon = die_is_type(die) || die_is_namespace(die);
8838 string separator = colon_colon ?
"::" :
".";
8844 case DW_TAG_unspecified_type:
8847 case DW_TAG_base_type:
8857 case DW_TAG_typedef:
8861 case DW_TAG_enumeration_type:
8862 case DW_TAG_structure_type:
8863 case DW_TAG_class_type:
8864 case DW_TAG_union_type:
8866 if (die_is_anonymous(die))
8870 where, tu_ctxt, guard);
8873 string parent_name = die_qualified_name(rdr, &scope_die,
8874 where, tu_ctxt, guard);
8875 repr = parent_name.empty() ? name : parent_name + separator + name;
8880 case DW_TAG_const_type:
8881 case DW_TAG_volatile_type:
8882 case DW_TAG_restrict_type:
8884 Dwarf_Die underlying_type_die;
8885 bool has_underlying_type_die =
8886 die_die_attribute(die, DW_AT_type, underlying_type_die);
8888 if (has_underlying_type_die && die_is_unspecified(&underlying_type_die))
8891 if (tag == DW_TAG_const_type)
8893 if (has_underlying_type_die
8894 && die_is_reference_type(&underlying_type_die))
8904 else if (!has_underlying_type_die
8905 || die_is_void_type(&underlying_type_die))
8913 else if (tag == DW_TAG_volatile_type)
8915 else if (tag == DW_TAG_restrict_type)
8920 string underlying_type_repr;
8921 if (has_underlying_type_die)
8922 underlying_type_repr =
8924 where, tu_ctxt, guard);
8926 underlying_type_repr =
"void";
8928 if (underlying_type_repr.empty())
8932 if (has_underlying_type_die)
8935 die_peel_qualified(&underlying_type_die, peeled);
8936 if (die_is_pointer_or_reference_type(&peeled))
8937 repr = underlying_type_repr +
" " + repr;
8939 repr +=
" " + underlying_type_repr;
8942 repr +=
" " + underlying_type_repr;
8947 case DW_TAG_pointer_type:
8948 case DW_TAG_reference_type:
8949 case DW_TAG_rvalue_reference_type:
8951 Dwarf_Die pointed_to_type_die;
8952 if (!die_die_attribute(die, DW_AT_type, pointed_to_type_die))
8954 if (tag == DW_TAG_pointer_type)
8959 if (die_is_unspecified(&pointed_to_type_die))
8962 string pointed_type_repr =
8964 where, tu_ctxt, guard);
8966 repr = pointed_type_repr;
8970 if (tag == DW_TAG_pointer_type)
8972 else if (tag == DW_TAG_reference_type)
8974 else if (tag == DW_TAG_rvalue_reference_type)
8981 case DW_TAG_subrange_type:
8994 build_subrange_type(
const_cast<reader&
>(rdr),
8995 die, where, tu_ctxt,
8997 repr += s->as_string();
9001 case DW_TAG_array_type:
9003 Dwarf_Die element_type_die;
9004 if (!die_die_attribute(die, DW_AT_type, element_type_die))
9006 string element_type_name =
9008 where, tu_ctxt, guard);
9009 if (element_type_name.empty())
9013 build_subranges_from_array_type_die(
const_cast<reader&
>(rdr),
9014 die, subranges, where, tu_ctxt,
9017 repr = element_type_name;
9022 case DW_TAG_subroutine_type:
9023 case DW_TAG_subprogram:
9025 string return_type_name;
9027 vector<string> parm_names;
9028 bool is_const =
false;
9029 bool is_static =
false;
9031 die_return_and_parm_names_from_fn_type_die(rdr, die, where,
9035 return_type_name, class_name,
9036 parm_names, is_const,
9037 is_static, tu_ctxt, guard);
9038 if (return_type_name.empty())
9039 return_type_name =
"void";
9041 repr = return_type_name;
9045 repr +=
" (" + class_name +
"::*)";
9049 for (vector<string>::const_iterator i = parm_names.begin();
9050 i != parm_names.end();
9053 if (i != parm_names.begin())
9062 case DW_TAG_string_type:
9063 case DW_TAG_ptr_to_member_type:
9064 case DW_TAG_set_type:
9065 case DW_TAG_file_type:
9066 case DW_TAG_packed_type:
9067 case DW_TAG_thrown_type:
9068 case DW_TAG_interface_type:
9069 case DW_TAG_shared_type:
9094die_qualified_decl_name(
const reader& rdr,
9095 const Dwarf_Die* die,
9097 reader::tu_context_type_sptr& tu_ctxt,
9098 unordered_set<void*>& guard)
9100 if (!die || !die_is_decl(die))
9103 string name = die_name(die);
9105 Dwarf_Die scope_die;
9106 if (!rdr.get_scope_die(die, where_addr, tu_ctxt, scope_die))
9109 string scope_name = die_qualified_name(rdr, &scope_die, where_addr,
9111 string separator =
"::";
9115 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
9118 case DW_TAG_namespace:
9120 case DW_TAG_variable:
9121 repr = scope_name.empty() ? name : scope_name + separator + name;
9123 case DW_TAG_subprogram:
9124 repr = die_function_signature(rdr, die,
9126 where_addr, tu_ctxt, guard);
9129 case DW_TAG_unspecified_parameters:
9133 case DW_TAG_formal_parameter:
9134 case DW_TAG_imported_declaration:
9135 case DW_TAG_GNU_template_template_param:
9136 case DW_TAG_GNU_template_parameter_pack:
9137 case DW_TAG_GNU_formal_parameter_pack:
9165die_qualified_name(
const reader& rdr,
const Dwarf_Die* die,
void* where,
9166 reader::tu_context_type_sptr& tu_ctxt,
9167 unordered_set<void*>& guard)
9169 if (die_is_type(die))
9171 else if (die_is_decl(die))
9172 return die_qualified_decl_name(rdr, die, where, tu_ctxt, guard);
9193die_qualified_name(
const reader& rdr,
const Dwarf_Die* die,
void* where,
9194 reader::tu_context_type_sptr& tu_ctxt)
9196 unordered_set<void*> guard;
9197 return die_qualified_name(rdr, die, where, tu_ctxt, guard);
9223die_qualified_type_name_empty(
const reader& rdr,
9224 const Dwarf_Die* die,
9225 void* where,
string &qualified_name,
9226 reader::tu_context_type_sptr& tu_ctxt,
9227 unordered_set<void*>& guard)
9232 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
9235 if (tag == DW_TAG_typedef
9236 || tag == DW_TAG_pointer_type
9237 || tag == DW_TAG_reference_type
9238 || tag == DW_TAG_rvalue_reference_type
9239 || tag == DW_TAG_array_type
9240 || tag == DW_TAG_const_type
9241 || tag == DW_TAG_volatile_type
9242 || tag == DW_TAG_restrict_type)
9244 Dwarf_Die underlying_type_die;
9245 if (die_die_attribute(die, DW_AT_type, underlying_type_die))
9249 where, tu_ctxt, guard);
9266 qualified_name = qname;
9317die_return_and_parm_names_from_fn_type_die(
const reader& rdr,
9318 const Dwarf_Die* die,
9321 bool qualified_name,
9323 string &return_type_name,
9325 vector<string>& parm_names,
9328 reader::tu_context_type_sptr& tu_ctxt,
9329 unordered_set<void*>& guard)
9334 if (guard.find(die->addr) != guard.end())
9336 guard.insert(die->addr);
9339 Dwarf_Die ret_type_die;
9340 if (!die_die_attribute(die, DW_AT_type, ret_type_die))
9341 return_type_name =
"void";
9346 ? rdr.get_die_pretty_representation(&ret_type_die, where_addr,
9348 : die_type_name(rdr, &ret_type_die, qualified_name,
9349 where_addr, tu_ctxt, guard);
9352 if (return_type_name.empty())
9353 return_type_name =
"void";
9355 Dwarf_Die object_pointer_die, class_die;
9357 die_function_type_is_method_type(rdr, die, where_addr,
9358 tu_ctxt, object_pointer_die,
9359 class_die, is_static);
9365 class_name = die_type_name(rdr, &class_die, qualified_name,
9366 where_addr, tu_ctxt, guard);
9368 Dwarf_Die this_pointer_die;
9369 Dwarf_Die pointed_to_die;
9371 && die_die_attribute(&object_pointer_die, DW_AT_type,
9373 if (die_die_attribute(&this_pointer_die, DW_AT_type, pointed_to_die))
9374 if (dwarf_tag(&pointed_to_die) == DW_TAG_const_type)
9377 string fn_name = die_name(die);
9378 string non_qualified_class_name = die_name(&class_die);
9379 bool is_ctor = fn_name == non_qualified_class_name;
9380 bool is_dtor = !fn_name.empty() && fn_name[0] ==
'~';
9382 if (is_ctor || is_dtor)
9383 return_type_name.clear();
9386 if (dwarf_child(
const_cast<Dwarf_Die*
>(die), &child) == 0)
9389 int child_tag = dwarf_tag(&child);
9390 bool first_parm =
true;
9391 if (child_tag == DW_TAG_formal_parameter)
9400 Dwarf_Die parm_type_die;
9401 if (!die_die_attribute(&child, DW_AT_type, parm_type_die))
9405 ? rdr.get_die_pretty_representation(&parm_type_die, where_addr,
9407 : die_type_name(rdr, &parm_type_die,
9408 qualified_name, where_addr, tu_ctxt, guard);
9412 parm_names.push_back(qname);
9414 else if (child_tag == DW_TAG_unspecified_parameters)
9417 parm_names.push_back(rdr.env().get_variadic_parameter_type_name());
9427 while (dwarf_siblingof(&child, &child) == 0);
9429 if (class_name.empty())
9431 Dwarf_Die parent_die;
9432 if (rdr.get_parent_die(die, parent_die, where_addr, tu_ctxt))
9434 if (die_is_class_type(&parent_die)
9436 class_name = die_type_name(rdr, &parent_die, qualified_name,
9437 where_addr, tu_ctxt, guard);
9441 guard.erase(die->addr);
9464die_function_signature(
const reader& rdr,
const Dwarf_Die *fn_die,
9465 bool qualified_name,
void* where_addr,
9466 reader::tu_context_type_sptr& tu_ctxt,
9467 unordered_set<void*>& guard)
9471 bool has_lang =
false;
9472 if ((has_lang = get_die_language(fn_die, lang)))
9480 string fn_name = die_linkage_name(fn_die);
9481 if (fn_name.empty())
9482 fn_name = die_name(fn_die);
9492 string return_type_name;
9493 Dwarf_Die ret_type_die;
9494 if (die_die_attribute(fn_die, DW_AT_type, ret_type_die))
9496 rdr.get_die_qualified_type_name(&ret_type_die, where_addr,
9499 if (return_type_name.empty())
9500 return_type_name =
"void";
9502 Dwarf_Die scope_die;
9504 if (qualified_name && rdr.get_scope_die(fn_die, where_addr,
9505 tu_ctxt, scope_die))
9506 scope_name = rdr.get_die_qualified_name(&scope_die, where_addr,
9508 string fn_name = die_name(fn_die);
9509 if (!scope_name.empty())
9510 fn_name = scope_name +
"::" + fn_name;
9513 vector<string> parm_names;
9514 bool is_const =
false;
9515 bool is_static =
false;
9518 die_return_and_parm_names_from_fn_type_die(rdr, fn_die, where_addr,
9521 return_type_name, class_name,
9522 parm_names, is_const, is_static,
9525 bool is_virtual = die_is_virtual(fn_die);
9531 if (!return_type_name.empty())
9532 repr +=
" " + return_type_name;
9534 repr +=
" " + fn_name;
9538 bool some_parm_emitted =
false;
9539 for (vector<string>::const_iterator i = parm_names.begin();
9540 i != parm_names.end();
9543 if (i != parm_names.begin())
9545 if (some_parm_emitted)
9554 some_parm_emitted =
true;
9599die_class_flat_representation(
const reader& rdr,
9600 const Dwarf_Die* die,
9601 const string& indent,
9603 bool qualified_names,
9605 reader::tu_context_type_sptr& tu_ctxt,
9606 unordered_set<void*>& guard)
9608 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
9610 string repr = indent;
9611 string local_indent =
" ";
9614 if (tag == DW_TAG_union_type)
9616 else if (tag == DW_TAG_structure_type)
9618 else if (tag == DW_TAG_class_type)
9625 if (die_is_anonymous(die))
9627 if (guard.find(die->addr) != guard.end())
9632 guard.insert(die->addr);
9635 if (!die_is_anonymous(die))
9636 repr += die_qualified_name(rdr, die, where_addr, tu_ctxt, guard);
9643 Dwarf_Die member_child_die;
9644 bool first_sibling =
true;
9645 for (
bool got_it = get_member_child_die(die, &member_child_die);
9647 got_it = get_next_member_sibling_die(&member_child_die,
9649 first_sibling =
false)
9653 if (!die_is_decl(&member_child_die)
9654 && !(die_is_type(&member_child_die)
9655 && die_is_anonymous(&member_child_die)))
9659 real_indent = first_sibling ?
"" :
" " ;
9661 real_indent = (first_sibling ?
"":
"\n") + indent + local_indent;
9663 repr += real_indent;
9665 repr += die_pretty_print_decl(rdr, &member_child_die,
9668 where_addr, tu_ctxt, guard);
9675 repr += indent +
"}";
9677 if (die_is_anonymous(die))
9678 guard.erase(die->addr);
9708die_enum_flat_representation(
const reader& rdr,
9709 const Dwarf_Die* die,
9710 const string& indent,
9712 bool qualified_names,
9714 reader::tu_context_type_sptr& tu_ctxt)
9716 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
9718 std::ostringstream o;
9719 string local_indent =
" ";
9722 if (tag == DW_TAG_enumeration_type)
9729 if (!die_is_anonymous(die))
9730 o << (qualified_names
9731 ? die_qualified_name(rdr, die, where_addr, tu_ctxt)
9741 bool first_enumerator=
true;
9742 if (dwarf_child(
const_cast<Dwarf_Die*
>(die), &child) == 0)
9746 if (dwarf_tag(&child) != DW_TAG_enumerator)
9751 die_loc_and_name(&child, tu_ctxt, l, name, m);
9753 die_unsigned_constant_attribute(&child, DW_AT_const_value, val);
9756 real_indent = first_enumerator ?
"" :
", ";
9758 real_indent = first_enumerator ?
"" :
",\n" + indent + local_indent;
9759 o << name +
" = " << val;
9760 first_enumerator =
false;
9762 while (dwarf_siblingof(&child, &child) == 0);
9807 const Dwarf_Die* die,
9808 const string& indent,
9810 bool qualified_names,
9812 reader::tu_context_type_sptr& tu_ctxt,
9813 unordered_set<void*>& guard)
9819 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
9823 case DW_TAG_class_type:
9824 case DW_TAG_structure_type:
9825 case DW_TAG_union_type:
9826 result = die_class_flat_representation(rdr, die, indent,
9827 one_line, qualified_names,
9828 where_addr, tu_ctxt, guard);
9830 case DW_TAG_enumeration_type:
9831 result = die_enum_flat_representation(rdr, die, indent,
9832 one_line, qualified_names,
9833 where_addr, tu_ctxt);
9870 const Dwarf_Die* die,
9871 const string& indent,
9873 bool qualified_names,
9875 reader::tu_context_type_sptr& tu_ctxt)
9877 unordered_set<void*> guard;
9879 one_line, qualified_names,
9880 where_addr, tu_ctxt, guard);
9902die_type_name(
const reader& rdr,
9903 const Dwarf_Die* die,
9904 bool qualified_name,
9906 reader::tu_context_type_sptr& tu_ctxt,
9907 unordered_set<void*>& guard)
9912 int tag = dwarf_tag (
const_cast<Dwarf_Die*
>(die));
9913 if (tag == DW_TAG_compile_unit
9914 || tag == DW_TAG_partial_unit
9915 || tag == DW_TAG_type_unit)
9918 string name = die_name(die);
9920 Dwarf_Die scope_die;
9921 if (!rdr.get_scope_die(die, where_addr, tu_ctxt, scope_die))
9924 bool colon_colon = die_is_type(die) || die_is_namespace(die);
9925 string separator = colon_colon ?
"::" :
".";
9931 case DW_TAG_unspecified_type:
9934 case DW_TAG_base_type:
9944 case DW_TAG_typedef:
9948 case DW_TAG_enumeration_type:
9949 case DW_TAG_structure_type:
9950 case DW_TAG_class_type:
9951 case DW_TAG_union_type:
9953 if (die_is_anonymous(die))
9957 where_addr, tu_ctxt,
9965 parent_name = die_qualified_name(rdr, &scope_die,
9966 where_addr, tu_ctxt, guard);
9968 repr = parent_name.empty() ? name : parent_name + separator + name;
9973 case DW_TAG_const_type:
9974 case DW_TAG_volatile_type:
9975 case DW_TAG_restrict_type:
9977 Dwarf_Die underlying_type_die;
9978 bool has_underlying_type_die =
9979 die_die_attribute(die, DW_AT_type, underlying_type_die);
9981 if (has_underlying_type_die && die_is_unspecified(&underlying_type_die))
9984 if (tag == DW_TAG_const_type)
9986 if (has_underlying_type_die
9987 && die_is_reference_type(&underlying_type_die))
9997 else if (!has_underlying_type_die
9998 || die_is_void_type(&underlying_type_die))
10006 else if (tag == DW_TAG_volatile_type)
10008 else if (tag == DW_TAG_restrict_type)
10013 string underlying_type_repr;
10014 if (has_underlying_type_die)
10015 underlying_type_repr =
10016 die_type_name(rdr, &underlying_type_die,
10017 qualified_name, where_addr,
10020 underlying_type_repr =
"void";
10022 if (underlying_type_repr.empty())
10026 if (has_underlying_type_die)
10029 die_peel_qualified(&underlying_type_die, peeled);
10030 if (die_is_pointer_or_reference_type(&peeled))
10031 repr = underlying_type_repr +
" " + repr;
10033 repr +=
" " + underlying_type_repr;
10036 repr +=
" " + underlying_type_repr;
10041 case DW_TAG_pointer_type:
10042 case DW_TAG_reference_type:
10043 case DW_TAG_rvalue_reference_type:
10045 Dwarf_Die pointed_to_type_die;
10046 if (!die_die_attribute(die, DW_AT_type, pointed_to_type_die))
10048 if (tag == DW_TAG_pointer_type)
10053 if (die_is_unspecified(&pointed_to_type_die))
10056 string pointed_type_repr =
10057 die_type_name(rdr, &pointed_to_type_die,
10058 qualified_name, where_addr,
10061 repr = pointed_type_repr;
10065 if (tag == DW_TAG_pointer_type)
10067 else if (tag == DW_TAG_reference_type)
10069 else if (tag == DW_TAG_rvalue_reference_type)
10076 case DW_TAG_subrange_type:
10089 build_subrange_type(
const_cast<reader&
>(rdr),
10090 die, where_addr, tu_ctxt,
10092 repr += s->as_string();
10096 case DW_TAG_array_type:
10098 Dwarf_Die element_type_die;
10099 if (!die_die_attribute(die, DW_AT_type, element_type_die))
10101 string element_type_name =
10102 die_type_name(rdr, &element_type_die,
10103 qualified_name, where_addr,
10105 if (element_type_name.empty())
10109 build_subranges_from_array_type_die(
const_cast<reader&
>(rdr), die,
10110 subranges, where_addr, tu_ctxt,
10113 repr = element_type_name;
10118 case DW_TAG_subroutine_type:
10119 case DW_TAG_subprogram:
10121 string return_type_name;
10123 vector<string> parm_names;
10124 bool is_const =
false;
10125 bool is_static =
false;
10127 die_return_and_parm_names_from_fn_type_die(rdr, die, where_addr,
10133 parm_names, is_const,
10134 is_static, tu_ctxt, guard);
10135 if (return_type_name.empty())
10136 return_type_name =
"void";
10138 repr = return_type_name;
10143 repr +=
" (" + class_name +
"::*)";
10148 for (vector<string>::const_iterator i = parm_names.begin();
10149 i != parm_names.end();
10152 if (i != parm_names.begin())
10161 case DW_TAG_string_type:
10162 case DW_TAG_ptr_to_member_type:
10163 case DW_TAG_set_type:
10164 case DW_TAG_file_type:
10165 case DW_TAG_packed_type:
10166 case DW_TAG_thrown_type:
10167 case DW_TAG_interface_type:
10168 case DW_TAG_shared_type:
10189die_type_name(
const reader& rdr,
10190 const Dwarf_Die* die,
10191 bool qualified_name,
10193 reader::tu_context_type_sptr& tu_ctxt)
10195 unordered_set<void*> guard;
10196 return die_type_name(rdr, die, qualified_name,
10197 where_addr, tu_ctxt, guard);
10223die_pretty_print_type(
const reader& rdr,
const Dwarf_Die* die,
void* where_addr,
10224 reader::tu_context_type_sptr& tu_ctxt,
10225 unordered_set<void*>& guard)
10228 || (!die_is_type(die)
10229 && dwarf_tag(
const_cast<Dwarf_Die*
>(die)) != DW_TAG_subprogram))
10234 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
10237 case DW_TAG_string_type:
10246 repr =
"string type";
10248 case DW_TAG_unspecified_type:
10249 case DW_TAG_ptr_to_member_type:
10252 case DW_TAG_namespace:
10253 repr =
"namespace " + rdr.get_die_qualified_type_name(die, where_addr,
10257 case DW_TAG_base_type:
10258 repr = rdr.get_die_qualified_type_name(die, where_addr, tu_ctxt, guard);
10261 case DW_TAG_typedef:
10263 string qualified_name;
10264 if (!die_qualified_type_name_empty(rdr, die,
10268 repr =
"typedef " + qualified_name;
10272 case DW_TAG_const_type:
10273 case DW_TAG_volatile_type:
10274 case DW_TAG_restrict_type:
10275 case DW_TAG_pointer_type:
10276 case DW_TAG_reference_type:
10277 case DW_TAG_rvalue_reference_type:
10278 repr = rdr.get_die_qualified_type_name(die, where_addr, tu_ctxt, guard);
10281 case DW_TAG_enumeration_type:
10283 string qualified_name =
10284 rdr.get_die_qualified_type_name(die, where_addr, tu_ctxt, guard);
10285 repr =
"enum " + qualified_name;
10289 case DW_TAG_structure_type:
10290 case DW_TAG_class_type:
10292 string qualified_name =
10293 rdr.get_die_qualified_type_name(die, where_addr, tu_ctxt, guard);
10294 repr =
"class " + qualified_name;
10298 case DW_TAG_union_type:
10300 string qualified_name =
10301 rdr.get_die_qualified_type_name(die, where_addr, tu_ctxt, guard);
10302 repr =
"union " + qualified_name;
10306 case DW_TAG_array_type:
10308 Dwarf_Die element_type_die;
10309 if (!die_die_attribute(die, DW_AT_type, element_type_die))
10311 string element_type_name =
10312 rdr.get_die_qualified_type_name(&element_type_die, where_addr,
10314 if (element_type_name.empty())
10318 build_subranges_from_array_type_die(rdr, die, subranges,
10319 where_addr, tu_ctxt,
10322 repr = element_type_name;
10327 case DW_TAG_subrange_type:
10341 case DW_TAG_subroutine_type:
10342 case DW_TAG_subprogram:
10344 string return_type_name;
10346 vector<string> parm_names;
10347 bool is_const =
false;
10348 bool is_static =
false;
10350 die_return_and_parm_names_from_fn_type_die(rdr, die, where_addr,
10354 return_type_name, class_name,
10355 parm_names, is_const,
10356 is_static, tu_ctxt, guard);
10358 repr =
"function type";
10360 repr =
"method type";
10361 repr +=
" " + rdr.get_die_qualified_type_name(die, where_addr,
10366 case DW_TAG_set_type:
10367 case DW_TAG_file_type:
10368 case DW_TAG_packed_type:
10369 case DW_TAG_thrown_type:
10370 case DW_TAG_interface_type:
10371 case DW_TAG_shared_type:
10404die_pretty_print_decl(
const reader& rdr,
const Dwarf_Die* die,
10405 bool qualified_name,
bool include_fns,
10406 void* where_offset,
10407 reader::tu_context_type_sptr& tu_ctxt,
10408 unordered_set<void*>& guard)
10410 if (!die || !die_is_decl(die))
10415 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
10418 case DW_TAG_namespace:
10419 repr =
"namespace " + die_qualified_name(rdr, die, where_offset,
10423 case DW_TAG_member:
10424 case DW_TAG_variable:
10426 string type_repr =
"void";
10427 Dwarf_Die type_die;
10428 if (die_die_attribute(die, DW_AT_type, type_die))
10429 type_repr = die_type_name(rdr, &type_die, qualified_name,
10430 where_offset, tu_ctxt, guard);
10431 repr = (qualified_name
10432 ? die_qualified_name(rdr, die, where_offset, tu_ctxt, guard)
10438 repr = type_repr +
" " + repr;
10442 case DW_TAG_subprogram:
10444 repr = die_function_signature(rdr, die, qualified_name,
10445 where_offset, tu_ctxt, guard);
10477 reader::tu_context_type_sptr& tu_ctxt,
10478 unordered_set<void*>& guard)
10480 if (die_is_type(die))
10481 return die_pretty_print_type(rdr, die, where_addr, tu_ctxt, guard);
10482 else if (die_is_decl(die))
10483 return die_pretty_print_decl(rdr, die,
10486 where_addr, tu_ctxt, guard);
10504get_next_member_sibling_die(
const Dwarf_Die *die, Dwarf_Die *member)
10509 bool found_member =
false;
10510 for (found_member = (dwarf_siblingof(
const_cast<Dwarf_Die*
>(die),
10513 found_member = (dwarf_siblingof(member, member) == 0))
10515 int tag = dwarf_tag(member);
10516 if (tag == DW_TAG_member || tag == DW_TAG_inheritance)
10520 return found_member;
10537get_member_child_die(
const Dwarf_Die *die, Dwarf_Die *child)
10542 int tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
10544 || tag == DW_TAG_union_type
10545 || tag == DW_TAG_class_type);
10547 bool found_child = (dwarf_child(
const_cast<Dwarf_Die*
>(die), child) == 0);
10552 tag = dwarf_tag(child);
10554 if (!(tag == DW_TAG_member
10555 || tag == DW_TAG_inheritance
10556 || tag == DW_TAG_subprogram))
10557 found_child = get_next_member_sibling_die(child, child);
10559 return found_child;
10569get_global_scope(reader::tu_context_type_sptr& tu_ctxt)
10571 return tu_ctxt->get_tu()->get_global_scope();
10591get_global_scope(reader& rdr,
10592 reader::tu_context_type_sptr& tu_ctxt,
10593 const Dwarf_Die* die)
10605 if (!die || dwarf_tag(
const_cast<Dwarf_Die*
>(die)) != DW_TAG_compile_unit)
10608 tu = tu_ctxt->get_tu();
10612 return tu->get_global_scope();;
10640get_scope_for_die(reader& rdr,
10642 bool called_for_public_decl,
10644 reader::tu_context_type_sptr& tu_ctxt)
10646 Dwarf_Die origin_die_mem;
10647 Dwarf_Die *die = &origin_die_mem;
10649 if (!die_origin_die(dye, origin_die_mem))
10652 memcpy(&origin_die_mem, dye,
sizeof(origin_die_mem));
10655 get_die_language(die, die_lang);
10656 if (
is_c_language(die_lang) || rdr.die_parent_map().empty())
10662 ABG_ASSERT(dwarf_tag(die) != DW_TAG_member);
10663 return get_global_scope(rdr, tu_ctxt, die);
10666 int tag = dwarf_tag(die);
10667 Dwarf_Die parent_die;
10668 bool got_parent =
false;
10670 if (tag == DW_TAG_subprogram)
10672 Dwarf_Die object_ptr_die;
10673 if (get_member_fn_class_die_from_object_pointer(die, parent_die,
10678 if (!got_parent && !rdr.get_parent_die(die, parent_die,
10679 where_addr, tu_ctxt))
10680 return rdr.nil_scope();
10682 if (dwarf_tag(&parent_die) == DW_TAG_compile_unit
10683 || dwarf_tag(&parent_die) == DW_TAG_partial_unit
10684 || dwarf_tag(&parent_die) == DW_TAG_type_unit)
10686 if (dwarf_tag(&parent_die) == DW_TAG_partial_unit
10687 || dwarf_tag(&parent_die) == DW_TAG_type_unit)
10688 return get_global_scope(tu_ctxt);
10697 return get_global_scope(rdr, tu_ctxt, &parent_die);
10702 if (dwarf_tag(&parent_die) == DW_TAG_array_type
10703 || dwarf_tag(&parent_die) == DW_TAG_lexical_block)
10714 called_for_public_decl,
10715 where_addr, tu_ctxt);
10723 if (!rdr.get_parent_die(&parent_die, parent_die,
10724 where_addr, tu_ctxt))
10725 return rdr.nil_scope();
10726 s = get_scope_for_die(rdr, &parent_die,
10727 called_for_public_decl,
10728 where_addr, tu_ctxt);
10733 d = build_ir_node_from_die(rdr, &parent_die,
10734 called_for_public_decl,
10735 where_addr, tu_ctxt,
10737 s = dynamic_pointer_cast<scope_decl>(d);
10741 return rdr.nil_scope();
10744 if (cl && cl->get_is_declaration_only())
10747 dynamic_pointer_cast<scope_decl>(cl->get_definition_of_declaration());
10764dwarf_language_to_tu_language(
size_t l)
10769 return translation_unit::LANG_C89;
10771 return translation_unit::LANG_C99;
10772#ifdef HAVE_DW_LANG_C11_enumerator
10774 return translation_unit::LANG_C11;
10776#ifdef HAVE_DW_LANG_C17
10778 return translation_unit::LANG_C17;
10780#ifdef HAVE_DW_LANG_C23
10782 return translation_unit::LANG_C23;
10785 return translation_unit::LANG_C;
10786#ifdef HAVE_DW_LANG_C_plus_plus_03_enumerator
10787 case DW_LANG_C_plus_plus_03:
10788 return translation_unit::LANG_C_plus_plus_03;
10791#ifdef HAVE_DW_LANG_C_plus_plus_11_enumerator
10792 case DW_LANG_C_plus_plus_11:
10793 return translation_unit::LANG_C_plus_plus_11;
10796#ifdef HAVE_DW_LANG_C_plus_plus_14_enumerator
10797 case DW_LANG_C_plus_plus_14:
10798 return translation_unit::LANG_C_plus_plus_14;
10800#ifdef HAVE_DW_LANG_C_plus_plus_17
10801 case DW_LANG_C_plus_plus_17:
10802 return translation_unit::LANG_C_plus_plus_17;
10805#ifdef HAVE_DW_LANG_C_plus_plus_20
10806 case DW_LANG_C_plus_plus_20:
10807 return translation_unit::LANG_C_plus_plus_20;
10809#ifdef HAVE_DW_LANG_C_plus_plus_23
10810 case DW_LANG_C_plus_plus_23:
10811 return translation_unit::LANG_C_plus_plus_23;
10813 case DW_LANG_C_plus_plus:
10814 return translation_unit::LANG_C_plus_plus;
10815#ifdef HAVE_DW_LANG_D_enumerator
10817 return translation_unit::LANG_D;
10819#ifdef HAVE_DW_LANG_OCaml_enumerator
10820 case DW_LANG_OCaml:
10821 return translation_unit::LANG_OCaml;
10823#ifdef HAVE_DW_LANG_Go_enumerator
10825 return translation_unit::LANG_Go;
10827#ifdef HAVE_DW_LANG_Rust_enumerator
10829 return translation_unit::LANG_Rust;
10831#ifdef HAVE_DW_LANG_Zig
10833 return translation_unit::LANG_Zig;
10835#ifdef HAVE_DW_LANG_Metal
10836 case DW_LANG_Metal:
10837 return translation_unit::LANG_Metal;
10839 case DW_LANG_Ada83:
10840 return translation_unit::LANG_Ada83;
10841 case DW_LANG_Ada95:
10842 return translation_unit::LANG_Ada95;
10843#ifdef HAVE_DW_LANG_Ada2005
10844 case DW_LANG_Ada2005:
10845 return translation_unit::LANG_Ada2005;
10848#ifdef HAVE_DW_LANG_Ada2012
10849 case DW_LANG_Ada2012:
10850 return translation_unit::LANG_Ada2012;
10852 case DW_LANG_Cobol74:
10853 return translation_unit::LANG_Cobol74;
10854 case DW_LANG_Cobol85:
10855 return translation_unit::LANG_Cobol85;
10856 case DW_LANG_Fortran77:
10857 return translation_unit::LANG_Fortran77;
10858 case DW_LANG_Fortran90:
10859 return translation_unit::LANG_Fortran90;
10860 case DW_LANG_Fortran95:
10861 return translation_unit::LANG_Fortran95;
10862#ifdef HAVE_DW_LANG_Fortran18
10863 case DW_LANG_Fortran18:
10864 return translation_unit::LANG_Fortran18;
10866#ifdef HAVE_DW_LANG_Fortran23
10867 case DW_LANG_Fortran23:
10868 return translation_unit::LANG_Fortran23;
10870 case DW_LANG_Pascal83:
10871 return translation_unit::LANG_Pascal83;
10872 case DW_LANG_Modula2:
10873 return translation_unit::LANG_Modula2;
10875 return translation_unit::LANG_Java;
10876#ifdef HAVE_DW_LANG_Kotlin
10877 case DW_LANG_Kotlin:
10878 return translation_unit::LANG_Kotlin;
10881 return translation_unit::LANG_PLI;
10883 return translation_unit::LANG_ObjC;
10884 case DW_LANG_ObjC_plus_plus:
10885 return translation_unit::LANG_ObjC_plus_plus;
10887#ifdef HAVE_DW_LANG_UPC_enumerator
10889 return translation_unit::LANG_UPC;
10891#ifdef HAVE_DW_LANG_Python_enumerator
10892 case DW_LANG_Python:
10893 return translation_unit::LANG_Python;
10895#ifdef HAVE_DW_LANG_Ruby
10897 return translation_unit::LANG_Ruby;
10899#ifdef HAVE_DW_LANG_Mips_Assembler_enumerator
10900 case DW_LANG_Mips_Assembler:
10901 return translation_unit::LANG_Mips_Assembler;
10903#ifdef HAVE_DW_LANG_Assembly
10904 case DW_LANG_Assembly:
10905 return translation_unit::LANG_Assembly;
10907#ifdef HAVE_DW_LANG_Crystal
10908 case DW_LANG_Crystal:
10909 return translation_unit::LANG_Crystal;
10911#ifdef HAVE_DW_LANG_HIP
10913 return translation_unit::LANG_HIP;
10915#ifdef HAVE_DW_LANG_C_sharp
10916 case DW_LANG_C_sharp:
10917 return translation_unit::LANG_C_sharp;
10919#ifdef HAVE_DW_LANG_Mojo
10921 return translation_unit::LANG_Mojo;
10923#ifdef HAVE_DW_LANG_GLSL
10925 return translation_unit::LANG_GLSL;
10927#ifdef HAVE_DW_LANG_GLSL_ES
10928 case DW_LANG_GLSL_ES:
10929 return translation_unit::LANG_GLSL_ES;
10931#ifdef HAVE_DW_LANG_HLSL
10933 return translation_unit::LANG_HLSL;
10935#ifdef HAVE_DW_LANG_OpenCL_CPP
10936 case DW_LANG_OpenCL_CPP:
10937 return translation_unit::LANG_OpenCL_CPP;
10939#ifdef HAVE_DW_LANG_CPP_for_OpenCL
10940 case DW_LANG_CPP_for_OpenCL:
10941 return translation_unit::LANG_CPP_for_OpenCL;
10943#ifdef HAVE_DW_LANG_SYCL
10945 return translation_unit::LANG_SYCL;
10947#ifdef HAVE_DW_LANG_Odin
10949 return translation_unit::LANG_Odin;
10951#ifdef HAVE_DW_LANG_P4
10953 return translation_unit::LANG_P4;
10955#ifdef HAVE_DW_LANG_Move
10957 return translation_unit::LANG_Move;
10959#ifdef HAVE_DW_LANG_Hylo
10961 return translation_unit::LANG_Hylo;
10965 return translation_unit::LANG_UNKNOWN;
10982 case translation_unit::LANG_UNKNOWN:
10983 case translation_unit::LANG_C89:
10984 case translation_unit::LANG_C99:
10985 case translation_unit::LANG_C11:
10986 case translation_unit::LANG_C17:
10987 case translation_unit::LANG_C23:
10988 case translation_unit::LANG_C:
10989 case translation_unit::LANG_C_plus_plus_03:
10990 case translation_unit::LANG_C_plus_plus_11:
10991 case translation_unit::LANG_C_plus_plus_14:
10992 case translation_unit::LANG_C_plus_plus_17:
10993 case translation_unit::LANG_C_plus_plus_20:
10994 case translation_unit::LANG_C_plus_plus_23:
10995 case translation_unit::LANG_C_plus_plus:
10996 case translation_unit::LANG_OCaml:
10997 case translation_unit::LANG_ObjC:
10998 case translation_unit::LANG_ObjC_plus_plus:
10999 case translation_unit::LANG_D:
11000 case translation_unit::LANG_Rust:
11001 case translation_unit::LANG_Go:
11002 case translation_unit::LANG_Zig:
11003 case translation_unit::LANG_Metal:
11004 case translation_unit::LANG_Java:
11005 case translation_unit::LANG_Kotlin:
11006 case translation_unit::LANG_Python:
11007 case translation_unit::LANG_Ruby:
11008 case translation_unit::LANG_UPC:
11009 case translation_unit::LANG_Mips_Assembler:
11010 case translation_unit::LANG_Assembly:
11011 case translation_unit::LANG_Crystal:
11012 case translation_unit::LANG_HIP:
11013 case translation_unit::LANG_C_sharp:
11014 case translation_unit::LANG_Mojo:
11015 case translation_unit::LANG_GLSL:
11016 case translation_unit::LANG_GLSL_ES:
11017 case translation_unit::LANG_HLSL:
11018 case translation_unit::LANG_Odin:
11019 case translation_unit::LANG_P4:
11020 case translation_unit::LANG_OpenCL_CPP:
11021 case translation_unit::LANG_CPP_for_OpenCL:
11022 case translation_unit::LANG_SYCL:
11023 case translation_unit::LANG_Move:
11024 case translation_unit::LANG_Hylo:
11027 case translation_unit::LANG_Cobol74:
11028 case translation_unit::LANG_Cobol85:
11029 case translation_unit::LANG_Fortran77:
11030 case translation_unit::LANG_Fortran90:
11031 case translation_unit::LANG_Fortran95:
11032 case translation_unit::LANG_Fortran18:
11033 case translation_unit::LANG_Fortran23:
11034 case translation_unit::LANG_Ada83:
11035 case translation_unit::LANG_Ada95:
11036 case translation_unit::LANG_Ada2005:
11037 case translation_unit::LANG_Ada2012:
11038 case translation_unit::LANG_Pascal83:
11039 case translation_unit::LANG_Modula2:
11040 case translation_unit::LANG_PLI:
11067 imported_unit_points_type::const_iterator& r)
11069 imported_unit_point v(val);
11070 imported_unit_points_type::const_iterator result =
11071 std::lower_bound(p.begin(), p.end(), v);
11073 bool is_ok = result != p.end();
11100build_ir_nodes_from_imported_unit(reader& rdr,
11102 reader::tu_context_type_sptr tu_ctxt)
11104 Dwarf_Die unit_to_import;
11105 if (!die_die_attribute(die, DW_AT_import, unit_to_import))
11109 if (dwarf_child(&unit_to_import, &child) != 0)
11112 string s = die_string_attribute(&unit_to_import, DW_AT_comp_dir);
11117 do_handle_dwarf_die(rdr, tu_ctxt, child, die_is_public_decl(&child));
11118 while (dwarf_siblingof(&child, &child) == 0);
11124do_handle_dwarf_die(reader& rdr, reader::tu_context_type_sptr tu_ctxt,
11125 Dwarf_Die& die,
bool die_is_public)
11127 int tag = dwarf_tag(&die);
11129 if ((rdr.load_undefined_interfaces()
11130 && (rdr.is_decl_die_with_undefined_symbol(&die)
11131 || rdr.is_decl_die_with_exported_symbol(&die)))
11132 || tag == DW_TAG_namespace)
11136 build_ir_node_from_die(rdr, &die,
11141 die.addr, tu_ctxt);
11144 else if (rdr.is_decl_die_with_exported_symbol(&die)
11145 || (!rdr.env().analyze_exported_interfaces_only()
11146 && die_is_decl(&die))
11147 || (rdr.env().load_all_types() && die_is_type(&die)))
11152 build_ir_node_from_die(rdr, &die,
11154 die.addr, tu_ctxt);
11157 else if (tag == DW_TAG_imported_unit)
11159 build_ir_nodes_from_imported_unit(rdr, &die, tu_ctxt);
11179build_translation_unit_and_add_to_ir(reader& rdr,
11183 reader::tu_context_type_sptr result;
11186 result.reset(
new reader::tu_context_type(die, tu));
11189 if (dwarf_child(&die, &child) != 0)
11193 result->get_tu()->set_is_constructed(
false);
11196 do_handle_dwarf_die(rdr, result, child, die_is_public_decl(&child));
11197 while (dwarf_siblingof(&child, &child) == 0);
11199 if (!result->var_decls_to_re_add_to_tree().empty())
11200 for (list<var_decl_sptr>::const_iterator v =
11201 result->var_decls_to_re_add_to_tree().begin();
11202 v != result->var_decls_to_re_add_to_tree().end();
11209 string demangled_name =
11211 if (!demangled_name.empty())
11213 std::list<string> fqn_comps;
11215 string mem_name = fqn_comps.back();
11216 fqn_comps.pop_back();
11219 if (!fqn_comps.empty())
11223 lookup_type<class_decl>(ty_name, *result->get_tu());
11247 ABG_ASSERT(dynamic_pointer_cast<var_decl>(d));
11254 result->var_decls_to_re_add_to_tree().clear();
11256 result->get_tu()->set_is_constructed(
true);
11279build_namespace_decl_and_add_to_ir(reader& rdr,
11282 reader::tu_context_type_sptr& tu_ctxt)
11289 unsigned tag = dwarf_tag(die);
11290 if (tag != DW_TAG_namespace && tag != DW_TAG_module)
11295 where_addr, tu_ctxt);
11298 is_namespace(rdr.lookup_artifact_from_die(die,
false))))
11301 string name, linkage_name;
11303 die_loc_and_name(die, tu_ctxt, loc, name, linkage_name);
11305 result.reset(
new namespace_decl(rdr.env(), name, loc));
11306 result =
is_namespace(rdr.maybe_associate_die_to_decl(die, result));
11310 if (dwarf_child(die, &child) != 0)
11313 tu_ctxt->scope_stack().push(result);
11315 do_handle_dwarf_die(rdr, tu_ctxt, child,
11321 die_is_public_decl(die)
11322 && die_is_public_decl(&child));
11323 while (dwarf_siblingof(&child, &child) == 0);
11324 tu_ctxt->scope_stack().pop();
11339build_type_decl(reader& rdr, Dwarf_Die* die,
11340 reader::tu_context_type_sptr& tu_ctxt)
11346 ABG_ASSERT(dwarf_tag(die) == DW_TAG_base_type);
11348 if ((result =
is_type_decl(rdr.lookup_type_artifact_from_die(die))))
11351 uint64_t byte_size = 0, bit_size = 0;
11352 if (!die_unsigned_constant_attribute(die, DW_AT_byte_size, byte_size))
11353 if (!die_unsigned_constant_attribute(die, DW_AT_bit_size, bit_size))
11356 if (bit_size == 0 && byte_size != 0)
11358 bit_size = byte_size * 8;
11360 string type_name, linkage_name;
11362 die_loc_and_name(die, tu_ctxt, loc, type_name, linkage_name);
11364 if (byte_size == 0)
11368 if (type_name ==
"void")
11369 result =
is_type_decl(build_ir_node_for_void_type(rdr, tu_ctxt));
11376 if (corpus_sptr corp = rdr.should_reuse_type_from_corpus_group())
11378 string normalized_type_name = type_name;
11379 real_type real_type;
11381 normalized_type_name = real_type.to_string();
11382 result = lookup_type<type_decl>(normalized_type_name, *corp);
11386 if (corpus_sptr corp = rdr.corpus())
11387 result = lookup_type<type_decl>(type_name, *corp);
11389 result.reset(
new type_decl(rdr.env(), type_name, bit_size,
11390 0, loc, linkage_name));
11408build_enum_underlying_type(reader& rdr,
11410 uint64_t enum_size,
11411 reader::tu_context_type_sptr& tu_ctxt,
11412 bool is_anonymous =
true)
11414 string underlying_type_name =
11418 type_decl_sptr result(
new type_decl(rdr.env(), underlying_type_name,
11419 enum_size, enum_size, location()));
11420 result->set_is_anonymous(is_anonymous);
11421 result->set_is_artificial(
true);
11424 result = dynamic_pointer_cast<type_decl>(d);
11426 maybe_canonicalize_type(result, rdr);
11441build_enum_type(reader& rdr,
11443 reader::tu_context_type_sptr& tu_ctxt,
11444 bool is_declaration_only)
11450 unsigned tag = dwarf_tag(die);
11451 if (tag != DW_TAG_enumeration_type)
11454 string name, linkage_name;
11456 die_loc_and_name(die, tu_ctxt, loc, name, linkage_name);
11458 bool is_anonymous =
false;
11462 name = get_internal_anonymous_die_prefix_name(die);
11465 is_anonymous =
true;
11468 bool use_odr = rdr.odr_is_relevant(die, tu_ctxt);
11480 result = pre_existing_enum;
11482 else if (corpus_sptr corp = rdr.should_reuse_type_from_corpus_group())
11491 if (pre_existing_enum->get_location() == loc)
11492 result = pre_existing_enum;
11502 if (die_unsigned_constant_attribute(die, DW_AT_byte_size, size))
11504 bool is_artificial = die_is_artificial(die);
11507 bool enum_underlying_type_is_anonymous=
true;
11511 if (dwarf_child(die, &child) == 0)
11515 if (dwarf_tag(&child) != DW_TAG_enumerator)
11520 die_loc_and_name(&child, tu_ctxt, l, n, m);
11522 die_unsigned_constant_attribute(&child, DW_AT_const_value, val);
11523 enms.push_back(enum_type_decl::enumerator(n, val));
11525 while (dwarf_siblingof(&child, &child) == 0);
11533 build_enum_underlying_type(rdr, name, size, tu_ctxt,
11534 enum_underlying_type_is_anonymous);
11536 result.reset(
new enum_type_decl(name, loc, t, enms, linkage_name));
11537 result->set_is_anonymous(is_anonymous);
11538 result->set_is_declaration_only(is_declaration_only);
11539 t->set_is_declaration_only(is_declaration_only);
11540 result->set_is_artificial(is_artificial);
11559finish_member_function_reading(Dwarf_Die* die,
11561 const class_or_union_sptr klass,
11572 size_t is_inline = die_is_declared_inline(die);
11573 bool is_ctor = (f->get_name() == klass->get_name());
11574 bool is_dtor = (!f->get_name().empty()
11575 &&
static_cast<string>(f->get_name())[0] ==
'~');
11576 bool is_virtual = die_is_virtual(die);
11577 int64_t vindex = -1;
11579 die_virtual_function_index(die, vindex);
11582 if (!c->is_struct())
11583 access = private_access;
11584 die_access_specifier(die, access);
11586 m->is_declared_inline(is_inline);
11590 bool is_static = method_t->get_is_for_static_method();
11598 if (is_virtual && !f->get_linkage_name().empty() && !f->get_symbol()
11618 rdr.record_a_fn_decl_with_no_symbol(die, f);
11636static method_decl_sptr
11637is_function_for_die_a_member_of_class(reader& rdr,
11638 Dwarf_Die* function_die,
11639 const class_or_union_sptr& class_type)
11644 return method_decl_sptr();
11652 method_type = method->get_type();
11653 method_scope = method->get_scope();
11660 class_or_union_sptr method_class = method_type->get_class_type();
11663 if (method_class.get() == class_type.get())
11666 || (method_scope.get() == method_class.get()))
11692static method_decl_sptr
11693add_or_update_member_function(reader& rdr,
11694 Dwarf_Die* function_die,
11695 const class_or_union_sptr class_type,
11696 bool called_from_public_decl,
11698 reader::tu_context_type_sptr& tu_ctxt)
11700 if (!function_die || dwarf_tag(function_die) != DW_TAG_subprogram)
11703 method_decl_sptr method =
11704 is_function_for_die_a_member_of_class(rdr, function_die, class_type);
11709 ABG_ASSERT(!scope || scope.get() == class_type.get());
11712 if (!potential_member_fn_should_be_dropped(rdr, tu_ctxt, function_die))
11714 string linkage_name = die_linkage_name(function_die);
11715 if (!linkage_name.empty())
11716 method = class_type->find_member_function_sptr(linkage_name);
11719 method =
is_method_decl(build_ir_node_from_die(rdr, function_die,
11721 called_from_public_decl,
11725 return method_decl_sptr();
11729 if (!tu_ctxt->is_wip_function_type_die(function_die))
11730 finish_member_function_reading(function_die,
11736 rdr.schedule_method_to_finish_reading(*function_die, method);
11780add_or_update_class_type(reader& rdr,
11784 bool called_from_public_decl,
11786 bool is_declaration_only,
11787 reader::tu_context_type_sptr& tu_ctxt)
11793 unsigned tag = dwarf_tag(die);
11795 if (tag != DW_TAG_class_type && tag != DW_TAG_structure_type)
11798 if ((result =
is_class_type(tu_ctxt->lookup_wip_type_from_die(die))))
11801 string name, linkage_name;
11803 die_loc_and_name(die, tu_ctxt, loc, name, linkage_name);
11804 cleanup_decl_name(name);
11806 bool is_anonymous =
false;
11811 name = get_internal_anonymous_die_prefix_name(die);
11814 is_anonymous =
true;
11819 if (corpus_sptr corp = rdr.should_reuse_type_from_corpus_group())
11829 result = lookup_type<class_decl>(name, *corp);
11835 && (result->get_is_declaration_only() == is_declaration_only
11836 || (!result->get_is_declaration_only()
11837 && is_declaration_only)))
11839 result =
is_class_type(rdr.maybe_associate_die_to_type(die, result));
11852 die_size_in_bits(die, size);
11853 bool is_artificial = die_is_artificial(die);
11856 bool has_child = (dwarf_child(die, &child) == 0);
11863 if (has_child && klass->get_is_declaration_only()
11864 && klass->get_definition_of_declaration())
11865 result =
is_class_type(klass->get_definition_of_declaration());
11868 result->set_location(loc);
11873 if (!!result->get_size_in_bits() == result->get_is_declaration_only())
11886 result->set_is_declaration_only(is_declaration_only);
11889 result.reset(
new class_decl(rdr.env(), name, size,
11891 decl_base::VISIBILITY_DEFAULT,
11896 result->set_is_declaration_only(is_declaration_only);
11901 if (!klass || klass->get_is_declaration_only())
11902 if (size != result->get_size_in_bits())
11903 result->set_size_in_bits(size);
11907 if (!result->get_is_declaration_only() && has_child)
11908 if (result->get_size_in_bits() == 0 && size != 0)
11909 result->set_size_in_bits(size);
11911 result->set_is_artificial(is_artificial);
11918 tu_ctxt->mark_class_or_union_die_as_wip(die, result);
11920 bool is_incomplete_type =
false;
11921 if (is_declaration_only && size == 0 && has_child)
11933 is_incomplete_type =
true;
11936 dynamic_pointer_cast<scope_decl>(result);
11939 tu_ctxt->scope_stack().push(scop);
11941 if (has_child && !is_incomplete_type)
11945 tag = dwarf_tag(&child);
11948 if (tag == DW_TAG_inheritance)
11950 result->set_is_declaration_only(
false);
11952 Dwarf_Die type_die;
11953 if (!die_die_attribute(&child, DW_AT_type, type_die))
11956 string type_name = die_type_name(rdr, &type_die,
11959 type_base_sptr base_type;
11960 if (!type_name.empty())
11962 base_type = result->find_base_class(type_name);
11968 is_type(build_ir_node_from_die(rdr, &type_die,
11969 called_from_public_decl,
11983 die_access_specifier(&child, access);
11985 bool is_virt= die_is_virtual(&child);
11986 int64_t offset = 0;
11987 bool is_offset_present =
11988 die_member_offset(rdr, &child, offset);
11992 is_offset_present ? offset : -1,
11995 if (result->find_base_class(b->get_qualified_name()))
11997 result->add_base_specifier(base);
12000 else if (tag == DW_TAG_member
12001 || tag == DW_TAG_variable)
12003 Dwarf_Die type_die;
12004 if (!die_die_attribute(&child, DW_AT_type, type_die))
12009 die_loc_and_name(&child, tu_ctxt, loc, n, m);
12014 if (n.substr(0, 5) ==
"_vptr"
12016 && !std::isalnum(n.at(5))
12020 int64_t offset_in_bits = 0;
12021 bool is_laid_out = die_member_offset(rdr, &child,
12026 bool is_static = !is_laid_out;
12042 decl_base_sptr ty =
12043 is_decl(build_ir_node_from_die(rdr, &type_die,
12044 called_from_public_decl,
12046 type_base_sptr t =
is_type(ty);
12050 if (n.empty() && !die_is_anonymous_data_member(&child))
12056 n = rdr.build_name_for_buggy_anonymous_data_member(&child,
12065 result->set_is_declaration_only(
false);
12071 die_access_specifier(&child, access);
12076 lock_guard<recursive_mutex> lock(result->get_mutex());
12077 if (dm->get_name().empty()
12078 || !result->find_data_member(dm))
12081 is_static, offset_in_bits);
12087 else if (tag == DW_TAG_subprogram)
12089 add_or_update_member_function(rdr, &child, result,
12090 called_from_public_decl,
12093 else if (die_is_type(&child))
12100 }
while (dwarf_siblingof(&child, &child) == 0);
12103 tu_ctxt->scope_stack().pop();
12105 tu_ctxt->unmark_class_or_union_die_as_wip(die);
12132static union_decl_sptr
12133add_or_update_union_type(reader& rdr,
12135 union_decl_sptr union_type,
12136 bool called_from_public_decl,
12138 bool is_declaration_only,
12139 reader::tu_context_type_sptr& tu_ctxt)
12141 union_decl_sptr result;
12145 unsigned tag = dwarf_tag(die);
12147 if (tag != DW_TAG_union_type)
12150 if ((result =
is_union_type(tu_ctxt->lookup_wip_type_from_die(die))))
12153 string name, linkage_name;
12155 die_loc_and_name(die, tu_ctxt, loc, name, linkage_name);
12156 cleanup_decl_name(name);
12158 bool is_anonymous =
false;
12163 name = get_internal_anonymous_die_prefix_name(die);
12166 is_anonymous =
true;
12176 if (corpus_sptr corp = rdr.should_reuse_type_from_corpus_group())
12181 result = lookup_type<union_decl>(name, *corp);
12185 result =
is_union_type(rdr.maybe_associate_die_to_type(die, result));
12192 die_size_in_bits(die, size);
12193 bool is_artificial = die_is_artificial(die);
12197 result = union_type;
12198 result->set_location(loc);
12202 result.reset(
new union_decl(rdr.env(), name, size, loc,
12203 decl_base::VISIBILITY_DEFAULT,
12205 if (is_declaration_only)
12206 result->set_is_declaration_only(
true);
12213 result->set_size_in_bits(size);
12214 result->set_is_declaration_only(
false);
12217 result->set_is_artificial(is_artificial);
12220 bool has_child = (dwarf_child(die, &child) == 0);
12224 tu_ctxt->mark_class_or_union_die_as_wip(die, result);
12230 tag = dwarf_tag(&child);
12232 if (tag == DW_TAG_member || tag == DW_TAG_variable)
12234 Dwarf_Die type_die;
12235 if (!die_die_attribute(&child, DW_AT_type, type_die))
12240 die_loc_and_name(&child, tu_ctxt, loc, n, m);
12242 ssize_t offset_in_bits = 0;
12243 decl_base_sptr ty =
12244 is_decl(build_ir_node_from_die(rdr, &type_die,
12245 called_from_public_decl,
12246 where_addr, tu_ctxt));
12247 type_base_sptr t =
is_type(ty);
12254 result->set_is_declaration_only(
false);
12257 die_access_specifier(&child, access);
12261 lock_guard<recursive_mutex> lock(result->get_mutex());
12262 if (dm->get_name().empty()
12263 || !result->find_data_member(dm))
12273 else if (tag == DW_TAG_subprogram)
12275 add_or_update_member_function(rdr, &child, result,
12276 called_from_public_decl,
12277 where_addr, tu_ctxt);
12282 }
while (dwarf_siblingof(&child, &child) == 0);
12285 tu_ctxt->unmark_class_or_union_die_as_wip(die);
12307static type_base_sptr
12308build_qualified_type(reader& rdr,
12310 bool called_from_public_decl,
12312 reader::tu_context_type_sptr& tu_ctxt)
12314 type_base_sptr result;
12318 unsigned tag = dwarf_tag(die);
12320 if (tag != DW_TAG_const_type
12321 && tag != DW_TAG_volatile_type
12322 && tag != DW_TAG_restrict_type)
12325 Dwarf_Die underlying_type_die;
12326 decl_base_sptr utype_decl;
12327 if (!die_die_attribute(die, DW_AT_type, underlying_type_die))
12331 utype_decl = build_ir_node_for_void_type(rdr, tu_ctxt);
12334 utype_decl =
is_decl(build_ir_node_from_die(rdr, &underlying_type_die,
12335 called_from_public_decl,
12336 where_addr, tu_ctxt));
12340 type_base_sptr utype =
is_type(utype_decl);
12344 if (tag == DW_TAG_const_type)
12345 qual |= qualified_type_def::CV_CONST;
12346 else if (tag == DW_TAG_volatile_type)
12347 qual |= qualified_type_def::CV_VOLATILE;
12348 else if (tag == DW_TAG_restrict_type)
12349 qual |= qualified_type_def::CV_RESTRICT;
12354 result.reset(
new qualified_type_def(utype, qual, location()));
12372schedule_array_tree_for_late_canonicalization(
const type_base_sptr& t,
12377 schedule_array_tree_for_late_canonicalization(type->get_underlying_type(),
12379 rdr.schedule_type_for_late_canonicalization(t);
12383 schedule_array_tree_for_late_canonicalization(type->get_underlying_type(),
12385 rdr.schedule_type_for_late_canonicalization(t);
12389 for (vector<array_type_def::subrange_sptr>::const_iterator i =
12390 type->get_subranges().begin();
12391 i != type->get_subranges().end();
12394 if (!(*i)->get_scope())
12396 type->get_translation_unit()->get_global_scope());
12397 rdr.schedule_type_for_late_canonicalization(*i);
12401 schedule_array_tree_for_late_canonicalization(type->get_element_type(),
12403 rdr.schedule_type_for_late_canonicalization(type);
12422static decl_base_sptr
12423maybe_strip_qualification(
const qualified_type_def_sptr t,
12429 decl_base_sptr result = t;
12430 type_base_sptr u = t->get_underlying_type();
12434 if (result.get() != t.get())
12443 scope = array->get_scope();
12446 schedule_array_tree_for_late_canonicalization(array, rdr);
12448 t->set_underlying_type(array);
12449 u = t->get_underlying_type();
12457 schedule_array_tree_for_late_canonicalization(typdef, rdr);
12460 t->set_underlying_type(typdef);
12461 u = t->get_underlying_type();
12470 type_base_sptr element_type = array->get_element_type();
12475 ABG_ASSERT(!qualified->get_canonical_type());
12477 quals |= t->get_cv_quals();
12478 qualified->set_cv_quals(quals);
12484 qualified_type_def_sptr qual_type
12485 (
new qualified_type_def(element_type,
12487 t->get_location()));
12490 array->set_element_type(qual_type);
12491 rdr.schedule_type_for_late_canonicalization(
is_type(qual_type));
12516build_pointer_type_def(reader& rdr,
12518 bool called_from_public_decl,
12520 reader::tu_context_type_sptr& tu_ctxt)
12527 unsigned tag = dwarf_tag(die);
12528 if (tag != DW_TAG_pointer_type)
12532 Dwarf_Die underlying_type_die;
12533 bool has_underlying_type_die =
false;
12534 if (!die_die_attribute(die, DW_AT_type, underlying_type_die))
12537 utype_decl = build_ir_node_for_void_type(rdr, tu_ctxt);
12539 has_underlying_type_die =
true;
12541 if (!utype_decl && has_underlying_type_die)
12542 utype_decl = build_ir_node_from_die(rdr, &underlying_type_die,
12543 called_from_public_decl,
12544 where_addr, tu_ctxt);
12550 if ((result =
is_pointer_type(rdr.lookup_type_artifact_from_die(die))))
12553 type_base_sptr utype =
is_type(utype_decl);
12559 uint64_t size = tu_ctxt->get_tu()->get_address_size();
12560 if (die_unsigned_constant_attribute(die, DW_AT_byte_size, size))
12567 ABG_ASSERT((
size_t) tu_ctxt->get_tu()->get_address_size() == size);
12569 result.reset(
new pointer_type_def(utype, size, 0, location()));
12573 result =
is_pointer_type(build_ir_node_for_void_pointer_type(rdr, tu_ctxt));
12596build_reference_type(reader& rdr,
12598 bool called_from_public_decl,
12600 reader::tu_context_type_sptr& tu_ctxt)
12607 unsigned tag = dwarf_tag(die);
12608 if (tag != DW_TAG_reference_type
12609 && tag != DW_TAG_rvalue_reference_type)
12615 Dwarf_Die underlying_type_die;
12616 if (!die_die_attribute(die, DW_AT_type, underlying_type_die))
12620 build_ir_node_from_die(rdr, &underlying_type_die,
12621 called_from_public_decl,
12622 where_addr, tu_ctxt);
12631 type_base_sptr utype =
is_type(utype_decl);
12637 uint64_t size = tu_ctxt->get_tu()->get_address_size();
12638 if (die_unsigned_constant_attribute(die, DW_AT_byte_size, size))
12643 ABG_ASSERT((
size_t) tu_ctxt->get_tu()->get_address_size() == size);
12645 bool is_lvalue = tag == DW_TAG_reference_type;
12647 result.reset(
new reference_type_def(utype, is_lvalue, size,
12672build_ptr_to_mbr_type(reader& rdr,
12674 bool called_from_public_decl,
12676 reader::tu_context_type_sptr& tu_ctxt)
12683 unsigned tag = dwarf_tag(die);
12684 if (tag != DW_TAG_ptr_to_member_type)
12687 Dwarf_Die data_member_type_die, containing_type_die;
12689 if (!die_die_attribute(die, DW_AT_type, data_member_type_die)
12690 || !die_die_attribute(die, DW_AT_containing_type, containing_type_die))
12694 build_ir_node_from_die(rdr, &data_member_type_die,
12695 called_from_public_decl,
12696 where_addr, tu_ctxt);
12697 if (!data_member_type)
12701 build_ir_node_from_die(rdr, &containing_type_die,
12702 called_from_public_decl,
12703 where_addr, tu_ctxt);
12704 if (!containing_type)
12714 uint64_t size_in_bits = tu_ctxt->get_tu()->get_address_size();
12716 result.reset(
new ptr_to_mbr_type(data_member_type->get_environment(),
12739maybe_get_origin_type(reader& rdr,
12740 const Dwarf_Die* die,
12741 Dwarf_Die& origin_die,
12742 type_base_sptr& origin_type)
12744 bool found =
false;
12746 if (die_origin_die(die, origin_die))
12749 origin_type =
is_type(rdr.lookup_type_artifact_from_die(&origin_die));
12776build_function_type(reader& rdr,
12778 class_or_union_sptr is_method,
12780 vector<decl_base_sptr>& decls,
12781 reader::tu_context_type_sptr& tu_ctxt)
12788 ABG_ASSERT(dwarf_tag(die) == DW_TAG_subroutine_type
12789 || dwarf_tag(die) == DW_TAG_subprogram);
12797 decl_base_sptr type_decl;
12815 rdr.maybe_associate_die_to_type(die, fn_type);
12816 offset_t native_offset = dwarf_dieoffset(die);
12817 fn_type->set_native_offset(native_offset);
12825 bool is_const =
false;
12826 bool is_static =
false;
12827 Dwarf_Die object_pointer_die;
12828 Dwarf_Die class_type_die;
12829 bool has_this_parm_die =
12830 die_function_type_is_method_type(rdr, die, where_addr,
12831 tu_ctxt, object_pointer_die,
12834 if (has_this_parm_die)
12839 if (die_object_pointer_is_for_const_method(&object_pointer_die))
12847 class_or_union_sptr klass_type =
12850 where_addr, tu_ctxt));
12858 is_method = klass_type;
12870 result.reset(is_method
12871 ?
new method_type(is_method, is_const,
12872 tu->get_address_size(),
12874 : new function_type(rdr.env(), tu->get_address_size(),
12876 offset_t native_offset = dwarf_dieoffset(die);
12877 result->set_native_offset(native_offset);
12878 tu_ctxt->mark_function_type_die_as_wip(die, result);
12880 bool is_destructor =
false;
12882 is_destructor = die_is_destructor(die);
12884 type_base_sptr return_type;
12885 Dwarf_Die ret_type_die;
12886 if (die_die_attribute(die, DW_AT_type, ret_type_die))
12888 is_type(build_ir_node_from_die(rdr, &ret_type_die,
12890 where_addr, tu_ctxt));
12893 return_type =
is_type(build_ir_node_for_void_type(rdr, tu_ctxt));
12895 result->set_return_type(return_type);
12914 Dwarf_Die original_die;
12916 if (maybe_get_origin_type(rdr, die, original_die, t))
12920 if (dwarf_child(die, &child) == 0)
12923 int child_tag = dwarf_tag(&child);
12924 if (child_tag == DW_TAG_formal_parameter)
12927 string name, linkage_name;
12929 die_loc_and_name(&child, tu_ctxt, loc, name, linkage_name);
12935 bool parm_is_artificial = die_is_artificial(&child);
12936 type_base_sptr parm_type;
12937 Dwarf_Die parm_type_die;
12940 && parm_is_artificial
12941 && function_parms.size() == 1)
12952 if (die_die_attribute(&child, DW_AT_type, parm_type_die))
12954 is_type(build_ir_node_from_die(rdr, &parm_type_die,
12956 where_addr, tu_ctxt));
12963 && function_parms.empty())
12979 (
new function_decl::parameter(parm_type, name, loc,
12981 parm_is_artificial));
12982 function_parms.push_back(p);
12984 else if (child_tag == DW_TAG_unspecified_parameters)
12987 bool is_artificial = die_is_artificial(&child);
12989 type_base_sptr parm_type =
12990 is_type(build_ir_node_for_variadic_parameter_type(rdr, tu_ctxt));
12992 (
new function_decl::parameter(parm_type,
12997 function_parms.push_back(p);
13012 build_ir_node_from_die(rdr, &child,
13014 where_addr, tu_ctxt);
13016 if (decl_base_sptr d =
is_decl(ir_node))
13017 decls.push_back(d);
13020 while (dwarf_siblingof(&child, &child) == 0);
13037 if (!orig_fn_type->has_empty_parameters())
13039 unsigned o_nb_parms = orig_fn_type->get_nb_parameters();
13040 if (o_nb_parms > function_parms.size())
13045 for (
unsigned i = function_parms.size(); i < o_nb_parms; ++i)
13047 function_parms.push_back(p);
13050 result->set_parameters(function_parms);
13052 result->set_is_artificial(
true);
13054 tu_ctxt->unmark_function_type_die_as_wip(die);
13079build_function_type(reader& rdr,
13081 class_or_union_sptr is_method,
13083 reader::tu_context_type_sptr& tu_ctxt)
13085 vector<decl_base_sptr> decls;
13086 return build_function_type(rdr, die, is_method, where_addr, decls, tu_ctxt);
13112build_subrange_type(reader& rdr,
13113 const Dwarf_Die* die,
13115 reader::tu_context_type_sptr& tu_ctxt,
13116 bool associate_type_to_die)
13123 unsigned tag = dwarf_tag(
const_cast<Dwarf_Die*
>(die));
13124 if (tag != DW_TAG_subrange_type)
13127 string name = die_name(die);
13130 Dwarf_Die underlying_type_die;
13131 type_base_sptr underlying_type;
13133 bool is_signed =
false;
13134 if (die_die_attribute(die, DW_AT_type, underlying_type_die))
13136 is_type(build_ir_node_from_die(rdr,
13137 &underlying_type_die,
13141 if (underlying_type)
13144 if (die_unsigned_constant_attribute (&underlying_type_die,
13147 is_signed = (ate == DW_ATE_signed || ate == DW_ATE_signed_char);
13153 bool has_size_info =
false;
13155 if ((has_size_info = die_unsigned_constant_attribute(die,
13156 DW_AT_byte_size, size)))
13159 has_size_info = die_unsigned_constant_attribute(die,
13160 DW_AT_bit_size, size);
13163 array_type_def::subrange_type::bound_value lower_bound =
13164 get_default_array_lower_bound(language);
13165 array_type_def::subrange_type::bound_value upper_bound;
13166 uint64_t count = 0;
13167 bool is_non_finite =
false;
13168 bool non_zero_count_present =
false;
13179 die_constant_attribute(die, DW_AT_lower_bound, is_signed, lower_bound);
13181 bool found_upper_bound = die_constant_attribute(die, DW_AT_upper_bound,
13182 is_signed, upper_bound);
13183 if (!found_upper_bound)
13184 found_upper_bound = subrange_die_indirect_bound_value(die,
13189 if (!found_upper_bound)
13202 if (die_unsigned_constant_attribute(die, DW_AT_count, count))
13210 non_zero_count_present =
true;
13215 int64_t u = lower_bound.get_signed_value() + count;
13217 upper_bound = u - 1;
13220 if (!non_zero_count_present)
13224 is_non_finite =
true;
13227 if (UINT64_MAX == upper_bound.get_unsigned_value())
13230 is_non_finite =
true;
13233 (
new array_type_def::subrange_type(rdr.env(),
13239 result->is_non_finite(is_non_finite);
13242 result->set_size_in_bits(size);
13249 if (!underlying_type)
13250 result->set_size_in_bits(tu_ctxt->get_tu()->get_address_size());
13255 || (result->get_length() ==
13256 (uint64_t) (result->get_upper_bound()
13257 - result->get_lower_bound() + 1)));
13259 if (associate_type_to_die)
13282build_subranges_from_array_type_die(
const reader& rdr,
13283 const Dwarf_Die* die,
13286 reader::tu_context_type_sptr& tu_ctxt,
13287 bool associate_type_to_die)
13291 if (dwarf_child(
const_cast<Dwarf_Die*
>(die), &child) == 0)
13295 int child_tag = dwarf_tag(&child);
13296 if (child_tag == DW_TAG_subrange_type)
13299 if (associate_type_to_die)
13305 build_ir_node_from_die(
const_cast<reader&
>(rdr), &child,
13314 s = build_subrange_type(
const_cast<reader&
>(rdr),
13315 &child, where, tu_ctxt,
13318 subranges.push_back(s);
13321 while (dwarf_siblingof(&child, &child) == 0);
13342build_array_type(reader& rdr,
13344 bool called_from_public_decl,
13346 reader::tu_context_type_sptr& tu_ctxt)
13353 unsigned tag = dwarf_tag(die);
13354 if (tag != DW_TAG_array_type)
13357 decl_base_sptr type_decl;
13358 Dwarf_Die type_die;
13360 if (die_die_attribute(die, DW_AT_type, type_die))
13361 type_decl =
is_decl(build_ir_node_from_die(rdr, &type_die,
13362 called_from_public_decl,
13363 where_addr, tu_ctxt));
13367 type_base_sptr type =
is_type(type_decl);
13372 build_subranges_from_array_type_die(rdr, die, subranges, where_addr, tu_ctxt);
13374 result.reset(
new array_type_def(type, subranges, location()));
13396build_typedef_type(reader& rdr,
13398 bool called_from_public_decl,
13400 reader::tu_context_type_sptr& tu_ctxt)
13407 unsigned tag = dwarf_tag(die);
13408 if (tag != DW_TAG_typedef)
13411 if ((result =
is_typedef(rdr.lookup_type_artifact_from_die(die))))
13414 string name, linkage_name;
13416 die_loc_and_name(die, tu_ctxt, loc, name, linkage_name);
13418 if (corpus_sptr corp = rdr.should_reuse_type_from_corpus_group())
13424 type_base_sptr utype;
13425 Dwarf_Die underlying_type_die;
13426 if (!die_die_attribute(die, DW_AT_type, underlying_type_die))
13429 utype = rdr.env().get_void_type();
13433 is_type(build_ir_node_from_die(rdr,
13434 &underlying_type_die,
13435 called_from_public_decl,
13436 where_addr, tu_ctxt));
13440 if ((result =
is_typedef(rdr.lookup_type_artifact_from_die(die))))
13444 result.reset(
new typedef_decl(name, utype, loc, linkage_name));
13483build_or_get_var_decl_if_not_suppressed(reader& rdr,
13487 reader::tu_context_type_sptr& tu_ctxt,
13488 bool is_declaration_only,
13490 bool is_required_decl_spec)
13493 if (variable_is_suppressed(rdr, scope, die,
13494 is_declaration_only,
13495 is_required_decl_spec))
13497 lock_guard<recursive_mutex> lock(rdr.mutex_);
13498 ++rdr.stats_.number_of_suppressed_variables;
13504 string var_name = die_name(die);
13505 if (!var_name.empty())
13506 if ((var = class_type->find_data_member(var_name)))
13512 lock_guard<recursive_mutex> lock(rdr.mutex_);
13513 ++rdr.stats_.number_of_suppressed_variables;
13516 var = build_var_decl(rdr, die, where_addr, tu_ctxt, result);
13539build_var_decl(reader& rdr,
13542 reader::tu_context_type_sptr& tu_ctxt,
13548 int tag = dwarf_tag(die);
13549 ABG_ASSERT(tag == DW_TAG_variable || tag == DW_TAG_member);
13551 if (!die_is_public_decl(die))
13554 type_base_sptr type;
13555 Dwarf_Die type_die;
13556 if (die_die_attribute(die, DW_AT_type, type_die))
13559 build_ir_node_from_die(rdr, &type_die,
13561 where_addr, tu_ctxt);
13569 if (!type && !result)
13572 string name, linkage_name;
13574 die_loc_and_name(die, tu_ctxt, loc, name, linkage_name);
13576 if (!type && result && !result->get_type())
13577 type = rdr.env().get_void_type();
13580 result.reset(
new var_decl(name, type, loc, linkage_name));
13586 if (!linkage_name.empty())
13587 result->set_linkage_name(linkage_name);
13590 result->set_type(type);
13596 if (!result->get_symbol())
13599 Dwarf_Addr var_addr;
13601 if (rdr.get_variable_address(die, var_addr))
13604 update_main_symbol(var_addr,
13605 result->get_linkage_name().empty()
13606 ? result->get_name()
13607 : result->get_linkage_name());
13608 var_sym = rdr.variable_symbol_is_exported(var_addr);
13613 result->set_symbol(var_sym);
13616 string linkage_name = result->get_linkage_name();
13617 if (linkage_name.empty()
13618 || !var_sym->get_alias_from_name(linkage_name))
13619 result->set_linkage_name(var_sym->get_name());
13620 result->set_is_in_public_symbol_table(
true);
13623 if (!var_sym && rdr.is_decl_die_with_undefined_symbol(die))
13627 string n = result->get_linkage_name();
13629 n = result->get_name();
13630 var_sym = rdr.symtab()->lookup_undefined_variable_symbol(n);
13633 result->set_symbol(var_sym);
13634 result->set_is_in_public_symbol_table(
false);
13661function_is_suppressed(
const reader& rdr,
13663 Dwarf_Die *function_die,
13664 bool is_declaration_only)
13666 if (function_die == 0
13667 || dwarf_tag(function_die) != DW_TAG_subprogram)
13670 string fname = die_string_attribute(function_die, DW_AT_name);
13671 string flinkage_name = die_linkage_name(function_die);
13672 if (flinkage_name.empty() && die_is_in_c(function_die))
13673 flinkage_name = fname;
13683 && (!is_declaration_only || rdr.drop_undefined_syms()))
13685 Dwarf_Addr fn_addr;
13686 if (!rdr.get_function_address(function_die, fn_addr))
13690 rdr.function_symbol_is_exported(fn_addr);
13693 if (symbol->is_suppressed())
13700 if (symbol->has_aliases())
13702 !a->is_main_symbol(); a = a->get_next_alias())
13703 if (a->is_suppressed())
13752build_or_get_fn_decl_if_not_suppressed(reader& rdr,
13756 reader::tu_context_type_sptr& tu_ctxt,
13757 bool is_declaration_only,
13760 if (!die_is_function_decl(fn_die))
13764 if (function_is_suppressed(rdr, scope, fn_die, is_declaration_only))
13766 lock_guard<recursive_mutex> lock(rdr.mutex_);
13767 ++rdr.stats_.number_of_suppressed_functions;
13771 if (potential_member_fn_should_be_dropped(rdr, tu_ctxt, fn_die))
13776 lock_guard<recursive_mutex> lock(rdr.mutex_);
13777 ++rdr.stats_.number_of_allowed_functions;
13785 string linkage_name = die_linkage_name(fn_die);
13786 fn = klass->find_member_function_sptr(linkage_name);
13793 if (!fn || !fn->get_symbol())
13800 fn = build_function_decl(rdr, fn_die, where_addr, tu_ctxt, result);
13802 ABG_ASSERT(!fn || !fn->get_scope() || fn->get_scope().get() == scope.get());
13827variable_is_suppressed(
const reader& rdr,
13829 Dwarf_Die *variable_die,
13830 bool is_declaration_only,
13831 bool is_required_decl_spec)
13833 if (variable_die == 0
13834 || (dwarf_tag(variable_die) != DW_TAG_variable
13835 && dwarf_tag(variable_die) != DW_TAG_member))
13838 string name = die_string_attribute(variable_die, DW_AT_name);
13839 string linkage_name = die_linkage_name(variable_die);
13840 if (linkage_name.empty() && die_is_in_c(variable_die))
13841 linkage_name = name;
13850 && !is_required_decl_spec
13854 && (!is_declaration_only || !rdr.load_undefined_interfaces()))
13856 Dwarf_Addr var_addr = 0;
13857 if (!rdr.get_variable_address(variable_die, var_addr))
13861 rdr.variable_symbol_is_exported(var_addr);
13864 if (symbol->is_suppressed())
13871 if (symbol->has_aliases())
13873 !a->is_main_symbol(); a = a->get_next_alias())
13874 if (a->is_suppressed())
13903type_is_suppressed(
const reader& rdr,
13905 Dwarf_Die* type_die,
13906 reader::tu_context_type_sptr& tu_ctxt,
13907 bool& type_is_opaque)
13910 || (dwarf_tag(type_die) != DW_TAG_enumeration_type
13911 && dwarf_tag(type_die) != DW_TAG_class_type
13912 && dwarf_tag(type_die) != DW_TAG_structure_type
13913 && dwarf_tag(type_die) != DW_TAG_union_type))
13916 string type_name, linkage_name;
13917 location type_location;
13918 die_loc_and_name(type_die, tu_ctxt, type_location,
13919 type_name, linkage_name);
13943type_is_suppressed(
const reader& rdr,
13945 Dwarf_Die* type_die,
13946 reader::tu_context_type_sptr& tu_ctxt)
13948 bool type_is_opaque =
false;
13949 return type_is_suppressed(rdr, scope, type_die, tu_ctxt, type_is_opaque);
13973get_opaque_version_of_type(reader& rdr,
13975 Dwarf_Die* type_die,
13976 reader::tu_context_type_sptr& tu_ctxt)
13983 unsigned tag = dwarf_tag(type_die);
13984 if (tag != DW_TAG_class_type
13985 && tag != DW_TAG_structure_type
13986 && tag != DW_TAG_union_type
13987 && tag != DW_TAG_enumeration_type)
13990 string type_name, linkage_name;
13991 location type_location;
13992 die_loc_and_name(type_die, tu_ctxt, type_location, type_name, linkage_name);
14001 if (tag == DW_TAG_structure_type || tag == DW_TAG_class_type)
14003 result = rdr.get_a_declaration_only_class(qualified_name);
14014 tag == DW_TAG_structure_type,
14016 decl_base::VISIBILITY_DEFAULT));
14017 klass->set_is_declaration_only(
true);
14018 klass->set_is_artificial(die_is_artificial(type_die));
14019 klass =
is_class_type(rdr.maybe_associate_die_to_type(type_die, klass));
14020 rdr.maybe_schedule_declaration_only_class_for_resolution(klass);
14026 if (tag == DW_TAG_enumeration_type)
14028 result = rdr.get_a_declaration_only_enum(qualified_name);
14033 if (die_unsigned_constant_attribute(type_die, DW_AT_byte_size, size))
14036 build_enum_underlying_type(rdr, type_name, size,
14044 enum_type->set_is_artificial(die_is_artificial(type_die));
14045 enum_type =
is_enum_type(rdr.maybe_associate_die_to_type(type_die,
14048 result = enum_type;
14071 elf_symbol::FUNC_TYPE,
14072 elf_symbol::GLOBAL_BINDING,
14076 elf_symbol::DEFAULT_VISIBILITY);
14094build_function_decl(reader& rdr,
14097 reader::tu_context_type_sptr& tu_ctxt,
14103 int tag = dwarf_tag(die);
14106 || tag == DW_TAG_inlined_subroutine
14107 || tag == DW_TAG_dwarf_procedure);
14109 if (!die_is_public_decl(die))
14115 string fname, flinkage_name;
14117 die_loc_and_name(die, tu_ctxt, floc, fname, flinkage_name);
14118 cleanup_decl_name(fname);
14120 size_t is_inline = die_is_declared_inline(die);
14121 class_or_union_sptr is_method =
14123 where_addr, tu_ctxt));
14136 if (!flinkage_name.empty()
14137 && result->get_linkage_name() != flinkage_name)
14138 result->set_linkage_name(flinkage_name);
14140 if (!result->get_location())
14141 result->set_location(floc);
14142 result->is_declared_inline(is_inline);
14148 vector<decl_base_sptr> decls;
14154 fn_type = build_function_type(rdr, die, is_method,
14155 where_addr, decls, tu_ctxt);
14161 result.reset(is_method
14162 ?
new method_decl(fname, fn_type,
14165 : new function_decl(fname, fn_type,
14172 for (
const auto& decl : decls)
14178 if (!result->get_symbol()
14179 || result->get_symbol()->get_name() != result->get_linkage_name())
14182 Dwarf_Addr fn_addr;
14183 if (rdr.get_function_address(die, fn_addr))
14186 update_main_symbol(fn_addr,
14187 result->get_linkage_name().empty()
14188 ? result->get_name()
14189 : result->get_linkage_name());
14190 fn_sym = rdr.function_symbol_is_exported(fn_addr);
14195 result->set_symbol(fn_sym);
14196 result->set_is_in_public_symbol_table(
true);
14197 if (result->get_linkage_name().empty())
14198 result->set_linkage_name(fn_sym->get_name());
14201 if (!fn_sym && rdr.is_decl_die_with_undefined_symbol(die))
14205 string n = result->get_linkage_name();
14207 n = result->get_name();
14208 fn_sym = rdr.symtab()->lookup_undefined_function_symbol(n);
14211 result->set_symbol(fn_sym);
14212 result->set_is_in_public_symbol_table(
false);
14235maybe_canonicalize_type(
const type_base_sptr& t,
14241 rdr.schedule_type_for_late_canonicalization(t);
14250maybe_set_member_type_access_specifier(decl_base_sptr member_type_declaration,
14253 if (
is_type(member_type_declaration)
14256 class_or_union_sptr scope =
14261 die_access_specifier(die, access);
14274cleanup_decl_name(
string& str)
14292potential_member_fn_should_be_dropped(reader& rdr,
14293 reader::tu_context_type_sptr& tu_ctxt,
14294 const Dwarf_Die *fn_die)
14299 Dwarf_Die class_die;
14302 tu_ctxt, class_die);
14306 && !die_is_virtual(fn_die)
14308 &&!rdr.function_has_address(fn_die)
14311 && !rdr.load_undefined_interfaces())
14320 if (die_is_virtual(fn_die)
14321 && ((die_is_destructor(fn_die) && !rdr.function_has_address(fn_die))
14322 || die_linkage_name(fn_die).empty())
14345 && (rdr.is_decl_die_with_undefined_symbol(fn_die)
14346 || !rdr.is_decl_die_with_exported_symbol(fn_die))
14347 && !rdr.load_undefined_interfaces())
14391build_ir_node_from_die(reader& rdr,
14394 bool called_from_public_decl,
14396 reader::tu_context_type_sptr& tu_ctxt,
14397 bool is_declaration_only,
14398 bool is_required_decl_spec)
14402 if (!die || !scope)
14405 int tag = dwarf_tag(die);
14408 if (!called_from_public_decl)
14410 if (rdr.load_all_types() && die_is_type(die))
14414 else if (tag != DW_TAG_subprogram
14415 && tag != DW_TAG_variable
14416 && tag != DW_TAG_member
14417 && tag != DW_TAG_namespace)
14421 if ((result = rdr.lookup_artifact_from_die(die, die_is_type(die))))
14428 is_declaration_only = is_declaration_only && die_is_declaration_only(die);
14433 case DW_TAG_base_type:
14436 t =
is_type_decl(rdr.maybe_associate_die_to_type(die, t));
14440 maybe_canonicalize_type(t, rdr);
14444 case DW_TAG_typedef:
14447 called_from_public_decl,
14448 where_addr, tu_ctxt);
14450 t =
is_typedef(rdr.maybe_associate_die_to_type(die, t));
14454 maybe_set_member_type_access_specifier(
is_decl(result), die);
14455 maybe_canonicalize_type(t, rdr);
14457 auto utype = t->get_underlying_type();
14463 decl_base_sptr decl =
is_decl(utype);
14465 decl->add_naming_typedef(t);
14466 rdr.maybe_schedule_decl_only_type_for_resolution(utype);
14473 case DW_TAG_pointer_type:
14476 build_pointer_type_def(rdr, die,
14477 called_from_public_decl,
14478 where_addr, tu_ctxt);
14484 maybe_canonicalize_type(p, rdr);
14489 case DW_TAG_reference_type:
14490 case DW_TAG_rvalue_reference_type:
14493 build_reference_type(rdr, die,
14494 called_from_public_decl,
14495 where_addr, tu_ctxt);
14501 maybe_canonicalize_type(r, rdr);
14506 case DW_TAG_ptr_to_member_type:
14509 build_ptr_to_mbr_type(rdr, die, called_from_public_decl,
14510 where_addr, tu_ctxt);
14516 maybe_canonicalize_type(p, rdr);
14521 case DW_TAG_const_type:
14522 case DW_TAG_volatile_type:
14523 case DW_TAG_restrict_type:
14526 build_qualified_type(rdr, die,
14527 called_from_public_decl,
14528 where_addr, tu_ctxt);
14538 type_base_sptr ty =
is_type(d);
14542 result = rdr.maybe_associate_die_to_type(die, ty);
14547 maybe_canonicalize_type(
is_type(result), rdr);
14552 case DW_TAG_enumeration_type:
14554 bool type_is_opaque =
false;
14555 bool type_suppressed =
14556 type_is_suppressed(rdr, scope, die, tu_ctxt, type_is_opaque);
14557 if (type_suppressed && type_is_opaque)
14565 result = get_opaque_version_of_type(rdr, scope, die, tu_ctxt);
14566 maybe_canonicalize_type(
is_type(result), rdr);
14568 else if (!type_suppressed)
14571 is_declaration_only);
14572 e =
is_enum_type(rdr.maybe_associate_die_to_type(die, e));
14576 maybe_set_member_type_access_specifier(
is_decl(result), die);
14577 maybe_canonicalize_type(
is_type(result), rdr);
14583 case DW_TAG_class_type:
14584 case DW_TAG_structure_type:
14586 bool type_is_opaque =
false;
14587 bool type_suppressed=
14588 type_is_suppressed(rdr, scope, die, tu_ctxt, type_is_opaque);
14590 if (type_suppressed && type_is_opaque)
14598 result = get_opaque_version_of_type(rdr, scope, die, tu_ctxt);
14599 maybe_canonicalize_type(
is_type(result), rdr);
14601 else if (!type_suppressed)
14604 Dwarf_Die spec_die;
14605 if (die_die_attribute(die, DW_AT_specification, spec_die))
14608 get_scope_for_die(rdr, &spec_die,
14609 called_from_public_decl,
14610 where_addr, tu_ctxt);
14612 decl_base_sptr cl =
14613 is_decl(build_ir_node_from_die(rdr, &spec_die,
14615 called_from_public_decl,
14616 where_addr, tu_ctxt,
14617 is_declaration_only,
14620 klass = dynamic_pointer_cast<class_decl>(cl);
14624 add_or_update_class_type(rdr, die,
14625 tag == DW_TAG_structure_type,
14627 called_from_public_decl,
14629 is_declaration_only,
14636 string type_name = die_type_name(rdr, die,
14638 where_addr, tu_ctxt);
14644 add_or_update_class_type(rdr, die,
14645 tag == DW_TAG_structure_type,
14647 called_from_public_decl,
14649 is_declaration_only,
14654 add_or_update_class_type(rdr, die,
14655 tag == DW_TAG_structure_type,
14657 called_from_public_decl,
14659 is_declaration_only,
14664 maybe_set_member_type_access_specifier(klass, die);
14665 klass =
is_class_type(rdr.maybe_associate_die_to_type(die, klass));
14667 maybe_canonicalize_type(klass, rdr);
14674 case DW_TAG_union_type:
14676 if (!type_is_suppressed(rdr, scope, die, tu_ctxt))
14678 union_decl_sptr union_type;
14681 string type_name = die_type_name(rdr, die,
14683 where_addr, tu_ctxt);
14684 if (union_decl_sptr u =
14691 add_or_update_union_type(rdr, die, union_decl_sptr(),
14692 called_from_public_decl,
14694 is_declaration_only,
14700 is_union_type(rdr.maybe_associate_die_to_type(die, union_type));
14702 maybe_set_member_type_access_specifier(union_type, die);
14703 maybe_canonicalize_type(union_type, rdr);
14704 result = union_type;
14709 case DW_TAG_string_type:
14711 case DW_TAG_subroutine_type:
14715 where_addr, tu_ctxt);
14719 result->set_is_artificial(
false);
14721 maybe_canonicalize_type(f, rdr);
14725 case DW_TAG_array_type:
14728 called_from_public_decl,
14729 where_addr, tu_ctxt);
14732 a =
is_array_type(rdr.maybe_associate_die_to_type(die, a));
14735 maybe_canonicalize_type(a, rdr);
14739 case DW_TAG_subrange_type:
14745 build_subrange_type(rdr, die, where_addr, tu_ctxt,
14752 maybe_canonicalize_type(s, rdr);
14756 case DW_TAG_packed_type:
14758 case DW_TAG_set_type:
14760 case DW_TAG_file_type:
14762 case DW_TAG_thrown_type:
14764 case DW_TAG_interface_type:
14766 case DW_TAG_unspecified_type:
14768 case DW_TAG_shared_type:
14771 case DW_TAG_compile_unit:
14776 case DW_TAG_namespace:
14777 case DW_TAG_module:
14778 result = build_namespace_decl_and_add_to_ir(rdr, die,
14783 case DW_TAG_variable:
14784 case DW_TAG_member:
14786 if (tag == DW_TAG_member)
14790 get_scope_for_die(rdr, die,
14792 die_is_effectively_public_decl(rdr, die, tu_ctxt),
14793 where_addr, tu_ctxt);
14795 build_or_get_var_decl_if_not_suppressed(rdr, var_scope, die,
14796 where_addr, tu_ctxt,
14797 is_declaration_only,
14799 is_required_decl_spec);
14807 v = build_var_decl(rdr, die, where_addr, tu_ctxt, v);
14809 Dwarf_Addr addr = 0;
14810 bool has_data_location =
false;
14811 has_data_location = rdr.get_variable_address(die, addr);
14816 || (v && rdr.is_decl_die_with_undefined_symbol(die))
14817 || (v && rdr.is_decl_die_with_exported_symbol(die))
14822 v =
is_var_decl(rdr.maybe_associate_die_to_decl(die, v));
14838 tu_ctxt->var_decls_to_re_add_to_tree().push_back(v);
14845 if (rdr.has_scope_of_die_been_associated(die, where_addr,
14847 rdr.add_var_to_exported_or_undefined_decls(v);
14850 rdr.add_var_to_exported_or_undefined_decls(v);
14856 case DW_TAG_subprogram:
14857 case DW_TAG_inlined_subroutine:
14859 if (die_is_artificial(die))
14862 Dwarf_Die abstract_origin_die;
14863 memset(&abstract_origin_die, 0,
sizeof(abstract_origin_die));
14867 bool has_abstract_origin = die_origin_die(die, abstract_origin_die);
14869 scope_decl_sptr s = get_scope_for_die(rdr, die, called_from_public_decl,
14870 where_addr, tu_ctxt);
14872 class_or_union_sptr class_scope =
14875 string linkage_name = die_linkage_name(die);
14877 string spec_linkage_name;
14884 if (has_abstract_origin)
14886 (rdr.lookup_decl_from_die_addr(abstract_origin_die.addr));
14887 if (!existing_fn && !linkage_name.empty())
14889 class_scope->find_member_function_sptr(linkage_name);
14892 && existing_fn->get_scope()
14893 && existing_fn->get_scope().get() != class_scope.get())
14894 existing_fn.reset();
14896 else if (has_abstract_origin)
14900 existing_fn = build_function_decl(rdr, &abstract_origin_die,
14901 where_addr, tu_ctxt,
14904 tu_ctxt->scope_stack().push(interface_scope);
14908 || !existing_fn->get_scope()
14909 || existing_fn->get_scope() == class_scope);
14917 build_or_get_fn_decl_if_not_suppressed(rdr, interface_scope,
14918 die, where_addr, tu_ctxt,
14919 is_declaration_only,
14928 || !fn->get_scope()
14929 || fn->get_scope() == class_scope);
14936 string linkage_name = fn->get_linkage_name();
14937 fn = class_scope->find_member_function_sptr(linkage_name);
14943 if (fn->get_symbol())
14944 linkage_name = fn->get_symbol()->get_name();
14945 fn = class_scope->find_member_function_sptr(linkage_name);
14964 ABG_ASSERT(!scope || fn->get_scope() == scope);
14967 && !tu_ctxt->is_wip_function_type(fn->get_type())
14970 || (fn->get_symbol() && fn->get_symbol()->is_public())))
14974 rdr.add_fn_to_exported_or_undefined_decls(fn.get(),
true);
14977 maybe_canonicalize_type(fn->get_type(), rdr);
14979 tu_ctxt->get_tu());
14986 && !tu_ctxt->is_wip_function_type_die(die))
14988 class_or_union_sptr cou =
14991 finish_member_function_reading(die, fn, cou, rdr);
14994 && tu_ctxt->is_wip_function_type_die(die))
14997 rdr.schedule_method_to_finish_reading(*die, fn);
15001 tu_ctxt->scope_stack().pop();
15005 case DW_TAG_formal_parameter:
15010 case DW_TAG_constant:
15012 case DW_TAG_enumerator:
15015 case DW_TAG_partial_unit:
15021 case DW_TAG_imported_unit:
15025 case DW_TAG_dwarf_procedure:
15026 case DW_TAG_imported_declaration:
15027 case DW_TAG_entry_point:
15029 case DW_TAG_lexical_block:
15030 case DW_TAG_unspecified_parameters:
15031 case DW_TAG_variant:
15032 case DW_TAG_common_block:
15033 case DW_TAG_common_inclusion:
15034 case DW_TAG_inheritance:
15035 case DW_TAG_with_stmt:
15036 case DW_TAG_access_declaration:
15037 case DW_TAG_catch_block:
15038 case DW_TAG_friend:
15039 case DW_TAG_namelist:
15040 case DW_TAG_namelist_item:
15041 case DW_TAG_template_type_parameter:
15042 case DW_TAG_template_value_parameter:
15043 case DW_TAG_try_block:
15044 case DW_TAG_variant_part:
15045 case DW_TAG_imported_module:
15046 case DW_TAG_condition:
15047 case DW_TAG_type_unit:
15048 case DW_TAG_template_alias:
15049 case DW_TAG_lo_user:
15050 case DW_TAG_MIPS_loop:
15051 case DW_TAG_format_label:
15052 case DW_TAG_function_template:
15053 case DW_TAG_class_template:
15054 case DW_TAG_GNU_BINCL:
15055 case DW_TAG_GNU_EINCL:
15056 case DW_TAG_GNU_template_template_param:
15057 case DW_TAG_GNU_template_parameter_pack:
15058 case DW_TAG_GNU_formal_parameter_pack:
15059 case DW_TAG_GNU_call_site:
15060 case DW_TAG_GNU_call_site_parameter:
15061 case DW_TAG_hi_user:
15068 offset_t native_offset = dwarf_dieoffset(die);
15069 result->set_native_offset(native_offset);
15073 result->set_corpus(rdr.corpus().get());
15075 rdr.maybe_schedule_decl_only_type_for_resolution(result);
15085static decl_base_sptr
15086build_ir_node_for_void_type(reader& rdr,
15087 reader::tu_context_type_sptr& tu_ctxt)
15089 const environment& env = rdr.env();
15091 type_base_sptr t = env.get_void_type();
15097 rdr.schedule_type_for_late_canonicalization(t);
15100 return type_declaration;
15115build_ir_node_for_void_pointer_type(reader& rdr,
15116 reader::tu_context_type_sptr& tu_ctxt)
15118 const environment& env = rdr.env();
15119 type_base_sptr t = env.get_void_pointer_type();
15125 rdr.schedule_type_for_late_canonicalization(t);
15128 return type_declaration;
15136static decl_base_sptr
15137build_ir_node_for_variadic_parameter_type(reader &rdr,
15138 reader::tu_context_type_sptr& tu_ctxt)
15141 const environment& env = rdr.env();
15142 type_base_sptr t = env.get_variadic_parameter_type();
15148 rdr.schedule_type_for_late_canonicalization(t);
15151 return type_declaration;
15186build_ir_node_from_die(reader& rdr,
15188 bool called_from_public_decl,
15190 reader::tu_context_type_sptr& tu_ctxt,
15191 bool is_required_decl_spec)
15194 return decl_base_sptr();
15204 bool consider_as_called_from_public_decl =
15205 called_from_public_decl || die_is_effectively_public_decl(rdr, die,
15208 consider_as_called_from_public_decl,
15209 where_addr, tu_ctxt);
15213 if ((result = rdr.lookup_artifact_from_die(die, die_is_type(die))))
15215 if (
auto d =
is_decl(result))
15217 if (d->get_scope().get() == scope.get())
15227 scope = get_global_scope(rdr, tu_ctxt, die);
15229 result = build_ir_node_from_die(rdr, die, scope,
15230 called_from_public_decl,
15231 where_addr, tu_ctxt,
true,
15232 is_required_decl_spec);
15262elf_based_reader_sptr
15264 const vector<string>& debug_info_root_paths,
15269 reader_sptr r = reader::create(elf_path,
15270 debug_info_root_paths,
15272 return static_pointer_cast<elf_based_reader>(r);
15297elf_based_reader_sptr
15299 const vector<string>& debug_info_root_paths,
15337 const std::string& elf_path,
15338 const vector<string>& debug_info_root_path,
15341 reader& r =
dynamic_cast<reader&
>(rdr);
15342 r.options() = options;
15343 r.initialize(elf_path, debug_info_root_path);
15379 const vector<string>& debug_info_root_paths,
15384 elf_based_reader_sptr rdr =
15385 dwarf::reader::create(elf_path, debug_info_root_paths,
15388 return rdr->read_corpus(status);
15420 const vector<string>& debug_info_root_paths,
15447 const string& elf_path,
15448 const string& symbol_name,
15450 vector<elf_symbol_sptr>& syms)
15453 if (elf_version(EV_CURRENT) == EV_NONE)
15456 int fd = open(elf_path.c_str(), O_RDONLY);
15464 Elf* elf = elf_begin(fd, ELF_C_READ, 0);
15468 bool value = lookup_symbol_from_elf(env, elf, symbol_name,
15492 const string& path,
15493 const string& symname,
15494 vector<elf_symbol_sptr>& syms)
15496 if (elf_version(EV_CURRENT) == EV_NONE)
15499 int fd = open(path.c_str(), O_RDONLY);
15507 Elf* elf = elf_begin(fd, ELF_C_READ, 0);
15511 bool value = lookup_public_function_symbol_from_elf(env, elf, symname, syms);