1 //===-- ThreadSpec.h --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ThreadSpec_h_
11 #define liblldb_ThreadSpec_h_
13 #include "lldb/Utility/StructuredData.h"
14 #include "lldb/lldb-private.h"
17 namespace lldb_private {
19 // Note: For now the thread spec has only fixed elements -
25 // But if we need more generality, we can hang a key/value map off of this
27 // That's why the thread matches spec test is done as a virtual method in
28 // Thread::MatchesSpec,
29 // since it is the native thread that would know how to interpret the keys.
30 // I was going to do the Queue Name this way out of sheer orneriness, but that
32 // sufficiently general concept, so I put it in here on its own.
38 ThreadSpec(const ThreadSpec &rhs);
40 const ThreadSpec &operator=(const ThreadSpec &rhs);
42 static std::unique_ptr<ThreadSpec>
43 CreateFromStructuredData(const StructuredData::Dictionary &data_dict,
46 StructuredData::ObjectSP SerializeToStructuredData();
48 static const char *GetSerializationKey() { return "ThreadSpec"; }
50 void SetIndex(uint32_t index) { m_index = index; }
52 void SetTID(lldb::tid_t tid) { m_tid = tid; }
54 void SetName(llvm::StringRef name) { m_name = name; }
56 void SetQueueName(llvm::StringRef queue_name) { m_queue_name = queue_name; }
58 uint32_t GetIndex() const { return m_index; }
60 lldb::tid_t GetTID() const { return m_tid; }
62 const char *GetName() const;
64 const char *GetQueueName() const;
66 bool TIDMatches(lldb::tid_t thread_id) const {
67 if (m_tid == LLDB_INVALID_THREAD_ID || thread_id == LLDB_INVALID_THREAD_ID)
70 return thread_id == m_tid;
73 bool TIDMatches(Thread &thread) const;
75 bool IndexMatches(uint32_t index) const {
76 if (m_index == UINT32_MAX || index == UINT32_MAX)
79 return index == m_index;
82 bool IndexMatches(Thread &thread) const;
84 bool NameMatches(const char *name) const {
87 else if (name == nullptr)
90 return m_name == name;
93 bool NameMatches(Thread &thread) const;
95 bool QueueNameMatches(const char *queue_name) const {
96 if (m_queue_name.empty())
98 else if (queue_name == nullptr)
101 return m_queue_name == queue_name;
104 bool QueueNameMatches(Thread &thread) const;
106 bool ThreadPassesBasicTests(Thread &thread) const;
108 bool HasSpecification() const;
110 void GetDescription(Stream *s, lldb::DescriptionLevel level) const;
113 enum class OptionNames {
120 static const char *g_option_names[(size_t)OptionNames::LastOptionName];
122 static const char *GetKey(OptionNames enum_value) {
123 return g_option_names[(size_t) enum_value];
129 std::string m_queue_name;
132 } // namespace lldb_private
134 #endif // liblldb_ThreadSpec_h_