From 2232c617036b9e9c05d2d85866f096a3df580025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Thu, 8 Sep 2011 22:04:52 +0000 Subject: [PATCH] [INTERPRETER] * BUG: Fix a crash in stack backtrace management. git-svn-id: svn://localhost/gambas/trunk@4110 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- main/gbx/gb_error.c | 2 +- main/gbx/gbx_debug.c | 11 +++++++++-- main/gbx/gbx_stack.c | 2 +- main/gbx/gbx_stack.h | 3 ++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/main/gbx/gb_error.c b/main/gbx/gb_error.c index 82ef21fd8..429420466 100644 --- a/main/gbx/gb_error.c +++ b/main/gbx/gb_error.c @@ -641,5 +641,5 @@ void ERROR_deprecated(const char *msg) void ERROR_exit(void) { ERROR_reset(&ERROR_last); - FREE(&ERROR_backtrace, "ERROR_exit"); + STACK_free_backtrace(&ERROR_backtrace); } \ No newline at end of file diff --git a/main/gbx/gbx_debug.c b/main/gbx/gbx_debug.c index e920b95c5..0a48b0936 100644 --- a/main/gbx/gbx_debug.c +++ b/main/gbx/gbx_debug.c @@ -402,6 +402,7 @@ void DEBUG_print_backtrace(STACK_BACKTRACE *bt) { int i, n; bool stop; + STACK_BACKTRACE *end; //STACK_CONTEXT *sc = (STACK_CONTEXT *)(STACK_base + STACK_size) - err->bt_count; //fprintf(stderr, "0: %s\n", DEBUG_get_position(err->cp, err->fp, err->pc)); @@ -411,7 +412,8 @@ void DEBUG_print_backtrace(STACK_BACKTRACE *bt) if (STACK_backtrace_is_end(&bt[i])) { stop = TRUE; - STACK_backtrace_remove_end(&bt[i]); + end = &bt[i]; + STACK_backtrace_clear_end(end); } if (bt[i].pc) { @@ -419,12 +421,15 @@ void DEBUG_print_backtrace(STACK_BACKTRACE *bt) fprintf(stderr, "%d: %s\n", n, DEBUG_get_position(bt[i].cp, bt[i].fp, bt[i].pc)); } } + + STACK_backtrace_set_end(end); } GB_ARRAY DEBUG_get_string_array_from_backtrace(STACK_BACKTRACE *bt) { GB_ARRAY array; int i, n, size; + STACK_BACKTRACE *end; for (i = 0, size = 0;; i++) { @@ -432,7 +437,8 @@ GB_ARRAY DEBUG_get_string_array_from_backtrace(STACK_BACKTRACE *bt) size++; if (STACK_backtrace_is_end(&bt[i])) { - STACK_backtrace_remove_end(&bt[i]); + end = &bt[i]; + STACK_backtrace_clear_end(end); break; } } @@ -448,6 +454,7 @@ GB_ARRAY DEBUG_get_string_array_from_backtrace(STACK_BACKTRACE *bt) n++; } + STACK_backtrace_set_end(end); return array; } diff --git a/main/gbx/gbx_stack.c b/main/gbx/gbx_stack.c index 20ffe5143..b319727ee 100644 --- a/main/gbx/gbx_stack.c +++ b/main/gbx/gbx_stack.c @@ -261,7 +261,7 @@ STACK_BACKTRACE *STACK_get_backtrace(void) // Mark the end of the backtrace pbt--; - pbt->cp = (void *)(((intptr_t)(pbt->cp)) | 1); + STACK_backtrace_set_end(pbt); return bt; } diff --git a/main/gbx/gbx_stack.h b/main/gbx/gbx_stack.h index bfe7c52a3..6bfbb4106 100644 --- a/main/gbx/gbx_stack.h +++ b/main/gbx/gbx_stack.h @@ -86,7 +86,8 @@ bool STACK_has_error_handler(void); STACK_BACKTRACE *STACK_get_backtrace(void); #define STACK_free_backtrace(_backtrace) FREE(_backtrace, "STRACK_free_backtrace") #define STACK_backtrace_is_end(_bt) ((((intptr_t)((_bt)->cp)) & 1) != 0) -#define STACK_backtrace_remove_end(_bt) ((_bt)->cp = (void *)(((intptr_t)((_bt)->cp)) & ~1)) +#define STACK_backtrace_set_end(_bt) ((_bt)->cp = (void *)(((intptr_t)((_bt)->cp)) | 1)) +#define STACK_backtrace_clear_end(_bt) ((_bt)->cp = (void *)(((intptr_t)((_bt)->cp)) & ~1)) STACK_CONTEXT *STACK_get_frame(int frame);