libabigail/tools
Dodji Seketeli 104468d1a4 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.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-05-25 12:16:25 +02:00
..
.gitignore Update .gitignore files to ignore typical dev side products 2019-04-16 16:32:52 +02:00
abicompat.cc Drop unneccessary includes of abg-cxx-compat.h 2020-12-15 09:23:44 +01:00
abidiff.cc Bug 27512 - Remove broken zip-archive support 2021-03-19 10:52:57 +01:00
abidw.cc Detect failed self comparison in type canonicalization of abixml 2021-05-25 12:16:25 +02:00
abilint.cc reader: Handle 'abi-corpus' element being possibly empty 2021-05-03 17:13:31 +02:00
abipkgdiff.cc Bug 27232 - fedabipkgdiff fails on gawk from Fedora 33 2021-01-26 17:41:33 +01:00
abisym.cc Re-license the project to Apache v2 With LLVM Exception 2020-12-02 11:49:13 +01:00
binilint.cc Re-license the project to Apache v2 With LLVM Exception 2020-12-02 11:49:13 +01:00
fedabipkgdiff Bug 27255 - fedabipkgdiff fails on nfs-utils on Fedora 33 2021-01-27 11:20:48 +01:00
kmidiff.cc Re-license the project to Apache v2 With LLVM Exception 2020-12-02 11:49:13 +01:00
Makefile.am Bug 27512 - Remove broken zip-archive support 2021-03-19 10:52:57 +01:00