blob: 5f9365418d7af14bf356f3737b72ee2bc0fa01d4 [file] [log] [blame]
Johnny Chen9ed5b492012-01-05 21:48:15 +00001//===-- ProcessFreeBSD.h ------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_ProcessFreeBSD_H_
11#define liblldb_ProcessFreeBSD_H_
12
13// C Includes
14
15// C++ Includes
Ed Mastefe5a6422015-07-28 15:45:57 +000016#include <set>
Johnny Chen9ed5b492012-01-05 21:48:15 +000017#include <queue>
18
19// Other libraries and framework includes
20#include "lldb/Target/Process.h"
21#include "lldb/Target/ThreadList.h"
22#include "ProcessMessage.h"
Ed Mastefe5a6422015-07-28 15:45:57 +000023#include "ProcessFreeBSD.h"
Johnny Chen9ed5b492012-01-05 21:48:15 +000024
25class ProcessMonitor;
Ed Mastefe5a6422015-07-28 15:45:57 +000026class FreeBSDThread;
Johnny Chen9ed5b492012-01-05 21:48:15 +000027
28class ProcessFreeBSD :
Ed Mastefe5a6422015-07-28 15:45:57 +000029 public lldb_private::Process
Johnny Chen9ed5b492012-01-05 21:48:15 +000030{
31
32public:
33 //------------------------------------------------------------------
34 // Static functions.
35 //------------------------------------------------------------------
Greg Clayton29d19302012-02-27 18:40:48 +000036 static lldb::ProcessSP
Zachary Turner12004eb2015-09-02 16:47:47 +000037 CreateInstance(lldb::TargetSP target_sp,
Greg Clayton29d19302012-02-27 18:40:48 +000038 lldb_private::Listener &listener,
39 const lldb_private::FileSpec *crash_file_path);
Johnny Chen9ed5b492012-01-05 21:48:15 +000040
41 static void
42 Initialize();
43
44 static void
45 Terminate();
46
Greg Clayton57abc5d2013-05-10 21:47:16 +000047 static lldb_private::ConstString
Johnny Chen9ed5b492012-01-05 21:48:15 +000048 GetPluginNameStatic();
49
50 static const char *
51 GetPluginDescriptionStatic();
52
53 //------------------------------------------------------------------
54 // Constructors and destructors
55 //------------------------------------------------------------------
Zachary Turner12004eb2015-09-02 16:47:47 +000056 ProcessFreeBSD(lldb::TargetSP target_sp,
Ed Mastefe5a6422015-07-28 15:45:57 +000057 lldb_private::Listener &listener,
58 lldb::UnixSignalsSP &unix_signals_sp);
Johnny Chen9ed5b492012-01-05 21:48:15 +000059
Ed Mastefe5a6422015-07-28 15:45:57 +000060 ~ProcessFreeBSD();
Ed Maste7fd845c2013-12-09 15:51:17 +000061
62 virtual lldb_private::Error
Davide Italiano7769b4a2015-11-04 23:12:17 +000063 WillResume() override;
Ed Maste7fd845c2013-12-09 15:51:17 +000064
Johnny Chen9ed5b492012-01-05 21:48:15 +000065 //------------------------------------------------------------------
66 // PluginInterface protocol
67 //------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +000068 virtual lldb_private::ConstString
Davide Italiano7769b4a2015-11-04 23:12:17 +000069 GetPluginName() override;
Johnny Chen9ed5b492012-01-05 21:48:15 +000070
Johnny Chen9ed5b492012-01-05 21:48:15 +000071 virtual uint32_t
Davide Italiano7769b4a2015-11-04 23:12:17 +000072 GetPluginVersion() override;
Johnny Chen9ed5b492012-01-05 21:48:15 +000073
Ed Mastefe5a6422015-07-28 15:45:57 +000074public:
75 //------------------------------------------------------------------
76 // Process protocol.
77 //------------------------------------------------------------------
78 void
79 Finalize() override;
80
81 bool
Zachary Turner12004eb2015-09-02 16:47:47 +000082 CanDebug(lldb::TargetSP target_sp, bool plugin_specified_by_name) override;
Ed Mastefe5a6422015-07-28 15:45:57 +000083
84 lldb_private::Error
85 WillLaunch(lldb_private::Module *module) override;
86
87 lldb_private::Error
88 DoAttachToProcessWithID (lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info) override;
89
90 lldb_private::Error
Ed Maste81b4c5f2016-01-04 01:43:47 +000091 DoLaunch (lldb_private::Module *exe_module,
Ed Mastefe5a6422015-07-28 15:45:57 +000092 lldb_private::ProcessLaunchInfo &launch_info) override;
93
94 void
95 DidLaunch() override;
96
97 lldb_private::Error
98 DoResume() override;
99
100 lldb_private::Error
101 DoHalt(bool &caused_stop) override;
102
103 lldb_private::Error
104 DoDetach(bool keep_stopped) override;
105
106 lldb_private::Error
107 DoSignal(int signal) override;
108
109 lldb_private::Error
110 DoDestroy() override;
111
112 void
113 DoDidExec() override;
114
115 void
116 RefreshStateAfterStop() override;
117
118 bool
119 IsAlive() override;
120
121 size_t
122 DoReadMemory(lldb::addr_t vm_addr,
123 void *buf,
124 size_t size,
125 lldb_private::Error &error) override;
126
127 size_t
128 DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
129 lldb_private::Error &error) override;
130
131 lldb::addr_t
132 DoAllocateMemory(size_t size, uint32_t permissions,
133 lldb_private::Error &error) override;
134
135 lldb_private::Error
136 DoDeallocateMemory(lldb::addr_t ptr) override;
137
138 virtual size_t
139 GetSoftwareBreakpointTrapOpcode(lldb_private::BreakpointSite* bp_site);
140
141 lldb_private::Error
142 EnableBreakpointSite(lldb_private::BreakpointSite *bp_site) override;
143
144 lldb_private::Error
145 DisableBreakpointSite(lldb_private::BreakpointSite *bp_site) override;
146
147 lldb_private::Error
148 EnableWatchpoint(lldb_private::Watchpoint *wp, bool notify = true) override;
149
150 lldb_private::Error
151 DisableWatchpoint(lldb_private::Watchpoint *wp, bool notify = true) override;
152
153 lldb_private::Error
154 GetWatchpointSupportInfo(uint32_t &num) override;
155
156 lldb_private::Error
157 GetWatchpointSupportInfo(uint32_t &num, bool &after) override;
158
159 virtual uint32_t
160 UpdateThreadListIfNeeded();
161
162 bool
Ed Maste81b4c5f2016-01-04 01:43:47 +0000163 UpdateThreadList(lldb_private::ThreadList &old_thread_list,
Ed Mastefe5a6422015-07-28 15:45:57 +0000164 lldb_private::ThreadList &new_thread_list) override;
165
166 virtual lldb::ByteOrder
167 GetByteOrder() const;
168
169 lldb::addr_t
170 GetImageInfoAddress() override;
171
172 size_t
173 PutSTDIN(const char *buf, size_t len, lldb_private::Error &error) override;
174
175 const lldb::DataBufferSP
176 GetAuxvData () override;
177
178 //--------------------------------------------------------------------------
179 // ProcessFreeBSD internal API.
180
181 /// Registers the given message with this process.
182 virtual void
183 SendMessage(const ProcessMessage &message);
184
185 ProcessMonitor &
186 GetMonitor() { assert(m_monitor); return *m_monitor; }
187
188 lldb_private::FileSpec
189 GetFileSpec(const lldb_private::FileAction *file_action,
190 const lldb_private::FileSpec &default_file_spec,
191 const lldb_private::FileSpec &dbg_pts_file_spec);
192
193 /// Adds the thread to the list of threads for which we have received the initial stopping signal.
194 /// The \p stop_tid parameter indicates the thread which the stop happened for.
195 bool
196 AddThreadForInitialStopIfNeeded(lldb::tid_t stop_tid);
197
198 bool
199 WaitingForInitialStop(lldb::tid_t stop_tid);
200
201 virtual FreeBSDThread *
202 CreateNewFreeBSDThread(lldb_private::Process &process, lldb::tid_t tid);
203
Ed Maste7fd845c2013-12-09 15:51:17 +0000204protected:
Ed Mastefe5a6422015-07-28 15:45:57 +0000205 /// Target byte order.
206 lldb::ByteOrder m_byte_order;
207
208 /// Process monitor;
209 ProcessMonitor *m_monitor;
210
211 /// The module we are executing.
212 lldb_private::Module *m_module;
213
214 /// Message queue notifying this instance of inferior process state changes.
215 lldb_private::Mutex m_message_mutex;
216 std::queue<ProcessMessage> m_message_queue;
217
218 /// Drive any exit events to completion.
219 bool m_exit_now;
220
221 /// Returns true if the process has exited.
222 bool HasExited();
223
224 /// Returns true if the process is stopped.
225 bool IsStopped();
226
227 /// Returns true if at least one running is currently running
228 bool IsAThreadRunning();
229
230 typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
231 MMapMap m_addr_to_mmap_size;
232
233 typedef std::set<lldb::tid_t> ThreadStopSet;
234 /// Every thread begins with a stop signal. This keeps track
235 /// of the threads for which we have received the stop signal.
236 ThreadStopSet m_seen_initial_stop;
237
Ed Maste7fd845c2013-12-09 15:51:17 +0000238 friend class FreeBSDThread;
239
240 typedef std::vector<lldb::tid_t> tid_collection;
241 tid_collection m_suspend_tids;
242 tid_collection m_run_tids;
243 tid_collection m_step_tids;
244
245 int m_resume_signo;
246
Johnny Chen9ed5b492012-01-05 21:48:15 +0000247};
248
Ed Masteea660072013-12-04 13:41:18 +0000249#endif // liblldb_ProcessFreeBSD_H_