Skip to content

Commit

Permalink
Get backtraces
Browse files Browse the repository at this point in the history
  • Loading branch information
captainurist committed Nov 11, 2023
1 parent f3bf460 commit 1d894d5
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@
[submodule "thirdparty/spdlog"]
path = thirdparty/spdlog
url = https://github.com/gabime/spdlog.git
[submodule "thirdparty/backward_cpp"]
path = thirdparty/backward_cpp
url = https://github.com/captainurist/backward-cpp.git
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,3 @@ add_subdirectory(thirdparty)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/test)
add_subdirectory(test)
add_subdirectory(src)

4 changes: 2 additions & 2 deletions src/Bin/OpenEnroth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ if(BUILD_PLATFORM STREQUAL "android")
target_link_libraries(main PUBLIC application library_cli library_platform_main)
target_link_options(main PRIVATE "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libmain.map")
else()
add_executable(OpenEnroth MACOSX_BUNDLE)
target_sources(OpenEnroth PUBLIC ${BIN_OPENENROTH_HEADERS} ${BIN_OPENENROTH_SOURCES})
add_executable(OpenEnroth MACOSX_BUNDLE ${BIN_OPENENROTH_HEADERS} ${BIN_OPENENROTH_SOURCES} ${BACKWARD_ENABLE})
target_check_style(OpenEnroth)
target_link_libraries(OpenEnroth PUBLIC application library_cli library_platform_main)
add_backward(OpenEnroth)

set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT OpenEnroth)
endif()
1 change: 1 addition & 0 deletions src/Library/Random/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ set(LIBRARY_RANDOM_HEADERS
RandomEngineEnums.h)

add_library(library_random STATIC ${LIBRARY_RANDOM_SOURCES} ${LIBRARY_RANDOM_HEADERS})
target_link_libraries(library_random utility backward)
target_check_style(library_random)
21 changes: 21 additions & 0 deletions src/Library/Random/SequentialRandomEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

#include "RandomEngine.h"

#include "backward.hpp"

#include "Utility/Format.h"

class SequentialRandomEngine : public RandomEngine {
public:
virtual float randomFloat() override {
Expand All @@ -13,6 +17,23 @@ class SequentialRandomEngine : public RandomEngine {
virtual int random(int hi) override {
assert(hi > 0);

#if 1
fprintf(stderr, "Random called, returning %d, stacktrace:\n", _state + 1);

//using namespace backward;
backward::StackTrace st;
st.load_here(32);

backward::TraceResolver resolver;
resolver.load_stacktrace(st);

for (size_t trace_idx = st.size(); trace_idx > 0; --trace_idx) {
backward::ResolvedTrace frame = resolver.resolve(st[trace_idx - 1]);

fmt::print(stderr, "#{: <2} {}\n", frame.idx, frame.object_function);
}
#endif

return ++_state % hi;
}

Expand Down
1 change: 1 addition & 0 deletions test/Bin/GameTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ if(OE_BUILD_TESTS)

add_executable(OpenEnroth_GameTest ${GAME_TEST_MAIN_SOURCES} ${GAME_TEST_MAIN_HEADERS})
target_link_libraries(OpenEnroth_GameTest PUBLIC application testing_game library_cli library_platform_main GTest::gtest)
add_backward(OpenEnroth_GameTest)

target_check_style(OpenEnroth_GameTest)

Expand Down
2 changes: 2 additions & 0 deletions thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,5 @@ if(OE_BUILD_TESTS)
set(BUILD_GMOCK OFF)
add_subdirectory(googletest)
endif()

add_subdirectory(backward_cpp)
1 change: 1 addition & 0 deletions thirdparty/backward_cpp
Submodule backward_cpp added at 74088e

0 comments on commit 1d894d5

Please sign in to comment.