summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Carlton <carlton@bactrian.org>2003-02-12 00:38:07 +0000
committerDavid Carlton <carlton@bactrian.org>2003-02-12 00:38:07 +0000
commitecfc355f24dcf6d8750cb420c866dbb66203ba5e (patch)
tree2fd9bca233889b0d832e40b0e16d98258d2392a3
parent6c2b8225eefebddd6e32cc66f1f7c279710b6205 (diff)
downloadgdb-ecfc355f24dcf6d8750cb420c866dbb66203ba5e.tar.gz
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.
-rw-r--r--gdb/ChangeLog22
-rw-r--r--gdb/defs.h2
-rw-r--r--gdb/gdbtypes.c9
-rw-r--r--gdb/symfile.c47
-rw-r--r--gdb/symtab.c33
-rw-r--r--gdb/utils.c58
-rw-r--r--gdb/valops.c29
7 files changed, 120 insertions, 80 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4b3b5ff3581..05c3f0c2a67 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -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.
diff --git a/gdb/defs.h b/gdb/defs.h
index 09f04202ae3..9db9530b63f 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -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 *);
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 983f55b7818..3cb3a78c64d 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -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)
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 58edbf3ffe3..4534c30d5b5 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -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
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 07cb841fc82..a277efbd025 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -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);
}
}
diff --git a/gdb/utils.c b/gdb/utils.c
index 55cef3027c5..eadd1681611 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -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
diff --git a/gdb/valops.c b/gdb/valops.c
index c86de4cf295..0482cec532f 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -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,