Skip to content

Commit 8fe193a

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 b036821 commit 8fe193a

2 files changed

Lines changed: 96 additions & 37 deletions

File tree

sim_console.c

Lines changed: 93 additions & 37 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,9 +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? */
374380
{ "DBGINT", &sim_show_kmap, KMAP_DBGINT },
375-
#endif
376381
{ "PCHAR", &sim_show_pchar, 0 },
377382
{ "SPEED", &sim_show_cons_speed, 0 },
378383
{ "LOG", &sim_show_cons_log, 0 },
@@ -384,6 +389,7 @@ static SHTAB show_con_tab[] = {
384389
{ "INPUT", &sim_show_cons_send_input, 0 },
385390
{ "RESPONSE", &sim_show_cons_send_input, -1 },
386391
{ "DELAY", &sim_show_cons_expect, -1 },
392+
{ "DBGSIGNAL", &sim_show_dbgsignal, 0 },
387393
{ NULL, NULL, 0 }
388394
};
389395

@@ -2167,7 +2173,7 @@ else
21672173
if (isprint(kmap_char&0xFF))
21682174
fprintf (st, " = '%c'\n", kmap_char&0xFF);
21692175
else
2170-
if (kmap_char <= 26)
2176+
if (kmap_char <= 32)
21712177
fprintf (st, " = ^%c\n", '@' + (kmap_char&0xFF));
21722178
else
21732179
fprintf (st, "\n");
@@ -2891,6 +2897,48 @@ fprintf (st, "Console Send processing:\n");
28912897
return sim_show_send_input (st, &sim_con_send);
28922898
}
28932899

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

28962944
t_stat sim_poll_kbd (void)
@@ -3808,26 +3856,30 @@ static t_stat sim_os_ttrun (void)
38083856
{
38093857
sim_debug (DBG_TRC, &sim_con_telnet, "sim_os_ttrun() - BSDTTY\n");
38103858

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];
3859+
if (sim_dbg_signal) {
3860+
if (sim_dbg_int_char == 0)
3861+
sim_dbg_int_char = sim_int_char + 1; /* Set a reasonable default */
3862+
runtchars.t_intrc = sim_dbg_int_char; /* let debugger get SIGINT with next highest char */
38173863

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));
3864+
if (!sigint_message_issued) {
3865+
char sigint_name[8];
3866+
3867+
if (isprint(sim_dbg_int_char&0xFF))
3868+
sprintf(sigint_name, "'%c'", sim_dbg_int_char&0xFF);
38233869
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);
3870+
if (sim_dbg_int_char <= 32)
3871+
sprintf(sigint_name, "'^%c'", '@' + (sim_dbg_int_char&0xFF));
3872+
else
3873+
sprintf(sigint_name, "'\\%03o'", sim_dbg_int_char&0xFF);
3874+
3875+
sim_messagef (SCPE_OK, "SIGINT will be delivered to your debugger when the %s character is entered\n",
3876+
sigint_name);
3877+
3878+
sigint_message_issued = TRUE;
3879+
}
38273880
}
3828-
#else
3829-
runtchars.t_intrc = sim_int_char; /* in case changed */
3830-
#endif
3881+
else
3882+
runtchars.t_intrc = sim_int_char; /* in case changed */
38313883
fcntl (0, F_SETFL, runfl); /* non-block mode */
38323884
if (ioctl (0, TIOCSETP, &runtty) < 0)
38333885
return SCPE_TTIERR;
@@ -3991,24 +4043,28 @@ runtty.c_cc[VINTR] = 0; /* OS X doesn't deliver
39914043
#else
39924044
runtty.c_cc[VINTR] = sim_int_char; /* in case changed */
39934045
#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));
4046+
if (sim_dbg_signal) {
4047+
if (sim_dbg_int_char == 0)
4048+
sim_dbg_int_char = sim_int_char + 1; /* Set a reasonable default */
4049+
runtty.c_cc[VINTR] = sim_dbg_int_char; /* let debugger get SIGINT with next highest char */
4050+
4051+
if (!sigint_message_issued) {
4052+
char sigint_name[8];
4053+
4054+
if (isprint(sim_dbg_int_char&0xFF))
4055+
sprintf(sigint_name, "'%c'", sim_dbg_int_char&0xFF);
40064056
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);
4057+
if (sim_dbg_int_char <= 32)
4058+
sprintf(sigint_name, "'^%c'", '@' + (sim_dbg_int_char&0xFF));
4059+
else
4060+
sprintf(sigint_name, "'\\%03o'", sim_dbg_int_char&0xFF);
4061+
4062+
sim_messagef (SCPE_OK, "SIGINT will be delivered to your debugger when the %s character is entered\n",
4063+
sigint_name);
4064+
4065+
sigint_message_issued = TRUE;
4066+
}
40104067
}
4011-
#endif
40124068
if (tcsetattr (fileno(stdin), TCSETATTR_ACTION, &runtty) < 0)
40134069
return SCPE_TTIERR;
40144070
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)