--- freem/src/xecline.c 2025/04/15 16:49:36 1.15 +++ freem/src/xecline.c 2025/04/30 14:41:03 1.19 @@ -1,5 +1,5 @@ /* - * $Id: xecline.c,v 1.15 2025/04/15 16:49:36 snw Exp $ + * $Id: xecline.c,v 1.19 2025/04/30 14:41:03 snw Exp $ * freem interpreter proper * * @@ -24,6 +24,18 @@ * along with FreeM. If not, see . * * $Log: xecline.c,v $ + * Revision 1.19 2025/04/30 14:41:03 snw + * Further debugger work + * + * Revision 1.18 2025/04/29 18:46:17 snw + * Begin work on interactive debugger + * + * Revision 1.17 2025/04/28 19:38:55 snw + * Add trace mode + * + * Revision 1.16 2025/04/28 14:52:54 snw + * Temporarily revert global handler refactor and fix reference regression in xecline + * * Revision 1.15 2025/04/15 16:49:36 snw * Make use of logprintf throughout codebase * @@ -169,6 +181,8 @@ int xecline(int typ) unsigned long jobtime; char label[256], routine[256]; + char tracestr[512]; + char *vn; char *an; char *tmp; @@ -232,6 +246,9 @@ int xecline(int typ) next_line: /* entry point for next command line */ + if (debug_mode) { + debug_mode = debugger (DEBENTRY_LINE, codptr); + } job_set_status (pid, JSTAT_INTERPRETER); @@ -280,6 +297,10 @@ next_line: /* entry point for n codptr = code; next_cmnd: /* continue line entry point */ + if (debug_mode) { + debug_mode = debugger (DEBENTRY_CMD, codptr); + } + if (sigint_in_for) goto for_quit; if (forsw && (forpost[forx][0] != '\0')) { @@ -851,6 +872,8 @@ again: } } + if (trace_mode) tracestr[0] = '\0'; + switch (mcmnd) { case MAP: @@ -973,10 +996,15 @@ set0: ch = *codptr; - if (ch == '.') { - setref = TRUE; - codptr++; - expr (NAME); + if (ch == '.') { + if (!isdigit (*(codptr + 1))) { + setref = TRUE; + codptr++; + expr (NAME); + } + else { + expr (STRING); + } } else { expr (STRING); @@ -2359,6 +2387,10 @@ s_end: case QUIT: + if (trace_mode) { + fprintf (stderr, ">> TRACE: $STACK = %d QUIT CMD = %c\r\n", nstx, nestc[nstx]); + } + if (tp_level > 0) { merr_raise (M42); goto err; @@ -2388,6 +2420,10 @@ s_end: if (nestc[nstx] == '$') { /* extrinsic function/variable */ + if (trace_mode) { + fprintf (stderr, ">> TRACE: QUIT FROM EXTRINSIC\r\n"); + } + #ifdef DEBUG_NEWSTACK printf ("EXTRINSIC\r\n"); #endif @@ -2417,6 +2453,10 @@ s_end: else { expr (STRING); + + if (trace_mode) { + fprintf (stderr, ">> TRACE: QUIT FROM SUBROUTINE\r\n"); + } if (ierr != OK - CTRLB && merr () != OK && merr () != INRPT) { @@ -2583,7 +2623,6 @@ quit0: printf ("CHECK 03 (Stack PUSH)\r\n"); #endif - if (++nstx > NESTLEVLS) { nstx--; merr_raise (STKOV); @@ -2609,7 +2648,7 @@ quit0: nestn[nstx] = 0; /* no overring of routine */ nestr[nstx] = roucur - rouptr; /* save roucur: only for $V(26) needed */ ztrap[nstx][0] = EOL; - + forsw = TRUE; ftyp = 0; /* no args is FOREVER */ @@ -3053,6 +3092,21 @@ do_xecute: do_goto: + if (trace_mode) { + char rn[256]; + stcpy (rn, rou_name); + stcnv_m2c (rn); + + switch (mcmnd) { + case DO: + snprintf (tracestr, sizeof (tracestr) - 1, "rtn = %s $stack = %d do ", rn, nstx); + break; + case GOTO: + snprintf (tracestr, sizeof (tracestr) - 1, "rtn = %s $stack = %d goto ", rn, nstx); + break; + } + } + offset = 0; label[0] = routine[0] = EOL; dofram0 = 0; @@ -3087,6 +3141,14 @@ do_goto: stcpy (label, varnam); + if (trace_mode) { + char ttt[256]; + stcpy (ttt, label); + stcnv_m2c (ttt); + + strcat (tracestr, ttt); + } + ch = *++codptr; } @@ -3102,7 +3164,12 @@ do_goto: /* unless argument is numeric, expr returns wrong codptr */ if ((ch = *codptr) != SP && (ch != EOL) && (ch != ',') && (ch != '^')) ch = *++codptr; - + + if (trace_mode) { + char ttt[256]; + snprintf (ttt, 255, "+%d", offset); + strcat (tracestr, ttt); + } } if (ch == '^') { /* parse routine */ @@ -3112,12 +3179,26 @@ do_goto: if (merr () > OK) goto err; stcpy (routine, varnam); + + if (trace_mode) { + char ttt[256]; + char ttx[256]; + + stcpy (ttt, routine); + stcnv_m2c (ttt); + snprintf (ttx, 255, "^%s", ttt); + strcat (tracestr, ttx); + } dosave[0] = EOL; ch = *++codptr; loadsw = TRUE; } + if (trace_mode) { + fprintf (stderr, ">> TRACE: %s\r\n", tracestr); + } + if (ch == '(' && mcmnd == DO) { /* parse parameter */ if (offset) { @@ -5074,24 +5155,37 @@ open_socket: expr (STRING); if (merr () > OK) break; - switch (intexpr (argptr)) { - - case 2: - DSM2err = TRUE; - break; /* enable DSM V 2 error processing */ - - case -2: - DSM2err = FALSE; - break; /* enable normal error processing */ - - case 0: - breakon = FALSE; - break; /* disable CTRL/C */ - - default: - breakon = TRUE; - break; /* enable CTRL/C */ + { + char brkstr[256]; + + stcpy (brkstr, argptr); + stcnv_m2c (brkstr); + + if (strcmp (brkstr, "DEBUG") == 0) { + debug_mode = TRUE; + } + else { + switch (intexpr (argptr)) { + + case 2: + DSM2err = TRUE; + break; /* enable DSM V 2 error processing */ + + case -2: + DSM2err = FALSE; + break; /* enable normal error processing */ + + case 0: + breakon = FALSE; + break; /* disable CTRL/C */ + + default: + breakon = TRUE; + break; /* enable CTRL/C */ + } + } } + break; case VIEW: @@ -6656,8 +6750,7 @@ syn_evt_loop_bottom: if (ch != ',' && merr () == OK) { merr_raise (SPACER); } - else if ((ierr <= OK) || (debug_mode == TRUE)) { - if (debug_mode) goto direct_mode; + else if (ierr <= OK) { if (*++codptr != SP && *codptr != EOL) goto again; merr_raise (ARGLIST); @@ -6699,6 +6792,7 @@ err: } } + if (merr () > OK ) { char er_buf[ERRLEN]; @@ -6708,6 +6802,15 @@ err: stcpy (er_buf, errmes[merr ()]); stcnv_m2c (er_buf); + + /* + if (usermode == 1 && ztrap[nstx][0] == EOL && etrap[0] == '\0') { + debug_mode = TRUE; + debugger (DEBENTRY_ERROR, codptr); + } + */ + + #if !defined(MSDOS) logprintf (FM_LOG_DEBUG, "xecline: interpreter error %d [%s]", ierr, er_buf); #endif @@ -7080,6 +7183,7 @@ restart: free (t_nsn); + } @@ -7141,9 +7245,6 @@ restore: goto next_cmnd; } - else { - if (debug_mode) goto direct_mode; - } if (libcall == TRUE) { /* library mode: don't go to direct mode, just return */ return merr (); @@ -7220,13 +7321,6 @@ direct_mode: } } - else if (strcmp (fmrl_buf, "step") == 0) { - debug_mode = TRUE; - goto zgo; - } - else if ((strcmp (fmrl_buf, "cont") == 0) || (strcmp (fmrl_buf, "continue") == 0)) { - debug_mode = FALSE; - } else if (strcmp (fmrl_buf, "rbuf") == 0) { rbuf_dump (); }