ScriptInterpreter.h revision 177bc682e2b45354e8b0753e705dc84255c42173
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 ScriptInterpreter
24{
25public:
26
27    typedef void (*SWIGInitCallback) (void);
28
29    typedef bool (*SWIGBreakpointCallbackFunction) (const char *python_function_name,
30                                                    const char *session_dictionary_name,
31                                                    const lldb::StackFrameSP& frame_sp,
32                                                    const lldb::BreakpointLocationSP &bp_loc_sp);
33
34    typedef std::string (*SWIGPythonTypeScriptCallbackFunction) (const char *python_function_name,
35                                                                 const char *session_dictionary_name,
36                                                                 const lldb::ValueObjectSP& valobj_sp);
37
38    typedef void* (*SWIGPythonCreateSyntheticProvider) (const std::string python_class_name,
39                                                        const char *session_dictionary_name,
40                                                        const lldb::ValueObjectSP& valobj_sp);
41
42    typedef uint32_t       (*SWIGPythonCalculateNumChildren)        (void *implementor);
43    typedef void*          (*SWIGPythonGetChildAtIndex)             (void *implementor, uint32_t idx);
44    typedef int            (*SWIGPythonGetIndexOfChildWithName)     (void *implementor, const char* child_name);
45    typedef void*          (*SWIGPythonCastPyObjectToSBValue)       (void* data);
46    typedef void           (*SWIGPythonUpdateSynthProviderInstance) (void* data);
47
48    typedef bool           (*SWIGPythonCallCommand)                 (const char *python_function_name,
49                                                                     const char *session_dictionary_name,
50                                                                     lldb::DebuggerSP& debugger,
51                                                                     const char* args,
52                                                                     std::string& err_msg,
53                                                                     lldb_private::CommandReturnObject& cmd_retobj);
54
55    typedef bool           (*SWIGPythonCallModuleInit)              (const std::string python_module_name,
56                                                                     const char *session_dictionary_name,
57                                                                     lldb::DebuggerSP& debugger);
58
59    typedef enum
60    {
61        eScriptReturnTypeCharPtr,
62        eScriptReturnTypeBool,
63        eScriptReturnTypeShortInt,
64        eScriptReturnTypeShortIntUnsigned,
65        eScriptReturnTypeInt,
66        eScriptReturnTypeIntUnsigned,
67        eScriptReturnTypeLongInt,
68        eScriptReturnTypeLongIntUnsigned,
69        eScriptReturnTypeLongLong,
70        eScriptReturnTypeLongLongUnsigned,
71        eScriptReturnTypeFloat,
72        eScriptReturnTypeDouble,
73        eScriptReturnTypeChar,
74        eScriptReturnTypeCharStrOrNone
75    } ScriptReturnType;
76
77    ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang);
78
79    virtual ~ScriptInterpreter ();
80
81    virtual bool
82    ExecuteOneLine (const char *command, CommandReturnObject *result) = 0;
83
84    virtual void
85    ExecuteInterpreterLoop () = 0;
86
87    virtual bool
88    ExecuteOneLineWithReturn (const char *in_string, ScriptReturnType return_type, void *ret_value)
89    {
90        return true;
91    }
92
93    virtual bool
94    ExecuteMultipleLines (const char *in_string)
95    {
96        return true;
97    }
98
99    virtual bool
100    ExportFunctionDefinitionToInterpreter (StringList &function_def)
101    {
102        return false;
103    }
104
105    virtual bool
106    GenerateBreakpointCommandCallbackData (StringList &input, StringList &output)
107    {
108        return false;
109    }
110
111    virtual bool
112    GenerateTypeScriptFunction (StringList &input, StringList &output)
113    {
114        return false;
115    }
116
117    virtual bool
118    GenerateScriptAliasFunction (StringList &input, StringList &output)
119    {
120        return false;
121    }
122
123    virtual bool
124    GenerateTypeSynthClass (StringList &input, StringList &output)
125    {
126        return false;
127    }
128
129    virtual void*
130    CreateSyntheticScriptedProvider (std::string class_name,
131                                     lldb::ValueObjectSP valobj)
132    {
133        return NULL;
134    }
135
136    // use this if the function code is just a one-liner script
137    virtual bool
138    GenerateTypeScriptFunction (const char* oneliner, StringList &output)
139    {
140        return false;
141    }
142
143    virtual bool
144    GenerateFunction(std::string& signature, StringList &input, StringList &output)
145    {
146        return false;
147    }
148
149    virtual void
150    CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options,
151                                             CommandReturnObject &result);
152
153    /// Set a one-liner as the callback for the breakpoint.
154    virtual void
155    SetBreakpointCommandCallback (BreakpointOptions *bp_options,
156                                  const char *oneliner)
157    {
158        return;
159    }
160
161    virtual uint32_t
162    CalculateNumChildren (void *implementor)
163    {
164        return 0;
165    }
166
167    virtual lldb::ValueObjectSP
168    GetChildAtIndex (void *implementor, uint32_t idx)
169    {
170        return lldb::ValueObjectSP();
171    }
172
173    virtual int
174    GetIndexOfChildWithName (void *implementor, const char* child_name)
175    {
176        return UINT32_MAX;
177    }
178
179    virtual void
180    UpdateSynthProviderInstance (void* implementor)
181    {
182    }
183
184    virtual bool
185    RunScriptBasedCommand (const char* impl_function,
186                           const char* args,
187                           ScriptedCommandSynchronicity synchronicity,
188                           lldb_private::CommandReturnObject& cmd_retobj,
189                           Error& error)
190    {
191        return false;
192    }
193
194    virtual std::string
195    GetDocumentationForItem (const char* item)
196    {
197        return std::string("");
198    }
199
200    virtual bool
201    LoadScriptingModule (const char* filename,
202                         bool can_reload,
203                         lldb_private::Error& error)
204    {
205        error.SetErrorString("loading unimplemented");
206        return false;
207    }
208
209    const char *
210    GetScriptInterpreterPtyName ();
211
212    int
213    GetMasterFileDescriptor ();
214
215	CommandInterpreter &
216	GetCommandInterpreter ();
217
218    static std::string
219    LanguageToString (lldb::ScriptLanguage language);
220
221    static void
222    InitializeInterpreter (SWIGInitCallback python_swig_init_callback,
223                           SWIGBreakpointCallbackFunction python_swig_breakpoint_callback,
224                           SWIGPythonTypeScriptCallbackFunction python_swig_typescript_callback,
225                           SWIGPythonCreateSyntheticProvider python_swig_synthetic_script,
226                           SWIGPythonCalculateNumChildren python_swig_calc_children,
227                           SWIGPythonGetChildAtIndex python_swig_get_child_index,
228                           SWIGPythonGetIndexOfChildWithName python_swig_get_index_child,
229                           SWIGPythonCastPyObjectToSBValue python_swig_cast_to_sbvalue,
230                           SWIGPythonUpdateSynthProviderInstance python_swig_update_provider,
231                           SWIGPythonCallCommand python_swig_call_command,
232                           SWIGPythonCallModuleInit python_swig_call_mod_init);
233
234    static void
235    TerminateInterpreter ();
236
237    virtual void
238    ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing.
239
240protected:
241    CommandInterpreter &m_interpreter;
242    lldb::ScriptLanguage m_script_lang;
243};
244
245} // namespace lldb_private
246
247#endif // #ifndef liblldb_ScriptInterpreter_h_
248