MachThread.h revision 02274ed47ccff35a64870331f6e2c88c711ca0f9
1//===-- MachThread.h --------------------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// Created by Greg Clayton on 6/19/07. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef __MachThread_h__ 15#define __MachThread_h__ 16 17#include <string> 18#include <vector> 19#include <tr1/memory> // for std::tr1::shared_ptr 20 21#include <libproc.h> 22#include <mach/mach.h> 23#include <pthread.h> 24#include <sys/signal.h> 25 26#include "PThreadCondition.h" 27#include "PThreadMutex.h" 28#include "MachException.h" 29#include "DNBArch.h" 30#include "DNBRegisterInfo.h" 31 32class DNBBreakpoint; 33class MachProcess; 34 35class MachThread 36{ 37public: 38 39 MachThread (MachProcess *process, thread_t thread = 0); 40 ~MachThread (); 41 42 MachProcess * Process() { return m_process; } 43 const MachProcess * 44 Process() const { return m_process; } 45 nub_process_t ProcessID() const; 46 void Dump(uint32_t index); 47 thread_t ThreadID() const { return m_tid; } 48 thread_t InferiorThreadID() const; 49 50 uint32_t SequenceID() const { return m_seq_id; } 51 static bool ThreadIDIsValid(thread_t thread); 52 uint32_t Resume(); 53 uint32_t Suspend(); 54 uint32_t SuspendCount() const { return m_suspendCount; } 55 bool RestoreSuspendCount(); 56 57 bool GetRegisterState(int flavor, bool force); 58 bool SetRegisterState(int flavor); 59 uint64_t GetPC(uint64_t failValue = INVALID_NUB_ADDRESS); // Get program counter 60 bool SetPC(uint64_t value); // Set program counter 61 uint64_t GetSP(uint64_t failValue = INVALID_NUB_ADDRESS); // Get stack pointer 62 63 nub_break_t CurrentBreakpoint() const { return m_breakID; } 64 void SetCurrentBreakpoint(nub_break_t breakID) { m_breakID = breakID; } 65 uint32_t EnableHardwareBreakpoint (const DNBBreakpoint *breakpoint); 66 uint32_t EnableHardwareWatchpoint (const DNBBreakpoint *watchpoint); 67 bool DisableHardwareBreakpoint (const DNBBreakpoint *breakpoint); 68 bool DisableHardwareWatchpoint (const DNBBreakpoint *watchpoint); 69 70 nub_state_t GetState(); 71 void SetState(nub_state_t state); 72 73 void ThreadWillResume (const DNBThreadResumeAction *thread_action); 74 bool ShouldStop(bool &step_more); 75 bool IsStepping(); 76 bool ThreadDidStop(); 77 bool NotifyException(MachException::Data& exc); 78 const MachException::Data& GetStopException() { return m_stop_exception; } 79 80 uint32_t GetNumRegistersInSet(int regSet) const; 81 const char * GetRegisterSetName(int regSet) const; 82 const DNBRegisterInfo * 83 GetRegisterInfo(int regSet, int regIndex) const; 84 void DumpRegisterState(int regSet); 85 const DNBRegisterSetInfo * 86 GetRegisterSetInfo(nub_size_t *num_reg_sets ) const; 87 bool GetRegisterValue ( uint32_t reg_set_idx, uint32_t reg_idx, DNBRegisterValue *reg_value ); 88 bool SetRegisterValue ( uint32_t reg_set_idx, uint32_t reg_idx, const DNBRegisterValue *reg_value ); 89 nub_size_t GetRegisterContext (void *buf, nub_size_t buf_len); 90 nub_size_t SetRegisterContext (const void *buf, nub_size_t buf_len); 91 void NotifyBreakpointChanged (const DNBBreakpoint *bp); 92 93 bool IsUserReady(); 94 struct thread_basic_info * 95 GetBasicInfo (); 96 const char * GetBasicInfoAsString () const; 97 const char * GetName (); 98protected: 99 static bool GetBasicInfo(thread_t threadID, struct thread_basic_info *basic_info); 100 101 bool 102 GetIdentifierInfo (); 103 104// const char * 105// GetDispatchQueueName(); 106// 107 MachProcess * m_process; // The process that owns this thread 108 thread_t m_tid; // The thread port for this thread 109 uint32_t m_seq_id; // A Sequential ID that increments with each new thread 110 nub_state_t m_state; // The state of our process 111 PThreadMutex m_state_mutex; // Multithreaded protection for m_state 112 nub_break_t m_breakID; // Breakpoint that this thread is (stopped)/was(running) at (NULL for none) 113 struct thread_basic_info m_basicInfo; // Basic information for a thread used to see if a thread is valid 114 uint32_t m_suspendCount; // The current suspend count 115 MachException::Data m_stop_exception; // The best exception that describes why this thread is stopped 116 DNBArch m_arch; // Arch specific information for register state and more 117 std::vector<DNBRegisterSetInfo> m_regSets; // Register set information for this thread 118#ifdef THREAD_IDENTIFIER_INFO_COUNT 119 thread_identifier_info_data_t m_ident_info; 120 struct proc_threadinfo m_proc_threadinfo; 121 std::string m_dispatch_queue_name; 122#endif 123 124}; 125 126typedef std::tr1::shared_ptr<MachThread> MachThreadSP; 127 128#endif 129