[Lldb-commits] [lldb] r135770 - in /lldb/trunk: include/lldb/API/SBAddress.h include/lldb/API/SBTarget.h scripts/Python/interface/SBAddress.i scripts/Python/interface/SBTarget.i source/API/SBAddress.cpp source/API/SBModule.cpp source/API/SBTarget.cpp test/python_api/default-constructor/sb_target.py
Greg Clayton
gclayton at apple.com
Fri Jul 22 09:46:35 PDT 2011
Author: gclayton
Date: Fri Jul 22 11:46:35 2011
New Revision: 135770
URL: http://llvm.org/viewvc/llvm-project?rev=135770&view=rev
Log:
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.
Modified:
lldb/trunk/include/lldb/API/SBAddress.h
lldb/trunk/include/lldb/API/SBTarget.h
lldb/trunk/scripts/Python/interface/SBAddress.i
lldb/trunk/scripts/Python/interface/SBTarget.i
lldb/trunk/source/API/SBAddress.cpp
lldb/trunk/source/API/SBModule.cpp
lldb/trunk/source/API/SBTarget.cpp
lldb/trunk/test/python_api/default-constructor/sb_target.py
Modified: lldb/trunk/include/lldb/API/SBAddress.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBAddress.h?rev=135770&r1=135769&r2=135770&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBAddress.h (original)
+++ lldb/trunk/include/lldb/API/SBAddress.h Fri Jul 22 11:46:35 2011
@@ -23,6 +23,9 @@
SBAddress (const lldb::SBAddress &rhs);
+ // Create an address by resolving a load address using the supplied target
+ SBAddress (lldb::addr_t load_addr, lldb::SBTarget &target);
+
~SBAddress ();
#ifndef SWIG
@@ -42,6 +45,9 @@
addr_t
GetLoadAddress (const lldb::SBTarget &target) const;
+ void
+ SetLoadAddress (lldb::addr_t load_addr,
+ lldb::SBTarget &target);
bool
OffsetAddress (addr_t offset);
@@ -74,15 +80,15 @@
const lldb_private::Address *
operator->() const;
- const lldb_private::Address &
- operator*() const;
+ lldb_private::Address *
+ get ();
lldb_private::Address &
- operator*();
+ ref();
+
+ const lldb_private::Address &
+ ref() const;
- lldb_private::Address *
- get ();
-
#endif
Modified: lldb/trunk/include/lldb/API/SBTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=135770&r1=135769&r2=135770&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBTarget.h (original)
+++ lldb/trunk/include/lldb/API/SBTarget.h Fri Jul 22 11:46:35 2011
@@ -11,6 +11,7 @@
#define LLDB_SBTarget_h_
#include "lldb/API/SBDefines.h"
+#include "lldb/API/SBAddress.h"
#include "lldb/API/SBBroadcaster.h"
#include "lldb/API/SBFileSpec.h"
@@ -296,9 +297,8 @@
void
Clear ();
- bool
- ResolveLoadAddress (lldb::addr_t vm_addr,
- lldb::SBAddress& addr);
+ lldb::SBAddress
+ ResolveLoadAddress (lldb::addr_t vm_addr);
SBSymbolContext
ResolveSymbolContextForAddress (const SBAddress& addr,
Modified: lldb/trunk/scripts/Python/interface/SBAddress.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBAddress.i?rev=135770&r1=135769&r2=135770&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBAddress.i (original)
+++ lldb/trunk/scripts/Python/interface/SBAddress.i Fri Jul 22 11:46:35 2011
@@ -50,6 +50,9 @@
SBAddress (const lldb::SBAddress &rhs);
+ // Create an address by resolving a load address using the supplied target
+ SBAddress (lldb::addr_t load_addr, lldb::SBTarget &target);
+
~SBAddress ();
bool
@@ -64,6 +67,10 @@
addr_t
GetLoadAddress (const lldb::SBTarget &target) const;
+ void
+ SetLoadAddress (lldb::addr_t load_addr,
+ lldb::SBTarget &target);
+
bool
OffsetAddress (addr_t offset);
Modified: lldb/trunk/scripts/Python/interface/SBTarget.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBTarget.i?rev=135770&r1=135769&r2=135770&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBTarget.i (original)
+++ lldb/trunk/scripts/Python/interface/SBTarget.i Fri Jul 22 11:46:35 2011
@@ -343,9 +343,8 @@
void
Clear ();
- bool
- ResolveLoadAddress (lldb::addr_t vm_addr,
- lldb::SBAddress& addr);
+ lldb::SBAddress
+ ResolveLoadAddress (lldb::addr_t vm_addr);
SBSymbolContext
ResolveSymbolContextForAddress (const SBAddress& addr,
Modified: lldb/trunk/source/API/SBAddress.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBAddress.cpp?rev=135770&r1=135769&r2=135770&view=diff
==============================================================================
--- lldb/trunk/source/API/SBAddress.cpp (original)
+++ lldb/trunk/source/API/SBAddress.cpp Fri Jul 22 11:46:35 2011
@@ -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;
}
Modified: lldb/trunk/source/API/SBModule.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBModule.cpp?rev=135770&r1=135769&r2=135770&view=diff
==============================================================================
--- lldb/trunk/source/API/SBModule.cpp (original)
+++ lldb/trunk/source/API/SBModule.cpp Fri Jul 22 11:46:35 2011
@@ -228,7 +228,7 @@
SBModule::ResolveFileAddress (lldb::addr_t vm_addr, SBAddress& addr)
{
if (m_opaque_sp && addr.IsValid())
- return m_opaque_sp->ResolveFileAddress (vm_addr, *addr);
+ return m_opaque_sp->ResolveFileAddress (vm_addr, addr.ref());
if (addr.IsValid())
addr->Clear();
@@ -240,7 +240,7 @@
{
SBSymbolContext sb_sc;
if (m_opaque_sp && addr.IsValid())
- m_opaque_sp->ResolveSymbolContextForAddress (*addr, resolve_scope, *sb_sc);
+ m_opaque_sp->ResolveSymbolContextForAddress (addr.ref(), resolve_scope, *sb_sc);
return sb_sc;
}
Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=135770&r1=135769&r2=135770&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Fri Jul 22 11:46:35 2011
@@ -503,19 +503,23 @@
m_opaque_sp = target_sp;
}
-bool
-SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr,
- lldb::SBAddress& addr)
+lldb::SBAddress
+SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
{
- if (m_opaque_sp && addr.IsValid())
+ lldb::SBAddress sb_addr;
+ Address &addr = sb_addr.ref();
+ if (m_opaque_sp)
{
Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
- return m_opaque_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, *addr);
+ if (m_opaque_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr))
+ return sb_addr;
}
- if (addr.IsValid())
- addr->Clear();
- return false;
+ // We have a load address that isn't in a section, just return an address
+ // with the offset filled in (the address) and the section set to NULL
+ addr.SetSection(NULL);
+ addr.SetOffset(vm_addr);
+ return sb_addr;
}
SBSymbolContext
@@ -523,7 +527,7 @@
{
SBSymbolContext sc;
if (m_opaque_sp && addr.IsValid())
- m_opaque_sp->GetImages().ResolveSymbolContextForAddress (*addr, resolve_scope, sc.ref());
+ m_opaque_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
return sc;
}
Modified: lldb/trunk/test/python_api/default-constructor/sb_target.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/default-constructor/sb_target.py?rev=135770&r1=135769&r2=135770&view=diff
==============================================================================
--- lldb/trunk/test/python_api/default-constructor/sb_target.py (original)
+++ lldb/trunk/test/python_api/default-constructor/sb_target.py Fri Jul 22 11:46:35 2011
@@ -23,8 +23,7 @@
contextlist = lldb.SBSymbolContextList()
obj.FindFunctions("the_func", 0xff, True, contextlist)
obj.FindGlobalVariables("my_global_var", 1)
- address = lldb.SBAddress()
- obj.ResolveLoadAddress(0xffff, address)
+ address = obj.ResolveLoadAddress(0xffff)
obj.ResolveSymbolContextForAddress(address, 0)
obj.BreakpointCreateByLocation("filename", 20)
obj.BreakpointCreateByLocation(filespec, 20)
More information about the lldb-commits
mailing list