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 LLDB_TARGET_THREADSPEC_H
10 #define LLDB_TARGET_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  static std::unique_ptr<ThreadSpec>
39  Status &error);
40 
42 
43  static const char *GetSerializationKey() { return "ThreadSpec"; }
44 
45  void SetIndex(uint32_t index) { m_index = index; }
46 
47  void SetTID(lldb::tid_t tid) { m_tid = tid; }
48 
49  void SetName(llvm::StringRef name) { m_name = std::string(name); }
50 
51  void SetQueueName(llvm::StringRef queue_name) {
52  m_queue_name = std::string(queue_name);
53  }
54 
55  uint32_t GetIndex() const { return m_index; }
56 
57  lldb::tid_t GetTID() const { return m_tid; }
58 
59  const char *GetName() const;
60 
61  const char *GetQueueName() const;
62 
63  bool TIDMatches(lldb::tid_t thread_id) const {
65  return true;
66  else
67  return thread_id == m_tid;
68  }
69 
70  bool TIDMatches(Thread &thread) const;
71 
72  bool IndexMatches(uint32_t index) const {
73  if (m_index == UINT32_MAX || index == UINT32_MAX)
74  return true;
75  else
76  return index == m_index;
77  }
78 
79  bool IndexMatches(Thread &thread) const;
80 
81  bool NameMatches(const char *name) const {
82  if (m_name.empty())
83  return true;
84  else if (name == nullptr)
85  return false;
86  else
87  return m_name == name;
88  }
89 
90  bool NameMatches(Thread &thread) const;
91 
92  bool QueueNameMatches(const char *queue_name) const {
93  if (m_queue_name.empty())
94  return true;
95  else if (queue_name == nullptr)
96  return false;
97  else
98  return m_queue_name == queue_name;
99  }
100 
101  bool QueueNameMatches(Thread &thread) const;
102 
103  bool ThreadPassesBasicTests(Thread &thread) const;
104 
105  bool HasSpecification() const;
106 
107  void GetDescription(Stream *s, lldb::DescriptionLevel level) const;
108 
109 private:
110  enum class OptionNames {
111  ThreadIndex = 0,
112  ThreadID,
113  ThreadName,
114  QueueName,
116  };
117  static const char *g_option_names[(size_t)OptionNames::LastOptionName];
118 
119  static const char *GetKey(OptionNames enum_value) {
120  return g_option_names[(size_t) enum_value];
121  }
122 
127 };
128 
129 } // namespace lldb_private
130 
131 #endif // LLDB_TARGET_THREADSPEC_H
lldb_private::ThreadSpec::HasSpecification
bool HasSpecification() const
Definition: ThreadSpec.cpp:126
lldb_private::StructuredData::Dictionary
Definition: StructuredData.h:352
lldb_private::ThreadSpec::NameMatches
bool NameMatches(const char *name) const
Definition: ThreadSpec.h:81
lldb_private::ThreadSpec::OptionNames
OptionNames
Definition: ThreadSpec.h:110
StructuredData.h
lldb_private::ThreadSpec::SerializeToStructuredData
StructuredData::ObjectSP SerializeToStructuredData()
Definition: ThreadSpec.cpp:53
lldb_private::ThreadSpec::OptionNames::ThreadName
@ ThreadName
lldb_private::ThreadSpec::ThreadPassesBasicTests
bool ThreadPassesBasicTests(Thread &thread) const
Definition: ThreadSpec.cpp:107
lldb_private::Stream
Definition: Stream.h:28
lldb_private::ThreadSpec::TIDMatches
bool TIDMatches(lldb::tid_t thread_id) const
Definition: ThreadSpec.h:63
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::ThreadSpec::GetKey
static const char * GetKey(OptionNames enum_value)
Definition: ThreadSpec.h:119
lldb_private::ThreadSpec::GetDescription
void GetDescription(Stream *s, lldb::DescriptionLevel level) const
Definition: ThreadSpec.cpp:131
lldb_private::ThreadSpec::m_tid
lldb::tid_t m_tid
Definition: ThreadSpec.h:124
lldb_private::ThreadSpec::g_option_names
static const char * g_option_names[(size_t) OptionNames::LastOptionName]
Definition: ThreadSpec.h:117
lldb_private::Thread
Definition: Thread.h:60
lldb_private::StructuredData::ObjectSP
std::shared_ptr< Object > ObjectSP
Definition: StructuredData.h:59
lldb_private::ThreadSpec::IndexMatches
bool IndexMatches(uint32_t index) const
Definition: ThreadSpec.h:72
lldb_private::ThreadSpec::SetQueueName
void SetQueueName(llvm::StringRef queue_name)
Definition: ThreadSpec.h:51
lldb_private::ThreadSpec::m_index
uint32_t m_index
Definition: ThreadSpec.h:123
lldb_private::ThreadSpec::OptionNames::LastOptionName
@ LastOptionName
lldb_private::ThreadSpec::SetIndex
void SetIndex(uint32_t index)
Definition: ThreadSpec.h:45
lldb_private::ThreadSpec::QueueNameMatches
bool QueueNameMatches(const char *queue_name) const
Definition: ThreadSpec.h:92
lldb_private::ThreadSpec::OptionNames::ThreadIndex
@ ThreadIndex
lldb_private::ThreadSpec::ThreadSpec
ThreadSpec()
Definition: ThreadSpec.cpp:20
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::ThreadSpec::SetTID
void SetTID(lldb::tid_t tid)
Definition: ThreadSpec.h:47
lldb_private::ThreadSpec
Definition: ThreadSpec.h:33
lldb-private.h
lldb_private::ThreadSpec::OptionNames::QueueName
@ QueueName
lldb_private::ThreadSpec::GetName
const char * GetName() const
Definition: ThreadSpec.cpp:68
lldb_private::ThreadSpec::GetIndex
uint32_t GetIndex() const
Definition: ThreadSpec.h:55
lldb_private::ThreadSpec::m_queue_name
std::string m_queue_name
Definition: ThreadSpec.h:126
lldb_private::Status
Definition: Status.h:44
lldb_private::ThreadSpec::GetQueueName
const char * GetQueueName() const
Definition: ThreadSpec.cpp:72
uint32_t
lldb_private::ThreadSpec::SetName
void SetName(llvm::StringRef name)
Definition: ThreadSpec.h:49
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:31
lldb_private::ThreadSpec::GetSerializationKey
static const char * GetSerializationKey()
Definition: ThreadSpec.h:43
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ThreadSpec::m_name
std::string m_name
Definition: ThreadSpec.h:125
lldb_private::ThreadSpec::CreateFromStructuredData
static std::unique_ptr< ThreadSpec > CreateFromStructuredData(const StructuredData::Dictionary &data_dict, Status &error)
Definition: ThreadSpec.cpp:22
lldb_private::ThreadSpec::GetTID
lldb::tid_t GetTID() const
Definition: ThreadSpec.h:57
LLDB_INVALID_THREAD_ID
#define LLDB_INVALID_THREAD_ID
Definition: lldb-defines.h:94
lldb_private::ThreadSpec::OptionNames::ThreadID
@ ThreadID
lldb::DescriptionLevel
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
Definition: lldb-enumerations.h:207
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86