diff options
Diffstat (limited to 'libgo/runtime/go-caller.c')
-rw-r--r-- | libgo/runtime/go-caller.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/libgo/runtime/go-caller.c b/libgo/runtime/go-caller.c index 2143446..5e31f91 100644 --- a/libgo/runtime/go-caller.c +++ b/libgo/runtime/go-caller.c @@ -26,11 +26,13 @@ struct caller String file; intgo line; intgo index; + intgo frames; }; /* Collect file/line information for a PC value. If this is called - more than once, due to inlined functions, we use the last call, as - that is usually the most useful one. */ + more than once, due to inlined functions, we record the number of + inlined frames but return file/func/line for the last call, as + that is usually the most useful one. */ static int callback (void *data, uintptr_t pc __attribute__ ((unused)), @@ -38,6 +40,8 @@ callback (void *data, uintptr_t pc __attribute__ ((unused)), { struct caller *c = (struct caller *) data; + c->frames++; + /* The libbacktrace library says that these strings might disappear, but with the current implementation they won't. We can't easily allocate memory here, so for now assume that we can save a @@ -125,18 +129,19 @@ __go_get_backtrace_state () return back_state; } -/* Return function/file/line information for PC. The index parameter +/* Return function/file/line/nframes information for PC. The index parameter is the entry on the stack of inlined functions; -1 means the last - one. */ + one, with *nframes set to the count of inlined frames for this PC. */ static _Bool -__go_file_line (uintptr pc, int index, String *fn, String *file, intgo *line) +__go_file_line (uintptr pc, int index, String *fn, String *file, intgo *line, intgo *nframes) { struct caller c; struct backtrace_state *state; runtime_memclr (&c, sizeof c); c.index = index; + c.frames = 0; runtime_xadd (&__go_runtime_in_callers, 1); state = __go_get_backtrace_state (); runtime_xadd (&__go_runtime_in_callers, -1); @@ -144,6 +149,7 @@ __go_file_line (uintptr pc, int index, String *fn, String *file, intgo *line) *fn = c.fn; *file = c.file; *line = c.line; + *nframes = c.frames; // If backtrace_pcinfo didn't get the function name from the debug // info, try to get it from the symbol table. @@ -222,7 +228,7 @@ runtime_funcfileline (uintptr targetpc, int32 index) struct funcfileline_return ret; if (!__go_file_line (targetpc, index, &ret.retfn, &ret.retfile, - &ret.retline)) + &ret.retline, &ret.retframes)) runtime_memclr (&ret, sizeof ret); return ret; } |