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

proc: fix stacktrace frame after runtime.sigpanic #3638

Merged
merged 1 commit into from
Jan 18, 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
8 changes: 8 additions & 0 deletions _fixtures/panicline.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

import "os"

func main() {
fi, _ := os.Lstat("/this/path/does/not/exist")
fi.Size()
}
25 changes: 25 additions & 0 deletions pkg/proc/proc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6121,3 +6121,28 @@ func TestIssue3545(t *testing.T) {
}
})
}

func TestPanicLine(t *testing.T) {
withTestProcess("panicline", t, func(p *proc.Target, grp *proc.TargetGroup, fixture protest.Fixture) {
err := grp.Continue()
if runtime.GOOS == "darwin" && err != nil && err.Error() == "bad access" {
// not supported
return
}
assertNoError(err, t, "Continue()")
frames, err := proc.ThreadStacktrace(p, p.CurrentThread(), 20)
assertNoError(err, t, "ThreadStacktrace")
logStacktrace(t, p, frames)

found := false
for _, frame := range frames {
if strings.HasSuffix(frame.Call.File, "panicline.go") && frame.Call.Line == 7 {
found = true
break
}
}
if !found {
t.Fatalf("could not find panicline.go:6")
}
})
}
4 changes: 3 additions & 1 deletion pkg/proc/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ type stackIterator struct {
pc uint64
top bool
atend bool
sigret bool
frame Stackframe
target *Target
bi *BinaryInfo
Expand Down Expand Up @@ -270,6 +271,7 @@ func (it *stackIterator) Next() bool {
return true
}

it.sigret = it.frame.Current.Fn != nil && it.frame.Current.Fn.Name == "runtime.sigpanic"
it.top = false
it.pc = it.frame.Ret
it.regs = callFrameRegs
Expand Down Expand Up @@ -329,7 +331,7 @@ func (it *stackIterator) newStackframe(ret, retaddr uint64) Stackframe {
r.Regs.AddReg(it.regs.PCRegNum, op.DwarfRegisterFromUint64(it.pc))
}
r.Call = r.Current
if !it.top && r.Current.Fn != nil && it.pc != r.Current.Fn.Entry {
if !it.top && r.Current.Fn != nil && it.pc != r.Current.Fn.Entry && !it.sigret {
// if the return address is the entry point of the function that
// contains it then this is some kind of fake return frame (for example
// runtime.sigreturn) that didn't actually call the current frame,
Expand Down