summaryrefslogtreecommitdiffstats
path: root/disas/capstone.c
diff options
context:
space:
mode:
authorStefan Hajnoczi2022-10-06 13:11:56 +0200
committerStefan Hajnoczi2022-10-06 13:11:56 +0200
commitf1d33f55c47dfdaf8daacd618588ad3ae4c452d1 (patch)
treec759a5deb49756097f301652837b14ffc91ef6b2 /disas/capstone.c
parentMerge tag 'pull-hex-20221003' of https://github.com/quic/qemu into staging (diff)
parentplugins: add [pre|post]fork helpers to linux-user (diff)
downloadqemu-f1d33f55c47dfdaf8daacd618588ad3ae4c452d1.tar.gz
qemu-f1d33f55c47dfdaf8daacd618588ad3ae4c452d1.tar.xz
qemu-f1d33f55c47dfdaf8daacd618588ad3ae4c452d1.zip
Merge tag 'pull-testing-gdbstub-plugins-gitdm-061022-3' of https://github.com/stsquad/qemu into staging
testing, gdbstub, plugin and gitdm updates - cleanup scripts/ci/setup in advance of ppc64 runner - ensure detected gdb reported to TCG tests - update hexagon container with build deps - move alpine container to tagged release - fix overflow during qos-test test tree iteration - allow bios blobs to be built with test cross compilers - introduce monitor_puts for plain strings - share disas code between monitor and plugins - fix bug in execlog plugin - add more tcg plugin documentation, reorg - fix link to semihosting spec - re-factor gdbstub to use AccelClass/Ops - many gitdm updates - fix race with plugin mutex lock and linux-user fork() # -----BEGIN PGP SIGNATURE----- # # iQEzBAABCgAdFiEEZoWumedRZ7yvyN81+9DbCVqeKkQFAmM+s+YACgkQ+9DbCVqe # KkSDwgf/Qj0OScOr5Bfw3/KAV0/SFL1vHISb2r5qZVG4DvdY/c/sitPBHPJ8N5jQ # 918M8AiI3+4Mb/GwkdYBEyWgVZ5ELOkJTObypa5pwmF1K/xDUlG7ZRmJ9+xkJ44Q # TmrVLQyw6d907B2u+DfqX68AYYnto1yQT/eUo6TiLdIJ5NXIYRn5u34snG9qWHja # b/Dp7DxnoJMS1EhlMhukekCHGGNUeYn4ewIKbsG1EouH5PndzrvP8LRAcWyxv0m4 # tD2bEAHCMKqTqefkNgG7GCO3HND1JBfWdckx3OD4hBnMnuNtsZBL23QN7MDytgnv # 0JnYSwkWZCuMIt7oKCOXLUbCjQG97Q== # =1vZ4 # -----END PGP SIGNATURE----- # gpg: Signature made Thu 06 Oct 2022 06:54:30 EDT # gpg: using RSA key 6685AE99E75167BCAFC8DF35FBD0DB095A9E2A44 # gpg: Good signature from "Alex Bennée (Master Work Key) <alex.bennee@linaro.org>" [unknown] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: 6685 AE99 E751 67BC AFC8 DF35 FBD0 DB09 5A9E 2A44 * tag 'pull-testing-gdbstub-plugins-gitdm-061022-3' of https://github.com/stsquad/qemu: (52 commits) plugins: add [pre|post]fork helpers to linux-user contrib/gitdm: add Université Grenoble Alpes contrib/gitdm: add Simon to individual contributors contrib/gitdm: add China Telecom to the domain map contrib/gitdm: add ISCAS to the academics group contrib/gitdm: add WANG Xuerui to individual contributers contrib/gitdm: add Paul to individual contributors contrib/gitdm: add mapping for Loongson Technology accel/kvm: move kvm_update_guest_debug to inline stub gdbstub: move guest debug support check to ops gdbstub: move breakpoint logic to accel ops gdbstub: move sstep flags probing into AccelClass gdbstub: move into its own sub directory semihosting: update link to spec docs/devel: document the test plugins contrib/plugins: reset skip when matching in execlog docs/devel: move API to end of tcg-plugins.rst docs/devel: clean-up qemu invocations in tcg-plugins plugins: Assert mmu_idx in range before use in qemu_plugin_get_hwaddr plugins: extend execlog to filter matches ... Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'disas/capstone.c')
-rw-r--r--disas/capstone.c73
1 files changed, 43 insertions, 30 deletions
diff --git a/disas/capstone.c b/disas/capstone.c
index 20bc8f9669..fe3efb0d3c 100644
--- a/disas/capstone.c
+++ b/disas/capstone.c
@@ -191,37 +191,43 @@ bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size)
size_t tsize = MIN(sizeof(cap_buf) - csize, size);
const uint8_t *cbuf = cap_buf;
- info->read_memory_func(pc + csize, cap_buf + csize, tsize, info);
- csize += tsize;
- size -= tsize;
+ if (info->read_memory_func(pc + csize, cap_buf + csize, tsize, info) == 0) {
+ csize += tsize;
+ size -= tsize;
- while (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) {
- cap_dump_insn(info, insn);
- }
+ while (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) {
+ cap_dump_insn(info, insn);
+ }
+
+ /* If the target memory is not consumed, go back for more... */
+ if (size != 0) {
+ /*
+ * ... taking care to move any remaining fractional insn
+ * to the beginning of the buffer.
+ */
+ if (csize != 0) {
+ memmove(cap_buf, cbuf, csize);
+ }
+ continue;
+ }
- /* If the target memory is not consumed, go back for more... */
- if (size != 0) {
/*
- * ... taking care to move any remaining fractional insn
- * to the beginning of the buffer.
+ * Since the target memory is consumed, we should not have
+ * a remaining fractional insn.
*/
if (csize != 0) {
- memmove(cap_buf, cbuf, csize);
+ info->fprintf_func(info->stream,
+ "Disassembler disagrees with translator "
+ "over instruction decoding\n"
+ "Please report this to qemu-devel@nongnu.org\n");
}
- continue;
- }
+ break;
- /*
- * Since the target memory is consumed, we should not have
- * a remaining fractional insn.
- */
- if (csize != 0) {
+ } else {
info->fprintf_func(info->stream,
- "Disassembler disagrees with translator "
- "over instruction decoding\n"
- "Please report this to qemu-devel@nongnu.org\n");
+ "0x%08" PRIx64 ": unable to read memory\n", pc);
+ break;
}
- break;
}
cs_close(&handle);
@@ -286,16 +292,23 @@ bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int count)
/* Make certain that we can make progress. */
assert(tsize != 0);
- info->read_memory_func(pc + csize, cap_buf + csize, tsize, info);
- csize += tsize;
-
- if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) {
- cap_dump_insn(info, insn);
- if (--count <= 0) {
- break;
+ if (info->read_memory_func(pc + csize, cap_buf + csize,
+ tsize, info) == 0)
+ {
+ csize += tsize;
+
+ if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) {
+ cap_dump_insn(info, insn);
+ if (--count <= 0) {
+ break;
+ }
}
+ memmove(cap_buf, cbuf, csize);
+ } else {
+ info->fprintf_func(info->stream,
+ "0x%08" PRIx64 ": unable to read memory\n", pc);
+ break;
}
- memmove(cap_buf, cbuf, csize);
}
cs_close(&handle);