Index: tools/lldb-mi/MICmdBase.h =================================================================== --- tools/lldb-mi/MICmdBase.h +++ tools/lldb-mi/MICmdBase.h @@ -12,6 +12,8 @@ // C Includes // C++ Includes // Other libraries and framework includes +#include "lldb/API/SBError.h" + // Project includes #include "MICmdArgSet.h" #include "MICmdData.h" @@ -80,6 +82,11 @@ // Methods: protected: void SetError(const CMIUtilString &rErrMsg); + bool HandleSBError(const lldb::SBError &error, + const std::function &successHandler = + [] { return MIstatus::success; }, + const std::function &errorHandler = + [] { return MIstatus::failure; }); template T *GetOption(const CMIUtilString &vStrOptionName); bool ParseValidateCmdOptions(); Index: tools/lldb-mi/MICmdBase.cpp =================================================================== --- tools/lldb-mi/MICmdBase.cpp +++ tools/lldb-mi/MICmdBase.cpp @@ -214,6 +214,29 @@ //++ //------------------------------------------------------------------------------------ +// Details: Short cut function to check MI command's execute status and +// set an error in case of failure. +// Type: Method. +// Args: error - (R) Error description object. +// successHandler - (R) function describing actions to execute +// in case of success state of passed SBError object. +// errorHandler - (R) function describing actions to execute +// in case of fail status of passed SBError object. +// Return: bool. +// Throws: None. +//-- +bool CMICmdBase::HandleSBError(const lldb::SBError &error, + const std::function &successHandler, + const std::function &errorHandler) { + if (error.Success()) + return successHandler(); + + SetError(error.GetCString()); + return errorHandler(); +} + +//++ +//------------------------------------------------------------------------------------ // Details: Ask a command to provide its unique identifier. // Type: Method. // Args: A unique identifier for this command class. Index: tools/lldb-mi/MICmdCmdExec.cpp =================================================================== --- tools/lldb-mi/MICmdCmdExec.cpp +++ tools/lldb-mi/MICmdCmdExec.cpp @@ -233,23 +233,22 @@ // Throws: None. //-- bool CMICmdCmdExecContinue::Execute() { - lldb::SBError error = - CMICmnLLDBDebugSessionInfo::Instance().GetProcess().Continue(); - - if (error.Success()) { - // CODETAG_DEBUG_SESSION_RUNNING_PROG_RECEIVED_SIGINT_PAUSE_PROGRAM + auto successCaseHandler = [this] { 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 HandleSBError( + CMICmnLLDBDebugSessionInfo::Instance().GetProcess().Continue(), + successCaseHandler + ); } //++ @@ -502,11 +501,7 @@ } else rSessionInfo.GetProcess().GetSelectedThread().StepInto( nullptr, LLDB_INVALID_LINE_NUMBER, error); - if (error.Success()) - return MIstatus::success; - - SetError(error.GetCString()); - return MIstatus::failure; + return HandleSBError(error); } //++