]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Interpreter/ScriptInterpreter.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Interpreter / ScriptInterpreter.h
1 //===-- ScriptInterpreter.h -------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_ScriptInterpreter_h_
11 #define liblldb_ScriptInterpreter_h_
12
13 // C Includes
14 // C++ Includes
15 // Other libraries and framework includes
16 // Project includes
17 #include "lldb/lldb-private.h"
18
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"
24
25 #include "lldb/Host/PseudoTerminal.h"
26
27 namespace lldb_private {
28
29 class ScriptInterpreterLocker {
30 public:
31   ScriptInterpreterLocker() = default;
32
33   virtual ~ScriptInterpreterLocker() = default;
34
35 private:
36   DISALLOW_COPY_AND_ASSIGN(ScriptInterpreterLocker);
37 };
38
39 class ScriptInterpreter : public PluginInterface {
40 public:
41   typedef enum {
42     eScriptReturnTypeCharPtr,
43     eScriptReturnTypeBool,
44     eScriptReturnTypeShortInt,
45     eScriptReturnTypeShortIntUnsigned,
46     eScriptReturnTypeInt,
47     eScriptReturnTypeIntUnsigned,
48     eScriptReturnTypeLongInt,
49     eScriptReturnTypeLongIntUnsigned,
50     eScriptReturnTypeLongLong,
51     eScriptReturnTypeLongLongUnsigned,
52     eScriptReturnTypeFloat,
53     eScriptReturnTypeDouble,
54     eScriptReturnTypeChar,
55     eScriptReturnTypeCharStrOrNone,
56     eScriptReturnTypeOpaqueObject
57   } ScriptReturnType;
58
59   ScriptInterpreter(CommandInterpreter &interpreter,
60                     lldb::ScriptLanguage script_lang);
61
62   ~ScriptInterpreter() override;
63
64   struct ExecuteScriptOptions {
65   public:
66     ExecuteScriptOptions()
67         : m_enable_io(true), m_set_lldb_globals(true), m_maskout_errors(true) {}
68
69     bool GetEnableIO() const { return m_enable_io; }
70
71     bool GetSetLLDBGlobals() const { return m_set_lldb_globals; }
72
73     bool GetMaskoutErrors() const { return m_maskout_errors; }
74
75     ExecuteScriptOptions &SetEnableIO(bool enable) {
76       m_enable_io = enable;
77       return *this;
78     }
79
80     ExecuteScriptOptions &SetSetLLDBGlobals(bool set) {
81       m_set_lldb_globals = set;
82       return *this;
83     }
84
85     ExecuteScriptOptions &SetMaskoutErrors(bool maskout) {
86       m_maskout_errors = maskout;
87       return *this;
88     }
89
90   private:
91     bool m_enable_io;
92     bool m_set_lldb_globals;
93     bool m_maskout_errors;
94   };
95
96   virtual bool Interrupt() { return false; }
97
98   virtual bool ExecuteOneLine(
99       llvm::StringRef command, CommandReturnObject *result,
100       const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0;
101
102   virtual void ExecuteInterpreterLoop() = 0;
103
104   virtual bool ExecuteOneLineWithReturn(
105       llvm::StringRef in_string, ScriptReturnType return_type, void *ret_value,
106       const ExecuteScriptOptions &options = ExecuteScriptOptions()) {
107     return true;
108   }
109
110   virtual Status ExecuteMultipleLines(
111       const char *in_string,
112       const ExecuteScriptOptions &options = ExecuteScriptOptions()) {
113     Status error;
114     error.SetErrorString("not implemented");
115     return error;
116   }
117
118   virtual Status
119   ExportFunctionDefinitionToInterpreter(StringList &function_def) {
120     Status error;
121     error.SetErrorString("not implemented");
122     return error;
123   }
124
125   virtual Status GenerateBreakpointCommandCallbackData(StringList &input,
126                                                        std::string &output) {
127     Status error;
128     error.SetErrorString("not implemented");
129     return error;
130   }
131
132   virtual bool GenerateWatchpointCommandCallbackData(StringList &input,
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
143   virtual bool GenerateTypeScriptFunction(StringList &input,
144                                           std::string &output,
145                                           const void *name_token = nullptr) {
146     return false;
147   }
148
149   virtual bool GenerateScriptAliasFunction(StringList &input,
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
164   virtual StructuredData::ObjectSP
165   CreateSyntheticScriptedProvider(const char *class_name,
166                                   lldb::ValueObjectSP valobj) {
167     return StructuredData::ObjectSP();
168   }
169
170   virtual StructuredData::GenericSP
171   CreateScriptCommandObject(const char *class_name) {
172     return StructuredData::GenericSP();
173   }
174
175   virtual StructuredData::GenericSP
176   OSPlugin_CreatePluginObject(const char *class_name,
177                               lldb::ProcessSP process_sp) {
178     return StructuredData::GenericSP();
179   }
180
181   virtual StructuredData::DictionarySP
182   OSPlugin_RegisterInfo(StructuredData::ObjectSP os_plugin_object_sp) {
183     return StructuredData::DictionarySP();
184   }
185
186   virtual StructuredData::ArraySP
187   OSPlugin_ThreadsInfo(StructuredData::ObjectSP os_plugin_object_sp) {
188     return StructuredData::ArraySP();
189   }
190
191   virtual StructuredData::StringSP
192   OSPlugin_RegisterContextData(StructuredData::ObjectSP os_plugin_object_sp,
193                                lldb::tid_t thread_id) {
194     return StructuredData::StringSP();
195   }
196
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();
201   }
202
203   virtual StructuredData::ObjectSP
204   CreateScriptedThreadPlan(const char *class_name,
205                            lldb::ThreadPlanSP thread_plan_sp) {
206     return StructuredData::ObjectSP();
207   }
208
209   virtual bool
210   ScriptedThreadPlanExplainsStop(StructuredData::ObjectSP implementor_sp,
211                                  Event *event, bool &script_error) {
212     script_error = true;
213     return true;
214   }
215
216   virtual bool
217   ScriptedThreadPlanShouldStop(StructuredData::ObjectSP implementor_sp,
218                                Event *event, bool &script_error) {
219     script_error = true;
220     return true;
221   }
222
223   virtual bool
224   ScriptedThreadPlanIsStale(StructuredData::ObjectSP implementor_sp,
225                             bool &script_error) {
226     script_error = true;
227     return true;
228   }
229
230   virtual lldb::StateType
231   ScriptedThreadPlanGetRunState(StructuredData::ObjectSP implementor_sp,
232                                 bool &script_error) {
233     script_error = true;
234     return lldb::eStateStepping;
235   }
236
237   virtual StructuredData::ObjectSP
238   LoadPluginModule(const FileSpec &file_spec, lldb_private::Status &error) {
239     return StructuredData::ObjectSP();
240   }
241
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();
246   }
247
248   virtual Status GenerateFunction(const char *signature,
249                                   const StringList &input) {
250     Status error;
251     error.SetErrorString("unimplemented");
252     return error;
253   }
254
255   virtual void CollectDataForBreakpointCommandCallback(
256       std::vector<BreakpointOptions *> &options, CommandReturnObject &result);
257
258   virtual void
259   CollectDataForWatchpointCommandCallback(WatchpointOptions *wp_options,
260                                           CommandReturnObject &result);
261
262   /// Set the specified text as the callback for the breakpoint.
263   Status
264   SetBreakpointCommandCallback(std::vector<BreakpointOptions *> &bp_options_vec,
265                                const char *callback_text);
266
267   virtual Status SetBreakpointCommandCallback(BreakpointOptions *bp_options,
268                                               const char *callback_text) {
269     Status error;
270     error.SetErrorString("unimplemented");
271     return error;
272   }
273
274   /// This one is for deserialization:
275   virtual Status SetBreakpointCommandCallback(
276       BreakpointOptions *bp_options,
277       std::unique_ptr<BreakpointOptions::CommandData> &data_up) {
278     Status error;
279     error.SetErrorString("unimplemented");
280     return error;
281   }
282
283   void SetBreakpointCommandCallbackFunction(
284       std::vector<BreakpointOptions *> &bp_options_vec,
285       const char *function_name);
286
287   /// Set a one-liner as the callback for the breakpoint.
288   virtual void
289   SetBreakpointCommandCallbackFunction(BreakpointOptions *bp_options,
290                                        const char *function_name) {}
291
292   /// Set a one-liner as the callback for the watchpoint.
293   virtual void SetWatchpointCommandCallback(WatchpointOptions *wp_options,
294                                             const char *oneliner) {}
295
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) {
301     return false;
302   }
303
304   virtual void Clear() {
305     // Clean up any ref counts to SBObjects that might be in global variables
306   }
307
308   virtual size_t
309   CalculateNumChildren(const StructuredData::ObjectSP &implementor,
310                        uint32_t max) {
311     return 0;
312   }
313
314   virtual lldb::ValueObjectSP
315   GetChildAtIndex(const StructuredData::ObjectSP &implementor, uint32_t idx) {
316     return lldb::ValueObjectSP();
317   }
318
319   virtual int
320   GetIndexOfChildWithName(const StructuredData::ObjectSP &implementor,
321                           const char *child_name) {
322     return UINT32_MAX;
323   }
324
325   virtual bool
326   UpdateSynthProviderInstance(const StructuredData::ObjectSP &implementor) {
327     return false;
328   }
329
330   virtual bool MightHaveChildrenSynthProviderInstance(
331       const StructuredData::ObjectSP &implementor) {
332     return true;
333   }
334
335   virtual lldb::ValueObjectSP
336   GetSyntheticValue(const StructuredData::ObjectSP &implementor) {
337     return nullptr;
338   }
339
340   virtual ConstString
341   GetSyntheticTypeName(const StructuredData::ObjectSP &implementor) {
342     return ConstString();
343   }
344
345   virtual bool
346   RunScriptBasedCommand(const char *impl_function, llvm::StringRef args,
347                         ScriptedCommandSynchronicity synchronicity,
348                         lldb_private::CommandReturnObject &cmd_retobj,
349                         Status &error,
350                         const lldb_private::ExecutionContext &exe_ctx) {
351     return false;
352   }
353
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) {
359     return false;
360   }
361
362   virtual bool RunScriptFormatKeyword(const char *impl_function,
363                                       Process *process, std::string &output,
364                                       Status &error) {
365     error.SetErrorString("unimplemented");
366     return false;
367   }
368
369   virtual bool RunScriptFormatKeyword(const char *impl_function, Thread *thread,
370                                       std::string &output, Status &error) {
371     error.SetErrorString("unimplemented");
372     return false;
373   }
374
375   virtual bool RunScriptFormatKeyword(const char *impl_function, Target *target,
376                                       std::string &output, Status &error) {
377     error.SetErrorString("unimplemented");
378     return false;
379   }
380
381   virtual bool RunScriptFormatKeyword(const char *impl_function,
382                                       StackFrame *frame, std::string &output,
383                                       Status &error) {
384     error.SetErrorString("unimplemented");
385     return false;
386   }
387
388   virtual bool RunScriptFormatKeyword(const char *impl_function,
389                                       ValueObject *value, std::string &output,
390                                       Status &error) {
391     error.SetErrorString("unimplemented");
392     return false;
393   }
394
395   virtual bool GetDocumentationForItem(const char *item, std::string &dest) {
396     dest.clear();
397     return false;
398   }
399
400   virtual bool
401   GetShortHelpForCommandObject(StructuredData::GenericSP cmd_obj_sp,
402                                std::string &dest) {
403     dest.clear();
404     return false;
405   }
406
407   virtual uint32_t
408   GetFlagsForCommandObject(StructuredData::GenericSP cmd_obj_sp) {
409     return 0;
410   }
411
412   virtual bool GetLongHelpForCommandObject(StructuredData::GenericSP cmd_obj_sp,
413                                            std::string &dest) {
414     dest.clear();
415     return false;
416   }
417
418   virtual bool CheckObjectExists(const char *name) { return false; }
419
420   virtual bool
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");
425     return false;
426   }
427
428   virtual bool IsReservedWord(const char *word) { return false; }
429
430   virtual std::unique_ptr<ScriptInterpreterLocker> AcquireInterpreterLock();
431
432   const char *GetScriptInterpreterPtyName();
433
434   int GetMasterFileDescriptor();
435
436   CommandInterpreter &GetCommandInterpreter();
437
438   static std::string LanguageToString(lldb::ScriptLanguage language);
439
440   static lldb::ScriptLanguage StringToLanguage(const llvm::StringRef &string);
441
442   virtual void ResetOutputFileHandle(FILE *new_fh) {} // By default, do nothing.
443
444   lldb::ScriptLanguage GetLanguage() { return m_script_lang; }
445
446 protected:
447   CommandInterpreter &m_interpreter;
448   lldb::ScriptLanguage m_script_lang;
449 };
450
451 } // namespace lldb_private
452
453 #endif // liblldb_ScriptInterpreter_h_