]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / source / Plugins / Process / FreeBSD / ProcessFreeBSD.h
1 //===-- ProcessFreeBSD.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 #ifndef liblldb_ProcessFreeBSD_H_
11 #define liblldb_ProcessFreeBSD_H_
12
13 #include "Plugins/Process/POSIX/ProcessMessage.h"
14 #include "lldb/Target/Process.h"
15 #include "lldb/Target/ThreadList.h"
16 #include <mutex>
17 #include <queue>
18 #include <set>
19
20 class ProcessMonitor;
21 class FreeBSDThread;
22
23 class ProcessFreeBSD : public lldb_private::Process {
24
25 public:
26   // Static functions.
27   static lldb::ProcessSP
28   CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
29                  const lldb_private::FileSpec *crash_file_path);
30
31   static void Initialize();
32
33   static void Terminate();
34
35   static lldb_private::ConstString GetPluginNameStatic();
36
37   static const char *GetPluginDescriptionStatic();
38
39   // Constructors and destructors
40   ProcessFreeBSD(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
41                  lldb::UnixSignalsSP &unix_signals_sp);
42
43   ~ProcessFreeBSD();
44
45   virtual lldb_private::Status WillResume() override;
46
47   // PluginInterface protocol
48   virtual lldb_private::ConstString GetPluginName() override;
49
50   virtual uint32_t GetPluginVersion() override;
51
52 public:
53   // Process protocol.
54   void Finalize() override;
55
56   bool CanDebug(lldb::TargetSP target_sp,
57                 bool plugin_specified_by_name) override;
58
59   lldb_private::Status WillLaunch(lldb_private::Module *module) override;
60
61   lldb_private::Status DoAttachToProcessWithID(
62       lldb::pid_t pid,
63       const lldb_private::ProcessAttachInfo &attach_info) override;
64
65   lldb_private::Status
66   DoLaunch(lldb_private::Module *exe_module,
67            lldb_private::ProcessLaunchInfo &launch_info) override;
68
69   void DidLaunch() override;
70
71   lldb_private::Status DoResume() override;
72
73   lldb_private::Status DoHalt(bool &caused_stop) override;
74
75   lldb_private::Status DoDetach(bool keep_stopped) override;
76
77   lldb_private::Status DoSignal(int signal) override;
78
79   lldb_private::Status DoDestroy() override;
80
81   void DoDidExec() override;
82
83   void RefreshStateAfterStop() override;
84
85   bool IsAlive() override;
86
87   size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
88                       lldb_private::Status &error) override;
89
90   size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
91                        lldb_private::Status &error) override;
92
93   lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions,
94                                 lldb_private::Status &error) override;
95
96   lldb_private::Status DoDeallocateMemory(lldb::addr_t ptr) override;
97
98   virtual size_t
99   GetSoftwareBreakpointTrapOpcode(lldb_private::BreakpointSite *bp_site);
100
101   lldb_private::Status
102   EnableBreakpointSite(lldb_private::BreakpointSite *bp_site) override;
103
104   lldb_private::Status
105   DisableBreakpointSite(lldb_private::BreakpointSite *bp_site) override;
106
107   lldb_private::Status EnableWatchpoint(lldb_private::Watchpoint *wp,
108                                         bool notify = true) override;
109
110   lldb_private::Status DisableWatchpoint(lldb_private::Watchpoint *wp,
111                                          bool notify = true) override;
112
113   lldb_private::Status GetWatchpointSupportInfo(uint32_t &num) override;
114
115   lldb_private::Status GetWatchpointSupportInfo(uint32_t &num,
116                                                 bool &after) override;
117
118   virtual uint32_t UpdateThreadListIfNeeded();
119
120   bool UpdateThreadList(lldb_private::ThreadList &old_thread_list,
121                         lldb_private::ThreadList &new_thread_list) override;
122
123   virtual lldb::ByteOrder GetByteOrder() const;
124
125   lldb::addr_t GetImageInfoAddress() override;
126
127   size_t PutSTDIN(const char *buf, size_t len,
128                   lldb_private::Status &error) override;
129
130   lldb_private::DataExtractor GetAuxvData() override;
131
132   // ProcessFreeBSD internal API.
133
134   /// Registers the given message with this process.
135   virtual void SendMessage(const ProcessMessage &message);
136
137   ProcessMonitor &GetMonitor() {
138     assert(m_monitor);
139     return *m_monitor;
140   }
141
142   lldb_private::FileSpec
143   GetFileSpec(const lldb_private::FileAction *file_action,
144               const lldb_private::FileSpec &default_file_spec,
145               const lldb_private::FileSpec &dbg_pts_file_spec);
146
147   /// Adds the thread to the list of threads for which we have received the
148   /// initial stopping signal.
149   /// The \p stop_tid parameter indicates the thread which the stop happened
150   /// for.
151   bool AddThreadForInitialStopIfNeeded(lldb::tid_t stop_tid);
152
153   bool WaitingForInitialStop(lldb::tid_t stop_tid);
154
155   virtual FreeBSDThread *CreateNewFreeBSDThread(lldb_private::Process &process,
156                                                 lldb::tid_t tid);
157
158   static bool SingleStepBreakpointHit(
159       void *baton, lldb_private::StoppointCallbackContext *context,
160       lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
161
162   lldb_private::Status SetupSoftwareSingleStepping(lldb::tid_t tid);
163
164   lldb_private::Status SetSoftwareSingleStepBreakpoint(lldb::tid_t tid,
165                                                        lldb::addr_t addr);
166
167   bool IsSoftwareStepBreakpoint(lldb::tid_t tid);
168
169   bool SupportHardwareSingleStepping() const;
170
171   typedef std::vector<lldb::tid_t> tid_collection;
172   tid_collection &GetStepTids() { return m_step_tids; }
173
174 protected:
175   static const size_t MAX_TRAP_OPCODE_SIZE = 8;
176
177   /// Target byte order.
178   lldb::ByteOrder m_byte_order;
179
180   /// Process monitor;
181   ProcessMonitor *m_monitor;
182
183   /// The module we are executing.
184   lldb_private::Module *m_module;
185
186   /// Message queue notifying this instance of inferior process state changes.
187   std::recursive_mutex m_message_mutex;
188   std::queue<ProcessMessage> m_message_queue;
189
190   /// Drive any exit events to completion.
191   bool m_exit_now;
192
193   /// Returns true if the process has exited.
194   bool HasExited();
195
196   /// Returns true if the process is stopped.
197   bool IsStopped();
198
199   /// Returns true if at least one running is currently running
200   bool IsAThreadRunning();
201
202   typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
203   MMapMap m_addr_to_mmap_size;
204
205   typedef std::set<lldb::tid_t> ThreadStopSet;
206   /// Every thread begins with a stop signal. This keeps track
207   /// of the threads for which we have received the stop signal.
208   ThreadStopSet m_seen_initial_stop;
209
210   friend class FreeBSDThread;
211
212   tid_collection m_suspend_tids;
213   tid_collection m_run_tids;
214   tid_collection m_step_tids;
215   std::map<lldb::tid_t, lldb::break_id_t> m_threads_stepping_with_breakpoint;
216
217   int m_resume_signo;
218 };
219
220 #endif // liblldb_ProcessFreeBSD_H_