Make the SBAddress class easier to use when using the public
API.
SBTarget changes include changing:
bool
SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr,
lldb::SBAddress& addr);
to be:
lldb::SBAddress
SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr);
SBAddress can how contruct itself using a load address and a target
which can be used to resolve the address:
SBAddress (lldb::addr_t load_addr, lldb::SBTarget &target);
This will actually just call the new SetLoadAddress accessor:
void
SetLoadAddress (lldb::addr_t load_addr,
lldb::SBTarget &target);
This function will always succeed in making a SBAddress object
that can be used in API calls (even if "target" isn't valid).
If "target" is valid and there are sections currently loaded,
then it will resolve the address to a section offset address if
it can. Else an address with a NULL section and an offset that is
the "load_addr" that was passed in. We do this because a load address
might be from the heap or stack.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@135770 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/API/SBAddress.cpp b/source/API/SBAddress.cpp
index 6c357f9..57b58bf 100644
--- a/source/API/SBAddress.cpp
+++ b/source/API/SBAddress.cpp
@@ -39,6 +39,15 @@
m_opaque_ap.reset (new lldb_private::Address(*rhs.m_opaque_ap.get()));
}
+// Create an address by resolving a load address using the supplied target
+SBAddress::SBAddress (lldb::addr_t load_addr, lldb::SBTarget &target) :
+ m_opaque_ap()
+{
+ SetLoadAddress (load_addr, target);
+}
+
+
+
SBAddress::~SBAddress ()
{
}
@@ -110,6 +119,24 @@
return addr;
}
+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
+ m_opaque_ap->Clear();
+
+ // 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())
+ m_opaque_ap->SetOffset(load_addr);
+}
+
bool
SBAddress::OffsetAddress (addr_t offset)
{
@@ -138,7 +165,7 @@
}
lldb_private::Address &
-SBAddress::operator*()
+SBAddress::ref ()
{
if (m_opaque_ap.get() == NULL)
m_opaque_ap.reset (new lldb_private::Address);
@@ -146,8 +173,11 @@
}
const lldb_private::Address &
-SBAddress::operator*() const
+SBAddress::ref () const
{
+ // "const SBAddress &addr" should already have checked "addr.IsValid()"
+ // prior to calling this function. In case you didn't we will assert
+ // and die to let you know.
assert (m_opaque_ap.get());
return *m_opaque_ap;
}