LLDB  mainline
ScriptInterpreter.h
Go to the documentation of this file.
1 //===-- ScriptInterpreter.h -------------------------------------*- 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 #ifndef liblldb_ScriptInterpreter_h_
10 #define liblldb_ScriptInterpreter_h_
11 
12 #include "lldb/lldb-private.h"
13 
16 #include "lldb/Core/SearchFilter.h"
18 #include "lldb/Utility/Status.h"
20 
22 
23 namespace lldb_private {
24 
26 public:
27  ScriptInterpreterLocker() = default;
28 
29  virtual ~ScriptInterpreterLocker() = default;
30 
31 private:
32  DISALLOW_COPY_AND_ASSIGN(ScriptInterpreterLocker);
33 };
34 
36 public:
37  typedef enum {
52  eScriptReturnTypeOpaqueObject
54 
55  ScriptInterpreter(Debugger &debugger, lldb::ScriptLanguage script_lang);
56 
57  ~ScriptInterpreter() override;
58 
60  public:
62  : m_enable_io(true), m_set_lldb_globals(true), m_maskout_errors(true) {}
63 
64  bool GetEnableIO() const { return m_enable_io; }
65 
66  bool GetSetLLDBGlobals() const { return m_set_lldb_globals; }
67 
68  bool GetMaskoutErrors() const { return m_maskout_errors; }
69 
71  m_enable_io = enable;
72  return *this;
73  }
74 
76  m_set_lldb_globals = set;
77  return *this;
78  }
79 
81  m_maskout_errors = maskout;
82  return *this;
83  }
84 
85  private:
86  bool m_enable_io;
87  bool m_set_lldb_globals;
88  bool m_maskout_errors;
89  };
90 
91  virtual bool Interrupt() { return false; }
92 
93  virtual bool ExecuteOneLine(
94  llvm::StringRef command, CommandReturnObject *result,
95  const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0;
96 
97  virtual void ExecuteInterpreterLoop() = 0;
98 
100  llvm::StringRef in_string, ScriptReturnType return_type, void *ret_value,
101  const ExecuteScriptOptions &options = ExecuteScriptOptions()) {
102  return true;
103  }
104 
106  const char *in_string,
107  const ExecuteScriptOptions &options = ExecuteScriptOptions()) {
108  Status error;
109  error.SetErrorString("not implemented");
110  return error;
111  }
112 
113  virtual Status
115  Status error;
116  error.SetErrorString("not implemented");
117  return error;
118  }
119 
121  std::string &output) {
122  Status error;
123  error.SetErrorString("not implemented");
124  return error;
125  }
126 
128  std::string &output) {
129  return false;
130  }
131 
132  virtual bool GenerateTypeScriptFunction(const char *oneliner,
133  std::string &output,
134  const void *name_token = nullptr) {
135  return false;
136  }
137 
139  std::string &output,
140  const void *name_token = nullptr) {
141  return false;
142  }
143 
145  std::string &output) {
146  return false;
147  }
148 
149  virtual bool GenerateTypeSynthClass(StringList &input, std::string &output,
150  const void *name_token = nullptr) {
151  return false;
152  }
153 
154  virtual bool GenerateTypeSynthClass(const char *oneliner, std::string &output,
155  const void *name_token = nullptr) {
156  return false;
157  }
158 
160  CreateSyntheticScriptedProvider(const char *class_name,
161  lldb::ValueObjectSP valobj) {
162  return StructuredData::ObjectSP();
163  }
164 
166  CreateScriptCommandObject(const char *class_name) {
167  return StructuredData::GenericSP();
168  }
169 
171  CreateFrameRecognizer(const char *class_name) {
172  return StructuredData::GenericSP();
173  }
174 
175  virtual lldb::ValueObjectListSP GetRecognizedArguments(
176  const StructuredData::ObjectSP &implementor,
177  lldb::StackFrameSP frame_sp) {
178  return lldb::ValueObjectListSP();
179  }
180 
182  OSPlugin_CreatePluginObject(const char *class_name,
183  lldb::ProcessSP process_sp) {
184  return StructuredData::GenericSP();
185  }
186 
190  }
191 
194  return StructuredData::ArraySP();
195  }
196 
199  lldb::tid_t thread_id) {
200  return StructuredData::StringSP();
201  }
202 
205  lldb::tid_t tid, lldb::addr_t context) {
207  }
208 
210  CreateScriptedThreadPlan(const char *class_name,
211  lldb::ThreadPlanSP thread_plan_sp) {
212  return StructuredData::ObjectSP();
213  }
214 
215  virtual bool
217  Event *event, bool &script_error) {
218  script_error = true;
219  return true;
220  }
221 
222  virtual bool
224  Event *event, bool &script_error) {
225  script_error = true;
226  return true;
227  }
228 
229  virtual bool
231  bool &script_error) {
232  script_error = true;
233  return true;
234  }
235 
236  virtual lldb::StateType
238  bool &script_error) {
239  script_error = true;
240  return lldb::eStateStepping;
241  }
242 
244  CreateScriptedBreakpointResolver(const char *class_name,
245  StructuredDataImpl *args_data,
246  lldb::BreakpointSP &bkpt_sp) {
247  return StructuredData::GenericSP();
248  }
249 
250  virtual bool
252  SymbolContext *sym_ctx)
253  {
254  return false;
255  }
256 
257  virtual lldb::SearchDepth
259  {
261  }
262 
264  LoadPluginModule(const FileSpec &file_spec, lldb_private::Status &error) {
265  return StructuredData::ObjectSP();
266  }
267 
270  const char *setting_name, lldb_private::Status &error) {
272  }
273 
274  virtual Status GenerateFunction(const char *signature,
275  const StringList &input) {
276  Status error;
277  error.SetErrorString("unimplemented");
278  return error;
279  }
280 
281  virtual void CollectDataForBreakpointCommandCallback(
282  std::vector<BreakpointOptions *> &options, CommandReturnObject &result);
283 
284  virtual void
285  CollectDataForWatchpointCommandCallback(WatchpointOptions *wp_options,
286  CommandReturnObject &result);
287 
288  /// Set the specified text as the callback for the breakpoint.
289  Status
290  SetBreakpointCommandCallback(std::vector<BreakpointOptions *> &bp_options_vec,
291  const char *callback_text);
292 
294  const char *callback_text) {
295  Status error;
296  error.SetErrorString("unimplemented");
297  return error;
298  }
299 
300  /// This one is for deserialization:
302  BreakpointOptions *bp_options,
303  std::unique_ptr<BreakpointOptions::CommandData> &data_up) {
304  Status error;
305  error.SetErrorString("unimplemented");
306  return error;
307  }
308 
309  void SetBreakpointCommandCallbackFunction(
310  std::vector<BreakpointOptions *> &bp_options_vec,
311  const char *function_name);
312 
313  /// Set a one-liner as the callback for the breakpoint.
314  virtual void
316  const char *function_name) {}
317 
318  /// Set a one-liner as the callback for the watchpoint.
320  const char *oneliner) {}
321 
322  virtual bool GetScriptedSummary(const char *function_name,
323  lldb::ValueObjectSP valobj,
324  StructuredData::ObjectSP &callee_wrapper_sp,
325  const TypeSummaryOptions &options,
326  std::string &retval) {
327  return false;
328  }
329 
330  virtual void Clear() {
331  // Clean up any ref counts to SBObjects that might be in global variables
332  }
333 
334  virtual size_t
336  uint32_t max) {
337  return 0;
338  }
339 
340  virtual lldb::ValueObjectSP
342  return lldb::ValueObjectSP();
343  }
344 
345  virtual int
347  const char *child_name) {
348  return UINT32_MAX;
349  }
350 
351  virtual bool
353  return false;
354  }
355 
357  const StructuredData::ObjectSP &implementor) {
358  return true;
359  }
360 
361  virtual lldb::ValueObjectSP
363  return nullptr;
364  }
365 
366  virtual ConstString
368  return ConstString();
369  }
370 
371  virtual bool
372  RunScriptBasedCommand(const char *impl_function, llvm::StringRef args,
373  ScriptedCommandSynchronicity synchronicity,
375  Status &error,
376  const lldb_private::ExecutionContext &exe_ctx) {
377  return false;
378  }
379 
380  virtual bool RunScriptBasedCommand(
381  StructuredData::GenericSP impl_obj_sp, llvm::StringRef args,
382  ScriptedCommandSynchronicity synchronicity,
383  lldb_private::CommandReturnObject &cmd_retobj, Status &error,
384  const lldb_private::ExecutionContext &exe_ctx) {
385  return false;
386  }
387 
388  virtual bool RunScriptFormatKeyword(const char *impl_function,
389  Process *process, std::string &output,
390  Status &error) {
391  error.SetErrorString("unimplemented");
392  return false;
393  }
394 
395  virtual bool RunScriptFormatKeyword(const char *impl_function, Thread *thread,
396  std::string &output, Status &error) {
397  error.SetErrorString("unimplemented");
398  return false;
399  }
400 
401  virtual bool RunScriptFormatKeyword(const char *impl_function, Target *target,
402  std::string &output, Status &error) {
403  error.SetErrorString("unimplemented");
404  return false;
405  }
406 
407  virtual bool RunScriptFormatKeyword(const char *impl_function,
408  StackFrame *frame, std::string &output,
409  Status &error) {
410  error.SetErrorString("unimplemented");
411  return false;
412  }
413 
414  virtual bool RunScriptFormatKeyword(const char *impl_function,
415  ValueObject *value, std::string &output,
416  Status &error) {
417  error.SetErrorString("unimplemented");
418  return false;
419  }
420 
421  virtual bool GetDocumentationForItem(const char *item, std::string &dest) {
422  dest.clear();
423  return false;
424  }
425 
426  virtual bool
428  std::string &dest) {
429  dest.clear();
430  return false;
431  }
432 
433  virtual uint32_t
435  return 0;
436  }
437 
439  std::string &dest) {
440  dest.clear();
441  return false;
442  }
443 
444  virtual bool CheckObjectExists(const char *name) { return false; }
445 
446  virtual bool
447  LoadScriptingModule(const char *filename, bool can_reload, bool init_session,
448  lldb_private::Status &error,
449  StructuredData::ObjectSP *module_sp = nullptr) {
450  error.SetErrorString("loading unimplemented");
451  return false;
452  }
453 
454  virtual bool IsReservedWord(const char *word) { return false; }
455 
456  virtual std::unique_ptr<ScriptInterpreterLocker> AcquireInterpreterLock();
457 
458  const char *GetScriptInterpreterPtyName();
459 
460  int GetMasterFileDescriptor();
461 
462  static std::string LanguageToString(lldb::ScriptLanguage language);
463 
464  static lldb::ScriptLanguage StringToLanguage(const llvm::StringRef &string);
465 
466  virtual void ResetOutputFileHandle(FILE *new_fh) {} // By default, do nothing.
467 
468  lldb::ScriptLanguage GetLanguage() { return m_script_lang; }
469 
470 protected:
473 };
474 
475 } // namespace lldb_private
476 
477 #endif // liblldb_ScriptInterpreter_h_
virtual bool GetDocumentationForItem(const char *item, std::string &dest)
A class to manage flag bits.
Definition: Debugger.h:82
virtual lldb::StateType ScriptedThreadPlanGetRunState(StructuredData::ObjectSP implementor_sp, bool &script_error)
virtual Status GenerateFunction(const char *signature, const StringList &input)
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
virtual StructuredData::ArraySP OSPlugin_ThreadsInfo(StructuredData::ObjectSP os_plugin_object_sp)
virtual uint32_t GetFlagsForCommandObject(StructuredData::GenericSP cmd_obj_sp)
virtual bool ScriptedThreadPlanExplainsStop(StructuredData::ObjectSP implementor_sp, Event *event, bool &script_error)
std::shared_ptr< Array > ArraySP
virtual bool CheckObjectExists(const char *name)
virtual bool GenerateTypeScriptFunction(const char *oneliner, std::string &output, const void *name_token=nullptr)
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:33
virtual bool RunScriptFormatKeyword(const char *impl_function, Thread *thread, std::string &output, Status &error)
virtual bool GetLongHelpForCommandObject(StructuredData::GenericSP cmd_obj_sp, std::string &dest)
virtual StructuredData::DictionarySP OSPlugin_CreateThread(StructuredData::ObjectSP os_plugin_object_sp, lldb::tid_t tid, lldb::addr_t context)
virtual StructuredData::StringSP OSPlugin_RegisterContextData(StructuredData::ObjectSP os_plugin_object_sp, lldb::tid_t thread_id)
A file utility class.
Definition: FileSpec.h:55
virtual bool IsReservedWord(const char *word)
virtual bool ScriptedThreadPlanIsStale(StructuredData::ObjectSP implementor_sp, bool &script_error)
virtual bool GenerateTypeSynthClass(StringList &input, std::string &output, const void *name_token=nullptr)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
virtual lldb::ValueObjectSP GetChildAtIndex(const StructuredData::ObjectSP &implementor, uint32_t idx)
virtual bool RunScriptFormatKeyword(const char *impl_function, StackFrame *frame, std::string &output, Status &error)
virtual StructuredData::GenericSP CreateScriptCommandObject(const char *class_name)
virtual ~ScriptInterpreterLocker()=default
virtual bool RunScriptBasedCommand(const char *impl_function, llvm::StringRef args, ScriptedCommandSynchronicity synchronicity, lldb_private::CommandReturnObject &cmd_retobj, Status &error, const lldb_private::ExecutionContext &exe_ctx)
virtual void SetWatchpointCommandCallback(WatchpointOptions *wp_options, const char *oneliner)
Set a one-liner as the callback for the watchpoint.
virtual lldb::ValueObjectListSP GetRecognizedArguments(const StructuredData::ObjectSP &implementor, lldb::StackFrameSP frame_sp)
virtual int GetIndexOfChildWithName(const StructuredData::ObjectSP &implementor, const char *child_name)
virtual bool UpdateSynthProviderInstance(const StructuredData::ObjectSP &implementor)
virtual void ResetOutputFileHandle(FILE *new_fh)
virtual StructuredData::ObjectSP CreateScriptedThreadPlan(const char *class_name, lldb::ThreadPlanSP thread_plan_sp)
virtual bool GenerateTypeScriptFunction(StringList &input, std::string &output, const void *name_token=nullptr)
std::shared_ptr< Dictionary > DictionarySP
ExecuteScriptOptions & SetEnableIO(bool enable)
#define UINT32_MAX
Definition: lldb-defines.h:31
virtual bool ExecuteOneLineWithReturn(llvm::StringRef in_string, ScriptReturnType return_type, void *ret_value, const ExecuteScriptOptions &options=ExecuteScriptOptions())
ExecuteScriptOptions & SetMaskoutErrors(bool maskout)
virtual bool ScriptedThreadPlanShouldStop(StructuredData::ObjectSP implementor_sp, Event *event, bool &script_error)
virtual bool RunScriptFormatKeyword(const char *impl_function, Target *target, std::string &output, Status &error)
virtual bool LoadScriptingModule(const char *filename, bool can_reload, bool init_session, lldb_private::Status &error, StructuredData::ObjectSP *module_sp=nullptr)
uint64_t tid_t
Definition: lldb-types.h:86
virtual bool GenerateTypeSynthClass(const char *oneliner, std::string &output, const void *name_token=nullptr)
lldb::ScriptLanguage m_script_lang
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
Definition: Status.cpp:241
virtual bool GenerateScriptAliasFunction(StringList &input, std::string &output)
A plug-in interface definition class for debugging a process.
Definition: Process.h:353
virtual bool MightHaveChildrenSynthProviderInstance(const StructuredData::ObjectSP &implementor)
virtual StructuredData::ObjectSP CreateSyntheticScriptedProvider(const char *class_name, lldb::ValueObjectSP valobj)
virtual bool GenerateWatchpointCommandCallbackData(StringList &input, std::string &output)
Process or thread is in the process of stepping and can not be examined.
std::shared_ptr< String > StringSP
virtual StructuredData::DictionarySP GetDynamicSettings(StructuredData::ObjectSP plugin_module_sp, Target *target, const char *setting_name, lldb_private::Status &error)
virtual StructuredData::ObjectSP LoadPluginModule(const FileSpec &file_spec, lldb_private::Status &error)
virtual Status ExecuteMultipleLines(const char *in_string, const ExecuteScriptOptions &options=ExecuteScriptOptions())
lldb::ScriptLanguage GetLanguage()
virtual bool RunScriptFormatKeyword(const char *impl_function, ValueObject *value, std::string &output, Status &error)
virtual size_t CalculateNumChildren(const StructuredData::ObjectSP &implementor, uint32_t max)
virtual bool RunScriptFormatKeyword(const char *impl_function, Process *process, std::string &output, Status &error)
"lldb/Breakpoint/WatchpointOptions.h" Class that manages the options on a watchpoint.
uint64_t addr_t
Definition: lldb-types.h:83
virtual bool GetShortHelpForCommandObject(StructuredData::GenericSP cmd_obj_sp, std::string &dest)
A uniqued constant string class.
Definition: ConstString.h:38
"lldb/Breakpoint/BreakpointOptions.h" Class that manages the options on a breakpoint or breakpoint lo...
virtual StructuredData::DictionarySP OSPlugin_RegisterInfo(StructuredData::ObjectSP os_plugin_object_sp)
std::shared_ptr< Object > ObjectSP
virtual ConstString GetSyntheticTypeName(const StructuredData::ObjectSP &implementor)
virtual Status GenerateBreakpointCommandCallbackData(StringList &input, std::string &output)
virtual lldb::SearchDepth ScriptedBreakpointResolverSearchDepth(StructuredData::GenericSP implementor_sp)
virtual bool RunScriptBasedCommand(StructuredData::GenericSP impl_obj_sp, llvm::StringRef args, ScriptedCommandSynchronicity synchronicity, lldb_private::CommandReturnObject &cmd_retobj, Status &error, const lldb_private::ExecutionContext &exe_ctx)
virtual Status SetBreakpointCommandCallback(BreakpointOptions *bp_options, std::unique_ptr< BreakpointOptions::CommandData > &data_up)
This one is for deserialization:
virtual Status ExportFunctionDefinitionToInterpreter(StringList &function_def)
virtual StructuredData::GenericSP OSPlugin_CreatePluginObject(const char *class_name, lldb::ProcessSP process_sp)
std::shared_ptr< Generic > GenericSP
virtual StructuredData::GenericSP CreateFrameRecognizer(const char *class_name)
virtual Status SetBreakpointCommandCallback(BreakpointOptions *bp_options, const char *callback_text)
virtual bool ScriptedBreakpointResolverSearchCallback(StructuredData::GenericSP implementor_sp, SymbolContext *sym_ctx)
This base class provides an interface to stack frames.
Definition: StackFrame.h:40
virtual lldb::ValueObjectSP GetSyntheticValue(const StructuredData::ObjectSP &implementor)
virtual StructuredData::GenericSP CreateScriptedBreakpointResolver(const char *class_name, StructuredDataImpl *args_data, lldb::BreakpointSP &bkpt_sp)
An error handling class.
Definition: Status.h:44
virtual void SetBreakpointCommandCallbackFunction(BreakpointOptions *bp_options, const char *function_name)
Set a one-liner as the callback for the breakpoint.
virtual bool GetScriptedSummary(const char *function_name, lldb::ValueObjectSP valobj, StructuredData::ObjectSP &callee_wrapper_sp, const TypeSummaryOptions &options, std::string &retval)