Detect failed self comparison in type canonicalization of abixml
During the self comparison triggered by "abidw --abidiff <binary>",
some comparison errors can happen when canonicalizing types that are
"de-serialized" from the abixml that was serialized from the input
binary.
This patch adds some debugging checks and messaging to emit a message
when a type from the abixml appears to not "match" the original type
from the initial corpus it originated from.
This is the more detailed description:
Let's consider a type T coming from the corpus of the input binary.
That input corpus is serialized into abixml and de-serialized again
into a second corpus that we shall name the abixml corpus. From that
second corpus, let's consider the type T' that is the result of
serializing T into abixml and de-serializing it again. T is said to
be the original type of T'. If T is a canonical type, then T' should
equal T. Otherwise, if T is not a canonical type, its canonical type
should equal the canonical type of T'.
For the sake of simplicity, let's consider that T is a canonical
type. During the canonicalization of T', T' should equal T. Each and
every canonical type coming from the abixml corpus should be equal to its
original type from the binary corpus.
If a T' is different from its original type T, then there is an
"equality problem" between T and T'. In other words, there is a
mismatch between T and T'. We want to be notified of that problem so
that we can debug it further and fix it.
So this patch introduces the option "abidw --debug-abidiff <binary>"
to trigger the "debug self comparison mode". At canonicalization
time, we detect that we are in that debug self comparison mode and
during canonicalization of types from the abixml corpus, it detects
when they compare different from their counterpart from the original
corpus.
This debugging capability can be enabled at configure time with a new
--enable-debug-self-comparison configure option. That option defines
a new WITH_DEBUG_SELF_COMPARISON compile time macro that is used to
conditionally compile the implementation of this debugging feature.
So, one example of this might look like this:
abidw --debug-abidiff bin:
error: problem detected with type 'typedef Vmalloc_t' from second corpus
error: problem detected with type 'Vmalloc_t*' from second corpus
[...]
So that means the "typedef Vmalloc_t" read from the abixml compares
different from its original type where it should not.
So armed with this new insight, I know I need to debug that comparison
in particular to see why it wrongly results in two different types.
* doc/manuals/abidw.rst: Add documentation for the --debug-abidiff
option.
* include/abg-ir.h (environment::{set_self_comparison_debug_input,
get_self_comparison_debug_inputs, self_comparison_debug_is_on}):
Declare new methods.
* configure.ac: Define a new --enable-debug-self-comparison option
that is disabled by default. That option defines a new
WITH_DEBUG_SELF_COMPARISON preprocessor macro.
* src/abg-ir.cc
(environment::priv::{first_self_comparison_corpus_,
second_self_comparison_corpus_, self_comparison_debug_on_}): New
data members. Also, re-indent the data members.
(environment::{set_self_comparison_debug_input,
get_self_comparison_debug_inputs, self_comparison_debug_is_on}):
Define new method.
(type_base::get_canonical_type_for): In the "debug self comparison
mode", if a type coming from the second corpus compares different
from its counterpart coming from the first corpus then log a debug
message.
* src/abg-dwarf-reader.cc (read_debug_info_into_corpus): When
loading the first corpus, if the debug self comparison mode is on,
then save that corpus on the side in the environment.
* src/abg-reader.cc (read_corpus_from_input): When loading the
second corpus, if the debug self comparison mode is on, then save
that corpus on the side in the environment.
* tools/abidw.cc: Include the config.h file for preprocessor
macros defined at configure
(options::debug_abidiff): New data member.
(parse_command_line): Parse the --debug-abidiff option.
(load_corpus_and_write_abixml): Switch the self debug mode on when
the --debug-abidiff option is provided. Use a read_context for
the abixml loading. That is going to be useful for subsequent
patches.