b10840213a4448d2bdb12a7418c9197ef832fc4a
[platform/upstream/gcc.git] / libjava / sysdep / i386 / backtrace.h
1 // backtrace.h - Fallback backtrace implementation. i386 implementation.
2
3 /* Copyright (C) 2005  Free Software Foundation
4
5    This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
9 details.  */
10
11 #ifndef __SYSDEP_BACKTRACE_H__
12 #define __SYSDEP_BACKTRACE_H__
13
14 #include <java-stack.h>
15
16 #define HAVE_FALLBACK_BACKTRACE
17
18 /* Store return addresses of the current program stack in
19    STATE and return the exact number of values stored.  */
20 void
21 fallback_backtrace (_Jv_UnwindState *state)
22 {
23   register void *_ebp __asm__ ("ebp");
24   register void *_esp __asm__ ("esp");
25   unsigned int *rfp;
26
27   int i = state->pos;
28   for (rfp = *(unsigned int**)_ebp;
29        rfp && i < state->length;
30        rfp = *(unsigned int **)rfp)
31     {
32       int diff = *rfp - (unsigned int)rfp;
33       if ((void*)rfp < _esp || diff > 4 * 1024 || diff < 0)
34         break;
35
36       state->frames[i].type = frame_native;
37       state->frames[i].ip = (void*)(rfp[1]-4);
38       i++;
39     }
40   state->pos = i;
41 }
42 #endif