[Lldb-commits] [lldb] r184893 - <rdar://problem/14266411>

Enrico Granata egranata at apple.com
Tue Jun 25 16:43:29 PDT 2013


Author: enrico
Date: Tue Jun 25 18:43:28 2013
New Revision: 184893

URL: http://llvm.org/viewvc/llvm-project?rev=184893&view=rev
Log:
<rdar://problem/14266411>

The semi-unofficial way of returning a status from a Python command was to return a string (e.g. return "no such variable was found") that LLDB would pick as a clue of an error having happened

This checkin changes that:
- SBCommandReturnObject now exports a SetError() call, which can take an SBError or a plain C-string
- script commands now drop any return value and expect the SBCommandReturnObject ("return object") to be filled in appropriately - if you do nothing, a success will be assumed

If your commands were relying on returning a value and having LLDB pick that up as an error, please change your commands to SetError() through the return object or expect changes in behavior


Modified:
    lldb/trunk/include/lldb/API/SBCommandReturnObject.h
    lldb/trunk/include/lldb/API/SBError.h
    lldb/trunk/include/lldb/Interpreter/CommandReturnObject.h
    lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
    lldb/trunk/lldb.xcodeproj/project.pbxproj
    lldb/trunk/scripts/Python/interface/SBCommandReturnObject.i
    lldb/trunk/scripts/Python/python-wrapper.swig
    lldb/trunk/source/API/SBCommandReturnObject.cpp
    lldb/trunk/source/Commands/CommandObjectCommands.cpp
    lldb/trunk/source/Interpreter/CommandReturnObject.cpp
    lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
    lldb/trunk/test/functionalities/command_script/welcome.py

Modified: lldb/trunk/include/lldb/API/SBCommandReturnObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBCommandReturnObject.h?rev=184893&r1=184892&r2=184893&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBCommandReturnObject.h (original)
+++ lldb/trunk/include/lldb/API/SBCommandReturnObject.h Tue Jun 25 18:43:28 2013
@@ -98,6 +98,13 @@ public:
     const char *
     GetError (bool only_if_no_immediate);
     
+    void
+    SetError (lldb::SBError &error,
+              const char *fallback_error_cstr = NULL);
+    
+    void
+    SetError (const char* error_cstr);
+    
 protected:
     friend class SBCommandInterpreter;
     friend class SBOptions;

Modified: lldb/trunk/include/lldb/API/SBError.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBError.h?rev=184893&r1=184892&r2=184893&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBError.h (original)
+++ lldb/trunk/include/lldb/API/SBError.h Tue Jun 25 18:43:28 2013
@@ -66,6 +66,7 @@ public:
 
 protected:
 
+    friend class SBCommandReturnObject;
     friend class SBData;
     friend class SBDebugger;
     friend class SBCommunication;

Modified: lldb/trunk/include/lldb/Interpreter/CommandReturnObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandReturnObject.h?rev=184893&r1=184892&r2=184893&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandReturnObject.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandReturnObject.h Tue Jun 25 18:43:28 2013
@@ -143,8 +143,11 @@ public:
 
     void
     SetError (const Error &error, 
-              const char *fallback_error_cstr);
+              const char *fallback_error_cstr = NULL);
 
+    void
+    SetError (const char *error_cstr);
+    
     lldb::ReturnStatus
     GetStatus();
 

Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h?rev=184893&r1=184892&r2=184893&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h Tue Jun 25 18:43:28 2013
@@ -120,7 +120,6 @@ public:
                                                                      const char *session_dictionary_name,
                                                                      lldb::DebuggerSP& debugger,
                                                                      const char* args,
-                                                                     std::string& err_msg,
                                                                      lldb_private::CommandReturnObject& cmd_retobj);
     
     typedef bool           (*SWIGPythonCallModuleInit)              (const char *python_module_name,

Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=184893&r1=184892&r2=184893&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Tue Jun 25 18:43:28 2013
@@ -1656,7 +1656,7 @@
 		9A42976211861AA600FE05CD /* CommandObjectBreakpointCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandObjectBreakpointCommand.cpp; path = source/Commands/CommandObjectBreakpointCommand.cpp; sourceTree = "<group>"; };
 		9A4633DA11F65D8600955CE1 /* UserSettingsController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UserSettingsController.h; path = include/lldb/Core/UserSettingsController.h; sourceTree = "<group>"; };
 		9A4633DC11F65D9A00955CE1 /* UserSettingsController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UserSettingsController.cpp; path = source/Core/UserSettingsController.cpp; sourceTree = "<group>"; };
-		9A48A3A7124AAA5A00922451 /* python-extensions.swig */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.cpp; fileEncoding = 4; path = "python-extensions.swig"; sourceTree = "<group>"; };
+		9A48A3A7124AAA5A00922451 /* python-extensions.swig */ = {isa = PBXFileReference; explicitFileType = text.script.python; fileEncoding = 4; path = "python-extensions.swig"; sourceTree = "<group>"; };
 		9A4F350F1368A51A00823F52 /* StreamAsynchronousIO.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StreamAsynchronousIO.cpp; path = source/Core/StreamAsynchronousIO.cpp; sourceTree = "<group>"; };
 		9A4F35111368A54100823F52 /* StreamAsynchronousIO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StreamAsynchronousIO.h; path = include/lldb/Core/StreamAsynchronousIO.h; sourceTree = "<group>"; };
 		9A633FE7112DCE3C001A7E43 /* SBFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SBFrame.cpp; path = source/API/SBFrame.cpp; sourceTree = "<group>"; };

Modified: lldb/trunk/scripts/Python/interface/SBCommandReturnObject.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBCommandReturnObject.i?rev=184893&r1=184892&r2=184893&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBCommandReturnObject.i (original)
+++ lldb/trunk/scripts/Python/interface/SBCommandReturnObject.i Tue Jun 25 18:43:28 2013
@@ -58,7 +58,14 @@ public:
 
     void
     SetStatus (lldb::ReturnStatus status);
+    
+    void
+    SetError (lldb::SBError &error,
+              const char *fallback_error_cstr = NULL);
 
+    void
+    SetError (const char *error_cstr);
+    
     lldb::ReturnStatus
     GetStatus();
 

Modified: lldb/trunk/scripts/Python/python-wrapper.swig
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-wrapper.swig?rev=184893&r1=184892&r2=184893&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/python-wrapper.swig (original)
+++ lldb/trunk/scripts/Python/python-wrapper.swig Tue Jun 25 18:43:28 2013
@@ -318,7 +318,7 @@ LLDBSwigPythonCallTypeScript
     if (!python_function_name || !session_dictionary)
         return false;
 
-    PyObject *session_dict = (PyObject*)session_dictionary, *pfunc_impl = NULL, *pargs = NULL, *pvalue = NULL;
+    PyObject *session_dict = (PyObject*)session_dictionary, *pfunc_impl = NULL, *pvalue = NULL;
     
     if (pyfunct_wrapper && *pyfunct_wrapper && PyFunction_Check (*pyfunct_wrapper))
     {
@@ -475,10 +475,6 @@ LLDBSwigPython_GetChildAtIndex
     uint32_t idx
 )
 {
-
-    static char callee_name[] = "get_child_at_index";
-    static char param_format[] = "i";
-
     PyErr_Cleaner py_err_cleaner(true);
     
     PyCallable pfunc = PyCallable::FindWithMemberFunction(implementor,"get_child_at_index");
@@ -628,7 +624,6 @@ LLDBSwigPythonCallCommand
     const char *session_dictionary_name,
     lldb::DebuggerSP& debugger,
     const char* args,
-    std::string& err_msg,
     lldb_private::CommandReturnObject& cmd_retobj
 )
 {
@@ -653,23 +648,9 @@ LLDBSwigPythonCallCommand
         pvalue = pfunc(debugger_sb, args, &cmd_retobj_sb, session_dict = FindSessionDictionary(session_dictionary_name));
         
         Py_XINCREF (session_dict);
-        
-        if (pvalue != NULL)
-        {
-            if (pvalue == Py_None) // no error
-            {
-                err_msg.clear();
-                retval = true;
-            }
-            else
-            {
-                // return value is an error string
-                PyObjectToString(pvalue,err_msg);
-                retval = false;
-            }
-        }
-        
         Py_XDECREF (pvalue);
+        
+        retval = true;
     }
     
     return retval;

Modified: lldb/trunk/source/API/SBCommandReturnObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBCommandReturnObject.cpp?rev=184893&r1=184892&r2=184893&view=diff
==============================================================================
--- lldb/trunk/source/API/SBCommandReturnObject.cpp (original)
+++ lldb/trunk/source/API/SBCommandReturnObject.cpp Tue Jun 25 18:43:28 2013
@@ -8,8 +8,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "lldb/API/SBCommandReturnObject.h"
+#include "lldb/API/SBError.h"
 #include "lldb/API/SBStream.h"
 
+#include "lldb/Core/Error.h"
 #include "lldb/Core/Log.h"
 #include "lldb/Interpreter/CommandReturnObject.h"
 
@@ -329,3 +331,21 @@ SBCommandReturnObject::Printf(const char
     return 0;
 }
 
+void
+SBCommandReturnObject::SetError (lldb::SBError &error, const char *fallback_error_cstr)
+{
+    if (m_opaque_ap.get())
+    {
+        if (error.IsValid())
+            m_opaque_ap->SetError(error.ref(), fallback_error_cstr);
+        else if (fallback_error_cstr)
+            m_opaque_ap->SetError(Error(), fallback_error_cstr);
+    }
+}
+
+void
+SBCommandReturnObject::SetError (const char *error_cstr)
+{
+    if (m_opaque_ap.get() && error_cstr)
+        m_opaque_ap->SetError(error_cstr);
+}

Modified: lldb/trunk/source/Commands/CommandObjectCommands.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectCommands.cpp?rev=184893&r1=184892&r2=184893&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectCommands.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectCommands.cpp Tue Jun 25 18:43:28 2013
@@ -1330,7 +1330,9 @@ protected:
             // Don't change the status if the command already set it...
             if (result.GetStatus() == eReturnStatusInvalid)
             {
-                if (result.GetOutputData() == NULL || result.GetOutputData()[0] == '\0')
+                if (result.GetErrorData() && result.GetErrorData()[0])
+                    result.SetStatus(eReturnStatusFailed);
+                else if (result.GetOutputData() == NULL || result.GetOutputData()[0] == '\0')
                     result.SetStatus(eReturnStatusSuccessFinishNoResult);
                 else
                     result.SetStatus(eReturnStatusSuccessFinishResult);

Modified: lldb/trunk/source/Interpreter/CommandReturnObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandReturnObject.cpp?rev=184893&r1=184892&r2=184893&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandReturnObject.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandReturnObject.cpp Tue Jun 25 18:43:28 2013
@@ -143,9 +143,19 @@ CommandReturnObject::SetError (const Err
     const char *error_cstr = error.AsCString();
     if (error_cstr == NULL)
         error_cstr = fallback_error_cstr;
-    AppendError (error_cstr);
-    SetStatus (eReturnStatusFailed);
+    SetError(error_cstr);
 }
+
+void
+CommandReturnObject::SetError (const char *error_cstr)
+{
+    if (error_cstr)
+    {
+        AppendError (error_cstr);
+        SetStatus (eReturnStatusFailed);
+    }
+}
+
 // Similar to AppendError, but do not prepend 'Error: ' to message, and
 // don't append "\n" to the end of it.
 

Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=184893&r1=184892&r2=184893&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original)
+++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Tue Jun 25 18:43:28 2013
@@ -115,7 +115,6 @@ LLDBSwigPythonCallCommand (const char *p
                            const char *session_dictionary_name,
                            lldb::DebuggerSP& debugger,
                            const char* args,
-                           std::string& err_msg,
                            lldb_private::CommandReturnObject& cmd_retobj);
 
 extern "C" bool
@@ -2970,7 +2969,7 @@ ScriptInterpreterPython::RunScriptBasedC
         return false;
     }
     
-    bool ret_val;
+    bool ret_val = false;
     
     std::string err_msg;
 
@@ -2995,12 +2994,11 @@ ScriptInterpreterPython::RunScriptBasedC
                                              m_dictionary_name.c_str(),
                                              debugger_sp,
                                              args,
-                                             err_msg,
                                              cmd_retobj);
     }
 
     if (!ret_val)
-        error.SetErrorString(err_msg.c_str());
+        error.SetErrorString("unable to execute script function");
     else
         error.Clear();
     

Modified: lldb/trunk/test/functionalities/command_script/welcome.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/command_script/welcome.py?rev=184893&r1=184892&r2=184893&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/command_script/welcome.py (original)
+++ lldb/trunk/test/functionalities/command_script/welcome.py Tue Jun 25 18:43:28 2013
@@ -13,9 +13,7 @@ def target_name_impl(debugger, args, res
     file = target.GetExecutable()
     print >>result,  ('Current target ' + file.GetFilename())
     if args == 'fail':
-        return 'a test for error in command'
-    else:
-        return None
+        result.SetError('a test for error in command')
 
 def print_wait_impl(debugger, args, result, dict):
     result.SetImmediateOutputFile(sys.stdout)
@@ -25,11 +23,10 @@ def print_wait_impl(debugger, args, resu
     print >>result,  ('Still doing long task..')
     time.sleep(1)
     print >>result,  ('Done; if you saw the delays I am doing OK')
-    return None
 
 def check_for_synchro(debugger, args, result, dict):
     if debugger.GetAsync() == True:
         print >>result,  ('I am running async')
     if debugger.GetAsync() == False:
         print >>result,  ('I am running sync')
-    return None
+





More information about the lldb-commits mailing list