diff mbox series

[v4,08/11] target/mips: Use error_report for UHI_assert

Message ID 20220608051945.802339-9-richard.henderson@linaro.org
State Superseded
Headers show
Series target/mips: semihosting cleanup | expand

Commit Message

Richard Henderson June 8, 2022, 5:19 a.m. UTC
Always log the assert locally.  Do not report_fault, but
instead include the fact of the fault in the assertion.
Don't bother freeing allocated strings before the abort().

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/mips/tcg/sysemu/mips-semi.c | 39 ++++++++++++++----------------
 1 file changed, 18 insertions(+), 21 deletions(-)

Comments

Philippe Mathieu-Daudé June 10, 2022, 3:10 p.m. UTC | #1
On 8/6/22 07:19, Richard Henderson wrote:
> Always log the assert locally.  Do not report_fault, but
> instead include the fact of the fault in the assertion.
> Don't bother freeing allocated strings before the abort().
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   target/mips/tcg/sysemu/mips-semi.c | 39 ++++++++++++++----------------
>   1 file changed, 18 insertions(+), 21 deletions(-)

>       case UHI_assert:
> -        GET_TARGET_STRINGS_2(p, gpr[4], p2, gpr[5]);
> -        printf("assertion '");
> -        printf("\"%s\"", p);
> -        printf("': file \"%s\", line %d\n", p2, (int)gpr[6]);
> -        FREE_TARGET_STRING(p2, gpr[5]);
> -        FREE_TARGET_STRING(p, gpr[4]);
> -        abort();
> -        break;
> +        {
> +            const char *msg, *file;
> +
> +            msg = lock_user_string(gpr[4]);
> +            if (!msg) {
> +                msg = "<EFAULT>";
> +            }
> +            file = lock_user_string(gpr[5]);
> +            if (!file) {
> +                file = "<EFAULT>";
> +            }
> +
> +            error_report("UHI assertion \"%s\": file \"%s\", line %d",
> +                         msg, file, (int)gpr[6]);
> +            abort();
> +        }
> +
>       default:
>           error_report("Unknown UHI operation %d", op);
>           abort();

Pre-existing, so:
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

But since this is a guest error, I'd prefer we exit(1) instead.
diff mbox series

Patch

diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c
index ad11a46820..ae4b8849b1 100644
--- a/target/mips/tcg/sysemu/mips-semi.c
+++ b/target/mips/tcg/sysemu/mips-semi.c
@@ -221,18 +221,6 @@  static int copy_argn_to_target(CPUMIPSState *env, int arg_num,
         }                                       \
     } while (0)
 
-#define GET_TARGET_STRINGS_2(p, addr, p2, addr2)        \
-    do {                                                \
-        p = lock_user_string(addr);                     \
-        if (!p) {                                       \
-            report_fault(env);                          \
-        }                                               \
-        p2 = lock_user_string(addr2);                   \
-        if (!p2) {                                      \
-            report_fault(env);                          \
-        }                                               \
-    } while (0)
-
 #define FREE_TARGET_STRING(p, gpr)              \
     do {                                        \
         unlock_user(p, gpr, 0);                 \
@@ -243,7 +231,7 @@  void mips_semihosting(CPUMIPSState *env)
     CPUState *cs = env_cpu(env);
     target_ulong *gpr = env->active_tc.gpr;
     const UHIOp op = gpr[25];
-    char *p, *p2;
+    char *p;
 
     switch (op) {
     case UHI_exit:
@@ -355,14 +343,23 @@  void mips_semihosting(CPUMIPSState *env)
         break;
 
     case UHI_assert:
-        GET_TARGET_STRINGS_2(p, gpr[4], p2, gpr[5]);
-        printf("assertion '");
-        printf("\"%s\"", p);
-        printf("': file \"%s\", line %d\n", p2, (int)gpr[6]);
-        FREE_TARGET_STRING(p2, gpr[5]);
-        FREE_TARGET_STRING(p, gpr[4]);
-        abort();
-        break;
+        {
+            const char *msg, *file;
+
+            msg = lock_user_string(gpr[4]);
+            if (!msg) {
+                msg = "<EFAULT>";
+            }
+            file = lock_user_string(gpr[5]);
+            if (!file) {
+                file = "<EFAULT>";
+            }
+
+            error_report("UHI assertion \"%s\": file \"%s\", line %d",
+                         msg, file, (int)gpr[6]);
+            abort();
+        }
+
     default:
         error_report("Unknown UHI operation %d", op);
         abort();