source: git/omalloc/omGetBackTrace.c @ 9cf75aa

spielwiese
Last change on this file since 9cf75aa was 6ce030f, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
removal of the $Id$ svn tag from everywhere NOTE: the git SHA1 may be used instead (only on special places) NOTE: the libraries Singular/LIB/*.lib still contain the marker due to our current use of svn
  • Property mode set to 100644
File size: 2.3 KB
Line 
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_NDEBUG
8
9#if __GNUC__ > 1
10
11static void* om_this_main_frame_addr = 0;
12
13void omInitGetBackTrace()
14{
15  if (__builtin_frame_address(0) != 0 &&
16      __builtin_frame_address(1) > __builtin_frame_address(0))
17    om_this_main_frame_addr = __builtin_frame_address(1);
18}
19
20#define OM_GET_BACK_TRACE(j)                                    \
21case j:                                                         \
22{                                                               \
23  f_addr = __builtin_frame_address(j);                          \
24  if (f_addr  > this_frame && f_addr < om_this_main_frame_addr) \
25  {                                                             \
26    r_addr = __builtin_return_address(j);                       \
27    if (r_addr)                                                 \
28    {                                                           \
29      bt[i] = r_addr;                                           \
30      i++;                                                      \
31      if (i >= max) break;                                      \
32    }                                                           \
33    else break;                                                 \
34  }                                                             \
35  else break;                                                   \
36}
37
38int omGetBackTrace(void** bt, int start, int max)
39{
40  int i = 0;
41  void* this_frame = __builtin_frame_address(0);
42  void* f_addr;
43  void* r_addr;
44
45  start++;
46
47  switch(start)
48  {
49    OM_GET_BACK_TRACE(1)
50    OM_GET_BACK_TRACE(2)
51    OM_GET_BACK_TRACE(3)
52    OM_GET_BACK_TRACE(4)
53    OM_GET_BACK_TRACE(5)
54    OM_GET_BACK_TRACE(6)
55    OM_GET_BACK_TRACE(7)
56    OM_GET_BACK_TRACE(8)
57    OM_GET_BACK_TRACE(9)
58    OM_GET_BACK_TRACE(10)
59    OM_GET_BACK_TRACE(11)
60    OM_GET_BACK_TRACE(12)
61    OM_GET_BACK_TRACE(13)
62    OM_GET_BACK_TRACE(14)
63    OM_GET_BACK_TRACE(15)
64    OM_GET_BACK_TRACE(16)
65    OM_GET_BACK_TRACE(17)
66  }
67  if (i < max) bt[i] = 0;
68  return i;
69}
70
71#endif /* __GNUC__ > 1 */
72
73#endif /* ! OM_NDEBUG */
Note: See TracBrowser for help on using the repository browser.