1 //===-- MachThreadList.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 __MachThreadList_h__
15 #define __MachThreadList_h__
16 
17 #include "MachThread.h"
18 #include "ThreadInfo.h"
19 
20 class DNBThreadResumeActions;
21 
22 class MachThreadList {
23 public:
24   MachThreadList();
25   ~MachThreadList();
26 
27   void Clear();
28   void Dump() const;
29   bool GetRegisterValue(nub_thread_t tid, uint32_t set, uint32_t reg,
30                         DNBRegisterValue *reg_value) const;
31   bool SetRegisterValue(nub_thread_t tid, uint32_t set, uint32_t reg,
32                         const DNBRegisterValue *reg_value) const;
33   nub_size_t GetRegisterContext(nub_thread_t tid, void *buf, size_t buf_len);
34   nub_size_t SetRegisterContext(nub_thread_t tid, const void *buf,
35                                 size_t buf_len);
36   uint32_t SaveRegisterState(nub_thread_t tid);
37   bool RestoreRegisterState(nub_thread_t tid, uint32_t save_id);
38   const char *GetThreadInfo(nub_thread_t tid) const;
39   void ProcessWillResume(MachProcess *process,
40                          const DNBThreadResumeActions &thread_actions);
41   uint32_t ProcessDidStop(MachProcess *process);
42   bool NotifyException(MachException::Data &exc);
43   bool ShouldStop(bool &step_more);
44   const char *GetName(nub_thread_t tid);
45   nub_state_t GetState(nub_thread_t tid);
46   nub_thread_t SetCurrentThread(nub_thread_t tid);
47 
48   ThreadInfo::QoS GetRequestedQoS(nub_thread_t tid, nub_addr_t tsd,
49                                   uint64_t dti_qos_class_index);
50   nub_addr_t GetPThreadT(nub_thread_t tid);
51   nub_addr_t GetDispatchQueueT(nub_thread_t tid);
52   nub_addr_t
53   GetTSDAddressForThread(nub_thread_t tid,
54                          uint64_t plo_pthread_tsd_base_address_offset,
55                          uint64_t plo_pthread_tsd_base_offset,
56                          uint64_t plo_pthread_tsd_entry_size);
57 
58   bool GetThreadStoppedReason(nub_thread_t tid,
59                               struct DNBThreadStopInfo *stop_info) const;
60   void DumpThreadStoppedReason(nub_thread_t tid) const;
61   bool GetIdentifierInfo(nub_thread_t tid,
62                          thread_identifier_info_data_t *ident_info);
63   nub_size_t NumThreads() const;
64   nub_thread_t ThreadIDAtIndex(nub_size_t idx) const;
65   nub_thread_t CurrentThreadID();
66   void CurrentThread(MachThreadSP &threadSP);
67   void NotifyBreakpointChanged(const DNBBreakpoint *bp);
68   uint32_t EnableHardwareBreakpoint(const DNBBreakpoint *bp) const;
69   bool DisableHardwareBreakpoint(const DNBBreakpoint *bp) const;
70   uint32_t EnableHardwareWatchpoint(const DNBBreakpoint *wp) const;
71   bool DisableHardwareWatchpoint(const DNBBreakpoint *wp) const;
72   uint32_t NumSupportedHardwareWatchpoints() const;
73 
74   uint32_t GetThreadIndexForThreadStoppedWithSignal(const int signo) const;
75 
76   MachThreadSP GetThreadByID(nub_thread_t tid) const;
77 
78   MachThreadSP GetThreadByMachPortNumber(thread_t mach_port_number) const;
79   nub_thread_t GetThreadIDByMachPortNumber(thread_t mach_port_number) const;
80   thread_t GetMachPortNumberByThreadID(nub_thread_t globally_unique_id) const;
81 
82 protected:
83   typedef std::vector<MachThreadSP> collection;
84   typedef collection::iterator iterator;
85   typedef collection::const_iterator const_iterator;
86 
87   uint32_t UpdateThreadList(MachProcess *process, bool update,
88                             collection *num_threads = NULL);
89   //  const_iterator  FindThreadByID (thread_t tid) const;
90 
91   collection m_threads;
92   mutable PThreadMutex m_threads_mutex;
93   MachThreadSP m_current_thread;
94   bool m_is_64_bit;
95 };
96 
97 #endif // #ifndef __MachThreadList_h__
98