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