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>
This commit is contained in:
Dodji Seketeli 2014-06-23 17:24:54 +02:00
parent 3e215cc737
commit 01cd814bbc
8 changed files with 67 additions and 5 deletions

View File

@ -886,6 +886,9 @@ public:
location locus, const std::string& mangled_name = "",
visibility vis = VISIBILITY_DEFAULT);
static type_decl_sptr
get_void_type_decl();
virtual bool
operator==(const type_base&) const;

View File

@ -1970,6 +1970,9 @@ build_ir_node_from_die(read_context& ctxt,
bool called_from_public_decl,
size_t where_offset);
static decl_base_sptr
build_ir_node_for_void_type(read_context& ctxt);
static function_decl_sptr
build_function_decl(read_context& ctxt,
Dwarf_Die* die,
@ -4554,14 +4557,17 @@ build_pointer_type_def(read_context& ctxt,
if (tag != DW_TAG_pointer_type)
return result;
decl_base_sptr utype_decl;
Dwarf_Die underlying_type_die;
if (!die_die_attribute(die, DW_AT_type, underlying_type_die))
return result;
// If the DW_AT_type attribute is missing, that means we are
// looking at a pointer to "void".
utype_decl = build_ir_node_for_void_type(ctxt);
decl_base_sptr utype_decl =
build_ir_node_from_die(ctxt, &underlying_type_die,
called_from_public_decl,
where_offset);
if (!utype_decl)
utype_decl = build_ir_node_from_die(ctxt, &underlying_type_die,
called_from_public_decl,
where_offset);
if (!utype_decl)
return result;
@ -5321,6 +5327,20 @@ build_ir_node_from_die(read_context& ctxt,
return result;
}
/// Build the IR node for a void type.
///
/// @param ctxt the read context to use.
///
/// @return the void type node.
static decl_base_sptr
build_ir_node_for_void_type(read_context& ctxt)
{
decl_base_sptr t = type_decl::get_void_type_decl();
if (!has_scope(t))
add_decl_to_scope(t, ctxt.cur_tu()->get_global_scope());
return t;
}
/// Build an IR node from a given DIE and add the node to the current
/// IR being build and held in the read_context. Doing that is called
/// "emitting an IR node for the DIE".

View File

@ -3066,6 +3066,18 @@ type_decl::type_decl(const std::string& name,
{
}
/// Get a singleton representing a void type node.
///
/// @return the void type node.
type_decl_sptr
type_decl::get_void_type_decl()
{
static type_decl_sptr void_type_decl;
if (!void_type_decl)
void_type_decl.reset(new type_decl("void", 0, 0, location()));
return void_type_decl;
}
/// Return true if both types equals.
///
/// This operator re-uses the overload that takes a decl_base.

View File

@ -177,6 +177,10 @@ tests/data/test-read-dwarf/test2.so \
tests/data/test-read-dwarf/test2.so.abi \
tests/data/test-read-dwarf/test3.c \
tests/data/test-read-dwarf/test3.so \
tests/data/test-read-dwarf/test4.c \
tests/data/test-read-dwarf/test4.so \
tests/data/test-read-dwarf/test5.cc \
tests/data/test-read-dwarf/test5.so \
\
data/test-diff-filter/test0-v0.cc \
data/test-diff-filter/test0-v1.cc \

View File

@ -0,0 +1,6 @@
/// Compile this by doing g++ -g -Wall -c test5.cc
void
bar(void*)
{
}

Binary file not shown.

View File

@ -0,0 +1,12 @@
<abi-corpus path='data/test-read-dwarf/test5.o'>
<elf-function-symbols>
<elf-symbol name='_Z3barPv' type='func-type' binding='global-binding' is-defined='yes'/>
</elf-function-symbols>
<abi-instr version='1.0' address-size='64' path='test.cc'>
<type-decl name='void' id='type-id-1'/>
<pointer-type-def type-id='type-id-1' size-in-bits='64' alignment-in-bits='64' id='type-id-2'/>
<function-decl name='bar' mangled-name='_Z3barPv' filepath='/home/dodji/libabigailtests/test.cc' line='2' column='1' visibility='default' binding='global' size-in-bits='64' alignment-in-bits='64' elf-symbol-id='_Z3barPv'>
<parameter type-id='type-id-2'/>
</function-decl>
</abi-instr>
</abi-corpus>

View File

@ -75,6 +75,11 @@ InOutSpec in_out_specs[] =
"data/test-read-dwarf/test4.so.abi",
"output/test-read-dwarf/test4.so.abi"
},
{
"data/test-read-dwarf/test5.o",
"data/test-read-dwarf/test5.o.abi",
"output/test-read-dwarf/test5.o.abi"
},
// This should be the last entry.
{NULL, NULL, NULL}
};