]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeThreadListDarwin.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / Process / Darwin / NativeThreadListDarwin.h
1 //===-- NativeThreadListDarwin.h --------------------------------------*- C++
2 //-*-===//
3 //
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
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  Created by Greg Clayton on 6/19/07.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef __NativeThreadListDarwin_h__
15 #define __NativeThreadListDarwin_h__
16
17 #include <memory>
18 #include <mutex>
19 #include <vector>
20
21 #include "lldb/lldb-private-forward.h"
22 #include "lldb/lldb-types.h"
23
24 #include "MachException.h"
25
26 // #include "ThreadInfo.h"
27
28 namespace lldb_private {
29 namespace process_darwin {
30
31 class NativeBreakpointDarwin;
32 class NativeProcessDarwin;
33
34 class NativeThreadDarwin;
35 using NativeThreadDarwinSP = std::shared_ptr<NativeThreadDarwin>;
36
37 class NativeThreadListDarwin {
38 public:
39   NativeThreadListDarwin();
40   ~NativeThreadListDarwin();
41
42   void Clear();
43
44   void Dump(Stream &stream) const;
45
46 // These methods will be accessed directly from NativeThreadDarwin
47 #if 0
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);
54 #endif
55
56   const char *GetThreadInfo(lldb::tid_t tid) const;
57
58   void ProcessWillResume(NativeProcessDarwin &process,
59                          const ResumeActionList &thread_actions);
60
61   uint32_t ProcessDidStop(NativeProcessDarwin &process);
62
63   bool NotifyException(MachException::Data &exc);
64
65   bool ShouldStop(bool &step_more);
66
67 // These methods will be accessed directly from NativeThreadDarwin
68 #if 0
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);
72 #endif
73
74 // TODO: figure out if we need to add this to NativeThreadDarwin yet.
75 #if 0
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);
80 #endif
81
82 // These methods will be accessed directly from NativeThreadDarwin
83 #if 0
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);
87 #endif
88
89   size_t GetNumberOfThreads() const;
90
91   lldb::tid_t ThreadIDAtIndex(size_t idx) const;
92
93   lldb::tid_t GetCurrentThreadID();
94
95   NativeThreadDarwinSP GetCurrentThread();
96
97   void NotifyBreakpointChanged(const NativeBreakpointDarwin *bp);
98
99   uint32_t EnableHardwareBreakpoint(const NativeBreakpointDarwin *bp) const;
100
101   bool DisableHardwareBreakpoint(const NativeBreakpointDarwin *bp) const;
102
103   uint32_t EnableHardwareWatchpoint(const NativeBreakpointDarwin *wp) const;
104
105   bool DisableHardwareWatchpoint(const NativeBreakpointDarwin *wp) const;
106
107   uint32_t GetNumberOfSupportedHardwareWatchpoints() const;
108
109   size_t GetThreadIndexForThreadStoppedWithSignal(const int signo) const;
110
111   NativeThreadDarwinSP GetThreadByID(lldb::tid_t tid) const;
112
113   NativeThreadDarwinSP
114   GetThreadByMachPortNumber(::thread_t mach_port_number) const;
115
116   lldb::tid_t GetThreadIDByMachPortNumber(::thread_t mach_port_number) const;
117
118   thread_t GetMachPortNumberByThreadID(lldb::tid_t globally_unique_id) const;
119
120 protected:
121   typedef std::vector<NativeThreadDarwinSP> collection;
122   typedef collection::iterator iterator;
123   typedef collection::const_iterator const_iterator;
124
125   // Consider having this return an lldb_private::Status.
126   uint32_t UpdateThreadList(NativeProcessDarwin &process, bool update,
127                             collection *num_threads = nullptr);
128
129   collection m_threads;
130   mutable std::recursive_mutex m_threads_mutex;
131   NativeThreadDarwinSP m_current_thread;
132   bool m_is_64_bit;
133 };
134
135 } // namespace process_darwin
136 } // namespace lldb_private
137
138 #endif // #ifndef __NativeThreadListDarwin_h__