25#include "abg-internal.h"
30#include "abg-internal.h"
32ABG_BEGIN_EXPORT_DECLARATIONS
40ABG_END_EXPORT_DECLARATIONS
47using std::dynamic_pointer_cast;
54process_ctf_typedef(reader *rdr,
55 ctf_dict_t *ctf_dictionary,
59process_ctf_base_type(reader *rdr,
60 ctf_dict_t *ctf_dictionary,
64build_ir_node_for_variadic_parameter_type(reader &rdr,
68build_ir_node_for_void_type(reader& rdr,
72build_ir_node_for_void_pointer_type(reader& rdr,
76process_ctf_function_type(reader *rdr,
77 ctf_dict_t *ctf_dictionary,
81process_ctf_sou_members(reader *rdr,
82 ctf_dict_t *ctf_dictionary,
84 class_or_union_sptr sou);
87process_ctf_forward_type(reader *rdr,
88 ctf_dict_t *ctf_dictionary,
92process_ctf_struct_type(reader *rdr,
93 ctf_dict_t *ctf_dictionary,
97process_ctf_union_type(reader *rdr,
98 ctf_dict_t *ctf_dictionary,
102process_ctf_array_type(reader *rdr,
103 ctf_dict_t *ctf_dictionary,
107process_ctf_qualified_type(reader *rdr,
108 ctf_dict_t *ctf_dictionary,
112process_ctf_pointer_type(reader *rdr,
113 ctf_dict_t *ctf_dictionary,
117process_ctf_enum_type(reader *rdr,
118 ctf_dict_t *ctf_dictionary,
122fill_ctf_section(
const Elf_Scn *elf_section, ctf_sect_t *ctf_section);
125lookup_symbol_in_ctf_archive(ctf_archive_t *ctfa, ctf_dict_t **ctf_dict,
126 const char *sym_name);
129dic_type_key(ctf_dict_t *dic, ctf_id_t ctf_type);
135class reader :
public elf_based_reader
146 std::set<ctf_id_t> unknown_types_set;
151 ctf_sect_t symtab_sect;
152 ctf_sect_t strtab_sect;
160 corpus::exported_decls_builder*
161 exported_decls_builder()
162 {
return corpus()->get_exported_decls_builder().get();}
172 add_type(ctf_dict_t *dic, ctf_id_t ctf_type, type_base_sptr type)
174 string key = dic_type_key(dic, ctf_type);
175 types_map.insert(std::make_pair(key, type));
182 add_unknown_type(ctf_id_t ctf_type)
184 unknown_types_set.insert(ctf_type);
195 type_base_sptr result;
196 std::string key = dic_type_key(dic, ctf_type);
198 auto search = types_map.find(key);
199 if (search != types_map.end())
200 result = search->second;
208 lookup_unknown_type(ctf_id_t ctf_type)
209 {
return unknown_types_set.find(ctf_type) != unknown_types_set.end(); }
213 canonicalize_all_types(
void)
216 (types_map.begin(), types_map.end(),
217 [](
const string_type_base_sptr_map_type::const_iterator& i)
218 {return i->second;});
233 reader(
const string& elf_path,
234 const vector<char**>& debug_info_root_paths,
285 const vector<char**>& debug_info_root_paths,
286 bool load_all_types =
false,
287 bool linux_kernel_mode =
false)
289 load_all_types = load_all_types;
290 linux_kernel_mode = linux_kernel_mode;
308 cur_transl_unit()
const
332 find_ctfa_file(std::string& ctfa_file)
334 std::string ctfa_dirname;
340 ctfa_file = ctfa_dirname +
"/vmlinux.ctfa";
365 corpus_sptr corp =
corpus();
366 if ((corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)
372 (~STATUS_DEBUG_INFO_NOT_FOUND);
376 if ((status & STATUS_NO_SYMBOLS_FOUND)
383 GElf_Ehdr *ehdr, eh_mem;
384 if (!(ehdr = gelf_getehdr(
elf_handle(), &eh_mem)))
388 const char *symtab_name =
".dynsym";
389 const char *strtab_name =
".dynstr";
391 if (ehdr->e_type == ET_REL)
393 symtab_name =
".symtab";
394 strtab_name =
".strtab";
398 fill_ctf_section(ctf_scn, &ctf_sect);
400 const Elf_Scn* symtab_scn =
401 elf_helpers::find_section_by_name(
elf_handle(), symtab_name);
402 fill_ctf_section(symtab_scn, &symtab_sect);
404 const Elf_Scn* strtab_scn =
405 elf_helpers::find_section_by_name(
elf_handle(), strtab_name);
406 fill_ctf_section(strtab_scn, &strtab_sect);
415 process_ctf_archive()
417 corpus_sptr corp =
corpus();
420 std::make_shared<translation_unit>(env(),
"", 64);
421 ir_translation_unit->set_language(translation_unit::LANG_C);
422 corp->add(ir_translation_unit);
423 cur_transl_unit(ir_translation_unit);
426 ctf_dict_t *ctf_dict, *dict_tmp;
427 const auto symt =
symtab();
428 symtab_reader::symtab_filter filter = symt->make_filter();
429 filter.set_public_symbols();
430 std::string dict_name;
432 if ((corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)
437 std::size_t pos = dict_name.find(
".");
438 if (pos != string::npos)
439 dict_name.erase(pos);
441 std::replace(dict_name.begin(), dict_name.end(),
'-',
'_');
444 if ((ctf_dict = ctf_dict_open(ctfa,
445 dict_name.empty() ? NULL : dict_name.c_str(),
448 fprintf(stderr,
"ERROR dictionary not found\n");
454 for (
const auto& symbol : symtab_reader::filtered_symtab(*symt, filter))
456 std::string sym_name = symbol->get_name();
457 ctf_id_t ctf_sym_type;
459 ctf_sym_type = lookup_symbol_in_ctf_archive(ctfa, &ctf_dict,
461 if (ctf_sym_type == CTF_ERR)
464 if (ctf_type_kind(ctf_dict, ctf_sym_type) != CTF_K_FUNCTION)
466 const char *var_name = sym_name.c_str();
467 type_base_sptr var_type = build_type(ctf_dict, ctf_sym_type);
473 var_declaration.reset(
new var_decl(var_name,
478 var_declaration->set_symbol(symbol);
480 ir_translation_unit->get_global_scope());
481 var_declaration->set_is_in_public_symbol_table(
true);
486 const char *func_name = sym_name.c_str();
487 ctf_id_t ctf_sym = ctf_sym_type;
488 type_base_sptr func_type = build_type(ctf_dict, ctf_sym);
494 func_declaration.reset(
new function_decl(func_name,
498 func_declaration->set_symbol(symbol);
500 ir_translation_unit->get_global_scope());
501 func_declaration->set_is_in_public_symbol_table(
true);
508 ctf_dict_close(ctf_dict);
513 canonicalize_all_types();
526 process_ctf_type(ctf_dict_t *ctf_dictionary,
529 corpus_sptr corp =
corpus();
531 int type_kind = ctf_type_kind(ctf_dictionary, ctf_type);
532 type_base_sptr result;
534 if (lookup_unknown_type(ctf_type))
537 if ((result =
lookup_type(ctf_dictionary, ctf_type)))
546 = process_ctf_base_type(
this, ctf_dictionary, ctf_type);
553 = process_ctf_typedef(
this, ctf_dictionary, ctf_type);
554 result =
is_type(typedef_decl);
560 = process_ctf_pointer_type(
this, ctf_dictionary, ctf_type);
561 result = pointer_type;
568 type_base_sptr qualified_type
569 = process_ctf_qualified_type(
this, ctf_dictionary, ctf_type);
570 result = qualified_type;
576 = process_ctf_array_type(
this, ctf_dictionary, ctf_type);
583 = process_ctf_enum_type(
this, ctf_dictionary, ctf_type);
590 = process_ctf_function_type(
this, ctf_dictionary, ctf_type);
591 result = function_type;
597 = process_ctf_struct_type(
this, ctf_dictionary, ctf_type);
602 result = process_ctf_forward_type(
this, ctf_dictionary, ctf_type);
606 union_decl_sptr union_decl
607 = process_ctf_union_type(
this, ctf_dictionary, ctf_type);
619 fprintf(stderr,
"NOT PROCESSED TYPE %lu\n", ctf_type);
620 add_unknown_type(ctf_type);
638 build_type(ctf_dict_t *ctf_dictionary, ctf_id_t ctf_type)
640 type_base_sptr result =
lookup_type(ctf_dictionary, ctf_type);
643 result = process_ctf_type(ctf_dictionary, ctf_type);
658 corpus_sptr corp =
corpus();
662 origin |= corpus::CTF_ORIGIN;
663 corp->set_origin(origin);
665 slurp_elf_info(status);
667 return corpus_sptr();
669 if (!(origin & corpus::LINUX_KERNEL_BINARY_ORIGIN)
674 if ((corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)
679 std::string ctfa_filename;
680 if (find_ctfa_file(ctfa_filename))
681 ctfa = ctf_arc_open(ctfa_filename.c_str(), &errp);
689 ctfa = ctf_arc_bufopen(&ctf_sect, &symtab_sect,
690 &strtab_sect, &errp);
692 env().canonicalization_is_done(
false);
697 process_ctf_archive();
698 corpus()->sort_functions();
699 corpus()->sort_variables();
702 env().canonicalization_is_done(
true);
714typedef shared_ptr<reader> reader_sptr;
725process_ctf_typedef(reader *rdr,
726 ctf_dict_t *ctf_dictionary,
729 corpus_sptr corp = rdr->corpus();
733 ctf_id_t ctf_utype = ctf_type_reference(ctf_dictionary, ctf_type);
734 if (ctf_utype == CTF_ERR)
737 const char *typedef_name = ctf_type_name_raw(ctf_dictionary, ctf_type);
738 if (corpus_sptr corp = rdr->should_reuse_type_from_corpus_group())
742 type_base_sptr utype = rdr->build_type(ctf_dictionary, ctf_utype);
747 result = dynamic_pointer_cast<typedef_decl>
748 (rdr->lookup_type(ctf_dictionary, ctf_type));
752 result.reset(
new typedef_decl(typedef_name, utype, location(),
761 decl_base_sptr decl =
is_decl(utype);
763 decl->set_naming_typedef(result);
769 rdr->add_type(ctf_dictionary, ctf_type, result);
785process_ctf_base_type(reader *rdr,
786 ctf_dict_t *ctf_dictionary,
789 corpus_sptr corp = rdr->corpus();
793 ctf_id_t ctf_ref = ctf_type_reference(ctf_dictionary, ctf_type);
794 const char *type_name = ctf_type_name_raw(ctf_dictionary,
795 (ctf_ref != CTF_ERR) ? ctf_ref : ctf_type);
800 ctf_encoding_t type_encoding;
801 if (ctf_type_encoding(ctf_dictionary,
802 (ctf_ref != CTF_ERR) ? ctf_ref : ctf_type,
807 if (type_encoding.cte_bits == 0
808 && type_encoding.cte_format == CTF_INT_SIGNED)
811 decl_base_sptr type_declaration = build_ir_node_for_void_type(*rdr,
813 type_base_sptr void_type =
is_type(type_declaration);
819 if (corpus_sptr corp = rdr->should_reuse_type_from_corpus_group())
821 string normalized_type_name = type_name;
822 integral_type int_type;
824 normalized_type_name = int_type.to_string();
831 result.reset(
new type_decl(rdr->env(),
833 type_encoding.cte_bits,
843 rdr->add_type(ctf_dictionary, ctf_type, result);
857build_ir_node_for_variadic_parameter_type(reader &rdr,
861 const ir::environment& env = rdr.env();
862 type_base_sptr t = env.get_variadic_parameter_type();
866 return type_declaration;
883 const environment& env = rdr.env();
884 type_base_sptr t = env.get_void_type();
902build_ir_node_for_void_pointer_type(reader& rdr,
905 const environment& env = rdr.env();
906 type_base_sptr t = env.get_void_pointer_type();
921process_ctf_function_type(reader *rdr,
922 ctf_dict_t *ctf_dictionary,
925 corpus_sptr corp = rdr->corpus();
930 ctf_funcinfo_t funcinfo;
931 ctf_func_type_info(ctf_dictionary, ctf_type, &funcinfo);
932 int vararg_p = funcinfo.ctc_flags & CTF_FUNC_VARARG;
935 ctf_id_t ctf_ret_type = funcinfo.ctc_return;
936 type_base_sptr ret_type = rdr->build_type(ctf_dictionary, ctf_ret_type);
941 int argc = funcinfo.ctc_argc;
942 std::vector<ctf_id_t> argv(argc);
943 if (
static_cast<ctf_id_t
>(ctf_func_type_args(ctf_dictionary, ctf_type,
944 argc, argv.data())) == CTF_ERR)
948 for (
int i = 0; i < argc; i++)
950 ctf_id_t ctf_arg_type = argv[i];
951 type_base_sptr arg_type = rdr->build_type(ctf_dictionary, ctf_arg_type);
956 (
new function_decl::parameter(arg_type,
"",
960 function_parms.push_back(parm);
965 type_base_sptr arg_type =
966 is_type(build_ir_node_for_variadic_parameter_type(*rdr, tunit));
969 (
new function_decl::parameter(arg_type,
"",
973 function_parms.push_back(parm);
976 result = dynamic_pointer_cast<function_type>
977 (rdr->lookup_type(ctf_dictionary, ctf_type));
982 result.reset(
new function_type(ret_type,
984 tunit->get_address_size(),
989 tunit->bind_function_type_life_time(result);
990 result->set_is_artificial(
true);
993 rdr->add_type(ctf_dictionary, ctf_type, result);
1007process_ctf_sou_members(reader *rdr,
1008 ctf_dict_t *ctf_dictionary,
1010 class_or_union_sptr sou)
1012 corpus_sptr corp = rdr->corpus();
1014 ssize_t member_size;
1015 ctf_next_t *member_next = NULL;
1016 const char *member_name = NULL;
1017 ctf_id_t member_ctf_type;
1019 while ((member_size = ctf_member_next(ctf_dictionary, ctf_type,
1020 &member_next, &member_name,
1024 ctf_membinfo_t membinfo;
1026 if (
static_cast<ctf_id_t
>(ctf_member_info(ctf_dictionary,
1029 &membinfo)) == CTF_ERR)
1033 type_base_sptr member_type = rdr->build_type(ctf_dictionary,
1045 sou->add_data_member(data_member_decl,
1049 membinfo.ctm_offset);
1051 if (ctf_errno(ctf_dictionary) != ECTF_NEXT_END)
1052 fprintf(stderr,
"ERROR from ctf_member_next\n");
1063static type_base_sptr
1064process_ctf_forward_type(reader *rdr,
1065 ctf_dict_t *ctf_dictionary,
1069 decl_base_sptr result;
1070 std::string type_name = ctf_type_name_raw(ctf_dictionary,
1072 bool type_is_anonymous = (type_name ==
"");
1073 uint32_t kind = ctf_type_kind_forwarded (ctf_dictionary, ctf_type);
1075 if (kind == CTF_K_UNION)
1078 union_fwd(
new union_decl(rdr->env(),
1082 decl_base::VISIBILITY_DEFAULT,
1083 type_is_anonymous));
1084 union_fwd->set_is_declaration_only(
true);
1089 if (!type_is_anonymous)
1090 if (corpus_sptr corp = rdr->should_reuse_type_from_corpus_group())
1095 struct_fwd(
new class_decl(rdr->env(), type_name,
1099 decl_base::VISIBILITY_DEFAULT,
1100 type_is_anonymous));
1101 struct_fwd->set_is_declaration_only(
true);
1102 result = struct_fwd;
1109 rdr->add_type(ctf_dictionary, ctf_type,
is_type(result));
1123process_ctf_struct_type(reader *rdr,
1124 ctf_dict_t *ctf_dictionary,
1127 corpus_sptr corp = rdr->corpus();
1130 std::string struct_type_name = ctf_type_name_raw(ctf_dictionary,
1132 bool struct_type_is_anonymous = (struct_type_name ==
"");
1134 if (!struct_type_is_anonymous)
1135 if (corpus_sptr corp = rdr->should_reuse_type_from_corpus_group())
1140 result.reset(
new class_decl(rdr->env(),
1142 ctf_type_size(ctf_dictionary, ctf_type) * 8,
1146 decl_base::VISIBILITY_DEFAULT,
1147 struct_type_is_anonymous));
1157 rdr->add_type(ctf_dictionary, ctf_type, result);
1162 process_ctf_sou_members(rdr, ctf_dictionary, ctf_type, result);
1175static union_decl_sptr
1176process_ctf_union_type(reader *rdr,
1177 ctf_dict_t *ctf_dictionary,
1180 corpus_sptr corp = rdr->corpus();
1182 union_decl_sptr result;
1183 std::string union_type_name = ctf_type_name_raw(ctf_dictionary,
1185 bool union_type_is_anonymous = (union_type_name ==
"");
1187 if (!union_type_is_anonymous)
1188 if (corpus_sptr corp = rdr->should_reuse_type_from_corpus_group())
1193 result.reset(
new union_decl(rdr->env(),
1195 ctf_type_size(ctf_dictionary, ctf_type) * 8,
1197 decl_base::VISIBILITY_DEFAULT,
1198 union_type_is_anonymous));
1208 rdr->add_type(ctf_dictionary, ctf_type, result);
1213 process_ctf_sou_members(rdr, ctf_dictionary, ctf_type, result);
1231build_array_ctf_range(reader *rdr, ctf_dict_t *dic,
1232 ctf_id_t index, uint64_t nelems)
1234 bool is_non_finite =
false;
1235 corpus_sptr corp = rdr->corpus();
1238 array_type_def::subrange_type::bound_value lower_bound;
1239 array_type_def::subrange_type::bound_value upper_bound;
1241 type_base_sptr index_type = rdr->build_type(dic, index);
1245 lower_bound.set_unsigned(0);
1246 upper_bound.set_unsigned(nelems > 0 ? nelems - 1 : 0U);
1249 if (upper_bound.get_unsigned_value() == 0 && nelems == 0)
1250 is_non_finite =
true;
1252 subrange.reset(
new array_type_def::subrange_type(rdr->env(),
1258 translation_unit::LANG_C));
1262 subrange->is_non_finite(is_non_finite);
1279process_ctf_array_type(reader *rdr,
1280 ctf_dict_t *ctf_dictionary,
1283 corpus_sptr corp = rdr->corpus();
1286 ctf_arinfo_t ctf_ainfo;
1289 if (
static_cast<ctf_id_t
>(ctf_array_info(ctf_dictionary,
1291 &ctf_ainfo)) == CTF_ERR)
1294 ctf_id_t ctf_element_type = ctf_ainfo.ctr_contents;
1295 ctf_id_t ctf_index_type = ctf_ainfo.ctr_index;
1296 uint64_t nelems = ctf_ainfo.ctr_nelems;
1300 int type_array_kind = ctf_type_kind(ctf_dictionary, ctf_element_type);
1301 while (type_array_kind == CTF_K_ARRAY)
1303 if (
static_cast<ctf_id_t
>(ctf_array_info(ctf_dictionary,
1305 &ctf_ainfo)) == CTF_ERR)
1308 subrange = build_array_ctf_range(rdr, ctf_dictionary,
1309 ctf_ainfo.ctr_index,
1310 ctf_ainfo.ctr_nelems);
1311 subranges.push_back(subrange);
1312 ctf_element_type = ctf_ainfo.ctr_contents;
1313 type_array_kind = ctf_type_kind(ctf_dictionary, ctf_element_type);
1316 std::reverse(subranges.begin(), subranges.end());
1319 type_base_sptr element_type = rdr->build_type(ctf_dictionary,
1325 type_base_sptr index_type = rdr->build_type(ctf_dictionary,
1330 result = dynamic_pointer_cast<array_type_def>
1331 (rdr->lookup_type(ctf_dictionary, ctf_type));
1335 subrange = build_array_ctf_range(rdr, ctf_dictionary,
1336 ctf_index_type, nelems);
1337 subranges.push_back(subrange);
1340 result.reset(
new array_type_def(element_type, subranges, location()));
1345 rdr->add_type(ctf_dictionary, ctf_type, result);
1372static decl_base_sptr
1373maybe_strip_qualification(
const qualified_type_def_sptr t)
1378 decl_base_sptr result = t;
1379 type_base_sptr u = t->get_underlying_type();
1391 type_base_sptr element_type = array->get_element_type();
1396 quals |= t->get_cv_quals();
1399 qualified->set_cv_quals(quals);
1414static type_base_sptr
1415process_ctf_qualified_type(reader *rdr,
1416 ctf_dict_t *ctf_dictionary,
1419 corpus_sptr corp = rdr->corpus();
1421 type_base_sptr result;
1422 int type_kind = ctf_type_kind(ctf_dictionary, ctf_type);
1423 ctf_id_t ctf_utype = ctf_type_reference(ctf_dictionary, ctf_type);
1424 type_base_sptr utype = rdr->build_type(ctf_dictionary, ctf_utype);
1428 result = dynamic_pointer_cast<type_base>
1429 (rdr->lookup_type(ctf_dictionary, ctf_type));
1434 if (type_kind == CTF_K_CONST)
1435 qualifiers |= qualified_type_def::CV_CONST;
1436 else if (type_kind == CTF_K_VOLATILE)
1437 qualifiers |= qualified_type_def::CV_VOLATILE;
1438 else if (type_kind == CTF_K_RESTRICT)
1439 qualifiers |= qualified_type_def::CV_RESTRICT;
1447 result.reset(
new qualified_type_def(utype, qualifiers, location()));
1459 rdr->add_type(ctf_dictionary, ctf_type, result);
1474process_ctf_pointer_type(reader *rdr,
1475 ctf_dict_t *ctf_dictionary,
1478 corpus_sptr corp = rdr->corpus();
1481 ctf_id_t ctf_target_type = ctf_type_reference(ctf_dictionary, ctf_type);
1482 if (ctf_target_type == CTF_ERR)
1485 type_base_sptr target_type = rdr->build_type(ctf_dictionary,
1490 result = dynamic_pointer_cast<pointer_type_def>
1491 (rdr->lookup_type(ctf_dictionary, ctf_type));
1495 if (rdr->env().is_void_type(target_type))
1496 result =
is_pointer_type(build_ir_node_for_void_pointer_type(*rdr, tunit));
1498 result.reset(
new pointer_type_def(target_type,
1499 ctf_type_size(ctf_dictionary,
1501 ctf_type_align(ctf_dictionary,
1507 rdr->add_type(ctf_dictionary, ctf_type, result);
1522process_ctf_enum_type(reader *rdr,
1523 ctf_dict_t *ctf_dictionary,
1528 ctf_id_t ctf_ref = ctf_type_reference(ctf_dictionary, ctf_type);
1529 std::string enum_name = ctf_type_name_raw(ctf_dictionary,
1530 (ctf_ref != CTF_ERR)
1531 ? ctf_ref : ctf_type);
1533 if (!enum_name.empty())
1534 if (corpus_sptr corp = rdr->should_reuse_type_from_corpus_group())
1541 size_t utype_size_in_bits = ctf_type_size(ctf_dictionary,
1542 (ctf_ref != CTF_ERR)
1543 ? ctf_ref : ctf_type) * 8;
1544 string underlying_type_name =
1546 utype_size_in_bits);
1549 utype.reset(
new type_decl(rdr->env(),
1550 underlying_type_name,
1554 utype->set_is_anonymous(
true);
1555 utype->set_is_artificial(
true);
1564 ctf_next_t *enum_next = NULL;
1568 while ((ename = ctf_enum_next(ctf_dictionary, ctf_type, &enum_next, &evalue)))
1569 enms.push_back(enum_type_decl::enumerator(ename, evalue));
1571 if (ctf_errno(ctf_dictionary) != ECTF_NEXT_END)
1573 fprintf(stderr,
"ERROR from ctf_enum_next\n");
1577 result.reset(
new enum_type_decl(enum_name.c_str(), location(),
1578 utype, enms, enum_name.c_str()));
1582 rdr->add_type(ctf_dictionary, ctf_type, result);
1605lookup_symbol_in_ctf_archive(ctf_archive_t *ctfa, ctf_dict_t **ctf_dict,
1606 const char *sym_name)
1609 ctf_dict_t *dict = *ctf_dict;
1610 ctf_id_t ctf_type = ctf_lookup_by_symbol_name(dict, sym_name);
1612 if (ctf_type != CTF_ERR)
1617 ctf_type = ctf_lookup_variable(dict, sym_name);
1620 if (ctf_type == CTF_ERR)
1623 ctf_next_t *i = NULL;
1624 const char *arcname;
1626 while ((fp = ctf_archive_next(ctfa, &i, &arcname, 1, &ctf_err)) != NULL)
1628 if ((ctf_type = ctf_lookup_by_symbol_name (fp, sym_name)) == CTF_ERR)
1629 ctf_type = ctf_lookup_variable(fp, sym_name);
1631 if (ctf_type != CTF_ERR)
1650fill_ctf_section(
const Elf_Scn *elf_section, ctf_sect_t *ctf_section)
1652 GElf_Shdr section_header_mem, *section_header;
1653 Elf_Data *section_data;
1655 section_header = gelf_getshdr(
const_cast<Elf_Scn*
>(elf_section),
1656 §ion_header_mem);
1657 section_data = elf_getdata(
const_cast<Elf_Scn*
>(elf_section), 0);
1662 ctf_section->cts_name =
"";
1663 ctf_section->cts_data = (
char *) section_data->d_buf;
1664 ctf_section->cts_size = section_data->d_size;
1665 ctf_section->cts_entsize = section_header->sh_entsize;
1674elf_based_reader_sptr
1676 const vector<char**>& debug_info_root_paths,
1679 reader_sptr result(
new reader(elf_path,
1680 debug_info_root_paths,
1705 const std::string& elf_path,
1706 const vector<char**>& debug_info_root_path)
1708 ctf::reader& r =
dynamic_cast<reader&
>(rdr);
1709 r.initialize(elf_path, debug_info_root_path);
1726dic_type_key(ctf_dict_t *dic, ctf_id_t ctf_type)
1728 std::stringstream key;
1730 if (ctf_type_isparent (dic, ctf_type))
1731 key << std::hex << ctf_type;
1733 key << std::hex << ctf_type <<
'-' << ctf_cuname(dic);
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.
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.
Elf * elf_handle() const
Getter of the handle used to access ELF information from the current ELF file.
const Elf_Scn * find_ctf_section() const
Find and return a pointer to the the CTF section.
virtual ir::corpus_sptr read_corpus(status &status)
Read the ELF information associated to the current ELF file and construct an ABI representation from ...
const vector< char ** > & debug_info_root_paths() const
Getter of the vector of directory paths to look into for split debug information files.
symtab_reader::symtab_sptr & symtab() const
Getter of an abstract representation of the symbol table of the underlying ELF file.
The common interface of readers based on ELF.
elf_based_reader(const std::string &elf_path, const vector< char ** > &debug_info_root_paths, environment &env)
Readers that implement this interface must provide a factory method to create a reader instance as th...
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.
const options_type & options() const
Getter of the the options of the current Front End Interface.
void maybe_add_fn_to_exported_decls(const function_decl *fn)
Try and add the representation of the ABI of a function to the set of exported declarations of the cu...
corpus_sptr corpus()
Getter for the ABI corpus being built by the current front-end.
void maybe_add_var_to_exported_decls(const var_decl *var)
Try and add the representation of the ABI of a variable to the set of exported declarations of the cu...
corpus_group_sptr & corpus_group()
Getter for the ABI corpus group being built by the current front-end.
const std::string & corpus_path() const
Getter of the path to the file which an ABI corpus is to be created for.
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.
origin
This abstracts where the corpus comes from. That is, either it has been read from the native xml form...
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...
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.
CV
Bit field values representing the cv qualifiers of the underlying type.
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.
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.
void canonicalize_types(const input_iterator &begin, const input_iterator &end, deref_lambda deref)
Compute the canonical type for all the IR types of the system.
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.
bool parse_integral_type(const string &type_name, integral_type &type)
Parse an integral type from a string.
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.
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.
type_base_sptr canonicalize(type_base_sptr t)
Compute the canonical type of a given type.
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.
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.