#include "error.h"
+#include "c++/dwarf"
#include "c++/dwarf_edit"
#include "c++/dwarf_output"
#include "c++/dwarf_comparator"
// 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)
{
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;
}
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;
}
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;
}
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;
}
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));