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