public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-tromey-ambiguous-linespec: update decode_objc to the new style temporarily comment out decode_line_2
@ 2011-08-22 19:44 tromey
  0 siblings, 0 replies; only message in thread
From: tromey @ 2011-08-22 19:44 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-ambiguous-linespec has been updated
       via  23b786b79fe41fef568c7638947716b59b439cd0 (commit)
       via  68db9ebc7d388e5bc05de185914ad2f6fde0f523 (commit)
      from  de600ca29211dcdd7c06b09ee3a082fd02831073 (commit)

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

- Log -----------------------------------------------------------------
commit 23b786b79fe41fef568c7638947716b59b439cd0
Author: Tom Tromey <tromey@redhat.com>
Date:   Mon Aug 22 13:37:21 2011 -0600

    update decode_objc to the new style
    temporarily comment out decode_line_2

commit 68db9ebc7d388e5bc05de185914ad2f6fde0f523
Author: Tom Tromey <tromey@redhat.com>
Date:   Mon Aug 22 12:39:47 2011 -0600

    Remove objc_find_method_or_selector_end; in the end we didn't need it

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

Summary of changes:
 gdb/linespec.c  |  130 +++++++++++--------------------
 gdb/objc-lang.c |  230 ++++++++++++-------------------------------------------
 gdb/objc-lang.h |    8 +-
 3 files changed, 98 insertions(+), 270 deletions(-)

First 500 lines of diff:
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 51a1500..137f6d8 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -149,9 +149,11 @@ static char *find_toplevel_char (char *s, char c);
 
 static int is_objc_method_format (const char *s);
 
+#if 0
 static struct symtabs_and_lines decode_line_2 (struct symbol *[],
 					       int, int,
 					       struct linespec_result *);
+#endif
 
 static VEC (symtab_p) *symtab_from_filename (char **argptr,
 					     char *p, int is_quote_enclosed,
@@ -191,6 +193,10 @@ static void add_matching_symbols_to_info (const char *name,
 					  struct collect_info *info,
 					  struct program_space *pspace);
 
+static void add_all_symbol_names_from_pspace (struct collect_info *info,
+					      struct program_space *pspace,
+					      VEC (const_char_ptr) *names);
+
 /* Helper functions.  */
 
 static void
@@ -528,6 +534,9 @@ is_objc_method_format (const char *s)
   return 0;
 }
 
+#if 0 
+/* Not really deleted since we will resurrect this later.  */
+
 /* Given a list of NELTS symbols in SYM_ARR, return a list of lines to
    operate on (ask user if necessary).
    If CANONICAL is non-NULL return a corresponding array of mangled names
@@ -683,6 +692,7 @@ decode_line_2 (struct symbol *sym_arr[], int nelts, int funfirstline,
   discard_cleanups (old_chain);
   return return_values;
 }
+#endif
 
 /* Valid delimiters for linespec keywords "if", "thread" or "task".  */
 
@@ -1348,98 +1358,53 @@ locate_first_half (char **argptr, int *is_quote_enclosed)
    than one method that could represent the selector, then use some of
    the existing C++ code to let the user choose one.  */
 
-struct symtabs_and_lines
+static struct symtabs_and_lines
 decode_objc (struct linespec_state *self, char **argptr)
 {
-  struct symtabs_and_lines values;
-  struct symbol **sym_arr = NULL;
-  struct symbol *sym = NULL;
-  struct block *block;
-  unsigned i1 = 0;
-  unsigned i2 = 0;
-  struct symtab *file_symtab;
-
-  values.sals = NULL;
-  values.nelts = 0;
+  struct collect_info info;
+  VEC (const_char_ptr) *symbol_names = NULL;
+  char *new_argptr;
+  struct cleanup *cleanup = make_cleanup (VEC_cleanup (const_char_ptr),
+					  &symbol_names);
 
-  /* FIXME.  */
-  file_symtab = VEC_index (symtab_p, self->file_symtabs, 0);
+  info.state = self;
+  info.result.sals = NULL;
+  info.result.nelts = 0;
+  info.objfile = NULL;
 
-  block = get_search_block (file_symtab);
-  find_imps (file_symtab, block, *argptr, NULL, &i1, &i2); 
-    
-  if (i1 > 0)
+  new_argptr = find_imps (*argptr, &symbol_names); 
+  if (VEC_empty (const_char_ptr, symbol_names))
     {
-      sym_arr = (struct symbol **)
-	alloca ((i1 + 1) * sizeof (struct symbol *));
-      sym_arr[i1] = NULL;
-
-      *argptr = find_imps (file_symtab, block, *argptr, sym_arr, &i1, &i2);
+      do_cleanups (cleanup);
+      return info.result;
     }
 
-  /* i1 now represents the TOTAL number of matches found.
-     i2 represents how many HIGH-LEVEL (struct symbol) matches,
-     which will come first in the sym_arr array.  Any low-level
-     (minimal_symbol) matches will follow those.  */
-      
-  if (i1 == 1)
+  add_all_symbol_names_from_pspace (&info, NULL, symbol_names);
+
+  if (info.result.nelts > 0)
     {
-      if (i2 > 0)
-	{
-	  /* Already a struct symbol.  */
-	  sym = sym_arr[0];
-	}
-      else
-	{
-	  sym = find_pc_function (SYMBOL_VALUE_ADDRESS (sym_arr[0]));
-	  if ((sym != NULL) && strcmp (SYMBOL_LINKAGE_NAME (sym_arr[0]),
-				       SYMBOL_LINKAGE_NAME (sym)) != 0)
-	    {
-	      warning (_("debugging symbol \"%s\" does "
-			 "not match selector; ignoring"),
-		       SYMBOL_LINKAGE_NAME (sym));
-	      sym = NULL;
-	    }
-	}
-	      
-      values.sals = (struct symtab_and_line *)
-	xmalloc (sizeof (struct symtab_and_line));
-      values.nelts = 1;
-	      
-      if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
-	{
-	  /* Canonicalize this, so it remains resolved for dylib loads.  */
-	  values.sals[0] = find_function_start_sal (sym, self->funfirstline);
-	  build_canonical_line_spec (&values,
-				     SYMBOL_NATURAL_NAME (sym),
-				     self->canonical);
-	}
-      else
+      char *saved_arg;
+
+      saved_arg = alloca (new_argptr - *argptr + 1);
+      memcpy (saved_arg, *argptr, new_argptr - *argptr);
+      saved_arg[new_argptr - *argptr] = '\0';
+
+      if (self->canonical)
 	{
-	  /* The only match was a non-debuggable symbol, which might point
-	     to a function descriptor; resolve it to the actual code address
-	     instead.  */
-	  struct minimal_symbol *msymbol = (struct minimal_symbol *)sym_arr[0];
-	  struct objfile *objfile = msymbol_objfile (msymbol);
-	  struct gdbarch *gdbarch = get_objfile_arch (objfile);
-	  CORE_ADDR pc = SYMBOL_VALUE_ADDRESS (msymbol);
-
-	  pc = gdbarch_convert_from_func_ptr_addr (gdbarch, pc,
-						   &current_target);
-
-	  init_sal (&values.sals[0]);
-	  values.sals[0].pc = pc;
+	  self->canonical->pre_expanded = 1;
+	  if (self->user_filename)
+	    self->canonical->addr_string
+	      = xstrprintf ("%s:%s", self->user_filename, saved_arg);
+	  else
+	    self->canonical->addr_string = xstrdup (saved_arg);
 	}
-      return values;
+      build_canonical_line_spec (&info.result, saved_arg, self->canonical);
     }
 
-  if (i1 > 1)
-    {
-      /* More than one match.  The user must choose one or more.  */
-      return decode_line_2 (sym_arr, i2, self->funfirstline, self->canonical);
-    }
+  *argptr = new_argptr;
 
-  return values;
+  do_cleanups (cleanup);
+  return info.result;
 }
 
 /* This handles C++ and Java compound data structures.  P should point
@@ -1853,7 +1818,8 @@ compare_symbols (const void *a, const void *b)
 
 /* Look for all the matching instances of each symbol in NAMES.  Only
    instances from PSPACE are considered; other program spaces are
-   handled by our caller.  Results are stored into INFO.  */
+   handled by our caller.  If PSPACE is NULL, then all program spaces
+   are considered.  Results are stored into INFO.  */
 
 static void
 add_all_symbol_names_from_pspace (struct collect_info *info,
@@ -1863,8 +1829,6 @@ add_all_symbol_names_from_pspace (struct collect_info *info,
   int ix;
   const char *iter;
 
-  gdb_assert (pspace != NULL);
-
   for (ix = 0; VEC_iterate (const_char_ptr, names, ix, iter); ++ix)
     add_matching_symbols_to_info (iter, info, pspace);
 }
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 1eb9080..dcf9459 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -1112,15 +1112,11 @@ parse_method (char *method, char *type, char **class,
 }
 
 static void
-find_methods (struct symtab *symtab, char type, 
-	      const char *class, const char *category, 
-	      const char *selector, struct symbol **syms, 
-	      unsigned int *nsym, unsigned int *ndebug)
+find_methods (char type, const char *class, const char *category, 
+	      const char *selector,
+	      VEC (const_char_ptr) **symbol_names)
 {
   struct objfile *objfile = NULL;
-  struct minimal_symbol *msymbol = NULL;
-  struct block *block = NULL;
-  struct symbol *sym = NULL;
 
   char *symname = NULL;
 
@@ -1129,21 +1125,15 @@ find_methods (struct symtab *symtab, char type,
   char *ncategory = NULL;
   char *nselector = NULL;
 
-  unsigned int csym = 0;
-  unsigned int cdebug = 0;
-
   static char *tmp = NULL;
   static unsigned int tmplen = 0;
 
-  gdb_assert (nsym != NULL);
-  gdb_assert (ndebug != NULL);
-
-  if (symtab)
-    block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
+  gdb_assert (symbol_names != NULL);
 
   ALL_OBJFILES (objfile)
     {
       unsigned int *objc_csym;
+      struct minimal_symbol *msymbol = NULL;
 
       /* The objfile_csym variable counts the number of ObjC methods
 	 that this objfile defines.  We save that count as a private
@@ -1160,7 +1150,6 @@ find_methods (struct symtab *symtab, char type,
       ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
 	{
 	  struct gdbarch *gdbarch = get_objfile_arch (objfile);
-	  CORE_ADDR pc = SYMBOL_VALUE_ADDRESS (msymbol);
 
 	  QUIT;
 
@@ -1174,18 +1163,8 @@ find_methods (struct symtab *symtab, char type,
 	    /* Not a method name.  */
 	    continue;
 
-	  /* The minimal symbol might point to a function descriptor;
-	     resolve it to the actual code address instead.  */
-	  pc = gdbarch_convert_from_func_ptr_addr (gdbarch, pc,
-						   &current_target);
-
 	  objfile_csym++;
 
-	  if (symtab)
-	    if (pc < BLOCK_START (block) || pc >= BLOCK_END (block))
-	      /* Not in the specified symtab.  */
-	      continue;
-
 	  /* Now that thinks are a bit sane, clean up the symname.  */
 	  while ((strlen (symname) + 1) >= tmplen)
 	    {
@@ -1213,41 +1192,9 @@ find_methods (struct symtab *symtab, char type,
 	      ((nselector == NULL) || (strcmp (selector, nselector) != 0)))
 	    continue;
 
-	  sym = find_pc_function (pc);
-	  if (sym != NULL)
-	    {
-	      const char *newsymname = SYMBOL_NATURAL_NAME (sym);
-	  
-	      if (strcmp (symname, newsymname) == 0)
-		{
-		  /* Found a high-level method sym: swap it into the
-		     lower part of sym_arr (below num_debuggable).  */
-		  if (syms != NULL)
-		    {
-		      syms[csym] = syms[cdebug];
-		      syms[cdebug] = sym;
-		    }
-		  csym++;
-		  cdebug++;
-		}
-	      else
-		{
-		  warning (
-"debugging symbol \"%s\" does not match minimal symbol (\"%s\"); ignoring",
-                           newsymname, symname);
-		  if (syms != NULL)
-		    syms[csym] = (struct symbol *) msymbol;
-		  csym++;
-		}
-	    }
-	  else
-	    {
-	      /* Found a non-debuggable method symbol.  */
-	      if (syms != NULL)
-		syms[csym] = (struct symbol *) msymbol;
-	      csym++;
-	    }
+	  VEC_safe_push (const_char_ptr, *symbol_names, symname);
 	}
+
       if (objc_csym == NULL)
 	{
 	  objc_csym = obstack_alloc (&objfile->objfile_obstack,
@@ -1259,40 +1206,33 @@ find_methods (struct symtab *symtab, char type,
 	/* Count of ObjC methods in this objfile should be constant.  */
 	gdb_assert (*objc_csym == objfile_csym);
     }
-
-  if (nsym != NULL)
-    *nsym = csym;
-  if (ndebug != NULL)
-    *ndebug = cdebug;
 }
 
-/* Find the end of a method or selector in TEXT.  If no method or
-   selector is found, return NULL.  */
+/* Uniquify a VEC of strings.  */
 
-const char *
-objc_find_method_or_selector_end (const char *text)
+static void
+uniquify_strings (VEC (const_char_ptr) **strings)
 {
-  char *buf = NULL;
-  char type = '\0';
-  char *class = NULL;
-  char *category = NULL;
-  char *selector = NULL;
-  char *tmp;
-
-  buf = alloca (strlen (text) + 1);
-  strcpy (buf, text);
-  tmp = parse_method (buf, &type, &class, &category, &selector);
-
-  if (tmp == NULL)
+  int ix;
+  const char *elem, *last = NULL;
+  int out;
+
+  qsort (VEC_address (const_char_ptr, *strings),
+	 VEC_length (const_char_ptr, *strings),
+	 sizeof (const_char_ptr),
+	 compare_strings);
+  out = 0;
+  for (ix = 0; VEC_iterate (const_char_ptr, *strings, ix, elem); ++ix)
     {
-      strcpy (buf, text);
-      tmp = parse_selector (buf, &selector);
+      if (last == NULL || strcmp (last, elem) != 0)
+	{
+	  /* Keep ELEM.  */
+	  VEC_replace (const_char_ptr, *strings, out, elem);
+	  ++out;
+	}
+      last = elem;
     }
-
-  if (tmp == NULL)
-    return NULL;
-
-  return text + (tmp - buf);
+  VEC_truncate (const_char_ptr, *strings, out);
 }
 
 /* 
@@ -1326,31 +1266,19 @@ objc_find_method_or_selector_end (const char *text)
  */
 
 char *
-find_imps (struct symtab *symtab, struct block *block,
-	   char *method, struct symbol **syms, 
-	   unsigned int *nsym, unsigned int *ndebug)
+find_imps (char *method, VEC (const_char_ptr) **symbol_names)
 {
   char type = '\0';
   char *class = NULL;
   char *category = NULL;
   char *selector = NULL;
 
-  unsigned int csym = 0;
-  unsigned int cdebug = 0;
-
-  unsigned int ncsym = 0;
-  unsigned int ncdebug = 0;
-
   char *buf = NULL;
   char *tmp = NULL;
 
-  gdb_assert (nsym != NULL);
-  gdb_assert (ndebug != NULL);
+  int selector_case = 0;
 
-  if (nsym != NULL)
-    *nsym = 0;
-  if (ndebug != NULL)
-    *ndebug = 0;
+  gdb_assert (symbol_names != NULL);
 
   buf = (char *) alloca (strlen (method) + 1);
   strcpy (buf, method);
@@ -1358,99 +1286,37 @@ find_imps (struct symtab *symtab, struct block *block,
 
   if (tmp == NULL)
     {
-      struct symbol *sym = NULL;
-      struct minimal_symbol *msym = NULL;
-
       strcpy (buf, method);
       tmp = parse_selector (buf, &selector);
 
       if (tmp == NULL)
 	return NULL;
 
-      sym = lookup_symbol (selector, block, VAR_DOMAIN, 0);
-      if (sym != NULL) 
-	{
-	  if (syms)
-	    syms[csym] = sym;
-	  csym++;
-	  cdebug++;
-	}
-
-      if (sym == NULL)
-	msym = lookup_minimal_symbol (selector, 0, 0);
-
-      if (msym != NULL) 
-	{
-	  if (syms)
-	    syms[csym] = (struct symbol *)msym;
-	  csym++;
-	}
+      selector_case = 1;
     }
 
-  if (syms != NULL)
-    find_methods (symtab, type, class, category, selector, 
-		  syms + csym, &ncsym, &ncdebug);
-  else
-    find_methods (symtab, type, class, category, selector, 
-		  NULL, &ncsym, &ncdebug);
-
-  /* If we didn't find any methods, just return.  */
-  if (ncsym == 0 && ncdebug == 0)
-    return method;
+  find_methods (type, class, category, selector, symbol_names);
 
-  /* Take debug symbols from the second batch of symbols and swap them
-   * with debug symbols from the first batch.  Repeat until either the
-   * second section is out of debug symbols or the first section is
-   * full of debug symbols.  Either way we have all debug symbols
-   * packed to the beginning of the buffer.
-   */
-
-  if (syms != NULL) 
+  /* If we hit the "selector" case, and we found some methods, then
+     add the selector itself as a symbol, if it exists.  */
+  if (selector_case && !VEC_empty (const_char_ptr, *symbol_names))
     {
-      while ((cdebug < csym) && (ncdebug > 0))
+      struct symbol *sym = lookup_symbol (selector, NULL, VAR_DOMAIN, 0);
+
+      if (sym != NULL) 
+	VEC_safe_push (const_char_ptr, *symbol_names,
+		       SYMBOL_NATURAL_NAME (sym));
+      else
 	{
-	  struct symbol *s = NULL;
-	  /* First non-debugging symbol.  */
-	  unsigned int i = cdebug;
-	  /* Last of second batch of debug symbols.  */
-	  unsigned int j = csym + ncdebug - 1;
-
-	  s = syms[j];
-	  syms[j] = syms[i];
-	  syms[i] = s;
-
-	  /* We've moved a symbol from the second debug section to the
-             first one.  */
-	  cdebug++;
-	  ncdebug--;
+	  struct minimal_symbol *msym = lookup_minimal_symbol (selector, 0, 0);
+
+	  if (msym != NULL) 
+	    VEC_safe_push (const_char_ptr, *symbol_names,
+			   SYMBOL_NATURAL_NAME (msym));
 	}
     }
 


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


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

only message in thread, other threads:[~2011-08-22 19:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-22 19:44 [SCM] archer-tromey-ambiguous-linespec: update decode_objc to the new style temporarily comment out decode_line_2 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).