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" |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Debugger.h" |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Log.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/Core/State.h" |
| 19 | #include "lldb/Core/Stream.h" |
| 20 | #include "lldb/Core/StreamFile.h" |
| 21 | #include "lldb/Target/Process.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 23 | #include "lldb/Target/Target.h" |
| 24 | #include "lldb/Target/Thread.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | |
| 26 | // Project includes |
| 27 | |
Eli Friedman | 7a62c8b | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 28 | #include "lldb/API/SBBroadcaster.h" |
Eli Friedman | 7a62c8b | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 29 | #include "lldb/API/SBCommandReturnObject.h" |
Greg Clayton | 0a8dcac | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 30 | #include "lldb/API/SBDebugger.h" |
Eli Friedman | 7a62c8b | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 31 | #include "lldb/API/SBEvent.h" |
Greg Clayton | 0a8dcac | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 32 | #include "lldb/API/SBFileSpec.h" |
Eli Friedman | 7a62c8b | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | SBProcess::SBProcess () : |
Greg Clayton | bcaf99a | 2012-07-12 20:32:19 +0000 | [diff] [blame] | 42 | m_opaque_wp() |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | { |
| 44 | } |
| 45 | |
| 46 | |
| 47 | //---------------------------------------------------------------------- |
| 48 | // SBProcess constructor |
| 49 | //---------------------------------------------------------------------- |
| 50 | |
| 51 | SBProcess::SBProcess (const SBProcess& rhs) : |
Greg Clayton | bcaf99a | 2012-07-12 20:32:19 +0000 | [diff] [blame] | 52 | m_opaque_wp (rhs.m_opaque_wp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 53 | { |
| 54 | } |
| 55 | |
| 56 | |
| 57 | SBProcess::SBProcess (const lldb::ProcessSP &process_sp) : |
Greg Clayton | bcaf99a | 2012-07-12 20:32:19 +0000 | [diff] [blame] | 58 | m_opaque_wp (process_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 59 | { |
| 60 | } |
| 61 | |
Greg Clayton | 538eb82 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 62 | const SBProcess& |
| 63 | SBProcess::operator = (const SBProcess& rhs) |
| 64 | { |
| 65 | if (this != &rhs) |
Greg Clayton | bcaf99a | 2012-07-12 20:32:19 +0000 | [diff] [blame] | 66 | m_opaque_wp = rhs.m_opaque_wp; |
Greg Clayton | 538eb82 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 67 | return *this; |
| 68 | } |
| 69 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 70 | //---------------------------------------------------------------------- |
| 71 | // Destructor |
| 72 | //---------------------------------------------------------------------- |
| 73 | SBProcess::~SBProcess() |
| 74 | { |
| 75 | } |
| 76 | |
Jim Ingham | 5a15e69 | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 77 | const char * |
| 78 | SBProcess::GetBroadcasterClassName () |
| 79 | { |
| 80 | return Process::GetStaticBroadcasterClass().AsCString(); |
| 81 | } |
| 82 | |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 83 | lldb::ProcessSP |
| 84 | SBProcess::GetSP() const |
| 85 | { |
Greg Clayton | bcaf99a | 2012-07-12 20:32:19 +0000 | [diff] [blame] | 86 | return m_opaque_wp.lock(); |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 89 | void |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 90 | SBProcess::SetSP (const ProcessSP &process_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 91 | { |
Greg Clayton | bcaf99a | 2012-07-12 20:32:19 +0000 | [diff] [blame] | 92 | m_opaque_wp = process_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void |
| 96 | SBProcess::Clear () |
| 97 | { |
Greg Clayton | bcaf99a | 2012-07-12 20:32:19 +0000 | [diff] [blame] | 98 | m_opaque_wp.reset(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | |
| 102 | bool |
| 103 | SBProcess::IsValid() const |
| 104 | { |
Jim Ingham | d0bdddf | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 105 | ProcessSP process_sp(m_opaque_wp.lock()); |
| 106 | return ((bool) process_sp && process_sp->IsValid()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 107 | } |
| 108 | |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 109 | bool |
| 110 | SBProcess::RemoteLaunch (char const **argv, |
| 111 | char const **envp, |
| 112 | const char *stdin_path, |
| 113 | const char *stdout_path, |
| 114 | const char *stderr_path, |
| 115 | const char *working_directory, |
| 116 | uint32_t launch_flags, |
| 117 | bool stop_at_entry, |
| 118 | lldb::SBError& error) |
| 119 | { |
| 120 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 121 | if (log) { |
| 122 | log->Printf ("SBProcess(%p)::RemoteLaunch (argv=%p, envp=%p, stdin=%s, stdout=%s, stderr=%s, working-dir=%s, launch_flags=0x%x, stop_at_entry=%i, &error (%p))...", |
Greg Clayton | bcaf99a | 2012-07-12 20:32:19 +0000 | [diff] [blame] | 123 | m_opaque_wp.lock().get(), |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 124 | argv, |
| 125 | envp, |
| 126 | stdin_path ? stdin_path : "NULL", |
| 127 | stdout_path ? stdout_path : "NULL", |
| 128 | stderr_path ? stderr_path : "NULL", |
| 129 | working_directory ? working_directory : "NULL", |
| 130 | launch_flags, |
| 131 | stop_at_entry, |
| 132 | error.get()); |
| 133 | } |
| 134 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 135 | ProcessSP process_sp(GetSP()); |
| 136 | if (process_sp) |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 137 | { |
Greg Clayton | 9f3c98e | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 138 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 139 | if (process_sp->GetState() == eStateConnected) |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 140 | { |
Greg Clayton | 9f3c98e | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 141 | if (stop_at_entry) |
| 142 | launch_flags |= eLaunchFlagStopAtEntry; |
| 143 | ProcessLaunchInfo launch_info (stdin_path, |
| 144 | stdout_path, |
| 145 | stderr_path, |
| 146 | working_directory, |
| 147 | launch_flags); |
| 148 | Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer(); |
| 149 | if (exe_module) |
| 150 | launch_info.SetExecutableFile(exe_module->GetFileSpec(), true); |
| 151 | if (argv) |
| 152 | launch_info.GetArguments().AppendArguments (argv); |
| 153 | if (envp) |
| 154 | launch_info.GetEnvironmentEntries ().SetArguments (envp); |
| 155 | error.SetError (process_sp->Launch (launch_info)); |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 156 | } |
| 157 | else |
| 158 | { |
Greg Clayton | 9f3c98e | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 159 | error.SetErrorString ("must be in eStateConnected to call RemoteLaunch"); |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | else |
| 163 | { |
| 164 | error.SetErrorString ("unable to attach pid"); |
| 165 | } |
| 166 | |
| 167 | if (log) { |
| 168 | SBStream sstr; |
| 169 | error.GetDescription (sstr); |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 170 | log->Printf ("SBProcess(%p)::RemoteLaunch (...) => SBError (%p): %s", process_sp.get(), error.get(), sstr.GetData()); |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | return error.Success(); |
| 174 | } |
| 175 | |
| 176 | bool |
| 177 | SBProcess::RemoteAttachToProcessWithID (lldb::pid_t pid, lldb::SBError& error) |
| 178 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 179 | ProcessSP process_sp(GetSP()); |
| 180 | if (process_sp) |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 181 | { |
Greg Clayton | 9f3c98e | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 182 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 183 | if (process_sp->GetState() == eStateConnected) |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 184 | { |
Greg Clayton | 9f3c98e | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 185 | ProcessAttachInfo attach_info; |
| 186 | attach_info.SetProcessID (pid); |
| 187 | error.SetError (process_sp->Attach (attach_info)); |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 188 | } |
| 189 | else |
| 190 | { |
Greg Clayton | 9f3c98e | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 191 | error.SetErrorString ("must be in eStateConnected to call RemoteAttachToProcessWithID"); |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | else |
| 195 | { |
| 196 | error.SetErrorString ("unable to attach pid"); |
| 197 | } |
| 198 | |
| 199 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 200 | if (log) { |
| 201 | SBStream sstr; |
| 202 | error.GetDescription (sstr); |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 203 | log->Printf ("SBProcess(%p)::RemoteAttachToProcessWithID (%llu) => SBError (%p): %s", process_sp.get(), pid, error.get(), sstr.GetData()); |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | return error.Success(); |
| 207 | } |
| 208 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 209 | |
| 210 | uint32_t |
| 211 | SBProcess::GetNumThreads () |
| 212 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 213 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 214 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 215 | uint32_t num_threads = 0; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 216 | ProcessSP process_sp(GetSP()); |
| 217 | if (process_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 218 | { |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 219 | Process::StopLocker stop_locker; |
| 220 | |
| 221 | const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 222 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 223 | num_threads = process_sp->GetThreadList().GetSize(can_update); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 224 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 225 | |
| 226 | if (log) |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 227 | log->Printf ("SBProcess(%p)::GetNumThreads () => %d", process_sp.get(), num_threads); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 228 | |
| 229 | return num_threads; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | SBThread |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 233 | SBProcess::GetSelectedThread () const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 234 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 235 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 236 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 237 | SBThread sb_thread; |
Greg Clayton | 90c5214 | 2012-01-30 02:53:15 +0000 | [diff] [blame] | 238 | ThreadSP thread_sp; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 239 | ProcessSP process_sp(GetSP()); |
| 240 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 241 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 242 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 243 | thread_sp = process_sp->GetThreadList().GetSelectedThread(); |
Greg Clayton | 90c5214 | 2012-01-30 02:53:15 +0000 | [diff] [blame] | 244 | sb_thread.SetThread (thread_sp); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 245 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 246 | |
| 247 | if (log) |
| 248 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 249 | log->Printf ("SBProcess(%p)::GetSelectedThread () => SBThread(%p)", process_sp.get(), thread_sp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 250 | } |
| 251 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 252 | return sb_thread; |
| 253 | } |
| 254 | |
| 255 | SBTarget |
| 256 | SBProcess::GetTarget() const |
| 257 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 258 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 259 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 260 | SBTarget sb_target; |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 261 | TargetSP target_sp; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 262 | ProcessSP process_sp(GetSP()); |
| 263 | if (process_sp) |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 264 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 265 | target_sp = process_sp->GetTarget().shared_from_this(); |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 266 | sb_target.SetSP (target_sp); |
| 267 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 268 | |
| 269 | if (log) |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 270 | log->Printf ("SBProcess(%p)::GetTarget () => SBTarget(%p)", process_sp.get(), target_sp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 271 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 272 | return sb_target; |
| 273 | } |
| 274 | |
| 275 | |
| 276 | size_t |
| 277 | SBProcess::PutSTDIN (const char *src, size_t src_len) |
| 278 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 279 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 280 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 281 | size_t ret_val = 0; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 282 | ProcessSP process_sp(GetSP()); |
| 283 | if (process_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 284 | { |
| 285 | Error error; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 286 | ret_val = process_sp->PutSTDIN (src, src_len, error); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 287 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 288 | |
| 289 | if (log) |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 290 | log->Printf ("SBProcess(%p)::PutSTDIN (src=\"%s\", src_len=%d) => %lu", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 291 | process_sp.get(), |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 292 | src, |
| 293 | (uint32_t) src_len, |
| 294 | ret_val); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 295 | |
| 296 | return ret_val; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | size_t |
| 300 | SBProcess::GetSTDOUT (char *dst, size_t dst_len) const |
| 301 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 302 | size_t bytes_read = 0; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 303 | ProcessSP process_sp(GetSP()); |
| 304 | if (process_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 305 | { |
| 306 | Error error; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 307 | bytes_read = process_sp->GetSTDOUT (dst, dst_len, error); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 308 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 309 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 310 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 311 | if (log) |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 312 | log->Printf ("SBProcess(%p)::GetSTDOUT (dst=\"%.*s\", dst_len=%zu) => %zu", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 313 | process_sp.get(), (int) bytes_read, dst, dst_len, bytes_read); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 314 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 315 | return bytes_read; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | size_t |
| 319 | SBProcess::GetSTDERR (char *dst, size_t dst_len) const |
| 320 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 321 | size_t bytes_read = 0; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 322 | ProcessSP process_sp(GetSP()); |
| 323 | if (process_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 324 | { |
| 325 | Error error; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 326 | bytes_read = process_sp->GetSTDERR (dst, dst_len, error); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 327 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 328 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 329 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 330 | if (log) |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 331 | log->Printf ("SBProcess(%p)::GetSTDERR (dst=\"%.*s\", dst_len=%zu) => %zu", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 332 | process_sp.get(), (int) bytes_read, dst, dst_len, bytes_read); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 333 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 334 | return bytes_read; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | void |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 338 | SBProcess::ReportEventState (const SBEvent &event, FILE *out) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 339 | { |
| 340 | if (out == NULL) |
| 341 | return; |
| 342 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 343 | ProcessSP process_sp(GetSP()); |
| 344 | if (process_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 345 | { |
| 346 | const StateType event_state = SBProcess::GetStateFromEvent (event); |
| 347 | char message[1024]; |
| 348 | int message_len = ::snprintf (message, |
| 349 | sizeof (message), |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 350 | "Process %llu %s\n", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 351 | process_sp->GetID(), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 352 | SBDebugger::StateAsCString (event_state)); |
| 353 | |
| 354 | if (message_len > 0) |
| 355 | ::fwrite (message, 1, message_len, out); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | void |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 360 | SBProcess::AppendEventStateReport (const SBEvent &event, SBCommandReturnObject &result) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 361 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 362 | ProcessSP process_sp(GetSP()); |
| 363 | if (process_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 364 | { |
| 365 | const StateType event_state = SBProcess::GetStateFromEvent (event); |
| 366 | char message[1024]; |
| 367 | ::snprintf (message, |
| 368 | sizeof (message), |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 369 | "Process %llu %s\n", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 370 | process_sp->GetID(), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 371 | SBDebugger::StateAsCString (event_state)); |
| 372 | |
| 373 | result.AppendMessage (message); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | bool |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 378 | SBProcess::SetSelectedThread (const SBThread &thread) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 379 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 380 | ProcessSP process_sp(GetSP()); |
| 381 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 382 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 383 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 384 | return process_sp->GetThreadList().SetSelectedThreadByID (thread.GetThreadID()); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 385 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 386 | return false; |
| 387 | } |
| 388 | |
| 389 | bool |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 390 | SBProcess::SetSelectedThreadByID (uint32_t tid) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 391 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 392 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 393 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 394 | bool ret_val = false; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 395 | ProcessSP process_sp(GetSP()); |
| 396 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 397 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 398 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 399 | ret_val = process_sp->GetThreadList().SetSelectedThreadByID (tid); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 400 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 401 | |
| 402 | if (log) |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 403 | log->Printf ("SBProcess(%p)::SetSelectedThreadByID (tid=0x%4.4x) => %s", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 404 | process_sp.get(), tid, (ret_val ? "true" : "false")); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 405 | |
| 406 | return ret_val; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Jim Ingham | efbdd22 | 2012-07-13 20:18:18 +0000 | [diff] [blame] | 409 | bool |
| 410 | SBProcess::SetSelectedThreadByIndexID (uint32_t index_id) |
| 411 | { |
| 412 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 413 | |
| 414 | bool ret_val = false; |
| 415 | ProcessSP process_sp(GetSP()); |
| 416 | if (process_sp) |
| 417 | { |
| 418 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 419 | ret_val = process_sp->GetThreadList().SetSelectedThreadByIndexID (index_id); |
| 420 | } |
| 421 | |
| 422 | if (log) |
| 423 | log->Printf ("SBProcess(%p)::SetSelectedThreadByID (tid=0x%x) => %s", |
| 424 | process_sp.get(), index_id, (ret_val ? "true" : "false")); |
| 425 | |
| 426 | return ret_val; |
| 427 | } |
| 428 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 429 | SBThread |
| 430 | SBProcess::GetThreadAtIndex (size_t index) |
| 431 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 432 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 433 | |
Greg Clayton | 90c5214 | 2012-01-30 02:53:15 +0000 | [diff] [blame] | 434 | SBThread sb_thread; |
| 435 | ThreadSP thread_sp; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 436 | ProcessSP process_sp(GetSP()); |
| 437 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 438 | { |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 439 | Process::StopLocker stop_locker; |
| 440 | const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 441 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 442 | thread_sp = process_sp->GetThreadList().GetThreadAtIndex(index, can_update); |
Greg Clayton | 90c5214 | 2012-01-30 02:53:15 +0000 | [diff] [blame] | 443 | sb_thread.SetThread (thread_sp); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 444 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 445 | |
| 446 | if (log) |
| 447 | { |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 448 | log->Printf ("SBProcess(%p)::GetThreadAtIndex (index=%d) => SBThread(%p)", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 449 | process_sp.get(), (uint32_t) index, thread_sp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 450 | } |
| 451 | |
Greg Clayton | 90c5214 | 2012-01-30 02:53:15 +0000 | [diff] [blame] | 452 | return sb_thread; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | StateType |
| 456 | SBProcess::GetState () |
| 457 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 458 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 459 | StateType ret_val = eStateInvalid; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 460 | ProcessSP process_sp(GetSP()); |
| 461 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 462 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 463 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 464 | ret_val = process_sp->GetState(); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 465 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 466 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 467 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 468 | if (log) |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 469 | log->Printf ("SBProcess(%p)::GetState () => %s", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 470 | process_sp.get(), |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 471 | lldb_private::StateAsCString (ret_val)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 472 | |
| 473 | return ret_val; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | |
| 477 | int |
| 478 | SBProcess::GetExitStatus () |
| 479 | { |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 480 | int exit_status = 0; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 481 | ProcessSP process_sp(GetSP()); |
| 482 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 483 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 484 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 485 | exit_status = process_sp->GetExitStatus (); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 486 | } |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 487 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 488 | if (log) |
| 489 | log->Printf ("SBProcess(%p)::GetExitStatus () => %i (0x%8.8x)", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 490 | process_sp.get(), exit_status, exit_status); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 491 | |
| 492 | return exit_status; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | const char * |
| 496 | SBProcess::GetExitDescription () |
| 497 | { |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 498 | const char *exit_desc = NULL; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 499 | ProcessSP process_sp(GetSP()); |
| 500 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 501 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 502 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 503 | exit_desc = process_sp->GetExitDescription (); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 504 | } |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 505 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 506 | if (log) |
| 507 | log->Printf ("SBProcess(%p)::GetExitDescription () => %s", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 508 | process_sp.get(), exit_desc); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 509 | return exit_desc; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | lldb::pid_t |
| 513 | SBProcess::GetProcessID () |
| 514 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 515 | lldb::pid_t ret_val = LLDB_INVALID_PROCESS_ID; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 516 | ProcessSP process_sp(GetSP()); |
| 517 | if (process_sp) |
| 518 | ret_val = process_sp->GetID(); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 519 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 520 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 521 | if (log) |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 522 | log->Printf ("SBProcess(%p)::GetProcessID () => %llu", process_sp.get(), ret_val); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 523 | |
| 524 | return ret_val; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 525 | } |
| 526 | |
Johnny Chen | 60a544f | 2011-03-01 22:56:31 +0000 | [diff] [blame] | 527 | ByteOrder |
| 528 | SBProcess::GetByteOrder () const |
| 529 | { |
| 530 | ByteOrder byteOrder = eByteOrderInvalid; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 531 | ProcessSP process_sp(GetSP()); |
| 532 | if (process_sp) |
| 533 | byteOrder = process_sp->GetTarget().GetArchitecture().GetByteOrder(); |
Johnny Chen | 60a544f | 2011-03-01 22:56:31 +0000 | [diff] [blame] | 534 | |
| 535 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 536 | if (log) |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 537 | log->Printf ("SBProcess(%p)::GetByteOrder () => %d", process_sp.get(), byteOrder); |
Johnny Chen | 60a544f | 2011-03-01 22:56:31 +0000 | [diff] [blame] | 538 | |
| 539 | return byteOrder; |
| 540 | } |
| 541 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 542 | uint32_t |
| 543 | SBProcess::GetAddressByteSize () const |
| 544 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 545 | uint32_t size = 0; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 546 | ProcessSP process_sp(GetSP()); |
| 547 | if (process_sp) |
| 548 | size = process_sp->GetTarget().GetArchitecture().GetAddressByteSize(); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 549 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 550 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 551 | if (log) |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 552 | log->Printf ("SBProcess(%p)::GetAddressByteSize () => %d", process_sp.get(), size); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 553 | |
| 554 | return size; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 555 | } |
| 556 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 557 | SBError |
| 558 | SBProcess::Continue () |
| 559 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 560 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 561 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 562 | SBError sb_error; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 563 | ProcessSP process_sp(GetSP()); |
| 564 | |
| 565 | if (log) |
| 566 | log->Printf ("SBProcess(%p)::Continue ()...", process_sp.get()); |
| 567 | |
| 568 | if (process_sp) |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 569 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 570 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 571 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 572 | Error error (process_sp->Resume()); |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 573 | if (error.Success()) |
| 574 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 575 | if (process_sp->GetTarget().GetDebugger().GetAsyncExecution () == false) |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 576 | { |
| 577 | if (log) |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 578 | log->Printf ("SBProcess(%p)::Continue () waiting for process to stop...", process_sp.get()); |
| 579 | process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 580 | } |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 581 | } |
| 582 | sb_error.SetError(error); |
| 583 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 584 | else |
| 585 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 586 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 587 | if (log) |
| 588 | { |
| 589 | SBStream sstr; |
| 590 | sb_error.GetDescription (sstr); |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 591 | log->Printf ("SBProcess(%p)::Continue () => SBError (%p): %s", process_sp.get(), sb_error.get(), sstr.GetData()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 592 | } |
| 593 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 594 | return sb_error; |
| 595 | } |
| 596 | |
| 597 | |
| 598 | SBError |
| 599 | SBProcess::Destroy () |
| 600 | { |
| 601 | SBError sb_error; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 602 | ProcessSP process_sp(GetSP()); |
| 603 | if (process_sp) |
Greg Clayton | 72e1c78 | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 604 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 605 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 606 | sb_error.SetError(process_sp->Destroy()); |
Greg Clayton | 72e1c78 | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 607 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 608 | else |
| 609 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 610 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 611 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 612 | if (log) |
| 613 | { |
| 614 | SBStream sstr; |
| 615 | sb_error.GetDescription (sstr); |
Greg Clayton | 72e1c78 | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 616 | log->Printf ("SBProcess(%p)::Destroy () => SBError (%p): %s", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 617 | process_sp.get(), |
Greg Clayton | 72e1c78 | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 618 | sb_error.get(), |
| 619 | sstr.GetData()); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 620 | } |
| 621 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 622 | return sb_error; |
| 623 | } |
| 624 | |
| 625 | |
| 626 | SBError |
| 627 | SBProcess::Stop () |
| 628 | { |
| 629 | SBError sb_error; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 630 | ProcessSP process_sp(GetSP()); |
| 631 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 632 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 633 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 634 | sb_error.SetError (process_sp->Halt()); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 635 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 636 | else |
| 637 | sb_error.SetErrorString ("SBProcess is invalid"); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 638 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 639 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 640 | if (log) |
| 641 | { |
| 642 | SBStream sstr; |
| 643 | sb_error.GetDescription (sstr); |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 644 | log->Printf ("SBProcess(%p)::Stop () => SBError (%p): %s", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 645 | process_sp.get(), |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 646 | sb_error.get(), |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 647 | sstr.GetData()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 648 | } |
| 649 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 650 | return sb_error; |
| 651 | } |
| 652 | |
| 653 | SBError |
| 654 | SBProcess::Kill () |
| 655 | { |
| 656 | SBError sb_error; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 657 | ProcessSP process_sp(GetSP()); |
| 658 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 659 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 660 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 661 | sb_error.SetError (process_sp->Destroy()); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 662 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 663 | else |
| 664 | sb_error.SetErrorString ("SBProcess is invalid"); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 665 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 666 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 667 | if (log) |
| 668 | { |
| 669 | SBStream sstr; |
| 670 | sb_error.GetDescription (sstr); |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 671 | log->Printf ("SBProcess(%p)::Kill () => SBError (%p): %s", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 672 | process_sp.get(), |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 673 | sb_error.get(), |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 674 | sstr.GetData()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 675 | } |
| 676 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 677 | return sb_error; |
| 678 | } |
| 679 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 680 | SBError |
| 681 | SBProcess::Detach () |
| 682 | { |
| 683 | SBError sb_error; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 684 | ProcessSP process_sp(GetSP()); |
| 685 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 686 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 687 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 688 | sb_error.SetError (process_sp->Detach()); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 689 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 690 | else |
| 691 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 692 | |
| 693 | return sb_error; |
| 694 | } |
| 695 | |
| 696 | SBError |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 697 | SBProcess::Signal (int signo) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 698 | { |
| 699 | SBError sb_error; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 700 | ProcessSP process_sp(GetSP()); |
| 701 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 702 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 703 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 704 | sb_error.SetError (process_sp->Signal (signo)); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 705 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 706 | else |
| 707 | sb_error.SetErrorString ("SBProcess is invalid"); |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 708 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 709 | if (log) |
| 710 | { |
| 711 | SBStream sstr; |
| 712 | sb_error.GetDescription (sstr); |
| 713 | log->Printf ("SBProcess(%p)::Signal (signo=%i) => SBError (%p): %s", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 714 | process_sp.get(), |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 715 | signo, |
| 716 | sb_error.get(), |
| 717 | sstr.GetData()); |
| 718 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 719 | return sb_error; |
| 720 | } |
| 721 | |
Jim Ingham | 5d90ade | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 722 | void |
| 723 | SBProcess::SendAsyncInterrupt () |
| 724 | { |
| 725 | ProcessSP process_sp(GetSP()); |
| 726 | if (process_sp) |
| 727 | { |
| 728 | process_sp->SendAsyncInterrupt (); |
| 729 | } |
| 730 | } |
| 731 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 732 | SBThread |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 733 | SBProcess::GetThreadByID (tid_t tid) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 734 | { |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 735 | SBThread sb_thread; |
Greg Clayton | 90c5214 | 2012-01-30 02:53:15 +0000 | [diff] [blame] | 736 | ThreadSP thread_sp; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 737 | ProcessSP process_sp(GetSP()); |
| 738 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 739 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 740 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 741 | Process::StopLocker stop_locker; |
| 742 | const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); |
| 743 | thread_sp = process_sp->GetThreadList().FindThreadByID (tid, can_update); |
Greg Clayton | 90c5214 | 2012-01-30 02:53:15 +0000 | [diff] [blame] | 744 | sb_thread.SetThread (thread_sp); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 745 | } |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 746 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 747 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 748 | if (log) |
| 749 | { |
Greg Clayton | d9919d3 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 750 | log->Printf ("SBProcess(%p)::GetThreadByID (tid=0x%4.4llx) => SBThread (%p)", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 751 | process_sp.get(), |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 752 | tid, |
Greg Clayton | 90c5214 | 2012-01-30 02:53:15 +0000 | [diff] [blame] | 753 | thread_sp.get()); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | return sb_thread; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 757 | } |
| 758 | |
Jim Ingham | efbdd22 | 2012-07-13 20:18:18 +0000 | [diff] [blame] | 759 | SBThread |
| 760 | SBProcess::GetThreadByIndexID (uint32_t index_id) |
| 761 | { |
| 762 | SBThread sb_thread; |
| 763 | ThreadSP thread_sp; |
| 764 | ProcessSP process_sp(GetSP()); |
| 765 | if (process_sp) |
| 766 | { |
| 767 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 768 | Process::StopLocker stop_locker; |
| 769 | const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); |
| 770 | thread_sp = process_sp->GetThreadList().FindThreadByIndexID (index_id, can_update); |
| 771 | sb_thread.SetThread (thread_sp); |
| 772 | } |
| 773 | |
| 774 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 775 | if (log) |
| 776 | { |
| 777 | log->Printf ("SBProcess(%p)::GetThreadByID (tid=0x%x) => SBThread (%p)", |
| 778 | process_sp.get(), |
| 779 | index_id, |
| 780 | thread_sp.get()); |
| 781 | } |
| 782 | |
| 783 | return sb_thread; |
| 784 | } |
| 785 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 786 | StateType |
| 787 | SBProcess::GetStateFromEvent (const SBEvent &event) |
| 788 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 789 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 790 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 791 | StateType ret_val = Process::ProcessEventData::GetStateFromEvent (event.get()); |
| 792 | |
| 793 | if (log) |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 794 | log->Printf ("SBProcess::GetStateFromEvent (event.sp=%p) => %s", event.get(), |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 795 | lldb_private::StateAsCString (ret_val)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 796 | |
| 797 | return ret_val; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 798 | } |
| 799 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 800 | bool |
| 801 | SBProcess::GetRestartedFromEvent (const SBEvent &event) |
| 802 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 803 | return Process::ProcessEventData::GetRestartedFromEvent (event.get()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | SBProcess |
| 807 | SBProcess::GetProcessFromEvent (const SBEvent &event) |
| 808 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 809 | SBProcess process(Process::ProcessEventData::GetProcessFromEvent (event.get())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 810 | return process; |
| 811 | } |
| 812 | |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 813 | bool |
| 814 | SBProcess::EventIsProcessEvent (const SBEvent &event) |
| 815 | { |
Jim Ingham | 5a15e69 | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 816 | return strcmp (event.GetBroadcasterClass(), SBProcess::GetBroadcasterClass()) == 0; |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 817 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 818 | |
| 819 | SBBroadcaster |
| 820 | SBProcess::GetBroadcaster () const |
| 821 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 822 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 823 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 824 | ProcessSP process_sp(GetSP()); |
| 825 | |
| 826 | SBBroadcaster broadcaster(process_sp.get(), false); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 827 | |
| 828 | if (log) |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 829 | log->Printf ("SBProcess(%p)::GetBroadcaster () => SBBroadcaster (%p)", process_sp.get(), |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 830 | broadcaster.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 831 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 832 | return broadcaster; |
| 833 | } |
| 834 | |
Jim Ingham | 5a15e69 | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 835 | const char * |
| 836 | SBProcess::GetBroadcasterClass () |
| 837 | { |
| 838 | return Process::GetStaticBroadcasterClass().AsCString(); |
| 839 | } |
| 840 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 841 | size_t |
| 842 | SBProcess::ReadMemory (addr_t addr, void *dst, size_t dst_len, SBError &sb_error) |
| 843 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 844 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 845 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 846 | size_t bytes_read = 0; |
| 847 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 848 | ProcessSP process_sp(GetSP()); |
| 849 | |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 850 | if (log) |
| 851 | { |
| 852 | log->Printf ("SBProcess(%p)::ReadMemory (addr=0x%llx, dst=%p, dst_len=%zu, SBError (%p))...", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 853 | process_sp.get(), |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 854 | addr, |
| 855 | dst, |
Greg Clayton | bae39c5 | 2011-12-03 00:46:21 +0000 | [diff] [blame] | 856 | dst_len, |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 857 | sb_error.get()); |
| 858 | } |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 859 | |
| 860 | if (process_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 861 | { |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 862 | Process::StopLocker stop_locker; |
| 863 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 864 | { |
| 865 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 866 | bytes_read = process_sp->ReadMemory (addr, dst, dst_len, sb_error.ref()); |
| 867 | } |
| 868 | else |
| 869 | { |
Greg Clayton | 9f3c98e | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 870 | if (log) |
| 871 | log->Printf ("SBProcess(%p)::ReadMemory() => error: process is running", process_sp.get()); |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 872 | sb_error.SetErrorString("process is running"); |
| 873 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 874 | } |
| 875 | else |
| 876 | { |
| 877 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 878 | } |
| 879 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 880 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 881 | { |
| 882 | SBStream sstr; |
| 883 | sb_error.GetDescription (sstr); |
Greg Clayton | bae39c5 | 2011-12-03 00:46:21 +0000 | [diff] [blame] | 884 | log->Printf ("SBProcess(%p)::ReadMemory (addr=0x%llx, dst=%p, dst_len=%zu, SBError (%p): %s) => %zu", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 885 | process_sp.get(), |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 886 | addr, |
| 887 | dst, |
Greg Clayton | bae39c5 | 2011-12-03 00:46:21 +0000 | [diff] [blame] | 888 | dst_len, |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 889 | sb_error.get(), |
| 890 | sstr.GetData(), |
Greg Clayton | bae39c5 | 2011-12-03 00:46:21 +0000 | [diff] [blame] | 891 | bytes_read); |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 892 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 893 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 894 | return bytes_read; |
| 895 | } |
| 896 | |
| 897 | size_t |
Greg Clayton | 4a2e337 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 898 | SBProcess::ReadCStringFromMemory (addr_t addr, void *buf, size_t size, lldb::SBError &sb_error) |
| 899 | { |
| 900 | size_t bytes_read = 0; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 901 | ProcessSP process_sp(GetSP()); |
| 902 | if (process_sp) |
Greg Clayton | 4a2e337 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 903 | { |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 904 | Process::StopLocker stop_locker; |
| 905 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 906 | { |
| 907 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 908 | bytes_read = process_sp->ReadCStringFromMemory (addr, (char *)buf, size, sb_error.ref()); |
| 909 | } |
| 910 | else |
| 911 | { |
Greg Clayton | 9f3c98e | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 912 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 913 | if (log) |
| 914 | log->Printf ("SBProcess(%p)::ReadCStringFromMemory() => error: process is running", process_sp.get()); |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 915 | sb_error.SetErrorString("process is running"); |
| 916 | } |
Greg Clayton | 4a2e337 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 917 | } |
| 918 | else |
| 919 | { |
| 920 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 921 | } |
| 922 | return bytes_read; |
| 923 | } |
| 924 | |
| 925 | uint64_t |
| 926 | SBProcess::ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &sb_error) |
| 927 | { |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 928 | uint64_t value = 0; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 929 | ProcessSP process_sp(GetSP()); |
| 930 | if (process_sp) |
Greg Clayton | 4a2e337 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 931 | { |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 932 | Process::StopLocker stop_locker; |
| 933 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 934 | { |
| 935 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 936 | value = process_sp->ReadUnsignedIntegerFromMemory (addr, byte_size, 0, sb_error.ref()); |
| 937 | } |
| 938 | else |
| 939 | { |
Greg Clayton | 9f3c98e | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 940 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 941 | if (log) |
| 942 | log->Printf ("SBProcess(%p)::ReadUnsignedFromMemory() => error: process is running", process_sp.get()); |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 943 | sb_error.SetErrorString("process is running"); |
| 944 | } |
Greg Clayton | 4a2e337 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 945 | } |
| 946 | else |
| 947 | { |
| 948 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 949 | } |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 950 | return value; |
Greg Clayton | 4a2e337 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | lldb::addr_t |
| 954 | SBProcess::ReadPointerFromMemory (addr_t addr, lldb::SBError &sb_error) |
| 955 | { |
| 956 | lldb::addr_t ptr = LLDB_INVALID_ADDRESS; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 957 | ProcessSP process_sp(GetSP()); |
| 958 | if (process_sp) |
Greg Clayton | 4a2e337 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 959 | { |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 960 | Process::StopLocker stop_locker; |
| 961 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 962 | { |
| 963 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 964 | ptr = process_sp->ReadPointerFromMemory (addr, sb_error.ref()); |
| 965 | } |
| 966 | else |
| 967 | { |
Greg Clayton | 9f3c98e | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 968 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 969 | if (log) |
| 970 | log->Printf ("SBProcess(%p)::ReadPointerFromMemory() => error: process is running", process_sp.get()); |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 971 | sb_error.SetErrorString("process is running"); |
| 972 | } |
Greg Clayton | 4a2e337 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 973 | } |
| 974 | else |
| 975 | { |
| 976 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 977 | } |
| 978 | return ptr; |
| 979 | } |
| 980 | |
| 981 | size_t |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 982 | SBProcess::WriteMemory (addr_t addr, const void *src, size_t src_len, SBError &sb_error) |
| 983 | { |
| 984 | size_t bytes_written = 0; |
| 985 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 986 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 987 | |
| 988 | ProcessSP process_sp(GetSP()); |
| 989 | |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 990 | if (log) |
| 991 | { |
| 992 | log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%llx, src=%p, dst_len=%zu, SBError (%p))...", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 993 | process_sp.get(), |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 994 | addr, |
| 995 | src, |
Greg Clayton | bae39c5 | 2011-12-03 00:46:21 +0000 | [diff] [blame] | 996 | src_len, |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 997 | sb_error.get()); |
| 998 | } |
| 999 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1000 | if (process_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1001 | { |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1002 | Process::StopLocker stop_locker; |
| 1003 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 1004 | { |
| 1005 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 1006 | bytes_written = process_sp->WriteMemory (addr, src, src_len, sb_error.ref()); |
| 1007 | } |
| 1008 | else |
| 1009 | { |
Greg Clayton | 9f3c98e | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 1010 | if (log) |
| 1011 | log->Printf ("SBProcess(%p)::WriteMemory() => error: process is running", process_sp.get()); |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1012 | sb_error.SetErrorString("process is running"); |
| 1013 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1016 | if (log) |
| 1017 | { |
| 1018 | SBStream sstr; |
| 1019 | sb_error.GetDescription (sstr); |
Greg Clayton | bae39c5 | 2011-12-03 00:46:21 +0000 | [diff] [blame] | 1020 | log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%llx, src=%p, dst_len=%zu, SBError (%p): %s) => %zu", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1021 | process_sp.get(), |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1022 | addr, |
| 1023 | src, |
Greg Clayton | bae39c5 | 2011-12-03 00:46:21 +0000 | [diff] [blame] | 1024 | src_len, |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1025 | sb_error.get(), |
| 1026 | sstr.GetData(), |
Greg Clayton | bae39c5 | 2011-12-03 00:46:21 +0000 | [diff] [blame] | 1027 | bytes_written); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1028 | } |
| 1029 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1030 | return bytes_written; |
| 1031 | } |
| 1032 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 1033 | bool |
| 1034 | SBProcess::GetDescription (SBStream &description) |
| 1035 | { |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 1036 | Stream &strm = description.ref(); |
| 1037 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1038 | ProcessSP process_sp(GetSP()); |
| 1039 | if (process_sp) |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 1040 | { |
| 1041 | char path[PATH_MAX]; |
| 1042 | GetTarget().GetExecutable().GetPath (path, sizeof(path)); |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1043 | Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer(); |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 1044 | const char *exe_name = NULL; |
| 1045 | if (exe_module) |
| 1046 | exe_name = exe_module->GetFileSpec().GetFilename().AsCString(); |
| 1047 | |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 1048 | strm.Printf ("SBProcess: pid = %llu, state = %s, threads = %d%s%s", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1049 | process_sp->GetID(), |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 1050 | lldb_private::StateAsCString (GetState()), |
| 1051 | GetNumThreads(), |
| 1052 | exe_name ? ", executable = " : "", |
| 1053 | exe_name ? exe_name : ""); |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 1054 | } |
| 1055 | else |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 1056 | strm.PutCString ("No value"); |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 1057 | |
| 1058 | return true; |
| 1059 | } |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1060 | |
| 1061 | uint32_t |
Johnny Chen | 191343e | 2012-05-23 22:34:34 +0000 | [diff] [blame] | 1062 | SBProcess::GetNumSupportedHardwareWatchpoints (lldb::SBError &sb_error) const |
| 1063 | { |
| 1064 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1065 | |
| 1066 | uint32_t num = 0; |
| 1067 | ProcessSP process_sp(GetSP()); |
| 1068 | if (process_sp) |
| 1069 | { |
| 1070 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 1071 | sb_error.SetError(process_sp->GetWatchpointSupportInfo (num)); |
| 1072 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1073 | if (log) |
| 1074 | log->Printf ("SBProcess(%p)::GetNumSupportedHardwareWatchpoints () => %u", |
| 1075 | process_sp.get(), num); |
| 1076 | } |
| 1077 | else |
| 1078 | { |
| 1079 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 1080 | } |
| 1081 | return num; |
| 1082 | } |
| 1083 | |
| 1084 | uint32_t |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1085 | SBProcess::LoadImage (lldb::SBFileSpec &sb_image_spec, lldb::SBError &sb_error) |
| 1086 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1087 | ProcessSP process_sp(GetSP()); |
| 1088 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1089 | { |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1090 | Process::StopLocker stop_locker; |
| 1091 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 1092 | { |
| 1093 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 1094 | return process_sp->LoadImage (*sb_image_spec, sb_error.ref()); |
| 1095 | } |
| 1096 | else |
| 1097 | { |
Greg Clayton | 9f3c98e | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 1098 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1099 | if (log) |
| 1100 | log->Printf ("SBProcess(%p)::LoadImage() => error: process is running", process_sp.get()); |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1101 | sb_error.SetErrorString("process is running"); |
| 1102 | } |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1103 | } |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1104 | return LLDB_INVALID_IMAGE_TOKEN; |
| 1105 | } |
| 1106 | |
| 1107 | lldb::SBError |
| 1108 | SBProcess::UnloadImage (uint32_t image_token) |
| 1109 | { |
| 1110 | lldb::SBError sb_error; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1111 | ProcessSP process_sp(GetSP()); |
| 1112 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1113 | { |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1114 | Process::StopLocker stop_locker; |
| 1115 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 1116 | { |
| 1117 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 1118 | sb_error.SetError (process_sp->UnloadImage (image_token)); |
| 1119 | } |
| 1120 | else |
| 1121 | { |
Greg Clayton | 9f3c98e | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 1122 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1123 | if (log) |
| 1124 | log->Printf ("SBProcess(%p)::UnloadImage() => error: process is running", process_sp.get()); |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1125 | sb_error.SetErrorString("process is running"); |
| 1126 | } |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1127 | } |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1128 | else |
| 1129 | sb_error.SetErrorString("invalid process"); |
| 1130 | return sb_error; |
| 1131 | } |