Commit fcbcc0fd authored by Hiroshi Ioka's avatar Hiroshi Ioka Committed by Ian Lance Taylor

debug/macho: make tests more comprehensive

add tests for LC_LOAD_DYLIB.

Change-Id: Ic4b7a0f6296709175e9a75240aecd1d5291ade4b
Reviewed-on: https://go-review.googlesource.com/56311Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 8e52a5ee
...@@ -12,7 +12,7 @@ import ( ...@@ -12,7 +12,7 @@ import (
type fileTest struct { type fileTest struct {
file string file string
hdr FileHeader hdr FileHeader
segments []*SegmentHeader loads []interface{}
sections []*SectionHeader sections []*SectionHeader
} }
...@@ -20,19 +20,19 @@ var fileTests = []fileTest{ ...@@ -20,19 +20,19 @@ var fileTests = []fileTest{
{ {
"testdata/gcc-386-darwin-exec", "testdata/gcc-386-darwin-exec",
FileHeader{0xfeedface, Cpu386, 0x3, 0x2, 0xc, 0x3c0, 0x85}, FileHeader{0xfeedface, Cpu386, 0x3, 0x2, 0xc, 0x3c0, 0x85},
[]*SegmentHeader{ []interface{}{
{LoadCmdSegment, 0x38, "__PAGEZERO", 0x0, 0x1000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, &SegmentHeader{LoadCmdSegment, 0x38, "__PAGEZERO", 0x0, 0x1000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
{LoadCmdSegment, 0xc0, "__TEXT", 0x1000, 0x1000, 0x0, 0x1000, 0x7, 0x5, 0x2, 0x0}, &SegmentHeader{LoadCmdSegment, 0xc0, "__TEXT", 0x1000, 0x1000, 0x0, 0x1000, 0x7, 0x5, 0x2, 0x0},
{LoadCmdSegment, 0xc0, "__DATA", 0x2000, 0x1000, 0x1000, 0x1000, 0x7, 0x3, 0x2, 0x0}, &SegmentHeader{LoadCmdSegment, 0xc0, "__DATA", 0x2000, 0x1000, 0x1000, 0x1000, 0x7, 0x3, 0x2, 0x0},
{LoadCmdSegment, 0x7c, "__IMPORT", 0x3000, 0x1000, 0x2000, 0x1000, 0x7, 0x7, 0x1, 0x0}, &SegmentHeader{LoadCmdSegment, 0x7c, "__IMPORT", 0x3000, 0x1000, 0x2000, 0x1000, 0x7, 0x7, 0x1, 0x0},
{LoadCmdSegment, 0x38, "__LINKEDIT", 0x4000, 0x1000, 0x3000, 0x12c, 0x7, 0x1, 0x0, 0x0}, &SegmentHeader{LoadCmdSegment, 0x38, "__LINKEDIT", 0x4000, 0x1000, 0x3000, 0x12c, 0x7, 0x1, 0x0, 0x0},
nil, nil, // LC_SYMTAB
nil, nil, // LC_DYSYMTAB
nil, nil, // LC_LOAD_DYLINKER
nil, nil, // LC_UUID
nil, nil, // LC_UNIXTHREAD
nil, &Dylib{nil, "/usr/lib/libgcc_s.1.dylib", 0x2, 0x10000, 0x10000},
nil, &Dylib{nil, "/usr/lib/libSystem.B.dylib", 0x2, 0x6f0104, 0x10000},
}, },
[]*SectionHeader{ []*SectionHeader{
{"__text", "__TEXT", 0x1f68, 0x88, 0xf68, 0x2, 0x0, 0x0, 0x80000400}, {"__text", "__TEXT", 0x1f68, 0x88, 0xf68, 0x2, 0x0, 0x0, 0x80000400},
...@@ -45,18 +45,18 @@ var fileTests = []fileTest{ ...@@ -45,18 +45,18 @@ var fileTests = []fileTest{
{ {
"testdata/gcc-amd64-darwin-exec", "testdata/gcc-amd64-darwin-exec",
FileHeader{0xfeedfacf, CpuAmd64, 0x80000003, 0x2, 0xb, 0x568, 0x85}, FileHeader{0xfeedfacf, CpuAmd64, 0x80000003, 0x2, 0xb, 0x568, 0x85},
[]*SegmentHeader{ []interface{}{
{LoadCmdSegment64, 0x48, "__PAGEZERO", 0x0, 0x100000000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, &SegmentHeader{LoadCmdSegment64, 0x48, "__PAGEZERO", 0x0, 0x100000000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
{LoadCmdSegment64, 0x1d8, "__TEXT", 0x100000000, 0x1000, 0x0, 0x1000, 0x7, 0x5, 0x5, 0x0}, &SegmentHeader{LoadCmdSegment64, 0x1d8, "__TEXT", 0x100000000, 0x1000, 0x0, 0x1000, 0x7, 0x5, 0x5, 0x0},
{LoadCmdSegment64, 0x138, "__DATA", 0x100001000, 0x1000, 0x1000, 0x1000, 0x7, 0x3, 0x3, 0x0}, &SegmentHeader{LoadCmdSegment64, 0x138, "__DATA", 0x100001000, 0x1000, 0x1000, 0x1000, 0x7, 0x3, 0x3, 0x0},
{LoadCmdSegment64, 0x48, "__LINKEDIT", 0x100002000, 0x1000, 0x2000, 0x140, 0x7, 0x1, 0x0, 0x0}, &SegmentHeader{LoadCmdSegment64, 0x48, "__LINKEDIT", 0x100002000, 0x1000, 0x2000, 0x140, 0x7, 0x1, 0x0, 0x0},
nil, nil, // LC_SYMTAB
nil, nil, // LC_DYSYMTAB
nil, nil, // LC_LOAD_DYLINKER
nil, nil, // LC_UUID
nil, nil, // LC_UNIXTHREAD
nil, &Dylib{nil, "/usr/lib/libgcc_s.1.dylib", 0x2, 0x10000, 0x10000},
nil, &Dylib{nil, "/usr/lib/libSystem.B.dylib", 0x2, 0x6f0104, 0x10000},
}, },
[]*SectionHeader{ []*SectionHeader{
{"__text", "__TEXT", 0x100000f14, 0x6d, 0xf14, 0x2, 0x0, 0x0, 0x80000400}, {"__text", "__TEXT", 0x100000f14, 0x6d, 0xf14, 0x2, 0x0, 0x0, 0x80000400},
...@@ -72,11 +72,11 @@ var fileTests = []fileTest{ ...@@ -72,11 +72,11 @@ var fileTests = []fileTest{
{ {
"testdata/gcc-amd64-darwin-exec-debug", "testdata/gcc-amd64-darwin-exec-debug",
FileHeader{0xfeedfacf, CpuAmd64, 0x80000003, 0xa, 0x4, 0x5a0, 0}, FileHeader{0xfeedfacf, CpuAmd64, 0x80000003, 0xa, 0x4, 0x5a0, 0},
[]*SegmentHeader{ []interface{}{
nil, nil, // LC_UUID
{LoadCmdSegment64, 0x1d8, "__TEXT", 0x100000000, 0x1000, 0x0, 0x0, 0x7, 0x5, 0x5, 0x0}, &SegmentHeader{LoadCmdSegment64, 0x1d8, "__TEXT", 0x100000000, 0x1000, 0x0, 0x0, 0x7, 0x5, 0x5, 0x0},
{LoadCmdSegment64, 0x138, "__DATA", 0x100001000, 0x1000, 0x0, 0x0, 0x7, 0x3, 0x3, 0x0}, &SegmentHeader{LoadCmdSegment64, 0x138, "__DATA", 0x100001000, 0x1000, 0x0, 0x0, 0x7, 0x3, 0x3, 0x0},
{LoadCmdSegment64, 0x278, "__DWARF", 0x100002000, 0x1000, 0x1000, 0x1bc, 0x7, 0x3, 0x7, 0x0}, &SegmentHeader{LoadCmdSegment64, 0x278, "__DWARF", 0x100002000, 0x1000, 0x1000, 0x1bc, 0x7, 0x3, 0x7, 0x0},
}, },
[]*SectionHeader{ []*SectionHeader{
{"__text", "__TEXT", 0x100000f14, 0x0, 0x0, 0x2, 0x0, 0x0, 0x80000400}, {"__text", "__TEXT", 0x100000f14, 0x0, 0x0, 0x2, 0x0, 0x0, 0x80000400},
...@@ -112,28 +112,32 @@ func TestOpen(t *testing.T) { ...@@ -112,28 +112,32 @@ func TestOpen(t *testing.T) {
continue continue
} }
for i, l := range f.Loads { for i, l := range f.Loads {
if i >= len(tt.segments) { if i >= len(tt.loads) {
break break
} }
sh := tt.segments[i]
s, ok := l.(*Segment) want := tt.loads[i]
if sh == nil { if want == nil {
if ok {
t.Errorf("open %s, section %d: skipping %#v\n", tt.file, i, &s.SegmentHeader)
}
continue continue
} }
if !ok {
t.Errorf("open %s, section %d: not *Segment\n", tt.file, i) switch l := l.(type) {
continue case *Segment:
have := &l.SegmentHeader
if !reflect.DeepEqual(have, want) {
t.Errorf("open %s, segment %d:\n\thave %#v\n\twant %#v\n", tt.file, i, have, want)
} }
have := &s.SegmentHeader case *Dylib:
want := sh have := l
have.LoadBytes = nil
if !reflect.DeepEqual(have, want) { if !reflect.DeepEqual(have, want) {
t.Errorf("open %s, segment %d:\n\thave %#v\n\twant %#v\n", tt.file, i, have, want) t.Errorf("open %s, segment %d:\n\thave %#v\n\twant %#v\n", tt.file, i, have, want)
} }
default:
t.Errorf("open %s, section %d: unknown load command\n\thave %#v\n\twant %#v\n", tt.file, i, l, want)
}
} }
tn := len(tt.segments) tn := len(tt.loads)
fn := len(f.Loads) fn := len(f.Loads)
if tn != fn { if tn != fn {
t.Errorf("open %s: len(Loads) = %d, want %d", tt.file, fn, tn) t.Errorf("open %s: len(Loads) = %d, want %d", tt.file, fn, tn)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment