* python/py-autoload.c (print_script): Print "Missing" instead of
[deliverable/binutils-gdb.git] / gdb / macrocmd.c
index 8213c0d703b8e536a0e9a53bc30debb92c415bba..c77156a416a52ead6f7cbc39641aba0269543263 100644 (file)
@@ -1,5 +1,6 @@
 /* C preprocessor macro expansion commands for GDB.
-   Copyright (C) 2002, 2007, 2008 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2007, 2008, 2009, 2010, 2011
+   Free Software Foundation, Inc.
    Contributed by Red Hat, Inc.
 
    This file is part of GDB.
@@ -50,6 +51,7 @@ macro_expand_command (char *exp, int from_tty)
   struct macro_scope *ms = NULL;
   char *expanded = NULL;
   struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &ms);
+
   make_cleanup (free_current_contents, &expanded);
 
   /* You know, when the user doesn't specify any expression, it would be
@@ -158,7 +160,10 @@ info_macro_command (char *name, int from_tty)
 
       fprintf_filtered (gdb_stdout, "Defined at ");
       show_pp_source_pos (gdb_stdout, file, line);
-      fprintf_filtered (gdb_stdout, "#define %s", name);
+      if (line != 0)
+       fprintf_filtered (gdb_stdout, "#define %s", name);
+      else
+       fprintf_filtered (gdb_stdout, "-D%s", name);
       if (d->kind == macro_function_like)
         {
           int i;
@@ -172,7 +177,10 @@ info_macro_command (char *name, int from_tty)
             }
           fputs_filtered (")", gdb_stdout);
         }
-      fprintf_filtered (gdb_stdout, " %s\n", d->replacement);
+      if (line != 0)
+       fprintf_filtered (gdb_stdout, " %s\n", d->replacement);
+      else
+       fprintf_filtered (gdb_stdout, "=%s\n", d->replacement);
     }
   else
     {
@@ -197,18 +205,37 @@ skip_ws (char **expp)
     ++*expp;
 }
 
+/* Try to find the bounds of an identifier.  If an identifier is
+   found, returns a newly allocated string; otherwise returns NULL.
+   EXPP is a pointer to an input string; it is updated to point to the
+   text following the identifier.  If IS_PARAMETER is true, this
+   function will also allow "..." forms as used in varargs macro
+   parameters.  */
+
 static char *
-extract_identifier (char **expp)
+extract_identifier (char **expp, int is_parameter)
 {
   char *result;
   char *p = *expp;
   unsigned int len;
-  if (! *p || ! macro_is_identifier_nondigit (*p))
-    return NULL;
-  for (++p;
-       *p && (macro_is_identifier_nondigit (*p) || macro_is_digit (*p));
-       ++p)
-    ;
+
+  if (is_parameter && !strncmp (p, "...", 3))
+    {
+      /* Ok.  */
+    }
+  else
+    {
+      if (! *p || ! macro_is_identifier_nondigit (*p))
+       return NULL;
+      for (++p;
+          *p && (macro_is_identifier_nondigit (*p) || macro_is_digit (*p));
+          ++p)
+       ;
+    }
+
+  if (is_parameter && !strncmp (p, "...", 3))      
+    p += 3;
+
   len = p - *expp;
   result = (char *) xmalloc (len + 1);
   memcpy (result, *expp, len);
@@ -224,6 +251,7 @@ free_macro_definition_ptr (void *ptr)
 {
   int i;
   struct macro_definition *loc = (struct macro_definition *) ptr;
+
   for (i = 0; i < loc->argc; ++i)
     xfree ((char *) loc->argv[i]);
   xfree ((char *) loc->argv);
@@ -246,7 +274,7 @@ macro_define_command (char *exp, int from_tty)
   memset (&new_macro, 0, sizeof (struct macro_definition));
 
   skip_ws (&exp);
-  name = extract_identifier (&exp);
+  name = extract_identifier (&exp, 0);
   if (! name)
     error (_("Invalid macro name."));
   if (*exp == '(')
@@ -271,10 +299,10 @@ macro_define_command (char *exp, int from_tty)
            {
              alloced *= 2;
              argv = (char **) xrealloc (argv, alloced * sizeof (char *));
-             /* Must update new_macro as well... */
+             /* Must update new_macro as well...  */
              new_macro.argv = (const char * const *) argv;
            }
-         argv[new_macro.argc] = extract_identifier (&exp);
+         argv[new_macro.argc] = extract_identifier (&exp, 1);
          if (! argv[new_macro.argc])
            error (_("Macro is missing an argument."));
          ++new_macro.argc;
@@ -296,13 +324,17 @@ macro_define_command (char *exp, int from_tty)
        }
       /* Skip the closing paren.  */
       ++exp;
+      skip_ws (&exp);
 
       macro_define_function (macro_main (macro_user_macros), -1, name,
                             new_macro.argc, (const char **) new_macro.argv,
                             exp);
     }
   else
-    macro_define_object (macro_main (macro_user_macros), -1, name, exp);
+    {
+      skip_ws (&exp);
+      macro_define_object (macro_main (macro_user_macros), -1, name, exp);
+    }
 
   do_cleanups (cleanup_chain);
 }
@@ -317,7 +349,7 @@ macro_undef_command (char *exp, int from_tty)
     error (_("usage: macro undef NAME"));
 
   skip_ws (&exp);
-  name = extract_identifier (&exp);
+  name = extract_identifier (&exp, 0);
   if (! name)
     error (_("Invalid macro name."));
   macro_undef (macro_main (macro_user_macros), -1, name);
@@ -326,28 +358,28 @@ macro_undef_command (char *exp, int from_tty)
 
 
 static void
-print_one_macro (const char *name, const struct macro_definition *macro)
+print_one_macro (const char *name, const struct macro_definition *macro,
+                void *ignore)
 {
   fprintf_filtered (gdb_stdout, "macro define %s", name);
   if (macro->kind == macro_function_like)
     {
       int i;
+
       fprintf_filtered (gdb_stdout, "(");
       for (i = 0; i < macro->argc; ++i)
        fprintf_filtered (gdb_stdout, "%s%s", (i > 0) ? ", " : "",
                          macro->argv[i]);
       fprintf_filtered (gdb_stdout, ")");
     }
-  /* Note that we don't need a leading space here -- "macro define"
-     provided it.  */
-  fprintf_filtered (gdb_stdout, "%s\n", macro->replacement);
+  fprintf_filtered (gdb_stdout, " %s\n", macro->replacement);
 }
 
 
 static void
 macro_list_command (char *exp, int from_tty)
 {
-  macro_for_each (macro_user_macros, print_one_macro);
+  macro_for_each (macro_user_macros, print_one_macro, NULL);
 }
 
 
@@ -359,8 +391,6 @@ extern initialize_file_ftype _initialize_macrocmd; /* -Wmissing-prototypes */
 void
 _initialize_macrocmd (void)
 {
-  struct cmd_list_element *c;
-
   /* We introduce a new command prefix, `macro', under which we'll put
      the various commands for working with preprocessor macros.  */
   add_prefix_cmd ("macro", class_info, macro_command,
This page took 0.027034 seconds and 4 git commands to generate.