Fix nested lambda captures display
authorIgor Kulaychuk <i.kulaychuk@samsung.com>
Sat, 22 Jul 2017 20:28:46 +0000 (23:28 +0300)
committerIgor Kulaychuk <i.kulaychuk@samsung.com>
Mon, 13 Nov 2017 19:22:40 +0000 (22:22 +0300)
src/debug/netcoredbg/valuewalk.cpp

index 524fd44..5241b24 100644 (file)
@@ -361,6 +361,36 @@ HRESULT WalkMembers(ICorDebugValue *pValue, ICorDebugILFrame *pILFrame, WalkMemb
     return WalkMembers(pValue, pILFrame, nullptr, cb);
 }
 
+static HRESULT HandleSpecialLocalVar(const std::string &localName,
+                                     ICorDebugValue *pLocalValue,
+                                     ICorDebugILFrame *pILFrame,
+                                     WalkStackVarsCallback cb)
+{
+    static const std::string captureName = "CS$<>";
+
+    HRESULT Status;
+
+    if (!std::equal(captureName.begin(), captureName.end(), localName.begin()))
+        return S_FALSE;
+
+    // Substitute local value with its fields
+    IfFailRet(WalkMembers(pLocalValue, pILFrame, [&](
+        mdMethodDef,
+        ICorDebugModule *,
+        ICorDebugType *,
+        ICorDebugValue *pValue,
+        bool is_static,
+        const std::string &name)
+    {
+        HRESULT Status;
+        if (std::equal(captureName.begin(), captureName.end(), name.begin()))
+            return S_OK;
+        return cb(pILFrame, pValue, name);
+    }));
+
+    return S_OK;
+}
+
 static HRESULT HandleSpecialThisParam(ICorDebugValue *pThisValue,
                                       ICorDebugILFrame *pILFrame,
                                       WalkStackVarsCallback cb)
@@ -394,6 +424,10 @@ static HRESULT HandleSpecialThisParam(ICorDebugValue *pThisValue,
         bool is_static,
         const std::string &name)
     {
+        HRESULT Status;
+        IfFailRet(HandleSpecialLocalVar(name, pValue, pILFrame, cb));
+        if (Status == S_OK)
+            return S_OK;
         return cb(pILFrame, pValue, name.empty() ? "this" : name);
     }));
     return S_OK;
@@ -501,6 +535,10 @@ HRESULT WalkStackVars(ICorDebugFrame *pFrame, WalkStackVarsCallback cb)
             if (Status == S_FALSE)
                 break;
 
+            IfFailRet(HandleSpecialLocalVar(paramName, pValue, pILFrame, cb));
+            if (Status == S_OK)
+                continue;
+
             IfFailRet(cb(pILFrame, pValue, paramName));
         }
     }