Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/proc: defend better against missing DWARF #3695

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/dwarf/godwarf/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package godwarf

import (
"debug/dwarf"
"errors"
"fmt"
"sort"
)
Expand Down Expand Up @@ -90,6 +91,9 @@ type Tree struct {
// range of addresses that is not covered by its parent LoadTree will fix
// the parent entry.
func LoadTree(off dwarf.Offset, dw *dwarf.Data, staticBase uint64) (*Tree, error) {
if dw == nil {
return nil, errors.New("unable to load DWARF tree: no DWARF information present")
}
rdr := dw.Reader()
rdr.Seek(off)

Expand Down
4 changes: 4 additions & 0 deletions pkg/proc/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ func (scope *EvalScope) Locals(flags localsFlags) ([]*Variable, error) {
return nil, errors.New("unable to find function context")
}

if scope.image().Stripped() {
return nil, errors.New("unable to find locals: no debug information present in binary")
}

trustArgOrder := (flags&localsTrustArgOrder != 0) && scope.BinInfo.Producer() != "" && goversion.ProducerAfterOrEqual(scope.BinInfo.Producer(), 1, 12) && scope.Fn != nil && (scope.PC == scope.Fn.Entry)

dwarfTree, err := scope.image().getDwarfTree(scope.Fn.offset)
Expand Down
10 changes: 9 additions & 1 deletion pkg/proc/proc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3216,11 +3216,19 @@ func TestDebugStripped(t *testing.T) {
assertLineNumber(p, t, 37, "first continue")
assertNoError(grp.Next(), t, "Next")
assertLineNumber(p, t, 38, "after next")

// Assert that commands like "args", "locals", etc... will
// return an error instead of panic.
s, err := proc.ThreadScope(p, p.CurrentThread())
assertNoError(err, t, "ThreadScope")
_, err = s.Locals(0)
if err == nil {
t.Error("expected an error to be returned from scope.Locals in stripped binary")
}
})
}

func TestDebugStripped2(t *testing.T) {
// Currently only implemented for Linux ELF executables.
// TODO(derekparker): Add support for PE.
skipOn(t, "not working on windows", "windows")
skipOn(t, "not working on freebsd", "freebsd")
Expand Down