From patchwork Tue Jan 2 14:43:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 83146 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2982C3858437 for ; Tue, 2 Jan 2024 14:43:54 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 398BE3858CDB for ; Tue, 2 Jan 2024 14:43:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 398BE3858CDB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 398BE3858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704206604; cv=none; b=JMJZExtG2bD4flbvIvJCc8AMmRvJJr9+V/0AYGUKpOzNLCh5+OUeMXDTftvRDwf1Ynd9z5DaSfEV7fSZcJNx5szx2j18NZRvGj3nby9rlFz0sHVjCQaGn8aqxmVaaLfVtc22A8ZzEbxpefHa64XPorSb4wU3wtlc8OjYL/Uo+IM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704206604; c=relaxed/simple; bh=/nyiyt9D7D3VNR5FNaM+fIgC5WFn2AGXrkbBAvf9fnY=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=tG2+upDDk/XArCsH+fpWecX50kgjSMw6Ud2oYT6nhZAXY09W4Bh52IY9hNmx85QVvjGpNDubLFoszl0Bk0VX4lOiN8/QF6CLKQey3dK5OU2d8iOzkuk5FvWpW2FGT2TD8DS4Px0GPRwpaedK7UC5Z9YkMccqZNpnTfHPx1dKj9Q= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704206602; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9sBhik9sNaxnZqajcJHZu8yvFMlY+zbO4haFq2HA0So=; b=GZzNQo3oBcGk40ezpXNyfmD6gy3a0lWB9FoHGkq4mER47BA0LG96171sLxQ2Qj1U2FyEGN vgG1/P1Df3EmqQqBHhMyB5+E5DBmqMszNiwEt3KybU+xZPWx9EvvGVQcHw67FFYMKE8HkG PGYxw6nu/pSSPrGKruCs6cKL5d+XffA= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-455-eNoW20IaMmWX5s-Zga5jOw-1; Tue, 02 Jan 2024 09:43:21 -0500 X-MC-Unique: eNoW20IaMmWX5s-Zga5jOw-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-40d8586c709so22790025e9.1 for ; Tue, 02 Jan 2024 06:43:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704206600; x=1704811400; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9sBhik9sNaxnZqajcJHZu8yvFMlY+zbO4haFq2HA0So=; b=EPwrNNiRZOFiYQtzqO0crNE7+U1Sf5aSu9MIXervA6TgHcadOQBYYawIsNV6iS2yPt S7guIJvBnnjEeIyl3yrFU3xI3AUhKX//qaW2egDJhdDzwF4oFdKCLpWU+FD7s5rFzgC6 ZVu9ynII4gRW56QrdHlJYJjIwoKHeH5+BLACHxCkrzMM5T4Spj5WpCtaljuernkVAD7o dNzFqCaAtCuCY85WvdpzD4PsqAMp7OrAImag1yzWxblPUQeEubCQ0Io3nNQt5ZwiCLHM UGZ2jiZFc4w4nRx2ya2/b5yi+Cz3X5p2Sm6nAxCbTxCjrTEQDtk17g7B6NBhh1v+HCh7 lk7w== X-Gm-Message-State: AOJu0YyfR5UyP+grF6X5zMGjBWk/ZAqe06Gq82/KyH/ZaUS+zhvwsSrG ebzRfGqxyyxJ9QfvSdsuLpm9r+0Xxrx9SB7e0dp4ku5sRs4WM5Z639/0FjOGfLO3eZpmt/9xnEi ev9Of/6UNTHx7wZNksZAL5viv6/odTNALCWWd6hni17LDtrCkEe0ASFdd8vDqLEEQXIXKt+8FDF zIX2MwBA5gxyVkqQ== X-Received: by 2002:a05:600c:198a:b0:40d:5358:8d77 with SMTP id t10-20020a05600c198a00b0040d53588d77mr6745635wmq.80.1704206600132; Tue, 02 Jan 2024 06:43:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFW4rrUoQrFcFu8xmbjeDTCpjx+mrvmcnQJirUIGTaidcuBwGziWuDg1IOrMaxqSGu5Z80f7g== X-Received: by 2002:a05:600c:198a:b0:40d:5358:8d77 with SMTP id t10-20020a05600c198a00b0040d53588d77mr6745629wmq.80.1704206599721; Tue, 02 Jan 2024 06:43:19 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id fc16-20020a05600c525000b0040d4dc06f91sm37619350wmb.43.2024.01.02.06.43.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 06:43:19 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 1/3] gdb: don't try to style content in error calls Date: Tue, 2 Jan 2024 14:43:11 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org While working on a later commit in this series I realised that the error() function doesn't support output styling. Due to the way that output from error() calls is passed around within the exception object and often combined with other output, it's not immediately obvious to me if we should be trying to support styling in this context or not. On inspection, I found two places in GDB where we apparently try to apply styling within the error() output, however, both of these places are in infrequently used (and likely untested) code. So, rather than try to implement styling in the error() output, right now I'm proposing to just remove these two attempts to style error() output. This doesn't mean that someone shouldn't add error() styling in the future, but right now, I'm not planning to do that, so I just wanted to fix these two mistakes as I saw them. --- gdb/procfs.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/gdb/procfs.c b/gdb/procfs.c index 1410bbc0d7d..0eafc2eddcc 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -605,10 +605,8 @@ static void proc_error (procinfo *pi, const char *func, int line) { int saved_errno = errno; - error ("procfs: %s line %d, %ps: %s", - func, line, styled_string (file_name_style.style (), - pi->pathname), - safe_strerror (saved_errno)); + error ("procfs: %s line %d, %s: %s", + func, line, pi->pathname, safe_strerror (saved_errno)); } /* Updates the status struct in the procinfo. There is a 'valid' From patchwork Tue Jan 2 14:43:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 83147 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 995D53858281 for ; Tue, 2 Jan 2024 14:44:20 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 7212E3858C2C for ; Tue, 2 Jan 2024 14:43:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7212E3858C2C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7212E3858C2C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704206612; cv=none; b=MHEpZU2Oq6m5ShbxVG8J5tgwaqpXQlcEdBLxJz2StSZdTBUuRTEJSpwud4gpgLQKjNeniSOaRVxFLxa0ARtpAttGxM3GCErKn7WThmBgKzcV402K0VAMVEu3zd0YDACzfYg0H3NUCy5VyChapTT09tgB5RCysLJnlb1GeZ0GHfQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704206612; c=relaxed/simple; bh=zu1COLfIyqHoc8ZowpE32S5ZrxJYjp4F51pqmyh4ybw=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Bq5pw7C2YweX089NUhzSzN3a+nTijFssvgpRpmazbWGoYMU0wjiSU+yRyZkBFYVruf+WfV1FHaUDEzbLf3w8WCOT2KsoaoHYElD1inbaOt0RP8wVZ/D8IxBM+IhS2weqs+E+WAa+HnKrc9c7LzFglt+17BUlc6tSCcBjbl+Zt7s= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704206609; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LOjZaQPn0ySzom4HBtEHVIY0W1hJuQWSRt78s1u9JVg=; b=Od2l0UZ4xQXYEBE0PkCc6PBkDt0fNnNtIKLiwZvdNWwIxqjNyz36Pdf8r5GRtuQ4AqpyOq TUwCCOKRWSrByPoogylpuZ1hefTUeavcfn/1ujBAycFxDPVsU7rL7sa0GGo+p6hgm7gotA KaWCnr08igj6vyXGD9rUxGu1SaEPMPs= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-217-JdQXooG0PBG33E1LwS9UKQ-1; Tue, 02 Jan 2024 09:43:23 -0500 X-MC-Unique: JdQXooG0PBG33E1LwS9UKQ-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-40d3b4606b3so86616235e9.2 for ; Tue, 02 Jan 2024 06:43:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704206601; x=1704811401; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KlFyQiiqU7ZKcfuCelqJCh+DGwgBZC2WN5R36VeJL4k=; b=QIx6X27PE5N570VgzR+eDxHl0m13XBWo1Es8nAJ42g8/lKiFIWRW5qIlcAS0KNpWSB Vf1muHB9eWQOb01LiXB6RwsG0cuGmkiROPbt5tep7wqaSvpB8+L1EYBcydNwrrh4ZO+b uVQhZiPETORG8cmKtm2vpnoMG1yEhXeu6jv7942sFEPVKAWj2PXUZuBydc56hfdH6b0V SB0h8/U19UigZpxDLVz5PjCCkKP3Oe9hhonqhKeXde0+yn30vb4yCqbkEKPgf7CoPt4N 7ggH478G4p/zIN9nTvgUZYxkZmRfm1gXBlOOptX8hEdadeiH9UfYwUAGpBQfYqaPksal j4IQ== X-Gm-Message-State: AOJu0YwvqsqNvm2M6tjOc17BwNvzzdloI7G6R8APd5yudbpS41YZebvI c3mirQv6BfDt9Ya3nscW5r50y6mL9aN9h6wopOgOEkRIwCRukbQKwUyNK2I/+yCJRHY741B+aOz 8uGmeWH66YvYKskkzKFvO6C1v2bFPshglvbuBaZOUWMem2zK8TYWFF09D+gnX8lATlQSBfOW5Qi K4vJj0TjEjo0AEDg== X-Received: by 2002:a05:600c:19cc:b0:40d:5f8a:5b13 with SMTP id u12-20020a05600c19cc00b0040d5f8a5b13mr4946486wmq.65.1704206601083; Tue, 02 Jan 2024 06:43:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IF95eTB7gewn1Y2jutjvEU7BsL9DEJaSziBhmWrX8aid4KhjRPs/xIh4TwQQa0lpdV+GGe8YA== X-Received: by 2002:a05:600c:19cc:b0:40d:5f8a:5b13 with SMTP id u12-20020a05600c19cc00b0040d5f8a5b13mr4946479wmq.65.1704206600815; Tue, 02 Jan 2024 06:43:20 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id r20-20020a05600c459400b0040c3dcc36e6sm44560675wmo.47.2024.01.02.06.43.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 06:43:20 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 2/3] gdb: merge error handling from different expression parsers Date: Tue, 2 Jan 2024 14:43:12 +0000 Message-Id: <06889e172a22e80af44b30b1e70f1f06ecb3ba96.1704206350.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Many (all?) of the expression parsers implement yyerror to handle parser errors, and all of these functions are basically identical. This commit adds a new parser_state::parse_error() function, which implements the common error handling code, this function can then be called from all the different yyerror functions. The benefit of this is that (in a future commit) I can improve the error output, and all the expression parsers will benefit. This commit is pure refactoring though, and so, there should be no user visible changes after this commit. --- gdb/ada-exp.y | 2 +- gdb/c-exp.y | 5 +---- gdb/d-exp.y | 5 +---- gdb/f-exp.y | 5 +---- gdb/go-exp.y | 5 +---- gdb/m2-exp.y | 5 +---- gdb/p-exp.y | 5 +---- gdb/parse.c | 11 +++++++++++ gdb/parser-defs.h | 5 +++++ 9 files changed, 23 insertions(+), 25 deletions(-) diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y index fcb5aa4379b..2a1cff50887 100644 --- a/gdb/ada-exp.y +++ b/gdb/ada-exp.y @@ -1212,7 +1212,7 @@ ada_parse (struct parser_state *par_state) static void yyerror (const char *msg) { - error (_("Error in expression, near `%s'."), pstate->lexptr); + pstate->parse_error (msg); } /* Emit expression to access an instance of SYM, in block BLOCK (if diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 2b4c21850d3..6697b3b2278 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -3482,8 +3482,5 @@ c_print_token (FILE *file, int type, YYSTYPE value) static void yyerror (const char *msg) { - if (pstate->prev_lexptr) - pstate->lexptr = pstate->prev_lexptr; - - error (_("A %s in expression, near `%s'."), msg, pstate->lexptr); + pstate->parse_error (msg); } diff --git a/gdb/d-exp.y b/gdb/d-exp.y index e2507982d50..627c681d895 100644 --- a/gdb/d-exp.y +++ b/gdb/d-exp.y @@ -1631,9 +1631,6 @@ d_parse (struct parser_state *par_state) static void yyerror (const char *msg) { - if (pstate->prev_lexptr) - pstate->lexptr = pstate->prev_lexptr; - - error (_("A %s in expression, near `%s'."), msg, pstate->lexptr); + pstate->parse_error (msg); } diff --git a/gdb/f-exp.y b/gdb/f-exp.y index e4e2171d641..88a95bccb11 100644 --- a/gdb/f-exp.y +++ b/gdb/f-exp.y @@ -1736,8 +1736,5 @@ f_language::parser (struct parser_state *par_state) const static void yyerror (const char *msg) { - if (pstate->prev_lexptr) - pstate->lexptr = pstate->prev_lexptr; - - error (_("A %s in expression, near `%s'."), msg, pstate->lexptr); + pstate->parse_error (msg); } diff --git a/gdb/go-exp.y b/gdb/go-exp.y index c9b9c0b1ab7..561a3bef1b0 100644 --- a/gdb/go-exp.y +++ b/gdb/go-exp.y @@ -1545,8 +1545,5 @@ go_language::parser (struct parser_state *par_state) const static void yyerror (const char *msg) { - if (pstate->prev_lexptr) - pstate->lexptr = pstate->prev_lexptr; - - error (_("A %s in expression, near `%s'."), msg, pstate->lexptr); + pstate->parse_error (msg); } diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y index 092a8be248d..9a8767f5ac7 100644 --- a/gdb/m2-exp.y +++ b/gdb/m2-exp.y @@ -1006,8 +1006,5 @@ m2_language::parser (struct parser_state *par_state) const static void yyerror (const char *msg) { - if (pstate->prev_lexptr) - pstate->lexptr = pstate->prev_lexptr; - - error (_("A %s in expression, near `%s'."), msg, pstate->lexptr); + pstate->parse_error (msg); } diff --git a/gdb/p-exp.y b/gdb/p-exp.y index b0f334897ad..9dfa8c5fd4f 100644 --- a/gdb/p-exp.y +++ b/gdb/p-exp.y @@ -1660,8 +1660,5 @@ pascal_language::parser (struct parser_state *par_state) const static void yyerror (const char *msg) { - if (pstate->prev_lexptr) - pstate->lexptr = pstate->prev_lexptr; - - error (_("A %s in expression, near `%s'."), msg, pstate->lexptr); + pstate->parse_error (msg); } diff --git a/gdb/parse.c b/gdb/parse.c index b57d112fafd..efac0dee1af 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -244,6 +244,17 @@ parser_state::push_dollar (struct stoken str) (create_internalvar (copy.c_str () + 1)); } +/* See parser-defs.h. */ + +void +parser_state::parse_error (const char *msg) +{ + if (this->prev_lexptr) + this->lexptr = this->prev_lexptr; + + error (_("A %s in expression, near `%s'."), msg, this->lexptr); +} + const char * diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h index 93ebdf5c061..4d40245228b 100644 --- a/gdb/parser-defs.h +++ b/gdb/parser-defs.h @@ -262,6 +262,11 @@ struct parser_state : public expr_builder push (expr::make_operation (std::move (lhs), std::move (rhs))); } + /* Function called from various the various parsers yyerror functions to + throw an error. The error will include a message identifying the + location of the error within the current expression. */ + void parse_error (const char *msg); + /* If this is nonzero, this block is used as the lexical context for symbol names. */ From patchwork Tue Jan 2 14:43:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 83148 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DEAEA3858C2F for ; Tue, 2 Jan 2024 14:44:28 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id B27B63858C41 for ; Tue, 2 Jan 2024 14:43:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B27B63858C41 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B27B63858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704206607; cv=none; b=n+OwXRaeEggPbDY0CEyE/eQ5EN6eN0FPH6m0OHS+XhXrXjgP5oCrzgoXYauybETCJVe5mYFyus1Mh9fe5S4ZguXGpNl0Gkamlk6DViiDu61fu0hehaK8KRe6TAwuGqnyxgDnKBhKLoUrYIHDfhWLqhxlHfpwzKx4WMARL9tELug= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704206607; c=relaxed/simple; bh=/d4qAdmA9D3MzuFYWBXz1Fochos/RufnoeT9YmiOV3k=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=pfR5El7v8Ubu34OIaB8nSt0mZXpyg8mTz+iaShmobJnGJDhMhuSQZSWmKz/bTVijWf1Umur5bCC3NYzgBgkyQBPihosdF0k5DSg6sjrF/0x3XgGtIVR6ObJ4JFvssGQY4TA0JcchnSNIaFrx/KaCBqzZj3ombVTV63rijoGWtRs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704206605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZJvurFoKnmqDD+71tP5J/D2F8WY3GmQ/KIEnw1/u6m0=; b=aogbbmvBRt3niqZrBFEWLxfFBxgQ6Vkzfh2L2ZMUyiVZfH59fQ/iGidPh/KPO8WHS/XDCl wNcOvkB//Qy8MX3c3IB2Zt/SEzpS9l/cZilDlJPER0bvSxwsKvAZlXwIecRcFpD8iqLPLX Hm07fm/g+kpl0hJEtkecT3qr742M/Kk= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-594--q7RBXKfM66jPNUW0gMQqg-1; Tue, 02 Jan 2024 09:43:24 -0500 X-MC-Unique: -q7RBXKfM66jPNUW0gMQqg-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-336992b0f37so6121209f8f.0 for ; Tue, 02 Jan 2024 06:43:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704206603; x=1704811403; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Aio5wV7xpoGXa/l6yOoW7ECWdu4KQHdIVDOOqeIyg38=; b=AQ4cYNWFVkH6TOna7tqKl7P04FbCOv7Xj34HYIXGVE4Whp9gilUNfM5h7Bkh7LxytJ 8dkeAwPFVFgAdVDAuSK+4cApDg0BktVfU/4UqrGHWmhRnpexQFK2ybaGYrJRFWUGofoJ gZ4cNkymNK3nD+9daM3FjPLr+417UyVcJ5hksdCu9ePNQmOGs+vsD0Wc4/8O6h7eFeBn TuT5kIdqWwgyFtzkaXHx8Wzl4ioKnqKfjxmu2SXfW7vLu+UnsdNPvjnG5/t0G+5nd+N4 Te5R6W/I0AOAcQ/iTA3OgZRjUeNabFYUt2/3EK+ysgyQY6bBZY9D4ausT9UeGYiltffs Z68w== X-Gm-Message-State: AOJu0Yy5tfX+yQtuFsF+DkgwqKOxsAbnaQex6WkunGC69t2n/7suCNcM dOq5vbRCJKxFY+ZuPKXCkAPJOo0tau3gaVkNro9BjlfuHlvR0uejZ2QvNinpCYs4HouuJc4Uyuv 1nYE94Zs0uucVGKQ4zjxkJ7qo2u5Do+CzQ1P5K5jTQolUYvVXQSqIXKM6QrcOnxt+d1vGrArw+o 2oCRzvLcpWl4fLWw== X-Received: by 2002:a05:600c:1987:b0:40d:5798:1797 with SMTP id t7-20020a05600c198700b0040d57981797mr6412969wmq.63.1704206602866; Tue, 02 Jan 2024 06:43:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IEG/Videbpkw8rORaDZLfbyf5QOgl7Br2d8VD9dj/brYAl8Y9HdF6fc6jYYNkMEpF//I1SrZg== X-Received: by 2002:a05:600c:1987:b0:40d:5798:1797 with SMTP id t7-20020a05600c198700b0040d57981797mr6412962wmq.63.1704206602589; Tue, 02 Jan 2024 06:43:22 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id z5-20020a05600c0a0500b0040d81ca11casm13154799wmp.28.2024.01.02.06.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 06:43:21 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 3/3] gdb: improve error reporting from expression parser Date: Tue, 2 Jan 2024 14:43:13 +0000 Message-Id: <27b42f0c67b536beaf4afd05d5dd748524357c9d.1704206350.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This commits changes how errors are reported from the expression parser. Previously, parser errors were reported like this: (gdb) p a1 +}= 432 A syntax error in expression, near `}= 432'. (gdb) p a1 + A syntax error in expression, near `'. The first case is fine, a user can figure out what's going wrong, but the second case is a little confusing; as the error occurred at the end of the expression GDB just reports the empty string to the user. After this commit the first case is unchanged, but the second case now reports like this: (gdb) p a1 + A syntax error in expression, near the end of `a1 +'. Which I think is clearer. There is a possible issue if the expression being parsed is very long, GDB will repeat the whole expression. But this issue already exists in the standard case; if the error occurs early in a long expression GDB will repeat everything after the syntax error. So I've not worried about this case in my new code either, which keeps things simpler. I did consider trying to have multi-line errors here, in the style that gcc produces, with some kind of '~~~~~^' marker on the second line to indicate where the error occurred; but I rejected this due to the places in GDB where we catch an error and repackage the message within some longer string, I don't think multi-line error messages would work well in that case. At a minimum it would require some significant work in order to make all our error handling multi-line aware. I've added a couple of extra tests in gdb.base/exprs.exp. --- gdb/parse.c | 6 +++++- gdb/parser-defs.h | 4 ++++ gdb/testsuite/gdb.base/exprs.exp | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gdb/parse.c b/gdb/parse.c index efac0dee1af..e8bb112177f 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -252,7 +252,11 @@ parser_state::parse_error (const char *msg) if (this->prev_lexptr) this->lexptr = this->prev_lexptr; - error (_("A %s in expression, near `%s'."), msg, this->lexptr); + if (*this->lexptr == '\0') + error (_("A %s in expression, near the end of `%s'."), + msg, this->start_of_input); + else + error (_("A %s in expression, near `%s'."), msg, this->lexptr); } diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h index 4d40245228b..34673787ef0 100644 --- a/gdb/parser-defs.h +++ b/gdb/parser-defs.h @@ -152,6 +152,7 @@ struct parser_state : public expr_builder expression_context_block (context_block), expression_context_pc (context_pc), lexptr (input), + start_of_input (input), block_tracker (tracker), comma_terminates ((flags & PARSER_COMMA_TERMINATES) != 0), parse_completion (completion), @@ -288,6 +289,9 @@ struct parser_state : public expr_builder Currently used only for error reporting. */ const char *prev_lexptr = nullptr; + /* A pointer to the start of the full input, used for error reporting. */ + const char *start_of_input = nullptr; + /* Number of arguments seen so far in innermost function call. */ int arglist_len = 0; diff --git a/gdb/testsuite/gdb.base/exprs.exp b/gdb/testsuite/gdb.base/exprs.exp index 79ae905fccf..8c85b579b9d 100644 --- a/gdb/testsuite/gdb.base/exprs.exp +++ b/gdb/testsuite/gdb.base/exprs.exp @@ -275,3 +275,11 @@ gdb_test "print null_t_struct && null_t_struct->v_int_member == 0" \ # Regression test for unusual function-call parse that caused a crash. gdb_test "print v_short++(97)" \ "cast the call to its declared return type" + +# Test for a syntax error at the end of an expression. +gdb_test "print v_short + " \ + "A syntax error in expression, near the end of `v_short \\+'\\." + +# Test for a syntax error in the middle of an expression. +gdb_test "print v_short =}{= 3" \ + "A syntax error in expression, near `\\}\\{= 3'\\."