From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tromey@adacore.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Fix formatted print of functions
Date: Tue, 29 Sep 2026 16:03:42 -0400 [thread overview]
Message-ID: <867a66f7-edca-4fbd-8477-f558b8c41f09@simark.ca> (raw)
In-Reply-To: <20260929173704.2866399-1-tromey@adacore.com>
On 9/29/26 1:37 PM, Tom Tromey wrote:
> A user noticed that formatted printing of functions is strange. That
> is, printing a function normally does what you'd expect, but "print/d"
> or "print/x" will, bizarrely, instead print the value of the first
> byte of the function's body:
>
> (gdb) print main
> $1 = {<text variable, no debug info>} 0x393c20 <main>
> (gdb) print/x main
> $2 = 0x41
>
> This doesn't seem useful or intuitive to me.
>
> This patch changes gdb to instead simply print the function pointer
> using the specified format.
>
> Regression tested on x86-64 Fedora 43.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34685
> ---
> gdb/testsuite/gdb.base/printcmds.exp | 7 +++++++
> gdb/testsuite/gdb.cp/printmethod.exp | 11 ++++++++++-
> gdb/valprint.c | 8 ++++++++
> 3 files changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp
> index 9de1bcdd1a3..940622abb76 100644
> --- a/gdb/testsuite/gdb.base/printcmds.exp
> +++ b/gdb/testsuite/gdb.base/printcmds.exp
> @@ -1176,6 +1176,13 @@ proc test_printf_convenience_var {prefix} {
> }
> }
>
> +# Test formatted print with a function. See PR gdb/34685.
> +proc test_function_print {} {
> + set value [get_var_address main]
> + gdb_test "print/x main" " = $value"
> + gdb_test "print/d main" " = [expr {$value}]"
> +}
This proc is never called.
> +
> clean_restart
>
> gdb_test "print \$pc" "No registers\\."
> diff --git a/gdb/testsuite/gdb.cp/printmethod.exp b/gdb/testsuite/gdb.cp/printmethod.exp
> index fdc1c91bf23..e19646b0366 100644
> --- a/gdb/testsuite/gdb.cp/printmethod.exp
> +++ b/gdb/testsuite/gdb.cp/printmethod.exp
> @@ -49,4 +49,13 @@ gdb_test "print theA->nonvirt" \
> "${::valnum_re} = {void \\(A \\* const\\)} $hex <A::nonvirt\\((void|)\\)>" \
> "print nonvirtual method."
>
> -gdb_exit
> +proc test_formatted {exp} {
> + set out [get_valueof "" $exp ""]
> + regexp -- [subst_vars {^.* ($::hex) .*$}] $out ignore value
> + gdb_test "print/x $exp = $value"
> + gdb_test "print/d $exp" " = [expr {$value}]"
The quotes are wrong on the first gdb_test.
Simon
prev parent reply other threads:[~2026-09-29 20:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 17:37 Tom Tromey
2026-09-29 20:03 ` Simon Marchi [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=867a66f7-edca-4fbd-8477-f558b8c41f09@simark.ca \
--to=simark@simark.ca \
--cc=gdb-patches@sourceware.org \
--cc=tromey@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox