-
Notifications
You must be signed in to change notification settings - Fork 101
feat: add cpptrace for better stack traces #4042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
kdrienCG
wants to merge
15
commits into
develop
Choose a base branch
from
feature/kdrienCG/betterStackTrace
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5881085
add cpptrace
kdrienCG 6a684f2
modify main to use cpptrace stacktrace
kdrienCG 69ba20e
fix typo in include
kdrienCG 39051fa
add missing parenthesis
kdrienCG 8abfda8
reorganize main.cpp for readability
kdrienCG a02d863
use cpptrace for GeosException
kdrienCG 2977086
add cpptrace in buildGuide
kdrienCG 473d53a
fix default in BuildProcess
kdrienCG 5a981de
fix regex
kdrienCG 0f9d202
add signal-safe stack trace method
kdrienCG e88e821
modify types
kdrienCG 197c7ee
move include position
kdrienCG 5cec03f
document signalSafeStackTrace() reverting to LvArray
kdrienCG e4334c2
use match_results::suffix instead of pos + len
kdrienCG 1566e6e
remove unused exception parameter
kdrienCG File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| set( PREPROCESSOR_DEFINES BOUNDS_CHECK | ||
| CALIPER | ||
| CPPTRACE | ||
| CHAI | ||
| CUDA | ||
| CUDA_NVTOOLSEXT | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| /* | ||
| * ------------------------------------------------------------------------------------------------------------ | ||
| * SPDX-License-Identifier: LGPL-2.1-only | ||
| * | ||
| * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC | ||
| * Copyright (c) 2018-2024 TotalEnergies | ||
| * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University | ||
| * Copyright (c) 2023-2024 Chevron | ||
| * Copyright (c) 2019- GEOS/GEOSX Contributors | ||
| * All rights reserved | ||
| * | ||
| * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. | ||
| * ------------------------------------------------------------------------------------------------------------ | ||
| */ | ||
|
|
||
| /** | ||
| * @file StackTrace.cpp | ||
| */ | ||
|
|
||
| #include "StackTrace.hpp" | ||
| #include "LvArray/src/system.hpp" | ||
|
|
||
| #include "common/GeosxConfig.hpp" | ||
| #ifdef GEOS_USE_CPPTRACE | ||
| #include <cpptrace/cpptrace.hpp> | ||
| #include <cpptrace/from_current.hpp> | ||
| #include <cpptrace/formatting.hpp> | ||
| #endif | ||
|
|
||
| namespace geos | ||
| { | ||
|
|
||
|
|
||
| std::string StackTrace::stackTrace() | ||
| { | ||
| #ifdef GEOS_USE_CPPTRACE | ||
| return formatter().format( cpptrace::generate_trace( /* skip = */ 1 ) ); | ||
| #else | ||
| return LvArray::system::stackTrace( true ); | ||
| #endif | ||
| } | ||
|
|
||
| std::string StackTrace::signalSafeStackTrace() | ||
| { | ||
| return LvArray::system::stackTrace( true ); | ||
| } | ||
|
|
||
| #ifdef GEOS_USE_CPPTRACE | ||
| cpptrace::formatter const & StackTrace::formatter() | ||
| { | ||
| static cpptrace::formatter const fmt = cpptrace::formatter{} | ||
| .header( "" ) | ||
| .addresses( cpptrace::formatter::address_mode::none ) | ||
| .paths( cpptrace::formatter::path_mode::basename ) | ||
| .symbols( cpptrace::formatter::symbol_mode::pretty ) | ||
| .snippets( false ) | ||
| .columns( true ) | ||
| .filtered_frame_placeholders( false ) | ||
| .filter( []( cpptrace::stacktrace_frame const & frame ) | ||
| { | ||
| static char const * const blacklist[] = { | ||
| "__cxa_throw", | ||
| "__cxa_rethrow", | ||
| "_Unwind_RaiseException", | ||
| "_Unwind_Resume", | ||
| "cpptrace::detail::", | ||
| "cpptrace::v1::detail::", | ||
| "cpptrace::try_catch::", | ||
| "cpptrace::v1::try_catch::", | ||
| }; | ||
| for( char const * symbolToHide : blacklist ) | ||
| { | ||
| if( frame.symbol.find( symbolToHide ) != std::string::npos ) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } ); | ||
|
|
||
| return fmt; | ||
| } | ||
|
|
||
| std::string StackTrace::formatStackTrace( cpptrace::stacktrace const & stacktrace ) | ||
| { | ||
| return formatter().format( stacktrace ); | ||
| } | ||
| #endif | ||
|
|
||
|
|
||
| } /* namespace geos */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * ------------------------------------------------------------------------------------------------------------ | ||
| * SPDX-License-Identifier: LGPL-2.1-only | ||
| * | ||
| * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC | ||
| * Copyright (c) 2018-2024 TotalEnergies | ||
| * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University | ||
| * Copyright (c) 2023-2024 Chevron | ||
| * Copyright (c) 2019- GEOS/GEOSX Contributors | ||
| * All rights reserved | ||
| * | ||
| * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. | ||
| * ------------------------------------------------------------------------------------------------------------ | ||
| */ | ||
|
|
||
| /** | ||
| * @file StackTrace.hpp | ||
| */ | ||
|
|
||
| #ifndef GEOS_COMMON_LOGGER_STACKTRACE_HPP | ||
| #define GEOS_COMMON_LOGGER_STACKTRACE_HPP | ||
|
|
||
| #include "common/GeosxConfig.hpp" // For the following guards | ||
| #ifdef GEOS_USE_CPPTRACE | ||
| #include <cpptrace/cpptrace.hpp> | ||
| #include <cpptrace/formatting.hpp> | ||
| #endif | ||
|
|
||
| #include <string> | ||
|
|
||
| namespace geos | ||
| { | ||
|
|
||
| /** | ||
| * @brief Utility class to interact with stack traces. | ||
| */ | ||
| class StackTrace | ||
| { | ||
| public: | ||
|
|
||
| /** | ||
| * @brief Get a stack trace for the current thread. | ||
| * @return The stack trace as a string. | ||
| * @note Not signal-safe. Use signalSafeStackTrace() from inside a signal handler. | ||
| */ | ||
| static std::string stackTrace(); | ||
|
|
||
| /** | ||
| * @brief Get a stack trace from a context where signal-safety is required. | ||
| * @return The stack trace as a string. | ||
| * @note Implementation reverts back to LvArray::system stack trace for signal-safety | ||
| */ | ||
| static std::string signalSafeStackTrace(); | ||
|
|
||
| #ifdef GEOS_USE_CPPTRACE | ||
| /** | ||
| * @brief Access the configured cpptrace formatter. | ||
| * @return The formatter instance. | ||
| */ | ||
| static cpptrace::formatter const & formatter(); | ||
|
|
||
| /** | ||
| * @brief Format a cpptrace stacktrace using the configured formatter. | ||
| * @param stacktrace The cpptrace stack trace to format. | ||
| * @return Formatted stack trace string. | ||
| */ | ||
| static std::string formatStackTrace( cpptrace::stacktrace const & stacktrace ); | ||
| #endif | ||
|
|
||
| }; | ||
|
|
||
|
|
||
| } /* namespace geos */ | ||
|
|
||
| #endif /* GEOS_COMMON_LOGGER_STACKTRACE_HPP */ | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is worth documenting here that behavior for signal-safe is dropping
cpptraceThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in commit 5cec03