Skip to content

Commit 44b7ba3

Browse files
Move IsDebuggerPresent to minipal, convert to QCall (#108837)
* Move IsDebuggerPresent to minipal, convert to QCall --------- Co-authored-by: Aaron Robinson <[email protected]>
1 parent 69dc5ec commit 44b7ba3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+302
-452
lines changed

src/coreclr/System.Private.CoreLib/src/System/Diagnostics/Debugger.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,12 @@ static void NotifyOfCrossThreadDependencySlow()
5858
[return: MarshalAs(UnmanagedType.Bool)]
5959
private static partial bool LaunchInternal();
6060

61-
// Returns whether or not a debugger is attached to the process.
62-
//
63-
public static extern bool IsAttached
64-
{
65-
[MethodImpl(MethodImplOptions.InternalCall)]
66-
get;
67-
}
61+
// Returns whether or not a managed debugger is attached to the process.
62+
public static bool IsAttached => IsManagedDebuggerAttached() != 0;
63+
64+
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "DebugDebugger_IsManagedDebuggerAttached")]
65+
[SuppressGCTransition]
66+
private static partial int IsManagedDebuggerAttached();
6867

6968
// Constants representing the importance level of messages to be logged.
7069
//
@@ -85,9 +84,11 @@ public static extern bool IsAttached
8584
private static partial void LogInternal(int level, string? category, string? message);
8685

8786
// Checks to see if an attached debugger has logging enabled
88-
//
89-
[MethodImpl(MethodImplOptions.InternalCall)]
90-
public static extern bool IsLogging();
87+
public static bool IsLogging() => IsLoggingInternal() != 0;
88+
89+
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "DebugDebugger_IsLoggingHelper")]
90+
[SuppressGCTransition]
91+
private static partial int IsLoggingInternal();
9192

9293
// Posts a custom notification for the attached debugger. If there is no
9394
// debugger attached, has no effect. The debugger may or may not

src/coreclr/debug/ee/debugger.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,7 @@ void Debugger::SendRawEvent(const DebuggerIPCEvent * pManagedEvent)
16511651

16521652
// If no debugger attached, then don't bother raising a 1st-chance exception because nobody will sniff it.
16531653
// @dbgtodo iDNA: in iDNA case, the recorder may sniff it.
1654-
if (!IsDebuggerPresent())
1654+
if (!minipal_is_native_debugger_present())
16551655
{
16561656
return;
16571657
}
@@ -6469,7 +6469,7 @@ HRESULT Debugger::LaunchDebuggerForUser(Thread * pThread, EXCEPTION_POINTERS * p
64696469
//
64706470
SendUserBreakpointAndSynchronize(g_pEEInterface->GetThread());
64716471
}
6472-
else if (!CORDebuggerAttached() && IsDebuggerPresent())
6472+
else if (!CORDebuggerAttached() && minipal_is_native_debugger_present())
64736473
{
64746474
//
64756475
// If the registered debugger is not a managed debugger, send a native breakpoint
@@ -6485,7 +6485,7 @@ HRESULT Debugger::LaunchDebuggerForUser(Thread * pThread, EXCEPTION_POINTERS * p
64856485
DebugBreak();
64866486
}
64876487

6488-
if (!IsDebuggerPresent())
6488+
if (!minipal_is_native_debugger_present())
64896489
{
64906490
LOG((LF_CORDB, LL_ERROR, "D::LDFU: Failed to launch the debugger.\n"));
64916491
}
@@ -7106,7 +7106,7 @@ void Debugger::JitAttach(Thread * pThread, EXCEPTION_POINTERS * pExceptionInfo,
71067106
CONTRACTL_END;
71077107

71087108
// Don't do anything if there is a native debugger already attached or the debugging support has been disabled.
7109-
if (IsDebuggerPresent() || m_pRCThread == NULL)
7109+
if (minipal_is_native_debugger_present() || m_pRCThread == NULL)
71107110
return;
71117111

71127112
GCX_PREEMP_EEINTERFACE_TOGGLE_IFTHREAD();
@@ -7181,7 +7181,7 @@ void Debugger::EnsureDebuggerAttached(Thread * pThread, EXCEPTION_POINTERS * pEx
71817181
{
71827182
// if the debugger is already attached then we can't launch one
71837183
// and whatever attach state we are in is just what we get
7184-
if(IsDebuggerPresent())
7184+
if(minipal_is_native_debugger_present())
71857185
{
71867186
// unblock other threads waiting on our attach and clean up
71877187
PostJitAttach();
@@ -8919,7 +8919,7 @@ void Debugger::SendUserBreakpoint(Thread * thread)
89198919
// On jit-attach, we just send the UserBreak event. Don't do an extra step-out.
89208920
SendUserBreakpointAndSynchronize(thread);
89218921
}
8922-
else if (IsDebuggerPresent())
8922+
else if (minipal_is_native_debugger_present())
89238923
{
89248924
DebugBreak();
89258925
}
@@ -16796,4 +16796,3 @@ void Debugger::MulticastTraceNextStep(DELEGATEREF pbDel, INT32 count)
1679616796
#endif //DACCESS_COMPILE
1679716797

1679816798
#endif //DEBUGGING_SUPPORTED
16799-

src/coreclr/debug/ee/debuggermessagebox.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static void DbgPrintf(const LPCSTR szFormat, ...)
2323

2424
va_end(args);
2525

26-
if (IsDebuggerPresent())
26+
if (minipal_is_native_debugger_present())
2727
{
2828
OutputDebugStringUtf8(szBuffer);
2929
}

src/coreclr/dlls/mscordac/mscordac_unixexports.src

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ nativeStringResourceTable_mscorrc
3636
#PAL_GetTransportPipeName
3737
#PAL_InitializeDLL
3838
#PAL_TerminateEx
39-
#PAL_IsDebuggerPresent
4039
#PAL_OpenProcessMemory
4140
#PAL_CloseProcessMemory
4241
#PAL_ReadProcessMemory

src/coreclr/hosts/corerun/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ set(CLR_CMAKE_KEEP_NATIVE_SYMBOLS TRUE)
1414
add_executable_clr(corerun
1515
corerun.cpp
1616
dotenv.cpp
17+
${CLR_SRC_NATIVE_DIR}/minipal/debugger.c
1718
native.rc
1819
)
1920

src/coreclr/hosts/corerun/corerun.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ namespace pal
4949
#ifdef TARGET_WINDOWS
5050
#define CDECL __cdecl
5151
#include <Windows.h>
52+
#include <minipal/debugger.h>
5253

5354
#define DLL_EXPORT __declspec(dllexport)
5455
#define MAIN __cdecl wmain
@@ -138,7 +139,7 @@ namespace pal
138139

139140
inline debugger_state_t is_debugger_attached()
140141
{
141-
return (::IsDebuggerPresent() == TRUE) ? debugger_state_t::attached : debugger_state_t::not_attached;
142+
return (minipal_is_native_debugger_present() == TRUE) ? debugger_state_t::attached : debugger_state_t::not_attached;
142143
}
143144

144145
inline bool does_file_exist(const string_t& file_path)

src/coreclr/jit/error.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <corjit.h> // for CORJIT_INTERNALERROR
1010
#include <safemath.h> // For FitsIn, used by SafeCvt methods.
1111

12+
#include <minipal/debugger.h>
13+
1214
#define FATAL_JIT_EXCEPTION 0x02345678
1315
class Compiler;
1416

@@ -247,7 +249,7 @@ extern void notYetImplemented(const char* msg, const char* file, unsigned line);
247249
#define BreakIfDebuggerPresent() \
248250
do \
249251
{ \
250-
if (IsDebuggerPresent()) \
252+
if (minipal_is_native_debugger_present()) \
251253
DebugBreak(); \
252254
} while (0)
253255
#endif

src/coreclr/minipal/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ if (CLR_CMAKE_HOST_UNIX)
55
else (CLR_CMAKE_HOST_UNIX)
66
add_subdirectory(Windows)
77
endif (CLR_CMAKE_HOST_UNIX)
8-

src/coreclr/minipal/Unix/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
set(SOURCES
22
doublemapping.cpp
33
dn-u16.cpp
4+
${CLR_SRC_NATIVE_DIR}/minipal/debugger.c
45
${CLR_SRC_NATIVE_DIR}/minipal/time.c
56
)
67

src/coreclr/minipal/Windows/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
set(SOURCES
22
doublemapping.cpp
33
dn-u16.cpp
4+
${CLR_SRC_NATIVE_DIR}/minipal/debugger.c
45
${CLR_SRC_NATIVE_DIR}/minipal/utf8.c
56
${CLR_SRC_NATIVE_DIR}/minipal/time.c
67
)

0 commit comments

Comments
 (0)