blob: beacb0186c6511b77cf66d36204dbb5f7eecf841 [file] [log] [blame]
Johnny Chen9ed5b492012-01-05 21:48:15 +00001//===-- ProcessPOSIX.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_ProcessPOSIX_H_
11#define liblldb_ProcessPOSIX_H_
12
13// C Includes
14
15// C++ Includes
16#include <queue>
Matt Kopecb2910442013-07-09 15:09:45 +000017#include <set>
Johnny Chen9ed5b492012-01-05 21:48:15 +000018
19// Other libraries and framework includes
20#include "lldb/Target/Process.h"
21#include "lldb/Target/UnixSignals.h"
22#include "ProcessMessage.h"
23
24class ProcessMonitor;
Michael Sartain9f822cd2013-07-31 23:27:46 +000025class POSIXThread;
Johnny Chen9ed5b492012-01-05 21:48:15 +000026
27class ProcessPOSIX :
28 public lldb_private::Process
29{
30public:
31
32 //------------------------------------------------------------------
33 // Constructors and destructors
34 //------------------------------------------------------------------
35 ProcessPOSIX(lldb_private::Target& target,
36 lldb_private::Listener &listener);
37
38 virtual
39 ~ProcessPOSIX();
40
41 //------------------------------------------------------------------
42 // Process protocol.
43 //------------------------------------------------------------------
Andrew Kaylorbc68b432013-07-10 21:57:27 +000044 virtual void
45 Finalize();
46
Johnny Chen9ed5b492012-01-05 21:48:15 +000047 virtual bool
48 CanDebug(lldb_private::Target &target, bool plugin_specified_by_name);
49
50 virtual lldb_private::Error
51 WillLaunch(lldb_private::Module *module);
52
53 virtual lldb_private::Error
54 DoAttachToProcessWithID(lldb::pid_t pid);
55
56 virtual lldb_private::Error
Greg Claytone2186ed2012-09-07 17:51:47 +000057 DoAttachToProcessWithID (lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info);
58
59 virtual lldb_private::Error
Johnny Chen9ed5b492012-01-05 21:48:15 +000060 DoLaunch (lldb_private::Module *exe_module,
Jean-Daniel Dupas7782de92013-12-09 22:52:50 +000061 lldb_private::ProcessLaunchInfo &launch_info);
Johnny Chen9ed5b492012-01-05 21:48:15 +000062
63 virtual void
64 DidLaunch();
65
66 virtual lldb_private::Error
Ed Maste30df85e2013-12-11 20:43:27 +000067 DoResume();
Johnny Chen9ed5b492012-01-05 21:48:15 +000068
69 virtual lldb_private::Error
70 DoHalt(bool &caused_stop);
71
72 virtual lldb_private::Error
Ed Maste7dcb77d2013-08-30 13:11:30 +000073 DoDetach(bool keep_stopped) = 0;
Johnny Chen9ed5b492012-01-05 21:48:15 +000074
75 virtual lldb_private::Error
76 DoSignal(int signal);
77
78 virtual lldb_private::Error
79 DoDestroy();
80
81 virtual void
Matt Kopec718be872013-10-09 19:39:55 +000082 DoDidExec();
83
84 virtual void
Johnny Chen9ed5b492012-01-05 21:48:15 +000085 RefreshStateAfterStop();
86
87 virtual bool
88 IsAlive();
89
90 virtual size_t
91 DoReadMemory(lldb::addr_t vm_addr,
92 void *buf,
93 size_t size,
94 lldb_private::Error &error);
95
96 virtual size_t
97 DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
98 lldb_private::Error &error);
99
100 virtual lldb::addr_t
101 DoAllocateMemory(size_t size, uint32_t permissions,
102 lldb_private::Error &error);
103
104 virtual lldb_private::Error
105 DoDeallocateMemory(lldb::addr_t ptr);
106
Matt Kopec00049b82013-02-27 20:13:38 +0000107 virtual lldb::addr_t
108 ResolveIndirectFunction(const lldb_private::Address *address, lldb_private::Error &error);
109
Johnny Chen9ed5b492012-01-05 21:48:15 +0000110 virtual size_t
111 GetSoftwareBreakpointTrapOpcode(lldb_private::BreakpointSite* bp_site);
112
113 virtual lldb_private::Error
Daniel Maleab7eec012013-02-15 20:23:25 +0000114 EnableBreakpointSite(lldb_private::BreakpointSite *bp_site);
Johnny Chen9ed5b492012-01-05 21:48:15 +0000115
116 virtual lldb_private::Error
Daniel Maleab7eec012013-02-15 20:23:25 +0000117 DisableBreakpointSite(lldb_private::BreakpointSite *bp_site);
Johnny Chen9ed5b492012-01-05 21:48:15 +0000118
Matt Kopece9ea0da2013-05-07 19:29:28 +0000119 virtual lldb_private::Error
120 EnableWatchpoint(lldb_private::Watchpoint *wp, bool notify = true);
121
122 virtual lldb_private::Error
123 DisableWatchpoint(lldb_private::Watchpoint *wp, bool notify = true);
124
125 virtual lldb_private::Error
126 GetWatchpointSupportInfo(uint32_t &num);
127
128 virtual lldb_private::Error
129 GetWatchpointSupportInfo(uint32_t &num, bool &after);
130
Johnny Chen9ed5b492012-01-05 21:48:15 +0000131 virtual uint32_t
132 UpdateThreadListIfNeeded();
133
Greg Claytonc3c0b0e2012-04-12 19:04:34 +0000134 virtual bool
Johnny Chen9ed5b492012-01-05 21:48:15 +0000135 UpdateThreadList(lldb_private::ThreadList &old_thread_list,
136 lldb_private::ThreadList &new_thread_list) = 0;
137
138 virtual lldb::ByteOrder
139 GetByteOrder() const;
140
141 virtual lldb::addr_t
142 GetImageInfoAddress();
143
144 virtual size_t
145 PutSTDIN(const char *buf, size_t len, lldb_private::Error &error);
146
Johnny Chen9ed5b492012-01-05 21:48:15 +0000147 //--------------------------------------------------------------------------
148 // ProcessPOSIX internal API.
149
150 /// Registers the given message with this process.
Ed Maste7fd845c2013-12-09 15:51:17 +0000151 virtual void
Ed Maste30df85e2013-12-11 20:43:27 +0000152 SendMessage(const ProcessMessage &message);
Johnny Chen9ed5b492012-01-05 21:48:15 +0000153
154 ProcessMonitor &
155 GetMonitor() { assert(m_monitor); return *m_monitor; }
156
157 lldb_private::UnixSignals &
158 GetUnixSignals();
159
160 const char *
161 GetFilePath(const lldb_private::ProcessLaunchInfo::FileAction *file_action,
162 const char *default_path);
163
Andrew Kaylor93132f52013-05-28 23:04:25 +0000164 /// Stops all threads in the process.
165 /// The \p stop_tid parameter indicates the thread which initiated the stop.
166 virtual void
167 StopAllThreads(lldb::tid_t stop_tid);
168
Matt Kopecb2910442013-07-09 15:09:45 +0000169 /// Adds the thread to the list of threads for which we have received the initial stopping signal.
170 /// The \p stop_tid paramter indicates the thread which the stop happened for.
171 bool
172 AddThreadForInitialStopIfNeeded(lldb::tid_t stop_tid);
173
Andrew Kaylord4d54992013-09-17 00:30:24 +0000174 bool
175 WaitingForInitialStop(lldb::tid_t stop_tid);
176
Michael Sartain9f822cd2013-07-31 23:27:46 +0000177 virtual POSIXThread *
178 CreateNewPOSIXThread(lldb_private::Process &process, lldb::tid_t tid);
179
Johnny Chen9ed5b492012-01-05 21:48:15 +0000180protected:
181 /// Target byte order.
182 lldb::ByteOrder m_byte_order;
183
184 /// Process monitor;
185 ProcessMonitor *m_monitor;
186
187 /// The module we are executing.
188 lldb_private::Module *m_module;
189
190 /// Message queue notifying this instance of inferior process state changes.
191 lldb_private::Mutex m_message_mutex;
192 std::queue<ProcessMessage> m_message_queue;
193
Johnny Chen9ed5b492012-01-05 21:48:15 +0000194 /// Drive any exit events to completion.
195 bool m_exit_now;
196
197 /// OS-specific signal set.
198 lldb_private::UnixSignals m_signals;
199
200 /// Returns true if the process has exited.
201 bool HasExited();
202
203 /// Returns true if the process is stopped.
204 bool IsStopped();
205
Matt Kopecb2910442013-07-09 15:09:45 +0000206 /// Returns true if at least one running is currently running
207 bool IsAThreadRunning();
208
Johnny Chen9ed5b492012-01-05 21:48:15 +0000209 typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
210 MMapMap m_addr_to_mmap_size;
Matt Kopecb2910442013-07-09 15:09:45 +0000211
212 typedef std::set<lldb::tid_t> ThreadStopSet;
213 /// Every thread begins with a stop signal. This keeps track
214 /// of the threads for which we have received the stop signal.
215 ThreadStopSet m_seen_initial_stop;
Johnny Chen9ed5b492012-01-05 21:48:15 +0000216};
217
Johnny Chen9ed5b492012-01-05 21:48:15 +0000218#endif // liblldb_MacOSXProcess_H_