diff options
| author | Ed Maste <emaste@FreeBSD.org> | 2014-02-18 16:23:10 +0000 |
|---|---|---|
| committer | Ed Maste <emaste@FreeBSD.org> | 2014-02-18 16:23:10 +0000 |
| commit | 866dcdacfe59f5f448e008fe2c4cb9dfcf72b2ec (patch) | |
| tree | 95cb16075f0af1b3a05b9b84eb18dda8e6c903e9 /include/lldb/Interpreter | |
| parent | de889deb2c386f2a7831befaf226e5c86685fa53 (diff) | |
Diffstat (limited to 'include/lldb/Interpreter')
| -rw-r--r-- | include/lldb/Interpreter/CommandInterpreter.h | 79 | ||||
| -rw-r--r-- | include/lldb/Interpreter/PythonDataObjects.h | 25 | ||||
| -rw-r--r-- | include/lldb/Interpreter/ScriptInterpreter.h | 6 | ||||
| -rw-r--r-- | include/lldb/Interpreter/ScriptInterpreterPython.h | 151 |
4 files changed, 150 insertions, 111 deletions
diff --git a/include/lldb/Interpreter/CommandInterpreter.h b/include/lldb/Interpreter/CommandInterpreter.h index 31fcc38eed9a3..bcb9b5538c842 100644 --- a/include/lldb/Interpreter/CommandInterpreter.h +++ b/include/lldb/Interpreter/CommandInterpreter.h @@ -17,6 +17,7 @@ #include "lldb/lldb-private.h" #include "lldb/Core/Broadcaster.h" #include "lldb/Core/Debugger.h" +#include "lldb/Core/IOHandler.h" #include "lldb/Core/Log.h" #include "lldb/Interpreter/CommandHistory.h" #include "lldb/Interpreter/CommandObject.h" @@ -29,7 +30,8 @@ namespace lldb_private { class CommandInterpreter : public Broadcaster, - public Properties + public Properties, + public IOHandlerDelegate { public: typedef std::map<std::string, OptionArgVectorSP> OptionArgMap; @@ -213,10 +215,10 @@ public: void HandleCommandsFromFile (FileSpec &file, ExecutionContext *context, - bool stop_on_continue, - bool stop_on_error, - bool echo_commands, - bool print_results, + LazyBool stop_on_continue, + LazyBool stop_on_error, + LazyBool echo_commands, + LazyBool print_results, LazyBool add_to_history, CommandReturnObject &result); @@ -305,7 +307,8 @@ public: ExecutionContext GetExecutionContext() { - return m_exe_ctx_ref.Lock(); + const bool thread_and_frame_only_if_stopped = true; + return m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped); } void @@ -317,20 +320,12 @@ public: const char * ProcessEmbeddedScriptCommands (const char *arg); - const char * - GetPrompt (); - void - SetPrompt (const char *); - - bool Confirm (const char *message, bool default_answer); + UpdatePrompt (const char *); - static size_t - GetConfirmationInputReaderCallback (void *baton, - InputReader &reader, - lldb::InputReaderAction action, - const char *bytes, - size_t bytes_len); + bool + Confirm (const char *message, + bool default_answer); void LoadCommandDictionary (); @@ -395,8 +390,12 @@ public: bool GetBatchCommandMode () { return m_batch_command_mode; } - void - SetBatchCommandMode (bool value) { m_batch_command_mode = value; } + bool + SetBatchCommandMode (bool value) { + const bool old_value = m_batch_command_mode; + m_batch_command_mode = value; + return old_value; + } void ChildrenTruncated () @@ -435,6 +434,25 @@ public: return m_command_history; } + bool + IsActive (); + + void + RunCommandInterpreter (bool auto_handle_events, + bool spawn_thread); + + void + GetLLDBCommandsFromIOHandler (const char *prompt, + IOHandlerDelegate &delegate, + bool asynchronously, + void *baton); + + void + GetPythonCommandsFromIOHandler (const char *prompt, + IOHandlerDelegate &delegate, + bool asynchronously, + void *baton); + //------------------------------------------------------------------ // Properties //------------------------------------------------------------------ @@ -450,12 +468,31 @@ public: protected: friend class Debugger; + //------------------------------------------------------------------ + // IOHandlerDelegate functions + //------------------------------------------------------------------ + virtual void + IOHandlerInputComplete (IOHandler &io_handler, + std::string &line); + + virtual ConstString + GetControlSequence (char ch) + { + if (ch == 'd') + return ConstString("quit\n"); + return ConstString(); + } + + size_t + GetProcessOutput (); + void SetSynchronous (bool value); lldb::CommandObjectSP GetCommandSP (const char *cmd, bool include_aliases = true, bool exact = true, StringList *matches = NULL); + private: Error @@ -473,10 +510,12 @@ private: CommandHistory m_command_history; std::string m_repeat_command; // Stores the command that will be executed for an empty command string. std::unique_ptr<ScriptInterpreter> m_script_interpreter_ap; + lldb::IOHandlerSP m_command_io_handler_sp; char m_comment_char; bool m_batch_command_mode; ChildrenTruncatedWarningStatus m_truncation_warning; // Whether we truncated children and whether the user has been told uint32_t m_command_source_depth; + std::vector<uint32_t> m_command_source_flags; }; diff --git a/include/lldb/Interpreter/PythonDataObjects.h b/include/lldb/Interpreter/PythonDataObjects.h index 2762d452c0c8e..55df4fd1b0a12 100644 --- a/include/lldb/Interpreter/PythonDataObjects.h +++ b/include/lldb/Interpreter/PythonDataObjects.h @@ -31,7 +31,7 @@ namespace lldb_private { { } - PythonObject (PyObject* py_obj) : + explicit PythonObject (PyObject* py_obj) : m_py_obj(NULL) { Reset (py_obj); @@ -43,7 +43,7 @@ namespace lldb_private { Reset (rhs.m_py_obj); } - PythonObject (const lldb::ScriptInterpreterObjectSP &script_object_sp); + explicit PythonObject (const lldb::ScriptInterpreterObjectSP &script_object_sp); virtual ~PythonObject () @@ -51,18 +51,10 @@ namespace lldb_private { Reset (NULL); } - const PythonObject & - operator = (const PythonObject &rhs) - { - if (this != &rhs) - Reset (rhs.m_py_obj); - return *this; - } - bool Reset (const PythonObject &object) { - return Reset(object.GetPythonObject()); + return Reset(object.get()); } virtual bool @@ -90,11 +82,11 @@ namespace lldb_private { Dump (Stream &strm) const; PyObject* - GetPythonObject () const + get () const { return m_py_obj; } - + PythonString Repr (); @@ -159,7 +151,7 @@ namespace lldb_private { { public: - PythonList (); + PythonList (bool create_empty); PythonList (PyObject* py_obj); PythonList (const PythonObject &object); PythonList (const lldb::ScriptInterpreterObjectSP &script_object_sp); @@ -186,7 +178,7 @@ namespace lldb_private { { public: - PythonDictionary (); + explicit PythonDictionary (bool create_empty); PythonDictionary (PyObject* object); PythonDictionary (const PythonObject &object); PythonDictionary (const lldb::ScriptInterpreterObjectSP &script_object_sp); @@ -221,6 +213,9 @@ namespace lldb_private { GetValueAtPosition (uint32_t pos) const; void + SetItemForKey (const PythonString &key, PyObject *value); + + void SetItemForKey (const PythonString &key, const PythonObject& value); }; diff --git a/include/lldb/Interpreter/ScriptInterpreter.h b/include/lldb/Interpreter/ScriptInterpreter.h index 9f529b822910a..1d62c9b0fb529 100644 --- a/include/lldb/Interpreter/ScriptInterpreter.h +++ b/include/lldb/Interpreter/ScriptInterpreter.h @@ -245,11 +245,13 @@ public: return true; } - virtual bool + virtual Error ExecuteMultipleLines (const char *in_string, const ExecuteScriptOptions &options = ExecuteScriptOptions()) { - return true; + Error error; + error.SetErrorString("not implemented"); + return error; } virtual bool diff --git a/include/lldb/Interpreter/ScriptInterpreterPython.h b/include/lldb/Interpreter/ScriptInterpreterPython.h index b729cb6280072..ba532808673fe 100644 --- a/include/lldb/Interpreter/ScriptInterpreterPython.h +++ b/include/lldb/Interpreter/ScriptInterpreterPython.h @@ -19,16 +19,21 @@ #include "lldb/lldb-python.h" #include "lldb/lldb-private.h" +#include "lldb/Core/IOHandler.h" #include "lldb/Interpreter/ScriptInterpreter.h" -#include "lldb/Core/InputReader.h" +#include "lldb/Interpreter/PythonDataObjects.h" #include "lldb/Host/Terminal.h" namespace lldb_private { -class ScriptInterpreterPython : public ScriptInterpreter +class ScriptInterpreterPython : + public ScriptInterpreter, + public IOHandlerDelegateMultiline { public: + friend class IOHandlerPythonInterpreter; + ScriptInterpreterPython (CommandInterpreter &interpreter); ~ScriptInterpreterPython (); @@ -47,7 +52,7 @@ public: void *ret_value, const ExecuteScriptOptions &options = ExecuteScriptOptions()); - bool + lldb_private::Error ExecuteMultipleLines (const char *in_string, const ExecuteScriptOptions &options = ExecuteScriptOptions()); @@ -134,20 +139,20 @@ public: bool GenerateWatchpointCommandCallbackData (StringList &input, std::string& output); - static size_t - GenerateBreakpointOptionsCommandCallback (void *baton, - InputReader &reader, - lldb::InputReaderAction notification, - const char *bytes, - size_t bytes_len); - - static size_t - GenerateWatchpointOptionsCommandCallback (void *baton, - InputReader &reader, - lldb::InputReaderAction notification, - const char *bytes, - size_t bytes_len); - +// static size_t +// GenerateBreakpointOptionsCommandCallback (void *baton, +// InputReader &reader, +// lldb::InputReaderAction notification, +// const char *bytes, +// size_t bytes_len); +// +// static size_t +// GenerateWatchpointOptionsCommandCallback (void *baton, +// InputReader &reader, +// lldb::InputReaderAction notification, +// const char *bytes, +// size_t bytes_len); + static bool BreakpointCallbackFunction (void *baton, StoppointCallbackContext *context, @@ -238,9 +243,6 @@ public: virtual void ResetOutputFileHandle (FILE *new_fh); - static lldb::thread_result_t - RunEmbeddedPythonInterpreter (lldb::thread_arg_t baton); - static void InitializePrivate (); @@ -266,10 +268,29 @@ public: SWIGPythonScriptKeyword_Frame swig_run_script_keyword_frame, SWIGPython_GetDynamicSetting swig_plugin_get); + const char * + GetDictionaryName () + { + return m_dictionary_name.c_str(); + } + + + //---------------------------------------------------------------------- + // IOHandlerDelegate + //---------------------------------------------------------------------- + virtual void + IOHandlerActivated (IOHandler &io_handler); + + virtual void + IOHandlerInputComplete (IOHandler &io_handler, std::string &data); + protected: bool - EnterSession (bool init_lldb_globals); + EnterSession (uint16_t on_entry_flags, + FILE *in, + FILE *out, + FILE *err); void LeaveSession (); @@ -279,8 +300,6 @@ protected: void RestoreTerminalState (); - -private: class SynchronicityHandler { @@ -322,7 +341,7 @@ private: private: DISALLOW_COPY_AND_ASSIGN (ScriptInterpreterPythonObject); }; - +public: class Locker : public ScriptInterpreterLocker { public: @@ -331,7 +350,8 @@ private: { AcquireLock = 0x0001, InitSession = 0x0002, - InitGlobals = 0x0004 + InitGlobals = 0x0004, + NoSTDIN = 0x0008 }; enum OnLeave @@ -344,7 +364,9 @@ private: Locker (ScriptInterpreterPython *py_interpreter = NULL, uint16_t on_entry = AcquireLock | InitSession, uint16_t on_leave = FreeLock | TearDownSession, - FILE* wait_msg_handle = NULL); + FILE *in = NULL, + FILE *out = NULL, + FILE *err = NULL); ~Locker (); @@ -354,7 +376,7 @@ private: DoAcquireLock (); bool - DoInitSession (bool init_lldb_globals); + DoInitSession (uint16_t on_entry_flags, FILE *in, FILE *out, FILE *err); bool DoFreeLock (); @@ -367,59 +389,40 @@ private: bool m_teardown_session; ScriptInterpreterPython *m_python_interpreter; - FILE* m_tmp_fh; +// FILE* m_tmp_fh; PyGILState_STATE m_GILState; }; - - class PythonInputReaderManager - { - public: - PythonInputReaderManager (ScriptInterpreterPython *interpreter); - - explicit operator bool() - { - return m_error; - } - - ~PythonInputReaderManager(); - - private: - - static size_t - InputReaderCallback (void *baton, - InputReader &reader, - lldb::InputReaderAction notification, - const char *bytes, - size_t bytes_len); - - static lldb::thread_result_t - RunPythonInputReader (lldb::thread_arg_t baton); - - ScriptInterpreterPython *m_interpreter; - lldb::DebuggerSP m_debugger_sp; - lldb::InputReaderSP m_reader_sp; - bool m_error; +private: + + enum ActiveIOHandler { + eIOHandlerNone, + eIOHandlerBreakpoint, + eIOHandlerWatchpoint }; + PythonObject & + GetMainModule (); + + PythonDictionary & + GetSessionDictionary (); + + PythonDictionary & + GetSysModuleDictionary (); - static size_t - InputReaderCallback (void *baton, - InputReader &reader, - lldb::InputReaderAction notification, - const char *bytes, - size_t bytes_len); - - - lldb_utility::PseudoTerminal m_embedded_thread_pty; - lldb_utility::PseudoTerminal m_embedded_python_pty; - lldb::InputReaderSP m_embedded_thread_input_reader_sp; - lldb::InputReaderSP m_embedded_python_input_reader_sp; - FILE *m_dbg_stdout; - PyObject *m_new_sysout; - PyObject *m_old_sysout; - PyObject *m_old_syserr; - PyObject *m_run_one_line; + bool + GetEmbeddedInterpreterModuleObjects (); + + PythonObject m_saved_stdin; + PythonObject m_saved_stdout; + PythonObject m_saved_stderr; + PythonObject m_main_module; + PythonObject m_lldb_module; + PythonDictionary m_session_dict; + PythonDictionary m_sys_module_dict; + PythonObject m_run_one_line_function; + PythonObject m_run_one_line_str_global; std::string m_dictionary_name; TerminalState m_terminal_state; + ActiveIOHandler m_active_io_handler; bool m_session_is_active; bool m_pty_slave_is_open; bool m_valid_session; |
