PR gas/11395
[deliverable/binutils-gdb.git] / gdb / completer.c
index b14edafbeef2b3b366b64de34450375ed98cd88c..5d0898d04c53ac881a55e7aac00f763301426a48 100644 (file)
@@ -1,5 +1,6 @@
 /* Line completion stuff for GDB, the GNU debugger.
-   Copyright (C) 2000, 2001, 2007, 2008, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2001, 2007, 2008, 2009, 2010
+   Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -23,6 +24,7 @@
 #include "filenames.h"         /* For DOSish file names.  */
 #include "language.h"
 #include "gdb_assert.h"
+#include "exceptions.h"
 
 #include "cli/cli-decode.h"
 
@@ -78,10 +80,6 @@ static char *gdb_completer_file_name_break_characters = " \t\n*|\"';?><@";
 static char *gdb_completer_file_name_break_characters = " \t\n*|\"';:?><";
 #endif
 
-/* These are used when completing on locations, which can mix file
-   names and symbol names separated by a colon.  */
-static char *gdb_completer_loc_break_characters = " \t\n*|\"';:?><,";
-
 /* Characters that can be used to quote completion strings.  Note that we
    can't include '"' because the gdb C parser treats such quoted sequences
    as strings.  */
@@ -129,6 +127,7 @@ filename_completer (struct cmd_list_element *ignore, char *text, char *word)
   while (1)
     {
       char *p, *q;
+
       p = rl_filename_completion_function (text, subsequent_name);
       if (return_val_used >= return_val_alloced)
        {
@@ -352,7 +351,15 @@ count_struct_fields (struct type *type)
       if (i < TYPE_N_BASECLASSES (type))
        result += count_struct_fields (TYPE_BASECLASS (type, i));
       else if (TYPE_FIELD_NAME (type, i))
-       ++result;
+       {
+         if (TYPE_FIELD_NAME (type, i)[0] != '\0')
+           ++result;
+         else if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_UNION)
+           {
+             /* Recurse into anonymous unions.  */
+             result += count_struct_fields (TYPE_FIELD_TYPE (type, i));
+           }
+       }
     }
 
   for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
@@ -381,17 +388,29 @@ add_struct_fields (struct type *type, int *nextp, char **output,
       if (i < TYPE_N_BASECLASSES (type))
        add_struct_fields (TYPE_BASECLASS (type, i), nextp, output,
                           fieldname, namelen);
-      else if (TYPE_FIELD_NAME (type, i)
-              && ! strncmp (TYPE_FIELD_NAME (type, i), fieldname, namelen))
+      else if (TYPE_FIELD_NAME (type, i))
        {
-         output[*nextp] = xstrdup (TYPE_FIELD_NAME (type, i));
-         ++*nextp;
+         if (TYPE_FIELD_NAME (type, i)[0] != '\0')
+           {
+             if (! strncmp (TYPE_FIELD_NAME (type, i), fieldname, namelen))
+               {
+                 output[*nextp] = xstrdup (TYPE_FIELD_NAME (type, i));
+                 ++*nextp;
+               }
+           }
+         else if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_UNION)
+           {
+             /* Recurse into anonymous unions.  */
+             add_struct_fields (TYPE_FIELD_TYPE (type, i), nextp, output,
+                                fieldname, namelen);
+           }
        }
     }
 
   for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
     {
       char *name = TYPE_FN_FIELDLIST_NAME (type, i);
+
       if (name && ! strncmp (name, fieldname, namelen))
        {
          if (!computed_type_name)
@@ -400,7 +419,7 @@ add_struct_fields (struct type *type, int *nextp, char **output,
              computed_type_name = 1;
            }
          /* Omit constructors from the completion list.  */
-         if (type_name && strcmp (type_name, name))
+         if (!type_name || strcmp (type_name, name))
            {
              output[*nextp] = xstrdup (name);
              ++*nextp;
@@ -415,13 +434,19 @@ add_struct_fields (struct type *type, int *nextp, char **output,
 char **
 expression_completer (struct cmd_list_element *ignore, char *text, char *word)
 {
-  struct type *type;
+  struct type *type = NULL;
   char *fieldname, *p;
+  volatile struct gdb_exception except;
 
   /* Perform a tentative parse of the expression, to see whether a
      field completion is required.  */
   fieldname = NULL;
-  type = parse_field_expression (text, &fieldname);
+  TRY_CATCH (except, RETURN_MASK_ERROR)
+    {
+      type = parse_field_expression (text, &fieldname);
+    }
+  if (except.reason < 0)
+    return NULL;
   if (fieldname && type)
     {
       for (;;)
@@ -786,7 +811,8 @@ command_completer (struct cmd_list_element *ignore, char *text, char *word)
 char *
 gdb_completion_word_break_characters (void)
 {
-  char ** list;
+  char **list;
+
   list = complete_line_internal (rl_line_buffer, rl_line_buffer, rl_point,
                                 handle_brkchars);
   gdb_assert (list == NULL);
This page took 0.030016 seconds and 4 git commands to generate.