From patchwork Sat Dec 15 23:24:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 30682 Received: (qmail 59364 invoked by alias); 15 Dec 2018 23:25:01 -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 59118 invoked by uid 89); 15 Dec 2018 23:24:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=raw, token, choices, *type X-HELO: mail-wm1-f66.google.com Received: from mail-wm1-f66.google.com (HELO mail-wm1-f66.google.com) (209.85.128.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 15 Dec 2018 23:24:41 +0000 Received: by mail-wm1-f66.google.com with SMTP id s14so8956702wmh.1 for ; Sat, 15 Dec 2018 15:24:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id; bh=FPkqGtfOM8Svp4vRrRqNxUGfTFhlrMnxp2d5nCJ2Vsw=; b=DKu+MvoNVAS6TlbyoGdgCCqnH3fh3H9NJEDFRoTrxIhelDW6gcx6/Q9K9/hFvuWLWJ fkrBVyJt9QKBLqgZcE7X9gJRkO+91k3DumUc35atQ//v/XHlqDXWTbIHm8c6abXT5sG8 nayzaOdxqxrL1+WZF0xy8Iqs8odWsJsoHRKO1LtkzCnOJMZ4+P2jYv7Ilz6v6VHf0bAP pGoCjqN5wsQi9S+xh6v4oSm26TbQjDbNoWtLcjb1NXqo9YHbsgouuMsgnJphBjFDJhIW 2kGq3UnM+ROkGpeDqEJmaIF6+F3xFQER1x/cBLUz6wURGpyF9HOrQWfR1IsrbE3DGoO2 fmcQ== Return-Path: Received: from localhost (host86-156-236-210.range86-156.btcentralplus.com. [86.156.236.210]) by smtp.gmail.com with ESMTPSA id s8sm7957772wrn.44.2018.12.15.15.24.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 15 Dec 2018 15:24:25 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: jimw@sifive.com, palmer@sifive.com, jhb@FreeBSD.org, Andrew Burgess Subject: [PATCH] gdb: Allow struct fields named double Date: Sat, 15 Dec 2018 23:24:14 +0000 Message-Id: <20181215232414.10883-1-andrew.burgess@embecosm.com> X-IsSubscribed: yes The patch below fixes an issue with the current was floating point is handled on RISC-V. We currently model 64-bit floating point as a union with fields 'double' and 'float'. The problem is that having a field named 'double' isn't currently valid in GDB (though float is fine). The easiest solution might be to change the field names... but the patch below instead extends the C parser to allow double as a field name. I'd be interested in hearing feedback on the below, Thanks, Andrew --- The 64-bit RISC-V target currently models the floating point registers as having the following type: union riscv_double { builtin_type_ieee_single float; builtin_type_ieee_double double; } Notice the choice of names for the fields of this struct, possibly not ideal choices, as these are not valid field names in C. However, this type is only ever defined within GDB (or in the target description), and no restriction seems to exist on the field names in that case. The problem though is that currently: (gdb) info registers $ft0 ft0 {float = 0, double = 0} (raw 0x0000000000000000) (gdb) p $ft0.float $1 = 0 (gdb) p $ft0.double A syntax error in expression, near `double'. We can access the 'float' field, but not the 'double' field. This is because the string 'double' is handled differently to the string 'float' in c-exp.y. In both cases the string '$ft0' is parsed as a VARIABLE expression. In the 'float' case, the string 'float' becomes a generic NAME token in 'lex_one_token', which then allows the rule "exp '.' name" to match and the field name lookup to occur. The 'double' case is different. In order to allow parsing of the type string 'long double', the 'double' string becomes the token DOUBLE_KEYWORD. At this point there's no rule to match "exp '.' DOUBLE_KEYWORD", so we can never lookup the field named 'double'. We could rename the fields for RISC-V, and maybe that would be the best solution. However, its not hard to allow for fields named 'double', which is what this patch does. A new case is added to the 'name' rule to match the DOUBLE_KEYWORD, and create a suitable 'struct stoken'. With this done the "exp '.' name" pattern can now match, and we can lookup the double field. With this patch in place I now see this behaviour: (gdb) info registers $ft0 ft0 {float = 0, double = 0} (raw 0x0000000000000000) (gdb) p $ft0.float $1 = 0 (gdb) p $ft0.double $2 = 0 This change was tested on x86-64 GNU/Linux with no regressions. gdb/ChangeLog: * c-exp.y (name): Allow DOUBLE_KEYWORD to act as a name. (typename_stoken): New function. --- gdb/ChangeLog | 5 +++++ gdb/c-exp.y | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/gdb/c-exp.y b/gdb/c-exp.y index bfc78415b22..8d805cbde3d 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -113,6 +113,7 @@ static int type_aggregate_p (struct type *); static int parse_number (struct parser_state *par_state, const char *, int, int, YYSTYPE *); static struct stoken operator_stoken (const char *); +static struct stoken typename_stoken (const char *); static void check_parameter_typelist (VEC (type_ptr) *); static void write_destructor_name (struct parser_state *par_state, struct stoken); @@ -1642,6 +1643,7 @@ name : NAME { $$ = $1.stoken; } | TYPENAME { $$ = $1.stoken; } | NAME_OR_INT { $$ = $1.stoken; } | UNKNOWN_CPP_NAME { $$ = $1.stoken; } + | DOUBLE_KEYWORD { $$ = typename_stoken ("double"); } | oper { $$ = $1; } ; @@ -1707,6 +1709,21 @@ operator_stoken (const char *op) return st; }; +/* Returns a stoken of the type named TYPE. */ + +static struct stoken +typename_stoken (const char *type) +{ + struct stoken st = { NULL, 0 }; + char *buf = xstrdup (type); + st.ptr = buf; + st.length = strlen (type); + + /* The toplevel (c_parse) will free the memory allocated here. */ + make_cleanup (free, buf); + return st; +}; + /* Return true if the type is aggregate-like. */ static int