Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* PR gdb/260: variables not expanded on the add-symbol-file command line
@ 2003-06-21 22:31 Daniel Jacobowitz
  2003-06-22 17:59 ` Andrew Cagney
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Jacobowitz @ 2003-06-21 22:31 UTC (permalink / raw)
  To: gdb-patches

This PR gets reported pretty regularly.  Since the command line
overhaul I was hoping to do never materialized, does anyone object to
this patch to fix the specific problem in add-symbol-file?  I believe
the patch is simple enough to have no copyright issues.

The problem is that the code tries to parse <decimalnum> and 0x<hexnum>
directly, and does not accept convenience variables.

----- Forwarded message from Nick Hibma <n_hibma@webweaving.org> -----

Date: 28 May 2002 19:28:01 -0000
From: Nick Hibma <n_hibma@webweaving.org>
Subject: Re: gdb/260: variables not expanded on the add-symbol-file command line
To: nobody@sources.redhat.com
Cc: gdb-prs@sources.redhat.com,
Reply-To: Nick Hibma <n_hibma@webweaving.org>

The following reply was made to PR gdb/260; it has been noted by GNATS.

From: Nick Hibma <n_hibma@webweaving.org>
To: nobody@sources.redhat.com, phil@off.net,
 	gdb-gnats@sources.redhat.com, gdb-prs@sources.redhat.com
Cc:  
Subject: Re: gdb/260: variables not expanded on the add-symbol-file command line
Date: Tue, 28 May 2002 21:23:53 +0200

 http://sources.redhat.com/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gdb&pr=260
 
 The following patch fixes this (in 5.2) (note that it also removes a
 duplicate initialisation):
 
 # diff -wu symfile.c.orig symfile.c
 --- symfile.c.orig      Tue May 28 15:51:37 2002
 +++ symfile.c   Tue May 28 21:21:04 2002
 @@ -1546,11 +1546,7 @@
        char *val = sect_opts[i].value;
        char *sec = sect_opts[i].name;
   
 -      val = sect_opts[i].value;
 -      if (val[0] == '0' && val[1] == 'x')
 -       addr = strtoul (val+2, NULL, 16);
 -      else
 -       addr = strtoul (val, NULL, 10);
 +      addr = parse_and_eval_address(val);
  
        /* Here we store the section offsets in the order they were
           entered on the command line. */

----- End forwarded message -----

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


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

* Re: PR gdb/260: variables not expanded on the add-symbol-file command line
  2003-06-21 22:31 PR gdb/260: variables not expanded on the add-symbol-file command line Daniel Jacobowitz
@ 2003-06-22 17:59 ` Andrew Cagney
  2003-06-22 18:34   ` Daniel Jacobowitz
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Cagney @ 2003-06-22 17:59 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches

> This PR gets reported pretty regularly.  Since the command line
> overhaul I was hoping to do never materialized, does anyone object to
> this patch to fix the specific problem in add-symbol-file?  I believe
> the patch is simple enough to have no copyright issues.
> 
> The problem is that the code tries to parse <decimalnum> and 0x<hexnum>
> directly, and does not accept convenience variables.

Yes, looks safe.

Andrew



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

* Re: PR gdb/260: variables not expanded on the add-symbol-file command line
  2003-06-22 17:59 ` Andrew Cagney
@ 2003-06-22 18:34   ` Daniel Jacobowitz
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Jacobowitz @ 2003-06-22 18:34 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: gdb-patches

On Sun, Jun 22, 2003 at 01:59:17PM -0400, Andrew Cagney wrote:
> >This PR gets reported pretty regularly.  Since the command line
> >overhaul I was hoping to do never materialized, does anyone object to
> >this patch to fix the specific problem in add-symbol-file?  I believe
> >the patch is simple enough to have no copyright issues.
> >
> >The problem is that the code tries to parse <decimalnum> and 0x<hexnum>
> >directly, and does not accept convenience variables.
> 
> Yes, looks safe.

Here's what I checked in.  You get a testcase for free!

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

2003-06-22  Daniel Jacobowitz  <drow@mvista.com>

	* symfile.c (add_symbol_file_command): Use parse_and_eval_address.
	Suggested by Nick Hibma <n_hibma@webweaving.org>.

2003-06-22  Daniel Jacobowitz  <drow@mvista.com>

	* gdb.base/relocate.exp: Test add-symbol-file with a variable
	offset.

Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.99
diff -u -p -r1.99 symfile.c
--- symfile.c	17 Jun 2003 19:15:24 -0000	1.99
+++ symfile.c	22 Jun 2003 18:23:36 -0000
@@ -1807,11 +1807,7 @@ add_symbol_file_command (char *args, int
       char *val = sect_opts[i].value;
       char *sec = sect_opts[i].name;
  
-      val = sect_opts[i].value;
-      if (val[0] == '0' && val[1] == 'x')
-	addr = strtoul (val+2, NULL, 16);
-      else
-	addr = strtoul (val, NULL, 10);
+      addr = parse_and_eval_address (val);
 
       /* Here we store the section offsets in the order they were
          entered on the command line. */
Index: testsuite/gdb.base/relocate.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/relocate.exp,v
retrieving revision 1.2
diff -u -p -r1.2 relocate.exp
--- testsuite/gdb.base/relocate.exp	20 Jan 2003 15:40:07 -0000	1.2
+++ testsuite/gdb.base/relocate.exp	22 Jun 2003 18:23:37 -0000
@@ -105,4 +105,30 @@ if { "${function_foo_addr}" == "${functi
   pass "functions have different addresses"
 }
 
+# Now use a variable as an offset to add-symbol-file, and check that
+# the functions' addresses change.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+
+gdb_test "set \$offset = 0x10000" ""
+
+# Load the object file.
+gdb_test "add-symbol-file ${binfile} \$offset" \
+	"Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\." \
+	"add-symbol-file ${testfile}.o \$offset" \
+	"add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x10000\[\r\n\]+\\(y or n\\) " \
+	"y"
+
+# Print the addresses of functions.
+set new_function_foo_addr [get_var_address function_foo]
+
+# Make sure they have different addresses.
+if { "${function_foo_addr}" == "${new_function_foo_addr}" } {
+  fail "function foo has a different address"
+} else {
+  pass "function foo has a different address"
+}
+
 return 0


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

end of thread, other threads:[~2003-06-22 18:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-21 22:31 PR gdb/260: variables not expanded on the add-symbol-file command line Daniel Jacobowitz
2003-06-22 17:59 ` Andrew Cagney
2003-06-22 18:34   ` Daniel Jacobowitz

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