1254721Semaste//===-- ScriptInterpreter.h -------------------------------------*- C++ -*-===//
2254721Semaste//
3254721Semaste//                     The LLVM Compiler Infrastructure
4254721Semaste//
5254721Semaste// This file is distributed under the University of Illinois Open Source
6254721Semaste// License. See LICENSE.TXT for details.
7254721Semaste//
8254721Semaste//===----------------------------------------------------------------------===//
9254721Semaste
10254721Semaste#ifndef liblldb_ScriptInterpreter_h_
11254721Semaste#define liblldb_ScriptInterpreter_h_
12254721Semaste
13254721Semaste#include "lldb/lldb-private.h"
14254721Semaste
15254721Semaste#include "lldb/Core/Broadcaster.h"
16254721Semaste#include "lldb/Core/Error.h"
17254721Semaste
18254721Semaste#include "lldb/Utility/PseudoTerminal.h"
19254721Semaste
20254721Semaste
21254721Semastenamespace lldb_private {
22254721Semaste
23254721Semasteclass ScriptInterpreterObject
24254721Semaste{
25254721Semastepublic:
26254721Semaste    ScriptInterpreterObject() :
27254721Semaste    m_object(NULL)
28254721Semaste    {}
29254721Semaste
30254721Semaste    ScriptInterpreterObject(void* obj) :
31254721Semaste    m_object(obj)
32254721Semaste    {}
33254721Semaste
34254721Semaste    ScriptInterpreterObject(const ScriptInterpreterObject& rhs)
35254721Semaste    : m_object(rhs.m_object)
36254721Semaste    {}
37254721Semaste
38254721Semaste    virtual void*
39254721Semaste    GetObject()
40254721Semaste    {
41254721Semaste        return m_object;
42254721Semaste    }
43254721Semaste
44254721Semaste    operator bool ()
45254721Semaste    {
46254721Semaste        return m_object != NULL;
47254721Semaste    }
48254721Semaste
49254721Semaste    ScriptInterpreterObject&
50254721Semaste    operator = (const ScriptInterpreterObject& rhs)
51254721Semaste    {
52254721Semaste        if (this != &rhs)
53254721Semaste            m_object = rhs.m_object;
54254721Semaste        return *this;
55254721Semaste    }
56254721Semaste
57254721Semaste    virtual
58254721Semaste    ~ScriptInterpreterObject()
59254721Semaste    {}
60254721Semaste
61254721Semasteprotected:
62254721Semaste    void* m_object;
63254721Semaste};
64254721Semaste
65254721Semasteclass ScriptInterpreterLocker
66254721Semaste{
67254721Semastepublic:
68254721Semaste
69254721Semaste    ScriptInterpreterLocker ()
70254721Semaste    {
71254721Semaste    }
72254721Semaste
73254721Semaste    virtual ~ScriptInterpreterLocker ()
74254721Semaste    {
75254721Semaste    }
76254721Semasteprivate:
77254721Semaste    DISALLOW_COPY_AND_ASSIGN (ScriptInterpreterLocker);
78254721Semaste};
79254721Semaste
80254721Semaste
81254721Semasteclass ScriptInterpreter
82254721Semaste{
83254721Semastepublic:
84254721Semaste
85254721Semaste    typedef void (*SWIGInitCallback) (void);
86254721Semaste
87254721Semaste    typedef bool (*SWIGBreakpointCallbackFunction) (const char *python_function_name,
88254721Semaste                                                    const char *session_dictionary_name,
89254721Semaste                                                    const lldb::StackFrameSP& frame_sp,
90254721Semaste                                                    const lldb::BreakpointLocationSP &bp_loc_sp);
91254721Semaste
92254721Semaste    typedef bool (*SWIGWatchpointCallbackFunction) (const char *python_function_name,
93254721Semaste                                                    const char *session_dictionary_name,
94254721Semaste                                                    const lldb::StackFrameSP& frame_sp,
95254721Semaste                                                    const lldb::WatchpointSP &wp_sp);
96254721Semaste
97254721Semaste    typedef bool (*SWIGPythonTypeScriptCallbackFunction) (const char *python_function_name,
98254721Semaste                                                          void *session_dictionary,
99254721Semaste                                                          const lldb::ValueObjectSP& valobj_sp,
100254721Semaste                                                          void** pyfunct_wrapper,
101254721Semaste                                                          std::string& retval);
102254721Semaste
103254721Semaste    typedef void* (*SWIGPythonCreateSyntheticProvider) (const char *python_class_name,
104254721Semaste                                                        const char *session_dictionary_name,
105254721Semaste                                                        const lldb::ValueObjectSP& valobj_sp);
106254721Semaste
107254721Semaste    typedef void* (*SWIGPythonCreateOSPlugin) (const char *python_class_name,
108254721Semaste                                               const char *session_dictionary_name,
109254721Semaste                                               const lldb::ProcessSP& process_sp);
110254721Semaste
111254721Semaste    typedef uint32_t       (*SWIGPythonCalculateNumChildren)                   (void *implementor);
112254721Semaste    typedef void*          (*SWIGPythonGetChildAtIndex)                        (void *implementor, uint32_t idx);
113254721Semaste    typedef int            (*SWIGPythonGetIndexOfChildWithName)                (void *implementor, const char* child_name);
114254721Semaste    typedef void*          (*SWIGPythonCastPyObjectToSBValue)                  (void* data);
115254721Semaste    typedef bool           (*SWIGPythonUpdateSynthProviderInstance)            (void* data);
116254721Semaste    typedef bool           (*SWIGPythonMightHaveChildrenSynthProviderInstance) (void* data);
117254721Semaste
118254721Semaste
119254721Semaste    typedef bool           (*SWIGPythonCallCommand)                 (const char *python_function_name,
120254721Semaste                                                                     const char *session_dictionary_name,
121254721Semaste                                                                     lldb::DebuggerSP& debugger,
122254721Semaste                                                                     const char* args,
123254721Semaste                                                                     lldb_private::CommandReturnObject& cmd_retobj);
124254721Semaste
125254721Semaste    typedef bool           (*SWIGPythonCallModuleInit)              (const char *python_module_name,
126254721Semaste                                                                     const char *session_dictionary_name,
127254721Semaste                                                                     lldb::DebuggerSP& debugger);
128254721Semaste
129254721Semaste    typedef bool            (*SWIGPythonScriptKeyword_Process)      (const char* python_function_name,
130254721Semaste                                                                     const char* session_dictionary_name,
131254721Semaste                                                                     lldb::ProcessSP& process,
132254721Semaste                                                                     std::string& output);
133254721Semaste    typedef bool            (*SWIGPythonScriptKeyword_Thread)      (const char* python_function_name,
134254721Semaste                                                                    const char* session_dictionary_name,
135254721Semaste                                                                    lldb::ThreadSP& thread,
136254721Semaste                                                                    std::string& output);
137254721Semaste
138254721Semaste    typedef bool            (*SWIGPythonScriptKeyword_Target)      (const char* python_function_name,
139254721Semaste                                                                    const char* session_dictionary_name,
140254721Semaste                                                                    lldb::TargetSP& target,
141254721Semaste                                                                    std::string& output);
142254721Semaste
143254721Semaste    typedef bool            (*SWIGPythonScriptKeyword_Frame)      (const char* python_function_name,
144254721Semaste                                                                    const char* session_dictionary_name,
145254721Semaste                                                                    lldb::StackFrameSP& frame,
146254721Semaste                                                                    std::string& output);
147254721Semaste
148254721Semaste
149254721Semaste
150254721Semaste    typedef enum
151254721Semaste    {
152254721Semaste        eScriptReturnTypeCharPtr,
153254721Semaste        eScriptReturnTypeBool,
154254721Semaste        eScriptReturnTypeShortInt,
155254721Semaste        eScriptReturnTypeShortIntUnsigned,
156254721Semaste        eScriptReturnTypeInt,
157254721Semaste        eScriptReturnTypeIntUnsigned,
158254721Semaste        eScriptReturnTypeLongInt,
159254721Semaste        eScriptReturnTypeLongIntUnsigned,
160254721Semaste        eScriptReturnTypeLongLong,
161254721Semaste        eScriptReturnTypeLongLongUnsigned,
162254721Semaste        eScriptReturnTypeFloat,
163254721Semaste        eScriptReturnTypeDouble,
164254721Semaste        eScriptReturnTypeChar,
165254721Semaste        eScriptReturnTypeCharStrOrNone
166254721Semaste    } ScriptReturnType;
167254721Semaste
168254721Semaste    ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang);
169254721Semaste
170254721Semaste    virtual ~ScriptInterpreter ();
171254721Semaste
172254721Semaste    struct ExecuteScriptOptions
173254721Semaste    {
174254721Semaste    public:
175254721Semaste        ExecuteScriptOptions () :
176254721Semaste            m_enable_io(true),
177254721Semaste            m_set_lldb_globals(true),
178254721Semaste            m_maskout_errors(true)
179254721Semaste        {
180254721Semaste        }
181254721Semaste
182254721Semaste        bool
183254721Semaste        GetEnableIO () const
184254721Semaste        {
185254721Semaste            return m_enable_io;
186254721Semaste        }
187254721Semaste
188254721Semaste        bool
189254721Semaste        GetSetLLDBGlobals () const
190254721Semaste        {
191254721Semaste            return m_set_lldb_globals;
192254721Semaste        }
193254721Semaste
194254721Semaste        bool
195254721Semaste        GetMaskoutErrors () const
196254721Semaste        {
197254721Semaste            return m_maskout_errors;
198254721Semaste        }
199254721Semaste
200254721Semaste        ExecuteScriptOptions&
201254721Semaste        SetEnableIO (bool enable)
202254721Semaste        {
203254721Semaste            m_enable_io = enable;
204254721Semaste            return *this;
205254721Semaste        }
206254721Semaste
207254721Semaste        ExecuteScriptOptions&
208254721Semaste        SetSetLLDBGlobals (bool set)
209254721Semaste        {
210254721Semaste            m_set_lldb_globals = set;
211254721Semaste            return *this;
212254721Semaste        }
213254721Semaste
214254721Semaste        ExecuteScriptOptions&
215254721Semaste        SetMaskoutErrors (bool maskout)
216254721Semaste        {
217254721Semaste            m_maskout_errors = maskout;
218254721Semaste            return *this;
219254721Semaste        }
220254721Semaste
221254721Semaste    private:
222254721Semaste        bool m_enable_io;
223254721Semaste        bool m_set_lldb_globals;
224254721Semaste        bool m_maskout_errors;
225254721Semaste    };
226254721Semaste
227254721Semaste    virtual bool
228254721Semaste    ExecuteOneLine (const char *command,
229254721Semaste                    CommandReturnObject *result,
230254721Semaste                    const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0;
231254721Semaste
232254721Semaste    virtual void
233254721Semaste    ExecuteInterpreterLoop () = 0;
234254721Semaste
235254721Semaste    virtual bool
236254721Semaste    ExecuteOneLineWithReturn (const char *in_string,
237254721Semaste                              ScriptReturnType return_type,
238254721Semaste                              void *ret_value,
239254721Semaste                              const ExecuteScriptOptions &options = ExecuteScriptOptions())
240254721Semaste    {
241254721Semaste        return true;
242254721Semaste    }
243254721Semaste
244254721Semaste    virtual bool
245254721Semaste    ExecuteMultipleLines (const char *in_string,
246254721Semaste                          const ExecuteScriptOptions &options = ExecuteScriptOptions())
247254721Semaste    {
248254721Semaste        return true;
249254721Semaste    }
250254721Semaste
251254721Semaste    virtual bool
252254721Semaste    ExportFunctionDefinitionToInterpreter (StringList &function_def)
253254721Semaste    {
254254721Semaste        return false;
255254721Semaste    }
256254721Semaste
257254721Semaste    virtual bool
258254721Semaste    GenerateBreakpointCommandCallbackData (StringList &input, std::string& output)
259254721Semaste    {
260254721Semaste        return false;
261254721Semaste    }
262254721Semaste
263254721Semaste    virtual bool
264254721Semaste    GenerateWatchpointCommandCallbackData (StringList &input, std::string& output)
265254721Semaste    {
266254721Semaste        return false;
267254721Semaste    }
268254721Semaste
269254721Semaste    virtual bool
270254721Semaste    GenerateTypeScriptFunction (const char* oneliner, std::string& output, void* name_token = NULL)
271254721Semaste    {
272254721Semaste        return false;
273254721Semaste    }
274254721Semaste
275254721Semaste    virtual bool
276254721Semaste    GenerateTypeScriptFunction (StringList &input, std::string& output, void* name_token = NULL)
277254721Semaste    {
278254721Semaste        return false;
279254721Semaste    }
280254721Semaste
281254721Semaste    virtual bool
282254721Semaste    GenerateScriptAliasFunction (StringList &input, std::string& output)
283254721Semaste    {
284254721Semaste        return false;
285254721Semaste    }
286254721Semaste
287254721Semaste    virtual bool
288254721Semaste    GenerateTypeSynthClass (StringList &input, std::string& output, void* name_token = NULL)
289254721Semaste    {
290254721Semaste        return false;
291254721Semaste    }
292254721Semaste
293254721Semaste    virtual bool
294254721Semaste    GenerateTypeSynthClass (const char* oneliner, std::string& output, void* name_token = NULL)
295254721Semaste    {
296254721Semaste        return false;
297254721Semaste    }
298254721Semaste
299254721Semaste    virtual lldb::ScriptInterpreterObjectSP
300254721Semaste    CreateSyntheticScriptedProvider (const char *class_name,
301254721Semaste                                     lldb::ValueObjectSP valobj)
302254721Semaste    {
303254721Semaste        return lldb::ScriptInterpreterObjectSP();
304254721Semaste    }
305254721Semaste
306254721Semaste    virtual lldb::ScriptInterpreterObjectSP
307254721Semaste    OSPlugin_CreatePluginObject (const char *class_name,
308254721Semaste                                 lldb::ProcessSP process_sp)
309254721Semaste    {
310254721Semaste        return lldb::ScriptInterpreterObjectSP();
311254721Semaste    }
312254721Semaste
313254721Semaste    virtual lldb::ScriptInterpreterObjectSP
314254721Semaste    OSPlugin_RegisterInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp)
315254721Semaste    {
316254721Semaste        return lldb::ScriptInterpreterObjectSP();
317254721Semaste    }
318254721Semaste
319254721Semaste    virtual lldb::ScriptInterpreterObjectSP
320254721Semaste    OSPlugin_ThreadsInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp)
321254721Semaste    {
322254721Semaste        return lldb::ScriptInterpreterObjectSP();
323254721Semaste    }
324254721Semaste
325254721Semaste    virtual lldb::ScriptInterpreterObjectSP
326254721Semaste    OSPlugin_RegisterContextData (lldb::ScriptInterpreterObjectSP os_plugin_object_sp,
327254721Semaste                                  lldb::tid_t thread_id)
328254721Semaste    {
329254721Semaste        return lldb::ScriptInterpreterObjectSP();
330254721Semaste    }
331254721Semaste
332254721Semaste    virtual lldb::ScriptInterpreterObjectSP
333254721Semaste    OSPlugin_CreateThread (lldb::ScriptInterpreterObjectSP os_plugin_object_sp,
334254721Semaste                           lldb::tid_t tid,
335254721Semaste                           lldb::addr_t context)
336254721Semaste    {
337254721Semaste        return lldb::ScriptInterpreterObjectSP();
338254721Semaste    }
339254721Semaste
340254721Semaste    virtual bool
341254721Semaste    GenerateFunction(const char *signature, const StringList &input)
342254721Semaste    {
343254721Semaste        return false;
344254721Semaste    }
345254721Semaste
346254721Semaste    virtual void
347254721Semaste    CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options,
348254721Semaste                                             CommandReturnObject &result);
349254721Semaste
350254721Semaste    virtual void
351254721Semaste    CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options,
352254721Semaste                                             CommandReturnObject &result);
353254721Semaste
354254721Semaste    /// Set a one-liner as the callback for the breakpoint.
355254721Semaste    virtual void
356254721Semaste    SetBreakpointCommandCallback (BreakpointOptions *bp_options,
357254721Semaste                                  const char *oneliner)
358254721Semaste    {
359254721Semaste        return;
360254721Semaste    }
361254721Semaste
362254721Semaste    /// Set a one-liner as the callback for the watchpoint.
363254721Semaste    virtual void
364254721Semaste    SetWatchpointCommandCallback (WatchpointOptions *wp_options,
365254721Semaste                                  const char *oneliner)
366254721Semaste    {
367254721Semaste        return;
368254721Semaste    }
369254721Semaste
370254721Semaste    virtual bool
371254721Semaste    GetScriptedSummary (const char *function_name,
372254721Semaste                        lldb::ValueObjectSP valobj,
373254721Semaste                        lldb::ScriptInterpreterObjectSP& callee_wrapper_sp,
374254721Semaste                        std::string& retval)
375254721Semaste    {
376254721Semaste        return false;
377254721Semaste    }
378254721Semaste
379254721Semaste    virtual size_t
380254721Semaste    CalculateNumChildren (const lldb::ScriptInterpreterObjectSP& implementor)
381254721Semaste    {
382254721Semaste        return 0;
383254721Semaste    }
384254721Semaste
385254721Semaste    virtual lldb::ValueObjectSP
386254721Semaste    GetChildAtIndex (const lldb::ScriptInterpreterObjectSP& implementor, uint32_t idx)
387254721Semaste    {
388254721Semaste        return lldb::ValueObjectSP();
389254721Semaste    }
390254721Semaste
391254721Semaste    virtual int
392254721Semaste    GetIndexOfChildWithName (const lldb::ScriptInterpreterObjectSP& implementor, const char* child_name)
393254721Semaste    {
394254721Semaste        return UINT32_MAX;
395254721Semaste    }
396254721Semaste
397254721Semaste    virtual bool
398254721Semaste    UpdateSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor)
399254721Semaste    {
400254721Semaste        return false;
401254721Semaste    }
402254721Semaste
403254721Semaste    virtual bool
404254721Semaste    MightHaveChildrenSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor)
405254721Semaste    {
406254721Semaste        return true;
407254721Semaste    }
408254721Semaste
409254721Semaste    virtual bool
410254721Semaste    RunScriptBasedCommand (const char* impl_function,
411254721Semaste                           const char* args,
412254721Semaste                           ScriptedCommandSynchronicity synchronicity,
413254721Semaste                           lldb_private::CommandReturnObject& cmd_retobj,
414254721Semaste                           Error& error)
415254721Semaste    {
416254721Semaste        return false;
417254721Semaste    }
418254721Semaste
419254721Semaste    virtual bool
420254721Semaste    RunScriptFormatKeyword (const char* impl_function,
421254721Semaste                            Process* process,
422254721Semaste                            std::string& output,
423254721Semaste                            Error& error)
424254721Semaste    {
425254721Semaste        error.SetErrorString("unimplemented");
426254721Semaste        return false;
427254721Semaste    }
428254721Semaste
429254721Semaste    virtual bool
430254721Semaste    RunScriptFormatKeyword (const char* impl_function,
431254721Semaste                            Thread* thread,
432254721Semaste                            std::string& output,
433254721Semaste                            Error& error)
434254721Semaste    {
435254721Semaste        error.SetErrorString("unimplemented");
436254721Semaste        return false;
437254721Semaste    }
438254721Semaste
439254721Semaste    virtual bool
440254721Semaste    RunScriptFormatKeyword (const char* impl_function,
441254721Semaste                            Target* target,
442254721Semaste                            std::string& output,
443254721Semaste                            Error& error)
444254721Semaste    {
445254721Semaste        error.SetErrorString("unimplemented");
446254721Semaste        return false;
447254721Semaste    }
448254721Semaste
449254721Semaste    virtual bool
450254721Semaste    RunScriptFormatKeyword (const char* impl_function,
451254721Semaste                            StackFrame* frame,
452254721Semaste                            std::string& output,
453254721Semaste                            Error& error)
454254721Semaste    {
455254721Semaste        error.SetErrorString("unimplemented");
456254721Semaste        return false;
457254721Semaste    }
458254721Semaste
459254721Semaste    virtual bool
460254721Semaste    GetDocumentationForItem (const char* item, std::string& dest)
461254721Semaste    {
462254721Semaste		dest.clear();
463254721Semaste        return false;
464254721Semaste    }
465254721Semaste
466254721Semaste    virtual bool
467254721Semaste    CheckObjectExists (const char* name)
468254721Semaste    {
469254721Semaste        return false;
470254721Semaste    }
471254721Semaste
472254721Semaste    virtual bool
473254721Semaste    LoadScriptingModule (const char* filename,
474254721Semaste                         bool can_reload,
475254721Semaste                         bool init_session,
476254721Semaste                         lldb_private::Error& error)
477254721Semaste    {
478254721Semaste        error.SetErrorString("loading unimplemented");
479254721Semaste        return false;
480254721Semaste    }
481254721Semaste
482254721Semaste    virtual lldb::ScriptInterpreterObjectSP
483254721Semaste    MakeScriptObject (void* object)
484254721Semaste    {
485254721Semaste        return lldb::ScriptInterpreterObjectSP(new ScriptInterpreterObject(object));
486254721Semaste    }
487254721Semaste
488254721Semaste    virtual std::unique_ptr<ScriptInterpreterLocker>
489254721Semaste    AcquireInterpreterLock ();
490254721Semaste
491254721Semaste    const char *
492254721Semaste    GetScriptInterpreterPtyName ();
493254721Semaste
494254721Semaste    int
495254721Semaste    GetMasterFileDescriptor ();
496254721Semaste
497254721Semaste	CommandInterpreter &
498254721Semaste	GetCommandInterpreter ();
499254721Semaste
500254721Semaste    static std::string
501254721Semaste    LanguageToString (lldb::ScriptLanguage language);
502254721Semaste
503254721Semaste    static void
504254721Semaste    InitializeInterpreter (SWIGInitCallback python_swig_init_callback);
505254721Semaste
506254721Semaste    static void
507254721Semaste    TerminateInterpreter ();
508254721Semaste
509254721Semaste    virtual void
510254721Semaste    ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing.
511254721Semaste
512254721Semasteprotected:
513254721Semaste    CommandInterpreter &m_interpreter;
514254721Semaste    lldb::ScriptLanguage m_script_lang;
515254721Semaste};
516254721Semaste
517254721Semaste} // namespace lldb_private
518254721Semaste
519254721Semaste#endif // #ifndef liblldb_ScriptInterpreter_h_
520