aboutsummaryrefslogtreecommitdiff
path: root/gdb/mi/mi-parse.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-parse.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-parse.c')
-rw-r--r--gdb/mi/mi-parse.c43
1 files changed, 21 insertions, 22 deletions
diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
index 4541b66..774d368 100644
--- a/gdb/mi/mi-parse.c
+++ b/gdb/mi/mi-parse.c
@@ -223,12 +223,20 @@ mi_parse_free (struct mi_parse *parse)
xfree (parse);
}
+/* A cleanup that calls mi_parse_free. */
+
+static void
+mi_parse_cleanup (void *arg)
+{
+ mi_parse_free (arg);
+}
struct mi_parse *
-mi_parse (char *cmd)
+mi_parse (char *cmd, char **token)
{
char *chp;
struct mi_parse *parse = XMALLOC (struct mi_parse);
+ struct cleanup *cleanup;
memset (parse, 0, sizeof (*parse));
parse->all = 0;
@@ -236,6 +244,8 @@ mi_parse (char *cmd)
parse->thread = -1;
parse->frame = -1;
+ cleanup = make_cleanup (mi_parse_cleanup, parse);
+
/* Before starting, skip leading white space. */
while (isspace (*cmd))
cmd++;
@@ -243,9 +253,9 @@ mi_parse (char *cmd)
/* Find/skip any token and then extract it. */
for (chp = cmd; *chp >= '0' && *chp <= '9'; chp++)
;
- parse->token = xmalloc ((chp - cmd + 1) * sizeof (char *));
- memcpy (parse->token, cmd, (chp - cmd));
- parse->token[chp - cmd] = '\0';
+ *token = xmalloc ((chp - cmd + 1) * sizeof (char *));
+ memcpy (*token, cmd, (chp - cmd));
+ (*token)[chp - cmd] = '\0';
/* This wasn't a real MI command. Return it as a CLI_COMMAND. */
if (*chp != '-')
@@ -254,6 +264,9 @@ mi_parse (char *cmd)
chp++;
parse->command = xstrdup (chp);
parse->op = CLI_COMMAND;
+
+ discard_cleanups (cleanup);
+
return parse;
}
@@ -271,15 +284,7 @@ mi_parse (char *cmd)
/* Find the command in the MI table. */
parse->cmd = mi_lookup (parse->command);
if (parse->cmd == NULL)
- {
- /* FIXME: This should be a function call. */
- fprintf_unfiltered
- (raw_stdout,
- "%s^error,msg=\"Undefined MI command: %s\"\n",
- parse->token, parse->command);
- mi_parse_free (parse);
- return NULL;
- }
+ error (_("Undefined MI command: %s"), parse->command);
/* Skip white space following the command. */
while (isspace (*chp))
@@ -349,15 +354,7 @@ mi_parse (char *cmd)
{
mi_parse_argv (chp, parse);
if (parse->argv == NULL)
- {
- /* FIXME: This should be a function call. */
- fprintf_unfiltered
- (raw_stdout,
- "%s^error,msg=\"Problem parsing arguments: %s %s\"\n",
- parse->token, parse->command, chp);
- mi_parse_free (parse);
- return NULL;
- }
+ error (_("Problem parsing arguments: %s %s"), parse->command, chp);
}
/* FIXME: DELETE THIS */
@@ -366,6 +363,8 @@ mi_parse (char *cmd)
if (parse->cmd->cli.cmd != NULL)
parse->args = xstrdup (chp);
+ discard_cleanups (cleanup);
+
/* Fully parsed. */
parse->op = MI_COMMAND;
return parse;