LLDB  mainline
CommandObjectScript.cpp
Go to the documentation of this file.
1 //===-- CommandObjectScript.cpp -------------------------------------------===//
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 #include "lldb/Core/Debugger.h"
12 #include "lldb/Host/Config.h"
16 #include "lldb/Utility/Args.h"
17 
18 using namespace lldb;
19 using namespace lldb_private;
20 
21 // CommandObjectScript
22 
23 CommandObjectScript::CommandObjectScript(CommandInterpreter &interpreter,
24  ScriptLanguage script_lang)
26  interpreter, "script",
27  "Invoke the script interpreter with provided code and display any "
28  "results. Start the interactive interpreter if no code is supplied.",
29  "script [<script-code>]") {}
30 
32 
33 bool CommandObjectScript::DoExecute(llvm::StringRef command,
34  CommandReturnObject &result) {
37  result.AppendError(
38  "the script-lang setting is set to none - scripting not available");
40  return false;
41  }
42 
43  ScriptInterpreter *script_interpreter = GetDebugger().GetScriptInterpreter();
44 
45  if (script_interpreter == nullptr) {
46  result.AppendError("no script interpreter");
48  return false;
49  }
50 
51  // Script might change Python code we use for formatting. Make sure we keep
52  // up to date with it.
54 
55  if (command.empty()) {
56  script_interpreter->ExecuteInterpreterLoop();
58  return result.Succeeded();
59  }
60 
61  // We can do better when reporting the status of one-liner script execution.
62  if (script_interpreter->ExecuteOneLine(command, &result))
64  else
66 
67  return result.Succeeded();
68 }
A class that represents a running process on the host machine.
CommandInterpreter & m_interpreter
virtual bool ExecuteOneLine(llvm::StringRef command, CommandReturnObject *result, const ExecuteScriptOptions &options=ExecuteScriptOptions())=0
ScriptInterpreter * GetScriptInterpreter(bool can_create=true, llvm::Optional< lldb::ScriptLanguage > language={})
Definition: Debugger.cpp:1182
lldb::ScriptLanguage GetScriptLanguage() const
Definition: Debugger.cpp:299
void void AppendError(llvm::StringRef in_string)
Definition: SBAddress.h:15
virtual void ExecuteInterpreterLoop()=0
void SetStatus(lldb::ReturnStatus status)
ScriptLanguage
Script interpreter types.
bool DoExecute(llvm::StringRef command, CommandReturnObject &result) override