Debian Codegraph @

rpython/translator/c/src/debug_traceback.h

raw symbols SCIP
1 /**************************************************************/
2 /*** C header subsection: RPython tracebacks for debugging ***/
3
4
5 /* We store a list of (location, exctype) in a circular buffer that
6 we hope is large enough. Example of how to interpret the content
7 of the buffer:
8
9 location exctype meaning
10
11 NULL &KeyError a KeyError was raised
12 h:5 NULL it was raised at h:5
13 g:12 NULL which itself was called from g:12
14 f:17 &KeyError called from f:17, where a finally block starts
15 ... ...more exceptions can occur...
16 RERAISE &KeyError eventually the KeyError is re-raised by f
17 entry:25 NULL which itself was called from entry:25
18
19 Note that decoding the buffer assumes that when exctype matches, it was
20 really the same exception, for the purpose of going back from the RERAISE
21 line to the f:17/KeyError line.
22 */
23
24 #ifdef RPY_LL_ASSERT
25 # define PYPY_DEBUG_TRACEBACK_DEPTH 8192 /* a power of two */
26 #else
27 # define PYPY_DEBUG_TRACEBACK_DEPTH 128 /* a power of two */
28 #endif
29
30 #define PYPYDTPOS_RERAISE ((struct pypydtpos_s *) -1)
31 #define PYPYDTSTORE(loc, etype) \
32 pypy_debug_tracebacks[pypydtcount].location = loc; \
33 pypy_debug_tracebacks[pypydtcount].exctype = etype; \
34 pypydtcount = (pypydtcount + 1) & (PYPY_DEBUG_TRACEBACK_DEPTH-1)
35
36 #define OP_DEBUG_START_TRACEBACK(etype, _) PYPYDTSTORE(NULL, etype)
37 #define OP_DEBUG_RERAISE_TRACEBACK(etp, _) PYPYDTSTORE(PYPYDTPOS_RERAISE, etp)
38 #define OP_DEBUG_PRINT_TRACEBACK() pypy_debug_traceback_print()
39
40 #define PYPY_DEBUG_RECORD_TRACEBACK(funcname) { \
41 static struct pypydtpos_s loc = { \
42 PYPY_FILE_NAME, funcname, __LINE__ }; \
43 PYPYDTSTORE(&loc, NULL); \
44 }
45 #define PYPY_DEBUG_CATCH_EXCEPTION(funcname, etype, is_fatal) { \
46 static struct pypydtpos_s loc = { \
47 PYPY_FILE_NAME, funcname, __LINE__ }; \
48 PYPYDTSTORE(&loc, etype); \
49 if (is_fatal) pypy_debug_catch_fatal_exception(); \
50 }
51
52 struct pypydtpos_s {
53 const char *filename;
54 const char *funcname;
55 int lineno;
56 };
57
58 struct pypydtentry_s {
59 struct pypydtpos_s *location;
60 void *exctype;
61 };
62
63 RPY_EXTERN int pypydtcount;
64 RPY_EXTERN struct pypydtentry_s pypy_debug_tracebacks[PYPY_DEBUG_TRACEBACK_DEPTH];
65
66 RPY_EXTERN void pypy_debug_traceback_print(void);
67 RPY_EXTERN void pypy_debug_catch_fatal_exception(void);