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