1 //===-- NativeThreadDarwin.h ---------------------------------- -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef NativeThreadDarwin_H
11 #define NativeThreadDarwin_H
14 #include <mach/mach_types.h>
16 #include <sys/proc_info.h>
24 #include "lldb/Host/common/NativeThreadProtocol.h"
25 #include "lldb/lldb-private-forward.h"
27 #include "MachException.h"
29 namespace lldb_private {
30 namespace process_darwin {
32 class NativeProcessDarwin;
33 using NativeProcessDarwinSP = std::shared_ptr<NativeProcessDarwin>;
35 class NativeThreadListDarwin;
37 class NativeThreadDarwin : public NativeThreadProtocol {
38 friend class NativeProcessDarwin;
39 friend class NativeThreadListDarwin;
43 GetGloballyUniqueThreadIDForMachPortID(::thread_t mach_port_id);
45 NativeThreadDarwin(NativeProcessDarwin *process, bool is_64_bit,
46 lldb::tid_t unique_thread_id = 0,
47 ::thread_t mach_thread_port = 0);
49 // -----------------------------------------------------------------
50 // NativeThreadProtocol Interface
51 // -----------------------------------------------------------------
52 std::string GetName() override;
54 lldb::StateType GetState() override;
56 bool GetStopReason(ThreadStopInfo &stop_info,
57 std::string &description) override;
59 NativeRegisterContextSP GetRegisterContext() override;
61 Status SetWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags,
62 bool hardware) override;
64 Status RemoveWatchpoint(lldb::addr_t addr) override;
66 // -----------------------------------------------------------------
67 // New methods that are fine for others to call.
68 // -----------------------------------------------------------------
69 void Dump(Stream &stream) const;
72 // -----------------------------------------------------------------
73 // Interface for friend classes
74 // -----------------------------------------------------------------
76 /// Resumes the thread. If @p signo is anything but
77 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
78 Status Resume(uint32_t signo);
80 /// Single steps the thread. If @p signo is anything but
81 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
82 Status SingleStep(uint32_t signo);
84 bool NotifyException(MachException::Data &exc);
86 bool ShouldStop(bool &step_more) const;
90 void SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr);
92 /// Return true if the thread is stopped.
93 /// If stopped by a signal, indicate the signo in the signo
94 /// argument. Otherwise, return LLDB_INVALID_SIGNAL_NUMBER.
95 bool IsStopped(int *signo);
97 const struct thread_basic_info *GetBasicInfo() const;
99 static bool GetBasicInfo(::thread_t thread,
100 struct thread_basic_info *basicInfoPtr);
102 bool IsUserReady() const;
104 void SetStoppedByExec();
106 void SetStoppedByBreakpoint();
108 void SetStoppedByWatchpoint(uint32_t wp_index);
110 bool IsStoppedAtBreakpoint();
112 bool IsStoppedAtWatchpoint();
114 void SetStoppedByTrace();
116 void SetStoppedWithNoReason();
120 Status RequestStop();
122 // -------------------------------------------------------------------------
123 /// Return the mach thread port number for this thread.
126 /// The mach port number for this thread. Returns NULL_THREAD
127 /// when the thread is invalid.
128 // -------------------------------------------------------------------------
129 thread_t GetMachPortNumber() const { return m_mach_thread_port; }
131 static bool MachPortNumberIsValid(::thread_t thread);
133 // ---------------------------------------------------------------------
135 // ---------------------------------------------------------------------
136 bool GetIdentifierInfo();
138 void MaybeLogStateChange(lldb::StateType new_state);
140 NativeProcessDarwinSP GetNativeProcessDarwinSP();
144 inline void MaybePrepareSingleStepWorkaround();
146 inline void MaybeCleanupSingleStepWorkaround();
148 // -----------------------------------------------------------------
150 // -----------------------------------------------------------------
152 // The mach thread port for the thread.
153 ::thread_t m_mach_thread_port;
155 // The most recently-retrieved thread basic info.
156 mutable ::thread_basic_info m_basic_info;
158 struct proc_threadinfo m_proc_threadinfo;
160 thread_identifier_info_data_t m_ident_info;
163 lldb::StateType m_state;
164 ThreadStopInfo m_stop_info;
165 NativeRegisterContextSP m_reg_context_sp;
166 std::string m_stop_description;
167 using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>;
168 WatchpointIndexMap m_watchpoint_index_map;
169 // cpu_set_t m_original_cpu_set; // For single-step workaround.
173 typedef std::shared_ptr<NativeThreadDarwin> NativeThreadDarwinSP;
175 } // namespace process_darwin
176 } // namespace lldb_private
178 #endif // #ifndef NativeThreadDarwin_H