diff options
author | Andreas Kling <kling@serenityos.org> | 2022-10-06 13:35:46 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-10-06 15:29:38 +0200 |
commit | da781e90c11e6b7ac645f0ce046f909d3d3118f5 (patch) | |
tree | feffb4549ad769ed6eb00de84ba032d62d0de8a3 | |
parent | 4fdfaff4ca506d239e632586f10c015311aeea11 (diff) | |
download | serenity-da781e90c11e6b7ac645f0ce046f909d3d3118f5.zip |
AK: Print VERIFY() error messages in release builds
Until now, VERIFY() failures would just cause a __builtin_trap() in
release builds, which made them a bit too harsh. This commit adds an
out-of-line helper function that prints the error before trapping.
-rw-r--r-- | AK/Assertions.cpp | 20 | ||||
-rw-r--r-- | AK/Assertions.h | 9 |
2 files changed, 26 insertions, 3 deletions
diff --git a/AK/Assertions.cpp b/AK/Assertions.cpp new file mode 100644 index 0000000000..d8ac028345 --- /dev/null +++ b/AK/Assertions.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <AK/Assertions.h> +#include <AK/Format.h> + +#if !defined(KERNEL) && defined(NDEBUG) +extern "C" { + +void ak_verification_failed(char const* message) +{ + dbgln("VERIFICATION FAILED: {}", message); + __builtin_trap(); +} +} + +#endif diff --git a/AK/Assertions.h b/AK/Assertions.h index 648d9b9d49..ab628c14a6 100644 --- a/AK/Assertions.h +++ b/AK/Assertions.h @@ -13,9 +13,12 @@ # ifndef NDEBUG # define VERIFY assert # else -# define VERIFY(expr) \ - (__builtin_expect(!(expr), 0) \ - ? __builtin_trap() \ +# define __stringify_helper(x) # x +# define __stringify(x) __stringify_helper(x) +extern "C" __attribute__((noreturn)) void ak_verification_failed(char const*); +# define VERIFY(expr) \ + (__builtin_expect(!(expr), 0) \ + ? ak_verification_failed(#expr "\n" __FILE__ ":" __stringify(__LINE__)) \ : (void)0) # endif # define VERIFY_NOT_REACHED() VERIFY(false) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */ |