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