1 /* go-callers.c -- get callers for Go.
3 Copyright 2012 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
14 /* Argument passed to callback function. */
23 /* Callback function for backtrace_simple. Just collect the PC
24 values. Return zero to continue, non-zero to stop. */
27 callback (void *data
, uintptr_t pc
)
29 struct callers_data
*arg
= (struct callers_data
*) data
;
31 arg
->pcbuf
[arg
->index
] = pc
;
33 return arg
->index
>= arg
->max
;
39 error_callback (void *data
__attribute__ ((unused
)),
40 const char *msg
, int errnum
)
43 runtime_printf ("%s errno %d\n", msg
, errnum
);
47 /* Gather caller PC's. */
50 runtime_callers (int32 skip
, uintptr
*pcbuf
, int32 m
)
52 struct callers_data data
;
57 backtrace_simple (__go_get_backtrace_state (), skip
+ 1, callback
,
58 error_callback
, &data
);
62 int Callers (int, struct __go_open_array
)
63 __asm__ ("runtime.Callers");
66 Callers (int skip
, struct __go_open_array pc
)
68 /* In the Go 1 release runtime.Callers has an off-by-one error,
69 which we can not correct because it would break backward
70 compatibility. Adjust SKIP here to be compatible. */
71 return runtime_callers (skip
- 1, (uintptr
*) pc
.__values
, pc
.__count
);