Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Keith Seitz <keiths@redhat.com>
To: "gp >> \"gdb-patches@sourceware.org ml\"" <gdb-patches@sourceware.org>
Subject: [RFA] Cleanup: Use add_sal_to_sals for expressions
Date: Tue, 17 Jul 2012 21:29:00 -0000	[thread overview]
Message-ID: <5005D93D.7020808@redhat.com> (raw)

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

             reply	other threads:[~2012-07-17 21:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-17 21:29 Keith Seitz [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5005D93D.7020808@redhat.com \
    --to=keiths@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox