Add _EFN_GetManagedThread for !analyze
authorMike McLaughlin <mikem@microsoft.com>
Wed, 26 Jun 2019 00:23:51 +0000 (17:23 -0700)
committerMike McLaughlin <mikem@microsoft.com>
Wed, 26 Jun 2019 18:21:54 +0000 (11:21 -0700)
Instead of reading "gCurrentThreadInfo.m_pThread" in the runtime.

eng/Versions.props
src/SOS/Strike/sos.def
src/SOS/Strike/sos_stacktrace.h
src/SOS/Strike/strike.cpp

index 29e40edb5030086218a0e416c81bea7795af00e2..48b13959c2d9e68a12837106b979644626a1ae84 100644 (file)
@@ -3,7 +3,7 @@
   <PropertyGroup>
     <RepositoryUrl>https://github.com/dotnet/diagnostics</RepositoryUrl>
     <PreReleaseVersionLabel>preview6</PreReleaseVersionLabel>
-    <VersionPrefix>1.0.4</VersionPrefix>
+    <VersionPrefix>1.0.5</VersionPrefix>
     <DotNetUseShippingVersions>true</DotNetUseShippingVersions>
   </PropertyGroup>
 
index cebf92cc0ef220823a62f9fe9228f2460796a466..bb1a2c51f341f22bc243420e50cddceeefd4e682 100644 (file)
@@ -191,6 +191,8 @@ EXPORTS
     _EFN_GetManagedObjectFieldInfo    
     _EFN_GetManagedObjectName
     _EFN_StackTrace
+    _EFN_GetManagedThread
+    VerifyGMT
     bpmd
     BPMD=bpmd
     DebugExtensionInitialize
index 0af241ca3bc0716abc9d3cb7cad6814d21b395a5..a9a54cf205bb4276624c94ad70c1e5a56f66bab5 100644 (file)
@@ -166,6 +166,16 @@ HRESULT CALLBACK _EFN_GetManagedObjectFieldInfo(
     PULONG pOffset
     );
 
+// _EFN_GetManagedThread - return the managed thread object for the os thread id
+//
+// osThreadId - os thread id
+// pManagedObject - managed thread object returned
+HRESULT CALLBACK _EFN_GetManagedThread(
+    PDEBUG_CLIENT client,
+    ULONG osThreadId,
+    PULONG64 pManagedObject
+);
+
 #ifdef __cplusplus
 }
 #endif // __cplusplus : extern "C"
index fa7212bd770b06629d7ef429e781cac47d458f76..92b48188c98704e5f17e38251e0f3491a61e3601 100644 (file)
@@ -15362,6 +15362,74 @@ _EFN_GetManagedObjectFieldInfo(
     return S_OK;
 }
 
+DECLARE_API(VerifyGMT)
+{
+    ULONG osThreadId;
+    {
+        INIT_API();
+
+        CMDValue arg[] =
+        {   // vptr, type
+            {&osThreadId, COHEX},
+        };
+        size_t nArg;
+
+        if (!GetCMDOption(args, NULL, 0, arg, _countof(arg), &nArg))
+        {
+            return Status;
+        }
+    }
+    ULONG64 managedObject;
+    HRESULT hr = _EFN_GetManagedThread(client, osThreadId, &managedObject);
+    {
+        INIT_API();
+
+        if (SUCCEEDED(hr)) {
+            ExtOut("%08x %p\n", osThreadId, managedObject);
+        }
+        else {
+            ExtErr("_EFN_GetManagedThread FAILED %08x\n", hr);
+        }
+    }
+    return hr;
+}
+
+HRESULT CALLBACK
+_EFN_GetManagedThread(
+    PDEBUG_CLIENT client,
+    ULONG osThreadId,
+    PULONG64 pManagedObject)
+{
+    INIT_API();
+
+    _ASSERTE(pManagedObject != nullptr);
+    *pManagedObject = 0;
+
+    DacpThreadStoreData threadStore;
+    if ((Status = threadStore.Request(g_sos)) != S_OK)
+    {
+        return Status;
+    }
+
+    CLRDATA_ADDRESS curThread = threadStore.firstThread;
+    while (curThread)
+    {
+        DacpThreadData thread;
+        if ((Status = thread.Request(g_sos, curThread)) != S_OK)
+        {
+            return Status;
+        }        
+        if (thread.osThreadId == osThreadId)
+        {        
+            *pManagedObject = (ULONG64)curThread;
+            return S_OK;
+        }
+        curThread = thread.nextThread;
+    }
+
+    return E_INVALIDARG;
+}
+
 #endif // FEATURE_PAL
 
 //