ScriptInterpreter.h revision e86cbb9ef128db87cf904e330b2edfc15566bacd
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#include "lldb/Core/Broadcaster.h" 15#include "lldb/Utility/PseudoTerminal.h" 16 17namespace lldb_private { 18 19class ScriptInterpreter 20{ 21public: 22 23 typedef void (*SWIGInitCallback) (void); 24 25 typedef bool (*SWIGBreakpointCallbackFunction) (const char *python_function_name, 26 const char *session_dictionary_name, 27 const lldb::StackFrameSP& frame_sp, 28 const lldb::BreakpointLocationSP &bp_loc_sp); 29 typedef enum 30 { 31 eCharPtr, 32 eBool, 33 eShortInt, 34 eShortIntUnsigned, 35 eInt, 36 eIntUnsigned, 37 eLongInt, 38 eLongIntUnsigned, 39 eLongLong, 40 eLongLongUnsigned, 41 eFloat, 42 eDouble, 43 eChar 44 } ReturnType; 45 46 47 ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang); 48 49 virtual ~ScriptInterpreter (); 50 51 virtual bool 52 ExecuteOneLine (const char *command, CommandReturnObject *result) = 0; 53 54 virtual void 55 ExecuteInterpreterLoop () = 0; 56 57 virtual bool 58 ExecuteOneLineWithReturn (const char *in_string, ReturnType return_type, void *ret_value) 59 { 60 return true; 61 } 62 63 virtual bool 64 ExecuteMultipleLines (const char *in_string) 65 { 66 return true; 67 } 68 69 virtual bool 70 ExportFunctionDefinitionToInterpreter (StringList &function_def) 71 { 72 return false; 73 } 74 75 virtual bool 76 GenerateBreakpointCommandCallbackData (StringList &input, StringList &output) 77 { 78 return false; 79 } 80 81 virtual void 82 CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options, 83 CommandReturnObject &result); 84 85 /// Set a one-liner as the callback for the breakpoint. 86 virtual void 87 SetBreakpointCommandCallback (BreakpointOptions *bp_options, 88 const char *oneliner) 89 { 90 return; 91 } 92 93 const char * 94 GetScriptInterpreterPtyName (); 95 96 int 97 GetMasterFileDescriptor (); 98 99 CommandInterpreter & 100 GetCommandInterpreter (); 101 102 static std::string 103 LanguageToString (lldb::ScriptLanguage language); 104 105 static void 106 InitializeInterpreter (SWIGInitCallback python_swig_init_callback, 107 SWIGBreakpointCallbackFunction python_swig_breakpoint_callback); 108 109 static void 110 TerminateInterpreter (); 111 112 virtual void 113 ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing. 114 115protected: 116 CommandInterpreter &m_interpreter; 117 lldb::ScriptLanguage m_script_lang; 118 119 // Scripting languages may need to use stdin for their interactive loops; 120 // however we don't want them to grab the real system stdin because that 121 // resource needs to be shared among the debugger UI, the inferior process and these 122 // embedded scripting loops. Therefore we need to set up a pseudoterminal and use that 123 // as stdin for the script interpreter interactive loops/prompts. 124 125 lldb_utility::PseudoTerminal m_interpreter_pty; // m_session_pty 126 std::string m_pty_slave_name; //m_session_pty_slave_name 127 128private: 129 130}; 131 132} // namespace lldb_private 133 134#endif // #ifndef liblldb_ScriptInterpreter_h_ 135