Index: gdb/mi/mi-parse.c |
diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c |
index 02700c4eec78073e88310a8431fd315c0a833568..a092759043b586e3c90543b5f32697e021e7a6cb 100644 |
--- a/gdb/mi/mi-parse.c |
+++ b/gdb/mi/mi-parse.c |
@@ -1,6 +1,6 @@ |
/* MI Command Set - MI parser. |
- Copyright (C) 2000-2002, 2007-2012 Free Software Foundation, Inc. |
+ Copyright (C) 2000-2013 Free Software Foundation, Inc. |
Contributed by Cygnus Solutions (a Red Hat company). |
@@ -25,13 +25,19 @@ |
#include "charset.h" |
#include <ctype.h> |
-#include "gdb_string.h" |
+#include <string.h> |
+#include "cli/cli-utils.h" |
+#include "language.h" |
+ |
+static const char mi_no_values[] = "--no-values"; |
+static const char mi_simple_values[] = "--simple-values"; |
+static const char mi_all_values[] = "--all-values"; |
/* Like parse_escape, but leave the results as a host char, not a |
target char. */ |
static int |
-mi_parse_escape (char **string_ptr) |
+mi_parse_escape (const char **string_ptr) |
{ |
int c = *(*string_ptr)++; |
@@ -102,9 +108,9 @@ mi_parse_escape (char **string_ptr) |
} |
static void |
-mi_parse_argv (char *args, struct mi_parse *parse) |
+mi_parse_argv (const char *args, struct mi_parse *parse) |
{ |
- char *chp = args; |
+ const char *chp = args; |
int argc = 0; |
char **argv = xmalloc ((argc + 1) * sizeof (char *)); |
@@ -114,8 +120,7 @@ mi_parse_argv (char *args, struct mi_parse *parse) |
char *arg; |
/* Skip leading white space. */ |
- while (isspace (*chp)) |
- chp++; |
+ chp = skip_spaces_const (chp); |
/* Three possibilities: EOF, quoted string, or other text. */ |
switch (*chp) |
{ |
@@ -127,7 +132,7 @@ mi_parse_argv (char *args, struct mi_parse *parse) |
{ |
/* A quoted string. */ |
int len; |
- char *start = chp + 1; |
+ const char *start = chp + 1; |
/* Determine the buffer size. */ |
chp = start; |
@@ -184,7 +189,7 @@ mi_parse_argv (char *args, struct mi_parse *parse) |
/* An unquoted string. Accumulate all non-blank |
characters into a buffer. */ |
int len; |
- char *start = chp; |
+ const char *start = chp; |
while (*chp != '\0' && !isspace (*chp)) |
{ |
@@ -229,9 +234,9 @@ mi_parse_cleanup (void *arg) |
} |
struct mi_parse * |
-mi_parse (char *cmd, char **token) |
+mi_parse (const char *cmd, char **token) |
{ |
- char *chp; |
+ const char *chp; |
struct mi_parse *parse = XMALLOC (struct mi_parse); |
struct cleanup *cleanup; |
@@ -240,12 +245,12 @@ mi_parse (char *cmd, char **token) |
parse->thread_group = -1; |
parse->thread = -1; |
parse->frame = -1; |
+ parse->language = language_unknown; |
cleanup = make_cleanup (mi_parse_cleanup, parse); |
/* Before starting, skip leading white space. */ |
- while (isspace (*cmd)) |
- cmd++; |
+ cmd = skip_spaces_const (cmd); |
/* Find/skip any token and then extract it. */ |
for (chp = cmd; *chp >= '0' && *chp <= '9'; chp++) |
@@ -257,8 +262,7 @@ mi_parse (char *cmd, char **token) |
/* This wasn't a real MI command. Return it as a CLI_COMMAND. */ |
if (*chp != '-') |
{ |
- while (isspace (*chp)) |
- chp++; |
+ chp = skip_spaces_const (chp); |
parse->command = xstrdup (chp); |
parse->op = CLI_COMMAND; |
@@ -269,7 +273,7 @@ mi_parse (char *cmd, char **token) |
/* Extract the command. */ |
{ |
- char *tmp = chp + 1; /* discard ``-'' */ |
+ const char *tmp = chp + 1; /* discard ``-'' */ |
for (; *chp && !isspace (*chp); chp++) |
; |
@@ -281,17 +285,20 @@ mi_parse (char *cmd, char **token) |
/* Find the command in the MI table. */ |
parse->cmd = mi_lookup (parse->command); |
if (parse->cmd == NULL) |
- error (_("Undefined MI command: %s"), parse->command); |
+ throw_error (UNDEFINED_COMMAND_ERROR, |
+ _("Undefined MI command: %s"), parse->command); |
/* Skip white space following the command. */ |
- while (isspace (*chp)) |
- chp++; |
+ chp = skip_spaces_const (chp); |
/* Parse the --thread and --frame options, if present. At present, |
some important commands, like '-break-*' are implemented by |
forwarding to the CLI layer directly. We want to parse --thread |
and --frame here, so as not to leave those option in the string |
- that will be passed to CLI. */ |
+ that will be passed to CLI. |
+ |
+ Same for the --language option. */ |
+ |
for (;;) |
{ |
const char *option; |
@@ -299,6 +306,7 @@ mi_parse (char *cmd, char **token) |
size_t tgs = sizeof ("--thread-group ") - 1; |
size_t ts = sizeof ("--thread ") - 1; |
size_t fs = sizeof ("--frame ") - 1; |
+ size_t ls = sizeof ("--language ") - 1; |
if (strncmp (chp, "--all ", as) == 0) |
{ |
@@ -313,6 +321,8 @@ mi_parse (char *cmd, char **token) |
} |
if (strncmp (chp, "--thread-group ", tgs) == 0) |
{ |
+ char *endp; |
+ |
option = "--thread-group"; |
if (parse->thread_group != -1) |
error (_("Duplicate '--thread-group' option")); |
@@ -320,31 +330,54 @@ mi_parse (char *cmd, char **token) |
if (*chp != 'i') |
error (_("Invalid thread group id")); |
chp += 1; |
- parse->thread_group = strtol (chp, &chp, 10); |
+ parse->thread_group = strtol (chp, &endp, 10); |
+ chp = endp; |
} |
else if (strncmp (chp, "--thread ", ts) == 0) |
{ |
+ char *endp; |
+ |
option = "--thread"; |
if (parse->thread != -1) |
error (_("Duplicate '--thread' option")); |
chp += ts; |
- parse->thread = strtol (chp, &chp, 10); |
+ parse->thread = strtol (chp, &endp, 10); |
+ chp = endp; |
} |
else if (strncmp (chp, "--frame ", fs) == 0) |
{ |
+ char *endp; |
+ |
option = "--frame"; |
if (parse->frame != -1) |
error (_("Duplicate '--frame' option")); |
chp += fs; |
- parse->frame = strtol (chp, &chp, 10); |
+ parse->frame = strtol (chp, &endp, 10); |
+ chp = endp; |
+ } |
+ else if (strncmp (chp, "--language ", ls) == 0) |
+ { |
+ char *lang_name; |
+ struct cleanup *old_chain; |
+ |
+ option = "--language"; |
+ chp += ls; |
+ lang_name = extract_arg_const (&chp); |
+ old_chain = make_cleanup (xfree, lang_name); |
+ |
+ parse->language = language_enum (lang_name); |
+ if (parse->language == language_unknown |
+ || parse->language == language_auto) |
+ error (_("Invalid --language argument: %s"), lang_name); |
+ |
+ do_cleanups (old_chain); |
} |
else |
break; |
if (*chp != '\0' && !isspace (*chp)) |
error (_("Invalid value for the '%s' option"), option); |
- while (isspace (*chp)) |
- chp++; |
+ chp = skip_spaces_const (chp); |
} |
/* For new argv commands, attempt to return the parsed argument |
@@ -368,3 +401,21 @@ mi_parse (char *cmd, char **token) |
parse->op = MI_COMMAND; |
return parse; |
} |
+ |
+enum print_values |
+mi_parse_print_values (const char *name) |
+{ |
+ if (strcmp (name, "0") == 0 |
+ || strcmp (name, mi_no_values) == 0) |
+ return PRINT_NO_VALUES; |
+ else if (strcmp (name, "1") == 0 |
+ || strcmp (name, mi_all_values) == 0) |
+ return PRINT_ALL_VALUES; |
+ else if (strcmp (name, "2") == 0 |
+ || strcmp (name, mi_simple_values) == 0) |
+ return PRINT_SIMPLE_VALUES; |
+ else |
+ error (_("Unknown value for PRINT_VALUES: must be: \ |
+0 or \"%s\", 1 or \"%s\", 2 or \"%s\""), |
+ mi_no_values, mi_all_values, mi_simple_values); |
+} |