24 llvm::StringRef description)
30 "target group destroyed while it still contains targets");
34 return llvm::Error::success();
39 :
Base(group_list, description) {}
46 if (!GetTargets().empty())
47 return llvm::createStringError(
48 "the CPU target must be the first target in the group");
50 case Role::Accelerator:
51 if (GetTargets(Role::CPU).size() != 1)
52 return llvm::createStringError(
53 "the group must contain one CPU target before adding accelerators");
56 return llvm::Error::success();
60 std::vector<TargetSP> cpu_targets = GetTargets(Role::CPU);
61 assert(cpu_targets.size() <= 1 &&
62 "CPU and accelerator group contains multiple CPU targets");
63 return cpu_targets.empty() ? nullptr : cpu_targets.front();
68 return llvm::createStringError(
69 "cannot add a null target to a target group");
70 if (!target_sp->IsValid())
71 return llvm::createStringError(
72 "cannot add an invalid target to a target group");
76 return llvm::createStringError(
"target group's debugger no longer exists");
77 if (&target_sp->GetDebugger() != debugger_sp.get())
78 return llvm::createStringError(
"target belongs to a different debugger");
80 std::lock_guard<std::recursive_mutex> guard(*
m_mutex);
82 TargetSP member_sp = entry.target_wp.lock();
83 assert(member_sp &&
"target did not remove itself from its target group");
86 if (member_sp != target_sp)
88 if (entry.role == role)
89 return llvm::Error::success();
90 return llvm::createStringError(
91 "target is already in the group with a different role");
98 target_sp->AddTargetGroup(shared_from_this());
99 return llvm::Error::success();
106 std::lock_guard<std::recursive_mutex> guard(*
m_mutex);
107 bool removed =
false;
108 auto it = std::remove_if(
110 TargetSP member_sp = entry.target_wp.lock();
111 assert(member_sp &&
"target did not remove itself from its "
113 if (member_sp == target_sp) {
119 m_entries.erase(it, m_entries.end());
121 target_sp->RemoveTargetGroup(
this);
125std::optional<TargetGroup::Role>
130 std::lock_guard<std::recursive_mutex> guard(*
m_mutex);
132 TargetSP member_sp = entry.target_wp.lock();
133 assert(member_sp &&
"target did not remove itself from its target group");
134 if (member_sp == target_sp)
141 std::vector<TargetSP> targets;
142 std::lock_guard<std::recursive_mutex> guard(*
m_mutex);
144 TargetSP target_sp = entry.target_wp.lock();
145 assert(target_sp &&
"target did not remove itself from its target group");
147 targets.push_back(std::move(target_sp));
153 std::vector<TargetSP> targets;
154 std::lock_guard<std::recursive_mutex> guard(*
m_mutex);
156 if (entry.role != role)
158 TargetSP target_sp = entry.target_wp.lock();
159 assert(target_sp &&
"target did not remove itself from its target group");
161 targets.push_back(std::move(target_sp));
static llvm::raw_ostream & error(Stream &strm)
friend class TargetGroupList
lldb::TargetSP GetCPUTarget() const
Return the CPU target, or nullptr if the group has no CPU target.
llvm::Error ValidateTargetAddition(const lldb::TargetSP &target_sp, Role role) const override
TargetGroupCPUAndAccelerators(TargetGroupList &group_list, llvm::StringRef description)
llvm::RTTIExtends< TargetGroupCPUAndAccelerators, TargetGroup > Base
std::shared_ptr< std::recursive_mutex > m_mutex
friend class TargetGroupList
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.
TargetGroup(const TargetGroup &)=delete
Target groups have identity and maintain backlinks in their member targets, so they cannot be copied ...
std::vector< lldb::TargetSP > GetTargets() const
Return every target in the group.
virtual llvm::Error ValidateTargetAddition(const lldb::TargetSP &target_sp, Role role) const
Validate a new membership while the membership lock is held.
lldb::DebuggerWP m_debugger_wp
std::string m_description
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