ScriptInterpreter.h revision 155ee91cc315888c26de1bfebd876bf35b857329
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
21namespace lldb_private {
22
23class ScriptInterpreterObject
24{
25public:
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    ScriptInterpreterObject&
45    operator = (const ScriptInterpreterObject& rhs)
46    {
47        if (this != &rhs)
48            m_object = rhs.m_object;
49        return *this;
50    }
51
52    virtual
53    ~ScriptInterpreterObject()
54    {}
55
56protected:
57    void* m_object;
58};
59
60class ScriptInterpreter
61{
62public:
63
64    typedef void (*SWIGInitCallback) (void);
65
66    typedef bool (*SWIGBreakpointCallbackFunction) (const char *python_function_name,
67                                                    const char *session_dictionary_name,
68                                                    const lldb::StackFrameSP& frame_sp,
69                                                    const lldb::BreakpointLocationSP &bp_loc_sp);
70
71    typedef bool (*SWIGWatchpointCallbackFunction) (const char *python_function_name,
72                                                    const char *session_dictionary_name,
73                                                    const lldb::StackFrameSP& frame_sp,
74                                                    const lldb::WatchpointSP &wp_sp);
75
76    typedef bool (*SWIGPythonTypeScriptCallbackFunction) (const char *python_function_name,
77                                                          void *session_dictionary,
78                                                          const lldb::ValueObjectSP& valobj_sp,
79                                                          void** pyfunct_wrapper,
80                                                          std::string& retval);
81
82    typedef void* (*SWIGPythonCreateSyntheticProvider) (const std::string python_class_name,
83                                                        const char *session_dictionary_name,
84                                                        const lldb::ValueObjectSP& valobj_sp);
85
86    typedef void* (*SWIGPythonCreateOSPlugin) (const std::string python_class_name,
87                                               const char *session_dictionary_name,
88                                               const lldb::ProcessSP& process_sp);
89
90    typedef uint32_t       (*SWIGPythonCalculateNumChildren)        (void *implementor);
91    typedef void*          (*SWIGPythonGetChildAtIndex)             (void *implementor, uint32_t idx);
92    typedef int            (*SWIGPythonGetIndexOfChildWithName)     (void *implementor, const char* child_name);
93    typedef void*          (*SWIGPythonCastPyObjectToSBValue)       (void* data);
94    typedef bool           (*SWIGPythonUpdateSynthProviderInstance) (void* data);
95
96    typedef bool           (*SWIGPythonCallCommand)                 (const char *python_function_name,
97                                                                     const char *session_dictionary_name,
98                                                                     lldb::DebuggerSP& debugger,
99                                                                     const char* args,
100                                                                     std::string& err_msg,
101                                                                     lldb_private::CommandReturnObject& cmd_retobj);
102
103    typedef bool           (*SWIGPythonCallModuleInit)              (const std::string python_module_name,
104                                                                     const char *session_dictionary_name,
105                                                                     lldb::DebuggerSP& debugger);
106
107    typedef enum
108    {
109        eScriptReturnTypeCharPtr,
110        eScriptReturnTypeBool,
111        eScriptReturnTypeShortInt,
112        eScriptReturnTypeShortIntUnsigned,
113        eScriptReturnTypeInt,
114        eScriptReturnTypeIntUnsigned,
115        eScriptReturnTypeLongInt,
116        eScriptReturnTypeLongIntUnsigned,
117        eScriptReturnTypeLongLong,
118        eScriptReturnTypeLongLongUnsigned,
119        eScriptReturnTypeFloat,
120        eScriptReturnTypeDouble,
121        eScriptReturnTypeChar,
122        eScriptReturnTypeCharStrOrNone
123    } ScriptReturnType;
124
125    ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang);
126
127    virtual ~ScriptInterpreter ();
128
129    virtual bool
130    ExecuteOneLine (const char *command, CommandReturnObject *result, bool enable_io) = 0;
131
132    virtual void
133    ExecuteInterpreterLoop () = 0;
134
135    virtual bool
136    ExecuteOneLineWithReturn (const char *in_string, ScriptReturnType return_type, void *ret_value, bool enable_io)
137    {
138        return true;
139    }
140
141    virtual bool
142    ExecuteMultipleLines (const char *in_string, bool enable_io)
143    {
144        return true;
145    }
146
147    virtual bool
148    ExportFunctionDefinitionToInterpreter (StringList &function_def)
149    {
150        return false;
151    }
152
153    virtual bool
154    GenerateBreakpointCommandCallbackData (StringList &input, std::string& output)
155    {
156        return false;
157    }
158
159    virtual bool
160    GenerateWatchpointCommandCallbackData (StringList &input, std::string& output)
161    {
162        return false;
163    }
164
165    virtual bool
166    GenerateTypeScriptFunction (const char* oneliner, std::string& output, void* name_token = NULL)
167    {
168        return false;
169    }
170
171    virtual bool
172    GenerateTypeScriptFunction (StringList &input, std::string& output, void* name_token = NULL)
173    {
174        return false;
175    }
176
177    virtual bool
178    GenerateScriptAliasFunction (StringList &input, std::string& output)
179    {
180        return false;
181    }
182
183    virtual bool
184    GenerateTypeSynthClass (StringList &input, std::string& output, void* name_token = NULL)
185    {
186        return false;
187    }
188
189    virtual bool
190    GenerateTypeSynthClass (const char* oneliner, std::string& output, void* name_token = NULL)
191    {
192        return false;
193    }
194
195    virtual lldb::ScriptInterpreterObjectSP
196    CreateSyntheticScriptedProvider (std::string class_name,
197                                     lldb::ValueObjectSP valobj)
198    {
199        return lldb::ScriptInterpreterObjectSP();
200    }
201
202    virtual lldb::ScriptInterpreterObjectSP
203    CreateOSPlugin (std::string class_name,
204                    lldb::ProcessSP process_sp)
205    {
206        return lldb::ScriptInterpreterObjectSP();
207    }
208
209    virtual lldb::ScriptInterpreterObjectSP
210    OSPlugin_QueryForRegisterInfo (lldb::ScriptInterpreterObjectSP object)
211    {
212        return lldb::ScriptInterpreterObjectSP();
213    }
214
215    virtual bool
216    GenerateFunction(const char *signature, const StringList &input)
217    {
218        return false;
219    }
220
221    virtual void
222    CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options,
223                                             CommandReturnObject &result);
224
225    virtual void
226    CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options,
227                                             CommandReturnObject &result);
228
229    /// Set a one-liner as the callback for the breakpoint.
230    virtual void
231    SetBreakpointCommandCallback (BreakpointOptions *bp_options,
232                                  const char *oneliner)
233    {
234        return;
235    }
236
237    /// Set a one-liner as the callback for the watchpoint.
238    virtual void
239    SetWatchpointCommandCallback (WatchpointOptions *wp_options,
240                                  const char *oneliner)
241    {
242        return;
243    }
244
245    virtual bool
246    GetScriptedSummary (const char *function_name,
247                        lldb::ValueObjectSP valobj,
248                        lldb::ScriptInterpreterObjectSP& callee_wrapper_sp,
249                        std::string& retval)
250    {
251        return false;
252    }
253
254    virtual uint32_t
255    CalculateNumChildren (const lldb::ScriptInterpreterObjectSP& implementor)
256    {
257        return 0;
258    }
259
260    virtual lldb::ValueObjectSP
261    GetChildAtIndex (const lldb::ScriptInterpreterObjectSP& implementor, uint32_t idx)
262    {
263        return lldb::ValueObjectSP();
264    }
265
266    virtual int
267    GetIndexOfChildWithName (const lldb::ScriptInterpreterObjectSP& implementor, const char* child_name)
268    {
269        return UINT32_MAX;
270    }
271
272    virtual bool
273    UpdateSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor)
274    {
275        return false;
276    }
277
278    virtual bool
279    RunScriptBasedCommand (const char* impl_function,
280                           const char* args,
281                           ScriptedCommandSynchronicity synchronicity,
282                           lldb_private::CommandReturnObject& cmd_retobj,
283                           Error& error)
284    {
285        return false;
286    }
287
288    virtual std::string
289    GetDocumentationForItem (const char* item)
290    {
291        return std::string("");
292    }
293
294    virtual bool
295    LoadScriptingModule (const char* filename,
296                         bool can_reload,
297                         lldb_private::Error& error)
298    {
299        error.SetErrorString("loading unimplemented");
300        return false;
301    }
302
303    virtual lldb::ScriptInterpreterObjectSP
304    MakeScriptObject (void* object)
305    {
306        return lldb::ScriptInterpreterObjectSP(new ScriptInterpreterObject(object));
307    }
308
309    const char *
310    GetScriptInterpreterPtyName ();
311
312    int
313    GetMasterFileDescriptor ();
314
315	CommandInterpreter &
316	GetCommandInterpreter ();
317
318    static std::string
319    LanguageToString (lldb::ScriptLanguage language);
320
321    static void
322    InitializeInterpreter (SWIGInitCallback python_swig_init_callback);
323
324    static void
325    TerminateInterpreter ();
326
327    virtual void
328    ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing.
329
330protected:
331    CommandInterpreter &m_interpreter;
332    lldb::ScriptLanguage m_script_lang;
333};
334
335} // namespace lldb_private
336
337#endif // #ifndef liblldb_ScriptInterpreter_h_
338