]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Interpreter/CommandObjectScript.cpp
Import bhyve_graphics into CURRENT. Thanks to all who tested
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Interpreter / CommandObjectScript.cpp
1 //===-- CommandObjectScript.cpp ---------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "CommandObjectScript.h"
11
12 // C Includes
13 // C++ Includes
14 // Other libraries and framework includes
15 // Project includes
16
17 #include "lldb/Core/Debugger.h"
18
19 #include "lldb/DataFormatters/DataVisualization.h"
20
21 #include "lldb/Interpreter/Args.h"
22 #include "lldb/Interpreter/CommandInterpreter.h"
23 #include "lldb/Interpreter/CommandReturnObject.h"
24 #include "lldb/Interpreter/ScriptInterpreter.h"
25
26 using namespace lldb;
27 using namespace lldb_private;
28
29 //-------------------------------------------------------------------------
30 // CommandObjectScript
31 //-------------------------------------------------------------------------
32
33 CommandObjectScript::CommandObjectScript (CommandInterpreter &interpreter, ScriptLanguage script_lang) :
34     CommandObjectRaw (interpreter, 
35                       "script",
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>]")
38 {
39 }
40
41 CommandObjectScript::~CommandObjectScript ()
42 {
43 }
44
45 bool
46 CommandObjectScript::DoExecute
47 (
48     const char *command,
49     CommandReturnObject &result
50 )
51 {
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);
56     return false;
57 #else
58     if (m_interpreter.GetDebugger().GetScriptLanguage() == lldb::eScriptLanguageNone)
59     {
60         result.AppendError("the script-lang setting is set to none - scripting not available");
61         result.SetStatus (eReturnStatusFailed);
62         return false;
63     }
64     
65     ScriptInterpreter *script_interpreter = m_interpreter.GetScriptInterpreter ();
66
67     if (script_interpreter == nullptr)
68     {
69         result.AppendError("no script interpreter");
70         result.SetStatus (eReturnStatusFailed);
71         return false;
72     }
73
74     DataVisualization::ForceUpdate(); // script might change Python code we use for formatting.. make sure we keep up to date with it
75     
76     if (command == nullptr || command[0] == '\0')
77     {
78         script_interpreter->ExecuteInterpreterLoop ();
79         result.SetStatus (eReturnStatusSuccessFinishNoResult);
80         return result.Succeeded();
81     }
82
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);
86     else
87         result.SetStatus(eReturnStatusFailed);
88
89     return result.Succeeded();
90 #endif
91 }