2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
5 #ifndef BREAKPOINT_MANAGER_H
6 #define BREAKPOINT_MANAGER_H
8 #include <util/DoublyLinkedList.h>
9 #include <util/SplayTree.h>
11 #include <arch/user_debugger.h>
15 struct BreakpointManager
{
22 status_t
InstallBreakpoint(void* address
);
23 status_t
UninstallBreakpoint(void* address
);
25 status_t
InstallWatchpoint(void* address
, uint32 type
,
27 status_t
UninstallWatchpoint(void* address
);
29 void RemoveAllBreakpoints();
30 // break- and watchpoints
32 static bool CanAccessAddress(const void* address
,
34 status_t
ReadMemory(const void* _address
, void* _buffer
,
35 size_t size
, size_t& bytesRead
);
36 status_t
WriteMemory(void* _address
, const void* _buffer
,
37 size_t size
, size_t& bytesWritten
);
39 void PrepareToContinue(void* address
);
42 struct InstalledBreakpoint
;
44 struct Breakpoint
: DoublyLinkedListLinkImpl
<Breakpoint
> {
46 InstalledBreakpoint
* installedBreakpoint
;
50 DEBUG_SOFTWARE_BREAKPOINT_SIZE
];
53 typedef DoublyLinkedList
<Breakpoint
> BreakpointList
;
55 struct InstalledBreakpoint
: SplayTreeLink
<InstalledBreakpoint
> {
56 InstalledBreakpoint
* splayNext
;
57 Breakpoint
* breakpoint
;
60 InstalledBreakpoint(addr_t address
);
63 struct InstalledWatchpoint
64 : DoublyLinkedListLinkImpl
<InstalledWatchpoint
> {
66 #if DEBUG_SHARED_BREAK_AND_WATCHPOINTS
67 Breakpoint
* breakpoint
;
71 typedef DoublyLinkedList
<InstalledWatchpoint
>
72 InstalledWatchpointList
;
74 struct InstalledBreakpointSplayDefinition
{
75 typedef addr_t KeyType
;
76 typedef InstalledBreakpoint NodeType
;
78 static const KeyType
& GetKey(const InstalledBreakpoint
* node
)
83 static SplayTreeLink
<NodeType
>* GetLink(
84 InstalledBreakpoint
* node
)
89 static int Compare(addr_t key
, const InstalledBreakpoint
* node
)
91 if (key
< node
->address
)
93 return key
== node
->address
? 0 : 1;
96 // for IteratableSplayTree only
97 static NodeType
** GetListLink(InstalledBreakpoint
* node
)
99 return &node
->splayNext
;
103 typedef IteratableSplayTree
<InstalledBreakpointSplayDefinition
>
107 Breakpoint
* _GetUnusedHardwareBreakpoint(bool force
);
109 status_t
_InstallSoftwareBreakpoint(
110 InstalledBreakpoint
* installed
,
112 status_t
_UninstallSoftwareBreakpoint(
113 Breakpoint
* breakpoint
);
115 status_t
_InstallHardwareBreakpoint(
116 Breakpoint
* breakpoint
, addr_t address
);
117 status_t
_UninstallHardwareBreakpoint(
118 Breakpoint
* breakpoint
);
120 InstalledWatchpoint
* _FindWatchpoint(addr_t address
) const;
121 status_t
_InstallWatchpoint(
122 InstalledWatchpoint
* watchpoint
,
123 addr_t address
, uint32 type
, int32 length
);
124 status_t
_UninstallWatchpoint(
125 InstalledWatchpoint
* watchpoint
);
127 status_t
_ReadMemory(const addr_t _address
,
128 void* _buffer
, size_t size
,
130 status_t
_WriteMemory(addr_t _address
,
131 const void* _buffer
, size_t size
,
132 size_t& bytesWritten
);
136 BreakpointList fHardwareBreakpoints
;
137 BreakpointTree fBreakpoints
;
138 InstalledWatchpointList fWatchpoints
;
139 int32 fBreakpointCount
;
140 int32 fWatchpointCount
;
144 #endif // BREAKPOINT_MANAGER_H