Skip to content

Commit 5aa10d0

Browse files
committed
added unit test
1 parent c101b2e commit 5aa10d0

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

src/debug/dwarf/testdata/typedef.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ gcc -gdwarf-2 -m64 -c typedef.c && gcc -gdwarf-2 -m64 -o typedef.elf typedef.o
88
99
OS X Mach-O:
1010
gcc -gdwarf-2 -m64 -c typedef.c -o typedef.macho
11+
gcc -gdwarf-4 -m64 -c typedef.c -o typedef.macho4
1112
*/
1213
#include <complex.h>
1314

6.07 KB
Binary file not shown.

src/debug/dwarf/type_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,54 @@ func TestUnsupportedTypes(t *testing.T) {
228228
}
229229
}
230230
}
231+
232+
func TestBitOffsetsELF(t *testing.T) { testBitOffsets(t, elfData(t, "testdata/typedef.elf")) }
233+
234+
func TestBitOffsetsMachO(t *testing.T) {
235+
testBitOffsets(t, machoData(t, "testdata/typedef.macho"))
236+
}
237+
238+
func TestBitOffsetsMachO4(t *testing.T) {
239+
testBitOffsets(t, machoData(t, "testdata/typedef.macho4"))
240+
}
241+
242+
func TestBitOffsetsELFDwarf4(t *testing.T) {
243+
testBitOffsets(t, elfData(t, "testdata/typedef.elf4"))
244+
}
245+
246+
func testBitOffsets(t *testing.T, d *Data) {
247+
r := d.Reader()
248+
for {
249+
e, err := r.Next()
250+
if err != nil {
251+
t.Fatal("r.Next:", err)
252+
}
253+
if e == nil {
254+
break
255+
}
256+
257+
if e.Tag == TagStructType {
258+
typ, err := d.Type(e.Offset)
259+
if err != nil {
260+
t.Fatal("d.Type:", err)
261+
}
262+
263+
t1 := typ.(*StructType)
264+
265+
for _, field := range t1.Field {
266+
// We're only testing for bitfields
267+
if field.BitSize == 0 {
268+
continue
269+
}
270+
271+
// Ensure BitOffset is not zero
272+
if field.BitOffset == 0 {
273+
t.Errorf("bit offset of field %s in %s %s is not set", field.Name, t1.Kind, t1.StructName)
274+
}
275+
}
276+
}
277+
if e.Tag != TagCompileUnit {
278+
r.SkipChildren()
279+
}
280+
}
281+
}

0 commit comments

Comments
 (0)