llvm-project/lldb/source/Breakpoint/BreakpointSiteList.cpp

241 lines
6.9 KiB
C++
Raw Normal View History

//===-- BreakpointSiteList.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/Breakpoint/BreakpointSiteList.h"
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "lldb/Core/Stream.h"
2010-06-09 15:47:43 +08:00
#include <algorithm>
using namespace lldb;
using namespace lldb_private;
BreakpointSiteList::BreakpointSiteList() :
m_mutex (Mutex::eMutexTypeRecursive),
m_bp_site_list()
{
}
BreakpointSiteList::~BreakpointSiteList()
{
}
// Add breakpoint site to the list. However, if the element already exists in the
// list, then we don't add it, and return LLDB_INVALID_BREAK_ID.
lldb::break_id_t
BreakpointSiteList::Add(const BreakpointSiteSP &bp)
{
lldb::addr_t bp_site_load_addr = bp->GetLoadAddress();
Mutex::Locker locker(m_mutex);
collection::iterator iter = m_bp_site_list.find (bp_site_load_addr);
if (iter == m_bp_site_list.end())
{
m_bp_site_list.insert (iter, collection::value_type (bp_site_load_addr, bp));
return bp->GetID();
}
else
{
return LLDB_INVALID_BREAK_ID;
}
}
bool
Abtracted the old "lldb_private::Thread::StopInfo" into an abtract class. This will allow debugger plug-ins to make any instance of "lldb_private::StopInfo" that can completely describe any stop reason. It also provides a framework for doing intelligent things with the stop info at important times in the lifetime of the inferior. Examples include the signal stop info in StopInfoUnixSignal. It will check with the process to see that the current action is for the signal. These actions include wether to stop for the signal, wether the notify that the signal was hit, and wether to pass the signal along to the inferior process. The StopInfoUnixSignal class overrides the "ShouldStop()" method of StopInfo and this allows the stop info to determine if it should stop at the signal or continue the process. StopInfo subclasses must override the following functions: virtual lldb::StopReason GetStopReason () const = 0; virtual const char * GetDescription () = 0; StopInfo subclasses can override the following functions: // If the subclass returns "false", the inferior will resume. The default // version of this function returns "true" which means the default stop // info will stop the process. The breakpoint subclass will check if // the breakpoint wants us to stop by calling any installed callback on // the breakpoint, and also checking if the breakpoint is for the current // thread. Signals will check if they should stop based off of the // UnixSignal settings in the process. virtual bool ShouldStop (Event *event_ptr); // Sublasses can state if they want to notify the debugger when "ShouldStop" // returns false. This would be handy for breakpoints where you want to // log information and continue and is also used by the signal stop info // to notify that a signal was received (after it checks with the process // signal settings). virtual bool ShouldNotify (Event *event_ptr) { return false; } // Allow subclasses to do something intelligent right before we resume. // The signal class will figure out if the signal should be propagated // to the inferior process and pass that along to the debugger plug-ins. virtual void WillResume (lldb::StateType resume_state) { // By default, don't do anything } The support the Mach exceptions was moved into the lldb/source/Plugins/Process/Utility folder and now doesn't polute the lldb_private::Thread class with platform specific code. llvm-svn: 110184
2010-08-04 09:40:35 +08:00
BreakpointSiteList::ShouldStop (StoppointCallbackContext *context, lldb::break_id_t site_id)
{
Abtracted the old "lldb_private::Thread::StopInfo" into an abtract class. This will allow debugger plug-ins to make any instance of "lldb_private::StopInfo" that can completely describe any stop reason. It also provides a framework for doing intelligent things with the stop info at important times in the lifetime of the inferior. Examples include the signal stop info in StopInfoUnixSignal. It will check with the process to see that the current action is for the signal. These actions include wether to stop for the signal, wether the notify that the signal was hit, and wether to pass the signal along to the inferior process. The StopInfoUnixSignal class overrides the "ShouldStop()" method of StopInfo and this allows the stop info to determine if it should stop at the signal or continue the process. StopInfo subclasses must override the following functions: virtual lldb::StopReason GetStopReason () const = 0; virtual const char * GetDescription () = 0; StopInfo subclasses can override the following functions: // If the subclass returns "false", the inferior will resume. The default // version of this function returns "true" which means the default stop // info will stop the process. The breakpoint subclass will check if // the breakpoint wants us to stop by calling any installed callback on // the breakpoint, and also checking if the breakpoint is for the current // thread. Signals will check if they should stop based off of the // UnixSignal settings in the process. virtual bool ShouldStop (Event *event_ptr); // Sublasses can state if they want to notify the debugger when "ShouldStop" // returns false. This would be handy for breakpoints where you want to // log information and continue and is also used by the signal stop info // to notify that a signal was received (after it checks with the process // signal settings). virtual bool ShouldNotify (Event *event_ptr) { return false; } // Allow subclasses to do something intelligent right before we resume. // The signal class will figure out if the signal should be propagated // to the inferior process and pass that along to the debugger plug-ins. virtual void WillResume (lldb::StateType resume_state) { // By default, don't do anything } The support the Mach exceptions was moved into the lldb/source/Plugins/Process/Utility folder and now doesn't polute the lldb_private::Thread class with platform specific code. llvm-svn: 110184
2010-08-04 09:40:35 +08:00
BreakpointSiteSP site_sp (FindByID (site_id));
if (site_sp)
{
// Let the BreakpointSite decide if it should stop here (could not have
// reached it's target hit count yet, or it could have a callback
// that decided it shouldn't stop (shared library loads/unloads).
Abtracted the old "lldb_private::Thread::StopInfo" into an abtract class. This will allow debugger plug-ins to make any instance of "lldb_private::StopInfo" that can completely describe any stop reason. It also provides a framework for doing intelligent things with the stop info at important times in the lifetime of the inferior. Examples include the signal stop info in StopInfoUnixSignal. It will check with the process to see that the current action is for the signal. These actions include wether to stop for the signal, wether the notify that the signal was hit, and wether to pass the signal along to the inferior process. The StopInfoUnixSignal class overrides the "ShouldStop()" method of StopInfo and this allows the stop info to determine if it should stop at the signal or continue the process. StopInfo subclasses must override the following functions: virtual lldb::StopReason GetStopReason () const = 0; virtual const char * GetDescription () = 0; StopInfo subclasses can override the following functions: // If the subclass returns "false", the inferior will resume. The default // version of this function returns "true" which means the default stop // info will stop the process. The breakpoint subclass will check if // the breakpoint wants us to stop by calling any installed callback on // the breakpoint, and also checking if the breakpoint is for the current // thread. Signals will check if they should stop based off of the // UnixSignal settings in the process. virtual bool ShouldStop (Event *event_ptr); // Sublasses can state if they want to notify the debugger when "ShouldStop" // returns false. This would be handy for breakpoints where you want to // log information and continue and is also used by the signal stop info // to notify that a signal was received (after it checks with the process // signal settings). virtual bool ShouldNotify (Event *event_ptr) { return false; } // Allow subclasses to do something intelligent right before we resume. // The signal class will figure out if the signal should be propagated // to the inferior process and pass that along to the debugger plug-ins. virtual void WillResume (lldb::StateType resume_state) { // By default, don't do anything } The support the Mach exceptions was moved into the lldb/source/Plugins/Process/Utility folder and now doesn't polute the lldb_private::Thread class with platform specific code. llvm-svn: 110184
2010-08-04 09:40:35 +08:00
return site_sp->ShouldStop (context);
}
// We should stop here since this BreakpointSite isn't valid anymore or it
// doesn't exist.
return true;
}
lldb::break_id_t
BreakpointSiteList::FindIDByAddress (lldb::addr_t addr)
{
BreakpointSiteSP bp = FindByAddress (addr);
if (bp)
{
//DBLogIf(PD_LOG_BREAKPOINTS, "BreakpointSiteList::%s ( addr = 0x%8.8" PRIx64 " ) => %u", __FUNCTION__, (uint64_t)addr, bp->GetID());
return bp.get()->GetID();
}
//DBLogIf(PD_LOG_BREAKPOINTS, "BreakpointSiteList::%s ( addr = 0x%8.8" PRIx64 " ) => NONE", __FUNCTION__, (uint64_t)addr);
return LLDB_INVALID_BREAK_ID;
}
bool
BreakpointSiteList::Remove (lldb::break_id_t break_id)
{
Mutex::Locker locker(m_mutex);
collection::iterator pos = GetIDIterator(break_id); // Predicate
if (pos != m_bp_site_list.end())
{
m_bp_site_list.erase(pos);
return true;
}
return false;
}
bool
BreakpointSiteList::RemoveByAddress (lldb::addr_t address)
{
Mutex::Locker locker(m_mutex);
collection::iterator pos = m_bp_site_list.find(address);
if (pos != m_bp_site_list.end())
{
m_bp_site_list.erase(pos);
return true;
}
return false;
}
class BreakpointSiteIDMatches
{
public:
BreakpointSiteIDMatches (lldb::break_id_t break_id) :
m_break_id(break_id)
{
}
bool operator() (std::pair <lldb::addr_t, BreakpointSiteSP> val_pair) const
{
return m_break_id == val_pair.second.get()->GetID();
}
private:
const lldb::break_id_t m_break_id;
};
BreakpointSiteList::collection::iterator
BreakpointSiteList::GetIDIterator (lldb::break_id_t break_id)
{
Mutex::Locker locker(m_mutex);
return std::find_if(m_bp_site_list.begin(), m_bp_site_list.end(), // Search full range
BreakpointSiteIDMatches(break_id)); // Predicate
}
BreakpointSiteList::collection::const_iterator
BreakpointSiteList::GetIDConstIterator (lldb::break_id_t break_id) const
{
Mutex::Locker locker(m_mutex);
return std::find_if(m_bp_site_list.begin(), m_bp_site_list.end(), // Search full range
BreakpointSiteIDMatches(break_id)); // Predicate
}
BreakpointSiteSP
BreakpointSiteList::FindByID (lldb::break_id_t break_id)
{
Mutex::Locker locker(m_mutex);
BreakpointSiteSP stop_sp;
collection::iterator pos = GetIDIterator(break_id);
if (pos != m_bp_site_list.end())
stop_sp = pos->second;
return stop_sp;
}
const BreakpointSiteSP
BreakpointSiteList::FindByID (lldb::break_id_t break_id) const
{
Mutex::Locker locker(m_mutex);
BreakpointSiteSP stop_sp;
collection::const_iterator pos = GetIDConstIterator(break_id);
if (pos != m_bp_site_list.end())
stop_sp = pos->second;
return stop_sp;
}
BreakpointSiteSP
BreakpointSiteList::FindByAddress (lldb::addr_t addr)
{
BreakpointSiteSP found_sp;
Mutex::Locker locker(m_mutex);
collection::iterator iter = m_bp_site_list.find(addr);
if (iter != m_bp_site_list.end())
found_sp = iter->second;
return found_sp;
}
bool
BreakpointSiteList::BreakpointSiteContainsBreakpoint (lldb::break_id_t bp_site_id, lldb::break_id_t bp_id)
{
Mutex::Locker locker(m_mutex);
collection::const_iterator pos = GetIDConstIterator(bp_site_id);
if (pos != m_bp_site_list.end())
return pos->second->IsBreakpointAtThisSite (bp_id);
return false;
}
void
BreakpointSiteList::Dump (Stream *s) const
{
s->Printf("%p: ", this);
Added more platform support. There are now some new commands: platform status -- gets status information for the selected platform platform create <platform-name> -- creates a new instance of a remote platform platform list -- list all available platforms platform select -- select a platform instance as the current platform (not working yet) When using "platform create" it will create a remote platform and make it the selected platform. For instances for iPhone OS debugging on Mac OS X one can do: (lldb) platform create remote-ios --sdk-version=4.0 Remote platform: iOS platform SDK version: 4.0 SDK path: "/Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.0" Not connected to a remote device. (lldb) file ~/Documents/a.out Current executable set to '~/Documents/a.out' (armv6). (lldb) image list [ 0] /Volumes/work/gclayton/Documents/devb/attach/a.out [ 1] /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.0/Symbols/usr/lib/dyld [ 2] /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.0/Symbols/usr/lib/libSystem.B.dylib Note that this is all happening prior to running _or_ connecting to a remote platform. Once connected to a remote platform the OS version might change which means we will need to update our dependecies. Also once we run, we will need to match up the actualy binaries with the actualy UUID's to files in the SDK, or download and cache them locally. This is just the start of the remote platforms, but this modification is the first iteration in getting the platforms really doing something. llvm-svn: 127934
2011-03-19 09:12:21 +08:00
//s->Indent();
s->Printf("BreakpointSiteList with %u BreakpointSites:\n", (uint32_t)m_bp_site_list.size());
s->IndentMore();
collection::const_iterator pos;
collection::const_iterator end = m_bp_site_list.end();
for (pos = m_bp_site_list.begin(); pos != end; ++pos)
pos->second.get()->Dump(s);
s->IndentLess();
}
void
BreakpointSiteList::ForEach (std::function <void(BreakpointSite *)> const &callback)
{
Mutex::Locker locker(m_mutex);
for (auto pair : m_bp_site_list)
callback (pair.second.get());
}
bool
BreakpointSiteList::FindInRange (lldb::addr_t lower_bound, lldb::addr_t upper_bound, BreakpointSiteList &bp_site_list) const
{
if (lower_bound > upper_bound)
return false;
Mutex::Locker locker(m_mutex);
collection::const_iterator lower, upper, pos;
lower = m_bp_site_list.lower_bound(lower_bound);
if (lower == m_bp_site_list.end()
|| (*lower).first >= upper_bound)
return false;
// This is one tricky bit. The breakpoint might overlap the bottom end of the range. So we grab the
// breakpoint prior to the lower bound, and check that that + its byte size isn't in our range.
if (lower != m_bp_site_list.begin())
{
collection::const_iterator prev_pos = lower;
prev_pos--;
const BreakpointSiteSP &prev_bp = (*prev_pos).second;
if (prev_bp->GetLoadAddress() + prev_bp->GetByteSize() > lower_bound)
bp_site_list.Add (prev_bp);
}
upper = m_bp_site_list.upper_bound(upper_bound);
for (pos = lower; pos != upper; pos++)
{
bp_site_list.Add ((*pos).second);
}
return true;
}