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) |
Greg Clayton | 6fea17e | 2014-03-03 19:15:20 +0000 | [diff] [blame] | 341 | log->Printf("SBProcess(%p)::PutSTDIN (src=\"%s\", src_len=%" PRIu64 ") => %" PRIu64, |
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, |
Greg Clayton | 6fea17e | 2014-03-03 19:15:20 +0000 | [diff] [blame] | 344 | (uint64_t) src_len, |
| 345 | (uint64_t) 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 |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 538 | SBProcess::GetNumQueues () |
| 539 | { |
| 540 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 541 | |
| 542 | uint32_t num_queues = 0; |
| 543 | ProcessSP process_sp(GetSP()); |
| 544 | if (process_sp) |
| 545 | { |
| 546 | Process::StopLocker stop_locker; |
| 547 | |
| 548 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 549 | num_queues = process_sp->GetQueueList().GetSize(); |
| 550 | } |
| 551 | |
| 552 | if (log) |
| 553 | log->Printf ("SBProcess(%p)::GetNumQueues () => %d", process_sp.get(), num_queues); |
| 554 | |
| 555 | return num_queues; |
| 556 | } |
| 557 | |
| 558 | SBQueue |
| 559 | SBProcess::GetQueueAtIndex (size_t index) |
| 560 | { |
| 561 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 562 | |
| 563 | SBQueue sb_queue; |
| 564 | QueueSP queue_sp; |
| 565 | ProcessSP process_sp(GetSP()); |
| 566 | if (process_sp) |
| 567 | { |
| 568 | Process::StopLocker stop_locker; |
| 569 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 570 | queue_sp = process_sp->GetQueueList().GetQueueAtIndex(index); |
| 571 | sb_queue.SetQueue (queue_sp); |
| 572 | } |
| 573 | |
| 574 | if (log) |
| 575 | { |
| 576 | log->Printf ("SBProcess(%p)::GetQueueAtIndex (index=%d) => SBQueue(%p)", |
| 577 | process_sp.get(), (uint32_t) index, queue_sp.get()); |
| 578 | } |
| 579 | |
| 580 | return sb_queue; |
| 581 | } |
| 582 | |
| 583 | |
| 584 | uint32_t |
Jim Ingham | bf2956a2 | 2013-01-08 23:22:42 +0000 | [diff] [blame] | 585 | SBProcess::GetStopID(bool include_expression_stops) |
| 586 | { |
| 587 | ProcessSP process_sp(GetSP()); |
| 588 | if (process_sp) |
| 589 | { |
| 590 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 591 | if (include_expression_stops) |
| 592 | return process_sp->GetStopID(); |
| 593 | else |
| 594 | return process_sp->GetLastNaturalStopID(); |
| 595 | } |
| 596 | return 0; |
| 597 | } |
| 598 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 599 | StateType |
| 600 | SBProcess::GetState () |
| 601 | { |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 602 | |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 603 | StateType ret_val = eStateInvalid; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 604 | ProcessSP process_sp(GetSP()); |
| 605 | if (process_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 606 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 607 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 608 | ret_val = process_sp->GetState(); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 609 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 610 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 611 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 612 | if (log) |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 613 | log->Printf ("SBProcess(%p)::GetState () => %s", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 614 | process_sp.get(), |
Caroline Tice | 750cd17 | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 615 | lldb_private::StateAsCString (ret_val)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 616 | |
| 617 | return ret_val; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | |
| 621 | int |
| 622 | SBProcess::GetExitStatus () |
| 623 | { |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 624 | int exit_status = 0; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 625 | ProcessSP process_sp(GetSP()); |
| 626 | if (process_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 627 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 628 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 629 | exit_status = process_sp->GetExitStatus (); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 630 | } |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 631 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 632 | if (log) |
| 633 | log->Printf ("SBProcess(%p)::GetExitStatus () => %i (0x%8.8x)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 634 | process_sp.get(), exit_status, exit_status); |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 635 | |
| 636 | return exit_status; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | const char * |
| 640 | SBProcess::GetExitDescription () |
| 641 | { |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 642 | const char *exit_desc = NULL; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 643 | ProcessSP process_sp(GetSP()); |
| 644 | if (process_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 645 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 646 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 647 | exit_desc = process_sp->GetExitDescription (); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 648 | } |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 649 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 650 | if (log) |
| 651 | log->Printf ("SBProcess(%p)::GetExitDescription () => %s", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 652 | process_sp.get(), exit_desc); |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 653 | return exit_desc; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | lldb::pid_t |
| 657 | SBProcess::GetProcessID () |
| 658 | { |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 659 | lldb::pid_t ret_val = LLDB_INVALID_PROCESS_ID; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 660 | ProcessSP process_sp(GetSP()); |
| 661 | if (process_sp) |
| 662 | ret_val = process_sp->GetID(); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 663 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 664 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 665 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 666 | log->Printf ("SBProcess(%p)::GetProcessID () => %" PRIu64, process_sp.get(), ret_val); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 667 | |
| 668 | return ret_val; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 669 | } |
| 670 | |
Greg Clayton | 949e822 | 2013-01-16 17:29:04 +0000 | [diff] [blame] | 671 | uint32_t |
| 672 | SBProcess::GetUniqueID() |
| 673 | { |
| 674 | uint32_t ret_val = 0; |
| 675 | ProcessSP process_sp(GetSP()); |
| 676 | if (process_sp) |
| 677 | ret_val = process_sp->GetUniqueID(); |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 678 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 949e822 | 2013-01-16 17:29:04 +0000 | [diff] [blame] | 679 | if (log) |
| 680 | log->Printf ("SBProcess(%p)::GetUniqueID () => %" PRIu32, process_sp.get(), ret_val); |
| 681 | return ret_val; |
| 682 | } |
| 683 | |
Johnny Chen | cf386e2 | 2011-03-01 22:56:31 +0000 | [diff] [blame] | 684 | ByteOrder |
| 685 | SBProcess::GetByteOrder () const |
| 686 | { |
| 687 | ByteOrder byteOrder = eByteOrderInvalid; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 688 | ProcessSP process_sp(GetSP()); |
| 689 | if (process_sp) |
| 690 | byteOrder = process_sp->GetTarget().GetArchitecture().GetByteOrder(); |
Johnny Chen | cf386e2 | 2011-03-01 22:56:31 +0000 | [diff] [blame] | 691 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 692 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Johnny Chen | cf386e2 | 2011-03-01 22:56:31 +0000 | [diff] [blame] | 693 | if (log) |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 694 | log->Printf ("SBProcess(%p)::GetByteOrder () => %d", process_sp.get(), byteOrder); |
Johnny Chen | cf386e2 | 2011-03-01 22:56:31 +0000 | [diff] [blame] | 695 | |
| 696 | return byteOrder; |
| 697 | } |
| 698 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 699 | uint32_t |
| 700 | SBProcess::GetAddressByteSize () const |
| 701 | { |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 702 | uint32_t size = 0; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 703 | ProcessSP process_sp(GetSP()); |
| 704 | if (process_sp) |
| 705 | size = process_sp->GetTarget().GetArchitecture().GetAddressByteSize(); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 706 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 707 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 708 | if (log) |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 709 | log->Printf ("SBProcess(%p)::GetAddressByteSize () => %d", process_sp.get(), size); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 710 | |
| 711 | return size; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 712 | } |
| 713 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 714 | SBError |
| 715 | SBProcess::Continue () |
| 716 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 717 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 718 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 719 | SBError sb_error; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 720 | ProcessSP process_sp(GetSP()); |
| 721 | |
| 722 | if (log) |
| 723 | log->Printf ("SBProcess(%p)::Continue ()...", process_sp.get()); |
| 724 | |
| 725 | if (process_sp) |
Greg Clayton | 5d5028b | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 726 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 727 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 728 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 729 | Error error (process_sp->Resume()); |
Greg Clayton | 5d5028b | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 730 | if (error.Success()) |
| 731 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 732 | if (process_sp->GetTarget().GetDebugger().GetAsyncExecution () == false) |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 733 | { |
| 734 | if (log) |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 735 | log->Printf ("SBProcess(%p)::Continue () waiting for process to stop...", process_sp.get()); |
| 736 | process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 737 | } |
Greg Clayton | 5d5028b | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 738 | } |
| 739 | sb_error.SetError(error); |
| 740 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 741 | else |
| 742 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 743 | |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 744 | if (log) |
| 745 | { |
| 746 | SBStream sstr; |
| 747 | sb_error.GetDescription (sstr); |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 748 | 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] | 749 | } |
| 750 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 751 | return sb_error; |
| 752 | } |
| 753 | |
| 754 | |
| 755 | SBError |
| 756 | SBProcess::Destroy () |
| 757 | { |
| 758 | SBError sb_error; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 759 | ProcessSP process_sp(GetSP()); |
| 760 | if (process_sp) |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 761 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 762 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 763 | sb_error.SetError(process_sp->Destroy()); |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 764 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 765 | else |
| 766 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 767 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 768 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 769 | if (log) |
| 770 | { |
| 771 | SBStream sstr; |
| 772 | sb_error.GetDescription (sstr); |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 773 | log->Printf ("SBProcess(%p)::Destroy () => SBError (%p): %s", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 774 | process_sp.get(), |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 775 | sb_error.get(), |
| 776 | sstr.GetData()); |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 777 | } |
| 778 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 779 | return sb_error; |
| 780 | } |
| 781 | |
| 782 | |
| 783 | SBError |
| 784 | SBProcess::Stop () |
| 785 | { |
| 786 | SBError sb_error; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 787 | ProcessSP process_sp(GetSP()); |
| 788 | if (process_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 789 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 790 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 791 | sb_error.SetError (process_sp->Halt()); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 792 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 793 | else |
| 794 | sb_error.SetErrorString ("SBProcess is invalid"); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 795 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 796 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 797 | if (log) |
| 798 | { |
| 799 | SBStream sstr; |
| 800 | sb_error.GetDescription (sstr); |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 801 | log->Printf ("SBProcess(%p)::Stop () => SBError (%p): %s", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 802 | process_sp.get(), |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 803 | sb_error.get(), |
Caroline Tice | 750cd17 | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 804 | sstr.GetData()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 805 | } |
| 806 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 807 | return sb_error; |
| 808 | } |
| 809 | |
| 810 | SBError |
| 811 | SBProcess::Kill () |
| 812 | { |
| 813 | SBError sb_error; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 814 | ProcessSP process_sp(GetSP()); |
| 815 | if (process_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 816 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 817 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 818 | sb_error.SetError (process_sp->Destroy()); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 819 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 820 | else |
| 821 | sb_error.SetErrorString ("SBProcess is invalid"); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 822 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 823 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 824 | if (log) |
| 825 | { |
| 826 | SBStream sstr; |
| 827 | sb_error.GetDescription (sstr); |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 828 | log->Printf ("SBProcess(%p)::Kill () => SBError (%p): %s", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 829 | process_sp.get(), |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 830 | sb_error.get(), |
Caroline Tice | 750cd17 | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 831 | sstr.GetData()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 832 | } |
| 833 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 834 | return sb_error; |
| 835 | } |
| 836 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 837 | SBError |
| 838 | SBProcess::Detach () |
| 839 | { |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 840 | // FIXME: This should come from a process default. |
| 841 | bool keep_stopped = false; |
| 842 | return Detach (keep_stopped); |
| 843 | } |
| 844 | |
| 845 | SBError |
| 846 | SBProcess::Detach (bool keep_stopped) |
| 847 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 848 | SBError sb_error; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 849 | ProcessSP process_sp(GetSP()); |
| 850 | if (process_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 851 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 852 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 853 | sb_error.SetError (process_sp->Detach(keep_stopped)); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 854 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 855 | else |
| 856 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 857 | |
| 858 | return sb_error; |
| 859 | } |
| 860 | |
| 861 | SBError |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 862 | SBProcess::Signal (int signo) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 863 | { |
| 864 | SBError sb_error; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 865 | ProcessSP process_sp(GetSP()); |
| 866 | if (process_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 867 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 868 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 869 | sb_error.SetError (process_sp->Signal (signo)); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 870 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 871 | else |
| 872 | sb_error.SetErrorString ("SBProcess is invalid"); |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 873 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 874 | if (log) |
| 875 | { |
| 876 | SBStream sstr; |
| 877 | sb_error.GetDescription (sstr); |
| 878 | log->Printf ("SBProcess(%p)::Signal (signo=%i) => SBError (%p): %s", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 879 | process_sp.get(), |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 880 | signo, |
| 881 | sb_error.get(), |
| 882 | sstr.GetData()); |
| 883 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 884 | return sb_error; |
| 885 | } |
| 886 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 887 | void |
| 888 | SBProcess::SendAsyncInterrupt () |
| 889 | { |
| 890 | ProcessSP process_sp(GetSP()); |
| 891 | if (process_sp) |
| 892 | { |
| 893 | process_sp->SendAsyncInterrupt (); |
| 894 | } |
| 895 | } |
| 896 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 897 | SBThread |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 898 | SBProcess::GetThreadByID (tid_t tid) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 899 | { |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 900 | SBThread sb_thread; |
Greg Clayton | 17a6ad0 | 2012-01-30 02:53:15 +0000 | [diff] [blame] | 901 | ThreadSP thread_sp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 902 | ProcessSP process_sp(GetSP()); |
| 903 | if (process_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 904 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 905 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 906 | Process::StopLocker stop_locker; |
| 907 | const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); |
| 908 | thread_sp = process_sp->GetThreadList().FindThreadByID (tid, can_update); |
Greg Clayton | 17a6ad0 | 2012-01-30 02:53:15 +0000 | [diff] [blame] | 909 | sb_thread.SetThread (thread_sp); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 910 | } |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 911 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 912 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 913 | if (log) |
| 914 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 915 | log->Printf ("SBProcess(%p)::GetThreadByID (tid=0x%4.4" PRIx64 ") => SBThread (%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 916 | process_sp.get(), |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 917 | tid, |
Greg Clayton | 17a6ad0 | 2012-01-30 02:53:15 +0000 | [diff] [blame] | 918 | thread_sp.get()); |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | return sb_thread; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 922 | } |
| 923 | |
Jim Ingham | 18b4689 | 2012-07-13 20:18:18 +0000 | [diff] [blame] | 924 | SBThread |
| 925 | SBProcess::GetThreadByIndexID (uint32_t index_id) |
| 926 | { |
| 927 | SBThread sb_thread; |
| 928 | ThreadSP thread_sp; |
| 929 | ProcessSP process_sp(GetSP()); |
| 930 | if (process_sp) |
| 931 | { |
| 932 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 933 | Process::StopLocker stop_locker; |
| 934 | const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); |
| 935 | thread_sp = process_sp->GetThreadList().FindThreadByIndexID (index_id, can_update); |
| 936 | sb_thread.SetThread (thread_sp); |
| 937 | } |
| 938 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 939 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Jim Ingham | 18b4689 | 2012-07-13 20:18:18 +0000 | [diff] [blame] | 940 | if (log) |
| 941 | { |
| 942 | log->Printf ("SBProcess(%p)::GetThreadByID (tid=0x%x) => SBThread (%p)", |
| 943 | process_sp.get(), |
| 944 | index_id, |
| 945 | thread_sp.get()); |
| 946 | } |
| 947 | |
| 948 | return sb_thread; |
| 949 | } |
| 950 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 951 | StateType |
| 952 | SBProcess::GetStateFromEvent (const SBEvent &event) |
| 953 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 954 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 955 | |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 956 | StateType ret_val = Process::ProcessEventData::GetStateFromEvent (event.get()); |
| 957 | |
| 958 | if (log) |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 959 | log->Printf ("SBProcess::GetStateFromEvent (event.sp=%p) => %s", event.get(), |
Caroline Tice | 750cd17 | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 960 | lldb_private::StateAsCString (ret_val)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 961 | |
| 962 | return ret_val; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 963 | } |
| 964 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 965 | bool |
| 966 | SBProcess::GetRestartedFromEvent (const SBEvent &event) |
| 967 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 968 | return Process::ProcessEventData::GetRestartedFromEvent (event.get()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 969 | } |
| 970 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 971 | size_t |
| 972 | SBProcess::GetNumRestartedReasonsFromEvent (const lldb::SBEvent &event) |
| 973 | { |
| 974 | return Process::ProcessEventData::GetNumRestartedReasons(event.get()); |
| 975 | } |
| 976 | |
| 977 | const char * |
| 978 | SBProcess::GetRestartedReasonAtIndexFromEvent (const lldb::SBEvent &event, size_t idx) |
| 979 | { |
| 980 | return Process::ProcessEventData::GetRestartedReasonAtIndex(event.get(), idx); |
| 981 | } |
| 982 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 983 | SBProcess |
| 984 | SBProcess::GetProcessFromEvent (const SBEvent &event) |
| 985 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 986 | SBProcess process(Process::ProcessEventData::GetProcessFromEvent (event.get())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 987 | return process; |
| 988 | } |
| 989 | |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 990 | bool |
| 991 | SBProcess::EventIsProcessEvent (const SBEvent &event) |
| 992 | { |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 993 | return strcmp (event.GetBroadcasterClass(), SBProcess::GetBroadcasterClass()) == 0; |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 994 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 995 | |
| 996 | SBBroadcaster |
| 997 | SBProcess::GetBroadcaster () const |
| 998 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 999 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1000 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1001 | ProcessSP process_sp(GetSP()); |
| 1002 | |
| 1003 | SBBroadcaster broadcaster(process_sp.get(), false); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1004 | |
| 1005 | if (log) |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1006 | log->Printf ("SBProcess(%p)::GetBroadcaster () => SBBroadcaster (%p)", process_sp.get(), |
Caroline Tice | 750cd17 | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 1007 | broadcaster.get()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1008 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1009 | return broadcaster; |
| 1010 | } |
| 1011 | |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 1012 | const char * |
| 1013 | SBProcess::GetBroadcasterClass () |
| 1014 | { |
| 1015 | return Process::GetStaticBroadcasterClass().AsCString(); |
| 1016 | } |
| 1017 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1018 | size_t |
| 1019 | SBProcess::ReadMemory (addr_t addr, void *dst, size_t dst_len, SBError &sb_error) |
| 1020 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1021 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
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 | size_t bytes_read = 0; |
| 1024 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1025 | ProcessSP process_sp(GetSP()); |
| 1026 | |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1027 | if (log) |
| 1028 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1029 | 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] | 1030 | process_sp.get(), |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1031 | addr, |
| 1032 | dst, |
Greg Clayton | 43e0af0 | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 1033 | (uint64_t)dst_len, |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1034 | sb_error.get()); |
| 1035 | } |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1036 | |
| 1037 | if (process_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1038 | { |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1039 | Process::StopLocker stop_locker; |
| 1040 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 1041 | { |
| 1042 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 1043 | bytes_read = process_sp->ReadMemory (addr, dst, dst_len, sb_error.ref()); |
| 1044 | } |
| 1045 | else |
| 1046 | { |
Greg Clayton | c9858e4 | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 1047 | if (log) |
| 1048 | log->Printf ("SBProcess(%p)::ReadMemory() => error: process is running", process_sp.get()); |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1049 | sb_error.SetErrorString("process is running"); |
| 1050 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1051 | } |
| 1052 | else |
| 1053 | { |
| 1054 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 1055 | } |
| 1056 | |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1057 | if (log) |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 1058 | { |
| 1059 | SBStream sstr; |
| 1060 | sb_error.GetDescription (sstr); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1061 | 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] | 1062 | process_sp.get(), |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 1063 | addr, |
| 1064 | dst, |
Greg Clayton | 43e0af0 | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 1065 | (uint64_t)dst_len, |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 1066 | sb_error.get(), |
| 1067 | sstr.GetData(), |
Greg Clayton | 43e0af0 | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 1068 | (uint64_t)bytes_read); |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 1069 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1070 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1071 | return bytes_read; |
| 1072 | } |
| 1073 | |
| 1074 | size_t |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 1075 | SBProcess::ReadCStringFromMemory (addr_t addr, void *buf, size_t size, lldb::SBError &sb_error) |
| 1076 | { |
| 1077 | size_t bytes_read = 0; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1078 | ProcessSP process_sp(GetSP()); |
| 1079 | if (process_sp) |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 1080 | { |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1081 | Process::StopLocker stop_locker; |
| 1082 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 1083 | { |
| 1084 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 1085 | bytes_read = process_sp->ReadCStringFromMemory (addr, (char *)buf, size, sb_error.ref()); |
| 1086 | } |
| 1087 | else |
| 1088 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1089 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | c9858e4 | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 1090 | if (log) |
| 1091 | log->Printf ("SBProcess(%p)::ReadCStringFromMemory() => error: process is running", process_sp.get()); |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1092 | sb_error.SetErrorString("process is running"); |
| 1093 | } |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 1094 | } |
| 1095 | else |
| 1096 | { |
| 1097 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 1098 | } |
| 1099 | return bytes_read; |
| 1100 | } |
| 1101 | |
| 1102 | uint64_t |
| 1103 | SBProcess::ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &sb_error) |
| 1104 | { |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1105 | uint64_t value = 0; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1106 | ProcessSP process_sp(GetSP()); |
| 1107 | if (process_sp) |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 1108 | { |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1109 | Process::StopLocker stop_locker; |
| 1110 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 1111 | { |
| 1112 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 1113 | value = process_sp->ReadUnsignedIntegerFromMemory (addr, byte_size, 0, sb_error.ref()); |
| 1114 | } |
| 1115 | else |
| 1116 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1117 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | c9858e4 | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 1118 | if (log) |
| 1119 | log->Printf ("SBProcess(%p)::ReadUnsignedFromMemory() => error: process is running", process_sp.get()); |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1120 | sb_error.SetErrorString("process is running"); |
| 1121 | } |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 1122 | } |
| 1123 | else |
| 1124 | { |
| 1125 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 1126 | } |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1127 | return value; |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | lldb::addr_t |
| 1131 | SBProcess::ReadPointerFromMemory (addr_t addr, lldb::SBError &sb_error) |
| 1132 | { |
| 1133 | lldb::addr_t ptr = LLDB_INVALID_ADDRESS; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1134 | ProcessSP process_sp(GetSP()); |
| 1135 | if (process_sp) |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 1136 | { |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1137 | Process::StopLocker stop_locker; |
| 1138 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 1139 | { |
| 1140 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 1141 | ptr = process_sp->ReadPointerFromMemory (addr, sb_error.ref()); |
| 1142 | } |
| 1143 | else |
| 1144 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1145 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | c9858e4 | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 1146 | if (log) |
| 1147 | log->Printf ("SBProcess(%p)::ReadPointerFromMemory() => error: process is running", process_sp.get()); |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1148 | sb_error.SetErrorString("process is running"); |
| 1149 | } |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 1150 | } |
| 1151 | else |
| 1152 | { |
| 1153 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 1154 | } |
| 1155 | return ptr; |
| 1156 | } |
| 1157 | |
| 1158 | size_t |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1159 | SBProcess::WriteMemory (addr_t addr, const void *src, size_t src_len, SBError &sb_error) |
| 1160 | { |
| 1161 | size_t bytes_written = 0; |
| 1162 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1163 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1164 | |
| 1165 | ProcessSP process_sp(GetSP()); |
| 1166 | |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1167 | if (log) |
| 1168 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1169 | 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] | 1170 | process_sp.get(), |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1171 | addr, |
| 1172 | src, |
Greg Clayton | 43e0af0 | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 1173 | (uint64_t)src_len, |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1174 | sb_error.get()); |
| 1175 | } |
| 1176 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1177 | if (process_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1178 | { |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1179 | Process::StopLocker stop_locker; |
| 1180 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 1181 | { |
| 1182 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 1183 | bytes_written = process_sp->WriteMemory (addr, src, src_len, sb_error.ref()); |
| 1184 | } |
| 1185 | else |
| 1186 | { |
Greg Clayton | c9858e4 | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 1187 | if (log) |
| 1188 | log->Printf ("SBProcess(%p)::WriteMemory() => error: process is running", process_sp.get()); |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1189 | sb_error.SetErrorString("process is running"); |
| 1190 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1191 | } |
| 1192 | |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1193 | if (log) |
| 1194 | { |
| 1195 | SBStream sstr; |
| 1196 | sb_error.GetDescription (sstr); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1197 | 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] | 1198 | process_sp.get(), |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1199 | addr, |
| 1200 | src, |
Greg Clayton | 43e0af0 | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 1201 | (uint64_t)src_len, |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1202 | sb_error.get(), |
| 1203 | sstr.GetData(), |
Greg Clayton | 43e0af0 | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 1204 | (uint64_t)bytes_written); |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1207 | return bytes_written; |
| 1208 | } |
| 1209 | |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 1210 | bool |
| 1211 | SBProcess::GetDescription (SBStream &description) |
| 1212 | { |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 1213 | Stream &strm = description.ref(); |
| 1214 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1215 | ProcessSP process_sp(GetSP()); |
| 1216 | if (process_sp) |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 1217 | { |
| 1218 | char path[PATH_MAX]; |
| 1219 | GetTarget().GetExecutable().GetPath (path, sizeof(path)); |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1220 | Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer(); |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 1221 | const char *exe_name = NULL; |
| 1222 | if (exe_module) |
| 1223 | exe_name = exe_module->GetFileSpec().GetFilename().AsCString(); |
| 1224 | |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1225 | strm.Printf ("SBProcess: pid = %" PRIu64 ", state = %s, threads = %d%s%s", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1226 | process_sp->GetID(), |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 1227 | lldb_private::StateAsCString (GetState()), |
| 1228 | GetNumThreads(), |
| 1229 | exe_name ? ", executable = " : "", |
| 1230 | exe_name ? exe_name : ""); |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 1231 | } |
| 1232 | else |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 1233 | strm.PutCString ("No value"); |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 1234 | |
| 1235 | return true; |
| 1236 | } |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1237 | |
| 1238 | uint32_t |
Johnny Chen | f9ef60d | 2012-05-23 22:34:34 +0000 | [diff] [blame] | 1239 | SBProcess::GetNumSupportedHardwareWatchpoints (lldb::SBError &sb_error) const |
| 1240 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1241 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Johnny Chen | f9ef60d | 2012-05-23 22:34:34 +0000 | [diff] [blame] | 1242 | |
| 1243 | uint32_t num = 0; |
| 1244 | ProcessSP process_sp(GetSP()); |
| 1245 | if (process_sp) |
| 1246 | { |
| 1247 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 1248 | sb_error.SetError(process_sp->GetWatchpointSupportInfo (num)); |
Johnny Chen | f9ef60d | 2012-05-23 22:34:34 +0000 | [diff] [blame] | 1249 | if (log) |
| 1250 | log->Printf ("SBProcess(%p)::GetNumSupportedHardwareWatchpoints () => %u", |
| 1251 | process_sp.get(), num); |
| 1252 | } |
| 1253 | else |
| 1254 | { |
| 1255 | sb_error.SetErrorString ("SBProcess is invalid"); |
| 1256 | } |
| 1257 | return num; |
| 1258 | } |
| 1259 | |
| 1260 | uint32_t |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1261 | SBProcess::LoadImage (lldb::SBFileSpec &sb_image_spec, lldb::SBError &sb_error) |
| 1262 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1263 | ProcessSP process_sp(GetSP()); |
| 1264 | if (process_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1265 | { |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1266 | Process::StopLocker stop_locker; |
| 1267 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 1268 | { |
| 1269 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 1270 | return process_sp->LoadImage (*sb_image_spec, sb_error.ref()); |
| 1271 | } |
| 1272 | else |
| 1273 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1274 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | c9858e4 | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 1275 | if (log) |
| 1276 | log->Printf ("SBProcess(%p)::LoadImage() => error: process is running", process_sp.get()); |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1277 | sb_error.SetErrorString("process is running"); |
| 1278 | } |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1279 | } |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1280 | return LLDB_INVALID_IMAGE_TOKEN; |
| 1281 | } |
| 1282 | |
| 1283 | lldb::SBError |
| 1284 | SBProcess::UnloadImage (uint32_t image_token) |
| 1285 | { |
| 1286 | lldb::SBError sb_error; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1287 | ProcessSP process_sp(GetSP()); |
| 1288 | if (process_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1289 | { |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1290 | Process::StopLocker stop_locker; |
| 1291 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 1292 | { |
| 1293 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 1294 | sb_error.SetError (process_sp->UnloadImage (image_token)); |
| 1295 | } |
| 1296 | else |
| 1297 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1298 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | c9858e4 | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 1299 | if (log) |
| 1300 | log->Printf ("SBProcess(%p)::UnloadImage() => error: process is running", process_sp.get()); |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1301 | sb_error.SetErrorString("process is running"); |
| 1302 | } |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1303 | } |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1304 | else |
| 1305 | sb_error.SetErrorString("invalid process"); |
| 1306 | return sb_error; |
| 1307 | } |
Jason Molenda | 8c71337 | 2013-11-05 11:00:35 +0000 | [diff] [blame] | 1308 | |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame^] | 1309 | lldb::SBError |
| 1310 | SBProcess::SendEventData (const char *event_data) |
| 1311 | { |
| 1312 | lldb::SBError sb_error; |
| 1313 | ProcessSP process_sp(GetSP()); |
| 1314 | if (process_sp) |
| 1315 | { |
| 1316 | Process::StopLocker stop_locker; |
| 1317 | if (stop_locker.TryLock(&process_sp->GetRunLock())) |
| 1318 | { |
| 1319 | Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); |
| 1320 | sb_error.SetError (process_sp->SendEventData (event_data)); |
| 1321 | } |
| 1322 | else |
| 1323 | { |
| 1324 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1325 | if (log) |
| 1326 | log->Printf ("SBProcess(%p)::SendEventData() => error: process is running", process_sp.get()); |
| 1327 | sb_error.SetErrorString("process is running"); |
| 1328 | } |
| 1329 | } |
| 1330 | else |
| 1331 | sb_error.SetErrorString("invalid process"); |
| 1332 | return sb_error; |
| 1333 | } |
| 1334 | |
Jason Molenda | 8c71337 | 2013-11-05 11:00:35 +0000 | [diff] [blame] | 1335 | uint32_t |
Jason Molenda | 95d005c | 2013-11-06 03:07:33 +0000 | [diff] [blame] | 1336 | SBProcess::GetNumExtendedBacktraceTypes () |
Jason Molenda | 8c71337 | 2013-11-05 11:00:35 +0000 | [diff] [blame] | 1337 | { |
| 1338 | ProcessSP process_sp(GetSP()); |
| 1339 | if (process_sp && process_sp->GetSystemRuntime()) |
| 1340 | { |
| 1341 | SystemRuntime *runtime = process_sp->GetSystemRuntime(); |
Jason Molenda | 95d005c | 2013-11-06 03:07:33 +0000 | [diff] [blame] | 1342 | return runtime->GetExtendedBacktraceTypes().size(); |
Jason Molenda | 8c71337 | 2013-11-05 11:00:35 +0000 | [diff] [blame] | 1343 | } |
| 1344 | return 0; |
| 1345 | } |
| 1346 | |
| 1347 | const char * |
Jason Molenda | 95d005c | 2013-11-06 03:07:33 +0000 | [diff] [blame] | 1348 | SBProcess::GetExtendedBacktraceTypeAtIndex (uint32_t idx) |
Jason Molenda | 8c71337 | 2013-11-05 11:00:35 +0000 | [diff] [blame] | 1349 | { |
| 1350 | ProcessSP process_sp(GetSP()); |
| 1351 | if (process_sp && process_sp->GetSystemRuntime()) |
| 1352 | { |
| 1353 | SystemRuntime *runtime = process_sp->GetSystemRuntime(); |
Jason Molenda | 008c45f | 2013-11-12 23:33:32 +0000 | [diff] [blame] | 1354 | const std::vector<ConstString> &names = runtime->GetExtendedBacktraceTypes(); |
Jason Molenda | 8c71337 | 2013-11-05 11:00:35 +0000 | [diff] [blame] | 1355 | if (idx < names.size()) |
| 1356 | { |
| 1357 | return names[idx].AsCString(); |
| 1358 | } |
| 1359 | else |
| 1360 | { |
| 1361 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1362 | if (log) |
Jason Molenda | 95d005c | 2013-11-06 03:07:33 +0000 | [diff] [blame] | 1363 | log->Printf("SBProcess(%p)::GetExtendedBacktraceTypeAtIndex() => error: requested extended backtrace name out of bounds", process_sp.get()); |
Jason Molenda | 8c71337 | 2013-11-05 11:00:35 +0000 | [diff] [blame] | 1364 | } |
| 1365 | } |
| 1366 | return NULL; |
| 1367 | } |