From patchwork Thu Jan 5 16:43:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 639295 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp329376pvb; Thu, 5 Jan 2023 09:04:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXt00hjIeltEIyNLZJ89CmXCi8cQTOMsb7eS6ySZ/fYU7bc2iWhGJ5dkMqtNVG/XuQpWakve X-Received: by 2002:a05:6358:c9a:b0:e0:5e94:d1e3 with SMTP id o26-20020a0563580c9a00b000e05e94d1e3mr1106663rwj.3.1672938255539; Thu, 05 Jan 2023 09:04:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672938255; cv=none; d=google.com; s=arc-20160816; b=WMdPwD6L2t6zR7lZd0q4rRC1GgMq0LFe5gocmzXzpBIlYK+vDX60Iwhokuj5GN4tNm JbFHht1CPY3+VCZQLAleTUk0oX3VRC8etvrNE6LDVWYtYBTNSCvYP10ktCOR/uxWkwv1 IDQf6FZazzZxscUrvntMWIhH8IhQbVxV9S4C2R+naAyG1KJnV9ExgSz6Gt9bMkVwiN6W MNW5gd+lJiGPhY0CiQC+bU+pdd5MIGUe4lUejcGxjfviCGVqpRVecOjdiD4Qle54he3x ynappr+Ce3+G41lkbl3nmJ94fy9Kzc1Gjx+SvXVDUWJkPiC43RmKPhg60UUxZZPzrypZ 8RWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dq+rRQ8VRcqDw3VK+XUoNAUY4lPdXx+D6O3N7YMZLHQ=; b=rggTONsMYtmt3XOxezM2ImU3o4F1Il5Ld0icvjuYIL0/9LNlNcaVpBtmlqA8u3DWVW XBvd3/eINAfZi+PWbzSAaWMtwDsor7+mwKWS+8cc63HJKjPtcib/Go9et8G9mS1gScR4 y3lDfps3UYpwt1dqratzAzyY9jZEwawAaLUgDUcqH+uG38nlAxCGaZUBH2y3KTU8xjuV PPDxqlWNwJF/mzvYuvvZOPs+oTXX334jTKPirLPqSzesgyOLQ/EHjsmZv68dC1yEdiR0 FqUi0Ly6lbj7OJYwIeWKvFgwbOwr0SbeB8lzaiZMVGFTacoINgbQxLAScmpmcAdIB6X7 OMrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iy30XnDG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b5-20020a05620a04e500b006fed8cfbfdesi19398860qkh.267.2023.01.05.09.04.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 05 Jan 2023 09:04:15 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iy30XnDG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pDTLU-0007be-2Z; Thu, 05 Jan 2023 11:44:00 -0500 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 1pDTLO-0007Kd-0H for qemu-devel@nongnu.org; Thu, 05 Jan 2023 11:43:55 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pDTKz-00072F-JZ for qemu-devel@nongnu.org; Thu, 05 Jan 2023 11:43:53 -0500 Received: by mail-wm1-x32f.google.com with SMTP id m3so19553479wmq.0 for ; Thu, 05 Jan 2023 08:43:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dq+rRQ8VRcqDw3VK+XUoNAUY4lPdXx+D6O3N7YMZLHQ=; b=iy30XnDGoFXdLHjGUr4l17D1YAkJ/mqJOBAgy9h+gIvBibMgnhJphZYcm9botUhcPp bl384/qXwT/4Hu0RvaTaLK5L7F7ztdLWyOsObt39ojHyoiAtkAz4HJfrzNEnkNSI5VFz agcgDWSapfc8SmGNm11RWZE9HpE/rUNWao0A2c+Z9HmwL6oc3fwuxAO5VlrpVQDWT6/x mdz9gtKA3ib8NwQ6YzK3778kUNpUTMSVKAJr8ekT/2R6B23TygoZzGSmDugk/HtgH2Mw 7I7qglsCXErU67FHgehYuR8eKPAukA0FCBcRHIpborcSDpeLwcqQnj7IzIAp5swtSU8L dczA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dq+rRQ8VRcqDw3VK+XUoNAUY4lPdXx+D6O3N7YMZLHQ=; b=dfeJAXtPZ/5s13CtLsUrJJUoM5Z/R7L5NFaPMcKcI5j6ooZQ0C7WKW+aMypri3p80j Vk0EUzzUFkhxj7pgXwuAuxVzlHV8uZQmQS9FP5BBUhlnK85vv84JC5t44UAoBf7ZDbhn CFWAaBGnf71vQzee3F61aKifiRfNK6nA2iimMqXaR2wzXvxrFIDPxQzEci6RbVtCPJpL DlDc911oliKeo90NfgEeCE8yoJll8qyp/wSA+IaC1N9ZXxNvNDbcVTwKWILon+MMgMb/ 9mqNWMY+3bi6gDp8W/O5jThDQMyp6bHl+mgTBeSeX+68xc8VLJsVkEFGKhQINNRc+mdA U9AQ== X-Gm-Message-State: AFqh2krmZBkZRUX0AFTIXhDZnH0sa4nMzDU2QCGeu1VFDesS/fuft/S8 D/sM8aVaxePp107JYHCS+ZYJeg== X-Received: by 2002:a05:600c:4307:b0:3d3:494f:6a39 with SMTP id p7-20020a05600c430700b003d3494f6a39mr37100454wme.16.1672937008193; Thu, 05 Jan 2023 08:43:28 -0800 (PST) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id ay19-20020a5d6f13000000b0022cdeba3f83sm18000710wrb.84.2023.01.05.08.43.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 08:43:25 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 4EEC31FFB8; Thu, 5 Jan 2023 16:43:21 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org, alex.bennee@gmail.com Cc: David Hildenbrand , Sunil Muthuswamy , Aurelien Jarno , Michael Rolnik , Aleksandar Rikalo , Greg Kurz , Ilya Leoshkevich , Thomas Huth , qemu-ppc@nongnu.org, Laurent Vivier , Max Filippov , Yanan Wang , Marek Vasut , Stafford Horne , Peter Maydell , Daniel Henrique Barboza , Palmer Dabbelt , =?utf-8?q?Alex_Benn=C3=A9e?= , Taylor Simpson , Marcel Apfelbaum , Alexandre Iooss , Chris Wulff , Richard Henderson , Eduardo Habkost , Song Gao , Mark Cave-Ayland , =?utf-8?q?C=C3=A9dric_Le_?= =?utf-8?q?Goater?= , Artyom Tarasenko , Paolo Bonzini , qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Alistair Francis , "Edgar E. Iglesias" , Bastian Koppelmann , Jiaxun Yang , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Bin Meng , Mahmoud Mandour , David Gibson , Yoshinori Sato , Xiaojuan Yang , qemu-arm@nongnu.org Subject: [PATCH v2 14/21] gdbstub: specialise target_memory_rw_debug Date: Thu, 5 Jan 2023 16:43:13 +0000 Message-Id: <20230105164320.2164095-15-alex.bennee@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230105164320.2164095-1-alex.bennee@linaro.org> References: <20230105164320.2164095-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org The two implementations are different enough to encourage having a specialisation and we can move some of the softmmu only stuff out of gdbstub. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- gdbstub/internals.h | 19 ++++++++++++ gdbstub/gdbstub.c | 73 +++++++-------------------------------------- gdbstub/softmmu.c | 51 +++++++++++++++++++++++++++++++ gdbstub/user.c | 15 ++++++++++ 4 files changed, 96 insertions(+), 62 deletions(-) diff --git a/gdbstub/internals.h b/gdbstub/internals.h index 646d2c4e82..55f3d820aa 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -181,6 +181,10 @@ void gdb_handle_query_xfer_auxv(GArray *params, void *user_ctx); /*user */ void gdb_handle_query_attached(GArray *params, void *user_ctx); /* both */ +/* softmmu only */ +void gdb_handle_query_qemu_phy_mem_mode(GArray *params, void *user_ctx); +void gdb_handle_set_qemu_phy_mem_mode(GArray *params, void *user_ctx); + /* * Break/Watch point support - there is an implementation for softmmu * and user mode. @@ -190,4 +194,19 @@ int gdb_breakpoint_insert(CPUState *cs, int type, hwaddr addr, hwaddr len); int gdb_breakpoint_remove(CPUState *cs, int type, hwaddr addr, hwaddr len); void gdb_breakpoint_remove_all(CPUState *cs); +/** + * gdb_target_memory_rw_debug() - handle debug access to memory + * @cs: CPUState + * @addr: nominal address, could be an entire physical address + * @buf: data + * @len: length of access + * @is_write: is it a write operation + * + * This function is specialised depending on the mode we are running + * in. For softmmu guests we can switch the interpretation of the + * address to a physical address. + */ +int gdb_target_memory_rw_debug(CPUState *cs, hwaddr addr, + uint8_t *buf, int len, bool is_write); + #endif /* GDBSTUB_INTERNALS_H */ diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 0d90685c72..91021859a1 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -46,33 +46,6 @@ #include "internals.h" -#ifndef CONFIG_USER_ONLY -static int phy_memory_mode; -#endif - -static inline int target_memory_rw_debug(CPUState *cpu, target_ulong addr, - uint8_t *buf, int len, bool is_write) -{ - CPUClass *cc; - -#ifndef CONFIG_USER_ONLY - if (phy_memory_mode) { - if (is_write) { - cpu_physical_memory_write(addr, buf, len); - } else { - cpu_physical_memory_read(addr, buf, len); - } - return 0; - } -#endif - - cc = CPU_GET_CLASS(cpu); - if (cc->memory_rw_debug) { - return cc->memory_rw_debug(cpu, addr, buf, len, is_write); - } - return cpu_memory_rw_debug(cpu, addr, buf, len, is_write); -} - typedef struct GDBRegisterState { int base_reg; int num_regs; @@ -1194,11 +1167,11 @@ static void handle_write_mem(GArray *params, void *user_ctx) } gdb_hextomem(gdbserver_state.mem_buf, get_param(params, 2)->data, - get_param(params, 1)->val_ull); - if (target_memory_rw_debug(gdbserver_state.g_cpu, - get_param(params, 0)->val_ull, - gdbserver_state.mem_buf->data, - gdbserver_state.mem_buf->len, true)) { + get_param(params, 1)->val_ull); + if (gdb_target_memory_rw_debug(gdbserver_state.g_cpu, + get_param(params, 0)->val_ull, + gdbserver_state.mem_buf->data, + gdbserver_state.mem_buf->len, true)) { gdb_put_packet("E14"); return; } @@ -1222,10 +1195,10 @@ static void handle_read_mem(GArray *params, void *user_ctx) g_byte_array_set_size(gdbserver_state.mem_buf, get_param(params, 1)->val_ull); - if (target_memory_rw_debug(gdbserver_state.g_cpu, - get_param(params, 0)->val_ull, - gdbserver_state.mem_buf->data, - gdbserver_state.mem_buf->len, false)) { + if (gdb_target_memory_rw_debug(gdbserver_state.g_cpu, + get_param(params, 0)->val_ull, + gdbserver_state.mem_buf->data, + gdbserver_state.mem_buf->len, false)) { gdb_put_packet("E14"); return; } @@ -1675,30 +1648,6 @@ static void handle_query_qemu_supported(GArray *params, void *user_ctx) gdb_put_strbuf(); } -#ifndef CONFIG_USER_ONLY -static void handle_query_qemu_phy_mem_mode(GArray *params, - void *user_ctx) -{ - g_string_printf(gdbserver_state.str_buf, "%d", phy_memory_mode); - gdb_put_strbuf(); -} - -static void handle_set_qemu_phy_mem_mode(GArray *params, void *user_ctx) -{ - if (!params->len) { - gdb_put_packet("E22"); - return; - } - - if (!get_param(params, 0)->val_ul) { - phy_memory_mode = 0; - } else { - phy_memory_mode = 1; - } - gdb_put_packet("OK"); -} -#endif - static const GdbCmdParseEntry gdb_gen_query_set_common_table[] = { /* Order is important if has same prefix */ { @@ -1789,7 +1738,7 @@ static const GdbCmdParseEntry gdb_gen_query_table[] = { }, #ifndef CONFIG_USER_ONLY { - .handler = handle_query_qemu_phy_mem_mode, + .handler = gdb_handle_query_qemu_phy_mem_mode, .cmd = "qemu.PhyMemMode", }, #endif @@ -1805,7 +1754,7 @@ static const GdbCmdParseEntry gdb_gen_set_table[] = { }, #ifndef CONFIG_USER_ONLY { - .handler = handle_set_qemu_phy_mem_mode, + .handler = gdb_handle_set_qemu_phy_mem_mode, .cmd = "qemu.PhyMemMode:", .cmd_startswith = 1, .schema = "l0" diff --git a/gdbstub/softmmu.c b/gdbstub/softmmu.c index 19fcb3be7d..c42230acca 100644 --- a/gdbstub/softmmu.c +++ b/gdbstub/softmmu.c @@ -409,9 +409,60 @@ void gdb_exit(int code) qemu_chr_fe_deinit(&gdbserver_system_state.chr, true); } +/* + * Memory access + */ +static int phy_memory_mode; + +int gdb_target_memory_rw_debug(CPUState *cpu, hwaddr addr, + uint8_t *buf, int len, bool is_write) +{ + CPUClass *cc; + + if (phy_memory_mode) { + if (is_write) { + cpu_physical_memory_write(addr, buf, len); + } else { + cpu_physical_memory_read(addr, buf, len); + } + return 0; + } + + cc = CPU_GET_CLASS(cpu); + if (cc->memory_rw_debug) { + return cc->memory_rw_debug(cpu, addr, buf, len, is_write); + } + + return cpu_memory_rw_debug(cpu, addr, buf, len, is_write); +} + + /* * Softmmu specific command helpers */ + +void gdb_handle_query_qemu_phy_mem_mode(GArray *params, + void *user_ctx) +{ + g_string_printf(gdbserver_state.str_buf, "%d", phy_memory_mode); + gdb_put_strbuf(); +} + +void gdb_handle_set_qemu_phy_mem_mode(GArray *params, void *user_ctx) +{ + if (!params->len) { + gdb_put_packet("E22"); + return; + } + + if (!get_param(params, 0)->val_ul) { + phy_memory_mode = 0; + } else { + phy_memory_mode = 1; + } + gdb_put_packet("OK"); +} + void gdb_handle_query_rcmd(GArray *params, void *user_ctx) { const guint8 zero = 0; diff --git a/gdbstub/user.c b/gdbstub/user.c index a668b16952..74f541223c 100644 --- a/gdbstub/user.c +++ b/gdbstub/user.c @@ -376,6 +376,21 @@ int gdb_continue_partial(char *newstates) return res; } +/* + * Memory access helpers + */ +int gdb_target_memory_rw_debug(CPUState *cpu, hwaddr addr, + uint8_t *buf, int len, bool is_write) +{ + CPUClass *cc; + + cc = CPU_GET_CLASS(cpu); + if (cc->memory_rw_debug) { + return cc->memory_rw_debug(cpu, addr, buf, len, is_write); + } + return cpu_memory_rw_debug(cpu, addr, buf, len, is_write); +} + /* * Break/Watch point helpers */