Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SBProcess.cpp -------------------------------------------*- 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 | |
Eli Friedman | 7a62c8b | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 10 | #include "lldb/API/SBProcess.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 11 | |
| 12 | #include "lldb/lldb-defines.h" |
| 13 | #include "lldb/lldb-types.h" |
| 14 | |
Jim Ingham | 84cdc15 | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 15 | #include "lldb/Interpreter/Args.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | #include "lldb/Core/DataBufferHeap.h" |
| 17 | #include "lldb/Core/DataExtractor.h" |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame^] | 18 | #include "lldb/Core/Debugger.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/Core/State.h" |
| 20 | #include "lldb/Core/Stream.h" |
| 21 | #include "lldb/Core/StreamFile.h" |
| 22 | #include "lldb/Target/Process.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 24 | #include "lldb/Target/Target.h" |
| 25 | #include "lldb/Target/Thread.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | |
| 27 | // Project includes |
| 28 | |
Eli Friedman | 7a62c8b | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 29 | #include "lldb/API/SBBroadcaster.h" |
| 30 | #include "lldb/API/SBDebugger.h" |
| 31 | #include "lldb/API/SBCommandReturnObject.h" |
| 32 | #include "lldb/API/SBEvent.h" |
| 33 | #include "lldb/API/SBThread.h" |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 34 | #include "lldb/API/SBStream.h" |
Eli Friedman | 7a62c8b | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 35 | #include "lldb/API/SBStringList.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | |
| 37 | using namespace lldb; |
| 38 | using namespace lldb_private; |
| 39 | |
| 40 | |
| 41 | |
| 42 | SBProcess::SBProcess () : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 43 | m_opaque_sp() |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | { |
| 45 | } |
| 46 | |
| 47 | |
| 48 | //---------------------------------------------------------------------- |
| 49 | // SBProcess constructor |
| 50 | //---------------------------------------------------------------------- |
| 51 | |
| 52 | SBProcess::SBProcess (const SBProcess& rhs) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 53 | m_opaque_sp (rhs.m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | { |
| 55 | } |
| 56 | |
| 57 | |
| 58 | SBProcess::SBProcess (const lldb::ProcessSP &process_sp) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 59 | m_opaque_sp (process_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | { |
| 61 | } |
| 62 | |
| 63 | //---------------------------------------------------------------------- |
| 64 | // Destructor |
| 65 | //---------------------------------------------------------------------- |
| 66 | SBProcess::~SBProcess() |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | void |
| 71 | SBProcess::SetProcess (const ProcessSP &process_sp) |
| 72 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 73 | m_opaque_sp = process_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void |
| 77 | SBProcess::Clear () |
| 78 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 79 | m_opaque_sp.reset(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | |
| 83 | bool |
| 84 | SBProcess::IsValid() const |
| 85 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 86 | return m_opaque_sp.get() != NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | |
| 90 | uint32_t |
| 91 | SBProcess::GetNumThreads () |
| 92 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 93 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 94 | { |
| 95 | const bool can_update = true; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 96 | return m_opaque_sp->GetThreadList().GetSize(can_update); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 97 | } |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | SBThread |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 102 | SBProcess::GetSelectedThread () const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 103 | { |
| 104 | SBThread sb_thread; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 105 | if (m_opaque_sp) |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 106 | sb_thread.SetThread (m_opaque_sp->GetThreadList().GetSelectedThread()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 107 | return sb_thread; |
| 108 | } |
| 109 | |
| 110 | SBTarget |
| 111 | SBProcess::GetTarget() const |
| 112 | { |
| 113 | SBTarget sb_target; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 114 | if (m_opaque_sp) |
| 115 | sb_target = m_opaque_sp->GetTarget().GetSP(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 116 | return sb_target; |
| 117 | } |
| 118 | |
| 119 | |
| 120 | size_t |
| 121 | SBProcess::PutSTDIN (const char *src, size_t src_len) |
| 122 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 123 | if (m_opaque_sp != NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 124 | { |
| 125 | Error error; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 126 | return m_opaque_sp->PutSTDIN (src, src_len, error); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 127 | } |
| 128 | else |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | size_t |
| 133 | SBProcess::GetSTDOUT (char *dst, size_t dst_len) const |
| 134 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 135 | if (m_opaque_sp != NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 136 | { |
| 137 | Error error; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 138 | return m_opaque_sp->GetSTDOUT (dst, dst_len, error); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 139 | } |
| 140 | else |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | size_t |
| 145 | SBProcess::GetSTDERR (char *dst, size_t dst_len) const |
| 146 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 147 | if (m_opaque_sp != NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 148 | { |
| 149 | Error error; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 150 | return m_opaque_sp->GetSTDERR (dst, dst_len, error); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 151 | } |
| 152 | else |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | void |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 157 | SBProcess::ReportEventState (const SBEvent &event, FILE *out) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 158 | { |
| 159 | if (out == NULL) |
| 160 | return; |
| 161 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 162 | if (m_opaque_sp != NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 163 | { |
| 164 | const StateType event_state = SBProcess::GetStateFromEvent (event); |
| 165 | char message[1024]; |
| 166 | int message_len = ::snprintf (message, |
| 167 | sizeof (message), |
| 168 | "Process %d %s\n", |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 169 | m_opaque_sp->GetID(), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 170 | SBDebugger::StateAsCString (event_state)); |
| 171 | |
| 172 | if (message_len > 0) |
| 173 | ::fwrite (message, 1, message_len, out); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | void |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 178 | SBProcess::AppendEventStateReport (const SBEvent &event, SBCommandReturnObject &result) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 179 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 180 | if (m_opaque_sp != NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 181 | { |
| 182 | const StateType event_state = SBProcess::GetStateFromEvent (event); |
| 183 | char message[1024]; |
| 184 | ::snprintf (message, |
| 185 | sizeof (message), |
| 186 | "Process %d %s\n", |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 187 | m_opaque_sp->GetID(), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 188 | SBDebugger::StateAsCString (event_state)); |
| 189 | |
| 190 | result.AppendMessage (message); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | bool |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 195 | SBProcess::SetSelectedThread (const SBThread &thread) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 196 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 197 | if (m_opaque_sp != NULL) |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 198 | return m_opaque_sp->GetThreadList().SetSelectedThreadByID (thread.GetThreadID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 199 | return false; |
| 200 | } |
| 201 | |
| 202 | bool |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 203 | SBProcess::SetSelectedThreadByID (uint32_t tid) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 204 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 205 | if (m_opaque_sp != NULL) |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 206 | return m_opaque_sp->GetThreadList().SetSelectedThreadByID (tid); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 207 | return false; |
| 208 | } |
| 209 | |
| 210 | SBThread |
| 211 | SBProcess::GetThreadAtIndex (size_t index) |
| 212 | { |
| 213 | SBThread thread; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 214 | if (m_opaque_sp) |
| 215 | thread.SetThread (m_opaque_sp->GetThreadList().GetThreadAtIndex(index)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 216 | return thread; |
| 217 | } |
| 218 | |
| 219 | StateType |
| 220 | SBProcess::GetState () |
| 221 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 222 | if (m_opaque_sp != NULL) |
| 223 | return m_opaque_sp->GetState(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 224 | else |
| 225 | return eStateInvalid; |
| 226 | } |
| 227 | |
| 228 | |
| 229 | int |
| 230 | SBProcess::GetExitStatus () |
| 231 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 232 | if (m_opaque_sp != NULL) |
| 233 | return m_opaque_sp->GetExitStatus (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 234 | else |
| 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | const char * |
| 239 | SBProcess::GetExitDescription () |
| 240 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 241 | if (m_opaque_sp != NULL) |
| 242 | return m_opaque_sp->GetExitDescription (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 243 | else |
| 244 | return NULL; |
| 245 | } |
| 246 | |
| 247 | lldb::pid_t |
| 248 | SBProcess::GetProcessID () |
| 249 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 250 | if (m_opaque_sp) |
| 251 | return m_opaque_sp->GetID(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 252 | else |
| 253 | return LLDB_INVALID_PROCESS_ID; |
| 254 | } |
| 255 | |
| 256 | uint32_t |
| 257 | SBProcess::GetAddressByteSize () const |
| 258 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 259 | if (m_opaque_sp) |
| 260 | return m_opaque_sp->GetAddressByteSize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 261 | else |
| 262 | return 0; |
| 263 | } |
| 264 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 265 | bool |
| 266 | SBProcess::WaitUntilProcessHasStopped (SBCommandReturnObject &result) |
| 267 | { |
| 268 | bool state_changed = false; |
| 269 | |
| 270 | if (IsValid()) |
| 271 | { |
| 272 | EventSP event_sp; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 273 | StateType state = m_opaque_sp->WaitForStateChangedEvents (NULL, event_sp); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 274 | |
| 275 | while (StateIsStoppedState (state)) |
| 276 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 277 | state = m_opaque_sp->WaitForStateChangedEvents (NULL, event_sp); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 278 | SBEvent event (event_sp); |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 279 | AppendEventStateReport (event, result); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 280 | state_changed = true; |
| 281 | } |
| 282 | } |
| 283 | return state_changed; |
| 284 | } |
| 285 | |
| 286 | SBError |
| 287 | SBProcess::Continue () |
| 288 | { |
| 289 | SBError sb_error; |
| 290 | if (IsValid()) |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame^] | 291 | { |
| 292 | Error error (m_opaque_sp->Resume()); |
| 293 | if (error.Success()) |
| 294 | { |
| 295 | if (m_opaque_sp->GetTarget().GetDebugger().GetAsyncExecution () == false) |
| 296 | m_opaque_sp->WaitForProcessToStop (NULL); |
| 297 | } |
| 298 | sb_error.SetError(error); |
| 299 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 300 | else |
| 301 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 302 | |
| 303 | return sb_error; |
| 304 | } |
| 305 | |
| 306 | |
| 307 | SBError |
| 308 | SBProcess::Destroy () |
| 309 | { |
| 310 | SBError sb_error; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 311 | if (m_opaque_sp) |
| 312 | sb_error.SetError(m_opaque_sp->Destroy()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 313 | else |
| 314 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 315 | |
| 316 | return sb_error; |
| 317 | } |
| 318 | |
| 319 | |
| 320 | SBError |
| 321 | SBProcess::Stop () |
| 322 | { |
| 323 | SBError sb_error; |
| 324 | if (IsValid()) |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 325 | sb_error.SetError (m_opaque_sp->Halt()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 326 | else |
| 327 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 328 | return sb_error; |
| 329 | } |
| 330 | |
| 331 | SBError |
| 332 | SBProcess::Kill () |
| 333 | { |
| 334 | SBError sb_error; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 335 | if (m_opaque_sp) |
| 336 | sb_error.SetError (m_opaque_sp->Destroy()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 337 | else |
| 338 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 339 | return sb_error; |
| 340 | } |
| 341 | |
| 342 | |
| 343 | SBError |
| 344 | SBProcess::AttachByName (const char *name, bool wait_for_launch) |
| 345 | { |
| 346 | SBError sb_error; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 347 | if (m_opaque_sp) |
| 348 | sb_error.SetError (m_opaque_sp->Attach (name, wait_for_launch)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 349 | else |
| 350 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 351 | return sb_error; |
| 352 | } |
| 353 | |
| 354 | lldb::pid_t |
Caroline Tice | dfc91c3 | 2010-09-15 18:29:06 +0000 | [diff] [blame] | 355 | SBProcess::AttachByPID (lldb::pid_t attach_pid) // DEPRECATED: will be removed in a few builds in favor of SBError AttachByPID(pid_t) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 356 | { |
| 357 | Attach (attach_pid); |
| 358 | return GetProcessID(); |
| 359 | } |
| 360 | |
Caroline Tice | dfc91c3 | 2010-09-15 18:29:06 +0000 | [diff] [blame] | 361 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 362 | SBError |
| 363 | SBProcess::Attach (lldb::pid_t attach_pid) |
| 364 | { |
| 365 | SBError sb_error; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 366 | if (m_opaque_sp) |
| 367 | sb_error.SetError (m_opaque_sp->Attach (attach_pid)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 368 | else |
| 369 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 370 | return sb_error; |
| 371 | } |
| 372 | |
| 373 | SBError |
| 374 | SBProcess::Detach () |
| 375 | { |
| 376 | SBError sb_error; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 377 | if (m_opaque_sp) |
| 378 | sb_error.SetError (m_opaque_sp->Detach()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 379 | else |
| 380 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 381 | |
| 382 | return sb_error; |
| 383 | } |
| 384 | |
| 385 | SBError |
| 386 | SBProcess::Signal (int signal) |
| 387 | { |
| 388 | SBError sb_error; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 389 | if (m_opaque_sp) |
| 390 | sb_error.SetError (m_opaque_sp->Signal (signal)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 391 | else |
| 392 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 393 | return sb_error; |
| 394 | } |
| 395 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 396 | SBThread |
| 397 | SBProcess::GetThreadByID (tid_t sb_thread_id) |
| 398 | { |
| 399 | SBThread thread; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 400 | if (m_opaque_sp) |
| 401 | thread.SetThread (m_opaque_sp->GetThreadList().FindThreadByID ((tid_t) sb_thread_id)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 402 | return thread; |
| 403 | } |
| 404 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 405 | StateType |
| 406 | SBProcess::GetStateFromEvent (const SBEvent &event) |
| 407 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 408 | return Process::ProcessEventData::GetStateFromEvent (event.get()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 411 | bool |
| 412 | SBProcess::GetRestartedFromEvent (const SBEvent &event) |
| 413 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 414 | return Process::ProcessEventData::GetRestartedFromEvent (event.get()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | SBProcess |
| 418 | SBProcess::GetProcessFromEvent (const SBEvent &event) |
| 419 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 420 | SBProcess process(Process::ProcessEventData::GetProcessFromEvent (event.get())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 421 | return process; |
| 422 | } |
| 423 | |
| 424 | |
| 425 | SBBroadcaster |
| 426 | SBProcess::GetBroadcaster () const |
| 427 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 428 | SBBroadcaster broadcaster(m_opaque_sp.get(), false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 429 | return broadcaster; |
| 430 | } |
| 431 | |
| 432 | lldb_private::Process * |
| 433 | SBProcess::operator->() const |
| 434 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 435 | return m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | size_t |
| 439 | SBProcess::ReadMemory (addr_t addr, void *dst, size_t dst_len, SBError &sb_error) |
| 440 | { |
| 441 | size_t bytes_read = 0; |
| 442 | |
| 443 | if (IsValid()) |
| 444 | { |
| 445 | Error error; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 446 | bytes_read = m_opaque_sp->ReadMemory (addr, dst, dst_len, error); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 447 | sb_error.SetError (error); |
| 448 | } |
| 449 | else |
| 450 | { |
| 451 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 452 | } |
| 453 | |
| 454 | return bytes_read; |
| 455 | } |
| 456 | |
| 457 | size_t |
| 458 | SBProcess::WriteMemory (addr_t addr, const void *src, size_t src_len, SBError &sb_error) |
| 459 | { |
| 460 | size_t bytes_written = 0; |
| 461 | |
| 462 | if (IsValid()) |
| 463 | { |
| 464 | Error error; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 465 | bytes_written = m_opaque_sp->WriteMemory (addr, src, src_len, error); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 466 | sb_error.SetError (error); |
| 467 | } |
| 468 | |
| 469 | return bytes_written; |
| 470 | } |
| 471 | |
| 472 | // Mimic shared pointer... |
| 473 | lldb_private::Process * |
| 474 | SBProcess::get() const |
| 475 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 476 | return m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 479 | bool |
| 480 | SBProcess::GetDescription (SBStream &description) |
| 481 | { |
| 482 | if (m_opaque_sp) |
| 483 | { |
| 484 | char path[PATH_MAX]; |
| 485 | GetTarget().GetExecutable().GetPath (path, sizeof(path)); |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 486 | Module *exe_module = m_opaque_sp->GetTarget().GetExecutableModule ().get(); |
| 487 | const char *exe_name = NULL; |
| 488 | if (exe_module) |
| 489 | exe_name = exe_module->GetFileSpec().GetFilename().AsCString(); |
| 490 | |
| 491 | description.Printf ("Process {pid: %d, state: %s, threads: %d%s%s}", |
| 492 | m_opaque_sp->GetID(), |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 493 | SBDebugger::StateAsCString (GetState()), |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 494 | GetNumThreads(), |
| 495 | exe_name ? ", executable: " : "", |
| 496 | exe_name ? exe_name : ""); |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 497 | } |
| 498 | else |
| 499 | description.Printf ("No value"); |
| 500 | |
| 501 | return true; |
| 502 | } |