[Lldb-commits] [PATCH] D48295: [WIP] Implement new ReturnMIStatus method of CMICmdBase class.
Alexander Polyakov via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Mon Jun 18 15:35:18 PDT 2018
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
More information about the lldb-commits
mailing list