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 | { |
| 146 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 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 | |
| 225 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 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 | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 239 | LogSP 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 | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 261 | LogSP 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 | |
| 281 | SBTarget |
| 282 | SBProcess::GetTarget() const |
| 283 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 284 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 285 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 286 | SBTarget sb_target; |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 287 | TargetSP target_sp; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 288 | ProcessSP process_sp(GetSP()); |
| 289 | if (process_sp) |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 290 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 291 | target_sp = process_sp->GetTarget().shared_from_this(); |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 292 | sb_target.SetSP (target_sp); |
| 293 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 294 | |
| 295 | if (log) |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 296 | 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] | 297 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 298 | return sb_target; |
| 299 | } |
| 300 | |
| 301 | |
| 302 | size_t |
| 303 | SBProcess::PutSTDIN (const char *src, size_t src_len) |
| 304 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 305 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 306 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 307 | size_t ret_val = 0; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 308 | ProcessSP process_sp(GetSP()); |
| 309 | if (process_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 310 | { |
| 311 | Error error; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 312 | ret_val = process_sp->PutSTDIN (src, src_len, error); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 313 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 314 | |
| 315 | if (log) |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 316 | log->Printf ("SBProcess(%p)::PutSTDIN (src=\"%s\", src_len=%d) => %lu", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 317 | process_sp.get(), |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 318 | src, |
| 319 | (uint32_t) src_len, |
| 320 | ret_val); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 321 | |
| 322 | return ret_val; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | size_t |
| 326 | SBProcess::GetSTDOUT (char *dst, size_t dst_len) const |
| 327 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 328 | size_t bytes_read = 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 | bytes_read = process_sp->GetSTDOUT (dst, dst_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 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 336 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 337 | if (log) |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 338 | log->Printf ("SBProcess(%p)::GetSTDOUT (dst=\"%.*s\", dst_len=%" PRIu64 ") => %" PRIu64, |
Greg Clayton | 851e30e | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 339 | process_sp.get(), |
| 340 | (int) bytes_read, |
| 341 | dst, |
| 342 | (uint64_t)dst_len, |
| 343 | (uint64_t)bytes_read); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 344 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 345 | return bytes_read; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | size_t |
| 349 | SBProcess::GetSTDERR (char *dst, size_t dst_len) const |
| 350 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 351 | size_t bytes_read = 0; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 352 | ProcessSP process_sp(GetSP()); |
| 353 | if (process_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 354 | { |
| 355 | Error error; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 356 | bytes_read = process_sp->GetSTDERR (dst, dst_len, error); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 357 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 358 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 359 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 360 | if (log) |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 361 | log->Printf ("SBProcess(%p)::GetSTDERR (dst=\"%.*s\", dst_len=%" PRIu64 ") => %" PRIu64, |
Greg Clayton | 851e30e | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 362 | process_sp.get(), |
| 363 | (int) bytes_read, |
| 364 | dst, |
| 365 | (uint64_t)dst_len, |
| 366 | (uint64_t)bytes_read); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 367 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 368 | return bytes_read; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Han Ming Ong | fb9cee6 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 371 | size_t |
| 372 | SBProcess::GetAsyncProfileData(char *dst, size_t dst_len) const |
| 373 | { |
| 374 | size_t bytes_read = 0; |
| 375 | ProcessSP process_sp(GetSP()); |
| 376 | if (process_sp) |
| 377 | { |
| 378 | Error error; |
| 379 | bytes_read = process_sp->GetAsyncProfileData (dst, dst_len, error); |
| 380 | } |
| 381 | |
| 382 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 383 | if (log) |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 384 | log->Printf ("SBProcess(%p)::GetProfileData (dst=\"%.*s\", dst_len=%" PRIu64 ") => %" PRIu64, |
Han Ming Ong | fb9cee6 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 385 | process_sp.get(), |
| 386 | (int) bytes_read, |
| 387 | dst, |
| 388 | (uint64_t)dst_len, |
| 389 | (uint64_t)bytes_read); |
| 390 | |
| 391 | return bytes_read; |
| 392 | } |
| 393 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 394 | void |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 395 | SBProcess::ReportEventState (const SBEvent &event, FILE *out) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 396 | { |
| 397 | if (out == NULL) |
| 398 | return; |
| 399 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 400 | ProcessSP process_sp(GetSP()); |
| 401 | if (process_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 402 | { |
| 403 | const StateType event_state = SBProcess::GetStateFromEvent (event); |
| 404 | char message[1024]; |
| 405 | int message_len = ::snprintf (message, |
| 406 | sizeof (message), |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 407 | "Process %" PRIu64 " %s\n", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 408 | process_sp->GetID(), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 409 | SBDebugger::StateAsCString (event_state)); |
| 410 | |
| 411 | if (message_len > 0) |
| 412 | ::fwrite (message, 1, message_len, out); |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | void |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 417 | SBProcess::AppendEventStateReport (const SBEvent &event, SBCommandReturnObject &result) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 418 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 419 | ProcessSP process_sp(GetSP()); |
| 420 | if (process_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 421 | { |
| 422 | const StateType event_state = SBProcess::GetStateFromEvent (event); |
| 423 | char message[1024]; |
| 424 | ::snprintf (message, |
| 425 | sizeof (message), |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 426 | "Process %" PRIu64 " %s\n", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 427 | process_sp->GetID(), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 428 | SBDebugger::StateAsCString (event_state)); |
| 429 | |
| 430 | result.AppendMessage (message); |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | bool |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 435 | SBProcess::SetSelectedThread (const SBThread &thread) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 436 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 437 | ProcessSP process_sp(GetSP()); |
| 438 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 439 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 440 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 441 | return process_sp->GetThreadList().SetSelectedThreadByID (thread.GetThreadID()); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 442 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 443 | return false; |
| 444 | } |
| 445 | |
| 446 | bool |
Greg Clayton | 82560f2 | 2012-10-12 23:32:11 +0000 | [diff] [blame] | 447 | SBProcess::SetSelectedThreadByID (lldb::tid_t tid) |
| 448 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 449 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 450 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 451 | bool ret_val = false; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 452 | ProcessSP process_sp(GetSP()); |
| 453 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 454 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 455 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 456 | ret_val = process_sp->GetThreadList().SetSelectedThreadByID (tid); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 457 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 458 | |
| 459 | if (log) |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 460 | log->Printf ("SBProcess(%p)::SetSelectedThreadByID (tid=0x%4.4" PRIx64 ") => %s", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 461 | process_sp.get(), tid, (ret_val ? "true" : "false")); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 462 | |
| 463 | return ret_val; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Jim Ingham | efbdd22 | 2012-07-13 20:18:18 +0000 | [diff] [blame] | 466 | bool |
| 467 | SBProcess::SetSelectedThreadByIndexID (uint32_t index_id) |
| 468 | { |
| 469 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 470 | |
| 471 | bool ret_val = false; |
| 472 | ProcessSP process_sp(GetSP()); |
| 473 | if (process_sp) |
| 474 | { |
| 475 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 476 | ret_val = process_sp->GetThreadList().SetSelectedThreadByIndexID (index_id); |
| 477 | } |
| 478 | |
| 479 | if (log) |
| 480 | log->Printf ("SBProcess(%p)::SetSelectedThreadByID (tid=0x%x) => %s", |
| 481 | process_sp.get(), index_id, (ret_val ? "true" : "false")); |
| 482 | |
| 483 | return ret_val; |
| 484 | } |
| 485 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 486 | SBThread |
| 487 | SBProcess::GetThreadAtIndex (size_t index) |
| 488 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 489 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 490 | |
Greg Clayton | 90c5214 | 2012-01-30 02:53:15 +0000 | [diff] [blame] | 491 | SBThread sb_thread; |
| 492 | ThreadSP thread_sp; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 493 | ProcessSP process_sp(GetSP()); |
| 494 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 495 | { |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 496 | Process::StopLocker stop_locker; |
| 497 | const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 498 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 499 | thread_sp = process_sp->GetThreadList().GetThreadAtIndex(index, can_update); |
Greg Clayton | 90c5214 | 2012-01-30 02:53:15 +0000 | [diff] [blame] | 500 | sb_thread.SetThread (thread_sp); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 501 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 502 | |
| 503 | if (log) |
| 504 | { |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 505 | log->Printf ("SBProcess(%p)::GetThreadAtIndex (index=%d) => SBThread(%p)", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 506 | process_sp.get(), (uint32_t) index, thread_sp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 507 | } |
| 508 | |
Greg Clayton | 90c5214 | 2012-01-30 02:53:15 +0000 | [diff] [blame] | 509 | return sb_thread; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 510 | } |
| 511 | |
Jim Ingham | 0e3b98e | 2013-01-08 23:22:42 +0000 | [diff] [blame] | 512 | uint32_t |
| 513 | SBProcess::GetStopID(bool include_expression_stops) |
| 514 | { |
| 515 | ProcessSP process_sp(GetSP()); |
| 516 | if (process_sp) |
| 517 | { |
| 518 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 519 | if (include_expression_stops) |
| 520 | return process_sp->GetStopID(); |
| 521 | else |
| 522 | return process_sp->GetLastNaturalStopID(); |
| 523 | } |
| 524 | return 0; |
| 525 | } |
| 526 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 527 | StateType |
| 528 | SBProcess::GetState () |
| 529 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 530 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 531 | StateType ret_val = eStateInvalid; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 532 | ProcessSP process_sp(GetSP()); |
| 533 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 534 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 535 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 536 | ret_val = process_sp->GetState(); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 537 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 538 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 539 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 540 | if (log) |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 541 | log->Printf ("SBProcess(%p)::GetState () => %s", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 542 | process_sp.get(), |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 543 | lldb_private::StateAsCString (ret_val)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 544 | |
| 545 | return ret_val; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | |
| 549 | int |
| 550 | SBProcess::GetExitStatus () |
| 551 | { |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 552 | int exit_status = 0; |
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 | exit_status = process_sp->GetExitStatus (); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 558 | } |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 559 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 560 | if (log) |
| 561 | log->Printf ("SBProcess(%p)::GetExitStatus () => %i (0x%8.8x)", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 562 | process_sp.get(), exit_status, exit_status); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 563 | |
| 564 | return exit_status; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | const char * |
| 568 | SBProcess::GetExitDescription () |
| 569 | { |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 570 | const char *exit_desc = NULL; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 571 | ProcessSP process_sp(GetSP()); |
| 572 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 573 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 574 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 575 | exit_desc = process_sp->GetExitDescription (); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 576 | } |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 577 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 578 | if (log) |
| 579 | log->Printf ("SBProcess(%p)::GetExitDescription () => %s", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 580 | process_sp.get(), exit_desc); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 581 | return exit_desc; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | lldb::pid_t |
| 585 | SBProcess::GetProcessID () |
| 586 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 587 | lldb::pid_t ret_val = LLDB_INVALID_PROCESS_ID; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 588 | ProcessSP process_sp(GetSP()); |
| 589 | if (process_sp) |
| 590 | ret_val = process_sp->GetID(); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 591 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 592 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 593 | if (log) |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 594 | log->Printf ("SBProcess(%p)::GetProcessID () => %" PRIu64, process_sp.get(), ret_val); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 595 | |
| 596 | return ret_val; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 597 | } |
| 598 | |
Greg Clayton | 6474274 | 2013-01-16 17:29:04 +0000 | [diff] [blame] | 599 | uint32_t |
| 600 | SBProcess::GetUniqueID() |
| 601 | { |
| 602 | uint32_t ret_val = 0; |
| 603 | ProcessSP process_sp(GetSP()); |
| 604 | if (process_sp) |
| 605 | ret_val = process_sp->GetUniqueID(); |
| 606 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 607 | if (log) |
| 608 | log->Printf ("SBProcess(%p)::GetUniqueID () => %" PRIu32, process_sp.get(), ret_val); |
| 609 | return ret_val; |
| 610 | } |
| 611 | |
Johnny Chen | 60a544f | 2011-03-01 22:56:31 +0000 | [diff] [blame] | 612 | ByteOrder |
| 613 | SBProcess::GetByteOrder () const |
| 614 | { |
| 615 | ByteOrder byteOrder = eByteOrderInvalid; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 616 | ProcessSP process_sp(GetSP()); |
| 617 | if (process_sp) |
| 618 | byteOrder = process_sp->GetTarget().GetArchitecture().GetByteOrder(); |
Johnny Chen | 60a544f | 2011-03-01 22:56:31 +0000 | [diff] [blame] | 619 | |
| 620 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 621 | if (log) |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 622 | log->Printf ("SBProcess(%p)::GetByteOrder () => %d", process_sp.get(), byteOrder); |
Johnny Chen | 60a544f | 2011-03-01 22:56:31 +0000 | [diff] [blame] | 623 | |
| 624 | return byteOrder; |
| 625 | } |
| 626 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 627 | uint32_t |
| 628 | SBProcess::GetAddressByteSize () const |
| 629 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 630 | uint32_t size = 0; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 631 | ProcessSP process_sp(GetSP()); |
| 632 | if (process_sp) |
| 633 | size = process_sp->GetTarget().GetArchitecture().GetAddressByteSize(); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 634 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 635 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 636 | if (log) |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 637 | log->Printf ("SBProcess(%p)::GetAddressByteSize () => %d", process_sp.get(), size); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 638 | |
| 639 | return size; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 640 | } |
| 641 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 642 | SBError |
| 643 | SBProcess::Continue () |
| 644 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 645 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 646 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 647 | SBError sb_error; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 648 | ProcessSP process_sp(GetSP()); |
| 649 | |
| 650 | if (log) |
| 651 | log->Printf ("SBProcess(%p)::Continue ()...", process_sp.get()); |
| 652 | |
| 653 | if (process_sp) |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 654 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 655 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 656 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 657 | Error error (process_sp->Resume()); |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 658 | if (error.Success()) |
| 659 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 660 | if (process_sp->GetTarget().GetDebugger().GetAsyncExecution () == false) |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 661 | { |
| 662 | if (log) |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 663 | log->Printf ("SBProcess(%p)::Continue () waiting for process to stop...", process_sp.get()); |
| 664 | process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 665 | } |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 666 | } |
| 667 | sb_error.SetError(error); |
| 668 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 669 | else |
| 670 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 671 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 672 | if (log) |
| 673 | { |
| 674 | SBStream sstr; |
| 675 | sb_error.GetDescription (sstr); |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 676 | 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] | 677 | } |
| 678 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 679 | return sb_error; |
| 680 | } |
| 681 | |
| 682 | |
| 683 | SBError |
| 684 | SBProcess::Destroy () |
| 685 | { |
| 686 | SBError sb_error; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 687 | ProcessSP process_sp(GetSP()); |
| 688 | if (process_sp) |
Greg Clayton | 72e1c78 | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 689 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 690 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 691 | sb_error.SetError(process_sp->Destroy()); |
Greg Clayton | 72e1c78 | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 692 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 693 | else |
| 694 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 695 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 696 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 697 | if (log) |
| 698 | { |
| 699 | SBStream sstr; |
| 700 | sb_error.GetDescription (sstr); |
Greg Clayton | 72e1c78 | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 701 | log->Printf ("SBProcess(%p)::Destroy () => SBError (%p): %s", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 702 | process_sp.get(), |
Greg Clayton | 72e1c78 | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 703 | sb_error.get(), |
| 704 | sstr.GetData()); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 705 | } |
| 706 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 707 | return sb_error; |
| 708 | } |
| 709 | |
| 710 | |
| 711 | SBError |
| 712 | SBProcess::Stop () |
| 713 | { |
| 714 | SBError sb_error; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 715 | ProcessSP process_sp(GetSP()); |
| 716 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 717 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 718 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 719 | sb_error.SetError (process_sp->Halt()); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 720 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 721 | else |
| 722 | sb_error.SetErrorString ("SBProcess is invalid"); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 723 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 724 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 725 | if (log) |
| 726 | { |
| 727 | SBStream sstr; |
| 728 | sb_error.GetDescription (sstr); |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 729 | log->Printf ("SBProcess(%p)::Stop () => SBError (%p): %s", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 730 | process_sp.get(), |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 731 | sb_error.get(), |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 732 | sstr.GetData()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 733 | } |
| 734 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 735 | return sb_error; |
| 736 | } |
| 737 | |
| 738 | SBError |
| 739 | SBProcess::Kill () |
| 740 | { |
| 741 | SBError sb_error; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 742 | ProcessSP process_sp(GetSP()); |
| 743 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 744 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 745 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 746 | sb_error.SetError (process_sp->Destroy()); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 747 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 748 | else |
| 749 | sb_error.SetErrorString ("SBProcess is invalid"); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 750 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 751 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 752 | if (log) |
| 753 | { |
| 754 | SBStream sstr; |
| 755 | sb_error.GetDescription (sstr); |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 756 | log->Printf ("SBProcess(%p)::Kill () => SBError (%p): %s", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 757 | process_sp.get(), |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 758 | sb_error.get(), |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 759 | sstr.GetData()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 760 | } |
| 761 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 762 | return sb_error; |
| 763 | } |
| 764 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 765 | SBError |
| 766 | SBProcess::Detach () |
| 767 | { |
| 768 | SBError sb_error; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 769 | ProcessSP process_sp(GetSP()); |
| 770 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 771 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 772 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 773 | sb_error.SetError (process_sp->Detach()); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 774 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 775 | else |
| 776 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 777 | |
| 778 | return sb_error; |
| 779 | } |
| 780 | |
| 781 | SBError |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 782 | SBProcess::Signal (int signo) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 783 | { |
| 784 | SBError sb_error; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 785 | ProcessSP process_sp(GetSP()); |
| 786 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 787 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 788 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 789 | sb_error.SetError (process_sp->Signal (signo)); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 790 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 791 | else |
| 792 | sb_error.SetErrorString ("SBProcess is invalid"); |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 793 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 794 | if (log) |
| 795 | { |
| 796 | SBStream sstr; |
| 797 | sb_error.GetDescription (sstr); |
| 798 | log->Printf ("SBProcess(%p)::Signal (signo=%i) => SBError (%p): %s", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 799 | process_sp.get(), |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 800 | signo, |
| 801 | sb_error.get(), |
| 802 | sstr.GetData()); |
| 803 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 804 | return sb_error; |
| 805 | } |
| 806 | |
Jim Ingham | 5d90ade | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 807 | void |
| 808 | SBProcess::SendAsyncInterrupt () |
| 809 | { |
| 810 | ProcessSP process_sp(GetSP()); |
| 811 | if (process_sp) |
| 812 | { |
| 813 | process_sp->SendAsyncInterrupt (); |
| 814 | } |
| 815 | } |
| 816 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 817 | SBThread |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 818 | SBProcess::GetThreadByID (tid_t tid) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 819 | { |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 820 | SBThread sb_thread; |
Greg Clayton | 90c5214 | 2012-01-30 02:53:15 +0000 | [diff] [blame] | 821 | ThreadSP thread_sp; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 822 | ProcessSP process_sp(GetSP()); |
| 823 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 824 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 825 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 826 | Process::StopLocker stop_locker; |
| 827 | const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); |
| 828 | thread_sp = process_sp->GetThreadList().FindThreadByID (tid, can_update); |
Greg Clayton | 90c5214 | 2012-01-30 02:53:15 +0000 | [diff] [blame] | 829 | sb_thread.SetThread (thread_sp); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 830 | } |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 831 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 832 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 833 | if (log) |
| 834 | { |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 835 | log->Printf ("SBProcess(%p)::GetThreadByID (tid=0x%4.4" PRIx64 ") => SBThread (%p)", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 836 | process_sp.get(), |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 837 | tid, |
Greg Clayton | 90c5214 | 2012-01-30 02:53:15 +0000 | [diff] [blame] | 838 | thread_sp.get()); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | return sb_thread; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 842 | } |
| 843 | |
Jim Ingham | efbdd22 | 2012-07-13 20:18:18 +0000 | [diff] [blame] | 844 | SBThread |
| 845 | SBProcess::GetThreadByIndexID (uint32_t index_id) |
| 846 | { |
| 847 | SBThread sb_thread; |
| 848 | ThreadSP thread_sp; |
| 849 | ProcessSP process_sp(GetSP()); |
| 850 | if (process_sp) |
| 851 | { |
| 852 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 853 | Process::StopLocker stop_locker; |
| 854 | const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); |
| 855 | thread_sp = process_sp->GetThreadList().FindThreadByIndexID (index_id, can_update); |
| 856 | sb_thread.SetThread (thread_sp); |
| 857 | } |
| 858 | |
| 859 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 860 | if (log) |
| 861 | { |
| 862 | log->Printf ("SBProcess(%p)::GetThreadByID (tid=0x%x) => SBThread (%p)", |
| 863 | process_sp.get(), |
| 864 | index_id, |
| 865 | thread_sp.get()); |
| 866 | } |
| 867 | |
| 868 | return sb_thread; |
| 869 | } |
| 870 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 871 | StateType |
| 872 | SBProcess::GetStateFromEvent (const SBEvent &event) |
| 873 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 874 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 875 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 876 | StateType ret_val = Process::ProcessEventData::GetStateFromEvent (event.get()); |
| 877 | |
| 878 | if (log) |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 879 | log->Printf ("SBProcess::GetStateFromEvent (event.sp=%p) => %s", event.get(), |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 880 | lldb_private::StateAsCString (ret_val)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 881 | |
| 882 | return ret_val; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 883 | } |
| 884 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 885 | bool |
| 886 | SBProcess::GetRestartedFromEvent (const SBEvent &event) |
| 887 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 888 | return Process::ProcessEventData::GetRestartedFromEvent (event.get()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | SBProcess |
| 892 | SBProcess::GetProcessFromEvent (const SBEvent &event) |
| 893 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 894 | SBProcess process(Process::ProcessEventData::GetProcessFromEvent (event.get())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 895 | return process; |
| 896 | } |
| 897 | |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 898 | bool |
| 899 | SBProcess::EventIsProcessEvent (const SBEvent &event) |
| 900 | { |
Jim Ingham | 5a15e69 | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 901 | return strcmp (event.GetBroadcasterClass(), SBProcess::GetBroadcasterClass()) == 0; |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 902 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 903 | |
| 904 | SBBroadcaster |
| 905 | SBProcess::GetBroadcaster () const |
| 906 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 907 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 908 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 909 | ProcessSP process_sp(GetSP()); |
| 910 | |
| 911 | SBBroadcaster broadcaster(process_sp.get(), false); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 912 | |
| 913 | if (log) |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 914 | log->Printf ("SBProcess(%p)::GetBroadcaster () => SBBroadcaster (%p)", process_sp.get(), |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 915 | broadcaster.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 916 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 917 | return broadcaster; |
| 918 | } |
| 919 | |
Jim Ingham | 5a15e69 | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 920 | const char * |
| 921 | SBProcess::GetBroadcasterClass () |
| 922 | { |
| 923 | return Process::GetStaticBroadcasterClass().AsCString(); |
| 924 | } |
| 925 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 926 | size_t |
| 927 | SBProcess::ReadMemory (addr_t addr, void *dst, size_t dst_len, SBError &sb_error) |
| 928 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 929 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 930 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 931 | size_t bytes_read = 0; |
| 932 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 933 | ProcessSP process_sp(GetSP()); |
| 934 | |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 935 | if (log) |
| 936 | { |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 937 | 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] | 938 | process_sp.get(), |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 939 | addr, |
| 940 | dst, |
Greg Clayton | 851e30e | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 941 | (uint64_t)dst_len, |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 942 | sb_error.get()); |
| 943 | } |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 944 | |
| 945 | if (process_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 946 | { |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 947 | Process::StopLocker stop_locker; |
| 948 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 949 | { |
| 950 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 951 | bytes_read = process_sp->ReadMemory (addr, dst, dst_len, sb_error.ref()); |
| 952 | } |
| 953 | else |
| 954 | { |
Greg Clayton | 9f3c98e | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 955 | if (log) |
| 956 | log->Printf ("SBProcess(%p)::ReadMemory() => error: process is running", process_sp.get()); |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 957 | sb_error.SetErrorString("process is running"); |
| 958 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 959 | } |
| 960 | else |
| 961 | { |
| 962 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 963 | } |
| 964 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 965 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 966 | { |
| 967 | SBStream sstr; |
| 968 | sb_error.GetDescription (sstr); |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 969 | 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] | 970 | process_sp.get(), |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 971 | addr, |
| 972 | dst, |
Greg Clayton | 851e30e | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 973 | (uint64_t)dst_len, |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 974 | sb_error.get(), |
| 975 | sstr.GetData(), |
Greg Clayton | 851e30e | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 976 | (uint64_t)bytes_read); |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 977 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 978 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 979 | return bytes_read; |
| 980 | } |
| 981 | |
| 982 | size_t |
Greg Clayton | 4a2e337 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 983 | SBProcess::ReadCStringFromMemory (addr_t addr, void *buf, size_t size, lldb::SBError &sb_error) |
| 984 | { |
| 985 | size_t bytes_read = 0; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 986 | ProcessSP process_sp(GetSP()); |
| 987 | if (process_sp) |
Greg Clayton | 4a2e337 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 988 | { |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 989 | Process::StopLocker stop_locker; |
| 990 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 991 | { |
| 992 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 993 | bytes_read = process_sp->ReadCStringFromMemory (addr, (char *)buf, size, sb_error.ref()); |
| 994 | } |
| 995 | else |
| 996 | { |
Greg Clayton | 9f3c98e | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 997 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 998 | if (log) |
| 999 | log->Printf ("SBProcess(%p)::ReadCStringFromMemory() => error: process is running", process_sp.get()); |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1000 | sb_error.SetErrorString("process is running"); |
| 1001 | } |
Greg Clayton | 4a2e337 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 1002 | } |
| 1003 | else |
| 1004 | { |
| 1005 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 1006 | } |
| 1007 | return bytes_read; |
| 1008 | } |
| 1009 | |
| 1010 | uint64_t |
| 1011 | SBProcess::ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &sb_error) |
| 1012 | { |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1013 | uint64_t value = 0; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1014 | ProcessSP process_sp(GetSP()); |
| 1015 | if (process_sp) |
Greg Clayton | 4a2e337 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 1016 | { |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1017 | Process::StopLocker stop_locker; |
| 1018 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 1019 | { |
| 1020 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 1021 | value = process_sp->ReadUnsignedIntegerFromMemory (addr, byte_size, 0, sb_error.ref()); |
| 1022 | } |
| 1023 | else |
| 1024 | { |
Greg Clayton | 9f3c98e | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 1025 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1026 | if (log) |
| 1027 | log->Printf ("SBProcess(%p)::ReadUnsignedFromMemory() => error: process is running", process_sp.get()); |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1028 | sb_error.SetErrorString("process is running"); |
| 1029 | } |
Greg Clayton | 4a2e337 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 1030 | } |
| 1031 | else |
| 1032 | { |
| 1033 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 1034 | } |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1035 | return value; |
Greg Clayton | 4a2e337 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | lldb::addr_t |
| 1039 | SBProcess::ReadPointerFromMemory (addr_t addr, lldb::SBError &sb_error) |
| 1040 | { |
| 1041 | lldb::addr_t ptr = LLDB_INVALID_ADDRESS; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1042 | ProcessSP process_sp(GetSP()); |
| 1043 | if (process_sp) |
Greg Clayton | 4a2e337 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 1044 | { |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1045 | Process::StopLocker stop_locker; |
| 1046 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 1047 | { |
| 1048 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 1049 | ptr = process_sp->ReadPointerFromMemory (addr, sb_error.ref()); |
| 1050 | } |
| 1051 | else |
| 1052 | { |
Greg Clayton | 9f3c98e | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 1053 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1054 | if (log) |
| 1055 | log->Printf ("SBProcess(%p)::ReadPointerFromMemory() => error: process is running", process_sp.get()); |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1056 | sb_error.SetErrorString("process is running"); |
| 1057 | } |
Greg Clayton | 4a2e337 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 1058 | } |
| 1059 | else |
| 1060 | { |
| 1061 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 1062 | } |
| 1063 | return ptr; |
| 1064 | } |
| 1065 | |
| 1066 | size_t |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1067 | SBProcess::WriteMemory (addr_t addr, const void *src, size_t src_len, SBError &sb_error) |
| 1068 | { |
| 1069 | size_t bytes_written = 0; |
| 1070 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1071 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1072 | |
| 1073 | ProcessSP process_sp(GetSP()); |
| 1074 | |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1075 | if (log) |
| 1076 | { |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1077 | 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] | 1078 | process_sp.get(), |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1079 | addr, |
| 1080 | src, |
Greg Clayton | 851e30e | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 1081 | (uint64_t)src_len, |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1082 | sb_error.get()); |
| 1083 | } |
| 1084 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1085 | if (process_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1086 | { |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1087 | Process::StopLocker stop_locker; |
| 1088 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 1089 | { |
| 1090 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 1091 | bytes_written = process_sp->WriteMemory (addr, src, src_len, sb_error.ref()); |
| 1092 | } |
| 1093 | else |
| 1094 | { |
Greg Clayton | 9f3c98e | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 1095 | if (log) |
| 1096 | log->Printf ("SBProcess(%p)::WriteMemory() => error: process is running", process_sp.get()); |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1097 | sb_error.SetErrorString("process is running"); |
| 1098 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1099 | } |
| 1100 | |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1101 | if (log) |
| 1102 | { |
| 1103 | SBStream sstr; |
| 1104 | sb_error.GetDescription (sstr); |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1105 | 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] | 1106 | process_sp.get(), |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1107 | addr, |
| 1108 | src, |
Greg Clayton | 851e30e | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 1109 | (uint64_t)src_len, |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1110 | sb_error.get(), |
| 1111 | sstr.GetData(), |
Greg Clayton | 851e30e | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 1112 | (uint64_t)bytes_written); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1113 | } |
| 1114 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1115 | return bytes_written; |
| 1116 | } |
| 1117 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 1118 | bool |
| 1119 | SBProcess::GetDescription (SBStream &description) |
| 1120 | { |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 1121 | Stream &strm = description.ref(); |
| 1122 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1123 | ProcessSP process_sp(GetSP()); |
| 1124 | if (process_sp) |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 1125 | { |
| 1126 | char path[PATH_MAX]; |
| 1127 | GetTarget().GetExecutable().GetPath (path, sizeof(path)); |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1128 | Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer(); |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 1129 | const char *exe_name = NULL; |
| 1130 | if (exe_module) |
| 1131 | exe_name = exe_module->GetFileSpec().GetFilename().AsCString(); |
| 1132 | |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1133 | strm.Printf ("SBProcess: pid = %" PRIu64 ", state = %s, threads = %d%s%s", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1134 | process_sp->GetID(), |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 1135 | lldb_private::StateAsCString (GetState()), |
| 1136 | GetNumThreads(), |
| 1137 | exe_name ? ", executable = " : "", |
| 1138 | exe_name ? exe_name : ""); |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 1139 | } |
| 1140 | else |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 1141 | strm.PutCString ("No value"); |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 1142 | |
| 1143 | return true; |
| 1144 | } |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1145 | |
| 1146 | uint32_t |
Johnny Chen | 191343e | 2012-05-23 22:34:34 +0000 | [diff] [blame] | 1147 | SBProcess::GetNumSupportedHardwareWatchpoints (lldb::SBError &sb_error) const |
| 1148 | { |
| 1149 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1150 | |
| 1151 | uint32_t num = 0; |
| 1152 | ProcessSP process_sp(GetSP()); |
| 1153 | if (process_sp) |
| 1154 | { |
| 1155 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 1156 | sb_error.SetError(process_sp->GetWatchpointSupportInfo (num)); |
Johnny Chen | 191343e | 2012-05-23 22:34:34 +0000 | [diff] [blame] | 1157 | if (log) |
| 1158 | log->Printf ("SBProcess(%p)::GetNumSupportedHardwareWatchpoints () => %u", |
| 1159 | process_sp.get(), num); |
| 1160 | } |
| 1161 | else |
| 1162 | { |
| 1163 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 1164 | } |
| 1165 | return num; |
| 1166 | } |
| 1167 | |
| 1168 | uint32_t |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1169 | SBProcess::LoadImage (lldb::SBFileSpec &sb_image_spec, lldb::SBError &sb_error) |
| 1170 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1171 | ProcessSP process_sp(GetSP()); |
| 1172 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1173 | { |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1174 | Process::StopLocker stop_locker; |
| 1175 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 1176 | { |
| 1177 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 1178 | return process_sp->LoadImage (*sb_image_spec, sb_error.ref()); |
| 1179 | } |
| 1180 | else |
| 1181 | { |
Greg Clayton | 9f3c98e | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 1182 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1183 | if (log) |
| 1184 | log->Printf ("SBProcess(%p)::LoadImage() => error: process is running", process_sp.get()); |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1185 | sb_error.SetErrorString("process is running"); |
| 1186 | } |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1187 | } |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1188 | return LLDB_INVALID_IMAGE_TOKEN; |
| 1189 | } |
| 1190 | |
| 1191 | lldb::SBError |
| 1192 | SBProcess::UnloadImage (uint32_t image_token) |
| 1193 | { |
| 1194 | lldb::SBError sb_error; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1195 | ProcessSP process_sp(GetSP()); |
| 1196 | if (process_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1197 | { |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1198 | Process::StopLocker stop_locker; |
| 1199 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 1200 | { |
| 1201 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 1202 | sb_error.SetError (process_sp->UnloadImage (image_token)); |
| 1203 | } |
| 1204 | else |
| 1205 | { |
Greg Clayton | 9f3c98e | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 1206 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1207 | if (log) |
| 1208 | log->Printf ("SBProcess(%p)::UnloadImage() => error: process is running", process_sp.get()); |
Greg Clayton | a894fe7 | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1209 | sb_error.SetErrorString("process is running"); |
| 1210 | } |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1211 | } |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1212 | else |
| 1213 | sb_error.SetErrorString("invalid process"); |
| 1214 | return sb_error; |
| 1215 | } |