public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-tromey-ambiguous-linespec: some cleanup fixes
@ 2011-08-12 13:50 tromey
  0 siblings, 0 replies; only message in thread
From: tromey @ 2011-08-12 13:50 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-ambiguous-linespec has been updated
       via  a5f2ba1785713e3d3b8bd27c82f444774022c9e2 (commit)
       via  9bbca45925e7e78a90378a28ffb039397bb47d2a (commit)
       via  9b58b50b98ca2828910dc3000cc2d7b729846f86 (commit)
       via  ef3e9ef67da9bb663fa9b9f468470c9463a56283 (commit)
      from  9ca0a7d8965feecffed6e2d5ac71c2d56044db14 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit a5f2ba1785713e3d3b8bd27c82f444774022c9e2
Author: Tom Tromey <tromey@redhat.com>
Date:   Fri Aug 12 07:49:43 2011 -0600

    some cleanup fixes

commit 9bbca45925e7e78a90378a28ffb039397bb47d2a
Author: Tom Tromey <tromey@redhat.com>
Date:   Fri Aug 12 07:39:22 2011 -0600

    test changes to decode_compound
    change linespec tests to be in C++

commit 9b58b50b98ca2828910dc3000cc2d7b729846f86
Author: Tom Tromey <tromey@redhat.com>
Date:   Thu Aug 11 14:54:21 2011 -0600

    initial fix of decode_compound
    untested

commit ef3e9ef67da9bb663fa9b9f468470c9463a56283
Author: Tom Tromey <tromey@redhat.com>
Date:   Wed Aug 10 14:05:42 2011 -0600

    remove obsolete FIXME

-----------------------------------------------------------------------

Summary of changes:
 gdb/linespec.c                                     |  235 +++++++++++---------
 gdb/testsuite/gdb.linespec/base/one/thefile.c      |   12 -
 gdb/testsuite/gdb.linespec/base/one/thefile.cc     |   19 ++
 .../base/two/{thefile.c => thefile.cc}             |    7 +
 gdb/testsuite/gdb.linespec/linespec.exp            |   37 +++-
 gdb/testsuite/gdb.linespec/{lspec.c => lspec.cc}   |    8 +-
 6 files changed, 191 insertions(+), 127 deletions(-)
 delete mode 100644 gdb/testsuite/gdb.linespec/base/one/thefile.c
 create mode 100644 gdb/testsuite/gdb.linespec/base/one/thefile.cc
 rename gdb/testsuite/gdb.linespec/base/two/{thefile.c => thefile.cc} (69%)
 rename gdb/testsuite/gdb.linespec/{lspec.c => lspec.cc} (61%)

First 500 lines of diff:
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 45b8d60..78f312c 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -100,23 +100,20 @@ static struct symtabs_and_lines decode_compound (struct linespec_state *self,
 						 char *saved_arg,
 						 char *p);
 
-static struct symbol *lookup_prefix_sym (char **argptr, char *p,
-					 struct symtab *);
+static VEC (symbolp) *lookup_prefix_sym (char **argptr, char *p,
+					 VEC (symtab_p) *);
 
-static struct symtabs_and_lines find_method (int funfirstline,
-					     struct linespec_result *canonical,
+static struct symtabs_and_lines find_method (struct linespec_state *self,
 					     char *saved_arg,
 					     char *copy,
-					     struct type *t,
-					     struct symbol *sym_class,
-					     struct symtab *);
+					     VEC (symbolp) *sym_classes);
 
 static void cplusplus_error (const char *name, const char *fmt, ...)
      ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (2, 3);
 
 static int total_number_of_methods (struct type *type);
 
-static int find_methods (struct type *, char *,
+static int find_methods (struct type *, const char *,
 			 enum language, struct symbol **, struct symtab *);
 
 static int add_matching_methods (int method_counter, struct type *t,
@@ -305,26 +302,14 @@ get_search_block (struct symtab *symtab)
    Note that this function is g++ specific.  */
 
 static int
-find_methods (struct type *t, char *name, enum language language,
+find_methods (struct type *t, const char *name, enum language language,
 	      struct symbol **sym_arr, struct symtab *file_symtab)
 {
   int i1 = 0;
   int ibase;
   char *class_name = type_name_no_tag (t);
-  struct cleanup *cleanup;
   char *canon;
 
-  /* NAME is typed by the user: it needs to be canonicalized before
-     passing to lookup_symbol.  */
-  canon = cp_canonicalize_string (name);
-  if (canon != NULL)
-    {
-      name = canon;
-      cleanup = make_cleanup (xfree, name);
-    }
-  else
-    cleanup = make_cleanup (null_cleanup, NULL);
-
   /* 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.  */
@@ -386,7 +371,6 @@ find_methods (struct type *t, char *name, enum language language,
       i1 += find_methods (TYPE_BASECLASS (t, ibase), name,
 			  language, sym_arr + i1, file_symtab);
 
-  do_cleanups (cleanup);
   return i1;
 }
 
@@ -1511,13 +1495,8 @@ decode_compound (struct linespec_state *self,
   char *temp_end;
   struct symbol *sym;
   char *copy;
-  struct symbol *sym_class;
-  struct type *t;
+  VEC (symbolp) *sym_classes;
   char *saved_arg;
-  struct symtab *file_symtab;
-
-  /* FIXME.  */
-  file_symtab = VEC_index (symtab_p, self->file_symtabs, 0);
 
   /* If the user specified any completer quote characters in the input,
      strip them.  They are superfluous.  */
@@ -1653,16 +1632,16 @@ decode_compound (struct linespec_state *self,
   /* Before the call, argptr->"AAA::inA::fun",
      p->"", p2->"::fun".  After the call: argptr->"fun", p, p2
      unchanged.  */
-  sym_class = lookup_prefix_sym (argptr, p2, file_symtab);
-
-  /* If sym_class has been found, and if "AAA::inA" is a class, then
-     we're in case 1 above.  So we look up "fun" as a method of that
-     class.  */
-  if (sym_class &&
-      (t = check_typedef (SYMBOL_TYPE (sym_class)),
-       (TYPE_CODE (t) == TYPE_CODE_STRUCT
-	|| TYPE_CODE (t) == TYPE_CODE_UNION)))
+  sym_classes = lookup_prefix_sym (argptr, p2, self->file_symtabs);
+
+  /* If a class has been found, then we're in case 1 above.  So we
+     look up "fun" as a method of those classes.  */
+  if (sym_classes)
     {
+      struct cleanup *cleanup;
+
+      cleanup = make_cleanup (VEC_cleanup (symbolp), &sym_classes);
+
       /* Arg token is not digits => try it as a function name.
 	 Find the next token (everything up to end or next
 	 blank).  */
@@ -1721,9 +1700,8 @@ decode_compound (struct linespec_state *self,
 	 here, we return.  If not, and we are at the and of the string,
 	 we'll lookup the whole string in the symbol tables.  */
 
-      return find_method (self->funfirstline, self->canonical,
-			  saved_arg, copy, t,
-			  sym_class, file_symtab);
+      do_cleanups (cleanup);
+      return find_method (self, saved_arg, copy, sym_classes);
     } /* End if symbol found.  */
 
 
@@ -1740,31 +1718,60 @@ decode_compound (struct linespec_state *self,
   /* Set argptr to skip over the name.  */
   *argptr = (*p == '\'') ? p + 1 : p;
 
-  /* Look up entire name.  */
-  sym = lookup_symbol (copy, get_selected_block (0), VAR_DOMAIN, 0);
-  if (sym)
-    return symbol_found (self->funfirstline, self->canonical, copy, sym,
-			 NULL, NULL);
-  else
-    {
-      struct minimal_symbol *msym;
-
-      /* Couldn't find any interpretation as classes/namespaces.  As a last
-	 resort, try the minimal symbol tables.  */
-      msym = lookup_minimal_symbol (copy, NULL, NULL);
-      if (msym != NULL)
-	return minsym_found (self->funfirstline, msym);
-    }    
-
-  /* Couldn't find a minimal symbol, either, so give up.  */
-  cplusplus_error (the_real_saved_arg,
-		   "Can't find member of namespace, "
-		   "class, struct, or union named \"%s\"\n",
-		   copy);
+  return decode_variable (self, copy);
 }
 
 /* Next come some helper functions for decode_compound.  */
 
+/* An instance of this type is used when collecting prefix symbols for
+   decode_compound.  */
+
+struct decode_compound_collector
+{
+  /* The result vector.  */
+  VEC (symbolp) *symbols;
+
+  /* A hash table of all symbols we found.  We use this to avoid
+     adding any symbol more than once.  */
+  htab_t unique_syms;
+};
+
+/* A cleanup function for an htab_t.  */
+
+static void
+cleanup_htab (void *arg)
+{
+  htab_delete (arg);
+}
+
+/* A callback for iterate_over_symbols that is used by
+   lookup_prefix_sym to collect type symbols.  */
+
+static int
+collect_one_symbol (struct symbol *sym, void *d)
+{
+  struct decode_compound_collector *collector = d;
+  void **slot;
+  struct type *t;
+
+  if (SYMBOL_CLASS (sym) != LOC_TYPEDEF)
+    return 1;
+
+  t = SYMBOL_TYPE (sym);
+  CHECK_TYPEDEF (t);
+  if (TYPE_CODE (t) != TYPE_CODE_STRUCT && TYPE_CODE (t) != TYPE_CODE_UNION)
+    return 1;
+
+  slot = htab_find_slot (collector->unique_syms, sym, INSERT);
+  if (!*slot)
+    {
+      *slot = sym;
+      VEC_safe_push (symbolp, collector->symbols, sym);
+    }
+
+  return 1;
+}
+
 /* Return the symbol corresponding to the substring of *ARGPTR ending
    at P, allowing whitespace.  Also, advance *ARGPTR past the symbol
    name in question, the compound object separator ("::" or "."), and
@@ -1772,12 +1779,17 @@ decode_compound (struct linespec_state *self,
    lookup_symbol call finds anything (i.e we return NULL).  As an
    example, say ARGPTR is "AAA::inA::fun" and P is "::inA::fun".  */
 
-static struct symbol *
-lookup_prefix_sym (char **argptr, char *p, struct symtab *file_symtab)
+static VEC (symbolp) *
+lookup_prefix_sym (char **argptr, char *p, VEC (symtab_p) *file_symtabs)
 {
   char *p1;
   char *copy;
-  struct symbol *sym;
+  int ix;
+  struct symtab *elt;
+  struct decode_compound_collector collector;
+  struct cleanup *outer;
+  struct cleanup *cleanup;
+  struct block *search_block;
 
   /* Extract the class name.  */
   p1 = p;
@@ -1795,50 +1807,73 @@ lookup_prefix_sym (char **argptr, char *p, struct symtab *file_symtab)
   /* At this point p1->"::inA::fun", p->"inA::fun" copy->"AAA",
      argptr->"inA::fun".  */
 
-  sym = lookup_symbol (copy, get_search_block (file_symtab), STRUCT_DOMAIN, 0);
-  if (sym == NULL)
+  collector.symbols = NULL;
+  outer = make_cleanup (VEC_cleanup (symbolp), &collector.symbols);
+
+  collector.unique_syms = htab_create_alloc (1, htab_hash_pointer,
+					     htab_eq_pointer, NULL,
+					     xcalloc, xfree);
+  cleanup = make_cleanup (cleanup_htab, collector.unique_syms);
+
+  for (ix = 0; VEC_iterate (symtab_p, file_symtabs, ix, elt); ++ix)
     {
-      /* 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);
+      struct block *search_block = get_search_block (elt);
 
-	  CHECK_TYPEDEF (t);
-	  if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
-	    return s;
-	}
+      iterate_over_symbols (search_block, copy, STRUCT_DOMAIN,
+			    collect_one_symbol, &collector);
+      iterate_over_symbols (search_block, copy, STRUCT_DOMAIN,
+			    collect_one_symbol, &collector);
     }
 
-  return sym;
+  do_cleanups (cleanup);
+  discard_cleanups (outer);
+  return collector.symbols;
 }
 
 /* This finds the method COPY in the class whose type is T and whose
    symbol is SYM_CLASS.  */
 
 static struct symtabs_and_lines
-find_method (int funfirstline, struct linespec_result *canonical,
-	     char *saved_arg,
-	     char *copy, struct type *t, struct symbol *sym_class,
-	     struct symtab *file_symtab)
+find_method (struct linespec_state *self, char *saved_arg,
+	     char *copy, VEC (symbolp) *sym_classes)
 {
   struct symtabs_and_lines values;
   struct symbol *sym = NULL;
   int i1;	/*  Counter for the symbol array.  */
-  struct symbol **sym_arr =  alloca (total_number_of_methods (t)
-				     * sizeof (struct symbol *));
+  struct symbol **sym_arr;
+  char *canon;
+  struct cleanup *cleanup;
+  int method_count, ix;
+
+  /* FIXME - use correct class - how? */
+  struct symbol *sym_class = VEC_index (symbolp, sym_classes, 0);
+
+  method_count = 0;
+  for (ix = 0; VEC_iterate (symbolp, sym_classes, ix, sym); ++ix)
+    method_count += total_number_of_methods (check_typedef (SYMBOL_TYPE (sym)));
+  sym_arr = XNEWVEC (struct symbol *, method_count);
+  cleanup = make_cleanup (xfree, sym_arr);
+
+  /* NAME is typed by the user: it needs to be canonicalized before
+     passing to lookup_symbol.  */
+  canon = cp_canonicalize_string (copy);
+  if (canon != NULL)
+    {
+      copy = canon;
+      make_cleanup (xfree, copy);
+    }
 
   /* Find all methods with a matching name, and put them in
      sym_arr.  */
 
-  i1 = find_methods (t, copy, SYMBOL_LANGUAGE (sym_class), sym_arr,
-		     file_symtab);
+  i1 = 0;
+  for (ix = 0; VEC_iterate (symbolp, sym_classes, ix, sym); ++ix)
+    {
+      struct type *t = check_typedef (SYMBOL_TYPE (sym));
+
+      i1 = find_methods (t, copy, SYMBOL_LANGUAGE (sym), sym_arr + i1,
+			 SYMBOL_SYMTAB (sym));
+    }
 
   /* If we were given a specific overload instance in COPY, defer the field
      acceptance till the strcmp_iw verification below, even if we found just
@@ -1854,7 +1889,7 @@ find_method (int funfirstline, struct linespec_result *canonical,
 	    xmalloc (sizeof (struct symtab_and_line));
 	  values.nelts = 1;
 	  values.sals[0] = find_function_start_sal (sym,
-						    funfirstline);
+						    self->funfirstline);
 	}
       else
 	{
@@ -1873,7 +1908,6 @@ find_method (int funfirstline, struct linespec_result *canonical,
 	  int i;
 	  char *name;
 	  char *canon;
-	  struct cleanup *cleanup;
 
 	  /* Construct the proper search name based on SYM_CLASS and COPY.
 	     SAVED_ARG may contain a valid name, but that name might not be
@@ -1890,10 +1924,9 @@ find_method (int funfirstline, struct linespec_result *canonical,
 	  canon = cp_canonicalize_string (name);
 	  if (canon != NULL)
 	    {
-	      xfree (name);
 	      name = canon;
+	      make_cleanup (xfree, name);
 	    }
-	  cleanup = make_cleanup (xfree, name);
 
 	  for (i = 0; i < i1; ++i)
 	    {
@@ -1903,7 +1936,7 @@ find_method (int funfirstline, struct linespec_result *canonical,
 		    xmalloc (sizeof (struct symtab_and_line));
 		  values.nelts = 1;
 		  values.sals[0] = find_function_start_sal (sym_arr[i],
-							    funfirstline);
+							    self->funfirstline);
 		  do_cleanups (cleanup);
 		  return values;
 		}
@@ -1914,7 +1947,8 @@ find_method (int funfirstline, struct linespec_result *canonical,
 				      SYMBOL_PRINT_NAME (sym_class), copy);
 	}
 
-      return decode_line_2 (sym_arr, i1, funfirstline, canonical);
+      do_cleanups (cleanup);
+      return decode_line_2 (sym_arr, i1, self->funfirstline, self->canonical);
     }
   else
     {
@@ -1981,14 +2015,6 @@ add_symtabs_to_list (struct symtab *symtab, void *d)
   return 0;
 }
 
-/* A cleanup function for an htab_t.  */
-
-static void
-cleanup_htab (void *arg)
-{
-  htab_delete (arg);
-}
-
 /* Return the symtab associated to the filename given by the substring
    of *ARGPTR ending at P, and advance ARGPTR past that filename.  */
 
@@ -2455,7 +2481,6 @@ decode_variable (struct linespec_state *self, char *copy)
     }
 
   /* Try one last thing, but only if no "file" part was given.  */
-  /* FIXME should do better at iterating in general.  */
   if (VEC_length (symtab_p, self->file_symtabs) == 1
       && VEC_index (symtab_p, self->file_symtabs, 0) == NULL)
     {
diff --git a/gdb/testsuite/gdb.linespec/base/one/thefile.c b/gdb/testsuite/gdb.linespec/base/one/thefile.c
deleted file mode 100644
index ad203a2..0000000
--- a/gdb/testsuite/gdb.linespec/base/one/thefile.c
+++ /dev/null
@@ -1,12 +0,0 @@
-/* The commented line must have the same line number in the other
-   "thefile.c".  */
-
-
-
-
-
-
-int m(int x)
-{
-  return x + 23;		/* thefile breakpoint */
-}
diff --git a/gdb/testsuite/gdb.linespec/base/one/thefile.cc b/gdb/testsuite/gdb.linespec/base/one/thefile.cc
new file mode 100644
index 0000000..882ccc9
--- /dev/null
+++ b/gdb/testsuite/gdb.linespec/base/one/thefile.cc
@@ -0,0 +1,19 @@
+/* The commented line must have the same line number in the other
+   "thefile.c".  */
+
+#include "../../lspec.h"
+
+
+
+
+
+
+int m(int x)
+{
+  return x + 23;		/* thefile breakpoint */
+}
+
+int NameSpace::overload(int x)
+{
+  return x + 23;
+}
diff --git a/gdb/testsuite/gdb.linespec/base/two/thefile.c b/gdb/testsuite/gdb.linespec/base/two/thefile.cc
similarity index 69%
rename from gdb/testsuite/gdb.linespec/base/two/thefile.c
rename to gdb/testsuite/gdb.linespec/base/two/thefile.cc
index c3c3579..43917f8 100644
--- a/gdb/testsuite/gdb.linespec/base/two/thefile.c
+++ b/gdb/testsuite/gdb.linespec/base/two/thefile.cc
@@ -1,6 +1,8 @@
 /* The commented line must have the same line number in the other
    "thefile.c".  */
 
+#include "../../lspec.h"
+
 static int dupname(int y)
 {
  label: return y;
@@ -10,3 +12,8 @@ int n(int y)
 {
   return dupname(y) - 23;	/* thefile breakpoint */
 }
+
+int NameSpace::overload(double x)
+{
+  return (int) x - 23;
+}
diff --git a/gdb/testsuite/gdb.linespec/linespec.exp b/gdb/testsuite/gdb.linespec/linespec.exp
index 49a457d..4b0e531 100644
--- a/gdb/testsuite/gdb.linespec/linespec.exp
+++ b/gdb/testsuite/gdb.linespec/linespec.exp
@@ -20,13 +20,18 @@ set testfile linespec
 set exefile lspec
 set binfile ${objdir}/${subdir}/${exefile}
 
-set baseone base/one/thefile.c
-set basetwo base/two/thefile.c
+set baseone base/one/thefile.cc
+set basetwo base/two/thefile.cc
 
 set hex {0x[0-9a-fA-F]+}
 
+if {[skip_cplus_tests]} {
+    unsupported linespec.exp
+    return
+}
+
 if {[prepare_for_testing ${testfile}.exp $exefile \
-	 [list lspec.c $baseone $basetwo] \
+	 [list lspec.cc $baseone $basetwo] \
 	 {debug nowarnings}]} {
     return -1
 }
@@ -41,12 +46,12 @@ if {$l1 != $l2} {
     error "somebody incompatibly modified the source files needed by linespec.exp"
 }
 
-gdb_test "break thefile.c:$l1" \
-    "Breakpoint 1 at $hex: thefile.c:$l1. \[(\]2 locations\[)\]" \
+gdb_test "break thefile.cc:$l1" \
+    "Breakpoint 1 at $hex: thefile.cc:$l1. \[(\]2 locations\[)\]" \
     "multi-location break using file:line"
 


hooks/post-receive
--
Repository for Project Archer.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-08-12 13:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-12 13:50 [SCM] archer-tromey-ambiguous-linespec: some cleanup fixes tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).