apolyakov updated this revision to Diff 152351.
apolyakov retitled this revision from "[lldb-mi] Correct error processing in 
exec-next command." to "[lldb-mi] Clean up and update a few MI commands.".
apolyakov edited the summary of this revision.
apolyakov added a comment.

I didn't committed patch https://reviews.llvm.org/D48295 yet, so I think if we 
change `HandleSBError` handlers from
`std::function<bool/void()>` to `std::function<bool/boid(CMICmdBase *)>` we'll 
be able to create anonymous namespace and declare there a function that takes a 
pointer to current command class(`this` pointer) instead if defining

  auto successHandler = [this] {
      // CODETAG_DEBUG_SESSION_RUNNING_PROG_RECEIVED_SIGINT_PAUSE_PROGRAM
      if (!CMIDriver::Instance().SetDriverStateRunningDebugging()) {
        const CMIUtilString 
&rErrMsg(CMIDriver::Instance().GetErrorDescription());
        this->SetError(CMIUtilString::Format(
            MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE),
            this->m_cmdData.strMiCmd.c_str(),
            rErrMsg.c_str()));
        return MIstatus::failure;
      }
      return MIstatus::success;

3 times in one file. It will reduce duplicating of code but I still think, is 
it worth it?


https://reviews.llvm.org/D47992

Files:
  tools/lldb-mi/MICmdCmdExec.cpp
  tools/lldb-mi/MICmdCmdExec.h

Index: tools/lldb-mi/MICmdCmdExec.h
===================================================================
--- tools/lldb-mi/MICmdCmdExec.h
+++ tools/lldb-mi/MICmdCmdExec.h
@@ -66,7 +66,6 @@
 private:
   const CMIUtilString m_constStrArgStart; // StopAtEntry - run to first
                                           // instruction or main() if specified
-  lldb::SBCommandReturnObject m_lldbResult;
 };
 
 //++
@@ -91,7 +90,6 @@
   bool Acknowledge() override;
   // From CMICmnBase
   /* dtor */ ~CMICmdCmdExecContinue() override;
-
   // Attributes:
 };
 
@@ -121,7 +119,6 @@
 
   // Attributes:
 private:
-  lldb::SBCommandReturnObject m_lldbResult;
   const CMIUtilString m_constStrArgNumber; // Not specified in MI spec but
                                            // Eclipse gives this option
 };
Index: tools/lldb-mi/MICmdCmdExec.cpp
===================================================================
--- tools/lldb-mi/MICmdCmdExec.cpp
+++ tools/lldb-mi/MICmdCmdExec.cpp
@@ -126,21 +126,27 @@
   }
 
   lldb::SBProcess process = rSessionInfo.GetTarget().Launch(launchInfo, error);
-  if ((!process.IsValid()) || (error.Fail())) {
+  if (!process.IsValid()) {
     SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_PROCESS),
                                    m_cmdData.strMiCmd.c_str(),
                                    errMsg.GetData()));
     return MIstatus::failure;
   }
 
-  if (!CMIDriver::Instance().SetDriverStateRunningDebugging()) {
-    const CMIUtilString &rErrMsg(CMIDriver::Instance().GetErrorDescription());
-    SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE),
-                                   m_cmdData.strMiCmd.c_str(),
-                                   rErrMsg.c_str()));
-    return MIstatus::failure;
-  }
-  return MIstatus::success;
+  auto successHandler = [this] {
+    // CODETAG_DEBUG_SESSION_RUNNING_PROG_RECEIVED_SIGINT_PAUSE_PROGRAM
+    if (!CMIDriver::Instance().SetDriverStateRunningDebugging()) {
+      const CMIUtilString &rErrMsg(CMIDriver::Instance().GetErrorDescription());
+      this->SetError(CMIUtilString::Format(
+          MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE),
+          this->m_cmdData.strMiCmd.c_str(),
+          rErrMsg.c_str()));
+      return MIstatus::failure;
+    }
+    return MIstatus::success;
+  };
+
+  return HandleSBErrorWithSuccess(error, successHandler);
 }
 
 //++
@@ -156,9 +162,8 @@
 // Throws:  None.
 //--
 bool CMICmdCmdExecRun::Acknowledge() {
-  const CMICmnMIResultRecord miRecordResult(
+  m_miResultRecord = CMICmnMIResultRecord(
       m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
-  m_miResultRecord = miRecordResult;
 
   CMICmnLLDBDebugSessionInfo &rSessionInfo(
       CMICmnLLDBDebugSessionInfo::Instance());
@@ -233,23 +238,22 @@
 // Throws:  None.
 //--
 bool CMICmdCmdExecContinue::Execute() {
-  lldb::SBError error =
-      CMICmnLLDBDebugSessionInfo::Instance().GetProcess().Continue();
- 
-  if (error.Success()) {
+  auto successHandler = [this] {
     // CODETAG_DEBUG_SESSION_RUNNING_PROG_RECEIVED_SIGINT_PAUSE_PROGRAM
     if (!CMIDriver::Instance().SetDriverStateRunningDebugging()) {
       const CMIUtilString &rErrMsg(CMIDriver::Instance().GetErrorDescription());
-      SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE),
-                                     m_cmdData.strMiCmd.c_str(),
-                                     rErrMsg.c_str()));
+      this->SetError(CMIUtilString::Format(
+          MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE),
+          this->m_cmdData.strMiCmd.c_str(),
+          rErrMsg.c_str()));
       return MIstatus::failure;
     }
     return MIstatus::success;
-  }
+  };
 
-  SetError(error.GetCString());
-  return MIstatus::failure;
+  return HandleSBErrorWithSuccess(
+      CMICmnLLDBDebugSessionInfo::Instance().GetProcess().Continue(),
+      successHandler);
 }
 
 //++
@@ -264,9 +268,8 @@
 // Throws:  None.
 //--
 bool CMICmdCmdExecContinue::Acknowledge() {
-  const CMICmnMIResultRecord miRecordResult(
+  m_miResultRecord = CMICmnMIResultRecord(
       m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
-  m_miResultRecord = miRecordResult;
   return MIstatus::success;
 }
 
@@ -358,18 +361,21 @@
   CMICmnLLDBDebugSessionInfo &rSessionInfo(
       CMICmnLLDBDebugSessionInfo::Instance());
 
+  lldb::SBError error;
   if (nThreadId != UINT64_MAX) {
     lldb::SBThread sbThread = rSessionInfo.GetProcess().GetThreadByIndexID(nThreadId);
     if (!sbThread.IsValid()) {
       SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_THREAD_INVALID),
                                      m_cmdData.strMiCmd.c_str(),
                                      m_constStrArgThread.c_str()));
       return MIstatus::failure;
     }
-    sbThread.StepOver();
-  } else rSessionInfo.GetProcess().GetSelectedThread().StepOver();
+    sbThread.StepOver(lldb::eOnlyDuringStepping, error);
+  } else
+    rSessionInfo.GetProcess().GetSelectedThread().StepOver(
+        lldb::eOnlyDuringStepping, error);
 
-  return MIstatus::success;
+  return HandleSBError(error);
 }
 
 //++
@@ -384,21 +390,8 @@
 // Throws:  None.
 //--
 bool CMICmdCmdExecNext::Acknowledge() {
-  if (m_lldbResult.GetErrorSize() > 0) {
-    const char *pLldbErr = m_lldbResult.GetError();
-    MIunused(pLldbErr);
-    const CMICmnMIValueConst miValueConst(m_lldbResult.GetError());
-    const CMICmnMIValueResult miValueResult("message", miValueConst);
-    const CMICmnMIResultRecord miRecordResult(
-        m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error,
-        miValueResult);
-    m_miResultRecord = miRecordResult;
-  } else {
-    const CMICmnMIResultRecord miRecordResult(
-        m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
-    m_miResultRecord = miRecordResult;
-  }
-
+  m_miResultRecord = CMICmnMIResultRecord(
+      m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
   return MIstatus::success;
 }
 
@@ -499,14 +492,11 @@
       return MIstatus::failure;
     }
     sbThread.StepInto(nullptr, LLDB_INVALID_LINE_NUMBER, error);
-  } else rSessionInfo.GetProcess().GetSelectedThread().StepInto(
-             nullptr, LLDB_INVALID_LINE_NUMBER, error);
-
-  if (error.Success())
-    return MIstatus::success;
+  } else
+    rSessionInfo.GetProcess().GetSelectedThread().StepInto(
+        nullptr, LLDB_INVALID_LINE_NUMBER, error);
 
-  SetError(error.GetCString());
-  return MIstatus::failure;
+  return HandleSBError(error);
 }
 
 //++
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to