Skip to content

Commit 876d410

Browse files
committed
[wpiutil] Use C++23 stacktrace library on Windows
This lets us remove the unmaintained StackWalker library and its hacky upstream_utils script. A Discord user also reported that StackWalker gives blank stacktraces: https://discord.com/channels/176186766946992128/368993897495527424/1261940029287301150 They reported an earlier version of this PR giving the following stacktrace instead: ``` D:\allwpilib\developerRobot\src\main\native\cpp\Robot.cpp(18): developerRobotCpp!Robot::RobotInit+0xB6 D:\allwpilib\wpilibc\src\main\native\cpp\TimedRobot.cpp(22): wpilibcd!frc::TimedRobot::StartCompetition+0x4F D:\allwpilib\wpilibc\src\main\native\include\frc\RobotBase.h(36): developerRobotCpp!frc::impl::RunRobot<Robot>+0xC8 D:\allwpilib\wpilibc\src\main\native\include\frc\RobotBase.h(106): developerRobotCpp!frc::StartRobot<Robot>+0x17E D:\allwpilib\developerRobot\src\main\native\cpp\Robot.cpp(60): developerRobotCpp!main+0xB D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl(79): developerRobotCpp!invoke_main+0x39 D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl(288): developerRobotCpp!__scrt_common_main_seh+0x132 D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl(331): developerRobotCpp!__scrt_common_main+0xE D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp(17): developerRobotCpp!mainCRTStartup+0xE KERNEL32!BaseThreadInitThunk+0x1D ntdll!RtlUserThreadStart+0x28 ```
1 parent d62ab12 commit 876d410

File tree

19 files changed

+68
-2007
lines changed

19 files changed

+68
-2007
lines changed

.github/workflows/upstream-utils.yml

-6
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,6 @@ jobs:
120120
./mpack.py clone
121121
./mpack.py copy-src
122122
./mpack.py format-patch
123-
- name: Run stack_walker.py
124-
run: |
125-
cd upstream_utils
126-
./stack_walker.py clone
127-
./stack_walker.py copy-src
128-
./stack_walker.py format-patch
129123
- name: Run memory.py
130124
run: |
131125
cd upstream_utils

ThirdPartyNotices.txt

-30
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ jQuery wpinet/src/main/native/resources/jquery-*
3333
popper.js wpinet/src/main/native/resources/popper-*
3434
units wpimath/src/main/native/include/units/
3535
Eigen wpimath/src/main/native/thirdparty/eigen/include/
36-
StackWalker wpiutil/src/main/native/windows/StackWalker.*
3736
Team 254 Library wpimath/src/main/java/edu/wpi/first/math/spline/SplineParameterizer.java
3837
wpimath/src/main/java/edu/wpi/first/math/trajectory/TrajectoryParameterizer.java
3938
wpimath/src/main/native/include/frc/spline/SplineParameterizer.h
@@ -1026,35 +1025,6 @@ Exhibit B - "Incompatible With Secondary Licenses" Notice
10261025
defined by the Mozilla Public License, v. 2.0.
10271026

10281027

1029-
===================
1030-
StackWalker License
1031-
===================
1032-
Copyright (c) 2005-2013, Jochen Kalmbach
1033-
All rights reserved.
1034-
1035-
Redistribution and use in source and binary forms, with or without modification,
1036-
are permitted provided that the following conditions are met:
1037-
1038-
Redistributions of source code must retain the above copyright notice,
1039-
this list of conditions and the following disclaimer.
1040-
Redistributions in binary form must reproduce the above copyright notice,
1041-
this list of conditions and the following disclaimer in the documentation
1042-
and/or other materials provided with the distribution.
1043-
Neither the name of Jochen Kalmbach nor the names of its contributors may be
1044-
used to endorse or promote products derived from this software without
1045-
specific prior written permission.
1046-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1047-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
1048-
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1049-
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
1050-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1051-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1052-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1053-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1054-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1055-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1056-
1057-
10581028
================
10591029
Team 254 Library
10601030
================

apriltag/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ add_library(apriltag ${apriltag_native_src} ${apriltag_resources_src} ${apriltag
120120
set_target_properties(apriltag PROPERTIES DEBUG_POSTFIX "d")
121121

122122
set_property(TARGET apriltag PROPERTY FOLDER "libraries")
123-
target_compile_features(apriltag PUBLIC cxx_std_20)
123+
if(MSVC)
124+
target_compile_features(apriltag PUBLIC cxx_std_23)
125+
else()
126+
target_compile_features(apriltag PUBLIC cxx_std_20)
127+
endif()
124128
wpilib_target_warnings(apriltag)
125129

126130
target_link_libraries(apriltag wpimath)

fieldImages/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ add_library(fieldImages ${field_images_resources_src} src/main/native/cpp/fields
4646
set_target_properties(fieldImages PROPERTIES DEBUG_POSTFIX "d")
4747

4848
set_property(TARGET fieldImages PROPERTY FOLDER "libraries")
49-
target_compile_features(fieldImages PUBLIC cxx_std_20)
5049
if(MSVC)
5150
target_compile_options(fieldImages PUBLIC /bigobj)
51+
target_compile_features(fieldImages PUBLIC cxx_std_23)
52+
else()
53+
target_compile_features(fieldImages PUBLIC cxx_std_20)
5254
endif()
5355
wpilib_target_warnings(fieldImages)
5456

ntcore/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ target_include_directories(
2525
$<INSTALL_INTERFACE:${include_dest}/ntcore>
2626
)
2727
wpilib_target_warnings(ntcore)
28-
target_compile_features(ntcore PUBLIC cxx_std_20)
28+
if(MSVC)
29+
target_compile_features(ntcore PUBLIC cxx_std_23)
30+
else()
31+
target_compile_features(ntcore PUBLIC cxx_std_20)
32+
endif()
2933
target_link_libraries(ntcore PUBLIC wpinet wpiutil)
3034

3135
set_property(TARGET ntcore PROPERTY FOLDER "libraries")

romiVendordep/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ add_library(romiVendordep ${romiVendordep_native_src})
5252
set_target_properties(romiVendordep PROPERTIES DEBUG_POSTFIX "d")
5353
set_property(TARGET romiVendordep PROPERTY FOLDER "libraries")
5454

55-
target_compile_features(romiVendordep PUBLIC cxx_std_20)
55+
if(MSVC)
56+
target_compile_features(romiVendordep PUBLIC cxx_std_23)
57+
else()
58+
target_compile_features(romiVendordep PUBLIC cxx_std_20)
59+
endif()
5660
wpilib_target_warnings(romiVendordep)
5761
target_link_libraries(romiVendordep wpilibc)
5862

shared/config.gradle

+7
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ nativeUtils.platformConfigs.each {
3939
}
4040
}
4141

42+
// Use C++23 on Windows
43+
nativeUtils.platformConfigs.each {
44+
if (it.name.contains('windows')) {
45+
it.cppCompiler.args.add("/std:c++23preview")
46+
}
47+
}
48+
4249
nativeUtils.platformConfigs.linuxathena.linker.args.add("-Wl,--fatal-warnings")
4350

4451
if (project.hasProperty('ntcoreffibuild')) {

upstream_utils/stack_walker.py

-65
This file was deleted.

upstream_utils/stack_walker_patches/0001-Add-advapi-pragma.patch

-21
This file was deleted.

wpilibNewCommands/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ add_library(wpilibNewCommands ${wpilibNewCommands_native_src})
6060
set_target_properties(wpilibNewCommands PROPERTIES DEBUG_POSTFIX "d")
6161
set_property(TARGET wpilibNewCommands PROPERTY FOLDER "libraries")
6262

63-
target_compile_features(wpilibNewCommands PUBLIC cxx_std_20)
63+
if(MSVC)
64+
target_compile_features(wpilibNewCommands PUBLIC cxx_std_23)
65+
else()
66+
target_compile_features(wpilibNewCommands PUBLIC cxx_std_20)
67+
endif()
6468
wpilib_target_warnings(wpilibNewCommands)
6569
target_link_libraries(wpilibNewCommands wpilibc)
6670

wpimath/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ set_target_properties(wpimath PROPERTIES DEBUG_POSTFIX "d")
153153
set_property(TARGET wpimath PROPERTY FOLDER "libraries")
154154
target_compile_definitions(wpimath PRIVATE WPILIB_EXPORTS SLEIPNIR_EXPORTS)
155155

156-
target_compile_features(wpimath PUBLIC cxx_std_20)
157156
if(MSVC)
157+
target_compile_features(wpimath PUBLIC cxx_std_23)
158158
target_compile_options(wpimath PUBLIC /utf-8 /bigobj)
159159
endif()
160160
wpilib_target_warnings(wpimath)

wpinet/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ set_target_properties(wpinet PROPERTIES DEBUG_POSTFIX "d")
126126

127127
set_property(TARGET wpinet PROPERTY FOLDER "libraries")
128128

129-
target_compile_features(wpinet PUBLIC cxx_std_20)
129+
if(MSVC)
130+
target_compile_features(wpinet PUBLIC cxx_std_23)
131+
else()
132+
target_compile_features(wpinet PUBLIC cxx_std_20)
133+
endif()
130134
wpilib_target_warnings(wpinet)
131135
target_link_libraries(wpinet PUBLIC wpiutil)
132136

wpiutil/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,15 @@ set_target_properties(wpiutil PROPERTIES DEBUG_POSTFIX "d")
141141

142142
set_property(TARGET wpiutil PROPERTY FOLDER "libraries")
143143

144-
target_compile_features(wpiutil PUBLIC cxx_std_20)
145144
if(MSVC)
146145
target_compile_options(
147146
wpiutil
148147
PUBLIC /permissive- /Zc:preprocessor /Zc:__cplusplus /Zc:throwingNew /MP /bigobj /utf-8
149148
)
150149
target_compile_definitions(wpiutil PRIVATE -D_CRT_SECURE_NO_WARNINGS)
150+
target_compile_features(wpiutil PUBLIC cxx_std_23)
151+
else()
152+
target_compile_features(wpiutil PUBLIC cxx_std_20)
151153
endif()
152154
wpilib_target_warnings(wpiutil)
153155
if(WITH_PROTOBUF)

wpiutil/src/main/native/cpp/RuntimeCheck.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#ifdef _WIN32
88
#include <cstdio>
99
#include <memory>
10-
10+
#pragma comment(lib, "version.lib") // for VerQueryValueW
1111
#include "Windows.h"
1212
extern "C" int32_t WPI_IsRuntimeValid(uint32_t* foundMajor,
1313
uint32_t* foundMinor,

wpiutil/src/main/native/unix/StackTrace.cpp wpiutil/src/main/native/cpp/StackTrace.cpp

+23-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
#include "wpi/StackTrace.h"
66

7+
#ifdef __cpp_lib_stacktrace
8+
#include <stacktrace>
9+
#elif !defined(_WIN32)
710
#include <execinfo.h>
11+
#endif
812

913
#include <string>
1014

@@ -16,33 +20,41 @@
1620
namespace wpi {
1721

1822
std::string GetStackTraceDefault(int offset) {
19-
#ifndef __ANDROID__
23+
wpi::SmallString<1024> buf;
24+
wpi::raw_svector_ostream trace(buf);
25+
26+
#ifdef __cpp_lib_stacktrace
27+
auto stackTrace = std::stacktrace::current();
28+
29+
for (size_t i = offset; i < stackTrace.size(); ++i) {
30+
// Only print recursive functions once in a row
31+
if (i == 0 || stackTrace[i] != stackTrace[i - 1]) {
32+
trace << "\tat " << std::to_string(stackTrace[i]) << '\n';
33+
}
34+
}
35+
#elif !defined(_WIN32) && !defined(__ANDROID__)
2036
void* stackTrace[128];
2137
int stackSize = backtrace(stackTrace, 128);
2238
char** mangledSymbols = backtrace_symbols(stackTrace, stackSize);
23-
wpi::SmallString<1024> buf;
24-
wpi::raw_svector_ostream trace(buf);
2539

26-
for (int i = offset; i < stackSize; i++) {
27-
// Only print recursive functions once in a row.
40+
for (int i = offset; i < stackSize; ++i) {
41+
// Only print recursive functions once in a row
2842
if (i == 0 || stackTrace[i] != stackTrace[i - 1]) {
29-
// extract just function name from "pathToExe(functionName+offset)"
43+
// Extract just function name from "pathToExe(functionName+offset)"
3044
std::string_view sym = split(mangledSymbols[i], '(').second;
3145
std::string_view offset;
3246
std::tie(sym, offset) = split(sym, '+');
3347
std::string_view addr;
3448
std::tie(offset, addr) = split(offset, ')');
35-
trace << "\tat " << Demangle(sym) << " + " << offset << addr << "\n";
49+
50+
trace << "\tat " << Demangle(sym) << " + " << offset << addr << '\n';
3651
}
3752
}
3853

3954
std::free(mangledSymbols);
55+
#endif
4056

4157
return std::string{trace.str()};
42-
#else
43-
// backtrace_symbols not supported on android
44-
return "";
45-
#endif
4658
}
4759

4860
} // namespace wpi

wpiutil/src/main/native/windows/StackTrace.cpp

-42
This file was deleted.

0 commit comments

Comments
 (0)