Per-inferior/Inferior-qualified thread IDs
[deliverable/binutils-gdb.git] / gdb / mi / mi-parse.c
index 15fb77894673c2863b2501095823d3c9023fe305..bf6933e0f2e523f763a95aeeecd6e2dd95db3703 100644 (file)
@@ -1,6 +1,6 @@
 /* MI Command Set - MI parser.
 
-   Copyright (C) 2000-2013 Free Software Foundation, Inc.
+   Copyright (C) 2000-2016 Free Software Foundation, Inc.
 
    Contributed by Cygnus Solutions (a Red Hat company).
 
 #include "charset.h"
 
 #include <ctype.h>
-#include "gdb_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.  */
@@ -107,7 +111,7 @@ mi_parse_argv (const char *args, struct mi_parse *parse)
 {
   const char *chp = args;
   int argc = 0;
-  char **argv = xmalloc ((argc + 1) * sizeof (char *));
+  char **argv = XNEWVEC (char *, argc + 1);
 
   argv[argc] = NULL;
   while (1)
@@ -161,7 +165,7 @@ mi_parse_argv (const char *args, struct mi_parse *parse)
                return;
              }
            /* Create the buffer and copy characters in.  */
-           arg = xmalloc ((len + 1) * sizeof (char));
+           arg = XNEWVEC (char, len + 1);
            chp = start;
            len = 0;
            while (*chp != '\0' && *chp != '"')
@@ -191,14 +195,14 @@ mi_parse_argv (const char *args, struct mi_parse *parse)
                chp++;
              }
            len = chp - start;
-           arg = xmalloc ((len + 1) * sizeof (char));
+           arg = XNEWVEC (char, len + 1);
            strncpy (arg, start, len);
            arg[len] = '\0';
            break;
          }
        }
       /* Append arg to argv.  */
-      argv = xrealloc (argv, (argc + 2) * sizeof (char *));
+      argv = XRESIZEVEC (char *, argv, argc + 2);
       argv[argc++] = arg;
       argv[argc] = NULL;
     }
@@ -225,14 +229,14 @@ mi_parse_free (struct mi_parse *parse)
 static void
 mi_parse_cleanup (void *arg)
 {
-  mi_parse_free (arg);
+  mi_parse_free ((struct mi_parse *) arg);
 }
 
 struct mi_parse *
 mi_parse (const char *cmd, char **token)
 {
   const char *chp;
-  struct mi_parse *parse = XMALLOC (struct mi_parse);
+  struct mi_parse *parse = XNEW (struct mi_parse);
   struct cleanup *cleanup;
 
   memset (parse, 0, sizeof (*parse));
@@ -240,6 +244,7 @@ mi_parse (const 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);
 
@@ -249,7 +254,7 @@ mi_parse (const char *cmd, char **token)
   /* Find/skip any token and then extract it.  */
   for (chp = cmd; *chp >= '0' && *chp <= '9'; chp++)
     ;
-  *token = xmalloc (chp - cmd + 1);
+  *token = (char *) xmalloc (chp - cmd + 1);
   memcpy (*token, cmd, (chp - cmd));
   (*token)[chp - cmd] = '\0';
 
@@ -271,7 +276,7 @@ mi_parse (const char *cmd, char **token)
 
     for (; *chp && !isspace (*chp); chp++)
       ;
-    parse->command = xmalloc (chp - tmp + 1);
+    parse->command = (char *) xmalloc (chp - tmp + 1);
     memcpy (parse->command, tmp, chp - tmp);
     parse->command[chp - tmp] = '\0';
   }
@@ -279,7 +284,8 @@ mi_parse (const 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.  */
   chp = skip_spaces_const (chp);
@@ -288,7 +294,10 @@ mi_parse (const char *cmd, char **token)
      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;
@@ -296,6 +305,7 @@ mi_parse (const 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)
        {
@@ -344,6 +354,23 @@ mi_parse (const char *cmd, char **token)
          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;
 
@@ -373,3 +400,21 @@ mi_parse (const 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);
+}
This page took 0.02688 seconds and 4 git commands to generate.