From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19405 invoked by alias); 3 May 2008 23:38:39 -0000 Received: (qmail 19394 invoked by uid 22791); 3 May 2008 23:38:38 -0000 X-Spam-Check-By: sourceware.org Received: from mail3.caviumnetworks.com (HELO mail3.caviumnetworks.com) (12.108.191.235) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 03 May 2008 23:38:19 +0000 Received: from exch4.caveonetworks.com (Not Verified[192.168.16.23]) by mail3.caviumnetworks.com with MailMarshal (v6,2,2,3503) id ; Sat, 03 May 2008 19:38:20 -0400 Received: from exch4.caveonetworks.com ([192.168.16.23]) by exch4.caveonetworks.com with Microsoft SMTPSVC(6.0.3790.3959); Sat, 3 May 2008 16:38:17 -0700 Received: from localhost.localdomain ([64.169.86.201]) by exch4.caveonetworks.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Sat, 3 May 2008 16:38:16 -0700 Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by localhost.localdomain (8.14.2/8.13.7/Debian-2) with ESMTP id m43NcAa1017287 for ; Sat, 3 May 2008 16:38:15 -0700 Received: (from anemet@localhost) by localhost.localdomain (8.14.2/8.13.7/Submit) id m43NcAib017284; Sat, 3 May 2008 16:38:10 -0700 From: Adam Nemet MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <18460.63329.752236.534872@localhost.localdomain> Date: Sat, 03 May 2008 23:48:00 -0000 To: gdb-patches@sourceware.org Subject: [PATCH] add-symbol-file not to print address truncated X-Mailer: VM 7.17 under 21.4 (patch 20) "Double Solitaire" XEmacs Lucid Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-05/txt/msg00151.txt.bz2 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.