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,
36 "Pass an expression to the script interpreter for evaluation and return the results. Drop into the interactive interpreter if no expression is given.",
37 "script [<script-expression-for-evaluation>]")
41 CommandObjectScript::~CommandObjectScript ()
46 CommandObjectScript::DoExecute
49 CommandReturnObject &result
52 #ifdef LLDB_DISABLE_PYTHON
53 // if we ever support languages other than Python this simple #ifdef won't work
54 result.AppendError("your copy of LLDB does not support scripting.");
55 result.SetStatus (eReturnStatusFailed);
58 if (m_interpreter.GetDebugger().GetScriptLanguage() == lldb::eScriptLanguageNone)
60 result.AppendError("the script-lang setting is set to none - scripting not available");
61 result.SetStatus (eReturnStatusFailed);
65 ScriptInterpreter *script_interpreter = m_interpreter.GetScriptInterpreter ();
67 if (script_interpreter == nullptr)
69 result.AppendError("no script interpreter");
70 result.SetStatus (eReturnStatusFailed);
74 DataVisualization::ForceUpdate(); // script might change Python code we use for formatting.. make sure we keep up to date with it
76 if (command == nullptr || command[0] == '\0')
78 script_interpreter->ExecuteInterpreterLoop ();
79 result.SetStatus (eReturnStatusSuccessFinishNoResult);
80 return result.Succeeded();
83 // We can do better when reporting the status of one-liner script execution.
84 if (script_interpreter->ExecuteOneLine (command, &result))
85 result.SetStatus(eReturnStatusSuccessFinishNoResult);
87 result.SetStatus(eReturnStatusFailed);
89 return result.Succeeded();