libabigail
abg-reporter-priv.h
1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 // -*- Mode: C++ -*-
3 //
4 // Copyright (C) 2013-2023 Red Hat, Inc.
5 //
6 // Author: Dodji Seketeli
7 
8 #ifndef __ABG_REPORTER_PRIV_H__
9 #define __ABG_REPORTER_PRIV_H__
10 
11 #include "abg-comparison.h"
12 #include "abg-reporter.h"
13 
14 /// This is a subroutine of a *::report() function.
15 ///
16 /// If the diff about two subjects S1 and S2 was reported earlier or
17 /// is being reported, emit a diagnostic message about this and return
18 /// from the current diff reporting function.
19 ///
20 /// @param S1 the first diff subject to take in account.
21 ///
22 /// @param S2 the second diff subject to take in account.
23 #define RETURN_IF_BEING_REPORTED_OR_WAS_REPORTED_EARLIER(S1, S2) \
24  do { \
25  if (diff_context_sptr ctxt = d.context()) \
26  if (diff_sptr _diff_ = ctxt->get_canonical_diff_for(S1, S2)) \
27  if (_diff_->currently_reporting() || _diff_->reported_once()) \
28  { \
29  if (_diff_->currently_reporting()) \
30  out << indent << "details are being reported\n"; \
31  else \
32  out << indent << "details were reported earlier\n"; \
33  return; \
34  } \
35  } while (false)
36 
37 /// This is a subroutine of a *::report() function.
38 ///
39 /// If a given diff was reported earlier or is being reported, emit a
40 /// diagnostic message about this and return from the current diff
41 /// reporting function.
42 ///
43 /// @param S1 the first diff subject to take in account.
44 ///
45 /// @param S2 the second diff subject to take in account.
46 ///
47 /// @param INTRO_TEXT the introductory text that precedes the
48 /// diagnostic.
49 #define RETURN_IF_BEING_REPORTED_OR_WAS_REPORTED_EARLIER2(D, INTRO_TEXT) \
50  do { \
51  if (diff_sptr _diff_ = d.context()->get_canonical_diff_for(D)) \
52  if (_diff_->currently_reporting() || _diff_->reported_once()) \
53  { \
54  string _name_ = _diff_->first_subject()->get_pretty_representation(); \
55  if (_diff_->currently_reporting()) \
56  out << indent << INTRO_TEXT << " '" << _name_ \
57  << "' changed, as being reported\n"; \
58  else \
59  { \
60  out << indent << INTRO_TEXT << " '" \
61  << _name_ << "' changed"; \
62  report_loc_info(D->first_subject(), *d.context(), out); \
63  out << ", as reported earlier\n"; \
64  } \
65  return ; \
66  } \
67  } while (false)
68 
69 /// This is a subroutine of a *::report() function.
70 ///
71 /// If the diff about two subjects S1 and S2 was reported earlier or
72 /// is being reported, emit a diagnostic message about this and return
73 /// from the current diff reporting function.
74 ///
75 ///
76 /// @param INTRO_TEXT the introductory text that precedes the
77 /// diagnostic.
78 #define RETURN_IF_BEING_REPORTED_OR_WAS_REPORTED_EARLIER3(S1, S2, INTRO_TEXT) \
79  do { \
80  if (diff_sptr _diff_ = d.context()->get_canonical_diff_for(S1, S2)) \
81  if (_diff_->currently_reporting() || _diff_->reported_once()) \
82  { \
83  string _name_ = _diff_->first_subject()->get_pretty_representation(); \
84  if (_diff_->currently_reporting()) \
85  out << indent << INTRO_TEXT << " '" << _name_ << "' changed; " \
86  "details are being reported\n"; \
87  else \
88  { \
89  out << indent << INTRO_TEXT << " '" << _name_ << "' changed"; \
90  report_loc_info(S1, *d.context(), out); \
91  out << ", as reported earlier\n"; \
92  } \
93  return ; \
94  } \
95  } while (false)
96 
97 namespace abigail
98 {
99 
100 namespace comparison
101 {
102 
103 uint64_t
104 convert_bits_to_bytes(size_t bits);
105 
106 uint64_t
107 maybe_convert_bits_to_bytes(uint64_t bits, const diff_context& ctxt);
108 
109 void
110 emit_num_value(uint64_t value, const diff_context& ctxt, ostream& out);
111 
112 void
113 show_offset_or_size(const string& what,
114  uint64_t value,
115  const diff_context& ctxt,
116  ostream& out);
117 
118 void
119 show_offset_or_size(uint64_t value,
120  const diff_context& ctxt,
121  ostream& out);
122 
123 void
124 show_numerical_change(const string& what,
125  uint64_t old_bits,
126  uint64_t new_bits,
127  const diff_context& ctxt,
128  ostream& out,
129  bool show_bits_or_bytes = true);
130 
131 void
132 represent(const diff_context& ctxt,
133  method_decl_sptr mem_fn,
134  ostream& out);
135 
136 void
138  const diff_context_sptr& ctxt,
139  ostream& out,
140  const string& indent);
141 
142 void
144  diff_context& ctxt,
145  ostream& out);
146 
147 void
149  diff_context& ctxt,
150  ostream& out);
151 
152 void
153 represent(const var_diff_sptr &diff,
154  diff_context_sptr ctxt,
155  ostream& out,
156  const string& indent = "",
157  bool local_only = false);
158 
159 void
160 represent(const subrange_diff& diff,
161  const diff_context_sptr ctxt,
162  ostream& out,
163  const string& indent = "",
164  bool local_only = false);
165 
166 void
168  type_or_decl_base_sptr second,
169  diff_context_sptr ctxt,
170  ostream& out,
171  const string& indent);
172 
173 bool
175  const diff_context& ctxt,
176  ostream &out);
177 
178 void
179 report_name_size_and_alignment_changes(decl_base_sptr first,
180  decl_base_sptr second,
181  diff_context_sptr ctxt,
182  ostream& out,
183  const string& indent);
184 
185 /// Represent the kind of difference we want report_mem_header() to
186 /// report.
188 {
189  del_kind,
190  ins_kind,
191  subtype_change_kind,
193 };
194 
195 void
196 report_mem_header(ostream& out,
197  diff_kind k,
198  const string& section_name,
199  const string& indent);
200 
201 void
202 report_mem_header(ostream& out,
203  size_t number,
204  size_t num_filtered,
205  diff_kind k,
206  const string& section_name,
207  const string& indent);
208 
209 bool
210 maybe_report_diff_for_member(const decl_base_sptr& decl1,
211  const decl_base_sptr& decl2,
212  const diff_context_sptr& ctxt,
213  ostream& out,
214  const string& indent);
215 
216 bool
217 maybe_report_diff_for_variable(const decl_base_sptr& decl1,
218  const decl_base_sptr& decl2,
219  const diff_context_sptr& ctxt,
220  ostream& out,
221  const string& indent);
222 
223 void
225  const elf_symbol_sptr& symbol2,
226  const diff_context_sptr& ctxt,
227  ostream& out,
228  const string& indent);
229 
230 void
231 show_linkage_name_and_aliases(ostream& out,
232  const string& indent,
233  const elf_symbol& symbol,
234  const string_elf_symbols_map_type& sym_map);
235 
236 void
238  const corpus_diff::diff_stats &s,
239  const string& indent,
240  ostream& out);
241 
242 void
244  ostream &out,
245  const string &indent);
246 
247 void
249  ostream &out,
250  const string &indent);
251 
252 void
254  ostream &out,
255  const string &indent);
256 
257 void
259  ostream &out,
260  const string &indent);
261 } // end namespace comparison
262 } // end namespace abigail
263 
264 #endif // __ABG_REPORTER_PRIV_H__
The declaration of the reporting types of libabigail's diff engine.
This type abstracts changes for a class_decl.
This is the base class of class_diff and union_diff.
This is a document class that aims to capture statistics about the changes carried by a corpus_diff t...
An abstraction of a diff between between two abi corpus.
The abstraction of a change between two ABI artifacts, a.k.a an artifact change.
Abstraction of an elf symbol.
Definition: abg-ir.h:923
shared_ptr< diff > diff_sptr
Convenience typedef for a shared_ptr for the diff class.
Definition: abg-fwd.h:76
void show_linkage_name_and_aliases(ostream &out, const string &indent, const elf_symbol &symbol, const string_elf_symbols_map_type &sym_map)
For a given symbol, emit a string made of its name and version. The string also contains the list of ...
void maybe_report_interfaces_impacted_by_diff(const diff *d, ostream &out, const string &indent)
If a given diff node impacts some public interfaces, then report about those impacted interfaces on a...
void maybe_report_diff_for_symbol(const elf_symbol_sptr &symbol1, const elf_symbol_sptr &symbol2, const diff_context_sptr &ctxt, ostream &out, const string &indent)
Report the difference between two ELF symbols, if there is any.
void maybe_show_relative_offset_change(const var_diff_sptr &diff, diff_context &ctxt, ostream &out)
If a given var_diff node carries a data member change in which the offset of the data member actually...
uint64_t convert_bits_to_bytes(size_t bits)
Convert a number in bits into a number in bytes.
void maybe_report_unreachable_type_changes(const corpus_diff &d, const corpus_diff::diff_stats &s, const string &indent, ostream &out)
Report changes about types that are not reachable from global functions and variables,...
shared_ptr< diff_context > diff_context_sptr
Convenience typedef for a shared pointer of diff_context.
Definition: abg-fwd.h:68
void report_size_and_alignment_changes(type_or_decl_base_sptr first, type_or_decl_base_sptr second, diff_context_sptr ctxt, ostream &out, const string &indent)
Report the size and alignment changes of a type.
bool report_loc_info(const type_or_decl_base_sptr &tod, const diff_context &ctxt, ostream &out)
shared_ptr< var_diff > var_diff_sptr
Convenience typedef for a shared pointer to a var_diff type.
void show_numerical_change(const string &what, uint64_t old_bits, uint64_t new_bits, const diff_context &ctxt, ostream &out, bool show_bits_or_byte)
Emit a message showing the numerical change between two values, to a given output stream.
bool maybe_report_diff_for_variable(const decl_base_sptr &decl1, const decl_base_sptr &decl2, const diff_context_sptr &ctxt, ostream &out, const string &indent)
Report the differences between two generic variables.
void maybe_report_base_class_reordering(const class_diff &d, ostream &out, const string &indent)
Report about the base classes of a class having been re-ordered.
void represent_data_member(var_decl_sptr d, const diff_context_sptr &ctxt, ostream &out, const string &indent)
Stream a string representation for a data member.
void maybe_show_relative_size_change(const var_diff_sptr &diff, diff_context &ctxt, ostream &out)
If a given var_diff node carries a hange in which the size of the variable actually changed,...
diff_kind
Represent the kind of difference we want report_mem_header() to report.
void maybe_report_data_members_replaced_by_anon_dm(const class_or_union_diff &d, ostream &out, const string &indent)
Report about data members replaced by an anonymous data member without changing the overall bit-layou...
bool maybe_report_diff_for_member(const decl_base_sptr &decl1, const decl_base_sptr &decl2, const diff_context_sptr &ctxt, ostream &out, const string &indent)
Report the differences in access specifiers and static-ness for class members.
void report_mem_header(ostream &out, size_t number, size_t num_filtered, diff_kind k, const string &section_name, const string &indent)
Output the header preceding the the report for insertion/deletion/change of a part of a class....
void show_offset_or_size(const string &what, uint64_t value, const diff_context &ctxt, ostream &out)
Emit a message showing the value of a numerical value representing a size or an offset,...
void emit_num_value(uint64_t value, const diff_context &ctxt, ostream &out)
Emit a numerical value to an output stream.
void report_name_size_and_alignment_changes(decl_base_sptr first, decl_base_sptr second, diff_context_sptr ctxt, ostream &out, const string &indent)
Report the name, size and alignment changes of a type.
void represent(const diff_context &ctxt, method_decl_sptr mem_fn, ostream &out)
Stream a string representation for a member function.
uint64_t maybe_convert_bits_to_bytes(uint64_t bits, const diff_context &ctxt)
Convert a bits value into a byte value if the current diff context instructs us to do so.
shared_ptr< elf_symbol > elf_symbol_sptr
A convenience typedef for a shared pointer to elf_symbol.
Definition: abg-ir.h:886
change_kind
A bitfield that gives callers of abigail::ir::equals() some insight about how different two internal ...
Definition: abg-ir.h:1323
shared_ptr< var_decl > var_decl_sptr
Convenience typedef for a shared pointer on a var_decl.
Definition: abg-fwd.h:254
shared_ptr< type_or_decl_base > type_or_decl_base_sptr
A convenience typedef for a shared_ptr to type_or_decl_base.
Definition: abg-fwd.h:119
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:909
Toplevel namespace for libabigail.