aboutsummaryrefslogtreecommitdiff
path: root/gdb/mi/mi-main.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2010-12-09 19:23:49 +0000
committerTom Tromey <tromey@redhat.com>2010-12-09 19:23:49 +0000
commit305aeedc41771066e7283a798b108c95b027997e (patch)
treed70f4243ed04ef7a18ff2553a8b93c98ea200c20 /gdb/mi/mi-main.c
parent90ecf1736cbde5d0ca94914e52a765d3ca01e5f5 (diff)
downloadgdb-305aeedc41771066e7283a798b108c95b027997e.zip
gdb-305aeedc41771066e7283a798b108c95b027997e.tar.gz
gdb-305aeedc41771066e7283a798b108c95b027997e.tar.bz2
gdb
* mi/mi-parse.h (mi_parse): Update. * mi/mi-parse.c (mi_parse_cleanup): New function. (mi_parse): Add 'token' argument. Throw exception on error. * mi/mi-main.c (mi_print_exception): New function. (mi_execute_command): Use mi_print_exception. Catch exceptions from mi_parse. gdb/testsuite * gdb.base/interp.exp: Add regression test.
Diffstat (limited to 'gdb/mi/mi-main.c')
-rw-r--r--gdb/mi/mi-main.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 3343c03..48e907f 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1865,11 +1865,26 @@ captured_mi_execute_command (struct ui_out *uiout, void *data)
return;
}
+/* Print a gdb exception to the MI output stream. */
+
+static void
+mi_print_exception (const char *token, struct gdb_exception exception)
+{
+ fputs_unfiltered (token, raw_stdout);
+ fputs_unfiltered ("^error,msg=\"", raw_stdout);
+ if (exception.message == NULL)
+ fputs_unfiltered ("unknown error", raw_stdout);
+ else
+ fputstr_unfiltered (exception.message, '"', raw_stdout);
+ fputs_unfiltered ("\"\n", raw_stdout);
+}
void
mi_execute_command (char *cmd, int from_tty)
{
- struct mi_parse *command;
+ char *token;
+ struct mi_parse *command = NULL;
+ volatile struct gdb_exception exception;
/* This is to handle EOF (^D). We just quit gdb. */
/* FIXME: we should call some API function here. */
@@ -1878,13 +1893,22 @@ mi_execute_command (char *cmd, int from_tty)
target_log_command (cmd);
- command = mi_parse (cmd);
-
- if (command != NULL)
+ TRY_CATCH (exception, RETURN_MASK_ALL)
+ {
+ command = mi_parse (cmd, &token);
+ }
+ if (exception.reason < 0)
+ {
+ mi_print_exception (token, exception);
+ xfree (token);
+ }
+ else
{
struct gdb_exception result;
ptid_t previous_ptid = inferior_ptid;
+ command->token = token;
+
if (do_timings)
{
command->cmd_start = (struct mi_timestamp *)
@@ -1898,13 +1922,7 @@ mi_execute_command (char *cmd, int from_tty)
{
/* The command execution failed and error() was called
somewhere. */
- fputs_unfiltered (command->token, raw_stdout);
- fputs_unfiltered ("^error,msg=\"", raw_stdout);
- if (result.message == NULL)
- fputs_unfiltered ("unknown error", raw_stdout);
- else
- fputstr_unfiltered (result.message, '"', raw_stdout);
- fputs_unfiltered ("\"\n", raw_stdout);
+ mi_print_exception (command->token, result);
mi_out_rewind (uiout);
}