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 backtrace function. */
23 static _Unwind_Reason_Code
24 backtrace (struct _Unwind_Context
*context
, void *varg
)
26 struct callers_data
*arg
= (struct callers_data
*) varg
;
28 int ip_before_insn
= 0;
31 pc
= _Unwind_GetIPInfo (context
, &ip_before_insn
);
33 pc
= _Unwind_GetIP (context
);
36 /* FIXME: If PC is in the __morestack routine, we should ignore
41 else if (arg
->index
>= arg
->max
)
42 return _URC_END_OF_STACK
;
45 /* Here PC will be the return address. We actually want the
46 address of the call instruction, so back up one byte and
47 count on the lookup routines handling that correctly. */
50 arg
->pcbuf
[arg
->index
] = pc
;
53 return _URC_NO_REASON
;
57 runtime_callers (int32 skip
, uintptr
*pcbuf
, int32 m
)
59 struct callers_data arg
;
65 _Unwind_Backtrace (backtrace
, &arg
);
69 int Callers (int, struct __go_open_array
)
70 __asm__ ("libgo_runtime.runtime.Callers");
73 Callers (int skip
, struct __go_open_array pc
)
75 return runtime_callers (skip
, (uintptr
*) pc
.__values
, pc
.__count
);