ScriptInterpreter.h revision 3e85b6378d312866ab25eb5623d9b8253bc498f8
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 lldb::ScriptInterpreterObjectSP
216    OSPlugin_QueryForThreadsInfo (lldb::ScriptInterpreterObjectSP object)
217    {
218        return lldb::ScriptInterpreterObjectSP();
219    }
220
221    virtual lldb::ScriptInterpreterObjectSP
222    OSPlugin_QueryForThreadInfo (lldb::ScriptInterpreterObjectSP object,
223                                 lldb::tid_t thread_id)
224    {
225        return lldb::ScriptInterpreterObjectSP();
226    }
227
228    virtual bool
229    GenerateFunction(const char *signature, const StringList &input)
230    {
231        return false;
232    }
233
234    virtual void
235    CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options,
236                                             CommandReturnObject &result);
237
238    virtual void
239    CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options,
240                                             CommandReturnObject &result);
241
242    /// Set a one-liner as the callback for the breakpoint.
243    virtual void
244    SetBreakpointCommandCallback (BreakpointOptions *bp_options,
245                                  const char *oneliner)
246    {
247        return;
248    }
249
250    /// Set a one-liner as the callback for the watchpoint.
251    virtual void
252    SetWatchpointCommandCallback (WatchpointOptions *wp_options,
253                                  const char *oneliner)
254    {
255        return;
256    }
257
258    virtual bool
259    GetScriptedSummary (const char *function_name,
260                        lldb::ValueObjectSP valobj,
261                        lldb::ScriptInterpreterObjectSP& callee_wrapper_sp,
262                        std::string& retval)
263    {
264        return false;
265    }
266
267    virtual uint32_t
268    CalculateNumChildren (const lldb::ScriptInterpreterObjectSP& implementor)
269    {
270        return 0;
271    }
272
273    virtual lldb::ValueObjectSP
274    GetChildAtIndex (const lldb::ScriptInterpreterObjectSP& implementor, uint32_t idx)
275    {
276        return lldb::ValueObjectSP();
277    }
278
279    virtual int
280    GetIndexOfChildWithName (const lldb::ScriptInterpreterObjectSP& implementor, const char* child_name)
281    {
282        return UINT32_MAX;
283    }
284
285    virtual bool
286    UpdateSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor)
287    {
288        return false;
289    }
290
291    virtual bool
292    RunScriptBasedCommand (const char* impl_function,
293                           const char* args,
294                           ScriptedCommandSynchronicity synchronicity,
295                           lldb_private::CommandReturnObject& cmd_retobj,
296                           Error& error)
297    {
298        return false;
299    }
300
301    virtual std::string
302    GetDocumentationForItem (const char* item)
303    {
304        return std::string("");
305    }
306
307    virtual bool
308    LoadScriptingModule (const char* filename,
309                         bool can_reload,
310                         lldb_private::Error& error)
311    {
312        error.SetErrorString("loading unimplemented");
313        return false;
314    }
315
316    virtual lldb::ScriptInterpreterObjectSP
317    MakeScriptObject (void* object)
318    {
319        return lldb::ScriptInterpreterObjectSP(new ScriptInterpreterObject(object));
320    }
321
322    const char *
323    GetScriptInterpreterPtyName ();
324
325    int
326    GetMasterFileDescriptor ();
327
328	CommandInterpreter &
329	GetCommandInterpreter ();
330
331    static std::string
332    LanguageToString (lldb::ScriptLanguage language);
333
334    static void
335    InitializeInterpreter (SWIGInitCallback python_swig_init_callback);
336
337    static void
338    TerminateInterpreter ();
339
340    virtual void
341    ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing.
342
343protected:
344    CommandInterpreter &m_interpreter;
345    lldb::ScriptLanguage m_script_lang;
346};
347
348} // namespace lldb_private
349
350#endif // #ifndef liblldb_ScriptInterpreter_h_
351