diff options
| author | Alexander Polyakov <polyakov.alx@gmail.com> | 2018-06-25 22:01:44 +0000 |
|---|---|---|
| committer | Alexander Polyakov <polyakov.alx@gmail.com> | 2018-06-25 22:01:44 +0000 |
| commit | 9bca7483a537dc37bd686cadc1af78c103248a8a (patch) | |
| tree | ee3a2d7e6eab7535437d10fc4cf65be7aea453c7 | |
| parent | 1649774816f791ee725349f2de4f73f2d0ff402b (diff) | |
| download | bcm5719-llvm-9bca7483a537dc37bd686cadc1af78c103248a8a.tar.gz bcm5719-llvm-9bca7483a537dc37bd686cadc1af78c103248a8a.zip | |
Implement new methods for handling an error in MI commands.
Summary:
The new methods take SBError object and call handler,
specified by user, depending on SBError status.
Reviewers: aprantl, clayborg, labath
Reviewed By: aprantl, clayborg
Subscribers: ki.stfu, lldb-commits
Differential Revision: https://reviews.llvm.org/D48295
llvm-svn: 335541
| -rw-r--r-- | lldb/tools/lldb-mi/MICmdBase.cpp | 58 | ||||
| -rw-r--r-- | lldb/tools/lldb-mi/MICmdBase.h | 10 |
2 files changed, 68 insertions, 0 deletions
diff --git a/lldb/tools/lldb-mi/MICmdBase.cpp b/lldb/tools/lldb-mi/MICmdBase.cpp index cd5bf27c73f..613f005cf75 100644 --- a/lldb/tools/lldb-mi/MICmdBase.cpp +++ b/lldb/tools/lldb-mi/MICmdBase.cpp @@ -214,6 +214,64 @@ void CMICmdBase::SetError(const CMIUtilString &rErrMsg) { //++ //------------------------------------------------------------------------------------ +// 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. diff --git a/lldb/tools/lldb-mi/MICmdBase.h b/lldb/tools/lldb-mi/MICmdBase.h index 66f9fa6ee5d..b5ac5be671f 100644 --- a/lldb/tools/lldb-mi/MICmdBase.h +++ b/lldb/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 @@ public: // 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(); |

