blob: 1d217e00035b2ca1f6be4bd81703e47f9f60a753 [file] [log] [blame]
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +00001//===-- ThreadSpec.cpp ------------------------------------------*- C++ -*-===//
Jim Ingham1b54c882010-06-16 02:00:15 +00002//
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
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +000010// C Includes
11// C++ Includes
12// Other libraries and framework includes
13// Project includes
Jim Ingham1b54c882010-06-16 02:00:15 +000014#include "lldb/Target/Thread.h"
15#include "lldb/Target/ThreadSpec.h"
16
17using namespace lldb;
18using namespace lldb_private;
19
Kate Stoneb9c1b512016-09-06 20:57:50 +000020ThreadSpec::ThreadSpec()
21 : m_index(UINT32_MAX), m_tid(LLDB_INVALID_THREAD_ID), m_name(),
22 m_queue_name() {}
23
24ThreadSpec::ThreadSpec(const ThreadSpec &rhs)
25 : m_index(rhs.m_index), m_tid(rhs.m_tid), m_name(rhs.m_name),
26 m_queue_name(rhs.m_queue_name) {}
27
28const ThreadSpec &ThreadSpec::operator=(const ThreadSpec &rhs) {
29 m_index = rhs.m_index;
30 m_tid = rhs.m_tid;
31 m_name = rhs.m_name;
32 m_queue_name = rhs.m_queue_name;
33 return *this;
Jim Ingham1b54c882010-06-16 02:00:15 +000034}
35
Kate Stoneb9c1b512016-09-06 20:57:50 +000036const char *ThreadSpec::GetName() const {
37 return m_name.empty() ? nullptr : m_name.c_str();
Jim Ingham1b54c882010-06-16 02:00:15 +000038}
39
Kate Stoneb9c1b512016-09-06 20:57:50 +000040const char *ThreadSpec::GetQueueName() const {
41 return m_queue_name.empty() ? nullptr : m_queue_name.c_str();
Jim Ingham1b54c882010-06-16 02:00:15 +000042}
43
Kate Stoneb9c1b512016-09-06 20:57:50 +000044bool ThreadSpec::TIDMatches(Thread &thread) const {
45 if (m_tid == LLDB_INVALID_THREAD_ID)
Jim Ingham01363092010-06-18 01:00:58 +000046 return true;
Kate Stoneb9c1b512016-09-06 20:57:50 +000047
48 lldb::tid_t thread_id = thread.GetID();
49 return TIDMatches(thread_id);
Jim Ingham01363092010-06-18 01:00:58 +000050}
51
Kate Stoneb9c1b512016-09-06 20:57:50 +000052bool ThreadSpec::IndexMatches(Thread &thread) const {
53 if (m_index == UINT32_MAX)
54 return true;
55 uint32_t index = thread.GetIndexID();
56 return IndexMatches(index);
Jim Ingham01363092010-06-18 01:00:58 +000057}
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +000058
Kate Stoneb9c1b512016-09-06 20:57:50 +000059bool ThreadSpec::NameMatches(Thread &thread) const {
60 if (m_name.empty())
61 return true;
Jim Ingham01363092010-06-18 01:00:58 +000062
Kate Stoneb9c1b512016-09-06 20:57:50 +000063 const char *name = thread.GetName();
64 return NameMatches(name);
65}
66
67bool ThreadSpec::QueueNameMatches(Thread &thread) const {
68 if (m_queue_name.empty())
69 return true;
70
71 const char *queue_name = thread.GetQueueName();
72 return QueueNameMatches(queue_name);
73}
74
75bool ThreadSpec::ThreadPassesBasicTests(Thread &thread) const {
76 if (!HasSpecification())
77 return true;
78
79 if (!TIDMatches(thread))
80 return false;
81
82 if (!IndexMatches(thread))
83 return false;
84
85 if (!NameMatches(thread))
86 return false;
87
88 if (!QueueNameMatches(thread))
89 return false;
90
91 return true;
92}
93
94bool ThreadSpec::HasSpecification() const {
95 return (m_index != UINT32_MAX || m_tid != LLDB_INVALID_THREAD_ID ||
96 !m_name.empty() || !m_queue_name.empty());
97}
98
99void ThreadSpec::GetDescription(Stream *s, lldb::DescriptionLevel level) const {
100 if (!HasSpecification()) {
101 if (level == eDescriptionLevelBrief) {
102 s->PutCString("thread spec: no ");
Jim Ingham01363092010-06-18 01:00:58 +0000103 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000104 } else {
105 if (level == eDescriptionLevelBrief) {
106 s->PutCString("thread spec: yes ");
107 } else {
108 if (GetTID() != LLDB_INVALID_THREAD_ID)
109 s->Printf("tid: 0x%" PRIx64 " ", GetTID());
110
111 if (GetIndex() != UINT32_MAX)
112 s->Printf("index: %d ", GetIndex());
113
114 const char *name = GetName();
115 if (name)
116 s->Printf("thread name: \"%s\" ", name);
117
118 const char *queue_name = GetQueueName();
119 if (queue_name)
120 s->Printf("queue name: \"%s\" ", queue_name);
121 }
122 }
Jim Ingham01363092010-06-18 01:00:58 +0000123}