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