From: Dodji Seketeli <dodji@seketeli.org>
To: libabigail@sourceware.org
Subject: [PATCH, applied] ir: Add a debug_comp_stack debugging function
Date: Mon, 19 Dec 2022 17:22:34 +0100 [thread overview]
Message-ID: <871qovfjn9.fsf@seketeli.org> (raw)
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
reply other threads:[~2022-12-19 16:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871qovfjn9.fsf@seketeli.org \
--to=dodji@seketeli.org \
--cc=libabigail@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).