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