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 &successHandler = + [] { return MIstatus::success; }, + const std::function &errorHandler = [] {}); + bool HandleSBErrorWithSuccess(const lldb::SBError &error, + const std::function &successHandler); + bool HandleSBErrorWithFailure(const lldb::SBError &error, + const std::function &errorHandler); 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,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 &successHandler, + const std::function &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 &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 &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.