]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
[gdb/exp] Fix cast handling for indirection
authorTom de Vries <tdevries@suse.de>
Fri, 3 May 2024 07:37:19 +0000 (09:37 +0200)
committerTom de Vries <tdevries@suse.de>
Fri, 3 May 2024 07:37:19 +0000 (09:37 +0200)
commited8fd0a342f6e832fee1a3fabc3e494977780dcf
tree296876eab5385713509f814832204f96059044ea
parente6d60e7624bffc24ce041da794b214e28ac80b4b
[gdb/exp] Fix cast handling for indirection

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 ()
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
gdb/expop.h
gdb/testsuite/gdb.base/cast-indirection.c [new file with mode: 0644]
gdb/testsuite/gdb.base/cast-indirection.exp [new file with mode: 0644]