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.
12 #include <StringList.h>
14 #include <ObjectList.h>
17 #include "ImageInfo.h"
18 #include "TargetAddressRange.h"
20 #include "ThreadInfo.h"
21 #include "UserBreakpoint.h"
22 #include "Watchpoint.h"
27 TEAM_EVENT_TEAM_RENAMED
,
29 TEAM_EVENT_THREAD_ADDED
,
30 TEAM_EVENT_THREAD_REMOVED
,
31 TEAM_EVENT_IMAGE_ADDED
,
32 TEAM_EVENT_IMAGE_REMOVED
,
34 TEAM_EVENT_THREAD_STATE_CHANGED
,
35 TEAM_EVENT_THREAD_CPU_STATE_CHANGED
,
36 TEAM_EVENT_THREAD_STACK_TRACE_CHANGED
,
38 TEAM_EVENT_IMAGE_DEBUG_INFO_CHANGED
,
40 TEAM_EVENT_IMAGE_LOAD_SETTINGS_CHANGED
,
41 TEAM_EVENT_IMAGE_LOAD_NAME_ADDED
,
42 TEAM_EVENT_IMAGE_LOAD_NAME_REMOVED
,
44 TEAM_EVENT_DEFAULT_SIGNAL_DISPOSITION_CHANGED
,
45 TEAM_EVENT_CUSTOM_SIGNAL_DISPOSITION_CHANGED
,
46 TEAM_EVENT_CUSTOM_SIGNAL_DISPOSITION_REMOVED
,
48 TEAM_EVENT_CONSOLE_OUTPUT_RECEIVED
,
50 TEAM_EVENT_BREAKPOINT_ADDED
,
51 TEAM_EVENT_BREAKPOINT_REMOVED
,
52 TEAM_EVENT_USER_BREAKPOINT_CHANGED
,
54 TEAM_EVENT_WATCHPOINT_ADDED
,
55 TEAM_EVENT_WATCHPOINT_REMOVED
,
56 TEAM_EVENT_WATCHPOINT_CHANGED
,
58 TEAM_EVENT_DEBUG_REPORT_CHANGED
,
60 TEAM_EVENT_CORE_FILE_CHANGED
,
62 TEAM_EVENT_MEMORY_CHANGED
71 class FunctionInstance
;
78 class TeamTypeInformation
;
83 typedef std::map
<int32
, int32
> SignalDispositionMappings
;
89 class BreakpointEvent
;
90 class ConsoleOutputEvent
;
91 class DebugReportEvent
;
92 class MemoryChangedEvent
;
95 class ImageLoadNameEvent
;
96 class DefaultSignalDispositionEvent
;
97 class CustomSignalDispositionEvent
;
99 class UserBreakpointEvent
;
100 class WatchpointEvent
;
101 class CoreFileChangedEvent
;
105 Team(team_id teamID
, TeamMemory
* teamMemory
,
106 Architecture
* architecture
,
107 TeamDebugInfo
* debugInfo
,
108 TeamTypeInformation
* typeInformation
);
113 bool Lock() { return fLock
.Lock(); }
114 void Unlock() { fLock
.Unlock(); }
116 team_id
ID() const { return fID
; }
117 TeamMemory
* GetTeamMemory() const
118 { return fTeamMemory
; }
119 Architecture
* GetArchitecture() const
120 { return fArchitecture
; }
121 TeamDebugInfo
* DebugInfo() const { return fDebugInfo
; }
123 GetTeamTypeInformation() const
124 { return fTypeInformation
; }
126 const char* Name() const { return fName
.String(); }
127 void SetName(const BString
& name
);
129 void AddThread(::Thread
* thread
);
130 status_t
AddThread(const ThreadInfo
& threadInfo
,
131 ::Thread
** _thread
= NULL
);
132 void RemoveThread(::Thread
* thread
);
133 bool RemoveThread(thread_id threadID
);
134 ::Thread
* ThreadByID(thread_id threadID
) const;
135 const ThreadList
& Threads() const;
137 status_t
AddImage(const ImageInfo
& imageInfo
,
138 LocatableFile
* imageFile
,
139 Image
** _image
= NULL
);
140 void RemoveImage(Image
* image
);
141 bool RemoveImage(image_id imageID
);
142 Image
* ImageByID(image_id imageID
) const;
143 Image
* ImageByAddress(target_addr_t address
) const;
144 const ImageList
& Images() const;
147 bool AddStopImageName(const BString
& name
);
148 void RemoveStopImageName(const BString
& name
);
149 const BStringList
& StopImageNames() const;
151 void SetStopOnImageLoad(bool enabled
,
152 bool useImageNameList
);
153 bool StopOnImageLoad() const
154 { return fStopOnImageLoad
; }
155 bool StopImageNameListEnabled() const
156 { return fStopImageNameListEnabled
; }
158 void SetDefaultSignalDisposition(int32 disposition
);
159 int32
DefaultSignalDisposition() const
160 { return fDefaultSignalDisposition
; }
161 bool SetCustomSignalDisposition(int32 signal
,
163 void RemoveCustomSignalDisposition(int32 signal
);
164 int32
SignalDispositionFor(int32 signal
) const;
165 // if no custom disposition is found,
167 const SignalDispositionMappings
&
168 GetSignalDispositionMappings() const;
170 void ClearSignalDispositionMappings();
172 bool AddBreakpoint(Breakpoint
* breakpoint
);
173 // takes over reference (also on error)
174 void RemoveBreakpoint(Breakpoint
* breakpoint
);
175 // releases its own reference
176 int32
CountBreakpoints() const;
177 Breakpoint
* BreakpointAt(int32 index
) const;
178 Breakpoint
* BreakpointAtAddress(
179 target_addr_t address
) const;
180 void GetBreakpointsInAddressRange(
181 TargetAddressRange range
,
182 BObjectList
<UserBreakpoint
>& breakpoints
)
184 void GetBreakpointsForSourceCode(
185 SourceCode
* sourceCode
,
186 BObjectList
<UserBreakpoint
>& breakpoints
)
189 void AddUserBreakpoint(
190 UserBreakpoint
* userBreakpoint
);
191 void RemoveUserBreakpoint(
192 UserBreakpoint
* userBreakpoint
);
193 const UserBreakpointList
& UserBreakpoints() const
194 { return fUserBreakpoints
; }
196 bool AddWatchpoint(Watchpoint
* watchpoint
);
197 // takes over reference (also on error)
198 void RemoveWatchpoint(Watchpoint
* watchpoint
);
199 // releases its own reference
200 int32
CountWatchpoints() const;
201 Watchpoint
* WatchpointAt(int32 index
) const;
202 Watchpoint
* WatchpointAtAddress(
203 target_addr_t address
) const;
204 void GetWatchpointsInAddressRange(
205 TargetAddressRange range
,
206 BObjectList
<Watchpoint
>& watchpoints
)
208 const WatchpointList
& Watchpoints() const
209 { return fWatchpoints
; }
211 status_t
GetStatementAtAddress(target_addr_t address
,
212 FunctionInstance
*& _function
,
213 Statement
*& _statement
);
214 // returns a reference to the statement,
215 // not to the functions instance, though,
217 status_t
GetStatementAtSourceLocation(
218 SourceCode
* sourceCode
,
219 const SourceLocation
& location
,
220 Statement
*& _statement
);
221 // returns a reference to the statement
222 // (any matching statement!),
225 Function
* FunctionByID(FunctionID
* functionID
) const;
227 void AddListener(Listener
* listener
);
228 void RemoveListener(Listener
* listener
);
230 // service methods for Thread
231 void NotifyThreadStateChanged(::Thread
* thread
);
232 void NotifyThreadCpuStateChanged(::Thread
* thread
);
233 void NotifyThreadStackTraceChanged(
236 // service methods for Image
237 void NotifyImageDebugInfoChanged(Image
* image
);
239 // service methods for Image load settings
240 void NotifyStopOnImageLoadChanged(bool enabled
,
241 bool useImageNameList
);
242 void NotifyStopImageNameAdded(const BString
& name
);
243 void NotifyStopImageNameRemoved(
244 const BString
& name
);
246 // service methods for Signal Disposition settings
247 void NotifyDefaultSignalDispositionChanged(
248 int32 newDisposition
);
249 void NotifyCustomSignalDispositionChanged(
250 int32 signal
, int32 disposition
);
251 void NotifyCustomSignalDispositionRemoved(
254 // service methods for console output
255 void NotifyConsoleOutputReceived(
256 int32 fd
, const BString
& output
);
258 // breakpoint related service methods
259 void NotifyUserBreakpointChanged(
260 UserBreakpoint
* breakpoint
);
262 // watchpoint related service methods
263 void NotifyWatchpointChanged(
264 Watchpoint
* watchpoint
);
266 // debug report related service methods
267 void NotifyDebugReportChanged(
268 const char* reportPath
, status_t result
);
270 // core file related service methods
271 void NotifyCoreFileChanged(
272 const char* targetPath
);
274 // memory write related service methods
275 void NotifyMemoryChanged(target_addr_t address
,
279 struct BreakpointByAddressPredicate
;
280 struct WatchpointByAddressPredicate
;
282 typedef BObjectList
<Breakpoint
> BreakpointList
;
283 typedef DoublyLinkedList
<Listener
> ListenerList
;
286 void _NotifyTeamRenamed();
287 void _NotifyThreadAdded(::Thread
* thread
);
288 void _NotifyThreadRemoved(::Thread
* thread
);
289 void _NotifyImageAdded(Image
* image
);
290 void _NotifyImageRemoved(Image
* image
);
295 TeamMemory
* fTeamMemory
;
298 Architecture
* fArchitecture
;
299 TeamDebugInfo
* fDebugInfo
;
303 bool fStopOnImageLoad
;
304 bool fStopImageNameListEnabled
;
305 BStringList fStopImageNames
;
306 int32 fDefaultSignalDisposition
;
307 SignalDispositionMappings
308 fCustomSignalDispositions
;
309 BreakpointList fBreakpoints
;
310 WatchpointList fWatchpoints
;
311 UserBreakpointList fUserBreakpoints
;
312 ListenerList fListeners
;
318 Event(uint32 type
, Team
* team
);
320 uint32
EventType() const { return fEventType
; }
321 Team
* GetTeam() const { return fTeam
; }
329 class Team::ThreadEvent
: public Event
{
331 ThreadEvent(uint32 type
, ::Thread
* thread
);
333 ::Thread
* GetThread() const { return fThread
; }
340 class Team::ImageEvent
: public Event
{
342 ImageEvent(uint32 type
, Image
* image
);
344 Image
* GetImage() const { return fImage
; }
351 class Team::ImageLoadEvent
: public Event
{
353 ImageLoadEvent(uint32 type
, Team
* team
,
354 bool stopOnImageLoad
,
355 bool stopImageNameListEnabled
);
357 bool StopOnImageLoad() const
358 { return fStopOnImageLoad
; }
359 bool StopImageNameListEnabled() const
360 { return fStopImageNameListEnabled
; }
363 bool fStopOnImageLoad
;
364 bool fStopImageNameListEnabled
;
368 class Team::ImageLoadNameEvent
: public Event
{
370 ImageLoadNameEvent(uint32 type
, Team
* team
,
371 const BString
& name
);
373 const BString
& ImageName() const { return fImageName
; }
380 class Team::DefaultSignalDispositionEvent
: public Event
{
382 DefaultSignalDispositionEvent(uint32 type
,
383 Team
* team
, int32 disposition
);
385 int32
DefaultDisposition() const
386 { return fDefaultDisposition
; }
389 int32 fDefaultDisposition
;
393 class Team::CustomSignalDispositionEvent
: public Event
{
395 CustomSignalDispositionEvent(uint32 type
,
396 Team
* team
, int32 signal
,
399 int32
Signal() const { return fSignal
; }
400 int32
Disposition() const { return fDisposition
; }
408 class Team::BreakpointEvent
: public Event
{
410 BreakpointEvent(uint32 type
, Team
* team
,
411 Breakpoint
* breakpoint
);
413 Breakpoint
* GetBreakpoint() const { return fBreakpoint
; }
416 Breakpoint
* fBreakpoint
;
420 class Team::ConsoleOutputEvent
: public Event
{
422 ConsoleOutputEvent(uint32 type
, Team
* team
,
423 int32 fd
, const BString
& output
);
425 int32
Descriptor() const { return fDescriptor
; }
426 const BString
& Output() const { return fOutput
; }
434 class Team::DebugReportEvent
: public Event
{
436 DebugReportEvent(uint32 type
, Team
* team
,
437 const char* reportPath
,
438 status_t finalStatus
);
440 const char* GetReportPath() const { return fReportPath
; }
441 status_t
GetFinalStatus() const { return fFinalStatus
; }
443 const char* fReportPath
;
444 status_t fFinalStatus
;
448 class Team::CoreFileChangedEvent
: public Event
{
450 CoreFileChangedEvent(uint32 type
, Team
* team
,
451 const char* targetPath
);
452 const char* GetTargetPath() const { return fTargetPath
; }
454 const char* fTargetPath
;
458 class Team::MemoryChangedEvent
: public Event
{
460 MemoryChangedEvent(uint32 type
, Team
* team
,
461 target_addr_t address
, target_size_t size
);
463 target_addr_t
GetTargetAddress() const
464 { return fTargetAddress
; }
466 target_size_t
GetSize() const { return fSize
; }
468 target_addr_t fTargetAddress
;
473 class Team::WatchpointEvent
: public Event
{
475 WatchpointEvent(uint32 type
, Team
* team
,
476 Watchpoint
* watchpoint
);
478 Watchpoint
* GetWatchpoint() const { return fWatchpoint
; }
481 Watchpoint
* fWatchpoint
;
485 class Team::UserBreakpointEvent
: public Event
{
487 UserBreakpointEvent(uint32 type
, Team
* team
,
488 UserBreakpoint
* breakpoint
);
490 UserBreakpoint
* GetBreakpoint() const { return fBreakpoint
; }
493 UserBreakpoint
* fBreakpoint
;
497 class Team::Listener
: public DoublyLinkedListLinkImpl
<Team::Listener
> {
501 virtual void TeamRenamed(
502 const Team::Event
& event
);
504 virtual void ThreadAdded(const Team::ThreadEvent
& event
);
505 virtual void ThreadRemoved(const Team::ThreadEvent
& event
);
507 virtual void ImageAdded(const Team::ImageEvent
& event
);
508 virtual void ImageRemoved(const Team::ImageEvent
& event
);
510 virtual void ThreadStateChanged(
511 const Team::ThreadEvent
& event
);
512 virtual void ThreadCpuStateChanged(
513 const Team::ThreadEvent
& event
);
514 virtual void ThreadStackTraceChanged(
515 const Team::ThreadEvent
& event
);
517 virtual void ImageDebugInfoChanged(
518 const Team::ImageEvent
& event
);
520 virtual void StopOnImageLoadSettingsChanged(
521 const Team::ImageLoadEvent
& event
);
522 virtual void StopOnImageLoadNameAdded(
523 const Team::ImageLoadNameEvent
& event
);
524 virtual void StopOnImageLoadNameRemoved(
525 const Team::ImageLoadNameEvent
& event
);
527 virtual void DefaultSignalDispositionChanged(
528 const Team::DefaultSignalDispositionEvent
&
530 virtual void CustomSignalDispositionChanged(
531 const Team::CustomSignalDispositionEvent
&
533 virtual void CustomSignalDispositionRemoved(
534 const Team::CustomSignalDispositionEvent
&
537 virtual void ConsoleOutputReceived(
538 const Team::ConsoleOutputEvent
& event
);
540 virtual void BreakpointAdded(
541 const Team::BreakpointEvent
& event
);
542 virtual void BreakpointRemoved(
543 const Team::BreakpointEvent
& event
);
544 virtual void UserBreakpointChanged(
545 const Team::UserBreakpointEvent
& event
);
547 virtual void WatchpointAdded(
548 const Team::WatchpointEvent
& event
);
549 virtual void WatchpointRemoved(
550 const Team::WatchpointEvent
& event
);
551 virtual void WatchpointChanged(
552 const Team::WatchpointEvent
& event
);
554 virtual void DebugReportChanged(
555 const Team::DebugReportEvent
& event
);
557 virtual void CoreFileChanged(
558 const Team::CoreFileChangedEvent
& event
);
560 virtual void MemoryChanged(
561 const Team::MemoryChangedEvent
& event
);