* linux-low.c (my_waitpid): Delete unnecessary prototype.
[deliverable/binutils-gdb.git] / gdb / linespec.c
index e2018e6a22e58b1df7b28e6215e343b5a2cc8dec..80aa3e12c43fe1274e030a5679fcbde883990775 100644 (file)
@@ -30,6 +30,7 @@
 #include "value.h"
 #include "completer.h"
 #include "cp-abi.h"
+#include "cp-support.h"
 #include "parser-defs.h"
 #include "block.h"
 #include "objc-lang.h"
@@ -65,7 +66,8 @@ static struct symtabs_and_lines decode_compound (char **argptr,
                                                 int funfirstline,
                                                 char ***canonical,
                                                 char *saved_arg,
-                                                char *p);
+                                                char *p,
+                                                int *not_found_ptr);
 
 static struct symbol *lookup_prefix_sym (char **argptr, char *p);
 
@@ -74,11 +76,8 @@ static struct symtabs_and_lines find_method (int funfirstline,
                                             char *saved_arg,
                                             char *copy,
                                             struct type *t,
-                                            struct symbol *sym_class);
-
-static int collect_methods (char *copy, struct type *t,
-                           struct symbol *sym_class,
-                           struct symbol **sym_arr);
+                                            struct symbol *sym_class,
+                                            int *not_found_ptr);
 
 static NORETURN void cplusplus_error (const char *name,
                                      const char *fmt, ...)
@@ -152,6 +151,7 @@ static NORETURN void
 cplusplus_error (const char *name, const char *fmt, ...)
 {
   struct ui_file *tmp_stream;
+  char *message;
   tmp_stream = mem_fileopen ();
   make_cleanup_ui_file_delete (tmp_stream);
 
@@ -168,7 +168,10 @@ cplusplus_error (const char *name, const char *fmt, ...)
                      ("Hint: try '%s<TAB> or '%s<ESC-?>\n"
                       "(Note leading single quote.)"),
                      name, name);
-  error_stream (tmp_stream);
+
+  message = ui_file_xstrdup (tmp_stream, NULL);
+  make_cleanup (xfree, message);
+  throw_error (NOT_FOUND_ERROR, "%s", message);
 }
 
 /* Return the number of methods described for TYPE, including the
@@ -306,11 +309,6 @@ add_matching_methods (int method_counter, struct type *t,
       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_in_language (phys_name,
                                   NULL, VAR_DOMAIN,
                                   language,
@@ -765,7 +763,7 @@ decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab,
        
       if (p[0] == '.' || p[1] == ':')
        return decode_compound (argptr, funfirstline, canonical,
-                               saved_arg, p);
+                               saved_arg, p, not_found_ptr);
 
       /* No, the first part is a filename; set file_symtab to be that file's
         symtab.  Also, move argptr past the filename.  */
@@ -849,6 +847,10 @@ decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab,
       p = skip_quoted (*argptr);
     }
 
+  /* Keep any template parameters */
+  if (*p == '<')
+    p = find_template_name_end (p);
+
   copy = (char *) alloca (p - *argptr + 1);
   memcpy (copy, *argptr, p - *argptr);
   copy[p - *argptr] = '\0';
@@ -1170,11 +1172,19 @@ decode_objc (char **argptr, int funfirstline, struct symtab *file_symtab,
        }
       else
        {
-         /* The only match was a non-debuggable symbol.  */
-         values.sals[0].symtab = NULL;
-         values.sals[0].line = 0;
-         values.sals[0].end = 0;
-         values.sals[0].pc = SYMBOL_VALUE_ADDRESS (sym_arr[0]);
+         /* The only match was a non-debuggable symbol, which might point
+            to a function descriptor; resolve it to the actual code address
+            instead.  */
+         struct minimal_symbol *msymbol = (struct minimal_symbol *)sym_arr[0];
+         struct objfile *objfile = msymbol_objfile (msymbol);
+         struct gdbarch *gdbarch = get_objfile_arch (objfile);
+         CORE_ADDR pc = SYMBOL_VALUE_ADDRESS (msymbol);
+
+         pc = gdbarch_convert_from_func_ptr_addr (gdbarch, pc,
+                                                  &current_target);
+
+         init_sal (&values.sals[0]);
+         values.sals[0].pc = pc;
        }
       return values;
     }
@@ -1195,7 +1205,7 @@ decode_objc (char **argptr, int funfirstline, struct symtab *file_symtab,
 
 static struct symtabs_and_lines
 decode_compound (char **argptr, int funfirstline, char ***canonical,
-                char *saved_arg, char *p)
+                char *saved_arg, char *p, int *not_found_ptr)
 {
   struct symtabs_and_lines values;
   char *p2;
@@ -1256,6 +1266,9 @@ decode_compound (char **argptr, int funfirstline, char ***canonical,
       /* Move pointer ahead to next double-colon.  */
       while (*p && (p[0] != ' ') && (p[0] != '\t') && (p[0] != '\''))
        {
+         if (current_language->la_language == language_cplus)
+           p += cp_validate_operator (p);
+
          if (p[0] == '<')
            {
              temp_end = find_template_name_end (p);
@@ -1333,6 +1346,15 @@ decode_compound (char **argptr, int funfirstline, char ***canonical,
          while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p != ':')
            p++;
          /* At this point p->"".  String ended.  */
+         /* Nope, C++ operators could have spaces in them
+            ("foo::operator <" or "foo::operator delete []").
+            I apologize, this is a bit hacky...  */
+         if (current_language->la_language == language_cplus
+             && *p == ' ' && p - 8 - *argptr + 1 > 0)
+           {
+             /* The above loop has already swallowed "operator".  */
+             p += cp_validate_operator (p - 8) - 8;
+           }
        }
 
       /* Allocate our own copy of the substring between argptr and
@@ -1362,7 +1384,7 @@ decode_compound (char **argptr, int funfirstline, char ***canonical,
         we'll lookup the whole string in the symbol tables.  */
 
       return find_method (funfirstline, canonical, saved_arg,
-                         copy, t, sym_class);
+                         copy, t, sym_class, not_found_ptr);
 
     } /* End if symbol found */
 
@@ -1385,6 +1407,8 @@ decode_compound (char **argptr, int funfirstline, char ***canonical,
 
   /* Couldn't find any interpretation as classes/namespaces, so give
      up.  The quotes are important if copy is empty.  */
+  if (not_found_ptr)
+    *not_found_ptr = 1;
   cplusplus_error (saved_arg,
                   "Can't find member of namespace, class, struct, or union named \"%s\"\n",
                   copy);
@@ -1404,6 +1428,7 @@ lookup_prefix_sym (char **argptr, char *p)
 {
   char *p1;
   char *copy;
+  struct symbol *sym;
 
   /* Extract the class name.  */
   p1 = p;
@@ -1422,7 +1447,26 @@ lookup_prefix_sym (char **argptr, char *p)
   /* At this point p1->"::inA::fun", p->"inA::fun" copy->"AAA",
      argptr->"inA::fun" */
 
-  return lookup_symbol (copy, 0, STRUCT_DOMAIN, 0);
+  sym = lookup_symbol (copy, 0, STRUCT_DOMAIN, 0);
+  if (sym == NULL)
+    {
+      /* Typedefs are in VAR_DOMAIN so the above symbol lookup will
+        fail when the user attempts to lookup a method of a class
+        via a typedef'd name (NOT via the class's name, which is already
+        handled in symbol_matches_domain).  So try the lookup again
+        using VAR_DOMAIN (where typedefs live) and double-check that we
+        found a struct/class type.  */
+      struct symbol *s = lookup_symbol (copy, 0, VAR_DOMAIN, 0);
+      if (s != NULL)
+       {
+         struct type *t = SYMBOL_TYPE (s);
+         CHECK_TYPEDEF (t);
+         if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
+           return s;
+       }
+    }
+
+  return sym;
 }
 
 /* This finds the method COPY in the class whose type is T and whose
@@ -1430,7 +1474,7 @@ lookup_prefix_sym (char **argptr, char *p)
 
 static struct symtabs_and_lines
 find_method (int funfirstline, char ***canonical, char *saved_arg,
-            char *copy, struct type *t, struct symbol *sym_class)
+            char *copy, struct type *t, struct symbol *sym_class, int *not_found_ptr)
 {
   struct symtabs_and_lines values;
   struct symbol *sym = NULL;
@@ -1441,7 +1485,7 @@ find_method (int funfirstline, char ***canonical, char *saved_arg,
   /* Find all methods with a matching name, and put them in
      sym_arr.  */
 
-  i1 = collect_methods (copy, t, sym_class, sym_arr);
+  i1 = find_methods (t, copy, SYMBOL_LANGUAGE (sym_class), sym_arr);
 
   if (i1 == 1)
     {
@@ -1471,58 +1515,19 @@ find_method (int funfirstline, char ***canonical, char *saved_arg,
     }
   else
     {
-      char *tmp;
-
-      if (is_operator_name (copy))
-       {
-         tmp = (char *) alloca (strlen (copy + 3) + 9);
-         strcpy (tmp, "operator ");
-         strcat (tmp, copy + 3);
-       }
-      else
-       tmp = copy;
-      if (tmp[0] == '~')
+      if (not_found_ptr)
+        *not_found_ptr = 1;
+      if (copy[0] == '~')
        cplusplus_error (saved_arg,
                         "the class `%s' does not have destructor defined\n",
                         SYMBOL_PRINT_NAME (sym_class));
       else
        cplusplus_error (saved_arg,
                         "the class %s does not have any method named %s\n",
-                        SYMBOL_PRINT_NAME (sym_class), tmp);
+                        SYMBOL_PRINT_NAME (sym_class), copy);
     }
 }
 
-/* Find all methods named COPY in the class whose type is T, and put
-   them in SYM_ARR.  Return the number of methods found.  */
-
-static int
-collect_methods (char *copy, struct type *t,
-                struct symbol *sym_class, struct symbol **sym_arr)
-{
-  int i1 = 0;  /*  Counter for the symbol array.  */
-
-  if (destructor_name_p (copy, t))
-    {
-      /* Destructors are a special case.  */
-      int m_index, f_index;
-
-      if (get_destructor_fn_field (t, &m_index, &f_index))
-       {
-         struct fn_field *f = TYPE_FN_FIELDLIST1 (t, m_index);
-
-         sym_arr[i1] =
-           lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, f_index),
-                          NULL, VAR_DOMAIN, (int *) NULL);
-         if (sym_arr[i1])
-           i1++;
-       }
-    }
-  else
-    i1 = find_methods (t, copy, SYMBOL_LANGUAGE (sym_class), sym_arr);
-
-  return i1;
-}
-
 \f
 
 /* Return the symtab associated to the filename given by the substring
@@ -1599,6 +1604,8 @@ decode_all_digits (char **argptr, struct symtab *default_symtab,
 
   init_sal (&val);
 
+  val.pspace = current_program_space;
+
   /* This is where we need to make sure that we have good defaults.
      We must guarantee that this section of code is never executed
      when we are called with just a function name, since
@@ -1650,6 +1657,7 @@ decode_all_digits (char **argptr, struct symtab *default_symtab,
   if (val.symtab == 0)
     val.symtab = file_symtab;
 
+  val.pspace = SYMTAB_PSPACE (val.symtab);
   val.pc = 0;
   values.sals = (struct symtab_and_line *)
     xmalloc (sizeof (struct symtab_and_line));
@@ -1669,7 +1677,7 @@ static struct symtabs_and_lines
 decode_dollar (char *copy, int funfirstline, struct symtab *default_symtab,
               char ***canonical, struct symtab *file_symtab)
 {
-  struct value *valx;
+  LONGEST valx;
   int index = 0;
   int need_canonical = 0;
   struct symtabs_and_lines values;
@@ -1684,10 +1692,12 @@ decode_dollar (char *copy, int funfirstline, struct symtab *default_symtab,
   if (!*p)             /* Reached end of token without hitting non-digit.  */
     {
       /* We have a value history reference.  */
+      struct value *val_history;
       sscanf ((copy[1] == '$') ? copy + 2 : copy + 1, "%d", &index);
-      valx = access_value_history ((copy[1] == '$') ? -index : index);
-      if (TYPE_CODE (value_type (valx)) != TYPE_CODE_INT)
+      val_history = access_value_history ((copy[1] == '$') ? -index : index);
+      if (TYPE_CODE (value_type (val_history)) != TYPE_CODE_INT)
        error (_("History values used in line specs must have integer values."));
+      valx = value_as_long (val_history);
     }
   else
     {
@@ -1709,8 +1719,7 @@ decode_dollar (char *copy, int funfirstline, struct symtab *default_symtab,
        return minsym_found (funfirstline, msymbol);
 
       /* Not a user variable or function -- must be convenience variable.  */
-      valx = value_of_internalvar (lookup_internalvar (copy + 1));
-      if (TYPE_CODE (value_type (valx)) != TYPE_CODE_INT)
+      if (!get_internalvar_integer (lookup_internalvar (copy + 1), &valx))
        error (_("Convenience variables used in line specs must have integer values."));
     }
 
@@ -1718,8 +1727,9 @@ decode_dollar (char *copy, int funfirstline, struct symtab *default_symtab,
 
   /* Either history value or convenience value from above, in valx.  */
   val.symtab = file_symtab ? file_symtab : default_symtab;
-  val.line = value_as_long (valx);
+  val.line = valx;
   val.pc = 0;
+  val.pspace = current_program_space;
 
   values.sals = (struct symtab_and_line *) xmalloc (sizeof val);
   values.sals[0] = val;
This page took 0.029733 seconds and 4 git commands to generate.