forked from wpilibsuite/allwpilib
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[upstream_utils] Add std::is_debugger_present() shim
Fixes wpilibsuite#7420.
- Loading branch information
Showing
14 changed files
with
383 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
36 changes: 36 additions & 0 deletions
36
upstream_utils/debugging_patches/0001-Remove-debugger_query-argument.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Tyler Veness <[email protected]> | ||
Date: Thu, 21 Nov 2024 17:23:48 -0800 | ||
Subject: [PATCH 1/2] Remove debugger_query argument | ||
|
||
--- | ||
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(); | ||
} |
35 changes: 35 additions & 0 deletions
35
upstream_utils/debugging_patches/0002-Guard-gnu-flatten-attribute.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Tyler Veness <[email protected]> | ||
Date: Thu, 21 Nov 2024 17:51:15 -0800 | ||
Subject: [PATCH 2/2] 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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
wpiutil/src/main/native/thirdparty/debugging/include/debugging.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef IXM_BREAKPOINT_HPP | ||
#define IXM_BREAKPOINT_HPP | ||
|
||
#include <debugging/detail/psnip_debug_trap.h> | ||
|
||
namespace wpi { | ||
|
||
bool is_debugger_present() noexcept; | ||
|
||
#if defined(__GNUC__) && !defined(__clang__) | ||
[[gnu::flatten]] | ||
#endif | ||
inline void breakpoint() noexcept | ||
{ | ||
psnip_trap(); | ||
} | ||
|
||
|
||
#if defined(__GNUC__) && !defined(__clang__) | ||
[[gnu::flatten]] | ||
#endif | ||
inline void breakpoint_if_debugging() noexcept | ||
{ | ||
if (is_debugger_present()) breakpoint(); | ||
} | ||
|
||
} // namespace wpi | ||
|
||
#endif |
83 changes: 83 additions & 0 deletions
83
wpiutil/src/main/native/thirdparty/debugging/include/debugging/detail/psnip_debug_trap.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* Debugging assertions and traps | ||
* Portable Snippets - https://github.com/nemequ/portable-snippets | ||
* Created by Evan Nemerson <[email protected]> | ||
* | ||
* To the extent possible under law, the authors have waived all | ||
* copyright and related or neighboring rights to this code. For | ||
* details, see the Creative Commons Zero 1.0 Universal license at | ||
* https://creativecommons.org/publicdomain/zero/1.0/ | ||
*/ | ||
|
||
#if !defined(PSNIP_DEBUG_TRAP_H) | ||
#define PSNIP_DEBUG_TRAP_H | ||
|
||
#if !defined(PSNIP_NDEBUG) && defined(NDEBUG) && !defined(PSNIP_DEBUG) | ||
# define PSNIP_NDEBUG 1 | ||
#endif | ||
|
||
#if defined(__has_builtin) && !defined(__ibmxl__) | ||
# if __has_builtin(__builtin_debugtrap) | ||
# define psnip_trap() __builtin_debugtrap() | ||
# elif __has_builtin(__debugbreak) | ||
# define psnip_trap() __debugbreak() | ||
# endif | ||
#endif | ||
#if !defined(psnip_trap) | ||
# if defined(_MSC_VER) || defined(__INTEL_COMPILER) | ||
# define psnip_trap() __debugbreak() | ||
# elif defined(__ARMCC_VERSION) | ||
# define psnip_trap() __breakpoint(42) | ||
# elif defined(__ibmxl__) || defined(__xlC__) | ||
# include <builtins.h> | ||
# define psnip_trap() __trap(42) | ||
# elif defined(__DMC__) && defined(_M_IX86) | ||
static inline void psnip_trap(void) { __asm int 3h; } | ||
# elif defined(__i386__) || defined(__x86_64__) | ||
static inline void psnip_trap(void) { __asm__ __volatile__("int3"); } | ||
# elif defined(__thumb__) | ||
static inline void psnip_trap(void) { __asm__ __volatile__(".inst 0xde01"); } | ||
# elif defined(__aarch64__) | ||
static inline void psnip_trap(void) { __asm__ __volatile__(".inst 0xd4200000"); } | ||
# elif defined(__arm__) | ||
static inline void psnip_trap(void) { __asm__ __volatile__(".inst 0xe7f001f0"); } | ||
# elif defined (__alpha__) && !defined(__osf__) | ||
static inline void psnip_trap(void) { __asm__ __volatile__("bpt"); } | ||
# elif defined(_54_) | ||
static inline void psnip_trap(void) { __asm__ __volatile__("ESTOP"); } | ||
# elif defined(_55_) | ||
static inline void psnip_trap(void) { __asm__ __volatile__(";\n .if (.MNEMONIC)\n ESTOP_1\n .else\n ESTOP_1()\n .endif\n NOP"); } | ||
# elif defined(_64P_) | ||
static inline void psnip_trap(void) { __asm__ __volatile__("SWBP 0"); } | ||
# elif defined(_6x_) | ||
static inline void psnip_trap(void) { __asm__ __volatile__("NOP\n .word 0x10000000"); } | ||
# elif defined(__STDC_HOSTED__) && (__STDC_HOSTED__ == 0) && defined(__GNUC__) | ||
# define psnip_trap() __builtin_trap() | ||
# else | ||
# include <signal.h> | ||
# if defined(SIGTRAP) | ||
# define psnip_trap() raise(SIGTRAP) | ||
# else | ||
# define psnip_trap() raise(SIGABRT) | ||
# endif | ||
# endif | ||
#endif | ||
|
||
#if defined(HEDLEY_LIKELY) | ||
# define PSNIP_DBG_LIKELY(expr) HEDLEY_LIKELY(expr) | ||
#elif defined(__GNUC__) && (__GNUC__ >= 3) | ||
# define PSNIP_DBG_LIKELY(expr) __builtin_expect(!!(expr), 1) | ||
#else | ||
# define PSNIP_DBG_LIKELY(expr) (!!(expr)) | ||
#endif | ||
|
||
#if !defined(PSNIP_NDEBUG) || (PSNIP_NDEBUG == 0) | ||
# define psnip_dbg_assert(expr) do { \ | ||
if (!PSNIP_DBG_LIKELY(expr)) { \ | ||
psnip_trap(); \ | ||
} \ | ||
} while (0) | ||
#else | ||
# define psnip_dbg_assert(expr) | ||
#endif | ||
|
||
#endif /* !defined(PSNIP_DEBUG_TRAP_H) */ |
Oops, something went wrong.