qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v1 6/7] disas: add optional note support to cap_disas


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH v1 6/7] disas: add optional note support to cap_disas
Date: Mon, 11 May 2020 14:18:13 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0

On 5/1/20 4:57 PM, Alex Bennée wrote:
Include support for outputting a note at the top of a chunk of
disassembly to capstone as well.

Signed-off-by: Alex Bennée <address@hidden>
---
  disas.c | 20 ++++++++++++--------
  1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/disas.c b/disas.c
index bb74650633..5e7eb65326 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,8 @@ 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\t\t%s\n", insn->mnemonic, insn->op_str,
+          note ? note : "");
/* Dump any remaining part of the insn on subsequent lines. */
      for (i = split; i < n; i += split) {
@@ -313,7 +315,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 +344,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 +361,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);

'note' directly?

Otherwise:

Reviewed-by: Philippe Mathieu-Daudé <address@hidden>

+        note = NULL;
      }
      if (size != 0) {
          (*info->fprintf_func)(info->stream,
@@ -402,7 +406,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 +420,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 +668,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;
      }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]