From patchwork Thu Aug 22 15:47:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Rische X-Patchwork-Id: 96321 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 C2AB83875465 for ; Thu, 22 Aug 2024 15:48:40 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-40141.protonmail.ch (mail-40141.protonmail.ch [185.70.40.141]) by sourceware.org (Postfix) with ESMTPS id 7137D3871037 for ; Thu, 22 Aug 2024 15:47:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7137D3871037 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=protonmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7137D3871037 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=185.70.40.141 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724341687; cv=none; b=IyrB5U72NzFj7Jpk3+08zl+OQT+TGf4EOb8DZJ5RAdNt+Fxr+4SomRFph8+AI/rxJEnltyUyYxmFZh2ftbhuvZ8VsNgVecsBR/xoQ1aaKxeSA6bUBnQG+ejwJmalf/MrevBJC8OQ1a2vH3VmcxyA2BvOkXYdzxlHEBbATkyDuA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724341687; c=relaxed/simple; bh=xu868nKAhyWNQytUIchkWkAm2+yMntEDHXIBynTdbaI=; h=DKIM-Signature:Date:To:From:Subject:Message-ID:MIME-Version; b=idLjJfcG3O7sPPM51Z5BjkGv/KYt3+aZByngvfa7gZFxDfEJwkNharFG3Lgh2OnwdzCSLo9TR3Xf6JrVP5se+LYE7M5PET7DaNypScnXQZmMEyTMS+fKtHGcGKUAb5rTCaJOmKnVCSr7ofZmh650wMtdaryIf/OjqiC63T8ZLzE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1724341674; x=1724600874; bh=/Ta6Zz0UtaOli742i9bt97iPL0LPSEhQAUuCkH9FQ7Q=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=u2mBmnzCJYEraIjtKS8VpTy/igKngjBZDSoh7G9ODgLopkXzPnIslfuj763QwqFBP +XgNmwV7Q/O7toTYAhX07HhLzw3NLJH+zUq7lJYrGmwPmvk91tnoOZKV5QR2N4Avmf 7jwRYZHr8R8ERQgz5JdTaIzRFpLe2iWEdadY5NoepiPk4drybO1zyNS23LXAfYxZ43 LCUQ/26aEFucsWZoi60CHtMuFpJeyNXc+ifMI99/nXS+SkiIfsQ50NvenKw6oY+hL0 XNdY6kkVPYrTNJBNY/BZVn14tFjZGkFx2O0Ko/StR28SdMBdj983gi1np9+B48D+/Y bpCRkya3BrMDQ== Date: Thu, 22 Aug 2024 15:47:48 +0000 To: gdb-patches@sourceware.org From: Antonio Rische Cc: Antonio Rische Subject: [PATCH 1/2] gdb: Do not create variables when parsing expressions Message-ID: <20240822154730.1595141-2-nt8r@protonmail.com> In-Reply-To: <20240822154730.1595141-1-nt8r@protonmail.com> References: <20240822154730.1595141-1-nt8r@protonmail.com> Feedback-ID: 21706885:user:proton X-Pm-Message-ID: 48f85c9ca551a676254ed904d3173e90dd4f90d1 MIME-Version: 1.0 X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, 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.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 is not particularly useful on its own, but allows us to parse expressions without having side-effects on the set of internalvars. This will then allow us to tab-complete internalvars in expressions without creating new internalvars, which would otherwise defeat the purpose of tab completion (completing only variables that have been set). --- gdb/ax-gdb.c | 25 +++++++++++++++++++++++ gdb/cli/cli-utils.c | 2 +- gdb/expop.h | 48 ++++++++++++++++++++++++++++++++++++++++++++- gdb/parse.c | 3 +-- 4 files changed, 74 insertions(+), 4 deletions(-) diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index 3d619012b..7853aa444 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -1668,6 +1668,31 @@ register_operation::do_generate_ax (struct expression *exp, value->type = register_type (ax->gdbarch, reg); } +void +uninit_internalvar_operation::do_generate_ax (struct expression *exp, + struct agent_expr *ax, + struct axs_value *value, + struct type *cast_type) +{ + const char *name = get_name (); + struct internalvar *var = lookup_only_internalvar(name); + struct trace_state_variable *tsv; + + tsv = find_trace_state_variable (name); + if (tsv) + { + ax_tsv (ax, aop_getv, tsv->number); + if (ax->tracing) + ax_tsv (ax, aop_tracev, tsv->number); + /* Trace state variables are always 64-bit integers. */ + value->kind = axs_rvalue; + value->type = builtin_type (ax->gdbarch)->builtin_long_long; + } + else if (! compile_internalvar_to_ax (var, ax, value)) + error (_("$%s is not a trace state variable; GDB agent " + "expressions cannot use convenience variables."), name); +} + void internalvar_operation::do_generate_ax (struct expression *exp, struct agent_expr *ax, diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c index 45b30842e..7dedb3829 100644 --- a/gdb/cli/cli-utils.c +++ b/gdb/cli/cli-utils.c @@ -49,7 +49,7 @@ get_ulongest (const char **pp, int trailer) while (isalnum (*p) || *p == '_') p++; std::string varname (start, p - start); - if (!get_internalvar_integer (lookup_internalvar (varname.c_str ()), + if (!get_internalvar_integer (lookup_only_internalvar (varname.c_str ()), &retval)) error (_("Convenience variable $%s does not have integer value."), varname.c_str ()); diff --git a/gdb/expop.h b/gdb/expop.h index 2d46a9dad..f0cc8dbb1 100644 --- a/gdb/expop.h +++ b/gdb/expop.h @@ -878,6 +878,42 @@ class bool_operation { return true; } }; +/* Reference to a variable that had not been defined at parse time. */ +class uninit_internalvar_operation + : public tuple_holding_operation +{ +public: + + using tuple_holding_operation::tuple_holding_operation; + + value *evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) override + { + internalvar* iv = lookup_only_internalvar(std::get<0> (m_storage).c_str ()); + if (!iv) { + return value::allocate (builtin_type (exp->gdbarch)->builtin_void); + } + return value_of_internalvar (exp->gdbarch, iv); + } + + const char *get_name () const + { + return std::get<0> (m_storage).c_str (); + } + + enum exp_opcode opcode () const override + { return OP_INTERNALVAR; } + +protected: + + void do_generate_ax (struct expression *exp, + struct agent_expr *ax, + struct axs_value *value, + struct type *cast_type) + override; +}; + class internalvar_operation : public tuple_holding_operation { @@ -1891,7 +1927,17 @@ class assign_operation struct expression *exp, enum noside noside) override { - value *lhs = std::get<0> (m_storage)->evaluate (nullptr, exp, noside); + operation *lhs_op = std::get<0> (m_storage).get(); + + /* If the operation is an internalvar that was not initialized at + parse time, ensure that it exists. */ + auto *uninit_var_op = dynamic_cast (lhs_op); + if (uninit_var_op) { + lookup_internalvar (uninit_var_op->get_name()); + } + + value *lhs = lhs_op->evaluate (nullptr, exp, noside); + /* Special-case assignments where the left-hand-side is a convenience variable -- in these, don't bother setting an expected type. This avoids a weird case where re-assigning a diff --git a/gdb/parse.c b/gdb/parse.c index e0837de7b..19e2504f9 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -242,8 +242,7 @@ parser_state::push_dollar (struct stoken str) /* Any other names are assumed to be debugger internal variables. */ - push_new - (create_internalvar (copy.c_str () + 1)); + push_new (copy.c_str () + 1); } /* See parser-defs.h. */ From patchwork Thu Aug 22 15:47:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Rische X-Patchwork-Id: 96322 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 99AE13875452 for ; Thu, 22 Aug 2024 15:49:01 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-4319.protonmail.ch (mail-4319.protonmail.ch [185.70.43.19]) by sourceware.org (Postfix) with ESMTPS id 28E103875440 for ; Thu, 22 Aug 2024 15:48:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 28E103875440 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=protonmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 28E103875440 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=185.70.43.19 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724341695; cv=none; b=S6+YJVyffq365cRJ0BsfY0NuEiZM+eGad+WSxblkGKH1bQ6Nijo6v9RLBhCFG4EViYlLkDFOc5HxsOeb1AhwQiKr6J8gVFY/zOuu4nCs5Gk3jP6pFHDam4xrbRCgtQXrwFsqp6HqPXdwEZeYgAL1YnEKlv8e/GcjU/wdOHJPLZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724341695; c=relaxed/simple; bh=1+n1GUKsowABhdfPJzNpb/9d0v83AqRJkR14SbWsj8M=; h=DKIM-Signature:Date:To:From:Subject:Message-ID:MIME-Version; b=Bcds6KIdbrPCcbrWXdpeRi0wzVM+mOFYzf5QuWYBFtzORWHEazZlC1eioYJBo4N133RCLH+sx07iKYxA4KwFHU6EspJWVJ7LMzsgrP/EkFYjgc25GHxc55bfeP65dnRYkQZ34NJTYLL1Scc5LBVET1XIOtj0tPTzd7/XEAKHJn4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1724341683; x=1724600883; bh=wKc0eyG8hjBkTxB0m6tkcp5DqlGJrzFtj2qaOzvRSRU=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=B4s2n9rDVxk7yIyIDlhjTNtJ7vL6DdtroJwi2xiQ9J5X5aEdZFVHTgHR+2zsU2Xt2 lc5wCUsA9DP+Hs88f9LTxtsgsJsO7Nq1PgAtfI3W1WQKbtGLmPwtmrMjZJuVQXYsA5 Og8LAWcxRnEqCEvjTnIDms+TtLJLeJ5R2/IT+7OvoOKR9yN+QjR7onDv59b3RV4SIF 4aISOBXg5UiexCCGeQ6oAkhllONBI4ZtRv2clEKdBGpKd7XJQK6i4xCSvRr00FB5K1 kks9jybTr/eBaS/MvVNoZm5RFEwbHKIjTEDL/HhPAB2UgaoIK4Z6lfhO9rkl1wxlUl 1GR+ar6hJAzJg== Date: Thu, 22 Aug 2024 15:47:57 +0000 To: gdb-patches@sourceware.org From: Antonio Rische Cc: Antonio Rische Subject: [PATCH 2/2] gdb: Tab complete internalvars in expressions Message-ID: <20240822154730.1595141-3-nt8r@protonmail.com> In-Reply-To: <20240822154730.1595141-1-nt8r@protonmail.com> References: <20240822154730.1595141-1-nt8r@protonmail.com> Feedback-ID: 21706885:user:proton X-Pm-Message-ID: 9005bf3aca8055571f946f8960cd880f835047c6 MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, 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.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 For example, 'print $f' after running 'set $foo=0' now tab completes. 'print $_siginf' also now tab completes. --- gdb/completer.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gdb/completer.c b/gdb/completer.c index 1008ec23b..6476ddf79 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -1099,6 +1099,16 @@ complete_expression (completion_tracker &tracker, && expr_completer->complete (exp.get (), tracker)) return; + if (text[0] == '$') + { + tracker.advance_custom_word_point_by (1); + /* We don't support completion of history indices. */ + if (!isdigit (text[1])) + complete_internalvar (tracker, &text[1]); + tracker.advance_custom_word_point_by (-1); + return; + } + complete_files_symbols (tracker, text, word); }