pkg/proc: fix for file reference handling with DWARF 5 compilation units (#2327)

Add a helper method for collecting line table file references that
does the correct thing for DWARF 5 vs DWARF 4 (in the latter case you
have an implicit 0 entry which is the comp dir, whereas in the former
case you do not). This is to avoid out-of-bounds errors when examining
the file table section of a DWARF 5 compilation unit's line table.

Included is a new linux/amd-only test that includes a precompiled C
object file with a DWARF-5 section that triggers the bug in question.

Fixes #2319
This commit is contained in:
Than McIntosh
2021-01-29 12:23:52 -05:00
committed by GitHub
parent 7548542795
commit dceffacb89
9 changed files with 138 additions and 18 deletions

View File

@ -377,7 +377,9 @@ func (it *stackIterator) appendInlineCalls(frames []Stackframe, frame Stackframe
if !okname || !okfileidx || !okline {
break
}
if fileidx-1 < 0 || fileidx-1 >= int64(len(frame.Current.Fn.cu.lineInfo.FileNames)) {
var e *dwarf.Entry
filepath, fileErr := frame.Current.Fn.cu.filePath(int(fileidx), e)
if fileErr != nil {
break
}
@ -400,7 +402,7 @@ func (it *stackIterator) appendInlineCalls(frames []Stackframe, frame Stackframe
lastpc: frame.lastpc,
})
frame.Call.File = frame.Current.Fn.cu.lineInfo.FileNames[fileidx-1].Path
frame.Call.File = filepath
frame.Call.Line = int(line)
}