blob: ca47e7208074bb5e9251c7466501db69d9a77f74 [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
61ThreadSpec::ThreadPassesBasicTests (Thread *thread) const
62{
63
64 if (!HasSpecification())
65 return true;
66
67 if (!TIDMatches(thread->GetID()))
68 return false;
69
70 if (!IndexMatches(thread->GetIndexID()))
71 return false;
72
73 if (!NameMatches (thread->GetName()))
74 return false;
75
76 if (!QueueNameMatches (thread->GetQueueName()))
77 return false;
78
79 return true;
80
81}
82
83bool
84ThreadSpec::HasSpecification() const
85{
Greg Claytona6253872010-12-15 20:50:06 +000086 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 +000087}
88void
89ThreadSpec::GetDescription (Stream *s, lldb::DescriptionLevel level) const
90{
91 if (!HasSpecification())
92 {
93 if (level == eDescriptionLevelBrief)
94 {
95 s->PutCString("thread spec: no ");
96 }
97 }
98 else
99 {
100 if (level == eDescriptionLevelBrief)
101 {
102 s->PutCString("thread spec: yes ");
103 }
104 else
105 {
106 if (GetTID() != LLDB_INVALID_THREAD_ID)
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000107 s->Printf("tid: 0x%x ", GetTID());
Jim Ingham649492b2010-06-18 01:00:58 +0000108
Greg Claytona6253872010-12-15 20:50:06 +0000109 if (GetIndex() != UINT32_MAX)
Jim Ingham649492b2010-06-18 01:00:58 +0000110 s->Printf("index: %d ", GetIndex());
111
112 const char *name = GetName();
113 if (name)
114 s->Printf ("thread name: \"%s\" ", name);
115
116 const char *queue_name = GetQueueName();
117 if (queue_name)
118 s->Printf ("queue name: \"%s\" ", queue_name);
119 }
120
121 }
122}