1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
14 var typedefTests
= map[string]string{
15 "t_ptr_volatile_int": "*volatile int",
16 "t_ptr_const_char": "*const char",
18 "t_ushort": "short unsigned int",
19 "t_func_int_of_float_double": "func(float, double) int",
20 "t_ptr_func_int_of_float_double": "*func(float, double) int",
21 "t_ptr_func_int_of_float_complex": "*func(complex float) int",
22 "t_ptr_func_int_of_double_complex": "*func(complex double) int",
23 "t_ptr_func_int_of_long_double_complex": "*func(complex long double) int",
24 "t_func_ptr_int_of_char_schar_uchar": "func(char, signed char, unsigned char) *int",
25 "t_func_void_of_char": "func(char) void",
26 "t_func_void_of_void": "func() void",
27 "t_func_void_of_ptr_char_dots": "func(*char, ...) void",
28 "t_my_struct": "struct my_struct {vi volatile int@0; x char@4 : 1@7; y int@4 : 4@27; z [0]int@8; array [40]long long int@8; zz [0]int@328}",
29 "t_my_struct1": "struct my_struct1 {zz [1]int@0}",
30 "t_my_union": "union my_union {vi volatile int@0; x char@0 : 1@7; y int@0 : 4@28; array [40]long long int@0}",
31 "t_my_enum": "enum my_enum {e1=1; e2=2; e3=-5; e4=1000000000000000}",
32 "t_my_list": "struct list {val short int@0; next *t_my_list@8}",
33 "t_my_tree": "struct tree {left *struct tree@0; right *struct tree@8; val long long unsigned int@16}",
36 // As Apple converts gcc to a clang-based front end
37 // they keep breaking the DWARF output. This map lists the
38 // conversion from real answer to Apple answer.
39 var machoBug
= map[string]string{
40 "func(*char, ...) void": "func(*char) void",
41 "enum my_enum {e1=1; e2=2; e3=-5; e4=1000000000000000}": "enum my_enum {e1=1; e2=2; e3=-5; e4=-1530494976}",
44 func elfData(t
*testing
.T
, name
string) *Data
{
45 f
, err
:= elf
.Open(name
)
57 func machoData(t
*testing
.T
, name
string) *Data
{
58 f
, err
:= macho
.Open(name
)
70 func TestTypedefsELF(t
*testing
.T
) { testTypedefs(t
, elfData(t
, "testdata/typedef.elf"), "elf") }
72 func TestTypedefsMachO(t
*testing
.T
) {
73 testTypedefs(t
, machoData(t
, "testdata/typedef.macho"), "macho")
76 func TestTypedefsELFDwarf4(t
*testing
.T
) { testTypedefs(t
, elfData(t
, "testdata/typedef.elf4"), "elf") }
78 func testTypedefs(t
*testing
.T
, d
*Data
, kind
string) {
80 seen
:= make(map[string]bool)
84 t
.Fatal("r.Next:", err
)
89 if e
.Tag
== TagTypedef
{
90 typ
, err
:= d
.Type(e
.Offset
)
92 t
.Fatal("d.Type:", err
)
94 t1
:= typ
.(*TypedefType
)
96 if ts
, ok
:= t1
.Type
.(*StructType
); ok
{
99 typstr
= t1
.Type
.String()
102 if want
, ok
:= typedefTests
[t1
.Name
]; ok
{
104 t
.Errorf("multiple definitions for %s", t1
.Name
)
107 if typstr
!= want
&& (kind
!= "macho" || typstr
!= machoBug
[want
]) {
108 t
.Errorf("%s:\n\thave %s\n\twant %s", t1
.Name
, typstr
, want
)
112 if e
.Tag
!= TagCompileUnit
{
117 for k
:= range typedefTests
{
119 t
.Errorf("missing %s", k
)