Commit Graph

2099 Commits

Author SHA1 Message Date
Dodji Seketeli
4ca76c4658 Misc style fixes
* include/abg-writer.h (write_translation_unit): Re-indent parms.
	* src/abg-writer.cc (write_translation_unit): Likewise.
	* test/test-read-write.cc (main): Fix white space.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-07 14:07:14 +01:00
Dodji Seketeli
aafb86f595 Fix global variables diff reporting in corpus-es
* src/abg-comparison.cc
	(corpus_diff::priv::ensure_lookup_tables_populated): Fix a wrong
	assert, resulting from a copy paste typo.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-06 17:38:13 +01:00
Dodji Seketeli
0d66442b8b Add support for global variables in corpus diffing
* include/abg-comparison.h (string_var_ptr_map, changed_var_ptr)
	(string_changed_var_ptr_map): New convenience typedefs.
	* src/abg-comparison.cc
	(corpus_diff::priv::{deleted_vars_,added_vars_,changed_vars_}):
	New members.
	(corpus_diff::priv::{lookup_tables_empty, clear_lookup_tables}):
	Update wrt the new variables related lookup tables.
	(corpus_diff::ensure_lookup_tables_populated): Update to populate
	variables related lookup tables.
	(corpus_diff::report): Update to display added/removed/changed
	variables.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-06 16:01:55 +01:00
Dodji Seketeli
a41b741118 Misc style fixlets
* include/abg-comparison.h (changed_function_ptr): Fix comment.
	* src/abg-comparison.cc (corpus_diff::report): Likewise.
	* src/abg-corpus.cc (corpus::is_empty): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-06 15:52:25 +01:00
Dodji Seketeli
fbb6b1bc73 Initial support for diffing ABI corpus files
* include/abg-comparison.h (string_function_ptr_map)
	(changed_function_ptr, string_changed_function_ptr_map)
	(corpus_diff_sptr): New convenience typedefs.
	(translation_unit_diff): Add comments.
	(class corpus_diff): New type.
	(compute_diff): New overload for corpus_diff.
	* include/abg-corpus.h (corpus::{functions, variables}): New
	typedefs.
	(corpus::{operator==, get_functions, get_variables}): New members.
	* include/abg-diff-utils.h (struct deep_ptr_eq_functor): New
	functor.
	* include/abg-ir.h (translation_unit::operator==): New member
	equality operator.
	* src/abg-comparison.cc (struct corpus_diff::priv): New private
	struct holding the private members of corpus_diff.
	(corpus_diff::priv::{lookup_tables_empty, clear_lookup_tables,
	ensure_lookup_tables_populated}): Define new private member functions.
	(corpus_diff::{corpus_diff, first_corpus, second_corpus,
	function_changes, variable_changes, length, report}): New public members.
	(struct noop_deleter): New struct.
	(compute_diff): New implementation for corpus_diff.
	* src/abg-corpus.cc (struct corpus::priv): Renamed corpus::impl
	into this.  Add new fns, vars and is_symbol_table_built data
	members.
	(corpus::priv::build_symbol_table): New member function.
	(class symtab_build_visitor_type): New visitor type to build the
	symbol table.
	(struct func_comp, struct var_comp): New comparison functors.
	(corpus::priv::build_symbol_table): Define new member function.
	(corpus::{corpus, add, get_translation_units, operator==,
	get_functions, get_variables}): Define new members.
	* src/abg-ir.cc (translation_unit::operator==): Define new member
	equality operator.
	(operator==(translation_unit_sptr l, translation_unit_sptr r)):
	Define new equality operator.
	* tools/abg-tools-utils.h (enum file_type): New enum.
	(guess_file_type): Declare new function.
	* tools/abg-tools-utils.cc (guess_file_type): define new function.
	* tools/bidiff.cc (main): Guess the type of the files given in
	input and support elf files reading and diffing.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-23 14:05:19 +01:00
Dodji Seketeli
dbc0225415 Generalize use of equality operator in core diff algorithms
* include/abg-diff-utils.h (struct default_eq_functor): New
	equality functor.
	(end_of_fr_d_path_in_k, end_of_frr_d_path_in_k_plus_delta): Add a
	new equality functor template parameter and document it.  Use it
	to compare the elements of the sequences given in argument.
	(compute_middle_snake, ses_len, compute_diff): Add a new equality
	functor template parameter and document it.  Adjust call to
	end_of_frr_d_path_in_k_plus_delta, end_of_fr_d_path_in_k and
	compute_middle_snake.
	(ses_len, compute_diff): Add a new overload that uses a
	default_eq_functor as comparison functor, to avoid breaking
	existing client code.
	* src/abg-diff-utils.cc (compute_middle_snake): Adjust the call to
	the compute_middle_snake.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-23 13:40:14 +01:00
Dodji Seketeli
165434a9d7 Change ir node visitor interface work on pointer to nodes
* include/abg-ir.h (ir_traversable_base): New type to be the base
	of IR nodes that are to be traversed.  Extends traversable_base.
	Its ir_traversable_base::traversable() method takes an
	ir_node_visitor&.
	(ir_node_visitor::visit): Change these virtual overloads to take
	pointers to IR nodes, rather than references.  This will be useful
	to e.g, store these IR nodes in containers on the side for some
	algorithms to work.  That is going to be useful later to,
	e.g. build symbol tables on the side, using the visitor interface.
	(class decl_base): Make this inherit ir_traversable_base.
	* src/abg-ir.cc (*::traverse): Adjust comments and the call the
	ir_node_visitor::visit call.  Use the ir_traversable_base type
	rather than traversable_base.
	(ir_traversable_base::traverse): Define.
	(ir_node_visitor::visit): Change these overloads to take pointers
	rather than reference to ir nodes.
	* tests/test-walker.cc (name_printing_visitor::visit): Adjust to
	take pointers rather than references.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-23 13:25:32 +01:00
Dodji Seketeli
f54bf5526b Do not forget to read function parms
* src/abg-dwarf-reader.cc (build_function_decl): Do not forget the
	the function parameters.  Oops.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-23 12:51:08 +01:00
Dodji Seketeli
6d4015ec75 Support reading member functions and member types from DWARF
* include/abg-ir.h (method_type_sptr): New convenience typedef.
	* src/abg-dwarf-reader.cc (read_context::{dwarf_version,
	die_wip_classes_map}): New accessors.
	(die_is_virtual): Rename is_virtual into this.
	(is_type_tag, is_type_die, die_virtual_function_index): Define new
	static functions.
	(die_member_offset): Fix comment.
	(get_scope_for_die): Take the read context as argument.
	(canonicalize_and_add_type_to_ir): Likewise.  On NULL scope, get
	the current translation unit from the read context.
	(canonicalize_and_insert_type_into_ir_under_scope): Handle NULL
	context.
	(build_function_decl): Support creating method_decls from here
	when necessary.
	(build_class_type_and_add_to_ir): Rename build_class_type into
	this.  Handle adding the class to the IR and to the relevant maps.
	During the creation of the class, arrange for
	build_ir_node_from_die on the current DIE to return a
	declaration-only class, representing the declaration for the class
	that is being constructed.  This breaks circular dependencies
	induced by decls/types that refer to the class being built, before
	the class is fully built and has a (logical) type ID.  Once the
	class is created, make it refer to the class declaration that was
	previously handed for the requests to the class DIE.  Now requests
	to the class DIE will just yield the newly built class.  Add
	support for member functions and member types.
	(build_corpus): Support reading the dwarf version and stick it
	into the context.
	(build_ir_node_from_die): Adjust for change in
	canonicalize_and_add_type_to_ir and build_class_type signature
	change.
	* src/abg-ir.cc (class_decl::method_decl::get_type): Support
	returning NULL type.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-20 16:19:58 +01:00
Dodji Seketeli
3a96067a44 Don't crash in get_global_scope on empty decls
* src/abg-ir.cc (get_global_scope): Don't crash when given a NULL
	decl.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-20 16:17:32 +01:00
Dodji Seketeli
f47b1ffd6d Make decl_base::set_scope virtual, to work on class_decl::member_type
* include/abg-ir.h (decl_base::set_scope): Make this virtual.
	(class_decl::member_type::set_scope): Declare an overload here.
	* src/abg-ir.cc (class_decl::member_type::set_scope): Define new
	overload.  Make this set the scope of the underlying type of the
	member type as well.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-20 16:14:21 +01:00
Dodji Seketeli
118a5df30d Support artificial parameters
* include/abg-ir.h (function_decl::parameter::{get,
	set}_artificial): Add new accessors for an "artificial" flag.
	* src/abg-reader.cc (build_function_parameter): Support reading
	the artificial parameter flag.
	* src/abg-writer.cc (write_function_decl): Support writing the
	artificial parameter flag.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-20 16:08:32 +01:00
Dodji Seketeli
3973bb400b Initial support for reading struct/class
* src/abg-dwarf-reader.cc (enum virtuality): New enum.
	(class expr_result, struct dwarf_expr_eval_context): New types.
	(die_size_in_bits)
	(die_access_specifier, die_virtuality, is_virtual)
	(die_location_expr, op_pushes_constant_value)
	(op_pushes_non_constant_value, op_manipulates_stack)
	(op_is_arith_logic, op_is_control_flow)
	(eval_last_constant_dwarf_sub_expr, die_member_offset)
	(build_class_type): New static functions.
	(build_ir_node_from_die<DW_TAG_{class, structure}_type>): Support
	creating IR node for class and struct by calling the new
	build_class_type.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-19 13:37:07 +01:00
Dodji Seketeli
8841dc17a4 Slight style fix
* src/abg-dwarf-reader.cc (build_qualified_type): Fix indentation.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-19 13:36:29 +01:00
Dodji Seketeli
15ef437155 Be more forgiving when parsing xml from stdin
* src/abg-libxml-utils.cc (xml_istream_input_read): Return the
	byte read count even when the stream seems to be borked.  In that
	case it should be zero.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-19 13:33:30 +01:00
Dodji Seketeli
4605c59587 Don't crash if building pointer/reference yields NULL
* src/abg-dwarf-reader.cc
	(build_ir_node_from_die<DW_TAG_pointer_type)
	(DW_TAG_rvalue{0,1}_reference_type>): Do not crash if building the
	IR node for the underlying type yields NULL.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-19 13:30:30 +01:00
Dodji Seketeli
92687c6a1c Use dwarf_attr_integrate() rather than dwarf_attr()
* src/abg-dwarf-reader.cc (die_string_attribute)
	(die_unsigned_constant_attribute, die_signed_constant_attribute)
	(die_flag_attribute, die_die_attribute): Use dwarf_attr_integrate
	rather than dwarf_attr to look through DW_AT_abstract_origin.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-19 13:27:17 +01:00
Dodji Seketeli
3b59c769ab Support enums
* src/abg-dwarf-reader.cc (build_enum_type): New function.
	(build_ir_node_from_die): Call the new build_enum_type here to
	Handle DW_TAG_enumeration_type DIEs.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-14 22:31:31 +01:00
Dodji Seketeli
5be46a9615 Build & use a DIE -> parent map to avoid emitting useless types
* include/abg-ir.h (translation_unit::{mark_type_as_used,
	prune_unused_types}): Remove these declarations.
	* src/abg-ir.cc (translation_unit::priv::used_types_): Remove.
	(class subtype_marking_visitor): Likewise.
	(translation_unit::{mark_type_as_used, prune_unused_types):
	Likewise.
	(get_top_most_scope_under): Fix logic and add comment.
	* src/abg-dwarf-reader.cc (die_tu_map_type, offset_offset_map):
	New convenience typedefs.
	(read_context::{die_tu_map_, die_parent_map_}): New context
	members.
	(read_context::{die_tu_map, die_parent_map}): New accessors.
	(build_ir_node_from_die): New overload that takes the scope of the
	ir node in parameter.
	(die_signed_constant_attribute): Un-comment this.
	(build_die_parent_relations_under, build_die_parent_map)
	(get_parent_die, get_scope_for_die): New static functions.
	(build_translation_unit_and_add_to_ir): Renamed
	build_translation_unit into this. Populate the new
	read_context::die_tu_map() here.
	(canonicalize_and_add_type_to_ir)
	(canonicalize_and_insert_type_into_ir)
	(canonicalize_and_insert_type_into_ir_under_scope): Move these
	overloads over the top of the file.
	(build_namespace_decl_and_add_to_ir): Fix this by adding the
	namespace to the IR scope of the DIE (using the new
	get_scope_for_die()).  Update the read_context::die_decl_map()
	map.
	(build_function_decl): Support functions that return void.  Also,
	skip parameters that don't have type set.
	(build_corpus): Walk all the DIEs to build a DIE -> parent map.
	Adjust for the rename to build_translation_unit_and_add_to_ir.
	(build_ir_node_from_die): Add a scope parm.  Adjust back to
	building IR nodes only for public decls, unless the
	'called_from_public_decl' flag is set.  Adjust to stick the resulting
	IR node into the scope given in parameter.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-14 22:15:16 +01:00
Dodji Seketeli
8a2cc28f8c Mark sub-types as part of general type marking
* src/abg-ir.cc (subtype_marking_visitor): New visitor.
	(translation_unit::mark_type_as_used): When marking a composite
	type as used, mark its sub-types as well.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-14 11:06:17 +01:00
Dodji Seketeli
96597e61ab Add missing virtual keywords for traverse() method
* include/abg-ir.h ({translation_unit, decl_base, scope_decl,
	type_decl, namespace_decl, qualified_type_decl, pointer_type_def,
	reference_type_def, enum_type_decl, typedef_decl, var_decl,
	function_tdecl, class_decl, class_decl::data_member,
	class_decl::member_function, class_decl::member_function_template,
	class_decl::member_class_template}::traverse): Add a virtual
	keyword at least to "document" that this method is virtual -- and
	thus remind the user that it overrides the
	traversable_base::traverse().

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-14 11:00:47 +01:00
Dodji Seketeli
d666251b42 Add a is_type overload
* include/abg-fwd.h (is_type): Declare new overload that takes a
	type reference.
	* src/abg-ir.cc (is_type): Define.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-14 10:03:09 +01:00
Dodji Seketeli
02b1b2a786 Prune types that are not ref'ed by public decls
* include/abg-fwd.h (remove_decl_from_scope): Declare new
	function.
	* include/abg-ir.h (type_base_sptr, decl_base_sptr): Move these
	convenience typedef before the translation_unit declaration.
	(translation_unit::{mark_type_as_used, prune_unused_types}):
	Declare new methods.
	(decl_base::remove_member_decl): Likewise.
	(class_decl::{remove_member_decl, remove_member_type): Likewise.
	* src/abg-dwarf-reader.cc (die_decl_map_type): Change this map
	type so that the value is now a DIE offset, rather than a DIE.
	This is because many times the lifetime of DIEs is shorter than
	the one of the reader_context.  Also, the die offset uniquely
	designates a physical DIE even if several different instances of
	logical DIE might point to it.
	(struct die_hash): Remove this as it's useless now that we store
	DIE offsets in the map.
	(build_translation_unit): Call build_ir_node_from_die w/o setting
	the called_from_public_decl flag.  Prune the types that are not
	used by any public decls.
	(build_namespace_decl_and_add_to_ir): all build_ir_node_from_die
	w/o setting the called_from_public_decl flag.
	(build_ir_node_from_die): Change the only_public_decl flag into a
	called_from_public_decl flag.  Mark types used by public decls as
	such.  Adjust for the parm changes of build_qualified_type
	build_pointer_type_def, build_reference_type, and
	build_typedef_type.
	(build_qualified_type, build_pointer_type_def)
	(build_reference_type, build_typedef_type): Take a new
	called_from_public_decl.  Pass it to build_ir_node_from_die.
	(build_var_decl): Call build_ir_node_from_die with the
	called_from_public_decl flag set to true to flag the types
	referenced by this variable as being used.
	(build_function_decl): Take a called_from_public_decl flag as
	well, as this function can now call build_function_decl itself to
	build a function decl out of the value of the DW_AT_specification
	attribute, for DIEs representing function definitions.  Also, flag
	the types referenced by public functions are being used.
	* src/abg-ir.cc (translation_unit::priv::used_types_): New map for
	the used types.
	(translation_unit::{mark_type_as_used, prune_unused_types}):
	Define new methods.
	(scope_decl::remove_member_decl): Likewise.
	(remove_decl_from_scope): Define new function.
	(class_decl::{remove_member_decl, remove_member_type}): Define new
	methods.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-13 18:11:46 +01:00
Dodji Seketeli
643b02fd6a Support reading namespaces
* include/abg-fwd.h (get_global_scope): Return a const
	global_scope.  Add a new overload that takes a naked pointer as
	parm.
	(insert_decl_into_scope, get_top_most_scope_under): Declare new
	entry points.
	* include/abg-ir.h (class decl_base, class scope_decl): Add
	insert_decl_into_scope as a friend of these classes.
	(scope_decl::{insert_decl_into_scope, find_iterator_for_member}):
	Declare new member.
	(scope_decl::get_member_decls): New non-const overload.
	* src/abg-dwarf-reader.cc (build_translation_unit): Remove the
	"recurse" parameter.  Adjust the call to build_ir_node_from_die to
	read just public decls that are at namespace scope.  Anything else
	should be dropped unless it's needed to emitting the public
	namespace-level decls.
	(build_namespace_decl_and_add_to_ir)
	(canonicalize_and_insert_type_into_ir): Define new static
	functions.
	(build_corpus): Adjust ad build_translation_unit doesn't have the
	"recurse" parameter anymore.
	(canonicalize_and_add_type_to_ir): Make this static.  Fix
	comments.
	(build_ir_node_from_die): Take a new "only_public_decl"
	parameter. For DW_TAG_base_type case, use the new
	canonicalize_and_insert_type_into_ir to insert the type at the
	right place in the global scope making sure it is seen before the
	current scope.  For pointer, references and qualified types, use
	canonicalize_and_insert_type_into_ir to add the type at the same
	scope as its underlying type.  Handle DW_TAG_{namespace,module}
	using the new build_namespace_decl_and_add_to_ir function.  Add
	some vertical spaces and some assertions.
	* src/abg-ir.cc (scope_decl::add_member_decl): Use scope_decl_sptr
	typedef.
	(scope_decl::{insert_member_decl,find_iterator_for_member}):
	Define new methods.
	(insert_decl_into_scope, get_top_most_scope_under): Define new
	functions.
	(get_global_scope): Constify the return type.
	(get_translation_unit): Adjust as get_global_scope now returns a
	const.
	* src/abg-reader.cc (get_translation_unit): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-12 15:40:52 +01:00
Dodji Seketeli
f918fdb0f9 Fix function_decl::parameter::operator==
* include/abg-ir.h (function_decl::parameter::operator==): Support
	empty type, e.g, in presence of a variadic parameter.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-12 15:36:17 +01:00
Dodji Seketeli
faa9ae485c Misc style fixes
* include/abg-ir.h (decl_base::set_visibility): Remove useless
	white space.
	(class scope_decl): Remove useless white space.
	(scope_decl::add_member_decl): Use decl_base_sptr convenience
	typedef.
	(global_scope_sptr, namespace_decl_sptr): New convenience typedef.
	(class global_scope): Remove useless white space.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-12 15:35:09 +01:00
Dodji Seketeli
8323ffbfad Misc style fixes
* src/abg-dwarf-reader.cc (die_string_attribute, is_public_decl)
	(build_translation_unit, build_ir_node_from_die): Fix comments.
	(die_unsigned_constant_attribute, die_signed_constant_attribute)
	(die_loc_and_name): Align parms.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-11 22:19:52 +01:00
Dodji Seketeli
8e49a7d499 Support typedef types
* src/abg-dwarf-reader.cc (build_typedef_type): Define new static
	function.
	(canonicalize_and_add_type_to_ir): Do not crash on NULL input
	type.  Also, add a new overload for smart pointer on scope.
	(build_ir_node_from_die): For DW_TAG_base_type case, adjust as
	canonicalize_and_add_type_to_ir now takes smart pointers on
	scopes.  Support the DW_TAG_typedef case by calling the new
	build_typedef_type.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-11 21:31:03 +01:00
Dodji Seketeli
d1295df59f Support reference types
* src/abg-dwarf-reader.cc (build_pointer_type_def): Do not forget
	to get the proper size of the pointer type.
	(build_reference_type): Define new static function.
	(build_ir_node_from_die): Call build_reference_type for the
	DW_TAG_reference_type and DW_TAG_rvalue_reference_type cases.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-11 20:52:50 +01:00
Dodji Seketeli
a789ed3ae8 Support pointer types
* include/abg-fwd.h (get_translation_unit, get_global_scope):
	Declare new overloads that act on a naked pointer to decl_base.
	* src/abg-dwarf-reader.cc (build_pointer_type_def): Define new
	static function.
	(canonicalize_and_add_type_to_ir): Take a naked pointer to
	scope_decl rather than a smart pointer.
	(build_ir_node_from_die): For DW_TAG_base_type, adjust.  Support
	DW_TAG_pointer_type case.  For DW_TAG_{const,volatile}_type case,
	make sure the qualified type is in the same scope as its
	underlying type.
	* src/abg-ir.cc (get_global_scope, get_translation_unit): Define
	new overloads that acts on a naked decl_base.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-11 20:28:18 +01:00
Dodji Seketeli
ae29e1e3e5 Support qualified types
* src/abg-dwarf-reader.cc (build_qualified_type)
	(canonicalize_and_add_type_to_ir): Define new static functions.
	(build_ir_node_from_die): In the DW_TAG_base_type case, use the
	new canonicalize_and_add_type_to_ir which is a factorization of
	this code.  In the DW_TAG_{const,volatile}_type, use the new
	build_qualified_type and canonicalize_and_add_type_to_ir
	functions.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-11 17:33:35 +01:00
Dodji Seketeli
6be3b8f4fe Support reading public functions from DWARF
* src/abg-dwarf-reader.cc (read_context::dwarf_): New member.
	(read_context::load_debug_info): Move the content of
	load_debug_info_from_elf here.
	(read_context::dwarf): New accessor for the dwarf_ member above.
	(die_flag_attribute, die_loc_and_name, is_public_decl)
	(build_function_decl): New static functions.
	(die_location): Do not try to create a location object when the
	location has empty file or empty line number.
	(build_translation_unit): Take a new address_size parameter.
	(build_type_decl): Really take a context parameter.  Use the new
	die_loc_and_name() here.
	(build_var_decl): Skip non-public vars.
	(build_corpus): Use dwarf_nextcu instead of dwfl_nextcu, so that
	we can get the address_size used in the current CU.  Note that for
	this we are getting the Dwarf* pointer from the context thanks to
	the new read_context::dwarf() getter.  Adjust the call to
	build_translation_unit to pass it the new address_size.
	(build_ir_node_from_die): Shorten lines a little bit.  Call the
	new build_function_decl to support reading DW_TAG_subprogram DIEs.
	(read_corpus_from_elf): Adjust to create the read context earlier
	and use its read_context::load_debug_info method to load the debug
	info.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-11 15:56:38 +01:00
Dodji Seketeli
7350cfd893 Make bilint read input from stdin
* include/abg-libxml-utils.h (new_reader_from_istream): Declare
	new public entry point.
	* src/abg-libxml-utils.cc (xml_istream_input_read)
	(xml_istream_input_close): New static functions.
	(new_reader_from_istream): Define new public input function.
	* include/abg-reader.h (read_translation_unit_from_istream):
	Declare new entry points.
	* src/abg-reader.cc (read_translation_unit_from_istream): Define
	new entry points.
	* tools/bilint.cc (options::{read_from_stdin, noout}): New
	members.
	(display_usage): Document --stdin and --noout.
	(parse_command_line): Adjust to consider that no option on the
	command line means reading from stdin, just like --stdin.  Support
	the --noout option as well.
	(main): Support Read the abi instr from stdin; in that case, what
	was read is just serialized back to stdout, unless --noout was
	supplied.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-11 15:20:42 +01:00
Dodji Seketeli
d3929eaf23 Support the "address-size" attribute for <abi-instr> elements
* include/abg-ir.h (translation_unit::translation_unit): Take an
	address_size parameter.
	(translation_unit::{get_address_size, set_address_size}): New
	accessors.
	* src/abg-ir.cc (translation_unit::priv::address_size_): New
	private member.
	(translation_unit::translation_unit): Take an address_size
	parameter.
	(translation_unit::{get_address_size, set_address_size}): Define
	these new methods.
	* src/abg-reader.cc (read_input): Read the "address-size"
	attribute from the abi-instr element.
	* src/abg-writer.cc (write_translation_unit): Write the
	"address-size" attribute.
	* tests/data/test-read-write/test23.xml: New test input.
	* tests/test-read-write.cc (in_out_specs): Add the new test above
	to the list of files to read and write back.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-11 12:30:19 +01:00
Dodji Seketeli
61b13cc9db Support variadic arguments in function decls
* src/abg-reader.cc (build_function_parameter): Support reading
	the "is-variadic" attribute.
	* src/abg-writer.cc (write_function_decl): Support writing the
	"is-variadic" attribute.
	* tests/data/test-read-write/test22.xml: New test input.
	* tests/test-read-write.cc (in_out_specs): Add the new test to the
	list of files to read and write back.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-11 12:17:55 +01:00
Dodji Seketeli
bd1af4cd52 Initial support of reading an ABI Corpus from DWARF
* configure.ac: Check the presence of libdw.so and
	elfutils/libdwfl.h headers from elfutils and define the necessary
	linking flags.
	* include/abg-dwarf-reader.h: New header file
	* include/Makefile.am: Add the new header file to the source
	distribution.
	* src/abg-dwarf-reader.cc:: New file.
	* src/Makefile.am: Add the new file to the source distribution.
	* include/abg-fwd.h (dump): Add declarations for several overloads
	to allow dumping to a given output stream.
	* include/abg-ir.h (class translation_unit): Use a pimpl idiom for
	this now.
	(translation_unit::canonicalize_type): Declare new method.
	* src/abg-ir.cc (struct translation_unit::priv): New private type
	for the pimpl idiom for translation_unit.
	(translation_unit::{translation_unit, get_global_scope, get_path,
	set_path, get_loc_mgr}): Adjust for pimpl idiom.
	(translation_unit::canonicalize_type): Define this new method and
	one overload.
	* src/abg-writer.cc (dump): Define several overloads to dump IR
	nodes to given output streams.
	* tools/bidw.cc: New file for the new bidw tool.
	* tools/Makefile.am: Define rules to build the new bidw tools.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-07 08:07:54 +01:00
Dodji Seketeli
96fba7d95f Pass a string by reference rather than by value
* tools/bilint.cc (display_usage): Pass program name by reference.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-07 07:26:06 +01:00
Dodji Seketeli
98681a9327 Misc style fixes
* src/abg-ir.cc (location_manager::location_manager)
	(translation_unit::{is_empty, traverse, ~translation_unit): Remove
	useless vertical white spaces.
	* tools/bilint.cc (parse_command_line): Fix indentation.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-07 07:22:57 +01:00
Dodji Seketeli
6258b5f824 Prepare serialization API for multiple backends
* include/abg-reader.h: New file with abigail::xml_reader APIs.
	* include/abg-writer.h: New file with abigail::xml_writer APIs.
	* include/Makefile.am: Add the new files above to the source
	distribution.
	* src/abg-reader.cc: Update top-file comments.
	(namespace xml_reader): Rename namespace
	reader into this.
	(read_to_translation_unit, read_corpus_from_archive): New static
	functions.
	(read_translation_unit_from_file)
	(read_translation_unit_from_file, read_corpus_from_file): New
	entry points.
	(struct array_deleter): New functor.
	(translation_unit::read): Remove this.
	* src/abg-writer.cc: Update top file comments.
	(namespace xml_writer): Rename namespace
	writer into this.
	(struct archive_write_ctxt): New internal type.
	(create_archive_write_context, write_translation_unit_to_archive)
	(write_translation_unit, write_corpus_to_archive): New low level
	static functions overloads.
	(write_corpus_to_archive, write_translation_unit): Public higher
	level overloads.
	(translation_unit::write): Remove.
	(dump): Update for new xml_writer namespace.
	* include/abg-ir.h (translation_unit::{read, write}): Remove these
	serialization methods.
	* include/abg-corpus.h (corpus_sptr): New convenience typedef.
	(corpus::{read, write}): Remove these methods.
	* src/abg-corpus.cc (corpus::{read, write})
	(corpus::impl::{serialized_tus, archive}): Remove these members.
	(corpus::impl::{get_archive, close_archive, write_tu_to_archive,
	read_to_translation_unit}): Remove these methods.
	* tests/test-bidiff.cc (main): Update for usage of the new
	xml_reader API.
	* tests/test-read-write.cc (main): Likewise. Update for the usage
	of the new xml_writer API, too.
	* tests/test-walker.cc (main): Update for the usage of the new
	xml_reader API.
	* tests/test-write-read-archive.cc (main): Likewise.  And for the
	xml_writer API, too.
	* tools/biar.cc (add_tus_to_archive, extract_tus_from_archive): Likewise.
	* tools/bidiff.cc (main): Likewise, for xml_reader APIs.
	* tools/bilint.cc (main): Likewise, for xml_writer APIs, too.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-04 20:26:38 +01:00
Dodji Seketeli
c5b81de47d Add support for bidiff regression testing
* tests/data/test-bidiff/test-enum0-v0.cc.bi: New input file.
	* tests/data/test-bidiff/test-enum0-v1.cc.bi: Likewise.
	* tests/data/test-bidiff/test-enum0-report.diff: Likewise.
	* tests/data/test-bidiff/test-enum1-v0.cc.bi: Likewise.
	* tests/data/test-bidiff/test-enum1-v1.cc.bi: Likewise.
	* tests/data/test-bidiff/test-enum1-report.txt: Likewise.
	* tests/data/test-bidiff/test-qual-type0-v0.cc.bi: Likewise.
	* tests/data/test-bidiff/test-qual-type0-v1.cc.bi: Likewise.
	* tests/data/test-bidiff/test-qual-type0-report.txt: Likewise.
	* tests/data/test-bidiff/test-struct0-v0.cc.bi: Likewise.
	* tests/data/test-bidiff/test-struct0-v1.cc.bi: Likewise.
	* tests/data/test-bidiff/test-struct0-report.txt: Likewise.
	* tests/data/test-bidiff/test-struct1-v0.cc.bi: Likewise.
	* tests/data/test-bidiff/test-struct1-v1.cc.bi: Likewise.
	* tests/data/test-bidiff/test-struct1-report.txt: Likewise.
	* tests/data/test-bidiff/test-var0-v0.cc.bi: Likewise.
	* tests/data/test-bidiff/test-var0-v1.cc.bi: Likewise.
	* tests/data/test-bidiff/test-var0-report.txt: Likewise.
	* tests/test-bidiff.cc: New file.
	* tests/Makefile.am: Build the new runtestbidiff regression test
	and add the above to the source distribution.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-29 14:32:30 +01:00
Dodji Seketeli
d8882b850c Add missing test inputs to source distribution
* tests/Makefile.am (data/test-read-write/test{17, 18, 19, 20,
	21}.xml): Add these test input files to the source distribution.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-29 13:37:58 +01:00
Dodji Seketeli
0d9ade8ce8 Add diff support for var_decl
* include/abg-comparison.h (class var_diff): New declaration.
	(var_diff_sptr): New convenience typedef.
	(compute_diff): New overloads for var_diff, decl_base and
	type_base.
	* src/abg-comparison.cc (try_to_diff): Renamed try_to_diff_types
	into this.
	(compute_diff_for_types): Adjust for the try_to_diff_types
	renaming.  Fix comments.
	(compute_diff_for_decls): Re-use try_to_diff.  Update for
	var_decl.
	(compute_diff): Define overloads for decl_base, type_base and
	var_decl.
	(diff_length_of_decl_bases, diff_length_of_type_bases): New static
	help functions.
	(report_name_size_and_alignment_changes): Renamed
	report_size_and_alignment_changes into this.  Make it report name
	changes as well.
	(var_diff::priv): New struct.
	(var_diff::{var_diff, first_var, second_var, type_diff, length,
	report}): Define methods.
	({qualified_type_diff, enum_diff, class_diff, scope_diff,
	function_decl_diff}::report): Do not report
	anything if the diff is empty.
	(type_decl_diff::length): Fix this.
	(type_decl_diff::report): Adjust for renaming to
	report_name_size_and_alignment_changes.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-28 15:05:30 +01:00
Dodji Seketeli
0b0dd479d1 Add enum_type_decl::get_pretty_representation()
* include/abg-ir.h (enum_type_decl::get_pretty_representation):
	Declare new virtual method override.
	* src/abg-ir.cc (enum_type_decl::get_pretty_representation):
	Define it.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-28 14:58:11 +01:00
Dodji Seketeli
2e704277e7 Change return type of abigail::is_type()
* include/abg-fwd.h (is_type): Change the return type from bool to
	type_base_sptr.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-28 14:51:23 +01:00
Dodji Seketeli
d186189b43 Support diff for enum_type_decl
* include/abg-ir.h (enum_type_decl_sptr): New typedef.
	(enum_type_decl::enumerator::enumerator): Make default constructor
	public so that enumerators can be stored in vectors.  Maybe I
	should have made stored pointers to enumerators instead ...
	(enum_type_decl::enumerator::get_qualified_name): Define new
	method.
	* include/abg-comparison.h (string_enumerator_map)
	(changed_enumerator, string_changed_enumerator_map)
	(enum_diff_sptr): New convenience typedefs.
	(class enum_diff): Declare new class.
	(compute_diff): New overload for enum_type_decl.
	* src/abg-comparison.cc (enum diff_kind, report_mem_header): Move
	these at the beginning of the file.
	(struct enum_diff::priv): Define this.
	(enum_diff::{clear_lookup_tables, lookup_tables_empty,
	ensure_lookup_tables_populated, enum_diff, first_enum,
	second_enum, underlying_type_diff, deleted_enumerators,
	inserted_enumerators, changed_enumerators, length, report}):
	Define these new methods.
	(compute_diff): New overload for enum_diff.
	(compute_diff_for_types): Add support enum_type_decl here.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-27 11:47:19 +01:00
Dodji Seketeli
cb05c8b3d9 Fix equality operator for enum_type_decl
* src/abg-ir.cc (enum_type_decl::operator==(const type_base& o)):
	This was comparing just the decl_base and type_base part of the
	enum.  Now re-use the enum_type_decl::operator==(const decl_base)
	that compares the entirety of the types.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-27 11:41:51 +01:00
Dodji Seketeli
2340e94a6f Fix indentation and wording of some existing diff reports
* src/abg-comparison.cc (class_diff::report): Fix report wording.
	Change indentation space from 4 white spaces to two.
	(scope_diff::report): Fix logic indentation generation.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-27 10:51:59 +01:00
Dodji Seketeli
abfc86ca6a Change enum_type_decl::enumerators from a list to a vector
* include/abg-ir.h (enum_type_decl::enumerators): Change this from
	a list to a vector.
	* src/abg-hash.cc (enum_type_decl:#️⃣:operator()): Use the
	typedef enum_type_decl::enumerators rather than std::list<blah>.
	* src/abg-ir.cc (enum_type_decl::get_enumerators): Use
	the enum_type_decl::enumerators typedef.
	(enum_type_decl::operator==): Likewise.
	* src/abg-reader.cc (build_enum_type_decl): Likewise.
	* src/abg-writer.cc (write_enum_type_decl): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-26 09:30:22 +01:00
Dodji Seketeli
6f897574f6 Fix thinko in qualified_type_diff::length
* src/abg-comparison.cc (qualified_type_diff::length): Fix thinko.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-25 23:29:36 +01:00
Dodji Seketeli
5ac1090324 Support diff between qualified types
* include/abg-ir.h (qualified_type_def_sptr): Declare new typedef.
	(class qualified_type_def): Add comment at the end.
	(operator<<(std::ostream&, qualified_type_def::CV)): Declare new
	streaming operator.
	* src/abg-ir.cc (operator<<(std::ostream&,
	qualified_type_def::CV)): Define this new streaming operator.
	* include/abg-comparison.h (class qualified_type): Declare new
	class.
	(compute_diff): Declare new overload for qualified_type_def_sptr.
	* src/abg-comparison.cc (struct qualified_type_diff::priv): Define
	new type.
	(qualified_type_diff::{qualified_type_diff, first_qualified_type,
	second_qualified_type, underlying_type_diff, length}):
	Define new methods.
	(get_leaf_type): Define new static function.
	(compute_diff): Define overload for qualified_type_def_sptr.
	(compute_diff_for_types): Add support for
	diffing qualified_type_def here.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-25 23:25:13 +01:00