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), m_tid(LLDB_INVALID_THREAD_ID), m_name(), 22 m_queue_name() {} 23 24 ThreadSpec::ThreadSpec(const ThreadSpec &rhs) 25 : m_index(rhs.m_index), m_tid(rhs.m_tid), m_name(rhs.m_name), 26 m_queue_name(rhs.m_queue_name) {} 27 28 const ThreadSpec &ThreadSpec::operator=(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 return *this; 34 } 35 36 const char *ThreadSpec::GetName() const { 37 return m_name.empty() ? nullptr : m_name.c_str(); 38 } 39 40 const char *ThreadSpec::GetQueueName() const { 41 return m_queue_name.empty() ? nullptr : m_queue_name.c_str(); 42 } 43 44 bool ThreadSpec::TIDMatches(Thread &thread) const { 45 if (m_tid == LLDB_INVALID_THREAD_ID) 46 return true; 47 48 lldb::tid_t thread_id = thread.GetID(); 49 return TIDMatches(thread_id); 50 } 51 52 bool ThreadSpec::IndexMatches(Thread &thread) const { 53 if (m_index == UINT32_MAX) 54 return true; 55 uint32_t index = thread.GetIndexID(); 56 return IndexMatches(index); 57 } 58 59 bool ThreadSpec::NameMatches(Thread &thread) const { 60 if (m_name.empty()) 61 return true; 62 63 const char *name = thread.GetName(); 64 return NameMatches(name); 65 } 66 67 bool ThreadSpec::QueueNameMatches(Thread &thread) const { 68 if (m_queue_name.empty()) 69 return true; 70 71 const char *queue_name = thread.GetQueueName(); 72 return QueueNameMatches(queue_name); 73 } 74 75 bool ThreadSpec::ThreadPassesBasicTests(Thread &thread) const { 76 if (!HasSpecification()) 77 return true; 78 79 if (!TIDMatches(thread)) 80 return false; 81 82 if (!IndexMatches(thread)) 83 return false; 84 85 if (!NameMatches(thread)) 86 return false; 87 88 if (!QueueNameMatches(thread)) 89 return false; 90 91 return true; 92 } 93 94 bool ThreadSpec::HasSpecification() const { 95 return (m_index != UINT32_MAX || m_tid != LLDB_INVALID_THREAD_ID || 96 !m_name.empty() || !m_queue_name.empty()); 97 } 98 99 void ThreadSpec::GetDescription(Stream *s, lldb::DescriptionLevel level) const { 100 if (!HasSpecification()) { 101 if (level == eDescriptionLevelBrief) { 102 s->PutCString("thread spec: no "); 103 } 104 } else { 105 if (level == eDescriptionLevelBrief) { 106 s->PutCString("thread spec: yes "); 107 } else { 108 if (GetTID() != LLDB_INVALID_THREAD_ID) 109 s->Printf("tid: 0x%" PRIx64 " ", GetTID()); 110 111 if (GetIndex() != UINT32_MAX) 112 s->Printf("index: %d ", GetIndex()); 113 114 const char *name = GetName(); 115 if (name) 116 s->Printf("thread name: \"%s\" ", name); 117 118 const char *queue_name = GetQueueName(); 119 if (queue_name) 120 s->Printf("queue name: \"%s\" ", queue_name); 121 } 122 } 123 } 124