Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] Cleanup: Use add_sal_to_sals for expressions
@ 2012-07-17 21:29 Keith Seitz
  2012-07-18 16:35 ` Tom Tromey
  0 siblings, 1 reply; 5+ messages in thread
From: Keith Seitz @ 2012-07-17 21:29 UTC (permalink / raw)
  To: gp >> "gdb-patches@sourceware.org ml"

[-- Attachment #1: Type: text/plain, Size: 1002 bytes --]

Hi,

Currently convert_linespec_to_sals treats expressions a little 
differently than other linespec conversions. It allocates a SaL, fills 
it in, and then relies on decode_line_full to fill in the "missing" 
canonical name.

This patch causes expressions to use add_sal_to_sals, which will then 
set a canonical name for the linespec, thereby negating the need to 
double-check for missing linespecs later (in decode_line_full).

[This would not be committed until after the 7.5 branch is cut. While I 
haven't run into the new assert, I would feel better with more 
people/platforms using this before pushing this to the public.]

Keith

ChangeLog
2012-07-17  Keith Seitz  <keiths@redhat.com>

	* linespec.c (add_sal_to_sals): Use SYMNAME as
	canonical if it is non-NULL and no symtab is set in
	the SaL.
	(convert_linespec_to_sals): Use add_sal_to_sals for
	expressions, too.
	(decode_line_full): No need to "fill in missing canonical names"
	anymore. Simply make cleanups for the allocated names.

[-- Attachment #2: use-add_sal_to_sals-for-expressions.patch --]
[-- Type: text/x-patch, Size: 1951 bytes --]

diff --git a/gdb/linespec.c b/gdb/linespec.c
index 4156694..91cacb5 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -842,6 +842,8 @@ add_sal_to_sals (struct linespec_state *self,
 	  else
 	    canonical_name = xstrprintf ("%s:%d", filename, sal->line);
 	}
+      else if (symname != NULL)
+	canonical_name = xstrdup (symname);
 
       self->canonical_names[sals->nelts - 1] = canonical_name;
     }
@@ -1837,13 +1839,14 @@ convert_linespec_to_sals (struct linespec_state *state, linespec_p ls)
 
   if (ls->expression != NULL)
     {
+      struct symtab_and_line sal;
+
       /* We have an expression.  No other attribute is allowed.  */
-      sals.sals = XMALLOC (struct symtab_and_line);
-      sals.nelts = 1;
-      sals.sals[0] = find_pc_line (ls->expr_pc, 0);
-      sals.sals[0].pc = ls->expr_pc;
-      sals.sals[0].section = find_pc_overlay (ls->expr_pc);
-      sals.sals[0].explicit_pc = 1;
+      sal = find_pc_line (ls->expr_pc, 0);
+      sal.pc = ls->expr_pc;
+      sal.section = find_pc_overlay (ls->expr_pc);
+      sal.explicit_pc = 1;
+      add_sal_to_sals (state, &sals, &sal, ls->expression);
     }
   else if (ls->labels.label_symbols != NULL)
     {
@@ -2284,19 +2287,15 @@ decode_line_full (char **argptr, int flags,
   gdb_assert (canonical->addr_string != NULL);
   canonical->pre_expanded = 1;
 
-  /* Fill in the missing canonical names.  */
+  /* Arrange for allocated canonical names to be freed.  */
   if (result.nelts > 0)
     {
       int i;
 
-      if (state->canonical_names == NULL)
-	state->canonical_names = xcalloc (result.nelts, sizeof (char *));
       make_cleanup (xfree, state->canonical_names);
       for (i = 0; i < result.nelts; ++i)
 	{
-	  if (state->canonical_names[i] == NULL)
-	    state->canonical_names[i] = savestring (arg_start,
-						    *argptr - arg_start);
+	  gdb_assert (state->canonical_names[i] != NULL);
 	  make_cleanup (xfree, state->canonical_names[i]);
 	}
     }

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-07-18 20:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-17 21:29 [RFA] Cleanup: Use add_sal_to_sals for expressions Keith Seitz
2012-07-18 16:35 ` Tom Tromey
2012-07-18 19:14   ` Keith Seitz
2012-07-18 20:11     ` Tom Tromey
2012-07-18 20:40       ` Keith Seitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox