xref: /haiku/src/kits/debugger/model/Breakpoint.cpp (revision aa3083e086e5a929c061c72983e09d916c548a38)
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 
12 BreakpointClient::~BreakpointClient()
13 {
14 }
15 
16 
17 // #pragma mark - Breakpoint
18 
19 
20 Breakpoint::Breakpoint(Image* image, target_addr_t address)
21 	:
22 	fAddress(address),
23 	fImage(image),
24 	fInstalled(false)
25 {
26 }
27 
28 
29 Breakpoint::~Breakpoint()
30 {
31 }
32 
33 
34 void
35 Breakpoint::SetInstalled(bool installed)
36 {
37 	fInstalled = installed;
38 }
39 
40 
41 bool
42 Breakpoint::ShouldBeInstalled() const
43 {
44 	if (!fClients.IsEmpty())
45 		return true;
46 
47 	return !fClients.IsEmpty() || HasEnabledUserBreakpoint();
48 }
49 
50 
51 bool
52 Breakpoint::IsUnused() const
53 {
54 	return fClients.IsEmpty() && fUserBreakpoints.IsEmpty();
55 }
56 
57 
58 bool
59 Breakpoint::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 
72 void
73 Breakpoint::AddUserBreakpoint(UserBreakpointInstance* instance)
74 {
75 	fUserBreakpoints.Add(instance);
76 }
77 
78 
79 void
80 Breakpoint::RemoveUserBreakpoint(UserBreakpointInstance* instance)
81 {
82 	fUserBreakpoints.Remove(instance);
83 }
84 
85 
86 bool
87 Breakpoint::AddClient(BreakpointClient* client)
88 {
89 	return fClients.AddItem(client);
90 }
91 
92 
93 void
94 Breakpoint::RemoveClient(BreakpointClient* client)
95 {
96 	fClients.RemoveItem(client);
97 }
98 
99 
100 /*static*/ int
101 Breakpoint::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
110 Breakpoint::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