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