UserBreakpoint.h revision fce4895d
1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2013-2014, Rene Gollent, rene@gollent.com.
4 * Distributed under the terms of the MIT License.
5 */
6#ifndef USER_BREAKPOINT_H
7#define USER_BREAKPOINT_H
8
9
10#include <ObjectList.h>
11#include <Referenceable.h>
12#include <util/DoublyLinkedList.h>
13
14#include "SourceLocation.h"
15#include "String.h"
16#include "Types.h"
17
18
19class Breakpoint;
20class Function;
21class FunctionID;
22class LocatableFile;
23class UserBreakpoint;
24
25
26class UserBreakpointLocation {
27public:
28								UserBreakpointLocation(FunctionID* functionID,
29									LocatableFile* sourceFile,
30									const SourceLocation& sourceLocation,
31									target_addr_t relativeAddress);
32								UserBreakpointLocation(
33									const UserBreakpointLocation& other);
34	virtual						~UserBreakpointLocation();
35
36			FunctionID*			GetFunctionID() const	{ return fFunctionID; }
37			LocatableFile*		SourceFile() const		{ return fSourceFile; }
38			SourceLocation		GetSourceLocation() const
39									{ return fSourceLocation; }
40			target_addr_t		RelativeAddress() const
41									{ return fRelativeAddress; }
42
43			UserBreakpointLocation& operator=(
44									const UserBreakpointLocation& other);
45
46private:
47			FunctionID*			fFunctionID;
48			LocatableFile*		fSourceFile;
49			SourceLocation		fSourceLocation;
50			target_addr_t		fRelativeAddress;
51};
52
53
54class UserBreakpointInstance
55	: public DoublyLinkedListLinkImpl<UserBreakpointInstance> {
56public:
57								UserBreakpointInstance(
58									UserBreakpoint* userBreakpoint,
59									target_addr_t address);
60
61			UserBreakpoint*		GetUserBreakpoint() const
62									{ return fUserBreakpoint; }
63			target_addr_t		Address() const	{ return fAddress; }
64
65			Breakpoint*			GetBreakpoint() const	{ return fBreakpoint; }
66			void				SetBreakpoint(Breakpoint* breakpoint);
67
68private:
69			target_addr_t		fAddress;
70			UserBreakpoint*		fUserBreakpoint;
71			Breakpoint*			fBreakpoint;
72};
73
74
75typedef DoublyLinkedList<UserBreakpointInstance> UserBreakpointInstanceList;
76
77
78class UserBreakpoint : public BReferenceable,
79	public DoublyLinkedListLinkImpl<UserBreakpoint> {
80public:
81								UserBreakpoint(
82									const UserBreakpointLocation& location);
83								~UserBreakpoint();
84
85			const UserBreakpointLocation& Location() const { return fLocation; }
86
87			int32				CountInstances() const;
88			UserBreakpointInstance* InstanceAt(int32 index) const;
89
90			// Note: After known to the BreakpointManager, those can only be
91			// invoked with the breakpoint manager lock held.
92			bool				AddInstance(UserBreakpointInstance* instance);
93			void				RemoveInstance(
94									UserBreakpointInstance* instance);
95			UserBreakpointInstance* RemoveInstanceAt(int32 index);
96
97			bool				IsValid() const		{ return fValid; }
98			void				SetValid(bool valid);
99									// BreakpointManager only
100
101			bool				IsEnabled() const	{ return fEnabled; }
102			void				SetEnabled(bool enabled);
103									// BreakpointManager only
104
105			bool				IsHidden() const	{ return fHidden; }
106			void				SetHidden(bool hidden);
107
108			bool				HasCondition() const
109									{ return !fConditionExpression.IsEmpty(); }
110			const BString&		Condition() const
111									{ return fConditionExpression; }
112			void				SetCondition(
113									const BString& conditionExpression);
114
115private:
116			typedef BObjectList<UserBreakpointInstance> InstanceList;
117
118private:
119			UserBreakpointLocation fLocation;
120			InstanceList		fInstances;
121			bool				fValid;
122			bool				fEnabled;
123			bool				fHidden;
124			BString				fConditionExpression;
125};
126
127
128typedef DoublyLinkedList<UserBreakpoint> UserBreakpointList;
129
130
131#endif	// USER_BREAKPOINT_H
132