Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add System.Diagnostics.StackFrame.GetMethodFromNativeIP API for VS4Mac #61289

Merged
merged 6 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.

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

namespace System.Diagnostics
{
Expand Down Expand Up @@ -50,5 +53,23 @@ private void BuildStackFrame(int skipFrames, bool needFileInfo)
}

private static bool AppendStackFrameWithoutMethodBase(StringBuilder sb) => false;

[DllImport(RuntimeHelpers.QCall, EntryPoint = "StackFrame_GetMethodDescFromNativeIP")]
private static extern RuntimeMethodHandleInternal GetMethodDescFromNativeIP(IntPtr ip);

/// <summary>
/// Returns the method info instance for the managed code IP address.
mikem8361 marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
/// <param name="ip">code address</param>
/// <returns>MethodInfo instance or null if IP not found</returns>
internal static MethodInfo? GetMethodInfoFromNativeIP(IntPtr ip)
{
RuntimeMethodHandleInternal method = GetMethodDescFromNativeIP(ip);

if (method.Value == IntPtr.Zero)
return null;

return RuntimeType.GetMethodBase(null, method) as MethodInfo;
mikem8361 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
20 changes: 19 additions & 1 deletion src/coreclr/vm/debugdebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ FCIMPL0(FC_BOOL_RET, DebugDebugger::IsLogging)
}
FCIMPLEND


FCIMPL4(void, DebugStackTrace::GetStackFramesInternal,
StackFrameHelper* pStackFrameHelperUNSAFE,
INT32 iSkip,
Expand Down Expand Up @@ -778,6 +777,25 @@ FCIMPL4(void, DebugStackTrace::GetStackFramesInternal,
}
FCIMPLEND

extern MethodDesc* QCALLTYPE StackFrame_GetMethodDescFromNativeIP(LPVOID ip)
{
QCALL_CONTRACT;

MethodDesc* pResult = nullptr;

BEGIN_QCALL;

EECodeInfo codeInfo((PCODE)ip);
if (codeInfo.IsValid())
{
pResult = codeInfo.GetMethodDesc();
mikem8361 marked this conversation as resolved.
Show resolved Hide resolved
}

END_QCALL;

return pResult;
}

FORCEINLINE void HolderDestroyStrongHandle(OBJECTHANDLE h) { if (h != NULL) DestroyStrongHandle(h); }
typedef Wrapper<OBJECTHANDLE, DoNothing<OBJECTHANDLE>, HolderDestroyStrongHandle, NULL> StrongHandleHolder;

Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/vm/debugdebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,6 @@ class DebugStackTrace

};

extern "C" MethodDesc* QCALLTYPE StackFrame_GetMethodDescFromNativeIP(LPVOID ip);

#endif // __DEBUG_DEBUGGER_h__
1 change: 1 addition & 0 deletions src/coreclr/vm/qcallentrypoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ static const Entry s_QCall[] =
DllImportEntry(RuntimeModule_GetType)
DllImportEntry(RuntimeModule_GetScopeName)
DllImportEntry(RuntimeModule_GetFullyQualifiedName)
DllImportEntry(StackFrame_GetMethodDescFromNativeIP)
DllImportEntry(ModuleBuilder_GetStringConstant)
DllImportEntry(ModuleBuilder_GetTypeRef)
DllImportEntry(ModuleBuilder_GetTokenFromTypeSpec)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
<type fullname="System.Runtime.CompilerServices.AsyncValueTaskMethodBuilder`1">
<property name="ObjectIdForDebugger" />
</type>
<type fullname="System.Diagnostics.StackFrame">
<method name="GetMethodInfoFromNativeIP" />
</type>
<type fullname="System.Threading.Tasks.Task">
<!-- Methods is used by VS Tasks Window. -->
<method name="GetActiveTaskFromId" />
Expand Down