Skip to content

Commit

Permalink
Update cpptrace to fix Visual Studio 2015 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
0blu committed Sep 5, 2024
1 parent 7e50e26 commit 6161309
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 41 deletions.
52 changes: 31 additions & 21 deletions dep/cpptrace/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ endif()
if(NOT WIN32)
check_support(HAS_UNWIND has_unwind.cpp "" "" "")
check_support(HAS_EXECINFO has_execinfo.cpp "" "" "")
check_support(HAS_BACKTRACE has_backtrace.cpp "" "backtrace" "${CPPTRACE_BACKTRACE_PATH_DEFINITION}")
set(STACKTRACE_LINK_LIB "stdc++_libbacktrace")
else()
check_support(HAS_STACKWALK has_stackwalk.cpp "" "dbghelp" "")
endif()

if(NOT WIN32 OR MINGW)
check_support(HAS_BACKTRACE has_backtrace.cpp "" "backtrace" "${CPPTRACE_BACKTRACE_PATH_DEFINITION}")
set(STACKTRACE_LINK_LIB "stdc++_libbacktrace")
check_support(HAS_CXX_EXCEPTION_TYPE has_cxx_exception_type.cpp "" "" "")
endif()

Expand All @@ -99,6 +99,10 @@ if(UNIX AND NOT APPLE)
endif()
endif()

if(APPLE)
check_support(HAS_MACH_VM has_mach_vm.cpp "" "" "")
endif()

# =============================================== Autoconfig unwinding ===============================================
# Unwind back-ends
if(
Expand Down Expand Up @@ -340,6 +344,10 @@ if(HAS_DLADDR1)
target_compile_definitions(${target_name} PUBLIC CPPTRACE_HAS_DLADDR1)
endif()

if(HAS_MACH_VM)
target_compile_definitions(${target_name} PUBLIC HAS_MACH_VM)
endif()

# Symbols
if(CPPTRACE_GET_SYMBOLS_WITH_LIBBACKTRACE)
if(NOT HAS_BACKTRACE)
Expand Down Expand Up @@ -523,26 +531,28 @@ if(CPPTRACE_UNWIND_WITH_LIBUNWIND)
endif()
endif()
if(NOT libunwind_FOUND)
# set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON)
# set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS ON)
find_path(LIBUNWIND_INCLUDE_DIRS NAMES "libunwind.h")
find_library(LIBUNWIND NAMES unwind libunwind libunwind8 libunwind.so.8 REQUIRED PATHS "/usr/lib/x86_64-linux-gnu/")
if(LIBUNWIND)
set(libunwind_FOUND TRUE)
endif()
if(NOT libunwind_FOUND)
# message(FATAL_ERROR "Unable to locate libunwind")
# Try to link with it if it's where it should be
# This path can be entered if libunwind was installed via the system package manager, sometimes. I probably messed
# up the find_library above.
set(LIBUNWIND_LDFLAGS "-lunwind")
endif()
if(NOT LIBUNWIND_LDFLAGS)
set(LIBUNWIND_LDFLAGS "${LIBUNWIND}")
if (NOT APPLE)
# set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON)
# set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS ON)
find_path(LIBUNWIND_INCLUDE_DIRS NAMES "libunwind.h")
find_library(LIBUNWIND NAMES unwind libunwind libunwind8 libunwind.so.8 REQUIRED PATHS "/usr/lib/x86_64-linux-gnu/")
if(LIBUNWIND)
set(libunwind_FOUND TRUE)
endif()
if(NOT libunwind_FOUND)
# message(FATAL_ERROR "Unable to locate libunwind")
# Try to link with it if it's where it should be
# This path can be entered if libunwind was installed via the system package manager, sometimes. I probably messed
# up the find_library above.
set(LIBUNWIND_LDFLAGS "-lunwind")
endif()
if(NOT LIBUNWIND_LDFLAGS)
set(LIBUNWIND_LDFLAGS "${LIBUNWIND}")
endif()
target_compile_options(${target_name} PRIVATE ${LIBUNWIND_CFLAGS_OTHER})
target_include_directories(${target_name} PRIVATE ${LIBUNWIND_INCLUDE_DIRS})
target_link_libraries(${target_name} PRIVATE ${LIBUNWIND_LDFLAGS})
endif()
target_compile_options(${target_name} PRIVATE ${LIBUNWIND_CFLAGS_OTHER})
target_include_directories(${target_name} PRIVATE ${LIBUNWIND_INCLUDE_DIRS})
target_link_libraries(${target_name} PRIVATE ${LIBUNWIND_LDFLAGS})
target_compile_definitions(${target_name} PUBLIC CPPTRACE_UNWIND_WITH_LIBUNWIND UNW_LOCAL_ONLY)
endif()
endif()
Expand Down
4 changes: 2 additions & 2 deletions dep/cpptrace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
It is used in MaNGOS to print the stack trace on failure.

## Source
Commit: https://github.com/jeremy-rifkin/cpptrace/commit/0742b42dadaac62436cb226a7d084738a8f82d1a
Date: 2024-08-21T13:47:23Z
Commit: https://github.com/jeremy-rifkin/cpptrace/commit/0d89be4fbed1c6bf5c81dc024ca9cec489f7e1d4
Date: 2024-09-05T03:32:00Z

## Copied files
```
Expand Down
23 changes: 23 additions & 0 deletions dep/cpptrace/cmake/has_mach_vm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <mach/mach.h>
#include <mach/mach_vm.h>
#include <cstdint>

int main() {
mach_vm_size_t vmsize;
uintptr_t addr = reinterpret_cast<uintptr_t>(&vmsize);
uintptr_t page_addr = addr & ~(4096 - 1);
mach_vm_address_t address = (mach_vm_address_t)page_addr;
vm_region_basic_info_data_t info;
mach_msg_type_number_t info_count =
sizeof(size_t) == 8 ? VM_REGION_BASIC_INFO_COUNT_64 : VM_REGION_BASIC_INFO_COUNT;
memory_object_name_t object;
mach_vm_region(
mach_task_self(),
&address,
&vmsize,
VM_REGION_BASIC_INFO,
(vm_region_info_t)&info,
&info_count,
&object
);
}
8 changes: 4 additions & 4 deletions dep/cpptrace/src/cpptrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ namespace cpptrace {
namespace detail {
std::atomic_bool absorb_trace_exceptions(true); // NOSONAR
std::atomic_bool resolve_inlined_calls(true); // NOSONAR
std::atomic<enum cache_mode> cache_mode(cache_mode::prioritize_speed); // NOSONAR
std::atomic<cache_mode> current_cache_mode(cache_mode::prioritize_speed); // NOSONAR
}

void absorb_trace_exceptions(bool absorb) {
Expand All @@ -508,7 +508,7 @@ namespace cpptrace {

namespace experimental {
void set_cache_mode(cache_mode mode) {
detail::cache_mode = mode;
detail::current_cache_mode = mode;
}
}

Expand All @@ -521,8 +521,8 @@ namespace cpptrace {
return resolve_inlined_calls;
}

enum cache_mode get_cache_mode() {
return cache_mode;
cache_mode get_cache_mode() {
return current_cache_mode;
}

CPPTRACE_FORCE_NO_INLINE
Expand Down
17 changes: 15 additions & 2 deletions dep/cpptrace/src/from_current.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#include <unistd.h>
#if IS_APPLE
#include <mach/mach.h>
#include <mach/mach_vm.h>
#ifdef HAS_MACH_VM
#include <mach/mach_vm.h>
#endif
#else
#include <fstream>
#include <iomanip>
Expand Down Expand Up @@ -112,13 +114,24 @@ namespace cpptrace {
#if IS_APPLE
int get_page_protections(void* page) {
// https://stackoverflow.com/a/12627784/15675011
#ifdef HAS_MACH_VM
mach_vm_size_t vmsize;
mach_vm_address_t address = (mach_vm_address_t)page;
#else
vm_size_t vmsize;
vm_address_t address = (vm_address_t)page;
#endif
vm_region_basic_info_data_t info;
mach_msg_type_number_t info_count =
sizeof(size_t) == 8 ? VM_REGION_BASIC_INFO_COUNT_64 : VM_REGION_BASIC_INFO_COUNT;
memory_object_name_t object;
kern_return_t status = mach_vm_region(
kern_return_t status =
#ifdef HAS_MACH_VM
mach_vm_region
#else
vm_region_64
#endif
(
mach_task_self(),
&address,
&vmsize,
Expand Down
2 changes: 1 addition & 1 deletion dep/cpptrace/src/platform/program_name.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace cpptrace {
namespace detail {
inline std::string program_name() {
inline const char* program_name() {
static std::mutex mutex;
const std::lock_guard<std::mutex> lock(mutex);
static std::string name;
Expand Down
2 changes: 1 addition & 1 deletion dep/cpptrace/src/utils/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace detail {

bool should_absorb_trace_exceptions();
bool should_resolve_inlined_calls();
enum cache_mode get_cache_mode();
cache_mode get_cache_mode();
}
}

Expand Down
16 changes: 8 additions & 8 deletions dep/cpptrace/src/utils/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ namespace detail {
// Lightweight std::source_location.
struct source_location {
const char* const file;
//const char* const function; // disabled for now due to static constexpr restrictions
const int line;
constexpr source_location(
//const char* _function /*= __builtin_FUNCTION()*/,
const char* _file = __builtin_FILE(),
int _line = __builtin_LINE()
) : file(_file), /*function(_function),*/ line(_line) {}
const char* _file,
int _line
) : file(_file), line(_line) {}
};

#define CPPTRACE_CURRENT_LOCATION ::cpptrace::detail::source_location(__FILE__, __LINE__)

enum class assert_type {
assert,
verify,
Expand Down Expand Up @@ -117,7 +117,7 @@ namespace detail {
}

// Check condition in both debug and release. std::runtime_error on failure.
#define PANIC(...) ((::cpptrace::detail::panic)(CPPTRACE_PFUNC, {}, ::cpptrace::detail::as_string(__VA_ARGS__)))
#define PANIC(...) ((::cpptrace::detail::panic)(CPPTRACE_PFUNC, CPPTRACE_CURRENT_LOCATION, ::cpptrace::detail::as_string(__VA_ARGS__)))

template<typename T>
void assert_impl(
Expand Down Expand Up @@ -153,13 +153,13 @@ namespace detail {

// Check condition in both debug and release. std::runtime_error on failure.
#define VERIFY(...) ( \
assert_impl(__VA_ARGS__, ::cpptrace::detail::assert_type::verify, #__VA_ARGS__, CPPTRACE_PFUNC, {}) \
assert_impl(__VA_ARGS__, ::cpptrace::detail::assert_type::verify, #__VA_ARGS__, CPPTRACE_PFUNC, CPPTRACE_CURRENT_LOCATION) \
)

#ifndef NDEBUG
// Check condition in both debug. std::runtime_error on failure.
#define ASSERT(...) ( \
assert_impl(__VA_ARGS__, ::cpptrace::detail::assert_type::assert, #__VA_ARGS__, CPPTRACE_PFUNC, {}) \
assert_impl(__VA_ARGS__, ::cpptrace::detail::assert_type::assert, #__VA_ARGS__, CPPTRACE_PFUNC, CPPTRACE_CURRENT_LOCATION) \
)
#else
// Check condition in both debug. std::runtime_error on failure.
Expand Down
6 changes: 4 additions & 2 deletions dep/cpptrace/src/utils/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,10 @@ namespace detail {
template<
typename T,
typename D
// workaround a msvc bug https://developercommunity.visualstudio.com/t/MSVC-1938331290-preview-fails-to-comp/10505565
#if !defined(_MSC_VER) || _MSC_VER != 1938
// workaround for:
// == 19.38-specific msvc bug https://developercommunity.visualstudio.com/t/MSVC-1938331290-preview-fails-to-comp/10505565
// <= 19.23 msvc also appears to fail (but for a different reason https://godbolt.org/z/6Y5EvdWPK)
#if !defined(_MSC_VER) || !(_MSC_VER <= 1923 || _MSC_VER == 1938)
,
typename std::enable_if<
std::is_same<decltype(std::declval<D>()(std::declval<T>())), void>::value,
Expand Down

0 comments on commit 6161309

Please sign in to comment.