@@ -26,8 +26,26 @@ pub mod _internal {
2626 #[ doc( hidden) ]
2727 pub use super :: _internal_once as _once;
2828
29+ #[ cfg( not( feature = "no_cache_debugger" ) ) ]
2930 pub fn _is_debugger_present ( ) -> bool {
30- pub use :: dbg_breakpoint:: { is_debugger_present, DebuggerPresence } ;
31+ use :: core:: sync:: atomic:: { AtomicBool , Ordering } ;
32+
33+ static DEBUGGER_CHECKED : AtomicBool = AtomicBool :: new ( false ) ;
34+ static DEBUGGER_ATTACHED : AtomicBool = AtomicBool :: new ( false ) ;
35+
36+ if !DEBUGGER_CHECKED . swap ( true , Ordering :: Relaxed ) {
37+ DEBUGGER_ATTACHED . swap ( check_debugger ( ) , Ordering :: Relaxed ) ;
38+ }
39+
40+ DEBUGGER_ATTACHED . load ( Ordering :: Relaxed )
41+ }
42+ #[ cfg( feature = "no_cache_debugger" ) ]
43+ pub fn _is_debugger_present ( ) -> bool {
44+ check_debugger ( )
45+ }
46+
47+ fn check_debugger ( ) -> bool {
48+ use :: dbg_breakpoint:: { is_debugger_present, DebuggerPresence } ;
3149
3250 let Some ( DebuggerPresence :: Detected ) = is_debugger_present ( ) else {
3351 return false ;
@@ -52,10 +70,7 @@ macro_rules! breakpoint {
5270 ( ) => { } ;
5371}
5472#[ macro_export]
55- #[ cfg( all(
56- any( target_arch = "x86" , target_arch = "x86_64" ) ,
57- debug_assertions
58- ) ) ]
73+ #[ cfg( all( any( target_arch = "x86" , target_arch = "x86_64" ) , debug_assertions) ) ]
5974macro_rules! breakpoint {
6075 ( ) => {
6176 if $crate:: _internal:: _is_debugger_present( ) {
@@ -66,10 +81,7 @@ macro_rules! breakpoint {
6681 } ;
6782}
6883#[ macro_export]
69- #[ cfg( all(
70- target_arch = "aarch64" ,
71- debug_assertions
72- ) ) ]
84+ #[ cfg( all( target_arch = "aarch64" , debug_assertions) ) ]
7385macro_rules! breakpoint {
7486 ( ) => {
7587 if $crate:: _internal:: _is_debugger_present( ) {
@@ -81,11 +93,7 @@ macro_rules! breakpoint {
8193}
8294#[ macro_export]
8395#[ cfg( all(
84- not( any(
85- target_arch = "x86" ,
86- target_arch = "x86_64" ,
87- target_arch = "aarch64" ,
88- ) ) ,
96+ not( any( target_arch = "x86" , target_arch = "x86_64" , target_arch = "aarch64" , ) ) ,
8997 debug_assertions
9098) ) ]
9199macro_rules! breakpoint {
0 commit comments