From 1d63398cbd071cd8c93b7c7db15d700c6df62af9 Mon Sep 17 00:00:00 2001 From: InvalidUsernameException Date: Sun, 4 May 2025 17:33:39 +0200 Subject: [PATCH] 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. --- AK/Assertions.cpp | 15 ++++++++------- AK/Assertions.h | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/AK/Assertions.cpp b/AK/Assertions.cpp index f5adf981f35..dfc8ab6ec37 100644 --- a/AK/Assertions.cpp +++ b/AK/Assertions.cpp @@ -33,18 +33,17 @@ # define ERRORLN warnln #endif +extern "C" { + #if defined(AK_HAS_STD_STACKTRACE) -namespace { -ALWAYS_INLINE void dump_backtrace() +void dump_backtrace() { // We assume the stacktrace implementation demangles symbols, as does microsoft/STL PRINT_ERROR(std::to_string(std::stacktrace::current(2)).c_str()); PRINT_ERROR("\n"); } -} #elif defined(AK_HAS_BACKTRACE_HEADER) -namespace { -ALWAYS_INLINE void dump_backtrace() +void dump_backtrace() { // Grab symbols and dso name for up to 256 frames void* trace[256] = {}; @@ -89,11 +88,13 @@ ALWAYS_INLINE void dump_backtrace() } free(syms); } +#else +void dump_backtrace() +{ + PRINT_ERROR("dump_backtrace() is not supported with the current compilation options.\n"); } #endif -extern "C" { - bool ak_colorize_output(void) { #if defined(AK_OS_SERENITY) || defined(AK_OS_ANDROID) diff --git a/AK/Assertions.h b/AK/Assertions.h index 83d913067ba..1d339e4d46b 100644 --- a/AK/Assertions.h +++ b/AK/Assertions.h @@ -6,6 +6,7 @@ #pragma once +extern "C" void dump_backtrace(); extern "C" bool ak_colorize_output(void); extern "C" __attribute__((noreturn)) void ak_trap(void);