My Project
Loading...
Searching...
No Matches
omGetBackTrace.c
Go to the documentation of this file.
1/*******************************************************************
2 * File: omGetBackTrace.c
3 * Purpose: routines for getting Backtraces of stack
4 * Author: obachman (Olaf Bachmann)
5 * Created: 11/99
6 *******************************************************************/
7#ifndef OM_INLINE /*during configure omConfig.h does not exists yet*/
8#include "omalloc/omConfig.h"
9#endif
10
11#ifdef HAVE_OMALLOC
12#ifndef OM_NDEBUG
13
14#if __GNUC__ > 1
15
16static void* om_this_main_frame_addr = 0;
17
19{
20 if (__builtin_frame_address(0) != 0 &&
21 __builtin_frame_address(1) > __builtin_frame_address(0))
22 om_this_main_frame_addr = __builtin_frame_address(1);
23}
24
25#define OM_GET_BACK_TRACE(j) \
26case j: \
27{ \
28 f_addr = __builtin_frame_address(j); \
29 if (f_addr > this_frame && f_addr < om_this_main_frame_addr) \
30 { \
31 r_addr = __builtin_return_address(j); \
32 if (r_addr) \
33 { \
34 bt[i] = r_addr; \
35 i++; \
36 if (i >= max) break; \
37 } \
38 else break; \
39 } \
40 else break; \
41}
42
43int omGetBackTrace(void** bt, int start, int max)
44{
45 int i = 0;
46 void* this_frame = __builtin_frame_address(0);
47 void* f_addr;
48 void* r_addr;
49
50 start++;
51
52 switch(start)
53 {
54 OM_GET_BACK_TRACE(1)
55 OM_GET_BACK_TRACE(2)
56/* the following fails on Mac OsX, but the debugging
57 * support it provides is too useful to disable it
58 */
59#ifdef __linux
60#if defined(__x86_64) || defined(__i386)
61 OM_GET_BACK_TRACE(3)
62 OM_GET_BACK_TRACE(4)
63 OM_GET_BACK_TRACE(5)
64 OM_GET_BACK_TRACE(6)
65 OM_GET_BACK_TRACE(7)
66 OM_GET_BACK_TRACE(8)
67 OM_GET_BACK_TRACE(9)
68 OM_GET_BACK_TRACE(10)
69 OM_GET_BACK_TRACE(11)
70 OM_GET_BACK_TRACE(12)
71 OM_GET_BACK_TRACE(13)
72 OM_GET_BACK_TRACE(14)
73 OM_GET_BACK_TRACE(15)
74 OM_GET_BACK_TRACE(16)
75 OM_GET_BACK_TRACE(17)
76#endif
77#endif
78 }
79 if (i < max) bt[i] = 0;
80 return i;
81}
82
83#endif /* __GNUC__ > 1 */
84
85#endif /* ! OM_NDEBUG */
86#endif
int i
Definition cfEzgcd.cc:132
static int max(int a, int b)
Definition fast_mult.cc:264
#define omInitGetBackTrace()
#define omGetBackTrace(bt, s, max)