aboutsummaryrefslogtreecommitdiff
path: root/libgo/runtime/go-caller.c
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2020-01-02 15:05:27 -0800
committerIan Lance Taylor <iant@golang.org>2020-01-21 23:53:22 -0800
commit5a8ea165926cb0737ab03bc48c18dc5198ab5305 (patch)
tree962dc3357c57f019f85658f99e2e753e30201c27 /libgo/runtime/go-caller.c
parent6ac6529e155c9baa0aaaed7aca06bd38ebda5b43 (diff)
downloadgcc-5a8ea165926cb0737ab03bc48c18dc5198ab5305.zip
gcc-5a8ea165926cb0737ab03bc48c18dc5198ab5305.tar.gz
gcc-5a8ea165926cb0737ab03bc48c18dc5198ab5305.tar.bz2
libgo: update to Go1.14beta1
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/214297
Diffstat (limited to 'libgo/runtime/go-caller.c')
-rw-r--r--libgo/runtime/go-caller.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/libgo/runtime/go-caller.c b/libgo/runtime/go-caller.c
index 5e31f91..a187876 100644
--- a/libgo/runtime/go-caller.c
+++ b/libgo/runtime/go-caller.c
@@ -27,6 +27,7 @@ struct caller
intgo line;
intgo index;
intgo frames;
+ bool more;
};
/* Collect file/line information for a PC value. If this is called
@@ -40,7 +41,19 @@ callback (void *data, uintptr_t pc __attribute__ ((unused)),
{
struct caller *c = (struct caller *) data;
- c->frames++;
+ /* We want to make sure we return at least one frame. If we already
+ have at least one frame, see if we should skip this one. */
+ if (c->frames > 0
+ && function != NULL
+ && runtime_skipInCallback (function, NULL))
+ return 0;
+
+ /* If we already have a frame, don't increment frames if we should
+ skip that one. */
+ if (c->frames == 0
+ || c->fn.len == 0
+ || !runtime_skipInCallback ((const char *) c->fn.str, NULL))
+ c->frames++;
/* The libbacktrace library says that these strings might disappear,
but with the current implementation they won't. We can't easily
@@ -51,7 +64,16 @@ callback (void *data, uintptr_t pc __attribute__ ((unused)),
c->line = lineno;
if (c->index == 0)
- return 1;
+ {
+ /* If there are more frames after the indexed one, and we should
+ skip this one, then skip it. */
+ if (c->more
+ && c->fn.len > 0
+ && runtime_skipInCallback((const char *) c->fn.str, NULL))
+ return 0;
+
+ return 1;
+ }
if (c->index > 0)
--c->index;
@@ -129,18 +151,21 @@ __go_get_backtrace_state ()
return back_state;
}
-/* 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, with *nframes set to the count of inlined frames for this PC. */
+/* 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, with *nframes set to the count of inlined frames for
+ this PC. If index is not -1, more is whether there are more frames
+ after this one. */
static _Bool
-__go_file_line (uintptr pc, int index, String *fn, String *file, intgo *line, intgo *nframes)
+__go_file_line (uintptr pc, int index, bool more, String *fn, String *file, intgo *line, intgo *nframes)
{
struct caller c;
struct backtrace_state *state;
runtime_memclr (&c, sizeof c);
c.index = index;
+ c.more = more;
c.frames = 0;
runtime_xadd (&__go_runtime_in_callers, 1);
state = __go_get_backtrace_state ();
@@ -223,11 +248,11 @@ Caller (intgo skip)
/* Look up the function name, file name, and line number for a PC. */
struct funcfileline_return
-runtime_funcfileline (uintptr targetpc, int32 index)
+runtime_funcfileline (uintptr targetpc, int32 index, bool more)
{
struct funcfileline_return ret;
- if (!__go_file_line (targetpc, index, &ret.retfn, &ret.retfile,
+ if (!__go_file_line (targetpc, index, more, &ret.retfn, &ret.retfile,
&ret.retline, &ret.retframes))
runtime_memclr (&ret, sizeof ret);
return ret;