ProcessPOSIX.h revision 263363
1//===-- 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> 17#include <set> 18 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; 25class POSIXThread; 26 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 //------------------------------------------------------------------ 44 virtual void 45 Finalize(); 46 47 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 57 DoAttachToProcessWithID (lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info); 58 59 virtual lldb_private::Error 60 DoLaunch (lldb_private::Module *exe_module, 61 const lldb_private::ProcessLaunchInfo &launch_info); 62 63 virtual void 64 DidLaunch(); 65 66 virtual lldb_private::Error 67 DoResume(); 68 69 virtual lldb_private::Error 70 DoHalt(bool &caused_stop); 71 72 virtual lldb_private::Error 73 DoDetach(bool keep_stopped) = 0; 74 75 virtual lldb_private::Error 76 DoSignal(int signal); 77 78 virtual lldb_private::Error 79 DoDestroy(); 80 81 virtual void 82 DoDidExec(); 83 84 virtual void 85 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 107 virtual lldb::addr_t 108 ResolveIndirectFunction(const lldb_private::Address *address, lldb_private::Error &error); 109 110 virtual size_t 111 GetSoftwareBreakpointTrapOpcode(lldb_private::BreakpointSite* bp_site); 112 113 virtual lldb_private::Error 114 EnableBreakpointSite(lldb_private::BreakpointSite *bp_site); 115 116 virtual lldb_private::Error 117 DisableBreakpointSite(lldb_private::BreakpointSite *bp_site); 118 119 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 131 virtual uint32_t 132 UpdateThreadListIfNeeded(); 133 134 virtual bool 135 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 147 //-------------------------------------------------------------------------- 148 // ProcessPOSIX internal API. 149 150 /// Registers the given message with this process. 151 void SendMessage(const ProcessMessage &message); 152 153 ProcessMonitor & 154 GetMonitor() { assert(m_monitor); return *m_monitor; } 155 156 lldb_private::UnixSignals & 157 GetUnixSignals(); 158 159 const char * 160 GetFilePath(const lldb_private::ProcessLaunchInfo::FileAction *file_action, 161 const char *default_path); 162 163 /// Stops all threads in the process. 164 /// The \p stop_tid parameter indicates the thread which initiated the stop. 165 virtual void 166 StopAllThreads(lldb::tid_t stop_tid); 167 168 /// Adds the thread to the list of threads for which we have received the initial stopping signal. 169 /// The \p stop_tid paramter indicates the thread which the stop happened for. 170 bool 171 AddThreadForInitialStopIfNeeded(lldb::tid_t stop_tid); 172 173 bool 174 WaitingForInitialStop(lldb::tid_t stop_tid); 175 176 virtual POSIXThread * 177 CreateNewPOSIXThread(lldb_private::Process &process, lldb::tid_t tid); 178 179protected: 180 /// Target byte order. 181 lldb::ByteOrder m_byte_order; 182 183 /// Process monitor; 184 ProcessMonitor *m_monitor; 185 186 /// The module we are executing. 187 lldb_private::Module *m_module; 188 189 /// Message queue notifying this instance of inferior process state changes. 190 lldb_private::Mutex m_message_mutex; 191 std::queue<ProcessMessage> m_message_queue; 192 193 /// Drive any exit events to completion. 194 bool m_exit_now; 195 196 /// OS-specific signal set. 197 lldb_private::UnixSignals m_signals; 198 199 /// Returns true if the process has exited. 200 bool HasExited(); 201 202 /// Returns true if the process is stopped. 203 bool IsStopped(); 204 205 /// Returns true if at least one running is currently running 206 bool IsAThreadRunning(); 207 208 typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap; 209 MMapMap m_addr_to_mmap_size; 210 211 typedef std::set<lldb::tid_t> ThreadStopSet; 212 /// Every thread begins with a stop signal. This keeps track 213 /// of the threads for which we have received the stop signal. 214 ThreadStopSet m_seen_initial_stop; 215}; 216 217#endif // liblldb_MacOSXProcess_H_ 218