From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23451 invoked by alias); 5 Apr 2012 18:03:52 -0000 Received: (qmail 23441 invoked by uid 22791); 5 Apr 2012 18:03:50 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 05 Apr 2012 18:03:34 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q35I3XW5010866 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 5 Apr 2012 14:03:33 -0400 Received: from barimba (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q35I3WDT013612 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 5 Apr 2012 14:03:32 -0400 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [2/2] RFA: implement 'set print symbol' Date: Thu, 05 Apr 2012 18:03:00 -0000 Message-ID: <871uo2giob.fsf@fleche.redhat.com> MIME-Version: 1.0 Content-Type: text/plain 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: 2012-04/txt/msg00075.txt.bz2 This needs a doc review. This fixes PR 13907. The bug is a feature request, asking for a way to print the symbol corresponding to an address. This already happens for function pointers, but the PR asks for it to happen for all pointers. This patch adds a new setting, 'set print symbol', which can be used to enable the new feature. Built and regtested on x86-64 Fedora 16. Ok? Tom >From e47ed6174be01701f0c13591be70f0ba81518270 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 30 Mar 2012 09:41:18 -0600 Subject: [PATCH 2/2] Fix PR expr/13907 PR exp/13907: * valprint.h (struct value_print_options) : New field. * valprint.c (user_print_options): Add default for symbol_print. (show_symbol_print): New function. (generic_val_print): Respect symbol_print. (_initialize_valprint): Add "print symbol" setting. * f-valprint.c (f_val_print): Respect symbol_print. * c-valprint.c (c_val_print): Respect symbol_print. * NEWS: Update. * gdb.base/printcmds.exp (test_print_symbol): New proc. Call it. * gdb.texinfo (Print Settings): Document 'set print symbol'. --- gdb/ChangeLog | 13 +++++++++++++ gdb/NEWS | 5 +++++ gdb/c-valprint.c | 4 +++- gdb/doc/ChangeLog | 4 ++++ gdb/doc/gdb.texinfo | 18 ++++++++++++++++++ gdb/f-valprint.c | 4 +++- gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.base/printcmds.exp | 11 +++++++++++ gdb/valprint.c | 25 +++++++++++++++++++++++-- gdb/valprint.h | 4 ++++ 10 files changed, 89 insertions(+), 4 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 9444f6a..e65d922 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -93,6 +93,11 @@ ** "info vtbl" can be used to show the virtual method tables for C++ and Java objects. + ** "set print symbol" + "show print symbol" + Controls whether GDB attempts to display the symbol, if any, + corresponding to addresses it prints. + * New targets Renesas RL78 rl78-*-elf diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c index 4e32973..3e28879 100644 --- a/gdb/c-valprint.c +++ b/gdb/c-valprint.c @@ -264,7 +264,9 @@ c_val_print (struct type *type, const gdb_byte *valaddr, return; } - if (options->addressprint) + if (options->symbol_print) + print_address_demangle (options, gdbarch, addr, stream, demangle); + else if (options->addressprint) fputs_filtered (paddress (gdbarch, addr), stream); /* For a pointer to a textual type, also print the string diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 8002429..4ef8c09 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -8116,6 +8116,24 @@ does not show the symbol name and filename of the referent, even with the appropriate @code{set print} options turned on. @end quotation +You can also enable @samp{/a}-like formatting all the time using +@samp{set print symbol on}: + +@table @code +@item set print symbol on +Tell @value{GDBN} to print the symbol corresponding to an address, if +one exists. + +@item set print symbol off +Tell @value{GDBN} not to print the symbol corresponding to an +address. In this mode, @value{GDBN} will still print the symbol +corresponding to pointers to functions. This is the default. + +@item show print symbol +Show whether @value{GDBN} will display the symbol corresponding to an +address. +@end table + Other settings control how different kinds of objects are printed: @table @code diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c index 3181356..fd60953 100644 --- a/gdb/f-valprint.c +++ b/gdb/f-valprint.c @@ -320,7 +320,9 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, return; } - if (options->addressprint && options->format != 's') + if (options->symbol_print) + print_address_demangle (options, gdbarch, addr, stream, demangle); + else if (options->addressprint && options->format != 's') fputs_filtered (paddress (gdbarch, addr), stream); /* For a pointer to char or unsigned char, also print the string diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp index 08a54b0..36e6194 100644 --- a/gdb/testsuite/gdb.base/printcmds.exp +++ b/gdb/testsuite/gdb.base/printcmds.exp @@ -773,6 +773,16 @@ proc test_printf_with_dfp {} { gdb_test "printf \"%DDf\\n\",1.2E6144dl" "1.200000000000000000000000000000000E\\+6144" } +proc test_print_symbol {} { + gdb_test_no_output "set print symbol on" + + gdb_test "print &three" " = .* " + gdb_test "print parrays" " = .* " + + # In case somebody adds tests after this. + gdb_test_no_output "set print symbol off" +} + # Escape a left curly brace to prevent it from being interpreted as # the beginning of a bound proc gdb_test_escape_braces { args } { @@ -840,3 +850,4 @@ test_print_array_constants test_print_enums test_printf test_printf_with_dfp +test_print_symbol diff --git a/gdb/valprint.c b/gdb/valprint.c index 08dcbc0..63cc909 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -85,7 +85,8 @@ struct value_print_options user_print_options = 1, /* static_field_print */ 1, /* pascal_static_field_print */ 0, /* raw */ - 0 /* summary */ + 0, /* summary */ + 0 /* symbol_print */ }; /* Initialize *OPTS to be a copy of the user print options. */ @@ -219,6 +220,16 @@ show_addressprint (struct ui_file *file, int from_tty, { fprintf_filtered (file, _("Printing of addresses is %s.\n"), value); } + +static void +show_symbol_print (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + fprintf_filtered (file, + _("Printing of symbols when printing pointers is %s.\n"), + value); +} + /* A helper function for val_print. When printing in "summary" mode, @@ -396,7 +407,9 @@ generic_val_print (struct type *type, const gdb_byte *valaddr, return; } - if (options->addressprint) + if (options->symbol_print) + print_address_demangle (options, gdbarch, addr, stream, demangle); + else if (options->addressprint) fputs_filtered (paddress (gdbarch, addr), stream); } break; @@ -2612,6 +2625,14 @@ Show printing of addresses."), NULL, show_addressprint, &setprintlist, &showprintlist); + add_setshow_boolean_cmd ("symbol", class_support, + &user_print_options.symbol_print, _("\ +Set printing of symbol names when printing pointers."), _("\ +Show printing of symbol names when printing pointers."), + NULL, NULL, + show_symbol_print, + &setprintlist, &showprintlist); + add_setshow_zuinteger_cmd ("input-radix", class_support, &input_radix_1, _("\ Set default input radix for entering numbers."), _("\ diff --git a/gdb/valprint.h b/gdb/valprint.h index 817e5cd..b853b1a 100644 --- a/gdb/valprint.h +++ b/gdb/valprint.h @@ -90,6 +90,10 @@ struct value_print_options /* If nonzero, print the value in "summary" form. */ int summary; + + /* If nonzero, when printing a pointer, print the symbol to which it + points, if any. */ + int symbol_print; }; /* The global print options set by the user. In general this should -- 1.7.7.6