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/CommandInterpreter.h"
22 #include "lldb/Interpreter/CommandReturnObject.h"
23 #include "lldb/Interpreter/ScriptInterpreter.h"
24 #include "lldb/Utility/Args.h"
27 using namespace lldb_private;
29 //-------------------------------------------------------------------------
30 // CommandObjectScript
31 //-------------------------------------------------------------------------
33 CommandObjectScript::CommandObjectScript(CommandInterpreter &interpreter,
34 ScriptLanguage script_lang)
36 interpreter, "script",
37 "Invoke the script interpreter with provided code and display any "
38 "results. Start the interactive interpreter if no code is supplied.",
39 "script [<script-code>]") {}
41 CommandObjectScript::~CommandObjectScript() {}
43 bool CommandObjectScript::DoExecute(llvm::StringRef command,
44 CommandReturnObject &result) {
45 #ifdef LLDB_DISABLE_PYTHON
46 // if we ever support languages other than Python this simple #ifdef won't
48 result.AppendError("your copy of LLDB does not support scripting.");
49 result.SetStatus(eReturnStatusFailed);
52 if (m_interpreter.GetDebugger().GetScriptLanguage() ==
53 lldb::eScriptLanguageNone) {
55 "the script-lang setting is set to none - scripting not available");
56 result.SetStatus(eReturnStatusFailed);
60 ScriptInterpreter *script_interpreter = m_interpreter.GetScriptInterpreter();
62 if (script_interpreter == nullptr) {
63 result.AppendError("no script interpreter");
64 result.SetStatus(eReturnStatusFailed);
68 DataVisualization::ForceUpdate(); // script might change Python code we use
69 // for formatting.. make sure we keep up to
72 if (command.empty()) {
73 script_interpreter->ExecuteInterpreterLoop();
74 result.SetStatus(eReturnStatusSuccessFinishNoResult);
75 return result.Succeeded();
78 // We can do better when reporting the status of one-liner script execution.
79 if (script_interpreter->ExecuteOneLine(command, &result))
80 result.SetStatus(eReturnStatusSuccessFinishNoResult);
82 result.SetStatus(eReturnStatusFailed);
84 return result.Succeeded();