[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 31/42] hvf: Makes assert_hvf_ok report failed expression
From: |
Paolo Bonzini |
Subject: |
[PULL 31/42] hvf: Makes assert_hvf_ok report failed expression |
Date: |
Sat, 8 Jun 2024 10:34:04 +0200 |
From: Phil Dennis-Jordan <phil@philjordan.eu>
When a macOS Hypervisor.framework call fails which is checked by
assert_hvf_ok(), Qemu exits printing the error value, but not the
location
in the code, as regular assert() macro expansions would.
This change turns assert_hvf_ok() into a macro similar to other
assertions, which expands to a call to the corresponding _impl()
function together with information about the expression that failed
the assertion and its location in the code.
Additionally, stringifying the numeric hv_return_t code is factored
into a helper function that can be reused for diagnostics and debugging
outside of assertions.
Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
Message-ID: <20240605112556.43193-8-phil@philjordan.eu>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
include/sysemu/hvf_int.h | 5 +++-
accel/hvf/hvf-all.c | 51 +++++++++++++++++-----------------------
2 files changed, 26 insertions(+), 30 deletions(-)
diff --git a/include/sysemu/hvf_int.h b/include/sysemu/hvf_int.h
index 30e739a2b52..5b28d17ba1f 100644
--- a/include/sysemu/hvf_int.h
+++ b/include/sysemu/hvf_int.h
@@ -60,7 +60,10 @@ struct AccelCPUState {
bool dirty;
};
-void assert_hvf_ok(hv_return_t ret);
+void assert_hvf_ok_impl(hv_return_t ret, const char *file, unsigned int line,
+ const char *exp);
+#define assert_hvf_ok(EX) assert_hvf_ok_impl((EX), __FILE__, __LINE__, #EX)
+const char *hvf_return_string(hv_return_t ret);
int hvf_arch_init(void);
int hvf_arch_init_vcpu(CPUState *cpu);
void hvf_arch_vcpu_destroy(CPUState *cpu);
diff --git a/accel/hvf/hvf-all.c b/accel/hvf/hvf-all.c
index db05b81be58..c008dc2f1ea 100644
--- a/accel/hvf/hvf-all.c
+++ b/accel/hvf/hvf-all.c
@@ -13,40 +13,33 @@
#include "sysemu/hvf.h"
#include "sysemu/hvf_int.h"
-void assert_hvf_ok(hv_return_t ret)
+const char *hvf_return_string(hv_return_t ret)
+{
+ switch (ret) {
+ case HV_SUCCESS: return "HV_SUCCESS";
+ case HV_ERROR: return "HV_ERROR";
+ case HV_BUSY: return "HV_BUSY";
+ case HV_BAD_ARGUMENT: return "HV_BAD_ARGUMENT";
+ case HV_NO_RESOURCES: return "HV_NO_RESOURCES";
+ case HV_NO_DEVICE: return "HV_NO_DEVICE";
+ case HV_UNSUPPORTED: return "HV_UNSUPPORTED";
+#if defined(MAC_OS_VERSION_11_0) && \
+ MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_11_0
+ case HV_DENIED: return "HV_DENIED";
+#endif
+ default: return "[unknown hv_return value]";
+ }
+}
+
+void assert_hvf_ok_impl(hv_return_t ret, const char *file, unsigned int line,
+ const char *exp)
{
if (ret == HV_SUCCESS) {
return;
}
- switch (ret) {
- case HV_ERROR:
- error_report("Error: HV_ERROR");
- break;
- case HV_BUSY:
- error_report("Error: HV_BUSY");
- break;
- case HV_BAD_ARGUMENT:
- error_report("Error: HV_BAD_ARGUMENT");
- break;
- case HV_NO_RESOURCES:
- error_report("Error: HV_NO_RESOURCES");
- break;
- case HV_NO_DEVICE:
- error_report("Error: HV_NO_DEVICE");
- break;
- case HV_UNSUPPORTED:
- error_report("Error: HV_UNSUPPORTED");
- break;
-#if defined(MAC_OS_VERSION_11_0) && \
- MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_11_0
- case HV_DENIED:
- error_report("Error: HV_DENIED");
- break;
-#endif
- default:
- error_report("Unknown Error");
- }
+ error_report("Error: %s = %s (0x%x, at %s:%u)",
+ exp, hvf_return_string(ret), ret, file, line);
abort();
}
--
2.45.1
- [PULL 21/42] machine, hostmem: improve error messages for unsupported features, (continued)
- [PULL 21/42] machine, hostmem: improve error messages for unsupported features, Paolo Bonzini, 2024/06/08
- [PULL 22/42] hostmem: simplify the code for merge and dump properties, Paolo Bonzini, 2024/06/08
- [PULL 19/42] osdep: Make qemu_madvise() return ENOSYS on unsupported OSes, Paolo Bonzini, 2024/06/08
- [PULL 23/42] scsi-disk: Don't silently truncate serial number, Paolo Bonzini, 2024/06/08
- [PULL 24/42] stubs/meson: Fix qemuutil build when --disable-system, Paolo Bonzini, 2024/06/08
- [PULL 25/42] i386/hvf: Adds support for INVTSC cpuid bit, Paolo Bonzini, 2024/06/08
- [PULL 27/42] hvf: Consistent types for vCPU handles, Paolo Bonzini, 2024/06/08
- [PULL 26/42] i386/hvf: Fixes some compilation warnings, Paolo Bonzini, 2024/06/08
- [PULL 28/42] i386/hvf: Fixes dirty memory tracking by page granularity RX->RWX change, Paolo Bonzini, 2024/06/08
- [PULL 29/42] i386/hvf: In kick_vcpu use hv_vcpu_interrupt to force exit, Paolo Bonzini, 2024/06/08
- [PULL 31/42] hvf: Makes assert_hvf_ok report failed expression,
Paolo Bonzini <=
- [PULL 30/42] i386/hvf: Updates API usage to use modern vCPU run function, Paolo Bonzini, 2024/06/08
- [PULL 33/42] target/i386: mark CR4.FRED not reserved, Paolo Bonzini, 2024/06/08
- [PULL 32/42] target/i386: add support for FRED in CPUID enumeration, Paolo Bonzini, 2024/06/08
- [PULL 34/42] vmxcap: add support for VMX FRED controls, Paolo Bonzini, 2024/06/08
- [PULL 35/42] target/i386: enumerate VMX nested-exception support, Paolo Bonzini, 2024/06/08
- [PULL 36/42] target/i386: Add get/set/migrate support for FRED MSRs, Paolo Bonzini, 2024/06/08
- [PULL 37/42] docs: i386: pc: Avoid mentioning limit of maximum vCPUs, Paolo Bonzini, 2024/06/08
- [PULL 40/42] i386: Add support for overflow recovery, Paolo Bonzini, 2024/06/08
- [PULL 42/42] python: mkvenv: remove ensure command, Paolo Bonzini, 2024/06/08
- [PULL 38/42] i386: Fix MCE support for AMD hosts, Paolo Bonzini, 2024/06/08