Commit graph

22 commits

Author SHA1 Message Date
R-Goc
ba5ef052e4 AK: Fix libbacktrace fallback
Introducing cpptrace as the primary backtrace library broke the
backtrace fallback during the code move. This commit properly links AK
to libbacktrace.

It also fixes the function signatures for the fallback backtrace
handlers.
2025-10-10 12:46:20 +02:00
R-Goc
62e7d1b5c8 AK: Remove FreeLibrary call in assertion handler
The call to FreeLibrary was incorrect as GetModuleHandle does not
increment the reference count of the DLL.
2025-10-08 07:07:57 +02:00
R-Goc
3c7bad32cd AK: Clean up backtraces
This commit replaces the default backtrace logic with cpptrace, for
nicer, colored backtraces. Cpptrace runs on all of our supported
platforms excpet android. As such backtrace.h is left in place.

All the backtrace functions are made noinline to have a consistent
number of frames. A maximum depth parameter is added to dump_backtrace
with a default of 100. This should be enough, and can be easily
changed, and allows for limiting the maximum depth.

Setting the LADYBIRD_BACKTRACE_SNIPPETS environment variable enables
surrouding code snippets in the backtrace. Specifically 2 lines above
and below. This number can be changed by calling snippet_context on the
formatter. For the whole list of options of what can be done with
formatting see the cpptrace repository.

On Windows we skipped frames when verification fails and when
dump_backtrace was added the logic was wrong and would have skipped
frames we care about.

This commit also implements skipping frames on Linux.
The only time where this does not skip all frames is when the call to
backtrace gets intercepted. Then we will end up skipping one frame less
than needed.

To keep delayload on Windows a patch and overlay port is used. When
upstream accepts these changes and vcpkg bumps the version the patch
could be removed to have just the cmake define.
2025-10-08 07:07:57 +02:00
ayeteadoe
dc707e6ed8 AK: Expose ak_assertion_handler weak symbol for custom death handling
When a `VERIFY()` assertion fails `ak_verification_failed` is invoked
which means the program will invoke `__builtin_trap` and immediately
quit. But with this change we have now allowed for an optional hook
into `ak_*_failed` that lets us perform some custom
action before program exits. This foundation is what we will
(ab)use to implement death tests without the process cloning
CrashTest infrastructure.
2025-05-16 13:23:32 -06:00
InvalidUsernameException
1d63398cbd AK: Expose dump_backtrace() publicly for debugging purposes
At this point, I've repeatedly felt the desire to be able to log
stacktraces to be able to see more easily what kind of call-sites exist
for a given piece of code. So this commit exposes `dump_backtrace()` in
the header so it can be used for this purpose.
2025-05-06 10:03:57 -04:00
R-Goc
fe26c3145d AK: Add stacktrace support using the standard lib
This commit adds support for using the standard library implementation
of <stacktrace> if libbacktrace is not found. This can also be
explicitly enabled through ENABLE_STD_STACKTRACE for platforms that have
libbacktrace available.

Co-Authored-By: Andrew Kaster <andrew@ladybird.org>
2025-03-05 10:25:12 -07:00
Jonne Ransijn
e38b206957 AK: Print a more useful error message when a MUST(...) fails
```
VERIFICATION FAILED: !_temporary_result.is_error()
```

is not really a helpful error message.

When we are including `AK/Format.h`, which is most of the time,
we can easily print a much more useful error message:

```
UNEXPECTED ERROR: Cannot allocate memory (errno=12)
```
2024-12-02 20:07:38 +01:00
Andreas Kling
cc4b3cbacc Meta: Update my e-mail address everywhere 2024-10-04 13:19:50 +02:00
Andreas Kling
df18a76ad2 AK: Add ASSERT() and ASSERT_NOT_REACHED() for debug-only assertions
Let's move towards using these for things that are "nice to check in
debug builds, but not essential".
2024-07-10 07:03:20 +02:00
Andrew Kaster
002bef8635 AK+CMake: Use the find module to find the correct backtrace(3) header
As recommended by the CMake docs, let's tolerate systems or setups that
don't have backtrace(3) in the `<execinfo.h>` header file, such as those
using libbacktrace directly.
2024-07-01 10:15:24 -06:00
Tim Ledbetter
5ca2f4dfd7 Everywhere: Remove all KERNEL #defines 2024-06-18 09:36:25 +02:00
Ali Mohammad Pur
cafe60d713 AK: Disable assertion output colors on windows 2023-10-29 07:40:35 +01:00
Idan Horowitz
702dd0ca55 AK: Use array element count instead of memory size in backtrace call
The backtrace execinfo API takes the number of addresses the result
buffer can hold instead of its size, for some reason. Previously
backtraces larger than 256 frames deep would write past the end of the
result buffer.
2023-10-27 16:06:35 -04:00
Timothy Flynn
0eaf13bae3 AK: Colorize log message for failed assertions
The log message can be hard to spot in a sea of debug messages. Colorize
it to make the message more immediately pop out.
2023-10-24 06:58:53 -04:00
Niklas Poslovski
485ae28ba7 AK: Add support for backtraces on Haiku 2023-09-29 15:11:52 +01:00
Andrew Kaster
10d7ec2027 AK: Enable backtrace() on Android API level 33 and higher
``<execinfo.h>`` was added to bionic in Android 13 (API 33)
2023-09-15 14:18:52 -06:00
Sergey Bugaev
4825919bcf AK, LibCore: Enable misc things on glibc
program_invocation_name, pthread_getattr_np(), EXECINFO_BACKTRACE are
all glibc specifics (that other libcs may also have).
2023-09-06 07:14:35 -06:00
Andrew Kaster
6e8f1549a3 AK+LibCore: Don't use unsupported features on Android 2023-09-03 11:38:51 +02:00
Andrew Kaster
aa03f73c2e AK: Demangle symbols on assertion failure on Linux as well
While macOS backtrace(3) puts a space directly after the mangled symbol
name, some versions of glibc put a + directly after it. This new logic
accounts for both situations when trying to demangle.

Co-Authored-By: Andreas Kling <kling@serenityos.org>
2023-09-03 07:51:03 +02:00
Andrew Kaster
4641af7873 AK: Always use our assertion failure method, and add backtrace to it
On platforms that support it, enable using ``<execinfo.h>`` to get
backtrace(3) to dump a backtrace on assertion failure. This should make
debugging things like WebContent crashes in Lagom much easier.
2023-09-01 11:50:47 +02:00
Andrew Kaster
012aaecccf AK: Always define ak_assertion_failed, even when NDEBUG is false
Just because we may compile serenity with or without NDEBUG doesn't
mean that consuming projects or Ports will share the setting.

Always define the custom assertion function so that we don't have to
keep the same debug settings between all projects.
2023-02-05 09:46:51 -07:00
Andreas Kling
da781e90c1 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.
2022-10-06 15:29:38 +02:00