Commit Graph

120 Commits

Author SHA1 Message Date
Dodji Seketeli
f44110b326 Support comparing symbols not referenced by debug info
* doc/manuals/abidiff.rst: Adjust intro to mention that w/o debug
	info, abidiff now works but just report about added/removed
	symbols.  Add documentation about the new
	--no-unreferenced-symbols option.
	* include/abg-comparison.h (string_elf_symbol_map): New typedef.
	(diff_context::show_symbols_unreferenced_by_debug_info): Declare
	new accessors.
	* src/abg-comparison.cc
	(diff_context::priv::show_syms_unreferenced_by_di_): New data
	member.
	(diff_context::priv::priv): Adjust.
	(diff_context::show_symbols_unreferenced_by_debug_info): Implement
	these accessors.
	(corpus_diff::priv::{unrefed_fn_syms_edit_script_,
	unrefed_var_syms_edit_script_, added_unrefed_fn_syms_,
	deleted_unrefed_fn_syms_, added_unrefed_var_syms_,
	deleted_unrefed_var_syms_}): New data members.
	(corpus_diff::priv::diff_stats::{num_func_syms_removed,
	num_func_syms_added, num_var_syms_removed, num_var_syms_added}):
	New data members.
	(corpus_diff::priv::diff_stats::diff_stats): Adjust.
	(corpus_diff::ensure_lookup_tables_populated): Populate lookup
	tables for added/removed symbols that are not referenced by any
	debug info.
	(corpus_diff::priv::apply_filters_and_compute_diff_stats): Compute
	stats for the added/removed symbols not referenced by any debug
	info.
	(corpus_diff::priv::emit_diff_stats): Emit stats about
	added/removed symbols that are not referenced by any debug info.
	(corpus_diff::length): Adjust to take in account added/removed
	symbols not referenced by any debug info.
	(show_linkage_name_and_aliases): New static function.
	(corpus_diff::report): When emitting a symbol name, emit its
	version too, and tell if it aliases other symbols.  Avoid emitted
	extra new lines.  Report added/removed symbols not referenced by
	any debug info.
	(compute_diff): In the overload for corpus_sptr, compute the diffs
	for symbols not referenced by debug info.
	* include/abg-corpus.h
	(corpus::get_unreferenced_{function,variable}_symbols): Declare
	new member functions.
	* src/abg-corpus.cc (corpus_priv::{unrefed_fun_symbols,
	unrefed_var_symbols}): New data members.
	(corpus_priv::build_unreferenced_symbols_tables): Define new
	member function.
	(struct comp_elf_symbols_functor): New functor.
	(corpus::is_empty): Adjust to take in account added/removed
	symbols not referenced by debug info.
	(corpus::{get_unreferenced_function_symbols,
	corpus::get_unreferenced_variable_symbols}): Define these
	accessors.
	* include/abg-dwarf-reader.h (enum status): Transform this into
	bitfields.  Add a STATUS_UNKNOWN value that has the value 0.
	(operator|(status, status), operator&(status, status))
	(operator|=(status&, status), operator&=(status, status)): New
	bit-wise operators to manipulate instances of the status bit-field.
	* src/abg-dwarf-reader.cc (get_version_for_symbol): Fix this to
	avoid returning garbage version sometimes.
	(read_debug_info_into_corpus): Fix this to return a non-null but
	empty corpus_sptr when there is no debug info available.
	(operator|(status, status), operator&(status, status))
	(operator|=(status&, status), operator&=(status, status)): Define
	these new bitwise operators to manipulate instances of the status
	bit-field.
	(read_corpus_from_elf): Now that the abigail::dwarf_reader::status
	is a bit-field, set it to reflect if debug info and/or symbol
	tables have been found.  Do not bail out if debug info hasn't been
	found.  Rather, keep going, and go look for symbols-only; this is
	a kind of operating in degraded mode.
	* include/abg-ir.h (elf_symbol::get_aliases_id_string): Add a flag
	that says if the current instance of elf_symbol should be included
	in the list of aliases or not.
	* src/abg-ir.cc (elf_symbol::get_aliases_id_string): Define it.
	* tests/data/test-diff-dwarf/test16-syms-only-v{0,1}.o: New test
	input.
	* tools/abidiff.cc
	(options::show_symbols_not_referenced_by_debug_info): New data
	member.
	(options:options): Adjust.
	(display_usage): Add an info string for the new
	--no-unreferenced-symbols command line option.
	(parse_command_line): Parse the new --no-unreferenced-symbols
	command line.
	(set_diff_context_from_opts): Set the diff_context according to
	the presence of --no-unreferenced-symbols.
	(main): Adjust for the fact that abigail::dwarf_reader::status is
	now a bit-field.
	* tools/abilint.cc (main): Adjust for the fact that
	abigail::dwarf_reader::status is now a bit-field..
	():
	* tests/data/test-diff-dwarf/test16-syms-only-report.txt: New test
	reference output.
	* tests/data/test-diff-dwarf/test16-syms-only-v{0,1}.cc: Source code
	for new test input.
	* tests/data/test-diff-dwarf/test17-non-refed-syms-v{0,1}.o: New
	test input.
	* tests/data/test-diff-dwarf/test17-non-refed-syms-v{0,1}.cc: New
	source code for test input.
	* tests/data/test-diff-dwarf/libtest18-alias-sym-v{0,1}.so: New
	test input.
	* tests/data/test-diff-dwarf/test18-alias-sym-report-0.txt:
	Reference output for new test input.
	* tests/data/test-diff-dwarf/test18-alias-sym-v{0,1}.cc: Source
	code for new test input.
	* tests/data/test-diff-dwarf/test18-alias-sym-version-script:
	Source code for new test input.
	* tests/Makefile.am: Add the new test materials to the source
	distribution.
	* tests/test-diff-dwarf.cc(in_out_specs): Add the new input tests
	above to the array of tests to run by this harness.
	(main): Emit empty reports for empty resulting diffs.
	* tests/data/test-diff-dwarf/test{0,8,9,12,14-inline-report,}-report.txt:
	Adjust.
	* tests/data/test-diff-filter/test{0,01,2,4,5,7,8,9,10,12,13,15-0,15-1}-report.txt:
	Likewise.
	* tests/data/test-diff-filter/test{19-enum,20-inline,}-report-0.txt:
	Likewise.
	* tests/data/test-diff-suppr/test0-type-suppr-report-{1,2}.txt:
	Likewise.
	* tests/data/test-diff-suppr/test{1,2}-typedef-suppr-report-1.txt:
	Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-10-22 23:04:40 +02:00
Dodji Seketeli
e4c21097fa Write comparison functions that hint at the kind of changes they see
* include/abg-ir.h (enum change_kind): Declare new enum.
	(operator|(change_kind, change_kind), operator&(change_kind,
	change_kind), operator|=(change_kind&, change_kind)): Declare new bit-wise
	operators for the new enum change_kind.
	(equals): Declare this new comparison function for decl_base,
	scope_decl, type_base, type_decl, scope_type_decl,
	qualified_type_def, pointer_type_def, reference_type_def,
	array_type_def, enum_type_decl, typedef_decl, var_decl,
	function_decl, function_type, class_decl, and
	class_decl::base_spec.
	(class_decl::base_spec::operator(const decl_base&)): Declare new
	equality operator.
	* src/abg-ir.cc (operator|(change_kind l, change_kind r))
	(operator&(change_kind l, change_kind r), operator|=(change_kind&
	l, change_kind r), operator&=(change_kind& l, change_kind r)):
	Define these new operators.
	(equals): Define this new comparison function for decl_base,
	scope_decl, type_base, type_decl, scope_type_decl,
	qualified_type_def, pointer_type_def, reference_type_def,
	array_type_def, enum_type_decl, typedef_decl, var_decl,
	function_decl, function_type, class_decl, and
	class_decl::base_spec.
	({decl_base, scope_decl, type_base, type_decl, scope_type_decl,
	qualified_type_def, pointer_type_def, reference_type_def,
	array_type_def, enum_type_decl, typedef_decl, var_decl,
	function_decl, function_type, class_decl,
	class_decl::base_spec}::operator==): Re-write these comparison
	operators in terms of their relevant equal() functions.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-10-13 17:44:44 +02:00
Dodji Seketeli
fccc516656 Put IR artifacts in the abigail::ir namespace
* include/abg-fwd.h: Wrap IR artifacts into abigail::ir namespace.
	Inject that new abigail::ir namespace into the abigail namespace.
	* include/abg-ir.h: Wrap IR artifacts into abigail::ir namespace.
	(function_decl::parameter::get_type_name): Adjust the call to
	abigail::get_type_name.  It's now a call to
	abigail::ir::get_type_name.
	* src/abg-ir.cc: Wrap IR artifacts into abigail::ir namespace.
	* include/abg-traverse.h: Wrap the ir traversing artifact into the
	abigail::ir namespace too.
	* src/abg-traverse.cc: Adjust.
	* include/abg-corpus.h: Wrap corpus type stuff into abigail::ir.
	* include/abg-dwarf-reader.h: Inject namespace abigail::ir stuff
	into the abigail::dwarf_reader namespace.
	* include/abg-reader.h: Inject namespace abigail::ir stuff into
	the abigail::xml_reader namespace.
	* src/abg-reader.cc: Adjust.
	* include/abg-writer.h: Inject namespace abigail::ir stuff into
	the abigail::xml_writer namespace.
	* src/abg-writer.cc: Inject namespace abigail::ir stuff into
	abigail namespace here too.
	* src/abg-hash.cc: Inject the abigail::ir namespace into the
	abigail namespace.
	* tools/abg-tools-utils.cc: Adjust for the injection of
	abigail::function_decl. It's now abigail::ir::function_decl.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-10-13 17:44:43 +02:00
Dodji Seketeli
5c67f59f76 constify dm_context_rel::operator==
* include/abg-ir.h (dm_context_rel::operator==): Make this const.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-10-13 17:41:17 +02:00
Dodji Seketeli
b9d97f21c3 Fixup member functions which virtual-ness has just been set
* include/abg-ir.h (fixup_virtual_member_function): Declare new
	function.
	(class_decl): Declare fixup_virtual_member_function() as a member.
	* src/abg-ir.cc (set_member_function_is_virtual): Ensure that the
	member function that has seen its virtualness set is also put
	correctly put in the vector of virtual member functions of its
	class.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-10-02 12:17:48 +02:00
Dodji Seketeli
cbf1debeab Fix reading several clones of the same member function from DWARF
* include/abg-fwd.h (set_member_function_is_ctor)
	(set_member_function_is_dtor, set_member_function_is_const)
	(set_member_function_vtable_offset): Declare new functions.
	* include/abg-ir.h (class_decl::sort_virtual_mem_fns): Declare new
	member function.
	(mem_fn_context_rel::{vtable_offset, is_constructor is_destructor,
	is_const}): Add these setters.
	(set_member_function_is_ctor, set_member_function_is_dtor)
	(set_member_function_is_static, set_member_function_is_const)
	(set_member_function_vtable_offset)
	(set_member_function_is_virtual): Declare these new friend
	function to class class_decl::method_decl.
	* src/abg-dwarf-reader.cc (finish_member_function_reading): Split
	this out from build_class_type_and_add_to_ir.  Use the new setters
	for member functions properties introduced above.
	(build_class_type_and_add_to_ir): Factorize the creation of member
	function by using build_ir_node_from_die.  Once that function has
	created the member function in a rather generic way, use the new
	finish_member_function_reading to set the remaining specific
	properties for member functions.
	(build_function_decl): When called to read additional properties
	of a function_decl, allow this to read and update the elf symbol
	properties too.  This is useful for building a clone of a function
	that already has an elf symbol.
	(build_ir_node_from_die):  When building a function decl, consider
	the case of a DIE that has both DW_AT_specification and
	DW_AT_abstract_origin set.  That is, DW_AT_abstract_origin is set,
	and the origin has DW_AT_specification set.  This is basically a
	clone of a function that implements an interface (this happens for
	destructors, for instance).  In this case, really do the cloning
	of the interface implementation.  If the cloned function happens
	to be member function, use finish_member_function_reading to read
	the properties relevant to its method-ness.
	* src/abg-ir.cc (set_member_function_is_ctor)
	(set_member_function_is_dtor, set_member_function_is_const)
	(set_member_function_vtable_offset)
	(class_decl::sort_virtual_mem_fns): Define new functions.
	(sort_virtual_member_functions): Define new static function.
	(struct virtual_member_function_less_than): New functor.
	(class_decl::add_member_function): Keep virtual member functions
	vector sorted.
	* data/test-read-dwarf/test1.abi: Adjust.  Now, both the
	cdtor specification and all the clones that implements the
	different are emitted.
	* data/test-read-dwarf/test2.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-10-02 10:09:23 +02:00
Dodji Seketeli
46dbc9ce41 Rename member_function_is_virtual to get_member_function_is_virtual
* include/abg-fwd.h (get_member_function_is_virtual): Renamed the
	declaration of member_function_is_virtual into this.
	* src/abg-ir.cc (get_member_function_is_virtual): Likewise for its
	definition.
	* include/abg-ir.h (class decl_base): Adjust the friend function
	member_function_is_virtual references.
	* src/abg-comp-filter.cc (has_virtual_mem_fn_change)
	(has_non_virtual_mem_fn_change): Adjust.
	* src/abg-comparison.cc (represent)
	(SKIP_MEM_FN_IF_VIRTUALITY_DISALLOWED, class_diff::report):
	Likewise.
	* src/abg-hash.cc (class_decl:#️⃣:operator()): Likewise.
	(function_decl::clone, class_decl::add_member_function): Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-09-30 18:16:03 +02:00
Dodji Seketeli
fde3436568 Better support for inline related diffs
* include/abg-comparison.h
	(diff_category::HARMLESS_SYMBOL_ALIAS_CHANGE_CATEORY): New
	enumerator.
	(diff_category::EVERYTHING_CATEGORY): Adjust.
	* include/abg-ir.h (elf_symbol::get_aliases_id_string)
	(elf_symbol::does_alias, elf_symbols_alias)
	(compute_aliases_for_elf_symbol): Declare new functions ...
	* src/abg-ir.cc (elf_symbol::get_aliases_id_string)
	(elf_symbol::does_alias, elf_symbols_alias)
	(compute_aliases_for_elf_symbol): ... and define them.
	(function_decl::operator==): Take in account elf symbol aliases.
	* src/abg-comp-filter.cc (function_name_changed_but_not_symbol):
	Define new static functions.
	(harmless_filter::visit): Categorize function name changes that
n	doesn't impact underlying elf symbols (or the fact that two
	symbols were aliases and are not anymore) as harmless.
	* src/abg-comparison.cc (function_decl_diff::report): Properly
	report function name changes, or symbol aliases changes for that
	matter.  Also report inline-ness declaration changes.
	* src/abg-dwarf-reader.cc (die_is_declared_inline): New static
	function.
	(build_function_decl): Use the above.
	* tools/bidiff.cc (set_diff_context_from_opts): Add
	abigail::comparison::HARMLESS_SYMBOL_ALIAS_CHANGE_CATEORY into the
	harmless change camp.
	* tests/data/test-diff-dwarf/test14-inline-report.txt: New test
	input.
	* tests/data/test-diff-dwarf/test14-inline-v0.o: Likewise.
	* tests/data/test-diff-dwarf/test14-inline-v1.o: Likewise.
	* tests/data/test-diff-dwarf/test14-inline-v0.cc: Source code for
	test input.
	* tests/data/test-diff-dwarf/test14-inline-v1.cc: Source code for
	test input.
	* tests/test-diff-dwarf.cc: Run this test harness over the new
	input above.
	* tests/data/test-diff-filter/test20-inline-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test20-inline-report-1.txt:
	Likewise.
	* tests/data/test-diff-filter/test20-inline-v0.o: New test input.
	* tests/data/test-diff-filter/test20-inline-v1.o: New test input.
	* tests/data/test-diff-filter/test20-inline-v0.cc: Source code for
	test input.
	* tests/data/test-diff-filter/test20-inline-v1.cc: Likewise.
	* tests/test-diff-filter.cc: Run this test harness over the new
	input above.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-09-16 15:10:41 +02:00
Dodji Seketeli
41cfd5a82b Add constness to elf_symbol::operator==
* include/abg-ir.h (elf_symbol::operator==): Add a const to the
	declaration ...
	* src/abg-ir.cc (elf_symbol::operator==): ... and to the definition.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-09-16 11:21:47 +02:00
Dodji Seketeli
5f9a3bf4dd Fix memory leaks due to cycles in types ownership
* include/abg-fwd.h (std::tr1::weak_ptr): Inject this type in the
	abigail namespace.
	* include/abg-ir.h: Write a memory management guideline for the IR
	artifacts.
	(Type_base_wptr, function_type_wptr)
	(class_decl_wptr): New typedefs.
	(translation_unit::get_canonical_function_type): Declare new
	member function.
	(qualified_type_def::underlying_type_)
	(reference_type_def::pointed_to_type_)
	(typedef_decl::underlying_type_, function_decl::parameter::type_)
	(function_type::return_type_, method_type::class_type_)
	(non_type_tparameter::type_, type_composition::type_): Make this a
	weak pointer.
	(qualified_type_def::get_pointed_to_type)
	(reference_type_def::get_pointed_to_type)
	(array_type::get_element_type, typedef_decl::get_underlying_type)
	(var_decl::get_type, function_decl::parameter::get_type)
	(function_type::get_return_type, method_type::get_class_type)
	(non_type_tparameter::get_type)
	(type_composition::get_composed_type): Adjust to make this return
	a shared pointer initialized with the content of the weak pointer.
	(function_decl::function_decl, method_decl::method_decl): Remove
	the overload that doesn't take a type.  This is because now,
	function types need to be registered to their containing
	translation unit.
	(struct function_type::hash): Declare here.
	* src/abg-hash.cc (struct function_type::hash): Declare this in
	abg-ir.h and just define the methods here.
	* src/abg-ir.cc (fn_type_ptr_map): New typedef.
	(translation_unit::priv::canonical_types_): Remove this unused
	member.
	(translation_unit::priv::canonical_function_types_): New member.
	(translation_unit::get_canonical_function_type): Define this
	function.
	(array_type_def::priv::element_type_, var_decl::priv::type_)
	(function_decl::priv::type_): Make this a weak pointer.
	(qualified_type_def::get_underlying_type)
	(pointer_type_def::get_pointed_to_type)
	(reference_type_def::get_pointed_to_type)
	(array_type_def::get_element_type)
	(typedef_decl::get_underlying_type, var_decl::get_type)
	(function_decl::get_type): Adjust to make this return a shared
	pointer initialized with the content of the weak pointer.
	(qualified_type_def::build_name)
	(pointer_type_def::get_qualified_name)
	(reference_type_def::get_qualified_name): Adjust.
	(method_type::set_class_type): Cleanup the logic.
	(function_decl::priv::priv): Remove the overload that takes a bare
	pointer to a type.  This should not be used now that we need the
	function type to registered with the translation unit.
	(function_decl::function_decl): Remove the overload that doesn't
	take a type.  This is because now, function types need to be
	registered to their containing translation unit.
	* src/abg-dwarf-reader.cc (build_function_decl): Register the
	function type within its translation type and use its canonical
	version.  This complies with the new memory management rules.
	* src/abg-reader.cc (build_function_decl): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-09-10 18:08:41 +02:00
Dodji Seketeli
a2f1adb617 Update copyright notice
* include/abg-ir.h: Update year of copyright notice.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-09-10 17:19:36 +02:00
Dodji Seketeli
30b7fb8e5a During comparison use symbol name + version as decl ID
* include/abg-ir.h ({var,function}_decl::get_id): New member
	function declarations.
	* src/abg-ir.cc ({var,function}_decl::get_id): New member function
	definitions.
	* src/abg-comparison.cc
	(corpus_diff::priv::ensure_lookup_tables_populated): Use the
	::get_id() function to get an identifier for the function or
	variable.
	* src/abg-corpus.cc (symtab_build_visitor_type::build_id): Use the
	get_id of the function/variable.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-08-26 14:37:14 +02:00
Dodji Seketeli
5c493339c6 Misc style cleanups
* include/abg-corpus.h (corpus::lookup_function_symbol)
	(corpus::lookup_variable_symbol): Add the name of the function
	parameter in the declaration.
	* include/abg-ir.h (elf_symbol::version::version): Properly indent
	this constructor declaration.
	* src/abg-corpus.cc
	(symtab_build_visitor_type::symtab_build_visitor_type): Properly
	indent constructor parameters.
	* src/abg-ir.cc (function_decl::operator==): Fix typo in
	comments.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-08-25 23:04:53 +02:00
Ondrej Oprala
055a789abe Support C and C++ array type.
* include/abg-comparison.h (array_diff): Declare new class.
	(array_diff_sptr): Shared pointer to type array_diff.
	(compute_diff): Overload the function to take type
	array_diff_sptr as the first two arguments.
	* include/abg-fwd.h (array_type_def): Declare new class.
	(subrange_type): Likewise.
	(is_array_def): Declare new function.
	* include/abg-ir.h (array_type_def_sptr): Shared pointer
	to type array_type_def.
	(array_type_def): Declare new class.
	(ir_node_visitor::visit): Declare a new virtual function
	taking a pointer to type array_type_def as an argument.
	* src/abg-comparison.cc (compute_diff_for_types): Add
	try_to_diff for two instances of type array_type_def.
	(array_diff::priv): declare struct for holding private members
	of type array_diff.
	(array_diff::array_diff): Define constructor.
	(array_diff::{first,second}_array):Define new
	member functions.
	(array_diff::element_type_diff): Likewise.
	(array_diff::{length,report,traverse}): Likewise.
	(compute_diff): Define function overloaded in
	include/abg-comparison.h.
	* src/abg-dwarf-reader.cc (build_array_type): Define new
	function. Handle DW_TAG_array_type and DW_TAG_subrange type.
	(build_ir_node_from_die): Amend case DW_TAG_array_type with
	a call to build_array_type.
	* src/abg-hash.cc (array_type_def::hash): Declare new struct.
	(type_base::dynamic_hash::operator()): Attempt to dynamic_cast
	the argument to type array_type_def as well.
	(array_type_def::hash): Declare new struct.
	* src/abg-ir.cc (array_type_def::array_type_def): Define
	constructors.
	(array_type_def::priv): declare struct for holding private members
	of type array_type_def.
	(array_type_def::operator==(const decl_base&):
	Define new operator.
	(array_type_def::operator==(const type_base&):
	Likewise.
	(array_type_def::append_subrange{,s}): Define
	new functions.
	(array_type_def::{set,get}_size_in_bits): Likewise.
	(array_type_def::get_dimension_count): Likewise.
	(array_type_def::get_qualified_name): Likewise.
	(array_type_def::get_pretty_representation): Likewise.
	(array_type_def::get_subrange_representation): Likewise.
	(array_type_def::traverse): Likewise.
	(array_type_def::get_{element_type,location,subranges}): Likewise.
	(array_type_def::is_infinite): Likewise.
	(array_type_def::~array_type_def): Define destructor.
	(ir_node_visitor::visit): Define function, taking
	pointer to array_type_def as an argument.
	* src/abg-reader.cc (map_id_and_node): Check if node
	is an array.
	(is_array_def): Check if object is an array.
	(handle_element_node): Handle array_type_def as well.
	(build_subrange_type): Define new function.
	(build_array_type_def): Likewise.
	(build_type): Build type array_type_def as well.
	(build_type_composition): Likewise.
	(handle_array_type_def): Define new function.
	* src/abg-writer.cc: (write_decl): Output arrays
	as well.
	(write_member_type): Likewise.
	(write_type_composition): Likewise.
	(write_array_type_def): Define new function.
	* tests/data/test-diff-dwarf/test{10,11}-v{0,1}.{cc,o}: New test source
	files
	* tests/data/test-diff-dwarf/test{10,11}-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test10-report.txt: New test input.
	* tests/data/test-read-dwarf/test7.cc: New test source
	file.
	* tests/data/test-read-dwarf/test7.so: New input binary
	to read.
	* tests/data/test-read-dwarf/test7.so.abi: New reference
	test to compare against.
	* tests/data/test-read-write/test25.xml: New test source
	file.
	* tests/test-diff-dwarf.cc: Adjust to launch the new test.
	* tests/test-read-dwarf.cc: Likewise.
	* tests/test-read-write.cc: Likewise.
	* test/Makefile.am: Add the new test inputs to the source
	distribution.

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-08-22 13:07:41 +02:00
Dodji Seketeli
01cd814bbc Support reading void* type from DWARF
* include/abg-ir.h (type_decl::get_void_type_decl): Declare new
	static method.
	* src/abg-ir.cc (type_decl::get_void_type_decl): Define it.
	* src/abg-dwarf-reader.cc (build_ir_node_for_void_type): Define
	new static function.
	(build_pointer_type_def): Support void* type nodes here.
	* tests/data/test-read-dwarf/test5.cc: Source code for new test
	input.
	* tests/data/test-read-dwarf/test5.o: New test input.
	* tests/data/test-read-dwarf/test5.o.abi: Likewise.
	* tests/Makefile.am: Add the above to the source distribution.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-06-23 17:31:26 +02:00
Dodji Seketeli
e2d450176b Add a symbol database to the ABI Corpus & support symbol aliases
* include/abg-corpus.h (corpus::{g,s}et_{fun,var}_symbol_map{_sptr}):
	Declare new accessors.
	(corpus::lookup_{variable,function}_symbol): Declare new member
	functions.
	* src/abg-corpus.cc (corpus::{g,s}et_{fun,var}_symbol_map{_sptr}):
	Define new accessors.
	(corpus::lookup_{variable,function}_symbol): Define new member
	functions.
	* include/abg-ir.h (string_elf_symbol_sptr_map_type)
	(string_elf_symbol_sptr_map_sptr, elf_symbols)
	(string_elf_symbols_map_type, string_elf_symbols_map_sptr): New
	convenience typedefs.
	(elf_symbol::{get_main_symbol, is_main_symbol, get_next_alias,
	has_aliases, add_alias, get_id_string,
	get_name_and_version_from_id, operator=}): Declare new member
	functions.
	* src/abg-ir.cc (elf_symbol::{get_main_symbol, is_main_symbol,
	get_next_alias, has_aliases, add_alias, get_id_string,
	get_name_and_version_from_id, operator=}): Define new member
	functions.
	* include/abg-reader.h (read_corpus_from_file): Take a shared
	pointer to corpus.
	* src/abg-reader.cc (read_context::{g,s}et_corpus): Define these.
	(build_elf_symbol_db, build_elf_symbol_from_reference)
	(read_symbol_db_from_input): Define new functions.
	(read_corpus_from_input): Adjust.  Make it read symbol databases.
	(build_elf_symbol): Harden this.
	(build_{var,function}_decl): Read the symbol reference.  Do not
	read the local symbol serialization anymore.
	(read_corpus_from_archive): Adjust.
	(read_corpus_from_file): Take a reference to a shared pointer to
	corpus, rather than a reference to the corpus.
	(read_corpus_from_native_xml): Only keep the overload that returns
	a corpus.  Set the current context with the corpus.
	* src/abg-dwarf-reader.cc (addr_elf_symbol_sptr_map_type)
	(addr_elf_symbol_sptr_map_sptr): New convenience typedefs.
	(read_context::{fun_sym_addr_sym_index_map_,
	var_sym_addr_sym_index_map_): Remove.
	(read_context::{fun,var}_addr_sym_map_): New.  Replace the above
	that got removed.
	(read_context::{var,fun}_syms_): New.
	(read_context::lookup_elf_{fn,var}_symbol_from_address): Adjust.
	(read_context::{fun,var}_addr_sym_map{_sptr}): New.
	(read_context::{fun,var}_syms{_sptr}): New.
	(read_context::load_symbol_maps): Replace
	read_context::load_symbol_addr_to_index_maps.  Adjust to load all
	the new maps.
	(read_context::maybe_load_symbol_maps): New.
	(read_debug_info_into_corpus): Renamed build_corpus into this.
	Update to load symbol maps and set it to the corpus.
	* src/abg-writer.cc (write_context::get_fun_symbol_map): New
	accessor.
	(write_elf_symbol_aliases, write_elf_symbol_reference)
	(write_elf_symbols_table): Define new static functions.
	(write_var_decl): Write the reference to the underlying symbol of
	the variable.  Do not write the full symbol here anymore.
	(write_function_decl):  Likewise, write the reference to the
	underlying symbol of the function.  Do not write the full symbol
	here anymore.
	(write_corpus_to_native_xml): Write the symbol databases at the
	beginning of the corpus document.
	* src/abg-comparison.cc
	(corpus_diff::priv::ensure_lookup_tables_populated): Now that the
	corpus has symbols, check if a the symbol of an allegedly deleted
	function (resp. variable) is deleted; if not, then do not report
	the function (resp. variable) as deleted.  Similarly, check if the
	symbol of an allegedly added function (resp. variable) is added.
	if not, the do not report the function (resp. variable) as added.
	* tests/test-write-read-archive.cc (main): Adjust.
	* tools/biar.cc (extract_tus_from_archive): Likewise.
	* tests/data/test-diff-filter/test9-report.txt: Adjust.
	* tests/data/test-read-dwarf/test0.abi: Likewise.
	* tests/data/test-read-dwarf/test1.abi: Likewise.
	* tests/data/test-read-dwarf/test2.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-05-28 16:33:35 +02:00
Dodji Seketeli
4d0de72a85 Support decl cloning when seeing DW_AT_abstract_origin
* include/abg-ir.h ({var,function}_decl::clone): New method.
	* src/abg-dwarf-reader.cc (die_die_attribute): Add a flag to avoid
	looking through DW_AT_abstract_origin attribute here.
	(build_function_decl): Set the linkage name from
	DW_AT_linkage_name if it's not set yet.
	(build_ir_node_from_die): For DW_TAG_{variable,subprogram}, when
	we see DW_AT_abstract_origin, clone the decl they refer to.
	Also, avoid dropping the DIE on the floor just because it doesn't
	have die_is_artificial here.
	* src/abg-ir.cc ({var,function}_decl::clone): Implement this.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-05-20 18:22:14 +02:00
Dodji Seketeli
335d8786b2 Serialize and de-serialize elf symbols for var & function decls
* abg-ir.h (string_to_elf_symbol_type, string_to_elf_symbol_binding):
	Declare new entry points.
	* src/abg-ir.cc (string_to_elf_symbol_type)
	(string_to_elf_symbol_binding): Define new entry points.
	* include/abg-libxml-utils.h (xml_char_sptr_to_string): Declare
	new entry points.
	* src/abg-libxml-utils.cc (xml_char_sptr_to_string): Define new
	entry points.
	* src/abg-reader.cc (read_elf_symbol_type)
	(read_elf_symbol_binding, build_elf_symbol): Define new static
	functions.
	(build_function_decl, build_var_decl): Use the new
	build_elf_symbol and set the symbol to the function.  Flag the
	function as having a public symbol in the symbol table if the
	symbol is public.
	* src/abg-writer.cc (write_elf_symbol_type)
	(write_elf_symbol_binding, write_elf_symbol): Define new static
	functions.
	(write_var_decl, write_function_decl): Use the new
	write_elf_symbol to serialize the symbol for the decl.
	* tests/data/test-read-dwarf/test[01].abi: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-05-14 11:19:34 +02:00
Dodji Seketeli
ce1278c3da Initial support for elf symbol (versionning) during decl comparison
* include/abg-fwd.h (get_linkage_name): Remove.
	* include/abg-dwarf-reader.h (enum symbol_type)
	(enum symbol_binding): Move these into abg-ir.h.
	(lookup_symbol_from_elf, lookup_public_function_symbol_from_elf):
	Adjust.
	* src/abg-dwarf-reader.cc (eval_last_constant_dwarf_sub_expr):
	Declare this before using it.
	(die_address_attribute, die_location_address)
	(stt_to_elf_symbol_type, stb_to_elf_symbol_binding)
	(find_hash_table_section_index, find_symbol_table_section)
	(find_symbol_table_section_index, find_text_section)
	(find_bss_section, compare_symbol_name)
	(get_symbol_versionning_sections get_version_for_symbol)
	(lookup_symbol_from_sysv_hash_tab)
	(lookup_symbol_from_gnu_hash_tab, get_elf_class_size_in_bytes)
	(bloom_word_at, setup_gnu_ht, lookup_symbol_from_elf_hash_tab)
	(lookup_symbol_from_symtab, maybe_adjust_fn_sym_address)
	(maybe_adjust_var_sym_address): New static functions.
	(enum hash_table_kind): New enum.
	(struct gnu_ht): New struct.
	(read_context::var_decls_to_add_): Renamed var_decls_to_add into
	this.
	(read_context::{fun, var}_sym_addr_sym_index_map_): New member.
	(read_context::{lookup_symbol_from_elf,
	lookup_elf_symbol_from_index, lookup_elf_fn_symbol_from_address,
	lookup_elf_var_symbol_from_address, fun_sym_addr_sym_index_map,
	var_sym_addr_sym_index_map, load_symbol_addr_to_index_maps,
	get_function_address, get_variable_address}): New member
	functions.
	(read_context::lookup_public_{variable,
	function}_symbol_from_elf): Adjust.
	(op_pushes_constant_value): Fix a bug here.
	(lookup_symbol_from_elf): Adjust.  Support cases where there is no
	elf hash table, e.g, for relocatable files.
	(lookup_public_function_symbol_from_elf)
	(lookup_public_variable_symbol_from_elf): Adjust.
	(build_var_decl): Allow updating the var_decl to associate it with
	its underlying symbol.  In that case, if the linkage name is not
	set, set it to the symbol name.
	(build_function_decl): Likewise for function_decl.
	(operator<<(std::ostream&, symbol_type)):
	(operator<<(std::ostream&, symbol_binding)): Move these do
	abg-ir.cc.
	* include/abg-ir.h (class elf_symbol): Declare new class.  Move
	enum symbol_binding and enum symbol_type (from abg-dwarf-reader.h) to
	elf_symbol::binding and elf_symbol::type here.
	(operator<<(std::ostream&, elf_symbol::type))
	(operator<<(std::ostream&, elf_symbol::binding))
	(operator==(const elf_symbol_sptr, const elf_symbol_sptr)): New
	operators.
	(class elf_symbol::version): Declare new class.
	(class var_decl): Make this pimpl, and add ...
	(var_decl::{g,s}et_symbol): ... new member functions.
	(class function_decl): Likewise, make this pimpl and add ...
	(function_decl::{g,s}et_symbol): ... new member functions.
	* src/abg-ir.cc (struct elf_symbol, elf_symbol::priv): New
	types.
	(elf_symbol::*): Lots of new members and member functions.
	(operator==(const elf_symbol_sptr, const elf_symbol_sptr)): New.
	(operator<<(std::ostream&, elf_symbol::type)): New.
	(operator<<(std::ostream&, elf_symbol::binding)): New.
	(elf_symbol::version::priv): New type.
	(elf_symbol::version::*): Lots of member functions.
	(get_linkage_name): Removed.
	(var_decl::priv): New type.  Pimplify the thing.
	(var_decl::{s,g}et_symbol): New.
	(var_decl::operator==): Take symbols in account in the comparison.
	(function_decl::priv): New type.
	(function_decl::*): Pimplify.
	(function_decl::{s,g}et_symbol): New.
	(function_decl::operator==): Take symbols in account in the
	comparison.
	* include/abg-comparison.h (diff_context::show_linkage_name): New
	member function.
	* src/abg-comparison.cc (diff_context::priv::show_linkage_name_):
	New member.
	(diff_context::priv::priv): Initialize it.
	(diff_context::show_linkage_names): New member function.
	(corpus_diff::report): If the user used --show-linkage-names,
	display the linkage name after the name of the functions.  Add
	missing "'" in the some spots.
	* tools/bidiff.cc (options.show_linkage_names): New member.
	(display_usage, parse_command_line): Support --linkage-names.
	* tools/bisym.cc (show_help): Add '\n' at the end of help string
	for --demangle.  Add --no-absolute-path option.
	(parse_command_line): Support --no-absolute-path.
	(main): Adjust for symbol (versionning) support.  Consider that
	the program successfully completed even when the symbol wasn't
	found.  Support --no-absolute-path.
	* tests/data/test-lookup-syms/test0-report.txt: New.
	* tests/data/test-lookup-syms/test01-report.txt: New.
	* tests/data/test-lookup-syms/test02-report.txt: New.
	* tests/data/test-read-dwarf/test0.abi: Adjust.
	* tests/data/test-read-dwarf/test1.abi: Adjust.
	* tests/data/test-diff-dwarf/test7-report.txt: Adjust.
	* tests/data/test-diff-filter/test10-report.txt: Adjust.
	* tests/data/test-diff-filter/test12-report.txt: Adjust.
	* tests/data/test-lookup-syms/test1-[123]-report.txt: New.
	* tests/data/test-lookup-syms/test1.c: New.
	* tests/data/test-lookup-syms/test1.version-script: New.
	* tests/test-lookup-syms.cc: Adjust for new tests.
	* test/Makefile.am: Adjust makefile.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-05-12 16:09:47 +02:00
Dodji Seketeli
bdf9e956d8 Rename decl_base::get_mangled_name into decl_base::get_linkage_name
* include/abg-ir.h (decl_base::get_linkage_name): Renamed
	decl_base::get_mangled_name into this.
	* src/abg-comparison.cc
	(class_diff::ensure_lookup_tables_populated)
	(function_decl_diff::report, type_decl_diff::report)
	(corpus_diff::priv::ensure_lookup_tables_populated)
	(corpus_diff::report, compute_diff): Adjust.
	* src/abg-corpus.cc ({var_comp, func_comp}::operator()): Likewise.
	(corpus::priv::build_symbol_table): Likewise.
	* src/abg-dwarf-reader.cc (die_linkage_name): Renamed
	die_mangled_name into this.
	(die_loc_and_name, build_translation_unit_and_add_to_ir)
	(build_namespace_decl_and_add_to_ir, build_type_decl)
	(build_enum_type, build_class_type_and_add_to_ir)
	(build_typedef_type, build_var_decl, build_function_decl, ): Adjust.
	* src/abg-hash.cc (decl_base:#️⃣:operator()): Likewise.
	* src/abg-ir.cc (decl_base::priv::linkage_name_): Renamed
	decl_base::priv::mangled_name_ into this.
	(decl_base::priv::priv, decl_base::{decl_base, operator==})
	(get_linkage_name, typedef_decl::typedef_decl, var_decl::var_decl)
	(function_decl::function_decl, class_decl::base_spec::base_spec)
	(class_decl::method_decl::method_decl): Adjust.
	(decl_base::{g,s}et_linkage_name): Renamed
	decl_base::{g,s}et_mangled_name into this.
	* src/abg-writer.cc (write_decl, write_typedef_decl)
	(write_var_decl, write_function_decl, dump): Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-05-11 19:22:00 +02:00
Dodji Seketeli
e2c776f4bc Pimplify decl_base and add decl_base::{s,g}et_is_in_public_symbol_table
* include/abg-ir.h (struct decl_base::priv): New pimpl type.
	(decl_base::priv_): New pimpl.
	(decl_base::{hashing_started, peek_hash_value,
	peek_qualified_name, set_qualified_name}): Declare new protected
	methods.
	(decl_base::{get_context_rel, set_qualified_name, get_location,
	set_location, set_name, set_mangled_name, get_visibility,
	set_visibility}): Move these out-of-line.
	(decl_base::{g,s}et_is_public_symbol_table):
	(class_decl::hashing_started): Remove this as we now have
	decl_base::hashing_started.
	(decl_base::{hash_, hashing_started, location_, context_, name_,
	qualified_parent_name_, qualified_name_, mangled_name_,
	visibility_}): Move all these members into the new ...
	* src/abg-ir.cc (struct decl_base::priv): ... pimpl type.
	(decl_base::decl_base): Move these out-of-line here.  Adjust the
	other overloads.
	(decl_base::{hashing_started, peek_hash_value,
	peek_qualified_name, set_qualified_name}): Define these new
	protected methods.
	(decl_base::{get_context_rel, set_context_rel, get_location,
	set_location, set_name, get_mangled_name, set_mangled_name,
	get_visibility, set_visibility}): Define these out-of-line here.
	(decl_base::{get_hash, set_hash, get_scope,
	get_qualified_parent_name, get_qualified_name, operator==,
	set_scope}): Adjust.
	(qualified_type_def::get_qualified_name): Likewise.
	(pointer_type_def::get_qualified_name): Likewise.
	(reference_type_def::get_qualified_name): Likewise.
	(var_decl::set_scope): Likewise.
	(class_decl::base_spec): Likewise.
	(class_decl::method_decl::set_scope): Likewise.
	(decl_base::{g,s}et_is_in_public_symbol_table): Define new accessors.
	* src/abg-hash.cc ({decl_base, type_decl, scope_decl,
	scope_type_decl, qualified_type_def, pointer_type_def,
	reference_type_def, enum_type_decl, typedef_decl, var_decl,
	class_decl}:#️⃣:operator): Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-04-21 17:13:46 +02:00
Dodji Seketeli
3ae24bafc3 Provide a robust way of getting the size of a qualified type
* include/abg-ir.h (qualified_type_def::get_size_in_bits): Declare
	new member function ...
	* src/abg-ir.cc (qualified_type_def::get_size_in_bits): ... and
	define it.  Keep in mind that some times the size of the
	underlying type can change between the moment the qualified type
	is created and the end of its life time.  That is because a
	subsequent DIE (from DWARF) can alter the size of the underlying
	type.  This overload allows the user to always query the size of
	the underlying type and keep the size of the qualified type in
	sync with it.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-04-16 11:41:20 +02:00
Dodji Seketeli
99d3857ddd Recognize virtual member functions better and store them appart
* include/abg-fwd.h (set_member_function_is_virtual): Declare new
	function.
	* include/abg-ir.h (class class_decl): Declare
	set_member_function_is_virtual and member_function_is_virtual as
	friends of class_decl.
	(class_decl::add_member_function): Take an is_virtual flag.
	(class_decl::get_num_virtual_functions): Remove.
	(class_decl::get_virtual_mem_fns): New member function.
	(mem_fn_context_rel::is_virtual_): New member.
	(mem_fn_context_rel::mem_fn_context_rel): Adjust to initialize the
	new is_virtual_ member.
	(mem_fn_context_rel::is_virtual): New member functions.
	* src/abg-comparison.cc (represent): Adjust.
	* src/abg-dwarf-reader.cc (build_class_type_and_add_to_ir): Adjust.
	* src/abg-ir.cc (member_function_is_virtual): Change this to use
	mem_fn_context_rel::is_virtual.
	(set_member_function_is_virtual): Define this new function.
	(class_decl::priv::virtual_mem_fns_): New member to hold virtual
	member functions.
	(class_decl::get_virtual_mem_fns): Implement this member function.
	(class_decl::get_num_virtual_functions): Remove.
	(class_decl::add_member_function): Take a new is_virtual flag.
	Add virtual member functions to
	class_decl::priv::virtual_mem_fns_.
	* src/abg-reader.cc (build_class_decl): Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-04-14 14:56:51 +02:00
Dodji Seketeli
7ac2fe072d Make class_decl pimpl and harden comparison infloop prevention
* include/abg-ir.h (class_decl::{priv}): New private data member.
	(class_decl::{get_is_declaration_only, set_is_declaration_only,
	is_struct, get_definition_of_declaration, get_earlier_declaration,
	add_base_specifier, get_base_specifiers, get_member_types,
	get_data_members, get_member_functions,
	get_member_function_templates, get_member_class_templates}): Move
	these methods out-of-line.
	(class_decl::{comparison_started_,
	declaration_,is_declaration_only_, definition_of_declaration,
	is_struct_, bases_, member_types_, data_members_,
	member_functions_, member_function_template,
	member_class_templates_}): Move these data members into the pimpl
	in ...
	* src/abg-ir.cc
	(class_decl::priv::{declaration_,is_declaration_only_,
	definition_of_declaration, is_struct_, bases_, member_types_,
	data_members_, member_functions_, member_function_template,
	member_class_templates_}): ... here.
	(class_decl::priv::classes_being_compared_): New data member.
	(class_decl::priv::priv): Initialize the data members.
	(class_decl::priv::{mark_as_being_compared,
	unmark_as_being_compared, comparison_started): New methods.
	(class_decl::{get_is_declaration_only, set_is_declaration_only,
	is_struct, get_definition_of_declaration, add_base_specifier,
	get_base_specifiers, get_member_types, get_data_members,
	get_member_functions, get_member_function_templates,
	get_member_class_templates}): Move these out-of-line in here.
	(class_decl::{class_decl, set_definition_of_declaration,
	set_earlier_declaration, insert_member_type, add_member_type,
	add_data_member, add_member_function,
	add_member_function_template, add_member_class_template,
	has_no_base_nor_member}): Adjust.
	(class_decl::operator==): Harden inf-loop prevention during class
	comparison using the new priv::mark/unmark_as_being_compared()
	functions.  Now comparison of a class really compares member
	functions again.  And it is *slooow*.  I should probably change
	this to compare only virtual member functions.  But at least this
	should be correct and robust for now.
	* tests/data/test-diff-filter/test0-report.txt: Adjust.
	* test01-report.txt: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-04-13 22:09:24 +02:00
Dodji Seketeli
d25c8bbbaa Fix and add missing hashing through the virtual decl_base::get_hash
* include/abg-ir.h (struct {scope_decl, non_type_tparameter,
	type_composition, class_decl}::hash): Declare hashers.
	({scope_decl, var_decl, non_type_tparameter, type_composition,
	class_decl}::get_hash): Provide new overloads of the get_hash.
	* src/abg-hash.cc ({type_decl, scope_type_decl,
	qualified_type_def, pointer_type_def, reference_type_def,
	enum_type_decl, typedef_decl, var_decl,
	function_decl}:#️⃣:operator()): If the hash is being
	calculated, do not use the not-yet fully calculated hash value.
	Rather, calculate the hash, cache it and return the value.
	({class_decl, non_type_tparameter}:#️⃣:operator()): Moved the
	{class_decl, non_type_tparameter}::hash declaration out of here
	and stick it in include/abg-ir.h.  Keep the definition of the
	hashing operators here though.
	(type_composition:#️⃣:operator()): New operator definition.
	* src/abg-ir.cc ({scope_decl, var_decl, class_decl,
	non_type_tparameter, type_composition}::get_hash): Define new
	virtual overload.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-04-09 17:11:32 +02:00
Dodji Seketeli
793be5e374 Fix mis-hashing of base specifiers and function_decl during comparison
* include/abg-ir.h (function_decl::get_hash): Declare new virtual
	overload.
	* src/abg-hash.cc (class_decl::base_spec:#️⃣:operator()):
	Properly hash the base specifier so that it doesn't collide with
	hashing a class.
	* src/abg-ir.cc (decl_base::get_hash): Abort if we detect a
	missing overload for this;
	(function_decl::get_hash() const): Implement this missing
	overload, allowing using the virtual decl_base::get_hash for
	function_decl.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-04-08 15:56:18 +02:00
Dodji Seketeli
435f1520d7 Make type_base::get_{size,alignment}_in_bits virtual
* include/abg-ir.h (type_base::get_{size,alignment}_in_bits): Make
	this virtual.
	(typedef_decl::get_{size,alignment}_in_bits): Add new member
	functions.  Get the size,alignment from the underlying type and
	update the current size/alignment if they differ.  Keep in mind
	that the size of an underlying class_decl can change over its
	lifetime, given how the dwarf reader reads the type information,
	i.e, there can be a DIE for a class type with no size information
	that will lead to the creation of a class_decl with size zero.
	Later during the DWARF reading process, another DIE will
	supplement the type information, adding size information to that
	class_decl.  In between, a typedef_decl might have been created
	with the first version of the class_decl that has a zero size.  I
	guess this should be extended to the other type constructs that
	have an underlying type (qualified types, references and pointers).

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-04-07 10:08:10 +02:00
Dodji Seketeli
64bbb5ccef Add a COMPATIBLE_TYPE_CHANGE_CATEGORY to bidiff --no-harmless
* include/abg-comparison.h
	(diff_category::COMPATIBLE_TYPE_CHANGE_CATEGORY): New enumerator.
	(operator|=(diff_category&, diff_category)): New declaration.
	* include/abg-fwd.h (is_typedef, strip_typedef)
	(types_are_compatible): New declarations.
	* include/abg-ir.h (operator==(const decl_base_sptr, const
	decl_base_sptr)): Added the consts here.
	(operator==(const type_base_sptr, const type_base_sptr)): New
	declaration.
	* src/abg-comp-filter.cc (is_compatible_change): New static
	function.
	(harmless_filter::visit): Detect compatible changes and add the
	sub-tree into the new COMPATIBLE_TYPE_CHANGE_CATEGORY if
	applicable. Cleanup the logic.
	* src/abg-comparison.cc (operator|=(diff_category&,
	diff_category)): Define new function.
	(operator==(const decl_base_sptr l, const decl_base_sptr r)): Add
	consts.
	(operator==(const type_base_sptr l, const type_base_sptr r)):
	Define new operator.
	(is_typedef, strip_typedef, types_are_compatible): New function
	definitions.
	* tests/data/test-diff-filter/test3-report.txt: New test report
	reference.
	* tests/data/test-diff-filter/test3-v0.cc: Source code for new
	test input.
	* tests/data/test-diff-filter/test3-v0.o: New test input.
	* tests/data/test-diff-filter/test3-v1.cc: Source code for new
	test input.
	* tests/data/test-diff-filter/test3-v1.o: New test input.
	* tests/test-diff-filter.cc: Adjust to consume the new tests
	inputs above.
	* tools/bidiff.cc: Add the new COMPATIBLE_TYPE_CHANGE_CATEGORY
	into the --harmless group.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-04-02 17:23:56 +02:00
Dodji Seketeli
88741744e7 Make tree walking preemptive
* include/abg-traverse.h (traversable_base::traversable): Change
	the signature of this to return a boolean.
	* include/abg-ir.h (ir_traversable_base::traverse): Change the
	signature of this to return a boolean.
	(*::traverse): Adjust.
	(ir_node_visitor::visit): Change the signature of this to return a
	boolean.
	* src/abg-corpus.cc (symtab_build_visitor_type::visit): Adjust.
	* src/abg-ir.cc (::traverse): Adjust.
	* tests/test-walker.cc (name_printing_visitor::visit): Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-03-27 13:01:17 +01:00
Dodji Seketeli
5558174054 Dynamically wire class_decl::base_spec hashing
* include/abg-ir.h (decl_base::get_hash): Make this virtual.
	(class_decl::base_spec::get_hash): Declare a new virtual overload.
	* src/abg-ir.cc (class_decl::base_spec::get_hash): Define.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-03-20 13:34:00 +01:00
Dodji Seketeli
40a0d8c854 Get rid of class_decl::member_function
* include/abg-fwd.h (is_member_function)
	(get_member_function_is_{ctor,dtor,const})
	(get_member_function_vtable_offset): New function declarations.
	* include/abg-ir.h (class_decl::member_function): Remove.
	(class_decl::member_functions): Adjust.  This is now just a vector
	of method_decl_sptr.
	(class_decl::add_member_function): Remove the overload taking
	class_decl::member_function.  Adjust the other overload to take a
	method_decl_sptr.
	(class mem_fn_context_rel): New class.
	(class_decl::method_decl::set_scope): New virtual overload.
	(class_decl::member_function): Remove.
	(operator==): Remove the overload taking a
	class_decl::member_function.
	(class_decl::member_function::hash): Remove.
	(ir_node_visitor::visit): Remove the overload taking a
	class_decl::member_function.
	* include/abg-comparison.h (changed_member_function_sptr)
	(string_member_function_sptr_map): Adjust.
	* src/abg-comparison.cc (represent): Adjust the overload taking a
	class_decl::member_function to take a class_decl::method_decl.
	(class_diff::{report, ensure_lookup_tables_populated}): Adjust.
	* src/abg-corpus.cc (symtab_build_visitor_type::visit): Remove the
	overload taking a class_decl::member_function.
	* src/abg-dwarf-reader.cc (build_class_type_and_add_to_ir):
	Adjust.
	* src/abg-hash.cc (decl_base:#️⃣:operator()): Use the fully
	qualified name of the decl in the hash, to increase the likelihood
	of avoiding hash collisions.
	(method_type:#️⃣:operator()): Likewise.
	(function_decl:#️⃣:operator()): Take member functions in
	account.
	(class_decl::member_function:#️⃣:operator()): Remove.
	(class_decl:#️⃣:operator()): Adjust.
	(type_base::dynamic_hash::operator()): Adjust.
	* src/abg-ir.cc (is_member_function)
	(get_member_function_is_{ctor,dtor,const})
	(get_member_function_vtable_offset): New function definitions.
	(function_decl::get_pretty_representation): Adjust.
	(function_decl::operator): Take member functions in account here.
	(class_decl::insert_member_decl): Adjust.
	(mem_fn_context_rel::~mem_fn_context_rel): New definition.
	(class_decl::member_function::*): Remove.
	(class_decl::method_decl::set_scope): New definition.
	(class_decl::get_num_virtual_functions): Adjust.
	(class_decl::add_member_function): Remove overload taking a
	class_decl::member_function.  Define a new overload taking a
	class_decl::method_decl.
	(ir_node_visitor::visit): Remove the overload taking a
	class_decl::member_function.
	* src/abg-reader.cc (build_class_decl): Adjust.
	* src/abg-writer.cc (write_voffset, write_class_decl): Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-03-20 12:21:36 +01:00
Dodji Seketeli
ed5cd14a34 Get rid of class_decl::data_member
* include/abg-fwd.h (has_scope): Delete the overloads for
	type_base.
	(get_member_is_static): Add an overload for decl_base*.
	({is,get,set}_data_member,{get_,set}_data_member_is_laid_out)
	({get,set}_data_member_offset): New access declarations.
	* include/abg-ir.h (class context_rel): Move up.
	(decl_base::set_context_rel): New definition.
	(class dm_context_rel): New type.
	(decl_base::hash_as_member): Remove.
	(var_decl::set_scope): Declare new virtual member.
	(class_decl::data_member): Remove.
	(ir_node_visitor::visit): Remove the overload for
	class_decl::data_member.
	(represent_data_member): Remove the represent overload for
	class_decl::data_member into this.  Make it take a var_decl.
	(represent): Change the overload that takes two
	class_decl::data_member take two var_decl.  And adjust it.
	(class_diff::report): Adjust.
	* src/abg-corpus.cc (symtab_build_visitor_type::visit): Remove the
	overload that takes a class_decl::data_member*.  Adjust the
	overload that takes a var_decl to recognize (static) data members.
	* src/abg-dwarf-reader.cc (build_translation_unit_and_add_to_ir)
	(build_class_type_and_add_to_ir, build_ir_node_from_die):
	Adjust.
	* src/abg-hash.cc (var_decl:#️⃣:operator()): Adjust.
	(class_decl::data_member:#️⃣:operator()): Remove.
	(decl_base:#️⃣:operator()): Take the context relationship in
	account here.
	(decl_base::hash_as_member::operator()): Remove.
	({enum_type_decl,typedef_decl}:#️⃣:operator()): Adjust.
	(class_decl::member_function:#️⃣:operator()): Adjust.
	(type_base::dynamic_hash::operator()): Adjust.
	* src/abg-ir.cc (dm_context_rel::~dm_context_rel): New definition.
	(has_scope): Remove overload for type_base.
	(get_member_is_static): New overload for decl_base*.
	(is_data_member): New function definition.
	({get,set}_data_member_{offset,is_laid_out}): Define new
	accessors.
	(var_decl::set_scope): Define new member function.  Make this set
	a dm_context_rel as the context relationship.
	(var_decl::operator==): Adjust to take in account the new data
	member relationship.
	(class_decl::class_decl): Adjust.
	(class_decl::insert_member_decl): Adjust.
	(class_decl::add_data_member): Remove the overload for
	class_decl::data_member.
	(class_decl::add_data_member): Adjust the overload for var_decl.
	(operator==): Remove overload for class_decl::data_member*.
	(class_decl::data_member::operator==): Likewise.
	(ir_node_visitor::visit): Remove overload for
	class_decl::data_member.
	* src/abg-writer.cc (write_layout_offset, write_class_decl):
	Adjust.
	* tests/data/test-read-write/test20.xml: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-03-19 21:18:38 +01:00
Dodji Seketeli
661f76c8f4 Better base class diff reporting
* include/abg-comparison.h (class base_diff): New.
	* include/abg-ir.h (function_decl::get_first_non_implicit_parm):
	New member function.
	(function_type::get_first_non_implicit_parm): Likewise.
	* src/abg-comparison.cc (base_has_changed): Change parm to take
	class_decl::base_spec_sptr.
	(class_diff::ensure_lookup_tables_populated): Compare the base
	specs not just the base classes.
	(class_diff::report): Adjust.  Report sub-type changes in the
	member functions.
	(base_diff::*): Define member functions.
	(compute_diff): Define an overload for base_diff_sptr.
	* src/abg-hash.cc ({function_type,
	method_type}:#️⃣:operator()): Do not hash the implicit parm of
	member functions.
	(class_decl:#️⃣:operator()):  Do not hash member types.
	* src/abg-ir.cc (decl_base::decl_base): Initialize the
	hashing_started_ member that got moved here from class_decl.
	(decl_base::get_hash): Do not set the hash if it's being set b/c
	we are in a class_decl.
	(decl_base::operator==) Do not compare hashes for now.  Two decls
	can have different hashes and compare equal; think about an
	incomplete type foo, that compares equal with a complete foo.
	Their hashes will be different though.  So for now, just avoid
	comparing these.
	(compare_function_types): Avoid comparing the implicit parameter
	for member functions.
	({function, method}_type::get_first_non_implicit_parm): New
	definition.
	* tests/data/test-read-write/test20.xml: Update.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-03-18 11:27:02 +01:00
Dodji Seketeli
ca53b99c5a Use the same representation for member and non-member types
* include/abg-fwd.h (is_at_class_scope): Add new oveloads.
	(as_non_member_type, as_non_member_class_decl): Remove.
	(has_scope, is_member_decl, is_member_type): New function
	declarations.  (get_member_is_static, set_member_is_static):
	Likewise.  * include/abg-ir.h (enum access_specifier): Move to
	the abigail:: namespace, from ...
	(class_decl::access_specifier): ... here.  (class
	context_rel): New type.  (decl_base::hash_as_member): New
	hasher.  (decl_base::context_): Change the type of this to
	context_rel_sptr.  (decl_base::get_context_rel): New protected
	getter.  (decl_base::get_scope): Move this out-of-line.
	(class_decl::member_type): Remove.
	(class_decl::member_types): Adjust this typedef.
	(class_decl::{insert,add}_member_type): Make these take a
	type_base_sptr now.  (class_decl::add_member_type): Change the
	overload that returned a member_type to return a
	type_base_sptr.  (get_member_access_specifier,
	set_member_access_specifier): New function declarations.  *
	include/abg-comparison.h (class member_type_diff): Remove.
	(compute_diff): Remove the overload for member_type_diff.  *
	src/abg-comparison.cc (compute_diff_for_types): Adjust for the
	removal of class_decl::member_type.
	(maybe_report_diff_for_class_members): New static function.
	(report_name_size_and_alignment_changes): Do not report a name
	change just because of a struct -> class change.  ({var_diff,
	enum_diff, function_decl_diff}::report): Use the new
	maybe_report_diff_for_class_members.  (class_diff::report):
	Adjust for the removal of class_decl::member_type.  Use the
	new maybe_report_diff_for_class_members.  (class member_diff):
	Remove.  * src/abg-dwarf-reader.cc (die_access_specifier)
	(get_scope_for_die, build_translation_unit_and_add_to_ir)
	(build_class_type_and_add_to_ir, build_function_decl)
	(build_ir_node_from_die): Adjust.  * abg-hash.cc (struct
	decl_base::hash_as_member): Define.  ({scope_type_decl,
	enum_type_decl, typedef_decl}:#️⃣:operator()): Use the
	decl_base::hash_as_member.
	* src/abg-ir.cc (decl_base::decl_base): Adjust.
	(decl_base::get_scope): New out-of-line getter.
	(decl_base::{operator==, set_scope): Adjust.
	(has_scope, is_member_decl, is_member_type)
	(get_member_access_specifier, set_member_access_specifier)
	(get_member_is_static, set_member_is_static, is_at_class_scope):
	New function definitions.
	(as_non_member_type, as_non_member_class_decl): Remove.
	(get_node_name): Adjust.
	(class_decl::{class_decl, set_earlier_declaration,
	insert_member_decl, insert_member_type, add_member_type):
	Likewise.
	(class_decl::member_type::*) Remove.
	* src/abg-reader.cc (read_access, build_qualified_type_decl)
	(build_reference_type_def, build_typedef_decl)
	(build_class_decl): Adjust.
	* src/abg-writer.cc (write_access, write_member_type)
	(write_class_decl): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-03-13 11:13:54 +01:00
Dodji Seketeli
df7c672219 Allow adding members to decl-only classes making them defined classes
* include/abg-fwd.h (lookup_type_in_scope)
	(lookup_var_decl_in_scope): New declarations.
	* include/abg-ir.h (class_decl::get_is_declaration_only): Rename
	is_declaration_only on this.
	(class_decl::set_is_declaration_only):
	* src/abg-comparison.cc (try_to_diff<class_decl>)
	(class_diff::ensure_lookup_tables_populated)
	(scope_diff::ensure_lookup_tables_populated): Update for the
	get_is_declaration_only renaming.
	* src/abg-dwarf-reader.cc (get_scope_for_die): Likewize.
	(build_class_type_and_add_to_ir): Make sure that a member type or
	data member is not already present in the class before adding it.
	Also, if a decl-only class gets a data member, it's not a
	decl-only class anymore.
	* src/abg-hash.cc (class_decl:#️⃣:operator()): Update for the
	get_is_declaration_only renaming.
	* src/abg-ir.cc (scope_decl::find_iterator_for_member)
	(look_through_decl_only_class): Likewise.
	(lookup_type_in_scope, lookup_var_decl_in_scope, get_node_name)
	(convert_node_to_decl, lookup_node_in_scope)
	(lookup_type_in_scope): New definitions.
	(class_decl::{set_definition_of_declaration,
	set_earlier_declaration, operator==}): Update for the
	get_is_declaration_only renaming.
	* src/abg-reader.cc (build_class_decl): Likewise.
	* src/abg-writer.cc (write_class_is_declaration_only): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-03-12 16:26:14 +01:00
Dodji Seketeli
1c6f62bad7 Tell struct and class apart
* include/abg-ir.h (class_decl::is_struct_): New member.
	(class_decl::class_decl): Take an additional is_struct member.
	(class_decl::is_struct): New getter.
	* src/abg-ir.cc (class_decl::class_decl): Initialize the new
	is_struct_ data member.
	(class_decl::get_pretty_representation): Tell struct and class
	apart.
	* abg-reader.cc (read_is_struct): New static function.
	(build_class_decl): Capture the struct-ness of the class.
	* src/abg-dwarf-reader.cc (build_class_type_and_add_to_ir):
	Likewise.
	* src/abg-writer.cc (write_is_struct): New static function.
	(write_class_decl): Write the struct-ness of the class.
	* tests/data/test-read-dwarf/test1.abi: Update test.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-03-10 10:04:34 +01:00
Dodji Seketeli
6c34ffd67e Fix function parameter addition/deletion/change detection
* include/abg-ir.h (function_decl::parameter::get_name_id):
	Declare new entry point.
	* src/abg-comparison.cc
	(function_decl_diff::ensure_lookup_tables_populated): Use the new
	function_decl::parameter::get_name_id() for the unique name of the
	parameter.  Also, fix a little logic error: if a parm is deleted
	and inserted, in all cases, consider it as not deleted.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-28 15:00:34 +01:00
Dodji Seketeli
5f7ce682e2 Constify function_decl::parameter::get_type_pretty_representation()
* include/abg-ir.h
	(function_decl::parameter::get_type_pretty_representation): This
	is now const.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-28 10:42:46 +01:00
Dodji Seketeli
fb2de7bb71 Improve API doc for the location machinery
* include/abg-ir.h (class location): Improve doc.
	(decl_base::{get,set}_location): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-28 10:26:00 +01:00
Dodji Seketeli
aa7ac96d62 Fix the support for printing cv-qualified names
* include/abg-ir.h (decl_base::{location_, name_,
	qualified_parent_name_, qualified_name_}): Make these data members
	protected rather than private.
	(decl_base::get_qualified_parent_name): Declare new member
	functions.
	(decl_base::get_qualified_name): Make the core overload virtual.
	Simplify the other overload that calls the core one.
	(qualified_type_def::build_name): Declare new protected helper
	function.
	(qualified_type_def::{get_cv_quals_string_prefix,
	get_qualified_name}): Declare new functions.
	(pointer_type_def::{get_qualified_name}}): Likewise.
	(class_decl::member_type::get_qualified_name): Likewise.
	* src/abg-ir.cc (decl_base::get_qualified_parent_name): New
	definition.
	(decl_base::get_name): Make this out-of-line.
	(decl_base::get_qualified_name): The signature of this got
	simplified.  Make it use the new get_qualified_parent_name.
	(qualified_type_def::{build_name, get_qualified_name,
	get_cv_quals_string_prefix}): New definitions.
	(qualified_type_def::qualified_type_def): Update the constructor
	to use the new build_name function above.
	(pointer_type_def::get_qualified_name): New definitions.
	(reference_type_def::get_qualified_name): Likewise.
	(class_decl::member_type::get_qualified_name): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-21 17:02:13 +01:00
Dodji Seketeli
56973d0ac3 Put the setter of access specifiers in class_decl::member_base
* include/abg-ir.h
	(class_decl::member_base::set_access_specifier): Put the setter
	for access specifier here, where it belongs ...
	(class_decl::member_type::set_access_specifier): ... not here.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-21 17:02:13 +01:00
Dodji Seketeli
bce6bba514 Do not forget to set the indexes of fn parms
* include/abg-ir.h (function_type::function_type): In the
	constructor that takes a vector of parms, walk the vector and set
	the indexes of the parms.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-21 14:22:18 +01:00
Dodji Seketeli
1046ba96e6 Unset decl scope when removing the decl from its scope
* src/abg-ir.cc (remove_decl_from_scope): Unset the scope of the
	decl.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-19 22:44:49 +01:00
Dodji Seketeli
278520086e Add class_decl::member_base::set_is_static() accessor
* include/abg-ir.h (class_decl::member_base::get_is_static):
	Rename is_static into get_is_static.
	(class_decl::member_base::set_is_static): New accessor.
	* src/abg-comparison.cc (represent): Adjust for
	class_decl::member_base::is_static -> get_is_static.
	* src/abg-corpus.cc (symtab_build_visitor_type::visit): Likewise.
	src/abg-hash.cc (class_decl::member_function:#️⃣:operator()):
	Likewise.
	* src/abg-ir.cc (class_decl::member_base::operator==): Likewise.
	* src/abg-writer.cc (write_class_decl): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-19 16:04:45 +01:00
Dodji Seketeli
9b1e3cd86a Do not forget to traverse member types
* include/abg-ir.h (class_decl::member_type::traverse): Declare new virtual
	function.
	(ir_node_visitor::visit): Declare new virtual function
	* src/abg-ir.cc (class_decl::member_type::traverse): Implement the
	traversal of a member type.
	(ir_node_visitor::visit): Provide a default implementation for the
	visitor of member type.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-11 16:14:53 +01:00
Dodji Seketeli
a5b80d8203 Fix access specifiers value
* include/abg-ir.h (class_decl::enum access_specifier): Give the enumerators
	the same values as what the DWARF spec says.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-11 15:59:12 +01:00
Dodji Seketeli
67829e0daa Misc diff report cleanups
* include/abg-ir.h (function_decl::parameter::get_type_name): Add
	comment.
	(function_decl::parameter::get_type_pretty_representation): New
	member fn.
	* src/abg-comparison.cc (represent): When representing changed
	members, use their pretty representation.
	(function_decl_diff::{ensure_lookup_tables_populated, report}): Use the
	pretty representation of parameters type.
	(typedef_diff::report): Enclose the underlying type in "'".
	(corpus_diff::report): Add proper spacing.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-10 21:31:19 +01:00
Dodji Seketeli
ce9a34ba92 More optimizations hinted by profiling
* include/abg-ir.h (decl_base::qualified_name_): New member.
	(decl_base::get_qualified_name): Cache the qualified name.
	(decl_base::get_type): Return a reference on the shared pointer.
	(method_type::get_class_type): Likewise.
	(class_decl::get_definition_of_declaration): Likewise.
	(class_decl::member_type::get_underlying_type): Likewise.
	(class_decl::base_spec::get_base_class): Likewise.
	* src/abg-ir.cc (decl_base::get_qualified_name): Implement the
	caching.
	(class_decl::member_type::get_qualified_name): Return a reference
	on the shared pointer.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-10 15:51:10 +01:00
Dodji Seketeli
d8046e575d Avoid crashing when getting function parm type name
* include/abg-ir.h (function_decl::parameter::get_type_name): New
	member function.
	* src/abg-comparison.cc
	(function_decl_diff::ensure_lookup_tables_populated): Use the new
	member function above.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-10 15:51:10 +01:00
Dodji Seketeli
cb764d3cdf Misc style fixes
* include/abg-hash.h (combine_hashes): Remove trailing white
	spaces.
	* include/abg-ir.h (class function_decl): Add end-of-class
	comment.
	(struct type_base::cached_hash): Fix comment.
	* src/abg-comparison.cc: Remove useless new line.
	* src/abg-corpus.cc: Likewise.
	* src/abg-writer.cc: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-10 15:51:10 +01:00