{0x40117e, nil},
}
testRanges(t, "testdata/line-clang-dwarf5.elf", want)
+
+ want = []wantRange{
+ {0x401126, [][2]uint64{{0x401126, 0x40116a}}},
+ {0x40116a, [][2]uint64{{0x40116a, 0x401180}}},
+ }
+ testRanges(t, "testdata/line-gcc-zstd.elf", want)
}
func TestRangesSection(t *testing.T) {
{"f2", [][2]uint64{{0x401180, 0x401197}}},
},
},
+ {
+ "testdata/line-gcc-zstd.elf",
+ subprograms{
+ {"f2", nil},
+ {"main", [][2]uint64{{0x40114b, 0x40116a}}},
+ {"f1", [][2]uint64{{0x401126, 0x40114b}}},
+ {"f2", [][2]uint64{{0x40116a, 0x401180}}},
+ },
+ },
}
for _, test := range tests {
testLineTable(t, want, files, elfData(t, "testdata/line-gcc.elf"))
}
+func TestLineELFGCCZstd(t *testing.T) {
+ // Generated by:
+ // # gcc --version | head -n1
+ // gcc (Debian 12.2.0-10) 12.2.0
+ // # gcc -g -no-pie -Wl,--compress-debug-sections=zstd line*.c
+
+ zfile1H := &LineFile{Name: "/home/iant/go/src/debug/dwarf/testdata/line1.h"}
+ zfile1C := &LineFile{Name: "/home/iant/go/src/debug/dwarf/testdata/line1.c"}
+ zfile2C := &LineFile{Name: "/home/iant/go/src/debug/dwarf/testdata/line2.c"}
+
+ // Line table based on readelf --debug-dump=rawline,decodedline
+ want := []LineEntry{
+ {Address: 0x401126, File: zfile1H, Line: 2, Column: 1, IsStmt: true},
+ {Address: 0x40112a, File: zfile1H, Line: 5, Column: 8, IsStmt: true},
+ {Address: 0x401131, File: zfile1H, Line: 5, Column: 2, IsStmt: true},
+ {Address: 0x401133, File: zfile1H, Line: 6, Column: 10, IsStmt: true, Discriminator: 3},
+ {Address: 0x40113d, File: zfile1H, Line: 5, Column: 22, IsStmt: true, Discriminator: 3},
+ {Address: 0x401141, File: zfile1H, Line: 5, Column: 15, IsStmt: true, Discriminator: 1},
+ {Address: 0x401147, File: zfile1H, Line: 7, Column: 1, IsStmt: true},
+ {Address: 0x40114b, File: zfile1C, Line: 6, Column: 1, IsStmt: true},
+ {Address: 0x40114f, File: zfile1C, Line: 7, Column: 2, IsStmt: true},
+ {Address: 0x401159, File: zfile1C, Line: 8, Column: 2, IsStmt: true},
+ {Address: 0x401168, File: zfile1C, Line: 9, Column: 1, IsStmt: true},
+ {Address: 0x40116a, EndSequence: true},
+
+ {Address: 0x40116a, File: zfile2C, Line: 4, Column: 1, IsStmt: true},
+ {Address: 0x40116e, File: zfile2C, Line: 5, Column: 2, IsStmt: true},
+ {Address: 0x40117d, File: zfile2C, Line: 6, Column: 1, IsStmt: true},
+ {Address: 0x401180, EndSequence: true},
+ }
+ files := [][]*LineFile{
+ {zfile1C, zfile1H, zfile1C},
+ {zfile2C, zfile2C},
+ }
+
+ testLineTable(t, want, files, elfData(t, "testdata/line-gcc-zstd.elf"))
+}
+
func TestLineGCCWindows(t *testing.T) {
// Generated by:
// > gcc --version
}
// Compare line tables.
- if !compareLines(got, want) {
+ if !compareLines(t, got, want) {
t.Log("Line tables do not match. Got:")
dumpLines(t, got)
t.Log("Want:")
}
}
-func compareLines(a, b []LineEntry) bool {
+func compareLines(t *testing.T, a, b []LineEntry) bool {
+ t.Helper()
if len(a) != len(b) {
+ t.Errorf("len(a) == %d, len(b) == %d", len(a), len(b))
return false
}
continue
}
if al.File.Name != bl.File.Name {
+ t.Errorf("%d: name %v != name %v", i, al.File.Name, bl.File.Name)
return false
}
al.File = nil
bl.File = nil
if al != bl {
+ t.Errorf("%d: %#v != %#v", i, al, bl)
return false
}
}