From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org, alex.bennee@gmail.com
Cc: "David Hildenbrand" <david@redhat.com>,
"Sunil Muthuswamy" <sunilmut@microsoft.com>,
"Aurelien Jarno" <aurelien@aurel32.net>,
"Michael Rolnik" <mrolnik@gmail.com>,
"Aleksandar Rikalo" <aleksandar.rikalo@syrmia.com>,
"Greg Kurz" <groug@kaod.org>,
"Ilya Leoshkevich" <iii@linux.ibm.com>,
"Thomas Huth" <thuth@redhat.com>,
qemu-ppc@nongnu.org, "Laurent Vivier" <laurent@vivier.eu>,
"Max Filippov" <jcmvbkbc@gmail.com>,
"Yanan Wang" <wangyanan55@huawei.com>,
"Marek Vasut" <marex@denx.de>,
"Stafford Horne" <shorne@gmail.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Daniel Henrique Barboza" <danielhb413@gmail.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Taylor Simpson" <tsimpson@quicinc.com>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Alexandre Iooss" <erdnaxe@crans.org>,
"Chris Wulff" <crwulff@gmail.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Song Gao" <gaosong@loongson.cn>,
"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
"Cédric Le Goater" <clg@kaod.org>,
"Artyom Tarasenko" <atar4qemu@gmail.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
qemu-riscv@nongnu.org, qemu-s390x@nongnu.org,
"Alistair Francis" <alistair.francis@wdc.com>,
"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
"Bastian Koppelmann" <kbastian@mail.uni-paderborn.de>,
"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Bin Meng" <bin.meng@windriver.com>,
"Mahmoud Mandour" <ma.mandourr@gmail.com>,
"David Gibson" <david@gibson.dropbear.id.au>,
"Yoshinori Sato" <ysato@users.sourceforge.jp>,
"Xiaojuan Yang" <yangxiaojuan@loongson.cn>,
qemu-arm@nongnu.org
Subject: [PATCH v2 14/21] gdbstub: specialise target_memory_rw_debug
Date: Thu, 5 Jan 2023 16:43:13 +0000 [thread overview]
Message-ID: <20230105164320.2164095-15-alex.bennee@linaro.org> (raw)
In-Reply-To: <20230105164320.2164095-1-alex.bennee@linaro.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 <alex.bennee@linaro.org>
---
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
*/
--
2.34.1
next prev parent reply other threads:[~2023-01-05 17:04 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-05 16:42 [PATCH v2 00/21] gdbstub: re-organise to for better compilation behaviour Alex Bennée
2023-01-05 16:43 ` [PATCH v2 01/21] gdbstub/internals.h: clean up include guard Alex Bennée
2023-01-05 17:01 ` Philippe Mathieu-Daudé
2023-01-08 12:51 ` Bin Meng
2023-01-05 16:43 ` [PATCH v2 02/21] target/arm: fix handling of HLT semihosting in system mode Alex Bennée
2023-01-06 20:36 ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 03/21] gdbstub: fix-up copyright and license files Alex Bennée
2023-01-05 17:02 ` Philippe Mathieu-Daudé
2023-01-05 16:43 ` [PATCH v2 04/21] gdbstub: Make syscall_complete/[gs]et_reg target-agnostic typedefs Alex Bennée
2023-01-05 16:43 ` [PATCH v2 05/21] gdbstub: define separate user/system structures Alex Bennée
2023-01-06 20:39 ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 06/21] gdbstub: move GDBState to shared internals header Alex Bennée
2023-01-06 20:42 ` Richard Henderson
2023-02-21 10:24 ` Alex Bennée
2023-02-21 10:36 ` Richard Henderson
2023-02-21 10:58 ` Alex Bennée
2023-01-05 16:43 ` [PATCH v2 07/21] includes: move tb_flush into its own header Alex Bennée
2023-01-05 16:43 ` [PATCH v2 08/21] gdbstub: move fromhex/tohex routines to internals Alex Bennée
2023-01-06 20:43 ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 09/21] gdbstub: make various helpers visible to the rest of the module Alex Bennée
2023-01-05 17:09 ` Philippe Mathieu-Daudé
2023-01-06 21:37 ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 10/21] gdbstub: move chunk of softmmu functionality to own file Alex Bennée
2023-01-06 21:51 ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 11/21] gdbstub: move chunks of user code into own files Alex Bennée
2023-01-06 21:56 ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 12/21] gdbstub: abstract target specific details from gdb_put_packet_binary Alex Bennée
2023-01-05 17:13 ` Philippe Mathieu-Daudé
2023-01-06 21:57 ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 13/21] gdbstub: specialise handle_query_attached Alex Bennée
2023-01-05 17:22 ` Philippe Mathieu-Daudé
2023-01-06 21:59 ` Richard Henderson
2023-01-05 16:43 ` Alex Bennée [this message]
2023-01-06 23:14 ` [PATCH v2 14/21] gdbstub: specialise target_memory_rw_debug Richard Henderson
2023-01-05 16:43 ` [PATCH v2 15/21] gdbstub: introduce gdb_get_max_cpus Alex Bennée
2023-01-06 23:16 ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 16/21] gdbstub: specialise stub_can_reverse Alex Bennée
2023-01-05 17:25 ` Philippe Mathieu-Daudé
2023-01-06 23:17 ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 17/21] gdbstub: fix address type of gdb_set_cpu_pc Alex Bennée
2023-01-05 17:26 ` Philippe Mathieu-Daudé
2023-01-06 23:19 ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 18/21] gdbstub: don't use target_ulong while handling registers Alex Bennée
2023-01-05 17:28 ` Philippe Mathieu-Daudé
2023-01-06 23:24 ` Richard Henderson
2023-01-06 23:23 ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 19/21] gdbstub: move register helpers into standalone include Alex Bennée
2023-01-05 16:56 ` Taylor Simpson
2023-01-05 17:30 ` Philippe Mathieu-Daudé
2023-01-05 19:05 ` Max Filippov
2023-01-06 23:28 ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 20/21] gdbstub: move syscall handling to new file Alex Bennée
2023-01-06 23:46 ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 21/21] gdbstub: only compile gdbstub twice for whole build Alex Bennée
2023-01-06 23:55 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230105164320.2164095-15-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=aleksandar.rikalo@syrmia.com \
--cc=alex.bennee@gmail.com \
--cc=alistair.francis@wdc.com \
--cc=atar4qemu@gmail.com \
--cc=aurelien@aurel32.net \
--cc=bin.meng@windriver.com \
--cc=clg@kaod.org \
--cc=crwulff@gmail.com \
--cc=danielhb413@gmail.com \
--cc=david@gibson.dropbear.id.au \
--cc=david@redhat.com \
--cc=edgar.iglesias@gmail.com \
--cc=eduardo@habkost.net \
--cc=erdnaxe@crans.org \
--cc=gaosong@loongson.cn \
--cc=groug@kaod.org \
--cc=iii@linux.ibm.com \
--cc=jcmvbkbc@gmail.com \
--cc=jiaxun.yang@flygoat.com \
--cc=kbastian@mail.uni-paderborn.de \
--cc=laurent@vivier.eu \
--cc=ma.mandourr@gmail.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=marex@denx.de \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=mrolnik@gmail.com \
--cc=palmer@dabbelt.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=shorne@gmail.com \
--cc=sunilmut@microsoft.com \
--cc=thuth@redhat.com \
--cc=tsimpson@quicinc.com \
--cc=wangyanan55@huawei.com \
--cc=yangxiaojuan@loongson.cn \
--cc=ysato@users.sourceforge.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).