From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id uqYrJBFikV/8OgAAWB0awg (envelope-from ) for ; Thu, 22 Oct 2020 06:42:25 -0400 Received: by simark.ca (Postfix, from userid 112) id 867C21E89B; Thu, 22 Oct 2020 06:42:25 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id F25A81E552 for ; Thu, 22 Oct 2020 06:42:23 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 901743982EC1; Thu, 22 Oct 2020 10:42:23 +0000 (GMT) Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by sourceware.org (Postfix) with ESMTPS id 87BDC3971C09 for ; Thu, 22 Oct 2020 10:42:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 87BDC3971C09 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wm1-x342.google.com with SMTP id d78so1455490wmd.3 for ; Thu, 22 Oct 2020 03:42:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=e6Ky44upw+X6b6Ws3jzQhR5+4knt/aS4LMc+twkN3Lw=; b=UmZNBVAmx3DaOCZbOtvxrgNFbFUNX3DY7Om9w5PkGbKkFN/Dw8VMmoJnos1GtS6wSY VCw6iuneQybjB5kHwstMjfGzw8tCJQ+uHAKe5IT9thAD/9yNfzuFRcUA+aXB20pprlrr X4TU5dNX8GoBpYeXo2PY3pfT522chOGb0aKpbnNWpESxFvZXZ1oW0HMk5e6ai0e5Bqow Jom7ZckSKX0gj9YBoZxmVAMhFcpWfEgmmiKW3uvw7mOBXTAvAYt5WUvAlwBT2JdZtHQ/ ql7WrWMPUG0uyBX9QVMn7XUSbeHIge3ArkOi63x9gsgQuLI+Yt917VLjLjDSn7kGx9O2 6erA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=e6Ky44upw+X6b6Ws3jzQhR5+4knt/aS4LMc+twkN3Lw=; b=ZoIQcx+lvsxUQbW88L548uaQM70+xJjA+fynJr3uYhDsOExd1X12zIL50RWFmoixMW E/T/3AHJGTRpWZOHkd1Ap3o4mXbCVn9s/uj/g9Tpy2VVfqq3X6R8i+8DRE6KfrvBLWp/ EU3K+cccgNfOs1C+vZ2Dqca/Rh2YfYvK63ZxjzPu5y3KTj6++sZClfkvzxaTGcE1q19e 0ZggrRN+aA45jiRpSIqwQQMqhoObkmyRlFEaBKE3vLxwIdDQ/81wbmW4TjO0IxcjZXcq jS+VIFnZ+ZC1+qMFxeoWasdQTjdghTKrWTpkIj2DcwQXtb6Aorgtzo2N4Kfkc8GfiuAm BRgQ== X-Gm-Message-State: AOAM531kjNA2idecF6RvfF+lzlLgWq4OTG81Qb3IADF7j+0cEsFjy0au 1I3yDFfFm0uLIz9l+HeJ+esn+gyPoNdqOw== X-Google-Smtp-Source: ABdhPJwQAuQc+wPxowkj3/n+FuSE6iimTAWSqtn5FxH2Ay1s3NKgkRD299sm1WLT/n7qDIzn2s6GZg== X-Received: by 2002:a1c:9dcc:: with SMTP id g195mr1828067wme.113.1603363338930; Thu, 22 Oct 2020 03:42:18 -0700 (PDT) Received: from localhost (host86-166-129-235.range86-166.btcentralplus.com. [86.166.129.235]) by smtp.gmail.com with ESMTPSA id v9sm2896535wmh.23.2020.10.22.03.42.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 03:42:18 -0700 (PDT) Date: Thu, 22 Oct 2020 11:42:16 +0100 From: Andrew Burgess To: gdb-patches@sourceware.org Subject: Re: [PATCHv5 3/4] gdb/fortran: add support for parsing array strides in expressions Message-ID: <20201022104216.GC28735@embecosm.com> References: <02f3e9f571844809528e74c2a8621b4ec467e22f.1602439661.git.andrew.burgess@embecosm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <02f3e9f571844809528e74c2a8621b4ec467e22f.1602439661.git.andrew.burgess@embecosm.com> X-Operating-System: Linux/5.8.13-100.fc31.x86_64 (x86_64) X-Uptime: 11:41:27 up 7 days, 2:46, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" I've pushed patches 1, 2, and 3 from this series (after addressing the issues Simon pointed out in #3). I'll review the feedback on patch #4 and repost this soon. Thanks, Andrew * Andrew Burgess [2020-10-11 19:12:12 +0100]: > With this commit GDB now understands the syntax of Fortran array > strides, a user can type an expression including an array stride, but > they will only get an error informing them that array strides are not > supported. > > This alone is an improvement on what we had before in GDB, better to > give the user a helpful message that a particular feature is not > supported than to just claim a syntax error. > > Before: > > (gdb) p array (1:10:2, 2:10:2) > A syntax error in expression, near `:2, 2:10:2)'. > > Now: > > (gdb) p array (1:10:2, 2:10:2) > Fortran array strides are not currently supported > > Later commits will allow GDB to handle array strides correctly. > > gdb/ChangeLog: > > * expprint.c (dump_subexp_body_standard): Print RANGE_HAS_STRIDE. > * expression.h (enum range_type): Add RANGE_HAS_STRIDE. > * f-exp.y (arglist): Allow for a series of subranges. > (subrange): Add cases for subranges with strides. > * f-lang.c (value_f90_subarray): Catch use of array strides and > throw an error. > * parse.c (operator_length_standard): Handle RANGE_HAS_STRIDE. > > gdb/testsuite/ChangeLog: > > * gdb.fortran/array-slices.exp: Add a new test. > --- > gdb/ChangeLog | 10 ++++++ > gdb/expprint.c | 4 +++ > gdb/expression.h | 3 ++ > gdb/f-exp.y | 38 ++++++++++++++++++++++ > gdb/f-lang.c | 10 +++++- > gdb/parse.c | 2 ++ > gdb/testsuite/ChangeLog | 4 +++ > gdb/testsuite/gdb.fortran/array-slices.exp | 15 +++++++++ > 8 files changed, 85 insertions(+), 1 deletion(-) > > diff --git a/gdb/expprint.c b/gdb/expprint.c > index 2dee2bb1932..a14eeb00f19 100644 > --- a/gdb/expprint.c > +++ b/gdb/expprint.c > @@ -1120,12 +1120,16 @@ dump_subexp_body_standard (struct expression *exp, > fputs_filtered ("..", stream); > if (!(range_flag & RANGE_HIGH_BOUND_DEFAULT)) > fputs_filtered ("EXP", stream); > + if (range_flag & RANGE_HAS_STRIDE) > + fputs_filtered (":EXP", stream); > fputs_filtered ("'", stream); > > if (!(range_flag & RANGE_LOW_BOUND_DEFAULT)) > elt = dump_subexp (exp, stream, elt); > if (!(range_flag & RANGE_HIGH_BOUND_DEFAULT)) > elt = dump_subexp (exp, stream, elt); > + if (range_flag & RANGE_HAS_STRIDE) > + elt = dump_subexp (exp, stream, elt); > } > break; > > diff --git a/gdb/expression.h b/gdb/expression.h > index fd483e5f277..8de712310ec 100644 > --- a/gdb/expression.h > +++ b/gdb/expression.h > @@ -199,6 +199,9 @@ enum range_flag : unsigned > > /* The high bound of this range is exclusive. */ > RANGE_HIGH_BOUND_EXCLUSIVE = 1 << 2, > + > + /* The range has a stride. */ > + RANGE_HAS_STRIDE = 1 << 3, > }; > > DEF_ENUM_FLAGS_TYPE (enum range_flag, range_flags); > diff --git a/gdb/f-exp.y b/gdb/f-exp.y > index a3314082d90..f227690cea6 100644 > --- a/gdb/f-exp.y > +++ b/gdb/f-exp.y > @@ -284,6 +284,10 @@ arglist : arglist ',' exp %prec ABOVE_COMMA > { pstate->arglist_len++; } > ; > > +arglist : arglist ',' subrange %prec ABOVE_COMMA > + { pstate->arglist_len++; } > + ; > + > /* There are four sorts of subrange types in F90. */ > > subrange: exp ':' exp %prec ABOVE_COMMA > @@ -314,6 +318,40 @@ subrange: ':' %prec ABOVE_COMMA > write_exp_elt_opcode (pstate, OP_RANGE); } > ; > > +/* And each of the four subrange types can also have a stride. */ > +subrange: exp ':' exp ':' exp %prec ABOVE_COMMA > + { write_exp_elt_opcode (pstate, OP_RANGE); > + write_exp_elt_longcst (pstate, > + (RANGE_STANDARD > + | RANGE_HAS_STRIDE)); > + write_exp_elt_opcode (pstate, OP_RANGE); } > + ; > + > +subrange: exp ':' ':' exp %prec ABOVE_COMMA > + { write_exp_elt_opcode (pstate, OP_RANGE); > + write_exp_elt_longcst (pstate, > + (RANGE_HIGH_BOUND_DEFAULT > + | RANGE_HAS_STRIDE)); > + write_exp_elt_opcode (pstate, OP_RANGE); } > + ; > + > +subrange: ':' exp ':' exp %prec ABOVE_COMMA > + { write_exp_elt_opcode (pstate, OP_RANGE); > + write_exp_elt_longcst (pstate, > + (RANGE_LOW_BOUND_DEFAULT > + | RANGE_HAS_STRIDE)); > + write_exp_elt_opcode (pstate, OP_RANGE); } > + ; > + > +subrange: ':' ':' exp %prec ABOVE_COMMA > + { write_exp_elt_opcode (pstate, OP_RANGE); > + write_exp_elt_longcst (pstate, > + (RANGE_LOW_BOUND_DEFAULT > + | RANGE_HIGH_BOUND_DEFAULT > + | RANGE_HAS_STRIDE)); > + write_exp_elt_opcode (pstate, OP_RANGE); } > + ; > + > complexnum: exp ',' exp > { } > ; > diff --git a/gdb/f-lang.c b/gdb/f-lang.c > index 37d05b27653..b888e3d4122 100644 > --- a/gdb/f-lang.c > +++ b/gdb/f-lang.c > @@ -124,7 +124,7 @@ value_f90_subarray (struct value *array, > struct expression *exp, int *pos, enum noside noside) > { > int pc = (*pos) + 1; > - LONGEST low_bound, high_bound; > + LONGEST low_bound, high_bound, stride; > struct type *range = check_typedef (value_type (array)->index_type ()); > enum range_flag range_flag > = (enum range_flag) longest_to_int (exp->elts[pc].longconst); > @@ -141,6 +141,14 @@ value_f90_subarray (struct value *array, > else > high_bound = value_as_long (evaluate_subexp (nullptr, exp, pos, noside)); > > + if ((range_flag & RANGE_HAS_STRIDE) == RANGE_HAS_STRIDE) > + stride = value_as_long (evaluate_subexp (nullptr, exp, pos, noside)); > + else > + stride = 1; > + > + if (stride != 1) > + error (_("Fortran array strides are not currently supported")); > + > return value_slice (array, low_bound, high_bound - low_bound + 1); > } > > diff --git a/gdb/parse.c b/gdb/parse.c > index 4a15de8a499..359ab6211aa 100644 > --- a/gdb/parse.c > +++ b/gdb/parse.c > @@ -924,6 +924,8 @@ operator_length_standard (const struct expression *expr, int endpos, > /* Assume the range has 2 arguments (low bound and high bound), then > reduce the argument count if any bounds are set to default. */ > args = 2; > + if (range_flag & RANGE_HAS_STRIDE) > + ++args; > if (range_flag & RANGE_LOW_BOUND_DEFAULT) > --args; > if (range_flag & RANGE_HIGH_BOUND_DEFAULT) > diff --git a/gdb/testsuite/gdb.fortran/array-slices.exp b/gdb/testsuite/gdb.fortran/array-slices.exp > index 31f95a3668d..a0e1d1fe8fc 100644 > --- a/gdb/testsuite/gdb.fortran/array-slices.exp > +++ b/gdb/testsuite/gdb.fortran/array-slices.exp > @@ -69,3 +69,18 @@ foreach result $array_contents msg $message_strings { > } > > gdb_continue_to_breakpoint "continue to Final Breakpoint" > + > +# Next test that asking for an array with stride at the CLI gives an > +# error. > +clean_restart ${testfile} > + > +if ![fortran_runto_main] then { > + perror "couldn't run to main" > + continue > +} > + > +gdb_breakpoint "show" > +gdb_continue_to_breakpoint "show" > +gdb_test "up" ".*" > +gdb_test "p array (1:10:2, 1:10:2)" \ > + "Fortran array strides are not currently supported" > -- > 2.25.4 >