source: git/omalloc/omGetBackTrace.c @ 3af3ca

fieker-DuValspielwiese
Last change on this file since 3af3ca was 341696, checked in by Hans Schönemann <hannes@…>, 15 years ago
Adding Id property to all files git-svn-id: file:///usr/local/Singular/svn/trunk@12231 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • 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 *  Version: $Id$
7 *******************************************************************/
8#ifndef OM_NDEBUG
9
10#if __GNUC__ > 1
11
12static void* om_this_main_frame_addr = 0;
13
14void omInitGetBackTrace()
15{
16  if (__builtin_frame_address(0) != 0 &&
17      __builtin_frame_address(1) > __builtin_frame_address(0))
18    om_this_main_frame_addr = __builtin_frame_address(1);
19}
20
21#define OM_GET_BACK_TRACE(j)                                    \
22case j:                                                         \
23{                                                               \
24  f_addr = __builtin_frame_address(j);                          \
25  if (f_addr  > this_frame && f_addr < om_this_main_frame_addr) \
26  {                                                             \
27    r_addr = __builtin_return_address(j);                       \
28    if (r_addr)                                                 \
29    {                                                           \
30      bt[i] = r_addr;                                           \
31      i++;                                                      \
32      if (i >= max) break;                                      \
33    }                                                           \
34    else break;                                                 \
35  }                                                             \
36  else break;                                                   \
37}
38
39int omGetBackTrace(void** bt, int start, int max)
40{
41  int i = 0;
42  void* this_frame = __builtin_frame_address(0);
43  void* f_addr;
44  void* r_addr;
45
46  start++;
47
48  switch(start)
49  {
50    OM_GET_BACK_TRACE(1)
51    OM_GET_BACK_TRACE(2)
52    OM_GET_BACK_TRACE(3)
53    OM_GET_BACK_TRACE(4)
54    OM_GET_BACK_TRACE(5)
55    OM_GET_BACK_TRACE(6)
56    OM_GET_BACK_TRACE(7)
57    OM_GET_BACK_TRACE(8)
58    OM_GET_BACK_TRACE(9)
59    OM_GET_BACK_TRACE(10)
60    OM_GET_BACK_TRACE(11)
61    OM_GET_BACK_TRACE(12)
62    OM_GET_BACK_TRACE(13)
63    OM_GET_BACK_TRACE(14)
64    OM_GET_BACK_TRACE(15)
65    OM_GET_BACK_TRACE(16)
66    OM_GET_BACK_TRACE(17)
67  }
68  if (i < max) bt[i] = 0;
69  return i;
70}
71
72#endif /* __GNUC__ > 1 */
73
74#endif /* ! OM_NDEBUG */
Note: See TracBrowser for help on using the repository browser.