From patchwork Wed May 25 08:11:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 12507 Received: (qmail 96884 invoked by alias); 25 May 2016 08:11:33 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 96766 invoked by uid 89); 25 May 2016 08:11:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=*******, 3086, 20160504, 1737 X-HELO: mail-wm0-f45.google.com Received: from mail-wm0-f45.google.com (HELO mail-wm0-f45.google.com) (74.125.82.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 25 May 2016 08:11:22 +0000 Received: by mail-wm0-f45.google.com with SMTP id n129so167837061wmn.1 for ; Wed, 25 May 2016 01:11:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=AqDZH584cg+4cCpZxiYiuWIDpd9Jqb98sPRy4o8Z8Mk=; b=hhAm7pKBM6r3MVAvbbY+IVNU0eXISMAv4YoD6J/0nQiT7Rb6XWKvJaBhUTRSeYx/52 4+8pIBAHrdZXfz2sQkE61/RTchDBivMko2ifBOnpK5XgctwKX/tYgxTOyJ4CkoW+n1+1 Izfr+BltyZ/aMLSewx6vWdD8ZCrtHchpxwEqXADC8cFLUqpKKdtIJ+cgVsLbRTqpM1fa teXu+ihZSpovM09oeIii9AN5d5GY7Rc1Qx9B6lR3K1OMGFPNYYBuSwdzZw7tWKo0B1z+ H8bNvlzEIXI7nJgtvjd5i0Krwk5h1MuzovsfDwFN9l4TSdy0fyBYYHWaOM1xj4q6xFxp K1kg== X-Gm-Message-State: ALyK8tJaTsmBJoCVqTwH1ghxaWTIpvuAtppT9g+jBs3niX/kAaUdcGdlS60v1Yyt+Dajjg== X-Received: by 10.28.137.14 with SMTP id l14mr1894056wmd.64.1464163879737; Wed, 25 May 2016 01:11:19 -0700 (PDT) Received: from localhost (host86-165-25-95.range86-165.btcentralplus.com. [86.165.25.95]) by smtp.gmail.com with ESMTPSA id f135sm7820724wmf.22.2016.05.25.01.11.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 May 2016 01:11:19 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/2] gdb: Forward VALUE_LVAL when avoiding side effects for STRUCTOP_PTR Date: Wed, 25 May 2016 09:11:00 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes 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 but applied to STRUCTOP_PTR rather than STRUCTOP_STRUCT. Both of these commits are building on top of commit ac1ca910d74d. 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. --- gdb/ChangeLog | 6 +++ gdb/eval.c | 2 +- gdb/testsuite/ChangeLog | 5 +++ gdb/testsuite/gdb.base/whatis.c | 8 ++-- gdb/testsuite/gdb.base/whatis.exp | 83 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 99 insertions(+), 5 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 46f5b42..7644c08 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2016-05-24 Andrew Burgess + + * 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. + 2016-05-24 Yan-Ting Lin * MAINTAINERS (Write After Approval): Add "Yan-Ting Lin". diff --git a/gdb/eval.c b/gdb/eval.c index 3f8ca66..de1c663 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -1917,7 +1917,7 @@ evaluate_subexp_standard (struct type *expect_type, arg3 = value_struct_elt (&arg1, NULL, &exp->elts[pc + 2].string, NULL, "structure pointer"); 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_MEMBER: diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 1f0e3f9..7825241 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-05-04 Andrew Burgess + + * gdb.base/whatis.c: Extend the test case. + * gdb.base/whatis.exp: Add additional tests. + 2016-05-23 Tom Tromey PR python/19438, PR python/18393: diff --git a/gdb/testsuite/gdb.base/whatis.c b/gdb/testsuite/gdb.base/whatis.c index d60afa2..e5cfa51 100644 --- a/gdb/testsuite/gdb.base/whatis.c +++ b/gdb/testsuite/gdb.base/whatis.c @@ -135,7 +135,7 @@ struct t_struct { #endif float v_float_member; double v_double_member; -} v_struct1; +} v_struct1, *v_struct_ptr1; struct { char v_char_member; @@ -147,7 +147,7 @@ struct { #endif float v_float_member; double v_double_member; -} v_struct2; +} v_struct2, *v_struct_ptr2; /**** unions *******/ @@ -161,7 +161,7 @@ union t_union { #endif float v_float_member; double v_double_member; -} v_union; +} v_union, *v_union_ptr; union { char v_char_member; @@ -173,7 +173,7 @@ union { #endif float v_float_member; double v_double_member; -} v_union2; +} v_union2, *v_union_ptr2; /*** Functions returning type ********/ diff --git a/gdb/testsuite/gdb.base/whatis.exp b/gdb/testsuite/gdb.base/whatis.exp index 93a4d44..0cdcf5b 100644 --- a/gdb/testsuite/gdb.base/whatis.exp +++ b/gdb/testsuite/gdb.base/whatis.exp @@ -294,6 +294,47 @@ gdb_test "whatis v_struct2" \ "type = struct \{\.\.\.\}" \ "whatis unnamed structure" +gdb_test "whatis &v_struct1" \ + "type = struct t_struct \\*" + +gdb_test "whatis &v_struct2" \ + "type = struct {\\.\\.\\.} \\*" + +gdb_test "whatis v_struct_ptr1" \ + "type = struct t_struct \\*" + +gdb_test "whatis v_struct_ptr2" \ + "type = struct {\\.\\.\\.} \\*" + +gdb_test "whatis &v_struct_ptr1" \ + "type = struct t_struct \\*\\*" + +gdb_test "whatis &v_struct_ptr2" \ + "type = struct {\\.\\.\\.} \\*\\*" + +gdb_test "whatis v_struct1.v_char_member" \ + "type = char" + +gdb_test "whatis v_struct2.v_char_member" \ + "type = char" + +gdb_test "whatis v_struct_ptr1->v_char_member" \ + "type = char" + +gdb_test "whatis v_struct_ptr2->v_char_member" \ + "type = char" + +gdb_test "whatis &(v_struct1.v_char_member)" \ + "type = char \\*" + +gdb_test "whatis &(v_struct2.v_char_member)" \ + "type = char \\*" + +gdb_test "whatis &(v_struct_ptr1->v_char_member)" \ + "type = char \\*" + +gdb_test "whatis &(v_struct_ptr2->v_char_member)" \ + "type = char \\*" # test whatis command with union types gdb_test "whatis v_union" \ @@ -308,6 +349,48 @@ gdb_test "whatis v_union2" \ "type = union \{\.\.\.\}" \ "whatis unnamed union" +gdb_test "whatis &v_union" \ + "type = union t_union \\*" + +gdb_test "whatis &v_union2" \ + "type = union {\\.\\.\\.} \\*" + +gdb_test "whatis v_union_ptr" \ + "type = union t_union \\*" + +gdb_test "whatis v_union_ptr2" \ + "type = union {\\.\\.\\.} \\*" + +gdb_test "whatis &v_union_ptr" \ + "type = union t_union \\*\\*" + +gdb_test "whatis &v_union_ptr2" \ + "type = union {\\.\\.\\.} \\*\\*" + +gdb_test "whatis v_union.v_char_member" \ + "type = char" + +gdb_test "whatis v_union2.v_char_member" \ + "type = char" + +gdb_test "whatis v_union_ptr->v_char_member" \ + "type = char" + +gdb_test "whatis v_union_ptr2->v_char_member" \ + "type = char" + +gdb_test "whatis &(v_union.v_char_member)" \ + "type = char \\*" + +gdb_test "whatis &(v_union2.v_char_member)" \ + "type = char \\*" + +gdb_test "whatis &(v_union_ptr->v_char_member)" \ + "type = char \\*" + +gdb_test "whatis &(v_union_ptr2->v_char_member)" \ + "type = char \\*" + # Using stabs we will mark these functions as prototyped. This # is harmless but causes an extra VOID to be printed.