]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/lldb/Interpreter/ScriptInterpreter.h
Import LLDB as of upstream SVN 228549 (git 39760838)
[FreeBSD/FreeBSD.git] / 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 #include "lldb/lldb-private.h"
14
15 #include "lldb/Core/Broadcaster.h"
16 #include "lldb/Core/Error.h"
17
18 #include "lldb/Utility/PseudoTerminal.h"
19
20
21 namespace lldb_private {
22
23 class ScriptInterpreterObject
24 {
25 public:
26     ScriptInterpreterObject() :
27     m_object(NULL)
28     {}
29     
30     ScriptInterpreterObject(void* obj) :
31     m_object(obj)
32     {}
33     
34     ScriptInterpreterObject(const ScriptInterpreterObject& rhs)
35     : m_object(rhs.m_object)
36     {}
37     
38     virtual void*
39     GetObject()
40     {
41         return m_object;
42     }
43     
44     explicit operator bool ()
45     {
46         return m_object != NULL;
47     }
48     
49     ScriptInterpreterObject&
50     operator = (const ScriptInterpreterObject& rhs)
51     {
52         if (this != &rhs)
53             m_object = rhs.m_object;
54         return *this;
55     }
56         
57     virtual
58     ~ScriptInterpreterObject()
59     {}
60     
61 protected:
62     void* m_object;
63 };
64     
65 class ScriptInterpreterLocker
66 {
67 public:
68     
69     ScriptInterpreterLocker ()
70     {
71     }
72     
73     virtual ~ScriptInterpreterLocker ()
74     {
75     }
76 private:
77     DISALLOW_COPY_AND_ASSIGN (ScriptInterpreterLocker);
78 };
79
80
81 class ScriptInterpreter
82 {
83 public:
84
85     typedef void (*SWIGInitCallback) (void);
86
87     typedef bool (*SWIGBreakpointCallbackFunction) (const char *python_function_name,
88                                                     const char *session_dictionary_name,
89                                                     const lldb::StackFrameSP& frame_sp,
90                                                     const lldb::BreakpointLocationSP &bp_loc_sp);
91     
92     typedef bool (*SWIGWatchpointCallbackFunction) (const char *python_function_name,
93                                                     const char *session_dictionary_name,
94                                                     const lldb::StackFrameSP& frame_sp,
95                                                     const lldb::WatchpointSP &wp_sp);
96     
97     typedef bool (*SWIGPythonTypeScriptCallbackFunction) (const char *python_function_name,
98                                                           void *session_dictionary,
99                                                           const lldb::ValueObjectSP& valobj_sp,
100                                                           void** pyfunct_wrapper,
101                                                           const lldb::TypeSummaryOptionsSP& options,
102                                                           std::string& retval);
103     
104     typedef void* (*SWIGPythonCreateSyntheticProvider) (const char *python_class_name,
105                                                         const char *session_dictionary_name,
106                                                         const lldb::ValueObjectSP& valobj_sp);
107
108     typedef void* (*SWIGPythonCreateScriptedThreadPlan) (const char *python_class_name,
109                                                         const char *session_dictionary_name,
110                                                         const lldb::ThreadPlanSP& thread_plan_sp);
111
112     typedef bool (*SWIGPythonCallThreadPlan) (void *implementor, const char *method_name, Event *event_sp, bool &got_error);
113
114     typedef void* (*SWIGPythonCreateOSPlugin) (const char *python_class_name,
115                                                const char *session_dictionary_name,
116                                                const lldb::ProcessSP& process_sp);
117     
118     typedef uint32_t        (*SWIGPythonCalculateNumChildren)                   (void *implementor);
119     typedef void*           (*SWIGPythonGetChildAtIndex)                        (void *implementor, uint32_t idx);
120     typedef int             (*SWIGPythonGetIndexOfChildWithName)                (void *implementor, const char* child_name);
121     typedef void*           (*SWIGPythonCastPyObjectToSBValue)                  (void* data);
122     typedef lldb::ValueObjectSP  (*SWIGPythonGetValueObjectSPFromSBValue)       (void* data);
123     typedef bool            (*SWIGPythonUpdateSynthProviderInstance)            (void* data);
124     typedef bool            (*SWIGPythonMightHaveChildrenSynthProviderInstance) (void* data);
125     typedef void*           (*SWIGPythonGetValueSynthProviderInstance)          (void *implementor);
126     
127     typedef bool            (*SWIGPythonCallCommand)            (const char *python_function_name,
128                                                                  const char *session_dictionary_name,
129                                                                  lldb::DebuggerSP& debugger,
130                                                                  const char* args,
131                                                                  lldb_private::CommandReturnObject& cmd_retobj,
132                                                                  lldb::ExecutionContextRefSP exe_ctx_ref_sp);
133     
134     typedef bool            (*SWIGPythonCallModuleInit)         (const char *python_module_name,
135                                                                  const char *session_dictionary_name,
136                                                                  lldb::DebuggerSP& debugger);
137     
138     typedef bool            (*SWIGPythonScriptKeyword_Process)  (const char* python_function_name,
139                                                                  const char* session_dictionary_name,
140                                                                  lldb::ProcessSP& process,
141                                                                  std::string& output);
142     typedef bool            (*SWIGPythonScriptKeyword_Thread)   (const char* python_function_name,
143                                                                  const char* session_dictionary_name,
144                                                                  lldb::ThreadSP& thread,
145                                                                  std::string& output);
146     
147     typedef bool            (*SWIGPythonScriptKeyword_Target)   (const char* python_function_name,
148                                                                  const char* session_dictionary_name,
149                                                                  lldb::TargetSP& target,
150                                                                  std::string& output);
151
152     typedef bool            (*SWIGPythonScriptKeyword_Frame)    (const char* python_function_name,
153                                                                  const char* session_dictionary_name,
154                                                                  lldb::StackFrameSP& frame,
155                                                                  std::string& output);
156
157     typedef bool            (*SWIGPythonScriptKeyword_Value)    (const char* python_function_name,
158                                                                  const char* session_dictionary_name,
159                                                                  lldb::ValueObjectSP& value,
160                                                                  std::string& output);
161     
162     typedef void*           (*SWIGPython_GetDynamicSetting)     (void* module,
163                                                                  const char* setting,
164                                                                  const lldb::TargetSP& target_sp);
165
166     typedef enum
167     {
168         eScriptReturnTypeCharPtr,
169         eScriptReturnTypeBool,
170         eScriptReturnTypeShortInt,
171         eScriptReturnTypeShortIntUnsigned,
172         eScriptReturnTypeInt,
173         eScriptReturnTypeIntUnsigned,
174         eScriptReturnTypeLongInt,
175         eScriptReturnTypeLongIntUnsigned,
176         eScriptReturnTypeLongLong,
177         eScriptReturnTypeLongLongUnsigned,
178         eScriptReturnTypeFloat,
179         eScriptReturnTypeDouble,
180         eScriptReturnTypeChar,
181         eScriptReturnTypeCharStrOrNone,
182         eScriptReturnTypeOpaqueObject
183     } ScriptReturnType;
184     
185     ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang);
186
187     virtual ~ScriptInterpreter ();
188
189     struct ExecuteScriptOptions
190     {
191     public:
192         ExecuteScriptOptions () :
193             m_enable_io(true),
194             m_set_lldb_globals(true),
195             m_maskout_errors(true)
196         {
197         }
198         
199         bool
200         GetEnableIO () const
201         {
202             return m_enable_io;
203         }
204         
205         bool
206         GetSetLLDBGlobals () const
207         {
208             return m_set_lldb_globals;
209         }
210         
211         bool
212         GetMaskoutErrors () const
213         {
214             return m_maskout_errors;
215         }
216         
217         ExecuteScriptOptions&
218         SetEnableIO (bool enable)
219         {
220             m_enable_io = enable;
221             return *this;
222         }
223
224         ExecuteScriptOptions&
225         SetSetLLDBGlobals (bool set)
226         {
227             m_set_lldb_globals = set;
228             return *this;
229         }
230
231         ExecuteScriptOptions&
232         SetMaskoutErrors (bool maskout)
233         {
234             m_maskout_errors = maskout;
235             return *this;
236         }
237         
238     private:
239         bool m_enable_io;
240         bool m_set_lldb_globals;
241         bool m_maskout_errors;
242     };
243
244     virtual bool
245     Interrupt()
246     {
247         return false;
248     }
249
250     virtual bool
251     ExecuteOneLine (const char *command,
252                     CommandReturnObject *result,
253                     const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0;
254
255     virtual void
256     ExecuteInterpreterLoop () = 0;
257
258     virtual bool
259     ExecuteOneLineWithReturn (const char *in_string,
260                               ScriptReturnType return_type,
261                               void *ret_value,
262                               const ExecuteScriptOptions &options = ExecuteScriptOptions())
263     {
264         return true;
265     }
266
267     virtual Error
268     ExecuteMultipleLines (const char *in_string,
269                           const ExecuteScriptOptions &options = ExecuteScriptOptions())
270     {
271         Error error;
272         error.SetErrorString("not implemented");
273         return error;
274     }
275
276     virtual Error
277     ExportFunctionDefinitionToInterpreter (StringList &function_def)
278     {
279         Error error;
280         error.SetErrorString("not implemented");
281         return error;
282     }
283
284     virtual Error
285     GenerateBreakpointCommandCallbackData (StringList &input, std::string& output)
286     {
287         Error error;
288         error.SetErrorString("not implemented");
289         return error;
290     }
291     
292     virtual bool
293     GenerateWatchpointCommandCallbackData (StringList &input, std::string& output)
294     {
295         return false;
296     }
297     
298     virtual bool
299     GenerateTypeScriptFunction (const char* oneliner, std::string& output, const void* name_token = NULL)
300     {
301         return false;
302     }
303     
304     virtual bool
305     GenerateTypeScriptFunction (StringList &input, std::string& output, const void* name_token = NULL)
306     {
307         return false;
308     }
309     
310     virtual bool
311     GenerateScriptAliasFunction (StringList &input, std::string& output)
312     {
313         return false;
314     }
315     
316     virtual bool
317     GenerateTypeSynthClass (StringList &input, std::string& output, const void* name_token = NULL)
318     {
319         return false;
320     }
321     
322     virtual bool
323     GenerateTypeSynthClass (const char* oneliner, std::string& output, const void* name_token = NULL)
324     {
325         return false;
326     }
327     
328     virtual lldb::ScriptInterpreterObjectSP
329     CreateSyntheticScriptedProvider (const char *class_name,
330                                      lldb::ValueObjectSP valobj)
331     {
332         return lldb::ScriptInterpreterObjectSP();
333     }
334     
335     virtual lldb::ScriptInterpreterObjectSP
336     OSPlugin_CreatePluginObject (const char *class_name,
337                                  lldb::ProcessSP process_sp)
338     {
339         return lldb::ScriptInterpreterObjectSP();
340     }
341     
342     virtual lldb::ScriptInterpreterObjectSP
343     OSPlugin_RegisterInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp)
344     {
345         return lldb::ScriptInterpreterObjectSP();
346     }
347     
348     virtual lldb::ScriptInterpreterObjectSP
349     OSPlugin_ThreadsInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp)
350     {
351         return lldb::ScriptInterpreterObjectSP();
352     }
353     
354     virtual lldb::ScriptInterpreterObjectSP
355     OSPlugin_RegisterContextData (lldb::ScriptInterpreterObjectSP os_plugin_object_sp,
356                                   lldb::tid_t thread_id)
357     {
358         return lldb::ScriptInterpreterObjectSP();
359     }
360
361     virtual lldb::ScriptInterpreterObjectSP
362     OSPlugin_CreateThread (lldb::ScriptInterpreterObjectSP os_plugin_object_sp,
363                            lldb::tid_t tid,
364                            lldb::addr_t context)
365     {
366         return lldb::ScriptInterpreterObjectSP();
367     }
368     
369     virtual lldb::ScriptInterpreterObjectSP
370     CreateScriptedThreadPlan (const char *class_name,
371                               lldb::ThreadPlanSP thread_plan_sp)
372     {
373         return lldb::ScriptInterpreterObjectSP();
374     }
375
376     virtual bool
377     ScriptedThreadPlanExplainsStop (lldb::ScriptInterpreterObjectSP implementor_sp,
378                                     Event *event,
379                                     bool &script_error)
380     {
381         script_error = true;
382         return true;
383     }
384
385     virtual bool
386     ScriptedThreadPlanShouldStop (lldb::ScriptInterpreterObjectSP implementor_sp,
387                                   Event *event,
388                                   bool &script_error)
389     {
390         script_error = true;
391         return true;
392     }
393
394     virtual lldb::StateType
395     ScriptedThreadPlanGetRunState (lldb::ScriptInterpreterObjectSP implementor_sp,
396                                    bool &script_error)
397     {
398         script_error = true;
399         return lldb::eStateStepping;
400     }
401
402     virtual lldb::ScriptInterpreterObjectSP
403     LoadPluginModule (const FileSpec& file_spec,
404                      lldb_private::Error& error)
405     {
406         return lldb::ScriptInterpreterObjectSP();
407     }
408     
409     virtual lldb::ScriptInterpreterObjectSP
410     GetDynamicSettings (lldb::ScriptInterpreterObjectSP plugin_module_sp,
411                         Target* target,
412                         const char* setting_name,
413                         lldb_private::Error& error)
414     {
415         return lldb::ScriptInterpreterObjectSP();
416     }
417
418     virtual Error
419     GenerateFunction(const char *signature, const StringList &input)
420     {
421         Error error;
422         error.SetErrorString("unimplemented");
423         return error;
424     }
425
426     virtual void 
427     CollectDataForBreakpointCommandCallback (std::vector<BreakpointOptions *> &options,
428                                              CommandReturnObject &result);
429
430     virtual void 
431     CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options,
432                                              CommandReturnObject &result);
433
434     /// Set the specified text as the callback for the breakpoint.
435     Error
436     SetBreakpointCommandCallback (std::vector<BreakpointOptions *> &bp_options_vec,
437                                   const char *callback_text);
438
439     virtual Error
440     SetBreakpointCommandCallback (BreakpointOptions *bp_options,
441                                   const char *callback_text)
442     {
443         Error error;
444         error.SetErrorString("unimplemented");
445         return error;
446     }
447     
448     void
449     SetBreakpointCommandCallbackFunction (std::vector<BreakpointOptions *> &bp_options_vec,
450                                   const char *function_name);
451
452     /// Set a one-liner as the callback for the breakpoint.
453     virtual void 
454     SetBreakpointCommandCallbackFunction (BreakpointOptions *bp_options,
455                                   const char *function_name)
456     {
457         return;
458     }
459     
460     /// Set a one-liner as the callback for the watchpoint.
461     virtual void 
462     SetWatchpointCommandCallback (WatchpointOptions *wp_options,
463                                   const char *oneliner)
464     {
465         return;
466     }
467     
468     virtual bool
469     GetScriptedSummary (const char *function_name,
470                         lldb::ValueObjectSP valobj,
471                         lldb::ScriptInterpreterObjectSP& callee_wrapper_sp,
472                         const TypeSummaryOptions& options,
473                         std::string& retval)
474     {
475         return false;
476     }
477     
478     virtual void
479     Clear ()
480     {
481         // Clean up any ref counts to SBObjects that might be in global variables
482     }
483     
484     virtual size_t
485     CalculateNumChildren (const lldb::ScriptInterpreterObjectSP& implementor)
486     {
487         return 0;
488     }
489     
490     virtual lldb::ValueObjectSP
491     GetChildAtIndex (const lldb::ScriptInterpreterObjectSP& implementor, uint32_t idx)
492     {
493         return lldb::ValueObjectSP();
494     }
495     
496     virtual int
497     GetIndexOfChildWithName (const lldb::ScriptInterpreterObjectSP& implementor, const char* child_name)
498     {
499         return UINT32_MAX;
500     }
501     
502     virtual bool
503     UpdateSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor)
504     {
505         return false;
506     }
507     
508     virtual bool
509     MightHaveChildrenSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor)
510     {
511         return true;
512     }
513     
514     virtual lldb::ValueObjectSP
515     GetSyntheticValue (const lldb::ScriptInterpreterObjectSP& implementor)
516     {
517         return nullptr;
518     }
519     
520     virtual bool
521     RunScriptBasedCommand (const char* impl_function,
522                            const char* args,
523                            ScriptedCommandSynchronicity synchronicity,
524                            lldb_private::CommandReturnObject& cmd_retobj,
525                            Error& error,
526                            const lldb_private::ExecutionContext& exe_ctx)
527     {
528         return false;
529     }
530     
531     virtual bool
532     RunScriptFormatKeyword (const char* impl_function,
533                             Process* process,
534                             std::string& output,
535                             Error& error)
536     {
537         error.SetErrorString("unimplemented");
538         return false;
539     }
540
541     virtual bool
542     RunScriptFormatKeyword (const char* impl_function,
543                             Thread* thread,
544                             std::string& output,
545                             Error& error)
546     {
547         error.SetErrorString("unimplemented");
548         return false;
549     }
550     
551     virtual bool
552     RunScriptFormatKeyword (const char* impl_function,
553                             Target* target,
554                             std::string& output,
555                             Error& error)
556     {
557         error.SetErrorString("unimplemented");
558         return false;
559     }
560     
561     virtual bool
562     RunScriptFormatKeyword (const char* impl_function,
563                             StackFrame* frame,
564                             std::string& output,
565                             Error& error)
566     {
567         error.SetErrorString("unimplemented");
568         return false;
569     }
570     
571     virtual bool
572     RunScriptFormatKeyword (const char* impl_function,
573                             ValueObject* value,
574                             std::string& output,
575                             Error& error)
576     {
577         error.SetErrorString("unimplemented");
578         return false;
579     }
580     
581     virtual bool
582     GetDocumentationForItem (const char* item, std::string& dest)
583     {
584                 dest.clear();
585         return false;
586     }
587     
588     virtual bool
589     CheckObjectExists (const char* name)
590     {
591         return false;
592     }
593
594     virtual bool
595     LoadScriptingModule (const char* filename,
596                          bool can_reload,
597                          bool init_session,
598                          lldb_private::Error& error,
599                          lldb::ScriptInterpreterObjectSP* module_sp = nullptr)
600     {
601         error.SetErrorString("loading unimplemented");
602         return false;
603     }
604
605     virtual lldb::ScriptInterpreterObjectSP
606     MakeScriptObject (void* object)
607     {
608         return lldb::ScriptInterpreterObjectSP(new ScriptInterpreterObject(object));
609     }
610     
611     virtual std::unique_ptr<ScriptInterpreterLocker>
612     AcquireInterpreterLock ();
613     
614     const char *
615     GetScriptInterpreterPtyName ();
616
617     int
618     GetMasterFileDescriptor ();
619
620         CommandInterpreter &
621         GetCommandInterpreter ();
622
623     static std::string
624     LanguageToString (lldb::ScriptLanguage language);
625     
626     static void
627     InitializeInterpreter (SWIGInitCallback python_swig_init_callback,
628                            SWIGBreakpointCallbackFunction swig_breakpoint_callback,
629                            SWIGWatchpointCallbackFunction swig_watchpoint_callback,
630                            SWIGPythonTypeScriptCallbackFunction swig_typescript_callback,
631                            SWIGPythonCreateSyntheticProvider swig_synthetic_script,
632                            SWIGPythonCalculateNumChildren swig_calc_children,
633                            SWIGPythonGetChildAtIndex swig_get_child_index,
634                            SWIGPythonGetIndexOfChildWithName swig_get_index_child,
635                            SWIGPythonCastPyObjectToSBValue swig_cast_to_sbvalue ,
636                            SWIGPythonGetValueObjectSPFromSBValue swig_get_valobj_sp_from_sbvalue,
637                            SWIGPythonUpdateSynthProviderInstance swig_update_provider,
638                            SWIGPythonMightHaveChildrenSynthProviderInstance swig_mighthavechildren_provider,
639                            SWIGPythonGetValueSynthProviderInstance swig_getvalue_provider,
640                            SWIGPythonCallCommand swig_call_command,
641                            SWIGPythonCallModuleInit swig_call_module_init,
642                            SWIGPythonCreateOSPlugin swig_create_os_plugin,
643                            SWIGPythonScriptKeyword_Process swig_run_script_keyword_process,
644                            SWIGPythonScriptKeyword_Thread swig_run_script_keyword_thread,
645                            SWIGPythonScriptKeyword_Target swig_run_script_keyword_target,
646                            SWIGPythonScriptKeyword_Frame swig_run_script_keyword_frame,
647                            SWIGPythonScriptKeyword_Value swig_run_script_keyword_value,
648                            SWIGPython_GetDynamicSetting swig_plugin_get,
649                            SWIGPythonCreateScriptedThreadPlan swig_thread_plan_script,
650                            SWIGPythonCallThreadPlan swig_call_thread_plan);
651
652     virtual void
653     ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing.
654
655 protected:
656     CommandInterpreter &m_interpreter;
657     lldb::ScriptLanguage m_script_lang;
658 };
659
660 } // namespace lldb_private
661
662 #endif // #ifndef liblldb_ScriptInterpreter_h_