diff --git a/HISTORY b/HISTORY index 647d484..581c2b3 100755 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,7 @@ +Jan. 30 2016 +Added a TRACE command to the shell +Fixed an infinity bug in the mb_debug_get_stack_trace function + Jan. 29 2016 Fixed lookup bugs with member sub routine of a class instance Fixed a member accessing bug with class instance diff --git a/core/my_basic.c b/core/my_basic.c index 9d29073..787c563 100755 --- a/core/my_basic.c +++ b/core/my_basic.c @@ -11190,7 +11190,7 @@ int mb_debug_get_stack_trace(struct mb_interpreter_t* s, void** l, char** fs, un if(fs && fc) { f = s->stack_frames->prev; - while(f && f->data && i < fc) { + while(f != s->stack_frames && f && f->data && i < fc) { fs[i++] = (char*)f->data; f = f->prev; } diff --git a/output/my_basic_mac b/output/my_basic_mac index 6807a9a..d33eda8 100755 Binary files a/output/my_basic_mac and b/output/my_basic_mac differ diff --git a/shell/main.c b/shell/main.c index 4a29ed5..df34d1f 100755 --- a/shell/main.c +++ b/shell/main.c @@ -1144,6 +1144,30 @@ static int set_importing_dirs(struct mb_interpreter_t* s, void** l) { return result; } +static int trace(struct mb_interpreter_t* s, void** l) { + int result = MB_FUNC_OK; + char* frames[16]; + char** p = frames; + + mb_assert(s && l); + + mb_check(mb_attempt_open_bracket(s, l)); + + mb_check(mb_attempt_close_bracket(s, l)); + + mb_check(mb_debug_get_stack_trace(s, l, frames, _countof(frames))); + + while(*p) { + _printf("%s", *p); + ++p; + if(*p) { + _printf(" <- "); + } + } + + return result; +} + static int gc(struct mb_interpreter_t* s, void** l) { int result = MB_FUNC_OK; int_t collected = 0; @@ -1193,6 +1217,7 @@ static void _on_stepped(struct mb_interpreter_t* s, char* f, int p, unsigned sho static void _on_error(struct mb_interpreter_t* s, mb_error_e e, char* m, char* f, int p, unsigned short row, unsigned short col, int abort_code) { mb_unrefvar(s); mb_unrefvar(p); + if(SE_NO_ERR != e) { if(f) { _printf("Error:\n [LINE] %d, [COL] %d, [FILE] %s,\n [CODE] %d, [MESSAGE] %s, [ABORT CODE] %d.\n", row, col, f, e, m, abort_code); @@ -1245,6 +1270,7 @@ static void _on_startup(void) { #endif /* _HAS_TICKS */ mb_reg_fun(bas, now); mb_reg_fun(bas, set_importing_dirs); + mb_reg_fun(bas, trace); mb_reg_fun(bas, gc); mb_reg_fun(bas, beep); }