diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2016-10-14 17:20:40 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2016-10-14 17:20:40 +0000 |
commit | db2fb304fe27afd8939aa94a4b11f050e6f625b3 (patch) | |
tree | 9d0eff081f71ed2e0ceaa851807623afe4a7f286 /libgo/go | |
parent | d2c4425e86310d44aa8e9f9d91b49e2e61237ef2 (diff) | |
download | gcc-db2fb304fe27afd8939aa94a4b11f050e6f625b3.tar.gz |
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
From-SVN: r241172
Diffstat (limited to 'libgo/go')
-rw-r--r-- | libgo/go/runtime/symtab.go | 38 |
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 |