Skip to content

Commit

Permalink
Update cpptrace to fix 32bit bug
Browse files Browse the repository at this point in the history
  • Loading branch information
0blu committed Sep 13, 2024
1 parent 242a9e9 commit 5025e3d
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 47 deletions.
58 changes: 26 additions & 32 deletions dep/cpptrace/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,15 @@ if(
)
)
# Attempt to auto-config
if(UNIX)
if(APPLE AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang"))
if(HAS_EXECINFO)
set(CPPTRACE_UNWIND_WITH_EXECINFO On)
message(STATUS "Cpptrace auto config: Using execinfo.h for unwinding")
else()
set(CPPTRACE_UNWIND_WITH_NOTHING On)
message(FATAL_ERROR "Cpptrace auto config: No unwinding back-end seems to be supported, stack tracing will not work. To compile anyway set CPPTRACE_UNWIND_WITH_NOTHING.")
endif()
elseif(UNIX)
if(HAS_UNWIND)
set(CPPTRACE_UNWIND_WITH_UNWIND On)
message(STATUS "Cpptrace auto config: Using libgcc unwind for unwinding")
Expand Down Expand Up @@ -406,50 +414,36 @@ if(CPPTRACE_GET_SYMBOLS_WITH_LIBDWARF)
find_package(zstd)
else()
cmake_policy(SET CMP0074 NEW)
set(ZSTD_BUILD_PROGRAMS OFF)
set(ZSTD_BUILD_CONTRIB OFF)
set(ZSTD_BUILD_TESTS OFF)
set(ZSTD_BUILD_STATIC ON)
set(ZSTD_BUILD_SHARED OFF)
set(ZSTD_LEGACY_SUPPORT OFF)
FetchContent_Declare(
zstd
GIT_REPOSITORY ${CPPTRACE_ZSTD_REPO}
GIT_TAG ${CPPTRACE_ZSTD_TAG}
GIT_SHALLOW ${CPPTRACE_ZSTD_SHALLOW}
URL "${CPPTRACE_ZSTD_URL}"
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
SOURCE_SUBDIR build/cmake
)
# FetchContent_MakeAvailable(zstd)
FetchContent_GetProperties(zstd)
if(NOT zstd_POPULATED)
FetchContent_Populate(zstd)
set(ZSTD_BUILD_PROGRAMS OFF)
set(ZSTD_BUILD_CONTRIB OFF)
set(ZSTD_BUILD_TESTS OFF)
set(ZSTD_BUILD_STATIC ON)
set(ZSTD_BUILD_SHARED OFF)
set(ZSTD_LEGACY_SUPPORT OFF)
add_subdirectory("${zstd_SOURCE_DIR}/build/cmake" "${zstd_BINARY_DIR}")
endif()
FetchContent_MakeAvailable(zstd)
endif()
# Libdwarf itself
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
# set(PIC_ALWAYS TRUE)
# set(BUILD_DWARFDUMP FALSE)
set(PIC_ALWAYS TRUE)
set(BUILD_DWARFDUMP FALSE)
FetchContent_Declare(
libdwarf
GIT_REPOSITORY ${CPPTRACE_LIBDWARF_REPO}
GIT_TAG ${CPPTRACE_LIBDWARF_TAG}
GIT_SHALLOW ${CPPTRACE_LIBDWARF_SHALLOW}
)
# FetchContent_MakeAvailable(libdwarf)
FetchContent_GetProperties(libdwarf)
if(NOT libdwarf_POPULATED)
set(PIC_ALWAYS TRUE)
set(BUILD_DWARFDUMP FALSE)
# set(ENABLE_DECOMPRESSION FALSE)
FetchContent_Populate(libdwarf)
add_subdirectory("${libdwarf_SOURCE_DIR}" "${libdwarf_BINARY_DIR}")
target_include_directories(
dwarf
PRIVATE
${zstd_SOURCE_DIR}/lib
)
endif()
FetchContent_MakeAvailable(libdwarf)
target_include_directories(
dwarf
PRIVATE
${zstd_SOURCE_DIR}/lib
)
endif()
if(CPPTRACE_CONAN)
target_link_libraries(${target_name} PRIVATE libdwarf::libdwarf)
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/0d89be4fbed1c6bf5c81dc024ca9cec489f7e1d4
Date: 2024-09-05T03:32:00Z
Commit: https://github.com/jeremy-rifkin/cpptrace/commit/4ed90c1585501f99a492f296a7f177503218f235
Date: 2024-09-13T05:42:17Z

## Copied files
```
Expand Down
6 changes: 2 additions & 4 deletions dep/cpptrace/cmake/OptionVariables.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ option(CPPTRACE_DEMANGLE_WITH_NOTHING "" OFF)
# ---- Back-end configurations ----

set(CPPTRACE_BACKTRACE_PATH "" CACHE STRING "Path to backtrace.h, if the compiler doesn't already know it. Check /usr/lib/gcc/x86_64-linux-gnu/*/include.")
set(CPPTRACE_HARD_MAX_FRAMES "" CACHE STRING "Hard limit on unwinding depth. Default is 200.")
set(CPPTRACE_HARD_MAX_FRAMES "" CACHE STRING "Hard limit on unwinding depth. Default is 400.")
set(CPPTRACE_ADDR2LINE_PATH "" CACHE STRING "Absolute path to the addr2line executable you want to use.")
option(CPPTRACE_ADDR2LINE_SEARCH_SYSTEM_PATH "" OFF)

Expand Down Expand Up @@ -176,9 +176,7 @@ option(CPPTRACE_SKIP_UNIT "" OFF)
option(CPPTRACE_STD_FORMAT "" ON)
option(CPPTRACE_UNPREFIXED_TRY_CATCH "" OFF)
option(CPPTRACE_USE_EXTERNAL_GTEST "" OFF)
set(CPPTRACE_ZSTD_REPO "https://github.com/facebook/zstd.git" CACHE STRING "")
set(CPPTRACE_ZSTD_TAG "794ea1b0afca0f020f4e57b6732332231fb23c70" CACHE STRING "") # v1.5.6
set(CPPTRACE_ZSTD_SHALLOW "1" CACHE STRING "")
set(CPPTRACE_ZSTD_URL "https://github.com/facebook/zstd/releases/download/v1.5.6/zstd-1.5.6.tar.gz" CACHE STRING "")
set(CPPTRACE_LIBDWARF_REPO "https://github.com/jeremy-rifkin/libdwarf-lite.git" CACHE STRING "")
set(CPPTRACE_LIBDWARF_TAG "97fd68c6026c0237943106d6bc3e83f3661d39e8" CACHE STRING "") # v0.11.0
set(CPPTRACE_LIBDWARF_SHALLOW "1" CACHE STRING "")
Expand Down
4 changes: 3 additions & 1 deletion dep/cpptrace/include/cpptrace/cpptrace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ namespace cpptrace {
);
struct CPPTRACE_EXPORT safe_object_frame {
frame_ptr raw_address;
frame_ptr address_relative_to_object_start; // base must still be added
// This ends up being the real object address. It was named at a time when I thought the object base address
// still needed to be added in
frame_ptr address_relative_to_object_start;
char object_path[CPPTRACE_PATH_MAX + 1];
// To be called outside a signal handler. Not signal safe.
object_frame resolve() const;
Expand Down
6 changes: 1 addition & 5 deletions dep/cpptrace/src/binary/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,9 @@ namespace detail {
""
};
}
auto base = get_module_image_base(frame.object_path);
if(base.is_error()) {
throw base.unwrap_error(); // This throw is intentional
}
return {
frame.raw_address,
frame.address_relative_to_object_start + base.unwrap_value(),
frame.address_relative_to_object_start,
std::move(object_path)
};
}
Expand Down
4 changes: 2 additions & 2 deletions dep/cpptrace/src/symbols/symbols_with_dbghelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ namespace dbghelp {
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
symbol->MaxNameLen = MAX_SYM_NAME;
union { DWORD64 a; DWORD b; } displacement;
IMAGEHLP_LINE64 line;
bool got_line = SymGetLineFromAddr64(proc, addr, &displacement.b, &line);
IMAGEHLP_LINE line;
bool got_line = SymGetLineFromAddr(proc, addr, &displacement.b, &line);
if(SymFromAddr(proc, addr, &displacement.a, symbol)) {
if(got_line) {
IMAGEHLP_STACK_FRAME frame;
Expand Down
2 changes: 1 addition & 1 deletion dep/cpptrace/src/unwind/unwind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace detail {
#ifdef CPPTRACE_HARD_MAX_FRAMES
constexpr std::size_t hard_max_frames = CPPTRACE_HARD_MAX_FRAMES;
#else
constexpr std::size_t hard_max_frames = 200;
constexpr std::size_t hard_max_frames = 400;
#endif

CPPTRACE_FORCE_NO_INLINE
Expand Down
2 changes: 2 additions & 0 deletions dep/cpptrace/src/utils/microfmt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// https://github.com/jeremy-rifkin/microfmt
// Format: {[align][width][:[fill][base]]} # width: number or {}

namespace cpptrace {
namespace microfmt {
namespace detail {
inline std::uint64_t clz(std::uint64_t value) {
Expand Down Expand Up @@ -301,5 +302,6 @@ namespace microfmt {
fwrite(str.data(), 1, str.size(), stream);
}
}
}

#endif

0 comments on commit 5025e3d

Please sign in to comment.