]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/arm/backtrace.c
1 /* Return backtrace of current program state.
2 Copyright (C) 2008-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <https://www.gnu.org/licenses/>. */
21 #include <unwind-link.h>
26 struct unwind_link
*unwind_link
;
31 /* This function is identical to "_Unwind_GetGR", except that it uses
32 "unwind_vrs_get" instead of "_Unwind_VRS_Get". */
33 static inline _Unwind_Word
34 unwind_getgr (struct unwind_link
*unwind_link
,
35 _Unwind_Context
*context
, int regno
)
38 UNWIND_LINK_PTR (unwind_link
, _Unwind_VRS_Get
)
39 (context
, _UVRSC_CORE
, regno
, _UVRSD_UINT32
, &val
);
43 /* This macro is identical to the _Unwind_GetIP macro, except that it
44 uses "unwind_getgr" instead of "_Unwind_GetGR". */
45 #define unwind_getip(context) \
46 (unwind_getgr (arg->unwind_link, context, 15) & ~(_Unwind_Word)1)
49 # define unwind_getip _Unwind_GetIP
52 static _Unwind_Reason_Code
53 backtrace_helper (struct _Unwind_Context
*ctx
, void *a
)
55 struct trace_arg
*arg
= a
;
57 /* We are first called with address in the __backtrace function.
60 arg
->array
[arg
->cnt
] = (void *) unwind_getip (ctx
);
61 if (++arg
->cnt
== arg
->size
)
62 return _URC_END_OF_STACK
;
63 return _URC_NO_REASON
;
67 __backtrace (void **array
, int size
)
69 struct trace_arg arg
=
72 .unwind_link
= __libc_unwind_link_get (),
77 if (size
<= 0 || arg
.unwind_link
== NULL
)
80 UNWIND_LINK_PTR (arg
.unwind_link
, _Unwind_Backtrace
)
81 (backtrace_helper
, &arg
);
83 if (arg
.cnt
> 1 && arg
.array
[arg
.cnt
- 1] == NULL
)
85 return arg
.cnt
!= -1 ? arg
.cnt
: 0;
87 weak_alias (__backtrace
, backtrace
)
88 libc_hidden_def (__backtrace
)