qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH v2 16/20] disas/nanomips: Replace exception handling


From: Richard Henderson
Subject: Re: [PATCH v2 16/20] disas/nanomips: Replace exception handling
Date: Mon, 5 Sep 2022 12:50:46 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0

On 9/5/22 10:55, Milica Lazarevic wrote:
Since there's no support for exception handling in C, the try-catch
blocks have been deleted, and throw clauses are replaced. When a runtime
error happens, we're printing out the error message. Disassembling of
the current instruction interrupts. This behavior is achieved by adding
sigsetjmp() to discard further disassembling after the error message
prints and by adding the siglongjmp() function to imitate throwing an
error. The goal was to maintain the same output as it was.

Signed-off-by: Milica Lazarevic <milica.lazarevic@syrmia.com>
---
  disas/nanomips.cpp | 126 ++++++++++++++++++++++-----------------------
  1 file changed, 61 insertions(+), 65 deletions(-)

diff --git a/disas/nanomips.cpp b/disas/nanomips.cpp
index 5142f307fc..a8295ebfa8 100644
--- a/disas/nanomips.cpp
+++ b/disas/nanomips.cpp
@@ -31,7 +31,6 @@
  #include "disas/dis-asm.h"
#include <string.h>
-#include <stdexcept>
  #include <stdio.h>
  #include <stdarg.h>
@@ -134,10 +133,12 @@ static uint64 renumber_registers(uint64 index, uint64 *register_list,
          return register_list[index];
      }
- throw std::runtime_error(img_format(
-                   "Invalid register mapping index %" PRIu64
-                   ", size of list = %zu",
-                   index, register_list_size));
+    g_autofree char *err = img_format(
+                      "Invalid register mapping index %" PRIu64
+                      ", size of list = %zu",
+                      index, register_list_size);
+    info->fprintf_func(info->stream, "%s", err);

There's no point passing the output of sprintf into fprintf like this.
Just fprintf in the first place.


+                        disassembly_function dis_fn = table[i].disassembly;
+                        if (dis_fn == 0) {
+                            strcpy(dis,
+                            "disassembler failure - bad table entry");
+                            return -6;
+                        }
+                        type = table[i].type;
+                        g_autofree char *dis_str = dis_fn(op_code, info);
+                        strcpy(dis, dis_str);
+                        return table[i].instructions_size;
+                    } else {
+                        strcpy(dis, "reserved instruction");
+                        return -2;

Ought these errors use the same error path?


r~



reply via email to

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