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
16namespace 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
34public:
35 ThreadSpec();
36
37 ThreadSpec(Thread &thread);
38
39 static std::unique_ptr<ThreadSpec>
41 Status &error);
42
44
45 static const char *GetSerializationKey() { return "ThreadSpec"; }
46
47 void SetIndex(uint32_t index) { m_index = index; }
48
49 void SetTID(lldb::tid_t tid) { m_tid = tid; }
50
51 void SetName(llvm::StringRef name) { m_name = std::string(name); }
52
53 void SetQueueName(llvm::StringRef queue_name) {
54 m_queue_name = std::string(queue_name);
55 }
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 {
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
111private:
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 = UINT32_MAX;
127 std::string m_name;
128 std::string m_queue_name;
129};
130
131} // namespace lldb_private
132
133#endif // LLDB_TARGET_THREADSPEC_H
static llvm::raw_ostream & error(Stream &strm)
An error handling class.
Definition Status.h:118
A stream class that can stream formatted output to a file.
Definition Stream.h:28
std::shared_ptr< Object > ObjectSP
bool HasSpecification() const
void SetIndex(uint32_t index)
Definition ThreadSpec.h:47
void SetName(llvm::StringRef name)
Definition ThreadSpec.h:51
bool NameMatches(const char *name) const
Definition ThreadSpec.h:83
bool TIDMatches(lldb::tid_t thread_id) const
Definition ThreadSpec.h:65
StructuredData::ObjectSP SerializeToStructuredData()
bool ThreadPassesBasicTests(Thread &thread) const
bool QueueNameMatches(const char *queue_name) const
Definition ThreadSpec.h:94
uint32_t GetIndex() const
Definition ThreadSpec.h:57
static const char * GetKey(OptionNames enum_value)
Definition ThreadSpec.h:121
void SetTID(lldb::tid_t tid)
Definition ThreadSpec.h:49
static const char * GetSerializationKey()
Definition ThreadSpec.h:45
const char * GetName() const
bool IndexMatches(uint32_t index) const
Definition ThreadSpec.h:74
void SetQueueName(llvm::StringRef queue_name)
Definition ThreadSpec.h:53
void GetDescription(Stream *s, lldb::DescriptionLevel level) const
const char * GetQueueName() const
static const char * g_option_names[(size_t) OptionNames::LastOptionName]
Definition ThreadSpec.h:119
static std::unique_ptr< ThreadSpec > CreateFromStructuredData(const StructuredData::Dictionary &data_dict, Status &error)
lldb::tid_t GetTID() const
Definition ThreadSpec.h:59
#define LLDB_INVALID_THREAD_ID
#define UINT32_MAX
A class that represents a running process on the host machine.
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
uint64_t tid_t
Definition lldb-types.h:84