* i386-tdep.c (i386_coff_osabi_sniffer): Add "coff-go32" to the
[deliverable/binutils-gdb.git] / gdb / linespec.c
index 3f790cc49c43820edb4835dd9b5d3f3877ebcc30..8e51021fc44a071d58eb75973d93fb0c4481dae5 100644 (file)
@@ -1,6 +1,6 @@
 /* Parser for linespec for the GNU debugger, GDB.
    Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
-   1996, 1997, 1998, 1999, 2000
+   1996, 1997, 1998, 1999, 2000, 2001
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -29,6 +29,7 @@
 #include "demangle.h"
 #include "value.h"
 #include "completer.h"
+#include "cp-abi.h"
 
 /* Prototype for one function in parser-defs.h,
    instead of including that entire file. */
@@ -41,7 +42,7 @@ extern char *operator_chars (char *, char **);
 
 /* Prototypes for local functions */
 
-static void cplusplus_hint (char *name);
+static void cplusplus_error (const char *name, const char *fmt, ...) ATTR_FORMAT (printf, 2, 3);
 
 static int total_number_of_methods (struct type *type);
 
@@ -57,17 +58,31 @@ static struct symtabs_and_lines decode_line_2 (struct symbol *[],
 
 /* Helper functions. */
 
-/* While the C++ support is still in flux, issue a possibly helpful hint on
-   using the new command completion feature on single quoted demangled C++
-   symbols.  Remove when loose ends are cleaned up.   FIXME -fnf */
+/* Issue a helpful hint on using the command completion feature on
+   single quoted demangled C++ symbols as part of the completion
+   error.  */
 
 static void
-cplusplus_hint (char *name)
+cplusplus_error (const char *name, const char *fmt, ...)
 {
+  struct ui_file *tmp_stream;
+  tmp_stream = mem_fileopen ();
+  make_cleanup_ui_file_delete (tmp_stream);
+
+  {
+    va_list args;
+    va_start (args, fmt);
+    vfprintf_unfiltered (tmp_stream, fmt, args);
+    va_end (args);
+  }
+
   while (*name == '\'')
     name++;
-  printf_filtered ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name, name);
-  printf_filtered ("(Note leading single quote.)\n");
+  fprintf_unfiltered (tmp_stream,
+                     ("Hint: try '%s<TAB> or '%s<ESC-?>\n"
+                      "(Note leading single quote.)"),
+                     name, name);
+  error_stream (tmp_stream);
 }
 
 /* Return the number of methods described for TYPE, including the
@@ -104,23 +119,20 @@ find_methods (struct type *t, char *name, struct symbol **sym_arr)
 {
   int i1 = 0;
   int ibase;
-  struct symbol *sym_class;
   char *class_name = type_name_no_tag (t);
 
   /* Ignore this class if it doesn't have a name.  This is ugly, but
      unless we figure out how to get the physname without the name of
      the class, then the loop can't do any good.  */
   if (class_name
-      && (sym_class = lookup_symbol (class_name,
-                                    (struct block *) NULL,
-                                    STRUCT_NAMESPACE,
-                                    (int *) NULL,
-                                    (struct symtab **) NULL)))
+      && (lookup_symbol (class_name, (struct block *) NULL,
+                        STRUCT_NAMESPACE, (int *) NULL,
+                        (struct symtab **) NULL)))
     {
       int method_counter;
+      int name_len = strlen (name);
 
-      /* FIXME: Shouldn't this just be CHECK_TYPEDEF (t)?  */
-      t = SYMBOL_TYPE (sym_class);
+      CHECK_TYPEDEF (t);
 
       /* Loop over each method name.  At this level, all overloads of a name
          are counted as a single name.  There is an inner loop which loops over
@@ -144,7 +156,7 @@ find_methods (struct type *t, char *name, struct symbol **sym_arr)
                method_name = dem_opname;
            }
 
-         if (STREQ (name, method_name))
+         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;
@@ -168,9 +180,9 @@ find_methods (struct type *t, char *name, struct symbol **sym_arr)
                  }
                else
                  phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
-
+               
                /* Destructor is handled by caller, dont add it to the list */
-               if (DESTRUCTOR_PREFIX_P (phys_name))
+               if (is_destructor_name (phys_name) != 0)
                  continue;
 
                sym_arr[i1] = lookup_symbol (phys_name,
@@ -191,6 +203,41 @@ find_methods (struct type *t, char *name, struct symbol **sym_arr)
                     */
                  }
              }
+         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_NAMESPACE,
+                                              (int *) NULL,
+                                              (struct symtab **) NULL);
+                 if (sym_arr[i1])
+                   i1++;
+               }
+           }
        }
     }
 
@@ -254,7 +301,9 @@ build_canonical_line_spec (struct symtab_and_line *sal, char *symname,
 
 /* Find an instance of the character C in the string S that is outside
    of all parenthesis pairs, single-quoted strings, and double-quoted
-   strings.  */
+   strings.  Also, ignore the char within a template name, like a ','
+   within foo<int, int>.  */
+
 static char *
 find_toplevel_char (char *s, char c)
 {
@@ -277,9 +326,9 @@ find_toplevel_char (char *s, char c)
        return scan;
       else if (*scan == '"' || *scan == '\'')
        quoted = *scan;
-      else if (*scan == '(')
+      else if (*scan == '(' || *scan == '<')
        depth++;
-      else if (*scan == ')' && depth > 0)
+      else if ((*scan == ')' || *scan == '>') && depth > 0)
        depth--;
     }
 
@@ -463,36 +512,7 @@ decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab,
               int default_line, char ***canonical)
 {
   struct symtabs_and_lines values;
-#ifdef HPPA_COMPILER_BUG
-  /* FIXME: The native HP 9000/700 compiler has a bug which appears
-     when optimizing this file with target i960-vxworks.  I haven't
-     been able to construct a simple test case.  The problem is that
-     in the second call to SKIP_PROLOGUE below, the compiler somehow
-     does not realize that the statement val = find_pc_line (...) will
-     change the values of the fields of val.  It extracts the elements
-     into registers at the top of the block, and does not update the
-     registers after the call to find_pc_line.  You can check this by
-     inserting a printf at the end of find_pc_line to show what values
-     it is returning for val.pc and val.end and another printf after
-     the call to see what values the function actually got (remember,
-     this is compiling with cc -O, with this patch removed).  You can
-     also examine the assembly listing: search for the second call to
-     skip_prologue; the LDO statement before the next call to
-     find_pc_line loads the address of the structure which
-     find_pc_line will return; if there is a LDW just before the LDO,
-     which fetches an element of the structure, then the compiler
-     still has the bug.
-
-     Setting val to volatile avoids the problem.  We must undef
-     volatile, because the HPPA native compiler does not define
-     __STDC__, although it does understand volatile, and so volatile
-     will have been defined away in defs.h.  */
-#undef volatile
-  volatile struct symtab_and_line val;
-#define volatile               /*nothing */
-#else
   struct symtab_and_line val;
-#endif
   register char *p, *p1;
   char *q, *pp, *ii, *p2;
 #if 0
@@ -612,10 +632,11 @@ decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab,
 
   s = NULL;
   p = *argptr;
-  if (**argptr == '"')
+  if (p[0] == '"')
     {
       is_quote_enclosed = 1;
       (*argptr)++;
+      p++;
     }
   else
     is_quote_enclosed = 0;
@@ -654,7 +675,7 @@ decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab,
   /* if the closing double quote was left at the end, remove it */
   if (is_quote_enclosed)
     {
-      char *closing_quote = strchr (p, '"');
+      char *closing_quote = strchr (p - 1, '"');
       if (closing_quote && closing_quote[1] == '\0')
        *closing_quote = '\0';
     }
@@ -753,10 +774,7 @@ decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab,
    opname = cplus_mangle_opname (tmp, DMGL_ANSI);
    if (opname == NULL)
    {
-   error_begin ();
-   printf_filtered ("no mangling for \"%s\"\n", tmp);
-   cplusplus_hint (saved_arg);
-   return_to_top_level (RETURN_ERROR);
+   cplusplus_error (saved_arg, "no mangling for \"%s\"\n", tmp);
    }
    copy = (char*) alloca (3 + strlen(opname));
    sprintf (copy, "__%s", opname);
@@ -833,7 +851,7 @@ decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab,
                    {
                      char *tmp;
 
-                     if (OPNAME_PREFIX_P (copy))
+                     if (is_operator_name (copy))
                        {
                          tmp = (char *) alloca (strlen (copy + 3) + 9);
                          strcpy (tmp, "operator ");
@@ -841,17 +859,14 @@ decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab,
                        }
                      else
                        tmp = copy;
-                     error_begin ();
                      if (tmp[0] == '~')
-                       printf_filtered
-                         ("the class `%s' does not have destructor defined\n",
-                          SYMBOL_SOURCE_NAME (sym_class));
+                       cplusplus_error (saved_arg,
+                                        "the class `%s' does not have destructor defined\n",
+                                        SYMBOL_SOURCE_NAME (sym_class));
                      else
-                       printf_filtered
-                         ("the class %s does not have any method named %s\n",
-                          SYMBOL_SOURCE_NAME (sym_class), tmp);
-                     cplusplus_hint (saved_arg);
-                     return_to_top_level (RETURN_ERROR);
+                       cplusplus_error (saved_arg,
+                                        "the class %s does not have any method named %s\n",
+                                        SYMBOL_SOURCE_NAME (sym_class), tmp);
                    }
                }
 
@@ -904,12 +919,10 @@ decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab,
            goto symbol_found;
 
          /* Couldn't find any interpretation as classes/namespaces, so give up */
-         error_begin ();
          /* The quotes are important if copy is empty.  */
-         printf_filtered
-           ("Can't find member of namespace, class, struct, or union named \"%s\"\n", copy);
-         cplusplus_hint (saved_arg);
-         return_to_top_level (RETURN_ERROR);
+         cplusplus_error (saved_arg,
+                          "Can't find member of namespace, class, struct, or union named \"%s\"\n",
+                          copy);
        }
       /*  end of C++  */
 
@@ -921,20 +934,12 @@ decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab,
       if ((*p == '"') && is_quote_enclosed)
        --p;
       copy = (char *) alloca (p - *argptr + 1);
-      if ((**argptr == '"') && is_quote_enclosed)
-       {
-         memcpy (copy, *argptr + 1, p - *argptr - 1);
-         /* It may have the ending quote right after the file name */
-         if (copy[p - *argptr - 2] == '"')
-           copy[p - *argptr - 2] = 0;
-         else
-           copy[p - *argptr - 1] = 0;
-       }
+      memcpy (copy, *argptr, p - *argptr);
+      /* It may have the ending quote right after the file name */
+      if (is_quote_enclosed && copy[p - *argptr - 1] == '"')
+       copy[p - *argptr - 1] = 0;
       else
-       {
-         memcpy (copy, *argptr, p - *argptr);
-         copy[p - *argptr] = 0;
-       }
+       copy[p - *argptr] = 0;
 
       /* Find that file's data.  */
       s = lookup_symtab (copy);
@@ -1092,9 +1097,6 @@ decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab,
       p = skip_quoted (*argptr);
     }
 
-  if (is_quote_enclosed && **argptr == '"')
-    (*argptr)++;
-
   copy = (char *) alloca (p - *argptr + 1);
   memcpy (copy, *argptr, p - *argptr);
   copy[p - *argptr] = '\0';
@@ -1116,7 +1118,7 @@ decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab,
 
   if (*copy == '$')
     {
-      value_ptr valx;
+      struct value *valx;
       int index = 0;
       int need_canonical = 0;
 
@@ -1149,7 +1151,7 @@ decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab,
            goto symbol_found;
 
          /* If symbol was not found, look in minimal symbol tables */
-         msymbol = lookup_minimal_symbol (copy, 0, 0);
+         msymbol = lookup_minimal_symbol (copy, NULL, NULL);
          /* Min symbol was found --> jump to minsym processing. */
          if (msymbol)
            goto minimal_symbol_found;
@@ -1182,7 +1184,7 @@ decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab,
 
   sym = lookup_symbol (copy,
                       (s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)
-                       : get_selected_block ()),
+                       : get_selected_block (0)),
                       VAR_NAMESPACE, 0, &sym_symtab);
 
 symbol_found:                  /* We also jump here from inside the C++ class/namespace 
@@ -1208,7 +1210,7 @@ symbol_found:                     /* We also jump here from inside the C++ class/namespace
            {
              struct blockvector *bv = BLOCKVECTOR (sym_symtab);
              struct block *b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
-             if (lookup_block_symbol (b, copy, VAR_NAMESPACE) != NULL)
+             if (lookup_block_symbol (b, copy, NULL, VAR_NAMESPACE) != NULL)
                build_canonical_line_spec (values.sals, copy, canonical);
            }
          return values;
This page took 0.0284140000000001 seconds and 4 git commands to generate.