aboutsummaryrefslogtreecommitdiff
path: root/libgo/go
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2016-10-14 17:20:40 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2016-10-14 17:20:40 +0000
commitd4316362b3572d728e71d2784e4c3c2758156b4a (patch)
tree9d0eff081f71ed2e0ceaa851807623afe4a7f286 /libgo/go
parent33949aba05699a188503c51e972036bf430aa64f (diff)
runtime: just do file/line lookup in C, move Func to Go
In order to port stack backtraces to Go, we need the ability to look up file/line information for PC values without allocating memory. This patch moves the handling of Func from C code to Go code, and simplifies the C code to just look up function/file/line/entry information for a PC. Reviewed-on: https://go-review.googlesource.com/31150 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@241172 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go')
-rw-r--r--libgo/go/runtime/symtab.go38
1 files changed, 23 insertions, 15 deletions
diff --git a/libgo/go/runtime/symtab.go b/libgo/go/runtime/symtab.go
index 7b76f11f3a6..52e2d03d14b 100644
--- a/libgo/go/runtime/symtab.go
+++ b/libgo/go/runtime/symtab.go
@@ -65,19 +65,20 @@ func (ci *Frames) Next() (frame Frame, more bool) {
}
more = len(ci.callers) > 0
- f, file, line := funcframe(pc, i)
- if f == nil {
+ // Subtract 1 from PC to undo the 1 we added in callback in
+ // go-callers.c.
+ function, file, line := funcfileline(pc-1, int32(i))
+ if function == "" && file == "" {
return Frame{}, more
}
+ entry := funcentry(pc - 1)
+ f := &Func{name: function, entry: entry}
- entry := f.Entry()
xpc := pc
if xpc > entry {
xpc--
}
- function := f.Name()
-
frame = Frame{
PC: xpc,
Func: f,
@@ -97,21 +98,29 @@ func (ci *Frames) Next() (frame Frame, more bool) {
// A Func represents a Go function in the running binary.
type Func struct {
- opaque struct{} // unexported field to disallow conversions
+ name string
+ entry uintptr
}
// FuncForPC returns a *Func describing the function that contains the
// given program counter address, or else nil.
-func FuncForPC(pc uintptr) *Func
+func FuncForPC(pc uintptr) *Func {
+ name, _, _ := funcfileline(pc, -1)
+ if name == "" {
+ return nil
+ }
+ entry := funcentry(pc)
+ return &Func{name: name, entry: entry}
+}
// Name returns the name of the function.
func (f *Func) Name() string {
- return funcname_go(f)
+ return f.name
}
// Entry returns the entry address of the function.
func (f *Func) Entry() uintptr {
- return funcentry_go(f)
+ return f.entry
}
// FileLine returns the file name and line number of the
@@ -119,11 +128,10 @@ func (f *Func) Entry() uintptr {
// The result will not be accurate if pc is not a program
// counter within f.
func (f *Func) FileLine(pc uintptr) (file string, line int) {
- return funcline_go(f, pc)
+ _, file, line = funcfileline(pc, -1)
+ return file, line
}
-// implemented in symtab.c
-func funcline_go(*Func, uintptr) (string, int)
-func funcname_go(*Func) string
-func funcentry_go(*Func) uintptr
-func funcframe(uintptr, int) (*Func, string, int)
+// implemented in go-caller.c
+func funcfileline(uintptr, int32) (string, string, int)
+func funcentry(uintptr) uintptr