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_
17 // Other libraries and framework includes
19 #include "lldb/lldb-private.h"
21 namespace lldb_private {
23 // Note: For now the thread spec has only fixed elements -
29 // But if we need more generality, we can hang a key/value map off of this
31 // That's why the thread matches spec test is done as a virtual method in
32 // Thread::MatchesSpec,
33 // since it is the native thread that would know how to interpret the keys.
34 // I was going to do the Queue Name this way out of sheer orneriness, but that
36 // sufficiently general concept, so I put it in here on its own.
42 ThreadSpec(const ThreadSpec &rhs);
44 const ThreadSpec &operator=(const ThreadSpec &rhs);
46 static std::unique_ptr<ThreadSpec>
47 CreateFromStructuredData(const StructuredData::Dictionary &data_dict,
50 StructuredData::ObjectSP SerializeToStructuredData();
52 static const char *GetSerializationKey() { return "ThreadSpec"; }
54 void SetIndex(uint32_t index) { m_index = index; }
56 void SetTID(lldb::tid_t tid) { m_tid = tid; }
58 void SetName(const char *name) { m_name = name; }
60 void SetQueueName(const char *queue_name) { m_queue_name = queue_name; }
62 uint32_t GetIndex() const { return m_index; }
64 lldb::tid_t GetTID() const { return m_tid; }
66 const char *GetName() const;
68 const char *GetQueueName() const;
70 bool TIDMatches(lldb::tid_t thread_id) const {
71 if (m_tid == LLDB_INVALID_THREAD_ID || thread_id == LLDB_INVALID_THREAD_ID)
74 return thread_id == m_tid;
77 bool TIDMatches(Thread &thread) const;
79 bool IndexMatches(uint32_t index) const {
80 if (m_index == UINT32_MAX || index == UINT32_MAX)
83 return index == m_index;
86 bool IndexMatches(Thread &thread) const;
88 bool NameMatches(const char *name) const {
91 else if (name == nullptr)
94 return m_name == name;
97 bool NameMatches(Thread &thread) const;
99 bool QueueNameMatches(const char *queue_name) const {
100 if (m_queue_name.empty())
102 else if (queue_name == nullptr)
105 return m_queue_name == queue_name;
108 bool QueueNameMatches(Thread &thread) const;
110 bool ThreadPassesBasicTests(Thread &thread) const;
112 bool HasSpecification() const;
114 void GetDescription(Stream *s, lldb::DescriptionLevel level) const;
117 enum class OptionNames {
124 static const char *g_option_names[(size_t)OptionNames::LastOptionName];
126 static const char *GetKey(OptionNames enum_value) {
127 return g_option_names[(size_t) enum_value];
133 std::string m_queue_name;
136 } // namespace lldb_private
138 #endif // liblldb_ThreadSpec_h_