From patchwork Sat Apr 27 08:52:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= X-Patchwork-Id: 89072 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 9C43A3858C50 for ; Sat, 27 Apr 2024 08:53:06 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail0.khirnov.net (mail0.khirnov.net [IPv6:2001:67c:1138:4304::3]) by sourceware.org (Postfix) with ESMTPS id 930E23858D28 for ; Sat, 27 Apr 2024 08:52:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 930E23858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=khirnov.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=khirnov.net ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 930E23858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:67c:1138:4304::3 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714207962; cv=none; b=kUtlmThf1AHTiuGBxSm54E1lhLkS4s2bqTh1hncuxYFxNLeafhpNHh1oUrmoBEweAgmjhnW/RvqnlEy6o2L/yjm5ldm0jEMOw1RKIotZxtmwFufU1pk3WuxeBnBF/CdSKj121ACLDnozrLRY7SMjO+pt/GtOdohe1C/bqkSbSWE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714207962; c=relaxed/simple; bh=mSNXgH/o9pVlHDgx5EORxB5hQ0neidjGGXA3pOvsmYg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=R5UCO2kssntOu6Vn1B6vsNFP1LZYiS2Ajy3vgKrfu8UneF4XGo6tYfjl7t8iKUw1jUX0o7ql/DNkCugkSNV8HnGw+tiMbDZQMwE6Hz1JER4YqAbYkXyoih36eMX+2FF4C0i0RigAIflpdyPcElveIZNRS8HDp1/e5nQXJR+JxtU= ARC-Authentication-Results: i=1; server2.sourceware.org Authentication-Results: mail0.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=F6zv5BO6; dkim-atps=neutral Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id B2800240DAC; Sat, 27 Apr 2024 10:52:36 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id gtIuacAHnI6o; Sat, 27 Apr 2024 10:52:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1714207954; bh=mSNXgH/o9pVlHDgx5EORxB5hQ0neidjGGXA3pOvsmYg=; h=From:To:Cc:Subject:Date:From; b=F6zv5BO6/BAAIZumhOUNnM1dfy3FtOaegmosVyyOQ5vcDvSRMuCVYvkJTEXQQfDzY 1RdbMudkQduMNG+YhMViyWqS+ULWEnTbT+W/GECToeys/D4ssN5zcPvLkVYwPcGoRz PKSlqvufQrxRTuovuvrKqbHDCxyY4vdVXac4zXA/qhjQT0FIk7SB8S9og2nEzcLSnA r4f3Lae6sgr/KoYfkGWmwcZGHybFMIwb5H0T7ClbqAE+4EdPWQG3J9JEMDYUzJPKjy FvTmpyX7lTkNj6FfZc8pB295uYUdRurhusdBUBhIfB1qkH3VIF1AekOuLGwu0fiDYS RqeEe5OyhCawQ== Received: from fedora.khirnov.net (ip-244-183.pel.cz [IPv6:2002:b061:f0a:201::d5e2:f4b7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "sasshka SMTP cert", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 0E8F52404E5; Sat, 27 Apr 2024 10:52:34 +0200 (CEST) Received: from fedora.redhat.com (localhost [IPv6:::1]) by fedora.khirnov.net (Postfix) with ESMTP id AFF7C869692; Sat, 27 Apr 2024 10:52:27 +0200 (CEST) From: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= To: gdb-patches@sourceware.org Cc: ahajkova@redhat.com Subject: [PATCH] Add "error_message+" feature to qSupported Date: Sat, 27 Apr 2024 10:52:26 +0200 Message-ID: <20240427085226.2087243-1-ahajkova@khirnov.net> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, SPF_HELO_NONE, SPF_PASS, TXREP 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 From: Alexandra Hájková Check if the gdbserver GDB is communicating with supports responding with the error message in an E.message format to GDB's packets. Add a new 'error_message' feature to the qSupported packet. When GDB and gdbserver support this feature then gdbserver is able to send errors in the E.message format for the qRcmd and m packets. Update qRcmd packet and m packets documentation as qRcmd newly accepts errors in a E.message format. Previously these two packets didn't support E.message style errors. Reviewed-By: Eli Zaretskii --- gdb/doc/gdb.texinfo | 27 ++++++++++++++++++++++ gdb/remote.c | 56 +++++++++++++++++++++++++++++++++++++++++++-- gdbserver/server.cc | 6 +++++ gdbserver/server.h | 5 ++++ 4 files changed, 92 insertions(+), 2 deletions(-) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 92731c510b2..c589c05db58 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -42888,6 +42888,11 @@ Reply: Memory contents; each byte is transmitted as a two-digit hexadecimal number. The reply may contain fewer addressable memory units than requested if the server was able to read only part of the region of memory. +@item E @var{NN} +@var{NN} is errno +@item E.errtext +Alternatively, an error can be sent as a string. This reply is only valid +if the 'accept-error-message' feature (@pxref{accept-error-message}) is enabled. @end table Unlike most packets, this packet does not support @@ -44398,6 +44403,13 @@ Reply: A command response with no output. @item @var{OUTPUT} A command response with the hex encoded output string @var{OUTPUT}. +@item E @var{NN} +Indicate a badly formed request. The error number @var{NN} is given as +hex digits. +@item E.errtext +Alternatively, an error can be sent as a string. This reply is only valid +if the 'accept-error-message' feature (@pxref{accept-error-message}) is enabled. +@item @w{} @end table Unlike most packets, this packet does not support @@ -44549,6 +44561,17 @@ including @samp{exec-events+} in its @samp{qSupported} reply. @item vContSupported This feature indicates whether @value{GDBN} wants to know the supported actions in the reply to @samp{vCont?} packet. + +@anchor{accept-error-message} +@item accept-error-message +This feature indicates whether @value{GDBN} supports accepting +a reply to a request in an @code{E.message} format including +@samp{accept-error-message+} in its @samp{qSupported} reply. This +feature only covers the @code{qRcmd} and @code{m} packets, and exists for +backwards compatibility reasons. Those packets, historically, didn't support +@code{E.message}. New packets should be written to support +@code{E.message} regardless of this feature being true or not. + @end table Stubs should ignore any unknown values for @@ -45065,6 +45088,10 @@ inspected, if @samp{qIsAddressTagged} (@pxref{qIsAddressTagged}) packet is not supported by the stub. Access to the @file{/proc/@var{pid}/smaps} file is done via @samp{vFile} requests. +@item accept-error-message +The remote stub supports replying with an error in a +@code{E.message} format. + @end table @item qSymbol:: diff --git a/gdb/remote.c b/gdb/remote.c index d425e558422..1cc445a0de3 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -377,6 +377,18 @@ enum { /* Support for the qIsAddressTagged packet. */ PACKET_qIsAddressTagged, + /* Support for accepting error message in a E.message format. + This allows every remote packet to return E.message. + + This feature only exists to fix a backwards compatibility issue + with the qRcmd and m packets. Historically, these two packets didn't + support E.message style errors, but when this feature is on + these two packets can receive E.message style errors. + + All new packets should be written to always accepts E.message style + errors, and so they should not need to check for this feature. */ + PACKET_accept_error_message, + PACKET_MAX }; @@ -798,6 +810,21 @@ struct remote_features bool remote_memory_tagging_p () const { return packet_support (PACKET_memory_tagging_feature) == PACKET_ENABLE; } + /* Returns true if accepting E.message in the packet response is supported, + false otherwise. + + Don't call this function. This function, and the feature it wraps + around only exists to fix a backwards compatibility issue with the + qRcmd and m packets. Historically, these two packets didn't + support E.message style errors, but when this feature is on (this + function returns true) these two packets can receive E.message style + errors. + + All new packets should be written to always accepts E.message style + errors, and so they should not need to check for this feature. */ + bool accept_error_message_p () const + { return packet_support (PACKET_accept_error_message) == PACKET_ENABLE; } + /* Reset all packets back to "unknown support". Called when opening a new connection to a remote target. */ void reset_all_packet_configs_support (); @@ -1389,6 +1416,20 @@ class remote_target : public process_stratum_target bool start_remote_1 (int from_tty, int extended_p); + /* Don't call this function. This function, and the feature it wraps + around only exists to fix a backwards compatibility issue with the + qRcmd and m packets. Historically, these two packets didn't + support E.message style errors, but when this feature is on (this + function returns true) these two packets can receive E.message style + errors. + + All new packets should be written to always accepts E.message style + errors, and so they should not need to check for this feature. */ + bool supports_error_message () + { + return m_features.accept_error_message_p (); + } + /* The remote state. Don't reference this directly. Use the get_remote_state method instead. */ remote_state m_remote_state; @@ -5815,6 +5856,8 @@ static const struct protocol_feature remote_protocol_features[] = { { "no-resumed", PACKET_DISABLE, remote_supported_packet, PACKET_no_resumed }, { "memory-tagging", PACKET_DISABLE, remote_supported_packet, PACKET_memory_tagging_feature }, + { "accept-error-message", PACKET_DISABLE, remote_supported_packet, + PACKET_accept_error_message }, }; static char *remote_support_xml; @@ -5933,6 +5976,10 @@ remote_target::remote_query_supported () != PACKET_DISABLE)) remote_query_supported_append (&q, remote_support_xml); + if (m_features.packet_set_cmd_state (PACKET_accept_error_message) + != AUTO_BOOLEAN_FALSE) + remote_query_supported_append (&q, "error_message+"); + q = "qSupported:" + q; putpkt (q.c_str ()); @@ -9649,7 +9696,8 @@ remote_target::remote_read_bytes_1 (CORE_ADDR memaddr, gdb_byte *myaddr, *p = '\0'; putpkt (rs->buf); getpkt (&rs->buf); - packet_result result = packet_check_result (rs->buf, false); + packet_result result = packet_check_result (rs->buf, + supports_error_message ()); if (result.status () == PACKET_ERROR) return TARGET_XFER_E_IO; /* Reply describes memory byte by byte, each byte encoded as two hex @@ -11996,7 +12044,8 @@ remote_target::rcmd (const char *command, struct ui_file *outbuf) remote_console_output (buf + 1); /* 'O' message from stub. */ continue; } - packet_result result = packet_check_result (buf, false); + packet_result result = packet_check_result (buf, + supports_error_message ()); if (strcmp (buf, "OK") == 0) break; else if (result.status () == PACKET_UNKNOWN) @@ -16255,6 +16304,9 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL, add_packet_config_cmd (PACKET_qIsAddressTagged, "qIsAddressTagged", "memory-tagging-address-check", 0); + add_packet_config_cmd (PACKET_accept_error_message, + "accept-error-message", "accept-error-message", 0); + /* Assert that we've registered "set remote foo-packet" commands for all packet configs. */ { diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 789af36d9a4..3aac361f39d 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -2710,6 +2710,8 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p) if (target_supports_memory_tagging ()) cs.memory_tagging_feature = true; } + else if (feature == "error_message+") + cs.error_message_supported = true; else { /* Move the unknown features all together. */ @@ -2839,6 +2841,9 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p) if (target_supports_memory_tagging ()) strcat (own_buf, ";memory-tagging+"); + if (cs.error_message_supported) + strcat (own_buf, ";accept-error-message+"); + /* Reinitialize components as needed for the new connection. */ hostio_handle_new_gdb_connection (); target_handle_new_gdb_connection (); @@ -4375,6 +4380,7 @@ captured_main (int argc, char *argv[]) cs.hwbreak_feature = 0; cs.vCont_supported = 0; cs.memory_tagging_feature = false; + cs.error_message_supported = false; remote_open (port); diff --git a/gdbserver/server.h b/gdbserver/server.h index 0074818c6df..c39241c960d 100644 --- a/gdbserver/server.h +++ b/gdbserver/server.h @@ -192,6 +192,11 @@ struct client_state /* If true, memory tagging features are supported. */ bool memory_tagging_feature = false; + /* If true then E.message style errors are supported everywhere, + including for the qRcmd and m packet. When false E.message errors + are not supported with qRcmd and m packets, but are still supported + everywhere else. This is for backward compatibility reasons. */ + bool error_message_supported = false; }; client_state &get_client_state ();