[19/27] {btf,ctf,dwarf}-reader, ir: Fix self-comparison debugging for corpus groups
Commit Message
Hello,
When debugging the self comparison of a corpus group, libabigail fails
to detect that two ABI artifacts belong to the same corpus group.
This is because it only takes into account each individual corpus, not
the fact that several corpora can be grouped into one corpus group.
This patch introduces a new function type_originates_from_corpus which
can detect that a type originates from a corpus or a from a corpus
group. That function is used to detect that the type being
canonicalized belongs to the ABIXML corpus group and so its canonical
type must match the one of its originating ELF type.
* src/abg-btf-reader.cc (reader::read_debug_info_into_corpus):
When reading an ELF binary, which is part of a corpus group, for
the purpose of self-comparison, set that corpus group as the
comparison input. Otherwise, if the ELF binary is not part of the
corpus group, set its corpus as the comparison input. This is
done only when we are debugging the self-comparison process by
doing abidw --debug-abidiff.
* src/abg-ctf-reader.cc (reader::read_corpus): Likewise.
* src/abg-dwarf-reader.cc (reader::read_debug_info_into_corpus):
Likewise.
* src/abg-ir-priv.h (type_originates_from_corpus): Declare ...
* src/abg-ir.cc (type_originates_from_corpus): ... new function.
(type_base::get_canonical_type_for): When debugging the
self-comparison process, use the new type_originates_from_corpus
to know if the current type being canonicalized originates from
the second corpus.
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
---
src/abg-btf-reader.cc | 11 +++++++++++
src/abg-ctf-reader.cc | 11 +++++++++++
src/abg-dwarf-reader.cc | 8 +++++++-
src/abg-ir-priv.h | 3 ++-
src/abg-ir.cc | 35 ++++++++++++++++++++++++++++++++++-
5 files changed, 65 insertions(+), 3 deletions(-)
@@ -552,6 +552,17 @@ public:
corpus()->add(artificial_tu);
cur_tu(artificial_tu);
+#ifdef WITH_DEBUG_SELF_COMPARISON
+ if (env().self_comparison_debug_is_on())
+ {
+ corpus_group_sptr g = corpus_group();
+ if (g)
+ env().set_self_comparison_debug_input(g);
+ else
+ env().set_self_comparison_debug_input(corpus());
+ }
+#endif
+
int number_of_types = nr_btf_types(btf_handle());
int first_type_id = 1;
// Are we looking at the BTF for a kernel module?
@@ -707,6 +707,17 @@ public:
&& (status & fe_iface::STATUS_DEBUG_INFO_NOT_FOUND))
return corp;
+#ifdef WITH_DEBUG_SELF_COMPARISON
+ if (env().self_comparison_debug_is_on())
+ {
+ corpus_group_sptr g = corpus_group();
+ if (g)
+ env().set_self_comparison_debug_input(g);
+ else
+ env().set_self_comparison_debug_input(corpus());
+ }
+#endif
+
tools_utils::timer t;
if (do_log())
t.start();
@@ -2296,7 +2296,13 @@ public:
#ifdef WITH_DEBUG_SELF_COMPARISON
if (env().self_comparison_debug_is_on())
- env().set_self_comparison_debug_input(corpus());
+ {
+ corpus_group_sptr g = corpus_group();
+ if (g)
+ env().set_self_comparison_debug_input(g);
+ else
+ env().set_self_comparison_debug_input(corpus());
+ }
#endif
env().priv_->do_log(do_log());
@@ -1841,7 +1841,8 @@ struct function_type::priv
size_t
get_canonical_type_index(const type_base& t);
-
+bool
+type_originates_from_corpus(type_base_sptr t, corpus_sptr& c);
} // end namespace ir
} // end namespace abigail
@@ -363,6 +363,37 @@ size_t
get_canonical_type_index(const type_base_sptr& t)
{return get_canonical_type_index(t.get());}
+/// Test if a type originates from a corpus.
+///
+/// Note that this function supports testing if a type originates from
+/// a corpus group.
+///
+/// @param t the type to consider.
+///
+/// @param c the corpus or corpus group to consider.
+///
+/// @return true iff the type @p t originates from the corpus (or
+/// group) @p c.
+bool
+type_originates_from_corpus(type_base_sptr t, corpus_sptr& c)
+{
+ bool result = false;
+ if (c && t->get_corpus())
+ {
+ corpus_group_sptr g = is_corpus_group(c);
+ if (g)
+ {
+ if (t->get_corpus()->get_group() == g.get())
+ result = true;
+ }
+ else
+ {
+ if (t->get_corpus() == c.get())
+ result = true;
+ }
+ }
+ return result;
+}
/// @brief the location of a token represented in its simplest form.
/// Instances of this type are to be stored in a sorted vector, so the
/// type must have proper relational operators.
@@ -15453,7 +15484,9 @@ type_base::get_canonical_type_for(type_base_sptr t)
// possibly via the use of 'abidw --debug-abidiff <binary>'.
corpus_sptr corp1, corp2;
env.get_self_comparison_debug_inputs(corp1, corp2);
- if (corp1 && corp2 && t->get_corpus() == corp2.get())
+ if (corp1 && corp2 && type_originates_from_corpus(t, corp2)
+ && corp1->get_origin() != corp2->get_origin()
+ && corp2->get_origin() & corpus::NATIVE_XML_ORIGIN)
{
// If 't' comes from the second corpus, then it *must*
// be equal to its matching canonical type coming from