mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 05:25:32 +03:00
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.
This commit is contained in:
parent
4fdfaff4ca
commit
da781e90c1
Notes:
sideshowbarker
2024-07-17 06:19:24 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/da781e90c1
20
AK/Assertions.cpp
Normal file
20
AK/Assertions.cpp
Normal file
@ -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
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user