blob: 379d7ea97918e622ad750dad8bf88783a61ced9a [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
Johnny Chen9ed5b492012-01-05 21:48:15 +000037 CreateInstance(lldb_private::Target& target,
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 //------------------------------------------------------------------
56 ProcessFreeBSD(lldb_private::Target& target,
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
63 WillResume();
64
Johnny Chen9ed5b492012-01-05 21:48:15 +000065 //------------------------------------------------------------------
66 // PluginInterface protocol
67 //------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +000068 virtual lldb_private::ConstString
Johnny Chen9ed5b492012-01-05 21:48:15 +000069 GetPluginName();
70
Johnny Chen9ed5b492012-01-05 21:48:15 +000071 virtual uint32_t
72 GetPluginVersion();
73
74 virtual void
75 GetPluginCommandHelp(const char *command, lldb_private::Stream *strm);
76
77 virtual lldb_private::Error
78 ExecutePluginCommand(lldb_private::Args &command,
79 lldb_private::Stream *strm);
80
81 virtual lldb_private::Log *
82 EnablePluginLogging(lldb_private::Stream *strm,
83 lldb_private::Args &command);
84
Ed Mastefe5a6422015-07-28 15:45:57 +000085public:
86 //------------------------------------------------------------------
87 // Process protocol.
88 //------------------------------------------------------------------
89 void
90 Finalize() override;
91
92 bool
93 CanDebug(lldb_private::Target &target, bool plugin_specified_by_name) override;
94
95 lldb_private::Error
96 WillLaunch(lldb_private::Module *module) override;
97
98 lldb_private::Error
99 DoAttachToProcessWithID (lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info) override;
100
101 lldb_private::Error
102 DoLaunch (lldb_private::Module *exe_module,
103 lldb_private::ProcessLaunchInfo &launch_info) override;
104
105 void
106 DidLaunch() override;
107
108 lldb_private::Error
109 DoResume() override;
110
111 lldb_private::Error
112 DoHalt(bool &caused_stop) override;
113
114 lldb_private::Error
115 DoDetach(bool keep_stopped) override;
116
117 lldb_private::Error
118 DoSignal(int signal) override;
119
120 lldb_private::Error
121 DoDestroy() override;
122
123 void
124 DoDidExec() override;
125
126 void
127 RefreshStateAfterStop() override;
128
129 bool
130 IsAlive() override;
131
132 size_t
133 DoReadMemory(lldb::addr_t vm_addr,
134 void *buf,
135 size_t size,
136 lldb_private::Error &error) override;
137
138 size_t
139 DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
140 lldb_private::Error &error) override;
141
142 lldb::addr_t
143 DoAllocateMemory(size_t size, uint32_t permissions,
144 lldb_private::Error &error) override;
145
146 lldb_private::Error
147 DoDeallocateMemory(lldb::addr_t ptr) override;
148
149 virtual size_t
150 GetSoftwareBreakpointTrapOpcode(lldb_private::BreakpointSite* bp_site);
151
152 lldb_private::Error
153 EnableBreakpointSite(lldb_private::BreakpointSite *bp_site) override;
154
155 lldb_private::Error
156 DisableBreakpointSite(lldb_private::BreakpointSite *bp_site) override;
157
158 lldb_private::Error
159 EnableWatchpoint(lldb_private::Watchpoint *wp, bool notify = true) override;
160
161 lldb_private::Error
162 DisableWatchpoint(lldb_private::Watchpoint *wp, bool notify = true) override;
163
164 lldb_private::Error
165 GetWatchpointSupportInfo(uint32_t &num) override;
166
167 lldb_private::Error
168 GetWatchpointSupportInfo(uint32_t &num, bool &after) override;
169
170 virtual uint32_t
171 UpdateThreadListIfNeeded();
172
173 bool
174 UpdateThreadList(lldb_private::ThreadList &old_thread_list,
175 lldb_private::ThreadList &new_thread_list) override;
176
177 virtual lldb::ByteOrder
178 GetByteOrder() const;
179
180 lldb::addr_t
181 GetImageInfoAddress() override;
182
183 size_t
184 PutSTDIN(const char *buf, size_t len, lldb_private::Error &error) override;
185
186 const lldb::DataBufferSP
187 GetAuxvData () override;
188
189 //--------------------------------------------------------------------------
190 // ProcessFreeBSD internal API.
191
192 /// Registers the given message with this process.
193 virtual void
194 SendMessage(const ProcessMessage &message);
195
196 ProcessMonitor &
197 GetMonitor() { assert(m_monitor); return *m_monitor; }
198
199 lldb_private::FileSpec
200 GetFileSpec(const lldb_private::FileAction *file_action,
201 const lldb_private::FileSpec &default_file_spec,
202 const lldb_private::FileSpec &dbg_pts_file_spec);
203
204 /// Adds the thread to the list of threads for which we have received the initial stopping signal.
205 /// The \p stop_tid parameter indicates the thread which the stop happened for.
206 bool
207 AddThreadForInitialStopIfNeeded(lldb::tid_t stop_tid);
208
209 bool
210 WaitingForInitialStop(lldb::tid_t stop_tid);
211
212 virtual FreeBSDThread *
213 CreateNewFreeBSDThread(lldb_private::Process &process, lldb::tid_t tid);
214
Ed Maste7fd845c2013-12-09 15:51:17 +0000215protected:
Ed Mastefe5a6422015-07-28 15:45:57 +0000216 /// Target byte order.
217 lldb::ByteOrder m_byte_order;
218
219 /// Process monitor;
220 ProcessMonitor *m_monitor;
221
222 /// The module we are executing.
223 lldb_private::Module *m_module;
224
225 /// Message queue notifying this instance of inferior process state changes.
226 lldb_private::Mutex m_message_mutex;
227 std::queue<ProcessMessage> m_message_queue;
228
229 /// Drive any exit events to completion.
230 bool m_exit_now;
231
232 /// Returns true if the process has exited.
233 bool HasExited();
234
235 /// Returns true if the process is stopped.
236 bool IsStopped();
237
238 /// Returns true if at least one running is currently running
239 bool IsAThreadRunning();
240
241 typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
242 MMapMap m_addr_to_mmap_size;
243
244 typedef std::set<lldb::tid_t> ThreadStopSet;
245 /// Every thread begins with a stop signal. This keeps track
246 /// of the threads for which we have received the stop signal.
247 ThreadStopSet m_seen_initial_stop;
248
Ed Maste7fd845c2013-12-09 15:51:17 +0000249 friend class FreeBSDThread;
250
251 typedef std::vector<lldb::tid_t> tid_collection;
252 tid_collection m_suspend_tids;
253 tid_collection m_run_tids;
254 tid_collection m_step_tids;
255
256 int m_resume_signo;
257
Johnny Chen9ed5b492012-01-05 21:48:15 +0000258};
259
Ed Masteea660072013-12-04 13:41:18 +0000260#endif // liblldb_ProcessFreeBSD_H_