From 224bb2aed0514bfa1dbfb4ee76bb2f79bd976cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Sun, 18 May 2014 21:39:52 +0000 Subject: [PATCH] [INTERPRETER] * BUG: Add a small reserved area in the stack for the Eval() function, so that the debugger can return the contents of a variable after a stack overflow without raising a new stack overflow error and then crashing. git-svn-id: svn://localhost/gambas/trunk@6276 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- main/gbx/gbx_eval.c | 3 +++ main/gbx/gbx_stack.c | 3 ++- main/gbx/gbx_stack.h | 9 +++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/main/gbx/gbx_eval.c b/main/gbx/gbx_eval.c index 6095e28bd..8d2c4ebf4 100644 --- a/main/gbx/gbx_eval.c +++ b/main/gbx/gbx_eval.c @@ -104,6 +104,8 @@ bool EVAL_expression(EXPRESSION *expr, EVAL_FUNCTION func) fprintf(stderr, "EVAL: %s\n", EVAL->source); #endif + STACK_enable_for_eval(); + nvar = EVAL->nvar; STACK_check(nvar); @@ -139,6 +141,7 @@ bool EVAL_expression(EXPRESSION *expr, EVAL_FUNCTION func) } END_TRY + STACK_disable_for_eval(); EXEC_debug = debug; return error; } diff --git a/main/gbx/gbx_stack.c b/main/gbx/gbx_stack.c index 455fe23c4..427bfe831 100644 --- a/main/gbx/gbx_stack.c +++ b/main/gbx/gbx_stack.c @@ -68,9 +68,10 @@ void STACK_init(void) STACK_process_stack_limit = (uintptr_t)&stack - max + 65536; - STACK_limit = (STACK_base + STACK_size); + STACK_limit = STACK_base + STACK_size; STACK_frame = (STACK_CONTEXT *)STACK_limit; STACK_frame_count = 0; + STACK_limit -= STACK_FOR_EVAL * sizeof(VALUE); SP = (VALUE *)STACK_base; } diff --git a/main/gbx/gbx_stack.h b/main/gbx/gbx_stack.h index f71402ad8..6469611f6 100644 --- a/main/gbx/gbx_stack.h +++ b/main/gbx/gbx_stack.h @@ -69,6 +69,8 @@ EXTERN uintptr_t STACK_process_stack_limit; #endif +#define STACK_FOR_EVAL 16 + void STACK_init(void); void STACK_exit(void); @@ -119,7 +121,7 @@ STACK_CONTEXT *STACK_get_frame(int frame); STACK_copy(STACK_frame, _context); \ \ STACK_frame_count++; \ - STACK_limit = (char *)STACK_frame; \ + STACK_limit -= sizeof(STACK_CONTEXT); \ }) #define STACK_pop_frame(_context) \ @@ -127,7 +129,10 @@ STACK_CONTEXT *STACK_get_frame(int frame); STACK_copy(_context, STACK_frame); \ STACK_frame++; \ STACK_frame_count--; \ - STACK_limit = (char *)STACK_frame; \ + STACK_limit += sizeof(STACK_CONTEXT); \ }) +#define STACK_enable_for_eval() STACK_limit += STACK_FOR_EVAL * sizeof(VALUE) +#define STACK_disable_for_eval() STACK_limit -= STACK_FOR_EVAL * sizeof(VALUE) + #endif