diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-02-08 15:37:43 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-02-08 15:37:43 +0000 |
commit | 74e6f14adb7057b29d361cc35c76f16663d1e649 (patch) | |
tree | f26b729ad50f3c18a319ff63f115f7eeb5c01eb5 /libgo/runtime/go-callers.c | |
parent | 080eaf7a88ee8039b6acf6c10394db18e9f34615 (diff) | |
download | gcc-74e6f14adb7057b29d361cc35c76f16663d1e649.zip gcc-74e6f14adb7057b29d361cc35c76f16663d1e649.tar.gz gcc-74e6f14adb7057b29d361cc35c76f16663d1e649.tar.bz2 |
runtime: get missing function name from symbol table
If we trace back through code that has no debug info, as when calling
through C code compiled with -g0, we won't have a function name.
Try to fetch the function name using the symbol table.
Adding the test case revealed that gotest failed to use the gccgo tag
when matching files, so add that.
Reviewed-on: https://go-review.googlesource.com/92756
From-SVN: r257495
Diffstat (limited to 'libgo/runtime/go-callers.c')
-rw-r--r-- | libgo/runtime/go-callers.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/libgo/runtime/go-callers.c b/libgo/runtime/go-callers.c index 2eaac68..5903153 100644 --- a/libgo/runtime/go-callers.c +++ b/libgo/runtime/go-callers.c @@ -143,6 +143,20 @@ callback (void *data, uintptr_t pc, const char *filename, int lineno, return arg->index >= arg->max; } +/* Syminfo callback. */ + +static void +syminfo_fnname_callback (void *data, uintptr_t pc __attribute__ ((unused)), + const char *symname, + uintptr_t address __attribute__ ((unused)), + uintptr_t size __attribute__ ((unused))) +{ + Location* locptr = (Location*) data; + + if (symname != NULL) + locptr->function = runtime_gostringnocopy ((const byte *) symname); +} + /* Error callback. */ static void @@ -179,15 +193,17 @@ int32 runtime_callers (int32 skip, Location *locbuf, int32 m, bool keep_thunks) { struct callers_data data; + struct backtrace_state* state; + int32 i; data.locbuf = locbuf; data.skip = skip + 1; data.index = 0; data.max = m; data.keep_thunks = keep_thunks; + state = __go_get_backtrace_state (); runtime_xadd (&runtime_in_callers, 1); - backtrace_full (__go_get_backtrace_state (), 0, callback, error_callback, - &data); + backtrace_full (state, 0, callback, error_callback, &data); runtime_xadd (&runtime_in_callers, -1); /* For some reason GCC sometimes loses the name of a thunk function @@ -204,6 +220,18 @@ runtime_callers (int32 skip, Location *locbuf, int32 m, bool keep_thunks) --data.index; } + /* Try to use backtrace_syminfo to fill in any missing function + names. This can happen when tracing through an object which has + no debug info; backtrace_syminfo will look at the symbol table to + get the name. This should only happen when tracing through code + that is not written in Go and is not part of libgo. */ + for (i = 0; i < data.index; ++i) + { + if (locbuf[i].function.len == 0 && locbuf[i].pc != 0) + backtrace_syminfo (state, locbuf[i].pc, syminfo_fnname_callback, + error_callback, &locbuf[i]); + } + return data.index; } |