mirror of
https://github.com/golang/go
synced 2024-11-26 20:01:19 -07:00
debug/dwarf: check for DWARFv4 AttrDataBitOffset value
AttrBitOffset is deprecated (but reserved) in DWARFv4. This fix adds
logic to check the new AttrDataBitOffset attribute if AttrBitOffset
attribute is not present.
Fixes #46784
Change-Id: I7406dcaa4c98e95df72361fd4462c39e6be8879d
GitHub-Last-Rev: 5aa10d0491
GitHub-Pull-Request: golang/go#46790
Reviewed-on: https://go-review.googlesource.com/c/go/+/328709
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
parent
a8aa6cfa6d
commit
065f380815
1
src/debug/dwarf/testdata/typedef.c
vendored
1
src/debug/dwarf/testdata/typedef.c
vendored
@ -8,6 +8,7 @@ gcc -gdwarf-2 -m64 -c typedef.c && gcc -gdwarf-2 -m64 -o typedef.elf typedef.o
|
||||
|
||||
OS X Mach-O:
|
||||
gcc -gdwarf-2 -m64 -c typedef.c -o typedef.macho
|
||||
gcc -gdwarf-4 -m64 -c typedef.c -o typedef.macho4
|
||||
*/
|
||||
#include <complex.h>
|
||||
|
||||
|
BIN
src/debug/dwarf/testdata/typedef.macho4
vendored
Normal file
BIN
src/debug/dwarf/testdata/typedef.macho4
vendored
Normal file
Binary file not shown.
@ -516,7 +516,10 @@ func (d *Data) readType(name string, r typeReader, off Offset, typeCache map[Off
|
||||
}).Basic()
|
||||
t.Name = name
|
||||
t.BitSize, _ = e.Val(AttrBitSize).(int64)
|
||||
t.BitOffset, _ = e.Val(AttrBitOffset).(int64)
|
||||
haveBitOffset := false
|
||||
if t.BitOffset, haveBitOffset = e.Val(AttrBitOffset).(int64); !haveBitOffset {
|
||||
t.BitOffset, _ = e.Val(AttrDataBitOffset).(int64)
|
||||
}
|
||||
|
||||
case TagClassType, TagStructType, TagUnionType:
|
||||
// Structure, union, or class type. (DWARF v2 §5.5)
|
||||
@ -578,7 +581,9 @@ func (d *Data) readType(name string, r typeReader, off Offset, typeCache map[Off
|
||||
haveBitOffset := false
|
||||
f.Name, _ = kid.Val(AttrName).(string)
|
||||
f.ByteSize, _ = kid.Val(AttrByteSize).(int64)
|
||||
f.BitOffset, haveBitOffset = kid.Val(AttrBitOffset).(int64)
|
||||
if f.BitOffset, haveBitOffset = kid.Val(AttrBitOffset).(int64); !haveBitOffset {
|
||||
f.BitOffset, haveBitOffset = kid.Val(AttrDataBitOffset).(int64)
|
||||
}
|
||||
f.BitSize, _ = kid.Val(AttrBitSize).(int64)
|
||||
t.Field = append(t.Field, f)
|
||||
|
||||
|
@ -228,3 +228,54 @@ func TestUnsupportedTypes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBitOffsetsELF(t *testing.T) { testBitOffsets(t, elfData(t, "testdata/typedef.elf")) }
|
||||
|
||||
func TestBitOffsetsMachO(t *testing.T) {
|
||||
testBitOffsets(t, machoData(t, "testdata/typedef.macho"))
|
||||
}
|
||||
|
||||
func TestBitOffsetsMachO4(t *testing.T) {
|
||||
testBitOffsets(t, machoData(t, "testdata/typedef.macho4"))
|
||||
}
|
||||
|
||||
func TestBitOffsetsELFDwarf4(t *testing.T) {
|
||||
testBitOffsets(t, elfData(t, "testdata/typedef.elf4"))
|
||||
}
|
||||
|
||||
func testBitOffsets(t *testing.T, d *Data) {
|
||||
r := d.Reader()
|
||||
for {
|
||||
e, err := r.Next()
|
||||
if err != nil {
|
||||
t.Fatal("r.Next:", err)
|
||||
}
|
||||
if e == nil {
|
||||
break
|
||||
}
|
||||
|
||||
if e.Tag == TagStructType {
|
||||
typ, err := d.Type(e.Offset)
|
||||
if err != nil {
|
||||
t.Fatal("d.Type:", err)
|
||||
}
|
||||
|
||||
t1 := typ.(*StructType)
|
||||
|
||||
for _, field := range t1.Field {
|
||||
// We're only testing for bitfields
|
||||
if field.BitSize == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// Ensure BitOffset is not zero
|
||||
if field.BitOffset == 0 {
|
||||
t.Errorf("bit offset of field %s in %s %s is not set", field.Name, t1.Kind, t1.StructName)
|
||||
}
|
||||
}
|
||||
}
|
||||
if e.Tag != TagCompileUnit {
|
||||
r.SkipChildren()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user