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; ProcessSP process_sp(GetSP()); if (log) { log->Printf ("SBProcess(%p)::ReadMemory (addr=0x%llx, dst=%p, dst_len=%zu, SBError (%p))...", process_sp.get(), addr, dst, dst_len, sb_error.get()); } if (process_sp) { Process::StopLocker stop_locker; if (stop_locker.TryLock(&process_sp->GetRunLock())) { Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); bytes_read = process_sp->ReadMemory (addr, dst, dst_len, sb_error.ref()); } else { if (log) log->Printf ("SBProcess(%p)::ReadMemory() => error: process is running", process_sp.get()); sb_error.SetErrorString("process is running"); } } 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) => %zu", process_sp.get(), addr, dst, dst_len, sb_error.get(), sstr.GetData(), bytes_read); } return bytes_read; }
SBThreadPlan SBThreadPlan::QueueThreadPlanForStepInRange(SBAddress &sb_start_address, lldb::addr_t size, SBError &error) { if (m_opaque_sp) { Address *start_address = sb_start_address.get(); if (!start_address) { return SBThreadPlan(); } AddressRange range(*start_address, size); SymbolContext sc; start_address->CalculateSymbolContext(&sc); Status plan_status; SBThreadPlan plan = SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepInRange( false, range, sc, NULL, eAllThreads, plan_status)); if (plan_status.Fail()) error.SetErrorString(plan_status.AsCString()); return plan; } else { return SBThreadPlan(); } }
SBError SBDebugger::RunREPL (lldb::LanguageType language, const char *repl_options) { SBError error; if (m_opaque_sp) error.ref() = m_opaque_sp->RunREPL(language, repl_options); else error.SetErrorString ("invalid debugger"); return error; }
uint64_t SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value) { error.Clear(); if (m_opaque_sp) { if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) { Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); Scalar scalar; if (m_opaque_sp->ResolveValue (scalar)) return scalar.GetRawBits64(fail_value); else error.SetErrorString("could not get value"); } else error.SetErrorString("could not get target"); } error.SetErrorString("invalid SBValue"); return fail_value; }
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)); ProcessSP process_sp(GetSP()); if (log) { log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%llx, src=%p, src_len=%llu, SBError (%p))...", process_sp.get(), addr, src, (uint64_t)src_len, sb_error.get()); } if (process_sp) { Process::StopLocker stop_locker; if (stop_locker.TryLock(&process_sp->GetRunLock())) { Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); bytes_written = process_sp->WriteMemory (addr, src, src_len, sb_error.ref()); } else { if (log) log->Printf ("SBProcess(%p)::WriteMemory() => error: process is running", process_sp.get()); sb_error.SetErrorString("process is running"); } } if (log) { SBStream sstr; sb_error.GetDescription (sstr); log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%llx, src=%p, src_len=%llu, SBError (%p): %s) => %llu", process_sp.get(), addr, src, (uint64_t)src_len, sb_error.get(), sstr.GetData(), (uint64_t)bytes_written); } return bytes_written; }
bool SBValue::SetData (lldb::SBData &data, SBError &error) { Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); ValueLocker locker; lldb::ValueObjectSP value_sp(GetSP(locker)); bool ret = true; if (value_sp) { DataExtractor *data_extractor = data.get(); if (!data_extractor) { if (log) log->Printf ("SBValue(%p)::SetData() => error: no data to set", value_sp.get()); error.SetErrorString("No data to set"); ret = false; } else { Error set_error; value_sp->SetData(*data_extractor, set_error); if (!set_error.Success()) { error.SetErrorStringWithFormat("Couldn't set data: %s", set_error.AsCString()); ret = false; } } } else { error.SetErrorStringWithFormat ("Couldn't set data: could not get SBValue: %s", locker.GetError().AsCString()); ret = false; } if (log) log->Printf ("SBValue(%p)::SetData (%p) => %s", value_sp.get(), data.get(), ret ? "true" : "false"); return ret; }
SBThreadPlan SBThreadPlan::QueueThreadPlanForStepScripted(const char *script_class_name, SBError &error) { if (m_opaque_sp) { Status plan_status; SBThreadPlan plan = SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepScripted( false, script_class_name, false, plan_status)); if (plan_status.Fail()) error.SetErrorString(plan_status.AsCString()); return plan; } else { return SBThreadPlan(); } }
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; }
uint64_t SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value) { error.Clear(); ValueLocker locker; lldb::ValueObjectSP value_sp(GetSP(locker)); if (value_sp) { Scalar scalar; if (value_sp->ResolveValue (scalar)) return scalar.ULongLong(fail_value); else error.SetErrorString("could not resolve value"); } else error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString()); return fail_value; }
SBThreadPlan SBThreadPlan::QueueThreadPlanForRunToAddress(SBAddress sb_address, SBError &error) { if (m_opaque_sp) { Address *address = sb_address.get(); if (!address) return SBThreadPlan(); Status plan_status; SBThreadPlan plan = SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForRunToAddress( false, *address, false, plan_status)); if (plan_status.Fail()) error.SetErrorString(plan_status.AsCString()); return plan; } else { return SBThreadPlan(); } }
SBThreadPlan SBThreadPlan::QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to, bool first_insn, SBError &error) { if (m_opaque_sp) { SymbolContext sc; sc = m_opaque_sp->GetThread().GetStackFrameAtIndex(0)->GetSymbolContext( lldb::eSymbolContextEverything); Status plan_status; SBThreadPlan plan = SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepOut( false, &sc, first_insn, false, eVoteYes, eVoteNoOpinion, frame_idx_to_step_to, plan_status)); if (plan_status.Fail()) error.SetErrorString(plan_status.AsCString()); return plan; } else { return SBThreadPlan(); } }
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; }