apolyakov updated this revision to Diff 152310. apolyakov retitled this revision from "[WIP] Implement new ReturnMIStatus method of CMICmdBase class." to "[WIP] Implement new methods for handling an error in MI commands.". apolyakov edited the summary of this revision. apolyakov added a comment.
Splitted functionality between a few functions with different names. If this patch is good, I'll remove [WIP] status and usage examples (in MICmdCmdExec.cpp file). https://reviews.llvm.org/D48295 Files: tools/lldb-mi/MICmdBase.cpp tools/lldb-mi/MICmdBase.h tools/lldb-mi/MICmdCmdExec.cpp
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 HandleSBErrorWithSuccess( + 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); } //++ 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,14 @@ // Methods: protected: void SetError(const CMIUtilString &rErrMsg); + bool HandleSBError(const lldb::SBError &error, + const std::function<bool()> &successHandler = + [] { return MIstatus::success; }, + const std::function<void()> &errorHandler = [] {}); + bool HandleSBErrorWithSuccess(const lldb::SBError &error, + const std::function<bool()> &successHandler); + bool HandleSBErrorWithFailure(const lldb::SBError &error, + const std::function<void()> &errorHandler); template <class T> 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,64 @@ //++ //------------------------------------------------------------------------------------ +// 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<bool()> &successHandler, + const std::function<void()> &errorHandler) { + if (error.Success()) + return successHandler(); + + SetError(error.GetCString()); + errorHandler(); + return MIstatus::failure; +} + +//++ +//------------------------------------------------------------------------------------ +// Details: Short cut function to check MI command's execute status and +// call specified handler function for success case. +// Type: Method. +// Args: error - (R) Error description object. +// successHandler - (R) function describing actions to execute +// in case of success state of passed SBError object. +// Return: bool. +// Throws: None. +//-- +bool CMICmdBase::HandleSBErrorWithSuccess( + const lldb::SBError &error, + const std::function<bool()> &successHandler) { + return HandleSBError(error, successHandler); +} + +//++ +//------------------------------------------------------------------------------------ +// Details: Short cut function to check MI command's execute status and +// call specified handler function for error case. +// Type: Method. +// Args: error - (R) Error description object. +// errorHandler - (R) function describing actions to execute +// in case of fail status of passed SBError object. +// Return: bool. +// Throws: None. +//-- +bool CMICmdBase::HandleSBErrorWithFailure( + const lldb::SBError &error, + const std::function<void()> &errorHandler) { + return HandleSBError(error, [] { return MIstatus::success; }, errorHandler); +} + +//++ +//------------------------------------------------------------------------------------ // Details: Ask a command to provide its unique identifier. // Type: Method. // Args: A unique identifier for this command class.
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits