summaryrefslogtreecommitdiffstats
path: root/disas.c
diff options
context:
space:
mode:
authorAlex Bennée2022-09-29 13:42:14 +0200
committerAlex Bennée2022-10-06 12:53:40 +0200
commit90bbf9d9dbbbc3956fd0e9a641e724d210190757 (patch)
tree491f91773048ac56ba4304918869f16c4336852a /disas.c
parentdisas: generalise plugin_printf and use for monitor_disas (diff)
downloadqemu-90bbf9d9dbbbc3956fd0e9a641e724d210190757.tar.gz
qemu-90bbf9d9dbbbc3956fd0e9a641e724d210190757.tar.xz
qemu-90bbf9d9dbbbc3956fd0e9a641e724d210190757.zip
disas: use result of ->read_memory_func
This gets especially confusing if you start plugging in host addresses from a trace and you wonder why the output keeps changing. Report when read_memory_func fails instead of blindly disassembling the buffer contents. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-Id: <20220929114231.583801-35-alex.bennee@linaro.org>
Diffstat (limited to 'disas.c')
-rw-r--r--disas.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/disas.c b/disas.c
index f07b6e760b..94d3b45042 100644
--- a/disas.c
+++ b/disas.c
@@ -83,18 +83,18 @@ static int print_insn_objdump(bfd_vma pc, disassemble_info *info,
const char *prefix)
{
int i, n = info->buffer_length;
- uint8_t *buf = g_malloc(n);
-
- info->read_memory_func(pc, buf, n, info);
-
- for (i = 0; i < n; ++i) {
- if (i % 32 == 0) {
- info->fprintf_func(info->stream, "\n%s: ", prefix);
+ g_autofree uint8_t *buf = g_malloc(n);
+
+ if (info->read_memory_func(pc, buf, n, info) == 0) {
+ for (i = 0; i < n; ++i) {
+ if (i % 32 == 0) {
+ info->fprintf_func(info->stream, "\n%s: ", prefix);
+ }
+ info->fprintf_func(info->stream, "%02x", buf[i]);
}
- info->fprintf_func(info->stream, "%02x", buf[i]);
+ } else {
+ info->fprintf_func(info->stream, "unable to read memory");
}
-
- g_free(buf);
return n;
}