blob: a865fe26746acd403db68cc5a5bec8fa90761230 [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;
25
26class ProcessPOSIX :
27 public lldb_private::Process
28{
29public:
30
31 //------------------------------------------------------------------
32 // Constructors and destructors
33 //------------------------------------------------------------------
34 ProcessPOSIX(lldb_private::Target& target,
35 lldb_private::Listener &listener);
36
37 virtual
38 ~ProcessPOSIX();
39
40 //------------------------------------------------------------------
41 // Process protocol.
42 //------------------------------------------------------------------
43 virtual bool
44 CanDebug(lldb_private::Target &target, bool plugin_specified_by_name);
45
46 virtual lldb_private::Error
47 WillLaunch(lldb_private::Module *module);
48
49 virtual lldb_private::Error
50 DoAttachToProcessWithID(lldb::pid_t pid);
51
52 virtual lldb_private::Error
Greg Claytone2186ed2012-09-07 17:51:47 +000053 DoAttachToProcessWithID (lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info);
54
55 virtual lldb_private::Error
Johnny Chen9ed5b492012-01-05 21:48:15 +000056 DoLaunch (lldb_private::Module *exe_module,
57 const lldb_private::ProcessLaunchInfo &launch_info);
58
59 virtual void
60 DidLaunch();
61
62 virtual lldb_private::Error
63 DoResume();
64
65 virtual lldb_private::Error
66 DoHalt(bool &caused_stop);
67
68 virtual lldb_private::Error
Jim Inghamacff8952013-05-02 00:27:30 +000069 DoDetach(bool keep_stopped);
Johnny Chen9ed5b492012-01-05 21:48:15 +000070
71 virtual lldb_private::Error
72 DoSignal(int signal);
73
74 virtual lldb_private::Error
75 DoDestroy();
76
77 virtual void
78 RefreshStateAfterStop();
79
80 virtual bool
81 IsAlive();
82
83 virtual size_t
84 DoReadMemory(lldb::addr_t vm_addr,
85 void *buf,
86 size_t size,
87 lldb_private::Error &error);
88
89 virtual size_t
90 DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
91 lldb_private::Error &error);
92
93 virtual lldb::addr_t
94 DoAllocateMemory(size_t size, uint32_t permissions,
95 lldb_private::Error &error);
96
97 virtual lldb_private::Error
98 DoDeallocateMemory(lldb::addr_t ptr);
99
Matt Kopec00049b82013-02-27 20:13:38 +0000100 virtual lldb::addr_t
101 ResolveIndirectFunction(const lldb_private::Address *address, lldb_private::Error &error);
102
Johnny Chen9ed5b492012-01-05 21:48:15 +0000103 virtual size_t
104 GetSoftwareBreakpointTrapOpcode(lldb_private::BreakpointSite* bp_site);
105
106 virtual lldb_private::Error
Daniel Maleab7eec012013-02-15 20:23:25 +0000107 EnableBreakpointSite(lldb_private::BreakpointSite *bp_site);
Johnny Chen9ed5b492012-01-05 21:48:15 +0000108
109 virtual lldb_private::Error
Daniel Maleab7eec012013-02-15 20:23:25 +0000110 DisableBreakpointSite(lldb_private::BreakpointSite *bp_site);
Johnny Chen9ed5b492012-01-05 21:48:15 +0000111
Matt Kopece9ea0da2013-05-07 19:29:28 +0000112 virtual lldb_private::Error
113 EnableWatchpoint(lldb_private::Watchpoint *wp, bool notify = true);
114
115 virtual lldb_private::Error
116 DisableWatchpoint(lldb_private::Watchpoint *wp, bool notify = true);
117
118 virtual lldb_private::Error
119 GetWatchpointSupportInfo(uint32_t &num);
120
121 virtual lldb_private::Error
122 GetWatchpointSupportInfo(uint32_t &num, bool &after);
123
Johnny Chen9ed5b492012-01-05 21:48:15 +0000124 virtual uint32_t
125 UpdateThreadListIfNeeded();
126
Greg Claytonc3c0b0e2012-04-12 19:04:34 +0000127 virtual bool
Johnny Chen9ed5b492012-01-05 21:48:15 +0000128 UpdateThreadList(lldb_private::ThreadList &old_thread_list,
129 lldb_private::ThreadList &new_thread_list) = 0;
130
131 virtual lldb::ByteOrder
132 GetByteOrder() const;
133
134 virtual lldb::addr_t
135 GetImageInfoAddress();
136
137 virtual size_t
138 PutSTDIN(const char *buf, size_t len, lldb_private::Error &error);
139
Johnny Chen9ed5b492012-01-05 21:48:15 +0000140 //--------------------------------------------------------------------------
141 // ProcessPOSIX internal API.
142
143 /// Registers the given message with this process.
144 void SendMessage(const ProcessMessage &message);
145
146 ProcessMonitor &
147 GetMonitor() { assert(m_monitor); return *m_monitor; }
148
149 lldb_private::UnixSignals &
150 GetUnixSignals();
151
152 const char *
153 GetFilePath(const lldb_private::ProcessLaunchInfo::FileAction *file_action,
154 const char *default_path);
155
Andrew Kaylor93132f52013-05-28 23:04:25 +0000156 /// Stops all threads in the process.
157 /// The \p stop_tid parameter indicates the thread which initiated the stop.
158 virtual void
159 StopAllThreads(lldb::tid_t stop_tid);
160
Matt Kopecb2910442013-07-09 15:09:45 +0000161 /// Adds the thread to the list of threads for which we have received the initial stopping signal.
162 /// The \p stop_tid paramter indicates the thread which the stop happened for.
163 bool
164 AddThreadForInitialStopIfNeeded(lldb::tid_t stop_tid);
165
Johnny Chen9ed5b492012-01-05 21:48:15 +0000166protected:
167 /// Target byte order.
168 lldb::ByteOrder m_byte_order;
169
170 /// Process monitor;
171 ProcessMonitor *m_monitor;
172
173 /// The module we are executing.
174 lldb_private::Module *m_module;
175
176 /// Message queue notifying this instance of inferior process state changes.
177 lldb_private::Mutex m_message_mutex;
178 std::queue<ProcessMessage> m_message_queue;
179
Johnny Chen9ed5b492012-01-05 21:48:15 +0000180 /// Drive any exit events to completion.
181 bool m_exit_now;
182
183 /// OS-specific signal set.
184 lldb_private::UnixSignals m_signals;
185
186 /// Returns true if the process has exited.
187 bool HasExited();
188
189 /// Returns true if the process is stopped.
190 bool IsStopped();
191
Matt Kopecb2910442013-07-09 15:09:45 +0000192 /// Returns true if at least one running is currently running
193 bool IsAThreadRunning();
194
Johnny Chen9ed5b492012-01-05 21:48:15 +0000195 typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
196 MMapMap m_addr_to_mmap_size;
Matt Kopecb2910442013-07-09 15:09:45 +0000197
198 typedef std::set<lldb::tid_t> ThreadStopSet;
199 /// Every thread begins with a stop signal. This keeps track
200 /// of the threads for which we have received the stop signal.
201 ThreadStopSet m_seen_initial_stop;
Johnny Chen9ed5b492012-01-05 21:48:15 +0000202};
203
Johnny Chen9ed5b492012-01-05 21:48:15 +0000204#endif // liblldb_MacOSXProcess_H_