From patchwork Thu May 4 14:21:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 68756 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 F0EB93853821 for ; Thu, 4 May 2023 14:22:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F0EB93853821 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683210140; bh=mIJtkbNyiDmhZt6SfOYqb0KG5wSOzzvmfr6sMzqdCFo=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=euraHdPf/1ltYqYLi51JkqjgcQIfsrkLwX7dsNsP8Pqfhd9zNxShLLQ6DeiWLGEAx 4Yh6EmXu+8YuidCO2t4mr/ZGvEMh/nKTVHjI6rOSw28tYq/YrnHMZhGroU7Zg46ydc N2z1A3NkYMiyHRsUn+TfTsDznkI3k7IDFOiPjN74= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by sourceware.org (Postfix) with ESMTPS id 5FDBD3858CDB for ; Thu, 4 May 2023 14:21:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5FDBD3858CDB Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-76937f5f9c5so11703039f.1 for ; Thu, 04 May 2023 07:21:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683210084; x=1685802084; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mIJtkbNyiDmhZt6SfOYqb0KG5wSOzzvmfr6sMzqdCFo=; b=i/noxkglzPh+4T5jOK9ZOE8OFuGxSepEoANl1Jxl/UXNoVHArBRyeznDnKDouZ6XdS QAUiP3Aps1qyyoo6nmtNXlrZ+n9Z0RCeuz6P50Jan8JntGt/XLNiuxwYPxJA0kqGYFaR 9xoQkVHtdjuLIIWljHMcOYmUEQVkc2agtSoGv+Dc+t4Y3YtmSbyZquEz4JumiqQYpI30 g4KoVhI7vkfKKIdXnyCaw4H5xc2UBljmVRZrJe91mAS71v1SrRec0qE76YRTeDNUc2hq dWgnJEHnmK/TC2EZYVsmEAnWEhJNY3YrbA0MkyA9RTHGZbKNdxsZA334nyysB0nGrng/ zLcA== X-Gm-Message-State: AC+VfDyWwH+x2n4CXCOuLFY4K1y/Su6DMO8/32sNd5jUnlEbJLgYVv5K mlPIVRsCymulM7sRZF1F0IePO/F0vzq2dLSFqL+1tQ== X-Google-Smtp-Source: ACHHUZ6UTA78GUazu3pZJmEH2W8veLadyulvhE8KO4Z89v3K/lzBploWPIADhumWhNJQkHFqZgSXmg== X-Received: by 2002:a5e:c817:0:b0:760:eab2:71b1 with SMTP id y23-20020a5ec817000000b00760eab271b1mr16561591iol.20.1683210084613; Thu, 04 May 2023 07:21:24 -0700 (PDT) Received: from localhost.localdomain (71-211-191-82.hlrn.qwest.net. [71.211.191.82]) by smtp.gmail.com with ESMTPSA id r16-20020a6b4410000000b00760a07e4e09sm9983384ioa.5.2023.05.04.07.21.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 07:21:24 -0700 (PDT) Date: Thu, 04 May 2023 08:21:22 -0600 Subject: [PATCH 01/11] Avoid forward declaration in parse.c MIME-Version: 1.0 Message-Id: <20230504-frameless-v1-1-4191201740b0@adacore.com> References: <20230504-frameless-v1-0-4191201740b0@adacore.com> In-Reply-To: <20230504-frameless-v1-0-4191201740b0@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This minorly rearranges parse.c to avoid the need for a forward declaration. --- gdb/parse.c | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/gdb/parse.c b/gdb/parse.c index a84b4b64fdb..e4678e9c6e8 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -72,12 +72,6 @@ show_parserdebug (struct ui_file *file, int from_tty, } -static expression_up parse_exp_in_context - (const char **, CORE_ADDR, - const struct block *, int, - bool, innermost_block_tracker *, - std::unique_ptr *); - /* Documented at it's declaration. */ void @@ -328,24 +322,6 @@ copy_name (struct stoken token) } -/* Read an expression from the string *STRINGPTR points to, - parse it, and return a pointer to a struct expression that we malloc. - Use block BLOCK as the lexical context for variable names; - if BLOCK is zero, use the block of the selected stack frame. - Meanwhile, advance *STRINGPTR to point after the expression, - at the first nonwhite character that is not part of the expression - (possibly a null character). - - If COMMA is nonzero, stop if a comma is reached. */ - -expression_up -parse_exp_1 (const char **stringptr, CORE_ADDR pc, const struct block *block, - int comma, innermost_block_tracker *tracker) -{ - return parse_exp_in_context (stringptr, pc, block, comma, false, - tracker, nullptr); -} - /* As for parse_exp_1, except that if VOID_CONTEXT_P, then no value is expected from the expression. */ @@ -453,6 +429,24 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc, return result; } +/* Read an expression from the string *STRINGPTR points to, + parse it, and return a pointer to a struct expression that we malloc. + Use block BLOCK as the lexical context for variable names; + if BLOCK is zero, use the block of the selected stack frame. + Meanwhile, advance *STRINGPTR to point after the expression, + at the first nonwhite character that is not part of the expression + (possibly a null character). + + If COMMA is nonzero, stop if a comma is reached. */ + +expression_up +parse_exp_1 (const char **stringptr, CORE_ADDR pc, const struct block *block, + int comma, innermost_block_tracker *tracker) +{ + return parse_exp_in_context (stringptr, pc, block, comma, false, + tracker, nullptr); +} + /* Parse STRING as an expression, and complain if this fails to use up all of the contents of STRING. TRACKER, if non-null, will be updated by the parser. VOID_CONTEXT_P should be true to indicate From patchwork Thu May 4 14:21:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 68753 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 8BF00385B508 for ; Thu, 4 May 2023 14:21:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8BF00385B508 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683210115; bh=08U5cbyWniqMXaTrPE1g1DC2tDiuDELM9sAHA5BET80=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=U3/CFXRzllFG9GsAmXa4wnQpdwB/bpH6omPR2JBVuC4eoxV7KEWyj5/dZ8NR/c49Z FDs/NrPNKZ+7dKdWKueH8h8M/c9YK/KrCNeY/B5XOKS5WGPscw3FG/0RwizGKff3oe mpWx947s1iLzGouI58oYf3A8jMokrVBubUK+j5M8= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by sourceware.org (Postfix) with ESMTPS id 1B0F63858C52 for ; Thu, 4 May 2023 14:21:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1B0F63858C52 Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-766692684e1so11794639f.3 for ; Thu, 04 May 2023 07:21:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683210085; x=1685802085; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=08U5cbyWniqMXaTrPE1g1DC2tDiuDELM9sAHA5BET80=; b=IiEwFa5RlsMClyDHt8ogT2A0eOBKpwqmJLpU7PNddpiY/FjU1jRsrJMbWTHqcvBVsd ZpSkJ27JCi4+VGBWr4n0CcQQVYPOhfVKuns1vcDHI94mu6SBuCx7WDgyYbo9EBDUu6t5 L0F8gjxEDHviutXTGr4pkhWyN/vl7raA0niYKvOtqmn33b44m2n0VIdGamSse5a06nmo 2SMtjPwz17V/kwWhUDHtwprB2qbSXUobYis0rzXbMN3Y7iJRf3hhYBv//4r2Uqv4BuQk P07fB6M5DhT3OUl6bDw7E+jpzrLmjayD8uYBKpYdB5HPCTeSwX6CgyH2Vvv1COkv7DMv 0yng== X-Gm-Message-State: AC+VfDwIehJfJ0sBmMTaYsgjEf6HdURf46JfFRbOdr4f9JyhGqCi+Q8C AwvLMbdK6y6hN04zUNo3syswp/2wMUf1h7GADpYXAg== X-Google-Smtp-Source: ACHHUZ6NC/KlyseQDSKdBODNNaFziHNYhKaxbby/tw+ok84BMNwru25vTXOHyFnJM2LV/7RIQUD7Tg== X-Received: by 2002:a5d:81d9:0:b0:768:dd79:c013 with SMTP id t25-20020a5d81d9000000b00768dd79c013mr12304084iol.17.1683210085279; Thu, 04 May 2023 07:21:25 -0700 (PDT) Received: from localhost.localdomain (71-211-191-82.hlrn.qwest.net. [71.211.191.82]) by smtp.gmail.com with ESMTPSA id r16-20020a6b4410000000b00760a07e4e09sm9983384ioa.5.2023.05.04.07.21.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 07:21:24 -0700 (PDT) Date: Thu, 04 May 2023 08:21:23 -0600 Subject: [PATCH 02/11] Move innermost_block_tracker to expression.h MIME-Version: 1.0 Message-Id: <20230504-frameless-v1-2-4191201740b0@adacore.com> References: <20230504-frameless-v1-0-4191201740b0@adacore.com> In-Reply-To: <20230504-frameless-v1-0-4191201740b0@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" I think parser-defs.h should hold declarations that can be used by parser implementations, whereas expression.h should hold declarations that are used by code that wants to call a parser. Following this logic, this patch moves innermost_block_tracker to expression.h. --- gdb/expression.h | 46 ++++++++++++++++++++++++++++++++++++++++++++-- gdb/parser-defs.h | 43 ------------------------------------------- 2 files changed, 44 insertions(+), 45 deletions(-) diff --git a/gdb/expression.h b/gdb/expression.h index e6e4bec2e80..8d351b30a3a 100644 --- a/gdb/expression.h +++ b/gdb/expression.h @@ -21,6 +21,7 @@ #define EXPRESSION_H 1 #include "gdbtypes.h" +#include "symtab.h" /* While parsing expressions we need to track the innermost lexical block that we encounter. In some situations we need to track the innermost @@ -239,9 +240,51 @@ struct expression typedef std::unique_ptr expression_up; +/* When parsing expressions we track the innermost block that was + referenced. */ + +class innermost_block_tracker +{ +public: + innermost_block_tracker (innermost_block_tracker_types types + = INNERMOST_BLOCK_FOR_SYMBOLS) + : m_types (types), + m_innermost_block (NULL) + { /* Nothing. */ } + + /* Update the stored innermost block if the new block B is more inner + than the currently stored block, or if no block is stored yet. The + type T tells us whether the block B was for a symbol or for a + register. The stored innermost block is only updated if the type T is + a type we are interested in, the types we are interested in are held + in M_TYPES and set during RESET. */ + void update (const struct block *b, innermost_block_tracker_types t); + + /* Overload of main UPDATE method which extracts the block from BS. */ + void update (const struct block_symbol &bs) + { + update (bs.block, INNERMOST_BLOCK_FOR_SYMBOLS); + } + + /* Return the stored innermost block. Can be nullptr if no symbols or + registers were found during an expression parse, and so no innermost + block was defined. */ + const struct block *block () const + { + return m_innermost_block; + } + +private: + /* The type of innermost block being looked for. */ + innermost_block_tracker_types m_types; + + /* The currently stored innermost block found while parsing an + expression. */ + const struct block *m_innermost_block; +}; + /* From parse.c */ -class innermost_block_tracker; extern expression_up parse_expression (const char *, innermost_block_tracker * = nullptr, bool void_context_p = false); @@ -270,7 +313,6 @@ struct expr_completion_base extern expression_up parse_expression_for_completion (const char *, std::unique_ptr *completer); -class innermost_block_tracker; extern expression_up parse_exp_1 (const char **, CORE_ADDR pc, const struct block *, int, innermost_block_tracker * = nullptr); diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h index 62829a86f9a..5c6bc222b6b 100644 --- a/gdb/parser-defs.h +++ b/gdb/parser-defs.h @@ -316,49 +316,6 @@ struct parser_state : public expr_builder std::vector m_operations; }; -/* When parsing expressions we track the innermost block that was - referenced. */ - -class innermost_block_tracker -{ -public: - innermost_block_tracker (innermost_block_tracker_types types - = INNERMOST_BLOCK_FOR_SYMBOLS) - : m_types (types), - m_innermost_block (NULL) - { /* Nothing. */ } - - /* Update the stored innermost block if the new block B is more inner - than the currently stored block, or if no block is stored yet. The - type T tells us whether the block B was for a symbol or for a - register. The stored innermost block is only updated if the type T is - a type we are interested in, the types we are interested in are held - in M_TYPES and set during RESET. */ - void update (const struct block *b, innermost_block_tracker_types t); - - /* Overload of main UPDATE method which extracts the block from BS. */ - void update (const struct block_symbol &bs) - { - update (bs.block, INNERMOST_BLOCK_FOR_SYMBOLS); - } - - /* Return the stored innermost block. Can be nullptr if no symbols or - registers were found during an expression parse, and so no innermost - block was defined. */ - const struct block *block () const - { - return m_innermost_block; - } - -private: - /* The type of innermost block being looked for. */ - innermost_block_tracker_types m_types; - - /* The currently stored innermost block found while parsing an - expression. */ - const struct block *m_innermost_block; -}; - /* A string token, either a char-string or bit-string. Char-strings are used, for example, for the names of symbols. */ From patchwork Thu May 4 14:21:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 68759 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 A45F23851C31 for ; Thu, 4 May 2023 14:22:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A45F23851C31 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683210169; bh=ZnLdxFXgcGMw1E6EAurgrwBsIdMWjK33duTnh8fJrh8=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=QDqOJixFXtSuNwO6j1koeIe0o+OHsxxVnDbz+hj6TJ1LoEgZ5tGG2RCm/o2yVT7Q4 epeNxVS2KLLBwDmPmzHoOxAWDdq6Bn0mIWI4Vi6dfPhUdVjUnN8p48f44ZQ1cDQSjH NqVY8APUzaMT4os3u9TswEvja12M5fnrAnhLubKM= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) by sourceware.org (Postfix) with ESMTPS id B07C33858C78 for ; Thu, 4 May 2023 14:21:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B07C33858C78 Received: by mail-il1-x129.google.com with SMTP id e9e14a558f8ab-33187944bc9so1133885ab.0 for ; Thu, 04 May 2023 07:21:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683210086; x=1685802086; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZnLdxFXgcGMw1E6EAurgrwBsIdMWjK33duTnh8fJrh8=; b=E5CFbVnGFDwB7Qz9v/31PgIkER/ixgxy0CRfOTsOcNorwrpRodTRoZxysvGUnBVfXs SkE2UokeObjcS43YQrWD/x4UqW5q8pnRwjlp/BG6GCLFnmvVdeLRtTWyO8iGFvlsIlku MVRmyOtU1/z29xnoQUudS+hzPPJl0SEzLf8xSMIm+1xTfmBbENxlXJ8ZfcUCZV5FN9dd DXkfMpYBhrEElPwkUkpx/OGj83Kj/4zyUiaOOFOHU1BYPd7zTc3VwUdkyHQDt1hVOUqJ MAQRSusrl2rxIytlpsaLnLQ4k1decNQpHyZ6g8yGvVeooD0Lsx8rksr+EWg2B2qSalwi ynxw== X-Gm-Message-State: AC+VfDyLBcKBmejS2NctR0W3epro4h42br2nJ5hEI0e7UfKPsAUEaHOn 9Ww87XyhpDsbyByTRx0Pe4F7ZIOAoJKq3QikmkQmHQ== X-Google-Smtp-Source: ACHHUZ6VGoO76nNernr89xJCVtRcafLataaUZfBcvX1xI5CCJHxtc98UpHX4CqfzqioGEJLG6kTOCw== X-Received: by 2002:a92:280d:0:b0:317:3f4:c06c with SMTP id l13-20020a92280d000000b0031703f4c06cmr2342ilf.20.1683210085921; Thu, 04 May 2023 07:21:25 -0700 (PDT) Received: from localhost.localdomain (71-211-191-82.hlrn.qwest.net. [71.211.191.82]) by smtp.gmail.com with ESMTPSA id r16-20020a6b4410000000b00760a07e4e09sm9983384ioa.5.2023.05.04.07.21.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 07:21:25 -0700 (PDT) Date: Thu, 04 May 2023 08:21:24 -0600 Subject: [PATCH 03/11] Introduce and use parser flags MIME-Version: 1.0 Message-Id: <20230504-frameless-v1-3-4191201740b0@adacore.com> References: <20230504-frameless-v1-0-4191201740b0@adacore.com> In-Reply-To: <20230504-frameless-v1-0-4191201740b0@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This patch adds a new parser_flags type and changes the parser APIs to use it rather than a collection of 'int' and 'bool'. More flags will be added in subsquent patches. --- gdb/ax-gdb.c | 3 ++- gdb/breakpoint.c | 3 ++- gdb/eval.c | 3 ++- gdb/expression.h | 21 +++++++++++++++++++-- gdb/parse.c | 29 +++++++++++++---------------- gdb/printcmd.c | 5 ++++- gdb/tracepoint.c | 10 ++++++---- 7 files changed, 48 insertions(+), 26 deletions(-) diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index 528f45e19eb..927dfc6337e 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -2615,7 +2615,8 @@ maint_agent_printf_command (const char *cmdrest, int from_tty) const char *cmd1; cmd1 = cmdrest; - expression_up expr = parse_exp_1 (&cmd1, 0, (struct block *) 0, 1); + expression_up expr = parse_exp_1 (&cmd1, 0, (struct block *) 0, + PARSER_COMMA_TERMINATES); argvec.push_back (expr.release ()); cmdrest = cmd1; if (*cmdrest == ',') diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 30d438d06df..de3a7e9ef9c 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -2526,7 +2526,8 @@ parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) const char *cmd1; cmd1 = cmdrest; - expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); + expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), + PARSER_COMMA_TERMINATES); argvec.push_back (expr.release ()); cmdrest = cmd1; if (*cmdrest == ',') diff --git a/gdb/eval.c b/gdb/eval.c index 9d5ca0b47de..d8d53c28686 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -81,7 +81,8 @@ parse_and_eval (const char *exp) struct value * parse_to_comma_and_eval (const char **expp) { - expression_up expr = parse_exp_1 (expp, 0, nullptr, 1); + expression_up expr = parse_exp_1 (expp, 0, nullptr, + PARSER_COMMA_TERMINATES); return expr->evaluate (); } diff --git a/gdb/expression.h b/gdb/expression.h index 8d351b30a3a..2e2d2a090f9 100644 --- a/gdb/expression.h +++ b/gdb/expression.h @@ -283,11 +283,27 @@ class innermost_block_tracker const struct block *m_innermost_block; }; +/* Flags that can affect the parsers. */ + +enum parser_flag +{ + /* This flag is set if the expression is being evaluated in a + context where a 'void' result type is expected. Parsers are free + to ignore this, or to use it to help with overload resolution + decisions. */ + PARSER_VOID_CONTEXT = (1 << 0), + + /* This flag is set if a top-level comma terminates the + expression. */ + PARSER_COMMA_TERMINATES = (1 << 1), +}; +DEF_ENUM_FLAGS_TYPE (enum parser_flag, parser_flags); + /* From parse.c */ extern expression_up parse_expression (const char *, innermost_block_tracker * = nullptr, - bool void_context_p = false); + parser_flags flags = 0); extern expression_up parse_expression_with_language (const char *string, enum language lang); @@ -314,7 +330,8 @@ extern expression_up parse_expression_for_completion (const char *, std::unique_ptr *completer); extern expression_up parse_exp_1 (const char **, CORE_ADDR pc, - const struct block *, int, + const struct block *, + parser_flags flags, innermost_block_tracker * = nullptr); /* From eval.c */ diff --git a/gdb/parse.c b/gdb/parse.c index e4678e9c6e8..ed0d0b8a880 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -328,7 +328,7 @@ copy_name (struct stoken token) static expression_up parse_exp_in_context (const char **stringptr, CORE_ADDR pc, const struct block *block, - int comma, bool void_context_p, + parser_flags flags, innermost_block_tracker *tracker, std::unique_ptr *completer) { @@ -398,8 +398,11 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc, to the value matching SELECTED_FRAME as set by get_current_arch. */ parser_state ps (lang, get_current_arch (), expression_context_block, - expression_context_pc, comma, *stringptr, - completer != nullptr, tracker, void_context_p); + expression_context_pc, + (flags & PARSER_COMMA_TERMINATES) != 0, + *stringptr, + completer != nullptr, tracker, + (flags & PARSER_VOID_CONTEXT) != 0); scoped_restore_current_language lang_saver; set_language (lang->la_language); @@ -435,31 +438,25 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc, if BLOCK is zero, use the block of the selected stack frame. Meanwhile, advance *STRINGPTR to point after the expression, at the first nonwhite character that is not part of the expression - (possibly a null character). - - If COMMA is nonzero, stop if a comma is reached. */ + (possibly a null character). FLAGS are passed to the parser. */ expression_up parse_exp_1 (const char **stringptr, CORE_ADDR pc, const struct block *block, - int comma, innermost_block_tracker *tracker) + parser_flags flags, innermost_block_tracker *tracker) { - return parse_exp_in_context (stringptr, pc, block, comma, false, + return parse_exp_in_context (stringptr, pc, block, flags, tracker, nullptr); } /* Parse STRING as an expression, and complain if this fails to use up all of the contents of STRING. TRACKER, if non-null, will be - updated by the parser. VOID_CONTEXT_P should be true to indicate - that the expression may be expected to return a value with void - type. Parsers are free to ignore this, or to use it to help with - overload resolution decisions. */ + updated by the parser. FLAGS are passed to the parser. */ expression_up parse_expression (const char *string, innermost_block_tracker *tracker, - bool void_context_p) + parser_flags flags) { - expression_up exp = parse_exp_in_context (&string, 0, nullptr, 0, - void_context_p, + expression_up exp = parse_exp_in_context (&string, 0, nullptr, flags, tracker, nullptr); if (*string) error (_("Junk after end of expression.")); @@ -495,7 +492,7 @@ parse_expression_for_completion try { - exp = parse_exp_in_context (&string, 0, 0, 0, false, nullptr, completer); + exp = parse_exp_in_context (&string, 0, 0, 0, nullptr, completer); } catch (const gdb_exception_error &except) { diff --git a/gdb/printcmd.c b/gdb/printcmd.c index e903bf48fa5..e04a9c28739 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -1315,7 +1315,10 @@ process_print_command_args (const char *args, value_print_options *print_opts, /* VOIDPRINT is true to indicate that we do want to print a void value, so invert it for parse_expression. */ - expression_up expr = parse_expression (exp, nullptr, !voidprint); + parser_flags flags = 0; + if (!voidprint) + flags = PARSER_VOID_CONTEXT; + expression_up expr = parse_expression (exp, nullptr, flags); return expr->evaluate (); } diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index ffda4a6439e..9e5ced1893e 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -680,7 +680,8 @@ validate_actionline (const char *line, struct breakpoint *b) { p = tmp_p; expression_up exp = parse_exp_1 (&p, loc->address, - block_for_pc (loc->address), 1); + block_for_pc (loc->address), + PARSER_COMMA_TERMINATES); if (exp->first_opcode () == OP_VAR_VALUE) { @@ -732,7 +733,8 @@ validate_actionline (const char *line, struct breakpoint *b) /* Only expressions are allowed for this action. */ expression_up exp = parse_exp_1 (&p, loc->address, - block_for_pc (loc->address), 1); + block_for_pc (loc->address), + PARSER_COMMA_TERMINATES); /* We have something to evaluate, make sure that the expr to bytecode translator can handle it and that it's not too @@ -1349,7 +1351,7 @@ encode_actions_1 (struct command_line *action, const char *exp_start = action_exp; expression_up exp = parse_exp_1 (&action_exp, tloc->address, block_for_pc (tloc->address), - 1); + PARSER_COMMA_TERMINATES); switch (exp->first_opcode ()) { @@ -1439,7 +1441,7 @@ encode_actions_1 (struct command_line *action, { expression_up exp = parse_exp_1 (&action_exp, tloc->address, block_for_pc (tloc->address), - 1); + PARSER_COMMA_TERMINATES); agent_expr_up aexpr = gen_eval_for_expr (tloc->address, exp.get ()); From patchwork Thu May 4 14:21:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 68754 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 94F943856275 for ; Thu, 4 May 2023 14:22:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 94F943856275 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683210129; bh=kdh7BcZwye8efjubBbzbl2qzKbHNOF7CoKYw6HQxhRU=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=EybD3ocYd8jjfw7foCzFZ+e1ur82PQ6WsHiorOoCBfmLoweKpAZXt2gBIBpewzomI Vhv9BwXh5iHdiTrptGioOXi7inGodQfS9/zxyI6L5wO1b6FIOrvNtaBIv3c3NU02fF xG0XE3y42POh/877erYUEifuDa+SoWsP5ckOvzEc= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by sourceware.org (Postfix) with ESMTPS id 4984638582AB for ; Thu, 4 May 2023 14:21:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4984638582AB Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-76983b8a1f5so35909939f.0 for ; Thu, 04 May 2023 07:21:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683210086; x=1685802086; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kdh7BcZwye8efjubBbzbl2qzKbHNOF7CoKYw6HQxhRU=; b=HvlXVYD98zO+nRQvrdDB8PR71aClRYiyElZNlP42caio/hiaj6brNMc8c6Qro5Tf+R PAmS8Q6pi68J/DvOq4MZFJxk4jri4cdJmd/IOu2yFQtlSXBvQ7uP2XYi0+RjKmjVxu32 R3wdqDxBm2SoCqxaQAX4It+AshovtrpN4BIUIf+n6LMw+v8N4tuVPiCwedfYgV3RWzSB qCC1+BDKxgVQ5Aifjx6FtHcauIMjSJ1b28zJKm/niSNLnCufIcHDHW12fUmzNUHBOWks X36sFgQQ3Z2AP7fLeuYGyMAaLMcJYVlNXAQ4RXXOZapFLyXUti4FXUJPNcg4bNKpntZb XG6A== X-Gm-Message-State: AC+VfDyVEcMEicmzGykNfjud9G10cf7YJhDfF3XDeWYhYNRdDHUrqfdY Oe8uxy1qN0bqOQVqxjW6Dq326IJ1cT4kVgawc+Wh5Q== X-Google-Smtp-Source: ACHHUZ5RhGrPsYvHsONPtYSU0TRVDvhS0z4xlhmQs0Y8sYOBQtOqA3Qprw09oNI4BB8+2y3aKcK9AQ== X-Received: by 2002:a05:6602:25d2:b0:760:b45d:7d54 with SMTP id d18-20020a05660225d200b00760b45d7d54mr17069729iop.13.1683210086542; Thu, 04 May 2023 07:21:26 -0700 (PDT) Received: from localhost.localdomain (71-211-191-82.hlrn.qwest.net. [71.211.191.82]) by smtp.gmail.com with ESMTPSA id r16-20020a6b4410000000b00760a07e4e09sm9983384ioa.5.2023.05.04.07.21.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 07:21:26 -0700 (PDT) Date: Thu, 04 May 2023 08:21:25 -0600 Subject: [PATCH 04/11] Simplify parser_state constructor MIME-Version: 1.0 Message-Id: <20230504-frameless-v1-4-4191201740b0@adacore.com> References: <20230504-frameless-v1-0-4191201740b0@adacore.com> In-Reply-To: <20230504-frameless-v1-0-4191201740b0@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This simplifies the parser_state constructor by having it accept a parser_flags parameter. --- gdb/parse.c | 7 ++----- gdb/parser-defs.h | 9 ++++----- gdb/rust-parse.c | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/gdb/parse.c b/gdb/parse.c index ed0d0b8a880..2f014dd2172 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -398,11 +398,8 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc, to the value matching SELECTED_FRAME as set by get_current_arch. */ parser_state ps (lang, get_current_arch (), expression_context_block, - expression_context_pc, - (flags & PARSER_COMMA_TERMINATES) != 0, - *stringptr, - completer != nullptr, tracker, - (flags & PARSER_VOID_CONTEXT) != 0); + expression_context_pc, flags, *stringptr, + completer != nullptr, tracker); scoped_restore_current_language lang_saver; set_language (lang->la_language); diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h index 5c6bc222b6b..2a246ff38f0 100644 --- a/gdb/parser-defs.h +++ b/gdb/parser-defs.h @@ -146,19 +146,18 @@ struct parser_state : public expr_builder struct gdbarch *gdbarch, const struct block *context_block, CORE_ADDR context_pc, - int comma, + parser_flags flags, const char *input, bool completion, - innermost_block_tracker *tracker, - bool void_p) + innermost_block_tracker *tracker) : expr_builder (lang, gdbarch), expression_context_block (context_block), expression_context_pc (context_pc), - comma_terminates (comma), + comma_terminates ((flags & PARSER_COMMA_TERMINATES) != 0), lexptr (input), parse_completion (completion), block_tracker (tracker), - void_context_p (void_p) + void_context_p ((flags & PARSER_VOID_CONTEXT) != 0) { } diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c index 648e48dda40..6ba959065c9 100644 --- a/gdb/rust-parse.c +++ b/gdb/rust-parse.c @@ -2300,7 +2300,7 @@ rust_lex_tests (void) { /* Set up dummy "parser", so that rust_type works. */ struct parser_state ps (language_def (language_rust), target_gdbarch (), - nullptr, 0, 0, nullptr, 0, nullptr, false); + nullptr, 0, 0, nullptr, 0, nullptr); rust_parser parser (&ps); rust_lex_test_one (&parser, "", 0); From patchwork Thu May 4 14:21:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 68755 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 2BEB9385B524 for ; Thu, 4 May 2023 14:22:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2BEB9385B524 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683210138; bh=o0zoI+4v+p1LTvLt5GPdLU+/9hDhnaytoX5FK4YZqzg=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=PeEQUQki5jQuMdYAFAvlEIVHBBjuHlfGKjB7UMug7HOFsdGDdsO9taSaRVWr38c7I NYfOAY/CxCDzl33ppcpvKfFyDYrg6Hz0fU8LAdIuLWSty5LDI0n3HU6mIgQWuvmtWZ +qYMuvDD6x+5kwq1WSwRRqet+KR6POCyBiIqAd9U= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by sourceware.org (Postfix) with ESMTPS id CE2E038582BD for ; Thu, 4 May 2023 14:21:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CE2E038582BD Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-769036b48b0so36160239f.0 for ; Thu, 04 May 2023 07:21:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683210087; x=1685802087; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o0zoI+4v+p1LTvLt5GPdLU+/9hDhnaytoX5FK4YZqzg=; b=OTQXPt4ueS0IuFkjF0NhM90ktHiTmldtOGmZFATfcfu8QcLV18PlxnE1JZmosVRGJy G695sU8+MgVbdb2t1Y1i4HZMJuUVXGkmDQAeXVDD2naTr/eK7nIdm+4zdtOtDzOnaw2g MkBMdgUTVjfDWJWq9MM4KD91KQoY0RaWImnn6xwvTnrLm6jkIPQhefeJ3wwtOed/L6Bo 33pP/9l5EkJtYcAz887pybfO0fl5g2bG6iqaqJOBC3WAEkYUBRpV4nCNsf0Mq486/NB3 5rbiBPHxeU5q4unn1ntKUH9Ws1bb3ih728HFERb2EsCtdUSIhnMHG3O1lMelCy5KcLtK r5vQ== X-Gm-Message-State: AC+VfDys0c0C+x+7uJfFuzSUJpvSQ+KzBppZCJ8QR/z+5sDQysnzZeC1 1PaOQOAx6kJQNCW0YQiOQnjAdHGeolCIKjTIvEgXiw== X-Google-Smtp-Source: ACHHUZ5GTfqEeZQSdqHo5h9cCg8pn3Es246B4WGuYDqh6Eqkc8wlvsKIMinuZKy99YGO2IzD4GmJIQ== X-Received: by 2002:a6b:f81a:0:b0:759:6a8e:96e5 with SMTP id o26-20020a6bf81a000000b007596a8e96e5mr16568527ioh.17.1683210087145; Thu, 04 May 2023 07:21:27 -0700 (PDT) Received: from localhost.localdomain (71-211-191-82.hlrn.qwest.net. [71.211.191.82]) by smtp.gmail.com with ESMTPSA id r16-20020a6b4410000000b00760a07e4e09sm9983384ioa.5.2023.05.04.07.21.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 07:21:26 -0700 (PDT) Date: Thu, 04 May 2023 08:21:26 -0600 Subject: [PATCH 05/11] Boolify parser_state::comma_terminates MIME-Version: 1.0 Message-Id: <20230504-frameless-v1-5-4191201740b0@adacore.com> References: <20230504-frameless-v1-0-4191201740b0@adacore.com> In-Reply-To: <20230504-frameless-v1-0-4191201740b0@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" parser_state::comma_terminates ought to be boolean, and changing it does not require any other changes. --- gdb/parser-defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h index 2a246ff38f0..e92b4804f47 100644 --- a/gdb/parser-defs.h +++ b/gdb/parser-defs.h @@ -277,7 +277,7 @@ struct parser_state : public expr_builder /* Nonzero means stop parsing on first comma (if not within parentheses). */ - int comma_terminates; + bool comma_terminates; /* During parsing of a C expression, the pointer to the next character is in this variable. */ From patchwork Thu May 4 14:21:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 68762 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 1D13E3854165 for ; Thu, 4 May 2023 14:23:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D13E3854165 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683210198; bh=X7qRer9ZdJ1qKyPgQ78smPb1j9eXLLQ0uj1bgQTKMyc=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=sTCwOuZaaRFWYNB2qr75OZ/m0fmSnS3VctCDX1gP10GzkuYNVa2iOOyE7wcRbu4NY Ak5Kpv5lvMrbYmJ8Cn1HYwKh7n4LsV5pPGDRioXFZ2wV37R77KMspLrslH9fOpVGLU XcFl1umCT3XFnQzDnMtyWwHN5ScpIGn+J/Z/15eY= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by sourceware.org (Postfix) with ESMTPS id 70D53385734F for ; Thu, 4 May 2023 14:21:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 70D53385734F Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-76640f8c456so10789239f.0 for ; Thu, 04 May 2023 07:21:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683210088; x=1685802088; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X7qRer9ZdJ1qKyPgQ78smPb1j9eXLLQ0uj1bgQTKMyc=; b=gID2aPxFERJULEj6uR87sO1h8SJA7JxVJZjrFw5xj8sbwpH7JkKT8dw2VoEGjydMTl Xz1AnYSNpNrdw83nxW4IOIRoSlIlTJ9evfcqYrPeCZxXtMC9RLCjwGtkCyQxDXKdL3HX wlCsJyDQn4O9C7NraJpoN8uIhlRO190rlmKC7LHfUyNFEdMS+Jcc3vIwSUSmH6kF0oz9 qkPMKsTkZjxxwNYEWMG2qkU/k+QN1lPApf2POIYRGKX26e2FpdM07ZlWGJ7lQ6ijXx7N YKMs93BEutGqPii97TCzSe8D9vIxCIkrDpa8QZKzWpxWQsJBQQOt98atFi05Loi80nEa BYMA== X-Gm-Message-State: AC+VfDzAa1KyJbV71GxeSj0MstjSBRVZhs+EuXoxSQmo64FKTMR796l0 PtZkqUgIPBn4evLdEzV4tHm60BVxcScbkQ5oWp6nYA== X-Google-Smtp-Source: ACHHUZ5oF2BFpTDSJ3zwSFSm9ymxKYLIE72E+LCLILyN2jFypxTrb8bptmxb0jQ2d76bHtSfYKAAhQ== X-Received: by 2002:a6b:d90f:0:b0:75c:6dba:111c with SMTP id r15-20020a6bd90f000000b0075c6dba111cmr17974843ioc.16.1683210087713; Thu, 04 May 2023 07:21:27 -0700 (PDT) Received: from localhost.localdomain (71-211-191-82.hlrn.qwest.net. [71.211.191.82]) by smtp.gmail.com with ESMTPSA id r16-20020a6b4410000000b00760a07e4e09sm9983384ioa.5.2023.05.04.07.21.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 07:21:27 -0700 (PDT) Date: Thu, 04 May 2023 08:21:27 -0600 Subject: [PATCH 06/11] Rearrange parser_state MIME-Version: 1.0 Message-Id: <20230504-frameless-v1-6-4191201740b0@adacore.com> References: <20230504-frameless-v1-0-4191201740b0@adacore.com> In-Reply-To: <20230504-frameless-v1-0-4191201740b0@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This patch mildly rearranges parser_state, moving all the bool fields together. --- gdb/parser-defs.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h index e92b4804f47..39046d04c8d 100644 --- a/gdb/parser-defs.h +++ b/gdb/parser-defs.h @@ -153,10 +153,10 @@ struct parser_state : public expr_builder : expr_builder (lang, gdbarch), expression_context_block (context_block), expression_context_pc (context_pc), - comma_terminates ((flags & PARSER_COMMA_TERMINATES) != 0), lexptr (input), - parse_completion (completion), block_tracker (tracker), + comma_terminates ((flags & PARSER_COMMA_TERMINATES) != 0), + parse_completion (completion), void_context_p ((flags & PARSER_VOID_CONTEXT) != 0) { } @@ -275,10 +275,6 @@ struct parser_state : public expr_builder point. */ const CORE_ADDR expression_context_pc; - /* Nonzero means stop parsing on first comma (if not within parentheses). */ - - bool comma_terminates; - /* During parsing of a C expression, the pointer to the next character is in this variable. */ @@ -292,15 +288,18 @@ struct parser_state : public expr_builder int arglist_len = 0; - /* True if parsing an expression to attempt completion. */ - bool parse_completion; - /* Completion state is updated here. */ std::unique_ptr m_completion_state; /* The innermost block tracker. */ innermost_block_tracker *block_tracker; + /* Nonzero means stop parsing on first comma (if not within parentheses). */ + bool comma_terminates; + + /* True if parsing an expression to attempt completion. */ + bool parse_completion; + /* True if no value is expected from the expression. */ bool void_context_p; From patchwork Thu May 4 14:21:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 68758 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 C674F3853549 for ; Thu, 4 May 2023 14:22:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C674F3853549 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683210166; bh=wPMmjoVsakfZPSKXROno3tAKp5D9eN4+9/xYlKQejak=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=s9IgDtV9raPkE6VJyWpDpc3G/uANkaPS5JXciR7e0T6aLfPFzDw4Ajkji8+AUTUh3 c9qwNANPQA7RDO2511xmkEz5S35TBQIwbySq6ZQ7jXFECoia4uoKeATKUkXfq/rIIM 7G7Hn4YYSEgTysMn9SaDVflyBdJyAE5ou/e/47AI= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by sourceware.org (Postfix) with ESMTPS id 30BB93857353 for ; Thu, 4 May 2023 14:21:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 30BB93857353 Received: by mail-io1-xd2f.google.com with SMTP id ca18e2360f4ac-763c34315c1so35311839f.3 for ; Thu, 04 May 2023 07:21:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683210088; x=1685802088; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wPMmjoVsakfZPSKXROno3tAKp5D9eN4+9/xYlKQejak=; b=O5zGJgK2bO1fFetnUBsuUuedlJhCtvTMYzGpbyg7fgWpK0AW9XhgFF+9O/zK8W+owa +UIWc5yLKTAcvhMScxs5miuue6I9das9zhSB9+L90UF1mpRo3JGzQRqQkvoIMvEjRf+5 dVZCHWpKAGaBTOOOOkTt6FTqIIe+GVRVQ+DYw2Gt+y/VXQM8k8f+qnUBdZo8oF+XRxJS KQ3BoNxhTLlDoJVkTBsFbwSFKC7DuaNulI0WeG3+PYre7YHZ9jWuEblNwhDw6uZ+BwUn lDVzdvcV7lZd+BDIcqfvYmkWftzBSlvZaiDzD/YIXZFZWWhvVUQo+lHTW91WAAH9hX7W hOzA== X-Gm-Message-State: AC+VfDwGz5Yi8l/DU1LmnSeHyxt5SdNIampGl/xi/5n/NXqleUupW18o ppNG/JwcyCFGnwy+XiUI2hSh7ULpAmsclva2qxLJjg== X-Google-Smtp-Source: ACHHUZ6AL+3Tn7zfV3SbGHBdLYjMFZkfDSe+SJa2TGzNll+WZssrMEkVIPlkvhgx4snnxhRkyw9z6A== X-Received: by 2002:a5d:8753:0:b0:763:5523:e89d with SMTP id k19-20020a5d8753000000b007635523e89dmr17440956iol.18.1683210088352; Thu, 04 May 2023 07:21:28 -0700 (PDT) Received: from localhost.localdomain (71-211-191-82.hlrn.qwest.net. [71.211.191.82]) by smtp.gmail.com with ESMTPSA id r16-20020a6b4410000000b00760a07e4e09sm9983384ioa.5.2023.05.04.07.21.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 07:21:28 -0700 (PDT) Date: Thu, 04 May 2023 08:21:28 -0600 Subject: [PATCH 07/11] Add PARSER_DEBUG flag MIME-Version: 1.0 Message-Id: <20230504-frameless-v1-7-4191201740b0@adacore.com> References: <20230504-frameless-v1-0-4191201740b0@adacore.com> In-Reply-To: <20230504-frameless-v1-0-4191201740b0@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This adds a new PARSER_DEBUG constant and changes the parser code to use it. This lets us make the 'parser_debug' global 'static'. --- gdb/ada-exp.y | 2 +- gdb/c-exp.y | 2 +- gdb/d-exp.y | 2 +- gdb/expression.h | 5 +++++ gdb/f-exp.y | 2 +- gdb/go-exp.y | 2 +- gdb/parse.c | 2 +- gdb/parser-defs.h | 8 +++++--- 8 files changed, 16 insertions(+), 9 deletions(-) diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y index 3e31d275046..23aebf0e236 100644 --- a/gdb/ada-exp.y +++ b/gdb/ada-exp.y @@ -1150,7 +1150,7 @@ ada_parse (struct parser_state *par_state) original_expr = par_state->lexptr; scoped_restore restore_yydebug = make_scoped_restore (&yydebug, - parser_debug); + par_state->debug); lexer_init (yyin); /* (Re-)initialize lexer. */ obstack_free (&temp_parse_space, NULL); diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 9ee4115560a..a8c78414253 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -3403,7 +3403,7 @@ c_parse (struct parser_state *par_state) = make_scoped_restore (&expression_macro_scope, macro_scope.get ()); scoped_restore restore_yydebug = make_scoped_restore (&yydebug, - parser_debug); + par_state->debug); /* Initialize some state used by the lexer. */ last_was_structop = false; diff --git a/gdb/d-exp.y b/gdb/d-exp.y index 3a4e7ee0434..b0f2c0d1c10 100644 --- a/gdb/d-exp.y +++ b/gdb/d-exp.y @@ -1607,7 +1607,7 @@ d_parse (struct parser_state *par_state) pstate = par_state; scoped_restore restore_yydebug = make_scoped_restore (&yydebug, - parser_debug); + par_state->debug); struct type_stack stack; scoped_restore restore_type_stack = make_scoped_restore (&type_stack, diff --git a/gdb/expression.h b/gdb/expression.h index 2e2d2a090f9..c485b159ef8 100644 --- a/gdb/expression.h +++ b/gdb/expression.h @@ -296,6 +296,11 @@ enum parser_flag /* This flag is set if a top-level comma terminates the expression. */ PARSER_COMMA_TERMINATES = (1 << 1), + + /* This flag is set if the parser should print debugging output as + it parses. For yacc-based parsers, this translates to setting + yydebug. */ + PARSER_DEBUG = (1 << 2), }; DEF_ENUM_FLAGS_TYPE (enum parser_flag, parser_flags); diff --git a/gdb/f-exp.y b/gdb/f-exp.y index 7fb1a9054e3..c0afebc0589 100644 --- a/gdb/f-exp.y +++ b/gdb/f-exp.y @@ -1697,7 +1697,7 @@ f_language::parser (struct parser_state *par_state) const /* Setting up the parser state. */ scoped_restore pstate_restore = make_scoped_restore (&pstate); scoped_restore restore_yydebug = make_scoped_restore (&yydebug, - parser_debug); + par_state->debug); gdb_assert (par_state != NULL); pstate = par_state; last_was_structop = false; diff --git a/gdb/go-exp.y b/gdb/go-exp.y index 542a06d06d6..5c213f138f0 100644 --- a/gdb/go-exp.y +++ b/gdb/go-exp.y @@ -1525,7 +1525,7 @@ go_language::parser (struct parser_state *par_state) const pstate = par_state; scoped_restore restore_yydebug = make_scoped_restore (&yydebug, - parser_debug); + par_state->debug); /* Initialize some state used by the lexer. */ last_was_structop = 0; diff --git a/gdb/parse.c b/gdb/parse.c index 2f014dd2172..bbe5cf12d37 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -62,7 +62,7 @@ show_expressiondebug (struct ui_file *file, int from_tty, /* True if an expression parser should set yydebug. */ -bool parser_debug; +static bool parser_debug; static void show_parserdebug (struct ui_file *file, int from_tty, diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h index 39046d04c8d..93ebdf5c061 100644 --- a/gdb/parser-defs.h +++ b/gdb/parser-defs.h @@ -32,8 +32,6 @@ struct language_defn; struct internalvar; class innermost_block_tracker; -extern bool parser_debug; - /* A class that can be used to build a "struct expression". */ struct expr_builder @@ -157,7 +155,8 @@ struct parser_state : public expr_builder block_tracker (tracker), comma_terminates ((flags & PARSER_COMMA_TERMINATES) != 0), parse_completion (completion), - void_context_p ((flags & PARSER_VOID_CONTEXT) != 0) + void_context_p ((flags & PARSER_VOID_CONTEXT) != 0), + debug ((flags & PARSER_DEBUG) != 0) { } @@ -303,6 +302,9 @@ struct parser_state : public expr_builder /* True if no value is expected from the expression. */ bool void_context_p; + /* True if parser debugging should be enabled. */ + bool debug; + private: /* Data structure for saving values of arglist_len for function calls whose From patchwork Thu May 4 14:21:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 68757 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 DD81D385773B for ; Thu, 4 May 2023 14:22:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD81D385773B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683210151; bh=V6A4st8Q8frJxRblwgkugDsYMnEpsVheuYZ0RNKTD9s=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=kT/9kI7rYN74N8S9bGCIwGMnlGMDeGBaX7v6cQtRndvRtQaypEJmA0UrxV8UTyPPE 8NpyfHvSPw9IzByQ1Arc9NmfJCJV88Zs0sd6MfJfvQH2owVH9STZlsP+G43/RL0X0a gKNpTjFKpwCuESNljhhbWtI8oy3h+qRb19kS+yqA= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by sourceware.org (Postfix) with ESMTPS id BE92A385734D for ; Thu, 4 May 2023 14:21:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BE92A385734D Received: by mail-il1-x12e.google.com with SMTP id e9e14a558f8ab-33119abae99so21104745ab.0 for ; Thu, 04 May 2023 07:21:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683210089; x=1685802089; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V6A4st8Q8frJxRblwgkugDsYMnEpsVheuYZ0RNKTD9s=; b=Mk4azK9zCKcJn3S/mUIQ06CRqnu7J7F9Gg3l9AWfcdTjy+a7drQZRndawUhuIdRUCx SCU/VgGivnulFZD8tCI6nLyBnH29LANaSv4ZQFubLov9sLJ+1X9fZ/iJ+saeVXLWTyMK JomwNJvS/iPcC9Y8mBBKnEclO14S2gtgwBjh+vlOQ2hSFbtxq+soCJXnMdRLEoNB34lp 4XgUeB3QfGBuw5PKI1m2ec6oeFqhtwU6bueSbXpMuD7e1CmQ/N/QL+sfa0zrHPILsMk0 WHWs8843oyczNBh1t1qzjF+EwQC52Kdyz34H/8lStfn7/xto2SCVnfyR4n0k4FMh+ZID yEOQ== X-Gm-Message-State: AC+VfDzrbDNO6Hf8KCPUsTec/srUO0fr/rTTB4AJS8xrr9Ae3XL2LHGC Az3msAcQYZAS/4IV2wFPEvcYIeGtvTKOAyjESApDmA== X-Google-Smtp-Source: ACHHUZ4bykuZ+ssRXb9C0sWEMYbx7WaX0bW708ln10hNhydf55FopUktv/95OTjvrxzRqXu41Epnrw== X-Received: by 2002:a6b:fd12:0:b0:769:b99d:f43e with SMTP id c18-20020a6bfd12000000b00769b99df43emr643299ioi.8.1683210088969; Thu, 04 May 2023 07:21:28 -0700 (PDT) Received: from localhost.localdomain (71-211-191-82.hlrn.qwest.net. [71.211.191.82]) by smtp.gmail.com with ESMTPSA id r16-20020a6b4410000000b00760a07e4e09sm9983384ioa.5.2023.05.04.07.21.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 07:21:28 -0700 (PDT) Date: Thu, 04 May 2023 08:21:29 -0600 Subject: [PATCH 08/11] Add PARSER_LEAVE_BLOCK_ALONE flag MIME-Version: 1.0 Message-Id: <20230504-frameless-v1-8-4191201740b0@adacore.com> References: <20230504-frameless-v1-0-4191201740b0@adacore.com> In-Reply-To: <20230504-frameless-v1-0-4191201740b0@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This adds a PARSER_LEAVE_BLOCK_ALONE flag, and changes the parse API to respect it. This flag lets callers avoid any change to the passed-in block and expression PC, letting them specify the context exactly. In particular, now nullptr can be used to indicate that the parse should not examine any local variables. --- gdb/expression.h | 6 ++++++ gdb/parse.c | 37 +++++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/gdb/expression.h b/gdb/expression.h index c485b159ef8..d1858776e8e 100644 --- a/gdb/expression.h +++ b/gdb/expression.h @@ -301,6 +301,12 @@ enum parser_flag it parses. For yacc-based parsers, this translates to setting yydebug. */ PARSER_DEBUG = (1 << 2), + + /* Normally the expression-parsing functions like parse_exp_1 will + attempt to find a context block if one is not passed in. If set, + this flag suppresses this search and uses a null context for the + parse. */ + PARSER_LEAVE_BLOCK_ALONE = (1 << 3), }; DEF_ENUM_FLAGS_TYPE (enum parser_flag, parser_flags); diff --git a/gdb/parse.c b/gdb/parse.c index bbe5cf12d37..221733a3f90 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -344,26 +344,31 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc, if (tracker == nullptr) tracker = &local_tracker; - /* If no context specified, try using the current frame, if any. */ - if (!expression_context_block) - expression_context_block = get_selected_block (&expression_context_pc); - else if (pc == 0) - expression_context_pc = expression_context_block->entry_pc (); - else - expression_context_pc = pc; + if ((flags & PARSER_LEAVE_BLOCK_ALONE) == 0) + { + /* If no context specified, try using the current frame, if any. */ + if (!expression_context_block) + expression_context_block + = get_selected_block (&expression_context_pc); + else if (pc == 0) + expression_context_pc = expression_context_block->entry_pc (); + else + expression_context_pc = pc; - /* Fall back to using the current source static context, if any. */ + /* Fall back to using the current source static context, if any. */ - if (!expression_context_block) - { - struct symtab_and_line cursal = get_current_source_symtab_and_line (); + if (!expression_context_block) + { + struct symtab_and_line cursal + = get_current_source_symtab_and_line (); - if (cursal.symtab) - expression_context_block - = cursal.symtab->compunit ()->blockvector ()->static_block (); + if (cursal.symtab) + expression_context_block + = cursal.symtab->compunit ()->blockvector ()->static_block (); - if (expression_context_block) - expression_context_pc = expression_context_block->entry_pc (); + if (expression_context_block) + expression_context_pc = expression_context_block->entry_pc (); + } } if (language_mode == language_mode_auto && block != NULL) From patchwork Thu May 4 14:21:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 68760 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 B6AFF3853556 for ; Thu, 4 May 2023 14:23:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B6AFF3853556 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683210181; bh=OJoOdEp/GWnx+pPk3NrURiBxXJb3ZYlfGmLc3wmqf3Q=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Sg6GCUbYdhfktxX6mQNk6aLLQecKOsfHD/Hfb+GtGTZseS1cCd30vCZ6kakij/jpn 7nLZ2Hb4gBD2eQ9JncOeoWMJY7JZhpgFnswyvGjPD2/Bz+QA7vsNoWieAlSF32ssS9 9/53GqlU1hlAeQRXJOk6b+THQAFM+gMtpVQblo1Q= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by sourceware.org (Postfix) with ESMTPS id 5896B385703C for ; Thu, 4 May 2023 14:21:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5896B385703C Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-763c3429abaso35093639f.1 for ; Thu, 04 May 2023 07:21:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683210089; x=1685802089; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OJoOdEp/GWnx+pPk3NrURiBxXJb3ZYlfGmLc3wmqf3Q=; b=QytBRH3Jd2HUYpfWTuD4VFoPCAOKw4qEBF7YCPvEhUKL6Xsf3UdOiBxVKJwhcL3kLD 02O9HjShkwR2PrWUXiF10MLrF0w/1t7jyGEOgr3ZnBDlxYdWVGsS+2litmNl+KunW+dg yPXpQW45vnPqTg/Y1j2x1aQbh1niPdn8k1JS95/JMtiB6qW+KQRBe/1BegjvKGQbeQVQ IgqUbUKOv9l2rxWe5k8oCZHT3edeRDEjXyYtQUd9j11a7tlRljOlVXcDa3dO4a7UJtuW KRCQ1S3NWF2HJ83HWCsF6fx4G2UmeRHye8PoRnDL1lRdodm/v4UsdUrQICUBk2iI8CVA lKMg== X-Gm-Message-State: AC+VfDz88pARyGhgNwoVJglWtmOCEgA3LKGpGbpyBNiRixsjqVdRF1ER UhMon8+L5WnenTDupsf7vji2c9zUNMoWbi2J0jnmEg== X-Google-Smtp-Source: ACHHUZ7UyZsn1P6sPHKSNag5JwSMU3lLfARtGlaWhBkUBgYeuutD9f6UNnwx/jVpZ14xDdMndyMv2g== X-Received: by 2002:a6b:4f11:0:b0:763:6b5a:cb1e with SMTP id d17-20020a6b4f11000000b007636b5acb1emr18704205iob.10.1683210089645; Thu, 04 May 2023 07:21:29 -0700 (PDT) Received: from localhost.localdomain (71-211-191-82.hlrn.qwest.net. [71.211.191.82]) by smtp.gmail.com with ESMTPSA id r16-20020a6b4410000000b00760a07e4e09sm9983384ioa.5.2023.05.04.07.21.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 07:21:29 -0700 (PDT) Date: Thu, 04 May 2023 08:21:30 -0600 Subject: [PATCH 09/11] Add flags to parse_and_eval MIME-Version: 1.0 Message-Id: <20230504-frameless-v1-9-4191201740b0@adacore.com> References: <20230504-frameless-v1-0-4191201740b0@adacore.com> In-Reply-To: <20230504-frameless-v1-0-4191201740b0@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This adds a flags parameter to parse_and_eval. --- gdb/eval.c | 4 ++-- gdb/value.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gdb/eval.c b/gdb/eval.c index d8d53c28686..457a6697923 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -67,9 +67,9 @@ parse_and_eval_long (const char *exp) } struct value * -parse_and_eval (const char *exp) +parse_and_eval (const char *exp, parser_flags flags) { - expression_up expr = parse_expression (exp); + expression_up expr = parse_expression (exp, nullptr, flags); return expr->evaluate (); } diff --git a/gdb/value.h b/gdb/value.h index d042d816409..a9c77a033ab 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -1313,7 +1313,7 @@ extern void fetch_subexp_value (struct expression *exp, std::vector *val_chain, bool preserve_errors); -extern struct value *parse_and_eval (const char *exp); +extern struct value *parse_and_eval (const char *exp, parser_flags flags = 0); extern struct value *parse_to_comma_and_eval (const char **expp); From patchwork Thu May 4 14:21:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 68763 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 ECD023853812 for ; Thu, 4 May 2023 14:23:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ECD023853812 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683210210; bh=QtrXtPAJ6PBcimlI9slFAtcLYFZsacjs3QzqXtI1gy8=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=pgGH5yYd56/CIHvAsUUz+whXqZQAS012zyTrg4sg7CDpe01Le5IN1Hem8MWwoxBmb q2xAcs2BZJTlhtP/2TBsRHm31hYZvp2sKbJIHmJ3nMH7X7uYZbEQwlDbZGTM08CN5u YduNHJMnHsfsr+bCuz5oQLYQc5fTaWZwiGOr8r5A= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by sourceware.org (Postfix) with ESMTPS id 1FD173858004 for ; Thu, 4 May 2023 14:21:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1FD173858004 Received: by mail-io1-xd32.google.com with SMTP id ca18e2360f4ac-760ecf3424bso10487839f.2 for ; Thu, 04 May 2023 07:21:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683210090; x=1685802090; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QtrXtPAJ6PBcimlI9slFAtcLYFZsacjs3QzqXtI1gy8=; b=a2oA5F3mFmr8+s8pdfxguJ4zlo2nN3cbC8HOGT0IuJPdWPo0vPFmxnUobs8u2+Phd3 Dfe1tCCCVDKHtlFsJF5QaWK29NMU7REIJsSpa2yyecnHZ+HXcZgFmE3bDvFiEEh376Y5 hppVjTU1l9RJtDgPvZo0eBIsxvTq1ytG4oZjJfvBuOdk6D+oeMR65Tts9w3kLuBtuJ49 5X1C3KnXvvJGES5CTY6inw9MW4i6f+ovhAc9LqP9x4qSbPxc2yGaIEssvIQUbcbKttgT nofyKJgW+vwpLaeTNUrAuISow5H6HCL+Ikx9rfkQTYQpeLX2n2SVOKdK+EKAvVTdfYzy cjFA== X-Gm-Message-State: AC+VfDx+cZVNvdBXDMxW9IJ6loBJX/FsQV6ebqJXny+Q2zoUzGqk+vfu 9HEYJCUrxMrz6bP020wsHABhmq5W9MZfHyssikrEaA== X-Google-Smtp-Source: ACHHUZ5/r9Ni7ltSL1kLVdsnY1fC4HfHpk3hCeu345mBrYjwqeTKMpgqm/e1WwTgtdlb2T3CY8IBOA== X-Received: by 2002:a5d:9a06:0:b0:763:92eb:f81e with SMTP id s6-20020a5d9a06000000b0076392ebf81emr15868021iol.8.1683210090309; Thu, 04 May 2023 07:21:30 -0700 (PDT) Received: from localhost.localdomain (71-211-191-82.hlrn.qwest.net. [71.211.191.82]) by smtp.gmail.com with ESMTPSA id r16-20020a6b4410000000b00760a07e4e09sm9983384ioa.5.2023.05.04.07.21.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 07:21:29 -0700 (PDT) Date: Thu, 04 May 2023 08:21:31 -0600 Subject: [PATCH 10/11] Add global_context parameter to gdb.parse_and_eval MIME-Version: 1.0 Message-Id: <20230504-frameless-v1-10-4191201740b0@adacore.com> References: <20230504-frameless-v1-0-4191201740b0@adacore.com> In-Reply-To: <20230504-frameless-v1-0-4191201740b0@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This adds a 'global_context' parse_and_eval to gdb.parse_and_eval. This lets users request a parse that is done at "global scope". I considered letting callers pass in a block instead, with None meaning "global" -- but then there didn't seem to be a clean way to express the default for this parameter. Reviewed-By: Eli Zaretskii --- gdb/NEWS | 4 ++++ gdb/doc/python.texi | 7 ++++++- gdb/python/python.c | 28 ++++++++++++++++++++++------ gdb/testsuite/gdb.python/py-value.c | 3 +++ gdb/testsuite/gdb.python/py-value.exp | 5 +++++ 5 files changed, 40 insertions(+), 7 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index e3c095de09e..4bf5603b550 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -162,6 +162,10 @@ info main (program-counter) values, and can be used as the frame-id when calling gdb.PendingFrame.create_unwind_info. + ** gdb.parse_and_eval now has a new "global_context" parameter. + This can be used to request that the parse only examine global + symbols. + *** Changes in GDB 13 * MI version 1 is deprecated, and will be removed in GDB 14. diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 7c3a3ccd379..dca16bb84e0 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -419,11 +419,16 @@ using the @code{gdb.Value} constructor. @end defun @findex gdb.parse_and_eval -@defun gdb.parse_and_eval (expression) +@defun gdb.parse_and_eval (expression, @r{[}, global_context@r{]}) Parse @var{expression}, which must be a string, as an expression in the current language, evaluate it, and return the result as a @code{gdb.Value}. +@var{global_context}, if provided, is a boolean indicating whether the +parsing should be done in the global context. The default is +@samp{False}, meaning that the current frame or current static context +should be used. + This function can be useful when implementing a new command (@pxref{CLI Commands In Python}, @pxref{GDB/MI Commands In Python}), as it provides a way to parse the diff --git a/gdb/python/python.c b/gdb/python/python.c index 168a0009f1b..42bb2ed34b1 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -969,19 +969,34 @@ gdbpy_decode_line (PyObject *self, PyObject *args) /* Parse a string and evaluate it as an expression. */ static PyObject * -gdbpy_parse_and_eval (PyObject *self, PyObject *args) +gdbpy_parse_and_eval (PyObject *self, PyObject *args, PyObject *kw) { + static const char *keywords[] = { "expression", "global_context", nullptr }; + const char *expr_str; + PyObject *global_context_obj = nullptr; - if (!PyArg_ParseTuple (args, "s", &expr_str)) - return NULL; + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O!", keywords, + &expr_str, + &PyBool_Type, &global_context_obj)) + return nullptr; + + parser_flags flags = 0; + if (global_context_obj != NULL) + { + int cmp = PyObject_IsTrue (global_context_obj); + if (cmp < 0) + return nullptr; + if (cmp) + flags |= PARSER_LEAVE_BLOCK_ALONE; + } PyObject *result = nullptr; try { gdbpy_allow_threads allow_threads; scoped_value_mark free_values; - struct value *val = parse_and_eval (expr_str); + struct value *val = parse_and_eval (expr_str, flags); result = value_to_value_object (val); } catch (const gdb_exception &except) @@ -2591,8 +2606,9 @@ The first element contains any unparsed portion of the String parameter\n\ (or None if the string was fully parsed). The second element contains\n\ a tuple that contains all the locations that match, represented as\n\ gdb.Symtab_and_line objects (or None)."}, - { "parse_and_eval", gdbpy_parse_and_eval, METH_VARARGS, - "parse_and_eval (String) -> Value.\n\ + { "parse_and_eval", (PyCFunction) gdbpy_parse_and_eval, + METH_VARARGS | METH_KEYWORDS, + "parse_and_eval (String, [Boolean]) -> Value.\n\ Parse String as an expression, evaluate it, and return the result as a Value." }, diff --git a/gdb/testsuite/gdb.python/py-value.c b/gdb/testsuite/gdb.python/py-value.c index 5a578de5d50..f0b1f5f160c 100644 --- a/gdb/testsuite/gdb.python/py-value.c +++ b/gdb/testsuite/gdb.python/py-value.c @@ -79,6 +79,8 @@ int func2 (int arg1, int arg2) char **save_argv; +int shadowed = 23; + int main (int argc, char *argv[]) { @@ -96,6 +98,7 @@ main (int argc, char *argv[]) int i = 2; int *ptr_i = &i; struct str *xstr; + int shadowed = 97; /* Prevent gcc from optimizing argv[] out. */ diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp index 898208b90d1..9fc25814721 100644 --- a/gdb/testsuite/gdb.python/py-value.exp +++ b/gdb/testsuite/gdb.python/py-value.exp @@ -338,6 +338,11 @@ proc test_value_in_inferior {} { gdb_py_test_silent_cmd "python str = '\"str\"'" "set up str variable" 1 gdb_test "python print (gdb.parse_and_eval (str).string (length = 10))" \ "gdb.error: Attempt to take address of value not located in memory.\r\nError while executing Python code." + + gdb_test "python print (gdb.parse_and_eval ('shadowed'))" \ + 97 "shadowed local value" + gdb_test "python print (gdb.parse_and_eval ('shadowed', global_context=True))" \ + 23 "shadowed global value" } proc test_inferior_function_call {} { From patchwork Thu May 4 14:21:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 68761 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 E1314384F024 for ; Thu, 4 May 2023 14:23:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E1314384F024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683210182; bh=SIfbXdHvoF9HB0AZHtpJGbUzPgxQan49lnp1x06IcxI=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=kKRh4u7tCcQWod5UcliVZxkeSnmwLGmy9Ar3k9yCG+9vi+N25e5/8MjBLLthecILw 9HtuKUC7mAQWGEaH1T14ELoTwTs2f0CvPs3aCvYG3TltuyjXG1e1GzgL9vSMzkharh w3LTeww2PY/tBLiVvDMNGiHMM6vpJVFLC6ibX0gQ= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by sourceware.org (Postfix) with ESMTPS id 2C1493857029 for ; Thu, 4 May 2023 14:21:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C1493857029 Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-760ecf3424bso10487939f.2 for ; Thu, 04 May 2023 07:21:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683210091; x=1685802091; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SIfbXdHvoF9HB0AZHtpJGbUzPgxQan49lnp1x06IcxI=; b=K5MjwrCHzuwc4LfWVMn8luC8t9BbRiP/oWP572y239+8xp1slKN5M3K6LZ2jcGbBOk 7WOB+kCBgOaRZIrJx0W2AFjlWopEC6Fbkjp6aIYLJ+Zkn08ranaMsO3UohzUMn/kmCtX 7SW8I/ADnntd/oT4znuZ5DbA/oEeCgEhehC/Z6sx2ksMHlwyOVhD1Y6pxdw7EKYgcLzd 5q7z/h1uhHgGQI9cFTbvBgLcbV7ADBB6H8x9ed1z+0jZcvfV9pQY+HGlqrm4iIkcNv/j ZB1i7A0k2w9nxosGrQ/vRQTYgYIS94K8YI6Lhm7P3VtAK7RYI9gdx/MlQsb74LszM91V /2xA== X-Gm-Message-State: AC+VfDxdcxH4ubKEDYOjBfxURgqmewCycnW1P+kZhFRicFVs14FVLPLv eKIxTErKx6Cy5YypOcDaXg0KGa9xh+IJYi6EDNvlaQ== X-Google-Smtp-Source: ACHHUZ43Z1itGu6lQ4Gih6VXuCvA+7PkCR46kFur3WTlvLmeb3B2M4KqHtdjpCW4fx9XLbWQQ0a35Q== X-Received: by 2002:a5e:dd03:0:b0:763:dbe5:c718 with SMTP id t3-20020a5edd03000000b00763dbe5c718mr14669713iop.4.1683210091066; Thu, 04 May 2023 07:21:31 -0700 (PDT) Received: from localhost.localdomain (71-211-191-82.hlrn.qwest.net. [71.211.191.82]) by smtp.gmail.com with ESMTPSA id r16-20020a6b4410000000b00760a07e4e09sm9983384ioa.5.2023.05.04.07.21.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 07:21:30 -0700 (PDT) Date: Thu, 04 May 2023 08:21:32 -0600 Subject: [PATCH 11/11] Handle DAP evaluate request without a frame ID MIME-Version: 1.0 Message-Id: <20230504-frameless-v1-11-4191201740b0@adacore.com> References: <20230504-frameless-v1-0-4191201740b0@adacore.com> In-Reply-To: <20230504-frameless-v1-0-4191201740b0@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" DAP specifies that if an evaluate request does not have a frameID parameter, then the expression is evaluated in the global scope. --- gdb/python/lib/gdb/dap/evaluate.py | 4 ++- gdb/testsuite/gdb.dap/frameless.c | 24 ++++++++++++++ gdb/testsuite/gdb.dap/frameless.exp | 62 +++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) diff --git a/gdb/python/lib/gdb/dap/evaluate.py b/gdb/python/lib/gdb/dap/evaluate.py index 55d41b0806d..8ed2402d916 100644 --- a/gdb/python/lib/gdb/dap/evaluate.py +++ b/gdb/python/lib/gdb/dap/evaluate.py @@ -30,10 +30,12 @@ class EvaluateResult(VariableReference): # Helper function to evaluate an expression in a certain frame. @in_gdb_thread def _evaluate(expr, frame_id): + global_context = True if frame_id is not None: frame = frame_for_id(frame_id) frame.select() - val = gdb.parse_and_eval(expr) + global_context = False + val = gdb.parse_and_eval(expr, global_context=global_context) ref = EvaluateResult(val) return ref.to_object() diff --git a/gdb/testsuite/gdb.dap/frameless.c b/gdb/testsuite/gdb.dap/frameless.c new file mode 100644 index 00000000000..fd17ad46dc2 --- /dev/null +++ b/gdb/testsuite/gdb.dap/frameless.c @@ -0,0 +1,24 @@ +/* Copyright 2023 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int variable = 23; + +int main () +{ + int variable = 97; + return 0; /* BREAK */ +} diff --git a/gdb/testsuite/gdb.dap/frameless.exp b/gdb/testsuite/gdb.dap/frameless.exp new file mode 100644 index 00000000000..3fb33467c94 --- /dev/null +++ b/gdb/testsuite/gdb.dap/frameless.exp @@ -0,0 +1,62 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test frameless evaluation in DAP. + +require allow_dap_tests + +load_lib dap-support.exp + +standard_testfile + +if {[build_executable ${testfile}.exp $testfile] == -1} { + return +} + +if {[dap_launch $testfile] == ""} { + return +} + +set line [gdb_get_line_number "BREAK"] +set obj [dap_check_request_and_response "set breakpoint by line number" \ + setBreakpoints \ + [format {o source [o path [%s]] breakpoints [a [o line [i %d]]]} \ + [list s $srcfile] $line]] +set line_bpno [dap_get_breakpoint_number $obj] + +dap_check_request_and_response "start inferior" configurationDone +dap_wait_for_event_and_check "inferior started" thread "body reason" started + +dap_wait_for_event_and_check "stopped at line breakpoint" stopped \ + "body reason" breakpoint \ + "body hitBreakpointIds" $line_bpno + +set bt [lindex [dap_check_request_and_response "backtrace" stackTrace \ + {o threadId [i 1]}] \ + 0] +set frame_id [dict get [lindex [dict get $bt body stackFrames] 0] id] + +set obj [dap_check_request_and_response "evaluate variable in function" \ + evaluate [format {o expression [s variable] frameId [i %s]} \ + $frame_id]] +dap_match_values "variable value in function" [lindex $obj 0] \ + "body result" 97 + +set obj [dap_check_request_and_response "evaluate variable globally" \ + evaluate {o expression [s variable]}] +dap_match_values "variable value globally" [lindex $obj 0] \ + "body result" 23 + +dap_shutdown