apolyakov added a comment.

Sure. For example we may look at `bool CMICmdCmdExecContinue::Execute()`, there 
we may see following code:

  if (error.Success()) {
      // 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()));
        return MIstatus::failure;
      }
      return MIstatus::success;
    }

instead of this we may do something like

  auto SetDriverStateRunning = [this] {
      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())
        );
      }
    };
  
  SuccessHandler = SetDriverStateRunning;

and finally we will have a function `CMICmdBase::FinishMICommand` (or another 
name :D) which will be like:

  bool CMICmdBase::FinishMICommand(const SBError &error) {
    if (error.Success()) {
      // call SucessHandler
      SucessHandler();
      return MIstatus::success;
    }
  
    // call ErrorHandler
    ErrorHandler();
    SetError(error.GetCString());
    return MIstatus::failure;
  }

Of course, there will be some default values to SuccessHandler and 
ErrorHandler(some dummy function).


https://reviews.llvm.org/D48295



_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to