2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2013-2016, Rene Gollent, rene@gollent.com.
4 * Distributed under the terms of the MIT License.
6 #ifndef TEAM_DEBUGGER_H
7 #define TEAM_DEBUGGER_H
14 #include "TeamSettings.h"
15 #include "ThreadHandler.h"
16 #include "UserInterface.h"
17 #include "util/Worker.h"
21 class DebuggerInterface
;
22 class DebugReportGenerator
;
24 class ImageCreatedEvent
;
25 class ImageDebugInfoLoadingState
;
26 class ImageDeletedEvent
;
27 class PostSyscallEvent
;
28 class SettingsManager
;
30 class TeamDeletedEvent
;
32 class TeamMemoryBlockManager
;
34 class ThreadCreatedEvent
;
35 class ThreadDeletedEvent
;
36 class ThreadRenamedEvent
;
37 class ThreadPriorityChangedEvent
;
38 class WatchpointManager
;
41 class TeamDebugger
: public BLooper
, private UserInterfaceListener
,
42 private JobListener
, private Team::Listener
{
47 TeamDebugger(Listener
* listener
,
48 UserInterface
* userInterface
,
49 SettingsManager
* settingsManager
);
52 status_t
Init(DebuggerInterface
* interface
,
53 thread_id threadID
, int argc
,
54 const char* const* argv
,
59 team_id
TeamID() const { return fTeamID
; }
61 bool IsPostMortem() const { return fIsPostMortem
; }
63 int ArgumentCount() const
64 { return fCommandLineArgc
; }
65 const char** Arguments() const
66 { return fCommandLineArgv
; }
67 SettingsManager
* GetSettingsManager() const
68 { return fSettingsManager
; }
70 virtual void MessageReceived(BMessage
* message
);
73 // UserInterfaceListener
74 virtual void FunctionSourceCodeRequested(
75 FunctionInstance
* function
,
76 bool forceDisassembly
= false);
77 virtual void SourceEntryLocateRequested(
78 const char* sourcePath
,
79 const char* locatedPath
);
80 virtual void SourceEntryInvalidateRequested(
81 LocatableFile
* sourceFile
);
82 virtual void ImageDebugInfoRequested(Image
* image
);
83 virtual void ValueNodeValueRequested(CpuState
* cpuState
,
84 ValueNodeContainer
* container
,
85 ValueNode
* valueNode
);
86 virtual void ValueNodeWriteRequested(ValueNode
* node
,
89 virtual void ThreadActionRequested(thread_id threadID
,
90 uint32 action
, target_addr_t address
);
92 virtual void SetBreakpointRequested(target_addr_t address
,
93 bool enabled
, bool hidden
= false);
94 virtual void SetBreakpointEnabledRequested(
95 UserBreakpoint
* breakpoint
,
97 virtual void SetBreakpointConditionRequested(
98 UserBreakpoint
* breakpoint
,
99 const char* condition
);
100 virtual void ClearBreakpointConditionRequested(
101 UserBreakpoint
* breakpoint
);
102 virtual void ClearBreakpointRequested(target_addr_t address
);
103 virtual void ClearBreakpointRequested(
104 UserBreakpoint
* breakpoint
);
106 virtual void SetStopOnImageLoadRequested(bool enabled
,
108 virtual void AddStopImageNameRequested(
110 virtual void RemoveStopImageNameRequested(
113 virtual void SetDefaultSignalDispositionRequested(
115 virtual void SetCustomSignalDispositionRequested(
116 int32 signal
, int32 disposition
);
117 virtual void RemoveCustomSignalDispositionRequested(
120 virtual void SetWatchpointRequested(target_addr_t address
,
121 uint32 type
, int32 length
, bool enabled
);
122 virtual void SetWatchpointEnabledRequested(
123 Watchpoint
*watchpoint
, bool enabled
);
124 virtual void ClearWatchpointRequested(target_addr_t address
);
125 virtual void ClearWatchpointRequested(
126 Watchpoint
* breakpoint
);
128 virtual void InspectRequested(target_addr_t address
,
129 TeamMemoryBlock::Listener
* listener
);
130 virtual void MemoryWriteRequested(target_addr_t address
,
131 const void* data
, target_size_t size
);
133 virtual void ExpressionEvaluationRequested(
134 SourceLanguage
* language
,
135 ExpressionInfo
* info
,
136 StackFrame
* frame
= NULL
,
137 ::Thread
* thread
= NULL
);
139 virtual void DebugReportRequested(entry_ref
* targetPath
);
141 virtual void WriteCoreFileRequested(entry_ref
* targetPath
);
143 virtual void TeamRestartRequested();
145 virtual bool UserInterfaceQuitRequested(
146 QuitOption quitOption
);
149 virtual void JobStarted(Job
* job
);
150 virtual void JobDone(Job
* job
);
151 virtual void JobWaitingForInput(Job
* job
);
152 virtual void JobFailed(Job
* job
);
153 virtual void JobAborted(Job
* job
);
156 virtual void ThreadStateChanged(
157 const ::Team::ThreadEvent
& event
);
158 virtual void ThreadCpuStateChanged(
159 const ::Team::ThreadEvent
& event
);
160 virtual void ThreadStackTraceChanged(
161 const ::Team::ThreadEvent
& event
);
162 virtual void ImageDebugInfoChanged(
163 const ::Team::ImageEvent
& event
);
167 struct ImageHandlerHashDefinition
;
168 struct ImageInfoPendingThread
;
169 struct ImageInfoPendingThreadHashDefinition
;
171 typedef BOpenHashTable
<ImageHandlerHashDefinition
> ImageHandlerTable
;
172 typedef BOpenHashTable
<ImageInfoPendingThreadHashDefinition
>
173 ImageInfoPendingThreadTable
;
176 static status_t
_DebugEventListenerEntry(void* data
);
177 status_t
_DebugEventListener();
179 void _HandleDebuggerMessage(DebugEvent
* event
);
181 bool _HandleTeamDeleted(
182 TeamDeletedEvent
* event
);
183 bool _HandleThreadCreated(
184 ThreadCreatedEvent
* event
);
185 bool _HandleThreadRenamed(
186 ThreadRenamedEvent
* event
);
187 bool _HandleThreadPriorityChanged(
188 ThreadPriorityChangedEvent
* event
);
189 bool _HandleThreadDeleted(
190 ThreadDeletedEvent
* event
);
191 bool _HandleImageCreated(
192 ImageCreatedEvent
* event
);
193 bool _HandleImageDeleted(
194 ImageDeletedEvent
* event
);
195 bool _HandlePostSyscall(
196 PostSyscallEvent
* event
);
198 void _PrepareForTeamExec(TeamExecEvent
* event
);
200 void _HandleImageDebugInfoChanged(image_id imageID
);
201 void _HandleImageFileChanged(image_id imageID
);
203 void _HandleSetUserBreakpoint(target_addr_t address
,
204 bool enabled
, bool hidden
);
205 void _HandleSetUserBreakpoint(
206 UserBreakpoint
* breakpoint
, bool enabled
);
207 void _HandleClearUserBreakpoint(
208 target_addr_t address
);
209 void _HandleClearUserBreakpoint(
210 UserBreakpoint
* breakpoint
);
212 void _HandleSetWatchpoint(target_addr_t address
,
213 uint32 type
, int32 length
, bool enabled
);
214 void _HandleSetWatchpoint(
215 Watchpoint
* watchpoint
, bool enabled
);
216 void _HandleClearWatchpoint( target_addr_t address
);
217 void _HandleClearWatchpoint(Watchpoint
* watchpoint
);
219 void _HandleInspectAddress(
220 target_addr_t address
,
221 TeamMemoryBlock::Listener
* listener
);
222 void _HandleWriteMemory(
223 target_addr_t address
, void* data
,
226 void _HandleEvaluateExpression(
227 SourceLanguage
* language
,
228 ExpressionInfo
* info
,
232 void _HandleWriteCoreFile(const entry_ref
& ref
);
234 status_t
_HandleSetArguments(int argc
,
235 const char* const* argv
);
237 void _HandleDebugInfoJobUserInput(
238 ImageDebugInfoLoadingState
* state
);
240 ThreadHandler
* _GetThreadHandler(thread_id threadID
);
242 status_t
_AddImage(const ImageInfo
& imageInfo
,
243 Image
** _image
= NULL
);
245 void _LoadSettings();
246 void _SaveSettings();
248 void _NotifyUser(const char* title
,
249 const char* text
,...);
251 void _ResetUserBackgroundStatusIfNeeded();
252 // updates user interface to
253 // ready/completed message
254 // for background work status
258 SettingsManager
* fSettingsManager
;
262 ThreadHandlerTable fThreadHandlers
;
263 // protected by the team lock
264 ImageHandlerTable
* fImageHandlers
;
265 ImageInfoPendingThreadTable
* fImageInfoPendingThreads
;
266 DebuggerInterface
* fDebuggerInterface
;
267 TeamDebugInfo
* fTeamDebugInfo
;
268 FileManager
* fFileManager
;
270 BreakpointManager
* fBreakpointManager
;
271 WatchpointManager
* fWatchpointManager
;
272 TeamMemoryBlockManager
*
274 DebugReportGenerator
*
276 thread_id fDebugEventListener
;
277 UserInterface
* fUserInterface
;
278 volatile bool fTerminating
;
279 bool fKillTeamOnQuit
;
280 TeamSettings fTeamSettings
;
281 int fCommandLineArgc
;
282 const char** fCommandLineArgv
;
287 class TeamDebugger::Listener
{
291 virtual void TeamDebuggerStarted(TeamDebugger
* debugger
) = 0;
292 virtual void TeamDebuggerRestartRequested(
293 TeamDebugger
* debugger
) = 0;
294 virtual void TeamDebuggerQuit(TeamDebugger
* debugger
) = 0;
298 #endif // TEAM_DEBUGGER_H