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"
13 #include "lldb/Core/Debugger.h"
15 #include "lldb/DataFormatters/DataVisualization.h"
17 #include "lldb/Interpreter/CommandInterpreter.h"
18 #include "lldb/Interpreter/CommandReturnObject.h"
19 #include "lldb/Interpreter/ScriptInterpreter.h"
20 #include "lldb/Utility/Args.h"
23 using namespace lldb_private;
25 //-------------------------------------------------------------------------
26 // CommandObjectScript
27 //-------------------------------------------------------------------------
29 CommandObjectScript::CommandObjectScript(CommandInterpreter &interpreter,
30 ScriptLanguage script_lang)
32 interpreter, "script",
33 "Invoke the script interpreter with provided code and display any "
34 "results. Start the interactive interpreter if no code is supplied.",
35 "script [<script-code>]") {}
37 CommandObjectScript::~CommandObjectScript() {}
39 bool CommandObjectScript::DoExecute(llvm::StringRef command,
40 CommandReturnObject &result) {
41 #ifdef LLDB_DISABLE_PYTHON
42 // if we ever support languages other than Python this simple #ifdef won't
44 result.AppendError("your copy of LLDB does not support scripting.");
45 result.SetStatus(eReturnStatusFailed);
48 if (m_interpreter.GetDebugger().GetScriptLanguage() ==
49 lldb::eScriptLanguageNone) {
51 "the script-lang setting is set to none - scripting not available");
52 result.SetStatus(eReturnStatusFailed);
56 ScriptInterpreter *script_interpreter = m_interpreter.GetScriptInterpreter();
58 if (script_interpreter == nullptr) {
59 result.AppendError("no script interpreter");
60 result.SetStatus(eReturnStatusFailed);
64 DataVisualization::ForceUpdate(); // script might change Python code we use
65 // for formatting.. make sure we keep up to
68 if (command.empty()) {
69 script_interpreter->ExecuteInterpreterLoop();
70 result.SetStatus(eReturnStatusSuccessFinishNoResult);
71 return result.Succeeded();
74 // We can do better when reporting the status of one-liner script execution.
75 if (script_interpreter->ExecuteOneLine(command, &result))
76 result.SetStatus(eReturnStatusSuccessFinishNoResult);
78 result.SetStatus(eReturnStatusFailed);
80 return result.Succeeded();