SBProcess.cpp revision 276479
1254721Semaste//===-- SBProcess.cpp -------------------------------------------*- C++ -*-===// 2254721Semaste// 3254721Semaste// The LLVM Compiler Infrastructure 4254721Semaste// 5254721Semaste// This file is distributed under the University of Illinois Open Source 6254721Semaste// License. See LICENSE.TXT for details. 7254721Semaste// 8254721Semaste//===----------------------------------------------------------------------===// 9254721Semaste 10254721Semaste#include "lldb/lldb-python.h" 11254721Semaste 12254721Semaste#include "lldb/API/SBProcess.h" 13254721Semaste 14258054Semaste// C Includes 15258054Semaste#include <inttypes.h> 16258054Semaste 17254721Semaste#include "lldb/lldb-defines.h" 18254721Semaste#include "lldb/lldb-types.h" 19254721Semaste 20254721Semaste#include "lldb/Interpreter/Args.h" 21254721Semaste#include "lldb/Core/Debugger.h" 22254721Semaste#include "lldb/Core/Log.h" 23254721Semaste#include "lldb/Core/Module.h" 24254721Semaste#include "lldb/Core/State.h" 25254721Semaste#include "lldb/Core/Stream.h" 26254721Semaste#include "lldb/Core/StreamFile.h" 27254721Semaste#include "lldb/Target/Process.h" 28254721Semaste#include "lldb/Target/RegisterContext.h" 29258054Semaste#include "lldb/Target/SystemRuntime.h" 30254721Semaste#include "lldb/Target/Target.h" 31254721Semaste#include "lldb/Target/Thread.h" 32254721Semaste 33254721Semaste// Project includes 34254721Semaste 35254721Semaste#include "lldb/API/SBBroadcaster.h" 36254721Semaste#include "lldb/API/SBCommandReturnObject.h" 37254721Semaste#include "lldb/API/SBDebugger.h" 38254721Semaste#include "lldb/API/SBEvent.h" 39254721Semaste#include "lldb/API/SBFileSpec.h" 40254721Semaste#include "lldb/API/SBThread.h" 41254721Semaste#include "lldb/API/SBStream.h" 42254721Semaste#include "lldb/API/SBStringList.h" 43276479Sdim#include "lldb/API/SBUnixSignals.h" 44254721Semaste 45254721Semasteusing namespace lldb; 46254721Semasteusing namespace lldb_private; 47254721Semaste 48254721Semaste 49254721SemasteSBProcess::SBProcess () : 50254721Semaste m_opaque_wp() 51254721Semaste{ 52254721Semaste} 53254721Semaste 54254721Semaste 55254721Semaste//---------------------------------------------------------------------- 56254721Semaste// SBProcess constructor 57254721Semaste//---------------------------------------------------------------------- 58254721Semaste 59254721SemasteSBProcess::SBProcess (const SBProcess& rhs) : 60254721Semaste m_opaque_wp (rhs.m_opaque_wp) 61254721Semaste{ 62254721Semaste} 63254721Semaste 64254721Semaste 65254721SemasteSBProcess::SBProcess (const lldb::ProcessSP &process_sp) : 66254721Semaste m_opaque_wp (process_sp) 67254721Semaste{ 68254721Semaste} 69254721Semaste 70254721Semasteconst SBProcess& 71254721SemasteSBProcess::operator = (const SBProcess& rhs) 72254721Semaste{ 73254721Semaste if (this != &rhs) 74254721Semaste m_opaque_wp = rhs.m_opaque_wp; 75254721Semaste return *this; 76254721Semaste} 77254721Semaste 78254721Semaste//---------------------------------------------------------------------- 79254721Semaste// Destructor 80254721Semaste//---------------------------------------------------------------------- 81254721SemasteSBProcess::~SBProcess() 82254721Semaste{ 83254721Semaste} 84254721Semaste 85254721Semasteconst char * 86254721SemasteSBProcess::GetBroadcasterClassName () 87254721Semaste{ 88254721Semaste return Process::GetStaticBroadcasterClass().AsCString(); 89254721Semaste} 90254721Semaste 91254721Semasteconst char * 92254721SemasteSBProcess::GetPluginName () 93254721Semaste{ 94254721Semaste ProcessSP process_sp(GetSP()); 95254721Semaste if (process_sp) 96254721Semaste { 97254721Semaste return process_sp->GetPluginName().GetCString(); 98254721Semaste } 99254721Semaste return "<Unknown>"; 100254721Semaste} 101254721Semaste 102254721Semasteconst char * 103254721SemasteSBProcess::GetShortPluginName () 104254721Semaste{ 105254721Semaste ProcessSP process_sp(GetSP()); 106254721Semaste if (process_sp) 107254721Semaste { 108254721Semaste return process_sp->GetPluginName().GetCString(); 109254721Semaste } 110254721Semaste return "<Unknown>"; 111254721Semaste} 112254721Semaste 113254721Semaste 114254721Semastelldb::ProcessSP 115254721SemasteSBProcess::GetSP() const 116254721Semaste{ 117254721Semaste return m_opaque_wp.lock(); 118254721Semaste} 119254721Semaste 120254721Semastevoid 121254721SemasteSBProcess::SetSP (const ProcessSP &process_sp) 122254721Semaste{ 123254721Semaste m_opaque_wp = process_sp; 124254721Semaste} 125254721Semaste 126254721Semastevoid 127254721SemasteSBProcess::Clear () 128254721Semaste{ 129254721Semaste m_opaque_wp.reset(); 130254721Semaste} 131254721Semaste 132254721Semaste 133254721Semastebool 134254721SemasteSBProcess::IsValid() const 135254721Semaste{ 136254721Semaste ProcessSP process_sp(m_opaque_wp.lock()); 137254721Semaste return ((bool) process_sp && process_sp->IsValid()); 138254721Semaste} 139254721Semaste 140254721Semastebool 141254721SemasteSBProcess::RemoteLaunch (char const **argv, 142254721Semaste char const **envp, 143254721Semaste const char *stdin_path, 144254721Semaste const char *stdout_path, 145254721Semaste const char *stderr_path, 146254721Semaste const char *working_directory, 147254721Semaste uint32_t launch_flags, 148254721Semaste bool stop_at_entry, 149254721Semaste lldb::SBError& error) 150254721Semaste{ 151254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 152276479Sdim if (log) 153254721Semaste 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))...", 154276479Sdim static_cast<void*>(m_opaque_wp.lock().get()), 155276479Sdim static_cast<void*>(argv), static_cast<void*>(envp), 156276479Sdim stdin_path ? stdin_path : "NULL", 157276479Sdim stdout_path ? stdout_path : "NULL", 158276479Sdim stderr_path ? stderr_path : "NULL", 159254721Semaste working_directory ? working_directory : "NULL", 160276479Sdim launch_flags, stop_at_entry, 161276479Sdim static_cast<void*>(error.get())); 162276479Sdim 163254721Semaste ProcessSP process_sp(GetSP()); 164254721Semaste if (process_sp) 165254721Semaste { 166254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 167254721Semaste if (process_sp->GetState() == eStateConnected) 168254721Semaste { 169254721Semaste if (stop_at_entry) 170254721Semaste launch_flags |= eLaunchFlagStopAtEntry; 171276479Sdim ProcessLaunchInfo launch_info (stdin_path, 172254721Semaste stdout_path, 173254721Semaste stderr_path, 174254721Semaste working_directory, 175254721Semaste launch_flags); 176254721Semaste Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer(); 177254721Semaste if (exe_module) 178254721Semaste launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true); 179254721Semaste if (argv) 180254721Semaste launch_info.GetArguments().AppendArguments (argv); 181254721Semaste if (envp) 182254721Semaste launch_info.GetEnvironmentEntries ().SetArguments (envp); 183254721Semaste error.SetError (process_sp->Launch (launch_info)); 184254721Semaste } 185254721Semaste else 186254721Semaste { 187254721Semaste error.SetErrorString ("must be in eStateConnected to call RemoteLaunch"); 188254721Semaste } 189254721Semaste } 190254721Semaste else 191254721Semaste { 192254721Semaste error.SetErrorString ("unable to attach pid"); 193254721Semaste } 194276479Sdim 195254721Semaste if (log) { 196254721Semaste SBStream sstr; 197254721Semaste error.GetDescription (sstr); 198276479Sdim log->Printf ("SBProcess(%p)::RemoteLaunch (...) => SBError (%p): %s", 199276479Sdim static_cast<void*>(process_sp.get()), 200276479Sdim static_cast<void*>(error.get()), sstr.GetData()); 201254721Semaste } 202276479Sdim 203254721Semaste return error.Success(); 204254721Semaste} 205254721Semaste 206254721Semastebool 207254721SemasteSBProcess::RemoteAttachToProcessWithID (lldb::pid_t pid, lldb::SBError& error) 208254721Semaste{ 209254721Semaste ProcessSP process_sp(GetSP()); 210254721Semaste if (process_sp) 211254721Semaste { 212254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 213254721Semaste if (process_sp->GetState() == eStateConnected) 214254721Semaste { 215254721Semaste ProcessAttachInfo attach_info; 216254721Semaste attach_info.SetProcessID (pid); 217276479Sdim error.SetError (process_sp->Attach (attach_info)); 218254721Semaste } 219254721Semaste else 220254721Semaste { 221254721Semaste error.SetErrorString ("must be in eStateConnected to call RemoteAttachToProcessWithID"); 222254721Semaste } 223254721Semaste } 224254721Semaste else 225254721Semaste { 226254721Semaste error.SetErrorString ("unable to attach pid"); 227254721Semaste } 228254721Semaste 229254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 230254721Semaste if (log) { 231254721Semaste SBStream sstr; 232254721Semaste error.GetDescription (sstr); 233276479Sdim log->Printf ("SBProcess(%p)::RemoteAttachToProcessWithID (%" PRIu64 ") => SBError (%p): %s", 234276479Sdim static_cast<void*>(process_sp.get()), pid, 235276479Sdim static_cast<void*>(error.get()), sstr.GetData()); 236254721Semaste } 237254721Semaste 238254721Semaste return error.Success(); 239254721Semaste} 240254721Semaste 241254721Semaste 242254721Semasteuint32_t 243254721SemasteSBProcess::GetNumThreads () 244254721Semaste{ 245254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 246254721Semaste 247254721Semaste uint32_t num_threads = 0; 248254721Semaste ProcessSP process_sp(GetSP()); 249254721Semaste if (process_sp) 250254721Semaste { 251254721Semaste Process::StopLocker stop_locker; 252276479Sdim 253254721Semaste const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); 254254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 255254721Semaste num_threads = process_sp->GetThreadList().GetSize(can_update); 256254721Semaste } 257254721Semaste 258254721Semaste if (log) 259276479Sdim log->Printf ("SBProcess(%p)::GetNumThreads () => %d", 260276479Sdim static_cast<void*>(process_sp.get()), num_threads); 261254721Semaste 262254721Semaste return num_threads; 263254721Semaste} 264254721Semaste 265254721SemasteSBThread 266254721SemasteSBProcess::GetSelectedThread () const 267254721Semaste{ 268254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 269254721Semaste 270254721Semaste SBThread sb_thread; 271254721Semaste ThreadSP thread_sp; 272254721Semaste ProcessSP process_sp(GetSP()); 273254721Semaste if (process_sp) 274254721Semaste { 275254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 276254721Semaste thread_sp = process_sp->GetThreadList().GetSelectedThread(); 277254721Semaste sb_thread.SetThread (thread_sp); 278254721Semaste } 279254721Semaste 280254721Semaste if (log) 281276479Sdim log->Printf ("SBProcess(%p)::GetSelectedThread () => SBThread(%p)", 282276479Sdim static_cast<void*>(process_sp.get()), 283276479Sdim static_cast<void*>(thread_sp.get())); 284254721Semaste 285254721Semaste return sb_thread; 286254721Semaste} 287254721Semaste 288254721SemasteSBThread 289254721SemasteSBProcess::CreateOSPluginThread (lldb::tid_t tid, lldb::addr_t context) 290254721Semaste{ 291254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 292276479Sdim 293254721Semaste SBThread sb_thread; 294254721Semaste ThreadSP thread_sp; 295254721Semaste ProcessSP process_sp(GetSP()); 296254721Semaste if (process_sp) 297254721Semaste { 298254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 299254721Semaste thread_sp = process_sp->CreateOSPluginThread(tid, context); 300254721Semaste sb_thread.SetThread (thread_sp); 301254721Semaste } 302276479Sdim 303254721Semaste if (log) 304276479Sdim log->Printf ("SBProcess(%p)::CreateOSPluginThread (tid=0x%" PRIx64 ", context=0x%" PRIx64 ") => SBThread(%p)", 305276479Sdim static_cast<void*>(process_sp.get()), tid, context, 306276479Sdim static_cast<void*>(thread_sp.get())); 307276479Sdim 308254721Semaste return sb_thread; 309254721Semaste} 310254721Semaste 311254721SemasteSBTarget 312254721SemasteSBProcess::GetTarget() const 313254721Semaste{ 314254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 315254721Semaste 316254721Semaste SBTarget sb_target; 317254721Semaste TargetSP target_sp; 318254721Semaste ProcessSP process_sp(GetSP()); 319254721Semaste if (process_sp) 320254721Semaste { 321254721Semaste target_sp = process_sp->GetTarget().shared_from_this(); 322254721Semaste sb_target.SetSP (target_sp); 323254721Semaste } 324276479Sdim 325254721Semaste if (log) 326276479Sdim log->Printf ("SBProcess(%p)::GetTarget () => SBTarget(%p)", 327276479Sdim static_cast<void*>(process_sp.get()), 328276479Sdim static_cast<void*>(target_sp.get())); 329254721Semaste 330254721Semaste return sb_target; 331254721Semaste} 332254721Semaste 333254721Semaste 334254721Semastesize_t 335254721SemasteSBProcess::PutSTDIN (const char *src, size_t src_len) 336254721Semaste{ 337254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 338254721Semaste 339254721Semaste size_t ret_val = 0; 340254721Semaste ProcessSP process_sp(GetSP()); 341254721Semaste if (process_sp) 342254721Semaste { 343254721Semaste Error error; 344254721Semaste ret_val = process_sp->PutSTDIN (src, src_len, error); 345254721Semaste } 346276479Sdim 347254721Semaste if (log) 348276479Sdim log->Printf("SBProcess(%p)::PutSTDIN (src=\"%s\", src_len=%" PRIu64 ") => %" PRIu64, 349276479Sdim static_cast<void*>(process_sp.get()), src, 350276479Sdim static_cast<uint64_t>(src_len), 351276479Sdim static_cast<uint64_t>(ret_val)); 352254721Semaste 353254721Semaste return ret_val; 354254721Semaste} 355254721Semaste 356254721Semastesize_t 357254721SemasteSBProcess::GetSTDOUT (char *dst, size_t dst_len) const 358254721Semaste{ 359254721Semaste size_t bytes_read = 0; 360254721Semaste ProcessSP process_sp(GetSP()); 361254721Semaste if (process_sp) 362254721Semaste { 363254721Semaste Error error; 364254721Semaste bytes_read = process_sp->GetSTDOUT (dst, dst_len, error); 365254721Semaste } 366276479Sdim 367254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 368254721Semaste if (log) 369254721Semaste log->Printf ("SBProcess(%p)::GetSTDOUT (dst=\"%.*s\", dst_len=%" PRIu64 ") => %" PRIu64, 370276479Sdim static_cast<void*>(process_sp.get()), 371276479Sdim static_cast<int>(bytes_read), dst, 372276479Sdim static_cast<uint64_t>(dst_len), 373276479Sdim static_cast<uint64_t>(bytes_read)); 374254721Semaste 375254721Semaste return bytes_read; 376254721Semaste} 377254721Semaste 378254721Semastesize_t 379254721SemasteSBProcess::GetSTDERR (char *dst, size_t dst_len) const 380254721Semaste{ 381254721Semaste size_t bytes_read = 0; 382254721Semaste ProcessSP process_sp(GetSP()); 383254721Semaste if (process_sp) 384254721Semaste { 385254721Semaste Error error; 386254721Semaste bytes_read = process_sp->GetSTDERR (dst, dst_len, error); 387254721Semaste } 388254721Semaste 389254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 390254721Semaste if (log) 391254721Semaste log->Printf ("SBProcess(%p)::GetSTDERR (dst=\"%.*s\", dst_len=%" PRIu64 ") => %" PRIu64, 392276479Sdim static_cast<void*>(process_sp.get()), 393276479Sdim static_cast<int>(bytes_read), dst, 394276479Sdim static_cast<uint64_t>(dst_len), 395276479Sdim static_cast<uint64_t>(bytes_read)); 396254721Semaste 397254721Semaste return bytes_read; 398254721Semaste} 399254721Semaste 400254721Semastesize_t 401254721SemasteSBProcess::GetAsyncProfileData(char *dst, size_t dst_len) const 402254721Semaste{ 403254721Semaste size_t bytes_read = 0; 404254721Semaste ProcessSP process_sp(GetSP()); 405254721Semaste if (process_sp) 406254721Semaste { 407254721Semaste Error error; 408254721Semaste bytes_read = process_sp->GetAsyncProfileData (dst, dst_len, error); 409254721Semaste } 410276479Sdim 411254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 412254721Semaste if (log) 413254721Semaste log->Printf ("SBProcess(%p)::GetProfileData (dst=\"%.*s\", dst_len=%" PRIu64 ") => %" PRIu64, 414276479Sdim static_cast<void*>(process_sp.get()), 415276479Sdim static_cast<int>(bytes_read), dst, 416276479Sdim static_cast<uint64_t>(dst_len), 417276479Sdim static_cast<uint64_t>(bytes_read)); 418276479Sdim 419254721Semaste return bytes_read; 420254721Semaste} 421254721Semaste 422254721Semastevoid 423254721SemasteSBProcess::ReportEventState (const SBEvent &event, FILE *out) const 424254721Semaste{ 425254721Semaste if (out == NULL) 426254721Semaste return; 427254721Semaste 428254721Semaste ProcessSP process_sp(GetSP()); 429254721Semaste if (process_sp) 430254721Semaste { 431254721Semaste const StateType event_state = SBProcess::GetStateFromEvent (event); 432254721Semaste char message[1024]; 433254721Semaste int message_len = ::snprintf (message, 434254721Semaste sizeof (message), 435254721Semaste "Process %" PRIu64 " %s\n", 436254721Semaste process_sp->GetID(), 437254721Semaste SBDebugger::StateAsCString (event_state)); 438254721Semaste 439254721Semaste if (message_len > 0) 440254721Semaste ::fwrite (message, 1, message_len, out); 441254721Semaste } 442254721Semaste} 443254721Semaste 444254721Semastevoid 445254721SemasteSBProcess::AppendEventStateReport (const SBEvent &event, SBCommandReturnObject &result) 446254721Semaste{ 447254721Semaste ProcessSP process_sp(GetSP()); 448254721Semaste if (process_sp) 449254721Semaste { 450254721Semaste const StateType event_state = SBProcess::GetStateFromEvent (event); 451254721Semaste char message[1024]; 452254721Semaste ::snprintf (message, 453254721Semaste sizeof (message), 454254721Semaste "Process %" PRIu64 " %s\n", 455254721Semaste process_sp->GetID(), 456254721Semaste SBDebugger::StateAsCString (event_state)); 457254721Semaste 458254721Semaste result.AppendMessage (message); 459254721Semaste } 460254721Semaste} 461254721Semaste 462254721Semastebool 463254721SemasteSBProcess::SetSelectedThread (const SBThread &thread) 464254721Semaste{ 465254721Semaste ProcessSP process_sp(GetSP()); 466254721Semaste if (process_sp) 467254721Semaste { 468254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 469254721Semaste return process_sp->GetThreadList().SetSelectedThreadByID (thread.GetThreadID()); 470254721Semaste } 471254721Semaste return false; 472254721Semaste} 473254721Semaste 474254721Semastebool 475254721SemasteSBProcess::SetSelectedThreadByID (lldb::tid_t tid) 476254721Semaste{ 477254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 478254721Semaste 479254721Semaste bool ret_val = false; 480254721Semaste ProcessSP process_sp(GetSP()); 481254721Semaste if (process_sp) 482254721Semaste { 483254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 484254721Semaste ret_val = process_sp->GetThreadList().SetSelectedThreadByID (tid); 485254721Semaste } 486254721Semaste 487254721Semaste if (log) 488254721Semaste log->Printf ("SBProcess(%p)::SetSelectedThreadByID (tid=0x%4.4" PRIx64 ") => %s", 489276479Sdim static_cast<void*>(process_sp.get()), tid, 490276479Sdim (ret_val ? "true" : "false")); 491254721Semaste 492254721Semaste return ret_val; 493254721Semaste} 494254721Semaste 495254721Semastebool 496254721SemasteSBProcess::SetSelectedThreadByIndexID (uint32_t index_id) 497254721Semaste{ 498254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 499254721Semaste 500254721Semaste bool ret_val = false; 501254721Semaste ProcessSP process_sp(GetSP()); 502254721Semaste if (process_sp) 503254721Semaste { 504254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 505254721Semaste ret_val = process_sp->GetThreadList().SetSelectedThreadByIndexID (index_id); 506254721Semaste } 507254721Semaste 508254721Semaste if (log) 509276479Sdim log->Printf ("SBProcess(%p)::SetSelectedThreadByID (tid=0x%x) => %s", 510276479Sdim static_cast<void*>(process_sp.get()), index_id, 511276479Sdim (ret_val ? "true" : "false")); 512254721Semaste 513254721Semaste return ret_val; 514254721Semaste} 515254721Semaste 516254721SemasteSBThread 517254721SemasteSBProcess::GetThreadAtIndex (size_t index) 518254721Semaste{ 519254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 520254721Semaste 521254721Semaste SBThread sb_thread; 522254721Semaste ThreadSP thread_sp; 523254721Semaste ProcessSP process_sp(GetSP()); 524254721Semaste if (process_sp) 525254721Semaste { 526254721Semaste Process::StopLocker stop_locker; 527254721Semaste const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); 528254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 529254721Semaste thread_sp = process_sp->GetThreadList().GetThreadAtIndex(index, can_update); 530254721Semaste sb_thread.SetThread (thread_sp); 531254721Semaste } 532254721Semaste 533254721Semaste if (log) 534254721Semaste log->Printf ("SBProcess(%p)::GetThreadAtIndex (index=%d) => SBThread(%p)", 535276479Sdim static_cast<void*>(process_sp.get()), 536276479Sdim static_cast<uint32_t>(index), 537276479Sdim static_cast<void*>(thread_sp.get())); 538254721Semaste 539254721Semaste return sb_thread; 540254721Semaste} 541254721Semaste 542254721Semasteuint32_t 543262528SemasteSBProcess::GetNumQueues () 544262528Semaste{ 545262528Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 546262528Semaste 547262528Semaste uint32_t num_queues = 0; 548262528Semaste ProcessSP process_sp(GetSP()); 549262528Semaste if (process_sp) 550262528Semaste { 551262528Semaste Process::StopLocker stop_locker; 552276479Sdim 553262528Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 554262528Semaste num_queues = process_sp->GetQueueList().GetSize(); 555262528Semaste } 556262528Semaste 557262528Semaste if (log) 558276479Sdim log->Printf ("SBProcess(%p)::GetNumQueues () => %d", 559276479Sdim static_cast<void*>(process_sp.get()), num_queues); 560262528Semaste 561262528Semaste return num_queues; 562262528Semaste} 563262528Semaste 564262528SemasteSBQueue 565262528SemasteSBProcess::GetQueueAtIndex (size_t index) 566262528Semaste{ 567262528Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 568262528Semaste 569262528Semaste SBQueue sb_queue; 570262528Semaste QueueSP queue_sp; 571262528Semaste ProcessSP process_sp(GetSP()); 572262528Semaste if (process_sp) 573262528Semaste { 574262528Semaste Process::StopLocker stop_locker; 575262528Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 576262528Semaste queue_sp = process_sp->GetQueueList().GetQueueAtIndex(index); 577262528Semaste sb_queue.SetQueue (queue_sp); 578262528Semaste } 579262528Semaste 580262528Semaste if (log) 581262528Semaste log->Printf ("SBProcess(%p)::GetQueueAtIndex (index=%d) => SBQueue(%p)", 582276479Sdim static_cast<void*>(process_sp.get()), 583276479Sdim static_cast<uint32_t>(index), 584276479Sdim static_cast<void*>(queue_sp.get())); 585262528Semaste 586262528Semaste return sb_queue; 587262528Semaste} 588262528Semaste 589262528Semaste 590262528Semasteuint32_t 591254721SemasteSBProcess::GetStopID(bool include_expression_stops) 592254721Semaste{ 593254721Semaste ProcessSP process_sp(GetSP()); 594254721Semaste if (process_sp) 595254721Semaste { 596254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 597254721Semaste if (include_expression_stops) 598254721Semaste return process_sp->GetStopID(); 599254721Semaste else 600254721Semaste return process_sp->GetLastNaturalStopID(); 601254721Semaste } 602254721Semaste return 0; 603254721Semaste} 604254721Semaste 605254721SemasteStateType 606254721SemasteSBProcess::GetState () 607254721Semaste{ 608254721Semaste 609254721Semaste StateType ret_val = eStateInvalid; 610254721Semaste ProcessSP process_sp(GetSP()); 611254721Semaste if (process_sp) 612254721Semaste { 613254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 614254721Semaste ret_val = process_sp->GetState(); 615254721Semaste } 616254721Semaste 617254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 618254721Semaste if (log) 619276479Sdim log->Printf ("SBProcess(%p)::GetState () => %s", 620276479Sdim static_cast<void*>(process_sp.get()), 621254721Semaste lldb_private::StateAsCString (ret_val)); 622254721Semaste 623254721Semaste return ret_val; 624254721Semaste} 625254721Semaste 626254721Semaste 627254721Semasteint 628254721SemasteSBProcess::GetExitStatus () 629254721Semaste{ 630254721Semaste int exit_status = 0; 631254721Semaste ProcessSP process_sp(GetSP()); 632254721Semaste if (process_sp) 633254721Semaste { 634254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 635254721Semaste exit_status = process_sp->GetExitStatus (); 636254721Semaste } 637254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 638254721Semaste if (log) 639276479Sdim log->Printf ("SBProcess(%p)::GetExitStatus () => %i (0x%8.8x)", 640276479Sdim static_cast<void*>(process_sp.get()), exit_status, 641276479Sdim exit_status); 642254721Semaste 643254721Semaste return exit_status; 644254721Semaste} 645254721Semaste 646254721Semasteconst char * 647254721SemasteSBProcess::GetExitDescription () 648254721Semaste{ 649254721Semaste const char *exit_desc = NULL; 650254721Semaste ProcessSP process_sp(GetSP()); 651254721Semaste if (process_sp) 652254721Semaste { 653254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 654254721Semaste exit_desc = process_sp->GetExitDescription (); 655254721Semaste } 656254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 657254721Semaste if (log) 658276479Sdim log->Printf ("SBProcess(%p)::GetExitDescription () => %s", 659276479Sdim static_cast<void*>(process_sp.get()), exit_desc); 660254721Semaste return exit_desc; 661254721Semaste} 662254721Semaste 663254721Semastelldb::pid_t 664254721SemasteSBProcess::GetProcessID () 665254721Semaste{ 666254721Semaste lldb::pid_t ret_val = LLDB_INVALID_PROCESS_ID; 667254721Semaste ProcessSP process_sp(GetSP()); 668254721Semaste if (process_sp) 669254721Semaste ret_val = process_sp->GetID(); 670254721Semaste 671254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 672254721Semaste if (log) 673276479Sdim log->Printf ("SBProcess(%p)::GetProcessID () => %" PRIu64, 674276479Sdim static_cast<void*>(process_sp.get()), ret_val); 675254721Semaste 676254721Semaste return ret_val; 677254721Semaste} 678254721Semaste 679254721Semasteuint32_t 680254721SemasteSBProcess::GetUniqueID() 681254721Semaste{ 682254721Semaste uint32_t ret_val = 0; 683254721Semaste ProcessSP process_sp(GetSP()); 684254721Semaste if (process_sp) 685254721Semaste ret_val = process_sp->GetUniqueID(); 686254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 687254721Semaste if (log) 688276479Sdim log->Printf ("SBProcess(%p)::GetUniqueID () => %" PRIu32, 689276479Sdim static_cast<void*>(process_sp.get()), ret_val); 690254721Semaste return ret_val; 691254721Semaste} 692254721Semaste 693254721SemasteByteOrder 694254721SemasteSBProcess::GetByteOrder () const 695254721Semaste{ 696254721Semaste ByteOrder byteOrder = eByteOrderInvalid; 697254721Semaste ProcessSP process_sp(GetSP()); 698254721Semaste if (process_sp) 699254721Semaste byteOrder = process_sp->GetTarget().GetArchitecture().GetByteOrder(); 700276479Sdim 701254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 702254721Semaste if (log) 703276479Sdim log->Printf ("SBProcess(%p)::GetByteOrder () => %d", 704276479Sdim static_cast<void*>(process_sp.get()), byteOrder); 705254721Semaste 706254721Semaste return byteOrder; 707254721Semaste} 708254721Semaste 709254721Semasteuint32_t 710254721SemasteSBProcess::GetAddressByteSize () const 711254721Semaste{ 712254721Semaste uint32_t size = 0; 713254721Semaste ProcessSP process_sp(GetSP()); 714254721Semaste if (process_sp) 715254721Semaste size = process_sp->GetTarget().GetArchitecture().GetAddressByteSize(); 716254721Semaste 717254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 718254721Semaste if (log) 719276479Sdim log->Printf ("SBProcess(%p)::GetAddressByteSize () => %d", 720276479Sdim static_cast<void*>(process_sp.get()), size); 721254721Semaste 722254721Semaste return size; 723254721Semaste} 724254721Semaste 725254721SemasteSBError 726254721SemasteSBProcess::Continue () 727254721Semaste{ 728254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 729276479Sdim 730254721Semaste SBError sb_error; 731254721Semaste ProcessSP process_sp(GetSP()); 732254721Semaste 733254721Semaste if (log) 734276479Sdim log->Printf ("SBProcess(%p)::Continue ()...", 735276479Sdim static_cast<void*>(process_sp.get())); 736254721Semaste 737254721Semaste if (process_sp) 738254721Semaste { 739254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 740276479Sdim 741254721Semaste Error error (process_sp->Resume()); 742254721Semaste if (error.Success()) 743254721Semaste { 744254721Semaste if (process_sp->GetTarget().GetDebugger().GetAsyncExecution () == false) 745254721Semaste { 746254721Semaste if (log) 747276479Sdim log->Printf ("SBProcess(%p)::Continue () waiting for process to stop...", 748276479Sdim static_cast<void*>(process_sp.get())); 749254721Semaste process_sp->WaitForProcessToStop (NULL); 750254721Semaste } 751254721Semaste } 752254721Semaste sb_error.SetError(error); 753254721Semaste } 754254721Semaste else 755254721Semaste sb_error.SetErrorString ("SBProcess is invalid"); 756254721Semaste 757254721Semaste if (log) 758254721Semaste { 759254721Semaste SBStream sstr; 760254721Semaste sb_error.GetDescription (sstr); 761276479Sdim log->Printf ("SBProcess(%p)::Continue () => SBError (%p): %s", 762276479Sdim static_cast<void*>(process_sp.get()), 763276479Sdim static_cast<void*>(sb_error.get()), sstr.GetData()); 764254721Semaste } 765254721Semaste 766254721Semaste return sb_error; 767254721Semaste} 768254721Semaste 769254721Semaste 770254721SemasteSBError 771254721SemasteSBProcess::Destroy () 772254721Semaste{ 773254721Semaste SBError sb_error; 774254721Semaste ProcessSP process_sp(GetSP()); 775254721Semaste if (process_sp) 776254721Semaste { 777254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 778254721Semaste sb_error.SetError(process_sp->Destroy()); 779254721Semaste } 780254721Semaste else 781254721Semaste sb_error.SetErrorString ("SBProcess is invalid"); 782254721Semaste 783254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 784254721Semaste if (log) 785254721Semaste { 786254721Semaste SBStream sstr; 787254721Semaste sb_error.GetDescription (sstr); 788276479Sdim log->Printf ("SBProcess(%p)::Destroy () => SBError (%p): %s", 789276479Sdim static_cast<void*>(process_sp.get()), 790276479Sdim static_cast<void*>(sb_error.get()), sstr.GetData()); 791254721Semaste } 792254721Semaste 793254721Semaste return sb_error; 794254721Semaste} 795254721Semaste 796254721Semaste 797254721SemasteSBError 798254721SemasteSBProcess::Stop () 799254721Semaste{ 800254721Semaste SBError sb_error; 801254721Semaste ProcessSP process_sp(GetSP()); 802254721Semaste if (process_sp) 803254721Semaste { 804254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 805254721Semaste sb_error.SetError (process_sp->Halt()); 806254721Semaste } 807254721Semaste else 808254721Semaste sb_error.SetErrorString ("SBProcess is invalid"); 809276479Sdim 810254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 811254721Semaste if (log) 812254721Semaste { 813254721Semaste SBStream sstr; 814254721Semaste sb_error.GetDescription (sstr); 815276479Sdim log->Printf ("SBProcess(%p)::Stop () => SBError (%p): %s", 816276479Sdim static_cast<void*>(process_sp.get()), 817276479Sdim static_cast<void*>(sb_error.get()), sstr.GetData()); 818254721Semaste } 819254721Semaste 820254721Semaste return sb_error; 821254721Semaste} 822254721Semaste 823254721SemasteSBError 824254721SemasteSBProcess::Kill () 825254721Semaste{ 826254721Semaste SBError sb_error; 827254721Semaste ProcessSP process_sp(GetSP()); 828254721Semaste if (process_sp) 829254721Semaste { 830254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 831254721Semaste sb_error.SetError (process_sp->Destroy()); 832254721Semaste } 833254721Semaste else 834254721Semaste sb_error.SetErrorString ("SBProcess is invalid"); 835254721Semaste 836254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 837254721Semaste if (log) 838254721Semaste { 839254721Semaste SBStream sstr; 840254721Semaste sb_error.GetDescription (sstr); 841276479Sdim log->Printf ("SBProcess(%p)::Kill () => SBError (%p): %s", 842276479Sdim static_cast<void*>(process_sp.get()), 843276479Sdim static_cast<void*>(sb_error.get()), sstr.GetData()); 844254721Semaste } 845254721Semaste 846254721Semaste return sb_error; 847254721Semaste} 848254721Semaste 849254721SemasteSBError 850254721SemasteSBProcess::Detach () 851254721Semaste{ 852254721Semaste // FIXME: This should come from a process default. 853254721Semaste bool keep_stopped = false; 854254721Semaste return Detach (keep_stopped); 855254721Semaste} 856254721Semaste 857254721SemasteSBError 858254721SemasteSBProcess::Detach (bool keep_stopped) 859254721Semaste{ 860254721Semaste SBError sb_error; 861254721Semaste ProcessSP process_sp(GetSP()); 862254721Semaste if (process_sp) 863254721Semaste { 864254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 865254721Semaste sb_error.SetError (process_sp->Detach(keep_stopped)); 866254721Semaste } 867254721Semaste else 868254721Semaste sb_error.SetErrorString ("SBProcess is invalid"); 869254721Semaste 870254721Semaste return sb_error; 871254721Semaste} 872254721Semaste 873254721SemasteSBError 874254721SemasteSBProcess::Signal (int signo) 875254721Semaste{ 876254721Semaste SBError sb_error; 877254721Semaste ProcessSP process_sp(GetSP()); 878254721Semaste if (process_sp) 879254721Semaste { 880254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 881254721Semaste sb_error.SetError (process_sp->Signal (signo)); 882254721Semaste } 883254721Semaste else 884276479Sdim sb_error.SetErrorString ("SBProcess is invalid"); 885254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 886254721Semaste if (log) 887254721Semaste { 888254721Semaste SBStream sstr; 889254721Semaste sb_error.GetDescription (sstr); 890276479Sdim log->Printf ("SBProcess(%p)::Signal (signo=%i) => SBError (%p): %s", 891276479Sdim static_cast<void*>(process_sp.get()), signo, 892276479Sdim static_cast<void*>(sb_error.get()), sstr.GetData()); 893254721Semaste } 894254721Semaste return sb_error; 895254721Semaste} 896254721Semaste 897276479SdimSBUnixSignals 898276479SdimSBProcess::GetUnixSignals() 899276479Sdim{ 900276479Sdim SBUnixSignals sb_unix_signals; 901276479Sdim ProcessSP process_sp(GetSP()); 902276479Sdim if (process_sp) 903276479Sdim { 904276479Sdim sb_unix_signals.SetSP(process_sp); 905276479Sdim } 906276479Sdim 907276479Sdim return sb_unix_signals; 908276479Sdim} 909276479Sdim 910254721Semastevoid 911254721SemasteSBProcess::SendAsyncInterrupt () 912254721Semaste{ 913254721Semaste ProcessSP process_sp(GetSP()); 914254721Semaste if (process_sp) 915254721Semaste { 916254721Semaste process_sp->SendAsyncInterrupt (); 917254721Semaste } 918254721Semaste} 919254721Semaste 920254721SemasteSBThread 921254721SemasteSBProcess::GetThreadByID (tid_t tid) 922254721Semaste{ 923254721Semaste SBThread sb_thread; 924254721Semaste ThreadSP thread_sp; 925254721Semaste ProcessSP process_sp(GetSP()); 926254721Semaste if (process_sp) 927254721Semaste { 928254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 929254721Semaste Process::StopLocker stop_locker; 930254721Semaste const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); 931254721Semaste thread_sp = process_sp->GetThreadList().FindThreadByID (tid, can_update); 932254721Semaste sb_thread.SetThread (thread_sp); 933254721Semaste } 934254721Semaste 935254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 936254721Semaste if (log) 937254721Semaste log->Printf ("SBProcess(%p)::GetThreadByID (tid=0x%4.4" PRIx64 ") => SBThread (%p)", 938276479Sdim static_cast<void*>(process_sp.get()), tid, 939276479Sdim static_cast<void*>(thread_sp.get())); 940254721Semaste 941254721Semaste return sb_thread; 942254721Semaste} 943254721Semaste 944254721SemasteSBThread 945254721SemasteSBProcess::GetThreadByIndexID (uint32_t index_id) 946254721Semaste{ 947254721Semaste SBThread sb_thread; 948254721Semaste ThreadSP thread_sp; 949254721Semaste ProcessSP process_sp(GetSP()); 950254721Semaste if (process_sp) 951254721Semaste { 952254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 953254721Semaste Process::StopLocker stop_locker; 954254721Semaste const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); 955254721Semaste thread_sp = process_sp->GetThreadList().FindThreadByIndexID (index_id, can_update); 956254721Semaste sb_thread.SetThread (thread_sp); 957254721Semaste } 958254721Semaste 959254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 960254721Semaste if (log) 961276479Sdim log->Printf ("SBProcess(%p)::GetThreadByID (tid=0x%x) => SBThread (%p)", 962276479Sdim static_cast<void*>(process_sp.get()), index_id, 963276479Sdim static_cast<void*>(thread_sp.get())); 964254721Semaste 965254721Semaste return sb_thread; 966254721Semaste} 967254721Semaste 968254721SemasteStateType 969254721SemasteSBProcess::GetStateFromEvent (const SBEvent &event) 970254721Semaste{ 971254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 972254721Semaste 973254721Semaste StateType ret_val = Process::ProcessEventData::GetStateFromEvent (event.get()); 974276479Sdim 975254721Semaste if (log) 976276479Sdim log->Printf ("SBProcess::GetStateFromEvent (event.sp=%p) => %s", 977276479Sdim static_cast<void*>(event.get()), 978254721Semaste lldb_private::StateAsCString (ret_val)); 979254721Semaste 980254721Semaste return ret_val; 981254721Semaste} 982254721Semaste 983254721Semastebool 984254721SemasteSBProcess::GetRestartedFromEvent (const SBEvent &event) 985254721Semaste{ 986254721Semaste return Process::ProcessEventData::GetRestartedFromEvent (event.get()); 987254721Semaste} 988254721Semaste 989254721Semastesize_t 990254721SemasteSBProcess::GetNumRestartedReasonsFromEvent (const lldb::SBEvent &event) 991254721Semaste{ 992254721Semaste return Process::ProcessEventData::GetNumRestartedReasons(event.get()); 993254721Semaste} 994254721Semaste 995254721Semasteconst char * 996254721SemasteSBProcess::GetRestartedReasonAtIndexFromEvent (const lldb::SBEvent &event, size_t idx) 997254721Semaste{ 998254721Semaste return Process::ProcessEventData::GetRestartedReasonAtIndex(event.get(), idx); 999254721Semaste} 1000254721Semaste 1001254721SemasteSBProcess 1002254721SemasteSBProcess::GetProcessFromEvent (const SBEvent &event) 1003254721Semaste{ 1004254721Semaste SBProcess process(Process::ProcessEventData::GetProcessFromEvent (event.get())); 1005254721Semaste return process; 1006254721Semaste} 1007254721Semaste 1008254721Semastebool 1009254721SemasteSBProcess::EventIsProcessEvent (const SBEvent &event) 1010254721Semaste{ 1011254721Semaste return strcmp (event.GetBroadcasterClass(), SBProcess::GetBroadcasterClass()) == 0; 1012254721Semaste} 1013254721Semaste 1014254721SemasteSBBroadcaster 1015254721SemasteSBProcess::GetBroadcaster () const 1016254721Semaste{ 1017254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1018254721Semaste 1019254721Semaste ProcessSP process_sp(GetSP()); 1020254721Semaste 1021254721Semaste SBBroadcaster broadcaster(process_sp.get(), false); 1022254721Semaste 1023254721Semaste if (log) 1024276479Sdim log->Printf ("SBProcess(%p)::GetBroadcaster () => SBBroadcaster (%p)", 1025276479Sdim static_cast<void*>(process_sp.get()), 1026276479Sdim static_cast<void*>(broadcaster.get())); 1027254721Semaste 1028254721Semaste return broadcaster; 1029254721Semaste} 1030254721Semaste 1031254721Semasteconst char * 1032254721SemasteSBProcess::GetBroadcasterClass () 1033254721Semaste{ 1034254721Semaste return Process::GetStaticBroadcasterClass().AsCString(); 1035254721Semaste} 1036254721Semaste 1037254721Semastesize_t 1038254721SemasteSBProcess::ReadMemory (addr_t addr, void *dst, size_t dst_len, SBError &sb_error) 1039254721Semaste{ 1040254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1041254721Semaste 1042254721Semaste size_t bytes_read = 0; 1043254721Semaste 1044254721Semaste ProcessSP process_sp(GetSP()); 1045254721Semaste 1046254721Semaste if (log) 1047254721Semaste log->Printf ("SBProcess(%p)::ReadMemory (addr=0x%" PRIx64 ", dst=%p, dst_len=%" PRIu64 ", SBError (%p))...", 1048276479Sdim static_cast<void*>(process_sp.get()), addr, 1049276479Sdim static_cast<void*>(dst), static_cast<uint64_t>(dst_len), 1050276479Sdim static_cast<void*>(sb_error.get())); 1051276479Sdim 1052254721Semaste if (process_sp) 1053254721Semaste { 1054254721Semaste Process::StopLocker stop_locker; 1055254721Semaste if (stop_locker.TryLock(&process_sp->GetRunLock())) 1056254721Semaste { 1057254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 1058254721Semaste bytes_read = process_sp->ReadMemory (addr, dst, dst_len, sb_error.ref()); 1059254721Semaste } 1060254721Semaste else 1061254721Semaste { 1062254721Semaste if (log) 1063276479Sdim log->Printf ("SBProcess(%p)::ReadMemory() => error: process is running", 1064276479Sdim static_cast<void*>(process_sp.get())); 1065254721Semaste sb_error.SetErrorString("process is running"); 1066254721Semaste } 1067254721Semaste } 1068254721Semaste else 1069254721Semaste { 1070254721Semaste sb_error.SetErrorString ("SBProcess is invalid"); 1071254721Semaste } 1072254721Semaste 1073254721Semaste if (log) 1074254721Semaste { 1075254721Semaste SBStream sstr; 1076254721Semaste sb_error.GetDescription (sstr); 1077254721Semaste log->Printf ("SBProcess(%p)::ReadMemory (addr=0x%" PRIx64 ", dst=%p, dst_len=%" PRIu64 ", SBError (%p): %s) => %" PRIu64, 1078276479Sdim static_cast<void*>(process_sp.get()), addr, 1079276479Sdim static_cast<void*>(dst), static_cast<uint64_t>(dst_len), 1080276479Sdim static_cast<void*>(sb_error.get()), sstr.GetData(), 1081276479Sdim static_cast<uint64_t>(bytes_read)); 1082254721Semaste } 1083254721Semaste 1084254721Semaste return bytes_read; 1085254721Semaste} 1086254721Semaste 1087254721Semastesize_t 1088254721SemasteSBProcess::ReadCStringFromMemory (addr_t addr, void *buf, size_t size, lldb::SBError &sb_error) 1089254721Semaste{ 1090254721Semaste size_t bytes_read = 0; 1091254721Semaste ProcessSP process_sp(GetSP()); 1092254721Semaste if (process_sp) 1093254721Semaste { 1094254721Semaste Process::StopLocker stop_locker; 1095254721Semaste if (stop_locker.TryLock(&process_sp->GetRunLock())) 1096254721Semaste { 1097254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 1098254721Semaste bytes_read = process_sp->ReadCStringFromMemory (addr, (char *)buf, size, sb_error.ref()); 1099254721Semaste } 1100254721Semaste else 1101254721Semaste { 1102254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1103254721Semaste if (log) 1104276479Sdim log->Printf ("SBProcess(%p)::ReadCStringFromMemory() => error: process is running", 1105276479Sdim static_cast<void*>(process_sp.get())); 1106254721Semaste sb_error.SetErrorString("process is running"); 1107254721Semaste } 1108254721Semaste } 1109254721Semaste else 1110254721Semaste { 1111254721Semaste sb_error.SetErrorString ("SBProcess is invalid"); 1112254721Semaste } 1113254721Semaste return bytes_read; 1114254721Semaste} 1115254721Semaste 1116254721Semasteuint64_t 1117254721SemasteSBProcess::ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &sb_error) 1118254721Semaste{ 1119254721Semaste uint64_t value = 0; 1120254721Semaste ProcessSP process_sp(GetSP()); 1121254721Semaste if (process_sp) 1122254721Semaste { 1123254721Semaste Process::StopLocker stop_locker; 1124254721Semaste if (stop_locker.TryLock(&process_sp->GetRunLock())) 1125254721Semaste { 1126254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 1127254721Semaste value = process_sp->ReadUnsignedIntegerFromMemory (addr, byte_size, 0, sb_error.ref()); 1128254721Semaste } 1129254721Semaste else 1130254721Semaste { 1131254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1132254721Semaste if (log) 1133276479Sdim log->Printf ("SBProcess(%p)::ReadUnsignedFromMemory() => error: process is running", 1134276479Sdim static_cast<void*>(process_sp.get())); 1135254721Semaste sb_error.SetErrorString("process is running"); 1136254721Semaste } 1137254721Semaste } 1138254721Semaste else 1139254721Semaste { 1140254721Semaste sb_error.SetErrorString ("SBProcess is invalid"); 1141254721Semaste } 1142254721Semaste return value; 1143254721Semaste} 1144254721Semaste 1145254721Semastelldb::addr_t 1146254721SemasteSBProcess::ReadPointerFromMemory (addr_t addr, lldb::SBError &sb_error) 1147254721Semaste{ 1148254721Semaste lldb::addr_t ptr = LLDB_INVALID_ADDRESS; 1149254721Semaste ProcessSP process_sp(GetSP()); 1150254721Semaste if (process_sp) 1151254721Semaste { 1152254721Semaste Process::StopLocker stop_locker; 1153254721Semaste if (stop_locker.TryLock(&process_sp->GetRunLock())) 1154254721Semaste { 1155254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 1156254721Semaste ptr = process_sp->ReadPointerFromMemory (addr, sb_error.ref()); 1157254721Semaste } 1158254721Semaste else 1159254721Semaste { 1160254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1161254721Semaste if (log) 1162276479Sdim log->Printf ("SBProcess(%p)::ReadPointerFromMemory() => error: process is running", 1163276479Sdim static_cast<void*>(process_sp.get())); 1164254721Semaste sb_error.SetErrorString("process is running"); 1165254721Semaste } 1166254721Semaste } 1167254721Semaste else 1168254721Semaste { 1169254721Semaste sb_error.SetErrorString ("SBProcess is invalid"); 1170254721Semaste } 1171254721Semaste return ptr; 1172254721Semaste} 1173254721Semaste 1174254721Semastesize_t 1175254721SemasteSBProcess::WriteMemory (addr_t addr, const void *src, size_t src_len, SBError &sb_error) 1176254721Semaste{ 1177254721Semaste size_t bytes_written = 0; 1178254721Semaste 1179254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1180254721Semaste 1181254721Semaste ProcessSP process_sp(GetSP()); 1182254721Semaste 1183254721Semaste if (log) 1184254721Semaste log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%" PRIx64 ", src=%p, src_len=%" PRIu64 ", SBError (%p))...", 1185276479Sdim static_cast<void*>(process_sp.get()), addr, 1186276479Sdim static_cast<const void*>(src), 1187276479Sdim static_cast<uint64_t>(src_len), 1188276479Sdim static_cast<void*>(sb_error.get())); 1189254721Semaste 1190254721Semaste if (process_sp) 1191254721Semaste { 1192254721Semaste Process::StopLocker stop_locker; 1193254721Semaste if (stop_locker.TryLock(&process_sp->GetRunLock())) 1194254721Semaste { 1195254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 1196254721Semaste bytes_written = process_sp->WriteMemory (addr, src, src_len, sb_error.ref()); 1197254721Semaste } 1198254721Semaste else 1199254721Semaste { 1200254721Semaste if (log) 1201276479Sdim log->Printf ("SBProcess(%p)::WriteMemory() => error: process is running", 1202276479Sdim static_cast<void*>(process_sp.get())); 1203254721Semaste sb_error.SetErrorString("process is running"); 1204254721Semaste } 1205254721Semaste } 1206254721Semaste 1207254721Semaste if (log) 1208254721Semaste { 1209254721Semaste SBStream sstr; 1210254721Semaste sb_error.GetDescription (sstr); 1211254721Semaste log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%" PRIx64 ", src=%p, src_len=%" PRIu64 ", SBError (%p): %s) => %" PRIu64, 1212276479Sdim static_cast<void*>(process_sp.get()), addr, 1213276479Sdim static_cast<const void*>(src), 1214276479Sdim static_cast<uint64_t>(src_len), 1215276479Sdim static_cast<void*>(sb_error.get()), sstr.GetData(), 1216276479Sdim static_cast<uint64_t>(bytes_written)); 1217254721Semaste } 1218254721Semaste 1219254721Semaste return bytes_written; 1220254721Semaste} 1221254721Semaste 1222254721Semastebool 1223254721SemasteSBProcess::GetDescription (SBStream &description) 1224254721Semaste{ 1225254721Semaste Stream &strm = description.ref(); 1226254721Semaste 1227254721Semaste ProcessSP process_sp(GetSP()); 1228254721Semaste if (process_sp) 1229254721Semaste { 1230254721Semaste char path[PATH_MAX]; 1231254721Semaste GetTarget().GetExecutable().GetPath (path, sizeof(path)); 1232254721Semaste Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer(); 1233254721Semaste const char *exe_name = NULL; 1234254721Semaste if (exe_module) 1235254721Semaste exe_name = exe_module->GetFileSpec().GetFilename().AsCString(); 1236254721Semaste 1237254721Semaste strm.Printf ("SBProcess: pid = %" PRIu64 ", state = %s, threads = %d%s%s", 1238254721Semaste process_sp->GetID(), 1239254721Semaste lldb_private::StateAsCString (GetState()), 1240254721Semaste GetNumThreads(), 1241254721Semaste exe_name ? ", executable = " : "", 1242254721Semaste exe_name ? exe_name : ""); 1243254721Semaste } 1244254721Semaste else 1245254721Semaste strm.PutCString ("No value"); 1246254721Semaste 1247254721Semaste return true; 1248254721Semaste} 1249254721Semaste 1250254721Semasteuint32_t 1251254721SemasteSBProcess::GetNumSupportedHardwareWatchpoints (lldb::SBError &sb_error) const 1252254721Semaste{ 1253254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1254254721Semaste 1255254721Semaste uint32_t num = 0; 1256254721Semaste ProcessSP process_sp(GetSP()); 1257254721Semaste if (process_sp) 1258254721Semaste { 1259254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 1260254721Semaste sb_error.SetError(process_sp->GetWatchpointSupportInfo (num)); 1261254721Semaste if (log) 1262254721Semaste log->Printf ("SBProcess(%p)::GetNumSupportedHardwareWatchpoints () => %u", 1263276479Sdim static_cast<void*>(process_sp.get()), num); 1264254721Semaste } 1265254721Semaste else 1266254721Semaste { 1267254721Semaste sb_error.SetErrorString ("SBProcess is invalid"); 1268254721Semaste } 1269254721Semaste return num; 1270254721Semaste} 1271254721Semaste 1272254721Semasteuint32_t 1273254721SemasteSBProcess::LoadImage (lldb::SBFileSpec &sb_image_spec, lldb::SBError &sb_error) 1274254721Semaste{ 1275254721Semaste ProcessSP process_sp(GetSP()); 1276254721Semaste if (process_sp) 1277254721Semaste { 1278254721Semaste Process::StopLocker stop_locker; 1279254721Semaste if (stop_locker.TryLock(&process_sp->GetRunLock())) 1280254721Semaste { 1281254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 1282254721Semaste return process_sp->LoadImage (*sb_image_spec, sb_error.ref()); 1283254721Semaste } 1284254721Semaste else 1285254721Semaste { 1286254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1287254721Semaste if (log) 1288276479Sdim log->Printf ("SBProcess(%p)::LoadImage() => error: process is running", 1289276479Sdim static_cast<void*>(process_sp.get())); 1290254721Semaste sb_error.SetErrorString("process is running"); 1291254721Semaste } 1292254721Semaste } 1293254721Semaste return LLDB_INVALID_IMAGE_TOKEN; 1294254721Semaste} 1295276479Sdim 1296254721Semastelldb::SBError 1297254721SemasteSBProcess::UnloadImage (uint32_t image_token) 1298254721Semaste{ 1299254721Semaste lldb::SBError sb_error; 1300254721Semaste ProcessSP process_sp(GetSP()); 1301254721Semaste if (process_sp) 1302254721Semaste { 1303254721Semaste Process::StopLocker stop_locker; 1304254721Semaste if (stop_locker.TryLock(&process_sp->GetRunLock())) 1305254721Semaste { 1306254721Semaste Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 1307254721Semaste sb_error.SetError (process_sp->UnloadImage (image_token)); 1308254721Semaste } 1309254721Semaste else 1310254721Semaste { 1311254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1312254721Semaste if (log) 1313276479Sdim log->Printf ("SBProcess(%p)::UnloadImage() => error: process is running", 1314276479Sdim static_cast<void*>(process_sp.get())); 1315254721Semaste sb_error.SetErrorString("process is running"); 1316254721Semaste } 1317254721Semaste } 1318254721Semaste else 1319254721Semaste sb_error.SetErrorString("invalid process"); 1320254721Semaste return sb_error; 1321254721Semaste} 1322258054Semaste 1323276479Sdimlldb::SBError 1324276479SdimSBProcess::SendEventData (const char *event_data) 1325276479Sdim{ 1326276479Sdim lldb::SBError sb_error; 1327276479Sdim ProcessSP process_sp(GetSP()); 1328276479Sdim if (process_sp) 1329276479Sdim { 1330276479Sdim Process::StopLocker stop_locker; 1331276479Sdim if (stop_locker.TryLock(&process_sp->GetRunLock())) 1332276479Sdim { 1333276479Sdim Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 1334276479Sdim sb_error.SetError (process_sp->SendEventData (event_data)); 1335276479Sdim } 1336276479Sdim else 1337276479Sdim { 1338276479Sdim Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1339276479Sdim if (log) 1340276479Sdim log->Printf ("SBProcess(%p)::SendEventData() => error: process is running", 1341276479Sdim static_cast<void*>(process_sp.get())); 1342276479Sdim sb_error.SetErrorString("process is running"); 1343276479Sdim } 1344276479Sdim } 1345276479Sdim else 1346276479Sdim sb_error.SetErrorString("invalid process"); 1347276479Sdim return sb_error; 1348276479Sdim} 1349276479Sdim 1350258054Semasteuint32_t 1351258054SemasteSBProcess::GetNumExtendedBacktraceTypes () 1352258054Semaste{ 1353258054Semaste ProcessSP process_sp(GetSP()); 1354258054Semaste if (process_sp && process_sp->GetSystemRuntime()) 1355258054Semaste { 1356258054Semaste SystemRuntime *runtime = process_sp->GetSystemRuntime(); 1357258054Semaste return runtime->GetExtendedBacktraceTypes().size(); 1358258054Semaste } 1359258054Semaste return 0; 1360258054Semaste} 1361258054Semaste 1362258054Semasteconst char * 1363258054SemasteSBProcess::GetExtendedBacktraceTypeAtIndex (uint32_t idx) 1364258054Semaste{ 1365258054Semaste ProcessSP process_sp(GetSP()); 1366258054Semaste if (process_sp && process_sp->GetSystemRuntime()) 1367258054Semaste { 1368258054Semaste SystemRuntime *runtime = process_sp->GetSystemRuntime(); 1369258884Semaste const std::vector<ConstString> &names = runtime->GetExtendedBacktraceTypes(); 1370258054Semaste if (idx < names.size()) 1371258054Semaste { 1372258054Semaste return names[idx].AsCString(); 1373258054Semaste } 1374258054Semaste else 1375258054Semaste { 1376258054Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1377258054Semaste if (log) 1378276479Sdim log->Printf("SBProcess(%p)::GetExtendedBacktraceTypeAtIndex() => error: requested extended backtrace name out of bounds", 1379276479Sdim static_cast<void*>(process_sp.get())); 1380258054Semaste } 1381258054Semaste } 1382258054Semaste return NULL; 1383258054Semaste} 1384