blob: 1f67d54de63e83511a3d174214719b6c7a92b7be [file] [log] [blame]
Stephen Wilsonf6f40332010-07-24 02:19:04 +00001//===-- ProcessLinux.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_ProcessLinux_H_
11#define liblldb_ProcessLinux_H_
12
13// C Includes
14
15// C++ Includes
16#include <queue>
17
18// Other libraries and framework includes
19#include "lldb/Target/Process.h"
Stephen Wilson67d9f7e2011-03-30 15:55:52 +000020#include "LinuxSignals.h"
Stephen Wilsonf6f40332010-07-24 02:19:04 +000021#include "ProcessMessage.h"
22
23class ProcessMonitor;
24
25class ProcessLinux :
26 public lldb_private::Process
27{
28public:
29 //------------------------------------------------------------------
30 // Static functions.
31 //------------------------------------------------------------------
32 static Process*
33 CreateInstance(lldb_private::Target& target,
34 lldb_private::Listener &listener);
35
36 static void
37 Initialize();
38
39 static void
40 Terminate();
41
42 static const char *
43 GetPluginNameStatic();
44
45 static const char *
46 GetPluginDescriptionStatic();
47
48 //------------------------------------------------------------------
49 // Constructors and destructors
50 //------------------------------------------------------------------
51 ProcessLinux(lldb_private::Target& target,
52 lldb_private::Listener &listener);
53
54 virtual
55 ~ProcessLinux();
56
57 //------------------------------------------------------------------
58 // Process protocol.
59 //------------------------------------------------------------------
60 virtual bool
Peter Collingbourne47556982011-07-22 19:12:53 +000061 CanDebug(lldb_private::Target &target, bool plugin_specified_by_name);
Stephen Wilsonf6f40332010-07-24 02:19:04 +000062
63 virtual lldb_private::Error
Stephen Wilson92241ef2011-01-16 19:45:39 +000064 WillLaunch(lldb_private::Module *module);
65
66 virtual lldb_private::Error
Stephen Wilsonf6f40332010-07-24 02:19:04 +000067 DoAttachToProcessWithID(lldb::pid_t pid);
68
69 virtual lldb_private::Error
Greg Claytonce65d2f2011-11-05 01:09:16 +000070 DoLaunch (lldb_private::Module *exe_module,
71 const lldb_private::ProcessLaunchInfo &launch_info);
Stephen Wilsonf6f40332010-07-24 02:19:04 +000072
Stephen Wilson92241ef2011-01-16 19:45:39 +000073 virtual void
74 DidLaunch();
75
Stephen Wilsonf6f40332010-07-24 02:19:04 +000076 virtual lldb_private::Error
77 DoResume();
78
79 virtual lldb_private::Error
Stephen Wilson3a804312011-01-04 21:41:31 +000080 DoHalt(bool &caused_stop);
Stephen Wilsonf6f40332010-07-24 02:19:04 +000081
82 virtual lldb_private::Error
83 DoDetach();
84
85 virtual lldb_private::Error
86 DoSignal(int signal);
87
88 virtual lldb_private::Error
89 DoDestroy();
90
91 virtual void
92 RefreshStateAfterStop();
93
94 virtual bool
95 IsAlive();
96
97 virtual size_t
98 DoReadMemory(lldb::addr_t vm_addr,
99 void *buf,
100 size_t size,
101 lldb_private::Error &error);
102
103 virtual size_t
104 DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
105 lldb_private::Error &error);
106
107 virtual lldb::addr_t
108 DoAllocateMemory(size_t size, uint32_t permissions,
109 lldb_private::Error &error);
110
Stephen Wilsonf6f40332010-07-24 02:19:04 +0000111 virtual lldb_private::Error
112 DoDeallocateMemory(lldb::addr_t ptr);
113
114 virtual size_t
115 GetSoftwareBreakpointTrapOpcode(lldb_private::BreakpointSite* bp_site);
116
117 virtual lldb_private::Error
118 EnableBreakpoint(lldb_private::BreakpointSite *bp_site);
119
120 virtual lldb_private::Error
121 DisableBreakpoint(lldb_private::BreakpointSite *bp_site);
122
123 virtual uint32_t
124 UpdateThreadListIfNeeded();
125
Johnny Chenb8f74aa2011-10-10 23:11:50 +0000126 uint32_t
127 UpdateThreadList(lldb_private::ThreadList &old_thread_list,
128 lldb_private::ThreadList &new_thread_list);
129
Stephen Wilsonf6f40332010-07-24 02:19:04 +0000130 virtual lldb::ByteOrder
131 GetByteOrder() const;
132
Stephen Wilson01316422011-01-15 00:10:37 +0000133 virtual lldb::addr_t
134 GetImageInfoAddress();
135
Stephen Wilsond1fbbb42011-03-23 02:14:42 +0000136 virtual size_t
137 PutSTDIN(const char *buf, size_t len, lldb_private::Error &error);
138
139 virtual size_t
140 GetSTDOUT(char *buf, size_t len, lldb_private::Error &error);
141
142 virtual size_t
143 GetSTDERR(char *buf, size_t len, lldb_private::Error &error);
144
Stephen Wilsonf6f40332010-07-24 02:19:04 +0000145 //------------------------------------------------------------------
146 // PluginInterface protocol
147 //------------------------------------------------------------------
148 virtual const char *
149 GetPluginName();
150
151 virtual const char *
152 GetShortPluginName();
153
154 virtual uint32_t
155 GetPluginVersion();
156
157 virtual void
158 GetPluginCommandHelp(const char *command, lldb_private::Stream *strm);
159
160 virtual lldb_private::Error
161 ExecutePluginCommand(lldb_private::Args &command,
162 lldb_private::Stream *strm);
163
164 virtual lldb_private::Log *
165 EnablePluginLogging(lldb_private::Stream *strm,
166 lldb_private::Args &command);
167
168 //--------------------------------------------------------------------------
169 // ProcessLinux internal API.
170
171 /// Registers the given message with this process.
172 void SendMessage(const ProcessMessage &message);
173
Johnny Chen3bf3a9d2011-10-18 18:09:30 +0000174 ProcessMonitor &
175 GetMonitor() { assert(m_monitor); return *m_monitor; }
Stephen Wilsonf6f40332010-07-24 02:19:04 +0000176
Stephen Wilson67d9f7e2011-03-30 15:55:52 +0000177 lldb_private::UnixSignals &
178 GetUnixSignals();
179
Stephen Wilsonf6f40332010-07-24 02:19:04 +0000180private:
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
Stephen Wilson67d9f7e2011-03-30 15:55:52 +0000194 /// True when the process has entered a state of "limbo".
195 ///
196 /// This flag qualifies eStateStopped. It lets us know that when we
197 /// continue from this state the process will exit. Also, when true,
198 /// Process::m_exit_status is set.
199 bool m_in_limbo;
200
201 /// Drive any exit events to completion.
202 bool m_exit_now;
203
204 /// Linux-specific signal set.
205 LinuxSignals m_linux_signals;
206
Stephen Wilsonf6f40332010-07-24 02:19:04 +0000207 /// Updates the loaded sections provided by the executable.
208 ///
209 /// FIXME: It would probably be better to delegate this task to the
210 /// DynamicLoader plugin, when we have one.
211 void UpdateLoadedSections();
212
213 /// Returns true if the process has exited.
214 bool HasExited();
Stephen Wilson67d9f7e2011-03-30 15:55:52 +0000215
216 /// Returns true if the process is stopped.
217 bool IsStopped();
Peter Collingbournead115462011-06-03 20:40:44 +0000218
219 typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
220 MMapMap m_addr_to_mmap_size;
Stephen Wilsonf6f40332010-07-24 02:19:04 +0000221};
222
223#endif // liblldb_MacOSXProcess_H_