Johnny Chen | 2341d35 | 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 | ff3536b | 2013-07-09 15:09:45 +0000 | [diff] [blame] | 17 | #include <set> |
Johnny Chen | 2341d35 | 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 | 4349bcb | 2013-07-31 23:27:46 +0000 | [diff] [blame^] | 25 | class POSIXThread; |
Johnny Chen | 2341d35 | 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 | 8592329 | 2013-07-10 21:57:27 +0000 | [diff] [blame] | 44 | virtual void |
| 45 | Finalize(); |
| 46 | |
Johnny Chen | 2341d35 | 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 | c643077 | 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 | 2341d35 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 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 |
Jim Ingham | 761afb8 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 73 | DoDetach(bool keep_stopped); |
Johnny Chen | 2341d35 | 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 |
| 82 | RefreshStateAfterStop(); |
| 83 | |
| 84 | virtual bool |
| 85 | IsAlive(); |
| 86 | |
| 87 | virtual size_t |
| 88 | DoReadMemory(lldb::addr_t vm_addr, |
| 89 | void *buf, |
| 90 | size_t size, |
| 91 | lldb_private::Error &error); |
| 92 | |
| 93 | virtual size_t |
| 94 | DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size, |
| 95 | lldb_private::Error &error); |
| 96 | |
| 97 | virtual lldb::addr_t |
| 98 | DoAllocateMemory(size_t size, uint32_t permissions, |
| 99 | lldb_private::Error &error); |
| 100 | |
| 101 | virtual lldb_private::Error |
| 102 | DoDeallocateMemory(lldb::addr_t ptr); |
| 103 | |
Matt Kopec | 4f9103f | 2013-02-27 20:13:38 +0000 | [diff] [blame] | 104 | virtual lldb::addr_t |
| 105 | ResolveIndirectFunction(const lldb_private::Address *address, lldb_private::Error &error); |
| 106 | |
Johnny Chen | 2341d35 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 107 | virtual size_t |
| 108 | GetSoftwareBreakpointTrapOpcode(lldb_private::BreakpointSite* bp_site); |
| 109 | |
| 110 | virtual lldb_private::Error |
Daniel Malea | 52d8dd9 | 2013-02-15 20:23:25 +0000 | [diff] [blame] | 111 | EnableBreakpointSite(lldb_private::BreakpointSite *bp_site); |
Johnny Chen | 2341d35 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 112 | |
| 113 | virtual lldb_private::Error |
Daniel Malea | 52d8dd9 | 2013-02-15 20:23:25 +0000 | [diff] [blame] | 114 | DisableBreakpointSite(lldb_private::BreakpointSite *bp_site); |
Johnny Chen | 2341d35 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 115 | |
Matt Kopec | 3d4d51c | 2013-05-07 19:29:28 +0000 | [diff] [blame] | 116 | virtual lldb_private::Error |
| 117 | EnableWatchpoint(lldb_private::Watchpoint *wp, bool notify = true); |
| 118 | |
| 119 | virtual lldb_private::Error |
| 120 | DisableWatchpoint(lldb_private::Watchpoint *wp, bool notify = true); |
| 121 | |
| 122 | virtual lldb_private::Error |
| 123 | GetWatchpointSupportInfo(uint32_t &num); |
| 124 | |
| 125 | virtual lldb_private::Error |
| 126 | GetWatchpointSupportInfo(uint32_t &num, bool &after); |
| 127 | |
Johnny Chen | 2341d35 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 128 | virtual uint32_t |
| 129 | UpdateThreadListIfNeeded(); |
| 130 | |
Greg Clayton | c8dd570 | 2012-04-12 19:04:34 +0000 | [diff] [blame] | 131 | virtual bool |
Johnny Chen | 2341d35 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 132 | UpdateThreadList(lldb_private::ThreadList &old_thread_list, |
| 133 | lldb_private::ThreadList &new_thread_list) = 0; |
| 134 | |
| 135 | virtual lldb::ByteOrder |
| 136 | GetByteOrder() const; |
| 137 | |
| 138 | virtual lldb::addr_t |
| 139 | GetImageInfoAddress(); |
| 140 | |
| 141 | virtual size_t |
| 142 | PutSTDIN(const char *buf, size_t len, lldb_private::Error &error); |
| 143 | |
Johnny Chen | 2341d35 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 144 | //-------------------------------------------------------------------------- |
| 145 | // ProcessPOSIX internal API. |
| 146 | |
| 147 | /// Registers the given message with this process. |
| 148 | void SendMessage(const ProcessMessage &message); |
| 149 | |
| 150 | ProcessMonitor & |
| 151 | GetMonitor() { assert(m_monitor); return *m_monitor; } |
| 152 | |
| 153 | lldb_private::UnixSignals & |
| 154 | GetUnixSignals(); |
| 155 | |
| 156 | const char * |
| 157 | GetFilePath(const lldb_private::ProcessLaunchInfo::FileAction *file_action, |
| 158 | const char *default_path); |
| 159 | |
Andrew Kaylor | 3bd2ebd | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 160 | /// Stops all threads in the process. |
| 161 | /// The \p stop_tid parameter indicates the thread which initiated the stop. |
| 162 | virtual void |
| 163 | StopAllThreads(lldb::tid_t stop_tid); |
| 164 | |
Matt Kopec | ff3536b | 2013-07-09 15:09:45 +0000 | [diff] [blame] | 165 | /// Adds the thread to the list of threads for which we have received the initial stopping signal. |
| 166 | /// The \p stop_tid paramter indicates the thread which the stop happened for. |
| 167 | bool |
| 168 | AddThreadForInitialStopIfNeeded(lldb::tid_t stop_tid); |
| 169 | |
Michael Sartain | 4349bcb | 2013-07-31 23:27:46 +0000 | [diff] [blame^] | 170 | virtual POSIXThread * |
| 171 | CreateNewPOSIXThread(lldb_private::Process &process, lldb::tid_t tid); |
| 172 | |
Johnny Chen | 2341d35 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 173 | protected: |
| 174 | /// Target byte order. |
| 175 | lldb::ByteOrder m_byte_order; |
| 176 | |
| 177 | /// Process monitor; |
| 178 | ProcessMonitor *m_monitor; |
| 179 | |
| 180 | /// The module we are executing. |
| 181 | lldb_private::Module *m_module; |
| 182 | |
| 183 | /// Message queue notifying this instance of inferior process state changes. |
| 184 | lldb_private::Mutex m_message_mutex; |
| 185 | std::queue<ProcessMessage> m_message_queue; |
| 186 | |
Johnny Chen | 2341d35 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 187 | /// Drive any exit events to completion. |
| 188 | bool m_exit_now; |
| 189 | |
| 190 | /// OS-specific signal set. |
| 191 | lldb_private::UnixSignals m_signals; |
| 192 | |
| 193 | /// Returns true if the process has exited. |
| 194 | bool HasExited(); |
| 195 | |
| 196 | /// Returns true if the process is stopped. |
| 197 | bool IsStopped(); |
| 198 | |
Matt Kopec | ff3536b | 2013-07-09 15:09:45 +0000 | [diff] [blame] | 199 | /// Returns true if at least one running is currently running |
| 200 | bool IsAThreadRunning(); |
| 201 | |
Johnny Chen | 2341d35 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 202 | typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap; |
| 203 | MMapMap m_addr_to_mmap_size; |
Matt Kopec | ff3536b | 2013-07-09 15:09:45 +0000 | [diff] [blame] | 204 | |
| 205 | typedef std::set<lldb::tid_t> ThreadStopSet; |
| 206 | /// Every thread begins with a stop signal. This keeps track |
| 207 | /// of the threads for which we have received the stop signal. |
| 208 | ThreadStopSet m_seen_initial_stop; |
Johnny Chen | 2341d35 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 209 | }; |
| 210 | |
Johnny Chen | 2341d35 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 211 | #endif // liblldb_MacOSXProcess_H_ |