From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 599CE3858D28 for ; Mon, 26 Feb 2024 13:15:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 599CE3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 599CE3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708953348; cv=none; b=eaKaovZKWfS2OLzlTCbo7YlaGtqGEMAUrtsO0uuV8+9NVEXnOKlC3SCYSHAsKFy75ClV8mcBj+KTFbeNYQL8BKkUD6x4kEOSo0o2Jp8ZbUsHU9wwDjpvybicA1ej/kebroSeCPvS6cztBATRC6yngI5V38tol/fmjVcTB5K6Tmw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708953348; c=relaxed/simple; bh=B4axKTHrHqSLD4gM60bGaYb4n6G/Ks5d/xNhLbmvI1g=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=lydZ0Eh+39N9VzNvE+65hi82+/O/xjKH8aD+VPyGmD5zHoYcKmH6+kCnFRvCB/2QpPwCLWP0oFTAPRCj8pelBkz3EKu4/hY/+U3PQIcPIpyA27MvMY93lVR/xPMMxw0TF+dL9bbFtI29HAyLcLXHgPr/180ndBUBrhEgPAmxkvM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708953345; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FUcxMrleDoUI/Upcq21kCnRcPvYW5EbzmbwMRx6fQRc=; b=HQjmEACxGgOkHthdjjcLbgUn6KfqsbYvghjiHbkjHhMkMYm05Qa1zFgIQplMXvsp61A4w8 29xYpzRD82FZ/jSd+ykyT+r18bGwam8BAHKD+Y5UKc6QekngYguWhBYXj8rlxiKUTo1cIj NVyYw/wVADH+Jnw0XVU7d4K9w2RmqKk= Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-553-a5JYG2VWNz-s8gOlCeeKxQ-1; Mon, 26 Feb 2024 08:15:44 -0500 X-MC-Unique: a5JYG2VWNz-s8gOlCeeKxQ-1 Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-2995140840eso2453026a91.1 for ; Mon, 26 Feb 2024 05:15:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708953343; x=1709558143; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FUcxMrleDoUI/Upcq21kCnRcPvYW5EbzmbwMRx6fQRc=; b=sKARjTq6JP7SuoU38SHwnqlsPaumzA5fKl4jwZcVyqrMgUT3vLU0v05Vc2sMzWrHjp m8n7w9VcR4+d+j/FMYIchCmmmTBX93QNH6w7l47MAHniX7g9d65SZXXF3hT3HHf9vsRU 1OKlCkYnscVq0VW9eVquvhiYYXpqpsPyGR+wH5s4p8fBiGPDtw/Mk0gTr8FkzYer74MG o6HMnKhbFr0gtkAKTZKL0lBBGaEje3aeVeVYYpTyaq0cD79vmhvQIWUfYlz2+PPWuGoz GPlwEJlAkow2zSCDhHFUBLMQ4X0Sve1Fe4nh7HTOddQtXVkPirOjManOgeBU3E5I9eMz lTrQ== X-Gm-Message-State: AOJu0YyIvPz3kb5VnBzz6xDyHDZlzcphYGIEaQkTg4bxzA7SLzCW4Qcb DcKg8+K4jBqPDFiQhveHoydhHojNogrACAwb/kl2+R6Zx0qkjmy0BMBr1QSX4XP9/b/3r+9gRWq 6hbAPtftN1MN5Qtn4rd5NUYwQSYpxkEp6AWRjcp4uGySmaKSx/ndPuTC4o9fhb8N2w9Rah8zyuV I3FtlC9afINKXkbfq5M4KhaHzji0A/9GBoCMDahuS9gA== X-Received: by 2002:a17:90b:1bc5:b0:299:4a63:9e50 with SMTP id oa5-20020a17090b1bc500b002994a639e50mr5553271pjb.14.1708953342922; Mon, 26 Feb 2024 05:15:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IG+1YBaFoYkFXQfstiQhhvSvbEj61IP2sJoJ1TX5jjWt5cWJWWX1mFbUPo1pi73/MgDSwEgymH26gEy7ds5ngU= X-Received: by 2002:a17:90b:1bc5:b0:299:4a63:9e50 with SMTP id oa5-20020a17090b1bc500b002994a639e50mr5553254pjb.14.1708953342605; Mon, 26 Feb 2024 05:15:42 -0800 (PST) MIME-Version: 1.0 References: <20240212144014.438615-1-ahajkova@redhat.com> In-Reply-To: <20240212144014.438615-1-ahajkova@redhat.com> From: Alexandra Petlanova Hajkova Date: Mon, 26 Feb 2024 14:15:30 +0100 Message-ID: Subject: Re: [PATCH 1/2] remote.c: Use packet_check_result To: gdb-patches@sourceware.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="000000000000ec9266061248b41e" X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --000000000000ec9266061248b41e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable ping On Mon, Feb 12, 2024 at 3:40=E2=80=AFPM Alexandra H=C3=A1jkov=C3=A1 wrote: > when processing the GDBserver reply to qRcmd packet. > Print error message or the error code. > Currently, when qRcmd request returns an error, > GDB just prints: > > Protocol error with Rcmd > > After this change, GDB will also print the error code: > > Protocol error with Rcmd: 01. > > Add an accept_msg argument to packet_check result. qRcmd > request (such as many other packets) does not recognise > "E.msg" form as an error right now. We want to recognise > "E.msg" as an error response only for the packets where > it's documented. > --- > gdb/remote.c | 65 ++++++++++++++++++++++++++++------------------------ > 1 file changed, 35 insertions(+), 30 deletions(-) > > diff --git a/gdb/remote.c b/gdb/remote.c > index 14c8b020b1e..8caee0dcff9 100644 > --- a/gdb/remote.c > +++ b/gdb/remote.c > @@ -2455,7 +2455,7 @@ add_packet_config_cmd (const unsigned int > which_packet, const char *name, > structure which contains the packet_status enum > and an error message for the PACKET_ERROR case. */ > static packet_result > -packet_check_result (const char *buf) > +packet_check_result (const char *buf, bool accept_msg) > { > if (buf[0] !=3D '\0') > { > @@ -2467,14 +2467,20 @@ packet_check_result (const char *buf) > /* "Enn" - definitely an error. */ > return { PACKET_ERROR, buf + 1 }; > > - /* Always treat "E." as an error. This will be used for > - more verbose error messages, such as E.memtypes. */ > - if (buf[0] =3D=3D 'E' && buf[1] =3D=3D '.') > + /* Not every request accepts an error in a E.msg form. > + Some packets accepts only Enn, in this case E. is not > + defined and E. is treated as PACKET_OK. */ > + if (accept_msg) > { > - if (buf[2] !=3D '\0') > - return { PACKET_ERROR, buf + 2 }; > - else > - return { PACKET_ERROR, "no error provided" }; > + /* Always treat "E." as an error. This will be used for > + more verbose error messages, such as E.memtypes. */ > + if (buf[0] =3D=3D 'E' && buf[1] =3D=3D '.') > + { > + if (buf[2] !=3D '\0') > + return { PACKET_ERROR, buf + 2 }; > + else > + return { PACKET_ERROR, "no error provided" }; > + } > } > > /* The packet may or may not be OK. Just assume it is. */ > @@ -2488,9 +2494,9 @@ packet_check_result (const char *buf) > } > > static packet_result > -packet_check_result (const gdb::char_vector &buf) > +packet_check_result (const gdb::char_vector &buf, bool accept_msg) > { > - return packet_check_result (buf.data ()); > + return packet_check_result (buf.data (), accept_msg); > } > > packet_status > @@ -2503,7 +2509,7 @@ remote_features::packet_ok (const char *buf, const > int which_packet) > && config->support =3D=3D PACKET_DISABLE) > internal_error (_("packet_ok: attempt to use a disabled packet")); > > - packet_result result =3D packet_check_result (buf); > + packet_result result =3D packet_check_result (buf, true); > switch (result.status ()) > { > case PACKET_OK: > @@ -8831,7 +8837,7 @@ remote_target::send_g_packet () > xsnprintf (rs->buf.data (), get_remote_packet_size (), "g"); > putpkt (rs->buf); > getpkt (&rs->buf); > - packet_result result =3D packet_check_result (rs->buf); > + packet_result result =3D packet_check_result (rs->buf, true); > if (result.status () =3D=3D PACKET_ERROR) > error (_("Could not read registers; remote failure reply '%s'"), > result.err_msg ()); > @@ -9140,7 +9146,7 @@ remote_target::store_registers_using_G (const struct > regcache *regcache) > bin2hex (regs, p, rsa->sizeof_g_packet); > putpkt (rs->buf); > getpkt (&rs->buf); > - packet_result pkt_status =3D packet_check_result (rs->buf); > + packet_result pkt_status =3D packet_check_result (rs->buf, true); > if (pkt_status.status () =3D=3D PACKET_ERROR) > error (_("Could not write registers; remote failure reply '%s'"), > pkt_status.err_msg ()); > @@ -9748,7 +9754,7 @@ remote_target::remote_send_printf (const char > *format, ...) > rs->buf[0] =3D '\0'; > getpkt (&rs->buf); > > - return packet_check_result (rs->buf).status (); > + return packet_check_result (rs->buf, true).status (); > } > > /* Flash writing can take quite some time. We'll set > @@ -11931,20 +11937,19 @@ remote_target::rcmd (const char *command, struct > ui_file *outbuf) > continue; > } > buf =3D rs->buf.data (); > - if (buf[0] =3D=3D '\0') > - error (_("Target does not support this command.")); > if (buf[0] =3D=3D 'O' && buf[1] !=3D 'K') > { > remote_console_output (buf + 1); /* 'O' message from stub. */ > continue; > } > - if (strcmp (buf, "OK") =3D=3D 0) > + packet_result result =3D packet_check_result (buf, true); > + if (result.status () =3D=3D PACKET_OK) > break; > - if (strlen (buf) =3D=3D 3 && buf[0] =3D=3D 'E' > - && isxdigit (buf[1]) && isxdigit (buf[2])) > - { > - error (_("Protocol error with Rcmd")); > - } > + else if (result.status () =3D=3D PACKET_UNKNOWN) > + error (_("Target does not support this command.")); > + else > + error (_("Protocol error with Rcmd: %s."), result.err_msg ()); > + > for (p =3D buf; p[0] !=3D '\0' && p[1] !=3D '\0'; p +=3D 2) > { > char c =3D (fromhex (p[0]) << 4) + fromhex (p[1]); > @@ -15571,7 +15576,7 @@ remote_target::store_memtags (CORE_ADDR address, > size_t len, > getpkt (&rs->buf); > > /* Verify if the request was successful. */ > - return packet_check_result (rs->buf).status () =3D=3D PACKET_OK; > + return (packet_check_result (rs->buf, true).status () =3D=3D PACKET_OK= ); > } > > /* Return true if remote target T is non-stop. */ > @@ -15672,26 +15677,26 @@ static void > test_packet_check_result () > { > std::string buf =3D "E.msg"; > - packet_result result =3D packet_check_result (buf.data ()); > + packet_result result =3D packet_check_result (buf.data (), true); > > SELF_CHECK (result.status () =3D=3D PACKET_ERROR); > SELF_CHECK (strcmp(result.err_msg (), "msg") =3D=3D 0); > > - result =3D packet_check_result ("E01"); > + result =3D packet_check_result ("E01", true); > SELF_CHECK (result.status () =3D=3D PACKET_ERROR); > SELF_CHECK (strcmp(result.err_msg (), "01") =3D=3D 0); > > - SELF_CHECK (packet_check_result ("E1").status () =3D=3D PACKET_OK); > + SELF_CHECK (packet_check_result ("E1", true).status () =3D=3D PACKET_O= K); > > - SELF_CHECK (packet_check_result ("E000").status () =3D=3D PACKET_OK); > + SELF_CHECK (packet_check_result ("E000", true).status () =3D=3D PACKET= _OK); > > - result =3D packet_check_result ("E."); > + result =3D packet_check_result ("E.", true); > SELF_CHECK (result.status () =3D=3D PACKET_ERROR); > SELF_CHECK (strcmp(result.err_msg (), "no error provided") =3D=3D 0); > > - SELF_CHECK (packet_check_result ("some response").status () =3D=3D > PACKET_OK); > + SELF_CHECK (packet_check_result ("some response", true).status () =3D= =3D > PACKET_OK); > > - SELF_CHECK (packet_check_result ("").status () =3D=3D PACKET_UNKNOWN); > + SELF_CHECK (packet_check_result ("", true).status () =3D=3D PACKET_UNK= NOWN); > } > } // namespace selftests > #endif /* GDB_SELF_TEST */ > -- > 2.43.0 > > --000000000000ec9266061248b41e--