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. */
13 /* Argument passed to callback function. */
22 /* Callback function for backtrace_simple. Just collect the PC
23 values. Return zero to continue, non-zero to stop. */
26 callback (void *data
, uintptr_t pc
)
28 struct callers_data
*arg
= (struct callers_data
*) data
;
30 arg
->pcbuf
[arg
->index
] = pc
;
32 return arg
->index
>= arg
->max
;
38 error_callback (void *data
__attribute__ ((unused
)),
39 const char *msg
, int errnum
)
42 runtime_printf ("%s errno %d\n", msg
, errnum
);
46 /* Gather caller PC's. */
49 runtime_callers (int32 skip
, uintptr
*pcbuf
, int32 m
)
51 struct callers_data data
;
56 backtrace_simple (__go_get_backtrace_state (), skip
+ 1, callback
,
57 error_callback
, &data
);
61 int Callers (int, struct __go_open_array
)
62 __asm__ ("runtime.Callers");
65 Callers (int skip
, struct __go_open_array pc
)
67 /* In the Go 1 release runtime.Callers has an off-by-one error,
68 which we can not correct because it would break backward
69 compatibility. Adjust SKIP here to be compatible. */
70 return runtime_callers (skip
- 1, (uintptr
*) pc
.__values
, pc
.__count
);