21 "target group destroyed while it still contains targets");
26 return llvm::createStringError(
27 "cannot add a null target to a target group");
28 if (!target_sp->IsValid())
29 return llvm::createStringError(
30 "cannot add an invalid target to a target group");
34 return llvm::createStringError(
"target group's debugger no longer exists");
35 if (&target_sp->GetDebugger() != debugger_sp.get())
36 return llvm::createStringError(
"target belongs to a different debugger");
38 std::lock_guard<std::recursive_mutex> guard(*
m_mutex);
40 TargetSP member_sp = entry.target_wp.lock();
41 assert(member_sp &&
"target did not remove itself from its target group");
44 if (member_sp != target_sp)
46 if (entry.role == role)
47 return llvm::Error::success();
48 return llvm::createStringError(
49 "target is already in the group with a different role");
53 target_sp->AddTargetGroup(shared_from_this());
54 return llvm::Error::success();
61 std::lock_guard<std::recursive_mutex> guard(*
m_mutex);
63 auto it = std::remove_if(
65 TargetSP member_sp = entry.target_wp.lock();
66 assert(member_sp &&
"target did not remove itself from its "
68 if (member_sp == target_sp) {
74 m_entries.erase(it, m_entries.end());
76 target_sp->RemoveTargetGroup(
this);
80std::optional<TargetGroup::Role>
85 std::lock_guard<std::recursive_mutex> guard(*
m_mutex);
87 TargetSP member_sp = entry.target_wp.lock();
88 assert(member_sp &&
"target did not remove itself from its target group");
89 if (member_sp == target_sp)
96 std::vector<TargetSP> targets;
97 std::lock_guard<std::recursive_mutex> guard(*
m_mutex);
99 TargetSP target_sp = entry.target_wp.lock();
100 assert(target_sp &&
"target did not remove itself from its target group");
102 targets.push_back(std::move(target_sp));
108 std::vector<TargetSP> targets;
109 std::lock_guard<std::recursive_mutex> guard(*
m_mutex);
111 if (entry.role != role)
113 TargetSP target_sp = entry.target_wp.lock();
114 assert(target_sp &&
"target did not remove itself from its target group");
116 targets.push_back(std::move(target_sp));
std::shared_ptr< std::recursive_mutex > m_mutex
bool RemoveTarget(const lldb::TargetSP &target_sp)
Remove target_sp from the group.
std::vector< Entry > m_entries
Targets are weakly held so membership does not extend their lifetime.
Role
Describes the part a target plays in this group.
llvm::Error AddTarget(const lldb::TargetSP &target_sp, Role role)
Add target_sp to the group with role.
std::optional< Role > GetRole(const lldb::TargetSP &target_sp) const
Return the role assigned to target_sp, if it is a member.
std::vector< lldb::TargetSP > GetTargets() const
Return every target in the group.
lldb::DebuggerWP m_debugger_wp
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Debugger > DebuggerSP
std::shared_ptr< lldb_private::Target > TargetSP