const Dwarf_Die *l, const Dwarf_Die *r,
bool update_canonical_dies_on_the_fly);
+static bool
+compare_dies_during_canonicalization(read_context& ctxt,
+ const Dwarf_Die *l, const Dwarf_Die *r,
+ bool update_canonical_dies_on_the_fly);
/// Find the file name of the alternate debug info file.
///
corpus::exported_decls_builder* exported_decls_builder_;
options_type options_;
bool drop_undefined_syms_;
+#ifdef WITH_DEBUG_TYPE_CANONICALIZATION
+ bool debug_die_canonicalization_is_on_;
+ bool use_canonical_die_comparison_;
+#endif
read_context();
private:
options_.load_in_linux_kernel_mode = linux_kernel_mode;
options_.load_all_types = load_all_types;
drop_undefined_syms_ = false;
+#ifdef WITH_DEBUG_TYPE_CANONICALIZATION
+ debug_die_canonicalization_is_on_ =
+ environment->debug_die_canonicalization_is_on();
+ use_canonical_die_comparison_ = true;
+#endif
load_in_linux_kernel_mode(linux_kernel_mode);
}
get_canonical_die(const Dwarf_Die *die,
Dwarf_Die &canonical_die,
size_t where,
- bool die_as_type) const
+ bool die_as_type)
{
const die_source source = get_die_source(die);
// ABG_ASSERT(i->second.size() == 1);
Dwarf_Off canonical_die_offset = i->second.front();
get_die_from_offset(source, canonical_die_offset, &canonical_die);
+#ifdef WITH_DEBUG_TYPE_CANONICALIZATION
+ if (debug_die_canonicalization_is_on_)
+ {
+ use_canonical_die_comparison_ = false;
+ bool structural_equality =
+ compare_dies(*this, &canonical_die, die,
+ /*update_canonical_dies_on_the_fly=*/false);
+ use_canonical_die_comparison_ = true;
+ if (!structural_equality)
+ {
+ std::cerr << "structural & canonical equality different for DIEs: "
+ << std::hex
+ << "l: " << canonical_die_offset
+ << ", r: " << die_offset
+ << std::dec
+ << ", repr: '"
+ << get_die_pretty_type_representation(&canonical_die, 0)
+ << "'"
+ << std::endl;
+ ABG_ASSERT_NOT_REACHED;
+ }
+ }
+#endif
set_canonical_die_offset(canonical_dies,
die_offset,
canonical_die_offset);
cur_die_offset = *o;
get_die_from_offset(source, cur_die_offset, &canonical_die);
// compare die and canonical_die.
- if (compare_dies(*this, die, &canonical_die,
- /*update_canonical_dies_on_the_fly=*/true))
+ if (compare_dies_during_canonicalization(const_cast<read_context&>(*this),
+ die, &canonical_die,
+ /*update_canonical_dies_on_the_fly=*/true))
{
set_canonical_die_offset(canonical_dies,
die_offset,
Dwarf_Off die_offset = i->second[n];
get_die_from_offset(source, die_offset, &canonical_die);
// compare die and canonical_die.
- if (compare_dies(*this, die, &canonical_die,
- /*update_canonical_dies_on_the_fly=*/true))
+ if (compare_dies_during_canonicalization(const_cast<read_context&>(*this),
+ die, &canonical_die,
+ /*update_canonical_dies_on_the_fly=*/true))
{
set_canonical_die_offset(canonical_dies,
initial_die_offset,
update_canonical_dies_on_the_fly);
}
+/// Compare two DIEs for the purpose of canonicalization.
+///
+/// This is a sub-routine of read_context::get_canonical_die.
+///
+/// When DIE canonicalization debugging is on, this function performs
+/// both structural and canonical comparison. It expects that both
+/// comparison yield the same result.
+///
+/// @param ctxt the read context.
+///
+/// @param l the left-hand-side comparison operand DIE.
+///
+/// @param r the right-hand-side comparison operand DIE.
+///
+/// @param update_canonical_dies_on_the_fly if true, then some
+/// aggregate DIEs will see their canonical types propagated.
+///
+/// @return true iff @p l equals @p r.
+static bool
+compare_dies_during_canonicalization(read_context& ctxt,
+ const Dwarf_Die *l,
+ const Dwarf_Die *r,
+ bool update_canonical_dies_on_the_fly)
+{
+#ifdef WITH_DEBUG_TYPE_CANONICALIZATION
+ if (ctxt.debug_die_canonicalization_is_on_)
+ {
+ bool canonical_equality = false, structural_equality = false;
+ ctxt.use_canonical_die_comparison_ = false;
+ structural_equality = compare_dies(ctxt, l, r,
+ /*update_canonical_dies_on_the_fly=*/false);
+ ctxt.use_canonical_die_comparison_ = true;
+ canonical_equality = compare_dies(ctxt, l, r,
+ update_canonical_dies_on_the_fly);
+ if (canonical_equality != structural_equality)
+ {
+ std::cerr << "structural & canonical equality different for DIEs: "
+ << std::hex
+ << "l: " << dwarf_dieoffset(const_cast<Dwarf_Die*>(l))
+ << ", r: " << dwarf_dieoffset(const_cast<Dwarf_Die*>(r))
+ << std::dec
+ << ", repr: '"
+ << ctxt.get_die_pretty_type_representation(l, 0)
+ << "'"
+ << std::endl;
+ ABG_ASSERT_NOT_REACHED;
+ }
+ return structural_equality;
+ }
+#endif
+ return compare_dies(ctxt, l, r,
+ update_canonical_dies_on_the_fly);
+}
+
// ----------------------------------
// </die comparison engine>
// ---------------------------------
#endif
#ifdef WITH_DEBUG_TYPE_CANONICALIZATION
bool debug_type_canonicalization;
+ bool debug_die_canonicalization;
#endif
bool annotate;
bool do_log;
#endif
#ifdef WITH_DEBUG_TYPE_CANONICALIZATION
debug_type_canonicalization(),
+ debug_die_canonicalization(),
#endif
annotate(),
do_log(),
#endif
#ifdef WITH_DEBUG_TYPE_CANONICALIZATION
<< " --debug-tc debug the type canonicalization process\n"
+ << " --debug-dc debug the DIE canonicalization process\n"
#endif
#ifdef WITH_CTF
<< " --ctf use CTF instead of DWARF in ELF files\n"
else if (!strcmp(argv[i], "--debug-tc")
|| !strcmp(argv[i], "debug-type-canonicalization"))
opts.debug_type_canonicalization = true;
+ else if (!strcmp(argv[i], "--debug-dc")
+ || !strcmp(argv[i], "debug-die-canonicalization"))
+ opts.debug_die_canonicalization = true;
#endif
else if (!strcmp(argv[i], "--annotate"))
opts.annotate = true;
#ifdef WITH_DEBUG_TYPE_CANONICALIZATION
if (opts.debug_type_canonicalization)
env->debug_type_canonicalization_is_on(true);
+ if (opts.debug_die_canonicalization)
+ env->debug_die_canonicalization_is_on(true);
#endif
// First of all, read a libabigail IR corpus from the file specified