Skip to content

Commit 1a5ca21

Browse files
committed
Enable boost stacktrace backtrace
1 parent 117c7fb commit 1a5ca21

File tree

6 files changed

+92
-10
lines changed

6 files changed

+92
-10
lines changed

.gitmodules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
[submodule "vcpkg"]
1010
path = depends/vcpkg
1111
url = https://github.com/microsoft/vcpkg.git
12+
ignore = dirty
1213
[submodule "libnet"]
1314
path = third_party/libnet/libnet
1415
url = https://github.com/libnet/libnet.git

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ add_subdirectory(third_party/bpftool EXCLUDE_FROM_ALL)
6363
add_subdirectory(third_party/libbpf EXCLUDE_FROM_ALL)
6464
add_subdirectory(third_party/libnet EXCLUDE_FROM_ALL)
6565
find_package(boost_program_options CONFIG REQUIRED)
66-
find_package(boost_stacktrace_addr2line CONFIG REQUIRED)
66+
find_package(boost_stacktrace_backtrace CONFIG REQUIRED)
6767
find_package(boost_stacktrace_basic CONFIG REQUIRED)
6868
find_package(boost_stacktrace_noop CONFIG REQUIRED)
6969
find_package(BpfObject REQUIRED)
@@ -80,10 +80,14 @@ find_package(ZLIB REQUIRED) # required by `FindBpfObject.cmake`
8080

8181
#
8282
# stacktrace
83+
# https://www.boost.org/doc/libs/master/doc/html/stacktrace/configuration_and_build.html
8384
#
8485
add_library(stacktrace_config INTERFACE)
86+
target_compile_definitions(stacktrace_config INTERFACE BOOST_STACKTRACE_LINK)
8587
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
86-
target_link_libraries(stacktrace_config INTERFACE Boost::stacktrace_addr2line dl)
88+
# libbacktrace is already linked statically with Boost::stacktrace_backtrace
89+
# through our patched vcpkg, so `-lbacktrace` is not needed.
90+
target_link_libraries(stacktrace_config INTERFACE Boost::stacktrace_backtrace dl)
8791
else()
8892
target_link_libraries(stacktrace_config INTERFACE Boost::stacktrace_noop)
8993
endif()

depends/vcpkg.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,14 @@
1212
{
1313
"name": "curl",
1414
"features": [
15-
"brotli",
1615
"c-ares",
17-
"gssapi",
1816
"http2",
1917
"idn",
2018
"idn2",
21-
"ldap",
2219
"openssl",
2320
"psl",
2421
"ssh",
25-
"ssl",
26-
"zstd"
22+
"ssl"
2723
]
2824
},
2925
"pcapplusplus",

depends/vcpkg.patch

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
diff --git a/ports/boost-stacktrace/features.cmake b/ports/boost-stacktrace/features.cmake
2+
index 3491066c4..9d4e1c242 100644
3+
--- a/ports/boost-stacktrace/features.cmake
4+
+++ b/ports/boost-stacktrace/features.cmake
5+
@@ -23,7 +23,7 @@
6+
# When ON, builds the boost_stacktrace_windbg_cached library variant. Defaults to ON under Windows when WinDbg support is autodetected and when thread_local is supported, otherwise OFF.
7+
8+
list(APPEND FEATURE_OPTIONS
9+
- -DBOOST_STACKTRACE_ENABLE_BACKTRACE=OFF
10+
+ -DBOOST_STACKTRACE_ENABLE_BACKTRACE=ON
11+
)
12+
13+
if(VCPKG_TARGET_IS_WINDOWS)
14+
@@ -34,4 +34,4 @@ else()
15+
list(APPEND FEATURE_OPTIONS
16+
-DBOOST_STACKTRACE_ENABLE_WINDBG=OFF
17+
)
18+
-endif()
19+
\ No newline at end of file
20+
+endif()
21+
diff --git a/ports/boost-stacktrace/fix_backtrace.diff b/ports/boost-stacktrace/fix_backtrace.diff
22+
new file mode 100644
23+
index 000000000..cb73ddb23
24+
--- /dev/null
25+
+++ b/ports/boost-stacktrace/fix_backtrace.diff
26+
@@ -0,0 +1,22 @@
27+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
28+
+index 4638618..6825856 100644
29+
+--- a/CMakeLists.txt
30+
++++ b/CMakeLists.txt
31+
+@@ -61,7 +61,7 @@ function(stacktrace_check var source incs libs defs)
32+
+
33+
+ endfunction()
34+
+
35+
+-stacktrace_check(BOOST_STACKTRACE_HAS_BACKTRACE has_backtrace.cpp "" "backtrace" "")
36+
++stacktrace_check(BOOST_STACKTRACE_HAS_BACKTRACE has_backtrace.cpp "" "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/libbacktrace.a" "")
37+
+
38+
+ set(_default_addr2line ON)
39+
+ if(WIN32 AND NOT CMAKE_CXX_PLATFORM_ID MATCHES "Cygwin")
40+
+@@ -90,7 +90,7 @@ message(STATUS "Boost.Stacktrace: "
41+
+ )
42+
+
43+
+ stacktrace_add_library(noop ${BOOST_STACKTRACE_ENABLE_NOOP} "" "")
44+
+-stacktrace_add_library(backtrace ${BOOST_STACKTRACE_ENABLE_BACKTRACE} "backtrace" "")
45+
++stacktrace_add_library(backtrace ${BOOST_STACKTRACE_ENABLE_BACKTRACE} "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/libbacktrace.a" "")
46+
+ stacktrace_add_library(addr2line ${BOOST_STACKTRACE_ENABLE_ADDR2LINE} "" "")
47+
+ stacktrace_add_library(basic ${BOOST_STACKTRACE_ENABLE_BASIC} "" "")
48+
+ stacktrace_add_library(windbg ${BOOST_STACKTRACE_ENABLE_WINDBG} "dbgeng;ole32" "_GNU_SOURCE=1")
49+
diff --git a/ports/boost-stacktrace/portfile.cmake b/ports/boost-stacktrace/portfile.cmake
50+
index cd2a782af..ccd630570 100644
51+
--- a/ports/boost-stacktrace/portfile.cmake
52+
+++ b/ports/boost-stacktrace/portfile.cmake
53+
@@ -8,6 +8,7 @@ vcpkg_from_github(
54+
HEAD_REF master
55+
PATCHES
56+
fix_config-check.diff
57+
+ fix_backtrace.diff
58+
)
59+
60+
set(FEATURE_OPTIONS "")
61+
diff --git a/ports/boost-stacktrace/vcpkg.json b/ports/boost-stacktrace/vcpkg.json
62+
index e734e9917..e9533afbc 100644
63+
--- a/ports/boost-stacktrace/vcpkg.json
64+
+++ b/ports/boost-stacktrace/vcpkg.json
65+
@@ -8,6 +8,7 @@
66+
"license": "BSL-1.0",
67+
"supports": "!uwp",
68+
"dependencies": [
69+
+ "libbacktrace",
70+
{
71+
"name": "boost-assert",
72+
"version>=": "1.85.0"

scripts/configure.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,21 @@ reset_files() {
8181
git -C "$PROJECT_DIR" submodule update --init --recursive
8282
for submod in "${in_tree_submods[@]}"; do
8383
msg "Cleaning $submod"
84+
git -C "$submod" restore .
8485
git -C "$submod" clean -xdf
8586
done
87+
8688
msg "Removing $BUILD_DIR"
8789
rm -rf "$BUILD_DIR"
8890

91+
msg "Patching vcpkg"
92+
git -C "$PROJECT_DIR/depends/vcpkg" restore .
93+
local out
94+
out="$(patch -d "$PROJECT_DIR/depends/vcpkg" -Np1 \
95+
-i "$PROJECT_DIR/depends/vcpkg.patch")" ||
96+
echo "$out" | grep -q 'Skipping patch' ||
97+
die "$out"
98+
8999
if [[ $CLEAN -ne 0 ]]; then
90100
exit 0
91101
fi

src/logger.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#define LOG_PATTERN "[%E.%f] [%P] [%^%L%L%$] %v"
1616

1717
using namespace std;
18-
namespace st = boost::stacktrace;
1918

2019
Logger logger; // global logger
2120

@@ -101,11 +100,11 @@ void Logger::warn(const string &msg) {
101100
}
102101

103102
void Logger::error(const string &msg) {
104-
auto trace = st::stacktrace();
103+
auto trace = boost::stacktrace::stacktrace();
105104
string msg_with_trace = msg;
106105

107106
if (!trace.empty()) {
108-
msg_with_trace += "\n" + st::to_string(trace);
107+
msg_with_trace += "\n" + boost::stacktrace::to_string(trace);
109108
}
110109

111110
if (this->_stdout_logger) {

0 commit comments

Comments
 (0)