* [PATCH] add-symbol-file not to print address truncated
@ 2008-05-03 23:48 Adam Nemet
2008-05-03 23:52 ` Pedro Alves
0 siblings, 1 reply; 7+ messages in thread
From: Adam Nemet @ 2008-05-03 23:48 UTC (permalink / raw)
To: gdb-patches
Usual issue, 32-bit host printing 64-bit target addresses incorrectly:
$ ./gdb -q
Setting up the environment for debugging gdb.
No symbol table is loaded. Use the "file" command.
(gdb) set mips abi n64
(gdb) add-symbol-file s.o 0x1234567876543210
add symbol table from file "s.o" at
.text_addr = 0x76543210
^^^^^^^^^^
(y or n) y
Reading symbols from
/home/anemet/src/mips64octeon-unknown-linux-gnu/gdb/s.o...(no debugging
symbols found)...done.
(gdb) info func
All defined functions:
Non-debugging symbols:
0x1234567876543210 f
I decided to use the same function to print the address above that is used to
print the symbols. This led me to move that code into its own function
hex_string_addr. Then looked through gdb and found a few other places that
used similar patterns to print 32- or 64-bit addresses. I changed those to
use this function too. Since now addresses are zero padded relocate.exp
needed adjustment.
Tested with mipsisa64-elf on the simulator and with x86_64-linux-gnu.
OK to install?
Adam
* defs.h (hex_string_addr): Declare.
* utils.c (hex_string_addr): Define.
* symfile.c (add_symbol_file_command): Use it.
* symtab.c (print_msymbol_info): Likewise.
* tracepoint.c (tracepoints_info): Likewise.
* ui-out.c (ui_out_field_core_addr): Likewise.
testsuite/
* gdb.base/relocate.exp: Adjust test since add-symbol-file padds
the address with zeros now.
Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.222
diff -F^\([(a-zA-Z0-9_]\|#define\) -u -p -r1.222 defs.h
--- defs.h 1 May 2008 23:09:14 -0000 1.222
+++ defs.h 3 May 2008 23:29:50 -0000
@@ -503,6 +503,7 @@ extern CORE_ADDR string_to_core_addr (co
string. */
extern char *hex_string (LONGEST);
extern char *hex_string_custom (LONGEST, int);
+extern char *hex_string_addr (CORE_ADDR);
extern void fprintf_symbol_filtered (struct ui_file *, char *,
enum language, int);
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.187
diff -F^\([(a-zA-Z0-9_]\|#define\) -u -p -r1.187 utils.c
--- utils.c 24 Apr 2008 11:13:44 -0000 1.187
+++ utils.c 3 May 2008 23:29:52 -0000
@@ -2757,6 +2757,24 @@ hex_string_custom (LONGEST num, int widt
return result_end - width - 2;
}
+/* Truncates ADDR to fit in the bits specified by gdbarch_addr_bit.
+ Then it converts the address to a C-format hexadecimal literal and
+ stores it in a static string. Returns a pointer to this string
+ that is valid until the next call. The address is padded on the
+ left with 0s to the width of addresses on the current
+ architecture. */
+
+char *
+hex_string_addr (CORE_ADDR addr)
+{
+ int addr_bit = gdbarch_addr_bit (current_gdbarch);
+
+ if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
+ addr &= ((CORE_ADDR) 1 << addr_bit) - 1;
+
+ return hex_string_custom (addr, addr_bit <= 32 ? 8 : 16);
+}
+
/* Convert VAL to a numeral in the given radix. For
* radix 10, IS_SIGNED may be true, indicating a signed quantity;
* otherwise VAL is interpreted as unsigned. If WIDTH is supplied,
Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.199
diff -F^\([(a-zA-Z0-9_]\|#define\) -u -p -r1.199 symfile.c
--- symfile.c 21 Apr 2008 14:25:16 -0000 1.199
+++ symfile.c 3 May 2008 23:29:50 -0000
@@ -2239,8 +2239,7 @@ add_symbol_file_command (char *args, int
entered on the command line. */
section_addrs->other[sec_num].name = sec;
section_addrs->other[sec_num].addr = addr;
- printf_unfiltered ("\t%s_addr = %s\n",
- sec, hex_string ((unsigned long)addr));
+ printf_unfiltered ("\t%s_addr = %s\n", sec, hex_string_addr (addr));
sec_num++;
/* The object's sections are initialized when a
Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.178
diff -F^\([(a-zA-Z0-9_]\|#define\) -u -p -r1.178 symtab.c
--- symtab.c 3 May 2008 00:37:34 -0000 1.178
+++ symtab.c 3 May 2008 23:29:51 -0000
@@ -3291,15 +3291,8 @@ print_msymbol_info (struct minimal_symbo
{
char *tmp;
- if (gdbarch_addr_bit (current_gdbarch) <= 32)
- tmp = hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol)
- & (CORE_ADDR) 0xffffffff,
- 8);
- else
- tmp = hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol),
- 16);
- printf_filtered ("%s %s\n",
- tmp, SYMBOL_PRINT_NAME (msymbol));
+ tmp = hex_string_addr (SYMBOL_VALUE_ADDRESS (msymbol));
+ printf_filtered ("%s %s\n", tmp, SYMBOL_PRINT_NAME (msymbol));
}
/* This is the guts of the commands "info functions", "info types", and
Index: tracepoint.c
===================================================================
RCS file: /cvs/src/src/gdb/tracepoint.c,v
retrieving revision 1.101
diff -F^\([(a-zA-Z0-9_]\|#define\) -u -p -r1.101 tracepoint.c
--- tracepoint.c 5 Feb 2008 16:05:56 -0000 1.101
+++ tracepoint.c 3 May 2008 23:29:51 -0000
@@ -500,12 +500,7 @@ tracepoints_info (char *tpnum_exp, int f
{
char *tmp;
- if (gdbarch_addr_bit (current_gdbarch) <= 32)
- tmp = hex_string_custom (t->address & (CORE_ADDR) 0xffffffff,
- 8);
- else
- tmp = hex_string_custom (t->address, 16);
-
+ tmp = hex_string_addr (t->address);
printf_filtered ("%s ", tmp);
}
printf_filtered ("%-5d %-5ld ", t->pass_count, t->step_count);
Index: ui-out.c
===================================================================
RCS file: /cvs/src/src/gdb/ui-out.c,v
retrieving revision 1.41
diff -F^\([(a-zA-Z0-9_]\|#define\) -u -p -r1.41 ui-out.c
--- ui-out.c 11 Jan 2008 13:34:15 -0000 1.41
+++ ui-out.c 3 May 2008 23:29:51 -0000
@@ -493,17 +493,7 @@ ui_out_field_core_addr (struct ui_out *u
char addstr[20];
int addr_bit = gdbarch_addr_bit (current_gdbarch);
- if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
- address &= ((CORE_ADDR) 1 << addr_bit) - 1;
-
- /* FIXME: cagney/2002-05-03: Need local_address_string() function
- that returns the language localized string formatted to a width
- based on gdbarch_addr_bit. */
- if (addr_bit <= 32)
- strcpy (addstr, hex_string_custom (address, 8));
- else
- strcpy (addstr, hex_string_custom (address, 16));
-
+ strcpy (addstr, hex_string_addr (address));
ui_out_field_string (uiout, fldname, addstr);
}
Index: testsuite/gdb.base/relocate.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/relocate.exp,v
retrieving revision 1.10
diff -F^\([(a-zA-Z0-9_]\|#define\) -u -p -r1.10 relocate.exp
--- testsuite/gdb.base/relocate.exp 1 Jan 2008 22:53:19 -0000 1.10
+++ testsuite/gdb.base/relocate.exp 3 May 2008 23:29:55 -0000
@@ -69,7 +69,7 @@ gdb_reinitialize_dir $srcdir/$subdir
gdb_test "add-symbol-file ${binfile} 0" \
"Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
"add-symbol-file ${testfile}.o 0" \
- "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0\[\r\n\]+\\(y or n\\) " \
+ "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0+\[\r\n\]+\\(y or n\\) " \
"y"
# Print the addresses of static variables.
@@ -118,7 +118,7 @@ gdb_test "set \$offset = 0x10000" ""
gdb_test "add-symbol-file ${binfile} \$offset" \
"Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
"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\\) " \
+ "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0*10000\[\r\n\]+\\(y or n\\) " \
"y"
# Print the addresses of functions.
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] add-symbol-file not to print address truncated
2008-05-03 23:48 [PATCH] add-symbol-file not to print address truncated Adam Nemet
@ 2008-05-03 23:52 ` Pedro Alves
2008-05-03 23:53 ` Adam Nemet
0 siblings, 1 reply; 7+ messages in thread
From: Pedro Alves @ 2008-05-03 23:52 UTC (permalink / raw)
To: gdb-patches; +Cc: Adam Nemet
Hi Adam,
A Sunday 04 May 2008 00:38:09, Adam Nemet wrote:
> Usual issue, 32-bit host printing 64-bit target addresses incorrectly:
>
> $ ./gdb -q
> Setting up the environment for debugging gdb.
> No symbol table is loaded. Use the "file" command.
> (gdb) set mips abi n64
> (gdb) add-symbol-file s.o 0x1234567876543210
> add symbol table from file "s.o" at
> .text_addr = 0x76543210
> ^^^^^^^^^^
> (y or n) y
> Reading symbols from
> /home/anemet/src/mips64octeon-unknown-linux-gnu/gdb/s.o...(no debugging
> symbols found)...done.
> (gdb) info func
> All defined functions:
>
> Non-debugging symbols:
> 0x1234567876543210 f
>
>
> I decided to use the same function to print the address above that is used
> to print the symbols. This led me to move that code into its own function
> hex_string_addr. Then looked through gdb and found a few other places that
> used similar patterns to print 32- or 64-bit addresses. I changed those to
> use this function too. Since now addresses are zero padded relocate.exp
> needed adjustment.
>
Would paddr_nz (in utils.c) do the trick?
--
Pedro Alves
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] add-symbol-file not to print address truncated
2008-05-03 23:52 ` Pedro Alves
@ 2008-05-03 23:53 ` Adam Nemet
2008-05-04 0:29 ` Pedro Alves
0 siblings, 1 reply; 7+ messages in thread
From: Adam Nemet @ 2008-05-03 23:53 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
Pedro Alves writes:
> Would paddr_nz (in utils.c) do the trick?
I thought of that but I don't think it would truncate the value when it needs
to be truncated. IOW, note the masking in hex_string_addr.
Adam
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] add-symbol-file not to print address truncated
2008-05-03 23:53 ` Adam Nemet
@ 2008-05-04 0:29 ` Pedro Alves
2008-05-04 0:43 ` Adam Nemet
0 siblings, 1 reply; 7+ messages in thread
From: Pedro Alves @ 2008-05-04 0:29 UTC (permalink / raw)
To: gdb-patches; +Cc: Adam Nemet
A Sunday 04 May 2008 00:48:35, Adam Nemet wrote:
> Pedro Alves writes:
> > Would paddr_nz (in utils.c) do the trick?
>
> I thought of that but I don't think it would truncate the value when it
> needs to be truncated. IOW, note the masking in hex_string_addr.
>
Ah, that looks like paddress then, except for the width.
const char *
paddress (CORE_ADDR addr)
{
/* Truncate address to the size of a target address, avoiding shifts
larger or equal than the width of a CORE_ADDR. The local
variable ADDR_BIT stops the compiler reporting a shift overflow
when it won't occur. */
/* NOTE: This assumes that the significant address information is
kept in the least significant bits of ADDR - the upper bits were
either zero or sign extended. Should gdbarch_address_to_pointer or
some ADDRESS_TO_PRINTABLE() be used to do the conversion? */
int addr_bit = gdbarch_addr_bit (current_gdbarch);
if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
addr &= ((CORE_ADDR) 1 << addr_bit) - 1;
return hex_string (addr);
}
char *
hex_string_addr (CORE_ADDR addr)
{
int addr_bit = gdbarch_addr_bit (current_gdbarch);
if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
addr &= ((CORE_ADDR) 1 << addr_bit) - 1;
return hex_string_custom (addr, addr_bit <= 32 ? 8 : 16);
}
--
Pedro Alves
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] add-symbol-file not to print address truncated
2008-05-04 0:29 ` Pedro Alves
@ 2008-05-04 0:43 ` Adam Nemet
2008-05-04 3:39 ` Daniel Jacobowitz
0 siblings, 1 reply; 7+ messages in thread
From: Adam Nemet @ 2008-05-04 0:43 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
Pedro Alves writes:
> Ah, that looks like paddress then, except for the width.
Right, I missed that. Thanks. I really don't care about width except that
that was what allowed me to reuse this function.
I can retest the patch without those bits then (which is pretty much an
obvious patch now) like:
* symfile.c (add_symbol_file_command): Use paddress rather than
hex_string to print the address.
Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.199
diff -F^\([(a-zA-Z0-9_]\|#define\) -u -p -u -r1.199 symfile.c
--- symfile.c 21 Apr 2008 14:25:16 -0000 1.199
+++ symfile.c 4 May 2008 00:11:11 -0000
@@ -2239,8 +2239,7 @@ add_symbol_file_command (char *args, int
entered on the command line. */
section_addrs->other[sec_num].name = sec;
section_addrs->other[sec_num].addr = addr;
- printf_unfiltered ("\t%s_addr = %s\n",
- sec, hex_string ((unsigned long)addr));
+ printf_unfiltered ("\t%s_addr = %s\n", sec, paddress (addr));
sec_num++;
/* The object's sections are initialized when a
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] add-symbol-file not to print address truncated
2008-05-04 0:43 ` Adam Nemet
@ 2008-05-04 3:39 ` Daniel Jacobowitz
2008-05-04 7:24 ` Adam Nemet
0 siblings, 1 reply; 7+ messages in thread
From: Daniel Jacobowitz @ 2008-05-04 3:39 UTC (permalink / raw)
To: Adam Nemet; +Cc: Pedro Alves, gdb-patches
On Sat, May 03, 2008 at 05:15:15PM -0700, Adam Nemet wrote:
> I can retest the patch without those bits then (which is pretty much an
> obvious patch now) like:
>
> * symfile.c (add_symbol_file_command): Use paddress rather than
> hex_string to print the address.
This is definitely OK.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] add-symbol-file not to print address truncated
2008-05-04 3:39 ` Daniel Jacobowitz
@ 2008-05-04 7:24 ` Adam Nemet
0 siblings, 0 replies; 7+ messages in thread
From: Adam Nemet @ 2008-05-04 7:24 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: Pedro Alves, gdb-patches
Daniel Jacobowitz writes:
> On Sat, May 03, 2008 at 05:15:15PM -0700, Adam Nemet wrote:
> > I can retest the patch without those bits then (which is pretty much an
> > obvious patch now) like:
> >
> > * symfile.c (add_symbol_file_command): Use paddress rather than
> > hex_string to print the address.
>
> This is definitely OK.
Just for the record, I checked this in after retesting on mipsisa64-elf.
Thanks, Dan and Pedro.
Adam
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-05-04 3:39 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-03 23:48 [PATCH] add-symbol-file not to print address truncated Adam Nemet
2008-05-03 23:52 ` Pedro Alves
2008-05-03 23:53 ` Adam Nemet
2008-05-04 0:29 ` Pedro Alves
2008-05-04 0:43 ` Adam Nemet
2008-05-04 3:39 ` Daniel Jacobowitz
2008-05-04 7:24 ` Adam Nemet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox