Skip to content

Commit 04f8b88

Browse files
Some CI and cmake changes (#9)
1 parent f28c2ca commit 04f8b88

24 files changed

+197
-119
lines changed

.clang-tidy

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
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'
3+
WarningsAsErrors: '*'
4+
HeaderFilterRegex: ''
5+
AnalyzeTemporaryDtors: false
6+
FormatStyle: none

.github/workflows/build.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
-D${{matrix.symbols}}=On \
4444
-D${{matrix.demangle}}=On \
4545
-DCPPTRACE_BACKTRACE_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/include/backtrace.h
46-
make
46+
make -j
4747
build-macos:
4848
runs-on: macos-13
4949
strategy:
@@ -79,7 +79,7 @@ jobs:
7979
-D${{matrix.unwind}}=On \
8080
-D${{matrix.symbols}}=On \
8181
-D${{matrix.demangle}}=On
82-
make
82+
make -j
8383
build-windows:
8484
runs-on: windows-2019
8585
strategy:
@@ -143,7 +143,7 @@ jobs:
143143
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
144144
-DCPPTRACE_BACKTRACE_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/include/backtrace.h \
145145
${{matrix.config}}
146-
make
146+
make -j
147147
build-macos-full-or-auto:
148148
runs-on: macos-13
149149
strategy:
@@ -164,7 +164,7 @@ jobs:
164164
-DCMAKE_CXX_COMPILER=${{matrix.compiler}} \
165165
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
166166
${{matrix.config}}
167-
make
167+
make -j
168168
# TODO: -DCMAKE_CXX_STANDARD isn't being honored?
169169
# build-linux-full-or-auto-23:
170170
# runs-on: ubuntu-22.04

.github/workflows/lint.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: lint
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
lint:
9+
runs-on: ubuntu-20.04
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: dependencies
13+
run: |
14+
sudo apt install clang-tidy
15+
- name: clang-tidy
16+
run: |
17+
chmod +x lint.sh
18+
./lint.sh -DCPPTRACE_BACKTRACE_PATH=\"/usr/lib/gcc/x86_64-linux-gnu/10/include/backtrace.h\"

.github/workflows/performance-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
-DCPPTRACE_BACKTRACE_PATH=/usr/lib/gcc/x86_64-linux-gnu/11/include/backtrace.h \
3838
-DCPPTRACE_BUILD_SPEEDTEST=On \
3939
-DBUILD_SHARED_LIBS=On
40-
make
40+
make -j
4141
- name: test
4242
working-directory: build
4343
run: |

.github/workflows/test.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
-DCPPTRACE_BUILD_TEST=On \
4949
$(if [ "${{matrix.symbols}}" = "CPPTRACE_GET_SYMBOLS_WITH_LIBDL" ]; then echo "-DCPPTRACE_BUILD_TEST_RDYNAMIC=On"; else echo ""; fi) \
5050
-DBUILD_SHARED_LIBS=On
51-
make
51+
make -j
5252
- name: test
5353
working-directory: build
5454
run: |
@@ -91,7 +91,7 @@ jobs:
9191
-DCPPTRACE_BUILD_TEST=On \
9292
$(if [ "${{matrix.symbols}}" = "CPPTRACE_GET_SYMBOLS_WITH_LIBDL" ]; then echo "-DCPPTRACE_BUILD_TEST_RDYNAMIC=On"; else echo ""; fi) \
9393
-DBUILD_SHARED_LIBS=On
94-
make
94+
make -j
9595
- name: test
9696
working-directory: build
9797
run: |
@@ -168,7 +168,7 @@ jobs:
168168
${{matrix.config}} \
169169
-DCPPTRACE_BUILD_TEST=On \
170170
-DBUILD_SHARED_LIBS=On
171-
make
171+
make -j
172172
- name: test
173173
working-directory: build
174174
run: |
@@ -195,7 +195,7 @@ jobs:
195195
${{matrix.config}} \
196196
-DCPPTRACE_BUILD_TEST=On \
197197
-DBUILD_SHARED_LIBS=On
198-
make
198+
make -j
199199
- name: test
200200
working-directory: build
201201
run: |

.gitignore

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
.vscode
2-
build
3-
build2
42
a.out
5-
test/build
6-
repro*/
3+
build*
4+
repro*

CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ endif()
66

77
project(
88
cpptrace
9-
VERSION 1.0.0
9+
VERSION 0.0.1
1010
LANGUAGES CXX
1111
)
1212

@@ -28,6 +28,7 @@ target_include_directories(
2828
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/cpptrace/cpptrace>
2929
)
3030

31+
# TODO
3132
target_compile_features(
3233
cpptrace
3334
PUBLIC
@@ -44,7 +45,8 @@ set_target_properties(
4445
target_compile_options(
4546
cpptrace
4647
PRIVATE
47-
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Werror=return-type -Wshadow>
48+
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Werror=return-type -Wshadow -Wundef>
49+
$<$<CXX_COMPILER_ID:GNU>:-Wuseless-cast -Wnonnull-compare>
4850
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX /permissive->
4951
)
5052

include/cpptrace/cpptrace.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef CPPTRACE_HPP
22
#define CPPTRACE_HPP
33

4-
#include <cstddef>
54
#include <cstdint>
65
#include <string>
76
#include <vector>

lint.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
status=0
4+
while read f
5+
do
6+
echo checking $f
7+
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"
8+
clang-tidy $f -- -std=c++11 -Iinclude $@ $flags
9+
ret=$?
10+
if [ $ret -ne 0 ]; then
11+
status=1
12+
fi
13+
done <<< $(find include src -name "*.hpp" -o -name "*.cpp" -not -path "test/speedtest.cpp" -not -path "src/full/full_trace_with_stacktrace.cpp")
14+
exit $status

src/cpptrace.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <cpptrace/cpptrace.hpp>
22

33
#include <cstddef>
4+
#include <cstdint>
45
#include <string>
56
#include <vector>
67
#include <iostream>
@@ -48,13 +49,13 @@ namespace cpptrace {
4849
namespace cpptrace {
4950
void print_trace(std::uint32_t skip) {
5051
std::cerr<<"Stack trace (most recent call first):"<<std::endl;
51-
std::size_t i = 0;
52+
std::size_t counter = 0;
5253
const auto trace = generate_trace(skip + 1);
5354
// +1 to skip one frame
5455
for(auto it = trace.begin() + 1; it != trace.end(); it++) {
5556
const auto& frame = *it;
5657
std::cerr
57-
<< i++
58+
<< counter++
5859
<< " "
5960
<< frame.filename
6061
<< ":"

src/demangle/cpptrace_demangle.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#ifndef CPPTRACE_DEMANGLE_HPP
22
#define CPPTRACE_DEMANGLE_HPP
33

4-
#include <cpptrace/cpptrace.hpp>
5-
64
#include <string>
75

86
namespace cpptrace {

src/demangle/demangle_with_cxxabi.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#ifdef CPPTRACE_DEMANGLE_WITH_CXXABI
22

3-
#include <cpptrace/cpptrace.hpp>
43
#include "cpptrace_demangle.hpp"
54

65
#include <cxxabi.h>
@@ -14,9 +13,10 @@ namespace cpptrace {
1413
int status;
1514
char* demangled = abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status);
1615
if(demangled) {
17-
std::string s = demangled;
16+
std::string str = demangled;
17+
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc)
1818
free(demangled);
19-
return s;
19+
return str;
2020
} else {
2121
return name;
2222
}

src/demangle/demangle_with_nothing.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#ifdef CPPTRACE_DEMANGLE_WITH_NOTHING
22

3-
#include <cpptrace/cpptrace.hpp>
43
#include "cpptrace_demangle.hpp"
54

6-
#include <cstdlib>
75
#include <string>
86

97
namespace cpptrace {

src/full/full_trace_with_libbacktrace.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#ifdef CPPTRACE_FULL_TRACE_WITH_LIBBACKTRACE
22

33
#include <cpptrace/cpptrace.hpp>
4-
#include "cpptrace_full_trace.hpp"
54
#include "../platform/cpptrace_program_name.hpp"
65
#include "../platform/cpptrace_common.hpp"
76

7+
#include <cstddef>
8+
#include <cstdint>
89
#include <vector>
910

1011
#ifdef CPPTRACE_BACKTRACE_PATH
@@ -16,7 +17,9 @@
1617
namespace cpptrace {
1718
namespace detail {
1819
struct trace_data {
20+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
1921
std::vector<stacktrace_frame>& frames;
22+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
2023
size_t& skip;
2124
};
2225

@@ -47,6 +50,7 @@ namespace cpptrace {
4750

4851
backtrace_state* get_backtrace_state() {
4952
// backtrace_create_state must be called only one time per program
53+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
5054
static backtrace_state* state = nullptr;
5155
static bool called = false;
5256
if(!called) {
@@ -67,7 +71,7 @@ namespace cpptrace {
6771
// fallback, try to at least recover the symbol name with backtrace_syminfo
6872
backtrace_syminfo(
6973
get_backtrace_state(),
70-
reinterpret_cast<uintptr_t>(frame.address),
74+
frame.address,
7175
syminfo_callback,
7276
error_callback,
7377
&frame

src/platform/cpptrace_common.hpp

+31-20
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,21 @@
1313
#define CPPTRACE_MAYBE_UNUSED __attribute__((unused))
1414
#endif
1515

16-
#include <stdlib.h>
17-
#include <stdio.h>
16+
#include <cstdint>
17+
#include <cstdio>
18+
#include <cstdlib>
19+
#include <ios>
20+
#include <sstream>
1821
#include <string>
22+
#include <utility>
1923
#include <vector>
20-
#include <sstream>
2124

2225
// Lightweight std::source_location.
2326
struct source_location {
27+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
2428
const char* const file;
2529
//const char* const function; // disabled for now due to static constexpr restrictions
30+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
2631
const int line;
2732
constexpr source_location(
2833
//const char* _function /*= __builtin_FUNCTION()*/,
@@ -44,14 +49,20 @@ static void primitive_assert_impl(
4449
const char* action = verify ? "verification" : "assertion";
4550
const char* name = verify ? "verify" : "assert";
4651
if(message == nullptr) {
47-
fprintf(stderr, "Cpptrace %s failed at %s:%d: %s\n",
48-
action, location.file, location.line, signature);
52+
(void) fprintf(
53+
stderr,
54+
"Cpptrace %s failed at %s:%d: %s\n",
55+
action, location.file, location.line, signature
56+
);
4957
} else {
50-
fprintf(stderr, "Cpptrace %s failed at %s:%d: %s: %s\n",
51-
action, location.file, location.line, signature, message);
58+
(void) fprintf(
59+
stderr,
60+
"Cpptrace %s failed at %s:%d: %s: %s\n",
61+
action, location.file, location.line, signature, message
62+
);
5263
}
53-
fprintf(stderr, " primitive_%s(%s);\n", name, expression);
54-
abort();
64+
(void) fprintf(stderr, " primitive_%s(%s);\n", name, expression);
65+
std::abort();
5566
}
5667
}
5768

@@ -70,15 +81,15 @@ void nothing() {}
7081
#endif
7182

7283
CPPTRACE_MAYBE_UNUSED
73-
static std::vector<std::string> split(const std::string& s, const std::string& delims) {
84+
static std::vector<std::string> split(const std::string& str, const std::string& delims) {
7485
std::vector<std::string> vec;
7586
size_t old_pos = 0;
7687
size_t pos = 0;
77-
while((pos = s.find_first_of(delims, old_pos)) != std::string::npos) {
78-
vec.emplace_back(s.substr(old_pos, pos - old_pos));
88+
while((pos = str.find_first_of(delims, old_pos)) != std::string::npos) {
89+
vec.emplace_back(str.substr(old_pos, pos - old_pos));
7990
old_pos = pos + 1;
8091
}
81-
vec.emplace_back(std::string(s.substr(old_pos)));
92+
vec.emplace_back(str.substr(old_pos));
8293
return vec;
8394
}
8495

@@ -98,22 +109,22 @@ static std::string join(const C& container, const std::string& delim) {
98109
return str;
99110
}
100111

101-
constexpr const char* const ws = " \t\n\r\f\v";
112+
constexpr const char* const whitespace = " \t\n\r\f\v";
102113

103114
CPPTRACE_MAYBE_UNUSED
104-
static std::string trim(const std::string& s) {
105-
if(s == "") {
115+
static std::string trim(const std::string& str) {
116+
if(str.empty()) {
106117
return "";
107118
}
108-
size_t l = s.find_first_not_of(ws);
109-
size_t r = s.find_last_not_of(ws) + 1;
110-
return s.substr(l, r - l);
119+
const size_t left = str.find_first_not_of(whitespace);
120+
const size_t right = str.find_last_not_of(whitespace) + 1;
121+
return str.substr(left, right - left);
111122
}
112123

113124
CPPTRACE_MAYBE_UNUSED
114125
static std::string to_hex(uintptr_t addr) {
115126
std::stringstream sstream;
116-
sstream<<std::hex<<uintptr_t(addr);
127+
sstream<<std::hex<<addr;
117128
return std::move(sstream).str();
118129
}
119130

0 commit comments

Comments
 (0)