* sysdeps/unix/sysv/linux/m68k/sysdep.h (INLINE_SYSCALL): Don't
[glibc.git] / sysdeps / s390 / s390-32 / backtrace.c
blobb89b5a39d91e9a643fff5bd37d12175db32201da
1 /* Return backtrace of current program state.
2 Copyright (C) 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #include <execinfo.h>
22 #include <stddef.h>
24 /* This is a global variable set at program start time. It marks the
25 highest used stack address. */
26 extern void *__libc_stack_end;
29 /* This is the stack layout we see for every non-leaf function.
30 size offset
31 %r15 -> +------------------+
32 4 | back chain | 0
33 4 | end of stack | 4
34 8 | glue | 8
35 8 | scratch | 16
36 40 | save area r6-r15 | 24
37 16 | save area f4,f6 | 64
38 16 | empty | 80
39 +------------------+
40 r14 in the save area holds the return address.
43 struct layout
45 int back_chain;
46 int end_of_stack;
47 int glue[2];
48 int scratch[2];
49 int save_grps[10];
50 int save_fp[4];
51 int empty[2];
54 int
55 __backtrace (array, size)
56 void **array;
57 int size;
59 /* We assume that all the code is generated with frame pointers set. */
60 struct layout *stack;
61 int cnt = 0;
63 asm ("LR %0,%%r15" : "=d" (stack) );
64 /* We skip the call to this function, it makes no sense to record it. */
65 stack = (struct layout *) stack->back_chain;
66 while (cnt < size)
68 if (stack == NULL || (void *) stack > __libc_stack_end)
69 /* This means the address is out of range. Note that for the
70 toplevel we see a frame pointer with value NULL which clearly is
71 out of range. */
72 break;
74 array[cnt++] = stack->save_grps[8];
76 stack = (struct layout *) stack->back_chain;
79 return cnt;
81 weak_alias (__backtrace, backtrace)