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 // C Includes 11 // C++ Includes 12 // Other libraries and framework includes 13 // Project includes 14 #include "lldb/Target/Thread.h" 15 #include "lldb/Target/ThreadSpec.h" 16 17 using namespace lldb; 18 using namespace lldb_private; 19 20 ThreadSpec::ThreadSpec() : 21 m_index (UINT32_MAX), 22 m_tid (LLDB_INVALID_THREAD_ID), 23 m_name(), 24 m_queue_name () 25 { 26 } 27 28 ThreadSpec::ThreadSpec(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 { 34 } 35 36 const ThreadSpec & 37 ThreadSpec::operator=(const ThreadSpec &rhs) 38 { 39 m_index = rhs.m_index; 40 m_tid = rhs.m_tid; 41 m_name = rhs.m_name; 42 m_queue_name = rhs.m_queue_name; 43 return *this; 44 } 45 46 const char * 47 ThreadSpec::GetName () const 48 { 49 return m_name.empty() ? nullptr : m_name.c_str(); 50 } 51 52 const char * 53 ThreadSpec::GetQueueName () const 54 { 55 return m_queue_name.empty() ? nullptr : m_queue_name.c_str(); 56 } 57 58 bool 59 ThreadSpec::TIDMatches (Thread &thread) const 60 { 61 if (m_tid == LLDB_INVALID_THREAD_ID) 62 return true; 63 64 lldb::tid_t thread_id = thread.GetID(); 65 return TIDMatches (thread_id); 66 } 67 68 bool 69 ThreadSpec::IndexMatches (Thread &thread) const 70 { 71 if (m_index == UINT32_MAX) 72 return true; 73 uint32_t index = thread.GetIndexID(); 74 return IndexMatches (index); 75 } 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 87 bool 88 ThreadSpec::QueueNameMatches (Thread &thread) const 89 { 90 if (m_queue_name.empty()) 91 return true; 92 93 const char *queue_name = thread.GetQueueName(); 94 return QueueNameMatches (queue_name); 95 } 96 97 bool 98 ThreadSpec::ThreadPassesBasicTests (Thread &thread) const 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 bool 119 ThreadSpec::HasSpecification() const 120 { 121 return (m_index != UINT32_MAX || m_tid != LLDB_INVALID_THREAD_ID || !m_name.empty() || !m_queue_name.empty()); 122 } 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 } 159