This regression was reported on irc. It comes from my patch 1f8a1ced4eefa4c6052a3e4566781527373eff45 struct s { int x; }; struct s *s2; int main() { } (gdb) p s2 && s2->x == 0 Cannot access memory at address 0x0
CVSROOT: /cvs/src Module name: src Changes by: tromey@sourceware.org 2013-05-13 16:51:52 Modified files: gdb : ChangeLog eval.c opencl-lang.c gdb/testsuite : ChangeLog gdb/testsuite/gdb.base: exprs.c exprs.exp Log message: PR exp/15364: * eval.c (evaluate_subexp_standard) <STRUCTOP_STRUCT, STRUCTOP_PTR>: Return a not_lval value for EVAL_AVOID_SIDE_EFFECTS. * opencl-lang.c (evaluate_subexp_opencl): Return a not_lval value for EVAL_AVOID_SIDE_EFFECTS. gdb/testsuite * gdb.base/exprs.exp (test_expr): Add regression test. * gdb.base/exprs.c (null_t_struct): New global. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.15548&r2=1.15549 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/eval.c.diff?cvsroot=src&r1=1.182&r2=1.183 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/opencl-lang.c.diff?cvsroot=src&r1=1.23&r2=1.24 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&r1=1.3656&r2=1.3657 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.base/exprs.c.diff?cvsroot=src&r1=1.3&r2=1.4 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.base/exprs.exp.diff?cvsroot=src&r1=1.29&r2=1.30
Fixed.
The master branch has been updated by Andrew Burgess <aburgess@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ac775bf4d35b7a2d5715e0ccf3d648d4670213fd commit ac775bf4d35b7a2d5715e0ccf3d648d4670213fd Author: Andrew Burgess <andrew.burgess@embecosm.com> Date: Tue May 24 16:17:52 2016 +0100 gdb: Forward VALUE_LVAL when avoiding side effects for STRUCTOP_PTR Assume that we have a C program like this: struct foo_type { int var; } foo; struct foo_type *foo_ptr = &foo; int main () { return foo_ptr->var; } Then GDB should be able to evaluate the following, however, it currently does not: (gdb) start ... (gdb) whatis &(foo_ptr->var) Attempt to take address of value not located in memory. The problem is that in EVAL_AVOID_SIDE_EFFECTS mode, eval.c:evaluate_subexp_standard always returns a not_lval value as the result for a STRUCTOP_PTR operation. As a consequence, the rest of the code believes that one cannot take the address of the returned value. This patch fixes STRUCTOP_PTR handling so that the VALUE_LVAL attribute for the returned value is properly initialized. After this change, the above session becomes: (gdb) start ... (gdb) whatis &(foo_ptr->var) type = int * This commit is largely the same as commit 2520f728b710 (Forward VALUE_LVAL when avoiding side effects for STRUCTOP_STRUCT) but applied to STRUCTOP_PTR rather than STRUCTOP_STRUCT. Both of these commits are building on top of commit ac1ca910d74d (Fixes for PR exp/15364). gdb/ChangeLog: * eval.c (evaluate_subexp_standard): If EVAL_AVOID_SIDE_EFFECTS mode, forward the VALUE_LVAL attribute to the returned value in the STRUCTOP_PTR case. gdb/testsuite/ChangeLog: * gdb.base/whatis.c: Extend the test case. * gdb.base/whatis.exp: Add additional tests.
The master branch has been updated by Andrew Burgess <aburgess@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=51415b9f309443261016ad1b63b9e350bbe3903d commit 51415b9f309443261016ad1b63b9e350bbe3903d Author: Andrew Burgess <andrew.burgess@embecosm.com> Date: Tue May 24 16:53:58 2016 +0100 gdb: Forward VALUE_LVAL when avoiding side effects for STRUCTOP_STRUCT When evaluating an expression with EVAL_AVOID_SIDE_EFFECTS if the value we return is forced to be of type not_lval then GDB will be unable to take the address of the returned value. Instead, we should properly initialise the LVAL of the returned value. This commit builds on two previous commits 2520f728b710 (Forward VALUE_LVAL when avoiding side effects for STRUCTOP_STRUCT) and ac775bf4d35b (gdb: Forward VALUE_LVAL when avoiding side effects for STRUCTOP_PTR), which in turn build on ac1ca910d74d (Fixes for PR exp/15364). This commit is currently untested due to my lack of access to an OpenCL compiler, however, if follows the same pattern as the first two commits mentioned above and so I believe that it is correct. gdb/ChangeLog: * opencl-lang.c (evaluate_subexp_opencl): If EVAL_AVOID_SIDE_EFFECTS mode, forward the VALUE_LVAL attribute to the returned value in the STRUCTOP_STRUCT case.