gdb invalid memory access handling improvements
v3 cover gdb invalid memory access handling improvements
This adds .debug=1 attribute for GDB's phys mem access mode, adds memory transaction error handling for it so it reports cannot access memory instead of silent success, and silences warning logs for invalid memory access coming from the debugger.
Changes since v1:
- Move phys_memory_rw_debug() into gdbstub/system.c and update patch changelog to match.
Since v2:
- Change to use Philippe's suggestion for log condition.
- Fixed flipped test noticed by Richard (sorry, forgot to actually test after rebasing).
Thanks,
Nick
Nicholas Piggin (2):
gdbstub: Improve physical memory access handling
memory: suppress INVALID_MEM logs caused by debug access
gdbstub/system.c | 27 +++++++++++++++++++++------ system/memory.c | 10 +++++++--- 2 files changed, 28 insertions(+), 9 deletions(-)
Signature · 1 line
2.47.1
PATCH v3 2/2 memory: suppress INVALID_MEM logs caused by debug access
Debugger-driven invalid memory accesses are not guest errors, so should not cause these error logs.
Debuggers can access memory wildly, including access to addresses not specified by the user (e.g., gdb it might try to walk the stack or load target addresses to display disassembly). Failure is reported synchronously by the GDB protcol so the user can be notified via the debugger client.
--- system/memory.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
system/memory.c +7 -3
@@ -1412,7 +1412,9 @@ bool memory_region_access_valid(MemoryRegion *mr, {if (mr->ops->valid.accepts && !mr->ops->valid.accepts (mr->opaque, addr, size, is_write, attrs)) { -qemu_log_mask (LOG_INVALID_MEM ,"Invalid %s at addr 0x%" HWADDR_PRIX +/* Don't log memory errors due to debugger accesses */ +int log_mask = attrs.debug ?0 :LOG_INVALID_MEM ; +qemu_log_mask (log_mask,"Invalid %s at addr 0x%" HWADDR_PRIX ", size %u, region '%s', reason: rejected\n" , is_write ?"write" :"read" , addr, size,memory_region_name (mr));
@@ -1420,7 +1422,8 @@ bool memory_region_access_valid(MemoryRegion *mr, }if (!mr->ops->valid.unaligned && (addr & (size -1 ))) { -qemu_log_mask (LOG_INVALID_MEM ,"Invalid %s at addr 0x%" HWADDR_PRIX +int log_mask = attrs.debug ?0 :LOG_INVALID_MEM ; +qemu_log_mask (log_mask,"Invalid %s at addr 0x%" HWADDR_PRIX ", size %u, region '%s', reason: unaligned\n" , is_write ?"write" :"read" , addr, size,memory_region_name (mr));
@@ -1434,7 +1437,8 @@ bool memory_region_access_valid(MemoryRegion *mr,if (size > mr->ops->valid.max_access_size || size < mr->ops->valid.min_access_size) { - qemu_log_mask(LOG_INVALID_MEM, "Invalid %s at addr 0x%" HWADDR_PRIX +int log_mask = attrs.debug ?0 :LOG_INVALID_MEM ; + qemu_log_mask(log_mask, "Invalid %s at addr 0x%" HWADDR_PRIX ", size %u, region '%s', reason: invalid size " "(min:%u max:%u)\n", is_write ? "write" : "read",
Signature · 1 line
2.47.1
PATCH v3 1/2 gdbstub: Improve physical memory access handling
In reply to Nicholas PigginBring 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.
--- gdbstub/system.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-)
gdbstub/system.c +21 -6
@@ -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) {
Signature · 1 line
2.47.1