diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2023-07-26 19:03:47 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2023-07-26 19:04:23 +0000 |
| commit | 7fa27ce4a07f19b07799a767fc29416f3b625afb (patch) | |
| tree | 27825c83636c4de341eb09a74f49f5d38a15d165 /lldb/source/Target/TargetList.cpp | |
| parent | e3b557809604d036af6e00c60f012c2025b59a5e (diff) | |
Diffstat (limited to 'lldb/source/Target/TargetList.cpp')
| -rw-r--r-- | lldb/source/Target/TargetList.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/lldb/source/Target/TargetList.cpp b/lldb/source/Target/TargetList.cpp index 8ce2ae8c2898..cb198e388011 100644 --- a/lldb/source/Target/TargetList.cpp +++ b/lldb/source/Target/TargetList.cpp @@ -325,6 +325,7 @@ Status TargetList::CreateTargetInternal(Debugger &debugger, return error; } target_sp.reset(new Target(debugger, arch, platform_sp, is_dummy_target)); + debugger.GetTargetList().RegisterInProcessTarget(target_sp); target_sp->SetExecutableModule(exe_module_sp, load_dependent_files); if (user_exe_path_is_bundle) exe_module_sp->GetFileSpec().GetPath(resolved_bundle_exe_path, @@ -336,6 +337,7 @@ Status TargetList::CreateTargetInternal(Debugger &debugger, // No file was specified, just create an empty target with any arch if a // valid arch was specified target_sp.reset(new Target(debugger, arch, platform_sp, is_dummy_target)); + debugger.GetTargetList().RegisterInProcessTarget(target_sp); } if (!target_sp) @@ -489,7 +491,7 @@ uint32_t TargetList::SignalIfRunning(lldb::pid_t pid, int signo) { return num_signals_sent; } -int TargetList::GetNumTargets() const { +size_t TargetList::GetNumTargets() const { std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex); return m_target_list.size(); } @@ -513,6 +515,7 @@ uint32_t TargetList::GetIndexOfTarget(lldb::TargetSP target_sp) const { void TargetList::AddTargetInternal(TargetSP target_sp, bool do_select) { lldbassert(!llvm::is_contained(m_target_list, target_sp) && "target already exists it the list"); + UnregisterInProcessTarget(target_sp); m_target_list.push_back(std::move(target_sp)); if (do_select) SetSelectedTargetInternal(m_target_list.size() - 1); @@ -540,3 +543,36 @@ lldb::TargetSP TargetList::GetSelectedTarget() { m_selected_target_idx = 0; return GetTargetAtIndex(m_selected_target_idx); } + +bool TargetList::AnyTargetContainsModule(Module &module) { + std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex); + for (const auto &target_sp : m_target_list) { + if (target_sp->GetImages().FindModule(&module)) + return true; + } + for (const auto &target_sp: m_in_process_target_list) { + if (target_sp->GetImages().FindModule(&module)) + return true; + } + return false; +} + + void TargetList::RegisterInProcessTarget(TargetSP target_sp) { + std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex); + [[maybe_unused]] bool was_added; + std::tie(std::ignore, was_added) = + m_in_process_target_list.insert(target_sp); + assert(was_added && "Target pointer was left in the in-process map"); + } + + void TargetList::UnregisterInProcessTarget(TargetSP target_sp) { + std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex); + [[maybe_unused]] bool was_present = + m_in_process_target_list.erase(target_sp); + assert(was_present && "Target pointer being removed was not registered"); + } + + bool TargetList::IsTargetInProcess(TargetSP target_sp) { + std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex); + return m_in_process_target_list.count(target_sp) == 1; + } |
