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