Fix for #167 review
authorAnton Zhukov <a.zhukov@samsung.com>
Tue, 15 Oct 2019 16:38:17 +0000 (12:38 -0400)
committerAlexander Soldatov/Staff Engineer/AI Compiler Lab /SRR/Samsung Electronics <soldatov.a@samsung.com>
Wed, 20 Nov 2019 13:14:05 +0000 (16:14 +0300)
src/debug/netcoredbg/debugger.h
src/debug/netcoredbg/manageddebugger.cpp
src/debug/netcoredbg/manageddebugger.h
src/debug/netcoredbg/valuewalk.cpp
src/debug/netcoredbg/vscodeprotocol.cpp

index f13df29152f8a0b68cd58dd8827dddc2fb550c47..358ff0ccb56757fe809cadc08e5d667ea77f8ab4 100644 (file)
@@ -46,7 +46,6 @@ public:
 
     virtual int GetLastStoppedThreadId() = 0;
 
-    virtual HRESULT CompleteException() = 0;
     virtual HRESULT Stop(int threadId, const StoppedEvent &event) = 0;
     virtual HRESULT Continue(int threadId) = 0;
     virtual HRESULT Pause() = 0;
index a2ed416caa60c634e57044ba9f16dc1e072faff3..517c25fd3c7997edcc2869bbaa2fbb845de73593 100644 (file)
@@ -1061,15 +1061,6 @@ HRESULT ManagedDebugger::StepCommand(int threadId, StepType stepType)
     return Status;
 }
 
-HRESULT ManagedDebugger::CompleteException()
-{
-    LogFuncEntry();
-
-    m_evaluator.pop_eval_queue();
-
-    return S_OK;
-}
-
 HRESULT ManagedDebugger::Stop(int threadId, const StoppedEvent &event)
 {
     LogFuncEntry();
@@ -1542,19 +1533,16 @@ HRESULT ManagedDebugger::GetExceptionInfoResponse(int threadId,
     // Are needed to move next line to Exception() callback?
     m_evaluator.push_eval_queue(threadId);
 
-    HRESULT res;
+    HRESULT res = E_FAIL;
     HRESULT Status = S_OK;
-    ToRelease<ICorDebugThread> pThread;
-    IfFailRet(m_pProcess->GetThread(threadId, &pThread));
-
+    bool hasInner = false;
+    Variable varException;
+    ToRelease <ICorDebugValue> evalValue;
     ToRelease<ICorDebugValue> pExceptionValue;
-    if ((res = pThread->GetCurrentException(&pExceptionValue)) != S_OK) {
-        Logger::levelLog(LOG_ERROR, "GetCurrentException() failed, %0x", res);
-        return res;
-    }
+    ToRelease<ICorDebugThread> pThread;
 
-    WCHAR fieldName[] = W("_message\0");
-    PrintStringField(pExceptionValue, fieldName, exceptionInfoResponse.description);
+    WCHAR message[] = W("_message\0");
+    uint64_t frameId = StackFrame(threadId, 0, "").id;
 
     std::unique_lock<std::mutex> lock(m_lastUnhandledExceptionThreadIdsMutex);
     if (m_lastUnhandledExceptionThreadIds.find(threadId) != m_lastUnhandledExceptionThreadIds.end()) {
@@ -1564,21 +1552,31 @@ HRESULT ManagedDebugger::GetExceptionInfoResponse(int threadId,
     else {
         lock.unlock();
         ExceptionBreakMode mode;
-        IfFailRet(m_breakpoints.GetExceptionBreakMode(mode, "*"));
+
+        if ((res = m_breakpoints.GetExceptionBreakMode(mode, "*")) && FAILED(res))
+            goto failed;
+
         exceptionInfoResponse.breakMode = mode;
     }
 
-    uint64_t frameId = StackFrame(threadId, 0, "").id;
-    Variable varException;
-    IfFailRet(m_variables.GetExceptionVariable(frameId, pThread, varException));
+    if ((res = m_pProcess->GetThread(threadId, &pThread)) && FAILED(res))
+        goto failed;
 
-    if (exceptionInfoResponse.breakMode.OnlyUnhandled() || exceptionInfoResponse.breakMode.UserUnhandled())
-    {
+    if ((res = pThread->GetCurrentException(&pExceptionValue)) && FAILED(res)) {
+        Logger::levelLog(LOG_ERROR, "GetCurrentException() failed, %0x", res);
+        goto failed;
+    }
+
+    PrintStringField(pExceptionValue, message, exceptionInfoResponse.description);
+
+    if ((res = m_variables.GetExceptionVariable(frameId, pThread, varException)) && FAILED(res))
+        goto failed;
+
+    if (exceptionInfoResponse.breakMode.OnlyUnhandled() || exceptionInfoResponse.breakMode.UserUnhandled()) {
         exceptionInfoResponse.description = "An unhandled exception of type '" + varException.type +
             "' occurred in " + varException.module;
     }
-    else
-    {
+    else {
         exceptionInfoResponse.description = "Exception thrown: '" + varException.type +
             "' in " + varException.module;
     }
@@ -1589,9 +1587,7 @@ HRESULT ManagedDebugger::GetExceptionInfoResponse(int threadId,
     exceptionInfoResponse.details.typeName = varException.type;
     exceptionInfoResponse.details.fullTypeName = varException.type;
 
-    bool hasInner = false;
-    ToRelease <ICorDebugValue> evalValue;
-    if (m_evaluator.getObjectByFunction("get_StackTrace", pThread, pExceptionValue, &evalValue) != S_OK) {
+    if (FAILED(m_evaluator.getObjectByFunction("get_StackTrace", pThread, pExceptionValue, &evalValue))) {
         exceptionInfoResponse.details.stackTrace = "<undefined>"; // Evaluating problem entire object
     }
     else {
@@ -1601,23 +1597,27 @@ HRESULT ManagedDebugger::GetExceptionInfoResponse(int threadId,
 
         ICorDebugValue *evalValueInner = pExceptionValue;
         while (isNotNull) {
-            IfFailRet(m_evaluator.getObjectByFunction("get_InnerException", pThread, evalValueInner, &evalValueOut));
+            if ((res = m_evaluator.getObjectByFunction("get_InnerException", pThread, evalValueInner, &evalValueOut)) && FAILED(res))
+                goto failed;
 
             string tmpstr;
             PrintValue(evalValueOut, tmpstr);
 
-            if (tmpstr.compare("null") == 0) {
+            if (tmpstr.compare("null") == 0)
                 break;
-            }
 
             ToRelease<ICorDebugValue> pValueTmp;
 
-            IfFailRet(DereferenceAndUnboxValue(evalValueOut, &pValueTmp, &isNotNull));
+            if ((res = DereferenceAndUnboxValue(evalValueOut, &pValueTmp, &isNotNull)) && FAILED(res))
+                goto failed;
+
             hasInner = true;
             ExceptionDetails inner;
-            PrintStringField(evalValueOut, fieldName, inner.message);
+            PrintStringField(evalValueOut, message, inner.message);
+
+            if ((res = m_evaluator.getObjectByFunction("get_StackTrace", pThread, evalValueOut, &pValueTmp)) && FAILED(res))
+                goto failed;
 
-            IfFailRet(m_evaluator.getObjectByFunction("get_StackTrace", pThread, evalValueOut, &pValueTmp));
             PrintValue(pValueTmp, inner.stackTrace);
 
             exceptionInfoResponse.details.innerException.push_back(inner);
@@ -1628,7 +1628,13 @@ HRESULT ManagedDebugger::GetExceptionInfoResponse(int threadId,
     if (hasInner)
         exceptionInfoResponse.description += "\n Inner exception found, see $exception in variables window for more details.";
 
+    m_evaluator.pop_eval_queue(); // CompleteException
     return S_OK;
+
+failed:
+    m_evaluator.pop_eval_queue(); // CompleteException
+    IfFailRet(res);
+    return res;
 }
 
 // MI
index aae637a088260bd60ebd7df30b54836d3f81dfbc..c6970f84757cf573342668fecbf6fc794aed6848 100644 (file)
@@ -609,7 +609,6 @@ public:
 
     int GetLastStoppedThreadId() override;
 
-    HRESULT CompleteException() override;
     HRESULT Stop(int threadId, const StoppedEvent &event) override;
     HRESULT Continue(int threadId) override;
     HRESULT Pause() override;
index 396bbbbe40279a6732d883559372502f1e9ac0f3..c1947468fccef4270c0fd9acdabe734bdc0f16a3 100644 (file)
@@ -337,8 +337,8 @@ HRESULT Evaluator::getObjectByFunction(
     IfFailRet(pValue2->GetExactType(&pType));
     ToRelease<ICorDebugFunction> pFunc;
 
-    const WCHAR* methodName = to_utf16(func).c_str();
-    IfFailRet(FindMethod(pType, methodName, &pFunc));
+    auto methodName = to_utf16(func);
+    IfFailRet(FindMethod(pType, methodName.c_str(), &pFunc));
 
     return EvalFunction(pThread, pFunc, pType, pInValue, ppOutValue);
 }
index df632de5aef561f14279fdd332b2cabfbcaab755..3eb5a39b364279f58df40015c9925d3fb47fc368 100644 (file)
@@ -398,11 +398,8 @@ HRESULT VSCodeProtocol::HandleCommand(const std::string &command, const json &ar
             body["details"] = getVSCode(exceptionResponse.details);
             // vsdbg extension
             // body["code"] = 0;
-            // Complete exception event processing int this point
-            m_debugger->CompleteException();
             return S_OK;
         }
-        m_debugger->CompleteException();
         return E_FAIL;
     } },
     { "setBreakpoints", [this](const json &arguments, json &body){