#include <readline/history.h>
#include <assert.h>
#include <errno.h>
+#include <setjmp.h>
#include "ansidecl.h"
#include "mi_gdb.h"
mi_free_output (res);
}
+static jmp_buf gdb_readline_jmp_buf;
+
+static void
+gdb_readline_sigint_handler (int signum)
+{
+ gdb_assert (signum == SIGINT);
+ longjmp (gdb_readline_jmp_buf, 1);
+}
+
+static char *
+gdb_readline (const char *prompt)
+{
+ char *retval;
+ sighandler_t saved_handler;
+ sigset_t mask;
+ int i;
+
+ i = sigprocmask (SIG_SETMASK, NULL, &mask);
+ assert (i == 0);
+ saved_handler = signal (SIGINT, gdb_readline_sigint_handler);
+ if (setjmp (gdb_readline_jmp_buf) != 0)
+ {
+ rl_free_line_state ();
+ rl_cleanup_after_signal ();
+
+ /* GDB prints this. */
+ puts ("Quit");
+
+ i = sigprocmask (SIG_SETMASK, &mask, NULL);
+ assert (i == 0);
+ }
+ retval = readline (prompt);
+ saved_handler = signal (SIGINT, saved_handler);
+ gdb_assert (saved_handler == gdb_readline_sigint_handler);
+ return retval;
+}
+
static void
commands_command_console_cb (const char *str, void *data)
{
int do_nest = 0;
prompt = xstrprintf ("%*s>", (int) nesting);
- data = readline (prompt);
+ data = gdb_readline (prompt);
xfree (prompt);
if (data == NULL)
data = xstrdup ("end");
char *prompt, *cmd;
prompt = gdb_show_string (h, "prompt");
- cmd = readline (prompt);
+ cmd = gdb_readline (prompt);
xfree (prompt);
if (cmd == NULL)