libabigail
abg-corpus.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 // -*- mode: C++ -*-
3 //
4 // Copyright (C) 2013-2023 Red Hat, Inc.
5 
6 /// @file
7 
8 #ifndef __ABG_CORPUS_H__
9 #define __ABG_CORPUS_H__
10 
11 #include <abg-ir.h>
12 
13 namespace abigail
14 {
15 
16 namespace ir
17 {
18 
19 /// This is the abstraction of a set of translation units (themselves
20 /// seen as bundles of unitary abi artefacts like types and decls)
21 /// bundled together as a corpus. A corpus is thus the Application
22 /// binary interface of a program, a library or just a set of modules
23 /// put together.
24 class corpus
25 {
26 public:
27  /// A convenience typedef for std::vector<string>.
28  typedef vector<string> strings_type;
29 
30  /// Convenience typedef for std::vector<abigail::ir::function_decl*>
31  typedef vector<function_decl*> functions;
32 
33  ///Convenience typedef for std::vector<abigail::ir::var_decl*>
34  typedef vector<var_decl*> variables;
35 
37 
38  /// Convenience typedef for shared_ptr<exported_decls_builder>.
39  typedef shared_ptr<exported_decls_builder> exported_decls_builder_sptr;
40 
41  /// This abstracts where the corpus comes from. That is, either it
42  /// has been read from the native xml format, from DWARF or built
43  /// artificially using the library's API.
44  enum origin
45  {
46  ARTIFICIAL_ORIGIN = 0,
47  NATIVE_XML_ORIGIN = 1,
48  ELF_ORIGIN = 1 << 1,
49  DWARF_ORIGIN = 1 << 2,
50  CTF_ORIGIN = 1 << 3,
51  BTF_ORIGIN = 1 << 4,
52  LINUX_KERNEL_BINARY_ORIGIN = 1 << 5
53  };
54 
55 private:
56  corpus();
57 
58  void set_group(corpus_group*);
59  void init_format_version();
60 
61 public:
62  struct priv;
63  std::unique_ptr<priv> priv_;
64 
65  corpus(const ir::environment&, const string& path= "");
66 
67  virtual ~corpus();
68 
69  const environment&
70  get_environment() const;
71 
72  bool
73  do_log() const;
74 
75  void
76  do_log(bool);
77 
78  void
79  add(const translation_unit_sptr&);
80 
81  const translation_units&
82  get_translation_units() const;
83 
85  find_translation_unit(const string &path) const;
86 
87  void
89 
90  type_maps&
91  get_types();
92 
93  const type_maps&
94  get_types() const;
95 
96  type_maps&
98 
99  const type_maps&
100  get_type_per_loc_map() const;
101 
102  virtual bool
104 
105  void
107 
108  bool
110 
111  const vector<type_base_wptr>&
113 
114  const corpus_group*
115  get_group() const;
116 
117  corpus_group*
118  get_group();
119 
120  origin
121  get_origin() const;
122 
123  void
125 
126  string&
128 
129  void
130  set_format_major_version_number(const string&);
131 
132  string&
134 
135  void
136  set_format_minor_version_number(const string&);
137 
138  string&
139  get_path() const;
140 
141  void
142  set_path(const string&);
143 
144  const vector<string>&
145  get_needed() const;
146 
147  void
148  set_needed(const vector<string>&);
149 
150  const string&
151  get_soname();
152 
153  void
154  set_soname(const string&);
155 
156  const string&
157  get_architecture_name() const;
158 
159  void
160  set_architecture_name(const string&);
161 
162  virtual bool
163  is_empty() const;
164 
165  bool
166  operator==(const corpus&) const;
167 
168  void
170 
172  get_symtab() const;
173 
174  virtual const string_elf_symbols_map_type&
175  get_fun_symbol_map() const;
176 
179 
180  virtual const elf_symbols&
181  get_sorted_fun_symbols() const;
182 
183  const elf_symbols&
185 
186  virtual const string_elf_symbols_map_type&
187  get_var_symbol_map() const;
188 
191 
192  virtual const elf_symbols&
193  get_sorted_var_symbols() const;
194 
195  const elf_symbols&
197 
198  const elf_symbol_sptr
199  lookup_function_symbol(const string& n) const;
200 
201  const elf_symbol_sptr
202  lookup_function_symbol(const string& symbol_name,
203  const elf_symbol::version& version) const;
204 
205  const elf_symbol_sptr
206  lookup_function_symbol(const elf_symbol& symbol) const;
207 
208  const elf_symbol_sptr
209  lookup_variable_symbol(const string& n) const;
210 
211  const elf_symbol_sptr
212  lookup_variable_symbol(const string& symbol_name,
213  const elf_symbol::version& version) const;
214 
215  const elf_symbol_sptr
216  lookup_variable_symbol(const elf_symbol& symbol) const;
217 
218  virtual const functions&
219  get_functions() const;
220 
221  const std::unordered_set<function_decl*>*
222  lookup_functions(const string& id) const;
223 
224  void
225  sort_functions();
226 
227  virtual const variables&
228  get_variables() const;
229 
230  void
231  sort_variables();
232 
233  virtual const elf_symbols&
235 
236  virtual const elf_symbols&
238 
239  vector<string>&
241 
242  const vector<string>&
244 
245  vector<string>&
247 
248  const vector<string>&
250 
251  vector<string>&
253 
254  const vector<string>&
256 
257  vector<string>&
259 
260  const vector<string>&
262 
263  vector<string>&
265 
266  const vector<string>&
268 
269  vector<string>&
271 
272  const vector<string>&
274 
275  void
277 
280 
281  friend class type_base;
282  friend class corpus_group;
283 };// end class corpus.
284 
287 
290 
293 
296 
297 /// Abstracts the building of the set of exported variables and
298 /// functions.
299 ///
300 /// Given a function or variable, this type can decide if it belongs
301 /// to the list of exported functions and variables based on all the
302 /// parameters needed.
304 {
305  // Forbid default construction.
307 
308 public:
309  class priv;
310  std::unique_ptr<priv> priv_;
311 
312  friend class corpus;
313 
315  variables& vars,
316  strings_type& fns_suppress_regexps,
317  strings_type& vars_suppress_regexps,
318  strings_type& fns_keep_regexps,
319  strings_type& vars_keep_regexps,
320  strings_type& sym_id_of_fns_to_keep,
321  strings_type& sym_id_of_vars_to_keep);
322 
323 
324  const functions&
325  exported_functions() const;
326 
327  functions&
329 
330  std::unordered_set<function_decl*>*
332 
333  const variables&
334  exported_variables() const;
335 
336  variables&
338 
339  void
341 
342  void
344 }; //corpus::exported_decls_builder
345 
346 /// Abstraction of a group of corpora.
347 ///
348 /// A corpus group is a union of corpora. It provides a unified view
349 /// of a set of corpora. It lets you get the set of functions,
350 /// variables and symbols that are defined and exported by a set of
351 /// corpora.
352 class corpus_group : public corpus
353 {
354  struct priv;
355  std::unique_ptr<priv> priv_;
356 
357  // Forbid copy
358  corpus_group(const corpus_group&);
359 
360 public:
361  typedef vector<corpus_sptr> corpora_type;
362 
363  corpus_group(const ir::environment&, const string&);
364 
365  virtual ~corpus_group();
366 
367  void add_corpus(const corpus_sptr&);
368 
369  const corpora_type&
370  get_corpora() const;
371 
372  const corpus_sptr
373  get_main_corpus() const;
374 
375  corpus_sptr
376  get_main_corpus();
377 
378  virtual bool
379  is_empty() const;
380 
381  virtual const corpus::functions&
382  get_functions() const;
383 
384  virtual const corpus::variables&
385  get_variables() const;
386 
387  virtual const string_elf_symbols_map_type&
388  get_var_symbol_map() const;
389 
390  virtual const string_elf_symbols_map_type&
391  get_fun_symbol_map() const;
392 
393  virtual const elf_symbols&
394  get_sorted_fun_symbols() const;
395 
396  virtual const elf_symbols&
397  get_sorted_var_symbols() const;
398 
399  virtual const elf_symbols&
401 
402  virtual const elf_symbols&
404 
405  unordered_set<interned_string, hash_interned_string>*
407 
408  virtual bool
410 
411  bool
412  operator==(const corpus_group&) const;
413 }; // end class corpus_group
414 
415 }// end namespace ir
416 }//end namespace abigail
417 #endif //__ABG_CORPUS_H__
std::shared_ptr< symtab > symtab_sptr
Convenience typedef for a shared pointer to a symtab.
Definition: abg-fwd.h:1540
Types of the main internal representation of libabigail.
The type of the private data of corpus::exported_decls_builder type.
Abstracts the building of the set of exported variables and functions.
Definition: abg-corpus.h:304
const functions & exported_functions() const
Getter for the reference to the vector of exported functions. This vector is shared with with the cor...
Definition: abg-corpus.cc:100
void maybe_add_fn_to_exported_fns(function_decl *)
Consider at all the tunables that control wether a function should be added to the set of exported fu...
Definition: abg-corpus.cc:158
std::unordered_set< function_decl * > * fn_id_maps_to_several_fns(function_decl *)
Test if a given function ID maps to several functions in the same corpus.
Definition: abg-corpus.cc:124
void maybe_add_var_to_exported_vars(const var_decl *)
Consider at all the tunables that control wether a variable should be added to the set of exported va...
Definition: abg-corpus.cc:181
const variables & exported_variables() const
Getter for the reference to the vector of exported variables. This vector is shared with with the cor...
Definition: abg-corpus.cc:140
Abstraction of a group of corpora.
Definition: abg-corpus.h:353
virtual const elf_symbols & get_sorted_var_symbols() const
Get a sorted vector of the symbols of the variables exported by the corpora of the current group.
Definition: abg-corpus.cc:1949
const corpora_type & get_corpora() const
Getter of the vector of corpora held by the current corpus_group.
Definition: abg-corpus.cc:1773
unordered_set< interned_string, hash_interned_string > * get_public_types_pretty_representations()
Getter of a pointer to the set of types reachable from public interfaces of a given corpus group.
Definition: abg-corpus.cc:2065
virtual const string_elf_symbols_map_type & get_var_symbol_map() const
Get the symbols of the global variables exported by the corpora of the current corpus_group.
Definition: abg-corpus.cc:1883
virtual const elf_symbols & get_sorted_fun_symbols() const
Get a sorted vector of the symbols of the functions exported by the corpora of the current group.
Definition: abg-corpus.cc:1917
virtual bool is_empty() const
Test if the current corpus group is empty.
Definition: abg-corpus.cc:1798
virtual const string_elf_symbols_map_type & get_fun_symbol_map() const
Get the symbols of the global functions exported by the corpora of the current corpus_group.
Definition: abg-corpus.cc:1900
const corpus_sptr get_main_corpus() const
Getter of the first corpus added to this Group.
Definition: abg-corpus.cc:1780
virtual const elf_symbols & get_unreferenced_function_symbols() const
Get the set of function symbols not referenced by any debug info, from all the corpora of the current...
Definition: abg-corpus.cc:1988
virtual const elf_symbols & get_unreferenced_variable_symbols() const
Get the set of variable symbols not referenced by any debug info, from all the corpora of the current...
Definition: abg-corpus.cc:2031
virtual bool recording_types_reachable_from_public_interface_supported()
Test if the recording of reachable types (and thus, indirectly, the recording of non-reachable types)...
Definition: abg-corpus.cc:2075
virtual const corpus::variables & get_variables() const
Get the global variables exported by the corpora of the current corpus group.
Definition: abg-corpus.cc:1849
virtual ~corpus_group()
Desctructor of the corpus_group type.
Definition: abg-corpus.cc:1734
void add_corpus(const corpus_sptr &)
Add a new corpus to the current instance of corpus_group.
Definition: abg-corpus.cc:1741
virtual const corpus::functions & get_functions() const
Get the functions exported by the corpora of the current corpus group.
Definition: abg-corpus.cc:1811
This is the abstraction of a set of translation units (themselves seen as bundles of unitary abi arte...
Definition: abg-corpus.h:25
virtual const elf_symbols & get_sorted_var_symbols() const
Getter for the sorted vector of variable symbols for this corpus.
Definition: abg-corpus.cc:1131
const elf_symbol_sptr lookup_function_symbol(const string &n) const
Look in the function symbols map for a symbol with a given name.
Definition: abg-corpus.cc:1166
origin
This abstracts where the corpus comes from. That is, either it has been read from the native xml form...
Definition: abg-corpus.h:45
void sort_functions()
Sort the set of functions exported by this corpus.
Definition: abg-corpus.cc:1354
void set_soname(const string &)
Setter for the soname property of the corpus.
Definition: abg-corpus.cc:995
const std::unordered_set< function_decl * > * lookup_functions(const string &id) const
Lookup the function which has a given function ID.
Definition: abg-corpus.cc:1340
const vector< type_base_wptr > & get_types_not_reachable_from_public_interfaces() const
Getter of a sorted vector of the types that are *NOT* reachable from public interfaces.
Definition: abg-corpus.cc:812
void record_type_as_reachable_from_public_interfaces(const type_base &)
Record a type as being reachable from public interfaces (global functions and variables).
Definition: abg-corpus.cc:774
const vector< string > & get_needed() const
Getter of the needed property of the corpus.
Definition: abg-corpus.cc:961
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...
Definition: abg-corpus.cc:1577
void maybe_drop_some_exported_decls()
After the set of exported functions and variables have been built, consider all the tunables that con...
Definition: abg-corpus.cc:1536
const string_elf_symbols_map_type & get_undefined_var_symbol_map() const
Getter for the map of variable symbols that are undefined in this corpus.
Definition: abg-corpus.cc:1157
void add(const translation_unit_sptr &)
Add a translation unit to the current ABI Corpus.
Definition: abg-corpus.cc:680
virtual const string_elf_symbols_map_type & get_var_symbol_map() const
Getter for the variable symbols map.
Definition: abg-corpus.cc:1147
shared_ptr< exported_decls_builder > exported_decls_builder_sptr
Convenience typedef for shared_ptr<exported_decls_builder>.
Definition: abg-corpus.h:36
const elf_symbol_sptr lookup_variable_symbol(const string &n) const
Look in the variable symbols map for a symbol with a given name.
Definition: abg-corpus.cc:1262
virtual const elf_symbols & get_sorted_fun_symbols() const
Return a sorted vector of function symbols for this corpus.
Definition: abg-corpus.cc:1111
const string & get_soname()
Getter for the soname property of the corpus.
Definition: abg-corpus.cc:984
const translation_units & get_translation_units() const
Return the list of translation units of the current corpus.
Definition: abg-corpus.cc:700
const symtab_reader::symtab_sptr & get_symtab() const
Getter for the symtab object.
Definition: abg-corpus.cc:1083
origin get_origin() const
Getter for the origin of the corpus.
Definition: abg-corpus.cc:885
virtual bool is_empty() const
Tests if the corpus is empty from an ABI surface perspective. I.e. if all of these criteria are true:
Definition: abg-corpus.cc:1030
type_maps & get_types()
Get the maps that associate a name to a certain kind of type.
Definition: abg-corpus.cc:732
vector< string > & get_sym_ids_of_vars_to_keep()
Getter for the vector of variable symbol IDs to keep.
Definition: abg-corpus.cc:1519
bool do_log() const
Test if logging was requested.
Definition: abg-corpus.cc:662
const translation_unit_sptr find_translation_unit(const string &path) const
Find the translation unit that has a given path.
Definition: abg-corpus.cc:710
const elf_symbols & get_sorted_undefined_fun_symbols() const
Getter for a sorted vector of the function symbols undefined in this corpus.
Definition: abg-corpus.cc:1120
vector< var_decl * > variables
Convenience typedef for std::vector<abigail::ir::var_decl*>
Definition: abg-corpus.h:34
string & get_path() const
Get the file path associated to the corpus file.
Definition: abg-corpus.cc:938
const string_elf_symbols_map_type & get_undefined_fun_symbol_map() const
Getter for the map of function symbols that are undefined in this corpus.
Definition: abg-corpus.cc:1100
void set_origin(origin)
Setter for the origin of the corpus.
Definition: abg-corpus.cc:892
virtual const string_elf_symbols_map_type & get_fun_symbol_map() const
Getter for the function symbols map.
Definition: abg-corpus.cc:1090
bool operator==(const corpus &) const
Compare the current corpus against another one.
Definition: abg-corpus.cc:1057
type_maps & get_type_per_loc_map()
Get the maps that associate a location string to a certain kind of type.
Definition: abg-corpus.cc:841
void drop_translation_units()
Erase the translation units contained in this in-memory object.
Definition: abg-corpus.cc:725
void sort_variables()
Sort the set of variables exported by this corpus.
Definition: abg-corpus.cc:1384
vector< string > & get_regex_patterns_of_vars_to_keep()
Accessor for the regex patterns describing the variables to keep into the public decl table....
Definition: abg-corpus.cc:1499
vector< string > & get_regex_patterns_of_vars_to_suppress()
Accessor for the regex patterns describing the variables to drop from the public decl table.
Definition: abg-corpus.cc:1440
const corpus_group * get_group() const
Getter of the group this corpus is a member of.
Definition: abg-corpus.cc:849
vector< string > & get_regex_patterns_of_fns_to_suppress()
Accessor for the regex patterns describing the functions to drop from the public decl table.
Definition: abg-corpus.cc:1422
virtual const elf_symbols & get_unreferenced_function_symbols() const
Getter of the set of function symbols that are not referenced by any function exported by the current...
Definition: abg-corpus.cc:1400
void set_path(const string &)
Set the file path associated to the corpus file.
Definition: abg-corpus.cc:950
virtual const elf_symbols & get_unreferenced_variable_symbols() const
Getter of the set of variable symbols that are not referenced by any variable exported by the current...
Definition: abg-corpus.cc:1413
bool type_is_reachable_from_public_interfaces(const type_base &) const
Test if a type is reachable from public interfaces (global functions and variables).
Definition: abg-corpus.cc:792
virtual bool recording_types_reachable_from_public_interface_supported()
Test if the recording of reachable types (and thus, indirectly, the recording of non-reachable types)...
Definition: abg-corpus.cc:763
virtual const variables & get_variables() const
Return the public decl table of the global variables of the current corpus.
Definition: abg-corpus.cc:1376
const elf_symbols & get_sorted_undefined_var_symbols() const
Getter for a sorted vector of the variable symbols undefined in this corpus.
Definition: abg-corpus.cc:1140
void set_needed(const vector< string > &)
Setter of the needed property of the corpus.
Definition: abg-corpus.cc:973
vector< string > & get_sym_ids_of_fns_to_keep()
Getter for the vector of function symbol IDs to keep.
Definition: abg-corpus.cc:1479
vector< function_decl * > functions
Convenience typedef for std::vector<abigail::ir::function_decl*>
Definition: abg-corpus.h:31
void set_architecture_name(const string &)
Setter for the architecture name of the corpus.
Definition: abg-corpus.cc:1017
void set_symtab(symtab_reader::symtab_sptr)
Setter for the symtab object.
Definition: abg-corpus.cc:1076
void set_format_major_version_number(const string &)
Setter of the major version number of the abixml serialization format.
Definition: abg-corpus.cc:908
const string & get_architecture_name() const
Getter for the architecture name of the corpus.
Definition: abg-corpus.cc:1006
vector< string > strings_type
A convenience typedef for std::vector<string>.
Definition: abg-corpus.h:28
const environment & get_environment() const
Getter of the enviroment of the corpus.
Definition: abg-corpus.cc:655
vector< string > & get_regex_patterns_of_fns_to_keep()
Accessor for the regex patterns describing the functions to keep into the public decl table....
Definition: abg-corpus.cc:1459
void set_format_minor_version_number(const string &)
Setter of the minor version number of the abixml serialization format.
Definition: abg-corpus.cc:926
string & get_format_minor_version_number() const
Getter of the minor version number of the abixml serialization format.
Definition: abg-corpus.cc:917
virtual const functions & get_functions() const
Return the functions public decl table of the current corpus.
Definition: abg-corpus.cc:1322
string & get_format_major_version_number() const
Getter of the major version number of the abixml serialization format.
Definition: abg-corpus.cc:900
The abstraction of the version of an ELF symbol.
Definition: abg-ir.h:1171
Abstraction of an elf symbol.
Definition: abg-ir.h:900
This is an abstraction of the set of resources necessary to manage several aspects of the internal re...
Definition: abg-ir.h:140
Abstraction for a function declaration.
Definition: abg-ir.h:3024
An abstraction helper for type declarations.
Definition: abg-ir.h:1951
This is a type that aggregates maps of all the kinds of types that are supported by libabigail.
Definition: abg-ir.h:576
Abstracts a variable declaration.
Definition: abg-ir.h:2921
corpus::origin operator|=(corpus::origin &l, corpus::origin r)
Bitwise |= operator for the corpus::origin type.
Definition: abg-corpus.cc:1616
shared_ptr< elf_symbol > elf_symbol_sptr
A convenience typedef for a shared pointer to elf_symbol.
Definition: abg-ir.h:863
std::vector< elf_symbol_sptr > elf_symbols
Convenience typedef for a vector of elf_symbol.
Definition: abg-ir.h:881
corpus::origin operator|(corpus::origin l, corpus::origin r)
Bitwise | operator for the corpus::origin type.
Definition: abg-corpus.cc:1602
corpus::origin operator&(corpus::origin l, corpus::origin r)
Bitwise & operator for the corpus::origin type.
Definition: abg-corpus.cc:1630
shared_ptr< translation_unit > translation_unit_sptr
Convenience typedef for a shared pointer on a translation_unit type.
Definition: abg-fwd.h:134
std::set< translation_unit_sptr, shared_translation_unit_comp > translation_units
Convenience typedef for an ordered set of translation_unit_sptr.
Definition: abg-ir.h:828
corpus::origin operator&=(corpus::origin &l, corpus::origin r)
Bitwise &= operator for the corpus::origin type.
Definition: abg-corpus.cc:1644
std::unordered_map< string, elf_symbols > string_elf_symbols_map_type
Convenience typedef for a map which key is a string and which value is a vector of elf_symbol.
Definition: abg-ir.h:886
Toplevel namespace for libabigail.
bool operator==(const std::string &l, const interned_string &r)
Equality operator.
Definition: abg-ir.cc:152