ScriptInterpreter.h revision 3370f0ce9e2ae2fe1f2adf3628f443053602efa4
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/API/SBValue.h" 14 15#include "lldb/lldb-private.h" 16#include "lldb/Core/Broadcaster.h" 17#include "lldb/Utility/PseudoTerminal.h" 18 19 20namespace lldb_private { 21 22class ScriptInterpreter 23{ 24public: 25 26 typedef void (*SWIGInitCallback) (void); 27 28 typedef bool (*SWIGBreakpointCallbackFunction) (const char *python_function_name, 29 const char *session_dictionary_name, 30 const lldb::StackFrameSP& frame_sp, 31 const lldb::BreakpointLocationSP &bp_loc_sp); 32 33 typedef std::string (*SWIGPythonTypeScriptCallbackFunction) (const char *python_function_name, 34 const char *session_dictionary_name, 35 const lldb::ValueObjectSP& valobj_sp); 36 37 typedef void* (*SWIGPythonCreateSyntheticProvider) (const std::string python_class_name, 38 const char *session_dictionary_name, 39 const lldb::ValueObjectSP& valobj_sp); 40 41 typedef uint32_t (*SWIGPythonCalculateNumChildren) (void *implementor); 42 typedef void* (*SWIGPythonGetChildAtIndex) (void *implementor, uint32_t idx); 43 typedef int (*SWIGPythonGetIndexOfChildWithName) (void *implementor, const char* child_name); 44 typedef lldb::SBValue* (*SWIGPythonCastPyObjectToSBValue) (void* data); 45 typedef void (*SWIGPythonUpdateSynthProviderInstance) (void* data); 46 47 typedef bool (*SWIGPythonCallCommand) (const char *python_function_name, 48 const char *session_dictionary_name, 49 lldb::DebuggerSP& debugger, 50 const char* args, 51 std::string& err_msg, 52 lldb_private::CommandReturnObject& cmd_retobj); 53 54 typedef enum 55 { 56 eCharPtr, 57 eBool, 58 eShortInt, 59 eShortIntUnsigned, 60 eInt, 61 eIntUnsigned, 62 eLongInt, 63 eLongIntUnsigned, 64 eLongLong, 65 eLongLongUnsigned, 66 eFloat, 67 eDouble, 68 eChar, 69 eCharStrOrNone 70 } ReturnType; 71 72 73 ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang); 74 75 virtual ~ScriptInterpreter (); 76 77 virtual bool 78 ExecuteOneLine (const char *command, CommandReturnObject *result) = 0; 79 80 virtual void 81 ExecuteInterpreterLoop () = 0; 82 83 virtual bool 84 ExecuteOneLineWithReturn (const char *in_string, ReturnType return_type, void *ret_value) 85 { 86 return true; 87 } 88 89 virtual bool 90 ExecuteMultipleLines (const char *in_string) 91 { 92 return true; 93 } 94 95 virtual bool 96 ExportFunctionDefinitionToInterpreter (StringList &function_def) 97 { 98 return false; 99 } 100 101 virtual bool 102 GenerateBreakpointCommandCallbackData (StringList &input, StringList &output) 103 { 104 return false; 105 } 106 107 virtual bool 108 GenerateTypeScriptFunction (StringList &input, StringList &output) 109 { 110 return false; 111 } 112 113 virtual bool 114 GenerateScriptAliasFunction (StringList &input, StringList &output) 115 { 116 return false; 117 } 118 119 virtual bool 120 GenerateTypeSynthClass (StringList &input, StringList &output) 121 { 122 return false; 123 } 124 125 virtual void* 126 CreateSyntheticScriptedProvider (std::string class_name, 127 lldb::ValueObjectSP valobj) 128 { 129 return NULL; 130 } 131 132 // use this if the function code is just a one-liner script 133 virtual bool 134 GenerateTypeScriptFunction (const char* oneliner, StringList &output) 135 { 136 return false; 137 } 138 139 virtual bool 140 GenerateFunction(std::string& signature, StringList &input, StringList &output) 141 { 142 return false; 143 } 144 145 virtual void 146 CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options, 147 CommandReturnObject &result); 148 149 /// Set a one-liner as the callback for the breakpoint. 150 virtual void 151 SetBreakpointCommandCallback (BreakpointOptions *bp_options, 152 const char *oneliner) 153 { 154 return; 155 } 156 157 virtual uint32_t 158 CalculateNumChildren (void *implementor) 159 { 160 return 0; 161 } 162 163 virtual void* 164 GetChildAtIndex (void *implementor, uint32_t idx) 165 { 166 return NULL; 167 } 168 169 virtual int 170 GetIndexOfChildWithName (void *implementor, const char* child_name) 171 { 172 return UINT32_MAX; 173 } 174 175 virtual void 176 UpdateSynthProviderInstance (void* implementor) 177 { 178 } 179 180 virtual lldb::SBValue* 181 CastPyObjectToSBValue (void* data) 182 { 183 return NULL; 184 } 185 186 virtual bool 187 RunScriptBasedCommand(const char* impl_function, 188 const char* args, 189 lldb_private::CommandReturnObject& cmd_retobj, 190 Error& error) 191 { 192 return false; 193 } 194 195 virtual std::string 196 GetDocumentationForItem(const char* item) 197 { 198 return std::string(""); 199 } 200 201 const char * 202 GetScriptInterpreterPtyName (); 203 204 int 205 GetMasterFileDescriptor (); 206 207 CommandInterpreter & 208 GetCommandInterpreter (); 209 210 static std::string 211 LanguageToString (lldb::ScriptLanguage language); 212 213 static void 214 InitializeInterpreter (SWIGInitCallback python_swig_init_callback, 215 SWIGBreakpointCallbackFunction python_swig_breakpoint_callback, 216 SWIGPythonTypeScriptCallbackFunction python_swig_typescript_callback, 217 SWIGPythonCreateSyntheticProvider python_swig_synthetic_script, 218 SWIGPythonCalculateNumChildren python_swig_calc_children, 219 SWIGPythonGetChildAtIndex python_swig_get_child_index, 220 SWIGPythonGetIndexOfChildWithName python_swig_get_index_child, 221 SWIGPythonCastPyObjectToSBValue python_swig_cast_to_sbvalue, 222 SWIGPythonUpdateSynthProviderInstance python_swig_update_provider, 223 SWIGPythonCallCommand python_swig_call_command); 224 225 static void 226 TerminateInterpreter (); 227 228 virtual void 229 ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing. 230 231protected: 232 CommandInterpreter &m_interpreter; 233 lldb::ScriptLanguage m_script_lang; 234 235 // Scripting languages may need to use stdin for their interactive loops; 236 // however we don't want them to grab the real system stdin because that 237 // resource needs to be shared among the debugger UI, the inferior process and these 238 // embedded scripting loops. Therefore we need to set up a pseudoterminal and use that 239 // as stdin for the script interpreter interactive loops/prompts. 240 241 lldb_utility::PseudoTerminal m_interpreter_pty; // m_session_pty 242 std::string m_pty_slave_name; //m_session_pty_slave_name 243 244private: 245 246}; 247 248} // namespace lldb_private 249 250#endif // #ifndef liblldb_ScriptInterpreter_h_ 251