1 //===-- FreeBSDThread.h -----------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef liblldb_FreeBSDThread_H_
10 #define liblldb_FreeBSDThread_H_
11 
12 #include <memory>
13 #include <string>
14 
15 #include "RegisterContextPOSIX.h"
16 #include "lldb/Target/Thread.h"
17 
18 class ProcessMessage;
19 class ProcessMonitor;
20 class POSIXBreakpointProtocol;
21 
22 // @class FreeBSDThread
23 // Abstraction of a FreeBSD thread.
24 class FreeBSDThread : public lldb_private::Thread {
25 public:
26   // Constructors and destructors
27   FreeBSDThread(lldb_private::Process &process, lldb::tid_t tid);
28 
29   virtual ~FreeBSDThread();
30 
31   // POSIXThread
32   void RefreshStateAfterStop() override;
33 
34   // This notifies the thread when a private stop occurs.
35   void DidStop() override;
36 
37   const char *GetInfo() override;
38 
39   void SetName(const char *name) override;
40 
41   const char *GetName() override;
42 
43   lldb::RegisterContextSP GetRegisterContext() override;
44 
45   lldb::RegisterContextSP
46   CreateRegisterContextForFrame(lldb_private::StackFrame *frame) override;
47 
48   lldb::addr_t GetThreadPointer() override;
49 
50   // These functions provide a mapping from the register offset
51   // back to the register index or name for use in debugging or log
52   // output.
53 
54   unsigned GetRegisterIndexFromOffset(unsigned offset);
55 
56   const char *GetRegisterName(unsigned reg);
57 
58   const char *GetRegisterNameFromOffset(unsigned offset);
59 
60   // These methods form a specialized interface to POSIX threads.
61   //
62   bool Resume();
63 
64   void Notify(const ProcessMessage &message);
65 
66   // These methods provide an interface to watchpoints
67   //
68   bool EnableHardwareWatchpoint(lldb_private::Watchpoint *wp);
69 
70   bool DisableHardwareWatchpoint(lldb_private::Watchpoint *wp);
71 
72   uint32_t NumSupportedHardwareWatchpoints();
73 
74   uint32_t FindVacantWatchpointIndex();
75 
76 protected:
GetPOSIXBreakpointProtocol()77   POSIXBreakpointProtocol *GetPOSIXBreakpointProtocol() {
78     if (!m_reg_context_sp)
79       m_reg_context_sp = GetRegisterContext();
80     return m_posix_thread;
81   }
82 
83   std::unique_ptr<lldb_private::StackFrame> m_frame_up;
84 
85   lldb::BreakpointSiteSP m_breakpoint;
86 
87   bool m_thread_name_valid;
88   std::string m_thread_name;
89   POSIXBreakpointProtocol *m_posix_thread;
90 
91   ProcessMonitor &GetMonitor();
92 
93   bool CalculateStopInfo() override;
94 
95   void BreakNotify(const ProcessMessage &message);
96   void WatchNotify(const ProcessMessage &message);
97   virtual void TraceNotify(const ProcessMessage &message);
98   void LimboNotify(const ProcessMessage &message);
99   void SignalNotify(const ProcessMessage &message);
100   void SignalDeliveredNotify(const ProcessMessage &message);
101   void CrashNotify(const ProcessMessage &message);
102   void ExitNotify(const ProcessMessage &message);
103   void ExecNotify(const ProcessMessage &message);
104 
105   // FreeBSDThread internal API.
106 
107   // POSIXThread override
108   virtual void WillResume(lldb::StateType resume_state) override;
109 };
110 
111 #endif // #ifndef liblldb_FreeBSDThread_H_
112