1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- mode: C++ -*-
//
// Copyright (C) 2013-2025 Red Hat, Inc.
/// @file
#ifndef __ABG_CORPUS_H__
#define __ABG_CORPUS_H__
#include <abg-ir.h>
namespace abigail
{
namespace ir
{
/// This is the abstraction of a set of translation units (themselves
/// seen as bundles of unitary abi artefacts like types and decls)
/// bundled together as a corpus. A corpus is thus the Application
/// binary interface of a program, a library or just a set of modules
/// put together.
class corpus
{
public:
/// A convenience typedef for std::vector<string>.
typedef vector<string> strings_type;
/// Convenience typedef for std::vector<abigail::ir::function_decl*>
typedef vector<const function_decl*> functions;
/// Convenience typedef for std::unordered_set<const function_decl*>
typedef std::unordered_set<const function_decl*> functions_set;
///Convenience typedef for std::vector<abigail::ir::var_decl*>
typedef vector<var_decl_sptr> variables;
/// Convenience typedef for std::unordered_set<const var_decl*>.
typedef std::unordered_set<var_decl_sptr> variables_set;
class exported_decls_builder;
/// Convenience typedef for shared_ptr<exported_decls_builder>.
typedef shared_ptr<exported_decls_builder> exported_decls_builder_sptr;
/// This abstracts where the corpus comes from. That is, either it
/// has been read from the native xml format, from DWARF or built
/// artificially using the library's API.
enum origin
{
ARTIFICIAL_ORIGIN = 0,
NATIVE_XML_ORIGIN = 1,
ELF_ORIGIN = 1 << 1,
DWARF_ORIGIN = 1 << 2,
CTF_ORIGIN = 1 << 3,
BTF_ORIGIN = 1 << 4,
LINUX_KERNEL_BINARY_ORIGIN = 1 << 5
};
private:
corpus();
void set_group(corpus_group*);
void init_format_version();
public:
struct priv;
std::unique_ptr<priv> priv_;
corpus(const ir::environment&, const string& path= "");
virtual ~corpus();
const environment&
get_environment() const;
bool
do_log() const;
void
do_log(bool);
void
add(const translation_unit_sptr&);
const translation_units&
get_translation_units() const;
const translation_unit_sptr
find_translation_unit(const string &path) const;
void
drop_translation_units();
type_maps&
get_types();
const type_maps&
get_types() const;
type_maps&
get_type_per_loc_map();
const type_maps&
get_type_per_loc_map() const;
virtual bool
recording_types_reachable_from_public_interface_supported();
void
record_type_as_reachable_from_public_interfaces(const type_base&);
bool
type_is_reachable_from_public_interfaces(const type_base&) const;
const vector<type_base_wptr>&
get_types_not_reachable_from_public_interfaces() const;
const corpus_group*
get_group() const;
corpus_group*
get_group();
origin
get_origin() const;
void
set_origin(origin);
string&
get_format_major_version_number() const;
void
set_format_major_version_number(const string&);
string&
get_format_minor_version_number() const;
void
set_format_minor_version_number(const string&);
string&
get_path() const;
void
set_path(const string&);
const vector<string>&
get_needed() const;
void
set_needed(const vector<string>&);
const string&
get_soname();
void
set_soname(const string&);
const string&
get_architecture_name() const;
void
set_architecture_name(const string&);
virtual bool
is_empty() const;
bool
operator==(const corpus&) const;
void
set_symtab(symtab_reader::symtab_sptr);
const symtab_reader::symtab_sptr&
get_symtab() const;
virtual const string_elf_symbols_map_type&
get_fun_symbol_map() const;
const string_elf_symbols_map_type&
get_undefined_fun_symbol_map() const;
virtual const elf_symbols&
get_sorted_fun_symbols() const;
const elf_symbols&
get_sorted_undefined_fun_symbols() const;
virtual const string_elf_symbols_map_type&
get_var_symbol_map() const;
const string_elf_symbols_map_type&
get_undefined_var_symbol_map() const;
virtual const elf_symbols&
get_sorted_var_symbols() const;
const elf_symbols&
get_sorted_undefined_var_symbols() const;
const elf_symbol_sptr
lookup_function_symbol(const string& n) const;
const elf_symbol_sptr
lookup_function_symbol(const string& symbol_name,
const elf_symbol::version& version) const;
const elf_symbol_sptr
lookup_function_symbol(const elf_symbol& symbol) const;
const elf_symbol_sptr
lookup_variable_symbol(const string& n) const;
const elf_symbol_sptr
lookup_variable_symbol(const string& symbol_name,
const elf_symbol::version& version) const;
const elf_symbol_sptr
lookup_variable_symbol(const elf_symbol& symbol) const;
virtual const functions&
get_functions() const;
virtual const std::unordered_set<function_decl*>*
lookup_functions(const interned_string& id) const;
virtual const std::unordered_set<function_decl*>*
lookup_functions(const char* id) const;
virtual const std::unordered_set<var_decl_sptr>*
lookup_variables(const interned_string& id) const;
virtual const std::unordered_set<var_decl_sptr>*
lookup_variables(const char* id) const;
void
sort_functions();
virtual const variables&
get_variables() const;
const functions_set&
get_undefined_functions() const;
functions_set&
get_undefined_functions();
const functions&
get_sorted_undefined_functions() const;
const variables_set&
get_undefined_variables() const;
variables_set&
get_undefined_variables();
const variables&
get_sorted_undefined_variables() const;
void
sort_variables();
virtual const elf_symbols&
get_unreferenced_function_symbols() const;
virtual const elf_symbols&
get_unreferenced_variable_symbols() const;
vector<string>&
get_regex_patterns_of_fns_to_suppress();
const vector<string>&
get_regex_patterns_of_fns_to_suppress() const;
vector<string>&
get_regex_patterns_of_vars_to_suppress();
const vector<string>&
get_regex_patterns_of_vars_to_suppress() const;
vector<string>&
get_regex_patterns_of_fns_to_keep();
const vector<string>&
get_regex_patterns_of_fns_to_keep() const;
vector<string>&
get_sym_ids_of_fns_to_keep();
const vector<string>&
get_sym_ids_of_fns_to_keep() const;
vector<string>&
get_regex_patterns_of_vars_to_keep();
const vector<string>&
get_regex_patterns_of_vars_to_keep() const;
vector<string>&
get_sym_ids_of_vars_to_keep();
const vector<string>&
get_sym_ids_of_vars_to_keep() const;
void
maybe_drop_some_exported_decls();
exported_decls_builder_sptr
get_exported_decls_builder() const;
friend class type_base;
friend class corpus_group;
};// end class corpus.
corpus::origin
operator|(corpus::origin l, corpus::origin r);
corpus::origin
operator|=(corpus::origin &l, corpus::origin r);
corpus::origin
operator&(corpus::origin l, corpus::origin r);
corpus::origin
operator&=(corpus::origin &l, corpus::origin r);
/// Abstracts the building of the set of exported variables and
/// functions.
///
/// Given a function or variable, this type can decide if it belongs
/// to the list of exported functions and variables based on all the
/// parameters needed.
class corpus::exported_decls_builder
{
// Forbid default construction.
exported_decls_builder();
public:
class priv;
std::unique_ptr<priv> priv_;
friend class corpus;
exported_decls_builder(functions& fns,
variables& vars,
strings_type& fns_suppress_regexps,
strings_type& vars_suppress_regexps,
strings_type& fns_keep_regexps,
strings_type& vars_keep_regexps,
strings_type& sym_id_of_fns_to_keep,
strings_type& sym_id_of_vars_to_keep);
const functions&
exported_functions() const;
functions&
exported_functions();
std::unordered_set<function_decl*>*
fn_id_maps_to_several_fns(const function_decl*);
const variables&
exported_variables() const;
variables&
exported_variables();
bool
maybe_add_fn_to_exported_fns(function_decl*);
bool
maybe_add_var_to_exported_vars(const var_decl_sptr&);
}; //corpus::exported_decls_builder
/// Abstraction of a group of corpora.
///
/// A corpus group is a union of corpora. It provides a unified view
/// of a set of corpora. It lets you get the set of functions,
/// variables and symbols that are defined and exported by a set of
/// corpora.
class corpus_group : public corpus
{
struct priv;
std::unique_ptr<priv> priv_;
// Forbid copy
corpus_group(const corpus_group&);
public:
typedef vector<corpus_sptr> corpora_type;
corpus_group(const ir::environment&, const string&);
virtual ~corpus_group();
void add_corpus(const corpus_sptr&);
bool has_corpus(const string&);
const corpora_type&
get_corpora() const;
const corpus_sptr
get_main_corpus() const;
corpus_sptr
get_main_corpus();
virtual bool
is_empty() const;
virtual const corpus::functions&
get_functions() const;
virtual const corpus::variables&
get_variables() const;
virtual const string_elf_symbols_map_type&
get_var_symbol_map() const;
virtual const string_elf_symbols_map_type&
get_fun_symbol_map() const;
virtual const elf_symbols&
get_sorted_fun_symbols() const;
virtual const elf_symbols&
get_sorted_var_symbols() const;
virtual const elf_symbols&
get_unreferenced_function_symbols() const;
virtual const elf_symbols&
get_unreferenced_variable_symbols() const;
unordered_set<interned_string, hash_interned_string>*
get_public_types_pretty_representations();
virtual bool
recording_types_reachable_from_public_interface_supported();
bool
operator==(const corpus_group&) const;
virtual const std::unordered_set<function_decl*>*
lookup_functions(const interned_string& id) const;
virtual const std::unordered_set<function_decl*>*
lookup_functions(const char* id) const;
virtual const std::unordered_set<var_decl_sptr>*
lookup_variables(const interned_string& id) const;
virtual const std::unordered_set<var_decl_sptr>*
lookup_variables(const char* id) const;
}; // end class corpus_group
corpus_group_sptr
is_corpus_group(const corpus_sptr&);
}// end namespace ir
}//end namespace abigail
#endif //__ABG_CORPUS_H__
|