25#include "abg-internal.h"
30#include "abg-internal.h"
32ABG_BEGIN_EXPORT_DECLARATIONS
40ABG_END_EXPORT_DECLARATIONS
51using std::dynamic_pointer_cast;
58process_ctf_typedef(reader *rdr,
59 ctf_dict_t *ctf_dictionary,
63process_ctf_base_type(reader *rdr,
64 ctf_dict_t *ctf_dictionary,
68build_ir_node_for_variadic_parameter_type(reader &rdr,
72build_ir_node_for_void_type(reader& rdr,
76build_ir_node_for_void_pointer_type(reader& rdr,
80process_ctf_function_type(reader *rdr,
81 ctf_dict_t *ctf_dictionary,
85process_ctf_sou_members(reader *rdr,
86 ctf_dict_t *ctf_dictionary,
88 class_or_union_sptr sou);
91process_ctf_forward_type(reader *rdr,
92 ctf_dict_t *ctf_dictionary,
96process_ctf_struct_type(reader *rdr,
97 ctf_dict_t *ctf_dictionary,
100static union_decl_sptr
101process_ctf_union_type(reader *rdr,
102 ctf_dict_t *ctf_dictionary,
106process_ctf_array_type(reader *rdr,
107 ctf_dict_t *ctf_dictionary,
111process_ctf_qualified_type(reader *rdr,
112 ctf_dict_t *ctf_dictionary,
116process_ctf_pointer_type(reader *rdr,
117 ctf_dict_t *ctf_dictionary,
121process_ctf_enum_type(reader *rdr,
122 ctf_dict_t *ctf_dictionary,
126fill_ctf_section(
const Elf_Scn *elf_section, ctf_sect_t *ctf_section);
129lookup_symbol_in_ctf_archive(ctf_archive_t *ctfa, ctf_dict_t **ctf_dict,
130 const char *sym_name);
133dic_type_key(ctf_dict_t *dic, ctf_id_t ctf_type);
148 vector<type_base_sptr> types_to_canonicalize;
152 vector<type_base_sptr> additional_types_to_canonicalize;
156 vector<type_base_sptr> types;
159 std::set<ctf_id_t> unknown_types_set;
164 ctf_sect_t symtab_sect;
165 ctf_sect_t strtab_sect;
174 exported_decls_builder()
189 add_type(ctf_dict_t *dic, ctf_id_t ctf_type, type_base_sptr type)
191 string key = dic_type_key(dic, ctf_type);
192 if (types_map.insert(std::make_pair(key, type)).second)
193 types_to_canonicalize.push_back(type);
201 add_type(
const type_base_sptr& t)
202 {additional_types_to_canonicalize.push_back(t);}
208 add_unknown_type(ctf_id_t ctf_type)
210 unknown_types_set.insert(ctf_type);
221 type_base_sptr result;
222 std::string key = dic_type_key(dic, ctf_type);
224 auto search = types_map.find(key);
225 if (search != types_map.end())
226 result = search->second;
234 lookup_unknown_type(ctf_id_t ctf_type)
235 {
return unknown_types_set.find(ctf_type) != unknown_types_set.end(); }
239 canonicalize_all_types(
void)
241 for (
auto& t: additional_types_to_canonicalize)
242 types_to_canonicalize.push_back(t);
243 additional_types_to_canonicalize.clear();
246 types_to_canonicalize.end(),
247 [](vector<type_base_sptr>::iterator& i)
263 reader(
const string& elf_path,
264 const vector<char**>& debug_info_root_paths,
267 ctfa(), ctf_sect(), symtab_sect(), strtab_sect()
287 types_to_canonicalize.clear();
314 const vector<char**>& debug_info_root_paths,
315 bool load_all_types =
false,
316 bool linux_kernel_mode =
false)
319 load_all_types = load_all_types;
320 linux_kernel_mode = linux_kernel_mode;
338 cur_transl_unit()
const
346 {
return options().env;}
353 {
return options().env;}
363 {
return options().do_log;}
372 find_ctfa_file(std::string& ctfa_file)
374 std::string ctfa_dirname;
375 dir_name(corpus_path(), ctfa_dirname,
false);
380 ctfa_file = ctfa_dirname +
"/vmlinux.ctfa";
387 for (
const auto& path : debug_info_root_paths())
405 corpus_sptr corp =
corpus();
407 if ((status & STATUS_NO_SYMBOLS_FOUND)
408 || !(status & STATUS_OK))
414 GElf_Ehdr *ehdr, eh_mem;
415 if (!(ehdr = gelf_getehdr(elf_handle(), &eh_mem)))
419 const char *symtab_name =
".dynsym";
420 const char *strtab_name =
".dynstr";
422 if (ehdr->e_type == ET_REL)
424 symtab_name =
".symtab";
425 strtab_name =
".strtab";
428 const Elf_Scn* ctf_scn = find_ctf_section();
430 fill_ctf_section(ctf_scn, &ctf_sect);
432 const Elf_Scn* symtab_scn =
433 elf_helpers::find_section_by_name(elf_handle(), symtab_name);
435 fill_ctf_section(symtab_scn, &symtab_sect);
437 const Elf_Scn* strtab_scn =
438 elf_helpers::find_section_by_name(elf_handle(), strtab_name);
440 fill_ctf_section(strtab_scn, &strtab_sect);
442 if (ctf_scn && symtab_scn && strtab_scn)
444 else if (corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)
449 (~STATUS_DEBUG_INFO_NOT_FOUND);
458 process_ctf_archive()
460 corpus_sptr corp =
corpus();
463 std::make_shared<translation_unit>(env(),
"", 64);
464 ir_translation_unit->set_language(translation_unit::LANG_C);
465 corp->add(ir_translation_unit);
466 cur_transl_unit(ir_translation_unit);
468 ctf_dict_t *ctf_dict =
nullptr, *initial_ctf_dict =
nullptr;
469 const auto symt = symtab();
473 ctf_next_t *it =
nullptr;
476 initial_ctf_dict = ctf_archive_next(ctfa, &it,
480 if (!initial_ctf_dict)
482 std::cerr <<
"Could not find any dictionnary in the CTF archive\n";
483 ctf_next_destroy(it);
487 ctf_dict = initial_ctf_dict;
490 std::string sym_name = symbol->get_name();
491 ctf_id_t ctf_sym_type;
493 ctf_sym_type = lookup_symbol_in_ctf_archive(ctfa, &ctf_dict,
495 if (ctf_sym_type == CTF_ERR)
498 if (ctf_type_kind(ctf_dict, ctf_sym_type) != CTF_K_FUNCTION)
500 const char *var_name = sym_name.c_str();
501 type_base_sptr var_type = build_type(ctf_dict, ctf_sym_type);
507 var_declaration.reset(
new var_decl(var_name,
512 var_declaration->set_symbol(symbol);
514 ir_translation_unit->get_global_scope());
515 var_declaration->set_is_in_public_symbol_table(
true);
516 add_var_to_exported_or_undefined_decls(var_declaration);
520 const char *func_name = sym_name.c_str();
521 ctf_id_t ctf_sym = ctf_sym_type;
522 type_base_sptr func_type = build_type(ctf_dict, ctf_sym);
532 func_declaration->set_symbol(symbol);
534 ir_translation_unit->get_global_scope());
535 func_declaration->set_is_in_public_symbol_table(
true);
536 add_fn_to_exported_or_undefined_decls(func_declaration.get());
538 if (ctf_dict != initial_ctf_dict)
540 ctf_dict_close(initial_ctf_dict);
541 initial_ctf_dict = ctf_dict;
544 ctf_dict_close(ctf_dict);
545 ctf_next_destroy(it);
558 process_ctf_type(ctf_dict_t *ctf_dictionary,
561 corpus_sptr corp =
corpus();
563 int type_kind = ctf_type_kind(ctf_dictionary, ctf_type);
564 type_base_sptr result;
566 if (lookup_unknown_type(ctf_type))
569 if ((result =
lookup_type(ctf_dictionary, ctf_type)))
578 = process_ctf_base_type(
this, ctf_dictionary, ctf_type);
585 = process_ctf_typedef(
this, ctf_dictionary, ctf_type);
592 = process_ctf_pointer_type(
this, ctf_dictionary, ctf_type);
593 result = pointer_type;
600 type_base_sptr qualified_type
601 = process_ctf_qualified_type(
this, ctf_dictionary, ctf_type);
602 result = qualified_type;
608 = process_ctf_array_type(
this, ctf_dictionary, ctf_type);
615 = process_ctf_enum_type(
this, ctf_dictionary, ctf_type);
622 = process_ctf_function_type(
this, ctf_dictionary, ctf_type);
629 = process_ctf_struct_type(
this, ctf_dictionary, ctf_type);
634 result = process_ctf_forward_type(
this, ctf_dictionary, ctf_type);
639 = process_ctf_union_type(
this, ctf_dictionary, ctf_type);
651 fprintf(stderr,
"NOT PROCESSED TYPE %lu\n", ctf_type);
652 add_unknown_type(ctf_type);
670 build_type(ctf_dict_t *ctf_dictionary, ctf_id_t ctf_type)
672 type_base_sptr result =
lookup_type(ctf_dictionary, ctf_type);
675 result = process_ctf_type(ctf_dictionary, ctf_type);
690 corpus_sptr corp =
corpus();
694 origin |= corpus::CTF_ORIGIN;
695 corp->set_origin(origin);
702 slurp_elf_info(status);
704 return corpus_sptr();
706 if (!(origin & corpus::LINUX_KERNEL_BINARY_ORIGIN)
710#ifdef WITH_DEBUG_SELF_COMPARISON
711 if (env().self_comparison_debug_is_on())
715 env().set_self_comparison_debug_input(g);
717 env().set_self_comparison_debug_input(
corpus());
726 if (corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)
730 std::string ctfa_filename;
731 if (find_ctfa_file(ctfa_filename))
732 ctfa = ctf_arc_open(ctfa_filename.c_str(), &errp);
742 && symtab_sect.cts_data
743 && strtab_sect.cts_data)
744 ctfa = ctf_arc_bufopen(&ctf_sect, &symtab_sect,
745 &strtab_sect, &errp);
750 cerr <<
"CTF Reader: Reading CTF info in:" << t <<
"\n";
759 process_ctf_archive();
764 canonicalize_all_types();
774 cerr <<
"CTF Reader: Building ABG-IR in:" << t <<
"\n";
788typedef shared_ptr<reader> reader_sptr;
799process_ctf_typedef(reader *rdr,
800 ctf_dict_t *ctf_dictionary,
803 corpus_sptr corp = rdr->corpus();
807 ctf_id_t ctf_utype = ctf_type_reference(ctf_dictionary, ctf_type);
808 if (ctf_utype == CTF_ERR)
811 const char *typedef_name = ctf_type_name_raw(ctf_dictionary, ctf_type);
812 if (corpus_sptr corp = rdr->should_reuse_type_from_corpus_group())
816 type_base_sptr utype = rdr->build_type(ctf_dictionary, ctf_utype);
821 result = dynamic_pointer_cast<typedef_decl>
822 (rdr->lookup_type(ctf_dictionary, ctf_type));
835 decl_base_sptr decl =
is_decl(utype);
837 decl->set_naming_typedef(result);
843 rdr->add_type(ctf_dictionary, ctf_type, result);
859process_ctf_base_type(reader *rdr,
860 ctf_dict_t *ctf_dictionary,
863 corpus_sptr corp = rdr->corpus();
867 ctf_id_t ctf_ref = ctf_type_reference(ctf_dictionary, ctf_type);
868 const char *type_name = ctf_type_name_raw(ctf_dictionary,
869 (ctf_ref != CTF_ERR) ? ctf_ref : ctf_type);
874 ctf_encoding_t type_encoding;
875 if (ctf_type_encoding(ctf_dictionary,
876 (ctf_ref != CTF_ERR) ? ctf_ref : ctf_type,
881 if (type_encoding.cte_bits == 0
882 && type_encoding.cte_format == CTF_INT_SIGNED)
885 decl_base_sptr type_declaration = build_ir_node_for_void_type(*rdr,
887 type_base_sptr void_type =
is_type(type_declaration);
892 if (corpus_sptr corp = rdr->should_reuse_type_from_corpus_group())
894 string normalized_type_name = type_name;
906 type_encoding.cte_bits,
916 rdr->add_type(ctf_dictionary, ctf_type, result);
930build_ir_node_for_variadic_parameter_type(reader &rdr,
939 return type_declaration;
975build_ir_node_for_void_pointer_type(reader& rdr,
994process_ctf_function_type(reader *rdr,
995 ctf_dict_t *ctf_dictionary,
998 corpus_sptr corp = rdr->corpus();
1003 ctf_funcinfo_t funcinfo;
1004 ctf_func_type_info(ctf_dictionary, ctf_type, &funcinfo);
1005 int vararg_p = funcinfo.ctc_flags & CTF_FUNC_VARARG;
1008 ctf_id_t ctf_ret_type = funcinfo.ctc_return;
1009 type_base_sptr ret_type = rdr->build_type(ctf_dictionary, ctf_ret_type);
1014 int argc = funcinfo.ctc_argc;
1015 std::vector<ctf_id_t> argv(argc);
1016 if (
static_cast<ctf_id_t
>(ctf_func_type_args(ctf_dictionary, ctf_type,
1017 argc, argv.data())) == CTF_ERR)
1021 for (
int i = 0; i < argc; i++)
1023 ctf_id_t ctf_arg_type = argv[i];
1024 type_base_sptr arg_type = rdr->build_type(ctf_dictionary, ctf_arg_type);
1033 function_parms.push_back(parm);
1038 type_base_sptr arg_type =
1039 is_type(build_ir_node_for_variadic_parameter_type(*rdr, tunit));
1046 function_parms.push_back(parm);
1049 result = dynamic_pointer_cast<function_type>
1050 (rdr->lookup_type(ctf_dictionary, ctf_type));
1057 tunit->get_address_size(),
1062 tunit->bind_function_type_life_time(result);
1063 result->set_is_artificial(
true);
1066 rdr->add_type(ctf_dictionary, ctf_type, result);
1080process_ctf_sou_members(reader *rdr,
1081 ctf_dict_t *ctf_dictionary,
1083 class_or_union_sptr sou)
1085 corpus_sptr corp = rdr->corpus();
1087 ssize_t member_size;
1088 ctf_next_t *member_next = NULL;
1089 const char *member_name = NULL;
1090 ctf_id_t member_ctf_type;
1092 while ((member_size = ctf_member_next(ctf_dictionary, ctf_type,
1093 &member_next, &member_name,
1097 ctf_membinfo_t membinfo;
1099 if (
static_cast<ctf_id_t
>(ctf_member_info(ctf_dictionary,
1102 &membinfo)) == CTF_ERR)
1106 type_base_sptr member_type = rdr->build_type(ctf_dictionary,
1118 sou->add_data_member(data_member_decl,
1124 if (ctf_errno(ctf_dictionary) != ECTF_NEXT_END)
1125 fprintf(stderr,
"ERROR from ctf_member_next\n");
1136static type_base_sptr
1137process_ctf_forward_type(reader *rdr,
1138 ctf_dict_t *ctf_dictionary,
1142 decl_base_sptr result;
1143 std::string type_name = ctf_type_name_raw(ctf_dictionary,
1145 bool type_is_anonymous = (type_name ==
"");
1146 uint32_t kind = ctf_type_kind_forwarded (ctf_dictionary, ctf_type);
1148 if (kind == CTF_K_UNION)
1155 decl_base::VISIBILITY_DEFAULT,
1156 type_is_anonymous));
1157 union_fwd->set_is_declaration_only(
true);
1162 if (!type_is_anonymous)
1163 if (corpus_sptr corp = rdr->should_reuse_type_from_corpus_group())
1168 struct_fwd(
new class_decl(rdr->env(), type_name,
1172 decl_base::VISIBILITY_DEFAULT,
1173 type_is_anonymous));
1174 struct_fwd->set_is_declaration_only(
true);
1175 result = struct_fwd;
1182 rdr->add_type(ctf_dictionary, ctf_type,
is_type(result));
1196process_ctf_struct_type(reader *rdr,
1197 ctf_dict_t *ctf_dictionary,
1200 corpus_sptr corp = rdr->corpus();
1203 std::string struct_type_name = ctf_type_name_raw(ctf_dictionary,
1205 bool struct_type_is_anonymous = (struct_type_name ==
"");
1207 if (!struct_type_is_anonymous)
1208 if (corpus_sptr corp = rdr->should_reuse_type_from_corpus_group())
1215 ctf_type_size(ctf_dictionary, ctf_type) * 8,
1219 decl_base::VISIBILITY_DEFAULT,
1220 struct_type_is_anonymous));
1230 rdr->add_type(ctf_dictionary, ctf_type, result);
1235 process_ctf_sou_members(rdr, ctf_dictionary, ctf_type, result);
1248static union_decl_sptr
1249process_ctf_union_type(reader *rdr,
1250 ctf_dict_t *ctf_dictionary,
1253 corpus_sptr corp = rdr->corpus();
1255 union_decl_sptr result;
1256 std::string union_type_name = ctf_type_name_raw(ctf_dictionary,
1258 bool union_type_is_anonymous = (union_type_name ==
"");
1260 if (!union_type_is_anonymous)
1261 if (corpus_sptr corp = rdr->should_reuse_type_from_corpus_group())
1268 ctf_type_size(ctf_dictionary, ctf_type) * 8,
1270 decl_base::VISIBILITY_DEFAULT,
1271 union_type_is_anonymous));
1281 rdr->add_type(ctf_dictionary, ctf_type, result);
1286 process_ctf_sou_members(rdr, ctf_dictionary, ctf_type, result);
1304build_array_ctf_range(reader *rdr, ctf_dict_t *dic,
1305 ctf_id_t index, uint64_t nelems)
1307 bool is_non_finite =
false;
1308 corpus_sptr corp = rdr->corpus();
1314 type_base_sptr index_type = rdr->build_type(dic, index);
1319 upper_bound.
set_unsigned(nelems > 0 ? nelems - 1 : 0U);
1323 is_non_finite =
true;
1331 translation_unit::LANG_C));
1333 subrange->set_size_in_bits(rdr->cur_transl_unit()->get_address_size());
1338 subrange->is_non_finite(is_non_finite);
1340 rdr->add_type(subrange);
1354process_ctf_array_type(reader *rdr,
1355 ctf_dict_t *ctf_dictionary,
1358 corpus_sptr corp = rdr->corpus();
1361 ctf_arinfo_t ctf_ainfo;
1364 if (
static_cast<ctf_id_t
>(ctf_array_info(ctf_dictionary,
1366 &ctf_ainfo)) == CTF_ERR)
1369 ctf_id_t ctf_element_type = ctf_ainfo.ctr_contents;
1370 ctf_id_t ctf_index_type = ctf_ainfo.ctr_index;
1371 uint64_t nelems = ctf_ainfo.ctr_nelems;
1375 int type_array_kind = ctf_type_kind(ctf_dictionary, ctf_element_type);
1376 while (type_array_kind == CTF_K_ARRAY)
1378 if (
static_cast<ctf_id_t
>(ctf_array_info(ctf_dictionary,
1380 &ctf_ainfo)) == CTF_ERR)
1383 subrange = build_array_ctf_range(rdr, ctf_dictionary,
1384 ctf_ainfo.ctr_index,
1385 ctf_ainfo.ctr_nelems);
1386 subranges.push_back(subrange);
1387 ctf_element_type = ctf_ainfo.ctr_contents;
1388 type_array_kind = ctf_type_kind(ctf_dictionary, ctf_element_type);
1391 std::reverse(subranges.begin(), subranges.end());
1394 type_base_sptr element_type = rdr->build_type(ctf_dictionary,
1400 type_base_sptr index_type = rdr->build_type(ctf_dictionary,
1405 result = dynamic_pointer_cast<array_type_def>
1406 (rdr->lookup_type(ctf_dictionary, ctf_type));
1410 subrange = build_array_ctf_range(rdr, ctf_dictionary,
1411 ctf_index_type, nelems);
1412 subranges.push_back(subrange);
1420 rdr->add_type(ctf_dictionary, ctf_type, result);
1447static decl_base_sptr
1448maybe_strip_qualification(
const qualified_type_def_sptr t)
1453 decl_base_sptr result = t;
1454 type_base_sptr u = t->get_underlying_type();
1466 type_base_sptr element_type = array->get_element_type();
1471 quals |= t->get_cv_quals();
1474 qualified->set_cv_quals(quals);
1489static type_base_sptr
1490process_ctf_qualified_type(reader *rdr,
1491 ctf_dict_t *ctf_dictionary,
1494 corpus_sptr corp = rdr->corpus();
1496 type_base_sptr result;
1497 int type_kind = ctf_type_kind(ctf_dictionary, ctf_type);
1498 ctf_id_t ctf_utype = ctf_type_reference(ctf_dictionary, ctf_type);
1499 type_base_sptr utype = rdr->build_type(ctf_dictionary, ctf_utype);
1503 result = dynamic_pointer_cast<type_base>
1504 (rdr->lookup_type(ctf_dictionary, ctf_type));
1509 if (type_kind == CTF_K_CONST)
1510 qualifiers |= qualified_type_def::CV_CONST;
1511 else if (type_kind == CTF_K_VOLATILE)
1512 qualifiers |= qualified_type_def::CV_VOLATILE;
1513 else if (type_kind == CTF_K_RESTRICT)
1514 qualifiers |= qualified_type_def::CV_RESTRICT;
1534 rdr->add_type(ctf_dictionary, ctf_type, result);
1549process_ctf_pointer_type(reader *rdr,
1550 ctf_dict_t *ctf_dictionary,
1553 corpus_sptr corp = rdr->corpus();
1556 ctf_id_t ctf_target_type = ctf_type_reference(ctf_dictionary, ctf_type);
1557 if (ctf_target_type == CTF_ERR)
1560 type_base_sptr target_type = rdr->build_type(ctf_dictionary,
1565 result = dynamic_pointer_cast<pointer_type_def>
1566 (rdr->lookup_type(ctf_dictionary, ctf_type));
1570 if (rdr->env().is_void_type(target_type))
1571 result =
is_pointer_type(build_ir_node_for_void_pointer_type(*rdr, tunit));
1574 ctf_type_size(ctf_dictionary,
1576 ctf_type_align(ctf_dictionary,
1582 rdr->add_type(ctf_dictionary, ctf_type, result);
1597process_ctf_enum_type(reader *rdr,
1598 ctf_dict_t *ctf_dictionary,
1603 ctf_id_t ctf_ref = ctf_type_reference(ctf_dictionary, ctf_type);
1604 std::string enum_name = ctf_type_name_raw(ctf_dictionary,
1605 (ctf_ref != CTF_ERR)
1606 ? ctf_ref : ctf_type);
1608 if (!enum_name.empty())
1609 if (corpus_sptr corp = rdr->should_reuse_type_from_corpus_group())
1616 size_t utype_size_in_bits = ctf_type_size(ctf_dictionary,
1617 (ctf_ref != CTF_ERR)
1618 ? ctf_ref : ctf_type) * 8;
1619 string underlying_type_name =
1621 utype_size_in_bits);
1625 underlying_type_name,
1629 utype->set_is_anonymous(
true);
1630 utype->set_is_artificial(
true);
1635 rdr->add_type(utype);
1639 ctf_next_t *enum_next = NULL;
1643 while ((ename = ctf_enum_next(ctf_dictionary, ctf_type, &enum_next, &evalue)))
1646 if (ctf_errno(ctf_dictionary) != ECTF_NEXT_END)
1648 fprintf(stderr,
"ERROR from ctf_enum_next\n");
1653 utype, enms, enum_name.c_str()));
1657 rdr->add_type(ctf_dictionary, ctf_type, result);
1680lookup_symbol_in_ctf_archive(ctf_archive_t *ctfa, ctf_dict_t **ctf_dict,
1681 const char *sym_name)
1684 ctf_dict_t *dict = *ctf_dict;
1685 ctf_id_t ctf_type = ctf_lookup_by_symbol_name(dict, sym_name);
1687 if (ctf_type != CTF_ERR)
1692 ctf_type = ctf_lookup_variable(dict, sym_name);
1695 if (ctf_type == CTF_ERR)
1698 ctf_next_t *i =
nullptr;
1699 const char *arcname =
nullptr;
1701 while ((fp = ctf_archive_next(ctfa, &i, &arcname,
1703 &ctf_err)) !=
nullptr)
1705 if ((ctf_type = ctf_lookup_by_symbol_name (fp, sym_name)) == CTF_ERR)
1706 ctf_type = ctf_lookup_variable(fp, sym_name);
1708 if (ctf_type != CTF_ERR)
1727fill_ctf_section(
const Elf_Scn *elf_section, ctf_sect_t *ctf_section)
1729 GElf_Shdr section_header_mem, *section_header;
1730 Elf_Data *section_data;
1732 section_header = gelf_getshdr(
const_cast<Elf_Scn*
>(elf_section),
1733 §ion_header_mem);
1734 section_data = elf_getdata(
const_cast<Elf_Scn*
>(elf_section), 0);
1739 ctf_section->cts_name =
"";
1740 ctf_section->cts_data = (
char *) section_data->d_buf;
1741 ctf_section->cts_size = section_data->d_size;
1742 ctf_section->cts_entsize = section_header->sh_entsize;
1754elf_based_reader_sptr
1756 const vector<char**>& debug_info_root_paths,
1759 reader_sptr result(
new reader(elf_path,
1760 debug_info_root_paths,
1763#ifdef WITH_DEBUG_SELF_COMPARISON
1764 if (env.self_comparison_debug_is_on())
1765 env.set_self_comparison_debug_input(result->corpus());
1783 const std::string& elf_path,
1784 const vector<char**>& debug_info_root_path)
1786 ctf::reader& r =
dynamic_cast<reader&
>(rdr);
1787 r.initialize(elf_path, debug_info_root_path);
1804dic_type_key(ctf_dict_t *dic, ctf_id_t ctf_type)
1806 std::stringstream key;
1808 if (ctf_type_isparent (dic, ctf_type))
1809 key << std::hex << ctf_type;
1811 key << std::hex << ctf_type <<
'-' << ctf_cuname(dic);
This file contains the declarations of the entry points to de-serialize an instance of abigail::corpu...
This file contains the declarations for an elf-based. DWARF and CTF readers can inherit this one.
This contains a set of ELF utilities used by the dwarf reader.
#define ABG_ASSERT(cond)
This is a wrapper around the 'assert' glibc call. It allows for its argument to have side effects,...
This contains the private implementation of the suppression engine of libabigail.
This contains the declarations for the symtab reader.
virtual ir::corpus_sptr read_corpus(status &status)
Read the ELF information associated to the current ELF file and construct an ABI representation from ...
The common interface of readers based on ELF.
virtual void initialize(const std::string &elf_path, const vector< char ** > &debug_info_root_paths)
(re)Initialize) the resources used by the current reader.
status
The status of the fe_iface::read_corpus call.
@ STATUS_NO_SYMBOLS_FOUND
This status is for when the symbols of the ELF binaries could not be read.
@ STATUS_DEBUG_INFO_NOT_FOUND
This status is for when the debug info could not be read.
@ STATUS_OK
This status is for when the call went OK.
@ STATUS_UNKNOWN
The status is in an unknown state.
This class is to hold the value of the bound of a subrange. The value can be either signed or unsigne...
uint64_t get_unsigned_value()
Getter of the bound value as an unsigned value.
void set_unsigned(uint64_t v)
Setter of the bound value as unsigned.
Abstraction for an array range type, like in Ada, or just for an array dimension like in C or C++.
The abstraction of an array type.
shared_ptr< subrange_type > subrange_sptr
Convenience typedef for a shared pointer on a function_decl::subrange.
std::vector< subrange_sptr > subranges_type
Convenience typedef for a vector of subrange_sptr.
Abstracts a class declaration.
Abstracts the building of the set of exported variables and functions.
Abstraction of a group of corpora.
This is the abstraction of a set of translation units (themselves seen as bundles of unitary abi arte...
origin
This abstracts where the corpus comes from. That is, either it has been read from the native xml form...
void sort_functions()
Sort the set of functions exported by this corpus.
exported_decls_builder_sptr get_exported_decls_builder() const
Getter for the object that is responsible for determining what decls ought to be in the set of export...
origin get_origin() const
Getter for the origin of the corpus.
void set_origin(origin)
Setter for the origin of the corpus.
void sort_variables()
Sort the set of variables exported by this corpus.
The abstraction of an enumerator.
Abstracts a declaration for an enum type.
std::vector< enumerator > enumerators
Convenience typedef for a list of enumerator.
This is an abstraction of the set of resources necessary to manage several aspects of the internal re...
const type_base_sptr & get_void_type() const
Get the unique type_decl that represents a "void" type for the current environment....
const type_base_sptr & get_void_pointer_type() const
Getter of the "pointer-to-void" IR node that is shared across the ABI corpus. This node must be the o...
bool canonicalization_is_done() const
Test if the canonicalization of types created out of the current environment is done.
const type_base_sptr & get_variadic_parameter_type() const
Get a type_decl instance that represents a the type of a variadic function parameter....
Abstraction of a function parameter.
Abstraction for a function declaration.
shared_ptr< parameter > parameter_sptr
Convenience typedef for a shared pointer on a function_decl::parameter.
std::vector< parameter_sptr > parameters
Convenience typedef for a vector of parameter_sptr.
Abstraction of a function type.
The source location of a token.
The abstraction of a pointer type.
The abstraction of a qualified type.
CV
Bit field values representing the cv qualifiers of the underlying type.
The internal representation of an integral type.
string to_string(bool internal=false) const
Return the string representation of the current instance of real_type.
A basic type declaration that introduces no scope.
The abstraction of a typedef declaration.
Abstracts a union type declaration.
Abstracts a variable declaration.
Helper class to allow range-for loops on symtabs for C++11 and later code. It serves as a proxy for t...
The symtab filter is the object passed to the symtab object in order to iterate over the symbols in t...
void set_public_symbols(bool new_value=true)
Enable or disable public symbol filtering.
void reset_reader(elf_based_reader &rdr, const std::string &elf_path, const vector< char ** > &debug_info_root_path)
Re-initialize a reader so that it can re-used to read another binary.
elf_based_reader_sptr create_reader(const std::string &elf_path, const vector< char ** > &debug_info_root_paths, environment &env)
Create and return a new read context to process CTF information from a given ELF file.
type_decl_sptr lookup_basic_type(const interned_string &type_name, const translation_unit &tu)
Lookup a basic type from a translation unit.
unordered_map< string, type_base_sptr > string_type_base_sptr_map_type
A convenience typedef for a map which key is a string and which value is a type_base_sptr.
shared_ptr< function_decl > function_decl_sptr
Convenience typedef for a shared pointer on a function_decl.
bool is_type(const type_or_decl_base &tod)
Test whether a declaration is a type.
bool parse_real_type(const string &type_name, real_type &type)
Parse a real type from a string.
shared_ptr< array_type_def > array_type_def_sptr
Convenience typedef for a shared pointer on a array_type_def.
bool is_anonymous_type(const type_base *t)
Test whether a declaration is a type.
class_or_union * is_class_or_union_type(const type_or_decl_base *t)
Test if a type is a class_or_union.
shared_ptr< class_decl > class_decl_sptr
Convenience typedef for a shared pointer on a class_decl.
const type_decl * is_type_decl(const type_or_decl_base *t)
Test whether a type is a type_decl (a builtin type).
function_type_sptr is_function_type(const type_or_decl_base_sptr &t)
Test whether a type is a function_type.
shared_ptr< function_type > function_type_sptr
Convenience typedef for a shared pointer on a function_type.
shared_ptr< typedef_decl > typedef_decl_sptr
Convenience typedef for a shared pointer on a typedef_decl.
class_decl_sptr lookup_class_type(const string &fqn, const translation_unit &tu)
Lookup a class type from a translation unit.
const enum_type_decl * is_enum_type(const type_or_decl_base *d)
Test if a decl is an enum_type_decl.
shared_ptr< var_decl > var_decl_sptr
Convenience typedef for a shared pointer on a var_decl.
shared_ptr< type_or_decl_base > type_or_decl_base_sptr
A convenience typedef for a shared_ptr to type_or_decl_base.
shared_ptr< translation_unit > translation_unit_sptr
Convenience typedef for a shared pointer on a translation_unit type.
void hash_and_canonicalize_types(IteratorType begin, IteratorType end, deref_lambda deref, bool do_log=false, bool show_stats=false)
Hash and canonicalize a sequence of types.
const type_base_sptr lookup_type(const interned_string &fqn, const translation_unit &tu)
Lookup a type in a translation unit.
union_decl_sptr lookup_union_type(const interned_string &type_name, const translation_unit &tu)
Lookup a union type from a translation unit.
shared_ptr< pointer_type_def > pointer_type_def_sptr
Convenience typedef for a shared pointer on a pointer_type_def.
decl_base * is_decl(const type_or_decl_base *d)
Test if an ABI artifact is a declaration.
decl_base_sptr add_decl_to_scope(decl_base_sptr decl, scope_decl *scope)
Appends a declaration to a given scope, if the declaration doesn't already belong to one and if the d...
string build_internal_underlying_enum_type_name(const string &base_name, bool is_anonymous, uint64_t size)
Build the internal name of the underlying type of an enum.
shared_ptr< enum_type_decl > enum_type_decl_sptr
Convenience typedef for shared pointer to a enum_type_decl.
const pointer_type_def * is_pointer_type(const type_or_decl_base *t, bool look_through_qualifiers)
Test whether a type is a pointer_type_def.
bool is_union_type(const type_or_decl_base &t)
Test if a type is a union_decl.
enum_type_decl_sptr lookup_enum_type(const interned_string &type_name, const translation_unit &tu)
Lookup an enum type from a translation unit.
const decl_base * get_type_declaration(const type_base *t)
Get the declaration for a given type.
array_type_def * is_array_type(const type_or_decl_base *type, bool look_through_qualifiers)
Test if a type is an array_type_def.
shared_ptr< type_decl > type_decl_sptr
Convenience typedef for a shared pointer on a type_decl.
qualified_type_def * is_qualified_type(const type_or_decl_base *t)
Test whether a type is a reference_type_def.
typedef_decl_sptr lookup_typedef_type(const interned_string &type_name, const translation_unit &tu)
Lookup a typedef type from a translation unit.
Toplevel namespace for libabigail.