]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
2003-02-11 David Carlton <carlton@math.stanford.edu>
authorDavid Carlton <carlton@bactrian.org>
Wed, 12 Feb 2003 00:38:07 +0000 (00:38 +0000)
committerDavid Carlton <carlton@bactrian.org>
Wed, 12 Feb 2003 00:38:07 +0000 (00:38 +0000)
* valops.c (find_oload_champ): Add comment.
(find_oload_champ_namespace_loop): Fix memory management.
(find_oload_champ_namespace): Add comment.
(find_overload_match): Free oload_syms, oload_champ_bv.
* gdbtypes.c (rank_function): Add comment.
* valops.c (find_oload_champ_namespace_loop): Allow num_fns to be
zero.
* symtab.c (lookup_partial_symbol): Use strcmp_iw_ordered.
(lookup_block_symbol): Delete comment.
* symfile.c (compare_psymbols): Use strcmp_iw_ordered.
* defs.h: Declare strcmp_iw_ordered.
* utils.c (strcmp_iw_ordered): New function.

gdb/ChangeLog
gdb/defs.h
gdb/gdbtypes.c
gdb/symfile.c
gdb/symtab.c
gdb/utils.c
gdb/valops.c

index 4b3b5ff3581a8f93c75548790f38fc164643fabe..05c3f0c2a67997cc0f89e5d76b201d1906fd5a31 100644 (file)
@@ -1,6 +1,26 @@
+2003-02-11  David Carlton  <carlton@math.stanford.edu>
+
+       * valops.c (find_oload_champ): Add comment.
+       (find_oload_champ_namespace_loop): Fix memory management.
+       (find_oload_champ_namespace): Add comment.
+       (find_overload_match): Free oload_syms, oload_champ_bv.
+       * gdbtypes.c (rank_function): Add comment.
+       * valops.c (find_oload_champ_namespace_loop): Allow num_fns to be
+       zero.
+       * symtab.c (lookup_partial_symbol): Use strcmp_iw_ordered.
+       (lookup_block_symbol): Delete comment.
+       * symfile.c (compare_psymbols): Use strcmp_iw_ordered.
+       * defs.h: Declare strcmp_iw_ordered.
+       * utils.c (strcmp_iw_ordered): New function.
+
+2003-02-10  David Carlton  <carlton@math.stanford.edu>
+
+       * symtab.c (read_in_psymtabs): Only read in symtabs where we find
+       a matching symbol.
+
 2003-02-07  David Carlton  <carlton@math.stanford.edu>
 
-       * gdb_mbuild.sh (keep): Delete extra shift after -f.
+       * gdb_mbuild.sh: Delete extra shift after -f.
 
        * Merge with mainline; tag is carlton_dictionary-20030207-merge.
 
index 09f04202ae3cb24f9970baa7cdbea91b1753ab8f..9db9530b63f1f4cd00efa9d9cb9f9a923f6b6051 100644 (file)
@@ -308,6 +308,8 @@ extern void notice_quit (void);
 
 extern int strcmp_iw (const char *, const char *);
 
+extern int strcmp_iw_ordered (const char *, const char *);
+
 extern int streq (const char *, const char *);
 
 extern int subset_compare (char *, char *);
index 983f55b781866244dd98e8fe740f403c5aa0f9bd..3cb3a78c64dfda00eedfae0f781e9320992c729d 100644 (file)
@@ -2410,9 +2410,12 @@ compare_badness (struct badness_vector *a, struct badness_vector *b)
     }
 }
 
-/* Rank a function by comparing its parameter types (PARMS, length NPARMS),
- * to the types of an argument list (ARGS, length NARGS).
- * Return a pointer to a badness vector. This has NARGS + 1 entries. */
+/* Rank a function by comparing its parameter types (PARMS, length
+   NPARMS), to the types of an argument list (ARGS, length NARGS).
+   Return a pointer to a badness vector. This has NARGS + 1
+   entries.
+
+   It is the caller's responsibility to free the return value.  */
 
 struct badness_vector *
 rank_function (struct type **parms, int nparms, struct type **args, int nargs)
index 58edbf3ffe3ee232efc43ea21b70c4a716de30bb..4534c30d5b51cad84466b34b6e58c6c58fd2751a 100644 (file)
@@ -213,52 +213,17 @@ compare_symbols (const void *s1p, const void *s2p)
   return (strcmp (SYMBOL_BEST_NAME (*s1), SYMBOL_BEST_NAME (*s2)));
 }
 
-/*
-
-   LOCAL FUNCTION
-
-   compare_psymbols -- compare two partial symbols by name
-
-   DESCRIPTION
-
-   Given pointers to pointers to two partial symbol table entries,
-   compare them by name and return -N, 0, or +N (ala strcmp).
-   Typically used by sorting routines like qsort().
-
-   NOTES
-
-   Does direct compare of first two characters before punting
-   and passing to strcmp for longer compares.  Note that the
-   original version had a bug whereby two null strings or two
-   identically named one character strings would return the
-   comparison of memory following the null byte.
-
- */
+/* This compares two partial symbols by names, using strcmp_iw_ordered
+   for the comparison.  */
 
 static int
 compare_psymbols (const void *s1p, const void *s2p)
 {
-  register struct partial_symbol **s1, **s2;
-  register const char *st1, *st2;
-
-  s1 = (struct partial_symbol **) s1p;
-  s2 = (struct partial_symbol **) s2p;
-  st1 = SYMBOL_BEST_NAME (*s1);
-  st2 = SYMBOL_BEST_NAME (*s2);
+  struct partial_symbol *const *s1 = s1p;
+  struct partial_symbol *const *s2 = s2p;
 
-
-  if ((st1[0] - st2[0]) || !st1[0])
-    {
-      return (st1[0] - st2[0]);
-    }
-  else if ((st1[1] - st2[1]) || !st1[1])
-    {
-      return (st1[1] - st2[1]);
-    }
-  else
-    {
-      return (strcmp (st1, st2));
-    }
+  return strcmp_iw_ordered (SYMBOL_BEST_NAME (*s1),
+                           SYMBOL_BEST_NAME (*s2));
 }
 
 void
index 07cb841fc82ae55e3b09e83caab84f296736a05e..a277efbd02583ba2da93f2e5eb0d91f4a41417ce 100644 (file)
@@ -1517,8 +1517,8 @@ lookup_partial_symbol (struct partial_symtab *pst, const char *name,
       do_linear_search = 0;
 
       /* Binary search.  This search is guaranteed to end with center
-         pointing at the earliest partial symbol with the correct
-         name.  At that point *all* partial symbols with that name
+         pointing at the earliest partial symbol whose name might be
+         correct.  At that point *all* partial symbols with that name
          will be checked against the correct namespace. */
 
       bottom = start;
@@ -1535,7 +1535,7 @@ lookup_partial_symbol (struct partial_symtab *pst, const char *name,
            {
              do_linear_search = 1;
            }
-         if (strcmp (SYMBOL_BEST_NAME (*center), name) >= 0)
+         if (strcmp_iw_ordered (SYMBOL_BEST_NAME (*center), name) >= 0)
            {
              top = center;
            }
@@ -1741,22 +1741,6 @@ find_main_psymtab (void)
    this particular linkage name.
 */
 
-/* FIXME: carlton/2002-09-26: I've slightly changed the semantics: I
-   replaced a call to SYMBOL_MATCHES_NAME (sym, name) with a call to
-   strcmp_iw (SYMBOL_BEST_NAME (sym), name) (inside the dict_iter_name
-   functions).  I think this is okay: the only situations where the
-   new behavior should differ from the old behavior are where NAME is
-   mangled (which shouldn't happen, right??? lookup_symbol always
-   tries to demangle appropriately) or where the symbol we find
-   doesn't have a demangled name and where the symbol's name is such
-   that strcmp and strcmp_iw don't match on it (which seems unlikely
-   to me).  */
-
-/* NOTE: carlton/2003-01-14: No, there are situations where this is
-   more generous: it ignores whitespace on demangled names, too.  This
-   is good: e.g. it makes recognizing templated types more generous.
-   See PR gdb/33.  */
-
 struct symbol *
 lookup_block_symbol (register const struct block *block, const char *name,
                     const char *linkage_name, const namespace_enum namespace)
@@ -4195,11 +4179,6 @@ make_symbol_overload_list_qualified (const char *func_name)
 /* Look through the partial symtabs for all symbols which begin
    by matching FUNC_NAME.  Make sure we read that symbol table in. */
 
-/* FIXME: carlton/2003-01-30.  Lies, all lies.  The function does
-   nothing of the kind: it just reads in every single partial symtab.
-   (It used to do it in a particularly amusing way, but I've fixed
-   that.)  */
-
 static void
 read_in_psymtabs (const char *func_name)
 {
@@ -4208,7 +4187,11 @@ read_in_psymtabs (const char *func_name)
 
   ALL_PSYMTABS (objfile, ps)
   {
-    if (!ps->readin)
+    if (ps->readin)
+      continue;
+
+    if ((lookup_partial_symbol (ps, func_name, 1, VAR_NAMESPACE) != NULL)
+       || (lookup_partial_symbol (ps, func_name, 0, VAR_NAMESPACE) != NULL))
       psymtab_to_symtab (ps);
   }
 }
index 55cef3027c5d66cb363991900aa02f0e975590e0..eadd1681611a8b3baf47b95c1c482b3740b8b904 100644 (file)
@@ -2359,6 +2359,64 @@ strcmp_iw (const char *string1, const char *string2)
   return (*string1 != '\0' && *string1 != '(') || (*string2 != '\0');
 }
 
+/* This is like strcmp except that it ignores whitespace and treats
+   '(' as the first non-NULL character in terms of ordering.  Like
+   strcmp (and unlike strcmp_iw), it returns negative if STRING1 <
+   STRING2, 0 if STRING2 = STRING2, and positive if STRING1 > STRING2
+   according to that ordering.
+
+   If a list is sorted according to this function and if you want to
+   find names in the list that match some fixed NAME according to
+   strcmp_iw(LIST_ELT, NAME), then the place to start looking is right
+   where this function would put NAME.  */
+
+int
+strcmp_iw_ordered (const char *string1, const char *string2)
+{
+  while ((*string1 != '\0') && (*string2 != '\0'))
+    {
+      while (isspace (*string1))
+       {
+         string1++;
+       }
+      while (isspace (*string2))
+       {
+         string2++;
+       }
+      if (*string1 != *string2)
+       {
+         break;
+       }
+      if (*string1 != '\0')
+       {
+         string1++;
+         string2++;
+       }
+    }
+
+  switch (*string1)
+    {
+      /* Characters are non-equal unless they're both '\0'; we want to
+        make sure we get the comparison right according to our
+        comparison in the cases where one of them is '\0' or '('.  */
+    case '\0':
+      if (*string2 == '\0')
+       return 0;
+      else
+       return -1;
+    case '(':
+      if (*string2 == '\0')
+       return 1;
+      else
+       return -1;
+    default:
+      if (*string2 == '(')
+       return 1;
+      else
+       return *string1 - *string2;
+    }
+}
+
 /* A simple comparison function with opposite semantics to strcmp.  */
 
 int
index c86de4cf295a1f04586c2d1929e50a9acadcd60d..0482cec532fcddc218b6db40c4860bf6bc68766a 100644 (file)
@@ -2795,6 +2795,8 @@ find_overload_match (struct type **arg_types, int nargs, char *name, int method,
         }
 
       old_cleanups = make_cleanup (xfree, func_name);
+      make_cleanup (xfree, oload_syms);
+      make_cleanup (xfree, oload_champ_bv);
 
       oload_champ = find_oload_champ_namespace (arg_types, nargs,
                                                current_block,
@@ -2893,7 +2895,8 @@ find_overload_match (struct type **arg_types, int nargs, char *name, int method,
    contained in QUALIFIED_NAME until it either finds a good match or
    runs out of namespaces.  It stores the overloaded functions in
    *OLOAD_SYMS, and the badness vector in *OLOAD_CHAMP_BV.  The
-   calling function is responsible for freeing *OLOAD_SYMS.  */
+   calling function is responsible for freeing *OLOAD_SYMS and
+   *OLOAD_CHAMP_BV.  */
 
 static int
 find_oload_champ_namespace (struct type **arg_types, int nargs,
@@ -2917,7 +2920,10 @@ find_oload_champ_namespace (struct type **arg_types, int nargs,
 /* Helper function for find_oload_champ_namespace; NAMESPACE_LEN is
    how deep we've looked for namespaces, and the champ is stored in
    OLOAD_CHAMP.  The return value is 1 if the champ is a good one, 0
-   if it isn't.  */
+   if it isn't.
+
+   It is the caller's responsibility to free *OLOAD_SYMS and
+   *OLOAD_CHAMP_BV.  */
 
 /* FIXME: carlton/2003-01-30: This isn't the cleanest function I've
    ever written, to put it mildly.  All this overloading stuff could
@@ -2951,6 +2957,10 @@ find_oload_champ_namespace_loop (struct type **arg_types, int nargs,
     = (cp_find_first_component (qualified_name + modified_namespace_len)
        - qualified_name);
 
+  /* Initialize these to values that can safely be xfree'd.  */
+  *oload_syms = NULL;
+  *oload_champ_bv = NULL;
+
   /* First, see if we have a deeper namespace we can search in.  If we
      get a good match there, use it.  */
 
@@ -2977,18 +2987,16 @@ find_oload_champ_namespace_loop (struct type **arg_types, int nargs,
      function symbol to start off with.)  */
 
   old_cleanups = make_cleanup (xfree, *oload_syms);
+  old_cleanups = make_cleanup (xfree, *oload_champ_bv);
   new_oload_syms = make_symbol_overload_list (func_name,
                                              qualified_name,
                                              namespace_len,
                                              current_block);
-  old_cleanups = make_cleanup (xfree, new_oload_syms);
   while (new_oload_syms[num_fns])
     ++num_fns;
-  if (!num_fns)
-    error ("Couldn't find function %s", func_name);
 
   new_oload_champ = find_oload_champ (arg_types, nargs, 0, num_fns,
-                                      NULL, new_oload_syms,
+                                     NULL, new_oload_syms,
                                      &new_oload_champ_bv);
 
   /* Case 1: We found a good match.  Free earlier matches (if any),
@@ -3001,17 +3009,16 @@ find_oload_champ_namespace_loop (struct type **arg_types, int nargs,
   if (new_oload_champ != -1
       && classify_oload_match (new_oload_champ_bv, nargs, 0) == STANDARD)
     {
-      if (searched_deeper)
-       xfree (*oload_syms);
       *oload_syms = new_oload_syms;
       *oload_champ = new_oload_champ;
       *oload_champ_bv = new_oload_champ_bv;
-      discard_cleanups (old_cleanups);
+      do_cleanups (old_cleanups);
       return 1;
     }
   else if (searched_deeper)
     {
       xfree (new_oload_syms);
+      xfree (new_oload_champ_bv);
       discard_cleanups (old_cleanups);
       return 0;
     }
@@ -3031,7 +3038,9 @@ find_oload_champ_namespace_loop (struct type **arg_types, int nargs,
    (depending on METHOD) given by FNS_PTR or OLOAD_SYMS, respectively.
    The number of methods/functions in the list is given by NUM_FNS.
    Return the index of the best match; store an indication of the
-   quality of the match in OLOAD_CHAMP_BV.  */
+   quality of the match in OLOAD_CHAMP_BV.
+
+   It is the caller's responsibility to free *OLOAD_CHAMP_BV.  */
 
 static int
 find_oload_champ (struct type **arg_types, int nargs, int method,