1 //===-- NativeProcessProtocol.h ---------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_NativeProcessProtocol_h_
11 #define liblldb_NativeProcessProtocol_h_
15 #include "lldb/lldb-private-forward.h"
16 #include "lldb/lldb-types.h"
17 #include "lldb/Core/Error.h"
18 #include "lldb/Host/Mutex.h"
20 #include "NativeBreakpointList.h"
22 namespace lldb_private
24 class MemoryRegionInfo;
25 class ResumeActionList;
27 //------------------------------------------------------------------
28 // NativeProcessProtocol
29 //------------------------------------------------------------------
30 class NativeProcessProtocol :
31 public std::enable_shared_from_this<NativeProcessProtocol>
33 friend class SoftwareBreakpoint;
36 static NativeProcessProtocol *
37 CreateInstance (lldb::pid_t pid);
39 // lldb_private::Host calls should be used to launch a process for debugging, and
40 // then the process should be attached to. When attaching to a process
41 // lldb_private::Host calls should be used to locate the process to attach to,
42 // and then this function should be called.
43 NativeProcessProtocol (lldb::pid_t pid);
46 virtual ~NativeProcessProtocol ()
51 Resume (const ResumeActionList &resume_actions) = 0;
59 //------------------------------------------------------------------
60 /// Sends a process a UNIX signal \a signal.
62 /// Implementer note: the WillSignal ()/DidSignal () calls
63 /// from the Process class are not replicated here since no
64 /// concrete classes implemented any behavior for those and
65 /// put all the work in DoSignal (...).
68 /// Returns an error object.
69 //------------------------------------------------------------------
71 Signal (int signo) = 0;
76 //----------------------------------------------------------------------
77 // Memory and memory region functions
78 //----------------------------------------------------------------------
81 GetMemoryRegionInfo (lldb::addr_t load_addr, MemoryRegionInfo &range_info);
84 ReadMemory (lldb::addr_t addr, void *buf, lldb::addr_t size, lldb::addr_t &bytes_read) = 0;
87 WriteMemory (lldb::addr_t addr, const void *buf, lldb::addr_t size, lldb::addr_t &bytes_written) = 0;
90 AllocateMemory (lldb::addr_t size, uint32_t permissions, lldb::addr_t &addr) = 0;
93 DeallocateMemory (lldb::addr_t addr) = 0;
96 GetSharedLibraryInfoAddress () = 0;
102 UpdateThreads () = 0;
105 GetArchitecture (ArchSpec &arch) const = 0;
107 //----------------------------------------------------------------------
108 // Breakpoint functions
109 //----------------------------------------------------------------------
111 SetBreakpoint (lldb::addr_t addr, uint32_t size, bool hardware) = 0;
114 RemoveBreakpoint (lldb::addr_t addr);
117 EnableBreakpoint (lldb::addr_t addr);
120 DisableBreakpoint (lldb::addr_t addr);
122 //----------------------------------------------------------------------
123 // Watchpoint functions
124 //----------------------------------------------------------------------
126 GetMaxWatchpoints () const;
129 SetWatchpoint (lldb::addr_t addr, size_t size, uint32_t watch_flags, bool hardware);
132 RemoveWatchpoint (lldb::addr_t addr);
134 //----------------------------------------------------------------------
136 //----------------------------------------------------------------------
149 return m_state == lldb::eStateRunning || IsStepping();
155 return m_state == lldb::eStateStepping;
161 return m_state == lldb::eStateStopped;
165 GetByteOrder (lldb::ByteOrder &byte_order) const;
167 //----------------------------------------------------------------------
169 //----------------------------------------------------------------------
171 GetExitStatus (lldb_private::ExitType *exit_type, int *status, std::string &exit_description);
174 SetExitStatus (lldb_private::ExitType exit_type, int status, const char *exit_description, bool bNotifyStateChange);
176 //----------------------------------------------------------------------
178 //----------------------------------------------------------------------
179 NativeThreadProtocolSP
180 GetThreadAtIndex (uint32_t idx);
182 NativeThreadProtocolSP
183 GetThreadByID (lldb::tid_t tid);
186 SetCurrentThreadID (lldb::tid_t tid)
188 m_current_thread_id = tid;
192 GetCurrentThreadID ()
194 return m_current_thread_id;
197 NativeThreadProtocolSP
200 return GetThreadByID (m_current_thread_id);
203 //----------------------------------------------------------------------
204 // Access to inferior stdio
205 //----------------------------------------------------------------------
207 int GetTerminalFileDescriptor ()
209 return m_terminal_fd;
212 //----------------------------------------------------------------------
214 //----------------------------------------------------------------------
219 // ---------------------------------------------------------------------
220 // Callbacks for low-level process state changes
221 // ---------------------------------------------------------------------
226 ~NativeDelegate () {}
229 InitializeDelegate (NativeProcessProtocol *process) = 0;
232 ProcessStateChanged (NativeProcessProtocol *process, lldb::StateType state) = 0;
235 DidExec (NativeProcessProtocol *process) = 0;
238 //------------------------------------------------------------------
239 /// Register a native delegate.
241 /// Clients can register nofication callbacks by passing in a
242 /// NativeDelegate impl and passing it into this function.
244 /// Note: it is required that the lifetime of the
245 /// native_delegate outlive the NativeProcessProtocol.
247 /// @param[in] native_delegate
248 /// A NativeDelegate impl to be called when certain events
249 /// happen within the NativeProcessProtocol or related threads.
252 /// true if the delegate was registered successfully;
253 /// false if the delegate was already registered.
255 /// @see NativeProcessProtocol::NativeDelegate.
256 //------------------------------------------------------------------
258 RegisterNativeDelegate (NativeDelegate &native_delegate);
260 //------------------------------------------------------------------
261 /// Unregister a native delegate previously registered.
263 /// @param[in] native_delegate
264 /// A NativeDelegate impl previously registered with this process.
266 /// @return Returns \b true if the NativeDelegate was
267 /// successfully removed from the process, \b false otherwise.
269 /// @see NativeProcessProtocol::NativeDelegate
270 //------------------------------------------------------------------
272 UnregisterNativeDelegate (NativeDelegate &native_delegate);
277 std::vector<NativeThreadProtocolSP> m_threads;
278 lldb::tid_t m_current_thread_id;
279 mutable Mutex m_threads_mutex;
281 lldb::StateType m_state;
282 mutable Mutex m_state_mutex;
284 lldb_private::ExitType m_exit_type;
286 std::string m_exit_description;
287 Mutex m_delegates_mutex;
288 std::vector<NativeDelegate*> m_delegates;
289 NativeBreakpointList m_breakpoint_list;
293 // -----------------------------------------------------------
294 // Internal interface for state handling
295 // -----------------------------------------------------------
297 SetState (lldb::StateType state, bool notify_delegates = true);
299 // Derived classes need not impelment this. It can be used as a
300 // hook to clear internal caches that should be invalidated when
303 // Note this function is called with the state mutex obtained
306 DoStopIDBumped (uint32_t newBumpId);
308 // -----------------------------------------------------------
309 // Internal interface for software breakpoints
310 // -----------------------------------------------------------
312 SetSoftwareBreakpoint (lldb::addr_t addr, uint32_t size_hint);
315 GetSoftwareBreakpointTrapOpcode (size_t trap_opcode_size_hint, size_t &actual_opcode_size, const uint8_t *&trap_opcode_bytes) = 0;
317 // -----------------------------------------------------------
318 /// Notify the delegate that an exec occurred.
320 /// Provide a mechanism for a delegate to clear out any exec-
322 // -----------------------------------------------------------
329 SynchronouslyNotifyProcessStateChanged (lldb::StateType state);
333 #endif // #ifndef liblldb_NativeProcessProtocol_h_