1 | This adds .debug=1 attribute for GDB's phys mem access mode, adds | 1 | This adds .debug=1 attribute for GDB's phys mem access mode, adds |
---|---|---|---|
2 | memory transaction error handling for it so it reports cannot access | 2 | memory transaction error handling for it so it reports cannot access |
3 | memory instead of silent success, and silences warning logs for | 3 | memory instead of silent success, and silences warning logs for |
4 | invalid memory access coming from the debugger. | 4 | invalid memory access coming from the debugger. |
5 | 5 | ||
6 | Changes since v1: | ||
7 | - Move phys_memory_rw_debug() into gdbstub/system.c and update patch | ||
8 | changelog to match. | ||
9 | |||
6 | Thanks, | 10 | Thanks, |
7 | Nick | 11 | Nick |
8 | 12 | ||
9 | Nicholas Piggin (2): | 13 | Nicholas Piggin (2): |
10 | gdbstub: Add phys_memory_rw_debug for physical memory access | 14 | gdbstub: Improve physical memory access handling |
11 | memory: suppress INVALID_MEM logs caused by debug access | 15 | memory: suppress INVALID_MEM logs caused by debug access |
12 | 16 | ||
13 | docs/devel/loads-stores.rst | 11 +++++++++++ | 17 | gdbstub/system.c | 27 +++++++++++++++++++++------ |
14 | include/exec/cpu-common.h | 3 +++ | 18 | system/memory.c | 37 ++++++++++++++++++++++--------------- |
15 | gdbstub/system.c | 7 +------ | 19 | 2 files changed, 43 insertions(+), 21 deletions(-) |
16 | system/memory.c | 37 ++++++++++++++++++++++--------------- | ||
17 | system/physmem.c | 16 ++++++++++++++++ | ||
18 | 5 files changed, 53 insertions(+), 21 deletions(-) | ||
19 | 20 | ||
20 | -- | 21 | -- |
21 | 2.47.1 | 22 | 2.47.1 | diff view generated by jsdifflib |
1 | Add an accessor for gdb physical memory access mode which sets the | 1 | Bring gdb's physical memory access handling up to speed with the CPU |
---|---|---|---|
2 | the .debug attribute for the MemTxAttribute, and also returns success | 2 | memory access, by setting MemTxAttribute.debug=1, and by checking for |
3 | to the caller. | 3 | memory transaction errors. |
4 | 4 | ||
5 | GDB with PhyMemMode will now report failure from memory accesses outside | 5 | GDB with PhyMemMode will now report failure for memory access outside |
6 | valid system memory addresses, and it is also able to write to ROMs as | 6 | valid system memory addresses, and it is also able to write to ROMs as |
7 | GDB virtual memory access can. | 7 | it can with virtual memory access. |
8 | 8 | ||
9 | Reviewed-by: David Hildenbrand <david@redhat.com> | ||
9 | Signed-off-by: Nicholas Piggin <npiggin@gmail.com> | 10 | Signed-off-by: Nicholas Piggin <npiggin@gmail.com> |
10 | --- | 11 | --- |
11 | docs/devel/loads-stores.rst | 11 +++++++++++ | 12 | gdbstub/system.c | 27 +++++++++++++++++++++------ |
12 | include/exec/cpu-common.h | 3 +++ | 13 | 1 file changed, 21 insertions(+), 6 deletions(-) |
13 | gdbstub/system.c | 7 +------ | ||
14 | system/physmem.c | 16 ++++++++++++++++ | ||
15 | 4 files changed, 31 insertions(+), 6 deletions(-) | ||
16 | 14 | ||
17 | diff --git a/docs/devel/loads-stores.rst b/docs/devel/loads-stores.rst | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/docs/devel/loads-stores.rst | ||
20 | +++ b/docs/devel/loads-stores.rst | ||
21 | @@ -XXX,XX +XXX,XX @@ would ignore the write attempt). | ||
22 | |||
23 | ``cpu_memory_rw_debug`` | ||
24 | |||
25 | +``phys_memory_rw_debug`` | ||
26 | +~~~~~~~~~~~~~~~~~~~~~~~ | ||
27 | + | ||
28 | +Access system memory by physical address for debug purposes. | ||
29 | + | ||
30 | +This function is intended for use by the GDB stub and similar code. | ||
31 | +It takes a physical address and operates on the system address space. | ||
32 | +Access is performed as in cpu_memory_rw_debug(). | ||
33 | + | ||
34 | +``phys_memory_rw_debug`` | ||
35 | + | ||
36 | ``dma_memory_*`` | ||
37 | ~~~~~~~~~~~~~~~~ | ||
38 | |||
39 | diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/include/exec/cpu-common.h | ||
42 | +++ b/include/exec/cpu-common.h | ||
43 | @@ -XXX,XX +XXX,XX @@ int ram_block_discard_guest_memfd_range(RAMBlock *rb, uint64_t start, | ||
44 | /* Returns: 0 on success, -1 on error */ | ||
45 | int cpu_memory_rw_debug(CPUState *cpu, vaddr addr, | ||
46 | void *ptr, size_t len, bool is_write); | ||
47 | +/* Returns: 0 on success, -1 on error */ | ||
48 | +int phys_memory_rw_debug(hwaddr addr, void *buf, | ||
49 | + hwaddr len, bool is_write); | ||
50 | |||
51 | /* vl.c */ | ||
52 | void list_cpus(void); | ||
53 | diff --git a/gdbstub/system.c b/gdbstub/system.c | 15 | diff --git a/gdbstub/system.c b/gdbstub/system.c |
54 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
55 | --- a/gdbstub/system.c | 17 | --- a/gdbstub/system.c |
56 | +++ b/gdbstub/system.c | 18 | +++ b/gdbstub/system.c |
57 | @@ -XXX,XX +XXX,XX @@ int gdb_target_memory_rw_debug(CPUState *cpu, hwaddr addr, | 19 | @@ -XXX,XX +XXX,XX @@ |
58 | uint8_t *buf, int len, bool is_write) | 20 | #include "exec/gdbstub.h" |
59 | { | 21 | #include "gdbstub/syscalls.h" |
60 | if (phy_memory_mode) { | 22 | #include "gdbstub/commands.h" |
61 | - if (is_write) { | 23 | +#include "exec/address-spaces.h" |
62 | - cpu_physical_memory_write(addr, buf, len); | 24 | #include "exec/hwaddr.h" |
63 | - } else { | 25 | #include "exec/tb-flush.h" |
64 | - cpu_physical_memory_read(addr, buf, len); | 26 | #include "system/accel-ops.h" |
65 | - } | 27 | @@ -XXX,XX +XXX,XX @@ void gdb_qemu_exit(int code) |
66 | - return 0; | 28 | */ |
67 | + return phys_memory_rw_debug(addr, buf, len, is_write); | 29 | static int phy_memory_mode; |
68 | } | 30 | |
69 | 31 | +/* | |
70 | if (cpu->cc->memory_rw_debug) { | 32 | + * Like cpu_memory_rw_debug but it operates on the system address space |
71 | diff --git a/system/physmem.c b/system/physmem.c | 33 | + * rather than the CPU's view of memory. |
72 | index XXXXXXX..XXXXXXX 100644 | 34 | + */ |
73 | --- a/system/physmem.c | 35 | +static int phys_memory_rw_debug(hwaddr addr, void *buf, |
74 | +++ b/system/physmem.c | 36 | + hwaddr len, bool is_write) |
75 | @@ -XXX,XX +XXX,XX @@ int cpu_memory_rw_debug(CPUState *cpu, vaddr addr, | ||
76 | return 0; | ||
77 | } | ||
78 | |||
79 | +/* physical memory access for debug (includes writing to ROM) */ | ||
80 | +int phys_memory_rw_debug(hwaddr addr, void *buf, | ||
81 | + hwaddr len, bool is_write) | ||
82 | +{ | 37 | +{ |
83 | + MemTxAttrs attrs = MEMTXATTRS_UNSPECIFIED; | 38 | + MemTxAttrs attrs = MEMTXATTRS_UNSPECIFIED; |
84 | + MemTxResult res; | 39 | + MemTxResult res; |
85 | + | 40 | + |
86 | + attrs.debug = 1; | 41 | + attrs.debug = 1; |
... | ... | ||
90 | + return -1; | 45 | + return -1; |
91 | + } | 46 | + } |
92 | + return 0; | 47 | + return 0; |
93 | +} | 48 | +} |
94 | + | 49 | + |
95 | bool cpu_physical_memory_is_io(hwaddr phys_addr) | 50 | int gdb_target_memory_rw_debug(CPUState *cpu, hwaddr addr, |
51 | uint8_t *buf, int len, bool is_write) | ||
96 | { | 52 | { |
97 | MemoryRegion*mr; | 53 | if (phy_memory_mode) { |
54 | - if (is_write) { | ||
55 | - cpu_physical_memory_write(addr, buf, len); | ||
56 | - } else { | ||
57 | - cpu_physical_memory_read(addr, buf, len); | ||
58 | - } | ||
59 | - return 0; | ||
60 | + return phys_memory_rw_debug(addr, buf, len, is_write); | ||
61 | } | ||
62 | |||
63 | if (cpu->cc->memory_rw_debug) { | ||
98 | -- | 64 | -- |
99 | 2.47.1 | 65 | 2.47.1 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
5 | specified by the user (e.g., gdb it might try to walk the stack or load | 5 | specified by the user (e.g., gdb it might try to walk the stack or load |
6 | target addresses to display disassembly). Failure is reported | 6 | target addresses to display disassembly). Failure is reported |
7 | synchronously by the GDB protcol so the user can be notified via the | 7 | synchronously by the GDB protcol so the user can be notified via the |
8 | debugger client. | 8 | debugger client. |
9 | 9 | ||
10 | Reviewed-by: David Hildenbrand <david@redhat.com> | ||
10 | Signed-off-by: Nicholas Piggin <npiggin@gmail.com> | 11 | Signed-off-by: Nicholas Piggin <npiggin@gmail.com> |
11 | --- | 12 | --- |
12 | system/memory.c | 37 ++++++++++++++++++++++--------------- | 13 | system/memory.c | 37 ++++++++++++++++++++++--------------- |
13 | 1 file changed, 22 insertions(+), 15 deletions(-) | 14 | 1 file changed, 22 insertions(+), 15 deletions(-) |
14 | 15 | ||
... | ... | diff view generated by jsdifflib |