Add ICorDebugDataTarget4 to SOS.
authorMike McLaughlin <mikem@microsoft.com>
Wed, 16 Sep 2015 22:08:11 +0000 (15:08 -0700)
committerMike McLaughlin <mikem@microsoft.com>
Fri, 18 Sep 2015 00:23:52 +0000 (17:23 -0700)
Now that Eugene fixed out of context unwinding in the DAC for Linux after
this change, the SOS "clrstack" command should always work and not hang anymore.

src/ToolBox/SOS/Strike/datatarget.cpp
src/ToolBox/SOS/Strike/datatarget.h
src/ToolBox/SOS/lldbplugin/debugclient.cpp
src/ToolBox/SOS/lldbplugin/debugclient.h
src/ToolBox/SOS/lldbplugin/inc/dbgeng.h
src/ToolBox/SOS/lldbplugin/mstypes.h
src/debug/daccess/datatargetadapter.cpp
src/debug/daccess/datatargetadapter.h
src/pal/inc/rt/palrt.h

index 82c1f86..6da8f71 100644 (file)
@@ -32,6 +32,12 @@ DataTarget::QueryInterface(
         AddRef();
         return S_OK;
     }
+    if (InterfaceId == IID_ICorDebugDataTarget4)
+    {
+        *Interface = (ICorDebugDataTarget4*)this;
+        AddRef();
+        return S_OK;
+    }
     else
     {
         *Interface = NULL;
@@ -188,3 +194,10 @@ DataTarget::Request(
 {
     return E_NOTIMPL;
 }
+
+HRESULT STDMETHODCALLTYPE 
+DataTarget::GetPid(
+    /* [out] */ DWORD *pdwProcessId)
+{
+    return g_ExtSystem->GetCurrentProcessId(pdwProcessId);
+}
\ No newline at end of file
index b82ab93..407ddc0 100644 (file)
@@ -4,7 +4,7 @@
 // Licensed under the MIT license. See LICENSE file in the project root for full license information. 
 //
 
-class DataTarget : public ICLRDataTarget
+class DataTarget : public ICLRDataTarget, ICorDebugDataTarget4
 {
 private:
     LONG m_ref;                         // Reference count.
@@ -82,4 +82,9 @@ public:
         /* [size_is][in] */ BYTE *inBuffer,
         /* [in] */ ULONG32 outBufferSize,
         /* [size_is][out] */ BYTE *outBuffer);
+
+    // ICorDebugDataTarget4
+
+    virtual HRESULT STDMETHODCALLTYPE GetPid(
+        /* [out] */ DWORD *pdwProcessId);
 };
\ No newline at end of file
index 51d61ba..ebb4504 100644 (file)
@@ -734,9 +734,34 @@ DebugClient::GetModuleBase(
 //----------------------------------------------------------------------------
 
 HRESULT 
+DebugClient::GetCurrentProcessId(
+    PULONG id)
+{
+    if (id == NULL)  
+    {
+        return E_INVALIDARG;
+    }
+
+    lldb::SBProcess process = GetCurrentProcess();
+    if (!process.IsValid())
+    {
+        *id = 0;
+        return E_FAIL;
+    }
+
+    *id = process.GetProcessID();
+    return S_OK;
+}
+
+HRESULT 
 DebugClient::GetCurrentThreadId(
     PULONG id)
 {
+    if (id == NULL)  
+    {
+        return E_INVALIDARG;
+    }
+
     lldb::SBThread thread = GetCurrentThread();
     if (!thread.IsValid())
     {
@@ -778,6 +803,11 @@ HRESULT
 DebugClient::GetCurrentThreadSystemId(
     PULONG sysId)
 {
+    if (sysId == NULL)  
+    {
+        return E_INVALIDARG;
+    }
+
     lldb::SBThread thread = GetCurrentThread();
     if (!thread.IsValid())
     {
@@ -808,6 +838,11 @@ DebugClient::GetThreadIdBySystemId(
     lldb::SBProcess process;
     lldb::SBThread thread;
 
+    if (threadId == NULL)  
+    {
+        return E_INVALIDARG;
+    }
+
     process = GetCurrentProcess();
     if (!process.IsValid())
     {
@@ -850,7 +885,7 @@ DebugClient::GetThreadContextById(
     DT_CONTEXT *dtcontext;
     HRESULT hr = E_FAIL;
 
-    if (contextSize < sizeof(DT_CONTEXT))
+    if (context == NULL || contextSize < sizeof(DT_CONTEXT))
     {
         goto exit;
     }
index cb2d089..c3978f2 100644 (file)
@@ -145,6 +145,9 @@ public:
     // IDebugSystemObjects
     //----------------------------------------------------------------------------
 
+    HRESULT GetCurrentProcessId(
+        PULONG id);
+
     HRESULT GetCurrentThreadId(
         PULONG id);
 
index 9890e13..36c1c83 100644 (file)
@@ -367,6 +367,9 @@ typedef class IDebugSymbols* PDEBUG_SYMBOLS;
 class IDebugSystemObjects 
 {
 public:
+    virtual HRESULT GetCurrentProcessId(
+        PULONG id) = 0;
+
     // Controls implicit thread used by the
     // debug engine.  The debuggers current
     // thread is just a piece of data held
index 17d421e..7b23dae 100644 (file)
@@ -50,6 +50,7 @@ typedef int HRESULT;
 #define S_FALSE                          (HRESULT)0x00000001
 #define E_NOTIMPL                        (HRESULT)0x80004001
 #define E_FAIL                           (HRESULT)0x80004005
+#define E_INVALIDARG                     (HRESULT)0x80070057
 
 #define MAX_PATH                         260 
 
index 902b7da..57d990a 100644 (file)
@@ -45,18 +45,18 @@ DataTargetAdapter::~DataTargetAdapter()
 // Standard impl of IUnknown::QueryInterface
 HRESULT STDMETHODCALLTYPE
 DataTargetAdapter::QueryInterface(
-    REFIID InterfaceId,
+    REFIID interfaceId,
     PVOID* pInterface)
 {
-    if (InterfaceId == IID_IUnknown)
+    if (interfaceId == IID_IUnknown)
     {
         *pInterface = static_cast<IUnknown *>(static_cast<ICorDebugDataTarget *>(this));
     }
-    else if (InterfaceId == IID_ICorDebugDataTarget)
+    else if (interfaceId == IID_ICorDebugDataTarget)
     {
         *pInterface = static_cast<ICorDebugDataTarget *>(this);
     }
-    else if (InterfaceId == IID_ICorDebugMutableDataTarget)
+    else if (interfaceId == IID_ICorDebugMutableDataTarget)
     {
         // Note that we always implement the mutable interface, even though our underlying target
         // may return E_NOTIMPL for all the functions on this interface.  There is no reliable way
@@ -65,8 +65,8 @@ DataTargetAdapter::QueryInterface(
     }
     else
     {
-        *pInterface = NULL;
-        return E_NOINTERFACE;
+        // For ICorDebugDataTarget4 and other interfaces directly implemented by the legacy data target.
+        return m_pLegacyTarget->QueryInterface(interfaceId, pInterface);
     }
 
     AddRef();
index 00289b7..30f097f 100644 (file)
@@ -25,7 +25,7 @@ interface ICLRDataTarget;
  * for dbgeng (watson, windbg, etc.) and for any other 3rd parties since 
  * it is a documented API for dump generation.
  */
-class DataTargetAdapter : public ICorDebugMutableDataTarget 
+class DataTargetAdapter : public ICorDebugMutableDataTarget
 {
 public:
     // Create an adapter over the supplied legacy data target interface
index 2d67e10..92d9b3a 100644 (file)
@@ -46,7 +46,6 @@ Revision History:
 #define E_UNEXPECTED                     _HRESULT_TYPEDEF_(0x8000FFFFL)
 #define E_OUTOFMEMORY                    _HRESULT_TYPEDEF_(0x8007000EL)
 #define E_INVALIDARG                     _HRESULT_TYPEDEF_(0x80070057L)
-#define E_INVALIDARG                     _HRESULT_TYPEDEF_(0x80070057L)
 #define E_POINTER                        _HRESULT_TYPEDEF_(0x80004003L)
 #define E_HANDLE                         _HRESULT_TYPEDEF_(0x80070006L)
 #define E_ABORT                          _HRESULT_TYPEDEF_(0x80004004L)