]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/powerpc/powerpc64/backtrace.c
* debug/pread64_chk.c: Use __libc_pread64 instead of __pread64.
[thirdparty/glibc.git] / sysdeps / powerpc / powerpc64 / backtrace.c
CommitLineData
cfc91acd 1/* Return backtrace of current program state.
0e66ade5 2 Copyright (C) 1998, 2000, 2002, 2005 Free Software Foundation, Inc.
cfc91acd
RM
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
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 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20#include <execinfo.h>
21#include <stddef.h>
22#include <bp-checks.h>
23
24/* This is the stack layout we see with every stack frame.
25 Note that every routine is required by the ABI to lay out the stack
26 like this.
27
28 +----------------+ +-----------------+
29 %r1 -> | %r1 last frame--------> | %r1 last frame--->... --> NULL
30 | | | |
31 | cr save | | cr save |
32 | | | |
33 | (unused) | | return address |
34 +----------------+ +-----------------+
35*/
36struct layout
37{
38 struct layout *__unbounded next;
39 long condition_register;
40 void *__unbounded return_address;
41};
42
43int
44__backtrace (void **array, int size)
45{
46 struct layout *current;
47 int count;
48
49 /* Force gcc to spill LR. */
50 asm volatile ("" : "=l"(current));
51
52 /* Get the address on top-of-stack. */
53 asm volatile ("ld %0,0(1)" : "=r"(current));
54 current = BOUNDED_1 (current);
55
56 for ( count = 0;
57 current != NULL && count < size;
58 current = BOUNDED_1 (current->next), count++)
59 array[count] = current->return_address;
60
61 /* It's possible the second-last stack frame can't return
62 (that is, it's __libc_start_main), in which case
63 the CRT startup code will have set its LR to 'NULL'. */
64 if (count > 0 && array[count-1] == NULL)
65 count--;
66
67 return count;
68}
69weak_alias (__backtrace, backtrace)
0e66ade5 70libc_hidden_def (__backtrace)