]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/lldb/Target/ThreadSpec.h
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / include / lldb / Target / ThreadSpec.h
1 //===-- ThreadSpec.h --------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_ThreadSpec_h_
11 #define liblldb_ThreadSpec_h_
12
13 // C Includes
14 // C++ Includes
15 #include <string>
16
17 // Other libraries and framework includes
18 // Project includes
19 #include "lldb/lldb-private.h"
20
21 namespace lldb_private {
22
23 // Note: For now the thread spec has only fixed elements -
24 //   Thread ID
25 //   Thread Index
26 //   Thread Name
27 //   Thread Queue Name
28 //
29 //  But if we need more generality, we can hang a key/value map off of this
30 //  structure.
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
35 //  seems a
36 //  sufficiently general concept, so I put it in here on its own.
37
38 class ThreadSpec {
39 public:
40   ThreadSpec();
41
42   ThreadSpec(const ThreadSpec &rhs);
43
44   const ThreadSpec &operator=(const ThreadSpec &rhs);
45
46   static std::unique_ptr<ThreadSpec>
47   CreateFromStructuredData(const StructuredData::Dictionary &data_dict,
48                            Error &error);
49
50   StructuredData::ObjectSP SerializeToStructuredData();
51
52   static const char *GetSerializationKey() { return "ThreadSpec"; }
53
54   void SetIndex(uint32_t index) { m_index = index; }
55
56   void SetTID(lldb::tid_t tid) { m_tid = tid; }
57
58   void SetName(const char *name) { m_name = name; }
59
60   void SetQueueName(const char *queue_name) { m_queue_name = queue_name; }
61
62   uint32_t GetIndex() const { return m_index; }
63
64   lldb::tid_t GetTID() const { return m_tid; }
65
66   const char *GetName() const;
67
68   const char *GetQueueName() const;
69
70   bool TIDMatches(lldb::tid_t thread_id) const {
71     if (m_tid == LLDB_INVALID_THREAD_ID || thread_id == LLDB_INVALID_THREAD_ID)
72       return true;
73     else
74       return thread_id == m_tid;
75   }
76
77   bool TIDMatches(Thread &thread) const;
78
79   bool IndexMatches(uint32_t index) const {
80     if (m_index == UINT32_MAX || index == UINT32_MAX)
81       return true;
82     else
83       return index == m_index;
84   }
85
86   bool IndexMatches(Thread &thread) const;
87
88   bool NameMatches(const char *name) const {
89     if (m_name.empty())
90       return true;
91     else if (name == nullptr)
92       return false;
93     else
94       return m_name == name;
95   }
96
97   bool NameMatches(Thread &thread) const;
98
99   bool QueueNameMatches(const char *queue_name) const {
100     if (m_queue_name.empty())
101       return true;
102     else if (queue_name == nullptr)
103       return false;
104     else
105       return m_queue_name == queue_name;
106   }
107
108   bool QueueNameMatches(Thread &thread) const;
109
110   bool ThreadPassesBasicTests(Thread &thread) const;
111
112   bool HasSpecification() const;
113
114   void GetDescription(Stream *s, lldb::DescriptionLevel level) const;
115
116 private:
117   enum class OptionNames {
118     ThreadIndex = 0,
119     ThreadID,
120     ThreadName,
121     QueueName,
122     LastOptionName
123   };
124   static const char *g_option_names[(size_t)OptionNames::LastOptionName];
125
126   static const char *GetKey(OptionNames enum_value) {
127     return g_option_names[(size_t) enum_value];
128   }
129
130   uint32_t m_index;
131   lldb::tid_t m_tid;
132   std::string m_name;
133   std::string m_queue_name;
134 };
135
136 } // namespace lldb_private
137
138 #endif // liblldb_ThreadSpec_h_