From nobody Sat Sep 21 05:22:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=quicinc.com ARC-Seal: i=1; a=rsa-sha256; t=1684440707; cv=none; d=zohomail.com; s=zohoarc; b=ERGHET7GxZhs3DTu7t3b8jmSHSMQyQdVDLme2YXqQKeQ0XBBNhUf7Udolj8tVovdHF2t7wEl0712+ZC2BynAg6MJsDRt1BoLr2Sa9KIosgGVsVutyBV1MlpWoDCp4tJe+Nywd8lJbmN6p62q4pqSBNWLCO0oSHdpcrRzNv/PPsQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684440707; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2GF6pJCvorg02iRo5ULtdoiq3CwjQXhEBnBUq+kVWkM=; b=ZIAAC6xY4wFBjKTCmRc5B0toyhf8OY5gNRLSU+rxq8HuLmtXTYjgqzIk2WOZUweY1Q+Z/qRHvSVb8atJs9W57IaYLZ/aDXTYIO874gFHvD1/yuMwE6/VBveSymFXiWqbuWuaLTl4oveM615LDO8f1VArcJgbX3k1a/9vE5BcDO8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684440707659397.20074656268037; Thu, 18 May 2023 13:11:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzjru-0000bl-4z; Thu, 18 May 2023 16:04:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzjri-0000DL-8n for qemu-devel@nongnu.org; Thu, 18 May 2023 16:04:48 -0400 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzjrS-00058P-Uh for qemu-devel@nongnu.org; Thu, 18 May 2023 16:04:44 -0400 Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34IFnFkc013274; Thu, 18 May 2023 20:04:19 GMT Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3qn8d2jex0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 18 May 2023 20:04:19 +0000 Received: from pps.filterd (NALASPPMTA05.qualcomm.com [127.0.0.1]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTP id 34IK4HuG012813; Thu, 18 May 2023 20:04:17 GMT Received: from pps.reinject (localhost [127.0.0.1]) by NALASPPMTA05.qualcomm.com (PPS) with ESMTPS id 3qj3mmta0j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 18 May 2023 20:04:17 +0000 Received: from NALASPPMTA05.qualcomm.com (NALASPPMTA05.qualcomm.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34IK1dhv008789; Thu, 18 May 2023 20:04:17 GMT Received: from hu-devc-sd-u20-a-1.qualcomm.com (hu-tsimpson-lv.qualcomm.com [10.47.204.221]) by NALASPPMTA05.qualcomm.com (PPS) with ESMTPS id 34IK4FK5012593 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 18 May 2023 20:04:17 +0000 Received: by hu-devc-sd-u20-a-1.qualcomm.com (Postfix, from userid 47164) id B90356E8; Thu, 18 May 2023 13:04:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-type : content-transfer-encoding; s=qcppdkim1; bh=2GF6pJCvorg02iRo5ULtdoiq3CwjQXhEBnBUq+kVWkM=; b=lKVqdUmlYpvLGcHubx5Q83ad+nKKxBhuOqoMSyaHJzabMcZMxG5r75Jj3QWaXByvXWna l8mUyHdlUXiDT8PY8T6wFji+s8ns9GMsFNMHEP4FRgNEjxnr10kYrHzrGkG4WEroiOSO m1nyNNm2tX+cZ75whL6sGzJxEJhE7qfsxbGLa7S7fiJtB8WMtpzzmYyVMMGIuJEifQHK xFYjPfGAWCGFEHsmGZxXIo5Oa+UUIVWFs1BMhhVt8QVgug+u1rq4n6JvcU8zWdz83rt+ C66QQcsGuDHlo4beAapxDeVZ69AcGCUENmSJYCOv7WgmVOH3bLMjHG/Imr7SC055w3a1 JQ== From: Taylor Simpson To: qemu-devel@nongnu.org Cc: tsimpson@quicinc.com, richard.henderson@linaro.org, philmd@linaro.org, peter.maydell@linaro.org, bcain@quicinc.com, quic_mathbern@quicinc.com, stefanha@redhat.com, ale@rev.ng, anjo@rev.ng, quic_mliebel@quicinc.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PULL v2 39/44] gdbstub: only send stop-reply packets when allowed to Date: Thu, 18 May 2023 13:04:06 -0700 Message-Id: <20230518200411.271148-40-tsimpson@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230518200411.271148-1-tsimpson@quicinc.com> References: <20230518200411.271148-1-tsimpson@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QCInternal: smtphost X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: _tyCK4FA1NJpq9Zo00ZzBnJjGqJgKe5Y X-Proofpoint-GUID: _tyCK4FA1NJpq9Zo00ZzBnJjGqJgKe5Y X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-18_15,2023-05-17_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 adultscore=0 malwarescore=0 mlxlogscore=877 bulkscore=0 phishscore=0 spamscore=0 suspectscore=0 clxscore=1015 mlxscore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305180165 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=tsimpson@qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @quicinc.com) X-ZM-MESSAGEID: 1684440708063100001 Content-Type: text/plain; charset="utf-8" From: Matheus Tavares Bernardino GDB's remote serial protocol allows stop-reply messages to be sent by the stub either as a notification packet or as a reply to a GDB command (provided that the cmd accepts such a response). QEMU currently does not implement notification packets, so it should only send stop-replies synchronously and when requested. Nevertheless, it still issues unsolicited stop messages through gdb_vm_state_change(). Although this behavior doesn't seem to cause problems with GDB itself (the messages are just ignored), it can impact other debuggers that implement the GDB remote serial protocol, like hexagon-lldb. Let's change the gdbstub to send stop messages only as a response to a previous GDB command that accepts such a reply. Signed-off-by: Matheus Tavares Bernardino Acked-by: Alex Benn=C3=A9e Signed-off-by: Taylor Simpson Message-Id: --- gdbstub/internals.h | 5 +++++ gdbstub/gdbstub.c | 37 ++++++++++++++++++++++++++++--------- gdbstub/softmmu.c | 13 +++++++++++-- gdbstub/user.c | 24 ++++++++++++++++-------- 4 files changed, 60 insertions(+), 19 deletions(-) diff --git a/gdbstub/internals.h b/gdbstub/internals.h index 94ddff4495..33d21d6488 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -65,6 +65,11 @@ typedef struct GDBState { GByteArray *mem_buf; int sstep_flags; int supported_sstep_flags; + /* + * Whether we are allowed to send a stop reply packet at this moment. + * Must be set off after sending the stop reply itself. + */ + bool allow_stop_reply; } GDBState; =20 /* lives in main gdbstub.c */ diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 0760d78685..be18568d0a 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -777,6 +777,10 @@ typedef void (*GdbCmdHandler)(GArray *params, void *us= er_ctx); /* * cmd_startswith -> cmd is compared using startswith * + * allow_stop_reply -> true iff the gdbstub can respond to this command wi= th a + * "stop reply" packet. The list of commands that accept such response is + * defined at the GDB Remote Serial Protocol documentation. see: + * https://sourceware.org/gdb/onlinedocs/gdb/Stop-Reply-Packets.html#Sto= p-Reply-Packets. * * schema definitions: * Each schema parameter entry consists of 2 chars, @@ -802,6 +806,7 @@ typedef struct GdbCmdParseEntry { const char *cmd; bool cmd_startswith; const char *schema; + bool allow_stop_reply; } GdbCmdParseEntry; =20 static inline int startswith(const char *string, const char *pattern) @@ -835,6 +840,7 @@ static int process_string_cmd(void *user_ctx, const cha= r *data, } } =20 + gdbserver_state.allow_stop_reply =3D cmd->allow_stop_reply; cmd->handler(params, user_ctx); return 0; } @@ -1283,11 +1289,14 @@ static void handle_v_attach(GArray *params, void *u= ser_ctx) gdbserver_state.g_cpu =3D cpu; gdbserver_state.c_cpu =3D cpu; =20 - g_string_printf(gdbserver_state.str_buf, "T%02xthread:", GDB_SIGNAL_TR= AP); - gdb_append_thread_id(cpu, gdbserver_state.str_buf); - g_string_append_c(gdbserver_state.str_buf, ';'); + if (gdbserver_state.allow_stop_reply) { + g_string_printf(gdbserver_state.str_buf, "T%02xthread:", GDB_SIGNA= L_TRAP); + gdb_append_thread_id(cpu, gdbserver_state.str_buf); + g_string_append_c(gdbserver_state.str_buf, ';'); + gdbserver_state.allow_stop_reply =3D false; cleanup: - gdb_put_strbuf(); + gdb_put_strbuf(); + } } =20 static void handle_v_kill(GArray *params, void *user_ctx) @@ -1310,12 +1319,14 @@ static const GdbCmdParseEntry gdb_v_commands_table[= ] =3D { .handler =3D handle_v_cont, .cmd =3D "Cont", .cmd_startswith =3D 1, + .allow_stop_reply =3D true, .schema =3D "s0" }, { .handler =3D handle_v_attach, .cmd =3D "Attach;", .cmd_startswith =3D 1, + .allow_stop_reply =3D true, .schema =3D "l0" }, { @@ -1698,10 +1709,13 @@ static void handle_gen_set(GArray *params, void *us= er_ctx) =20 static void handle_target_halt(GArray *params, void *user_ctx) { - g_string_printf(gdbserver_state.str_buf, "T%02xthread:", GDB_SIGNAL_TR= AP); - gdb_append_thread_id(gdbserver_state.c_cpu, gdbserver_state.str_buf); - g_string_append_c(gdbserver_state.str_buf, ';'); - gdb_put_strbuf(); + if (gdbserver_state.allow_stop_reply) { + g_string_printf(gdbserver_state.str_buf, "T%02xthread:", GDB_SIGNA= L_TRAP); + gdb_append_thread_id(gdbserver_state.c_cpu, gdbserver_state.str_bu= f); + g_string_append_c(gdbserver_state.str_buf, ';'); + gdb_put_strbuf(); + gdbserver_state.allow_stop_reply =3D false; + } /* * Remove all the breakpoints when this query is issued, * because gdb is doing an initial connect and the state @@ -1725,7 +1739,8 @@ static int gdb_handle_packet(const char *line_buf) static const GdbCmdParseEntry target_halted_cmd_desc =3D { .handler =3D handle_target_halt, .cmd =3D "?", - .cmd_startswith =3D 1 + .cmd_startswith =3D 1, + .allow_stop_reply =3D true, }; cmd_parser =3D &target_halted_cmd_desc; } @@ -1736,6 +1751,7 @@ static int gdb_handle_packet(const char *line_buf) .handler =3D handle_continue, .cmd =3D "c", .cmd_startswith =3D 1, + .allow_stop_reply =3D true, .schema =3D "L0" }; cmd_parser =3D &continue_cmd_desc; @@ -1747,6 +1763,7 @@ static int gdb_handle_packet(const char *line_buf) .handler =3D handle_cont_with_sig, .cmd =3D "C", .cmd_startswith =3D 1, + .allow_stop_reply =3D true, .schema =3D "l0" }; cmd_parser =3D &cont_with_sig_cmd_desc; @@ -1785,6 +1802,7 @@ static int gdb_handle_packet(const char *line_buf) .handler =3D handle_step, .cmd =3D "s", .cmd_startswith =3D 1, + .allow_stop_reply =3D true, .schema =3D "L0" }; cmd_parser =3D &step_cmd_desc; @@ -1976,6 +1994,7 @@ void gdb_read_byte(uint8_t ch) { uint8_t reply; =20 + gdbserver_state.allow_stop_reply =3D false; #ifndef CONFIG_USER_ONLY if (gdbserver_state.last_packet->len) { /* Waiting for a response to the last packet. If we see the start diff --git a/gdbstub/softmmu.c b/gdbstub/softmmu.c index 22ecd09d04..99d994e6bf 100644 --- a/gdbstub/softmmu.c +++ b/gdbstub/softmmu.c @@ -43,6 +43,7 @@ static void reset_gdbserver_state(void) g_free(gdbserver_state.processes); gdbserver_state.processes =3D NULL; gdbserver_state.process_num =3D 0; + gdbserver_state.allow_stop_reply =3D false; } =20 /* @@ -139,6 +140,10 @@ static void gdb_vm_state_change(void *opaque, bool run= ning, RunState state) return; } =20 + if (!gdbserver_state.allow_stop_reply) { + return; + } + gdb_append_thread_id(cpu, tid); =20 switch (state) { @@ -205,6 +210,7 @@ static void gdb_vm_state_change(void *opaque, bool runn= ing, RunState state) =20 send_packet: gdb_put_packet(buf->str); + gdbserver_state.allow_stop_reply =3D false; =20 /* disable single step if it was enabled */ cpu_single_step(cpu, 0); @@ -422,8 +428,11 @@ void gdb_exit(int code) =20 trace_gdbstub_op_exiting((uint8_t)code); =20 - snprintf(buf, sizeof(buf), "W%02x", (uint8_t)code); - gdb_put_packet(buf); + if (gdbserver_state.allow_stop_reply) { + snprintf(buf, sizeof(buf), "W%02x", (uint8_t)code); + gdb_put_packet(buf); + gdbserver_state.allow_stop_reply =3D false; + } =20 qemu_chr_fe_deinit(&gdbserver_system_state.chr, true); } diff --git a/gdbstub/user.c b/gdbstub/user.c index 80488b6bb9..5b375be1d9 100644 --- a/gdbstub/user.c +++ b/gdbstub/user.c @@ -108,8 +108,11 @@ void gdb_exit(int code) =20 trace_gdbstub_op_exiting((uint8_t)code); =20 - snprintf(buf, sizeof(buf), "W%02x", (uint8_t)code); - gdb_put_packet(buf); + if (gdbserver_state.allow_stop_reply) { + snprintf(buf, sizeof(buf), "W%02x", (uint8_t)code); + gdb_put_packet(buf); + gdbserver_state.allow_stop_reply =3D false; + } } =20 int gdb_handlesig(CPUState *cpu, int sig) @@ -127,11 +130,14 @@ int gdb_handlesig(CPUState *cpu, int sig) =20 if (sig !=3D 0) { gdb_set_stop_cpu(cpu); - g_string_printf(gdbserver_state.str_buf, - "T%02xthread:", gdb_target_signal_to_gdb(sig)); - gdb_append_thread_id(cpu, gdbserver_state.str_buf); - g_string_append_c(gdbserver_state.str_buf, ';'); - gdb_put_strbuf(); + if (gdbserver_state.allow_stop_reply) { + g_string_printf(gdbserver_state.str_buf, + "T%02xthread:", gdb_target_signal_to_gdb(sig)); + gdb_append_thread_id(cpu, gdbserver_state.str_buf); + g_string_append_c(gdbserver_state.str_buf, ';'); + gdb_put_strbuf(); + gdbserver_state.allow_stop_reply =3D false; + } } /* * gdb_put_packet() might have detected that the peer terminated the @@ -174,12 +180,14 @@ void gdb_signalled(CPUArchState *env, int sig) { char buf[4]; =20 - if (!gdbserver_state.init || gdbserver_user_state.fd < 0) { + if (!gdbserver_state.init || gdbserver_user_state.fd < 0 || + !gdbserver_state.allow_stop_reply) { return; } =20 snprintf(buf, sizeof(buf), "X%02x", gdb_target_signal_to_gdb(sig)); gdb_put_packet(buf); + gdbserver_state.allow_stop_reply =3D false; } =20 static void gdb_accept_init(int fd) --=20 2.25.1