* [PATCH, applied] ir: Add a debug_comp_stack debugging function
@ 2022-12-19 16:22 Dodji Seketeli
0 siblings, 0 replies; only message in thread
From: Dodji Seketeli @ 2022-12-19 16:22 UTC (permalink / raw)
To: libabigail
Hello,
When debugging type comparison, it can useful to see what the
comparison stack is. This patch adds the a debug_comp_stack to dump
the comparison stack as a string.
* include/abg-fwd.h (debug_comp_stack): Declare function.
* src/abg-ir.cc (debug_comp_vec, print_comp_stack): Define static
functions.
(debug_comp_stack): Define new function.
Signed-off-by: Dodji Seketeli <dodji@seketeli.org>
---
include/abg-fwd.h | 3 +++
src/abg-ir.cc | 46 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+)
diff --git a/include/abg-fwd.h b/include/abg-fwd.h
index d5fcce7b..8a4383c2 100644
--- a/include/abg-fwd.h
+++ b/include/abg-fwd.h
@@ -1056,6 +1056,9 @@ debug(const decl_base* artifact);
bool
debug_equals(const type_or_decl_base *l, const type_or_decl_base *r);
+void
+debug_comp_stack(const environment& env);
+
bool
odr_is_relevant(const type_or_decl_base&);
diff --git a/src/abg-ir.cc b/src/abg-ir.cc
index 85b5cbb3..2719954e 100644
--- a/src/abg-ir.cc
+++ b/src/abg-ir.cc
@@ -9533,6 +9533,52 @@ debug_equals(const type_or_decl_base *l, const type_or_decl_base *r)
return (*l == *r);
}
+/// Emit a trace of a comparison operand stack.
+///
+/// @param vect the operand stack to emit the trace for.
+///
+/// @param o the output stream to emit the trace to.
+static void
+debug_comp_vec(const vector<const type_base*>& vect, std::ostringstream& o)
+{
+ for (auto t : vect)
+ {
+ o << "|" << t->get_pretty_representation()
+ << "@" << std::hex << t << std::dec;
+ }
+ if (!vect.empty())
+ o << "|";
+}
+
+/// Construct a trace of the two comparison operand stacks.
+///
+/// @param the environment in which the comparison operand stacks are.
+///
+/// @return a string representing the trace.
+static string
+print_comp_stack(const environment& env)
+{
+ std::ostringstream o;
+ o << "left-operands: ";
+ debug_comp_vec(env.priv_->left_type_comp_operands_, o);
+ o << "\n" << "right-operands: ";
+ debug_comp_vec(env.priv_->right_type_comp_operands_, o);
+ o << "\n";
+ return o.str();
+}
+
+/// Emit a trace of the two comparison operands stack on the standard
+/// error stream.
+///
+/// @param env the environment the comparison operands stack belong
+/// to.
+void
+debug_comp_stack(const environment& env)
+{
+ std::cerr << print_comp_stack(env);
+ std::cerr << std::endl;
+}
+
/// By looking at the language of the TU a given ABI artifact belongs
/// to, test if the ONE Definition Rule should apply.
///
--
2.31.1
--
Dodji
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-12-19 16:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-19 16:22 [PATCH, applied] ir: Add a debug_comp_stack debugging function Dodji Seketeli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).