| 1 |
#include "singleheader.h" |
| 2 |
#include "src/debug_traceback.h" |
| 3 |
#include <stdio.h> |
| 4 |
#include <stdlib.h> |
| 5 |
|
| 6 |
int pypydtcount = 0; |
| 7 |
struct pypydtentry_s pypy_debug_tracebacks[PYPY_DEBUG_TRACEBACK_DEPTH]; |
| 8 |
|
| 9 |
void pypy_debug_traceback_print(void) |
| 10 |
{ |
| 11 |
int i; |
| 12 |
int skipping; |
| 13 |
void *my_etype = RPyFetchExceptionType(); |
| 14 |
struct pypydtpos_s *location; |
| 15 |
void *etype; |
| 16 |
int has_loc; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
fprintf(stderr, "RPython traceback:\n"); |
| 21 |
skipping = 0; |
| 22 |
i = pypydtcount; |
| 23 |
while (1) |
| 24 |
{ |
| 25 |
i = (i - 1) & (PYPY_DEBUG_TRACEBACK_DEPTH-1); |
| 26 |
if (i == pypydtcount) |
| 27 |
{ |
| 28 |
fprintf(stderr, " ...\n"); |
| 29 |
break; |
| 30 |
} |
| 31 |
|
| 32 |
location = pypy_debug_tracebacks[i].location; |
| 33 |
etype = pypy_debug_tracebacks[i].exctype; |
| 34 |
has_loc = location != NULL && location != PYPYDTPOS_RERAISE; |
| 35 |
|
| 36 |
if (skipping && has_loc && etype == my_etype) |
| 37 |
skipping = 0; |
| 38 |
|
| 39 |
if (!skipping) |
| 40 |
{ |
| 41 |
if (has_loc) |
| 42 |
fprintf(stderr, " File \"%s\", line %d, in %s\n", |
| 43 |
location->filename, location->lineno, location->funcname); |
| 44 |
else |
| 45 |
{ |
| 46 |
|
| 47 |
if (!my_etype) |
| 48 |
my_etype = etype; |
| 49 |
if (etype != my_etype) |
| 50 |
{ |
| 51 |
fprintf(stderr, " Note: this traceback is " |
| 52 |
"incomplete or corrupted!\n"); |
| 53 |
break; |
| 54 |
} |
| 55 |
if (location == NULL) |
| 56 |
break; |
| 57 |
skipping = 1; |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
void pypy_debug_catch_fatal_exception(void) |
| 64 |
{ |
| 65 |
pypy_debug_traceback_print(); |
| 66 |
fprintf(stderr, "Fatal RPython error: %.*s\n", |
| 67 |
(int)(RPyFetchExceptionType()->ov_name->rs_chars.length), |
| 68 |
RPyFetchExceptionType()->ov_name->rs_chars.items); |
| 69 |
abort(); |
| 70 |
} |