2009-11-12 H.J. Lu <hongjiu.lu@intel.com>
[deliverable/binutils-gdb.git] / gdb / linespec.c
index debe86f52b401df308093f9eab2116ab5414ec81..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"
@@ -150,7 +151,6 @@ static NORETURN void
 cplusplus_error (const char *name, const char *fmt, ...)
 {
   struct ui_file *tmp_stream;
-  long len;
   char *message;
   tmp_stream = mem_fileopen ();
   make_cleanup_ui_file_delete (tmp_stream);
@@ -169,9 +169,9 @@ cplusplus_error (const char *name, const char *fmt, ...)
                       "(Note leading single quote.)"),
                      name, name);
 
-  message = ui_file_xstrdup (tmp_stream, &len);                                   
-  make_cleanup (xfree, message);                                              
-  throw_error (NOT_FOUND_ERROR, "%s", message);  
+  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
@@ -1172,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;
     }
@@ -1258,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);
@@ -1335,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
@@ -1408,6 +1428,7 @@ lookup_prefix_sym (char **argptr, char *p)
 {
   char *p1;
   char *copy;
+  struct symbol *sym;
 
   /* Extract the class name.  */
   p1 = p;
@@ -1426,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
@@ -1475,26 +1515,16 @@ 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 (not_found_ptr)
         *not_found_ptr = 1;
-      if (tmp[0] == '~')
+      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);
     }
 }
 
@@ -1574,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
@@ -1625,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));
@@ -1696,6 +1729,7 @@ decode_dollar (char *copy, int funfirstline, struct symtab *default_symtab,
   val.symtab = file_symtab ? file_symtab : default_symtab;
   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.025483 seconds and 4 git commands to generate.