diff options
| author | Mark Wielaard <[email protected]> | 2010-10-21 00:36:27 +0200 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2010-10-21 00:37:45 +0200 |
| commit | 787a6c725671a313cd5022da2c79437687f7f326 (patch) | |
| tree | 9c5804ee7baf639b16ce24d9f11a0ca17ccc00df /tests | |
| parent | 9b08c6103b45bf986505d1b4eb4dcbab28f14397 (diff) | |
Add dwarf_comparator checks for DIEs to dwarf_edit_output.cc test.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/dwarf_edit_output.cc | 163 |
1 files changed, 147 insertions, 16 deletions
diff --git a/tests/dwarf_edit_output.cc b/tests/dwarf_edit_output.cc index b89bed54..fd42907d 100644 --- a/tests/dwarf_edit_output.cc +++ b/tests/dwarf_edit_output.cc @@ -29,6 +29,7 @@ #include "error.h" +#include "c++/dwarf" #include "c++/dwarf_edit" #include "c++/dwarf_output" #include "c++/dwarf_comparator" @@ -40,6 +41,41 @@ using namespace std; // Only used for testing. #include "print-die.hh" +typedef dwarf_ref_tracker<dwarf_edit, dwarf_edit> cmp_tracker; +struct cmp + : public dwarf_comparator<dwarf_edit, dwarf_edit, false, cmp_tracker> +{ + cmp_tracker _m_tracker; + + cmp () + : dwarf_comparator<dwarf_edit, dwarf_edit, false, cmp_tracker> (_m_tracker) + {} + + bool operator () (const dwarf_edit &a, const dwarf_edit &b) + { + return equals (a, b); + } + + // Customized compare function. Takes two debug_info_entries and + // the dwarf structure they reside in. The first debug_info_entry is assumed + // to reside in the first cu, the debug_info_entry in the next cu. + bool + compare_dies (const dwarf_edit::debug_info_entry &a, + const dwarf_edit::debug_info_entry &b, + const dwarf_edit &dw) + { + dwarf_edit::compile_units::const_iterator cu1, cu2; + cu1 = dw.compile_units ().begin (); + cu2 = dw.compile_units ().begin (); + cu2++; + + cmp_tracker::walk in (&this->_m_tracker, cu1, cu2); + + in.jump (a, b); + return equals (a, b); + } +}; + dwarf_edit & empty_cu (dwarf_edit &in) { @@ -59,19 +95,27 @@ empty_cus (dwarf_edit &in) dwarf_edit & two_same_dies (dwarf_edit &in) { - dwarf_edit::compile_unit &cu = in.add_unit (); - cu.attributes ()[DW_AT_producer].string () = "dwarf_edit_output_test"; + dwarf_edit::compile_unit &cu1 = in.add_unit (); + cu1.attributes ()[DW_AT_producer].string () = "dwarf_edit_output_test"; - dwarf_edit::debug_info_entry::pointer attr1 = cu.add_entry (DW_TAG_base_type); + dwarf_edit::debug_info_entry::pointer attr1 + = cu1.add_entry (DW_TAG_base_type); attr1->attributes ()[DW_AT_name].identifier () = "int"; // XXX Not a dwarf_constant? Prints out wrongly //attr1->attributes ()[DW_AT_encoding].dwarf_constant () = DW_ATE_signed; attr1->attributes ()[DW_AT_byte_size].constant () = 4; - dwarf_edit::debug_info_entry::pointer attr2 = cu.add_entry (DW_TAG_base_type); + dwarf_edit::compile_unit &cu2 = in.add_unit (); + cu2.attributes ()[DW_AT_producer].string () = "dwarf_edit_output_test"; + dwarf_edit::debug_info_entry::pointer attr2 + = cu2.add_entry (DW_TAG_base_type); attr2->attributes ()[DW_AT_name].identifier () = "int"; attr2->attributes ()[DW_AT_byte_size].constant () = 4; + cmp compare; + if (! compare.compare_dies (*attr1, *attr2, in)) + error (-1, 0, "two_same_dies not equal"); + return in; } @@ -113,25 +157,39 @@ var_ref_type_after (dwarf_edit &in) dwarf_edit & dup_same_type_vars (dwarf_edit &in) { - dwarf_edit::compile_unit &cu = in.add_unit (); - cu.attributes ()[DW_AT_producer].string () = "dwarf_edit_output_test"; + dwarf_edit::compile_unit &cu1 = in.add_unit (); + cu1.attributes ()[DW_AT_producer].string () = "dwarf_edit_output_test"; - dwarf_edit::debug_info_entry::pointer type1 = cu.add_entry (DW_TAG_base_type); + dwarf_edit::debug_info_entry::pointer type1 + = cu1.add_entry (DW_TAG_base_type); type1->attributes ()[DW_AT_name].identifier () = "int"; type1->attributes ()[DW_AT_byte_size].constant () = 4; - dwarf_edit::debug_info_entry::pointer type2 = cu.add_entry (DW_TAG_base_type); - type2->attributes ()[DW_AT_name].identifier () = "int"; - type2->attributes ()[DW_AT_byte_size].constant () = 4; - - dwarf_edit::debug_info_entry &var1 = *cu.add_entry (DW_TAG_variable); + dwarf_edit::debug_info_entry &var1 = *cu1.add_entry (DW_TAG_variable); var1.attributes ()[DW_AT_name].identifier () = "var1"; var1.attributes ()[DW_AT_type].reference () = type1; - dwarf_edit::debug_info_entry &var2 = *cu.add_entry (DW_TAG_variable); + dwarf_edit::compile_unit &cu2 = in.add_unit (); + cu2.attributes ()[DW_AT_producer].string () = "dwarf_edit_output_test"; + + dwarf_edit::debug_info_entry::pointer type2 + = cu2.add_entry (DW_TAG_base_type); + type2->attributes ()[DW_AT_name].identifier () = "int"; + type2->attributes ()[DW_AT_byte_size].constant () = 4; + + dwarf_edit::debug_info_entry &var2 = *cu2.add_entry (DW_TAG_variable); var2.attributes ()[DW_AT_name].identifier () = "var2"; var2.attributes ()[DW_AT_type].reference () = type2; + cmp compare; + // Types are equal. + if (! compare.compare_dies (*type1, *type2, in)) + error (-1, 0, "dup_same_type_vars types not equal"); + + // But vars have different names. + if (compare.compare_dies (var1, var2, in)) + error (-1, 0, "two_same_type_vars vars equal"); + return in; } @@ -223,8 +281,76 @@ two_circular_structs (dwarf_edit &in) dwarf_edit & two_circular_structs2 (dwarf_edit &in) { - circular_struct (in); - circular_struct2 (in); + dwarf_edit::compile_unit &cu1 = in.add_unit (); + cu1.attributes ()[DW_AT_producer].string () = "dwarf_edit_output_test"; + + dwarf_edit::debug_info_entry::pointer int_ref1 + = cu1.add_entry (DW_TAG_base_type); + int_ref1->attributes ()[DW_AT_name].identifier () = "int"; + int_ref1->attributes ()[DW_AT_byte_size].constant () = 4; + + dwarf_edit::debug_info_entry::pointer struct_ptr_ref1 + = cu1.add_entry (DW_TAG_pointer_type); + struct_ptr_ref1->attributes ()[DW_AT_byte_size].constant () = 8; + + dwarf_edit::debug_info_entry::pointer list_ptr1 + = cu1.add_entry (DW_TAG_structure_type); + dwarf_edit::debug_info_entry &list1 = *list_ptr1; + list1.attributes ()[DW_AT_name].identifier () = "list"; + list1.attributes ()[DW_AT_byte_size].constant () = 0x10; + + dwarf_edit::debug_info_entry &mi1 = *list1.add_entry (DW_TAG_member); + mi1.attributes ()[DW_AT_name].identifier () = "i"; + mi1.attributes ()[DW_AT_type].reference () = int_ref1; + + dwarf_edit::debug_info_entry &mn1 = *list1.add_entry (DW_TAG_member); + mn1.attributes ()[DW_AT_name].identifier () = "next"; + mn1.attributes ()[DW_AT_type].reference () = struct_ptr_ref1; + + struct_ptr_ref1->attributes ()[DW_AT_type].reference () = list_ptr1; + + dwarf_edit::debug_info_entry &var1 = *cu1.add_entry (DW_TAG_variable); + var1.attributes ()[DW_AT_name].identifier () = "var"; + var1.attributes ()[DW_AT_type].reference () = struct_ptr_ref1; + + // Second CU + + dwarf_edit::compile_unit &cu2 = in.add_unit (); + cu2.attributes ()[DW_AT_producer].string () = "dwarf_edit_output_test"; + + dwarf_edit::debug_info_entry::pointer int_ref2 + = cu2.add_entry (DW_TAG_base_type); + int_ref2->attributes ()[DW_AT_name].identifier () = "int"; + int_ref2->attributes ()[DW_AT_byte_size].constant () = 4; + + dwarf_edit::debug_info_entry::pointer list_ptr2 + = cu2.add_entry (DW_TAG_structure_type); + dwarf_edit::debug_info_entry &list2 = *list_ptr2; + list2.attributes ()[DW_AT_name].identifier () = "list"; + list2.attributes ()[DW_AT_byte_size].constant () = 0x10; + + dwarf_edit::debug_info_entry &mi2 = *list2.add_entry (DW_TAG_member); + mi2.attributes ()[DW_AT_name].identifier () = "i"; + mi2.attributes ()[DW_AT_type].reference () = int_ref2; + + dwarf_edit::debug_info_entry &mn2 = *list2.add_entry (DW_TAG_member); + mn2.attributes ()[DW_AT_name].identifier () = "next"; + + dwarf_edit::debug_info_entry::pointer struct_ptr_ref2 + = cu2.add_entry (DW_TAG_pointer_type); + struct_ptr_ref2->attributes ()[DW_AT_byte_size].constant () = 8; + struct_ptr_ref2->attributes ()[DW_AT_type].reference () = list_ptr2; + + mn2.attributes ()[DW_AT_type].reference () = struct_ptr_ref2; + + dwarf_edit::debug_info_entry &var2 = *cu2.add_entry (DW_TAG_variable); + var2.attributes ()[DW_AT_name].identifier () = "var"; + var2.attributes ()[DW_AT_type].reference () = struct_ptr_ref2; + + cmp compare; + if (! compare.compare_dies (var1, var2, in)) + error (-1, 0, "two_circular_structs2 vars not equal"); + return in; } @@ -291,6 +417,10 @@ var_struct_ptr_type (dwarf_edit &in) var2.attributes ()[DW_AT_name].identifier () = "var"; var2.attributes ()[DW_AT_type].reference () = struct_ptr_ref2; + cmp compare; + if (! compare.compare_dies (var1, var2, in)) + error (-1, 0, "var_struct_ptr_type vars not equal"); + return in; } @@ -395,7 +525,8 @@ main (int argc, char **argv) test_run (9, "two_circular_structs", two_circular_structs (in9)); // Won't merge CUs since order of children different. - // XXX but also structs and var aren't considered equal. Why not? + // XXX vars are considered equal according to dwarf_comparator, + // but not according to dwarf_output. Why not? And how to check? dwarf_edit in10; if (RUNTEST (10)) test_run (10, "two_circular_structs2", two_circular_structs2 (in10)); |
