25 #include "abg-internal.h"
30 #include "abg-internal.h"
32 ABG_BEGIN_EXPORT_DECLARATIONS
40 ABG_END_EXPORT_DECLARATIONS
47 using std::dynamic_pointer_cast;
54 process_ctf_typedef(reader *rdr,
55 ctf_dict_t *ctf_dictionary,
59 process_ctf_base_type(reader *rdr,
60 ctf_dict_t *ctf_dictionary,
64 build_ir_node_for_variadic_parameter_type(reader &rdr,
68 process_ctf_function_type(reader *rdr,
69 ctf_dict_t *ctf_dictionary,
73 process_ctf_sou_members(reader *rdr,
74 ctf_dict_t *ctf_dictionary,
76 class_or_union_sptr sou);
79 process_ctf_forward_type(reader *rdr,
80 ctf_dict_t *ctf_dictionary,
84 process_ctf_struct_type(reader *rdr,
85 ctf_dict_t *ctf_dictionary,
88 static union_decl_sptr
89 process_ctf_union_type(reader *rdr,
90 ctf_dict_t *ctf_dictionary,
94 process_ctf_array_type(reader *rdr,
95 ctf_dict_t *ctf_dictionary,
99 process_ctf_qualified_type(reader *rdr,
100 ctf_dict_t *ctf_dictionary,
104 process_ctf_pointer_type(reader *rdr,
105 ctf_dict_t *ctf_dictionary,
109 process_ctf_enum_type(reader *rdr,
110 ctf_dict_t *ctf_dictionary,
114 fill_ctf_section(
const Elf_Scn *elf_section, ctf_sect_t *ctf_section);
117 lookup_symbol_in_ctf_archive(ctf_archive_t *ctfa, ctf_dict_t **ctf_dict,
118 const char *sym_name);
121 dic_type_key(ctf_dict_t *dic, ctf_id_t ctf_type);
127 class reader :
public elf_based_reader
138 std::set<ctf_id_t> unknown_types_set;
143 ctf_sect_t symtab_sect;
144 ctf_sect_t strtab_sect;
152 corpus::exported_decls_builder*
153 exported_decls_builder()
154 {
return corpus()->get_exported_decls_builder().get();}
164 add_type(ctf_dict_t *dic, ctf_id_t ctf_type, type_base_sptr type)
166 string key = dic_type_key(dic, ctf_type);
167 types_map.insert(std::make_pair(key, type));
174 add_unknown_type(ctf_id_t ctf_type)
176 unknown_types_set.insert(ctf_type);
187 type_base_sptr result;
188 std::string key = dic_type_key(dic, ctf_type);
190 auto search = types_map.find(key);
191 if (search != types_map.end())
192 result = search->second;
200 lookup_unknown_type(ctf_id_t ctf_type)
201 {
return unknown_types_set.find(ctf_type) != unknown_types_set.end(); }
205 canonicalize_all_types(
void)
208 (types_map.begin(), types_map.end(),
209 [](
const string_type_base_sptr_map_type::const_iterator& i)
210 {return i->second;});
225 reader(
const string& elf_path,
226 const vector<char**>& debug_info_root_paths,
276 initialize(
const string& elf_path,
277 const vector<char**>& debug_info_root_paths,
278 bool load_all_types =
false,
279 bool linux_kernel_mode =
false)
281 load_all_types = load_all_types;
282 linux_kernel_mode = linux_kernel_mode;
283 reset(elf_path, debug_info_root_paths);
300 cur_transl_unit()
const
324 find_ctfa_file(std::string& ctfa_file)
326 std::string ctfa_dirname;
332 ctfa_file = ctfa_dirname +
"/vmlinux.ctfa";
357 corpus_sptr corp =
corpus();
358 if ((corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)
368 if ((status & STATUS_NO_SYMBOLS_FOUND)
375 GElf_Ehdr *ehdr, eh_mem;
376 if (!(ehdr = gelf_getehdr(
elf_handle(), &eh_mem)))
380 const char *symtab_name =
".dynsym";
381 const char *strtab_name =
".dynstr";
383 if (ehdr->e_type == ET_REL)
385 symtab_name =
".symtab";
386 strtab_name =
".strtab";
390 fill_ctf_section(ctf_scn, &ctf_sect);
392 const Elf_Scn* symtab_scn =
393 elf_helpers::find_section_by_name(
elf_handle(), symtab_name);
394 fill_ctf_section(symtab_scn, &symtab_sect);
396 const Elf_Scn* strtab_scn =
397 elf_helpers::find_section_by_name(
elf_handle(), strtab_name);
398 fill_ctf_section(strtab_scn, &strtab_sect);
407 process_ctf_archive()
409 corpus_sptr corp =
corpus();
412 std::make_shared<translation_unit>(env(),
"", 64);
413 ir_translation_unit->set_language(translation_unit::LANG_C);
414 corp->add(ir_translation_unit);
415 cur_transl_unit(ir_translation_unit);
418 ctf_dict_t *ctf_dict, *dict_tmp;
419 const auto symt =
symtab();
420 symtab_reader::symtab_filter filter = symt->make_filter();
421 filter.set_public_symbols();
422 std::string dict_name;
424 if ((corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)
429 std::size_t pos = dict_name.find(
".");
430 if (pos != string::npos)
431 dict_name.erase(pos);
433 std::replace(dict_name.begin(), dict_name.end(),
'-',
'_');
436 if ((ctf_dict = ctf_dict_open(ctfa,
437 dict_name.empty() ? NULL : dict_name.c_str(),
440 fprintf(stderr,
"ERROR dictionary not found\n");
446 for (
const auto& symbol : symtab_reader::filtered_symtab(*symt, filter))
448 std::string sym_name = symbol->get_name();
449 ctf_id_t ctf_sym_type;
451 ctf_sym_type = lookup_symbol_in_ctf_archive(ctfa, &ctf_dict,
453 if (ctf_sym_type == CTF_ERR)
456 if (ctf_type_kind(ctf_dict, ctf_sym_type) != CTF_K_FUNCTION)
458 const char *var_name = sym_name.c_str();
459 type_base_sptr var_type = build_type(ctf_dict, ctf_sym_type);
465 var_declaration.reset(
new var_decl(var_name,
470 var_declaration->set_symbol(symbol);
472 ir_translation_unit->get_global_scope());
473 var_declaration->set_is_in_public_symbol_table(
true);
478 const char *func_name = sym_name.c_str();
479 ctf_id_t ctf_sym = ctf_sym_type;
480 type_base_sptr func_type = build_type(ctf_dict, ctf_sym);
486 func_declaration.reset(
new function_decl(func_name,
490 func_declaration->set_symbol(symbol);
492 ir_translation_unit->get_global_scope());
493 func_declaration->set_is_in_public_symbol_table(
true);
500 ctf_dict_close(ctf_dict);
505 canonicalize_all_types();
518 process_ctf_type(ctf_dict_t *ctf_dictionary,
521 corpus_sptr corp =
corpus();
523 int type_kind = ctf_type_kind(ctf_dictionary, ctf_type);
524 type_base_sptr result;
526 if (lookup_unknown_type(ctf_type))
529 if ((result =
lookup_type(ctf_dictionary, ctf_type)))
538 = process_ctf_base_type(
this, ctf_dictionary, ctf_type);
545 = process_ctf_typedef(
this, ctf_dictionary, ctf_type);
546 result =
is_type(typedef_decl);
552 = process_ctf_pointer_type(
this, ctf_dictionary, ctf_type);
553 result = pointer_type;
560 type_base_sptr qualified_type
561 = process_ctf_qualified_type(
this, ctf_dictionary, ctf_type);
562 result = qualified_type;
568 = process_ctf_array_type(
this, ctf_dictionary, ctf_type);
575 = process_ctf_enum_type(
this, ctf_dictionary, ctf_type);
582 = process_ctf_function_type(
this, ctf_dictionary, ctf_type);
583 result = function_type;
589 = process_ctf_struct_type(
this, ctf_dictionary, ctf_type);
594 result = process_ctf_forward_type(
this, ctf_dictionary, ctf_type);
598 union_decl_sptr union_decl
599 = process_ctf_union_type(
this, ctf_dictionary, ctf_type);
611 fprintf(stderr,
"NOT PROCESSED TYPE %lu\n", ctf_type);
612 add_unknown_type(ctf_type);
630 build_type(ctf_dict_t *ctf_dictionary, ctf_id_t ctf_type)
632 type_base_sptr result =
lookup_type(ctf_dictionary, ctf_type);
635 result = process_ctf_type(ctf_dictionary, ctf_type);
650 corpus_sptr corp =
corpus();
654 origin |= corpus::CTF_ORIGIN;
655 corp->set_origin(origin);
657 slurp_elf_info(status);
659 return corpus_sptr();
661 if (!(origin & corpus::LINUX_KERNEL_BINARY_ORIGIN)
666 if ((corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)
671 std::string ctfa_filename;
672 if (find_ctfa_file(ctfa_filename))
673 ctfa = ctf_arc_open(ctfa_filename.c_str(), &errp);
681 ctfa = ctf_arc_bufopen(&ctf_sect, &symtab_sect,
682 &strtab_sect, &errp);
684 env().canonicalization_is_done(
false);
689 process_ctf_archive();
690 corpus()->sort_functions();
691 corpus()->sort_variables();
694 env().canonicalization_is_done(
true);
706 typedef shared_ptr<reader> reader_sptr;
717 process_ctf_typedef(reader *rdr,
718 ctf_dict_t *ctf_dictionary,
721 corpus_sptr corp = rdr->corpus();
725 ctf_id_t ctf_utype = ctf_type_reference(ctf_dictionary, ctf_type);
726 if (ctf_utype == CTF_ERR)
729 const char *typedef_name = ctf_type_name_raw(ctf_dictionary, ctf_type);
730 if (corpus_sptr corp = rdr->should_reuse_type_from_corpus_group())
734 type_base_sptr utype = rdr->build_type(ctf_dictionary, ctf_utype);
739 result = dynamic_pointer_cast<typedef_decl>
740 (rdr->lookup_type(ctf_dictionary, ctf_type));
744 result.reset(
new typedef_decl(typedef_name, utype, location(),
753 decl_base_sptr decl =
is_decl(utype);
755 decl->set_naming_typedef(result);
761 rdr->add_type(ctf_dictionary, ctf_type, result);
777 process_ctf_base_type(reader *rdr,
778 ctf_dict_t *ctf_dictionary,
781 corpus_sptr corp = rdr->corpus();
785 ctf_id_t ctf_ref = ctf_type_reference(ctf_dictionary, ctf_type);
786 const char *type_name = ctf_type_name_raw(ctf_dictionary,
787 (ctf_ref != CTF_ERR) ? ctf_ref : ctf_type);
792 ctf_encoding_t type_encoding;
793 if (ctf_type_encoding(ctf_dictionary,
794 (ctf_ref != CTF_ERR) ? ctf_ref : ctf_type,
799 if (type_encoding.cte_bits == 0
800 && type_encoding.cte_format == CTF_INT_SIGNED)
803 type_base_sptr void_type = rdr->env().get_void_type();
810 if (corpus_sptr corp = rdr->should_reuse_type_from_corpus_group())
812 string normalized_type_name = type_name;
813 integral_type int_type;
815 normalized_type_name = int_type.to_string();
822 result.reset(
new type_decl(rdr->env(),
824 type_encoding.cte_bits,
834 rdr->add_type(ctf_dictionary, ctf_type, result);
845 static decl_base_sptr
846 build_ir_node_for_variadic_parameter_type(reader &rdr,
850 const ir::environment& env = rdr.env();
851 type_base_sptr t = env.get_variadic_parameter_type();
856 return type_declaration;
868 process_ctf_function_type(reader *rdr,
869 ctf_dict_t *ctf_dictionary,
872 corpus_sptr corp = rdr->corpus();
877 ctf_funcinfo_t funcinfo;
878 ctf_func_type_info(ctf_dictionary, ctf_type, &funcinfo);
879 int vararg_p = funcinfo.ctc_flags & CTF_FUNC_VARARG;
882 ctf_id_t ctf_ret_type = funcinfo.ctc_return;
883 type_base_sptr ret_type = rdr->build_type(ctf_dictionary, ctf_ret_type);
888 int argc = funcinfo.ctc_argc;
889 std::vector<ctf_id_t> argv(argc);
890 if (
static_cast<ctf_id_t
>(ctf_func_type_args(ctf_dictionary, ctf_type,
891 argc, argv.data())) == CTF_ERR)
895 for (
int i = 0; i < argc; i++)
897 ctf_id_t ctf_arg_type = argv[i];
898 type_base_sptr arg_type = rdr->build_type(ctf_dictionary, ctf_arg_type);
903 (
new function_decl::parameter(arg_type,
"",
907 function_parms.push_back(parm);
912 type_base_sptr arg_type =
913 is_type(build_ir_node_for_variadic_parameter_type(*rdr, tunit));
916 (
new function_decl::parameter(arg_type,
"",
920 function_parms.push_back(parm);
923 result = dynamic_pointer_cast<function_type>
924 (rdr->lookup_type(ctf_dictionary, ctf_type));
929 result.reset(
new function_type(ret_type,
931 tunit->get_address_size(),
936 tunit->bind_function_type_life_time(result);
937 result->set_is_artificial(
true);
940 rdr->add_type(ctf_dictionary, ctf_type, result);
954 process_ctf_sou_members(reader *rdr,
955 ctf_dict_t *ctf_dictionary,
957 class_or_union_sptr sou)
959 corpus_sptr corp = rdr->corpus();
962 ctf_next_t *member_next = NULL;
963 const char *member_name = NULL;
964 ctf_id_t member_ctf_type;
966 while ((member_size = ctf_member_next(ctf_dictionary, ctf_type,
967 &member_next, &member_name,
971 ctf_membinfo_t membinfo;
973 if (
static_cast<ctf_id_t
>(ctf_member_info(ctf_dictionary,
976 &membinfo)) == CTF_ERR)
980 type_base_sptr member_type = rdr->build_type(ctf_dictionary,
992 sou->add_data_member(data_member_decl,
996 membinfo.ctm_offset);
998 if (ctf_errno(ctf_dictionary) != ECTF_NEXT_END)
999 fprintf(stderr,
"ERROR from ctf_member_next\n");
1010 static type_base_sptr
1011 process_ctf_forward_type(reader *rdr,
1012 ctf_dict_t *ctf_dictionary,
1016 decl_base_sptr result;
1017 std::string type_name = ctf_type_name_raw(ctf_dictionary,
1019 bool type_is_anonymous = (type_name ==
"");
1020 uint32_t kind = ctf_type_kind_forwarded (ctf_dictionary, ctf_type);
1022 if (kind == CTF_K_UNION)
1025 union_fwd(
new union_decl(rdr->env(),
1029 decl_base::VISIBILITY_DEFAULT,
1030 type_is_anonymous));
1031 union_fwd->set_is_declaration_only(
true);
1036 if (!type_is_anonymous)
1037 if (corpus_sptr corp = rdr->should_reuse_type_from_corpus_group())
1042 struct_fwd(
new class_decl(rdr->env(), type_name,
1046 decl_base::VISIBILITY_DEFAULT,
1047 type_is_anonymous));
1048 struct_fwd->set_is_declaration_only(
true);
1049 result = struct_fwd;
1056 rdr->add_type(ctf_dictionary, ctf_type,
is_type(result));
1070 process_ctf_struct_type(reader *rdr,
1071 ctf_dict_t *ctf_dictionary,
1074 corpus_sptr corp = rdr->corpus();
1077 std::string struct_type_name = ctf_type_name_raw(ctf_dictionary,
1079 bool struct_type_is_anonymous = (struct_type_name ==
"");
1081 if (!struct_type_is_anonymous)
1082 if (corpus_sptr corp = rdr->should_reuse_type_from_corpus_group())
1087 result.reset(
new class_decl(rdr->env(),
1089 ctf_type_size(ctf_dictionary, ctf_type) * 8,
1093 decl_base::VISIBILITY_DEFAULT,
1094 struct_type_is_anonymous));
1104 rdr->add_type(ctf_dictionary, ctf_type, result);
1109 process_ctf_sou_members(rdr, ctf_dictionary, ctf_type, result);
1122 static union_decl_sptr
1123 process_ctf_union_type(reader *rdr,
1124 ctf_dict_t *ctf_dictionary,
1127 corpus_sptr corp = rdr->corpus();
1129 union_decl_sptr result;
1130 std::string union_type_name = ctf_type_name_raw(ctf_dictionary,
1132 bool union_type_is_anonymous = (union_type_name ==
"");
1134 if (!union_type_is_anonymous)
1135 if (corpus_sptr corp = rdr->should_reuse_type_from_corpus_group())
1140 result.reset(
new union_decl(rdr->env(),
1142 ctf_type_size(ctf_dictionary, ctf_type) * 8,
1144 decl_base::VISIBILITY_DEFAULT,
1145 union_type_is_anonymous));
1155 rdr->add_type(ctf_dictionary, ctf_type, result);
1160 process_ctf_sou_members(rdr, ctf_dictionary, ctf_type, result);
1178 build_array_ctf_range(reader *rdr, ctf_dict_t *dic,
1179 ctf_id_t index, uint64_t nelems)
1181 bool is_infinite =
false;
1182 corpus_sptr corp = rdr->corpus();
1185 array_type_def::subrange_type::bound_value lower_bound;
1186 array_type_def::subrange_type::bound_value upper_bound;
1188 type_base_sptr index_type = rdr->build_type(dic, index);
1192 lower_bound.set_unsigned(0);
1193 upper_bound.set_unsigned(nelems > 0 ? nelems - 1 : 0U);
1196 if (upper_bound.get_unsigned_value() == 0 && nelems == 0)
1199 subrange.reset(
new array_type_def::subrange_type(rdr->env(),
1205 translation_unit::LANG_C));
1209 subrange->is_infinite(is_infinite);
1226 process_ctf_array_type(reader *rdr,
1227 ctf_dict_t *ctf_dictionary,
1230 corpus_sptr corp = rdr->corpus();
1233 ctf_arinfo_t ctf_ainfo;
1236 if (
static_cast<ctf_id_t
>(ctf_array_info(ctf_dictionary,
1238 &ctf_ainfo)) == CTF_ERR)
1241 ctf_id_t ctf_element_type = ctf_ainfo.ctr_contents;
1242 ctf_id_t ctf_index_type = ctf_ainfo.ctr_index;
1243 uint64_t nelems = ctf_ainfo.ctr_nelems;
1247 int type_array_kind = ctf_type_kind(ctf_dictionary, ctf_element_type);
1248 while (type_array_kind == CTF_K_ARRAY)
1250 if (
static_cast<ctf_id_t
>(ctf_array_info(ctf_dictionary,
1252 &ctf_ainfo)) == CTF_ERR)
1255 subrange = build_array_ctf_range(rdr, ctf_dictionary,
1256 ctf_ainfo.ctr_index,
1257 ctf_ainfo.ctr_nelems);
1258 subranges.push_back(subrange);
1259 ctf_element_type = ctf_ainfo.ctr_contents;
1260 type_array_kind = ctf_type_kind(ctf_dictionary, ctf_element_type);
1263 std::reverse(subranges.begin(), subranges.end());
1266 type_base_sptr element_type = rdr->build_type(ctf_dictionary,
1272 type_base_sptr index_type = rdr->build_type(ctf_dictionary,
1277 result = dynamic_pointer_cast<array_type_def>
1278 (rdr->lookup_type(ctf_dictionary, ctf_type));
1282 subrange = build_array_ctf_range(rdr, ctf_dictionary,
1283 ctf_index_type, nelems);
1284 subranges.push_back(subrange);
1287 result.reset(
new array_type_def(element_type, subranges, location()));
1292 rdr->add_type(ctf_dictionary, ctf_type, result);
1319 static decl_base_sptr
1320 maybe_strip_qualification(
const qualified_type_def_sptr t)
1325 decl_base_sptr result = t;
1326 type_base_sptr u = t->get_underlying_type();
1338 type_base_sptr element_type = array->get_element_type();
1343 quals |= t->get_cv_quals();
1346 qualified->set_cv_quals(quals);
1361 static type_base_sptr
1362 process_ctf_qualified_type(reader *rdr,
1363 ctf_dict_t *ctf_dictionary,
1366 corpus_sptr corp = rdr->corpus();
1368 type_base_sptr result;
1369 int type_kind = ctf_type_kind(ctf_dictionary, ctf_type);
1370 ctf_id_t ctf_utype = ctf_type_reference(ctf_dictionary, ctf_type);
1371 type_base_sptr utype = rdr->build_type(ctf_dictionary, ctf_utype);
1375 result = dynamic_pointer_cast<type_base>
1376 (rdr->lookup_type(ctf_dictionary, ctf_type));
1381 if (type_kind == CTF_K_CONST)
1382 qualifiers |= qualified_type_def::CV_CONST;
1383 else if (type_kind == CTF_K_VOLATILE)
1384 qualifiers |= qualified_type_def::CV_VOLATILE;
1385 else if (type_kind == CTF_K_RESTRICT)
1386 qualifiers |= qualified_type_def::CV_RESTRICT;
1394 result.reset(
new qualified_type_def(utype, qualifiers, location()));
1406 rdr->add_type(ctf_dictionary, ctf_type, result);
1421 process_ctf_pointer_type(reader *rdr,
1422 ctf_dict_t *ctf_dictionary,
1425 corpus_sptr corp = rdr->corpus();
1428 ctf_id_t ctf_target_type = ctf_type_reference(ctf_dictionary, ctf_type);
1429 if (ctf_target_type == CTF_ERR)
1432 type_base_sptr target_type = rdr->build_type(ctf_dictionary,
1437 result = dynamic_pointer_cast<pointer_type_def>
1438 (rdr->lookup_type(ctf_dictionary, ctf_type));
1442 result.reset(
new pointer_type_def(target_type,
1443 ctf_type_size(ctf_dictionary, ctf_type) * 8,
1444 ctf_type_align(ctf_dictionary, ctf_type) * 8,
1449 rdr->add_type(ctf_dictionary, ctf_type, result);
1464 process_ctf_enum_type(reader *rdr,
1465 ctf_dict_t *ctf_dictionary,
1470 ctf_id_t ctf_ref = ctf_type_reference(ctf_dictionary, ctf_type);
1471 std::string enum_name = ctf_type_name_raw(ctf_dictionary,
1472 (ctf_ref != CTF_ERR)
1473 ? ctf_ref : ctf_type);
1475 if (!enum_name.empty())
1476 if (corpus_sptr corp = rdr->should_reuse_type_from_corpus_group())
1483 size_t utype_size_in_bits = ctf_type_size(ctf_dictionary,
1484 (ctf_ref != CTF_ERR)
1485 ? ctf_ref : ctf_type) * 8;
1486 string underlying_type_name =
1488 utype_size_in_bits);
1491 utype.reset(
new type_decl(rdr->env(),
1492 underlying_type_name,
1496 utype->set_is_anonymous(
true);
1497 utype->set_is_artificial(
true);
1506 ctf_next_t *enum_next = NULL;
1510 while ((ename = ctf_enum_next(ctf_dictionary, ctf_type, &enum_next, &evalue)))
1511 enms.push_back(enum_type_decl::enumerator(ename, evalue));
1513 if (ctf_errno(ctf_dictionary) != ECTF_NEXT_END)
1515 fprintf(stderr,
"ERROR from ctf_enum_next\n");
1519 result.reset(
new enum_type_decl(enum_name.c_str(), location(),
1520 utype, enms, enum_name.c_str()));
1524 rdr->add_type(ctf_dictionary, ctf_type, result);
1547 lookup_symbol_in_ctf_archive(ctf_archive_t *ctfa, ctf_dict_t **ctf_dict,
1548 const char *sym_name)
1551 ctf_dict_t *dict = *ctf_dict;
1552 ctf_id_t ctf_type = ctf_lookup_by_symbol_name(dict, sym_name);
1554 if (ctf_type != CTF_ERR)
1559 ctf_type = ctf_lookup_variable(dict, sym_name);
1562 if (ctf_type == CTF_ERR)
1565 ctf_next_t *i = NULL;
1566 const char *arcname;
1568 while ((fp = ctf_archive_next(ctfa, &i, &arcname, 1, &ctf_err)) != NULL)
1570 if ((ctf_type = ctf_lookup_by_symbol_name (fp, sym_name)) == CTF_ERR)
1571 ctf_type = ctf_lookup_variable(fp, sym_name);
1573 if (ctf_type != CTF_ERR)
1592 fill_ctf_section(
const Elf_Scn *elf_section, ctf_sect_t *ctf_section)
1594 GElf_Shdr section_header_mem, *section_header;
1595 Elf_Data *section_data;
1597 section_header = gelf_getshdr(
const_cast<Elf_Scn*
>(elf_section),
1598 §ion_header_mem);
1599 section_data = elf_getdata(
const_cast<Elf_Scn*
>(elf_section), 0);
1604 ctf_section->cts_name =
"";
1605 ctf_section->cts_data = (
char *) section_data->d_buf;
1606 ctf_section->cts_size = section_data->d_size;
1607 ctf_section->cts_entsize = section_header->sh_entsize;
1616 elf_based_reader_sptr
1618 const vector<char**>& debug_info_root_paths,
1621 reader_sptr result(
new reader(elf_path,
1622 debug_info_root_paths,
1647 const std::string& elf_path,
1648 const vector<char**>& debug_info_root_path)
1650 ctf::reader& r =
dynamic_cast<reader&
>(rdr);
1651 r.initialize(elf_path, debug_info_root_path);
1668 dic_type_key(ctf_dict_t *dic, ctf_id_t ctf_type)
1670 std::stringstream key;
1672 if (ctf_type_isparent (dic, ctf_type))
1673 key << std::hex << ctf_type;
1675 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.
virtual void reset(const std::string &elf_path, const vector< char ** > &debug_info_root_paths)
Reset (re-initialize) the resources used by the current reader.
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...
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.
bool has_scope(const decl_base &d)
Tests if a declaration has got a scope.
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.
array_type_def * is_array_type(const type_or_decl_base *type)
Test if a type is an array_type_def.
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< 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.
enum_type_decl_sptr lookup_enum_type(const interned_string &type_name, const translation_unit &tu)
Lookup an enum type from a translation unit.
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.
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 decl_base * get_type_declaration(const type_base *t)
Get the declaration for a given type.
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.