* strerror.c: Revert last change. Declare static sys_nerr
[deliverable/binutils-gdb.git] / gdb / linespec.c
index bda41c78940bfc75a54a2c874847fa45eb98138f..7e8c6a7c9297e6dc458c97bc83981ab2c5d44b7e 100644 (file)
@@ -34,6 +34,7 @@
 #include "parser-defs.h"
 #include "block.h"
 #include "objc-lang.h"
+#include "linespec.h"
 
 /* We share this one with symtab.c, but it is not exported widely. */
 
@@ -82,11 +83,19 @@ static int total_number_of_methods (struct type *type);
 
 static int find_methods (struct type *, char *, struct symbol **);
 
+static int add_matching_methods (int method_counter, struct type *t,
+                                struct symbol **sym_arr);
+
+static int add_constructors (int method_counter, struct type *t,
+                            struct symbol **sym_arr);
+
 static void build_canonical_line_spec (struct symtab_and_line *,
                                       char *, char ***);
 
 static char *find_toplevel_char (char *s, char c);
 
+static int is_objc_method_format (const char *s);
+
 static struct symtabs_and_lines decode_line_2 (struct symbol *[],
                                               int, int, char ***);
 
@@ -210,7 +219,6 @@ find_methods (struct type *t, char *name, struct symbol **sym_arr)
           method_counter >= 0;
           --method_counter)
        {
-         int field_counter;
          char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter);
          char dem_opname[64];
 
@@ -226,88 +234,13 @@ find_methods (struct type *t, char *name, struct symbol **sym_arr)
 
          if (strcmp_iw (name, method_name) == 0)
            /* Find all the overloaded methods with that name.  */
-           for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1;
-                field_counter >= 0;
-                --field_counter)
-             {
-               struct fn_field *f;
-               char *phys_name;
-
-               f = TYPE_FN_FIELDLIST1 (t, method_counter);
-
-               if (TYPE_FN_FIELD_STUB (f, field_counter))
-                 {
-                   char *tmp_name;
-
-                   tmp_name = gdb_mangle_name (t,
-                                               method_counter,
-                                               field_counter);
-                   phys_name = alloca (strlen (tmp_name) + 1);
-                   strcpy (phys_name, tmp_name);
-                   xfree (tmp_name);
-                 }
-               else
-                 phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
-               
-               /* Destructor is handled by caller, don't add it to
-                  the list.  */
-               if (is_destructor_name (phys_name) != 0)
-                 continue;
-
-               sym_arr[i1] = lookup_symbol (phys_name,
-                                            NULL, VAR_DOMAIN,
-                                            (int *) NULL,
-                                            (struct symtab **) NULL);
-               if (sym_arr[i1])
-                 i1++;
-               else
-                 {
-                   /* This error message gets printed, but the method
-                      still seems to be found
-                      fputs_filtered("(Cannot find method ", gdb_stdout);
-                      fprintf_symbol_filtered (gdb_stdout, phys_name,
-                      language_cplus,
-                      DMGL_PARAMS | DMGL_ANSI);
-                      fputs_filtered(" - possibly inlined.)\n", gdb_stdout);
-                    */
-                 }
-             }
+           i1 += add_matching_methods (method_counter, t,
+                                       sym_arr + i1);
          else if (strncmp (class_name, name, name_len) == 0
                   && (class_name[name_len] == '\0'
                       || class_name[name_len] == '<'))
-           {
-             /* For GCC 3.x and stabs, constructors and destructors
-                have names like __base_ctor and __complete_dtor.
-                Check the physname for now if we're looking for a
-                constructor.  */
-             for (field_counter
-                    = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1;
-                  field_counter >= 0;
-                  --field_counter)
-               {
-                 struct fn_field *f;
-                 char *phys_name;
-                 
-                 f = TYPE_FN_FIELDLIST1 (t, method_counter);
-
-                 /* GCC 3.x will never produce stabs stub methods, so
-                    we don't need to handle this case.  */
-                 if (TYPE_FN_FIELD_STUB (f, field_counter))
-                   continue;
-                 phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
-                 if (! is_constructor_name (phys_name))
-                   continue;
-
-                 /* If this method is actually defined, include it in the
-                    list.  */
-                 sym_arr[i1] = lookup_symbol (phys_name,
-                                              NULL, VAR_DOMAIN,
-                                              (int *) NULL,
-                                              (struct symtab **) NULL);
-                 if (sym_arr[i1])
-                   i1++;
-               }
-           }
+           i1 += add_constructors (method_counter, t,
+                                   sym_arr + i1);
        }
     }
 
@@ -329,6 +262,113 @@ find_methods (struct type *t, char *name, struct symbol **sym_arr)
   return i1;
 }
 
+/* Add the symbols associated to methods of the class whose type is T
+   and whose name matches the method indexed by METHOD_COUNTER in the
+   array SYM_ARR.  Return the number of methods added.  */
+
+static int
+add_matching_methods (int method_counter, struct type *t,
+                     struct symbol **sym_arr)
+{
+  int field_counter;
+  int i1 = 0;
+
+  for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1;
+       field_counter >= 0;
+       --field_counter)
+    {
+      struct fn_field *f;
+      char *phys_name;
+
+      f = TYPE_FN_FIELDLIST1 (t, method_counter);
+
+      if (TYPE_FN_FIELD_STUB (f, field_counter))
+       {
+         char *tmp_name;
+
+         tmp_name = gdb_mangle_name (t,
+                                     method_counter,
+                                     field_counter);
+         phys_name = alloca (strlen (tmp_name) + 1);
+         strcpy (phys_name, tmp_name);
+         xfree (tmp_name);
+       }
+      else
+       phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
+               
+      /* Destructor is handled by caller, don't add it to
+        the list.  */
+      if (is_destructor_name (phys_name) != 0)
+       continue;
+
+      sym_arr[i1] = lookup_symbol (phys_name,
+                                  NULL, VAR_DOMAIN,
+                                  (int *) NULL,
+                                  (struct symtab **) NULL);
+      if (sym_arr[i1])
+       i1++;
+      else
+       {
+         /* This error message gets printed, but the method
+            still seems to be found
+            fputs_filtered("(Cannot find method ", gdb_stdout);
+            fprintf_symbol_filtered (gdb_stdout, phys_name,
+            language_cplus,
+            DMGL_PARAMS | DMGL_ANSI);
+            fputs_filtered(" - possibly inlined.)\n", gdb_stdout);
+         */
+       }
+    }
+
+  return i1;
+}
+
+/* Add the symbols associated to constructors of the class whose type
+   is CLASS_TYPE and which are indexed by by METHOD_COUNTER to the
+   array SYM_ARR.  Return the number of methods added.  */
+
+static int
+add_constructors (int method_counter, struct type *t,
+                 struct symbol **sym_arr)
+{
+  int field_counter;
+  int i1 = 0;
+
+  /* For GCC 3.x and stabs, constructors and destructors
+     have names like __base_ctor and __complete_dtor.
+     Check the physname for now if we're looking for a
+     constructor.  */
+  for (field_counter
+        = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1;
+       field_counter >= 0;
+       --field_counter)
+    {
+      struct fn_field *f;
+      char *phys_name;
+                 
+      f = TYPE_FN_FIELDLIST1 (t, method_counter);
+
+      /* GCC 3.x will never produce stabs stub methods, so
+        we don't need to handle this case.  */
+      if (TYPE_FN_FIELD_STUB (f, field_counter))
+       continue;
+      phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
+      if (! is_constructor_name (phys_name))
+       continue;
+
+      /* If this method is actually defined, include it in the
+        list.  */
+      sym_arr[i1] = lookup_symbol (phys_name,
+                                  NULL, VAR_DOMAIN,
+                                  (int *) NULL,
+                                  (struct symtab **) NULL);
+      if (sym_arr[i1])
+       i1++;
+    }
+
+  return i1;
+}
+
 /* Helper function for decode_line_1.
    Build a canonical line spec in CANONICAL if it is non-NULL and if
    the SAL has a symtab.
@@ -405,6 +445,25 @@ find_toplevel_char (char *s, char c)
   return 0;
 }
 
+/* Determines if the gives string corresponds to an Objective-C method
+   representation, such as -[Foo bar:] or +[Foo bar]. Objective-C symbols
+   are allowed to have spaces and parentheses in them.  */
+
+static int 
+is_objc_method_format (const char *s)
+{
+  if (s == NULL || *s == '\0')
+    return 0;
+  /* Handle arguments with the format FILENAME:SYMBOL.  */
+  if ((s[0] == ':') && (strchr ("+-", s[1]) != NULL) 
+      && (s[2] == '[') && strchr(s, ']'))
+    return 1;
+  /* Handle arguments that are just SYMBOL.  */
+  else if ((strchr ("+-", s[0]) != NULL) && (s[1] == '[') && strchr(s, ']'))
+    return 1;
+  return 0;
+}
+
 /* Given a list of NELTS symbols in SYM_ARR, return a list of lines to
    operate on (ask user if necessary).
    If CANONICAL is non-NULL return a corresponding array of mangled names
@@ -445,11 +504,18 @@ decode_line_2 (struct symbol *sym_arr[], int nelts, int funfirstline,
       if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK)
        {
          values.sals[i] = find_function_start_sal (sym_arr[i], funfirstline);
-         printf_unfiltered ("[%d] %s at %s:%d\n",
-                            (i + 2),
-                            SYMBOL_PRINT_NAME (sym_arr[i]),
-                            values.sals[i].symtab->filename,
-                            values.sals[i].line);
+         if (values.sals[i].symtab)
+           printf_unfiltered ("[%d] %s at %s:%d\n",
+                              (i + 2),
+                              SYMBOL_PRINT_NAME (sym_arr[i]),
+                              values.sals[i].symtab->filename,
+                              values.sals[i].line);
+         else
+           printf_unfiltered ("[%d] %s at ?FILE:%d [No symtab? Probably broken debug info...]\n",
+                              (i + 2),
+                              SYMBOL_PRINT_NAME (sym_arr[i]),
+                              values.sals[i].line);
+
        }
       else
        printf_unfiltered ("?HERE\n");
@@ -624,8 +690,7 @@ decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab,
 
   /* Check if this is an Objective-C method (anything that starts with
      a '+' or '-' and a '[').  */
-  if (*p && (p[0] == ':') && (strchr ("+-", p[1]) != NULL) 
-      && (p[2] == '['))
+  if (is_objc_method_format (p))
     {
       is_objc_method = 1;
       paren_pointer  = NULL; /* Just a category name.  Ignore it.  */
@@ -927,8 +992,7 @@ locate_first_half (char **argptr, int *is_quote_enclosed)
        }
       /* Check for a colon and a plus or minus and a [ (which
          indicates an Objective-C method) */
-      if (*p && (p[0] == ':') && (strchr ("+-", p[1]) != NULL) 
-         && (p[2] == '['))
+      if (is_objc_method_format (p))
        {
          break;
        }
This page took 0.026645 seconds and 4 git commands to generate.