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.

llvm-svn: 109899
This commit is contained in:
Johnny Chen 2010-07-30 22:33:14 +00:00
parent fe1a4944b1
commit 7dc2e4784e
7 changed files with 37 additions and 16 deletions

View File

@ -42,8 +42,8 @@ public:
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;

View File

@ -22,10 +22,10 @@ public:
~ScriptInterpreterNone ();
virtual void
ExecuteOneLine (CommandInterpreter &interpreter, const char *command);
bool
ExecuteOneLine (CommandInterpreter &interpreter, const char *command, CommandReturnObject *result);
virtual void
void
ExecuteInterpreterLoop (CommandInterpreter &interpreter);
};

View File

@ -24,8 +24,8 @@ public:
~ScriptInterpreterPython ();
void
ExecuteOneLine (CommandInterpreter &interpreter, const char *command);
bool
ExecuteOneLine (CommandInterpreter &interpreter, const char *command, CommandReturnObject *result);
void
ExecuteInterpreterLoop (CommandInterpreter &interpreter);

View File

@ -56,11 +56,18 @@ CommandObjectScript::ExecuteRawCommandString
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();
}

View File

@ -25,10 +25,11 @@ ScriptInterpreterNone::~ScriptInterpreterNone ()
{
}
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

View File

@ -258,17 +258,28 @@ ScriptInterpreterPython::~ScriptInterpreterPython ()
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;
}

View File

@ -21,6 +21,8 @@ class TestCommandSource(lldbtest.TestBase):
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)