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