aboutsummaryrefslogtreecommitdiff
path: root/disas.c
diff options
context:
space:
mode:
authorAlex Bennée <alex.bennee@linaro.org>2020-05-13 18:51:33 +0100
committerAlex Bennée <alex.bennee@linaro.org>2020-05-15 15:25:16 +0100
commit16b22e02b57e403568b471511e0b2a70789c94df (patch)
tree9576d756eaec6233395eabebed9a368170c1120e /disas.c
parente5ef4ec28b801155e20fdb3a4cd21920ffc5f1af (diff)
disas: add optional note support to cap_disas
Include support for outputting a note at the top of a chunk of disassembly to capstone as well. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20200513175134.19619-10-alex.bennee@linaro.org>
Diffstat (limited to 'disas.c')
-rw-r--r--disas.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/disas.c b/disas.c
index 7e8692de30..45285d3f63 100644
--- a/disas.c
+++ b/disas.c
@@ -260,7 +260,8 @@ static void cap_dump_insn_units(disassemble_info *info, cs_insn *insn,
}
}
-static void cap_dump_insn(disassemble_info *info, cs_insn *insn)
+static void cap_dump_insn(disassemble_info *info, cs_insn *insn,
+ const char *note)
{
fprintf_function print = info->fprintf_func;
int i, n, split;
@@ -281,7 +282,11 @@ static void cap_dump_insn(disassemble_info *info, cs_insn *insn)
}
/* Print the actual instruction. */
- print(info->stream, " %-8s %s\n", insn->mnemonic, insn->op_str);
+ print(info->stream, " %-8s %s", insn->mnemonic, insn->op_str);
+ if (note) {
+ print(info->stream, "\t\t%s", note);
+ }
+ print(info->stream, "\n");
/* Dump any remaining part of the insn on subsequent lines. */
for (i = split; i < n; i += split) {
@@ -313,7 +318,7 @@ static bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size)
size -= tsize;
while (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) {
- cap_dump_insn(info, insn);
+ cap_dump_insn(info, insn, NULL);
}
/* If the target memory is not consumed, go back for more... */
@@ -342,7 +347,8 @@ static bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size)
}
/* Disassemble SIZE bytes at CODE for the host. */
-static bool cap_disas_host(disassemble_info *info, void *code, size_t size)
+static bool cap_disas_host(disassemble_info *info, void *code, size_t size,
+ const char *note)
{
csh handle;
const uint8_t *cbuf;
@@ -358,7 +364,8 @@ static bool cap_disas_host(disassemble_info *info, void *code, size_t size)
pc = (uintptr_t)code;
while (cs_disasm_iter(handle, &cbuf, &size, &pc, insn)) {
- cap_dump_insn(info, insn);
+ cap_dump_insn(info, insn, note);
+ note = NULL;
}
if (size != 0) {
(*info->fprintf_func)(info->stream,
@@ -402,7 +409,7 @@ static bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int count)
csize += tsize;
if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) {
- cap_dump_insn(info, insn);
+ cap_dump_insn(info, insn, NULL);
if (--count <= 0) {
break;
}
@@ -416,7 +423,7 @@ static bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int count)
#endif /* !CONFIG_USER_ONLY */
#else
# define cap_disas_target(i, p, s) false
-# define cap_disas_host(i, p, s) false
+# define cap_disas_host(i, p, s, n) false
# define cap_disas_monitor(i, p, c) false
# define cap_disas_plugin(i, p, c) false
#endif /* CONFIG_CAPSTONE */
@@ -664,7 +671,7 @@ void disas(FILE *out, void *code, unsigned long size, const char *note)
print_insn = print_insn_hppa;
#endif
- if (s.info.cap_arch >= 0 && cap_disas_host(&s.info, code, size)) {
+ if (s.info.cap_arch >= 0 && cap_disas_host(&s.info, code, size, note)) {
return;
}