From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 632 invoked by alias); 13 Nov 2009 21:27:28 -0000 Received: (qmail 624 invoked by uid 22791); 13 Nov 2009 21:27:27 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN X-Spam-Check-By: sourceware.org Received: from NaN.false.org (HELO nan.false.org) (208.75.86.248) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 13 Nov 2009 21:27:19 +0000 Received: from nan.false.org (localhost [127.0.0.1]) by nan.false.org (Postfix) with ESMTP id 5DD5D10E87 for ; Fri, 13 Nov 2009 21:27:17 +0000 (GMT) Received: from caradoc.them.org (209.195.188.212.nauticom.net [209.195.188.212]) by nan.false.org (Postfix) with ESMTP id 26C5B10661 for ; Fri, 13 Nov 2009 21:27:17 +0000 (GMT) Received: from drow by caradoc.them.org with local (Exim 4.69) (envelope-from ) id 1N93fo-0007Vt-CI for gdb-patches@sourceware.org; Fri, 13 Nov 2009 16:27:16 -0500 Date: Fri, 13 Nov 2009 21:27:00 -0000 From: Daniel Jacobowitz To: gdb-patches@sourceware.org Subject: RFC: Strip the ISA bit when printing symbol offsets Message-ID: <20091113212716.GA28795@caradoc.them.org> Mail-Followup-To: gdb-patches@sourceware.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-IsSubscribed: yes 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: 2009-11/txt/msg00302.txt.bz2 When you compile a function in ARM's Thumb mode, the low bit of the function's address is set to indicate the use of an alternate instruction set. This currently causes failures in two tests (mi-var-child.exp and member-ptr.exp), because we print $hex instead of the expected $hex . What do you think of this patch, which causes us to strip off the low bit when computing the offset if FUNCTION is a function symbol (rather than a data variable)? It's not 100% honest - if the function contains embedded data, for instance, we might print the altered offset for something that isn't an instruction. But it's right more often than what we have now, since the address including low bit set jumps to the first instruction of FUNCTION. Comments? OK to commit? Tested on arm-none-eabi and x86_64-linux. 2009-11-13 Daniel Jacobowitz * defs.h (print_address_symbolic, build_address_symbolic): Update prototypes. * printcmd.c (print_address_symbolic): Take a gdbarch argument. Pass it to build_address_symbolic. All callers updated. (build_address_symbolic): Take a gdbarch argument. Use gdbarch_addr_bits_remove for functions. All callers updated. --- gdb/breakpoint.c | 3 ++- gdb/defs.h | 7 ++++--- gdb/disasm.c | 2 +- gdb/printcmd.c | 21 +++++++++++++++------ gdb/tui/tui-stack.c | 3 ++- 5 files changed, 24 insertions(+), 12 deletions(-) Index: gdb-mainline/gdb/breakpoint.c =================================================================== --- gdb-mainline.orig/gdb/breakpoint.c 2009-11-13 10:57:09.000000000 -0800 +++ gdb-mainline/gdb/breakpoint.c 2009-11-13 10:57:11.000000000 -0800 @@ -3862,7 +3862,8 @@ static void print_breakpoint_location (s } else { - print_address_symbolic (loc->address, stb->stream, demangle, ""); + print_address_symbolic (loc->gdbarch, loc->address, stb->stream, + demangle, ""); ui_out_field_stream (uiout, "at", stb); } Index: gdb-mainline/gdb/defs.h =================================================================== --- gdb-mainline.orig/gdb/defs.h 2009-11-13 10:57:09.000000000 -0800 +++ gdb-mainline/gdb/defs.h 2009-11-13 10:57:11.000000000 -0800 @@ -596,10 +596,11 @@ extern int info_verbose; extern void set_next_address (struct gdbarch *, CORE_ADDR); -extern void print_address_symbolic (CORE_ADDR, struct ui_file *, int, - char *); +extern void print_address_symbolic (struct gdbarch *, CORE_ADDR, + struct ui_file *, int, char *); -extern int build_address_symbolic (CORE_ADDR addr, +extern int build_address_symbolic (struct gdbarch *, + CORE_ADDR addr, int do_demangle, char **name, int *offset, Index: gdb-mainline/gdb/disasm.c =================================================================== --- gdb-mainline.orig/gdb/disasm.c 2009-11-13 10:57:09.000000000 -0800 +++ gdb-mainline/gdb/disasm.c 2009-11-13 10:57:11.000000000 -0800 @@ -116,7 +116,7 @@ dump_insns (struct gdbarch *gdbarch, str ui_out_text (uiout, pc_prefix (pc)); ui_out_field_core_addr (uiout, "address", gdbarch, pc); - if (!build_address_symbolic (pc, 0, &name, &offset, &filename, + if (!build_address_symbolic (gdbarch, pc, 0, &name, &offset, &filename, &line, &unmapped)) { /* We don't care now about line, filename and Index: gdb-mainline/gdb/printcmd.c =================================================================== --- gdb-mainline.orig/gdb/printcmd.c 2009-11-13 10:57:09.000000000 -0800 +++ gdb-mainline/gdb/printcmd.c 2009-11-13 11:01:17.000000000 -0800 @@ -562,7 +562,8 @@ set_next_address (struct gdbarch *gdbarc settings of the demangle and asm_demangle variables. */ void -print_address_symbolic (CORE_ADDR addr, struct ui_file *stream, +print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr, + struct ui_file *stream, int do_demangle, char *leadin) { char *name = NULL; @@ -575,7 +576,7 @@ print_address_symbolic (CORE_ADDR addr, struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name); make_cleanup (free_current_contents, &filename); - if (build_address_symbolic (addr, do_demangle, &name, &offset, + if (build_address_symbolic (gdbarch, addr, do_demangle, &name, &offset, &filename, &line, &unmapped)) { do_cleanups (cleanup_chain); @@ -615,7 +616,8 @@ print_address_symbolic (CORE_ADDR addr, success, when all the info in the OUT paramters is valid. Return 1 otherwise. */ int -build_address_symbolic (CORE_ADDR addr, /* IN */ +build_address_symbolic (struct gdbarch *gdbarch, + CORE_ADDR addr, /* IN */ int do_demangle, /* IN */ char **name, /* OUT */ int *offset, /* OUT */ @@ -658,6 +660,13 @@ build_address_symbolic (CORE_ADDR addr, if (symbol) { + /* If this is a function (i.e. a code address), strip out any + non-address bits. For instance, display a pointer to the + first instruction of a Thumb function as ; the + second instruction will be , even though the + pointer is . This matches the ISA behavior. */ + addr = gdbarch_addr_bits_remove (gdbarch, addr); + name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)); if (do_demangle || asm_demangle) name_temp = SYMBOL_PRINT_NAME (symbol); @@ -722,7 +731,7 @@ print_address (struct gdbarch *gdbarch, CORE_ADDR addr, struct ui_file *stream) { fputs_filtered (paddress (gdbarch, addr), stream); - print_address_symbolic (addr, stream, asm_demangle, " "); + print_address_symbolic (gdbarch, addr, stream, asm_demangle, " "); } /* Return a prefix for instruction address: @@ -763,11 +772,11 @@ print_address_demangle (struct gdbarch * else if (opts.addressprint) { fputs_filtered (paddress (gdbarch, addr), stream); - print_address_symbolic (addr, stream, do_demangle, " "); + print_address_symbolic (gdbarch, addr, stream, do_demangle, " "); } else { - print_address_symbolic (addr, stream, do_demangle, ""); + print_address_symbolic (gdbarch, addr, stream, do_demangle, ""); } } Index: gdb-mainline/gdb/tui/tui-stack.c =================================================================== --- gdb-mainline.orig/gdb/tui/tui-stack.c 2009-11-13 10:57:09.000000000 -0800 +++ gdb-mainline/gdb/tui/tui-stack.c 2009-11-13 10:57:11.000000000 -0800 @@ -218,7 +218,8 @@ tui_get_function_from_frame (struct fram struct ui_file *stream = tui_sfileopen (256); char *p; - print_address_symbolic (get_frame_pc (fi), stream, demangle, ""); + print_address_symbolic (get_frame_arch (fi), get_frame_pc (fi), + stream, demangle, ""); p = tui_file_get_strbuf (stream); /* Use simple heuristics to isolate the function name. The symbol -- Daniel Jacobowitz CodeSourcery