LLDB mainline
TargetGroupList.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_TARGET_TARGETGROUPLIST_H
10#define LLDB_TARGET_TARGETGROUPLIST_H
11
13
14#include <memory>
15#include <mutex>
16#include <type_traits>
17#include <utility>
18#include <vector>
19
20namespace lldb_private {
21
22/// A thread-safe collection of target groups. A Debugger uses one as its
23/// registry, and each Target uses one for the groups it belongs to.
25private:
26 friend class Debugger;
27 friend class Target;
28
29 explicit TargetGroupList(Debugger &debugger)
30 : m_debugger(debugger),
31 m_mutex(std::make_shared<std::recursive_mutex>()) {}
32
34 const std::shared_ptr<std::recursive_mutex> &mutex)
35 : m_debugger(debugger), m_mutex(mutex) {}
36
37public:
39
44
45 /// Create and register a target group.
46 lldb::TargetGroupSP CreateTargetGroup(llvm::StringRef description);
47
48 /// Create and register a target group of type GroupT. GroupT is constructed
49 /// with this list, \p description, and \p args. Its constructor may be
50 /// private if it friends TargetGroupList. Runtime-identifiable subclasses
51 /// should use llvm::RTTIExtends<GroupT, TargetGroup>.
52 template <typename GroupT, typename... Args>
53 std::shared_ptr<GroupT> CreateTargetGroup(llvm::StringRef description,
54 Args &&...args) {
55 static_assert(std::is_base_of_v<TargetGroup, GroupT>,
56 "GroupT must derive from TargetGroup");
57 auto group_sp = std::shared_ptr<GroupT>(
58 new GroupT(*this, description, std::forward<Args>(args)...));
59 std::lock_guard<std::recursive_mutex> guard(*m_mutex);
60 m_groups.push_back(group_sp);
61 return group_sp;
62 }
63
64 /// Remove \p group_sp from this list. Other shared references, including
65 /// target membership lists, remain valid.
66 bool DeleteTargetGroup(const lldb::TargetGroupSP &group_sp);
67
68 /// Return a snapshot of the target groups. Modifying the returned vector
69 /// does not modify this list.
70 std::vector<lldb::TargetGroupSP> GetGroups() const;
71
72private:
73 friend class TargetGroup;
74
75 void Add(const lldb::TargetGroupSP &group_sp);
76 void Remove(const TargetGroup *group);
77 void Clear();
78 void RemoveTarget(const lldb::TargetSP &target_sp);
79
81 /// Shared by the debugger's list, each target's list, and every group.
82 /// Group membership operations never acquire Target::m_mutex.
83 std::shared_ptr<std::recursive_mutex> m_mutex;
84 std::vector<lldb::TargetGroupSP> m_groups;
85};
86
87} // namespace lldb_private
88
89#endif // LLDB_TARGET_TARGETGROUPLIST_H
A command line argument class.
Definition Args.h:33
std::shared_ptr< GroupT > CreateTargetGroup(llvm::StringRef description, Args &&...args)
Create and register a target group of type GroupT.
lldb::TargetGroupSP CreateTargetGroup(llvm::StringRef description)
Create and register a target group.
bool DeleteTargetGroup(const lldb::TargetGroupSP &group_sp)
Remove group_sp from this list.
void RemoveTarget(const lldb::TargetSP &target_sp)
void Remove(const TargetGroup *group)
TargetGroupList(Debugger &debugger)
TargetGroupList(TargetGroupList &&)=delete
TargetGroupList & operator=(const TargetGroupList &)=delete
void Add(const lldb::TargetGroupSP &group_sp)
TargetGroupList(const TargetGroupList &)=delete
std::shared_ptr< std::recursive_mutex > m_mutex
Shared by the debugger's list, each target's list, and every group.
TargetGroupList(Debugger &debugger, const std::shared_ptr< std::recursive_mutex > &mutex)
std::vector< lldb::TargetGroupSP > GetGroups() const
Return a snapshot of the target groups.
std::vector< lldb::TargetGroupSP > m_groups
TargetGroupList & operator=(TargetGroupList &&)=delete
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::TargetGroup > TargetGroupSP
std::shared_ptr< lldb_private::Target > TargetSP