Skip to content

Commit 41174d8

Browse files
committed
Move IsDebuggerPresent to minipal, convert to QCall
1 parent 4e2fe8d commit 41174d8

File tree

43 files changed

+2945
-450
lines changed

Some content is hidden

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

43 files changed

+2945
-450
lines changed

s

Lines changed: 2629 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,18 @@ 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();
63+
64+
// Checks to see if an attached debugger has logging enabled
65+
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "DebugDebugger_IsManagedDebuggerAttached")]
66+
[return: MarshalAs(UnmanagedType.Bool)]
67+
private static partial bool IsManagedDebuggerAttached();
68+
69+
// Checks to see if an attached debugger has logging enabled
70+
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "DebugDebugger_IsAnyDebuggerAttached")]
71+
[return: MarshalAs(UnmanagedType.Bool)]
72+
internal static partial bool IsAnyDebuggerAttached();
6873

6974
// Constants representing the importance level of messages to be logged.
7075
//
@@ -84,10 +89,12 @@ public static extern bool IsAttached
8489
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "DebugDebugger_Log", StringMarshalling = StringMarshalling.Utf16)]
8590
private static partial void LogInternal(int level, string? category, string? message);
8691

92+
public static bool IsLogging() => IsLoggingHelper();
93+
8794
// Checks to see if an attached debugger has logging enabled
88-
//
89-
[MethodImpl(MethodImplOptions.InternalCall)]
90-
public static extern bool IsLogging();
95+
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "DebugDebugger_IsLoggingHelper")]
96+
[return: MarshalAs(UnmanagedType.Bool)]
97+
private static partial bool IsLoggingHelper();
9198

9299
// Posts a custom notification for the attached debugger. If there is no
93100
// 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
}
@@ -6460,7 +6460,7 @@ HRESULT Debugger::LaunchDebuggerForUser(Thread * pThread, EXCEPTION_POINTERS * p
64606460
//
64616461
SendUserBreakpointAndSynchronize(g_pEEInterface->GetThread());
64626462
}
6463-
else if (!CORDebuggerAttached() && IsDebuggerPresent())
6463+
else if (!CORDebuggerAttached() && minipal_is_native_debugger_present())
64646464
{
64656465
//
64666466
// If the registered debugger is not a managed debugger, send a native breakpoint
@@ -6476,7 +6476,7 @@ HRESULT Debugger::LaunchDebuggerForUser(Thread * pThread, EXCEPTION_POINTERS * p
64766476
DebugBreak();
64776477
}
64786478

6479-
if (!IsDebuggerPresent())
6479+
if (!minipal_is_native_debugger_present())
64806480
{
64816481
LOG((LF_CORDB, LL_ERROR, "D::LDFU: Failed to launch the debugger.\n"));
64826482
}
@@ -7097,7 +7097,7 @@ void Debugger::JitAttach(Thread * pThread, EXCEPTION_POINTERS * pExceptionInfo,
70977097
CONTRACTL_END;
70987098

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

71037103
GCX_PREEMP_EEINTERFACE_TOGGLE_IFTHREAD();
@@ -7172,7 +7172,7 @@ void Debugger::EnsureDebuggerAttached(Thread * pThread, EXCEPTION_POINTERS * pEx
71727172
{
71737173
// if the debugger is already attached then we can't launch one
71747174
// and whatever attach state we are in is just what we get
7175-
if(IsDebuggerPresent())
7175+
if(minipal_is_native_debugger_present())
71767176
{
71777177
// unblock other threads waiting on our attach and clean up
71787178
PostJitAttach();
@@ -8910,7 +8910,7 @@ void Debugger::SendUserBreakpoint(Thread * thread)
89108910
// On jit-attach, we just send the UserBreak event. Don't do an extra step-out.
89118911
SendUserBreakpointAndSynchronize(thread);
89128912
}
8913-
else if (IsDebuggerPresent())
8913+
else if (minipal_is_native_debugger_present())
89148914
{
89158915
DebugBreak();
89168916
}
@@ -16784,4 +16784,3 @@ void Debugger::MulticastTraceNextStep(DELEGATEREF pbDel, INT32 count)
1678416784
#endif //DACCESS_COMPILE
1678516785

1678616786
#endif //DEBUGGING_SUPPORTED
16787-

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/corerun.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ namespace pal
138138

139139
inline debugger_state_t is_debugger_attached()
140140
{
141-
return (::IsDebuggerPresent() == TRUE) ? debugger_state_t::attached : debugger_state_t::not_attached;
141+
return (minipal_is_native_debugger_present() == TRUE) ? debugger_state_t::attached : debugger_state_t::not_attached;
142142
}
143143

144144
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/is_native_debugger_present.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/nativeaot/Runtime/MiscHelpers.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "yieldprocessornormalized.h"
3737
#include "RhConfig.h"
3838
#include <minipal/cpuid.h>
39+
#include <minipal/is_native_debugger_present.h>
3940

4041
FCIMPL0(void, RhDebugBreak)
4142
{
@@ -394,6 +395,11 @@ EXTERN_C int32_t QCALLTYPE RhpGetCurrentThreadStackTrace(void* pOutputBuffer, ui
394395
return RhpCalculateStackTraceWorker(pOutputBuffer, outputBufferLength, pAddressInCurrentFrame);
395396
}
396397

398+
EXTERN_C UInt32_BOOL QCALLTYPE DebugDebugger_IsAnyDebuggerAttached()
399+
{
400+
return minipal_is_native_debugger_present();
401+
}
402+
397403
FCIMPL2(FC_BOOL_RET, RhCompareObjectContentsAndPadding, Object* pObj1, Object* pObj2)
398404
{
399405
ASSERT(pObj1->GetMethodTable() == pObj2->GetMethodTable());

src/coreclr/nativeaot/Runtime/PalRedhawkFunctions.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,6 @@ inline UInt32_BOOL PalInitializeCriticalSectionEx(CRITICAL_SECTION * arg1, uint3
7777
return InitializeCriticalSectionEx(arg1, arg2, arg3);
7878
}
7979

80-
extern "C" UInt32_BOOL __stdcall IsDebuggerPresent();
81-
inline UInt32_BOOL PalIsDebuggerPresent()
82-
{
83-
return IsDebuggerPresent();
84-
}
85-
8680
extern "C" void __stdcall LeaveCriticalSection(CRITICAL_SECTION *);
8781
inline void PalLeaveCriticalSection(CRITICAL_SECTION * arg1)
8882
{

src/coreclr/nativeaot/Runtime/rhassert.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "PalRedhawk.h"
88
#include "rhassert.h"
99

10+
#include <minipal/is_native_debugger_present.h>
11+
1012
#ifdef _DEBUG
1113

1214
void Assert(const char * expr, const char * file, uint32_t line_num, const char * message)
@@ -28,7 +30,7 @@ void Assert(const char * expr, const char * file, uint32_t line_num, const char
2830
fflush(stdout);
2931

3032
// If there's no debugger attached, we just FailFast
31-
if (!PalIsDebuggerPresent())
33+
if (!minipal_is_native_debugger_present())
3234
PalRaiseFailFastException(NULL, NULL, FAIL_FAST_GENERATE_EXCEPTION_ADDRESS);
3335

3436
// If there is a debugger attached, we break and then allow continuation.

0 commit comments

Comments
 (0)