// 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
{
}
private static bool AppendStackFrameWithoutMethodBase(StringBuilder sb) => false;
+
+ [DllImport(RuntimeHelpers.QCall, EntryPoint = "StackFrame_GetMethodDescFromNativeIP")]
+ private static extern RuntimeMethodHandleInternal GetMethodDescFromNativeIP(IntPtr ip);
+
+ /// <summary>
+ /// Returns the MethodBase instance for the managed code IP address.
+ ///
+ /// Warning: The implementation of this method has race for dynamic and collectible methods.
+ /// </summary>
+ /// <param name="ip">code address</param>
+ /// <returns>MethodBase instance for the method or null if IP not found</returns>
+ internal static MethodBase? GetMethodFromNativeIP(IntPtr ip)
+ {
+ RuntimeMethodHandleInternal method = GetMethodDescFromNativeIP(ip);
+
+ if (method.Value == IntPtr.Zero)
+ return null;
+
+ return RuntimeType.GetMethodBase(null, method);
+ }
}
}
}
FCIMPLEND
-
FCIMPL4(void, DebugStackTrace::GetStackFramesInternal,
StackFrameHelper* pStackFrameHelperUNSAFE,
INT32 iSkip,
}
FCIMPLEND
+extern MethodDesc* QCALLTYPE StackFrame_GetMethodDescFromNativeIP(LPVOID ip)
+{
+ QCALL_CONTRACT;
+
+ MethodDesc* pResult = nullptr;
+
+ BEGIN_QCALL;
+
+ // TODO: There is a race for dynamic and collectible methods here between getting
+ // the MethodDesc here and when the managed wrapper converts it into a MethodBase
+ // where the method could be collected.
+ EECodeInfo codeInfo((PCODE)ip);
+ if (codeInfo.IsValid())
+ {
+ pResult = codeInfo.GetMethodDesc();
+ }
+
+ END_QCALL;
+
+ return pResult;
+}
+
FORCEINLINE void HolderDestroyStrongHandle(OBJECTHANDLE h) { if (h != NULL) DestroyStrongHandle(h); }
typedef Wrapper<OBJECTHANDLE, DoNothing<OBJECTHANDLE>, HolderDestroyStrongHandle, NULL> StrongHandleHolder;
};
+extern "C" MethodDesc* QCALLTYPE StackFrame_GetMethodDescFromNativeIP(LPVOID ip);
+
#endif // __DEBUG_DEBUGGER_h__
DllImportEntry(RuntimeModule_GetType)
DllImportEntry(RuntimeModule_GetScopeName)
DllImportEntry(RuntimeModule_GetFullyQualifiedName)
+ DllImportEntry(StackFrame_GetMethodDescFromNativeIP)
DllImportEntry(ModuleBuilder_GetStringConstant)
DllImportEntry(ModuleBuilder_GetTypeRef)
DllImportEntry(ModuleBuilder_GetTokenFromTypeSpec)
<!-- Internal API used by tests only. -->
<method name="GetICUVersion" />
</type>
+ <type fullname="System.Diagnostics.StackFrame">
+ <!-- Used by VS4Mac via reflection to symbolize stack traces -->
+ <method name="GetMethodFromNativeIP" />
+ </type>
</assembly>
</linker>