xref: /llvm-project/lldb/source/Target/ThreadSpec.cpp (revision bdf4c6ac4f76b2ee32c848162a897c82c29ab499)
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::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 
83 bool
84 ThreadSpec::HasSpecification() const
85 {
86     return (m_index != UINT32_MAX || m_tid != LLDB_INVALID_THREAD_ID || !m_name.empty() || !m_queue_name.empty());
87 }
88 void
89 ThreadSpec::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)
107                 s->Printf("tid: 0x%llx ", GetTID());
108 
109             if (GetIndex() != UINT32_MAX)
110                 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 }
123