size_t SBProcess::ReadMemory (addr_t addr, void *dst, size_t dst_len, SBError &sb_error) { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); size_t bytes_read = 0; if (log) { log->Printf ("SBProcess(%p)::ReadMemory (addr=0x%llx, dst=%p, dst_len=%zu, SBError (%p))...", m_opaque_sp.get(), addr, dst, (uint32_t) dst_len, sb_error.get()); } if (m_opaque_sp) { Error error; Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); bytes_read = m_opaque_sp->ReadMemory (addr, dst, dst_len, error); sb_error.SetError (error); } else { sb_error.SetErrorString ("SBProcess is invalid"); } if (log) { SBStream sstr; sb_error.GetDescription (sstr); log->Printf ("SBProcess(%p)::ReadMemory (addr=0x%llx, dst=%p, dst_len=%zu, SBError (%p): %s) => %d", m_opaque_sp.get(), addr, dst, (uint32_t) dst_len, sb_error.get(), sstr.GetData(), (uint32_t) bytes_read); } return bytes_read; }
size_t SBProcess::WriteMemory (addr_t addr, const void *src, size_t src_len, SBError &sb_error) { size_t bytes_written = 0; LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%llx, src=%p, dst_len=%zu, SBError (%p))...", m_opaque_sp.get(), addr, src, (uint32_t) src_len, sb_error.get()); } if (m_opaque_sp) { Error error; Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); bytes_written = m_opaque_sp->WriteMemory (addr, src, src_len, error); sb_error.SetError (error); } if (log) { SBStream sstr; sb_error.GetDescription (sstr); log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%llx, src=%p, dst_len=%zu, SBError (%p): %s) => %d", m_opaque_sp.get(), addr, src, (uint32_t) src_len, sb_error.get(), sstr.GetData(), (uint32_t) bytes_written); } return bytes_written; }
lldb::SBWatchpoint SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error) { SBWatchpoint sb_watchpoint; // If the SBValue is not valid, there's no point in even trying to watch it. ValueLocker locker; lldb::ValueObjectSP value_sp(GetSP(locker)); TargetSP target_sp (GetTarget().GetSP()); if (value_sp && target_sp) { // Read and Write cannot both be false. if (!read && !write) return sb_watchpoint; // If the value is not in scope, don't try and watch and invalid value if (!IsInScope()) return sb_watchpoint; addr_t addr = GetLoadAddress(); if (addr == LLDB_INVALID_ADDRESS) return sb_watchpoint; size_t byte_size = GetByteSize(); if (byte_size == 0) return sb_watchpoint; uint32_t watch_type = 0; if (read) watch_type |= LLDB_WATCH_TYPE_READ; if (write) watch_type |= LLDB_WATCH_TYPE_WRITE; Error rc; ClangASTType type (value_sp->GetClangType()); WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc); error.SetError(rc); if (watchpoint_sp) { sb_watchpoint.SetSP (watchpoint_sp); Declaration decl; if (value_sp->GetDeclaration (decl)) { if (decl.GetFile()) { StreamString ss; // True to show fullpath for declaration file. decl.DumpStopContext(&ss, true); watchpoint_sp->SetDeclInfo(ss.GetString()); } } } } else if (target_sp) { Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBValue(%p)::Watch() => error getting SBValue: %s", value_sp.get(), locker.GetError().AsCString()); error.SetErrorStringWithFormat("could not get SBValue: %s", locker.GetError().AsCString()); } else { Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBValue(%p)::Watch() => error getting SBValue: no target", value_sp.get()); error.SetErrorString("could not set watchpoint, a target is required"); } return sb_watchpoint; }