Fix: Handle inability to find return addr

Fixes a code path where stacktrace returns < 2 locations and
thread.ReturnAddress would panic. Now returns an error.
This commit is contained in:
Derek Parker
2015-08-10 08:55:57 -05:00
parent 8de1a307ee
commit f43007c55e
3 changed files with 45 additions and 31 deletions

View File

@ -1,6 +1,9 @@
package proc
import "encoding/binary"
import (
"encoding/binary"
"fmt"
)
// Takes an offset from RSP and returns the address of the
// instruction the current function is going to return to.
@ -9,6 +12,9 @@ func (thread *Thread) ReturnAddress() (uint64, error) {
if err != nil {
return 0, err
}
if len(locations) < 2 {
return 0, fmt.Errorf("could not find return address for %s", locations[0].Fn.BaseName())
}
return locations[1].PC, nil
}
@ -75,7 +81,8 @@ func (dbp *Process) stacktrace(pc, sp uint64, depth int) ([]Location, error) {
break
}
locations = append(locations, Location{PC: ret, File: f, Line: l, Fn: fn})
if fn.Name == "runtime.goexit" {
// Look for "top of stack" functions.
if fn.Name == "runtime.rt0_go" {
break
}
}