1 //===-- NativeThreadListDarwin.h --------------------------------------*- C++
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 // Created by Greg Clayton on 6/19/07.
12 //===----------------------------------------------------------------------===//
14 #ifndef __NativeThreadListDarwin_h__
15 #define __NativeThreadListDarwin_h__
21 #include "lldb/lldb-private-forward.h"
22 #include "lldb/lldb-types.h"
24 #include "MachException.h"
26 // #include "ThreadInfo.h"
28 namespace lldb_private {
29 namespace process_darwin {
31 class NativeBreakpointDarwin;
32 class NativeProcessDarwin;
34 class NativeThreadDarwin;
35 using NativeThreadDarwinSP = std::shared_ptr<NativeThreadDarwin>;
37 class NativeThreadListDarwin {
39 NativeThreadListDarwin();
40 ~NativeThreadListDarwin();
44 void Dump(Stream &stream) const;
46 // These methods will be accessed directly from NativeThreadDarwin
48 bool GetRegisterValue (nub_thread_t tid, uint32_t set, uint32_t reg, DNBRegisterValue *reg_value) const;
49 bool SetRegisterValue (nub_thread_t tid, uint32_t set, uint32_t reg, const DNBRegisterValue *reg_value) const;
50 nub_size_t GetRegisterContext (nub_thread_t tid, void *buf, size_t buf_len);
51 nub_size_t SetRegisterContext (nub_thread_t tid, const void *buf, size_t buf_len);
52 uint32_t SaveRegisterState (nub_thread_t tid);
53 bool RestoreRegisterState (nub_thread_t tid, uint32_t save_id);
56 const char *GetThreadInfo(lldb::tid_t tid) const;
58 void ProcessWillResume(NativeProcessDarwin &process,
59 const ResumeActionList &thread_actions);
61 uint32_t ProcessDidStop(NativeProcessDarwin &process);
63 bool NotifyException(MachException::Data &exc);
65 bool ShouldStop(bool &step_more);
67 // These methods will be accessed directly from NativeThreadDarwin
69 const char * GetName (nub_thread_t tid);
70 nub_state_t GetState (nub_thread_t tid);
71 nub_thread_t SetCurrentThread (nub_thread_t tid);
74 // TODO: figure out if we need to add this to NativeThreadDarwin yet.
76 ThreadInfo::QoS GetRequestedQoS (nub_thread_t tid, nub_addr_t tsd, uint64_t dti_qos_class_index);
77 nub_addr_t GetPThreadT (nub_thread_t tid);
78 nub_addr_t GetDispatchQueueT (nub_thread_t tid);
79 nub_addr_t GetTSDAddressForThread (nub_thread_t tid, uint64_t plo_pthread_tsd_base_address_offset, uint64_t plo_pthread_tsd_base_offset, uint64_t plo_pthread_tsd_entry_size);
82 // These methods will be accessed directly from NativeThreadDarwin
84 bool GetThreadStoppedReason (nub_thread_t tid, struct DNBThreadStopInfo *stop_info) const;
85 void DumpThreadStoppedReason (nub_thread_t tid) const;
86 bool GetIdentifierInfo (nub_thread_t tid, thread_identifier_info_data_t *ident_info);
89 size_t GetNumberOfThreads() const;
91 lldb::tid_t ThreadIDAtIndex(size_t idx) const;
93 lldb::tid_t GetCurrentThreadID();
95 NativeThreadDarwinSP GetCurrentThread();
97 void NotifyBreakpointChanged(const NativeBreakpointDarwin *bp);
99 uint32_t EnableHardwareBreakpoint(const NativeBreakpointDarwin *bp) const;
101 bool DisableHardwareBreakpoint(const NativeBreakpointDarwin *bp) const;
103 uint32_t EnableHardwareWatchpoint(const NativeBreakpointDarwin *wp) const;
105 bool DisableHardwareWatchpoint(const NativeBreakpointDarwin *wp) const;
107 uint32_t GetNumberOfSupportedHardwareWatchpoints() const;
109 size_t GetThreadIndexForThreadStoppedWithSignal(const int signo) const;
111 NativeThreadDarwinSP GetThreadByID(lldb::tid_t tid) const;
114 GetThreadByMachPortNumber(::thread_t mach_port_number) const;
116 lldb::tid_t GetThreadIDByMachPortNumber(::thread_t mach_port_number) const;
118 thread_t GetMachPortNumberByThreadID(lldb::tid_t globally_unique_id) const;
121 typedef std::vector<NativeThreadDarwinSP> collection;
122 typedef collection::iterator iterator;
123 typedef collection::const_iterator const_iterator;
125 // Consider having this return an lldb_private::Status.
126 uint32_t UpdateThreadList(NativeProcessDarwin &process, bool update,
127 collection *num_threads = nullptr);
129 collection m_threads;
130 mutable std::recursive_mutex m_threads_mutex;
131 NativeThreadDarwinSP m_current_thread;
135 } // namespace process_darwin
136 } // namespace lldb_private
138 #endif // #ifndef __NativeThreadListDarwin_h__