This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] Cleanup: Use add_sal_to_sals for expressions


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.
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]);
 	}
     }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]