2010-06-09 00:52:24 +08:00
|
|
|
//===-- 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"
|
2010-09-20 13:20:02 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Address.h"
|
2010-10-26 11:11:13 +08:00
|
|
|
#include "lldb/Core/Log.h"
|
2010-12-21 04:49:23 +08:00
|
|
|
#include "lldb/Host/Mutex.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
2010-10-26 11:11:13 +08:00
|
|
|
using namespace lldb_private;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
SBAddress::SBAddress () :
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SBAddress::SBAddress (const lldb_private::Address *lldb_object_ptr) :
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (lldb_object_ptr)
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap.reset (new lldb_private::Address(*lldb_object_ptr));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBAddress::SBAddress (const SBAddress &rhs) :
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (rhs.IsValid())
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap.reset (new lldb_private::Address(*rhs.m_opaque_ap.get()));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBAddress::~SBAddress ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const SBAddress &
|
|
|
|
SBAddress::operator = (const SBAddress &rhs)
|
|
|
|
{
|
2010-10-31 11:01:06 +08:00
|
|
|
if (this != &rhs && rhs.IsValid())
|
|
|
|
m_opaque_ap.reset (new lldb_private::Address(*rhs.m_opaque_ap.get()));
|
2010-06-09 00:52:24 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBAddress::IsValid () const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_ap.get() != NULL && m_opaque_ap->IsValid();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-09-11 02:31:35 +08:00
|
|
|
void
|
|
|
|
SBAddress::Clear ()
|
|
|
|
{
|
|
|
|
m_opaque_ap.reset();
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void
|
|
|
|
SBAddress::SetAddress (const lldb_private::Address *lldb_object_ptr)
|
|
|
|
{
|
|
|
|
if (lldb_object_ptr)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
|
|
|
*m_opaque_ap = *lldb_object_ptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap.reset (new lldb_private::Address(*lldb_object_ptr));
|
2010-06-09 00:52:24 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
|
|
|
m_opaque_ap->Clear();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb::addr_t
|
|
|
|
SBAddress::GetFileAddress () const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
|
|
|
return m_opaque_ap->GetFileAddress();
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
return LLDB_INVALID_ADDRESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::addr_t
|
2010-09-15 07:36:40 +08:00
|
|
|
SBAddress::GetLoadAddress (const SBTarget &target) const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-12-21 04:49:23 +08:00
|
|
|
lldb::addr_t addr = LLDB_INVALID_ADDRESS;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
2010-10-26 11:11:13 +08:00
|
|
|
{
|
2010-12-21 04:49:23 +08:00
|
|
|
Mutex::Locker api_locker (target->GetAPIMutex());
|
|
|
|
addr = m_opaque_ap->GetLoadAddress (target.get());
|
2010-10-26 11:11:13 +08:00
|
|
|
}
|
2010-12-21 04:49:23 +08:00
|
|
|
|
|
|
|
if (log)
|
2010-10-26 11:11:13 +08:00
|
|
|
{
|
2010-12-21 04:49:23 +08:00
|
|
|
if (addr == LLDB_INVALID_ADDRESS)
|
2010-10-31 11:01:06 +08:00
|
|
|
log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => LLDB_INVALID_ADDRESS", target.get());
|
2010-12-21 04:49:23 +08:00
|
|
|
else
|
|
|
|
log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => 0x%llx", target.get(), addr);
|
2010-10-26 11:11:13 +08:00
|
|
|
}
|
2010-12-21 04:49:23 +08:00
|
|
|
|
|
|
|
return addr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBAddress::OffsetAddress (addr_t offset)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
addr_t addr_offset = m_opaque_ap->GetOffset();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (addr_offset != LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap->SetOffset(addr_offset + offset);
|
2010-06-09 00:52:24 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-11 02:31:35 +08:00
|
|
|
lldb_private::Address *
|
|
|
|
SBAddress::operator->()
|
|
|
|
{
|
|
|
|
return m_opaque_ap.get();
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
const lldb_private::Address *
|
|
|
|
SBAddress::operator->() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_ap.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-09-11 02:31:35 +08:00
|
|
|
lldb_private::Address &
|
|
|
|
SBAddress::operator*()
|
|
|
|
{
|
|
|
|
if (m_opaque_ap.get() == NULL)
|
|
|
|
m_opaque_ap.reset (new lldb_private::Address);
|
|
|
|
return *m_opaque_ap;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
const lldb_private::Address &
|
|
|
|
SBAddress::operator*() const
|
|
|
|
{
|
2010-09-11 02:31:35 +08:00
|
|
|
assert (m_opaque_ap.get());
|
2010-06-23 09:19:29 +08:00
|
|
|
return *m_opaque_ap;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
lldb_private::Address *
|
|
|
|
SBAddress::get ()
|
|
|
|
{
|
|
|
|
return m_opaque_ap.get();
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-09-20 13:20:02 +08:00
|
|
|
bool
|
|
|
|
SBAddress::GetDescription (SBStream &description)
|
|
|
|
{
|
2010-10-31 11:01:06 +08:00
|
|
|
// Call "ref()" on the stream to make sure it creates a backing stream in
|
|
|
|
// case there isn't one already...
|
2010-09-23 07:01:29 +08:00
|
|
|
description.ref();
|
2010-09-20 13:20:02 +08:00
|
|
|
if (m_opaque_ap.get())
|
2010-10-31 11:01:06 +08:00
|
|
|
m_opaque_ap->Dump (description.get(), NULL, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleInvalid, 4);
|
2010-09-20 13:20:02 +08:00
|
|
|
else
|
|
|
|
description.Printf ("No value");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|