1
0
mirror of https://github.com/simh/simh.git synced 2026-01-11 23:52:58 +00:00

SCP: Properly write debug output for commands run at the sim> prompt

- Without regard to whether the circular buffer data is otherwise in
   use while instructions are executing.
- When a circular debug buffer is in use, avoid writing out the contents
  with the periodic open file flushes and only do so on returns to the
  sim> prompt and when debug is closed
This commit is contained in:
Mark Pizzolato 2023-11-12 12:49:07 -10:00
parent 4b8902cd06
commit 65d0ae2a44
4 changed files with 23 additions and 17 deletions

19
scp.c
View File

@ -3192,8 +3192,9 @@ if ((stat = sim_brk_init ()) != SCPE_OK) {
sim_exit_status = EXIT_FAILURE;
goto cleanup_and_exit;
}
/* always check for register definition problems */
sim_sanity_check_register_declarations (NULL);
/* always check for register definition problems, unless we already did that */
if (register_check == FALSE)
sim_sanity_check_register_declarations (NULL);
if (device_unit_tests) {
int i;
@ -9604,7 +9605,7 @@ if (warned)
return r;
}
void sim_flush_buffered_files (void)
void sim_flush_buffered_files (t_bool debug_flush)
{
uint32 i, j;
DEVICE *dptr;
@ -9612,7 +9613,7 @@ UNIT *uptr;
if (sim_log) /* flush console log */
fflush (sim_log);
if (sim_deb) /* flush debug log */
if (debug_flush && (sim_deb != NULL)) /* flush debug log */
_sim_debug_flush ();
for (i = 1; (dptr = sim_devices[i]) != NULL; i++) { /* flush attached files */
for (j = 0; j < dptr->numunits; j++) { /* if not buffered in mem */
@ -9640,7 +9641,7 @@ t_stat
flush_svc (UNIT *uptr)
{
sim_activate_after (uptr, sim_flush_interval * 1000000);
sim_flush_buffered_files ();
sim_flush_buffered_files (FALSE);
return SCPE_OK;
}
@ -9920,7 +9921,7 @@ sim_brk_clrall (BRK_TYP_DYN_STEPOVER); /* cancel any step/over
signal (SIGHUP, sigterm_received ? SIG_IGN : SIG_DFL); /* cancel WRU */
#endif
signal (SIGTERM, sigterm_received ? SIG_IGN : SIG_DFL); /* cancel WRU */
sim_flush_buffered_files();
sim_flush_buffered_files (TRUE);
sim_cancel (&sim_flush_unit); /* cancel flush timer */
sim_cancel_step (); /* cancel step timer */
sim_throt_cancel (); /* cancel throttle */
@ -14232,9 +14233,9 @@ return SCPE_OK;
void _sim_scp_abort (const char *msg, const char *file, int linenum)
{
sim_printf ("%s - aborting from %s:%d\n", msg, file, linenum);
sim_flush_buffered_files ();
sim_flush_buffered_files (TRUE);
if (sim_deb)
fclose (sim_deb);
sim_set_deboff (0, NULL);
abort ();
}
@ -14269,7 +14270,7 @@ static void _debug_fwrite (const char *buf, size_t len)
{
size_t move_size;
if (sim_deb_buffer == NULL) {
if ((sim_deb_buffer == NULL) || (!sim_is_running)) {
_debug_fwrite_all (buf, len, sim_deb); /* output now. */
return;
}

2
scp.h
View File

@ -277,7 +277,7 @@ void _sim_debug_device (uint32 dbits, DEVICE* dptr, const char* fmt, ...) GCC_FM
#define sim_debug(dbits, dptr, ...) do { if ((sim_deb != NULL) && ((dptr) != NULL) && ((dptr)->dctrl & (dbits))) _sim_debug_device (dbits, dptr, __VA_ARGS__);} while (0)
#define sim_debug_unit(dbits, uptr, ...) do { if ((sim_deb != NULL) && ((uptr) != NULL) && (uptr->dptr != NULL) && (((uptr)->dctrl | (uptr)->dptr->dctrl) & (dbits))) _sim_debug_unit (dbits, uptr, __VA_ARGS__);} while (0)
#endif
void sim_flush_buffered_files (void);
void sim_flush_buffered_files (t_bool debug_flush);
/* Only for use in SCP code and libraries - NOT in simulator code */
#define SIM_SCP_ABORT(msg) _sim_scp_abort (msg, __FILE__, __LINE__)

View File

@ -1437,7 +1437,7 @@ for (i=(was_active_command ? sim_rem_cmd_active_line : 0);
sim_is_running = FALSE;
sim_rem_collect_all_registers ();
sim_stop_timer_services ();
sim_flush_buffered_files ();
sim_flush_buffered_files (TRUE);
if (rem->act == NULL) {
for (j=0; j < sim_rem_con_tmxr.lines; j++) {
TMLN *lpj = &sim_rem_con_tmxr.ldsc[j];
@ -1468,7 +1468,7 @@ for (i=(was_active_command ? sim_rem_cmd_active_line : 0);
sim_is_running = FALSE;
sim_rem_collect_all_registers ();
sim_stop_timer_services ();
sim_flush_buffered_files ();
sim_flush_buffered_files (TRUE);
stat = SCPE_STOP;
_sim_rem_message ("RUN", stat);
_sim_rem_log_out (lp);
@ -2414,13 +2414,18 @@ t_stat sim_set_deboff (int32 flag, CONST char *cptr)
{
if (cptr && (*cptr != 0)) /* now eol? */
return SCPE_2MARG;
if (sim_deb == NULL) /* no debug? */
return SCPE_OK;
if (sim_deb == NULL) { /* no debug? */
if (cptr != NULL)
return sim_messagef (SCPE_OK, "Debug not enabled\n");
else
return SCPE_OK;
}
if (sim_deb_switches & SWMASK ('B')) {
size_t offset = (sim_debug_buffer_inuse == sim_deb_buffer_size) ? sim_debug_buffer_offset : 0;
const char *bufmsg = "Circular Buffer Contents follow here:\n\n";
const char *bufmsg = "\nCircular Buffer Contents follow here:\n\n";
fwrite (bufmsg, 1, strlen (bufmsg), sim_deb);
if (sim_debug_buffer_inuse > 0)
fwrite (bufmsg, 1, strlen (bufmsg), sim_deb);
while (sim_debug_buffer_inuse > 0) {
size_t write_size = MIN (sim_deb_buffer_size - offset, sim_debug_buffer_inuse);

View File

@ -982,7 +982,7 @@ if (r == SCPE_OK) {
}
if ((sim_switches & SWMASK ('D')) && !had_debug)
sim_set_deboff (0, "");
sim_set_deboff (0, NULL);
if (sim_switches & SWMASK ('D'))
uptr->dctrl = starting_dctrl;
if ((r == SCPE_OK) && (sim_switches & SWMASK ('X')))