Cleanup exception stacktraces, so the compile the same on Windows.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
Stacktraces still appear to be empty on Windows, but that's an issue for a later day.
This commit is contained in:
parent
eb8356145f
commit
ba411d011b
|
@ -28,7 +28,7 @@ steps:
|
||||||
- cmake --build build-release --target all -- -j 4
|
- cmake --build build-release --target all -- -j 4
|
||||||
- cd build-debug
|
- cd build-debug
|
||||||
- ./ArbutilsTests -s --duration=true --force-colors=true
|
- ./ArbutilsTests -s --duration=true --force-colors=true
|
||||||
- valgrind --tool=memcheck --gen-suppressions=all --leak-check=full --leak-resolution=med --track-origins=yes --vgdb=no --error-exitcode=1 ./ArbutilsTests --test-case-exclude="Throw exception get stack trace"
|
- valgrind --tool=memcheck --gen-suppressions=all --leak-check=full --leak-resolution=med --track-origins=yes --vgdb=no --error-exitcode=1 ./ArbutilsTests
|
||||||
- name: test-release-windows
|
- name: test-release-windows
|
||||||
image: deukhoofd/windowsbuilder
|
image: deukhoofd/windowsbuilder
|
||||||
commands:
|
commands:
|
||||||
|
@ -63,6 +63,6 @@ volumes:
|
||||||
path: /home/docs/Arbutils
|
path: /home/docs/Arbutils
|
||||||
---
|
---
|
||||||
kind: signature
|
kind: signature
|
||||||
hmac: a85bf6d81ed3a176b8761dc084080dc0234b052ef3c60f07bb6b932dac4811d3
|
hmac: 38b3e0329693c61f83bcee5a596e6c560a591dc9f8ac8362e60387a99acb3626
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
|
@ -10,9 +10,9 @@ set(CMAKE_CXX_STANDARD 20)
|
||||||
|
|
||||||
if (NOT WINDOWS)
|
if (NOT WINDOWS)
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||||
else()
|
else ()
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
|
set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
|
||||||
endif()
|
endif ()
|
||||||
|
|
||||||
option(WINDOWS "Whether the build target is Windows or not." OFF)
|
option(WINDOWS "Whether the build target is Windows or not." OFF)
|
||||||
option(SHARED "Whether we should build a shared library, instead of a static one." OFF)
|
option(SHARED "Whether we should build a shared library, instead of a static one." OFF)
|
||||||
|
@ -31,7 +31,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||||
add_link_options(-fuse-ld=lld)
|
add_link_options(-fuse-ld=lld)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (CMAKE_BUILD_TYPE MATCHES Release AND NOT WINDOWS)
|
if (CMAKE_BUILD_TYPE MATCHES Release)
|
||||||
# Include debug symbols in all linux builds
|
# Include debug symbols in all linux builds
|
||||||
message("Including debug symbols")
|
message("Including debug symbols")
|
||||||
add_compile_options(-g -gline-tables-only)
|
add_compile_options(-g -gline-tables-only)
|
||||||
|
@ -49,8 +49,8 @@ CPMAddPackage(
|
||||||
DOWNLOAD_ONLY YES
|
DOWNLOAD_ONLY YES
|
||||||
)
|
)
|
||||||
CPMAddPackage(
|
CPMAddPackage(
|
||||||
NAME pcg-cpp
|
NAME pcg-cpp
|
||||||
GITHUB_REPOSITORY imneme/pcg-cpp
|
GITHUB_REPOSITORY imneme/pcg-cpp
|
||||||
GIT_TAG master
|
GIT_TAG master
|
||||||
DOWNLOAD_ONLY YES
|
DOWNLOAD_ONLY YES
|
||||||
)
|
)
|
||||||
|
@ -66,32 +66,36 @@ if (WINDOWS)
|
||||||
add_compile_options(-m64)
|
add_compile_options(-m64)
|
||||||
if (SHARED)
|
if (SHARED)
|
||||||
set_target_properties(Arbutils PROPERTIES SUFFIX ".dll")
|
set_target_properties(Arbutils PROPERTIES SUFFIX ".dll")
|
||||||
endif()
|
endif ()
|
||||||
endif (WINDOWS)
|
endif (WINDOWS)
|
||||||
|
|
||||||
if (CMAKE_BUILD_TYPE MATCHES "Debug")
|
if (CMAKE_BUILD_TYPE MATCHES "Debug")
|
||||||
ADD_DEFINITIONS(-DDEBUG)
|
ADD_DEFINITIONS(-DDEBUG)
|
||||||
endif()
|
endif ()
|
||||||
|
|
||||||
set(LINKS)
|
set(LINKS)
|
||||||
if (NOT WINDOWS AND PRETTYTRACES)
|
if (PRETTYTRACES)
|
||||||
set(LINKS ${LINKS} -lbfd -ldl)
|
if (NOT WINDOWS)
|
||||||
|
set(LINKS ${LINKS} -ldw)
|
||||||
|
else ()
|
||||||
|
set(LINKS ${LINKS} -ldbghelp -lpsapi)
|
||||||
|
endif ()
|
||||||
ADD_DEFINITIONS(-DPRETTYTRACES=1)
|
ADD_DEFINITIONS(-DPRETTYTRACES=1)
|
||||||
endif()
|
endif ()
|
||||||
if (SIGNAL_HANDLING)
|
if (SIGNAL_HANDLING)
|
||||||
ADD_DEFINITIONS(-DSIGNAL_HANDLING=1)
|
ADD_DEFINITIONS(-DSIGNAL_HANDLING=1)
|
||||||
endif()
|
endif ()
|
||||||
|
|
||||||
# If we want to link the C and C++ library statically, link those as well.
|
# If we want to link the C and C++ library statically, link those as well.
|
||||||
if (STATICC)
|
if (STATICC)
|
||||||
message("Linking dependencies statically.")
|
message("Linking dependencies statically.")
|
||||||
set (CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed")
|
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed")
|
||||||
set(LINKS -static-libgcc -static-libstdc++ ${LINKS})
|
set(LINKS -static-libgcc -static-libstdc++ ${LINKS})
|
||||||
endif(STATICC)
|
endif (STATICC)
|
||||||
|
|
||||||
if (WINDOWS)
|
if (WINDOWS)
|
||||||
set(LINKS ${LINKS} -Wl,-Bstatic -lm -lstdc++ -lpthread -Wl,-Bdynamic)
|
set(LINKS ${LINKS} -Wl,-Bstatic -lm -lstdc++ -lpthread -Wl,-Bdynamic)
|
||||||
endif()
|
endif ()
|
||||||
|
|
||||||
target_link_libraries(Arbutils ${LINKS})
|
target_link_libraries(Arbutils ${LINKS})
|
||||||
|
|
||||||
|
@ -120,4 +124,4 @@ if (NOT WINDOWS)
|
||||||
install(TARGETS Arbutils
|
install(TARGETS Arbutils
|
||||||
CONFIGURATIONS Release
|
CONFIGURATIONS Release
|
||||||
RUNTIME DESTINATION lib)
|
RUNTIME DESTINATION lib)
|
||||||
endif()
|
endif ()
|
|
@ -9,12 +9,10 @@
|
||||||
#include <source_location>
|
#include <source_location>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !WINDOWS
|
#if PRETTYTRACES && !WINDOWS
|
||||||
#if PRETTYTRACES
|
#define BACKWARD_HAS_DW 1
|
||||||
#define BACKWARD_HAS_BFD 1
|
|
||||||
#endif
|
#endif
|
||||||
#include <backward.hpp>
|
#include <backward.hpp>
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
namespace std {
|
namespace std {
|
||||||
|
@ -35,35 +33,24 @@ static constexpr const char* file_name(const char* path) {
|
||||||
namespace ArbUt {
|
namespace ArbUt {
|
||||||
/// @brief Implementation of std::logic_error that gives a stack trace when thrown.
|
/// @brief Implementation of std::logic_error that gives a stack trace when thrown.
|
||||||
class Exception : std::logic_error {
|
class Exception : std::logic_error {
|
||||||
#if !WINDOWS
|
|
||||||
backward::StackTrace _stack;
|
backward::StackTrace _stack;
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// @brief Throw an exception with specified message.
|
/// @brief Throw an exception with specified message.
|
||||||
explicit Exception(const std::string& msg) : std::logic_error(msg) {
|
explicit Exception(const std::string& msg) : std::logic_error(msg), _stack({}) {
|
||||||
#if !WINDOWS
|
|
||||||
_stack.load_here(32);
|
_stack.load_here(32);
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
_stack.skip_n_firsts(2);
|
_stack.skip_n_firsts(2);
|
||||||
#else
|
#else
|
||||||
_stack.skip_n_firsts(0);
|
_stack.skip_n_firsts(0);
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Copy operator.
|
/// @brief Copy operator.
|
||||||
Exception(const Exception& e) noexcept
|
Exception(const Exception& e) noexcept : std::logic_error(e.what()), _stack(e._stack) {}
|
||||||
: std::logic_error(e.what())
|
|
||||||
#if !WINDOWS
|
|
||||||
,
|
|
||||||
_stack(e._stack)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
}
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
/// @brief Throw a nicely formatted exception. The exception message will have the file name, line number, message,
|
/// @brief Throw a nicely formatted exception. The exception message will have the file name, line number,
|
||||||
/// along with any optional parameters passed.
|
/// message, along with any optional parameters passed.
|
||||||
[[noreturn]] static void Throw(const std::string& expression, const std::source_location& location,
|
[[noreturn]] static void Throw(const std::string& expression, const std::source_location& location,
|
||||||
const Args... args) {
|
const Args... args) {
|
||||||
std::stringstream error;
|
std::stringstream error;
|
||||||
|
@ -86,14 +73,9 @@ namespace ArbUt {
|
||||||
/// retrieved.
|
/// retrieved.
|
||||||
[[nodiscard]] std::string GetStacktrace([[maybe_unused]] size_t depth = 6,
|
[[nodiscard]] std::string GetStacktrace([[maybe_unused]] size_t depth = 6,
|
||||||
[[maybe_unused]] bool include_addr = true) const {
|
[[maybe_unused]] bool include_addr = true) const {
|
||||||
#if !WINDOWS
|
|
||||||
return BuildStacktraceFromStack(_stack, depth, include_addr);
|
return BuildStacktraceFromStack(_stack, depth, include_addr);
|
||||||
#else
|
|
||||||
return "Stack trace not available on Windows.";
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !WINDOWS
|
|
||||||
/// @brief Builds a string from a given stack.
|
/// @brief Builds a string from a given stack.
|
||||||
/// @param stack The stack to build the string from.
|
/// @param stack The stack to build the string from.
|
||||||
/// @param depth The max number of stacks it should retrieve.
|
/// @param depth The max number of stacks it should retrieve.
|
||||||
|
@ -170,7 +152,6 @@ namespace ArbUt {
|
||||||
|
|
||||||
ss << fileName << "[" << source.line << "] " << snippet << std::endl;
|
ss << fileName << "[" << source.line << "] " << snippet << std::endl;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue