]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Interpreter/ScriptInterpreter.h
Update LLDB snapshot to upstream r225923 (git 2b588ecd)
[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 #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     ExecuteOneLine (const char *command,
246                     CommandReturnObject *result,
247                     const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0;
248
249     virtual void
250     ExecuteInterpreterLoop () = 0;
251
252     virtual bool
253     ExecuteOneLineWithReturn (const char *in_string,
254                               ScriptReturnType return_type,
255                               void *ret_value,
256                               const ExecuteScriptOptions &options = ExecuteScriptOptions())
257     {
258         return true;
259     }
260
261     virtual Error
262     ExecuteMultipleLines (const char *in_string,
263                           const ExecuteScriptOptions &options = ExecuteScriptOptions())
264     {
265         Error error;
266         error.SetErrorString("not implemented");
267         return error;
268     }
269
270     virtual Error
271     ExportFunctionDefinitionToInterpreter (StringList &function_def)
272     {
273         Error error;
274         error.SetErrorString("not implemented");
275         return error;
276     }
277
278     virtual Error
279     GenerateBreakpointCommandCallbackData (StringList &input, std::string& output)
280     {
281         Error error;
282         error.SetErrorString("not implemented");
283         return error;
284     }
285     
286     virtual bool
287     GenerateWatchpointCommandCallbackData (StringList &input, std::string& output)
288     {
289         return false;
290     }
291     
292     virtual bool
293     GenerateTypeScriptFunction (const char* oneliner, std::string& output, void* name_token = NULL)
294     {
295         return false;
296     }
297     
298     virtual bool
299     GenerateTypeScriptFunction (StringList &input, std::string& output, void* name_token = NULL)
300     {
301         return false;
302     }
303     
304     virtual bool
305     GenerateScriptAliasFunction (StringList &input, std::string& output)
306     {
307         return false;
308     }
309     
310     virtual bool
311     GenerateTypeSynthClass (StringList &input, std::string& output, void* name_token = NULL)
312     {
313         return false;
314     }
315     
316     virtual bool
317     GenerateTypeSynthClass (const char* oneliner, std::string& output, void* name_token = NULL)
318     {
319         return false;
320     }
321     
322     virtual lldb::ScriptInterpreterObjectSP
323     CreateSyntheticScriptedProvider (const char *class_name,
324                                      lldb::ValueObjectSP valobj)
325     {
326         return lldb::ScriptInterpreterObjectSP();
327     }
328     
329     virtual lldb::ScriptInterpreterObjectSP
330     OSPlugin_CreatePluginObject (const char *class_name,
331                                  lldb::ProcessSP process_sp)
332     {
333         return lldb::ScriptInterpreterObjectSP();
334     }
335     
336     virtual lldb::ScriptInterpreterObjectSP
337     OSPlugin_RegisterInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp)
338     {
339         return lldb::ScriptInterpreterObjectSP();
340     }
341     
342     virtual lldb::ScriptInterpreterObjectSP
343     OSPlugin_ThreadsInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp)
344     {
345         return lldb::ScriptInterpreterObjectSP();
346     }
347     
348     virtual lldb::ScriptInterpreterObjectSP
349     OSPlugin_RegisterContextData (lldb::ScriptInterpreterObjectSP os_plugin_object_sp,
350                                   lldb::tid_t thread_id)
351     {
352         return lldb::ScriptInterpreterObjectSP();
353     }
354
355     virtual lldb::ScriptInterpreterObjectSP
356     OSPlugin_CreateThread (lldb::ScriptInterpreterObjectSP os_plugin_object_sp,
357                            lldb::tid_t tid,
358                            lldb::addr_t context)
359     {
360         return lldb::ScriptInterpreterObjectSP();
361     }
362     
363     virtual lldb::ScriptInterpreterObjectSP
364     CreateScriptedThreadPlan (const char *class_name,
365                               lldb::ThreadPlanSP thread_plan_sp)
366     {
367         return lldb::ScriptInterpreterObjectSP();
368     }
369
370     virtual bool
371     ScriptedThreadPlanExplainsStop (lldb::ScriptInterpreterObjectSP implementor_sp,
372                                     Event *event,
373                                     bool &script_error)
374     {
375         script_error = true;
376         return true;
377     }
378
379     virtual bool
380     ScriptedThreadPlanShouldStop (lldb::ScriptInterpreterObjectSP implementor_sp,
381                                   Event *event,
382                                   bool &script_error)
383     {
384         script_error = true;
385         return true;
386     }
387
388     virtual lldb::StateType
389     ScriptedThreadPlanGetRunState (lldb::ScriptInterpreterObjectSP implementor_sp,
390                                    bool &script_error)
391     {
392         script_error = true;
393         return lldb::eStateStepping;
394     }
395
396     virtual lldb::ScriptInterpreterObjectSP
397     LoadPluginModule (const FileSpec& file_spec,
398                      lldb_private::Error& error)
399     {
400         return lldb::ScriptInterpreterObjectSP();
401     }
402     
403     virtual lldb::ScriptInterpreterObjectSP
404     GetDynamicSettings (lldb::ScriptInterpreterObjectSP plugin_module_sp,
405                         Target* target,
406                         const char* setting_name,
407                         lldb_private::Error& error)
408     {
409         return lldb::ScriptInterpreterObjectSP();
410     }
411
412     virtual Error
413     GenerateFunction(const char *signature, const StringList &input)
414     {
415         Error error;
416         error.SetErrorString("unimplemented");
417         return error;
418     }
419
420     virtual void 
421     CollectDataForBreakpointCommandCallback (std::vector<BreakpointOptions *> &options,
422                                              CommandReturnObject &result);
423
424     virtual void 
425     CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options,
426                                              CommandReturnObject &result);
427
428     /// Set the specified text as the callback for the breakpoint.
429     Error
430     SetBreakpointCommandCallback (std::vector<BreakpointOptions *> &bp_options_vec,
431                                   const char *callback_text);
432
433     virtual Error
434     SetBreakpointCommandCallback (BreakpointOptions *bp_options,
435                                   const char *callback_text)
436     {
437         Error error;
438         error.SetErrorString("unimplemented");
439         return error;
440     }
441     
442     void
443     SetBreakpointCommandCallbackFunction (std::vector<BreakpointOptions *> &bp_options_vec,
444                                   const char *function_name);
445
446     /// Set a one-liner as the callback for the breakpoint.
447     virtual void 
448     SetBreakpointCommandCallbackFunction (BreakpointOptions *bp_options,
449                                   const char *function_name)
450     {
451         return;
452     }
453     
454     /// Set a one-liner as the callback for the watchpoint.
455     virtual void 
456     SetWatchpointCommandCallback (WatchpointOptions *wp_options,
457                                   const char *oneliner)
458     {
459         return;
460     }
461     
462     virtual bool
463     GetScriptedSummary (const char *function_name,
464                         lldb::ValueObjectSP valobj,
465                         lldb::ScriptInterpreterObjectSP& callee_wrapper_sp,
466                         const TypeSummaryOptions& options,
467                         std::string& retval)
468     {
469         return false;
470     }
471     
472     virtual void
473     Clear ()
474     {
475         // Clean up any ref counts to SBObjects that might be in global variables
476     }
477     
478     virtual size_t
479     CalculateNumChildren (const lldb::ScriptInterpreterObjectSP& implementor)
480     {
481         return 0;
482     }
483     
484     virtual lldb::ValueObjectSP
485     GetChildAtIndex (const lldb::ScriptInterpreterObjectSP& implementor, uint32_t idx)
486     {
487         return lldb::ValueObjectSP();
488     }
489     
490     virtual int
491     GetIndexOfChildWithName (const lldb::ScriptInterpreterObjectSP& implementor, const char* child_name)
492     {
493         return UINT32_MAX;
494     }
495     
496     virtual bool
497     UpdateSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor)
498     {
499         return false;
500     }
501     
502     virtual bool
503     MightHaveChildrenSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor)
504     {
505         return true;
506     }
507     
508     virtual lldb::ValueObjectSP
509     GetSyntheticValue (const lldb::ScriptInterpreterObjectSP& implementor)
510     {
511         return nullptr;
512     }
513     
514     virtual bool
515     RunScriptBasedCommand (const char* impl_function,
516                            const char* args,
517                            ScriptedCommandSynchronicity synchronicity,
518                            lldb_private::CommandReturnObject& cmd_retobj,
519                            Error& error,
520                            const lldb_private::ExecutionContext& exe_ctx)
521     {
522         return false;
523     }
524     
525     virtual bool
526     RunScriptFormatKeyword (const char* impl_function,
527                             Process* process,
528                             std::string& output,
529                             Error& error)
530     {
531         error.SetErrorString("unimplemented");
532         return false;
533     }
534
535     virtual bool
536     RunScriptFormatKeyword (const char* impl_function,
537                             Thread* thread,
538                             std::string& output,
539                             Error& error)
540     {
541         error.SetErrorString("unimplemented");
542         return false;
543     }
544     
545     virtual bool
546     RunScriptFormatKeyword (const char* impl_function,
547                             Target* target,
548                             std::string& output,
549                             Error& error)
550     {
551         error.SetErrorString("unimplemented");
552         return false;
553     }
554     
555     virtual bool
556     RunScriptFormatKeyword (const char* impl_function,
557                             StackFrame* frame,
558                             std::string& output,
559                             Error& error)
560     {
561         error.SetErrorString("unimplemented");
562         return false;
563     }
564     
565     virtual bool
566     RunScriptFormatKeyword (const char* impl_function,
567                             ValueObject* value,
568                             std::string& output,
569                             Error& error)
570     {
571         error.SetErrorString("unimplemented");
572         return false;
573     }
574     
575     virtual bool
576     GetDocumentationForItem (const char* item, std::string& dest)
577     {
578                 dest.clear();
579         return false;
580     }
581     
582     virtual bool
583     CheckObjectExists (const char* name)
584     {
585         return false;
586     }
587
588     virtual bool
589     LoadScriptingModule (const char* filename,
590                          bool can_reload,
591                          bool init_session,
592                          lldb_private::Error& error,
593                          lldb::ScriptInterpreterObjectSP* module_sp = nullptr)
594     {
595         error.SetErrorString("loading unimplemented");
596         return false;
597     }
598
599     virtual lldb::ScriptInterpreterObjectSP
600     MakeScriptObject (void* object)
601     {
602         return lldb::ScriptInterpreterObjectSP(new ScriptInterpreterObject(object));
603     }
604     
605     virtual std::unique_ptr<ScriptInterpreterLocker>
606     AcquireInterpreterLock ();
607     
608     const char *
609     GetScriptInterpreterPtyName ();
610
611     int
612     GetMasterFileDescriptor ();
613
614         CommandInterpreter &
615         GetCommandInterpreter ();
616
617     static std::string
618     LanguageToString (lldb::ScriptLanguage language);
619     
620     static void
621     InitializeInterpreter (SWIGInitCallback python_swig_init_callback,
622                            SWIGBreakpointCallbackFunction swig_breakpoint_callback,
623                            SWIGWatchpointCallbackFunction swig_watchpoint_callback,
624                            SWIGPythonTypeScriptCallbackFunction swig_typescript_callback,
625                            SWIGPythonCreateSyntheticProvider swig_synthetic_script,
626                            SWIGPythonCalculateNumChildren swig_calc_children,
627                            SWIGPythonGetChildAtIndex swig_get_child_index,
628                            SWIGPythonGetIndexOfChildWithName swig_get_index_child,
629                            SWIGPythonCastPyObjectToSBValue swig_cast_to_sbvalue ,
630                            SWIGPythonGetValueObjectSPFromSBValue swig_get_valobj_sp_from_sbvalue,
631                            SWIGPythonUpdateSynthProviderInstance swig_update_provider,
632                            SWIGPythonMightHaveChildrenSynthProviderInstance swig_mighthavechildren_provider,
633                            SWIGPythonGetValueSynthProviderInstance swig_getvalue_provider,
634                            SWIGPythonCallCommand swig_call_command,
635                            SWIGPythonCallModuleInit swig_call_module_init,
636                            SWIGPythonCreateOSPlugin swig_create_os_plugin,
637                            SWIGPythonScriptKeyword_Process swig_run_script_keyword_process,
638                            SWIGPythonScriptKeyword_Thread swig_run_script_keyword_thread,
639                            SWIGPythonScriptKeyword_Target swig_run_script_keyword_target,
640                            SWIGPythonScriptKeyword_Frame swig_run_script_keyword_frame,
641                            SWIGPythonScriptKeyword_Value swig_run_script_keyword_value,
642                            SWIGPython_GetDynamicSetting swig_plugin_get,
643                            SWIGPythonCreateScriptedThreadPlan swig_thread_plan_script,
644                            SWIGPythonCallThreadPlan swig_call_thread_plan);
645
646     virtual void
647     ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing.
648
649 protected:
650     CommandInterpreter &m_interpreter;
651     lldb::ScriptLanguage m_script_lang;
652 };
653
654 } // namespace lldb_private
655
656 #endif // #ifndef liblldb_ScriptInterpreter_h_