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