ScriptInterpreterPython.h revision c2a2825d787be5459fc55264e55b6020ff62f68a
1//===-- ScriptInterpreterPython.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 11#ifndef liblldb_ScriptInterpreterPython_h_ 12#define liblldb_ScriptInterpreterPython_h_ 13 14#if defined (__APPLE__) 15#include <Python/Python.h> 16#else 17#include <Python.h> 18#endif 19 20#include "lldb/lldb-private.h" 21#include "lldb/Interpreter/ScriptInterpreter.h" 22#include "lldb/Core/InputReader.h" 23#include "lldb/Host/Terminal.h" 24 25namespace lldb_private { 26 27class ScriptInterpreterPython : public ScriptInterpreter 28{ 29public: 30 31 ScriptInterpreterPython (CommandInterpreter &interpreter); 32 33 ~ScriptInterpreterPython (); 34 35 bool 36 ExecuteOneLine (const char *command, CommandReturnObject *result); 37 38 void 39 ExecuteInterpreterLoop (); 40 41 bool 42 ExecuteOneLineWithReturn (const char *in_string, 43 ScriptInterpreter::ReturnType return_type, 44 void *ret_value); 45 46 bool 47 ExecuteMultipleLines (const char *in_string); 48 49 bool 50 ExportFunctionDefinitionToInterpreter (StringList &function_def); 51 52 bool 53 GenerateTypeScriptFunction (StringList &input, StringList &output); 54 55 bool 56 GenerateTypeSynthClass (StringList &input, StringList &output); 57 58 // use this if the function code is just a one-liner script 59 bool 60 GenerateTypeScriptFunction (const char* oneliner, StringList &output); 61 62 virtual bool 63 GenerateScriptAliasFunction (StringList &input, StringList &output); 64 65 void* 66 CreateSyntheticScriptedProvider (std::string class_name, 67 lldb::ValueObjectSP valobj); 68 69 virtual uint32_t 70 CalculateNumChildren (void *implementor); 71 72 virtual void* 73 GetChildAtIndex (void *implementor, uint32_t idx); 74 75 virtual int 76 GetIndexOfChildWithName (void *implementor, const char* child_name); 77 78 virtual void 79 UpdateSynthProviderInstance (void* implementor); 80 81 virtual lldb::SBValue* 82 CastPyObjectToSBValue (void* data); 83 84 virtual bool 85 RunScriptBasedCommand(const char* impl_function, 86 const char* args, 87 lldb::SBStream& stream, 88 Error& error); 89 90 bool 91 GenerateFunction(std::string& signature, StringList &input, StringList &output); 92 93 bool 94 GenerateBreakpointCommandCallbackData (StringList &input, StringList &output); 95 96 static size_t 97 GenerateBreakpointOptionsCommandCallback (void *baton, 98 InputReader &reader, 99 lldb::InputReaderAction notification, 100 const char *bytes, 101 size_t bytes_len); 102 103 static bool 104 BreakpointCallbackFunction (void *baton, 105 StoppointCallbackContext *context, 106 lldb::user_id_t break_id, 107 lldb::user_id_t break_loc_id); 108 109 static std::string 110 CallPythonScriptFunction (const char *python_function_name, 111 lldb::ValueObjectSP valobj); 112 113 void 114 CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options, 115 CommandReturnObject &result); 116 117 /// Set a Python one-liner as the callback for the breakpoint. 118 void 119 SetBreakpointCommandCallback (BreakpointOptions *bp_options, 120 const char *oneliner); 121 122 StringList 123 ReadCommandInputFromUser (FILE *in_file); 124 125 virtual void 126 ResetOutputFileHandle (FILE *new_fh); 127 128 static lldb::thread_result_t 129 RunEmbeddedPythonInterpreter (lldb::thread_arg_t baton); 130 131 static void 132 InitializePrivate (); 133 134 static void 135 InitializeInterpreter (SWIGInitCallback python_swig_init_callback, 136 SWIGBreakpointCallbackFunction python_swig_breakpoint_callback, 137 SWIGPythonTypeScriptCallbackFunction python_swig_typescript_callback, 138 SWIGPythonCreateSyntheticProvider python_swig_synthetic_script, 139 SWIGPythonCalculateNumChildren python_swig_calc_children, 140 SWIGPythonGetChildAtIndex python_swig_get_child_index, 141 SWIGPythonGetIndexOfChildWithName python_swig_get_index_child, 142 SWIGPythonCastPyObjectToSBValue python_swig_cast_to_sbvalue, 143 SWIGPythonUpdateSynthProviderInstance python_swig_update_provider, 144 SWIGPythonCallCommand python_swig_call_command); 145 146protected: 147 148 void 149 EnterSession (); 150 151 void 152 LeaveSession (); 153 154 void 155 SaveTerminalState (int fd); 156 157 void 158 RestoreTerminalState (); 159 160private: 161 162 static size_t 163 InputReaderCallback (void *baton, 164 InputReader &reader, 165 lldb::InputReaderAction notification, 166 const char *bytes, 167 size_t bytes_len); 168 169 170 lldb_utility::PseudoTerminal m_embedded_python_pty; 171 lldb::InputReaderSP m_embedded_thread_input_reader_sp; 172 FILE *m_dbg_stdout; 173 PyObject *m_new_sysout; 174 std::string m_dictionary_name; 175 TerminalState m_terminal_state; 176 bool m_session_is_active; 177 bool m_pty_slave_is_open; 178 bool m_valid_session; 179 180}; 181 182} // namespace lldb_private 183 184 185#endif // #ifndef liblldb_ScriptInterpreterPython_h_ 186