[Lldb-commits] [lldb] r335541 - Implement new methods for handling an error in MI commands.

Alexander Polyakov via lldb-commits lldb-commits at lists.llvm.org
Mon Jun 25 15:01:44 PDT 2018


Author: apolyakov
Date: Mon Jun 25 15:01:44 2018
New Revision: 335541

URL: http://llvm.org/viewvc/llvm-project?rev=335541&view=rev
Log:
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

Modified:
    lldb/trunk/tools/lldb-mi/MICmdBase.cpp
    lldb/trunk/tools/lldb-mi/MICmdBase.h

Modified: lldb/trunk/tools/lldb-mi/MICmdBase.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdBase.cpp?rev=335541&r1=335540&r2=335541&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdBase.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdBase.cpp Mon Jun 25 15:01:44 2018
@@ -214,6 +214,64 @@ void CMICmdBase::SetError(const CMIUtilS
 
 //++
 //------------------------------------------------------------------------------------
+// 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.

Modified: lldb/trunk/tools/lldb-mi/MICmdBase.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdBase.h?rev=335541&r1=335540&r2=335541&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdBase.h (original)
+++ lldb/trunk/tools/lldb-mi/MICmdBase.h Mon Jun 25 15:01:44 2018
@@ -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();
 




More information about the lldb-commits mailing list