From 6611103cfe7a8c08554816fc08abef2e2960e799 Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Wed, 23 Jun 2010 01:19:29 +0000 Subject: Very large changes that were needed in order to allow multiple connections to the debugger from GUI windows. Previously there was one global debugger instance that could be accessed that had its own command interpreter and current state (current target/process/thread/frame). When a GUI debugger was attached, if it opened more than one window that each had a console window, there were issues where the last one to setup the global debugger object won and got control of the debugger. To avoid this we now create instances of the lldb_private::Debugger that each has its own state: - target list for targets the debugger instance owns - current process/thread/frame - its own command interpreter - its own input, output and error file handles to avoid conflicts - its own input reader stack So now clients should call: SBDebugger::Initialize(); // (static function) SBDebugger debugger (SBDebugger::Create()); // Use which ever file handles you wish debugger.SetErrorFileHandle (stderr, false); debugger.SetOutputFileHandle (stdout, false); debugger.SetInputFileHandle (stdin, true); // main loop SBDebugger::Terminate(); // (static function) SBDebugger::Initialize() and SBDebugger::Terminate() are ref counted to ensure nothing gets destroyed too early when multiple clients might be attached. Cleaned up the command interpreter and the CommandObject and all subclasses to take more appropriate arguments. llvm-svn: 106615 --- lldb/source/API/SBInputReader.cpp | 59 ++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 25 deletions(-) (limited to 'lldb/source/API/SBInputReader.cpp') diff --git a/lldb/source/API/SBInputReader.cpp b/lldb/source/API/SBInputReader.cpp index 022d73207ad2..4d1c7b91e8e9 100644 --- a/lldb/source/API/SBInputReader.cpp +++ b/lldb/source/API/SBInputReader.cpp @@ -10,8 +10,9 @@ #include "lldb/lldb-enumerations.h" -#include "lldb/API/SBInputReader.h" +#include "lldb/API/SBDebugger.h" #include "lldb/API/SBError.h" +#include "lldb/API/SBInputReader.h" #include "lldb/API/SBStringList.h" #include "lldb/Core/InputReader.h" @@ -20,7 +21,7 @@ using namespace lldb; using namespace lldb_private; SBInputReader::SBInputReader () : - m_reader_sp (), + m_opaque_sp (), m_callback_function (NULL), m_callback_baton (NULL) @@ -28,12 +29,12 @@ SBInputReader::SBInputReader () : } SBInputReader::SBInputReader (const lldb::InputReaderSP &reader_sp) : - m_reader_sp (reader_sp) + m_opaque_sp (reader_sp) { } SBInputReader::SBInputReader (const SBInputReader &rhs) : - m_reader_sp (rhs.m_reader_sp) + m_opaque_sp (rhs.m_opaque_sp) { } @@ -45,7 +46,7 @@ size_t SBInputReader::PrivateCallback ( void *baton, - InputReader *reader, + InputReader &reader, lldb::InputReaderAction notification, const char *bytes, size_t bytes_len @@ -62,6 +63,7 @@ SBInputReader::PrivateCallback SBError SBInputReader::Initialize ( + SBDebugger &debugger, Callback callback_function, void *callback_baton, lldb::InputReaderGranularity granularity, @@ -71,14 +73,14 @@ SBInputReader::Initialize ) { SBError sb_error; - m_reader_sp.reset (new InputReader ()); + m_opaque_sp.reset (new InputReader (debugger.ref())); m_callback_function = callback_function; m_callback_baton = callback_baton; - if (m_reader_sp) + if (m_opaque_sp) { - sb_error.SetError (m_reader_sp->Initialize (SBInputReader::PrivateCallback, + sb_error.SetError (m_opaque_sp->Initialize (SBInputReader::PrivateCallback, this, granularity, end_token, @@ -88,7 +90,7 @@ SBInputReader::Initialize if (sb_error.Fail()) { - m_reader_sp.reset (); + m_opaque_sp.reset (); m_callback_function = NULL; m_callback_baton = NULL; } @@ -99,46 +101,53 @@ SBInputReader::Initialize bool SBInputReader::IsValid () const { - return (m_reader_sp.get() != NULL); + return (m_opaque_sp.get() != NULL); } const SBInputReader & SBInputReader::operator = (const SBInputReader &rhs) { if (this != &rhs) - m_reader_sp = rhs.m_reader_sp; + m_opaque_sp = rhs.m_opaque_sp; return *this; } -lldb_private::InputReader * +InputReader * SBInputReader::operator->() const { - return m_reader_sp.get(); + return m_opaque_sp.get(); } lldb::InputReaderSP & SBInputReader::operator *() { - return m_reader_sp; + return m_opaque_sp; } const lldb::InputReaderSP & SBInputReader::operator *() const { - return m_reader_sp; + return m_opaque_sp; } -lldb_private::InputReader * +InputReader * SBInputReader::get() const { - return m_reader_sp.get(); + return m_opaque_sp.get(); +} + +InputReader & +SBInputReader::ref() const +{ + assert (m_opaque_sp.get()); + return *m_opaque_sp; } bool SBInputReader::IsDone () const { - if (m_reader_sp) - return m_reader_sp->IsDone(); + if (m_opaque_sp) + return m_opaque_sp->IsDone(); else return true; } @@ -146,15 +155,15 @@ SBInputReader::IsDone () const void SBInputReader::SetIsDone (bool value) { - if (m_reader_sp) - m_reader_sp->SetIsDone (value); + if (m_opaque_sp) + m_opaque_sp->SetIsDone (value); } bool SBInputReader::IsActive () const { - if (m_reader_sp) - return m_reader_sp->IsActive(); + if (m_opaque_sp) + return m_opaque_sp->IsActive(); else return false; } @@ -162,8 +171,8 @@ SBInputReader::IsActive () const InputReaderGranularity SBInputReader::GetGranularity () { - if (m_reader_sp) - return m_reader_sp->GetGranularity(); + if (m_opaque_sp) + return m_opaque_sp->GetGranularity(); else return eInputReaderGranularityInvalid; } -- cgit v1.2.3