Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: Kevin Buettner <kevinb@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] [gdb/exp] Fix cast handling for indirection
Date: Fri, 3 May 2024 09:37:59 +0200	[thread overview]
Message-ID: <fb7c6b63-7e33-4785-b2b9-844d1b0f67b9@suse.de> (raw)
In-Reply-To: <20240502193145.5da7327d@f39-zbm-amd>

On 5/3/24 04:31, Kevin Buettner wrote:
> On Thu,  2 May 2024 17:49:02 +0200
> Tom de Vries <tdevries@suse.de> wrote:
> 
>> Consider a test-case compiled without debug info, containing:
>> ...
>> char a = 'a';
>>
>> char *
>> a_loc (void)
>> {
>>    return &a;
>> }
>> ...
>>
>> We get:
>> ...
>> (gdb) p (char)*a_loc ()
>> Cannot access memory at address 0x10
>> ...
>>
>> There's a bug in unop_ind_base_operation::evaluate that evaluates
>> "(char)*a_loc ()" the same as:
>> ...
>> (gdb) p (char)*(char)a_loc ()
> 

Hi Kevin,

thanks for the review.

> This surprised me.  I would have thought that the evaluation would
> have been:
> 
>      (char)*(int)a_loc ()
> 
> ...due to the fact that functions lacking an explicit return type
> return 'int' in traditional C.
> 

Default-to-int was my first guess, but after debugging and investigating 
the code in unop_ind_base_operation::evaluate, I realized that the cast 
(passed in expect_type) is passed unmodified to the dereferenced expression.

I used this in the test-case, by changing the cast from int to char, to 
maximize the changes that the PR will produce an incorrect pointer.

>> Cannot access memory at address 0x10
>> ...
>>
>> Fix this by instead evaluating it the same as:
>> ...
>> (gdb) p (char)*(char *)a_loc ()
>> $1 = 97 'a'
>> ...
>>
>> Tested on x86_64-linux.
>>
>> PR exp/31693
>> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31693
> 
> Aside from the (possible) nit in the commit log that I mention
> above, the patch and test case look good to me.
> 
> Approved-by: Kevin Buettner <kevinb@redhat.com>
> 

Thanks, pushed unmodified.
- Tom

> Kevin
> 


  reply	other threads:[~2024-05-03  7:37 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 [this message]
2024-05-03 15:27   ` Tom Tromey
2024-05-03 16:04     ` Pedro Alves
2024-05-03 17:30       ` Kevin Buettner
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=fb7c6b63-7e33-4785-b2b9-844d1b0f67b9@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    --cc=kevinb@redhat.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