Skip to content

Commit acb10bd

Browse files
committed
CONSOLE: Separate debug character from signal
Add the "DBGSIGNAL", "DBGSIG" options to enable sending the interrupt to the user's debugger, which is presumably gdb. Separates setting the debugging interrupt character from the action so that it is possible to turn debugger interrupts on and off: set console dbgint=1f dbgsignal set console nodbgsignal Previously, this feature was only available if the compiler did not define __OPTIMIZE__, which precludes optimized debugging code, i.e., compiling with "-O2 -g".
1 parent c20b391 commit acb10bd

2 files changed

Lines changed: 97 additions & 36 deletions

File tree

sim_console.c

Lines changed: 94 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@
161161
/* Forward declarations of platform specific routines */
162162

163163
static t_stat sim_os_poll_kbd (void);
164+
#if defined(SIM_ASYNCH_IO) && defined(SIM_ASYNCH_MUX)
164165
static t_bool sim_os_poll_kbd_ready (int ms_timeout);
166+
#endif
165167
static t_stat sim_os_putchar (int32 out);
166168
static t_stat sim_os_ttinit (void);
167169
static t_stat sim_os_ttrun (void);
@@ -190,6 +192,7 @@ static t_stat sim_set_delay (int32 flag, CONST char *cptr);
190192

191193
int32 sim_int_char = 005; /* interrupt character */
192194
int32 sim_dbg_int_char = 0; /* SIGINT char under debugger */
195+
int32 sim_dbg_signal = 0; /* Enable SIGINT to debugger */
193196
static t_bool sigint_message_issued = FALSE;
194197
int32 sim_brk_char = 000; /* break character */
195198
int32 sim_tt_pchar = 0x00002780;
@@ -335,7 +338,6 @@ static CTAB set_con_tab[] = {
335338
{ "WRU", &sim_set_kmap, KMAP_WRU | KMAP_NZ },
336339
{ "BRK", &sim_set_kmap, KMAP_BRK },
337340
{ "DEL", &sim_set_kmap, KMAP_DEL | KMAP_NZ },
338-
{ "DBGINT", &sim_set_kmap, KMAP_DBGINT | KMAP_NZ },
339341
{ "PCHAR", &sim_set_pchar, 0 },
340342
{ "SPEED", &sim_set_cons_speed, 0 },
341343
{ "TELNET", &sim_set_telnet, 0 },
@@ -352,6 +354,11 @@ static CTAB set_con_tab[] = {
352354
{ "DELAY", &sim_set_delay, 0 },
353355
{ "RESPONSE", &sim_set_response, 1 | CMD_WANTSTR },
354356
{ "NORESPONSE", &sim_set_response, 0 },
357+
{ "DBGINT", &sim_set_kmap, KMAP_DBGINT | KMAP_NZ },
358+
{ "DBGSIG", &sim_set_dbgsignal, 0 },
359+
{ "DBGSIGNAL", &sim_set_dbgsignal, 0 },
360+
{ "NODBGSIG", &sim_reset_dbgsignal, 0 },
361+
{ "NODBGSIGNAL", &sim_reset_dbgsignal, 0 },
355362
{ NULL, NULL, 0 }
356363
};
357364

@@ -370,7 +377,7 @@ static SHTAB show_con_tab[] = {
370377
{ "WRU", &sim_show_kmap, KMAP_WRU },
371378
{ "BRK", &sim_show_kmap, KMAP_BRK },
372379
{ "DEL", &sim_show_kmap, KMAP_DEL },
373-
#if (defined(__GNUC__) && !defined(__OPTIMIZE__) && !defined(_WIN32)) /* Debug build? */
380+
#if !defined(_WIN32) && !defined(_WIN64) && !defined(VMS)
374381
{ "DBGINT", &sim_show_kmap, KMAP_DBGINT },
375382
#endif
376383
{ "PCHAR", &sim_show_pchar, 0 },
@@ -384,6 +391,7 @@ static SHTAB show_con_tab[] = {
384391
{ "INPUT", &sim_show_cons_send_input, 0 },
385392
{ "RESPONSE", &sim_show_cons_send_input, -1 },
386393
{ "DELAY", &sim_show_cons_expect, -1 },
394+
{ "DBGSIGNAL", &sim_show_dbgsignal, 0 },
387395
{ NULL, NULL, 0 }
388396
};
389397

@@ -2167,7 +2175,7 @@ else
21672175
if (isprint(kmap_char&0xFF))
21682176
fprintf (st, " = '%c'\n", kmap_char&0xFF);
21692177
else
2170-
if (kmap_char <= 26)
2178+
if (kmap_char <= 32)
21712179
fprintf (st, " = ^%c\n", '@' + (kmap_char&0xFF));
21722180
else
21732181
fprintf (st, "\n");
@@ -2891,6 +2899,48 @@ fprintf (st, "Console Send processing:\n");
28912899
return sim_show_send_input (st, &sim_con_send);
28922900
}
28932901

2902+
/* Enable console signal to debugger (for GNU C, Clang and not on Windows. */
2903+
t_stat sim_set_dbgsignal (int32 flag, CONST char *cptr)
2904+
{
2905+
#if !defined(_WIN32) && !defined(_WIN64) && !defined(VMS)
2906+
if (cptr != NULL && *cptr != '\0')
2907+
return SCPE_2FARG;
2908+
2909+
sim_dbg_signal = TRUE; /* Enable SIGINT to debugger */
2910+
return sim_messagef(SCPE_OK, "SIGINT to debugger enabled.\n");
2911+
#else
2912+
return sim_messagef(SCPE_NOFNC, "Debugger interrupt not supported on this platform.\n");
2913+
#endif
2914+
}
2915+
2916+
/* Turn off debugger signal */
2917+
t_stat sim_reset_dbgsignal (int32 flag, CONST char *cptr)
2918+
{
2919+
#if !defined(_WIN32) && !defined(_WIN64) && !defined(VMS)
2920+
if (cptr != NULL && *cptr != '\0') /* too many arguments? */
2921+
return SCPE_2MARG;
2922+
2923+
sim_dbg_signal = FALSE; /* Disable SIGINT to debugger */
2924+
return sim_messagef(SCPE_OK, "SIGINT to debugger is disabled.\n");
2925+
#else
2926+
return sim_messagef(SCPE_NOFNC, "Debugger interrupt not supported on this platform.\n");
2927+
#endif
2928+
}
2929+
2930+
t_stat sim_show_dbgsignal (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, CONST char *cptr)
2931+
{
2932+
#if !defined(_WIN32) && !defined(_WIN64) && !defined(VMS)
2933+
if (cptr != NULL && *cptr != '\0') /* too many arguments? */
2934+
return SCPE_2MARG;
2935+
2936+
fprintf(st, "%s interrupts to the debugger.\n", sim_dbg_signal ? "Delivering" : "Not delivering");
2937+
#else
2938+
fprintf(st, "Debugger interrupt not supported.\n");
2939+
#endif
2940+
2941+
return SCPE_OK;
2942+
}
2943+
28942944
/* Poll for character */
28952945

28962946
t_stat sim_poll_kbd (void)
@@ -3808,26 +3858,30 @@ static t_stat sim_os_ttrun (void)
38083858
{
38093859
sim_debug (DBG_TRC, &sim_con_telnet, "sim_os_ttrun() - BSDTTY\n");
38103860

3811-
#if (defined(__GNUC__) && !defined(__OPTIMIZE__)) /* Debug build? */
3812-
if (sim_dbg_int_char == 0)
3813-
sim_dbg_int_char = sim_int_char + 1;
3814-
runtchars.t_intrc = sim_dbg_int_char; /* let debugger get SIGINT with next highest char */
3815-
if (!sigint_message_issued) {
3816-
char sigint_name[8];
3861+
if (sim_dbg_signal) {
3862+
if (sim_dbg_int_char == 0)
3863+
sim_dbg_int_char = sim_int_char + 1; /* Set a reasonable default */
3864+
runtchars.t_intrc = sim_dbg_int_char; /* let debugger get SIGINT with next highest char */
38173865

3818-
if (isprint(sim_dbg_int_char&0xFF))
3819-
sprintf(sigint_name, "'%c'", sim_dbg_int_char&0xFF);
3820-
else
3821-
if (sim_dbg_int_char <= 26)
3822-
sprintf(sigint_name, "^%c", '@' + (sim_dbg_int_char&0xFF));
3866+
if (!sigint_message_issued) {
3867+
char sigint_name[8];
3868+
3869+
if (isprint(sim_dbg_int_char&0xFF))
3870+
sprintf(sigint_name, "'%c'", sim_dbg_int_char&0xFF);
38233871
else
3824-
sprintf(sigint_name, "'\\%03o'", sim_dbg_int_char&0xFF);
3825-
sigint_message_issued = TRUE;
3826-
sim_messagef (SCPE_OK, "SIGINT will be delivered to your debugger when the %s character is entered\n", sigint_name);
3872+
if (sim_dbg_int_char <= 32)
3873+
sprintf(sigint_name, "'^%c'", '@' + (sim_dbg_int_char&0xFF));
3874+
else
3875+
sprintf(sigint_name, "'\\%03o'", sim_dbg_int_char&0xFF);
3876+
3877+
sim_messagef (SCPE_OK, "SIGINT will be delivered to your debugger when the %s character is entered\n",
3878+
sigint_name);
3879+
3880+
sigint_message_issued = TRUE;
3881+
}
38273882
}
3828-
#else
3829-
runtchars.t_intrc = sim_int_char; /* in case changed */
3830-
#endif
3883+
else
3884+
runtchars.t_intrc = sim_int_char; /* in case changed */
38313885
fcntl (0, F_SETFL, runfl); /* non-block mode */
38323886
if (ioctl (0, TIOCSETP, &runtty) < 0)
38333887
return SCPE_TTIERR;
@@ -3991,24 +4045,28 @@ runtty.c_cc[VINTR] = 0; /* OS X doesn't deliver
39914045
#else
39924046
runtty.c_cc[VINTR] = sim_int_char; /* in case changed */
39934047
#endif
3994-
#if (defined(__GNUC__) && !defined(__OPTIMIZE__)) /* Debug build? */
3995-
if (sim_dbg_int_char == 0)
3996-
sim_dbg_int_char = sim_int_char + 1;
3997-
runtty.c_cc[VINTR] = sim_dbg_int_char; /* let debugger get SIGINT with next highest char */
3998-
if (!sigint_message_issued) {
3999-
char sigint_name[8];
4000-
4001-
if (isprint(sim_dbg_int_char&0xFF))
4002-
sprintf(sigint_name, "'%c'", sim_dbg_int_char&0xFF);
4003-
else
4004-
if (sim_dbg_int_char <= 26)
4005-
sprintf(sigint_name, "^%c", '@' + (sim_dbg_int_char&0xFF));
4048+
if (sim_dbg_signal) {
4049+
if (sim_dbg_int_char == 0)
4050+
sim_dbg_int_char = sim_int_char + 1; /* Set a reasonable default */
4051+
runtty.c_cc[VINTR] = sim_dbg_int_char; /* let debugger get SIGINT with next highest char */
4052+
4053+
if (!sigint_message_issued) {
4054+
char sigint_name[8];
4055+
4056+
if (isprint(sim_dbg_int_char&0xFF))
4057+
sprintf(sigint_name, "'%c'", sim_dbg_int_char&0xFF);
40064058
else
4007-
sprintf(sigint_name, "'\\%03o'", sim_dbg_int_char&0xFF);
4008-
sigint_message_issued = TRUE;
4009-
sim_messagef (SCPE_OK, "SIGINT will be delivered to your debugger when the %s character is entered\n", sigint_name);
4059+
if (sim_dbg_int_char <= 32)
4060+
sprintf(sigint_name, "'^%c'", '@' + (sim_dbg_int_char&0xFF));
4061+
else
4062+
sprintf(sigint_name, "'\\%03o'", sim_dbg_int_char&0xFF);
4063+
4064+
sim_messagef (SCPE_OK, "SIGINT will be delivered to your debugger when the %s character is entered\n",
4065+
sigint_name);
4066+
4067+
sigint_message_issued = TRUE;
4068+
}
40104069
}
4011-
#endif
40124070
if (tcsetattr (fileno(stdin), TCSETATTR_ACTION, &runtty) < 0)
40134071
return SCPE_TTIERR;
40144072
sim_os_set_thread_priority (PRIORITY_BELOW_NORMAL); /* try to lower pri */

sim_console.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ t_stat sim_set_cons_expect (int32 flg, CONST char *cptr);
9595
t_stat sim_set_cons_noexpect (int32 flg, CONST char *cptr);
9696
t_stat sim_set_pchar (int32 flag, CONST char *cptr);
9797
t_stat sim_set_cons_speed (int32 flag, CONST char *cptr);
98+
t_stat sim_set_dbgsignal (int32 flag, CONST char *cptr);
99+
t_stat sim_reset_dbgsignal (int32 flag, CONST char *cptr);
98100
t_stat sim_show_console (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, CONST char *cptr);
99101
t_stat sim_show_remote_console (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, CONST char *cptr);
100102
t_stat sim_show_kmap (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, CONST char *cptr);
@@ -107,6 +109,7 @@ t_stat sim_show_cons_buff (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, CONST
107109
t_stat sim_show_cons_log (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, CONST char *cptr);
108110
t_stat sim_show_cons_debug (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, CONST char *cptr);
109111
t_stat sim_show_cons_expect (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, CONST char *cptr);
112+
t_stat sim_show_dbgsignal (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, CONST char *cptr);
110113
t_stat sim_check_console (int32 sec);
111114
t_stat sim_open_logfile (const char *filename, t_bool binary, FILE **pf, FILEREF **pref);
112115
t_stat sim_close_logfile (FILEREF **pref);

0 commit comments

Comments
 (0)