[Lldb-commits] [lldb] r109899 - in /lldb/trunk: include/lldb/Interpreter/ScriptInterpreter.h include/lldb/Interpreter/ScriptInterpreterNone.h include/lldb/Interpreter/ScriptInterpreterPython.h source/Interpreter/CommandObjectScript.cpp source/Interpreter/ScriptInterpreterNone.cpp source/Interpreter/ScriptInterpreterPython.cpp test/command_source/TestCommandSource.py

Johnny Chen johnny.chen at apple.com
Fri Jul 30 15:33:14 PDT 2010


Author: johnny
Date: Fri Jul 30 17:33:14 2010
New Revision: 109899

URL: http://llvm.org/viewvc/llvm-project?rev=109899&view=rev
Log:
We can do better when reporting the status of one-liner script execution.

Change the prototype of ScriptInterpreter::ExecuteOneLine() to return bool
instead of void and take one additional parameter as CommandReturnObject *.

Propagate the status of one-liner execution back appropriately.

Modified:
    lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
    lldb/trunk/include/lldb/Interpreter/ScriptInterpreterNone.h
    lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h
    lldb/trunk/source/Interpreter/CommandObjectScript.cpp
    lldb/trunk/source/Interpreter/ScriptInterpreterNone.cpp
    lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
    lldb/trunk/test/command_source/TestCommandSource.py

Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h?rev=109899&r1=109898&r2=109899&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h Fri Jul 30 17:33:14 2010
@@ -42,8 +42,8 @@
 
     virtual ~ScriptInterpreter ();
 
-    virtual void
-    ExecuteOneLine (CommandInterpreter &interpreter, const char *command) = 0;
+    virtual bool
+    ExecuteOneLine (CommandInterpreter &interpreter, const char *command, CommandReturnObject *result) = 0;
 
     virtual void
     ExecuteInterpreterLoop (CommandInterpreter &interpreter) = 0;

Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreterNone.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreterNone.h?rev=109899&r1=109898&r2=109899&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreterNone.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreterNone.h Fri Jul 30 17:33:14 2010
@@ -22,10 +22,10 @@
 
     ~ScriptInterpreterNone ();
 
-    virtual void
-    ExecuteOneLine (CommandInterpreter &interpreter, const char *command);
+    bool
+    ExecuteOneLine (CommandInterpreter &interpreter, const char *command, CommandReturnObject *result);
 
-    virtual void
+    void
     ExecuteInterpreterLoop (CommandInterpreter &interpreter);
 
 };

Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h?rev=109899&r1=109898&r2=109899&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h Fri Jul 30 17:33:14 2010
@@ -24,8 +24,8 @@
 
     ~ScriptInterpreterPython ();
 
-    void
-    ExecuteOneLine (CommandInterpreter &interpreter, const char *command);
+    bool
+    ExecuteOneLine (CommandInterpreter &interpreter, const char *command, CommandReturnObject *result);
 
     void
     ExecuteInterpreterLoop (CommandInterpreter &interpreter);

Modified: lldb/trunk/source/Interpreter/CommandObjectScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandObjectScript.cpp?rev=109899&r1=109898&r2=109899&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandObjectScript.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandObjectScript.cpp Fri Jul 30 17:33:14 2010
@@ -56,11 +56,18 @@
         result.SetStatus (eReturnStatusFailed);
     }
 
-    if (command == NULL || command[0] == '\0')
+    if (command == NULL || command[0] == '\0') {
         script_interpreter->ExecuteInterpreterLoop (interpreter);
+        result.SetStatus (eReturnStatusSuccessFinishNoResult);
+        return result.Succeeded();
+    }
+
+    // We can do better when reporting the status of one-liner script execution.
+    if (script_interpreter->ExecuteOneLine (interpreter, command, &result))
+        result.SetStatus(eReturnStatusSuccessFinishNoResult);
     else
-        script_interpreter->ExecuteOneLine (interpreter, command); 
-    result.SetStatus (eReturnStatusSuccessFinishNoResult);
+        result.SetStatus(eReturnStatusFailed);
+
     return result.Succeeded();
 }
 

Modified: lldb/trunk/source/Interpreter/ScriptInterpreterNone.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterNone.cpp?rev=109899&r1=109898&r2=109899&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/ScriptInterpreterNone.cpp (original)
+++ lldb/trunk/source/Interpreter/ScriptInterpreterNone.cpp Fri Jul 30 17:33:14 2010
@@ -25,10 +25,11 @@
 {
 }
 
-void
-ScriptInterpreterNone::ExecuteOneLine (CommandInterpreter &interpreter, const char *command)
+bool
+ScriptInterpreterNone::ExecuteOneLine (CommandInterpreter &interpreter, const char *command, CommandReturnObject *)
 {
     interpreter.GetDebugger().GetErrorStream().PutCString ("error: there is no embedded script interpreter in this mode.\n");
+    return false;
 }
 
 void

Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=109899&r1=109898&r2=109899&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original)
+++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Fri Jul 30 17:33:14 2010
@@ -258,17 +258,28 @@
     Py_Finalize ();
 }
 
-void
-ScriptInterpreterPython::ExecuteOneLine (CommandInterpreter &interpreter, const char *command)
+bool
+ScriptInterpreterPython::ExecuteOneLine (CommandInterpreter &interpreter,
+                                         const char *command,
+                                         CommandReturnObject *result = 0)
 {
     if (command)
     {
         int success;
 
         success = PyRun_SimpleString (command);
-        if (success != 0)
-            interpreter.GetDebugger().GetErrorStream().Printf ("error: python failed attempting to evaluate '%s'\n", command);
+        if (success == 0)
+            return true;
+
+        // The one-liner failed.  Append the error message.
+        if (result)
+            result->AppendErrorWithFormat ("python failed attempting to evaluate '%s'\n", command);
+        return false;
     }
+
+    if (result)
+        result->AppendError ("empty command passed to python\n");
+    return false;
 }
 
 

Modified: lldb/trunk/test/command_source/TestCommandSource.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/command_source/TestCommandSource.py?rev=109899&r1=109898&r2=109899&view=diff
==============================================================================
--- lldb/trunk/test/command_source/TestCommandSource.py (original)
+++ lldb/trunk/test/command_source/TestCommandSource.py Fri Jul 30 17:33:14 2010
@@ -21,6 +21,8 @@
         self.assertTrue(res.Succeeded())
 
         self.ci.HandleCommand("script my.date()", res)
+        if (not res.Succeeded()):
+            print res.GetError()
         self.assertTrue(res.Succeeded())
 
         time.sleep(1)





More information about the lldb-commits mailing list