Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Kevin Buettner <kevinb@redhat.com>
To: Tom de Vries <tdevries@suse.de>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] [gdb/exp] Fix cast handling for indirection
Date: Thu, 2 May 2024 19:31:45 -0700	[thread overview]
Message-ID: <20240502193145.5da7327d@f39-zbm-amd> (raw)
In-Reply-To: <20240502154902.22575-1-tdevries@suse.de>

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 ()

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.

> 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>

Kevin


  reply	other threads:[~2024-05-03  2:32 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 [this message]
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
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=20240502193145.5da7327d@f39-zbm-amd \
    --to=kevinb@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tdevries@suse.de \
    /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