bool SBBreakpoint::GetDescription (SBStream &s) { if (m_opaque_sp) { Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); s.Printf("SBBreakpoint: id = %i, ", m_opaque_sp->GetID()); m_opaque_sp->GetResolverDescription (s.get()); m_opaque_sp->GetFilterDescription (s.get()); const size_t num_locations = m_opaque_sp->GetNumLocations (); s.Printf(", locations = %" PRIu64, (uint64_t)num_locations); return true; } s.Printf ("No value"); return false; }
bool SBProcess::GetDescription (SBStream &description) { Stream &strm = description.ref(); ProcessSP process_sp(GetSP()); if (process_sp) { char path[PATH_MAX]; GetTarget().GetExecutable().GetPath (path, sizeof(path)); Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer(); const char *exe_name = NULL; if (exe_module) exe_name = exe_module->GetFileSpec().GetFilename().AsCString(); strm.Printf ("SBProcess: pid = %" PRIu64 ", state = %s, threads = %d%s%s", process_sp->GetID(), lldb_private::StateAsCString (GetState()), GetNumThreads(), exe_name ? ", executable = " : "", exe_name ? exe_name : ""); } else strm.PutCString ("No value"); return true; }
bool SBProcess::RemoteAttachToProcessWithID (lldb::pid_t pid, lldb::SBError& error) { ProcessSP process_sp(GetSP()); if (process_sp) { Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); if (process_sp->GetState() == eStateConnected) { ProcessAttachInfo attach_info; attach_info.SetProcessID (pid); error.SetError (process_sp->Attach (attach_info)); } else { error.SetErrorString ("must be in eStateConnected to call RemoteAttachToProcessWithID"); } } else { error.SetErrorString ("unable to attach pid"); } Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { SBStream sstr; error.GetDescription (sstr); log->Printf ("SBProcess(%p)::RemoteAttachToProcessWithID (%" PRIu64 ") => SBError (%p): %s", process_sp.get(), pid, error.get(), sstr.GetData()); } return error.Success(); }
bool SBFunction::GetDescription (SBStream &s) { if (m_opaque_ptr) { s.Printf ("SBFunction: id = 0x%8.8x, name = %s", m_opaque_ptr->GetID(), m_opaque_ptr->GetName().AsCString()); Type *func_type = m_opaque_ptr->GetType(); if (func_type) s.Printf(", type = %s", func_type->GetName().AsCString()); return true; } s.Printf ("No value"); return false; }
bool SBBreakpointName::GetDescription(SBStream &s) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); BreakpointName *bp_name = GetBreakpointName(); if (!bp_name) { s.Printf("No value"); return false; } LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); std::lock_guard<std::recursive_mutex> guard( m_impl_up->GetTarget()->GetAPIMutex()); bp_name->GetDescription(s.get(), eDescriptionLevelFull); return true; }
SBDebugger SBDebugger::Create(bool source_init_files, lldb::LogOutputCallback callback, void *baton) { LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBDebugger debugger; debugger.reset(Debugger::CreateInstance(callback, baton)); if (log) { SBStream sstr; debugger.GetDescription (sstr); log->Printf ("SBDebugger::Create () => SBDebugger(%p): %s", debugger.m_opaque_sp.get(), sstr.GetData()); } SBCommandInterpreter interp = debugger.GetCommandInterpreter(); if (source_init_files) { interp.get()->SkipLLDBInitFiles(false); interp.get()->SkipAppInitFiles (false); SBCommandReturnObject result; interp.SourceInitFileInHomeDirectory(result); } else { interp.get()->SkipLLDBInitFiles(true); interp.get()->SkipAppInitFiles (true); } return debugger; }
size_t SBProcess::WriteMemory (addr_t addr, const void *src, size_t src_len, SBError &sb_error) { size_t bytes_written = 0; Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); ProcessSP process_sp(GetSP()); if (log) log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%" PRIx64 ", src=%p, src_len=%" PRIu64 ", SBError (%p))...", static_cast<void*>(process_sp.get()), addr, static_cast<const void*>(src), static_cast<uint64_t>(src_len), static_cast<void*>(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", static_cast<void*>(process_sp.get())); sb_error.SetErrorString("process is running"); } } if (log) { SBStream sstr; sb_error.GetDescription (sstr); log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%" PRIx64 ", src=%p, src_len=%" PRIu64 ", SBError (%p): %s) => %" PRIu64, static_cast<void*>(process_sp.get()), addr, static_cast<const void*>(src), static_cast<uint64_t>(src_len), static_cast<void*>(sb_error.get()), sstr.GetData(), static_cast<uint64_t>(bytes_written)); } return bytes_written; }
void SBDebugger::SetSelectedTarget (SBTarget &sb_target) { LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (m_opaque_sp) { m_opaque_sp->GetTargetList().SetSelectedTarget (sb_target.get()); } if (log) { SBStream sstr; sb_target.GetDescription (sstr, eDescriptionLevelBrief); log->Printf ("SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s", m_opaque_sp.get(), sb_target.get(), sstr.GetData()); } }
lldb::ReturnStatus SBCommandInterpreter::HandleCommand (const char *command_line, SBExecutionContext &override_context, SBCommandReturnObject &result, bool add_to_history) { Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBCommandInterpreter(%p)::HandleCommand (command=\"%s\", SBCommandReturnObject(%p), add_to_history=%i)", static_cast<void*>(m_opaque_ptr), command_line, static_cast<void*>(result.get()), add_to_history); ExecutionContext ctx, *ctx_ptr; if (override_context.get()) { ctx = override_context.get()->Lock(true); ctx_ptr = &ctx; } else ctx_ptr = nullptr; result.Clear(); if (command_line && IsValid()) { result.ref().SetInteractive(false); m_opaque_ptr->HandleCommand (command_line, add_to_history ? eLazyBoolYes : eLazyBoolNo, result.ref(), ctx_ptr); } else { result->AppendError ("SBCommandInterpreter or the command line is not valid"); result->SetStatus (eReturnStatusFailed); } // We need to get the value again, in case the command disabled the log! log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); if (log) { SBStream sstr; result.GetDescription (sstr); log->Printf ("SBCommandInterpreter(%p)::HandleCommand (command=\"%s\", SBCommandReturnObject(%p): %s, add_to_history=%i) => %i", static_cast<void*>(m_opaque_ptr), command_line, static_cast<void*>(result.get()), sstr.GetData(), add_to_history, result.GetStatus()); } return result.GetStatus(); }
SBFileSpec SBLineEntry::GetFileSpec() const { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); SBFileSpec sb_file_spec; if (m_opaque_ap.get() && m_opaque_ap->file) sb_file_spec.SetFileSpec(m_opaque_ap->file); if (log) { SBStream sstr; sb_file_spec.GetDescription(sstr); log->Printf("SBLineEntry(%p)::GetFileSpec () => SBFileSpec(%p): %s", static_cast<void *>(m_opaque_ap.get()), static_cast<const void *>(sb_file_spec.get()), sstr.GetData()); } return sb_file_spec; }
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; }
bool SBMemoryRegionInfoList::GetMemoryRegionAtIndex( uint32_t idx, SBMemoryRegionInfo ®ion_info) { Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); bool result = m_opaque_ap->GetMemoryRegionInfoAtIndex(idx, region_info); if (log) { SBStream sstr; region_info.GetDescription(sstr); log->Printf("SBMemoryRegionInfoList::GetMemoryRegionAtIndex (this.ap=%p, " "idx=%d) => SBMemoryRegionInfo (this.ap=%p, '%s')", static_cast<void *>(m_opaque_ap.get()), idx, static_cast<void *>(region_info.m_opaque_ap.get()), sstr.GetData()); } return result; }
bool SBFileSpec::GetDescription (SBStream &description) const { Stream &strm = description.ref(); char path[PATH_MAX]; if (m_opaque_ap->GetPath(path, sizeof(path))) strm.PutCString (path); return true; }
bool SBError::GetDescription (SBStream &description) { if (m_opaque_ap.get()) { if (m_opaque_ap->Success()) description.Printf ("success"); else { const char * err_string = GetCString(); description.Printf ("error: %s", (err_string != NULL ? err_string : "")); } } else description.Printf ("error: <NULL>"); return true; }
void SBCommandInterpreter::HandleCommandsFromFile (lldb::SBFileSpec &file, lldb::SBExecutionContext &override_context, lldb::SBCommandInterpreterRunOptions &options, lldb::SBCommandReturnObject result) { Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { SBStream s; file.GetDescription (s); log->Printf ("SBCommandInterpreter(%p)::HandleCommandsFromFile (file=\"%s\", SBCommandReturnObject(%p))", static_cast<void*>(m_opaque_ptr), s.GetData(), static_cast<void*>(result.get())); } if (!IsValid()) { result->AppendError ("SBCommandInterpreter is not valid."); result->SetStatus (eReturnStatusFailed); return; } if (!file.IsValid()) { SBStream s; file.GetDescription (s); result->AppendErrorWithFormat ("File is not valid: %s.", s.GetData()); result->SetStatus (eReturnStatusFailed); } FileSpec tmp_spec = file.ref(); ExecutionContext ctx, *ctx_ptr; if (override_context.get()) { ctx = override_context.get()->Lock(true); ctx_ptr = &ctx; } else ctx_ptr = nullptr; m_opaque_ptr->HandleCommandsFromFile (tmp_spec, ctx_ptr, options.ref(), result.ref()); }
void SBDebugger::Destroy (SBDebugger &debugger) { Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { SBStream sstr; debugger.GetDescription (sstr); log->Printf ("SBDebugger::Destroy () => SBDebugger(%p): %s", static_cast<void*>(debugger.m_opaque_sp.get()), sstr.GetData()); } Debugger::Destroy (debugger.m_opaque_sp); if (debugger.m_opaque_sp.get() != NULL) debugger.m_opaque_sp.reset(); }
bool SBCompileUnit::GetDescription(SBStream &description) { Stream &strm = description.ref(); if (m_opaque_ptr) { m_opaque_ptr->Dump(&strm, false); } else strm.PutCString("No value"); return true; }
SBModule SBSymbolContext::GetModule () { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBModule sb_module; if (m_opaque_ap.get()) sb_module.SetModule(m_opaque_ap->module_sp); if (log) { SBStream sstr; sb_module.GetDescription (sstr); log->Printf ("SBSymbolContext(%p)::GetModule () => SBModule(%p): %s", m_opaque_ap.get(), sb_module.get(), sstr.GetData()); } return sb_module; }
bool SBSymbolContext::GetDescription(SBStream &description) { Stream &strm = description.ref(); if (m_opaque_ap.get()) { m_opaque_ap->GetDescription(&strm, lldb::eDescriptionLevelFull, NULL); } else strm.PutCString("No value"); return true; }
bool SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes) { if (m_opaque_sp) { m_opaque_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes); return true; } return false; }
bool SBValue::GetExpressionPath (SBStream &description) { if (m_opaque_sp) { m_opaque_sp->GetExpressionPath (description.ref(), false); return true; } return false; }
SBDebugger SBDebugger::Create(bool source_init_files, lldb::LogOutputCallback callback, void *baton) { Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBDebugger debugger; // Currently we have issues if this function is called simultaneously on two different // threads. The issues mainly revolve around the fact that the lldb_private::FormatManager // uses global collections and having two threads parsing the .lldbinit files can cause // mayhem. So to get around this for now we need to use a mutex to prevent bad things // from happening. static Mutex g_mutex(Mutex::eMutexTypeRecursive); Mutex::Locker locker(g_mutex); debugger.reset(Debugger::CreateInstance(callback, baton)); if (log) { SBStream sstr; debugger.GetDescription (sstr); log->Printf ("SBDebugger::Create () => SBDebugger(%p): %s", static_cast<void*>(debugger.m_opaque_sp.get()), sstr.GetData()); } SBCommandInterpreter interp = debugger.GetCommandInterpreter(); if (source_init_files) { interp.get()->SkipLLDBInitFiles(false); interp.get()->SkipAppInitFiles (false); SBCommandReturnObject result; interp.SourceInitFileInHomeDirectory(result); } else { interp.get()->SkipLLDBInitFiles(true); interp.get()->SkipAppInitFiles (true); } return debugger; }
bool SBModule::GetDescription(SBStream &description) { Stream &strm = description.ref(); ModuleSP module_sp(GetSP()); if (module_sp) { module_sp->GetDescription(&strm); } else strm.PutCString("No value"); return true; }
SBModule SBSymbolContext::GetModule() { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); SBModule sb_module; ModuleSP module_sp; if (m_opaque_ap.get()) { module_sp = m_opaque_ap->module_sp; sb_module.SetSP(module_sp); } if (log) { SBStream sstr; sb_module.GetDescription(sstr); log->Printf("SBSymbolContext(%p)::GetModule () => SBModule(%p): %s", static_cast<void *>(m_opaque_ap.get()), static_cast<void *>(module_sp.get()), sstr.GetData()); } return sb_module; }
bool SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes) { ValueLocker locker; lldb::ValueObjectSP value_sp(GetSP(locker)); if (value_sp) { value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes); return true; } return false; }
bool SBValue::GetExpressionPath (SBStream &description) { ValueLocker locker; lldb::ValueObjectSP value_sp(GetSP(locker)); if (value_sp) { value_sp->GetExpressionPath (description.ref(), false); return true; } return false; }
SBThread SBFrame::GetThread () const { LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); ExecutionContext exe_ctx(m_opaque_sp.get()); ThreadSP thread_sp (exe_ctx.GetThreadSP()); SBThread sb_thread (thread_sp); if (log) { SBStream sstr; sb_thread.GetDescription (sstr); log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s", exe_ctx.GetFramePtr(), thread_sp.get(), sstr.GetData()); } return sb_thread; }
SBFileSpec SBCompileUnit::GetSupportFileAtIndex(uint32_t idx) const { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); SBFileSpec sb_file_spec; if (m_opaque_ptr) { FileSpecList &support_files = m_opaque_ptr->GetSupportFiles(); FileSpec file_spec = support_files.GetFileSpecAtIndex(idx); sb_file_spec.SetFileSpec(file_spec); } if (log) { SBStream sstr; sb_file_spec.GetDescription(sstr); log->Printf("SBCompileUnit(%p)::GetGetFileSpecAtIndex (idx=%u) => " "SBFileSpec(%p): '%s'", static_cast<void *>(m_opaque_ptr), idx, static_cast<const void *>(sb_file_spec.get()), sstr.GetData()); } return sb_file_spec; }
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; }
SBThread SBFrame::GetThread () const { LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBThread sb_thread; if (m_opaque_sp) { Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); sb_thread.SetThread (m_opaque_sp->GetThread().GetSP()); } if (log) { SBStream sstr; sb_thread.GetDescription (sstr); log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s", m_opaque_sp.get(), sb_thread.get(), sstr.GetData()); } return sb_thread; }