ScriptInterpreterPython.h revision 979e20d127335143ffc89c2e37ec3a8b717ff22d
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 void* 63 CreateSyntheticScriptedProvider (std::string class_name, 64 lldb::ValueObjectSP valobj); 65 66 virtual uint32_t 67 CalculateNumChildren (void *implementor); 68 69 virtual void* 70 GetChildAtIndex (void *implementor, uint32_t idx); 71 72 virtual int 73 GetIndexOfChildWithName (void *implementor, const char* child_name); 74 75 virtual void 76 UpdateSynthProviderInstance (void* implementor); 77 78 virtual lldb::SBValue* 79 CastPyObjectToSBValue (void* data); 80 81 bool 82 GenerateFunction(std::string& signature, StringList &input, StringList &output); 83 84 bool 85 GenerateBreakpointCommandCallbackData (StringList &input, StringList &output); 86 87 static size_t 88 GenerateBreakpointOptionsCommandCallback (void *baton, 89 InputReader &reader, 90 lldb::InputReaderAction notification, 91 const char *bytes, 92 size_t bytes_len); 93 94 static bool 95 BreakpointCallbackFunction (void *baton, 96 StoppointCallbackContext *context, 97 lldb::user_id_t break_id, 98 lldb::user_id_t break_loc_id); 99 100 static std::string 101 CallPythonScriptFunction (const char *python_function_name, 102 lldb::ValueObjectSP valobj); 103 104 void 105 CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options, 106 CommandReturnObject &result); 107 108 /// Set a Python one-liner as the callback for the breakpoint. 109 void 110 SetBreakpointCommandCallback (BreakpointOptions *bp_options, 111 const char *oneliner); 112 113 StringList 114 ReadCommandInputFromUser (FILE *in_file); 115 116 virtual void 117 ResetOutputFileHandle (FILE *new_fh); 118 119 static lldb::thread_result_t 120 RunEmbeddedPythonInterpreter (lldb::thread_arg_t baton); 121 122 static void 123 InitializePrivate (); 124 125 static void 126 InitializeInterpreter (SWIGInitCallback python_swig_init_callback, 127 SWIGBreakpointCallbackFunction python_swig_breakpoint_callback, 128 SWIGPythonTypeScriptCallbackFunction python_swig_typescript_callback, 129 SWIGPythonCreateSyntheticProvider python_swig_synthetic_script, 130 SWIGPythonCalculateNumChildren python_swig_calc_children, 131 SWIGPythonGetChildAtIndex python_swig_get_child_index, 132 SWIGPythonGetIndexOfChildWithName python_swig_get_index_child, 133 SWIGPythonCastPyObjectToSBValue python_swig_cast_to_sbvalue, 134 SWIGPythonUpdateSynthProviderInstance python_swig_update_provider); 135 136protected: 137 138 void 139 EnterSession (); 140 141 void 142 LeaveSession (); 143 144 void 145 SaveTerminalState (int fd); 146 147 void 148 RestoreTerminalState (); 149 150private: 151 152 static size_t 153 InputReaderCallback (void *baton, 154 InputReader &reader, 155 lldb::InputReaderAction notification, 156 const char *bytes, 157 size_t bytes_len); 158 159 160 lldb_utility::PseudoTerminal m_embedded_python_pty; 161 lldb::InputReaderSP m_embedded_thread_input_reader_sp; 162 FILE *m_dbg_stdout; 163 PyObject *m_new_sysout; 164 std::string m_dictionary_name; 165 TerminalState m_terminal_state; 166 bool m_session_is_active; 167 bool m_pty_slave_is_open; 168 bool m_valid_session; 169 170}; 171 172} // namespace lldb_private 173 174 175#endif // #ifndef liblldb_ScriptInterpreterPython_h_ 176