From 8d35b87fd1123273506dee1d29fe451cc43b6757 Mon Sep 17 00:00:00 2001 From: FellippeHeitor Date: Sun, 18 Jul 2021 22:02:41 -0300 Subject: [PATCH] Initial implementation of call stack ($DEBUG). --- source/ide/ide_methods.bas | 5 +++++ source/qb64.bas | 16 +++++++++++++--- source/utilities/vwatch/vwatch.bi | 2 ++ source/utilities/vwatch/vwatch.bm | 5 +++++ source/utilities/vwatch_stub.bm | 2 ++ 5 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 source/utilities/vwatch_stub.bm diff --git a/source/ide/ide_methods.bas b/source/ide/ide_methods.bas index 2e0e5b062..4720cb365 100644 --- a/source/ide/ide_methods.bas +++ b/source/ide/ide_methods.bas @@ -6315,6 +6315,11 @@ SUB DebugMode COLOR , 4 setStatusMessage 1, "Error occurred on line" + STR$(l), 13 PauseMode = -1 + CASE "call" + callstack = callstack + 1 + onLine$ = STR$(CVL(RIGHT$(value$, 4))) + procedure$ = LEFT$(value$, LEN(value$) - 4) + 'store this in an array and allow it to be inspected END SELECT _LIMIT 100 diff --git a/source/qb64.bas b/source/qb64.bas index 88cd5a9ed..dc3a300c7 100644 --- a/source/qb64.bas +++ b/source/qb64.bas @@ -4761,6 +4761,7 @@ DO END IF subfunc = RTRIM$(id.callname) 'SUB_..." + subfuncoriginalname$ = RTRIM$(id.cn) subfuncn = subfuncn + 1 closedsubfunc = 0 subfuncid = targetid @@ -5122,9 +5123,6 @@ DO PRINT #12, "uint8 *tmp_mem_static_pointer=mem_static_pointer;" PRINT #12, "uint32 tmp_cmem_sp=cmem_sp;" PRINT #12, "#include " + CHR$(34) + "data" + str2$(subfuncn) + ".txt" + CHR$(34) - IF vWatchOn = 1 THEN - PRINT #12, "*__LONG_VWATCH_SUBLEVEL=*__LONG_VWATCH_SUBLEVEL+ 1 ;" - END IF 'create new _MEM lock for this scope PRINT #12, "mem_lock *sf_mem_lock;" 'MUST not be static for recursion reasons @@ -5132,6 +5130,18 @@ DO PRINT #12, "sf_mem_lock=mem_lock_tmp;" PRINT #12, "sf_mem_lock->type=3;" + IF vWatchOn = 1 THEN + PRINT #12, "*__LONG_VWATCH_SUBLEVEL=*__LONG_VWATCH_SUBLEVEL+ 1 ;" + IF subfunc <> "SUB_VWATCH" THEN + temp$ = "FUNCTION " + IF id.subfunc = 2 THEN temp$ = "SUB " + temp$ = temp$ + subfuncoriginalname$ + PRINT #12, "qbs_set(__STRING_VWATCH_SUBNAME,qbs_new_txt_len(" + CHR$(34) + temp$ + CHR$(34) + "," + str2$(LEN(temp$)) + "));" + PRINT #12, "qbs_cleanup(qbs_tmp_base,0);" + PRINT #12, "*__LONG_VWATCH_LINENUMBER=-2; SUB_VWATCH((ptrszint*)vwatch_local_vars);" + END IF + END IF + PRINT #12, "if (new_error) goto exit_subfunc;" 'statementn = statementn + 1 diff --git a/source/utilities/vwatch/vwatch.bi b/source/utilities/vwatch/vwatch.bi index 14174e076..5f34af30d 100644 --- a/source/utilities/vwatch/vwatch.bi +++ b/source/utilities/vwatch/vwatch.bi @@ -1,8 +1,10 @@ $CHECKING:OFF DIM SHARED AS LONG vwatch_linenumber, vwatch_sublevel +DIM SHARED AS STRING vwatch_subname REDIM SHARED vwatch_breakpoints(0) AS _BYTE 'next lines are just to avoid "unused variable" warnings: vwatch_linenumber = 0 vwatch_sublevel = 0 vwatch_breakpoints(0) = 0 +vwatch_subname = "" $CHECKING:ON diff --git a/source/utilities/vwatch/vwatch.bm b/source/utilities/vwatch/vwatch.bm index 3db582dd3..5c96de6c5 100644 --- a/source/utilities/vwatch/vwatch.bm +++ b/source/utilities/vwatch/vwatch.bm @@ -75,6 +75,11 @@ SUB vwatch (localVariables AS _OFFSET) cmd$ = "error:" + MKL$(lastLine) GOSUB SendCommand EXIT SUB + ELSEIF vwatch_linenumber = -2 THEN + 'report a new sub/function has been "entered" + cmd$ = "call:" + vwatch_subname + MKL$(lastLine) + GOSUB SendCommand + EXIT SUB END IF IF vwatch_linenumber = lastLine THEN EXIT SUB diff --git a/source/utilities/vwatch_stub.bm b/source/utilities/vwatch_stub.bm new file mode 100644 index 000000000..f78094759 --- /dev/null +++ b/source/utilities/vwatch_stub.bm @@ -0,0 +1,2 @@ +SUB vwatch () +END SUB