Back to index

glibc  2.9
backtrace.c
Go to the documentation of this file.
00001 /* Return backtrace of current program state.
00002    Copyright (C) 2008 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by David S. Miller <davem@davemloft.net>
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public License as
00008    published by the Free Software Foundation; either version 2 of the
00009    License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public
00017    License along with the GNU C Library; see the file COPYING.LIB.  If not,
00018    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019    Boston, MA 02111-1307, USA.  */
00020 
00021 #include <execinfo.h>
00022 #include <stddef.h>
00023 #include <bp-checks.h>
00024 #include <sysdep.h>
00025 
00026 struct layout
00027 {
00028   unsigned long locals[8];
00029   unsigned long ins[6];
00030   unsigned long next;
00031   void *__unbounded return_address;
00032 };
00033 
00034 int
00035 __backtrace (void **array, int size)
00036 {
00037   struct layout *current;
00038   unsigned long fp;
00039   int count;
00040 
00041   asm volatile ("flushw");
00042   asm volatile ("mov %%fp, %0" : "=r"(fp));
00043   current = (struct layout *__unbounded) (fp + STACK_BIAS);
00044   current = BOUNDED_1 (current);
00045 
00046   for (count = 0; count < size; count++)
00047     {
00048       array[count] = current->return_address;
00049       if (!current->next)
00050        break;
00051       current = (struct layout *__unbounded) (current->next + STACK_BIAS);
00052       current = BOUNDED_1 (current);
00053     }
00054 
00055   return count;
00056 }
00057 weak_alias (__backtrace, backtrace)
00058 libc_hidden_def (__backtrace)