Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2024 Pyarelal Knowles, MIT License
# Copyright (c) 2024-2025 Pyarelal Knowles, MIT License

cmake_minimum_required(VERSION 3.20)

Expand All @@ -22,7 +22,7 @@ if(NOT TARGET decodeless::allocator)
FetchContent_Declare(
decodeless_allocator
GIT_REPOSITORY https://github.com/decodeless/allocator.git
GIT_TAG 976a34bd7f9784839dd9bba05262001a498f5ce4)
GIT_TAG 9b45b23ea556ae5ec42af4ce60b13bd3a7db8a8f)
FetchContent_MakeAvailable(decodeless_allocator)
else()
message(
Expand All @@ -43,7 +43,7 @@ if(NOT TARGET decodeless::mappedfile)
FetchContent_Declare(
decodeless_mappedfile
GIT_REPOSITORY https://github.com/decodeless/mappedfile.git
GIT_TAG bbd066e089210ac06063a9d4e278749b275fffe9)
GIT_TAG a6e59f8b193298a16534beab694e30ae76d7f457)
FetchContent_MakeAvailable(decodeless_mappedfile)
else()
message(
Expand Down
29 changes: 15 additions & 14 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2024 Pyarelal Knowles, MIT License
# Copyright (c) 2024-2025 Pyarelal Knowles, MIT License

cmake_minimum_required(VERSION 3.20)

Expand All @@ -24,7 +24,7 @@ if(NOT TARGET decodeless::offset_ptr)
FetchContent_Declare(
decodeless_offset_ptr
GIT_REPOSITORY https://github.com/decodeless/offset_ptr.git
GIT_TAG 1f87a9d7a8be23b90c06124014f286df91562006)
GIT_TAG 38ceefc6ce63fb4667cd207424b1277c3eed5f8d)
FetchContent_MakeAvailable(decodeless_offset_ptr)
else()
message(
Expand All @@ -39,8 +39,6 @@ add_executable(${PROJECT_NAME}_tests src/writer.cpp)
target_link_libraries(${PROJECT_NAME}_tests decodeless::writer
decodeless::offset_ptr gtest_main gmock_main)

# TODO: presets?
# https://stackoverflow.com/questions/45955272/modern-way-to-set-compiler-flags-in-cross-platform-cmake-project
if(MSVC)
target_compile_options(${PROJECT_NAME}_tests PRIVATE /W4 /WX)
target_compile_definitions(${PROJECT_NAME}_tests PRIVATE WIN32_LEAN_AND_MEAN=1
Expand All @@ -49,17 +47,20 @@ else()
target_compile_options(${PROJECT_NAME}_tests PRIVATE -Wall -Wextra -Wpedantic
-Werror)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(
${PROJECT_NAME}_tests
PRIVATE $<$<CONFIG:Debug>:-D_GLIBCXX_DEBUG>
$<$<CONFIG:Debug>:-D_GLIBCXX_DEBUG_BACKTRACE>)
try_compile(
HAS_STDCXX_LIBBACKTRACE SOURCE_FROM_CONTENT
stdc++_libbacktrace_test.cpp "int main() { return 0; }"
LINK_LIBRARIES stdc++_libbacktrace)
if(HAS_STDCXX_LIBBACKTRACE)
target_compile_definitions(${PROJECT_NAME}_tests
PRIVATE $<$<CONFIG:Debug>:_GLIBCXX_DEBUG>)

# Ugly detection for a working _GLIBCXX_DEBUG_BACKTRACE config, but the
# feature itself is useful
include(glibcxx_debug_backtrace.cmake)
if(GLIBCXX_DEBUG_BACKTRACE_SUPPORTED)
target_compile_definitions(
${PROJECT_NAME}_tests
PRIVATE $<$<CONFIG:Debug>:_GLIBCXX_DEBUG_BACKTRACE>)
target_link_libraries(${PROJECT_NAME}_tests
$<$<CONFIG:Debug>:stdc++_libbacktrace>)
$<$<CONFIG:Debug>:${GLIBCXX_DEBUG_BACKTRACE_LIBRARY}>)
target_compile_features(${PROJECT_NAME}_tests
PRIVATE ${GLIBCXX_DEBUG_BACKTRACE_CXX_FEATURE})
endif()
endif()

Expand Down
73 changes: 73 additions & 0 deletions test/glibcxx_debug_backtrace.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright (c) 2025 Pyarelal Knowles, MIT License
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Update copyright year.

The copyright year "2025" should be "2024-2025" to match other files.

-# Copyright (c) 2025 Pyarelal Knowles, MIT License
+# Copyright (c) 2024-2025 Pyarelal Knowles, MIT License
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Copyright (c) 2025 Pyarelal Knowles, MIT License
# Copyright (c) 2024-2025 Pyarelal Knowles, MIT License


if(NOT DEFINED GLIBCXX_DEBUG_BACKTRACE_SUPPORTED)
set(GLIBCXX_DEBUG_BACKTRACE_SUPPORTED false)
endif()

# Try default build with no extra libraries
if(NOT GLIBCXX_DEBUG_BACKTRACE_SUPPORTED)
try_compile(
DEBUG_BACKTRACE_JUSTWORKS SOURCE_FROM_CONTENT
stdc++_libbacktrace_test.cpp
"#include <vector>\nint main() { std::vector<int> v{0}; return v[0]; }"
COMPILE_DEFINITIONS -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_BACKTRACE)
Comment on lines +11 to +13
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Consider adding more test cases.

The test program only checks vector access. Consider adding more test cases that exercise different aspects of the debug functionality.

-    "#include <vector>\nint main() { std::vector<int> v{0}; return v[0]; }"
+    "#include <vector>\n#include <string>\nint main() {\n"
+    "  std::vector<int> v{0};\n"
+    "  std::string s;\n"
+    "  s.at(0); // Should trigger debug assertion\n"
+    "  return v[0];\n"
+    "}"

if(DEBUG_BACKTRACE_JUSTWORKS)
set(GLIBCXX_DEBUG_BACKTRACE_SUPPORTED true)
set(GLIBCXX_DEBUG_BACKTRACE_LIBRARY)
set(GLIBCXX_DEBUG_BACKTRACE_CXX_FEATURE)
endif()
endif()

# Try C++23 with no extra libraries
if(NOT GLIBCXX_DEBUG_BACKTRACE_SUPPORTED)
try_compile(
DEBUG_BACKTRACE_NEEDCXX23 SOURCE_FROM_CONTENT
stdc++_libbacktrace_test.cpp
"#include <vector>\nint main() { std::vector<int> v{0}; return v[0]; }"
COMPILE_DEFINITIONS -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_BACKTRACE
CXX_STANDARD 23 CXX_STANDARD_REQUIRED true)
if(DEBUG_BACKTRACE_NEEDCXX23)
set(GLIBCXX_DEBUG_BACKTRACE_SUPPORTED true)
set(GLIBCXX_DEBUG_BACKTRACE_LIBRARY)
set(GLIBCXX_DEBUG_BACKTRACE_CXX_FEATURE cxx_std_23)
endif()
endif()

# Try with libstdc++exp
if(NOT GLIBCXX_DEBUG_BACKTRACE_SUPPORTED)
try_compile(
DEBUG_BACKTRACE_NEEDSTDEXP SOURCE_FROM_CONTENT
stdc++_libbacktrace_test.cpp
"#include <vector>\nint main() { std::vector<int> v{0}; return v[0]; }"
COMPILE_DEFINITIONS -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_BACKTRACE CXX_STANDARD
20 CXX_STANDARD_REQUIRED true
LINK_LIBRARIES stdc++exp)
Comment on lines +42 to +44
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Fix line continuation indentation.

The line continuation indentation is inconsistent with other similar blocks in the file.

-    COMPILE_DEFINITIONS -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_BACKTRACE CXX_STANDARD
-                        20 CXX_STANDARD_REQUIRED true
-    LINK_LIBRARIES stdc++exp)
+    COMPILE_DEFINITIONS -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_BACKTRACE
+                       CXX_STANDARD 20
+                       CXX_STANDARD_REQUIRED true
+    LINK_LIBRARIES stdc++exp)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
COMPILE_DEFINITIONS -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_BACKTRACE CXX_STANDARD
20 CXX_STANDARD_REQUIRED true
LINK_LIBRARIES stdc++exp)
COMPILE_DEFINITIONS -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_BACKTRACE
CXX_STANDARD 20
CXX_STANDARD_REQUIRED true
LINK_LIBRARIES stdc++exp)

if(DEBUG_BACKTRACE_NEEDSTDEXP)
set(GLIBCXX_DEBUG_BACKTRACE_SUPPORTED true)
set(GLIBCXX_DEBUG_BACKTRACE_LIBRARY stdc++exp)
set(GLIBCXX_DEBUG_BACKTRACE_CXX_FEATURE)
endif()
endif()

# Try with libstdc++_libbacktrace
if(NOT GLIBCXX_DEBUG_BACKTRACE_SUPPORTED)
try_compile(
DEBUG_BACKTRACE_NEEDLIBBACKTRACE SOURCE_FROM_CONTENT
stdc++_libbacktrace_test.cpp
"#include <vector>\nint main() { std::vector<int> v{0}; return v[0]; }"
COMPILE_DEFINITIONS -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_BACKTRACE CXX_STANDARD
20 CXX_STANDARD_REQUIRED true
LINK_LIBRARIES stdc++_libbacktrace)
if(DEBUG_BACKTRACE_NEEDLIBBACKTRACE)
set(GLIBCXX_DEBUG_BACKTRACE_SUPPORTED true)
set(GLIBCXX_DEBUG_BACKTRACE_LIBRARY stdc++_libbacktrace)
set(GLIBCXX_DEBUG_BACKTRACE_CXX_FEATURE)
endif()
endif()

# Issue a warning if none of the above worked
if(NOT GLIBCXX_DEBUG_BACKTRACE_SUPPORTED)
message(
WARNING "No working try_compile configs with _GLIBCXX_DEBUG_BACKTRACE found"
)
Comment on lines +70 to +72
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Enhance warning message.

The warning message could be more informative by suggesting potential solutions.

-    WARNING "No working try_compile configs with _GLIBCXX_DEBUG_BACKTRACE found"
+    WARNING "No working try_compile configs with _GLIBCXX_DEBUG_BACKTRACE found. "
+            "Try installing libstdc++_libbacktrace or upgrading to a newer compiler."

endif()