]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/tools/lldb/include/lldb/Interpreter/ScriptInterpreter.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.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                                                           std::string& retval);
102     
103     typedef void* (*SWIGPythonCreateSyntheticProvider) (const char *python_class_name,
104                                                         const char *session_dictionary_name,
105                                                         const lldb::ValueObjectSP& valobj_sp);
106
107     typedef void* (*SWIGPythonCreateOSPlugin) (const char *python_class_name,
108                                                const char *session_dictionary_name,
109                                                const lldb::ProcessSP& process_sp);
110     
111     typedef uint32_t        (*SWIGPythonCalculateNumChildren)                   (void *implementor);
112     typedef void*           (*SWIGPythonGetChildAtIndex)                        (void *implementor, uint32_t idx);
113     typedef int             (*SWIGPythonGetIndexOfChildWithName)                (void *implementor, const char* child_name);
114     typedef void*           (*SWIGPythonCastPyObjectToSBValue)                  (void* data);
115     typedef lldb::ValueObjectSP  (*SWIGPythonGetValueObjectSPFromSBValue)       (void* data);
116     typedef bool            (*SWIGPythonUpdateSynthProviderInstance)            (void* data);
117     typedef bool            (*SWIGPythonMightHaveChildrenSynthProviderInstance) (void* data);
118
119     
120     typedef bool            (*SWIGPythonCallCommand)            (const char *python_function_name,
121                                                                  const char *session_dictionary_name,
122                                                                  lldb::DebuggerSP& debugger,
123                                                                  const char* args,
124                                                                  lldb_private::CommandReturnObject& cmd_retobj);
125     
126     typedef bool            (*SWIGPythonCallModuleInit)         (const char *python_module_name,
127                                                                  const char *session_dictionary_name,
128                                                                  lldb::DebuggerSP& debugger);
129     
130     typedef bool            (*SWIGPythonScriptKeyword_Process)  (const char* python_function_name,
131                                                                  const char* session_dictionary_name,
132                                                                  lldb::ProcessSP& process,
133                                                                  std::string& output);
134     typedef bool            (*SWIGPythonScriptKeyword_Thread)   (const char* python_function_name,
135                                                                  const char* session_dictionary_name,
136                                                                  lldb::ThreadSP& thread,
137                                                                  std::string& output);
138     
139     typedef bool            (*SWIGPythonScriptKeyword_Target)   (const char* python_function_name,
140                                                                  const char* session_dictionary_name,
141                                                                  lldb::TargetSP& target,
142                                                                  std::string& output);
143
144     typedef bool            (*SWIGPythonScriptKeyword_Frame)    (const char* python_function_name,
145                                                                  const char* session_dictionary_name,
146                                                                  lldb::StackFrameSP& frame,
147                                                                  std::string& output);
148     
149     typedef void*           (*SWIGPython_GetDynamicSetting)     (void* module,
150                                                                  const char* setting,
151                                                                  const lldb::TargetSP& target_sp);
152
153     typedef enum
154     {
155         eScriptReturnTypeCharPtr,
156         eScriptReturnTypeBool,
157         eScriptReturnTypeShortInt,
158         eScriptReturnTypeShortIntUnsigned,
159         eScriptReturnTypeInt,
160         eScriptReturnTypeIntUnsigned,
161         eScriptReturnTypeLongInt,
162         eScriptReturnTypeLongIntUnsigned,
163         eScriptReturnTypeLongLong,
164         eScriptReturnTypeLongLongUnsigned,
165         eScriptReturnTypeFloat,
166         eScriptReturnTypeDouble,
167         eScriptReturnTypeChar,
168         eScriptReturnTypeCharStrOrNone,
169         eScriptReturnTypeOpaqueObject
170     } ScriptReturnType;
171     
172     ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang);
173
174     virtual ~ScriptInterpreter ();
175
176     struct ExecuteScriptOptions
177     {
178     public:
179         ExecuteScriptOptions () :
180             m_enable_io(true),
181             m_set_lldb_globals(true),
182             m_maskout_errors(true)
183         {
184         }
185         
186         bool
187         GetEnableIO () const
188         {
189             return m_enable_io;
190         }
191         
192         bool
193         GetSetLLDBGlobals () const
194         {
195             return m_set_lldb_globals;
196         }
197         
198         bool
199         GetMaskoutErrors () const
200         {
201             return m_maskout_errors;
202         }
203         
204         ExecuteScriptOptions&
205         SetEnableIO (bool enable)
206         {
207             m_enable_io = enable;
208             return *this;
209         }
210
211         ExecuteScriptOptions&
212         SetSetLLDBGlobals (bool set)
213         {
214             m_set_lldb_globals = set;
215             return *this;
216         }
217
218         ExecuteScriptOptions&
219         SetMaskoutErrors (bool maskout)
220         {
221             m_maskout_errors = maskout;
222             return *this;
223         }
224         
225     private:
226         bool m_enable_io;
227         bool m_set_lldb_globals;
228         bool m_maskout_errors;
229     };
230     
231     virtual bool
232     ExecuteOneLine (const char *command,
233                     CommandReturnObject *result,
234                     const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0;
235
236     virtual void
237     ExecuteInterpreterLoop () = 0;
238
239     virtual bool
240     ExecuteOneLineWithReturn (const char *in_string,
241                               ScriptReturnType return_type,
242                               void *ret_value,
243                               const ExecuteScriptOptions &options = ExecuteScriptOptions())
244     {
245         return true;
246     }
247
248     virtual Error
249     ExecuteMultipleLines (const char *in_string,
250                           const ExecuteScriptOptions &options = ExecuteScriptOptions())
251     {
252         Error error;
253         error.SetErrorString("not implemented");
254         return error;
255     }
256
257     virtual bool
258     ExportFunctionDefinitionToInterpreter (StringList &function_def)
259     {
260         return false;
261     }
262
263     virtual bool
264     GenerateBreakpointCommandCallbackData (StringList &input, std::string& output)
265     {
266         return false;
267     }
268     
269     virtual bool
270     GenerateWatchpointCommandCallbackData (StringList &input, std::string& output)
271     {
272         return false;
273     }
274     
275     virtual bool
276     GenerateTypeScriptFunction (const char* oneliner, std::string& output, void* name_token = NULL)
277     {
278         return false;
279     }
280     
281     virtual bool
282     GenerateTypeScriptFunction (StringList &input, std::string& output, void* name_token = NULL)
283     {
284         return false;
285     }
286     
287     virtual bool
288     GenerateScriptAliasFunction (StringList &input, std::string& output)
289     {
290         return false;
291     }
292     
293     virtual bool
294     GenerateTypeSynthClass (StringList &input, std::string& output, void* name_token = NULL)
295     {
296         return false;
297     }
298     
299     virtual bool
300     GenerateTypeSynthClass (const char* oneliner, std::string& output, void* name_token = NULL)
301     {
302         return false;
303     }
304     
305     virtual lldb::ScriptInterpreterObjectSP
306     CreateSyntheticScriptedProvider (const char *class_name,
307                                      lldb::ValueObjectSP valobj)
308     {
309         return lldb::ScriptInterpreterObjectSP();
310     }
311     
312     virtual lldb::ScriptInterpreterObjectSP
313     OSPlugin_CreatePluginObject (const char *class_name,
314                                  lldb::ProcessSP process_sp)
315     {
316         return lldb::ScriptInterpreterObjectSP();
317     }
318     
319     virtual lldb::ScriptInterpreterObjectSP
320     OSPlugin_RegisterInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp)
321     {
322         return lldb::ScriptInterpreterObjectSP();
323     }
324     
325     virtual lldb::ScriptInterpreterObjectSP
326     OSPlugin_ThreadsInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp)
327     {
328         return lldb::ScriptInterpreterObjectSP();
329     }
330     
331     virtual lldb::ScriptInterpreterObjectSP
332     OSPlugin_RegisterContextData (lldb::ScriptInterpreterObjectSP os_plugin_object_sp,
333                                   lldb::tid_t thread_id)
334     {
335         return lldb::ScriptInterpreterObjectSP();
336     }
337
338     virtual lldb::ScriptInterpreterObjectSP
339     OSPlugin_CreateThread (lldb::ScriptInterpreterObjectSP os_plugin_object_sp,
340                            lldb::tid_t tid,
341                            lldb::addr_t context)
342     {
343         return lldb::ScriptInterpreterObjectSP();
344     }
345     
346     virtual lldb::ScriptInterpreterObjectSP
347     LoadPluginModule (const FileSpec& file_spec,
348                      lldb_private::Error& error)
349     {
350         return lldb::ScriptInterpreterObjectSP();
351     }
352     
353     virtual lldb::ScriptInterpreterObjectSP
354     GetDynamicSettings (lldb::ScriptInterpreterObjectSP plugin_module_sp,
355                         Target* target,
356                         const char* setting_name,
357                         lldb_private::Error& error)
358     {
359         return lldb::ScriptInterpreterObjectSP();
360     }
361
362     virtual bool
363     GenerateFunction(const char *signature, const StringList &input)
364     {
365         return false;
366     }
367
368     virtual void 
369     CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options,
370                                              CommandReturnObject &result);
371
372     virtual void 
373     CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options,
374                                              CommandReturnObject &result);
375
376     /// Set a one-liner as the callback for the breakpoint.
377     virtual void 
378     SetBreakpointCommandCallback (BreakpointOptions *bp_options,
379                                   const char *oneliner)
380     {
381         return;
382     }
383     
384     /// Set a one-liner as the callback for the watchpoint.
385     virtual void 
386     SetWatchpointCommandCallback (WatchpointOptions *wp_options,
387                                   const char *oneliner)
388     {
389         return;
390     }
391     
392     virtual bool
393     GetScriptedSummary (const char *function_name,
394                         lldb::ValueObjectSP valobj,
395                         lldb::ScriptInterpreterObjectSP& callee_wrapper_sp,
396                         std::string& retval)
397     {
398         return false;
399     }
400     
401     virtual size_t
402     CalculateNumChildren (const lldb::ScriptInterpreterObjectSP& implementor)
403     {
404         return 0;
405     }
406     
407     virtual lldb::ValueObjectSP
408     GetChildAtIndex (const lldb::ScriptInterpreterObjectSP& implementor, uint32_t idx)
409     {
410         return lldb::ValueObjectSP();
411     }
412     
413     virtual int
414     GetIndexOfChildWithName (const lldb::ScriptInterpreterObjectSP& implementor, const char* child_name)
415     {
416         return UINT32_MAX;
417     }
418     
419     virtual bool
420     UpdateSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor)
421     {
422         return false;
423     }
424     
425     virtual bool
426     MightHaveChildrenSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor)
427     {
428         return true;
429     }
430     
431     virtual bool
432     RunScriptBasedCommand (const char* impl_function,
433                            const char* args,
434                            ScriptedCommandSynchronicity synchronicity,
435                            lldb_private::CommandReturnObject& cmd_retobj,
436                            Error& error)
437     {
438         return false;
439     }
440     
441     virtual bool
442     RunScriptFormatKeyword (const char* impl_function,
443                             Process* process,
444                             std::string& output,
445                             Error& error)
446     {
447         error.SetErrorString("unimplemented");
448         return false;
449     }
450
451     virtual bool
452     RunScriptFormatKeyword (const char* impl_function,
453                             Thread* thread,
454                             std::string& output,
455                             Error& error)
456     {
457         error.SetErrorString("unimplemented");
458         return false;
459     }
460     
461     virtual bool
462     RunScriptFormatKeyword (const char* impl_function,
463                             Target* target,
464                             std::string& output,
465                             Error& error)
466     {
467         error.SetErrorString("unimplemented");
468         return false;
469     }
470     
471     virtual bool
472     RunScriptFormatKeyword (const char* impl_function,
473                             StackFrame* frame,
474                             std::string& output,
475                             Error& error)
476     {
477         error.SetErrorString("unimplemented");
478         return false;
479     }
480     
481     virtual bool
482     GetDocumentationForItem (const char* item, std::string& dest)
483     {
484                 dest.clear();
485         return false;
486     }
487     
488     virtual bool
489     CheckObjectExists (const char* name)
490     {
491         return false;
492     }
493
494     virtual bool
495     LoadScriptingModule (const char* filename,
496                          bool can_reload,
497                          bool init_session,
498                          lldb_private::Error& error,
499                          lldb::ScriptInterpreterObjectSP* module_sp = nullptr)
500     {
501         error.SetErrorString("loading unimplemented");
502         return false;
503     }
504
505     virtual lldb::ScriptInterpreterObjectSP
506     MakeScriptObject (void* object)
507     {
508         return lldb::ScriptInterpreterObjectSP(new ScriptInterpreterObject(object));
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     static void
527     InitializeInterpreter (SWIGInitCallback python_swig_init_callback,
528                            SWIGBreakpointCallbackFunction swig_breakpoint_callback,
529                            SWIGWatchpointCallbackFunction swig_watchpoint_callback,
530                            SWIGPythonTypeScriptCallbackFunction swig_typescript_callback,
531                            SWIGPythonCreateSyntheticProvider swig_synthetic_script,
532                            SWIGPythonCalculateNumChildren swig_calc_children,
533                            SWIGPythonGetChildAtIndex swig_get_child_index,
534                            SWIGPythonGetIndexOfChildWithName swig_get_index_child,
535                            SWIGPythonCastPyObjectToSBValue swig_cast_to_sbvalue ,
536                            SWIGPythonGetValueObjectSPFromSBValue swig_get_valobj_sp_from_sbvalue,
537                            SWIGPythonUpdateSynthProviderInstance swig_update_provider,
538                            SWIGPythonMightHaveChildrenSynthProviderInstance swig_mighthavechildren_provider,
539                            SWIGPythonCallCommand swig_call_command,
540                            SWIGPythonCallModuleInit swig_call_module_init,
541                            SWIGPythonCreateOSPlugin swig_create_os_plugin,
542                            SWIGPythonScriptKeyword_Process swig_run_script_keyword_process,
543                            SWIGPythonScriptKeyword_Thread swig_run_script_keyword_thread,
544                            SWIGPythonScriptKeyword_Target swig_run_script_keyword_target,
545                            SWIGPythonScriptKeyword_Frame swig_run_script_keyword_frame,
546                            SWIGPython_GetDynamicSetting swig_plugin_get);
547
548     static void
549     TerminateInterpreter ();
550
551     virtual void
552     ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing.
553
554 protected:
555     CommandInterpreter &m_interpreter;
556     lldb::ScriptLanguage m_script_lang;
557 };
558
559 } // namespace lldb_private
560
561 #endif // #ifndef liblldb_ScriptInterpreter_h_