LLDB  mainline
ThreadSpec.h
Go to the documentation of this file.
1 //===-- ThreadSpec.h --------------------------------------------*- C++ -*-===//
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 liblldb_ThreadSpec_h_
10 #define liblldb_ThreadSpec_h_
11 
13 #include "lldb/lldb-private.h"
14 #include <string>
15 
16 namespace lldb_private {
17 
18 // Note: For now the thread spec has only fixed elements -
19 // Thread ID
20 // Thread Index
21 // Thread Name
22 // Thread Queue Name
23 //
24 // But if we need more generality, we can hang a key/value map off of this
25 // structure.
26 // That's why the thread matches spec test is done as a virtual method in
27 // Thread::MatchesSpec,
28 // since it is the native thread that would know how to interpret the keys.
29 // I was going to do the Queue Name this way out of sheer orneriness, but that
30 // seems a
31 // sufficiently general concept, so I put it in here on its own.
32 
33 class ThreadSpec {
34 public:
35  ThreadSpec();
36 
37  ThreadSpec(const ThreadSpec &rhs);
38 
39  const ThreadSpec &operator=(const ThreadSpec &rhs);
40 
41  static std::unique_ptr<ThreadSpec>
43  Status &error);
44 
46 
47  static const char *GetSerializationKey() { return "ThreadSpec"; }
48 
49  void SetIndex(uint32_t index) { m_index = index; }
50 
51  void SetTID(lldb::tid_t tid) { m_tid = tid; }
52 
53  void SetName(llvm::StringRef name) { m_name = name; }
54 
55  void SetQueueName(llvm::StringRef queue_name) { m_queue_name = queue_name; }
56 
57  uint32_t GetIndex() const { return m_index; }
58 
59  lldb::tid_t GetTID() const { return m_tid; }
60 
61  const char *GetName() const;
62 
63  const char *GetQueueName() const;
64 
65  bool TIDMatches(lldb::tid_t thread_id) const {
66  if (m_tid == LLDB_INVALID_THREAD_ID || thread_id == LLDB_INVALID_THREAD_ID)
67  return true;
68  else
69  return thread_id == m_tid;
70  }
71 
72  bool TIDMatches(Thread &thread) const;
73 
74  bool IndexMatches(uint32_t index) const {
75  if (m_index == UINT32_MAX || index == UINT32_MAX)
76  return true;
77  else
78  return index == m_index;
79  }
80 
81  bool IndexMatches(Thread &thread) const;
82 
83  bool NameMatches(const char *name) const {
84  if (m_name.empty())
85  return true;
86  else if (name == nullptr)
87  return false;
88  else
89  return m_name == name;
90  }
91 
92  bool NameMatches(Thread &thread) const;
93 
94  bool QueueNameMatches(const char *queue_name) const {
95  if (m_queue_name.empty())
96  return true;
97  else if (queue_name == nullptr)
98  return false;
99  else
100  return m_queue_name == queue_name;
101  }
102 
103  bool QueueNameMatches(Thread &thread) const;
104 
105  bool ThreadPassesBasicTests(Thread &thread) const;
106 
107  bool HasSpecification() const;
108 
109  void GetDescription(Stream *s, lldb::DescriptionLevel level) const;
110 
111 private:
112  enum class OptionNames {
113  ThreadIndex = 0,
114  ThreadID,
115  ThreadName,
116  QueueName,
117  LastOptionName
118  };
119  static const char *g_option_names[(size_t)OptionNames::LastOptionName];
120 
121  static const char *GetKey(OptionNames enum_value) {
122  return g_option_names[(size_t) enum_value];
123  }
124 
125  uint32_t m_index;
126  lldb::tid_t m_tid;
127  std::string m_name;
128  std::string m_queue_name;
129 };
130 
131 } // namespace lldb_private
132 
133 #endif // liblldb_ThreadSpec_h_
static const char * GetSerializationKey()
Definition: ThreadSpec.h:47
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
void SetName(llvm::StringRef name)
Definition: ThreadSpec.h:53
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
bool NameMatches(const char *name) const
Definition: ThreadSpec.h:83
bool TIDMatches(lldb::tid_t thread_id) const
Definition: ThreadSpec.h:65
bool HasSpecification() const
Definition: ThreadSpec.cpp:140
StructuredData::ObjectSP SerializeToStructuredData()
Definition: ThreadSpec.cpp:67
bool IndexMatches(uint32_t index) const
Definition: ThreadSpec.h:74
const char * GetName() const
Definition: ThreadSpec.cpp:82
const char * GetQueueName() const
Definition: ThreadSpec.cpp:86
#define UINT32_MAX
Definition: lldb-defines.h:31
static std::unique_ptr< ThreadSpec > CreateFromStructuredData(const StructuredData::Dictionary &data_dict, Status &error)
Definition: ThreadSpec.cpp:36
void SetQueueName(llvm::StringRef queue_name)
Definition: ThreadSpec.h:55
lldb::tid_t GetTID() const
Definition: ThreadSpec.h:59
uint64_t tid_t
Definition: lldb-types.h:86
void SetIndex(uint32_t index)
Definition: ThreadSpec.h:49
const ThreadSpec & operator=(const ThreadSpec &rhs)
Definition: ThreadSpec.cpp:28
bool QueueNameMatches(const char *queue_name) const
Definition: ThreadSpec.h:94
#define LLDB_INVALID_THREAD_ID
Definition: lldb-defines.h:93
bool ThreadPassesBasicTests(Thread &thread) const
Definition: ThreadSpec.cpp:121
void SetTID(lldb::tid_t tid)
Definition: ThreadSpec.h:51
void GetDescription(Stream *s, lldb::DescriptionLevel level) const
Definition: ThreadSpec.cpp:145
uint32_t GetIndex() const
Definition: ThreadSpec.h:57
std::shared_ptr< Object > ObjectSP
An error handling class.
Definition: Status.h:44