[PATCH] [gdb/exp] Fix cast handling for indirection
Kevin Buettner
kevinb@redhat.com
Fri May 3 02:31:45 GMT 2024
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
More information about the Gdb-patches
mailing list