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"
|
2011-09-24 08:52:29 +08:00
|
|
|
#include "lldb/API/SBSection.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"
|
2011-03-31 09:08:07 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
2015-03-04 03:23:09 +08:00
|
|
|
#include "lldb/Core/StreamString.h"
|
|
|
|
#include "lldb/Symbol/LineEntry.h"
|
2010-12-21 04:49:23 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-09-24 08:52:29 +08:00
|
|
|
|
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 () :
|
2014-11-01 05:30:59 +08:00
|
|
|
m_opaque_ap (new Address())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-24 08:52:29 +08:00
|
|
|
SBAddress::SBAddress (const Address *lldb_object_ptr) :
|
2014-11-01 05:30:59 +08:00
|
|
|
m_opaque_ap (new Address())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (lldb_object_ptr)
|
2012-04-05 04:36:48 +08:00
|
|
|
ref() = *lldb_object_ptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBAddress::SBAddress (const SBAddress &rhs) :
|
2014-11-01 05:30:59 +08:00
|
|
|
m_opaque_ap (new Address())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (rhs.IsValid())
|
2012-04-05 04:36:48 +08:00
|
|
|
ref() = rhs.ref();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2012-02-04 10:58:17 +08:00
|
|
|
|
|
|
|
SBAddress::SBAddress (lldb::SBSection section, lldb::addr_t offset) :
|
2012-04-05 04:36:48 +08:00
|
|
|
m_opaque_ap(new Address (section.GetSP(), offset))
|
2012-02-04 10:58:17 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-07-23 00:46:35 +08:00
|
|
|
// Create an address by resolving a load address using the supplied target
|
|
|
|
SBAddress::SBAddress (lldb::addr_t load_addr, lldb::SBTarget &target) :
|
2014-11-01 05:30:59 +08:00
|
|
|
m_opaque_ap(new Address())
|
2011-07-23 00:46:35 +08:00
|
|
|
{
|
|
|
|
SetLoadAddress (load_addr, target);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SBAddress::~SBAddress ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const SBAddress &
|
|
|
|
SBAddress::operator = (const SBAddress &rhs)
|
|
|
|
{
|
2011-09-24 08:52:29 +08:00
|
|
|
if (this != &rhs)
|
|
|
|
{
|
|
|
|
if (rhs.IsValid())
|
2012-04-05 04:36:48 +08:00
|
|
|
ref() = rhs.ref();
|
2011-09-24 08:52:29 +08:00
|
|
|
else
|
2014-11-01 05:30:59 +08:00
|
|
|
m_opaque_ap.reset (new Address());
|
2011-09-24 08:52:29 +08:00
|
|
|
}
|
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 ()
|
|
|
|
{
|
2014-11-01 05:30:59 +08:00
|
|
|
m_opaque_ap.reset (new Address());
|
2010-09-11 02:31:35 +08:00
|
|
|
}
|
|
|
|
|
2012-02-04 10:58:17 +08:00
|
|
|
void
|
|
|
|
SBAddress::SetAddress (lldb::SBSection section, lldb::addr_t offset)
|
|
|
|
{
|
|
|
|
Address &addr = ref();
|
2012-02-24 09:59:29 +08:00
|
|
|
addr.SetSection (section.GetSP());
|
2012-02-04 10:58:17 +08:00
|
|
|
addr.SetOffset (offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void
|
2011-09-24 08:52:29 +08:00
|
|
|
SBAddress::SetAddress (const Address *lldb_object_ptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (lldb_object_ptr)
|
2012-04-05 04:36:48 +08:00
|
|
|
ref() = *lldb_object_ptr;
|
2011-09-24 08:52:29 +08:00
|
|
|
else
|
2014-11-01 05:30:59 +08:00
|
|
|
m_opaque_ap.reset (new Address());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb::addr_t
|
|
|
|
SBAddress::GetFileAddress () const
|
|
|
|
{
|
2014-11-01 05:30:59 +08:00
|
|
|
if (m_opaque_ap->IsValid())
|
2012-04-05 04:36:48 +08:00
|
|
|
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
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(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;
|
2012-01-30 15:41:31 +08:00
|
|
|
TargetSP target_sp (target.GetSP());
|
2012-10-23 04:49:35 +08:00
|
|
|
if (target_sp)
|
2010-10-26 11:11:13 +08:00
|
|
|
{
|
2014-11-01 05:30:59 +08:00
|
|
|
if (m_opaque_ap->IsValid())
|
2012-10-23 04:49:35 +08:00
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
|
2012-10-23 04:49:35 +08:00
|
|
|
addr = m_opaque_ap->GetLoadAddress (target_sp.get());
|
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
}
|
2014-04-04 12:06:10 +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)
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => LLDB_INVALID_ADDRESS",
|
|
|
|
static_cast<void*>(target_sp.get()));
|
2010-12-21 04:49:23 +08:00
|
|
|
else
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => 0x%" PRIx64,
|
|
|
|
static_cast<void*>(target_sp.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
|
|
|
}
|
|
|
|
|
2011-07-23 00:46:35 +08:00
|
|
|
void
|
|
|
|
SBAddress::SetLoadAddress (lldb::addr_t load_addr, lldb::SBTarget &target)
|
|
|
|
{
|
|
|
|
// Create the address object if we don't already have one
|
|
|
|
ref();
|
|
|
|
if (target.IsValid())
|
|
|
|
*this = target.ResolveLoadAddress(load_addr);
|
|
|
|
else
|
2012-04-05 04:36:48 +08:00
|
|
|
m_opaque_ap->Clear();
|
2011-07-23 00:46:35 +08:00
|
|
|
|
|
|
|
// Check if we weren't were able to resolve a section offset address.
|
|
|
|
// If we weren't it is ok, the load address might be a location on the
|
|
|
|
// stack or heap, so we should just have an address with no section and
|
|
|
|
// a valid offset
|
|
|
|
if (!m_opaque_ap->IsValid())
|
2012-04-05 04:36:48 +08:00
|
|
|
m_opaque_ap->SetOffset(load_addr);
|
2011-07-23 00:46:35 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool
|
|
|
|
SBAddress::OffsetAddress (addr_t offset)
|
|
|
|
{
|
2014-11-01 05:30:59 +08:00
|
|
|
if (m_opaque_ap->IsValid())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-04-05 04:36:48 +08:00
|
|
|
addr_t addr_offset = m_opaque_ap->GetOffset();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (addr_offset != LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
2012-04-05 04:36:48 +08:00
|
|
|
m_opaque_ap->SetOffset(addr_offset + offset);
|
2010-06-09 00:52:24 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-24 08:52:29 +08:00
|
|
|
lldb::SBSection
|
|
|
|
SBAddress::GetSection ()
|
|
|
|
{
|
|
|
|
lldb::SBSection sb_section;
|
2014-11-01 05:30:59 +08:00
|
|
|
if (m_opaque_ap->IsValid())
|
2012-04-05 04:36:48 +08:00
|
|
|
sb_section.SetSP (m_opaque_ap->GetSection());
|
2011-09-24 08:52:29 +08:00
|
|
|
return sb_section;
|
|
|
|
}
|
|
|
|
|
2012-01-29 14:07:39 +08:00
|
|
|
lldb::addr_t
|
|
|
|
SBAddress::GetOffset ()
|
|
|
|
{
|
2014-11-01 05:30:59 +08:00
|
|
|
if (m_opaque_ap->IsValid())
|
2012-10-31 00:32:38 +08:00
|
|
|
return m_opaque_ap->GetOffset();
|
2012-01-29 14:07:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2011-09-24 08:52:29 +08:00
|
|
|
|
|
|
|
Address *
|
2010-09-11 02:31:35 +08:00
|
|
|
SBAddress::operator->()
|
|
|
|
{
|
2012-04-05 04:36:48 +08:00
|
|
|
return m_opaque_ap.get();
|
2010-09-11 02:31:35 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-09-24 08:52:29 +08:00
|
|
|
const Address *
|
2010-06-09 00:52:24 +08:00
|
|
|
SBAddress::operator->() const
|
|
|
|
{
|
2012-04-05 04:36:48 +08:00
|
|
|
return m_opaque_ap.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-09-24 08:52:29 +08:00
|
|
|
Address &
|
2011-07-23 00:46:35 +08:00
|
|
|
SBAddress::ref ()
|
2010-09-11 02:31:35 +08:00
|
|
|
{
|
|
|
|
if (m_opaque_ap.get() == NULL)
|
2012-04-05 04:36:48 +08:00
|
|
|
m_opaque_ap.reset (new Address());
|
|
|
|
return *m_opaque_ap;
|
2010-09-11 02:31:35 +08:00
|
|
|
}
|
|
|
|
|
2011-09-24 08:52:29 +08:00
|
|
|
const Address &
|
2011-07-23 00:46:35 +08:00
|
|
|
SBAddress::ref () const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-04-05 04:36:48 +08:00
|
|
|
// This object should already have checked with "IsValid()"
|
2011-07-23 00:46:35 +08:00
|
|
|
// prior to calling this function. In case you didn't we will assert
|
|
|
|
// and die to let you know.
|
2010-09-11 02:31:35 +08:00
|
|
|
assert (m_opaque_ap.get());
|
2012-04-05 04:36:48 +08:00
|
|
|
return *m_opaque_ap;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-09-24 08:52:29 +08:00
|
|
|
Address *
|
2010-10-27 07:49:36 +08:00
|
|
|
SBAddress::get ()
|
|
|
|
{
|
2012-04-05 04:36:48 +08:00
|
|
|
return m_opaque_ap.get();
|
2010-10-27 07:49:36 +08:00
|
|
|
}
|
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...
|
2011-11-13 14:57:31 +08:00
|
|
|
Stream &strm = description.ref();
|
2014-11-01 05:30:59 +08:00
|
|
|
if (m_opaque_ap->IsValid())
|
2012-04-05 04:36:48 +08:00
|
|
|
{
|
|
|
|
m_opaque_ap->Dump (&strm,
|
|
|
|
NULL,
|
|
|
|
Address::DumpStyleResolvedDescription,
|
|
|
|
Address::DumpStyleModuleWithFileAddress,
|
|
|
|
4);
|
|
|
|
StreamString sstrm;
|
|
|
|
// m_opaque_ap->Dump (&sstrm, NULL, Address::DumpStyleResolvedDescription, Address::DumpStyleInvalid, 4);
|
|
|
|
// if (sstrm.GetData())
|
|
|
|
// strm.Printf (" (%s)", sstrm.GetData());
|
|
|
|
}
|
2010-09-20 13:20:02 +08:00
|
|
|
else
|
2011-11-13 14:57:31 +08:00
|
|
|
strm.PutCString ("No value");
|
2010-09-20 13:20:02 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-03-31 09:08:07 +08:00
|
|
|
|
|
|
|
SBModule
|
|
|
|
SBAddress::GetModule ()
|
|
|
|
{
|
|
|
|
SBModule sb_module;
|
2014-11-01 05:30:59 +08:00
|
|
|
if (m_opaque_ap->IsValid())
|
2012-04-05 04:36:48 +08:00
|
|
|
sb_module.SetSP (m_opaque_ap->GetModule());
|
2011-03-31 09:08:07 +08:00
|
|
|
return sb_module;
|
|
|
|
}
|
|
|
|
|
2011-08-13 05:40:01 +08:00
|
|
|
SBSymbolContext
|
|
|
|
SBAddress::GetSymbolContext (uint32_t resolve_scope)
|
|
|
|
{
|
|
|
|
SBSymbolContext sb_sc;
|
2014-11-01 05:30:59 +08:00
|
|
|
if (m_opaque_ap->IsValid())
|
2012-04-05 04:36:48 +08:00
|
|
|
m_opaque_ap->CalculateSymbolContext (&sb_sc.ref(), resolve_scope);
|
2011-08-13 05:40:01 +08:00
|
|
|
return sb_sc;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBCompileUnit
|
|
|
|
SBAddress::GetCompileUnit ()
|
|
|
|
{
|
|
|
|
SBCompileUnit sb_comp_unit;
|
2014-11-01 05:30:59 +08:00
|
|
|
if (m_opaque_ap->IsValid())
|
2012-04-05 04:36:48 +08:00
|
|
|
sb_comp_unit.reset(m_opaque_ap->CalculateSymbolContextCompileUnit());
|
2011-08-13 05:40:01 +08:00
|
|
|
return sb_comp_unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBFunction
|
|
|
|
SBAddress::GetFunction ()
|
|
|
|
{
|
|
|
|
SBFunction sb_function;
|
2014-11-01 05:30:59 +08:00
|
|
|
if (m_opaque_ap->IsValid())
|
2012-04-05 04:36:48 +08:00
|
|
|
sb_function.reset(m_opaque_ap->CalculateSymbolContextFunction());
|
2011-08-13 05:40:01 +08:00
|
|
|
return sb_function;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBBlock
|
|
|
|
SBAddress::GetBlock ()
|
|
|
|
{
|
|
|
|
SBBlock sb_block;
|
2014-11-01 05:30:59 +08:00
|
|
|
if (m_opaque_ap->IsValid())
|
2012-04-05 04:36:48 +08:00
|
|
|
sb_block.SetPtr(m_opaque_ap->CalculateSymbolContextBlock());
|
2011-08-13 05:40:01 +08:00
|
|
|
return sb_block;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBSymbol
|
|
|
|
SBAddress::GetSymbol ()
|
|
|
|
{
|
|
|
|
SBSymbol sb_symbol;
|
2014-11-01 05:30:59 +08:00
|
|
|
if (m_opaque_ap->IsValid())
|
2012-04-05 04:36:48 +08:00
|
|
|
sb_symbol.reset(m_opaque_ap->CalculateSymbolContextSymbol());
|
2011-08-13 05:40:01 +08:00
|
|
|
return sb_symbol;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBLineEntry
|
|
|
|
SBAddress::GetLineEntry ()
|
|
|
|
{
|
|
|
|
SBLineEntry sb_line_entry;
|
2014-11-01 05:30:59 +08:00
|
|
|
if (m_opaque_ap->IsValid())
|
2011-08-13 05:40:01 +08:00
|
|
|
{
|
|
|
|
LineEntry line_entry;
|
2012-04-05 04:36:48 +08:00
|
|
|
if (m_opaque_ap->CalculateSymbolContextLineEntry (line_entry))
|
2011-08-13 05:40:01 +08:00
|
|
|
sb_line_entry.SetLineEntry (line_entry);
|
|
|
|
}
|
|
|
|
return sb_line_entry;
|
|
|
|
}
|
|
|
|
|
2012-04-13 08:07:34 +08:00
|
|
|
AddressClass
|
|
|
|
SBAddress::GetAddressClass ()
|
|
|
|
{
|
2014-11-01 05:30:59 +08:00
|
|
|
if (m_opaque_ap->IsValid())
|
2012-04-13 08:07:34 +08:00
|
|
|
return m_opaque_ap->GetAddressClass();
|
|
|
|
return eAddressClassInvalid;
|
|
|
|
}
|
2011-03-31 09:08:07 +08:00
|
|
|
|