This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Forward VALUE_LVAL when avoiding side effects for STRUCTOP_STRUCT


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2520f728b710c0249cde01b8cfb4872a22ef10b6

commit 2520f728b710c0249cde01b8cfb4872a22ef10b6
Author: Pierre-Marie de Rodat <derodat@adacore.com>
Date:   Tue Sep 15 15:46:17 2015 +0200

    Forward VALUE_LVAL when avoiding side effects for STRUCTOP_STRUCT
    
    Assume foo_array is a pointer to a C structure. GDB must evaluate the
    following expression properly, but it does not currently:
    
        (gdb) print 1 && &foo_array[1].a
        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_STRUCT operation. As a consequence, the rest of
    the code believes that one cannot take the address of the returned
    value.
    
    This patch fixes STRUCTOP_STRUCT handling so that the VALUE_LVAL
    attribute for the returned value is properly initialized.  After this
    change, the above session becomes:
    
        (gdb) print 1 && &foo_array[1].a
        $1 = 1
    
    gdb/ChangeLog:
    
    	* eval.c (evaluate_subexp_standard) <STRUCTOP_STRUCT>: If
    	EVAL_AVOID_SIDE_EFFECTS mode, forward the VALUE_LVAL attribute
    	to the returned value.
    
    gdb/testsuite/ChangeLog:
    
    	* gdb.base/nested-addr.c: New file.
    	* gdb.base/nested-addr.exp: New testcase.
    
    Tested on x86_64-linux, no regression.

Diff:
---
 gdb/ChangeLog                          |  6 ++++++
 gdb/eval.c                             |  2 +-
 gdb/testsuite/ChangeLog                |  5 +++++
 gdb/testsuite/gdb.base/nested-addr.c   | 35 ++++++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.base/nested-addr.exp | 34 +++++++++++++++++++++++++++++++++
 5 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 578aeb8..e760bd0 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2015-10-12  Pierre-Marie de Rodat  <derodat@adacore.com>
+
+	* eval.c (evaluate_subexp_standard) <STRUCTOP_STRUCT>: If
+	EVAL_AVOID_SIDE_EFFECTS mode, forward the VALUE_LVAL attribute
+	to the returned value.
+
 2015-10-09  Joel Brobecker  <brobecker@adacore.com>
 
 	* ada-lang.c (ada_unpack_from_contents): Add guard that unpacked
diff --git a/gdb/eval.c b/gdb/eval.c
index a668e76..84e2e34 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1862,7 +1862,7 @@ evaluate_subexp_standard (struct type *expect_type,
       arg3 = value_struct_elt (&arg1, NULL, &exp->elts[pc + 2].string,
 			       NULL, "structure");
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	arg3 = value_zero (value_type (arg3), not_lval);
+	arg3 = value_zero (value_type (arg3), VALUE_LVAL (arg3));
       return arg3;
 
     case STRUCTOP_PTR:
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 71765a8..fbbe7ed 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2015-10-12  Pierre-Marie de Rodat  <derodat@adacore.com>
+
+	* gdb.base/nested-addr.c: New file.
+	* gdb.base/nested-addr.exp: New testcase.
+
 2015-10-09  Markus Metzger  <markus.t.metzger@intel.com>
 
 	* gdb.btrace/vdso.c (main): Remove breakpoint markers.
diff --git a/gdb/testsuite/gdb.base/nested-addr.c b/gdb/testsuite/gdb.base/nested-addr.c
new file mode 100644
index 0000000..a180fa8
--- /dev/null
+++ b/gdb/testsuite/gdb.base/nested-addr.c
@@ -0,0 +1,35 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2015 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <stdlib.h>
+
+typedef struct foo
+{
+  int a;
+  int b;
+} foo;
+
+static foo *foo_array = NULL;
+
+int
+main (void)
+{
+  foo_array = calloc (3, sizeof (*foo_array));
+  foo_array[1].a = 10;
+  foo_array[2].b = 20;
+  return 0; /* BREAK */
+}
diff --git a/gdb/testsuite/gdb.base/nested-addr.exp b/gdb/testsuite/gdb.base/nested-addr.exp
new file mode 100644
index 0000000..d6f980b
--- /dev/null
+++ b/gdb/testsuite/gdb.base/nested-addr.exp
@@ -0,0 +1,34 @@
+# Copyright 2015 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+standard_testfile
+
+if {[prepare_for_testing "${testfile}.exp" "${testfile}" "${srcfile}"]} {
+    return -1
+}
+
+if ![runto_main] {
+    return -1
+}
+
+gdb_breakpoint [gdb_get_line_number "BREAK"]
+gdb_continue_to_breakpoint "BREAK"
+
+# Sanity checking:
+gdb_test "print &foo_array\[1\].a" "= \\(int \\*\\) $hex.*"
+
+# A bug in EVAL_AVOID_SIDE_EFFECTS mode used to yield the following error:
+#    Attempt to take address of value not located in memory.
+gdb_test "print 1 && &foo_array\[1\].a" "= 1"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]