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
13 #include <debug_support.h>
15 #include "DebugEvent.h"
18 #include "TeamSettings.h"
19 #include "ThreadHandler.h"
20 #include "UserInterface.h"
24 class DebuggerInterface
;
25 class DebugReportGenerator
;
27 class SettingsManager
;
29 class TeamMemoryBlockManager
;
31 class WatchpointManager
;
34 class TeamDebugger
: public BLooper
, private UserInterfaceListener
,
35 private JobListener
, private Team::Listener
{
40 TeamDebugger(Listener
* listener
,
41 UserInterface
* userInterface
,
42 SettingsManager
* settingsManager
);
45 status_t
Init(DebuggerInterface
* interface
,
46 thread_id threadID
, int argc
,
47 const char* const* argv
,
52 team_id
TeamID() const { return fTeamID
; }
54 bool IsPostMortem() const { return fIsPostMortem
; }
56 int ArgumentCount() const
57 { return fCommandLineArgc
; }
58 const char** Arguments() const
59 { return fCommandLineArgv
; }
60 SettingsManager
* GetSettingsManager() const
61 { return fSettingsManager
; }
63 virtual void MessageReceived(BMessage
* message
);
66 // UserInterfaceListener
67 virtual void FunctionSourceCodeRequested(
68 FunctionInstance
* function
,
69 bool forceDisassembly
= false);
70 virtual void SourceEntryLocateRequested(
71 const char* sourcePath
,
72 const char* locatedPath
);
73 virtual void SourceEntryInvalidateRequested(
74 LocatableFile
* sourceFile
);
75 virtual void ImageDebugInfoRequested(Image
* image
);
76 virtual void ValueNodeValueRequested(CpuState
* cpuState
,
77 ValueNodeContainer
* container
,
78 ValueNode
* valueNode
);
79 virtual void ValueNodeWriteRequested(ValueNode
* node
,
82 virtual void ThreadActionRequested(thread_id threadID
,
83 uint32 action
, target_addr_t address
);
85 virtual void SetBreakpointRequested(target_addr_t address
,
86 bool enabled
, bool hidden
= false);
87 virtual void SetBreakpointEnabledRequested(
88 UserBreakpoint
* breakpoint
,
90 virtual void SetBreakpointConditionRequested(
91 UserBreakpoint
* breakpoint
,
92 const char* condition
);
93 virtual void ClearBreakpointConditionRequested(
94 UserBreakpoint
* breakpoint
);
95 virtual void ClearBreakpointRequested(target_addr_t address
);
96 virtual void ClearBreakpointRequested(
97 UserBreakpoint
* breakpoint
);
99 virtual void SetStopOnImageLoadRequested(bool enabled
,
101 virtual void AddStopImageNameRequested(
103 virtual void RemoveStopImageNameRequested(
106 virtual void SetDefaultSignalDispositionRequested(
108 virtual void SetCustomSignalDispositionRequested(
109 int32 signal
, int32 disposition
);
110 virtual void RemoveCustomSignalDispositionRequested(
113 virtual void SetWatchpointRequested(target_addr_t address
,
114 uint32 type
, int32 length
, bool enabled
);
115 virtual void SetWatchpointEnabledRequested(
116 Watchpoint
*watchpoint
, bool enabled
);
117 virtual void ClearWatchpointRequested(target_addr_t address
);
118 virtual void ClearWatchpointRequested(
119 Watchpoint
* breakpoint
);
121 virtual void InspectRequested(target_addr_t address
,
122 TeamMemoryBlock::Listener
* listener
);
123 virtual void MemoryWriteRequested(target_addr_t address
,
124 const void* data
, target_size_t size
);
126 virtual void ExpressionEvaluationRequested(
127 SourceLanguage
* language
,
128 ExpressionInfo
* info
,
129 StackFrame
* frame
= NULL
,
130 ::Thread
* thread
= NULL
);
132 virtual void DebugReportRequested(entry_ref
* targetPath
);
134 virtual void WriteCoreFileRequested(entry_ref
* targetPath
);
136 virtual void TeamRestartRequested();
138 virtual bool UserInterfaceQuitRequested(
139 QuitOption quitOption
);
142 virtual void JobStarted(Job
* job
);
143 virtual void JobDone(Job
* job
);
144 virtual void JobWaitingForInput(Job
* job
);
145 virtual void JobFailed(Job
* job
);
146 virtual void JobAborted(Job
* job
);
149 virtual void ThreadStateChanged(
150 const ::Team::ThreadEvent
& event
);
151 virtual void ThreadCpuStateChanged(
152 const ::Team::ThreadEvent
& event
);
153 virtual void ThreadStackTraceChanged(
154 const ::Team::ThreadEvent
& event
);
155 virtual void ImageDebugInfoChanged(
156 const ::Team::ImageEvent
& event
);
160 struct ImageHandlerHashDefinition
;
161 struct ImageInfoPendingThread
;
162 struct ImageInfoPendingThreadHashDefinition
;
164 typedef BOpenHashTable
<ImageHandlerHashDefinition
> ImageHandlerTable
;
165 typedef BOpenHashTable
<ImageInfoPendingThreadHashDefinition
>
166 ImageInfoPendingThreadTable
;
169 static status_t
_DebugEventListenerEntry(void* data
);
170 status_t
_DebugEventListener();
172 void _HandleDebuggerMessage(DebugEvent
* event
);
174 bool _HandleTeamDeleted(
175 TeamDeletedEvent
* event
);
176 bool _HandleThreadCreated(
177 ThreadCreatedEvent
* event
);
178 bool _HandleThreadRenamed(
179 ThreadRenamedEvent
* event
);
180 bool _HandleThreadPriorityChanged(
181 ThreadPriorityChangedEvent
* event
);
182 bool _HandleThreadDeleted(
183 ThreadDeletedEvent
* event
);
184 bool _HandleImageCreated(
185 ImageCreatedEvent
* event
);
186 bool _HandleImageDeleted(
187 ImageDeletedEvent
* event
);
188 bool _HandlePostSyscall(
189 PostSyscallEvent
* event
);
191 void _PrepareForTeamExec(TeamExecEvent
* event
);
193 void _HandleImageDebugInfoChanged(image_id imageID
);
194 void _HandleImageFileChanged(image_id imageID
);
196 void _HandleSetUserBreakpoint(target_addr_t address
,
197 bool enabled
, bool hidden
);
198 void _HandleSetUserBreakpoint(
199 UserBreakpoint
* breakpoint
, bool enabled
);
200 void _HandleClearUserBreakpoint(
201 target_addr_t address
);
202 void _HandleClearUserBreakpoint(
203 UserBreakpoint
* breakpoint
);
205 void _HandleSetWatchpoint(target_addr_t address
,
206 uint32 type
, int32 length
, bool enabled
);
207 void _HandleSetWatchpoint(
208 Watchpoint
* watchpoint
, bool enabled
);
209 void _HandleClearWatchpoint( target_addr_t address
);
210 void _HandleClearWatchpoint(Watchpoint
* watchpoint
);
212 void _HandleInspectAddress(
213 target_addr_t address
,
214 TeamMemoryBlock::Listener
* listener
);
215 void _HandleWriteMemory(
216 target_addr_t address
, void* data
,
219 void _HandleEvaluateExpression(
220 SourceLanguage
* language
,
221 ExpressionInfo
* info
,
225 void _HandleWriteCoreFile(const entry_ref
& ref
);
227 status_t
_HandleSetArguments(int argc
,
228 const char* const* argv
);
230 void _HandleDebugInfoJobUserInput(
231 ImageDebugInfoLoadingState
* state
);
233 ThreadHandler
* _GetThreadHandler(thread_id threadID
);
235 status_t
_AddImage(const ImageInfo
& imageInfo
,
236 Image
** _image
= NULL
);
238 void _LoadSettings();
239 void _SaveSettings();
241 void _NotifyUser(const char* title
,
242 const char* text
,...);
244 void _ResetUserBackgroundStatusIfNeeded();
245 // updates user interface to
246 // ready/completed message
247 // for background work status
251 SettingsManager
* fSettingsManager
;
255 ThreadHandlerTable fThreadHandlers
;
256 // protected by the team lock
257 ImageHandlerTable
* fImageHandlers
;
258 ImageInfoPendingThreadTable
* fImageInfoPendingThreads
;
259 DebuggerInterface
* fDebuggerInterface
;
260 TeamDebugInfo
* fTeamDebugInfo
;
261 FileManager
* fFileManager
;
263 BreakpointManager
* fBreakpointManager
;
264 WatchpointManager
* fWatchpointManager
;
265 TeamMemoryBlockManager
*
267 DebugReportGenerator
*
269 thread_id fDebugEventListener
;
270 UserInterface
* fUserInterface
;
271 volatile bool fTerminating
;
272 bool fKillTeamOnQuit
;
273 TeamSettings fTeamSettings
;
274 int fCommandLineArgc
;
275 const char** fCommandLineArgv
;
280 class TeamDebugger::Listener
{
284 virtual void TeamDebuggerStarted(TeamDebugger
* debugger
) = 0;
285 virtual void TeamDebuggerRestartRequested(
286 TeamDebugger
* debugger
) = 0;
287 virtual void TeamDebuggerQuit(TeamDebugger
* debugger
) = 0;
291 #endif // TEAM_DEBUGGER_H