LLDB mainline
TargetGroup.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_TARGETGROUP_H
10#define LLDB_TARGET_TARGETGROUP_H
11
12#include "lldb/lldb-forward.h"
13#include "llvm/ADT/StringRef.h"
14#include "llvm/Support/Error.h"
15
16#include <memory>
17#include <mutex>
18#include <optional>
19#include <string>
20#include <utility>
21#include <vector>
22
23namespace lldb_private {
24
25/// A group of related targets and the roles they play in that relationship.
26///
27/// Target::Destroy() automatically removes a target from all its groups;
28/// clients do not need to remove memberships during target destruction.
29class TargetGroup : public std::enable_shared_from_this<TargetGroup> {
30public:
31 /// Describes the part a target plays in this group.
32 enum class Role {
35 };
36
37 /// Target groups have identity and maintain backlinks in their member
38 /// targets, so they cannot be copied or moved. Create one with
39 /// Debugger::GetTargetGroupList().CreateTargetGroup().
40 TargetGroup(const TargetGroup &) = delete;
41 TargetGroup &operator=(const TargetGroup &) = delete;
45
46 llvm::StringRef GetDescription() const { return m_description; }
47
48 /// Add \p target_sp to the group with \p role. Adding an existing member
49 /// succeeds only when its role matches \p role.
50 llvm::Error AddTarget(const lldb::TargetSP &target_sp, Role role);
51
52 /// Remove \p target_sp from the group.
53 bool RemoveTarget(const lldb::TargetSP &target_sp);
54
55 /// Return the role assigned to \p target_sp, if it is a member.
56 std::optional<Role> GetRole(const lldb::TargetSP &target_sp) const;
57
58 /// Return every target in the group.
59 std::vector<lldb::TargetSP> GetTargets() const;
60
61 /// Return targets whose role is \p role.
62 std::vector<lldb::TargetSP> GetTargets(Role role) const;
63
64private:
65 friend class TargetGroupList;
66
71
72 TargetGroup(const lldb::DebuggerSP &debugger_sp, llvm::StringRef description,
73 std::shared_ptr<std::recursive_mutex> mutex)
74 : m_debugger_wp(debugger_sp), m_description(description),
75 m_mutex(std::move(mutex)) {}
76
78 std::string m_description;
79 std::shared_ptr<std::recursive_mutex> m_mutex;
80 /// Targets are weakly held so membership does not extend their lifetime.
81 std::vector<Entry> m_entries;
82};
83
84} // namespace lldb_private
85
86#endif // LLDB_TARGET_TARGETGROUP_H
std::shared_ptr< std::recursive_mutex > m_mutex
Definition TargetGroup.h:79
llvm::StringRef GetDescription() const
Definition TargetGroup.h:46
friend class TargetGroupList
Definition TargetGroup.h:65
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.
Definition TargetGroup.h:81
TargetGroup & operator=(const TargetGroup &)=delete
Role
Describes the part a target plays in this group.
Definition TargetGroup.h:32
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.
lldb::DebuggerWP m_debugger_wp
Definition TargetGroup.h:77
TargetGroup(TargetGroup &&)=delete
TargetGroup & operator=(TargetGroup &&)=delete
TargetGroup(const lldb::DebuggerSP &debugger_sp, llvm::StringRef description, std::shared_ptr< std::recursive_mutex > mutex)
Definition TargetGroup.h:72
A class that represents a running process on the host machine.
std::weak_ptr< lldb_private::Debugger > DebuggerWP
std::shared_ptr< lldb_private::Debugger > DebuggerSP
std::weak_ptr< lldb_private::Target > TargetWP
std::shared_ptr< lldb_private::Target > TargetSP