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#include "omalloc/omConfig.h"
8
9#ifdef HAVE_OMALLOC
10#ifndef OM_NDEBUG
11
12#if __GNUC__ > 1
13
14static void* om_this_main_frame_addr = 0;
15
17{
18 if (__builtin_frame_address(0) != 0 &&
19 __builtin_frame_address(1) > __builtin_frame_address(0))
20 om_this_main_frame_addr = __builtin_frame_address(1);
21}
22
23#define OM_GET_BACK_TRACE(j) \
24case j: \
25{ \
26 f_addr = __builtin_frame_address(j); \
27 if (f_addr > this_frame && f_addr < om_this_main_frame_addr) \
28 { \
29 r_addr = __builtin_return_address(j); \
30 if (r_addr) \
31 { \
32 bt[i] = r_addr; \
33 i++; \
34 if (i >= max) break; \
35 } \
36 else break; \
37 } \
38 else break; \
39}
40
41int omGetBackTrace(void** bt, int start, int max)
42{
43 int i = 0;
44 void* this_frame = __builtin_frame_address(0);
45 void* f_addr;
46 void* r_addr;
47
48 start++;
49
50 switch(start)
51 {
52 OM_GET_BACK_TRACE(1)
53 OM_GET_BACK_TRACE(2)
54/* the following fails on Mac OsX, but the debugging
55 * support it provides is too useful to disable it
56 */
57#ifdef __linux
58#if defined(__x86_64) || defined(__i386)
59 OM_GET_BACK_TRACE(3)
60 OM_GET_BACK_TRACE(4)
61 OM_GET_BACK_TRACE(5)
62 OM_GET_BACK_TRACE(6)
63 OM_GET_BACK_TRACE(7)
64 OM_GET_BACK_TRACE(8)
65 OM_GET_BACK_TRACE(9)
66 OM_GET_BACK_TRACE(10)
67 OM_GET_BACK_TRACE(11)
68 OM_GET_BACK_TRACE(12)
69 OM_GET_BACK_TRACE(13)
70 OM_GET_BACK_TRACE(14)
71 OM_GET_BACK_TRACE(15)
72 OM_GET_BACK_TRACE(16)
73 OM_GET_BACK_TRACE(17)
74#endif
75#endif
76 }
77 if (i < max) bt[i] = 0;
78 return i;
79}
80
81#endif /* __GNUC__ > 1 */
82
83#endif /* ! OM_NDEBUG */
84#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)