SBProcess.h revision b4e08abf4972befc8412bc83a0205fbdc547290e
1//===-- SBProcess.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 LLDB_SBProcess_h_ 11#define LLDB_SBProcess_h_ 12 13#include "lldb/API/SBDefines.h" 14#include "lldb/API/SBError.h" 15#include "lldb/API/SBTarget.h" 16#include <stdio.h> 17 18namespace lldb { 19 20class SBEvent; 21 22class SBProcess 23{ 24public: 25 //------------------------------------------------------------------ 26 /// Broadcaster event bits definitions. 27 //------------------------------------------------------------------ 28 enum 29 { 30 eBroadcastBitStateChanged = (1 << 0), 31 eBroadcastBitInterrupt = (1 << 1), 32 eBroadcastBitSTDOUT = (1 << 2), 33 eBroadcastBitSTDERR = (1 << 3), 34 eBroadcastBitProfileData = (1 << 4) 35 }; 36 37 SBProcess (); 38 39 SBProcess (const lldb::SBProcess& rhs); 40 41 const lldb::SBProcess& 42 operator = (const lldb::SBProcess& rhs); 43 44 SBProcess (const lldb::ProcessSP &process_sp); 45 46 ~SBProcess(); 47 48 static const char * 49 GetBroadcasterClassName (); 50 51 const char * 52 GetPluginName (); 53 54 const char * 55 GetShortPluginName (); 56 57 void 58 Clear (); 59 60 bool 61 IsValid() const; 62 63 lldb::SBTarget 64 GetTarget() const; 65 66 lldb::ByteOrder 67 GetByteOrder() const; 68 69 size_t 70 PutSTDIN (const char *src, size_t src_len); 71 72 size_t 73 GetSTDOUT (char *dst, size_t dst_len) const; 74 75 size_t 76 GetSTDERR (char *dst, size_t dst_len) const; 77 78 size_t 79 GetAsyncProfileData(char *dst, size_t dst_len) const; 80 81 void 82 ReportEventState (const lldb::SBEvent &event, FILE *out) const; 83 84 void 85 AppendEventStateReport (const lldb::SBEvent &event, lldb::SBCommandReturnObject &result); 86 87 //------------------------------------------------------------------ 88 /// Remote connection related functions. These will fail if the 89 /// process is not in eStateConnected. They are intended for use 90 /// when connecting to an externally managed debugserver instance. 91 //------------------------------------------------------------------ 92 bool 93 RemoteAttachToProcessWithID (lldb::pid_t pid, 94 lldb::SBError& error); 95 96 bool 97 RemoteLaunch (char const **argv, 98 char const **envp, 99 const char *stdin_path, 100 const char *stdout_path, 101 const char *stderr_path, 102 const char *working_directory, 103 uint32_t launch_flags, 104 bool stop_at_entry, 105 lldb::SBError& error); 106 107 //------------------------------------------------------------------ 108 // Thread related functions 109 //------------------------------------------------------------------ 110 uint32_t 111 GetNumThreads (); 112 113 lldb::SBThread 114 GetThreadAtIndex (size_t index); 115 116 lldb::SBThread 117 GetThreadByID (lldb::tid_t sb_thread_id); 118 119 lldb::SBThread 120 GetThreadByIndexID (uint32_t index_id); 121 122 lldb::SBThread 123 GetSelectedThread () const; 124 125 //------------------------------------------------------------------ 126 // Function for lazily creating a thread using the current OS 127 // plug-in. This function will be removed in the future when there 128 // are APIs to create SBThread objects through the interface and add 129 // them to the process through the SBProcess API. 130 //------------------------------------------------------------------ 131 lldb::SBThread 132 CreateOSPluginThread (lldb::tid_t tid, lldb::addr_t context); 133 134 bool 135 SetSelectedThread (const lldb::SBThread &thread); 136 137 bool 138 SetSelectedThreadByID (lldb::tid_t tid); 139 140 bool 141 SetSelectedThreadByIndexID (uint32_t index_id); 142 143 //------------------------------------------------------------------ 144 // Stepping related functions 145 //------------------------------------------------------------------ 146 147 lldb::StateType 148 GetState (); 149 150 int 151 GetExitStatus (); 152 153 const char * 154 GetExitDescription (); 155 156 //------------------------------------------------------------------ 157 /// Gets the process ID 158 /// 159 /// Returns the process identifier for the process as it is known 160 /// on the system on which the process is running. For unix systems 161 /// this is typically the same as if you called "getpid()" in the 162 /// process. 163 /// 164 /// @return 165 /// Returns LLDB_INVALID_PROCESS_ID if this object does not 166 /// contain a valid process object, or if the process has not 167 /// been launched. Returns a valid process ID if the process is 168 /// valid. 169 //------------------------------------------------------------------ 170 lldb::pid_t 171 GetProcessID (); 172 173 //------------------------------------------------------------------ 174 /// Gets the unique ID associated with this process object 175 /// 176 /// Unique IDs start at 1 and increment up with each new process 177 /// instance. Since starting a process on a system might always 178 /// create a process with the same process ID, there needs to be a 179 /// way to tell two process instances apart. 180 /// 181 /// @return 182 /// Returns a non-zero integer ID if this object contains a 183 /// valid process object, zero if this object does not contain 184 /// a valid process object. 185 //------------------------------------------------------------------ 186 uint32_t 187 GetUniqueID(); 188 189 uint32_t 190 GetAddressByteSize() const; 191 192 lldb::SBError 193 Destroy (); 194 195 lldb::SBError 196 Continue (); 197 198 lldb::SBError 199 Stop (); 200 201 lldb::SBError 202 Kill (); 203 204 lldb::SBError 205 Detach (); 206 207 lldb::SBError 208 Detach (bool keep_stopped); 209 210 lldb::SBError 211 Signal (int signal); 212 213 void 214 SendAsyncInterrupt(); 215 216 uint32_t 217 GetStopID(bool include_expression_stops = false); 218 219 size_t 220 ReadMemory (addr_t addr, void *buf, size_t size, lldb::SBError &error); 221 222 size_t 223 WriteMemory (addr_t addr, const void *buf, size_t size, lldb::SBError &error); 224 225 size_t 226 ReadCStringFromMemory (addr_t addr, void *buf, size_t size, lldb::SBError &error); 227 228 uint64_t 229 ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &error); 230 231 lldb::addr_t 232 ReadPointerFromMemory (addr_t addr, lldb::SBError &error); 233 234 // Events 235 static lldb::StateType 236 GetStateFromEvent (const lldb::SBEvent &event); 237 238 static bool 239 GetRestartedFromEvent (const lldb::SBEvent &event); 240 241 static size_t 242 GetNumRestartedReasonsFromEvent (const lldb::SBEvent &event); 243 244 static const char * 245 GetRestartedReasonAtIndexFromEvent (const lldb::SBEvent &event, size_t idx); 246 247 static lldb::SBProcess 248 GetProcessFromEvent (const lldb::SBEvent &event); 249 250 static bool 251 EventIsProcessEvent (const lldb::SBEvent &event); 252 253 lldb::SBBroadcaster 254 GetBroadcaster () const; 255 256 static const char * 257 GetBroadcasterClass (); 258 259 bool 260 GetDescription (lldb::SBStream &description); 261 262 uint32_t 263 GetNumSupportedHardwareWatchpoints (lldb::SBError &error) const; 264 265 uint32_t 266 LoadImage (lldb::SBFileSpec &image_spec, lldb::SBError &error); 267 268 lldb::SBError 269 UnloadImage (uint32_t image_token); 270 271protected: 272 friend class SBAddress; 273 friend class SBBreakpoint; 274 friend class SBBreakpointLocation; 275 friend class SBCommandInterpreter; 276 friend class SBDebugger; 277 friend class SBFunction; 278 friend class SBModule; 279 friend class SBTarget; 280 friend class SBThread; 281 friend class SBValue; 282 283 lldb::ProcessSP 284 GetSP() const; 285 286 void 287 SetSP (const lldb::ProcessSP &process_sp); 288 289 lldb::ProcessWP m_opaque_wp; 290}; 291 292} // namespace lldb 293 294#endif // LLDB_SBProcess_h_ 295