Skip to content

Commit

Permalink
Remove Helper Method Frames from debugdebugger (#107058)
Browse files Browse the repository at this point in the history
* Remove unused AllocObjectWrapper helper for x86.

* Convert Debugger.Break()

* Convert Debugger.CustomNotification()

* Convert StackTrace.GetStackFramesInternal()
  • Loading branch information
AaronRobinsonMSFT authored Aug 29, 2024
1 parent 4f01cb7 commit 2e7ee69
Show file tree
Hide file tree
Showing 16 changed files with 250 additions and 412 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ namespace System.Diagnostics
{
public static partial class Debugger
{
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "DebugDebugger_Break")]
private static partial void BreakInternal();

// Break causes a breakpoint to be signalled to an attached debugger. If no debugger
// is attached, the user is asked if they want to attach a debugger. If yes, then the
// debugger is launched.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void Break() => BreakInternal();

[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void BreakInternal();

// Launch launches & attaches a debugger to the process. If a debugger is already attached,
// nothing happens.
//
Expand All @@ -30,11 +30,6 @@ public static partial class Debugger
// See code:NotifyOfCrossThreadDependency for more details.
private sealed class CrossThreadDependencyNotification : ICustomDebuggerNotification { }

// Do not inline the slow path
[MethodImpl(MethodImplOptions.NoInlining)]
private static void NotifyOfCrossThreadDependencySlow() =>
CustomNotification(new CrossThreadDependencyNotification());

// Sends a notification to the debugger to indicate that execution is about to enter a path
// involving a cross thread dependency. A debugger that has opted into this type of notification
// can take appropriate action on receipt. For example, performing a funceval normally requires
Expand All @@ -49,6 +44,14 @@ public static void NotifyOfCrossThreadDependency()
{
NotifyOfCrossThreadDependencySlow();
}

// Do not inline the slow path
[MethodImpl(MethodImplOptions.NoInlining)]
static void NotifyOfCrossThreadDependencySlow()
{
var notify = new CrossThreadDependencyNotification();
CustomNotification(ObjectHandleOnStack.Create(ref notify));
}
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "DebugDebugger_Launch")]
Expand Down Expand Up @@ -89,7 +92,7 @@ public static extern bool IsAttached
// Posts a custom notification for the attached debugger. If there is no
// debugger attached, has no effect. The debugger may or may not
// report the notification depending on its settings.
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void CustomNotification(ICustomDebuggerNotification data);
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "DebugDebugger_CustomNotification")]
private static partial void CustomNotification(ObjectHandleOnStack data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ internal StackFrame(StackFrameHelper stackFrameHelper, int skipFrames, bool need

private void BuildStackFrame(int skipFrames, bool needFileInfo)
{
StackFrameHelper StackF = new StackFrameHelper(null);
StackFrameHelper StackF = new StackFrameHelper();

StackF.InitializeSourceInfo(0, needFileInfo, null);
StackF.InitializeSourceInfo(needFileInfo, null);

int iNumOfFrames = StackF.GetNumberOfFrames();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace System.Diagnostics
// VM\DebugDebugger.h. The binder will catch some of these layout problems.
internal sealed class StackFrameHelper
{
private Thread? targetThread;
private int[]? rgiOffset;
private int[]? rgiILOffset;

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

public StackFrameHelper(Thread? target)
public StackFrameHelper()
{
targetThread = target;
rgMethodHandle = null;
rgiMethodToken = null;
rgiOffset = null;
Expand Down Expand Up @@ -85,9 +83,9 @@ public StackFrameHelper(Thread? target)
// done by GetStackFramesInternal (on Windows for old PDB format).
//

internal void InitializeSourceInfo(int iSkip, bool fNeedFileInfo, Exception? exception)
internal void InitializeSourceInfo(bool fNeedFileInfo, Exception? exception)
{
StackTrace.GetStackFramesInternal(this, iSkip, fNeedFileInfo, exception);
StackTrace.GetStackFramesInternal(this, fNeedFileInfo, exception);

if (!fNeedFileInfo)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace System.Diagnostics
{
public partial class StackTrace
{
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void GetStackFramesInternal(StackFrameHelper sfh, int iSkip, bool fNeedFileInfo, Exception? e);
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "StackTrace_GetStackFramesInternal")]
private static partial void GetStackFramesInternal(ObjectHandleOnStack sfh, [MarshalAs(UnmanagedType.Bool)] bool fNeedFileInfo, ObjectHandleOnStack e);

internal static void GetStackFramesInternal(StackFrameHelper sfh, bool fNeedFileInfo, Exception? e)
=> GetStackFramesInternal(ObjectHandleOnStack.Create(ref sfh), fNeedFileInfo, ObjectHandleOnStack.Create(ref e));

internal static int CalculateFramesToSkip(StackFrameHelper StackF, int iNumFrames)
{
Expand Down Expand Up @@ -57,9 +61,9 @@ private void CaptureStackTrace(int skipFrames, bool fNeedFileInfo, Exception? e)
{
_methodsToSkip = skipFrames;

StackFrameHelper StackF = new StackFrameHelper(null);
StackFrameHelper StackF = new StackFrameHelper();

StackF.InitializeSourceInfo(0, fNeedFileInfo, e);
StackF.InitializeSourceInfo(fNeedFileInfo, e);

_numOfFrames = StackF.GetNumberOfFrames();

Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/debug/daccess/dacdbiimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3707,7 +3707,6 @@ void DacDbiInterfaceImpl::GetStackFramesFromException(VMPTR_Object vmObject, Dac
DebugStackTrace::GetStackFramesData stackFramesData;

stackFramesData.pDomain = NULL;
stackFramesData.skip = 0;
stackFramesData.NumFramesRequested = 0;

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

for (INT32 index = 0; index < dacStackFramesLength; ++index)
{
DebugStackTrace::DebugStackTraceElement const& currentElement = stackFramesData.pElements[index];
DebugStackTrace::Element const& currentElement = stackFramesData.pElements[index];
DacExceptionCallStackData& currentFrame = dacStackFrames[index];

AppDomain* pDomain = AppDomain::GetCurrentDomain();
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/debug/ee/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8849,7 +8849,7 @@ void Debugger::SendUserBreakpoint(Thread * thread)
{
THROWS;
GC_TRIGGERS;
MODE_ANY;
MODE_PREEMPTIVE;

PRECONDITION(thread != NULL);
PRECONDITION(thread == ::GetThreadNULLOk());
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/dlls/mscorrc/mscorrc.rc
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@ BEGIN
IDS_EE_INVALID_CA "Invalid custom attribute provided."

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

Expand Down
1 change: 0 additions & 1 deletion src/coreclr/dlls/mscorrc/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@
#define IDS_EE_INVALID_CA 0x1a10

#define IDS_EE_THREAD_CANNOT_GET 0x1a15
#define IDS_EE_THREAD_BAD_STATE 0x1a1b
#define IDS_EE_THREAD_ABORT_WHILE_SUSPEND 0x1a1c

#define IDS_EE_NOVARIANTRETURN 0x1a1d
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/vm/corelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,6 @@ DEFINE_METHOD(SAFE_HANDLE, DISPOSE_BOOL, Dispose,
DEFINE_CLASS(SECURITY_EXCEPTION, Security, SecurityException)

DEFINE_CLASS_U(Diagnostics, StackFrameHelper, StackFrameHelper)
DEFINE_FIELD_U(targetThread, StackFrameHelper, targetThread)
DEFINE_FIELD_U(rgiOffset, StackFrameHelper, rgiOffset)
DEFINE_FIELD_U(rgiILOffset, StackFrameHelper, rgiILOffset)
DEFINE_FIELD_U(dynamicMethods, StackFrameHelper, dynamicMethods)
Expand Down
Loading

0 comments on commit 2e7ee69

Please sign in to comment.