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