Skip to content

Commit 2e7ee69

Browse files
Remove Helper Method Frames from debugdebugger (#107058)
* Remove unused AllocObjectWrapper helper for x86. * Convert Debugger.Break() * Convert Debugger.CustomNotification() * Convert StackTrace.GetStackFramesInternal()
1 parent 4f01cb7 commit 2e7ee69

16 files changed

+250
-412
lines changed

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ namespace System.Diagnostics
1111
{
1212
public static partial class Debugger
1313
{
14+
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "DebugDebugger_Break")]
15+
private static partial void BreakInternal();
16+
1417
// Break causes a breakpoint to be signalled to an attached debugger. If no debugger
1518
// is attached, the user is asked if they want to attach a debugger. If yes, then the
1619
// debugger is launched.
1720
[MethodImpl(MethodImplOptions.NoInlining)]
1821
public static void Break() => BreakInternal();
1922

20-
[MethodImpl(MethodImplOptions.InternalCall)]
21-
private static extern void BreakInternal();
22-
2323
// Launch launches & attaches a debugger to the process. If a debugger is already attached,
2424
// nothing happens.
2525
//
@@ -30,11 +30,6 @@ public static partial class Debugger
3030
// See code:NotifyOfCrossThreadDependency for more details.
3131
private sealed class CrossThreadDependencyNotification : ICustomDebuggerNotification { }
3232

33-
// Do not inline the slow path
34-
[MethodImpl(MethodImplOptions.NoInlining)]
35-
private static void NotifyOfCrossThreadDependencySlow() =>
36-
CustomNotification(new CrossThreadDependencyNotification());
37-
3833
// Sends a notification to the debugger to indicate that execution is about to enter a path
3934
// involving a cross thread dependency. A debugger that has opted into this type of notification
4035
// can take appropriate action on receipt. For example, performing a funceval normally requires
@@ -49,6 +44,14 @@ public static void NotifyOfCrossThreadDependency()
4944
{
5045
NotifyOfCrossThreadDependencySlow();
5146
}
47+
48+
// Do not inline the slow path
49+
[MethodImpl(MethodImplOptions.NoInlining)]
50+
static void NotifyOfCrossThreadDependencySlow()
51+
{
52+
var notify = new CrossThreadDependencyNotification();
53+
CustomNotification(ObjectHandleOnStack.Create(ref notify));
54+
}
5255
}
5356

5457
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "DebugDebugger_Launch")]
@@ -89,7 +92,7 @@ public static extern bool IsAttached
8992
// Posts a custom notification for the attached debugger. If there is no
9093
// debugger attached, has no effect. The debugger may or may not
9194
// report the notification depending on its settings.
92-
[MethodImpl(MethodImplOptions.InternalCall)]
93-
private static extern void CustomNotification(ICustomDebuggerNotification data);
95+
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "DebugDebugger_CustomNotification")]
96+
private static partial void CustomNotification(ObjectHandleOnStack data);
9497
}
9598
}

src/coreclr/System.Private.CoreLib/src/System/Diagnostics/StackFrame.CoreCLR.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ internal StackFrame(StackFrameHelper stackFrameHelper, int skipFrames, bool need
3030

3131
private void BuildStackFrame(int skipFrames, bool needFileInfo)
3232
{
33-
StackFrameHelper StackF = new StackFrameHelper(null);
33+
StackFrameHelper StackF = new StackFrameHelper();
3434

35-
StackF.InitializeSourceInfo(0, needFileInfo, null);
35+
StackF.InitializeSourceInfo(needFileInfo, null);
3636

3737
int iNumOfFrames = StackF.GetNumberOfFrames();
3838

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace System.Diagnostics
1313
// VM\DebugDebugger.h. The binder will catch some of these layout problems.
1414
internal sealed class StackFrameHelper
1515
{
16-
private Thread? targetThread;
1716
private int[]? rgiOffset;
1817
private int[]? rgiILOffset;
1918

@@ -48,9 +47,8 @@ private delegate void GetSourceLineInfoDelegate(Assembly? assembly, string assem
4847
[ThreadStatic]
4948
private static int t_reentrancy;
5049

51-
public StackFrameHelper(Thread? target)
50+
public StackFrameHelper()
5251
{
53-
targetThread = target;
5452
rgMethodHandle = null;
5553
rgiMethodToken = null;
5654
rgiOffset = null;
@@ -85,9 +83,9 @@ public StackFrameHelper(Thread? target)
8583
// done by GetStackFramesInternal (on Windows for old PDB format).
8684
//
8785

88-
internal void InitializeSourceInfo(int iSkip, bool fNeedFileInfo, Exception? exception)
86+
internal void InitializeSourceInfo(bool fNeedFileInfo, Exception? exception)
8987
{
90-
StackTrace.GetStackFramesInternal(this, iSkip, fNeedFileInfo, exception);
88+
StackTrace.GetStackFramesInternal(this, fNeedFileInfo, exception);
9189

9290
if (!fNeedFileInfo)
9391
return;

src/coreclr/System.Private.CoreLib/src/System/Diagnostics/StackTrace.CoreCLR.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33

44
using System.Reflection;
55
using System.Runtime.CompilerServices;
6+
using System.Runtime.InteropServices;
67

78
namespace System.Diagnostics
89
{
910
public partial class StackTrace
1011
{
11-
[MethodImpl(MethodImplOptions.InternalCall)]
12-
internal static extern void GetStackFramesInternal(StackFrameHelper sfh, int iSkip, bool fNeedFileInfo, Exception? e);
12+
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "StackTrace_GetStackFramesInternal")]
13+
private static partial void GetStackFramesInternal(ObjectHandleOnStack sfh, [MarshalAs(UnmanagedType.Bool)] bool fNeedFileInfo, ObjectHandleOnStack e);
14+
15+
internal static void GetStackFramesInternal(StackFrameHelper sfh, bool fNeedFileInfo, Exception? e)
16+
=> GetStackFramesInternal(ObjectHandleOnStack.Create(ref sfh), fNeedFileInfo, ObjectHandleOnStack.Create(ref e));
1317

1418
internal static int CalculateFramesToSkip(StackFrameHelper StackF, int iNumFrames)
1519
{
@@ -57,9 +61,9 @@ private void CaptureStackTrace(int skipFrames, bool fNeedFileInfo, Exception? e)
5761
{
5862
_methodsToSkip = skipFrames;
5963

60-
StackFrameHelper StackF = new StackFrameHelper(null);
64+
StackFrameHelper StackF = new StackFrameHelper();
6165

62-
StackF.InitializeSourceInfo(0, fNeedFileInfo, e);
66+
StackF.InitializeSourceInfo(fNeedFileInfo, e);
6367

6468
_numOfFrames = StackF.GetNumberOfFrames();
6569

src/coreclr/debug/daccess/dacdbiimpl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3707,7 +3707,6 @@ void DacDbiInterfaceImpl::GetStackFramesFromException(VMPTR_Object vmObject, Dac
37073707
DebugStackTrace::GetStackFramesData stackFramesData;
37083708

37093709
stackFramesData.pDomain = NULL;
3710-
stackFramesData.skip = 0;
37113710
stackFramesData.NumFramesRequested = 0;
37123711

37133712
DebugStackTrace::GetStackFramesFromException(&objRef, &stackFramesData);
@@ -3720,7 +3719,7 @@ void DacDbiInterfaceImpl::GetStackFramesFromException(VMPTR_Object vmObject, Dac
37203719

37213720
for (INT32 index = 0; index < dacStackFramesLength; ++index)
37223721
{
3723-
DebugStackTrace::DebugStackTraceElement const& currentElement = stackFramesData.pElements[index];
3722+
DebugStackTrace::Element const& currentElement = stackFramesData.pElements[index];
37243723
DacExceptionCallStackData& currentFrame = dacStackFrames[index];
37253724

37263725
AppDomain* pDomain = AppDomain::GetCurrentDomain();

src/coreclr/debug/ee/debugger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8849,7 +8849,7 @@ void Debugger::SendUserBreakpoint(Thread * thread)
88498849
{
88508850
THROWS;
88518851
GC_TRIGGERS;
8852-
MODE_ANY;
8852+
MODE_PREEMPTIVE;
88538853

88548854
PRECONDITION(thread != NULL);
88558855
PRECONDITION(thread == ::GetThreadNULLOk());

src/coreclr/dlls/mscorrc/mscorrc.rc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ BEGIN
468468
IDS_EE_INVALID_CA "Invalid custom attribute provided."
469469

470470
IDS_EE_THREAD_CANNOT_GET "Unable to retrieve thread information."
471-
IDS_EE_THREAD_BAD_STATE "Thread in invalid state."
472471
IDS_EE_THREAD_ABORT_WHILE_SUSPEND "Thread is suspended; attempting to abort."
473472
IDS_EE_NOVARIANTRETURN "PInvoke restriction: cannot return variants."
474473

src/coreclr/dlls/mscorrc/resource.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@
233233
#define IDS_EE_INVALID_CA 0x1a10
234234

235235
#define IDS_EE_THREAD_CANNOT_GET 0x1a15
236-
#define IDS_EE_THREAD_BAD_STATE 0x1a1b
237236
#define IDS_EE_THREAD_ABORT_WHILE_SUSPEND 0x1a1c
238237

239238
#define IDS_EE_NOVARIANTRETURN 0x1a1d

src/coreclr/vm/corelib.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,6 @@ DEFINE_METHOD(SAFE_HANDLE, DISPOSE_BOOL, Dispose,
757757
DEFINE_CLASS(SECURITY_EXCEPTION, Security, SecurityException)
758758

759759
DEFINE_CLASS_U(Diagnostics, StackFrameHelper, StackFrameHelper)
760-
DEFINE_FIELD_U(targetThread, StackFrameHelper, targetThread)
761760
DEFINE_FIELD_U(rgiOffset, StackFrameHelper, rgiOffset)
762761
DEFINE_FIELD_U(rgiILOffset, StackFrameHelper, rgiILOffset)
763762
DEFINE_FIELD_U(dynamicMethods, StackFrameHelper, dynamicMethods)

0 commit comments

Comments
 (0)