Some more platform refactoring/cleanup, also add a note to readme

This commit is contained in:
Jeremy Rifkin 2024-08-18 12:07:34 -05:00
parent 164cc75681
commit 973309cb22
No known key found for this signature in database
GPG Key ID: 19AA8270105E8EB4
6 changed files with 31 additions and 14 deletions

View File

@ -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 `...`. Any declarator `catch` accepts works with `CPPTRACE_CATCH`, including `...`.
![from_current](res/from_current.png) ![from_current](res/from_current.png)

View File

@ -5,6 +5,7 @@
#include <system_error> #include <system_error>
#include <typeinfo> #include <typeinfo>
#include "platform/platform.hpp"
#include "utils/common.hpp" #include "utils/common.hpp"
#include "utils/microfmt.hpp" #include "utils/microfmt.hpp"
#include "utils/utils.hpp" #include "utils/utils.hpp"
@ -40,9 +41,9 @@ namespace cpptrace {
unwind_interceptor::~unwind_interceptor() = default; unwind_interceptor::~unwind_interceptor() = default;
#if defined(__GLIBCXX__) || defined(__GLIBCPP__) #if IS_LIBSTDCXX
constexpr size_t vtable_size = 11; constexpr size_t vtable_size = 11;
#elif defined(_LIBCPP_VERSION) #elif IS_LIBCXX
constexpr size_t vtable_size = 10; constexpr size_t vtable_size = 10;
#else #else
#warning "Cpptrace from_current: Unrecognized C++ standard library, from_current() won't be supported" #warning "Cpptrace from_current: Unrecognized C++ standard library, from_current() won't be supported"

View File

@ -3,17 +3,18 @@
#include <string> #include <string>
// libstdc++ and libc++ #include "platform/platform.hpp"
#if defined(CPPTRACE_HAS_CXX_EXCEPTION_TYPE) && (defined(__GLIBCXX__) || defined(__GLIBCPP__) || defined(_LIBCPP_VERSION))
#include <cxxabi.h>
#endif
#include "demangle/demangle.hpp" // libstdc++ and libc++
#if defined(CPPTRACE_HAS_CXX_EXCEPTION_TYPE) && (IS_LIBSTDCXX || IS_LIBCXX)
#include <cxxabi.h>
#include "demangle/demangle.hpp"
#endif
namespace cpptrace { namespace cpptrace {
namespace detail { namespace detail {
inline std::string exception_type_name() { inline std::string exception_type_name() {
#if defined(CPPTRACE_HAS_CXX_EXCEPTION_TYPE) && (defined(__GLIBCXX__) || defined(__GLIBCPP__) || defined(_LIBCPP_VERSION)) #if defined(CPPTRACE_HAS_CXX_EXCEPTION_TYPE) && (IS_LIBSTDCXX || IS_LIBCXX)
const std::type_info* t = abi::__cxa_current_exception_type(); const std::type_info* t = abi::__cxa_current_exception_type();
return t ? detail::demangle(t->name()) : "<unknown>"; return t ? detail::demangle(t->name()) : "<unknown>";
#else #else

View File

@ -2,6 +2,7 @@
#define PATH_HPP #define PATH_HPP
#include "utils/common.hpp" #include "utils/common.hpp"
#include "platform/platform.hpp"
#if IS_WINDOWS #if IS_WINDOWS
#include <windows.h> #include <windows.h>

View File

@ -35,4 +35,14 @@
#error "Unsupported compiler" #error "Unsupported compiler"
#endif #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 #endif

View File

@ -4,7 +4,9 @@
#include <mutex> #include <mutex>
#include <string> #include <string>
#if defined(_WIN32) #include "platform/platform.hpp"
#if IS_WINDOWS
#include <windows.h> #include <windows.h>
#define CPPTRACE_MAX_PATH MAX_PATH #define CPPTRACE_MAX_PATH MAX_PATH
@ -31,7 +33,7 @@ namespace detail {
} }
} }
#elif defined(__APPLE__) #elif IS_APPLE
#include <cstdint> #include <cstdint>
#include <mach-o/dyld.h> #include <mach-o/dyld.h>
@ -61,7 +63,7 @@ namespace detail {
} }
} }
#elif defined(__linux__) #elif IS_LINUX
#include <linux/limits.h> #include <linux/limits.h>
#include <sys/types.h> #include <sys/types.h>