1 //===-- ScriptInterpreter.h -------------------------------------*- 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 #ifndef liblldb_ScriptInterpreter_h_
11 #define liblldb_ScriptInterpreter_h_
15 // Other libraries and framework includes
17 #include "lldb/lldb-private.h"
19 #include "lldb/Breakpoint/BreakpointOptions.h"
20 #include "lldb/Core/Broadcaster.h"
21 #include "lldb/Core/PluginInterface.h"
22 #include "lldb/Utility/Status.h"
23 #include "lldb/Utility/StructuredData.h"
25 #include "lldb/Host/PseudoTerminal.h"
27 namespace lldb_private {
29 class ScriptInterpreterLocker {
31 ScriptInterpreterLocker() = default;
33 virtual ~ScriptInterpreterLocker() = default;
36 DISALLOW_COPY_AND_ASSIGN(ScriptInterpreterLocker);
39 class ScriptInterpreter : public PluginInterface {
42 eScriptReturnTypeCharPtr,
43 eScriptReturnTypeBool,
44 eScriptReturnTypeShortInt,
45 eScriptReturnTypeShortIntUnsigned,
47 eScriptReturnTypeIntUnsigned,
48 eScriptReturnTypeLongInt,
49 eScriptReturnTypeLongIntUnsigned,
50 eScriptReturnTypeLongLong,
51 eScriptReturnTypeLongLongUnsigned,
52 eScriptReturnTypeFloat,
53 eScriptReturnTypeDouble,
54 eScriptReturnTypeChar,
55 eScriptReturnTypeCharStrOrNone,
56 eScriptReturnTypeOpaqueObject
59 ScriptInterpreter(CommandInterpreter &interpreter,
60 lldb::ScriptLanguage script_lang);
62 ~ScriptInterpreter() override;
64 struct ExecuteScriptOptions {
66 ExecuteScriptOptions()
67 : m_enable_io(true), m_set_lldb_globals(true), m_maskout_errors(true) {}
69 bool GetEnableIO() const { return m_enable_io; }
71 bool GetSetLLDBGlobals() const { return m_set_lldb_globals; }
73 bool GetMaskoutErrors() const { return m_maskout_errors; }
75 ExecuteScriptOptions &SetEnableIO(bool enable) {
80 ExecuteScriptOptions &SetSetLLDBGlobals(bool set) {
81 m_set_lldb_globals = set;
85 ExecuteScriptOptions &SetMaskoutErrors(bool maskout) {
86 m_maskout_errors = maskout;
92 bool m_set_lldb_globals;
93 bool m_maskout_errors;
96 virtual bool Interrupt() { return false; }
98 virtual bool ExecuteOneLine(
99 llvm::StringRef command, CommandReturnObject *result,
100 const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0;
102 virtual void ExecuteInterpreterLoop() = 0;
104 virtual bool ExecuteOneLineWithReturn(
105 llvm::StringRef in_string, ScriptReturnType return_type, void *ret_value,
106 const ExecuteScriptOptions &options = ExecuteScriptOptions()) {
110 virtual Status ExecuteMultipleLines(
111 const char *in_string,
112 const ExecuteScriptOptions &options = ExecuteScriptOptions()) {
114 error.SetErrorString("not implemented");
119 ExportFunctionDefinitionToInterpreter(StringList &function_def) {
121 error.SetErrorString("not implemented");
125 virtual Status GenerateBreakpointCommandCallbackData(StringList &input,
126 std::string &output) {
128 error.SetErrorString("not implemented");
132 virtual bool GenerateWatchpointCommandCallbackData(StringList &input,
133 std::string &output) {
137 virtual bool GenerateTypeScriptFunction(const char *oneliner,
139 const void *name_token = nullptr) {
143 virtual bool GenerateTypeScriptFunction(StringList &input,
145 const void *name_token = nullptr) {
149 virtual bool GenerateScriptAliasFunction(StringList &input,
150 std::string &output) {
154 virtual bool GenerateTypeSynthClass(StringList &input, std::string &output,
155 const void *name_token = nullptr) {
159 virtual bool GenerateTypeSynthClass(const char *oneliner, std::string &output,
160 const void *name_token = nullptr) {
164 virtual StructuredData::ObjectSP
165 CreateSyntheticScriptedProvider(const char *class_name,
166 lldb::ValueObjectSP valobj) {
167 return StructuredData::ObjectSP();
170 virtual StructuredData::GenericSP
171 CreateScriptCommandObject(const char *class_name) {
172 return StructuredData::GenericSP();
175 virtual StructuredData::GenericSP
176 OSPlugin_CreatePluginObject(const char *class_name,
177 lldb::ProcessSP process_sp) {
178 return StructuredData::GenericSP();
181 virtual StructuredData::DictionarySP
182 OSPlugin_RegisterInfo(StructuredData::ObjectSP os_plugin_object_sp) {
183 return StructuredData::DictionarySP();
186 virtual StructuredData::ArraySP
187 OSPlugin_ThreadsInfo(StructuredData::ObjectSP os_plugin_object_sp) {
188 return StructuredData::ArraySP();
191 virtual StructuredData::StringSP
192 OSPlugin_RegisterContextData(StructuredData::ObjectSP os_plugin_object_sp,
193 lldb::tid_t thread_id) {
194 return StructuredData::StringSP();
197 virtual StructuredData::DictionarySP
198 OSPlugin_CreateThread(StructuredData::ObjectSP os_plugin_object_sp,
199 lldb::tid_t tid, lldb::addr_t context) {
200 return StructuredData::DictionarySP();
203 virtual StructuredData::ObjectSP
204 CreateScriptedThreadPlan(const char *class_name,
205 lldb::ThreadPlanSP thread_plan_sp) {
206 return StructuredData::ObjectSP();
210 ScriptedThreadPlanExplainsStop(StructuredData::ObjectSP implementor_sp,
211 Event *event, bool &script_error) {
217 ScriptedThreadPlanShouldStop(StructuredData::ObjectSP implementor_sp,
218 Event *event, bool &script_error) {
224 ScriptedThreadPlanIsStale(StructuredData::ObjectSP implementor_sp,
225 bool &script_error) {
230 virtual lldb::StateType
231 ScriptedThreadPlanGetRunState(StructuredData::ObjectSP implementor_sp,
232 bool &script_error) {
234 return lldb::eStateStepping;
237 virtual StructuredData::ObjectSP
238 LoadPluginModule(const FileSpec &file_spec, lldb_private::Status &error) {
239 return StructuredData::ObjectSP();
242 virtual StructuredData::DictionarySP
243 GetDynamicSettings(StructuredData::ObjectSP plugin_module_sp, Target *target,
244 const char *setting_name, lldb_private::Status &error) {
245 return StructuredData::DictionarySP();
248 virtual Status GenerateFunction(const char *signature,
249 const StringList &input) {
251 error.SetErrorString("unimplemented");
255 virtual void CollectDataForBreakpointCommandCallback(
256 std::vector<BreakpointOptions *> &options, CommandReturnObject &result);
259 CollectDataForWatchpointCommandCallback(WatchpointOptions *wp_options,
260 CommandReturnObject &result);
262 /// Set the specified text as the callback for the breakpoint.
264 SetBreakpointCommandCallback(std::vector<BreakpointOptions *> &bp_options_vec,
265 const char *callback_text);
267 virtual Status SetBreakpointCommandCallback(BreakpointOptions *bp_options,
268 const char *callback_text) {
270 error.SetErrorString("unimplemented");
274 /// This one is for deserialization:
275 virtual Status SetBreakpointCommandCallback(
276 BreakpointOptions *bp_options,
277 std::unique_ptr<BreakpointOptions::CommandData> &data_up) {
279 error.SetErrorString("unimplemented");
283 void SetBreakpointCommandCallbackFunction(
284 std::vector<BreakpointOptions *> &bp_options_vec,
285 const char *function_name);
287 /// Set a one-liner as the callback for the breakpoint.
289 SetBreakpointCommandCallbackFunction(BreakpointOptions *bp_options,
290 const char *function_name) {}
292 /// Set a one-liner as the callback for the watchpoint.
293 virtual void SetWatchpointCommandCallback(WatchpointOptions *wp_options,
294 const char *oneliner) {}
296 virtual bool GetScriptedSummary(const char *function_name,
297 lldb::ValueObjectSP valobj,
298 StructuredData::ObjectSP &callee_wrapper_sp,
299 const TypeSummaryOptions &options,
300 std::string &retval) {
304 virtual void Clear() {
305 // Clean up any ref counts to SBObjects that might be in global variables
309 CalculateNumChildren(const StructuredData::ObjectSP &implementor,
314 virtual lldb::ValueObjectSP
315 GetChildAtIndex(const StructuredData::ObjectSP &implementor, uint32_t idx) {
316 return lldb::ValueObjectSP();
320 GetIndexOfChildWithName(const StructuredData::ObjectSP &implementor,
321 const char *child_name) {
326 UpdateSynthProviderInstance(const StructuredData::ObjectSP &implementor) {
330 virtual bool MightHaveChildrenSynthProviderInstance(
331 const StructuredData::ObjectSP &implementor) {
335 virtual lldb::ValueObjectSP
336 GetSyntheticValue(const StructuredData::ObjectSP &implementor) {
341 GetSyntheticTypeName(const StructuredData::ObjectSP &implementor) {
342 return ConstString();
346 RunScriptBasedCommand(const char *impl_function, llvm::StringRef args,
347 ScriptedCommandSynchronicity synchronicity,
348 lldb_private::CommandReturnObject &cmd_retobj,
350 const lldb_private::ExecutionContext &exe_ctx) {
354 virtual bool RunScriptBasedCommand(
355 StructuredData::GenericSP impl_obj_sp, llvm::StringRef args,
356 ScriptedCommandSynchronicity synchronicity,
357 lldb_private::CommandReturnObject &cmd_retobj, Status &error,
358 const lldb_private::ExecutionContext &exe_ctx) {
362 virtual bool RunScriptFormatKeyword(const char *impl_function,
363 Process *process, std::string &output,
365 error.SetErrorString("unimplemented");
369 virtual bool RunScriptFormatKeyword(const char *impl_function, Thread *thread,
370 std::string &output, Status &error) {
371 error.SetErrorString("unimplemented");
375 virtual bool RunScriptFormatKeyword(const char *impl_function, Target *target,
376 std::string &output, Status &error) {
377 error.SetErrorString("unimplemented");
381 virtual bool RunScriptFormatKeyword(const char *impl_function,
382 StackFrame *frame, std::string &output,
384 error.SetErrorString("unimplemented");
388 virtual bool RunScriptFormatKeyword(const char *impl_function,
389 ValueObject *value, std::string &output,
391 error.SetErrorString("unimplemented");
395 virtual bool GetDocumentationForItem(const char *item, std::string &dest) {
401 GetShortHelpForCommandObject(StructuredData::GenericSP cmd_obj_sp,
408 GetFlagsForCommandObject(StructuredData::GenericSP cmd_obj_sp) {
412 virtual bool GetLongHelpForCommandObject(StructuredData::GenericSP cmd_obj_sp,
418 virtual bool CheckObjectExists(const char *name) { return false; }
421 LoadScriptingModule(const char *filename, bool can_reload, bool init_session,
422 lldb_private::Status &error,
423 StructuredData::ObjectSP *module_sp = nullptr) {
424 error.SetErrorString("loading unimplemented");
428 virtual bool IsReservedWord(const char *word) { return false; }
430 virtual std::unique_ptr<ScriptInterpreterLocker> AcquireInterpreterLock();
432 const char *GetScriptInterpreterPtyName();
434 int GetMasterFileDescriptor();
436 CommandInterpreter &GetCommandInterpreter();
438 static std::string LanguageToString(lldb::ScriptLanguage language);
440 static lldb::ScriptLanguage StringToLanguage(const llvm::StringRef &string);
442 virtual void ResetOutputFileHandle(FILE *new_fh) {} // By default, do nothing.
444 lldb::ScriptLanguage GetLanguage() { return m_script_lang; }
447 CommandInterpreter &m_interpreter;
448 lldb::ScriptLanguage m_script_lang;
451 } // namespace lldb_private
453 #endif // liblldb_ScriptInterpreter_h_