diff --git a/README.md b/README.md index c8d734c..1dd1c9d 100644 --- a/README.md +++ b/README.md @@ -382,6 +382,8 @@ CPPTRACE_TRY { } ``` +This functionality is entirely opt-in, the macros are in `cpptrace/from_current.hpp`. + Any declarator `catch` accepts works with `CPPTRACE_CATCH`, including `...`. ![from_current](res/from_current.png) diff --git a/src/from_current.cpp b/src/from_current.cpp index e7fbef6..06656d2 100644 --- a/src/from_current.cpp +++ b/src/from_current.cpp @@ -5,6 +5,7 @@ #include #include +#include "platform/platform.hpp" #include "utils/common.hpp" #include "utils/microfmt.hpp" #include "utils/utils.hpp" @@ -40,9 +41,9 @@ namespace cpptrace { unwind_interceptor::~unwind_interceptor() = default; - #if defined(__GLIBCXX__) || defined(__GLIBCPP__) + #if IS_LIBSTDCXX constexpr size_t vtable_size = 11; - #elif defined(_LIBCPP_VERSION) + #elif IS_LIBCXX constexpr size_t vtable_size = 10; #else #warning "Cpptrace from_current: Unrecognized C++ standard library, from_current() won't be supported" diff --git a/src/platform/exception_type.hpp b/src/platform/exception_type.hpp index b42f8de..5a989a3 100644 --- a/src/platform/exception_type.hpp +++ b/src/platform/exception_type.hpp @@ -3,21 +3,22 @@ #include -// libstdc++ and libc++ -#if defined(CPPTRACE_HAS_CXX_EXCEPTION_TYPE) && (defined(__GLIBCXX__) || defined(__GLIBCPP__) || defined(_LIBCPP_VERSION)) - #include -#endif +#include "platform/platform.hpp" -#include "demangle/demangle.hpp" +// libstdc++ and libc++ +#if defined(CPPTRACE_HAS_CXX_EXCEPTION_TYPE) && (IS_LIBSTDCXX || IS_LIBCXX) + #include + #include "demangle/demangle.hpp" +#endif namespace cpptrace { namespace detail { inline std::string exception_type_name() { - #if defined(CPPTRACE_HAS_CXX_EXCEPTION_TYPE) && (defined(__GLIBCXX__) || defined(__GLIBCPP__) || defined(_LIBCPP_VERSION)) - const std::type_info* t = abi::__cxa_current_exception_type(); - return t ? detail::demangle(t->name()) : ""; + #if defined(CPPTRACE_HAS_CXX_EXCEPTION_TYPE) && (IS_LIBSTDCXX || IS_LIBCXX) + const std::type_info* t = abi::__cxa_current_exception_type(); + return t ? detail::demangle(t->name()) : ""; #else - return ""; + return ""; #endif } } diff --git a/src/platform/path.hpp b/src/platform/path.hpp index d4cb5ee..f19320a 100644 --- a/src/platform/path.hpp +++ b/src/platform/path.hpp @@ -2,6 +2,7 @@ #define PATH_HPP #include "utils/common.hpp" +#include "platform/platform.hpp" #if IS_WINDOWS #include diff --git a/src/platform/platform.hpp b/src/platform/platform.hpp index 4d6ddfe..89206e8 100644 --- a/src/platform/platform.hpp +++ b/src/platform/platform.hpp @@ -35,4 +35,14 @@ #error "Unsupported compiler" #endif +#define IS_LIBSTDCXX 0 +#define IS_LIBCXX 0 +#if defined(__GLIBCXX__) || defined(__GLIBCPP__) +#undef IS_LIBSTDCXX +#define IS_LIBSTDCXX 1 +#elif defined(_LIBCPP_VERSION) +#undef IS_LIBCXX +#define IS_LIBCXX 1 +#endif + #endif diff --git a/src/platform/program_name.hpp b/src/platform/program_name.hpp index 19bcc37..3257244 100644 --- a/src/platform/program_name.hpp +++ b/src/platform/program_name.hpp @@ -4,7 +4,9 @@ #include #include -#if defined(_WIN32) +#include "platform/platform.hpp" + +#if IS_WINDOWS #include #define CPPTRACE_MAX_PATH MAX_PATH @@ -31,7 +33,7 @@ namespace detail { } } -#elif defined(__APPLE__) +#elif IS_APPLE #include #include @@ -61,7 +63,7 @@ namespace detail { } } -#elif defined(__linux__) +#elif IS_LINUX #include #include