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