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 "lldb/lldb-python.h"
12 #include "CommandObjectScript.h"
16 // Other libraries and framework includes
19 #include "lldb/Core/Debugger.h"
21 #include "lldb/DataFormatters/DataVisualization.h"
23 #include "lldb/Interpreter/Args.h"
24 #include "lldb/Interpreter/CommandInterpreter.h"
25 #include "lldb/Interpreter/CommandReturnObject.h"
26 #include "lldb/Interpreter/ScriptInterpreter.h"
29 using namespace lldb_private;
31 //-------------------------------------------------------------------------
32 // CommandObjectScript
33 //-------------------------------------------------------------------------
35 CommandObjectScript::CommandObjectScript (CommandInterpreter &interpreter, ScriptLanguage script_lang) :
36 CommandObjectRaw (interpreter,
38 "Pass an expression to the script interpreter for evaluation and return the results. Drop into the interactive interpreter if no expression is given.",
39 "script [<script-expression-for-evaluation>]")
43 CommandObjectScript::~CommandObjectScript ()
48 CommandObjectScript::DoExecute
51 CommandReturnObject &result
54 #ifdef LLDB_DISABLE_PYTHON
55 // if we ever support languages other than Python this simple #ifdef won't work
56 result.AppendError("your copy of LLDB does not support scripting.");
57 result.SetStatus (eReturnStatusFailed);
60 if (m_interpreter.GetDebugger().GetScriptLanguage() == lldb::eScriptLanguageNone)
62 result.AppendError("the script-lang setting is set to none - scripting not available");
63 result.SetStatus (eReturnStatusFailed);
67 ScriptInterpreter *script_interpreter = m_interpreter.GetScriptInterpreter ();
69 if (script_interpreter == nullptr)
71 result.AppendError("no script interpreter");
72 result.SetStatus (eReturnStatusFailed);
76 DataVisualization::ForceUpdate(); // script might change Python code we use for formatting.. make sure we keep up to date with it
78 if (command == nullptr || command[0] == '\0')
80 script_interpreter->ExecuteInterpreterLoop ();
81 result.SetStatus (eReturnStatusSuccessFinishNoResult);
82 return result.Succeeded();
85 // We can do better when reporting the status of one-liner script execution.
86 if (script_interpreter->ExecuteOneLine (command, &result))
87 result.SetStatus(eReturnStatusSuccessFinishNoResult);
89 result.SetStatus(eReturnStatusFailed);
91 return result.Succeeded();