size_t SBData::ReadRawData(lldb::SBError &error, lldb::offset_t offset, void *buf, size_t size) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); void *ok = NULL; if (!m_opaque_sp.get()) { error.SetErrorString("no value to read from"); } else { uint32_t old_offset = offset; ok = m_opaque_sp->GetU8(&offset, buf, size); if ((offset == old_offset) || (ok == NULL)) error.SetErrorString("unable to read data"); } if (log) log->Printf("SBData::ReadRawData (error=%p,offset=%" PRIu64 ",buf=%p,size=%" PRIu64 ") => " "(%p)", static_cast<void *>(error.get()), offset, static_cast<void *>(buf), static_cast<uint64_t>(size), static_cast<void *>(ok)); return ok ? size : 0; }
lldb::addr_t SBData::GetAddress (lldb::SBError& error, uint32_t offset) { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); lldb::addr_t value = 0; if (!m_opaque_sp.get()) { error.SetErrorString("no value to read from"); } else { uint32_t old_offset = offset; value = m_opaque_sp->GetAddress(&offset); if (offset == old_offset) error.SetErrorString("unable to read data"); } if (log) log->Printf ("SBData::GetAddress (error=%p,offset=%d) => " "(%p)", error.get(), offset, (void*)value); return value; }
int64_t SBData::GetSignedInt64 (lldb::SBError& error, lldb::offset_t offset) { Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); int64_t value = 0; if (!m_opaque_sp.get()) { error.SetErrorString("no value to read from"); } else { uint32_t old_offset = offset; value = (int64_t)m_opaque_sp->GetMaxS64(&offset, 8); if (offset == old_offset) error.SetErrorString("unable to read data"); } if (log) log->Printf ("SBData::GetSignedInt64 (error=%p,offset=%" PRIu64 ") => " "(%" PRId64 ")", error.get(), offset, value); return value; }
long double SBData::GetLongDouble (lldb::SBError& error, lldb::offset_t offset) { Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); long double value = 0; if (!m_opaque_sp.get()) { error.SetErrorString("no value to read from"); } else { uint32_t old_offset = offset; value = m_opaque_sp->GetLongDouble(&offset); if (offset == old_offset) error.SetErrorString("unable to read data"); } if (log) log->Printf ("SBData::GetLongDouble (error=%p,offset=%" PRIu64 ") => " "(%Lf)", error.get(), offset, value); return value; }
lldb::SBTarget SBDebugger::CreateTarget (const char *filename, const char *target_triple, const char *platform_name, bool add_dependent_modules, lldb::SBError& sb_error) { SBTarget sb_target; TargetSP target_sp; if (m_opaque_sp) { sb_error.Clear(); FileSpec filename_spec (filename, true); OptionGroupPlatform platform_options (false); platform_options.SetPlatformName (platform_name); sb_error.ref() = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, filename_spec, target_triple, add_dependent_modules, &platform_options, target_sp); if (sb_error.Success()) sb_target.SetSP (target_sp); } else { sb_error.SetErrorString("invalid target"); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\", triple=%s, platform_name=%s, add_dependent_modules=%u, error=%s) => SBTarget(%p)", m_opaque_sp.get(), filename, target_triple, platform_name, add_dependent_modules, sb_error.GetCString(), target_sp.get()); } return sb_target; }
lldb::addr_t SBProcess::ReadPointerFromMemory (addr_t addr, lldb::SBError &sb_error) { lldb::addr_t ptr = LLDB_INVALID_ADDRESS; if (m_opaque_sp) { Error error; Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); ptr = m_opaque_sp->ReadPointerFromMemory (addr, error); sb_error.SetError (error); } else { sb_error.SetErrorString ("SBProcess is invalid"); } return ptr; }
uint64_t SBProcess::ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &sb_error) { if (m_opaque_sp) { Error error; Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); uint64_t value = m_opaque_sp->ReadUnsignedIntegerFromMemory (addr, byte_size, 0, error); sb_error.SetError (error); return value; } else { sb_error.SetErrorString ("SBProcess is invalid"); } return 0; }
size_t SBProcess::ReadCStringFromMemory (addr_t addr, void *buf, size_t size, lldb::SBError &sb_error) { size_t bytes_read = 0; if (m_opaque_sp) { Error error; Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); bytes_read = m_opaque_sp->ReadCStringFromMemory (addr, (char *)buf, size, error); sb_error.SetError (error); } else { sb_error.SetErrorString ("SBProcess is invalid"); } return bytes_read; }
uint32_t SBProcess::GetNumSupportedHardwareWatchpoints (lldb::SBError &sb_error) const { Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); uint32_t num = 0; ProcessSP process_sp(GetSP()); if (process_sp) { Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); sb_error.SetError(process_sp->GetWatchpointSupportInfo (num)); if (log) log->Printf ("SBProcess(%p)::GetNumSupportedHardwareWatchpoints () => %u", static_cast<void*>(process_sp.get()), num); } else { sb_error.SetErrorString ("SBProcess is invalid"); } return num; }
uint32_t SBProcess::LoadImage (lldb::SBFileSpec &sb_image_spec, lldb::SBError &sb_error) { ProcessSP process_sp(GetSP()); if (process_sp) { Process::StopLocker stop_locker; if (stop_locker.TryLock(&process_sp->GetRunLock())) { Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); return process_sp->LoadImage (*sb_image_spec, sb_error.ref()); } else { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBProcess(%p)::LoadImage() => error: process is running", process_sp.get()); sb_error.SetErrorString("process is running"); } } return LLDB_INVALID_IMAGE_TOKEN; }
bool SBProcess::RemoteLaunch (char const **argv, char const **envp, const char *stdin_path, const char *stdout_path, const char *stderr_path, const char *working_directory, uint32_t launch_flags, bool stop_at_entry, lldb::SBError& error) { Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) 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))...", static_cast<void*>(m_opaque_wp.lock().get()), static_cast<void*>(argv), static_cast<void*>(envp), stdin_path ? stdin_path : "NULL", stdout_path ? stdout_path : "NULL", stderr_path ? stderr_path : "NULL", working_directory ? working_directory : "NULL", launch_flags, stop_at_entry, static_cast<void*>(error.get())); ProcessSP process_sp(GetSP()); if (process_sp) { Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); if (process_sp->GetState() == eStateConnected) { if (stop_at_entry) launch_flags |= eLaunchFlagStopAtEntry; ProcessLaunchInfo launch_info(FileSpec{stdin_path, false}, FileSpec{stdout_path, false}, FileSpec{stderr_path, false}, FileSpec{working_directory, false}, launch_flags); Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer(); if (exe_module) launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true); if (argv) launch_info.GetArguments().AppendArguments (argv); if (envp) launch_info.GetEnvironmentEntries ().SetArguments (envp); error.SetError (process_sp->Launch (launch_info)); } else { error.SetErrorString ("must be in eStateConnected to call RemoteLaunch"); } } else { error.SetErrorString ("unable to attach pid"); } if (log) { SBStream sstr; error.GetDescription (sstr); log->Printf ("SBProcess(%p)::RemoteLaunch (...) => SBError (%p): %s", static_cast<void*>(process_sp.get()), static_cast<void*>(error.get()), sstr.GetData()); } return error.Success(); }