]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/tools/lldb/source/Target/ThreadSpec.cpp
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / tools / lldb / source / Target / ThreadSpec.cpp
1 //===-- 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
13 using namespace lldb;
14 using namespace lldb_private;
15
16 ThreadSpec::ThreadSpec() :
17     m_index (UINT32_MAX),
18     m_tid (LLDB_INVALID_THREAD_ID),
19     m_name(),
20     m_queue_name ()
21 {
22 }
23
24 ThreadSpec::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
32 const ThreadSpec &
33 ThreadSpec::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
42 const char *
43 ThreadSpec::GetName () const
44 {
45     if (m_name.empty())
46         return NULL;
47     else
48         return m_name.c_str();
49 }
50
51 const char *
52 ThreadSpec::GetQueueName () const
53 {
54     if (m_queue_name.empty())
55         return NULL;
56     else
57         return m_queue_name.c_str();
58 }
59
60 bool
61 ThreadSpec::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 }
69 bool 
70 ThreadSpec::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 }
77 bool 
78 ThreadSpec::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 }
86 bool 
87 ThreadSpec::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
96 bool
97 ThreadSpec::ThreadPassesBasicTests (Thread &thread) const
98 {
99
100     if (!HasSpecification())
101         return true;
102         
103     if (!TIDMatches(thread))
104         return false;
105         
106     if (!IndexMatches(thread))
107         return false;
108         
109     if (!NameMatches (thread))
110         return false;
111         
112     if (!QueueNameMatches (thread))
113         return false;
114         
115     return true;
116
117 }
118
119 bool
120 ThreadSpec::HasSpecification() const
121 {
122     return (m_index != UINT32_MAX || m_tid != LLDB_INVALID_THREAD_ID || !m_name.empty() || !m_queue_name.empty());
123 }
124 void
125 ThreadSpec::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)
143                 s->Printf("tid: 0x%" PRIx64 " ", GetTID());
144                 
145             if (GetIndex() != UINT32_MAX)
146                 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 }