Files
clang-p2996/lldb/source/API/SBBroadcaster.cpp
Greg Clayton 6611103cfe 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
2010-06-23 01:19:29 +00:00

143 lines
2.9 KiB
C++

//===-- SBBroadcaster.cpp ---------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lldb/Core/Broadcaster.h"
#include "lldb/lldb-forward-rtti.h"
#include "lldb/API/SBBroadcaster.h"
#include "lldb/API/SBListener.h"
#include "lldb/API/SBEvent.h"
using namespace lldb;
using namespace lldb_private;
SBBroadcaster::SBBroadcaster () :
m_opaque (NULL),
m_opaque_owned (false)
{
}
SBBroadcaster::SBBroadcaster (const char *name) :
m_opaque (new Broadcaster (name)),
m_opaque_owned (true)
{
}
SBBroadcaster::SBBroadcaster (lldb_private::Broadcaster *broadcaster, bool owns) :
m_opaque (broadcaster),
m_opaque_owned (owns)
{
}
SBBroadcaster::~SBBroadcaster()
{
reset (NULL, false);
}
void
SBBroadcaster::BroadcastEventByType (uint32_t event_type, bool unique)
{
if (m_opaque == NULL)
return;
if (unique)
m_opaque->BroadcastEventIfUnique (event_type);
else
m_opaque->BroadcastEvent (event_type);
}
void
SBBroadcaster::BroadcastEvent (const SBEvent &event, bool unique)
{
if (m_opaque == NULL)
return;
EventSP event_sp = event.GetSP ();
if (unique)
m_opaque->BroadcastEventIfUnique (event_sp);
else
m_opaque->BroadcastEvent (event_sp);
}
void
SBBroadcaster::AddInitialEventsToListener (const SBListener &listener, uint32_t requested_events)
{
if (m_opaque)
m_opaque->AddInitialEventsToListener (listener.get(), requested_events);
}
uint32_t
SBBroadcaster::AddListener (const SBListener &listener, uint32_t event_mask)
{
if (m_opaque)
return m_opaque->AddListener (listener.get(), event_mask);
return 0;
}
const char *
SBBroadcaster::GetName ()
{
if (m_opaque)
return m_opaque->GetBroadcasterName().AsCString();
return NULL;
}
bool
SBBroadcaster::EventTypeHasListeners (uint32_t event_type)
{
if (m_opaque)
return m_opaque->EventTypeHasListeners (event_type);
return false;
}
bool
SBBroadcaster::RemoveListener (const SBListener &listener, uint32_t event_mask)
{
if (m_opaque)
return m_opaque->RemoveListener (listener.get(), event_mask);
return false;
}
Broadcaster *
SBBroadcaster::get () const
{
return m_opaque;
}
void
SBBroadcaster::reset (Broadcaster *broadcaster, bool owns)
{
if (m_opaque && m_opaque_owned)
delete m_opaque;
m_opaque = broadcaster;
m_opaque_owned = owns;
}
bool
SBBroadcaster::IsValid () const
{
return m_opaque != NULL;
}
bool
SBBroadcaster::operator == (const SBBroadcaster &rhs) const
{
return m_opaque == rhs.m_opaque;
}
bool
SBBroadcaster::operator != (const SBBroadcaster &rhs) const
{
return m_opaque != rhs.m_opaque;
}