1 //===-- CommandObjectScript.cpp ---------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "CommandObjectScript.h"
14 // Other libraries and framework includes
17 #include "lldb/Core/Debugger.h"
19 #include "lldb/DataFormatters/DataVisualization.h"
21 #include "lldb/Interpreter/Args.h"
22 #include "lldb/Interpreter/CommandInterpreter.h"
23 #include "lldb/Interpreter/CommandReturnObject.h"
24 #include "lldb/Interpreter/ScriptInterpreter.h"
27 using namespace lldb_private;
29 //-------------------------------------------------------------------------
30 // CommandObjectScript
31 //-------------------------------------------------------------------------
33 CommandObjectScript::CommandObjectScript(CommandInterpreter &interpreter, ScriptLanguage script_lang)
34 : CommandObjectRaw(interpreter, "script", "Invoke the script interpreter with provided code and display any "
35 "results. Start the interactive interpreter if no code is supplied.",
36 "script [<script-code>]")
40 CommandObjectScript::~CommandObjectScript ()
45 CommandObjectScript::DoExecute
48 CommandReturnObject &result
51 #ifdef LLDB_DISABLE_PYTHON
52 // if we ever support languages other than Python this simple #ifdef won't work
53 result.AppendError("your copy of LLDB does not support scripting.");
54 result.SetStatus (eReturnStatusFailed);
57 if (m_interpreter.GetDebugger().GetScriptLanguage() == lldb::eScriptLanguageNone)
59 result.AppendError("the script-lang setting is set to none - scripting not available");
60 result.SetStatus (eReturnStatusFailed);
64 ScriptInterpreter *script_interpreter = m_interpreter.GetScriptInterpreter ();
66 if (script_interpreter == nullptr)
68 result.AppendError("no script interpreter");
69 result.SetStatus (eReturnStatusFailed);
73 DataVisualization::ForceUpdate(); // script might change Python code we use for formatting.. make sure we keep up to date with it
75 if (command == nullptr || command[0] == '\0')
77 script_interpreter->ExecuteInterpreterLoop ();
78 result.SetStatus (eReturnStatusSuccessFinishNoResult);
79 return result.Succeeded();
82 // We can do better when reporting the status of one-liner script execution.
83 if (script_interpreter->ExecuteOneLine (command, &result))
84 result.SetStatus(eReturnStatusSuccessFinishNoResult);
86 result.SetStatus(eReturnStatusFailed);
88 return result.Succeeded();