LLDB  mainline
CommandObjectScript.cpp
Go to the documentation of this file.
1 //===-- CommandObjectScript.cpp ---------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "CommandObjectScript.h"
10 
11 
12 #include "lldb/Core/Debugger.h"
13 
15 
19 #include "lldb/Utility/Args.h"
20 
21 using namespace lldb;
22 using namespace lldb_private;
23 
24 // CommandObjectScript
25 
26 CommandObjectScript::CommandObjectScript(CommandInterpreter &interpreter,
27  ScriptLanguage script_lang)
29  interpreter, "script",
30  "Invoke the script interpreter with provided code and display any "
31  "results. Start the interactive interpreter if no code is supplied.",
32  "script [<script-code>]") {}
33 
35 
36 bool CommandObjectScript::DoExecute(llvm::StringRef command,
37  CommandReturnObject &result) {
38 #ifdef LLDB_DISABLE_PYTHON
39  // if we ever support languages other than Python this simple #ifdef won't
40  // work
41  result.AppendError("your copy of LLDB does not support scripting.");
43  return false;
44 #else
47  result.AppendError(
48  "the script-lang setting is set to none - scripting not available");
50  return false;
51  }
52 
53  ScriptInterpreter *script_interpreter = GetDebugger().GetScriptInterpreter();
54 
55  if (script_interpreter == nullptr) {
56  result.AppendError("no script interpreter");
58  return false;
59  }
60 
61  DataVisualization::ForceUpdate(); // script might change Python code we use
62  // for formatting.. make sure we keep up to
63  // date with it
64 
65  if (command.empty()) {
66  script_interpreter->ExecuteInterpreterLoop();
68  return result.Succeeded();
69  }
70 
71  // We can do better when reporting the status of one-liner script execution.
72  if (script_interpreter->ExecuteOneLine(command, &result))
74  else
76 
77  return result.Succeeded();
78 #endif
79 }
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
CommandInterpreter & m_interpreter
virtual bool ExecuteOneLine(llvm::StringRef command, CommandReturnObject *result, const ExecuteScriptOptions &options=ExecuteScriptOptions())=0
lldb::ScriptLanguage GetScriptLanguage() const
Definition: Debugger.cpp:430
ScriptInterpreter * GetScriptInterpreter(bool can_create=true)
Definition: Debugger.cpp:1289
void void AppendError(llvm::StringRef in_string)
Definition: SBAddress.h:15
virtual void ExecuteInterpreterLoop()=0
void SetStatus(lldb::ReturnStatus status)
bool DoExecute(llvm::StringRef command, CommandReturnObject &result) override