Host/target/native split for sun4.
[deliverable/binutils-gdb.git] / gdb / symtab.c
index d92605e68dc302dd2b3ad0cf7a08db593eddacbc..fdda171bb8d519c7ab57ca0e36c20af6f7cc493c 100644 (file)
@@ -134,63 +134,75 @@ lookup_symtab_1 (name)
   register struct symtab *s;
   register struct partial_symtab *ps;
   register char *slash;
-  register int len;
   register struct objfile *objfile;
 
-  ALL_SYMTABS (objfile, s)
-    {
-      if (strcmp (name, s->filename) == 0)
-       {
-         return (s);
-       }
-    }
+ got_symtab:
 
-  ALL_PSYMTABS (objfile, ps)
-    {
-      if (strcmp (name, ps -> filename) == 0)
-       {
-         if (ps -> readin)
-           {
-             error ("Internal: readin pst for `%s' found when no symtab found.", name);
-           }
-         return (PSYMTAB_TO_SYMTAB (ps));
-       }
-    }
+  /* First, search for an exact match */
+
+  ALL_SYMTABS (objfile, s)
+    if (strcmp (name, s->filename) == 0)
+      return s;
 
   slash = strchr (name, '/');
-  len = strlen (name);
+
+  /* Now, search for a matching tail (only if name doesn't have any dirs) */
 
   if (!slash)
-    {
-      ALL_SYMTABS (objfile, s)
-       {
-         int l = strlen (s->filename);
-         
-         if (l > len
-             && s->filename[l - len -1] == '/'
-             && (strcmp (s->filename + l - len, name) == 0))
-           {
-             return (s);
-           }
-       }
+    ALL_SYMTABS (objfile, s)
+      {
+       char *p = s -> filename;
+       char *tail = strrchr (p, '/');
 
-      ALL_PSYMTABS (objfile, ps)
-       {
-         int l = strlen (ps -> filename);
+       if (tail)
+         p = tail + 1;
+
+       if (strcmp (p, name) == 0)
+         return s;
+      }
+
+  /* Same search rules as above apply here, but now we look thru the
+     psymtabs.  */
+
+  ALL_PSYMTABS (objfile, ps)
+    if (strcmp (name, ps -> filename) == 0)
+      goto got_psymtab;
+
+  if (!slash)
+    ALL_PSYMTABS (objfile, ps)
+      {
+       char *p = ps -> filename;
+       char *tail = strrchr (p, '/');
+
+       if (tail)
+         p = tail + 1;
+
+       if (strcmp (p, name) == 0)
+         goto got_psymtab;
+      }
 
-         if (l > len
-             && ps -> filename[l - len - 1] == '/'
-             && (strcmp (ps->filename + l - len, name) == 0))
-           {
-             if (ps -> readin)
-               {
-                 error ("Internal: readin pst for `%s' found when no symtab found.", name);
-               }
-             return (PSYMTAB_TO_SYMTAB (ps));
-           }
-       }
-    }
   return (NULL);
+
+ got_psymtab:
+
+  if (ps -> readin)
+    error ("Internal: readin %s pst for `%s' found when no symtab found.",
+          ps -> filename, name);
+
+  s = PSYMTAB_TO_SYMTAB (ps);
+
+  if (s)
+    return s;
+
+  /* At this point, we have located the psymtab for this file, but
+     the conversion to a symtab has failed.  This usually happens
+     when we are looking up an include file.  In this case,
+     PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
+     been created.  So, we need to run through the symtabs again in
+     order to find the file.
+     XXX - This is a crock, and should be fixed inside of the the
+     symbol parsing routines. */
+  goto got_symtab;
 }
 
 /* Lookup the symbol table of a source file named NAME.  Try a couple
@@ -250,19 +262,29 @@ gdb_mangle_name (type, i, j)
   struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
   struct fn_field *method = &f[j];
   char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
-  int is_constructor = strcmp(field_name, TYPE_NAME (type)) == 0;
-
+  char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
+  char *newname = type_name_no_tag (type);
+  int is_constructor = strcmp(field_name, newname) == 0;
+  int is_destructor = is_constructor && physname[0] == '_'
+      && physname[1] == CPLUS_MARKER && physname[2] == '_';
   /* Need a new type prefix.  */
   char *const_prefix = method->is_const ? "C" : "";
   char *volatile_prefix = method->is_volatile ? "V" : "";
-  char *newname = type_name_no_tag (type);
   char buf[20];
+#ifndef GCC_MANGLE_BUG
   int len = strlen (newname);
 
+  if (is_destructor)
+    {
+      mangled_name = (char*) xmalloc(strlen(physname)+1);
+      strcpy(mangled_name, physname);
+      return mangled_name;
+    }
+
   sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
   mangled_name_len = ((is_constructor ? 0 : strlen (field_name))
                          + strlen (buf) + len
-                         + strlen (TYPE_FN_FIELD_PHYSNAME (f, j))
+                         + strlen (physname)
                          + 1);
 
   /* Only needed for GNU-mangled names.  ANSI-mangled names
@@ -289,9 +311,53 @@ gdb_mangle_name (type, i, j)
     }
   strcat (mangled_name, buf);
   strcat (mangled_name, newname);
-  strcat (mangled_name, TYPE_FN_FIELD_PHYSNAME (f, j));
+#else
+  char *opname;
 
-  return mangled_name;
+  if (is_constructor)
+    {
+      buf[0] = '\0';
+    }
+  else
+    {
+      sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
+    }
+
+  mangled_name_len = ((is_constructor ? 0 : strlen (field_name))
+                     + strlen (buf) + strlen (physname) + 1);
+
+  /* Only needed for GNU-mangled names.  ANSI-mangled names
+     work with the normal mechanisms.  */
+  if (OPNAME_PREFIX_P (field_name))
+    {
+      opname = cplus_mangle_opname (field_name + 3, 0);
+      if (opname == NULL)
+       {
+         error ("No mangling for \"%s\"", field_name);
+       }
+      mangled_name_len += strlen (opname);
+      mangled_name = (char *) xmalloc (mangled_name_len);
+
+      strncpy (mangled_name, field_name, 3);
+      strcpy (mangled_name + 3, opname);
+    }
+  else
+    {
+      mangled_name = (char *) xmalloc (mangled_name_len);
+      if (is_constructor)
+       {
+         mangled_name[0] = '\0';
+       }
+      else
+       {
+         strcpy (mangled_name, field_name);
+       }
+    }
+  strcat (mangled_name, buf);
+
+#endif
+  strcat (mangled_name, physname);
+  return (mangled_name);
 }
 
 \f
@@ -500,7 +566,8 @@ found:
 
          ALL_MSYMBOLS (objfile, msymbol)
            {
-             demangled = demangle_and_match (msymbol -> name, name, 0);
+             demangled = demangle_and_match (msymbol -> name, name,
+                                             DMGL_PARAMS | DMGL_ANSI);
              if (demangled != NULL)
                {
                  free (demangled);
@@ -558,7 +625,7 @@ found_msym:
          block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
          sym = lookup_block_symbol (block, name, namespace);
          if (!sym)
-           error ("Internal: global symbol `%s' found in psymtab but not in symtab", name);
+           error ("Internal: global symbol `%s' found in %s psymtab but not in symtab", name, ps->filename);
          if (symtab != NULL)
            *symtab = s;
          return sym;
@@ -592,7 +659,7 @@ found_msym:
          block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
          sym = lookup_block_symbol (block, name, namespace);
          if (!sym)
-           error ("Internal: static symbol `%s' found in psymtab but not in symtab", name);
+           error ("Internal: static symbol `%s' found in %s psymtab but not in symtab", name, ps->filename);
          if (symtab != NULL)
            *symtab = s;
          return sym;
@@ -627,7 +694,7 @@ found_msym:
              block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
              sym = lookup_demangled_block_symbol (block, name);
              if (!sym)
-               error ("Internal: mangled static symbol `%s' found in psymtab but not in symtab", name);
+               error ("Internal: mangled static symbol `%s' found in %s psymtab but not in symtab", name, ps->filename);
              if (symtab != NULL)
                *symtab = s;
              return sym;
@@ -659,7 +726,8 @@ lookup_demangled_block_symbol (block, name)
       sym = BLOCK_SYM (block, bot);
       if (SYMBOL_NAMESPACE (sym) == VAR_NAMESPACE)
        {
-         demangled = demangle_and_match (SYMBOL_NAME (sym), name, 0);
+         demangled = demangle_and_match (SYMBOL_NAME (sym), name,
+                                         DMGL_PARAMS | DMGL_ANSI);
          if (demangled != NULL)
            {
              free (demangled);
@@ -691,7 +759,8 @@ lookup_demangled_partial_symbol (pst, name)
     {
       if (SYMBOL_NAMESPACE (psym) == VAR_NAMESPACE)
        {
-         demangled = demangle_and_match (SYMBOL_NAME (psym), name, 0);
+         demangled = demangle_and_match (SYMBOL_NAME (psym), name,
+                                         DMGL_PARAMS | DMGL_ANSI);
          if (demangled != NULL)
            {
              free (demangled);
@@ -1429,6 +1498,7 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line)
   char *copy;
   struct symbol *sym_class;
   int i1;
+  int is_quoted;
   struct symbol **sym_arr;
   struct type *t;
   char **physnames;
@@ -1443,22 +1513,9 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line)
       default_line = current_source_line;
     }
 
+  /* See if arg is *PC */
 
-  /* Check to see if *ARGPTR points to a string that has been quoted with
-     gdb_completer_quote_characters.  If so, P will be left pointing at
-     someplace other than *ARGPTR */
-
-  if (((p = skip_quoted (*argptr)) != *argptr) &&
-      ((*(p - 1) != **argptr) ||
-       (strchr (gdb_completer_quote_characters, **argptr) == NULL)))
-    {
-      /* Not quoted symbol string specification, reset P */
-      p = *argptr;
-    }
-
-  /* See if arg is *PC or '<some symbol specifier string>' */
-
-  if ((**argptr == '*') || (p != *argptr))
+  if (**argptr == '*')
     {
       if (**argptr == '*')
        {
@@ -1475,7 +1532,8 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line)
 
   /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
 
-  s = 0;
+  s = NULL;
+  is_quoted = (strchr (gdb_completer_quote_characters, **argptr) != NULL);
 
   for (p = *argptr; *p; p++)
     {
@@ -1484,7 +1542,7 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line)
     }
   while (p[0] == ' ' || p[0] == '\t') p++;
 
-  if (p[0] == ':')
+  if ((p[0] == ':') && !is_quoted)
     {
 
       /*  C++  */
@@ -1494,7 +1552,7 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line)
          p1 = p;
          while (p != *argptr && p[-1] == ' ') --p;
          copy = (char *) alloca (p - *argptr + 1);
-         (void) memcpy (copy, *argptr, p - *argptr);
+         memcpy (copy, *argptr, p - *argptr);
          copy[p - *argptr] = 0;
 
          /* Discard the class name from the arg.  */
@@ -1521,7 +1579,7 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line)
                  char *tmp = alloca (q1 - q + 1);
                  memcpy (tmp, q, q1 - q);
                  tmp[q1 - q] = '\0';
-                 opname = cplus_mangle_opname (tmp, 1);
+                 opname = cplus_mangle_opname (tmp, DMGL_ANSI);
                  if (opname == NULL)
                    {
                      warning ("no mangling for \"%s\"", tmp);
@@ -1535,7 +1593,7 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line)
              else
                {
                  copy = (char *) alloca (p - *argptr + 1 + (q1 - q));
-                 (void) memcpy (copy, *argptr, p - *argptr);
+                 memcpy (copy, *argptr, p - *argptr);
                  copy[p - *argptr] = '\0';
                }
 
@@ -1630,7 +1688,7 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line)
       p1 = p;
       while (p != *argptr && p[-1] == ' ') --p;
       copy = (char *) alloca (p - *argptr + 1);
-      (void) memcpy (copy, *argptr, p - *argptr);
+      memcpy (copy, *argptr, p - *argptr);
       copy[p - *argptr] = 0;
 
       /* Find that file's data.  */
@@ -1717,7 +1775,7 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line)
 
   p = skip_quoted (*argptr);
   copy = (char *) alloca (p - *argptr + 1);
-  (void) memcpy (copy, *argptr, p - *argptr);
+  memcpy (copy, *argptr, p - *argptr);
   copy[p - *argptr] = '\0';
   if ((copy[0] == copy [p - *argptr - 1])
       && strchr (gdb_completer_quote_characters, copy[0]) != NULL)
@@ -1784,7 +1842,7 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line)
          values.sals = (struct symtab_and_line *)
            xmalloc (sizeof (struct symtab_and_line));
          values.nelts = 1;
-         (void) memset (&values.sals[0], 0, sizeof (values.sals[0]));
+         memset (&values.sals[0], 0, sizeof (values.sals[0]));
          values.sals[0].symtab = sym_symtab;
          values.sals[0].line = SYMBOL_LINE (sym);
          return values;
@@ -1846,6 +1904,7 @@ decode_line_2 (sym_arr, nelts, funfirstline)
   char *args, *arg1;
   int i;
   char *prompt;
+  char *demangled;
 
   values.sals = (struct symtab_and_line *) alloca (nelts * sizeof(struct symtab_and_line));
   return_values.sals = (struct symtab_and_line *) xmalloc (nelts * sizeof(struct symtab_and_line));
@@ -1864,8 +1923,15 @@ decode_line_2 (sym_arr, nelts, funfirstline)
          values.sals[i] = find_pc_line (pc, 0);
          values.sals[i].pc = (values.sals[i].end && values.sals[i].pc != pc) ?
                               values.sals[i].end                      :  pc;
-         printf("[%d] file:%s; line number:%d\n",
-                (i+2), values.sals[i].symtab->filename, values.sals[i].line);
+         demangled = cplus_demangle (SYMBOL_NAME (sym_arr[i]),
+                                     DMGL_PARAMS | DMGL_ANSI);
+         printf("[%d] %s at %s:%d\n", (i+2),
+                demangled ? demangled : SYMBOL_NAME (sym_arr[i]), 
+                values.sals[i].symtab->filename, values.sals[i].line);
+         if (demangled != NULL)
+           {
+             free (demangled);
+           }
        }
       else printf ("?HERE\n");
       i++;
@@ -1899,8 +1965,8 @@ decode_line_2 (sym_arr, nelts, funfirstline)
        error ("cancelled");
       else if (num == 1)
        {
-         (void) memcpy (return_values.sals, values.sals,
-                        (nelts * sizeof(struct symtab_and_line)));
+         memcpy (return_values.sals, values.sals,
+                 (nelts * sizeof(struct symtab_and_line)));
          return_values.nelts = nelts;
          return return_values;
        }
@@ -2031,7 +2097,7 @@ static int
 name_match (name)
      char *name;
 {
-  char *demangled = cplus_demangle (name, 0);
+  char *demangled = cplus_demangle (name, DMGL_ANSI);
   if (demangled != NULL)
     {
       int cond = re_exec (demangled);
@@ -2043,7 +2109,8 @@ name_match (name)
 #define NAME_MATCH(NAME) name_match(NAME)
 
 /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
-   If CLASS is zero, list all symbols except functions and type names.
+   If CLASS is zero, list all symbols except functions, type names, and
+                    constants (enums).
    If CLASS is 1, list only functions.
    If CLASS is 2, list only type names.
    If CLASS is 3, list only method names.
@@ -2159,7 +2226,7 @@ list_symbols (regexp, class, bpt)
                      || (class == 2 && SYMBOL_CLASS (psym) == LOC_TYPEDEF)
                      || (class == 3 && SYMBOL_CLASS (psym) == LOC_BLOCK)))
                {
-                 (void) PSYMTAB_TO_SYMTAB(ps);
+                 PSYMTAB_TO_SYMTAB(ps);
                  keep_going = 0;
                }
            }
@@ -2221,7 +2288,8 @@ list_symbols (regexp, class, bpt)
                sym = BLOCK_SYM (b, j);
                if ((regexp == 0 || NAME_MATCH (SYMBOL_NAME (sym)))
                    && ((class == 0 && SYMBOL_CLASS (sym) != LOC_TYPEDEF
-                        && SYMBOL_CLASS (sym) != LOC_BLOCK)
+                        && SYMBOL_CLASS (sym) != LOC_BLOCK
+                        && SYMBOL_CLASS (sym) != LOC_CONST)
                        || (class == 1 && SYMBOL_CLASS (sym) == LOC_BLOCK)
                        || (class == 2 && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
                        || (class == 3 && SYMBOL_CLASS (sym) == LOC_BLOCK)))
@@ -2389,35 +2457,50 @@ completion_list_add_symbol (symname, text, text_len)
 {
   char *demangled;
   int newsize;
+  int i;
+
+  /* clip symbols that cannot match */
+
+  if (!cplus_match (symname, text, text_len)) {
+    return;
+  }
+
+  /* matches mangled, may match unmangled.  now clip any symbol names
+     that we've already considered.  (This is a time optimization)  */
 
-  /* First see if SYMNAME is a C++ mangled name, and if so, use the
-     demangled name instead, including any parameters. */
+  for (i = 0; i < return_val_index; ++i) {
+    if (strcmp (symname, return_val[i]) == 0) {
+      return;
+    }
+  }
+  
+  /* See if SYMNAME is a C++ mangled name, and if so, use the
+     demangled name instead, including any parameters.  */
 
   if ((demangled = cplus_demangle (symname, DMGL_PARAMS | DMGL_ANSI)) != NULL)
     {
+      if (strncmp (demangled, text, text_len) != 0) {
+       return;
+      }        /* demangled, but didn't match so clip it */
+
       symname = demangled;
+    } else {
+      symname = savestring (symname, strlen (symname));
     }
 
   /* If we have a match for a completion, then add SYMNAME to the current
-     list of matches. Note that we always make a copy of the string, even
-     if it is one that was returned from cplus_demangle and is already
-     in malloc'd memory. */
+     list of matches. Note that the name is in freshly malloc'd space;
+     either from cplus_demangle or from savestring above.  */
 
-  if (strncmp (symname, text, text_len) == 0)
+  if (return_val_index + 3 > return_val_size)
     {
-      if (return_val_index + 3 > return_val_size)
-       {
-         newsize = (return_val_size *= 2) * sizeof (char *);
-         return_val = (char **) xrealloc ((char *) return_val, newsize);
-       }
-      return_val[return_val_index++] = savestring (symname, strlen (symname));
-      return_val[return_val_index] = NULL;
+      newsize = (return_val_size *= 2) * sizeof (char *);
+      return_val = (char **) xrealloc ((char *) return_val, newsize);
     }
+  return_val[return_val_index++] = symname;
+  return_val[return_val_index] = NULL;
 
-  if (demangled != NULL)
-    {
-      free (demangled);
-    }
+  return;
 }
 
 /* Return a NULL terminated array of all symbols (regardless of class) which
This page took 0.03158 seconds and 4 git commands to generate.