Skip to content

[Cmake][Sys] print backtrace if POSIX signal is catched#1692

Merged
tdavidcl merged 21 commits intoShamrock-code:mainfrom
tdavidcl:patch-2026-02-28-19-59
Mar 7, 2026
Merged

[Cmake][Sys] print backtrace if POSIX signal is catched#1692
tdavidcl merged 21 commits intoShamrock-code:mainfrom
tdavidcl:patch-2026-02-28-19-59

Conversation

@tdavidcl
Copy link
Member

No description provided.

@github-actions
Copy link
Contributor

Thanks @tdavidcl for opening this PR!

You can do multiple things directly here:
1 - Comment pre-commit.ci run to run pre-commit checks.
2 - Comment pre-commit.ci autofix to apply fixes.
3 - Add label autofix.ci to fix authorship & pre-commit for every commit made.
4 - Add label light-ci to only trigger a reduced & faster version of the CI (need the full one before merge).
5 - Add label trigger-ci to create an empty commit to trigger the CI.

Once the workflow completes a message will appear displaying informations related to the run.

Also the PR gets automatically reviewed by gemini, you can:
1 - Comment /gemini review to trigger a review
2 - Comment /gemini summary for a summary
3 - Tag it using @gemini-code-assist either in the PR or in review comments on files

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the system's debugging capabilities by integrating the cpptrace library. When enabled, this integration allows for the generation and printing of more detailed and user-friendly stack traces upon the reception of POSIX signals, providing valuable diagnostic information for unexpected program terminations. The changes primarily involve updating the build system to include and conditionally link cpptrace, and modifying the signal handling logic to leverage its features.

Highlights

  • cpptrace Integration: The cpptrace library has been added as a Git submodule and integrated into the CMake build system, providing advanced stack tracing capabilities.
  • Conditional Backtrace Printing: The system's signal handler now conditionally uses cpptrace to generate and print detailed stack traces when a POSIX signal is caught, enhancing debugging information.
  • CMake Configuration: A new CMake module (ShamConfigureCppTrace.cmake) was introduced to manage the cpptrace integration, allowing users to enable or disable it via the SHAMROCK_USE_CPPTRACE option.
Changelog
  • .gitmodules
    • Added external/cpptrace submodule.
  • CMakeLists.txt
    • Included ShamConfigureCppTrace in the main CMake configuration.
  • cmake/ShamConfigureCppTrace.cmake
    • New file added to define SHAMROCK_USE_CPPTRACE option and integrate cpptrace submodule.
  • external/cpptrace
    • Added cpptrace submodule commit reference.
  • src/shamsys/CMakeLists.txt
    • Conditionally linked shamsys with cpptrace::cpptrace.
    • Added SHAMROCK_USE_CPPTRACE compile definition.
  • src/shamsys/include/shamsys/SignalCatch.hpp
    • Included <csignal> header.
  • src/shamsys/src/SignalCatch.cpp
    • Conditionally included cpptrace/cpptrace.hpp.
    • Modified the signal handler to include cpptrace::generate_trace().to_string(shamcmdopt::is_a_tty()) in the log message when SHAMROCK_USE_CPPTRACE is defined.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request integrates cpptrace to provide more detailed backtraces when a POSIX signal is caught, which is a valuable addition for debugging. However, the current implementation introduces a significant security risk by using non-async-signal-safe functions like fmt::format, std::string, and std::cout within the signal handler. This can lead to deadlocks, undefined behavior, and potential denial of service. Additionally, there's a minor typo in a CMake comment and duplicated code in SignalCatch.cpp that should be refactored for maintainability.

@tdavidcl
Copy link
Member Author

tdavidcl commented Mar 1, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new feature to print a backtrace when a POSIX signal is caught, which is very helpful for debugging crashes. It integrates the cpptrace library as a submodule and updates the signal handling logic to generate and display/save a detailed crash report. However, the implementation has significant security concerns: the signal handler uses non-async-signal-safe functions, potentially leading to deadlocks and Denial of Service, and the crash report file creation is vulnerable to path traversal and symlink attacks due to an unsanitized environment variable for the output path. Additionally, the robustness of the static formatter object initialization should be improved to avoid potential issues during program startup. Addressing these points will enhance both the security and stability of the application's error handling.

@tdavidcl
Copy link
Member Author

tdavidcl commented Mar 1, 2026

AI will never shut up even when asked to about safety …

@tdavidcl
Copy link
Member Author

tdavidcl commented Mar 2, 2026

this PR will wait for jeremy-rifkin/cpptrace#321 before changing the submodule to the resulting commit and merge

@tdavidcl tdavidcl marked this pull request as ready for review March 2, 2026 23:54
@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

Workflow report

workflow report corresponding to commit bc59fe6
Commiter email is timothee.davidcleris@proton.me
GitHub page artifact URL GitHub page artifact link (can expire)

Pre-commit check report

Pre-commit check: ✅

trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check for merge conflicts................................................Passed
check that executables have shebangs.....................................Passed
check that scripts with shebangs are executable..........................Passed
check for added large files..............................................Passed
check for case conflicts.................................................Passed
check for broken symlinks................................................Passed
check yaml...............................................................Passed
detect private key.......................................................Passed
No-tabs checker..........................................................Passed
Tabs remover.............................................................Passed
Validate GitHub Workflows................................................Passed
clang-format.............................................................Passed
ruff check...............................................................Passed
ruff format..............................................................Passed
Check doxygen headers....................................................Passed
Check license headers....................................................Passed
Check #pragma once.......................................................Passed
Check SYCL #include......................................................Passed
No ssh in git submodules remote..........................................Passed
No UTF-8 in files (except for authors)...................................Passed

Test pipeline can run.

Clang-tidy diff report

No relevant changes found.
Well done!

You should now go back to your normal life and enjoy a hopefully sunny day while waiting for the review.

Doxygen diff with main

Removed warnings : 5
New warnings : 6
Warnings count : 8202 → 8203 (0.0%)

Detailed changes :
+ src/shamsys/src/SignalCatch.cpp:118: warning: Member register_signals() (function) of namespace shamsys is not documented.
+ src/shamsys/src/SignalCatch.cpp:118: warning: Member register_signals() (function) of namespace shamsys is not documented.
+ src/shamsys/src/SignalCatch.cpp:118: warning: Member register_signals() (function) of namespace shamsys is not documented.
+ src/shamsys/src/SignalCatch.cpp:43: warning: Member SHAM_CRASH_REPORT_FILE (variable) of file SignalCatch.cpp is not documented.
+ src/shamsys/src/SignalCatch.cpp:45: warning: Member crash_report (variable) of file SignalCatch.cpp is not documented.
+ src/shamsys/src/SignalCatch.cpp:46: warning: Member crash_report_filename (variable) of file SignalCatch.cpp is not documented.
- src/shamsys/src/SignalCatch.cpp:57: warning: Member signal_callback_handler(int signum) (function) of namespace shamsys::details is not documented.
- src/shamsys/src/SignalCatch.cpp:57: warning: Member signal_callback_handler(int signum) (function) of namespace shamsys::details is not documented.
- src/shamsys/src/SignalCatch.cpp:78: warning: Member register_signals() (function) of namespace shamsys is not documented.
- src/shamsys/src/SignalCatch.cpp:78: warning: Member register_signals() (function) of namespace shamsys is not documented.
- src/shamsys/src/SignalCatch.cpp:78: warning: Member register_signals() (function) of namespace shamsys is not documented.

@tdavidcl tdavidcl merged commit 9789073 into Shamrock-code:main Mar 7, 2026
75 checks passed
@tdavidcl tdavidcl deleted the patch-2026-02-28-19-59 branch March 7, 2026 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant