llvm-project/lldb/source/API/SBAddress.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

119 lines
2.4 KiB
C++

//===-- SBAddress.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/API/SBAddress.h"
#include "lldb/API/SBProcess.h"
#include "lldb/Core/Address.h"
using namespace lldb;
SBAddress::SBAddress () :
m_opaque_ap ()
{
}
SBAddress::SBAddress (const lldb_private::Address *lldb_object_ptr) :
m_opaque_ap ()
{
if (lldb_object_ptr)
m_opaque_ap.reset (new lldb_private::Address(*lldb_object_ptr));
}
SBAddress::SBAddress (const SBAddress &rhs) :
m_opaque_ap ()
{
if (rhs.IsValid())
m_opaque_ap.reset (new lldb_private::Address(*rhs.m_opaque_ap.get()));
}
SBAddress::~SBAddress ()
{
}
const SBAddress &
SBAddress::operator = (const SBAddress &rhs)
{
if (this != &rhs)
{
if (rhs.IsValid())
m_opaque_ap.reset (new lldb_private::Address(*rhs.m_opaque_ap.get()));
}
return *this;
}
bool
SBAddress::IsValid () const
{
return m_opaque_ap.get() != NULL && m_opaque_ap->IsValid();
}
void
SBAddress::SetAddress (const lldb_private::Address *lldb_object_ptr)
{
if (lldb_object_ptr)
{
if (m_opaque_ap.get())
*m_opaque_ap = *lldb_object_ptr;
else
m_opaque_ap.reset (new lldb_private::Address(*lldb_object_ptr));
return;
}
if (m_opaque_ap.get())
m_opaque_ap->Clear();
}
lldb::addr_t
SBAddress::GetFileAddress () const
{
if (m_opaque_ap.get())
return m_opaque_ap->GetFileAddress();
else
return LLDB_INVALID_ADDRESS;
}
lldb::addr_t
SBAddress::GetLoadAddress (const SBProcess &process) const
{
if (m_opaque_ap.get())
return m_opaque_ap->GetLoadAddress(process.get());
else
return LLDB_INVALID_ADDRESS;
}
bool
SBAddress::OffsetAddress (addr_t offset)
{
if (m_opaque_ap.get())
{
addr_t addr_offset = m_opaque_ap->GetOffset();
if (addr_offset != LLDB_INVALID_ADDRESS)
{
m_opaque_ap->SetOffset(addr_offset + offset);
return true;
}
}
return false;
}
const lldb_private::Address *
SBAddress::operator->() const
{
return m_opaque_ap.get();
}
const lldb_private::Address &
SBAddress::operator*() const
{
return *m_opaque_ap;
}