From patchwork Fri May 12 15:00:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 20428 Received: (qmail 75149 invoked by alias); 12 May 2017 15:03:08 -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 75109 invoked by uid 89); 12 May 2017 15:03:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=treatment, H*MI:sk:2017051 X-HELO: outbound-ss-1812.hostmonster.com Received: from gproxy1-pub.mail.unifiedlayer.com (HELO outbound-ss-1812.hostmonster.com) (69.89.25.95) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 12 May 2017 15:03:05 +0000 Received: from cmgw3 (cmgw4 [10.0.90.84]) by gproxy1.mail.unifiedlayer.com (Postfix) with ESMTP id 5BAC5175D5E for ; Fri, 12 May 2017 09:01:04 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id KT101v00N2f2jeq01T13Nr; Fri, 12 May 2017 09:01:04 -0600 X-Authority-Analysis: v=2.2 cv=VKStp5HX c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=3GLR1-XzZKwA:10 a=tJ8p9aeEuA8A:10 a=zstS-IiYAAAA:8 a=Nx-fyZQlMOm_SJYrETkA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-63-71.hlrn.qwest.net ([75.166.63.71]:52762 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1d9C3w-0003el-Jk; Fri, 12 May 2017 09:01:00 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [FYI 3/3] Avoid exponential behavior in rust_evaluate_subexp Date: Fri, 12 May 2017 09:00:55 -0600 Message-Id: <20170512150055.27230-4-tom@tromey.com> In-Reply-To: <20170512150055.27230-1-tom@tromey.com> References: <20170512150055.27230-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1d9C3w-0003el-Jk X-Source-Sender: 75-166-63-71.hlrn.qwest.net (bapiya.Home) [75.166.63.71]:52762 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== The STRUCTOP_STRUCT case in rust_evaluate_subexp would evaluate its LHS, and then, if it did not need Rust-specific treatment, it would back up and re-evaluate the entire STRUCTOP_STRUCT part of the expression using evaluate_subexp_standard. This yields exponential behavior and causes some expressions to evaluate extremely slowly. The fix is to simply do the needed work inline. This is PR rust/21483. ChangeLog 2017-05-12 Tom Tromey PR rust/21483: * rust-lang.c (rust_evaluate_subexp) : Don't recurse, just call value_struct_elt directly. --- gdb/ChangeLog | 6 ++++++ gdb/rust-lang.c | 15 +++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c2d3f2d..71aea52 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2017-05-12 Tom Tromey + PR rust/21483: + * rust-lang.c (rust_evaluate_subexp) : Don't + recurse, just call value_struct_elt directly. + +2017-05-12 Tom Tromey + * rust-lang.c (rust_dump_subexp_body) : Fix. diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index b4a529d..898edda 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -1762,7 +1762,7 @@ tuple structs, and tuple-like enum variants")); case STRUCTOP_STRUCT: { - struct value* lhs; + struct value *lhs; struct type *type; int tem, pc; @@ -1771,16 +1771,14 @@ tuple structs, and tuple-like enum variants")); (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); lhs = evaluate_subexp (NULL_TYPE, exp, pos, noside); + const char *field_name = &exp->elts[pc + 2].string; type = value_type (lhs); if (TYPE_CODE (type) == TYPE_CODE_UNION && !rust_union_is_untagged (type)) { int i, start; struct disr_info disr; - struct type* variant_type; - char* field_name; - - field_name = &exp->elts[pc + 2].string; + struct type *variant_type; disr = rust_get_disr_info (type, value_contents (lhs), value_embedded_offset (lhs), @@ -1817,9 +1815,10 @@ which has only anonymous fields"), } else { - /* Field access in structs and untagged unions works like C. */ - *pos = pc; - result = evaluate_subexp_standard (expect_type, exp, pos, noside); + result = value_struct_elt (&lhs, NULL, field_name, NULL, + "structure"); + if (noside == EVAL_AVOID_SIDE_EFFECTS) + result = value_zero (value_type (result), VALUE_LVAL (result)); } } break;