diff options
author | Greg Clayton <gclayton@apple.com> | 2012-02-24 01:59:29 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2012-02-24 01:59:29 +0000 |
commit | e72dfb321c5977c65f2d95b8b9d250b69a290b6c (patch) | |
tree | 1141c7e9afa82b440290a8b2578501deb85fb096 /lldb/source/Breakpoint | |
parent | da970541146d44d426b4306d3692cce19fae9689 (diff) | |
download | bcm5719-llvm-e72dfb321c5977c65f2d95b8b9d250b69a290b6c.tar.gz bcm5719-llvm-e72dfb321c5977c65f2d95b8b9d250b69a290b6c.zip |
<rdar://problem/10103468>
I started work on being able to add symbol files after a debug session
had started with a new "target symfile add" command and quickly ran into
problems with stale Address objects in breakpoint locations that had
lldb_private::Section pointers into modules that had been removed or
replaced. This also let to grabbing stale modules from those sections.
So I needed to thread harded the Address, Section and related objects.
To do this I modified the ModuleChild class to now require a ModuleSP
on initialization so that a weak reference can created. I also changed
all places that were handing out "Section *" to have them hand out SectionSP.
All ObjectFile, SymbolFile and SymbolVendors were inheriting from ModuleChild
so all of the find plug-in, static creation function and constructors now
require ModuleSP references instead of Module *.
Address objects now have weak references to their sections which can
safely go stale when a module gets destructed.
This checkin doesn't complete the "target symfile add" command, but it
does get us a lot clioser to being able to do such things without a high
risk of crashing or memory corruption.
llvm-svn: 151336
Diffstat (limited to 'lldb/source/Breakpoint')
-rw-r--r-- | lldb/source/Breakpoint/Breakpoint.cpp | 20 | ||||
-rw-r--r-- | lldb/source/Breakpoint/BreakpointLocationList.cpp | 32 |
2 files changed, 39 insertions, 13 deletions
diff --git a/lldb/source/Breakpoint/Breakpoint.cpp b/lldb/source/Breakpoint/Breakpoint.cpp index 5fd8f253034..4d37a7a7edd 100644 --- a/lldb/source/Breakpoint/Breakpoint.cpp +++ b/lldb/source/Breakpoint/Breakpoint.cpp @@ -351,8 +351,8 @@ Breakpoint::ModulesChanged (ModuleList &module_list, bool load) BreakpointLocationSP break_loc = m_locations.GetByIndex(loc_idx); if (!break_loc->IsEnabled()) continue; - const Section *section = break_loc->GetAddress().GetSection(); - if (section == NULL || section->GetModule() == module_sp.get()) + SectionSP section_sp (break_loc->GetAddress().GetSection()); + if (!section_sp || section_sp->GetModule() == module_sp) { if (!seen) seen = true; @@ -419,23 +419,25 @@ Breakpoint::ModulesChanged (ModuleList &module_list, bool load) ModuleSP module_sp (module_list.GetModuleAtIndex (i)); if (m_filter_sp->ModulePasses (module_sp)) { - const size_t num_locs = m_locations.GetSize(); - for (size_t loc_idx = 0; loc_idx < num_locs; ++loc_idx) + size_t loc_idx = 0; + while (loc_idx < m_locations.GetSize()) { - BreakpointLocationSP break_loc = m_locations.GetByIndex(loc_idx); - const Section *section = break_loc->GetAddress().GetSection(); - if (section && section->GetModule() == module_sp.get()) + BreakpointLocationSP break_loc_sp (m_locations.GetByIndex(loc_idx)); + SectionSP section_sp (break_loc_sp->GetAddress().GetSection()); + if (section_sp && section_sp->GetModule() == module_sp) { // Remove this breakpoint since the shared library is // unloaded, but keep the breakpoint location around // so we always get complete hit count and breakpoint // lifetime info - break_loc->ClearBreakpointSite(); + break_loc_sp->ClearBreakpointSite(); if (removed_locations_event) { - removed_locations_event->GetBreakpointLocationCollection().Add(break_loc); + removed_locations_event->GetBreakpointLocationCollection().Add(break_loc_sp); } + //m_locations.RemoveLocation (break_loc_sp); } + ++loc_idx; } } } diff --git a/lldb/source/Breakpoint/BreakpointLocationList.cpp b/lldb/source/Breakpoint/BreakpointLocationList.cpp index ac98b9a8f78..7fc4d81e283 100644 --- a/lldb/source/Breakpoint/BreakpointLocationList.cpp +++ b/lldb/source/Breakpoint/BreakpointLocationList.cpp @@ -25,7 +25,8 @@ BreakpointLocationList::BreakpointLocationList(Breakpoint &owner) : m_address_to_location (), m_mutex (Mutex::eMutexTypeRecursive), m_new_location_recorder (NULL), - m_owner (owner) + m_owner (owner), + m_next_id (0) { } @@ -38,7 +39,7 @@ BreakpointLocationList::Create (const Address &addr) { Mutex::Locker locker (m_mutex); // The location ID is just the size of the location list + 1 - lldb::break_id_t bp_loc_id = m_locations.size() + 1; + lldb::break_id_t bp_loc_id = ++m_next_id; BreakpointLocationSP bp_loc_sp (new BreakpointLocation (bp_loc_id, m_owner, addr)); m_locations.push_back (bp_loc_sp); m_address_to_location[addr] = bp_loc_sp; @@ -98,8 +99,8 @@ BreakpointLocationList::FindInModule (Module *module, for (pos = m_locations.begin(); pos != end; ++pos) { BreakpointLocationSP break_loc = (*pos); - const Section *section = break_loc->GetAddress().GetSection(); - if (section && section->GetModule() == module) + SectionSP section_sp (break_loc->GetAddress().GetSection()); + if (section_sp && section_sp->GetModule().get() == module) { bp_loc_list.Add (break_loc); } @@ -245,6 +246,29 @@ BreakpointLocationList::AddLocation (const Address &addr, bool *new_location) return bp_loc_sp; } +bool +BreakpointLocationList::RemoveLocation (const lldb::BreakpointLocationSP &bp_loc_sp) +{ + if (bp_loc_sp) + { + Mutex::Locker locker (m_mutex); + + m_address_to_location.erase (bp_loc_sp->GetAddress()); + + collection::iterator pos, end = m_locations.end(); + for (pos = m_locations.begin(); pos != end; ++pos) + { + if ((*pos).get() == bp_loc_sp.get()) + { + m_locations.erase (pos); + return true; + } + } + } + return false; +} + + void BreakpointLocationList::StartRecordingNewLocations (BreakpointLocationCollection &new_locations) |