[Lldb-commits] [PATCH] D89358: Add an API to get an SBBreakpoint's owning SBTarget
Jim Ingham via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue Oct 13 18:47:46 PDT 2020
jingham created this revision.
jingham added a reviewer: JDevlieghere.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
jingham requested review of this revision.
Scripted breakpoint resolvers receive the breakpoint they are being set on, and the callback takes an SBSymbolContext.
Sometimes (for instance if you want to disassemble instructions) you need access to the target that owns the breakpoint. We don't include the owning target in an SBSymbolContext, which mirrors the fact that SBModules aren't owned by a single target, but live in the shared cache and might have many SBTarget owners. So you can't get it from there.
However, an SBBreakpoint is always owned by one target, so it makes sense to be able to get an SBBreakpoint's SBTarget.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D89358
Files:
lldb/bindings/interface/SBBreakpoint.i
lldb/include/lldb/API/SBBreakpoint.h
lldb/source/API/SBBreakpoint.cpp
lldb/test/API/python_api/breakpoint/TestBreakpointAPI.py
Index: lldb/test/API/python_api/breakpoint/TestBreakpointAPI.py
===================================================================
--- lldb/test/API/python_api/breakpoint/TestBreakpointAPI.py
+++ lldb/test/API/python_api/breakpoint/TestBreakpointAPI.py
@@ -66,6 +66,9 @@
location = breakpoint.GetLocationAtIndex(0)
self.assertTrue(location.IsValid())
+ # Make sure the breakpoint's target is right:
+ self.assertEqual(target, breakpoint.GetTarget(), "Breakpoint reports its target correctly")
+
self.assertTrue(self.dbg.DeleteTarget(target))
self.assertFalse(breakpoint.IsValid())
self.assertFalse(location.IsValid())
Index: lldb/source/API/SBBreakpoint.cpp
===================================================================
--- lldb/source/API/SBBreakpoint.cpp
+++ lldb/source/API/SBBreakpoint.cpp
@@ -81,6 +81,16 @@
return m_opaque_wp.lock() != rhs.m_opaque_wp.lock();
}
+SBTarget SBBreakpoint::GetTarget() const {
+ LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBTarget, SBBreakpoint, GetTarget);
+
+ BreakpointSP bkpt_sp = GetSP();
+ if (bkpt_sp)
+ return SBTarget(bkpt_sp->GetTargetSP());
+
+ return SBTarget();
+}
+
break_id_t SBBreakpoint::GetID() const {
LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::break_id_t, SBBreakpoint, GetID);
@@ -988,6 +998,7 @@
LLDB_REGISTER_METHOD(bool,
SBBreakpoint, operator!=,(const lldb::SBBreakpoint &));
LLDB_REGISTER_METHOD_CONST(lldb::break_id_t, SBBreakpoint, GetID, ());
+ LLDB_REGISTER_METHOD_CONST(lldb::SBTarget, SBBreakpoint, GetTarget, ());
LLDB_REGISTER_METHOD_CONST(bool, SBBreakpoint, IsValid, ());
LLDB_REGISTER_METHOD_CONST(bool, SBBreakpoint, operator bool, ());
LLDB_REGISTER_METHOD(void, SBBreakpoint, ClearAllBreakpointSites, ());
Index: lldb/include/lldb/API/SBBreakpoint.h
===================================================================
--- lldb/include/lldb/API/SBBreakpoint.h
+++ lldb/include/lldb/API/SBBreakpoint.h
@@ -42,6 +42,8 @@
void ClearAllBreakpointSites();
+ lldb::SBTarget GetTarget() const;
+
lldb::SBBreakpointLocation FindLocationByAddress(lldb::addr_t vm_addr);
lldb::break_id_t FindLocationIDByAddress(lldb::addr_t vm_addr);
Index: lldb/bindings/interface/SBBreakpoint.i
===================================================================
--- lldb/bindings/interface/SBBreakpoint.i
+++ lldb/bindings/interface/SBBreakpoint.i
@@ -100,6 +100,9 @@
void
ClearAllBreakpointSites ();
+ lldb::SBTarget
+ GetTarget() const;
+
lldb::SBBreakpointLocation
FindLocationByAddress (lldb::addr_t vm_addr);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89358.298007.patch
Type: text/x-patch
Size: 2640 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20201014/e7349010/attachment.bin>
More information about the lldb-commits
mailing list