dwarf/line: Fixed DirIdx (index starts at one) (#1873)

* Fixed DirIdx (index starts at one)

I am using the elf to load C++ based elf and there the index starts at one and not zero, hence the minor fix.

* Added test

* Added proper test for c-generated elf & replaced index offset by adding build dir

* Changed other IncludeDir test

* Format fix & replace print with actual test

* Format fixes @derekparker requested.
This commit is contained in:
Klemens Morgenstern 2020-02-22 00:00:34 +07:00 committed by GitHub
parent fcba291125
commit 17f2fa7908
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 4 deletions

BIN
_fixtures/debug_line_c_data Normal file

Binary file not shown.

@ -74,9 +74,7 @@ func Parse(compdir string, buf *bytes.Buffer, logfn func(string, ...interface{})
dbl.Logf = logfn
dbl.staticBase = staticBase
dbl.Lookup = make(map[string]*FileEntry)
if compdir != "" {
dbl.IncludeDirs = append(dbl.IncludeDirs, compdir)
}
dbl.IncludeDirs = append(dbl.IncludeDirs, compdir)
dbl.stateMachineCache = make(map[uint64]*StateMachine)
dbl.lastMachineCache = make(map[uint64]*StateMachine)

@ -109,10 +109,19 @@ func testDebugLinePrologueParser(p string, t *testing.T) {
}
}
if len(dbl.IncludeDirs) != 0 {
if len(dbl.IncludeDirs) != 1 {
t.Fatal("Include dirs not parsed correctly")
}
for _, ln := range dbl.Lookup {
if ln.Path == "<autogenerated>" {
continue
}
if _, err := os.Stat(ln.Path); err != nil {
t.Fatalf("Invalid input path %s: %s\n", ln.Path, err)
}
}
for _, n := range dbl.FileNames {
if strings.Contains(n.Path, "/_fixtures/testnextprog.go") {
mainFileFound = true
@ -289,3 +298,43 @@ func BenchmarkPCToLine(b *testing.B) {
runTestPCToLine(b, lineInfos, entries, basePCs, false, 0x10000)
}
}
func TestDebugLineC(t * testing.T) {
p, err := filepath.Abs("../../../_fixtures/debug_line_c_data")
if err != nil {
t.Fatal("Could not find test data", p, err)
}
data, err := ioutil.ReadFile(p)
if err != nil {
t.Fatal("Could not read test data", err)
}
parsed := ParseAll(data, nil, 0, true)
if len(parsed) == 0 {
t.Fatal("Parser result is empty")
}
file := []string{"main.c", "/mnt/c/develop/delve/_fixtures/main.c" ,"/usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h",
"/usr/include/x86_64-linux-gnu/bits/types.h" ,"/usr/include/x86_64-linux-gnu/bits/libio.h", "/usr/include/stdio.h",
"/usr/include/x86_64-linux-gnu/bits/sys_errlist.h"}
for _, ln := range parsed {
if len(ln.FileNames) == 0 {
t.Fatal("Parser could not parse Filenames")
}
for _, fn := range ln.FileNames {
found := false
for _, cmp := range file {
if filepath.ToSlash(fn.Path) == cmp {
found = true
break
}
}
if !found {
t.Fatalf("Found %s does not appear in the filelist\n", fn.Path)
}
}
}
}