blob: cb54469ba9014a3fd83256f3081e6670d2af4201 [file] [log] [blame]
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001//===-- ThreadSpec.cpp ----------------------------------------------*- 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#include "lldb/Target/Thread.h"
11#include "lldb/Target/ThreadSpec.h"
12
13using namespace lldb;
14using namespace lldb_private;
15
16ThreadSpec::ThreadSpec() :
Greg Claytona6253872010-12-15 20:50:06 +000017 m_index (UINT32_MAX),
Jim Ingham3c7b5b92010-06-16 02:00:15 +000018 m_tid (LLDB_INVALID_THREAD_ID),
19 m_name(),
20 m_queue_name ()
21{
22}
23
24ThreadSpec::ThreadSpec (const ThreadSpec &rhs) :
25 m_index(rhs.m_index),
26 m_tid(rhs.m_tid),
27 m_name(rhs.m_name),
28 m_queue_name(rhs.m_queue_name)
29{
30}
31
32const ThreadSpec &
33ThreadSpec::operator=(const ThreadSpec &rhs)
34{
35 m_index = rhs.m_index;
36 m_tid = rhs.m_tid;
37 m_name = rhs.m_name;
38 m_queue_name = rhs.m_queue_name;
39 return *this;
40}
41
42const char *
43ThreadSpec::GetName () const
44{
45 if (m_name.empty())
46 return NULL;
47 else
48 return m_name.c_str();
49}
50
51const char *
52ThreadSpec::GetQueueName () const
53{
54 if (m_queue_name.empty())
55 return NULL;
56 else
57 return m_queue_name.c_str();
58}
Jim Ingham649492b2010-06-18 01:00:58 +000059
60bool
Jim Inghama2664912012-03-07 22:03:04 +000061ThreadSpec::TIDMatches (Thread &thread) const
62{
63 if (m_tid == LLDB_INVALID_THREAD_ID)
64 return true;
65
66 lldb::tid_t thread_id = thread.GetID();
67 return TIDMatches (thread_id);
68}
69bool
70ThreadSpec::IndexMatches (Thread &thread) const
71{
72 if (m_index == UINT32_MAX)
73 return true;
74 uint32_t index = thread.GetIndexID();
75 return IndexMatches (index);
76}
77bool
78ThreadSpec::NameMatches (Thread &thread) const
79{
80 if (m_name.empty())
81 return true;
82
83 const char *name = thread.GetName();
84 return NameMatches (name);
85}
86bool
87ThreadSpec::QueueNameMatches (Thread &thread) const
88{
89 if (m_queue_name.empty())
90 return true;
91
92 const char *queue_name = thread.GetQueueName();
93 return QueueNameMatches (queue_name);
94}
95
96bool
97ThreadSpec::ThreadPassesBasicTests (Thread &thread) const
Jim Ingham649492b2010-06-18 01:00:58 +000098{
99
100 if (!HasSpecification())
101 return true;
102
Jim Inghama2664912012-03-07 22:03:04 +0000103 if (!TIDMatches(thread))
Jim Ingham649492b2010-06-18 01:00:58 +0000104 return false;
105
Jim Inghama2664912012-03-07 22:03:04 +0000106 if (!IndexMatches(thread))
Jim Ingham649492b2010-06-18 01:00:58 +0000107 return false;
108
Jim Inghama2664912012-03-07 22:03:04 +0000109 if (!NameMatches (thread))
Jim Ingham649492b2010-06-18 01:00:58 +0000110 return false;
111
Jim Inghama2664912012-03-07 22:03:04 +0000112 if (!QueueNameMatches (thread))
Jim Ingham649492b2010-06-18 01:00:58 +0000113 return false;
114
115 return true;
116
117}
118
119bool
120ThreadSpec::HasSpecification() const
121{
Greg Claytona6253872010-12-15 20:50:06 +0000122 return (m_index != UINT32_MAX || m_tid != LLDB_INVALID_THREAD_ID || !m_name.empty() || !m_queue_name.empty());
Jim Ingham649492b2010-06-18 01:00:58 +0000123}
124void
125ThreadSpec::GetDescription (Stream *s, lldb::DescriptionLevel level) const
126{
127 if (!HasSpecification())
128 {
129 if (level == eDescriptionLevelBrief)
130 {
131 s->PutCString("thread spec: no ");
132 }
133 }
134 else
135 {
136 if (level == eDescriptionLevelBrief)
137 {
138 s->PutCString("thread spec: yes ");
139 }
140 else
141 {
142 if (GetTID() != LLDB_INVALID_THREAD_ID)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000143 s->Printf("tid: 0x%" PRIx64 " ", GetTID());
Jim Ingham649492b2010-06-18 01:00:58 +0000144
Greg Claytona6253872010-12-15 20:50:06 +0000145 if (GetIndex() != UINT32_MAX)
Jim Ingham649492b2010-06-18 01:00:58 +0000146 s->Printf("index: %d ", GetIndex());
147
148 const char *name = GetName();
149 if (name)
150 s->Printf ("thread name: \"%s\" ", name);
151
152 const char *queue_name = GetQueueName();
153 if (queue_name)
154 s->Printf ("queue name: \"%s\" ", queue_name);
155 }
156
157 }
158}