1/* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6#include "Breakpoint.h" 7 8 9// #pragma mark - BreakpointClient 10 11 12BreakpointClient::~BreakpointClient() 13{ 14} 15 16 17// #pragma mark - Breakpoint 18 19 20Breakpoint::Breakpoint(Image* image, target_addr_t address) 21 : 22 fAddress(address), 23 fImage(image), 24 fInstalled(false) 25{ 26} 27 28 29Breakpoint::~Breakpoint() 30{ 31} 32 33 34void 35Breakpoint::SetInstalled(bool installed) 36{ 37 fInstalled = installed; 38} 39 40 41bool 42Breakpoint::ShouldBeInstalled() const 43{ 44 if (!fClients.IsEmpty()) 45 return true; 46 47 return !fClients.IsEmpty() || HasEnabledUserBreakpoint(); 48} 49 50 51bool 52Breakpoint::IsUnused() const 53{ 54 return fClients.IsEmpty() && fUserBreakpoints.IsEmpty(); 55} 56 57 58bool 59Breakpoint::HasEnabledUserBreakpoint() const 60{ 61 for (UserBreakpointInstanceList::ConstIterator it 62 = fUserBreakpoints.GetIterator(); 63 UserBreakpointInstance* instance = it.Next();) { 64 if (instance->GetUserBreakpoint()->IsEnabled()) 65 return true; 66 } 67 68 return false; 69} 70 71 72void 73Breakpoint::AddUserBreakpoint(UserBreakpointInstance* instance) 74{ 75 fUserBreakpoints.Add(instance); 76} 77 78 79void 80Breakpoint::RemoveUserBreakpoint(UserBreakpointInstance* instance) 81{ 82 fUserBreakpoints.Remove(instance); 83} 84 85 86bool 87Breakpoint::AddClient(BreakpointClient* client) 88{ 89 return fClients.AddItem(client); 90} 91 92 93void 94Breakpoint::RemoveClient(BreakpointClient* client) 95{ 96 fClients.RemoveItem(client); 97} 98 99 100/*static*/ int 101Breakpoint::CompareBreakpoints(const Breakpoint* a, const Breakpoint* b) 102{ 103 if (a->Address() < b->Address()) 104 return -1; 105 return a->Address() == b->Address() ? 0 : 1; 106} 107 108 109/*static*/ int 110Breakpoint::CompareAddressBreakpoint(const target_addr_t* address, 111 const Breakpoint* breakpoint) 112{ 113 if (*address < breakpoint->Address()) 114 return -1; 115 return *address == breakpoint->Address() ? 0 : 1; 116} 117