LLDB mainline
ScriptInterpreterNone.cpp
Go to the documentation of this file.
1//===-- ScriptInterpreterNone.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
10#include "lldb/Core/Debugger.h"
12#include "lldb/Host/Config.h"
13#include "lldb/Utility/Stream.h"
15#include "llvm/Support/ErrorExtras.h"
16
17using namespace lldb;
18using namespace lldb_private;
19
21
23 Debugger &debugger, lldb::ScriptLanguage requested_language)
25 m_requested_language(requested_language) {}
26
28
29static bool IsBuiltWith(lldb::ScriptLanguage language) {
30 switch (language) {
32 return LLDB_ENABLE_PYTHON;
34 return LLDB_ENABLE_LUA;
35 default:
36 return false;
37 }
38}
39
41 llvm::Error error =
43 // A plugin library that failed to load leaves no error behind.
45 error = llvm::createStringError("its plugin was not loaded");
46 if (error)
47 return llvm::createStringErrorV("{0} scripting is unavailable: {1}",
49 llvm::toString(std::move(error)));
50 return llvm::Error::success();
51}
52
53static llvm::Error CreateNoScriptingError() {
54 return llvm::createStringError(
55 "Embedded script interpreter unavailable. LLDB was built without "
56 "scripting language support.");
57}
58
59bool ScriptInterpreterNone::ExecuteOneLine(llvm::StringRef command,
60 CommandReturnObject *result,
61 const ExecuteScriptOptions &) {
62 llvm::Error error = GetUnavailableError();
63 if (!error)
65 if (result)
66 result->AppendError(llvm::toString(std::move(error)));
67 else
68 m_debugger.GetAsyncErrorStream()->Printf(
69 "error: %s\n", llvm::toString(std::move(error)).c_str());
70 return false;
71}
72
74 if (llvm::Error error = GetUnavailableError())
75 return error;
77}
78
80 const char *filename, const LoadScriptOptions &options, Status &error,
81 StructuredData::ObjectSP *module_sp, FileSpec extra_search_dir,
82 lldb::TargetSP loaded_into_target_sp) {
83 if (llvm::Error unavailable = GetUnavailableError()) {
84 error = Status::FromError(std::move(unavailable));
85 return false;
86 }
87 return ScriptInterpreter::LoadScriptingModule(filename, options, error,
88 module_sp, extra_search_dir,
89 loaded_into_target_sp);
90}
91
93 std::vector<std::reference_wrapper<BreakpointOptions>> &options,
94 CommandReturnObject &result) {
95 if (llvm::Error unavailable = GetUnavailableError())
96 result.AppendError(llvm::toString(std::move(unavailable)));
97 else
99}
100
102 WatchpointOptions *wp_options, CommandReturnObject &result) {
103 if (llvm::Error unavailable = GetUnavailableError())
104 result.AppendError(llvm::toString(std::move(unavailable)));
105 else
107 result);
108}
109
111 BreakpointOptions &bp_options, const char *callback_text,
112 bool is_callback) {
113 if (llvm::Error unavailable = GetUnavailableError())
114 return unavailable;
116 bp_options, callback_text, is_callback);
117}
118
120 BreakpointOptions &bp_options, const char *function_name,
121 StructuredData::ObjectSP extra_args_sp) {
122 if (llvm::Error unavailable = GetUnavailableError())
123 return unavailable;
125 bp_options, function_name, extra_args_sp);
126}
127
129 WatchpointOptions *wp_options, const char *user_input, bool is_callback) {
130 if (llvm::Error unavailable = GetUnavailableError())
131 return unavailable;
132 return ScriptInterpreter::SetWatchpointCommandCallback(wp_options, user_input,
133 is_callback);
134}
135
141
145
148 lldb::ScriptLanguage requested_language) {
149 return std::make_shared<ScriptInterpreterNone>(debugger, requested_language);
150}
151
153 return "Null script interpreter";
154}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_PLUGIN_DEFINE(PluginName)
static llvm::Error CreateNoScriptingError()
static bool IsBuiltWith(lldb::ScriptLanguage language)
"lldb/Breakpoint/BreakpointOptions.h" Class that manages the options on a breakpoint or breakpoint lo...
void AppendError(llvm::StringRef in_string)
A class to manage flag bits.
Definition Debugger.h:106
A file utility class.
Definition FileSpec.h:56
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static llvm::Error GetScriptInterpreterError(lldb::ScriptLanguage script_lang)
Returns the error recorded for script_lang, or success.
static bool UnregisterPlugin(ABICreateInstance create_callback)
Stands in for a script language without an interpreter, reporting why it is unavailable.
llvm::Error SetBreakpointCommandCallback(BreakpointOptions &bp_options, const char *callback_text, bool is_callback) override
static lldb::ScriptInterpreterSP CreateInstance(Debugger &debugger, lldb::ScriptLanguage requested_language)
llvm::Error GetUnavailableError() const
Returns the error recorded for the requested language, or success.
bool ExecuteOneLine(llvm::StringRef command, CommandReturnObject *result, const ExecuteScriptOptions &options=ExecuteScriptOptions()) override
static llvm::StringRef GetPluginNameStatic()
void CollectDataForWatchpointCommandCallback(WatchpointOptions *wp_options, CommandReturnObject &result) override
llvm::Error SetBreakpointCommandCallbackFunction(BreakpointOptions &bp_options, const char *function_name, StructuredData::ObjectSP extra_args_sp) override
Set a script function as the callback for the breakpoint.
ScriptInterpreterNone(Debugger &debugger, lldb::ScriptLanguage requested_language)
static llvm::StringRef GetPluginDescriptionStatic()
void CollectDataForBreakpointCommandCallback(std::vector< std::reference_wrapper< BreakpointOptions > > &options, CommandReturnObject &result) override
llvm::Error SetWatchpointCommandCallback(WatchpointOptions *wp_options, const char *user_input, bool is_callback) override
Set a one-liner as the callback for the watchpoint.
bool LoadScriptingModule(const char *filename, const LoadScriptOptions &options, lldb_private::Status &error, StructuredData::ObjectSP *module_sp=nullptr, FileSpec extra_search_dir={}, lldb::TargetSP loaded_into_target_sp={}) override
virtual void CollectDataForBreakpointCommandCallback(std::vector< std::reference_wrapper< BreakpointOptions > > &options, CommandReturnObject &result)
virtual llvm::Error SetWatchpointCommandCallback(WatchpointOptions *wp_options, const char *user_input, bool is_callback)
Set a one-liner as the callback for the watchpoint.
virtual bool LoadScriptingModule(const char *filename, const LoadScriptOptions &options, lldb_private::Status &error, StructuredData::ObjectSP *module_sp=nullptr, FileSpec extra_search_dir={}, lldb::TargetSP loaded_into_target_sp={})
static std::string LanguageToString(lldb::ScriptLanguage language)
llvm::Error SetBreakpointCommandCallbackFunction(std::vector< std::reference_wrapper< BreakpointOptions > > &bp_options_vec, const char *function_name, StructuredData::ObjectSP extra_args_sp)
llvm::Error SetBreakpointCommandCallback(std::vector< std::reference_wrapper< BreakpointOptions > > &bp_options_vec, const char *callback_text)
Set the specified text as the callback for the breakpoint.
ScriptInterpreter(Debugger &debugger, lldb::ScriptLanguage script_lang)
virtual void CollectDataForWatchpointCommandCallback(WatchpointOptions *wp_options, CommandReturnObject &result)
An error handling class.
Definition Status.h:118
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Definition Status.cpp:136
std::shared_ptr< Object > ObjectSP
"lldb/Breakpoint/WatchpointOptions.h" Class that manages the options on a watchpoint.
A class that represents a running process on the host machine.
ScriptLanguage
Script interpreter types.
@ eScriptLanguageNone
@ eScriptLanguagePython
std::shared_ptr< lldb_private::ScriptInterpreter > ScriptInterpreterSP
std::shared_ptr< lldb_private::Target > TargetSP