Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 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> |
Matt Kopec | b291044 | 2013-07-09 15:09:45 +0000 | [diff] [blame] | 17 | #include <set> |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 18 | |
| 19 | // Other libraries and framework includes |
| 20 | #include "lldb/Target/Process.h" |
| 21 | #include "lldb/Target/UnixSignals.h" |
| 22 | #include "ProcessMessage.h" |
| 23 | |
| 24 | class ProcessMonitor; |
Michael Sartain | 9f822cd | 2013-07-31 23:27:46 +0000 | [diff] [blame] | 25 | class POSIXThread; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 26 | |
| 27 | class ProcessPOSIX : |
| 28 | public lldb_private::Process |
| 29 | { |
| 30 | public: |
| 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 Kaylor | bc68b43 | 2013-07-10 21:57:27 +0000 | [diff] [blame] | 44 | virtual void |
| 45 | Finalize(); |
| 46 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 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 |
Greg Clayton | e2186ed | 2012-09-07 17:51:47 +0000 | [diff] [blame] | 57 | DoAttachToProcessWithID (lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info); |
| 58 | |
| 59 | virtual lldb_private::Error |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 60 | DoLaunch (lldb_private::Module *exe_module, |
Jean-Daniel Dupas | 7782de9 | 2013-12-09 22:52:50 +0000 | [diff] [blame] | 61 | lldb_private::ProcessLaunchInfo &launch_info); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 62 | |
| 63 | virtual void |
| 64 | DidLaunch(); |
| 65 | |
| 66 | virtual lldb_private::Error |
Ed Maste | 30df85e | 2013-12-11 20:43:27 +0000 | [diff] [blame^] | 67 | DoResume(); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 68 | |
| 69 | virtual lldb_private::Error |
| 70 | DoHalt(bool &caused_stop); |
| 71 | |
| 72 | virtual lldb_private::Error |
Ed Maste | 7dcb77d | 2013-08-30 13:11:30 +0000 | [diff] [blame] | 73 | DoDetach(bool keep_stopped) = 0; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 74 | |
| 75 | virtual lldb_private::Error |
| 76 | DoSignal(int signal); |
| 77 | |
| 78 | virtual lldb_private::Error |
| 79 | DoDestroy(); |
| 80 | |
| 81 | virtual void |
Matt Kopec | 718be87 | 2013-10-09 19:39:55 +0000 | [diff] [blame] | 82 | DoDidExec(); |
| 83 | |
| 84 | virtual void |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 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 | |
Matt Kopec | 00049b8 | 2013-02-27 20:13:38 +0000 | [diff] [blame] | 107 | virtual lldb::addr_t |
| 108 | ResolveIndirectFunction(const lldb_private::Address *address, lldb_private::Error &error); |
| 109 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 110 | virtual size_t |
| 111 | GetSoftwareBreakpointTrapOpcode(lldb_private::BreakpointSite* bp_site); |
| 112 | |
| 113 | virtual lldb_private::Error |
Daniel Malea | b7eec01 | 2013-02-15 20:23:25 +0000 | [diff] [blame] | 114 | EnableBreakpointSite(lldb_private::BreakpointSite *bp_site); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 115 | |
| 116 | virtual lldb_private::Error |
Daniel Malea | b7eec01 | 2013-02-15 20:23:25 +0000 | [diff] [blame] | 117 | DisableBreakpointSite(lldb_private::BreakpointSite *bp_site); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 118 | |
Matt Kopec | e9ea0da | 2013-05-07 19:29:28 +0000 | [diff] [blame] | 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 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 131 | virtual uint32_t |
| 132 | UpdateThreadListIfNeeded(); |
| 133 | |
Greg Clayton | c3c0b0e | 2012-04-12 19:04:34 +0000 | [diff] [blame] | 134 | virtual bool |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 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 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 147 | //-------------------------------------------------------------------------- |
| 148 | // ProcessPOSIX internal API. |
| 149 | |
| 150 | /// Registers the given message with this process. |
Ed Maste | 7fd845c | 2013-12-09 15:51:17 +0000 | [diff] [blame] | 151 | virtual void |
Ed Maste | 30df85e | 2013-12-11 20:43:27 +0000 | [diff] [blame^] | 152 | SendMessage(const ProcessMessage &message); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 153 | |
| 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 Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 164 | /// 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 Kopec | b291044 | 2013-07-09 15:09:45 +0000 | [diff] [blame] | 169 | /// 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 Kaylor | d4d5499 | 2013-09-17 00:30:24 +0000 | [diff] [blame] | 174 | bool |
| 175 | WaitingForInitialStop(lldb::tid_t stop_tid); |
| 176 | |
Michael Sartain | 9f822cd | 2013-07-31 23:27:46 +0000 | [diff] [blame] | 177 | virtual POSIXThread * |
| 178 | CreateNewPOSIXThread(lldb_private::Process &process, lldb::tid_t tid); |
| 179 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 180 | protected: |
| 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 Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 194 | /// 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 Kopec | b291044 | 2013-07-09 15:09:45 +0000 | [diff] [blame] | 206 | /// Returns true if at least one running is currently running |
| 207 | bool IsAThreadRunning(); |
| 208 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 209 | typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap; |
| 210 | MMapMap m_addr_to_mmap_size; |
Matt Kopec | b291044 | 2013-07-09 15:09:45 +0000 | [diff] [blame] | 211 | |
| 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 Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 216 | }; |
| 217 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 218 | #endif // liblldb_MacOSXProcess_H_ |