From 04f8b88efd70b5b222bd5a610686879cc353cf60 Mon Sep 17 00:00:00 2001 From: Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com> Date: Tue, 18 Jul 2023 22:21:56 -0400 Subject: [PATCH] Some CI and cmake changes (#9) --- .clang-tidy | 6 + .github/workflows/build.yml | 8 +- .github/workflows/lint.yml | 18 +++ .github/workflows/performance-tests.yml | 2 +- .github/workflows/test.yml | 8 +- .gitignore | 6 +- CMakeLists.txt | 6 +- include/cpptrace/cpptrace.hpp | 1 - lint.sh | 14 +++ src/cpptrace.cpp | 5 +- src/demangle/cpptrace_demangle.hpp | 2 - src/demangle/demangle_with_cxxabi.cpp | 6 +- src/demangle/demangle_with_nothing.cpp | 2 - src/full/full_trace_with_libbacktrace.cpp | 8 +- src/platform/cpptrace_common.hpp | 53 +++++---- src/platform/cpptrace_program_name.hpp | 13 ++- src/symbols/cpptrace_symbols.hpp | 2 +- src/symbols/symbols_with_addr2line.cpp | 130 +++++++++++++--------- src/symbols/symbols_with_dl.cpp | 8 +- src/symbols/symbols_with_libbacktrace.cpp | 8 +- src/symbols/symbols_with_nothing.cpp | 2 +- src/unwind/cpptrace_unwind.hpp | 2 +- src/unwind/unwind_with_execinfo.cpp | 6 +- src/unwind/unwind_with_nothing.cpp | 2 +- 24 files changed, 198 insertions(+), 120 deletions(-) create mode 100644 .clang-tidy create mode 100644 .github/workflows/lint.yml create mode 100644 lint.sh diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..331c4f7 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,6 @@ +--- +Checks: '-*,clang-diagnostic-*,clang-analyzer-*,bugprone-*,cert-*,clang-analyzer-*,concurrency-*,cppcoreguidelines-*,misc-*,modernize-*,performance-*,portability-*,readability-*,-cppcoreguidelines-macro-usage,-modernize-use-trailing-return-type,-misc-non-private-member-variables-in-classes,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-type-vararg,-cppcoreguidelines-avoid-c-arrays,-modernize-avoid-c-arrays,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-readability-else-after-return,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cert-dcl50-cpp,-cppcoreguidelines-init-variables,-readability-implicit-bool-conversion,-cppcoreguidelines-pro-bounds-constant-array-index,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-type-member-init,-readability-isolate-declaration,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-cppcoreguidelines-pro-type-union-access,-cppcoreguidelines-pro-type-cstyle-cast,-readability-named-parameter,-cppcoreguidelines-avoid-goto,-readability-uppercase-literal-suffix,-performance-avoid-endl,-bugprone-easily-swappable-parameters' +WarningsAsErrors: '*' +HeaderFilterRegex: '' +AnalyzeTemporaryDtors: false +FormatStyle: none diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 68b12c5..4ca0290 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,7 +43,7 @@ jobs: -D${{matrix.symbols}}=On \ -D${{matrix.demangle}}=On \ -DCPPTRACE_BACKTRACE_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/include/backtrace.h - make + make -j build-macos: runs-on: macos-13 strategy: @@ -79,7 +79,7 @@ jobs: -D${{matrix.unwind}}=On \ -D${{matrix.symbols}}=On \ -D${{matrix.demangle}}=On - make + make -j build-windows: runs-on: windows-2019 strategy: @@ -143,7 +143,7 @@ jobs: -DCMAKE_CXX_STANDARD=${{matrix.std}} \ -DCPPTRACE_BACKTRACE_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/include/backtrace.h \ ${{matrix.config}} - make + make -j build-macos-full-or-auto: runs-on: macos-13 strategy: @@ -164,7 +164,7 @@ jobs: -DCMAKE_CXX_COMPILER=${{matrix.compiler}} \ -DCMAKE_CXX_STANDARD=${{matrix.std}} \ ${{matrix.config}} - make + make -j # TODO: -DCMAKE_CXX_STANDARD isn't being honored? # build-linux-full-or-auto-23: # runs-on: ubuntu-22.04 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..401b5a1 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,18 @@ +name: lint + +on: + push: + pull_request: + +jobs: + lint: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - name: dependencies + run: | + sudo apt install clang-tidy + - name: clang-tidy + run: | + chmod +x lint.sh + ./lint.sh -DCPPTRACE_BACKTRACE_PATH=\"/usr/lib/gcc/x86_64-linux-gnu/10/include/backtrace.h\" diff --git a/.github/workflows/performance-tests.yml b/.github/workflows/performance-tests.yml index a1664ed..8151c58 100644 --- a/.github/workflows/performance-tests.yml +++ b/.github/workflows/performance-tests.yml @@ -37,7 +37,7 @@ jobs: -DCPPTRACE_BACKTRACE_PATH=/usr/lib/gcc/x86_64-linux-gnu/11/include/backtrace.h \ -DCPPTRACE_BUILD_SPEEDTEST=On \ -DBUILD_SHARED_LIBS=On - make + make -j - name: test working-directory: build run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0f911ee..ffd5ebe 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -48,7 +48,7 @@ jobs: -DCPPTRACE_BUILD_TEST=On \ $(if [ "${{matrix.symbols}}" = "CPPTRACE_GET_SYMBOLS_WITH_LIBDL" ]; then echo "-DCPPTRACE_BUILD_TEST_RDYNAMIC=On"; else echo ""; fi) \ -DBUILD_SHARED_LIBS=On - make + make -j - name: test working-directory: build run: | @@ -91,7 +91,7 @@ jobs: -DCPPTRACE_BUILD_TEST=On \ $(if [ "${{matrix.symbols}}" = "CPPTRACE_GET_SYMBOLS_WITH_LIBDL" ]; then echo "-DCPPTRACE_BUILD_TEST_RDYNAMIC=On"; else echo ""; fi) \ -DBUILD_SHARED_LIBS=On - make + make -j - name: test working-directory: build run: | @@ -168,7 +168,7 @@ jobs: ${{matrix.config}} \ -DCPPTRACE_BUILD_TEST=On \ -DBUILD_SHARED_LIBS=On - make + make -j - name: test working-directory: build run: | @@ -195,7 +195,7 @@ jobs: ${{matrix.config}} \ -DCPPTRACE_BUILD_TEST=On \ -DBUILD_SHARED_LIBS=On - make + make -j - name: test working-directory: build run: | diff --git a/.gitignore b/.gitignore index 8750b75..ef80ab0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ .vscode -build -build2 a.out -test/build -repro*/ +build* +repro* diff --git a/CMakeLists.txt b/CMakeLists.txt index 5964073..4645307 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ endif() project( cpptrace - VERSION 1.0.0 + VERSION 0.0.1 LANGUAGES CXX ) @@ -28,6 +28,7 @@ target_include_directories( $ ) +# TODO target_compile_features( cpptrace PUBLIC @@ -44,7 +45,8 @@ set_target_properties( target_compile_options( cpptrace PRIVATE - $<$>:-Wall -Wextra -Werror=return-type -Wshadow> + $<$>:-Wall -Wextra -Werror=return-type -Wshadow -Wundef> + $<$:-Wuseless-cast -Wnonnull-compare> $<$:/W4 /WX /permissive-> ) diff --git a/include/cpptrace/cpptrace.hpp b/include/cpptrace/cpptrace.hpp index a87b919..5f37144 100644 --- a/include/cpptrace/cpptrace.hpp +++ b/include/cpptrace/cpptrace.hpp @@ -1,7 +1,6 @@ #ifndef CPPTRACE_HPP #define CPPTRACE_HPP -#include #include #include #include diff --git a/lint.sh b/lint.sh new file mode 100644 index 0000000..baa7a53 --- /dev/null +++ b/lint.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +status=0 +while read f +do + echo checking $f + flags="-DCPPTRACE_FULL_TRACE_WITH_LIBBACKTRACE -DCPPTRACE_FULL_TRACE_WITH_STACKTRACE -DCPPTRACE_GET_SYMBOLS_WITH_LIBBACKTRACE -DCPPTRACE_GET_SYMBOLS_WITH_LIBDL -DCPPTRACE_GET_SYMBOLS_WITH_ADDR2LINE -DCPPTRACE_GET_SYMBOLS_WITH_NOTHING -DCPPTRACE_UNWIND_WITH_EXECINFO -DCPPTRACE_UNWIND_WITH_NOTHING -DCPPTRACE_DEMANGLE_WITH_CXXABI -DCPPTRACE_DEMANGLE_WITH_NOTHING" + clang-tidy $f -- -std=c++11 -Iinclude $@ $flags + ret=$? + if [ $ret -ne 0 ]; then + status=1 + fi +done <<< $(find include src -name "*.hpp" -o -name "*.cpp" -not -path "test/speedtest.cpp" -not -path "src/full/full_trace_with_stacktrace.cpp") +exit $status diff --git a/src/cpptrace.cpp b/src/cpptrace.cpp index 6435d30..eee4776 100644 --- a/src/cpptrace.cpp +++ b/src/cpptrace.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -48,13 +49,13 @@ namespace cpptrace { namespace cpptrace { void print_trace(std::uint32_t skip) { std::cerr<<"Stack trace (most recent call first):"< - #include namespace cpptrace { diff --git a/src/demangle/demangle_with_cxxabi.cpp b/src/demangle/demangle_with_cxxabi.cpp index b0ce423..fb193a5 100644 --- a/src/demangle/demangle_with_cxxabi.cpp +++ b/src/demangle/demangle_with_cxxabi.cpp @@ -1,6 +1,5 @@ #ifdef CPPTRACE_DEMANGLE_WITH_CXXABI -#include #include "cpptrace_demangle.hpp" #include @@ -14,9 +13,10 @@ namespace cpptrace { int status; char* demangled = abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status); if(demangled) { - std::string s = demangled; + std::string str = demangled; + // NOLINTNEXTLINE(cppcoreguidelines-no-malloc) free(demangled); - return s; + return str; } else { return name; } diff --git a/src/demangle/demangle_with_nothing.cpp b/src/demangle/demangle_with_nothing.cpp index e86acf4..a102fc9 100644 --- a/src/demangle/demangle_with_nothing.cpp +++ b/src/demangle/demangle_with_nothing.cpp @@ -1,9 +1,7 @@ #ifdef CPPTRACE_DEMANGLE_WITH_NOTHING -#include #include "cpptrace_demangle.hpp" -#include #include namespace cpptrace { diff --git a/src/full/full_trace_with_libbacktrace.cpp b/src/full/full_trace_with_libbacktrace.cpp index f9acc3c..d5de589 100644 --- a/src/full/full_trace_with_libbacktrace.cpp +++ b/src/full/full_trace_with_libbacktrace.cpp @@ -1,10 +1,11 @@ #ifdef CPPTRACE_FULL_TRACE_WITH_LIBBACKTRACE #include -#include "cpptrace_full_trace.hpp" #include "../platform/cpptrace_program_name.hpp" #include "../platform/cpptrace_common.hpp" +#include +#include #include #ifdef CPPTRACE_BACKTRACE_PATH @@ -16,7 +17,9 @@ namespace cpptrace { namespace detail { struct trace_data { + // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members) std::vector& frames; + // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members) size_t& skip; }; @@ -47,6 +50,7 @@ namespace cpptrace { backtrace_state* get_backtrace_state() { // backtrace_create_state must be called only one time per program + // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static backtrace_state* state = nullptr; static bool called = false; if(!called) { @@ -67,7 +71,7 @@ namespace cpptrace { // fallback, try to at least recover the symbol name with backtrace_syminfo backtrace_syminfo( get_backtrace_state(), - reinterpret_cast(frame.address), + frame.address, syminfo_callback, error_callback, &frame diff --git a/src/platform/cpptrace_common.hpp b/src/platform/cpptrace_common.hpp index 1ff59cc..27025fc 100644 --- a/src/platform/cpptrace_common.hpp +++ b/src/platform/cpptrace_common.hpp @@ -13,16 +13,21 @@ #define CPPTRACE_MAYBE_UNUSED __attribute__((unused)) #endif -#include -#include -#include -#include +#include +#include +#include +#include #include +#include +#include +#include // Lightweight std::source_location. struct source_location { + // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members) const char* const file; //const char* const function; // disabled for now due to static constexpr restrictions + // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members) const int line; constexpr source_location( //const char* _function /*= __builtin_FUNCTION()*/, @@ -44,14 +49,20 @@ static void primitive_assert_impl( const char* action = verify ? "verification" : "assertion"; const char* name = verify ? "verify" : "assert"; if(message == nullptr) { - fprintf(stderr, "Cpptrace %s failed at %s:%d: %s\n", - action, location.file, location.line, signature); + (void) fprintf( + stderr, + "Cpptrace %s failed at %s:%d: %s\n", + action, location.file, location.line, signature + ); } else { - fprintf(stderr, "Cpptrace %s failed at %s:%d: %s: %s\n", - action, location.file, location.line, signature, message); + (void) fprintf( + stderr, + "Cpptrace %s failed at %s:%d: %s: %s\n", + action, location.file, location.line, signature, message + ); } - fprintf(stderr, " primitive_%s(%s);\n", name, expression); - abort(); + (void) fprintf(stderr, " primitive_%s(%s);\n", name, expression); + std::abort(); } } @@ -70,15 +81,15 @@ void nothing() {} #endif CPPTRACE_MAYBE_UNUSED -static std::vector split(const std::string& s, const std::string& delims) { +static std::vector split(const std::string& str, const std::string& delims) { std::vector vec; size_t old_pos = 0; size_t pos = 0; - while((pos = s.find_first_of(delims, old_pos)) != std::string::npos) { - vec.emplace_back(s.substr(old_pos, pos - old_pos)); + while((pos = str.find_first_of(delims, old_pos)) != std::string::npos) { + vec.emplace_back(str.substr(old_pos, pos - old_pos)); old_pos = pos + 1; } - vec.emplace_back(std::string(s.substr(old_pos))); + vec.emplace_back(str.substr(old_pos)); return vec; } @@ -98,22 +109,22 @@ static std::string join(const C& container, const std::string& delim) { return str; } -constexpr const char* const ws = " \t\n\r\f\v"; +constexpr const char* const whitespace = " \t\n\r\f\v"; CPPTRACE_MAYBE_UNUSED -static std::string trim(const std::string& s) { - if(s == "") { +static std::string trim(const std::string& str) { + if(str.empty()) { return ""; } - size_t l = s.find_first_not_of(ws); - size_t r = s.find_last_not_of(ws) + 1; - return s.substr(l, r - l); + const size_t left = str.find_first_not_of(whitespace); + const size_t right = str.find_last_not_of(whitespace) + 1; + return str.substr(left, right - left); } CPPTRACE_MAYBE_UNUSED static std::string to_hex(uintptr_t addr) { std::stringstream sstream; - sstream< -#ifdef _WIN32 +#if defined(_WIN32) #include namespace cpptrace { @@ -20,7 +20,7 @@ namespace cpptrace { } } -#elif __APPLE__ +#elif defined(__APPLE__) #include #include @@ -42,8 +42,9 @@ namespace cpptrace { } } -#elif __linux__ +#elif defined(__linux__) #include +#include #include namespace cpptrace { @@ -55,11 +56,11 @@ namespace cpptrace { if(!did_init) { did_init = true; char buffer[PATH_MAX + 1]; - ssize_t s = readlink("/proc/self/exe", buffer, PATH_MAX); - if(s == -1) { + const ssize_t size = readlink("/proc/self/exe", buffer, PATH_MAX); + if(size == -1) { return nullptr; } - buffer[s] = 0; + buffer[size] = 0; name = buffer; valid = true; } diff --git a/src/symbols/cpptrace_symbols.hpp b/src/symbols/cpptrace_symbols.hpp index 20189f8..39c125a 100644 --- a/src/symbols/cpptrace_symbols.hpp +++ b/src/symbols/cpptrace_symbols.hpp @@ -8,13 +8,13 @@ namespace cpptrace { namespace detail { + // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) class symbolizer { struct impl; std::unique_ptr pimpl; public: symbolizer(); ~symbolizer(); - //stacktrace_frame resolve_frame(void* addr); std::vector resolve_frames(const std::vector& frames); }; } diff --git a/src/symbols/symbols_with_addr2line.cpp b/src/symbols/symbols_with_addr2line.cpp index 89e90ea..98bafda 100644 --- a/src/symbols/symbols_with_addr2line.cpp +++ b/src/symbols/symbols_with_addr2line.cpp @@ -4,13 +4,17 @@ #include "cpptrace_symbols.hpp" #include "../platform/cpptrace_common.hpp" -#include -#include -#include +#include +#include +#include #include +#include +#include +#include #include #include +// NOLINTNEXTLINE(misc-include-cleaner) #include #include @@ -28,7 +32,7 @@ namespace cpptrace { // reference: https://github.com/bminor/glibc/blob/master/debug/backtracesyms.c std::vector frames; frames.reserve(addrs.size()); - for(const auto addr : addrs) { + for(const void* addr : addrs) { Dl_info info; dlframe frame; frame.raw_address = reinterpret_cast(addr); @@ -47,16 +51,18 @@ namespace cpptrace { bool has_addr2line() { // Detects if addr2line exists by trying to invoke addr2line --help constexpr int magic = 42; - pid_t pid = fork(); + // NOLINTNEXTLINE(misc-include-cleaner) + const pid_t pid = fork(); if(pid == -1) { return false; } if(pid == 0) { // child close(STDOUT_FILENO); // TODO: path execlp("addr2line", "addr2line", "--help", nullptr); - exit(magic); + _exit(magic); } int status; waitpid(pid, &status, 0); + // NOLINTNEXTLINE(misc-include-cleaner) return WEXITSTATUS(status) == 0; } @@ -71,12 +77,13 @@ namespace cpptrace { }; static_assert(sizeof(pipe_t) == 2 * sizeof(int), "Unexpected struct packing"); - static std::string resolve_addresses(const std::string& addresses, const std::string& executable) { + std::string resolve_addresses(const std::string& addresses, const std::string& executable) { pipe_t output_pipe; pipe_t input_pipe; internal_verify(pipe(output_pipe.data) == 0); internal_verify(pipe(input_pipe.data) == 0); - pid_t pid = fork(); + // NOLINTNEXTLINE(misc-include-cleaner) + const pid_t pid = fork(); if(pid == -1) { return ""; } // error? TODO: Diagnostic if(pid == 0) { // child dup2(output_pipe.write_end, STDOUT_FILENO); @@ -107,24 +114,68 @@ namespace cpptrace { } struct symbolizer::impl { + using target_vec = std::vector>>; + + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) + std::unordered_map get_addr2line_targets( + const std::vector& dlframes, + std::vector& trace + ) { + std::unordered_map entries; + for(std::size_t i = 0; i < dlframes.size(); i++) { + const auto& entry = dlframes[i]; + entries[entry.obj_path].emplace_back( + to_hex(entry.raw_address - entry.obj_base), + trace[i] + ); + // Set what is known for now, and resolutions from addr2line should overwrite + trace[i].filename = entry.obj_path; + trace[i].symbol = entry.symbol; + } + return entries; + } + + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) + void update_trace(const std::string& line, size_t entry_index, const target_vec& entries_vec) { + // Result will be of the form " at " path:line + // The path may be ?? if addr2line cannot resolve, line may be ? + // Edge cases: + // ?? ??:0 + const std::size_t at_location = line.find(" at "); + std::size_t symbol_end; + std::size_t filename_start; + if(at_location != std::string::npos) { + symbol_end = at_location; + filename_start = at_location + 4; + } else { + internal_verify(line.find("?? ") == 0, "Unexpected edge case while processing addr2line output"); + symbol_end = 2; + filename_start = 3; + } + auto symbol = line.substr(0, symbol_end); + auto colon = line.rfind(':'); + internal_verify(colon != std::string::npos); + internal_verify(colon > filename_start); + auto filename = line.substr(filename_start, colon - filename_start); + auto line_number = line.substr(colon + 1); + if(line_number != "?") { + entries_vec[entry_index].second.get().line = std::stoi(line_number); + } + if(filename != "??") { + entries_vec[entry_index].second.get().filename = filename; + } + if(!symbol.empty()) { + entries_vec[entry_index].second.get().symbol = symbol; + } + } + + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) std::vector resolve_frames(const std::vector& frames) { + // TODO: Refactor better std::vector trace(frames.size(), stacktrace_frame { 0, 0, 0, "", "" }); if(has_addr2line()) { - std::vector dlframes = backtrace_frames(frames); - std::unordered_map< - std::string, - std::vector>> - > entries; - for(size_t i = 0; i < dlframes.size(); i++) { - const auto& entry = dlframes[i]; - entries[entry.obj_path].push_back({ - to_hex(entry.raw_address - entry.obj_base), - trace[i] - }); - // Set what is known for now, and resolutions from addr2line should overwrite - trace[i].filename = entry.obj_path; - trace[i].symbol = entry.symbol; - } + const std::vector dlframes = backtrace_frames(frames); + const auto entries = get_addr2line_targets(dlframes, trace); for(const auto& entry : entries) { const auto& object_name = entry.first; const auto& entries_vec = entry.second; @@ -136,37 +187,7 @@ namespace cpptrace { auto output = split(trim(resolve_addresses(address_input, object_name)), "\n"); internal_verify(output.size() == entries_vec.size()); for(size_t i = 0; i < output.size(); i++) { - // Result will be of the form " at " path:line - // The path may be ?? if addr2line cannot resolve, line may be ? - // Edge cases: - // ?? ??:0 - const auto& line = output[i]; - std::size_t at_location = line.find(" at "); - std::size_t symbol_end; - std::size_t filename_start; - if(at_location != std::string::npos) { - symbol_end = at_location; - filename_start = at_location + 4; - } else { - internal_verify(line.find("?? ") == 0, "Unexpected edge case while processing addr2line output"); - symbol_end = 2; - filename_start = 3; - } - auto symbol = line.substr(0, symbol_end); - auto colon = line.rfind(":"); - internal_verify(colon != std::string::npos); - internal_verify(colon > filename_start); - auto filename = line.substr(filename_start, colon - filename_start); - auto line_number = line.substr(colon + 1); - if(line_number != "?") { - entries_vec[i].second.get().line = std::stoi(line_number); - } - if(filename != "??") { - entries_vec[i].second.get().filename = filename; - } - if(symbol != "") { - entries_vec[i].second.get().symbol = symbol; - } + update_trace(output[i], i, entries_vec); } } } @@ -174,6 +195,7 @@ namespace cpptrace { } }; + // NOLINTNEXTLINE(bugprone-unhandled-exception-at-new) symbolizer::symbolizer() : pimpl{new impl} {} symbolizer::~symbolizer() = default; diff --git a/src/symbols/symbols_with_dl.cpp b/src/symbols/symbols_with_dl.cpp index fd28ee9..7d0cf3d 100644 --- a/src/symbols/symbols_with_dl.cpp +++ b/src/symbols/symbols_with_dl.cpp @@ -2,8 +2,8 @@ #include #include "cpptrace_symbols.hpp" -#include "../platform/cpptrace_program_name.hpp" +#include #include #include @@ -12,7 +12,8 @@ namespace cpptrace { namespace detail { struct symbolizer::impl { - stacktrace_frame resolve_frame(void* addr) { + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) + stacktrace_frame resolve_frame(const void* addr) { Dl_info info; if(dladdr(addr, &info)) { return { @@ -34,6 +35,7 @@ namespace cpptrace { } }; + // NOLINTNEXTLINE(bugprone-unhandled-exception-at-new) symbolizer::symbolizer() : pimpl{new impl} {} symbolizer::~symbolizer() = default; @@ -44,7 +46,7 @@ namespace cpptrace { std::vector symbolizer::resolve_frames(const std::vector& frames) { std::vector trace; trace.reserve(frames.size()); - for(const auto frame : frames) { + for(const void* frame : frames) { trace.push_back(pimpl->resolve_frame(frame)); } return trace; diff --git a/src/symbols/symbols_with_libbacktrace.cpp b/src/symbols/symbols_with_libbacktrace.cpp index 18c999c..c619fc5 100644 --- a/src/symbols/symbols_with_libbacktrace.cpp +++ b/src/symbols/symbols_with_libbacktrace.cpp @@ -4,6 +4,7 @@ #include "cpptrace_symbols.hpp" #include "../platform/cpptrace_program_name.hpp" +#include #include #include @@ -42,6 +43,7 @@ namespace cpptrace { backtrace_state* get_backtrace_state() { // backtrace_create_state must be called only one time per program + // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static backtrace_state* state = nullptr; static bool called = false; if(!called) { @@ -53,7 +55,8 @@ namespace cpptrace { // TODO: Handle backtrace_pcinfo calling the callback multiple times on inlined functions struct symbolizer::impl { - stacktrace_frame resolve_frame(void* addr) { + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) + stacktrace_frame resolve_frame(const void* addr) { stacktrace_frame frame; frame.col = 0; backtrace_pcinfo( @@ -77,6 +80,7 @@ namespace cpptrace { } }; + // NOLINTNEXTLINE(bugprone-unhandled-exception-at-new) symbolizer::symbolizer() : pimpl{new impl} {} symbolizer::~symbolizer() = default; @@ -87,7 +91,7 @@ namespace cpptrace { std::vector symbolizer::resolve_frames(const std::vector& frames) { std::vector trace; trace.reserve(frames.size()); - for(const auto frame : frames) { + for(const void* frame : frames) { trace.push_back(pimpl->resolve_frame(frame)); } return trace; diff --git a/src/symbols/symbols_with_nothing.cpp b/src/symbols/symbols_with_nothing.cpp index 3e3c08b..78e42d7 100644 --- a/src/symbols/symbols_with_nothing.cpp +++ b/src/symbols/symbols_with_nothing.cpp @@ -2,7 +2,6 @@ #include #include "cpptrace_symbols.hpp" -#include "../platform/cpptrace_program_name.hpp" #include @@ -21,6 +20,7 @@ namespace cpptrace { // }; // } + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) std::vector symbolizer::resolve_frames(const std::vector& frames) { return std::vector(frames.size(), { 0, diff --git a/src/unwind/cpptrace_unwind.hpp b/src/unwind/cpptrace_unwind.hpp index 8e351c1..a890917 100644 --- a/src/unwind/cpptrace_unwind.hpp +++ b/src/unwind/cpptrace_unwind.hpp @@ -1,10 +1,10 @@ #ifndef CPPTRACE_UNWIND_HPP #define CPPTRACE_UNWIND_HPP -#include #include "../platform/cpptrace_common.hpp" #include +#include namespace cpptrace { namespace detail { diff --git a/src/unwind/unwind_with_execinfo.cpp b/src/unwind/unwind_with_execinfo.cpp index 7be1f3e..8c72ee5 100644 --- a/src/unwind/unwind_with_execinfo.cpp +++ b/src/unwind/unwind_with_execinfo.cpp @@ -1,10 +1,10 @@ #ifdef CPPTRACE_UNWIND_WITH_EXECINFO -#include #include "cpptrace_unwind.hpp" #include "../platform/cpptrace_common.hpp" #include +#include #include #include @@ -14,9 +14,9 @@ namespace cpptrace { CPPTRACE_FORCE_NO_INLINE std::vector capture_frames(size_t skip) { std::vector frames(hard_max_frames + skip, nullptr); - int n_frames = backtrace(frames.data(), hard_max_frames + skip); + const int n_frames = backtrace(frames.data(), int(hard_max_frames + skip)); frames.resize(n_frames); - frames.erase(frames.begin(), frames.begin() + std::min(skip + 1, frames.size())); + frames.erase(frames.begin(), frames.begin() + ptrdiff_t(std::min(skip + 1, frames.size()))); frames.shrink_to_fit(); return frames; } diff --git a/src/unwind/unwind_with_nothing.cpp b/src/unwind/unwind_with_nothing.cpp index 8462e9d..b862f18 100644 --- a/src/unwind/unwind_with_nothing.cpp +++ b/src/unwind/unwind_with_nothing.cpp @@ -1,8 +1,8 @@ #ifdef CPPTRACE_UNWIND_WITH_NOTHING -#include #include "cpptrace_unwind.hpp" +#include #include namespace cpptrace {