xref: /haiku/headers/private/debugger/model/Thread.h (revision fce4895d1884da5ae6fb299d23c735c598e690b1)
1 /*
2  * Copyright 2013-2016, Rene Gollent, rene@gollent.com.
3  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
4  * Distributed under the terms of the MIT License.
5  */
6 #ifndef THREAD_H
7 #define THREAD_H
8 
9 #include <OS.h>
10 #include <String.h>
11 
12 #include <Referenceable.h>
13 #include <util/DoublyLinkedList.h>
14 
15 #include "ReturnValueInfo.h"
16 #include "types/Types.h"
17 
18 
19 class CpuState;
20 class StackTrace;
21 class Team;
22 
23 
24 // general thread state
25 enum {
26 	THREAD_STATE_UNKNOWN,
27 	THREAD_STATE_RUNNING,
28 	THREAD_STATE_STOPPED
29 };
30 
31 // reason why stopped
32 enum {
33 	THREAD_STOPPED_UNKNOWN,
34 	THREAD_STOPPED_DEBUGGED,
35 	THREAD_STOPPED_DEBUGGER_CALL,
36 	THREAD_STOPPED_BREAKPOINT,
37 	THREAD_STOPPED_WATCHPOINT,
38 	THREAD_STOPPED_SINGLE_STEP,
39 	THREAD_STOPPED_EXCEPTION
40 };
41 
42 
43 class Thread : public BReferenceable,
44 	public DoublyLinkedListLinkImpl< ::Thread> {
45 public:
46 								Thread(Team* team, thread_id threadID);
47 								~Thread();
48 
49 			status_t			Init();
50 
GetTeam()51 			Team*				GetTeam() const	{ return fTeam; }
ID()52 			thread_id			ID() const		{ return fID; }
53 
54 			bool				IsMainThread() const;
55 
Name()56 			const char*			Name() const	{ return fName.String(); }
57 			void				SetName(const BString& name);
58 
State()59 			uint32				State() const	{ return fState; }
60 			void				SetState(uint32 state,
61 									uint32 reason = THREAD_STOPPED_UNKNOWN,
62 									const BString& info = BString());
63 
StoppedReason()64 			uint32				StoppedReason() const
65 									{ return fStoppedReason; }
StoppedReasonInfo()66 			const BString&		StoppedReasonInfo() const
67 									{ return fStoppedReasonInfo; }
68 
GetCpuState()69 			CpuState*			GetCpuState() const	{ return fCpuState; }
70 			void				SetCpuState(CpuState* state);
71 
GetStackTrace()72 			StackTrace*			GetStackTrace() const	{ return fStackTrace; }
73 			void				SetStackTrace(StackTrace* trace);
74 
StopRequestPending()75 			bool				StopRequestPending() const
76 									{ return fStopRequestPending; }
77 			void				SetStopRequestPending();
78 
79 			ReturnValueInfoList*
ReturnValueInfos()80 								ReturnValueInfos() const
81 								{ return fReturnValueInfos; }
82 			status_t			AddReturnValueInfo(ReturnValueInfo* info);
83 			void				ClearReturnValueInfos();
84 
85 private:
86 			Team*				fTeam;
87 			thread_id			fID;
88 			BString				fName;
89 			uint32				fState;
90 			ReturnValueInfoList*
91 								fReturnValueInfos;
92 			bool				fStopRequestPending;
93 			uint32				fStoppedReason;
94 			BString				fStoppedReasonInfo;
95 			CpuState*			fCpuState;
96 			StackTrace*			fStackTrace;
97 };
98 
99 
100 typedef DoublyLinkedList< ::Thread> ThreadList;
101 
102 
103 #endif	// THREAD_H
104