From 8d2728d0f04e15da6f6e3ce35f73c772fb66d8b9 Mon Sep 17 00:00:00 2001 From: Leandro SQ <11012599+LeandroSQ@users.noreply.github.com> Date: Thu, 15 Feb 2024 15:36:28 -0300 Subject: [PATCH 1/7] fix: Broken link on README.md (#88) This pull request includes a minor change to the `README.md` file. The change updates the link to the `signal-safe-tracing.md` file, moving it into the `docs` directory. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 892480a..c5188a3 100644 --- a/README.md +++ b/README.md @@ -455,7 +455,7 @@ non-signal-safe functions such as `malloc()`. To avoid this, call these routines to "warm up" the library. Because signal-safe tracing is an involved process, I have written up a comprehensive overview of -what is involved at [signal-safe-tracing.md](signal-safe-tracing.md). +what is involved at [signal-safe-tracing.md](docs/signal-safe-tracing.md). ## Utility Types From c3b38381ab2df6e6e4233e6ff3e7dd182414dc7b Mon Sep 17 00:00:00 2001 From: ethanol20924 <33417736+ethanol20924@users.noreply.github.com> Date: Fri, 16 Feb 2024 18:28:38 +0100 Subject: [PATCH 2/7] Small fix to allow for compiling with Homebrew installed Clang on Mac (#89) When building with Clang installed with Homebrew: ``` -- The C compiler identification is Clang 17.0.6 -- The CXX compiler identification is Clang 17.0.6 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /opt/homebrew/opt/llvm/bin/clang - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /opt/homebrew/opt/llvm/bin/clang++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done ``` I get the following error: ``` /opt/homebrew/opt/llvm/bin/llvm-ranlib: error: Invalid option: '-no_warning_for_no_symbols' make[2]: *** [_deps/zstd-build/lib/libzstd.a] Error 1 make[2]: *** Deleting file `_deps/zstd-build/lib/libzstd.a' make[1]: *** [_deps/zstd-build/lib/CMakeFiles/libzstd_static.dir/all] Error 2 make: *** [all] Error 2 ``` If I instead build with AppleClang: ``` -- The C compiler identification is AppleClang 15.0.0.15000100 -- The CXX compiler identification is AppleClang 15.0.0.15000100 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done ``` It works as expected. Source of the problem is found at `CMakeLists.txt:282`: ```CMake if(APPLE) SET(CMAKE_C_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") SET(CMAKE_CXX_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") endif() ``` Changing it to check specifically for AppleClang appears to fix the problem for me: ```CMake if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") SET(CMAKE_C_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") SET(CMAKE_CXX_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") endif() ``` --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e077cf8..7f4a34d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -279,7 +279,7 @@ target_compile_features( PRIVATE cxx_std_11 ) -if(APPLE) +if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") SET(CMAKE_C_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") SET(CMAKE_CXX_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") endif() From aa446b0540dc7858fb54f7d464a810823507d7a8 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Sun, 18 Feb 2024 13:10:21 +0700 Subject: [PATCH 3/7] Fix typos. (#90) --- CHANGELOG.md | 2 +- README.md | 2 +- SECURITY.md | 2 +- ci/util.py | 2 +- docs/signal-safe-tracing.md | 4 ++-- src/cpptrace.cpp | 4 ++-- test/signal_demo.cpp | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d63f14..1165ebd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ What's new: Most notable improvements: - Updated cpptrace exception objects to generate traces at the callsite for improved consistency with trace output. As - part fo this cpptrace exception objects have had their constructors updated. + part of this cpptrace exception objects have had their constructors updated. - Improved dwarf back-end robustness - Fallback to the compilation-unit cache or walking compilation-units if aranges lookup fails - Eliminated reliance on a CMake-generated export header diff --git a/README.md b/README.md index c5188a3..6babc29 100644 --- a/README.md +++ b/README.md @@ -250,7 +250,7 @@ namespace cpptrace { `cpptrace::demangle` provides a helper function for name demangling, since it has to implement that helper internally anyways. -`cpptrace::isatty` and the fileno definitions are useful for deciding whether to use color when printing stack taces. +`cpptrace::isatty` and the fileno definitions are useful for deciding whether to use color when printing stack traces. `cpptrace::register_terminate_handler()` is a helper function to set a custom `std::terminate` handler that prints a stack trace from a cpptrace exception (more info below) and otherwise behaves like the normal terminate handler. diff --git a/SECURITY.md b/SECURITY.md index c33bbd5..7f20442 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -6,7 +6,7 @@ We take security seriously and I'm grateful for reports of security vulnerabilit If the vulnerability can be reported without revealing exploitable specifics, please open an issue. -If the vulnerability can't be reported publically without leaving an obvious exploit in the public eye please email me +If the vulnerability can't be reported publicly without leaving an obvious exploit in the public eye please email me at jeremy@rifkin.dev or reach out to me on [discord](https://discord.gg/7kv5AuCndG). I will do my best to get back to you within a day. diff --git a/ci/util.py b/ci/util.py index 45fdd3c..4933e6e 100644 --- a/ci/util.py +++ b/ci/util.py @@ -60,7 +60,7 @@ def run_matrix(matrix, exclude, fn): # results[config_tuple] = matrix_config["compiler"] != "g++-10" #else: # results[config_tuple] = not (matrix_config["compiler"] == "clang++-14" and matrix_config["symbols"] == "CPPTRACE_GET_SYMBOLS_WITH_ADDR2LINE") - # I had an idea for printing 2d slices of the n-dimentional matrix, but it didn't pan out as much as I'd hoped + # I had an idea for printing 2d slices of the n-dimensional matrix, but it didn't pan out as much as I'd hoped dimensions = len(values) # # Output diagnostic tables # print("Results:", results) diff --git a/docs/signal-safe-tracing.md b/docs/signal-safe-tracing.md index 362166c..3dbebdb 100644 --- a/docs/signal-safe-tracing.md +++ b/docs/signal-safe-tracing.md @@ -138,7 +138,7 @@ void do_signal_safe_trace(cpptrace::frame_ptr* buffer, std::size_t size) { pipe_t input_pipe; pipe(input_pipe.data); const pid_t pid = fork(); - if(pid == -1) { return; /* Some error ocurred */ } + if(pid == -1) { return; /* Some error occurred */ } if(pid == 0) { // child dup2(input_pipe.read_end, STDIN_FILENO); close(input_pipe.read_end); @@ -160,7 +160,7 @@ void do_signal_safe_trace(cpptrace::frame_ptr* buffer, std::size_t size) { void handler(int signo, siginfo_t* info, void* context) { // Print basic message - const char* message = "SIGSEGV ocurred:\n"; + const char* message = "SIGSEGV occurred:\n"; write(STDERR_FILENO, message, strlen(message)); // Generate trace constexpr std::size_t N = 100; diff --git a/src/cpptrace.cpp b/src/cpptrace.cpp index d69a2c2..1af76e8 100644 --- a/src/cpptrace.cpp +++ b/src/cpptrace.cpp @@ -455,7 +455,7 @@ namespace cpptrace { // TODO: Append to message somehow std::fprintf( stderr, - "Cpptrace: Exception ocurred while resolving trace in cpptrace::exception object:\n%s\n", + "Cpptrace: Exception occurred while resolving trace in cpptrace::exception object:\n%s\n", e.what() ); } @@ -520,7 +520,7 @@ namespace cpptrace { // TODO: Append to message somehow? std::fprintf( stderr, - "Exception ocurred while resolving trace in cpptrace::exception object:\n%s\n", + "Exception occurred while resolving trace in cpptrace::exception object:\n%s\n", e.what() ); } diff --git a/test/signal_demo.cpp b/test/signal_demo.cpp index dc7decc..1d7b9a4 100644 --- a/test/signal_demo.cpp +++ b/test/signal_demo.cpp @@ -35,7 +35,7 @@ struct pipe_t { static_assert(sizeof(pipe_t) == 2 * sizeof(int), "Unexpected struct packing"); void handler(int signo, siginfo_t* info, void* context) { - const char* message = "SIGSEGV ocurred:\n"; + const char* message = "SIGSEGV occurred:\n"; write(STDERR_FILENO, message, strlen(message)); cpptrace::frame_ptr buffer[100]; std::size_t count = cpptrace::safe_generate_raw_trace(buffer, 100); From 9296b892ac3e7bd8ea82f62489e52cebc94934f4 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Sun, 18 Feb 2024 23:48:12 +0700 Subject: [PATCH 4/7] ci: Update `ilammy/msvc-dev-cmd` to 1.13 from 1.10. (#91) This should remove most of the warnings about using older versions of NodeJS. --- .github/workflows/build.yml | 2 +- .github/workflows/cmake-integration.yml | 6 +++--- .github/workflows/performance-tests.yml | 2 +- .github/workflows/test.yml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 717175e..4ce8221 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -91,7 +91,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Enable Developer Command Prompt - uses: ilammy/msvc-dev-cmd@v1.10.0 + uses: ilammy/msvc-dev-cmd@v1.13.0 - name: dependencies run: | pip3 install colorama diff --git a/.github/workflows/cmake-integration.yml b/.github/workflows/cmake-integration.yml index 84a6b7a..b1870fd 100644 --- a/.github/workflows/cmake-integration.yml +++ b/.github/workflows/cmake-integration.yml @@ -198,7 +198,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Enable Developer Command Prompt - uses: ilammy/msvc-dev-cmd@v1.10.0 + uses: ilammy/msvc-dev-cmd@v1.13.0 - name: test run: | $tag=$(git rev-parse --abbrev-ref HEAD) @@ -219,7 +219,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Enable Developer Command Prompt - uses: ilammy/msvc-dev-cmd@v1.10.0 + uses: ilammy/msvc-dev-cmd@v1.13.0 - name: test run: | $tag=$(git rev-parse --abbrev-ref HEAD) @@ -248,7 +248,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Enable Developer Command Prompt - uses: ilammy/msvc-dev-cmd@v1.10.0 + uses: ilammy/msvc-dev-cmd@v1.13.0 - name: test run: | cd .. diff --git a/.github/workflows/performance-tests.yml b/.github/workflows/performance-tests.yml index 0ca7884..6448f04 100644 --- a/.github/workflows/performance-tests.yml +++ b/.github/workflows/performance-tests.yml @@ -48,7 +48,7 @@ jobs: # steps: # - uses: actions/checkout@v4 # - name: Enable Developer Command Prompt - # uses: ilammy/msvc-dev-cmd@v1.10.0 + # uses: ilammy/msvc-dev-cmd@v1.13.0 # - name: build # run: | # mkdir -p build diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5090241..202e168 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -107,7 +107,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Enable Developer Command Prompt - uses: ilammy/msvc-dev-cmd@v1.10.0 + uses: ilammy/msvc-dev-cmd@v1.13.0 - name: dependencies run: | pip3 install colorama From 1488460172fe78d8c803b6706a9969ad8674ef79 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 19 Feb 2024 00:16:04 +0700 Subject: [PATCH 5/7] Use `defined(CPPTRACE_HAS_CXX_EXCEPTION_TYPE)`. (#94) This is set by the build system when it is available and not set when not available (and not set to 1/0 respectively). The current code can generate a warning when this preprocessor definition is not defined. --- src/utils/exception_type.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/exception_type.hpp b/src/utils/exception_type.hpp index 25d44b6..0d9047e 100644 --- a/src/utils/exception_type.hpp +++ b/src/utils/exception_type.hpp @@ -4,7 +4,7 @@ #include // libstdc++ and libc++ -#if CPPTRACE_HAS_CXX_EXCEPTION_TYPE && defined(__GLIBCXX__) || defined(__GLIBCPP__) || defined(_LIBCPP_VERSION) +#if defined(CPPTRACE_HAS_CXX_EXCEPTION_TYPE) && defined(__GLIBCXX__) || defined(__GLIBCPP__) || defined(_LIBCPP_VERSION) #include #endif @@ -13,7 +13,7 @@ namespace cpptrace { namespace detail { inline std::string exception_type_name() { - #if CPPTRACE_HAS_CXX_EXCEPTION_TYPE && defined(__GLIBCXX__) || defined(__GLIBCPP__) || defined(_LIBCPP_VERSION) + #if defined(CPPTRACE_HAS_CXX_EXCEPTION_TYPE) && defined(__GLIBCXX__) || defined(__GLIBCPP__) || defined(_LIBCPP_VERSION) const std::type_info* t = abi::__cxa_current_exception_type(); return t ? detail::demangle(t->name()) : ""; #else From a144002bf00c4789efb59ec287d27c5cf4b41461 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 19 Feb 2024 00:21:48 +0700 Subject: [PATCH 6/7] Tweaks from clang-tidy (#92) This is (perhaps) mainly for discussion as I saw you removed `clang-tidy` checks last year. These fix a variety of minor things. With one of the options that I was using, these still remain: ``` /Users/bruce/Development/custodian/cpptrace/src/symbols/../utils/utils.hpp:235:22: warning: noexcept specifier on the move constructor evaluates to 'false' [performance-noexcept-move-constructor] 235 | noexcept(std::is_nothrow_move_constructible::value) | ^ /Users/bruce/Development/custodian/cpptrace/src/symbols/../utils/utils.hpp:250:64: warning: noexcept specifier on the move assignment operator evaluates to 'false' [performance-noexcept-move-constructor] 250 | noexcept(std::is_nothrow_move_assignable::value && std::is_nothrow_move_constructible::value) | ^ ``` --- include/cpptrace/cpptrace.hpp | 4 ++-- src/binary/mach-o.hpp | 4 ++-- src/cpptrace.cpp | 6 +++--- src/symbols/symbols_with_libdwarf.cpp | 6 +++--- src/utils/utils.hpp | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/cpptrace/cpptrace.hpp b/include/cpptrace/cpptrace.hpp index 2a03162..b4bb01f 100644 --- a/include/cpptrace/cpptrace.hpp +++ b/include/cpptrace/cpptrace.hpp @@ -293,7 +293,7 @@ namespace cpptrace { // Interface for a traced exception object class CPPTRACE_EXPORT exception : public std::exception { public: - virtual const char* what() const noexcept = 0; + const char* what() const noexcept override = 0; virtual const char* message() const noexcept = 0; virtual const stacktrace& trace() const noexcept = 0; }; @@ -413,7 +413,7 @@ namespace cpptrace { mutable std::string message_value; public: explicit nested_exception( - std::exception_ptr exception_ptr, + const std::exception_ptr& exception_ptr, raw_trace&& trace = detail::get_raw_trace_and_absorb() ) noexcept : lazy_exception(std::move(trace)), ptr(exception_ptr) {} diff --git a/src/binary/mach-o.hpp b/src/binary/mach-o.hpp index b0260a3..7769089 100644 --- a/src/binary/mach-o.hpp +++ b/src/binary/mach-o.hpp @@ -372,7 +372,7 @@ namespace detail { // produce information similar to dsymutil -dump-debug-map static void print_debug_map(const debug_map& debug_map) { for(const auto& entry : debug_map) { - std::cout<"<" << '\n'; return; } const auto reset = color ? ESC "0m" : ""; @@ -237,7 +237,7 @@ namespace cpptrace { } } if(newline_at_end || &frame != &frames.back()) { - stream << std::endl; + stream << '\n'; } counter++; } diff --git a/src/symbols/symbols_with_libdwarf.cpp b/src/symbols/symbols_with_libdwarf.cpp index 20d691b..d357fdf 100644 --- a/src/symbols/symbols_with_libdwarf.cpp +++ b/src/symbols/symbols_with_libdwarf.cpp @@ -186,7 +186,7 @@ namespace libdwarf { } CPPTRACE_FORCE_NO_INLINE_FOR_PROFILING - ~dwarf_resolver() { + ~dwarf_resolver() override { // TODO: Maybe redundant since dwarf_finish(dbg); will clean up the line stuff anyway but may as well just // for thoroughness for(auto& entry : line_contexts) { @@ -928,7 +928,7 @@ namespace libdwarf { optional> symbols; std::unique_ptr resolver; - target_object(std::string object_path) : object_path(object_path) {} + target_object(std::string object_path) : object_path(std::move(object_path)) {} std::unique_ptr& get_resolver() { if(!resolver) { @@ -1003,7 +1003,7 @@ namespace libdwarf { // get symbol entries from debug map, as well as the various object files used to make this binary for(auto& entry : source_debug_map) { // object it came from - target_objects.push_back({std::move(entry.first)}); + target_objects.push_back({entry.first}); // push the symbols auto& map_entry_symbols = entry.second; symbols.reserve(symbols.size() + map_entry_symbols.size()); diff --git a/src/utils/utils.hpp b/src/utils/utils.hpp index c51a2a2..c61db30 100644 --- a/src/utils/utils.hpp +++ b/src/utils/utils.hpp @@ -280,7 +280,7 @@ namespace detail { return *this; } - void swap(optional& other) { + void swap(optional& other) noexcept { if(holds_value && other.holds_value) { std::swap(uvalue, other.uvalue); } else if(holds_value && !other.holds_value) { @@ -409,7 +409,7 @@ namespace detail { optional deleter; public: raii_wrapper(T obj, D deleter) : obj(obj), deleter(deleter) {} - raii_wrapper(raii_wrapper&& other) noexcept : obj(std::move(other.obj)), deleter(other.deleter) { + raii_wrapper(raii_wrapper&& other) noexcept : obj(std::move(other.obj)), deleter(std::move(other.deleter)) { other.deleter = nullopt; } raii_wrapper(const raii_wrapper&) = delete; From f879cd8b7b1a1d5ea1a3384df861e865a70e1151 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 19 Feb 2024 15:11:33 +0700 Subject: [PATCH 7/7] README: improve text about macOS and `dsymutil` (#93) According to the release notes, I think this is true ... if not, disregard! --- README.md | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6babc29..8d4a445 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ endif() Be sure to configure with `-DCMAKE_BUILD_TYPE=Debug` or `-DDCMAKE_BUILD_TYPE=RelWithDebInfo` for symbols and line information. -On macOS it is recommended to generate a .dSYM file, see [Platform Logistics](#platform-logistics) below. +On macOS it is recommended to generate a `.dSYM` file, see [Platform Logistics](#platform-logistics) below. For other ways to use the library, such as through package managers, a system-wide installation, or on a platform without internet access see [Usage](#usage) below. @@ -728,9 +728,11 @@ target_link_libraries(main PRIVATE cpptrace::cpptrace) # Platform Logistics -Windows and macos require a little extra work to get everything in the right place +Windows and macOS require a little extra work to get everything in the right place. -Copying the library .dll on windows: +## Windows + +Copying the library `.dll` on Windows: ```cmake # Copy the cpptrace.dll on windows to the same directory as the executable for your_target. @@ -745,18 +747,22 @@ if(WIN32) endif() ``` -On macOS it's recommended to generate a dSYM file containing debug information for your program: +## macOS -In xcode cmake this can be done with +On macOS, it is recommended to generate a `dSYM` file containing debug information for your program. +This is not required as cpptrace makes a good effort at finding and reading the debug information +without this, but having a `dSYM` file is the most robust method. + +When using Xcode with CMake, this can be done with: ```cmake set_target_properties(your_target PROPERTIES XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf-with-dsym") ``` -And outside xcode this can be done with `dsymutil yourbinary`: +Outside of Xcode, this can be done with `dsymutil yourbinary`: ```cmake -# Create a .dSYM file on macos. Currently required, but hopefully not for long +# Create a .dSYM file on macOS if(APPLE) add_custom_command( TARGET your_target