]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Interpreter/ScriptInterpreter.h
Merge ^/head r306412 through r306905.
[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/Core/Broadcaster.h"
20 #include "lldb/Core/Error.h"
21 #include "lldb/Core/PluginInterface.h"
22 #include "lldb/Core/StructuredData.h"
23
24 #include "lldb/Utility/PseudoTerminal.h"
25
26 namespace lldb_private {
27     
28 class ScriptInterpreterLocker
29 {
30 public:
31     
32     ScriptInterpreterLocker() = default;
33     
34     virtual ~ScriptInterpreterLocker() = default;
35
36 private:
37     DISALLOW_COPY_AND_ASSIGN (ScriptInterpreterLocker);
38 };
39
40 class ScriptInterpreter : public PluginInterface
41 {
42 public:
43     typedef enum
44     {
45         eScriptReturnTypeCharPtr,
46         eScriptReturnTypeBool,
47         eScriptReturnTypeShortInt,
48         eScriptReturnTypeShortIntUnsigned,
49         eScriptReturnTypeInt,
50         eScriptReturnTypeIntUnsigned,
51         eScriptReturnTypeLongInt,
52         eScriptReturnTypeLongIntUnsigned,
53         eScriptReturnTypeLongLong,
54         eScriptReturnTypeLongLongUnsigned,
55         eScriptReturnTypeFloat,
56         eScriptReturnTypeDouble,
57         eScriptReturnTypeChar,
58         eScriptReturnTypeCharStrOrNone,
59         eScriptReturnTypeOpaqueObject
60     } ScriptReturnType;
61     
62     ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang);
63
64     ~ScriptInterpreter() override;
65
66     struct ExecuteScriptOptions
67     {
68     public:
69         ExecuteScriptOptions () :
70             m_enable_io(true),
71             m_set_lldb_globals(true),
72             m_maskout_errors(true)
73         {
74         }
75         
76         bool
77         GetEnableIO () const
78         {
79             return m_enable_io;
80         }
81         
82         bool
83         GetSetLLDBGlobals () const
84         {
85             return m_set_lldb_globals;
86         }
87         
88         bool
89         GetMaskoutErrors () const
90         {
91             return m_maskout_errors;
92         }
93         
94         ExecuteScriptOptions&
95         SetEnableIO (bool enable)
96         {
97             m_enable_io = enable;
98             return *this;
99         }
100
101         ExecuteScriptOptions&
102         SetSetLLDBGlobals (bool set)
103         {
104             m_set_lldb_globals = set;
105             return *this;
106         }
107
108         ExecuteScriptOptions&
109         SetMaskoutErrors (bool maskout)
110         {
111             m_maskout_errors = maskout;
112             return *this;
113         }
114         
115     private:
116         bool m_enable_io;
117         bool m_set_lldb_globals;
118         bool m_maskout_errors;
119     };
120
121     virtual bool
122     Interrupt()
123     {
124         return false;
125     }
126
127     virtual bool
128     ExecuteOneLine (const char *command,
129                     CommandReturnObject *result,
130                     const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0;
131
132     virtual void
133     ExecuteInterpreterLoop () = 0;
134
135     virtual bool
136     ExecuteOneLineWithReturn (const char *in_string,
137                               ScriptReturnType return_type,
138                               void *ret_value,
139                               const ExecuteScriptOptions &options = ExecuteScriptOptions())
140     {
141         return true;
142     }
143
144     virtual Error
145     ExecuteMultipleLines (const char *in_string,
146                           const ExecuteScriptOptions &options = ExecuteScriptOptions())
147     {
148         Error error;
149         error.SetErrorString("not implemented");
150         return error;
151     }
152
153     virtual Error
154     ExportFunctionDefinitionToInterpreter (StringList &function_def)
155     {
156         Error error;
157         error.SetErrorString("not implemented");
158         return error;
159     }
160
161     virtual Error
162     GenerateBreakpointCommandCallbackData (StringList &input, std::string& output)
163     {
164         Error error;
165         error.SetErrorString("not implemented");
166         return error;
167     }
168     
169     virtual bool
170     GenerateWatchpointCommandCallbackData (StringList &input, std::string& output)
171     {
172         return false;
173     }
174     
175     virtual bool
176     GenerateTypeScriptFunction(const char* oneliner, std::string& output, const void* name_token = nullptr)
177     {
178         return false;
179     }
180     
181     virtual bool
182     GenerateTypeScriptFunction(StringList &input, std::string& output, const void* name_token = nullptr)
183     {
184         return false;
185     }
186     
187     virtual bool
188     GenerateScriptAliasFunction (StringList &input, std::string& output)
189     {
190         return false;
191     }
192     
193     virtual bool
194     GenerateTypeSynthClass(StringList &input, std::string& output, const void* name_token = nullptr)
195     {
196         return false;
197     }
198     
199     virtual bool
200     GenerateTypeSynthClass(const char* oneliner, std::string& output, const void* name_token = nullptr)
201     {
202         return false;
203     }
204
205     virtual StructuredData::ObjectSP
206     CreateSyntheticScriptedProvider(const char *class_name, lldb::ValueObjectSP valobj)
207     {
208         return StructuredData::ObjectSP();
209     }
210
211     virtual StructuredData::GenericSP
212     CreateScriptCommandObject (const char *class_name)
213     {
214         return StructuredData::GenericSP();
215     }
216
217     virtual StructuredData::GenericSP
218     OSPlugin_CreatePluginObject (const char *class_name,
219                                  lldb::ProcessSP process_sp)
220     {
221         return StructuredData::GenericSP();
222     }
223
224     virtual StructuredData::DictionarySP
225     OSPlugin_RegisterInfo(StructuredData::ObjectSP os_plugin_object_sp)
226     {
227         return StructuredData::DictionarySP();
228     }
229
230     virtual StructuredData::ArraySP
231     OSPlugin_ThreadsInfo(StructuredData::ObjectSP os_plugin_object_sp)
232     {
233         return StructuredData::ArraySP();
234     }
235
236     virtual StructuredData::StringSP
237     OSPlugin_RegisterContextData(StructuredData::ObjectSP os_plugin_object_sp, lldb::tid_t thread_id)
238     {
239         return StructuredData::StringSP();
240     }
241
242     virtual StructuredData::DictionarySP
243     OSPlugin_CreateThread(StructuredData::ObjectSP os_plugin_object_sp, lldb::tid_t tid, lldb::addr_t context)
244     {
245         return StructuredData::DictionarySP();
246     }
247
248     virtual StructuredData::ObjectSP
249     CreateScriptedThreadPlan(const char *class_name, lldb::ThreadPlanSP thread_plan_sp)
250     {
251         return StructuredData::ObjectSP();
252     }
253
254     virtual bool
255     ScriptedThreadPlanExplainsStop(StructuredData::ObjectSP implementor_sp, Event *event, bool &script_error)
256     {
257         script_error = true;
258         return true;
259     }
260
261     virtual bool
262     ScriptedThreadPlanShouldStop(StructuredData::ObjectSP implementor_sp, Event *event, bool &script_error)
263     {
264         script_error = true;
265         return true;
266     }
267
268     virtual lldb::StateType
269     ScriptedThreadPlanGetRunState(StructuredData::ObjectSP implementor_sp, bool &script_error)
270     {
271         script_error = true;
272         return lldb::eStateStepping;
273     }
274
275     virtual StructuredData::ObjectSP
276     LoadPluginModule(const FileSpec &file_spec, lldb_private::Error &error)
277     {
278         return StructuredData::ObjectSP();
279     }
280
281     virtual StructuredData::DictionarySP
282     GetDynamicSettings(StructuredData::ObjectSP plugin_module_sp, Target *target, const char *setting_name, lldb_private::Error &error)
283     {
284         return StructuredData::DictionarySP();
285     }
286
287     virtual Error
288     GenerateFunction(const char *signature, const StringList &input)
289     {
290         Error error;
291         error.SetErrorString("unimplemented");
292         return error;
293     }
294
295     virtual void 
296     CollectDataForBreakpointCommandCallback (std::vector<BreakpointOptions *> &options,
297                                              CommandReturnObject &result);
298
299     virtual void 
300     CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options,
301                                              CommandReturnObject &result);
302
303     /// Set the specified text as the callback for the breakpoint.
304     Error
305     SetBreakpointCommandCallback (std::vector<BreakpointOptions *> &bp_options_vec,
306                                   const char *callback_text);
307
308     virtual Error
309     SetBreakpointCommandCallback (BreakpointOptions *bp_options,
310                                   const char *callback_text)
311     {
312         Error error;
313         error.SetErrorString("unimplemented");
314         return error;
315     }
316     
317     void
318     SetBreakpointCommandCallbackFunction (std::vector<BreakpointOptions *> &bp_options_vec,
319                                   const char *function_name);
320
321     /// Set a one-liner as the callback for the breakpoint.
322     virtual void 
323     SetBreakpointCommandCallbackFunction (BreakpointOptions *bp_options,
324                                   const char *function_name)
325     {
326     }
327     
328     /// Set a one-liner as the callback for the watchpoint.
329     virtual void 
330     SetWatchpointCommandCallback (WatchpointOptions *wp_options,
331                                   const char *oneliner)
332     {
333     }
334
335     virtual bool
336     GetScriptedSummary(const char *function_name, lldb::ValueObjectSP valobj, StructuredData::ObjectSP &callee_wrapper_sp,
337                        const TypeSummaryOptions &options, std::string &retval)
338     {
339         return false;
340     }
341     
342     virtual void
343     Clear ()
344     {
345         // Clean up any ref counts to SBObjects that might be in global variables
346     }
347
348     virtual size_t
349     CalculateNumChildren(const StructuredData::ObjectSP &implementor, uint32_t max)
350     {
351         return 0;
352     }
353
354     virtual lldb::ValueObjectSP
355     GetChildAtIndex(const StructuredData::ObjectSP &implementor, uint32_t idx)
356     {
357         return lldb::ValueObjectSP();
358     }
359
360     virtual int
361     GetIndexOfChildWithName(const StructuredData::ObjectSP &implementor, const char *child_name)
362     {
363         return UINT32_MAX;
364     }
365
366     virtual bool
367     UpdateSynthProviderInstance(const StructuredData::ObjectSP &implementor)
368     {
369         return false;
370     }
371
372     virtual bool
373     MightHaveChildrenSynthProviderInstance(const StructuredData::ObjectSP &implementor)
374     {
375         return true;
376     }
377
378     virtual lldb::ValueObjectSP
379     GetSyntheticValue(const StructuredData::ObjectSP &implementor)
380     {
381         return nullptr;
382     }
383
384     virtual ConstString
385     GetSyntheticTypeName (const StructuredData::ObjectSP &implementor)
386     {
387         return ConstString();
388     }
389     
390     virtual bool
391     RunScriptBasedCommand (const char* impl_function,
392                            const char* args,
393                            ScriptedCommandSynchronicity synchronicity,
394                            lldb_private::CommandReturnObject& cmd_retobj,
395                            Error& error,
396                            const lldb_private::ExecutionContext& exe_ctx)
397     {
398         return false;
399     }
400     
401     virtual bool
402     RunScriptBasedCommand (StructuredData::GenericSP impl_obj_sp,
403                            const char* args,
404                            ScriptedCommandSynchronicity synchronicity,
405                            lldb_private::CommandReturnObject& cmd_retobj,
406                            Error& error,
407                            const lldb_private::ExecutionContext& exe_ctx)
408     {
409         return false;
410     }
411     
412     virtual bool
413     RunScriptFormatKeyword (const char* impl_function,
414                             Process* process,
415                             std::string& output,
416                             Error& error)
417     {
418         error.SetErrorString("unimplemented");
419         return false;
420     }
421
422     virtual bool
423     RunScriptFormatKeyword (const char* impl_function,
424                             Thread* thread,
425                             std::string& output,
426                             Error& error)
427     {
428         error.SetErrorString("unimplemented");
429         return false;
430     }
431     
432     virtual bool
433     RunScriptFormatKeyword (const char* impl_function,
434                             Target* target,
435                             std::string& output,
436                             Error& error)
437     {
438         error.SetErrorString("unimplemented");
439         return false;
440     }
441     
442     virtual bool
443     RunScriptFormatKeyword (const char* impl_function,
444                             StackFrame* frame,
445                             std::string& output,
446                             Error& error)
447     {
448         error.SetErrorString("unimplemented");
449         return false;
450     }
451     
452     virtual bool
453     RunScriptFormatKeyword (const char* impl_function,
454                             ValueObject* value,
455                             std::string& output,
456                             Error& error)
457     {
458         error.SetErrorString("unimplemented");
459         return false;
460     }
461     
462     virtual bool
463     GetDocumentationForItem (const char* item, std::string& dest)
464     {
465         dest.clear();
466         return false;
467     }
468     
469     virtual bool
470     GetShortHelpForCommandObject (StructuredData::GenericSP cmd_obj_sp,
471                                   std::string& dest)
472     {
473         dest.clear();
474         return false;
475     }
476     
477     virtual uint32_t
478     GetFlagsForCommandObject (StructuredData::GenericSP cmd_obj_sp)
479     {
480         return 0;
481     }
482
483     virtual bool
484     GetLongHelpForCommandObject (StructuredData::GenericSP cmd_obj_sp,
485                                  std::string& dest)
486     {
487         dest.clear();
488         return false;
489     }
490     
491     virtual bool
492     CheckObjectExists (const char* name)
493     {
494         return false;
495     }
496
497     virtual bool
498     LoadScriptingModule(const char *filename, bool can_reload, bool init_session, lldb_private::Error &error,
499                         StructuredData::ObjectSP *module_sp = nullptr)
500     {
501         error.SetErrorString("loading unimplemented");
502         return false;
503     }
504     
505     virtual bool
506     IsReservedWord (const char* word)
507     {
508         return false;
509     }
510     
511     virtual std::unique_ptr<ScriptInterpreterLocker>
512     AcquireInterpreterLock ();
513     
514     const char *
515     GetScriptInterpreterPtyName ();
516
517     int
518     GetMasterFileDescriptor ();
519
520     CommandInterpreter &
521     GetCommandInterpreter();
522
523     static std::string
524     LanguageToString (lldb::ScriptLanguage language);
525
526     virtual void
527     ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing.
528
529 protected:
530     CommandInterpreter &m_interpreter;
531     lldb::ScriptLanguage m_script_lang;
532 };
533
534 } // namespace lldb_private
535
536 #endif // liblldb_ScriptInterpreter_h_