Fix a couple bugs in GetContainingObject
authorAndrew Au <andrewau@microsoft.com>
Fri, 10 Aug 2018 17:27:24 +0000 (10:27 -0700)
committerAndrew Au <cshung@gmail.com>
Wed, 7 Nov 2018 02:34:47 +0000 (18:34 -0800)
Commit migrated from https://github.com/dotnet/coreclr/commit/3c2a1f099cf2150f5b3597bd3d40e1061ef13aa7

src/coreclr/src/debug/di/process.cpp
src/coreclr/src/inc/cordebug.idl

index 1411857..5225205 100644 (file)
@@ -2529,10 +2529,15 @@ COM_METHOD CordbProcess::EnableExceptionCallbacksOutsideOfMyCode(BOOL enableExce
 
 COM_METHOD CordbProcess::GetContainingObject(CORDB_ADDRESS interiorPointer, ICorDebugObjectValue** ppContainingObject)
 {
+    if (!ppContainingObject)
+        return E_POINTER;
+
     HRESULT hr = S_OK;
     // TODO, databp, I don't know what I am doing, NO_LOCK doesn't sound right
     PUBLIC_API_NO_LOCK_BEGIN(this);
 
+    *ppContainingObject = nullptr;
+
     RSLockHolder ch(this->GetStopGoLock());
 
     DebuggerIPCEvent      event;
@@ -2543,14 +2548,21 @@ COM_METHOD CordbProcess::GetContainingObject(CORDB_ADDRESS interiorPointer, ICor
 
     event.GetContainer.interiorPointer = CORDB_ADDRESS_TO_PTR(interiorPointer);
 
-    HRESULT hr = this->SendIPCEvent(&event, sizeof(DebuggerIPCEvent));
+    hr = this->SendIPCEvent(&event, sizeof(DebuggerIPCEvent));
     hr = WORST_HR(hr, event.hr);
 
     if (SUCCEEDED(hr))
     {
         _ASSERTE(event.type == DB_IPCE_GET_CONTAINER_RESULT);
         CORDB_ADDRESS containerAddress = PTR_TO_CORDB_ADDRESS(event.GetContainerResult.answer);
-        hr = this->GetObject(containerAddress, ppContainingObject);
+        if (containerAddress == 0)
+        {
+            hr = S_FALSE;
+        }
+        else
+        {
+            hr = this->GetObject(containerAddress, ppContainingObject);
+        }
     }
 
     PUBLIC_API_END(hr);
index 961a03c..0fd1588 100644 (file)
@@ -3307,12 +3307,12 @@ interface ICorDebugProcess10 : IUnknown
     //   
     // Returns
     //   S_OK - on success
-    //   
-    // TODO: What if the pointer is not an interior pointer?
-    // TODO: What are all the possible error exit codes?
+    //   S_FALSE   - if the given interior pointer is not inside an object
+    //   E_POINTER - ppContainingObject is NULL
     // 
     HRESULT GetContainingObject([in] CORDB_ADDRESS interiorPointer, [out] ICorDebugObjectValue** ppContainingObject);
 
+    //
     // Enable or disable the GC notification events. The GC notification events are turned off by default
     // They will be delivered through ICorDebugManagedCallback4
     // 
@@ -3320,7 +3320,8 @@ interface ICorDebugProcess10 : IUnknown
     //   fEnable - true to enable the events, false to disable
     // 
     // Returns
-    //   S_OK - on success    
+    //   S_OK - on success   
+    // 
     HRESULT EnableGCNotificationEvents(BOOL fEnable);
 }