This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] add-symbol-file not to print address truncated
- From: Adam Nemet <anemet at caviumnetworks dot com>
- To: gdb-patches at sourceware dot org
- Date: Sat, 3 May 2008 16:38:09 -0700
- Subject: [PATCH] add-symbol-file not to print address truncated
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.