diff mbox series

[v2,1/2] gdbstub: Improve physical memory access handling

Message ID 20250317051605.1108128-2-npiggin@gmail.com (mailing list archive)
State New
Headers show
Series gdb invalid memory access handling improvements | expand

Commit Message

Nicholas Piggin March 17, 2025, 5:16 a.m. UTC
Bring gdb's physical memory access handling up to speed with the CPU
memory access, by setting MemTxAttribute.debug=1, and by checking for
memory transaction errors.

GDB with PhyMemMode will now report failure for memory access outside
valid system memory addresses, and it is also able to write to ROMs as
it can with virtual memory access.

Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 gdbstub/system.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

Comments

Richard Henderson March 17, 2025, 4:57 p.m. UTC | #1
On 3/16/25 22:16, Nicholas Piggin wrote:
> Bring gdb's physical memory access handling up to speed with the CPU
> memory access, by setting MemTxAttribute.debug=1, and by checking for
> memory transaction errors.
> 
> GDB with PhyMemMode will now report failure for memory access outside
> valid system memory addresses, and it is also able to write to ROMs as
> it can with virtual memory access.
> 
> Reviewed-by: David Hildenbrand<david@redhat.com>
> Signed-off-by: Nicholas Piggin<npiggin@gmail.com>
> ---
>   gdbstub/system.c | 27 +++++++++++++++++++++------
>   1 file changed, 21 insertions(+), 6 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
diff mbox series

Patch

diff --git a/gdbstub/system.c b/gdbstub/system.c
index dd22ff0fb3a..6a550e229e2 100644
--- a/gdbstub/system.c
+++ b/gdbstub/system.c
@@ -17,6 +17,7 @@ 
 #include "exec/gdbstub.h"
 #include "gdbstub/syscalls.h"
 #include "gdbstub/commands.h"
+#include "exec/address-spaces.h"
 #include "exec/hwaddr.h"
 #include "exec/tb-flush.h"
 #include "system/accel-ops.h"
@@ -453,16 +454,30 @@  void gdb_qemu_exit(int code)
  */
 static int phy_memory_mode;
 
+/*
+ * Like cpu_memory_rw_debug but it operates on the system address space
+ * rather than the CPU's view of memory.
+ */
+static int phys_memory_rw_debug(hwaddr addr, void *buf,
+                                hwaddr len, bool is_write)
+{
+    MemTxAttrs attrs = MEMTXATTRS_UNSPECIFIED;
+    MemTxResult res;
+
+    attrs.debug = 1;
+    res = address_space_rw(&address_space_memory, addr, attrs,
+                           buf, len, is_write);
+    if (res != MEMTX_OK) {
+        return -1;
+    }
+    return 0;
+}
+
 int gdb_target_memory_rw_debug(CPUState *cpu, hwaddr addr,
                                uint8_t *buf, int len, bool is_write)
 {
     if (phy_memory_mode) {
-        if (is_write) {
-            cpu_physical_memory_write(addr, buf, len);
-        } else {
-            cpu_physical_memory_read(addr, buf, len);
-        }
-        return 0;
+        return phys_memory_rw_debug(addr, buf, len, is_write);
     }
 
     if (cpu->cc->memory_rw_debug) {