mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-06 03:31:43 +00:00
[upstream_utils] Add std::is_debugger_present() shim (#7423)
This commit is contained in:
48
upstream_utils/debugging.py
Executable file
48
upstream_utils/debugging.py
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from upstream_utils import Lib, walk_cwd_and_copy_if
|
||||
|
||||
|
||||
def copy_upstream_src(wpilib_root):
|
||||
wpiutil = os.path.join(wpilib_root, "wpiutil")
|
||||
|
||||
# Delete old install
|
||||
for d in [
|
||||
"src/main/native/thirdparty/debugging/src",
|
||||
"src/main/native/thirdparty/debugging/include",
|
||||
]:
|
||||
shutil.rmtree(os.path.join(wpiutil, d), ignore_errors=True)
|
||||
|
||||
# Copy debugging files into allwpilib
|
||||
filenames = walk_cwd_and_copy_if(
|
||||
lambda dp, f: dp.startswith(os.path.join(".", "src"))
|
||||
or dp.startswith(os.path.join(".", "include")),
|
||||
os.path.join(wpiutil, "src/main/native/thirdparty/debugging"),
|
||||
)
|
||||
|
||||
for filename in filenames:
|
||||
with open(filename) as f:
|
||||
content = f.read()
|
||||
|
||||
# Rename namespace from stdx to wpi
|
||||
content = content.replace("namespace stdx", "namespace wpi")
|
||||
|
||||
with open(filename, "w") as f:
|
||||
f.write(content)
|
||||
|
||||
|
||||
def main():
|
||||
name = "debugging"
|
||||
url = "https://github.com/grafikrobot/debugging"
|
||||
# master on 2024-11-21
|
||||
tag = "c510133c44894b93afbb5be55275bfb88163a2cb"
|
||||
|
||||
expected = Lib(name, url, tag, copy_upstream_src)
|
||||
expected.main()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,35 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Tyler Veness <calcmogul@gmail.com>
|
||||
Date: Thu, 21 Nov 2024 17:51:15 -0800
|
||||
Subject: [PATCH 1/4] Guard [[gnu::flatten]] attribute
|
||||
|
||||
---
|
||||
include/debugging.hpp | 10 ++++++++--
|
||||
1 file changed, 8 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/include/debugging.hpp b/include/debugging.hpp
|
||||
index 70ba724a2b6522a774931af7d7be2cee9408567a..25014a9fc65d06052089058feea7566462c01d60 100644
|
||||
--- a/include/debugging.hpp
|
||||
+++ b/include/debugging.hpp
|
||||
@@ -7,13 +7,19 @@ namespace stdx {
|
||||
|
||||
bool is_debugger_present() noexcept;
|
||||
|
||||
-[[gnu::flatten]] inline void breakpoint() noexcept
|
||||
+#if defined(__GNUC__) && !defined(__clang__)
|
||||
+[[gnu::flatten]]
|
||||
+#endif
|
||||
+inline void breakpoint() noexcept
|
||||
{
|
||||
psnip_trap();
|
||||
}
|
||||
|
||||
|
||||
-[[gnu::flatten]] inline void breakpoint_if_debugging() noexcept
|
||||
+#if defined(__GNUC__) && !defined(__clang__)
|
||||
+[[gnu::flatten]]
|
||||
+#endif
|
||||
+inline void breakpoint_if_debugging() noexcept
|
||||
{
|
||||
if (is_debugger_present()) breakpoint();
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Tyler Veness <calcmogul@gmail.com>
|
||||
Date: Thu, 21 Nov 2024 17:23:48 -0800
|
||||
Subject: [PATCH 2/4] Remove debugger_query argument from Windows and macOS
|
||||
|
||||
---
|
||||
src/macos.cxx | 2 +-
|
||||
src/windows.cxx | 2 +-
|
||||
2 files changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/src/macos.cxx b/src/macos.cxx
|
||||
index bbcf6f2eec9ea479a2bea0ff06b454dc81b5d356..85dbb5f45d89680e39b4847a9aa2d5472c824f2a 100644
|
||||
--- a/src/macos.cxx
|
||||
+++ b/src/macos.cxx
|
||||
@@ -13,7 +13,7 @@ auto exc = std::array<T, EXC_TYPES_COUNT> { {} };
|
||||
|
||||
namespace stdx {
|
||||
|
||||
-bool is_debugger_present(debugger_query q) noexcept
|
||||
+bool is_debugger_present() noexcept
|
||||
{
|
||||
mach_msg_type_number_t count {};
|
||||
auto masks = exc<exception_mask_t>;
|
||||
diff --git a/src/windows.cxx b/src/windows.cxx
|
||||
index eec576f415d52f63d2658012546ead2e691d7415..45d98eb27c5182de7ad11291925275fb4fdb54fb 100644
|
||||
--- a/src/windows.cxx
|
||||
+++ b/src/windows.cxx
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace stdx {
|
||||
|
||||
-bool is_debugger_present(debugger_query q) noexcept
|
||||
+bool is_debugger_present() noexcept
|
||||
{
|
||||
return ::IsDebuggerPresent();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Tyler Veness <calcmogul@gmail.com>
|
||||
Date: Thu, 21 Nov 2024 18:09:37 -0800
|
||||
Subject: [PATCH 3/4] Fix exception mask type typo on macOS
|
||||
|
||||
---
|
||||
src/macos.cxx | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/macos.cxx b/src/macos.cxx
|
||||
index 85dbb5f45d89680e39b4847a9aa2d5472c824f2a..2c68064742bc7883a08551b88cd5dbb9a1f38100 100644
|
||||
--- a/src/macos.cxx
|
||||
+++ b/src/macos.cxx
|
||||
@@ -20,7 +20,7 @@ bool is_debugger_present() noexcept
|
||||
auto ports = exc<mach_port_t>;
|
||||
auto behaviors = exc<exception_behavior_t>;
|
||||
auto flavors = exc<thread_state_flavor_t>;
|
||||
- exception_mast_t mask
|
||||
+ exception_mask_t mask
|
||||
= EXC_MASK_ALL & ~(EXC_MASK_RESOURCE | EXC_MASK_GUARD);
|
||||
kern_return_t result = task_get_exception_ports(mach_task_self(), mask,
|
||||
masks.data(), &count, ports.data(), behaviors.data(), flavors.data());
|
||||
@@ -0,0 +1,21 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Tyler Veness <calcmogul@gmail.com>
|
||||
Date: Thu, 21 Nov 2024 18:49:53 -0800
|
||||
Subject: [PATCH 4/4] Remove NOMINMAX macro from Windows
|
||||
|
||||
---
|
||||
src/windows.cxx | 1 -
|
||||
1 file changed, 1 deletion(-)
|
||||
|
||||
diff --git a/src/windows.cxx b/src/windows.cxx
|
||||
index 45d98eb27c5182de7ad11291925275fb4fdb54fb..d20ae438ef9b2de8830c6df099f0476aba395de5 100644
|
||||
--- a/src/windows.cxx
|
||||
+++ b/src/windows.cxx
|
||||
@@ -4,7 +4,6 @@
|
||||
# include <debugging.hpp>
|
||||
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
-# define NOMINMAX
|
||||
# include <Windows.h>
|
||||
|
||||
namespace stdx {
|
||||
@@ -55,9 +55,10 @@ def copy_to(files, root, rename_c_to_cpp=False):
|
||||
for f in files:
|
||||
dest_file = os.path.join(root, f)
|
||||
|
||||
# Rename .cc file to .cpp
|
||||
if dest_file.endswith(".cc"):
|
||||
# Rename .cc or .cxx file to .cpp
|
||||
if dest_file.endswith(".cc") or dest_file.endswith(".cxx"):
|
||||
dest_file = os.path.splitext(dest_file)[0] + ".cpp"
|
||||
|
||||
if rename_c_to_cpp and dest_file.endswith(".c"):
|
||||
dest_file = os.path.splitext(dest_file)[0] + ".cpp"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user