ScriptInterpreter.h revision 59df36f99b76e33852e6848a162f5c2851074ea2
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 78 ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang); 79 80 virtual ~ScriptInterpreter (); 81 82 virtual bool 83 ExecuteOneLine (const char *command, CommandReturnObject *result) = 0; 84 85 virtual void 86 ExecuteInterpreterLoop () = 0; 87 88 virtual bool 89 ExecuteOneLineWithReturn (const char *in_string, ScriptReturnType return_type, void *ret_value) 90 { 91 return true; 92 } 93 94 virtual bool 95 ExecuteMultipleLines (const char *in_string) 96 { 97 return true; 98 } 99 100 virtual bool 101 ExportFunctionDefinitionToInterpreter (StringList &function_def) 102 { 103 return false; 104 } 105 106 virtual bool 107 GenerateBreakpointCommandCallbackData (StringList &input, StringList &output) 108 { 109 return false; 110 } 111 112 virtual bool 113 GenerateTypeScriptFunction (StringList &input, StringList &output) 114 { 115 return false; 116 } 117 118 virtual bool 119 GenerateScriptAliasFunction (StringList &input, StringList &output) 120 { 121 return false; 122 } 123 124 virtual bool 125 GenerateTypeSynthClass (StringList &input, StringList &output) 126 { 127 return false; 128 } 129 130 virtual void* 131 CreateSyntheticScriptedProvider (std::string class_name, 132 lldb::ValueObjectSP valobj) 133 { 134 return NULL; 135 } 136 137 // use this if the function code is just a one-liner script 138 virtual bool 139 GenerateTypeScriptFunction (const char* oneliner, StringList &output) 140 { 141 return false; 142 } 143 144 virtual bool 145 GenerateFunction(std::string& signature, StringList &input, StringList &output) 146 { 147 return false; 148 } 149 150 virtual void 151 CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options, 152 CommandReturnObject &result); 153 154 /// Set a one-liner as the callback for the breakpoint. 155 virtual void 156 SetBreakpointCommandCallback (BreakpointOptions *bp_options, 157 const char *oneliner) 158 { 159 return; 160 } 161 162 virtual uint32_t 163 CalculateNumChildren (void *implementor) 164 { 165 return 0; 166 } 167 168 virtual lldb::ValueObjectSP 169 GetChildAtIndex (void *implementor, uint32_t idx) 170 { 171 return lldb::ValueObjectSP(); 172 } 173 174 virtual int 175 GetIndexOfChildWithName (void *implementor, const char* child_name) 176 { 177 return UINT32_MAX; 178 } 179 180 virtual void 181 UpdateSynthProviderInstance (void* implementor) 182 { 183 } 184 185 virtual bool 186 RunScriptBasedCommand (const char* impl_function, 187 const char* args, 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 lldb_private::Error& error) 203 { 204 error.SetErrorString("loading unimplemented"); 205 return false; 206 } 207 208 const char * 209 GetScriptInterpreterPtyName (); 210 211 int 212 GetMasterFileDescriptor (); 213 214 CommandInterpreter & 215 GetCommandInterpreter (); 216 217 static std::string 218 LanguageToString (lldb::ScriptLanguage language); 219 220 static void 221 InitializeInterpreter (SWIGInitCallback python_swig_init_callback, 222 SWIGBreakpointCallbackFunction python_swig_breakpoint_callback, 223 SWIGPythonTypeScriptCallbackFunction python_swig_typescript_callback, 224 SWIGPythonCreateSyntheticProvider python_swig_synthetic_script, 225 SWIGPythonCalculateNumChildren python_swig_calc_children, 226 SWIGPythonGetChildAtIndex python_swig_get_child_index, 227 SWIGPythonGetIndexOfChildWithName python_swig_get_index_child, 228 SWIGPythonCastPyObjectToSBValue python_swig_cast_to_sbvalue, 229 SWIGPythonUpdateSynthProviderInstance python_swig_update_provider, 230 SWIGPythonCallCommand python_swig_call_command, 231 SWIGPythonCallModuleInit python_swig_call_mod_init); 232 233 static void 234 TerminateInterpreter (); 235 236 virtual void 237 ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing. 238 239protected: 240 CommandInterpreter &m_interpreter; 241 lldb::ScriptLanguage m_script_lang; 242 243 // Scripting languages may need to use stdin for their interactive loops; 244 // however we don't want them to grab the real system stdin because that 245 // resource needs to be shared among the debugger UI, the inferior process and these 246 // embedded scripting loops. Therefore we need to set up a pseudoterminal and use that 247 // as stdin for the script interpreter interactive loops/prompts. 248 249 lldb_utility::PseudoTerminal m_interpreter_pty; // m_session_pty 250 std::string m_pty_slave_name; //m_session_pty_slave_name 251 252private: 253 254}; 255 256} // namespace lldb_private 257 258#endif // #ifndef liblldb_ScriptInterpreter_h_ 259