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 LLDB_INTERPRETER_SCRIPTINTERPRETER_H
10 #define LLDB_INTERPRETER_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:
33 };
34 
36 public:
52  eScriptReturnTypeOpaqueObject
53  };
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  // If this is true then any exceptions raised by the script will be
69  // cleared with PyErr_Clear(). If false then they will be left for
70  // the caller to clean up
71  bool GetMaskoutErrors() const { return m_maskout_errors; }
72 
74  m_enable_io = enable;
75  return *this;
76  }
77 
79  m_set_lldb_globals = set;
80  return *this;
81  }
82 
84  m_maskout_errors = maskout;
85  return *this;
86  }
87 
88  private:
92  };
93 
94  virtual bool Interrupt() { return false; }
95 
96  virtual bool ExecuteOneLine(
97  llvm::StringRef command, CommandReturnObject *result,
98  const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0;
99 
100  virtual void ExecuteInterpreterLoop() = 0;
101 
103  llvm::StringRef in_string, ScriptReturnType return_type, void *ret_value,
104  const ExecuteScriptOptions &options = ExecuteScriptOptions()) {
105  return true;
106  }
107 
109  const char *in_string,
110  const ExecuteScriptOptions &options = ExecuteScriptOptions()) {
111  Status error;
112  error.SetErrorString("not implemented");
113  return error;
114  }
115 
116  virtual Status
118  Status error;
119  error.SetErrorString("not implemented");
120  return error;
121  }
122 
124  StringList &input,
125  std::string &output,
126  bool has_extra_args) {
127  Status error;
128  error.SetErrorString("not implemented");
129  return error;
130  }
131 
133  std::string &output) {
134  return false;
135  }
136 
137  virtual bool GenerateTypeScriptFunction(const char *oneliner,
138  std::string &output,
139  const void *name_token = nullptr) {
140  return false;
141  }
142 
144  std::string &output,
145  const void *name_token = nullptr) {
146  return false;
147  }
148 
150  std::string &output) {
151  return false;
152  }
153 
154  virtual bool GenerateTypeSynthClass(StringList &input, std::string &output,
155  const void *name_token = nullptr) {
156  return false;
157  }
158 
159  virtual bool GenerateTypeSynthClass(const char *oneliner, std::string &output,
160  const void *name_token = nullptr) {
161  return false;
162  }
163 
165  CreateSyntheticScriptedProvider(const char *class_name,
166  lldb::ValueObjectSP valobj) {
167  return StructuredData::ObjectSP();
168  }
169 
171  CreateScriptCommandObject(const char *class_name) {
172  return StructuredData::GenericSP();
173  }
174 
176  CreateFrameRecognizer(const char *class_name) {
177  return StructuredData::GenericSP();
178  }
179 
180  virtual lldb::ValueObjectListSP GetRecognizedArguments(
181  const StructuredData::ObjectSP &implementor,
182  lldb::StackFrameSP frame_sp) {
183  return lldb::ValueObjectListSP();
184  }
185 
187  OSPlugin_CreatePluginObject(const char *class_name,
188  lldb::ProcessSP process_sp) {
189  return StructuredData::GenericSP();
190  }
191 
195  }
196 
199  return StructuredData::ArraySP();
200  }
201 
204  lldb::tid_t thread_id) {
205  return StructuredData::StringSP();
206  }
207 
210  lldb::tid_t tid, lldb::addr_t context) {
212  }
213 
215  CreateScriptedThreadPlan(const char *class_name,
216  StructuredDataImpl *args_data,
217  std::string &error_str,
218  lldb::ThreadPlanSP thread_plan_sp) {
219  return StructuredData::ObjectSP();
220  }
221 
222  virtual bool
224  Event *event, bool &script_error) {
225  script_error = true;
226  return true;
227  }
228 
229  virtual bool
231  Event *event, bool &script_error) {
232  script_error = true;
233  return true;
234  }
235 
236  virtual bool
238  bool &script_error) {
239  script_error = true;
240  return true;
241  }
242 
243  virtual lldb::StateType
245  bool &script_error) {
246  script_error = true;
247  return lldb::eStateStepping;
248  }
249 
251  CreateScriptedBreakpointResolver(const char *class_name,
252  StructuredDataImpl *args_data,
253  lldb::BreakpointSP &bkpt_sp) {
254  return StructuredData::GenericSP();
255  }
256 
257  virtual bool
259  SymbolContext *sym_ctx)
260  {
261  return false;
262  }
263 
264  virtual lldb::SearchDepth
266  {
268  }
269 
271  LoadPluginModule(const FileSpec &file_spec, lldb_private::Status &error) {
272  return StructuredData::ObjectSP();
273  }
274 
277  const char *setting_name, lldb_private::Status &error) {
279  }
280 
281  virtual Status GenerateFunction(const char *signature,
282  const StringList &input) {
283  Status error;
284  error.SetErrorString("unimplemented");
285  return error;
286  }
287 
288  virtual void CollectDataForBreakpointCommandCallback(
289  std::vector<BreakpointOptions *> &options, CommandReturnObject &result);
290 
291  virtual void
292  CollectDataForWatchpointCommandCallback(WatchpointOptions *wp_options,
293  CommandReturnObject &result);
294 
295  /// Set the specified text as the callback for the breakpoint.
296  Status
297  SetBreakpointCommandCallback(std::vector<BreakpointOptions *> &bp_options_vec,
298  const char *callback_text);
299 
301  const char *callback_text) {
302  Status error;
303  error.SetErrorString("unimplemented");
304  return error;
305  }
306 
307  /// This one is for deserialization:
309  BreakpointOptions *bp_options,
310  std::unique_ptr<BreakpointOptions::CommandData> &data_up) {
311  Status error;
312  error.SetErrorString("unimplemented");
313  return error;
314  }
315 
316  Status SetBreakpointCommandCallbackFunction(
317  std::vector<BreakpointOptions *> &bp_options_vec,
318  const char *function_name, StructuredData::ObjectSP extra_args_sp);
319 
320  /// Set a script function as the callback for the breakpoint.
321  virtual Status
323  BreakpointOptions *bp_options,
324  const char *function_name,
325  StructuredData::ObjectSP extra_args_sp) {
326  Status error;
327  error.SetErrorString("unimplemented");
328  return error;
329  }
330 
331  /// Set a one-liner as the callback for the watchpoint.
333  const char *oneliner) {}
334 
335  virtual bool GetScriptedSummary(const char *function_name,
336  lldb::ValueObjectSP valobj,
337  StructuredData::ObjectSP &callee_wrapper_sp,
338  const TypeSummaryOptions &options,
339  std::string &retval) {
340  return false;
341  }
342 
343  virtual void Clear() {
344  // Clean up any ref counts to SBObjects that might be in global variables
345  }
346 
347  virtual size_t
349  uint32_t max) {
350  return 0;
351  }
352 
353  virtual lldb::ValueObjectSP
355  return lldb::ValueObjectSP();
356  }
357 
358  virtual int
360  const char *child_name) {
361  return UINT32_MAX;
362  }
363 
364  virtual bool
366  return false;
367  }
368 
370  const StructuredData::ObjectSP &implementor) {
371  return true;
372  }
373 
374  virtual lldb::ValueObjectSP
376  return nullptr;
377  }
378 
379  virtual ConstString
381  return ConstString();
382  }
383 
384  virtual bool
385  RunScriptBasedCommand(const char *impl_function, llvm::StringRef args,
386  ScriptedCommandSynchronicity synchronicity,
388  Status &error,
389  const lldb_private::ExecutionContext &exe_ctx) {
390  return false;
391  }
392 
393  virtual bool RunScriptBasedCommand(
394  StructuredData::GenericSP impl_obj_sp, llvm::StringRef args,
395  ScriptedCommandSynchronicity synchronicity,
396  lldb_private::CommandReturnObject &cmd_retobj, Status &error,
397  const lldb_private::ExecutionContext &exe_ctx) {
398  return false;
399  }
400 
401  virtual bool RunScriptFormatKeyword(const char *impl_function,
402  Process *process, std::string &output,
403  Status &error) {
404  error.SetErrorString("unimplemented");
405  return false;
406  }
407 
408  virtual bool RunScriptFormatKeyword(const char *impl_function, Thread *thread,
409  std::string &output, Status &error) {
410  error.SetErrorString("unimplemented");
411  return false;
412  }
413 
414  virtual bool RunScriptFormatKeyword(const char *impl_function, Target *target,
415  std::string &output, Status &error) {
416  error.SetErrorString("unimplemented");
417  return false;
418  }
419 
420  virtual bool RunScriptFormatKeyword(const char *impl_function,
421  StackFrame *frame, std::string &output,
422  Status &error) {
423  error.SetErrorString("unimplemented");
424  return false;
425  }
426 
427  virtual bool RunScriptFormatKeyword(const char *impl_function,
428  ValueObject *value, std::string &output,
429  Status &error) {
430  error.SetErrorString("unimplemented");
431  return false;
432  }
433 
434  virtual bool GetDocumentationForItem(const char *item, std::string &dest) {
435  dest.clear();
436  return false;
437  }
438 
439  virtual bool
441  std::string &dest) {
442  dest.clear();
443  return false;
444  }
445 
446  virtual uint32_t
448  return 0;
449  }
450 
452  std::string &dest) {
453  dest.clear();
454  return false;
455  }
456 
457  virtual bool CheckObjectExists(const char *name) { return false; }
458 
459  virtual bool
460  LoadScriptingModule(const char *filename, bool init_session,
461  lldb_private::Status &error,
462  StructuredData::ObjectSP *module_sp = nullptr);
463 
464  virtual bool IsReservedWord(const char *word) { return false; }
465 
466  virtual std::unique_ptr<ScriptInterpreterLocker> AcquireInterpreterLock();
467 
468  const char *GetScriptInterpreterPtyName();
469 
470  int GetMasterFileDescriptor();
471 
472  virtual llvm::Expected<unsigned>
473  GetMaxPositionalArgumentsForCallable(const llvm::StringRef &callable_name) {
474  return llvm::createStringError(
475  llvm::inconvertibleErrorCode(), "Unimplemented function");
476  }
477 
478  static std::string LanguageToString(lldb::ScriptLanguage language);
479 
480  static lldb::ScriptLanguage StringToLanguage(const llvm::StringRef &string);
481 
482  lldb::ScriptLanguage GetLanguage() { return m_script_lang; }
483 
484 protected:
487 };
488 
489 } // namespace lldb_private
490 
491 #endif // LLDB_INTERPRETER_SCRIPTINTERPRETER_H
virtual bool GetDocumentationForItem(const char *item, std::string &dest)
A class to manage flag bits.
Definition: Debugger.h:70
virtual lldb::StateType ScriptedThreadPlanGetRunState(StructuredData::ObjectSP implementor_sp, bool &script_error)
virtual Status GenerateFunction(const char *signature, const StringList &input)
virtual StructuredData::ObjectSP CreateScriptedThreadPlan(const char *class_name, StructuredDataImpl *args_data, std::string &error_str, lldb::ThreadPlanSP thread_plan_sp)
A class that represents a running process on the host machine.
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)
DISALLOW_COPY_AND_ASSIGN(ScriptInterpreterLocker)
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:56
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 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())
virtual Status SetBreakpointCommandCallbackFunction(BreakpointOptions *bp_options, const char *function_name, StructuredData::ObjectSP extra_args_sp)
Set a script function as the callback for the breakpoint.
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)
StateType
Process and Thread States.
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:242
virtual bool GenerateScriptAliasFunction(StringList &input, std::string &output)
A plug-in interface definition class for debugging a process.
Definition: Process.h:362
virtual llvm::Expected< unsigned > GetMaxPositionalArgumentsForCallable(const llvm::StringRef &callable_name)
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.
virtual Status GenerateBreakpointCommandCallbackData(StringList &input, std::string &output, bool has_extra_args)
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:40
"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 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
ScriptLanguage
Script interpreter types.
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 bool GetScriptedSummary(const char *function_name, lldb::ValueObjectSP valobj, StructuredData::ObjectSP &callee_wrapper_sp, const TypeSummaryOptions &options, std::string &retval)