Skip to content

Commit c81d31e

Browse files
committed
[Core] improve stacktrace output
1 parent 9118cea commit c81d31e

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

include/stormkit/Core/PlatformMacro.hpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,49 @@
1919

2020
#if defined(_MSC_VER) and not defined(__clang__)
2121
#pragma warning(disable: 4251)
22-
#define STORMKIT_COMPILER_MSVC "MSVC " + std::to_string(_MSC_VER)
23-
#define STORMKIT_COMPILER STORMKIT_COMPILER_MSVC
24-
#define STORMKIT_EXPORT __declspec(dllexport)
25-
#define STORMKIT_IMPORT __declspec(dllimport)
26-
#define STORMKIT_RESTRICT __restrict
22+
#define STORMKIT_COMPILER_MSSTL "MSSTL"
23+
#define STORMKIT_COMPILER_CXXLIB STORMKIT_COMPILER_MSSTL
24+
#define STORMKIT_COMPILER_MSVC "MSVC " + std::to_string(_MSC_VER)
25+
#define STORMKIT_COMPILER STORMKIT_COMPILER_MSVC
26+
#define STORMKIT_EXPORT __declspec(dllexport)
27+
#define STORMKIT_IMPORT __declspec(dllimport)
28+
#define STORMKIT_RESTRICT __restrict
2729
#define STORMKIT_PRIVATE
2830
#define STORMKIT_FORCE_INLINE_IMPL __forceinline
2931
#elif defined(_MSC_VER) and defined(__clang__)
32+
#if defined(_LIBCPP_VERSION)
33+
#define STORMKIT_COMPILER_LIBCPP "libc++"
34+
#define STORMKIT_COMPILER_CXXLIB STORMKIT_COMPILER_LIBCPP
35+
#else
36+
#define STORMKIT_COMPILER_MSSTL "MSSTL"
37+
#define STORMKIT_COMPILER_CXXLIB STORMKIT_COMPILER_MSSTL
38+
#endif
3039
#define STORMKIT_EXPORT __declspec(dllexport)
3140
#define STORMKIT_IMPORT __declspec(dllimport)
3241
#define STORMKIT_PRIVATE [[gnu::visibility("hidden")]]
3342
#define STORMKIT_RESTRICT __restrict
3443
#define STORMKIT_FORCE_INLINE_IMPL [[gnu::always_inline]] inline
3544
#elif defined(__MINGW32__)
45+
#if defined(_LIBCPP_VERSION)
46+
#define STORMKIT_COMPILER_LIBCPP "libc++"
47+
#define STORMKIT_COMPILER_CXXLIB STORMKIT_COMPILER_LIBCPP
48+
#else
49+
#define STORMKIT_COMPILER_LIBSTDCPP "libstdc++"
50+
#define STORMKIT_COMPILER_CXXLIB STORMKIT_COMPILER_LIBSTDCPP
51+
#endif
3652
#define STORMKIT_EXPORT __declspec(dllexport)
3753
#define STORMKIT_IMPORT __declspec(dllimport)
3854
#define STORMKIT_PRIVATE
3955
#define STORMKIT_RESTRICT __restrict inline
4056
#define STORMKIT_FORCE_INLINE_IMPL [[gnu::always_inline]] inline
4157
#else
58+
#if defined(_LIBCPP_VERSION)
59+
#define STORMKIT_COMPILER_LIBCPP "libc++"
60+
#define STORMKIT_COMPILER_CXXLIB STORMKIT_COMPILER_LIBCPP
61+
#else
62+
#define STORMKIT_COMPILER_LIBSTDCPP "libstdc++"
63+
#define STORMKIT_COMPILER_CXXLIB STORMKIT_COMPILER_LIBSTDCPP
64+
#endif
4265
#define STORMKIT_IMPORT [[gnu::visibility("default")]]
4366
#define STORMKIT_EXPORT [[gnu::visibility("default")]]
4467
#define STORMKIT_PRIVATE [[gnu::visibility("hidden")]]

src/Core/Stacktrace.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ module;
88
#include <cpptrace/cpptrace.hpp>
99
#endif
1010

11+
#include <stormkit/Core/PlatformMacro.hpp>
12+
1113
module stormkit.Core;
1214

1315
import std;
1416

1517
import :Console;
18+
import :String.Operations;
1619

1720
namespace stormkit::core {
1821
/////////////////////////////////////
@@ -39,6 +42,16 @@ namespace stormkit::core {
3942
i += 1;
4043
continue;
4144
}
45+
auto symbol = frame.symbol;
46+
#ifdef STORMKIT_COMPILER_LIBCPP
47+
symbol = replace(symbol, "::__1::", "::");
48+
#endif
49+
symbol
50+
= replace(symbol, "basic_string_view<char, std::char_traits<char>>", "string_view");
51+
symbol = replace(symbol,
52+
"basic_string<char, std::char_traits<char>, std::allocator<char>>",
53+
"string");
54+
4255
if (frame.line.has_value() and frame.column.has_value())
4356
std::println(std::cerr,
4457
"{}# {}{} at {}:{}:{}",
@@ -51,7 +64,7 @@ namespace stormkit::core {
5164
? ""
5265
: std::format(" in {}",
5366
ConsoleStyle { .fg = ConsoleColor::Yellow }
54-
| frame.symbol),
67+
| symbol),
5568
ConsoleStyle { .fg = ConsoleColor::Green } | frame.filename,
5669
ConsoleStyle { .fg = ConsoleColor::Blue } | frame.line.value(),
5770
ConsoleStyle { .fg = ConsoleColor::Blue } | frame.column.value());
@@ -67,7 +80,7 @@ namespace stormkit::core {
6780
? ""
6881
: std::format(" in {}",
6982
ConsoleStyle { .fg = ConsoleColor::Yellow }
70-
| frame.symbol),
83+
| symbol),
7184
ConsoleStyle { .fg = ConsoleColor::Green } | frame.filename);
7285
}
7386
}

0 commit comments

Comments
 (0)