1 /* Copyright (C) 2006-2016 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
25 #include <gnu/lib-names.h>
39 static _Unwind_Reason_Code
40 backtrace_helper (struct _Unwind_Context
*ctx
, void *a
)
42 struct trace_arg
*arg
= a
;
43 if (++arg
->cnt
== arg
->size
)
44 return _URC_END_OF_STACK
;
45 return _URC_NO_REASON
;
51 struct trace_arg arg
= { .size
= 100, .cnt
= -1 };
53 _Unwind_Reason_Code (*unwind_backtrace
) (_Unwind_Trace_Fn
, void *);
55 if (i
!= othervar
|| thr
!= 94)
57 printf ("i %d thr %d\n", i
, thr
);
61 /* Test if callback function of _Unwind_Backtrace is not called infinitely
62 times. See Bug 18508 or gcc bug "Bug 66303 - runtime.Caller() returns
63 infinitely deep stack frames on s390x.".
64 The go runtime calls backtrace_full() in
65 <gcc-src>/libbacktrace/backtrace.c, which uses _Unwind_Backtrace(). */
66 handle
= dlopen (LIBGCC_S_SO
, RTLD_LAZY
);
69 unwind_backtrace
= dlsym (handle
, "_Unwind_Backtrace");
70 if (unwind_backtrace
!= NULL
)
72 unwind_backtrace (backtrace_helper
, &arg
);
73 assert (arg
.cnt
!= -1 && arg
.cnt
< 100);
78 /* Since uc_link below has been set to NULL, setcontext is supposed to
79 terminate the process normally after this function returns. */
85 if (getcontext (&ucp
) != 0)
89 puts ("context handling not supported");
93 puts ("getcontext failed");
98 ucp
.uc_stack
.ss_sp
= st1
;
99 ucp
.uc_stack
.ss_size
= sizeof st1
;
100 makecontext (&ucp
, (void (*) (void)) cf
, 1, somevar
- 2);
101 if (setcontext (&ucp
) != 0)
103 puts ("setcontext failed");
109 #define TEST_FUNCTION do_test ()
110 #include "../test-skeleton.c"