Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Kevin Buettner <kevinb@redhat.com>
To: Pedro Alves <pedro@palves.net>
Cc: gdb-patches@sourceware.org, Tom Tromey <tom@tromey.com>,
	Tom de Vries <tdevries@suse.de>
Subject: Re: [PATCH] [gdb/exp] Fix cast handling for indirection
Date: Fri, 3 May 2024 10:30:50 -0700	[thread overview]
Message-ID: <20240503103050.2ef46699@f39-zbm-amd> (raw)
In-Reply-To: <51de396e-67fc-4451-a13e-091178d188f7@palves.net>

On Fri, 3 May 2024 17:04:41 +0100
Pedro Alves <pedro@palves.net> wrote:

> > I was wondering if this patch causes gdb to accept some weird things
> > that might have been rejected in the past, by introducing a hidden cast.
> > Maybe print (char) *85732 does something surprising now.  I'm not
> > entirely sure if that's bad.  
> 
> I am totally surprised that:
> 
>  +# Regression test for PR31693.
>  +gdb_test "p (char)*a_loc ()" " = 97 'a'"
> 
> this actually works, instead of telling the user:
> 
>   "'a_loc' has unknown return type; cast the call to its declared return type"
> 
> It seems like a misfeature to me to assume that "char *" is the right type.
> 
> Thus, I don't agree with the patch.

Using a GDB built with Tom de Vries's patch, I see:

(gdb) p *a_loc()
'a_loc' has unknown return type; cast the call to its declared return type

This is the same as the pre-patch behavior.

With Tom's patch, GDB now infers the function's return type, based
on the cast:

(gdb) p (char)*a_loc()
$1 = 97 'a'

I like this behavior and certainly find it preferable to the behavior
without his patch:

(gdb) p (char)*a_loc()
Cannot access memory at address 0x4

With regard to doing something like 'print (char) *85732', I
don't see anything surprising...

(gdb) p/d (char *)a_loc()
$1 = 4210692

(I'll use 4210692 in place of 85732.)

Pre-patch:

(gdb) p *4210692
$2 = 97
(gdb) p (char)*4210692
$3 = 97 'a'

With Tom de Vries's patch:

(gdb) p *4210692
$9 = 97
(gdb) p (char)*4210692
$10 = 97 'a'

Kevin


  reply	other threads:[~2024-05-03 17:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-02 15:49 Tom de Vries
2024-05-03  2:31 ` Kevin Buettner
2024-05-03  7:37   ` Tom de Vries
2024-05-03 15:27   ` Tom Tromey
2024-05-03 16:04     ` Pedro Alves
2024-05-03 17:30       ` Kevin Buettner [this message]
2024-05-03 23:17         ` Pedro Alves
2024-05-03 23:26           ` Pedro Alves
2024-05-06  0:54             ` Kevin Buettner
2024-05-06  6:52               ` Tom de Vries

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=20240503103050.2ef46699@f39-zbm-amd \
    --to=kevinb@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@palves.net \
    --cc=tdevries@suse.de \
    --cc=tom@tromey.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