Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 1 | //===-- SWIG Interface for SBProcess ----------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | namespace lldb { |
| 10 | |
| 11 | %feature("docstring", |
| 12 | "Represents the process associated with the target program. |
| 13 | |
| 14 | SBProcess supports thread iteration. For example (from test/lldbutil.py), |
| 15 | |
| 16 | # ================================================== |
| 17 | # Utility functions related to Threads and Processes |
| 18 | # ================================================== |
| 19 | |
| 20 | def get_stopped_threads(process, reason): |
| 21 | '''Returns the thread(s) with the specified stop reason in a list. |
| 22 | |
| 23 | The list can be empty if no such thread exists. |
| 24 | ''' |
| 25 | threads = [] |
| 26 | for t in process: |
| 27 | if t.GetStopReason() == reason: |
| 28 | threads.append(t) |
| 29 | return threads |
| 30 | |
| 31 | ... |
| 32 | " |
| 33 | ) SBProcess; |
| 34 | class SBProcess |
| 35 | { |
| 36 | public: |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 37 | enum |
| 38 | { |
| 39 | eBroadcastBitStateChanged = (1 << 0), |
| 40 | eBroadcastBitInterrupt = (1 << 1), |
| 41 | eBroadcastBitSTDOUT = (1 << 2), |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 42 | eBroadcastBitSTDERR = (1 << 3), |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 43 | eBroadcastBitProfileData = (1 << 4), |
| 44 | eBroadcastBitStructuredData = (1 << 5) |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | SBProcess (); |
| 48 | |
| 49 | SBProcess (const lldb::SBProcess& rhs); |
| 50 | |
| 51 | ~SBProcess(); |
| 52 | |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 53 | static const char * |
| 54 | GetBroadcasterClassName (); |
| 55 | |
Jim Ingham | d7b30ef | 2012-10-26 19:18:04 +0000 | [diff] [blame] | 56 | const char * |
| 57 | GetPluginName (); |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 58 | |
Jim Ingham | d7b30ef | 2012-10-26 19:18:04 +0000 | [diff] [blame] | 59 | const char * |
| 60 | GetShortPluginName (); |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 61 | |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 62 | void |
| 63 | Clear (); |
| 64 | |
| 65 | bool |
| 66 | IsValid() const; |
| 67 | |
Pavel Labath | 7f5237b | 2019-03-11 13:58:46 +0000 | [diff] [blame] | 68 | explicit operator bool() const; |
| 69 | |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 70 | lldb::SBTarget |
| 71 | GetTarget() const; |
| 72 | |
| 73 | lldb::ByteOrder |
| 74 | GetByteOrder() const; |
| 75 | |
Johnny Chen | 49cb85d | 2011-11-28 21:39:07 +0000 | [diff] [blame] | 76 | %feature("autodoc", " |
| 77 | Writes data into the current process's stdin. API client specifies a Python |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 78 | string as the only argument.") PutSTDIN; |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 79 | size_t |
| 80 | PutSTDIN (const char *src, size_t src_len); |
| 81 | |
Johnny Chen | d80e5e9 | 2011-11-28 19:12:25 +0000 | [diff] [blame] | 82 | %feature("autodoc", " |
| 83 | Reads data from the current process's stdout stream. API client specifies |
| 84 | the size of the buffer to read data into. It returns the byte buffer in a |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 85 | Python string.") GetSTDOUT; |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 86 | size_t |
| 87 | GetSTDOUT (char *dst, size_t dst_len) const; |
| 88 | |
Johnny Chen | d80e5e9 | 2011-11-28 19:12:25 +0000 | [diff] [blame] | 89 | %feature("autodoc", " |
| 90 | Reads data from the current process's stderr stream. API client specifies |
| 91 | the size of the buffer to read data into. It returns the byte buffer in a |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 92 | Python string.") GetSTDERR; |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 93 | size_t |
| 94 | GetSTDERR (char *dst, size_t dst_len) const; |
| 95 | |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 96 | size_t |
| 97 | GetAsyncProfileData(char *dst, size_t dst_len) const; |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 98 | |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 99 | void |
| 100 | ReportEventState (const lldb::SBEvent &event, FILE *out) const; |
| 101 | |
| 102 | void |
| 103 | AppendEventStateReport (const lldb::SBEvent &event, lldb::SBCommandReturnObject &result); |
| 104 | |
| 105 | %feature("docstring", " |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 106 | Remote connection related functions. These will fail if the |
| 107 | process is not in eStateConnected. They are intended for use |
| 108 | when connecting to an externally managed debugserver instance.") RemoteAttachToProcessWithID; |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 109 | bool |
| 110 | RemoteAttachToProcessWithID (lldb::pid_t pid, |
| 111 | lldb::SBError& error); |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 112 | |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 113 | %feature("docstring", |
| 114 | "See SBTarget.Launch for argument description and usage." |
| 115 | ) RemoteLaunch; |
| 116 | bool |
| 117 | RemoteLaunch (char const **argv, |
| 118 | char const **envp, |
| 119 | const char *stdin_path, |
| 120 | const char *stdout_path, |
| 121 | const char *stderr_path, |
| 122 | const char *working_directory, |
| 123 | uint32_t launch_flags, |
| 124 | bool stop_at_entry, |
| 125 | lldb::SBError& error); |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 126 | |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 127 | //------------------------------------------------------------------ |
| 128 | // Thread related functions |
| 129 | //------------------------------------------------------------------ |
| 130 | uint32_t |
| 131 | GetNumThreads (); |
| 132 | |
Jim Ingham | 18b4689 | 2012-07-13 20:18:18 +0000 | [diff] [blame] | 133 | %feature("autodoc", " |
| 134 | Returns the INDEX'th thread from the list of current threads. The index |
| 135 | of a thread is only valid for the current stop. For a persistent thread |
| 136 | identifier use either the thread ID or the IndexID. See help on SBThread |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 137 | for more details.") GetThreadAtIndex; |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 138 | lldb::SBThread |
| 139 | GetThreadAtIndex (size_t index); |
| 140 | |
Jim Ingham | 18b4689 | 2012-07-13 20:18:18 +0000 | [diff] [blame] | 141 | %feature("autodoc", " |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 142 | Returns the thread with the given thread ID.") GetThreadByID; |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 143 | lldb::SBThread |
| 144 | GetThreadByID (lldb::tid_t sb_thread_id); |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 145 | |
Jim Ingham | 18b4689 | 2012-07-13 20:18:18 +0000 | [diff] [blame] | 146 | %feature("autodoc", " |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 147 | Returns the thread with the given thread IndexID.") GetThreadByIndexID; |
Jim Ingham | 18b4689 | 2012-07-13 20:18:18 +0000 | [diff] [blame] | 148 | lldb::SBThread |
| 149 | GetThreadByIndexID (uint32_t index_id); |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 150 | |
Jim Ingham | 18b4689 | 2012-07-13 20:18:18 +0000 | [diff] [blame] | 151 | %feature("autodoc", " |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 152 | Returns the currently selected thread.") GetSelectedThread; |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 153 | lldb::SBThread |
| 154 | GetSelectedThread () const; |
| 155 | |
Greg Clayton | a4d8747 | 2013-01-18 23:41:08 +0000 | [diff] [blame] | 156 | %feature("autodoc", " |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 157 | Lazily create a thread on demand through the current OperatingSystem plug-in, if the current OperatingSystem plug-in supports it.") CreateOSPluginThread; |
Greg Clayton | a4d8747 | 2013-01-18 23:41:08 +0000 | [diff] [blame] | 158 | lldb::SBThread |
| 159 | CreateOSPluginThread (lldb::tid_t tid, lldb::addr_t context); |
| 160 | |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 161 | bool |
| 162 | SetSelectedThread (const lldb::SBThread &thread); |
| 163 | |
| 164 | bool |
Greg Clayton | ea561dc | 2012-10-12 23:32:11 +0000 | [diff] [blame] | 165 | SetSelectedThreadByID (lldb::tid_t tid); |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 166 | |
Jim Ingham | 18b4689 | 2012-07-13 20:18:18 +0000 | [diff] [blame] | 167 | bool |
| 168 | SetSelectedThreadByIndexID (uint32_t index_id); |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 169 | |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 170 | //------------------------------------------------------------------ |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 171 | // Queue related functions |
| 172 | //------------------------------------------------------------------ |
| 173 | uint32_t |
| 174 | GetNumQueues (); |
| 175 | |
| 176 | lldb::SBQueue |
| 177 | GetQueueAtIndex (uint32_t index); |
| 178 | |
| 179 | //------------------------------------------------------------------ |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 180 | // Stepping related functions |
| 181 | //------------------------------------------------------------------ |
| 182 | |
| 183 | lldb::StateType |
| 184 | GetState (); |
| 185 | |
| 186 | int |
| 187 | GetExitStatus (); |
| 188 | |
| 189 | const char * |
| 190 | GetExitDescription (); |
| 191 | |
Greg Clayton | 949e822 | 2013-01-16 17:29:04 +0000 | [diff] [blame] | 192 | %feature("autodoc", " |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 193 | Returns the process ID of the process.") GetProcessID; |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 194 | lldb::pid_t |
| 195 | GetProcessID (); |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 196 | |
Greg Clayton | 949e822 | 2013-01-16 17:29:04 +0000 | [diff] [blame] | 197 | %feature("autodoc", " |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 198 | Returns an integer ID that is guaranteed to be unique across all process instances. This is not the process ID, just a unique integer for comparison and caching purposes.") GetUniqueID; |
Greg Clayton | 949e822 | 2013-01-16 17:29:04 +0000 | [diff] [blame] | 199 | uint32_t |
| 200 | GetUniqueID(); |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 201 | |
| 202 | uint32_t |
| 203 | GetAddressByteSize() const; |
| 204 | |
| 205 | %feature("docstring", " |
| 206 | Kills the process and shuts down all threads that were spawned to |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 207 | track and monitor process.") Destroy; |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 208 | lldb::SBError |
| 209 | Destroy (); |
| 210 | |
| 211 | lldb::SBError |
| 212 | Continue (); |
| 213 | |
| 214 | lldb::SBError |
| 215 | Stop (); |
| 216 | |
| 217 | %feature("docstring", "Same as Destroy(self).") Destroy; |
| 218 | lldb::SBError |
| 219 | Kill (); |
| 220 | |
| 221 | lldb::SBError |
| 222 | Detach (); |
| 223 | |
| 224 | %feature("docstring", "Sends the process a unix signal.") Signal; |
| 225 | lldb::SBError |
| 226 | Signal (int signal); |
| 227 | |
Todd Fiala | 802dc402 | 2014-06-23 19:30:49 +0000 | [diff] [blame] | 228 | lldb::SBUnixSignals |
| 229 | GetUnixSignals(); |
| 230 | |
Jim Ingham | bf2956a2 | 2013-01-08 23:22:42 +0000 | [diff] [blame] | 231 | %feature("docstring", " |
| 232 | Returns a stop id that will increase every time the process executes. If |
| 233 | include_expression_stops is true, then stops caused by expression evaluation |
| 234 | will cause the returned value to increase, otherwise the counter returned will |
| 235 | only increase when execution is continued explicitly by the user. Note, the value |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 236 | will always increase, but may increase by more than one per stop.") GetStopID; |
Jim Ingham | bf2956a2 | 2013-01-08 23:22:42 +0000 | [diff] [blame] | 237 | uint32_t |
| 238 | GetStopID(bool include_expression_stops = false); |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 239 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 240 | void |
| 241 | SendAsyncInterrupt(); |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 242 | |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 243 | %feature("autodoc", " |
| 244 | Reads memory from the current process's address space and removes any |
| 245 | traps that may have been inserted into the memory. It returns the byte |
| 246 | buffer in a Python string. Example: |
| 247 | |
| 248 | # Read 4 bytes from address 'addr' and assume error.Success() is True. |
| 249 | content = process.ReadMemory(addr, 4, error) |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 250 | new_bytes = bytearray(content)") ReadMemory; |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 251 | size_t |
| 252 | ReadMemory (addr_t addr, void *buf, size_t size, lldb::SBError &error); |
| 253 | |
| 254 | %feature("autodoc", " |
| 255 | Writes memory to the current process's address space and maintains any |
| 256 | traps that might be present due to software breakpoints. Example: |
| 257 | |
| 258 | # Create a Python string from the byte array. |
| 259 | new_value = str(bytes) |
| 260 | result = process.WriteMemory(addr, new_value, error) |
| 261 | if not error.Success() or result != len(bytes): |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 262 | print('SBProcess.WriteMemory() failed!')") WriteMemory; |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 263 | size_t |
| 264 | WriteMemory (addr_t addr, const void *buf, size_t size, lldb::SBError &error); |
| 265 | |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 266 | %feature("autodoc", " |
| 267 | Reads a NULL terminated C string from the current process's address space. |
| 268 | It returns a python string of the exact length, or truncates the string if |
| 269 | the maximum character limit is reached. Example: |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 270 | |
| 271 | # Read a C string of at most 256 bytes from address '0x1000' |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 272 | error = lldb.SBError() |
Johnny Chen | 80e3e84 | 2011-12-15 22:34:59 +0000 | [diff] [blame] | 273 | cstring = process.ReadCStringFromMemory(0x1000, 256, error) |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 274 | if error.Success(): |
Zachary Turner | 5f3fd80 | 2015-10-16 17:52:32 +0000 | [diff] [blame] | 275 | print('cstring: ', cstring) |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 276 | else |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 277 | print('error: ', error)") ReadCStringFromMemory; |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 278 | |
| 279 | size_t |
Zachary Turner | 4407396 | 2016-01-25 23:21:18 +0000 | [diff] [blame] | 280 | ReadCStringFromMemory (addr_t addr, void *char_buf, size_t size, lldb::SBError &error); |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 281 | |
| 282 | %feature("autodoc", " |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 283 | Reads an unsigned integer from memory given a byte size and an address. |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 284 | Returns the unsigned integer that was read. Example: |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 285 | |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 286 | # Read a 4 byte unsigned integer from address 0x1000 |
| 287 | error = lldb.SBError() |
| 288 | uint = ReadUnsignedFromMemory(0x1000, 4, error) |
| 289 | if error.Success(): |
Zachary Turner | 5f3fd80 | 2015-10-16 17:52:32 +0000 | [diff] [blame] | 290 | print('integer: %u' % uint) |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 291 | else |
Pavel Labath | 27e9d98 | 2019-04-21 12:48:53 +0000 | [diff] [blame] | 292 | print('error: ', error)") ReadUnsignedFromMemory; |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 293 | |
| 294 | uint64_t |
| 295 | ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &error); |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 296 | |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 297 | %feature("autodoc", " |
| 298 | Reads a pointer from memory from an address and returns the value. Example: |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 299 | |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 300 | # Read a pointer from address 0x1000 |
| 301 | error = lldb.SBError() |
| 302 | ptr = ReadPointerFromMemory(0x1000, error) |
| 303 | if error.Success(): |
Zachary Turner | 5f3fd80 | 2015-10-16 17:52:32 +0000 | [diff] [blame] | 304 | print('pointer: 0x%x' % ptr) |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 305 | else |
Pavel Labath | 27e9d98 | 2019-04-21 12:48:53 +0000 | [diff] [blame] | 306 | print('error: ', error)") ReadPointerFromMemory; |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 307 | |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 308 | lldb::addr_t |
| 309 | ReadPointerFromMemory (addr_t addr, lldb::SBError &error); |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 310 | |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 311 | |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 312 | // Events |
| 313 | static lldb::StateType |
| 314 | GetStateFromEvent (const lldb::SBEvent &event); |
| 315 | |
| 316 | static bool |
| 317 | GetRestartedFromEvent (const lldb::SBEvent &event); |
| 318 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 319 | static size_t |
| 320 | GetNumRestartedReasonsFromEvent (const lldb::SBEvent &event); |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 321 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 322 | static const char * |
| 323 | GetRestartedReasonAtIndexFromEvent (const lldb::SBEvent &event, size_t idx); |
| 324 | |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 325 | static lldb::SBProcess |
| 326 | GetProcessFromEvent (const lldb::SBEvent &event); |
| 327 | |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 328 | static bool |
Ilia K | 06d2855 | 2015-05-15 09:29:09 +0000 | [diff] [blame] | 329 | GetInterruptedFromEvent (const lldb::SBEvent &event); |
| 330 | |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 331 | static lldb::SBStructuredData |
| 332 | GetStructuredDataFromEvent (const lldb::SBEvent &event); |
| 333 | |
Ilia K | 06d2855 | 2015-05-15 09:29:09 +0000 | [diff] [blame] | 334 | static bool |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 335 | EventIsProcessEvent (const lldb::SBEvent &event); |
| 336 | |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 337 | static bool |
| 338 | EventIsStructuredDataEvent (const lldb::SBEvent &event); |
| 339 | |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 340 | lldb::SBBroadcaster |
| 341 | GetBroadcaster () const; |
| 342 | |
| 343 | bool |
| 344 | GetDescription (lldb::SBStream &description); |
| 345 | |
| 346 | uint32_t |
Johnny Chen | f9ef60d | 2012-05-23 22:34:34 +0000 | [diff] [blame] | 347 | GetNumSupportedHardwareWatchpoints (lldb::SBError &error) const; |
| 348 | |
| 349 | uint32_t |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 350 | LoadImage (lldb::SBFileSpec &image_spec, lldb::SBError &error); |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 351 | |
Jim Ingham | 0d231f7 | 2018-06-28 20:02:11 +0000 | [diff] [blame] | 352 | %feature("autodoc", " |
| 353 | Load the library whose filename is given by image_spec looking in all the |
| 354 | paths supplied in the paths argument. If successful, return a token that |
| 355 | can be passed to UnloadImage and fill loaded_path with the path that was |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 356 | successfully loaded. On failure, return |
| 357 | lldb.LLDB_INVALID_IMAGE_TOKEN.") LoadImageUsingPaths; |
| 358 | uint32_t |
Jim Ingham | 0d231f7 | 2018-06-28 20:02:11 +0000 | [diff] [blame] | 359 | LoadImageUsingPaths(const lldb::SBFileSpec &image_spec, |
| 360 | SBStringList &paths, |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 361 | lldb::SBFileSpec &loaded_path, |
Jim Ingham | 0d231f7 | 2018-06-28 20:02:11 +0000 | [diff] [blame] | 362 | SBError &error); |
| 363 | |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 364 | lldb::SBError |
| 365 | UnloadImage (uint32_t image_token); |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 366 | |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 367 | lldb::SBError |
| 368 | SendEventData (const char *event_data); |
Johnny Chen | 39c6d0f | 2012-01-06 00:46:12 +0000 | [diff] [blame] | 369 | |
Jason Molenda | 8c71337 | 2013-11-05 11:00:35 +0000 | [diff] [blame] | 370 | %feature("autodoc", " |
| 371 | Return the number of different thread-origin extended backtraces |
| 372 | this process can support as a uint32_t. |
| 373 | When the process is stopped and you have an SBThread, lldb may be |
| 374 | able to show a backtrace of when that thread was originally created, |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 375 | or the work item was enqueued to it (in the case of a libdispatch |
| 376 | queue).") GetNumExtendedBacktraceTypes; |
| 377 | |
Jason Molenda | 8c71337 | 2013-11-05 11:00:35 +0000 | [diff] [blame] | 378 | uint32_t |
Jason Molenda | 95d005c | 2013-11-06 03:07:33 +0000 | [diff] [blame] | 379 | GetNumExtendedBacktraceTypes (); |
Jason Molenda | 8c71337 | 2013-11-05 11:00:35 +0000 | [diff] [blame] | 380 | |
| 381 | %feature("autodoc", " |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 382 | Takes an index argument, returns the name of one of the thread-origin |
| 383 | extended backtrace methods as a str.") GetExtendedBacktraceTypeAtIndex; |
Jason Molenda | 8c71337 | 2013-11-05 11:00:35 +0000 | [diff] [blame] | 384 | |
| 385 | const char * |
Jason Molenda | 95d005c | 2013-11-06 03:07:33 +0000 | [diff] [blame] | 386 | GetExtendedBacktraceTypeAtIndex (uint32_t idx); |
Jason Molenda | 8c71337 | 2013-11-05 11:00:35 +0000 | [diff] [blame] | 387 | |
Kuba Brecka | a51ea38 | 2014-09-06 01:33:13 +0000 | [diff] [blame] | 388 | lldb::SBThreadCollection |
| 389 | GetHistoryThreads (addr_t addr); |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 390 | |
Kuba Brecka | 6392754 | 2014-10-11 01:59:32 +0000 | [diff] [blame] | 391 | bool |
| 392 | IsInstrumentationRuntimePresent(lldb::InstrumentationRuntimeType type); |
Kuba Brecka | a51ea38 | 2014-09-06 01:33:13 +0000 | [diff] [blame] | 393 | |
Adrian McCarthy | f7d1893 | 2015-11-20 23:09:11 +0000 | [diff] [blame] | 394 | lldb::SBError |
| 395 | SaveCore(const char *file_name); |
| 396 | |
Ravitheja Addepally | d5d8d91 | 2017-04-26 08:48:50 +0000 | [diff] [blame] | 397 | lldb::SBTrace |
| 398 | StartTrace(SBTraceOptions &options, lldb::SBError &error); |
| 399 | |
Greg Clayton | 4d32eb6 | 2016-06-24 23:40:35 +0000 | [diff] [blame] | 400 | lldb::SBError |
| 401 | GetMemoryRegionInfo(lldb::addr_t load_addr, lldb::SBMemoryRegionInfo ®ion_info); |
| 402 | |
| 403 | lldb::SBMemoryRegionInfoList |
| 404 | GetMemoryRegions(); |
| 405 | |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 406 | %feature("autodoc", " |
| 407 | Get information about the process. |
| 408 | Valid process info will only be returned when the process is alive, |
| 409 | use IsValid() to check if the info returned is valid. |
| 410 | |
| 411 | process_info = process.GetProcessInfo() |
| 412 | if process_info.IsValid(): |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 413 | process_info.GetProcessID()") GetProcessInfo; |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 414 | lldb::SBProcessInfo |
| 415 | GetProcessInfo(); |
| 416 | |
Greg Clayton | 13d1950 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 417 | %pythoncode %{ |
Greg Clayton | 6b2bd93 | 2012-02-01 08:09:32 +0000 | [diff] [blame] | 418 | def __get_is_alive__(self): |
| 419 | '''Returns "True" if the process is currently alive, "False" otherwise''' |
| 420 | s = self.GetState() |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 421 | if (s == eStateAttaching or |
| 422 | s == eStateLaunching or |
| 423 | s == eStateStopped or |
| 424 | s == eStateRunning or |
| 425 | s == eStateStepping or |
| 426 | s == eStateCrashed or |
Greg Clayton | 6b2bd93 | 2012-02-01 08:09:32 +0000 | [diff] [blame] | 427 | s == eStateSuspended): |
| 428 | return True |
| 429 | return False |
| 430 | |
| 431 | def __get_is_running__(self): |
| 432 | '''Returns "True" if the process is currently running, "False" otherwise''' |
| 433 | state = self.GetState() |
| 434 | if state == eStateRunning or state == eStateStepping: |
| 435 | return True |
| 436 | return False |
| 437 | |
Greg Clayton | d458c4d | 2016-07-05 18:19:43 +0000 | [diff] [blame] | 438 | def __get_is_stopped__(self): |
Greg Clayton | 6b2bd93 | 2012-02-01 08:09:32 +0000 | [diff] [blame] | 439 | '''Returns "True" if the process is currently stopped, "False" otherwise''' |
| 440 | state = self.GetState() |
| 441 | if state == eStateStopped or state == eStateCrashed or state == eStateSuspended: |
| 442 | return True |
| 443 | return False |
| 444 | |
Greg Clayton | b62bb8c | 2012-02-03 03:22:53 +0000 | [diff] [blame] | 445 | class threads_access(object): |
Greg Clayton | 6b2bd93 | 2012-02-01 08:09:32 +0000 | [diff] [blame] | 446 | '''A helper object that will lazily hand out thread for a process when supplied an index.''' |
| 447 | def __init__(self, sbprocess): |
| 448 | self.sbprocess = sbprocess |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 449 | |
Greg Clayton | 6b2bd93 | 2012-02-01 08:09:32 +0000 | [diff] [blame] | 450 | def __len__(self): |
Filipe Cabecinhas | 1a96ef8 | 2012-05-11 20:39:42 +0000 | [diff] [blame] | 451 | if self.sbprocess: |
| 452 | return int(self.sbprocess.GetNumThreads()) |
Greg Clayton | 6b2bd93 | 2012-02-01 08:09:32 +0000 | [diff] [blame] | 453 | return 0 |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 454 | |
Greg Clayton | 6b2bd93 | 2012-02-01 08:09:32 +0000 | [diff] [blame] | 455 | def __getitem__(self, key): |
| 456 | if type(key) is int and key < len(self): |
| 457 | return self.sbprocess.GetThreadAtIndex(key) |
| 458 | return None |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 459 | |
Greg Clayton | b62bb8c | 2012-02-03 03:22:53 +0000 | [diff] [blame] | 460 | def get_threads_access_object(self): |
| 461 | '''An accessor function that returns a modules_access() object which allows lazy thread access from a lldb.SBProcess object.''' |
| 462 | return self.threads_access (self) |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 463 | |
Greg Clayton | 6b2bd93 | 2012-02-01 08:09:32 +0000 | [diff] [blame] | 464 | def get_process_thread_list(self): |
Greg Clayton | b62bb8c | 2012-02-03 03:22:53 +0000 | [diff] [blame] | 465 | '''An accessor function that returns a list() that contains all threads in a lldb.SBProcess object.''' |
Greg Clayton | 6b2bd93 | 2012-02-01 08:09:32 +0000 | [diff] [blame] | 466 | threads = [] |
Enrico Granata | beea93c | 2012-10-08 19:06:11 +0000 | [diff] [blame] | 467 | accessor = self.get_threads_access_object() |
| 468 | for idx in range(len(accessor)): |
| 469 | threads.append(accessor[idx]) |
Greg Clayton | 6b2bd93 | 2012-02-01 08:09:32 +0000 | [diff] [blame] | 470 | return threads |
Pavel Labath | 4da5a1d | 2019-04-03 11:48:38 +0000 | [diff] [blame] | 471 | |
| 472 | def __iter__(self): |
| 473 | '''Iterate over all threads in a lldb.SBProcess object.''' |
| 474 | return lldb_iter(self, 'GetNumThreads', 'GetThreadAtIndex') |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 475 | |
Pavel Labath | 4da5a1d | 2019-04-03 11:48:38 +0000 | [diff] [blame] | 476 | def __len__(self): |
| 477 | '''Return the number of threads in a lldb.SBProcess object.''' |
| 478 | return self.GetNumThreads() |
| 479 | |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 480 | |
Jonas Devlieghere | 89b6584 | 2019-07-02 22:18:35 +0000 | [diff] [blame^] | 481 | threads = property(get_process_thread_list, None, doc='''A read only property that returns a list() of lldb.SBThread objects for this process.''') |
| 482 | thread = property(get_threads_access_object, None, doc='''A read only property that returns an object that can access threads by thread index (thread = lldb.process.thread[12]).''') |
| 483 | is_alive = property(__get_is_alive__, None, doc='''A read only property that returns a boolean value that indicates if this process is currently alive.''') |
| 484 | is_running = property(__get_is_running__, None, doc='''A read only property that returns a boolean value that indicates if this process is currently running.''') |
| 485 | is_stopped = property(__get_is_stopped__, None, doc='''A read only property that returns a boolean value that indicates if this process is currently stopped.''') |
| 486 | id = property(GetProcessID, None, doc='''A read only property that returns the process ID as an integer.''') |
| 487 | target = property(GetTarget, None, doc='''A read only property that an lldb object that represents the target (lldb.SBTarget) that owns this process.''') |
| 488 | num_threads = property(GetNumThreads, None, doc='''A read only property that returns the number of threads in this process as an integer.''') |
| 489 | selected_thread = property(GetSelectedThread, SetSelectedThread, doc='''A read/write property that gets/sets the currently selected thread in this process. The getter returns a lldb.SBThread object and the setter takes an lldb.SBThread object.''') |
| 490 | state = property(GetState, None, doc='''A read only property that returns an lldb enumeration value (see enumerations that start with "lldb.eState") that represents the current state of this process (running, stopped, exited, etc.).''') |
| 491 | exit_state = property(GetExitStatus, None, doc='''A read only property that returns an exit status as an integer of this process when the process state is lldb.eStateExited.''') |
| 492 | exit_description = property(GetExitDescription, None, doc='''A read only property that returns an exit description as a string of this process when the process state is lldb.eStateExited.''') |
| 493 | broadcaster = property(GetBroadcaster, None, doc='''A read only property that an lldb object that represents the broadcaster (lldb.SBBroadcaster) for this process.''') |
Greg Clayton | 13d1950 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 494 | %} |
| 495 | |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 496 | }; |
| 497 | |
| 498 | } // namespace lldb |