ScriptInterpreterPython.h revision e5e34cb15f031237004b05abfa623c71f879f6c0
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_private::CommandReturnObject& cmd_retobj, 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 virtual std::string 114 GetDocumentationForItem(const char* item); 115 116 void 117 CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options, 118 CommandReturnObject &result); 119 120 /// Set a Python one-liner as the callback for the breakpoint. 121 void 122 SetBreakpointCommandCallback (BreakpointOptions *bp_options, 123 const char *oneliner); 124 125 StringList 126 ReadCommandInputFromUser (FILE *in_file); 127 128 virtual void 129 ResetOutputFileHandle (FILE *new_fh); 130 131 static lldb::thread_result_t 132 RunEmbeddedPythonInterpreter (lldb::thread_arg_t baton); 133 134 static void 135 InitializePrivate (); 136 137 static void 138 InitializeInterpreter (SWIGInitCallback python_swig_init_callback, 139 SWIGBreakpointCallbackFunction python_swig_breakpoint_callback, 140 SWIGPythonTypeScriptCallbackFunction python_swig_typescript_callback, 141 SWIGPythonCreateSyntheticProvider python_swig_synthetic_script, 142 SWIGPythonCalculateNumChildren python_swig_calc_children, 143 SWIGPythonGetChildAtIndex python_swig_get_child_index, 144 SWIGPythonGetIndexOfChildWithName python_swig_get_index_child, 145 SWIGPythonCastPyObjectToSBValue python_swig_cast_to_sbvalue, 146 SWIGPythonUpdateSynthProviderInstance python_swig_update_provider, 147 SWIGPythonCallCommand python_swig_call_command); 148 149protected: 150 151 void 152 EnterSession (); 153 154 void 155 LeaveSession (); 156 157 void 158 SaveTerminalState (int fd); 159 160 void 161 RestoreTerminalState (); 162 163private: 164 165 static size_t 166 InputReaderCallback (void *baton, 167 InputReader &reader, 168 lldb::InputReaderAction notification, 169 const char *bytes, 170 size_t bytes_len); 171 172 173 lldb_utility::PseudoTerminal m_embedded_python_pty; 174 lldb::InputReaderSP m_embedded_thread_input_reader_sp; 175 FILE *m_dbg_stdout; 176 PyObject *m_new_sysout; 177 std::string m_dictionary_name; 178 TerminalState m_terminal_state; 179 bool m_session_is_active; 180 bool m_pty_slave_is_open; 181 bool m_valid_session; 182 183}; 184 185} // namespace lldb_private 186 187 188#endif // #ifndef liblldb_ScriptInterpreterPython_h_ 189