Eugene Zelenko | e65b2cf | 2015-12-15 01:33:19 +0000 | [diff] [blame] | 1 | //===-- ThreadSpec.cpp ------------------------------------------*- C++ -*-===// |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 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 | |
Eugene Zelenko | e65b2cf | 2015-12-15 01:33:19 +0000 | [diff] [blame] | 10 | // C Includes |
| 11 | // C++ Includes |
| 12 | // Other libraries and framework includes |
| 13 | // Project includes |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 14 | #include "lldb/Target/Thread.h" |
| 15 | #include "lldb/Target/ThreadSpec.h" |
| 16 | |
| 17 | using namespace lldb; |
| 18 | using namespace lldb_private; |
| 19 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 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; |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 36 | const char *ThreadSpec::GetName() const { |
| 37 | return m_name.empty() ? nullptr : m_name.c_str(); |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 40 | const char *ThreadSpec::GetQueueName() const { |
| 41 | return m_queue_name.empty() ? nullptr : m_queue_name.c_str(); |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 44 | bool ThreadSpec::TIDMatches(Thread &thread) const { |
| 45 | if (m_tid == LLDB_INVALID_THREAD_ID) |
Jim Ingham | 0136309 | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 46 | return true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 47 | |
| 48 | lldb::tid_t thread_id = thread.GetID(); |
| 49 | return TIDMatches(thread_id); |
Jim Ingham | 0136309 | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 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); |
Jim Ingham | 0136309 | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 57 | } |
Eugene Zelenko | e65b2cf | 2015-12-15 01:33:19 +0000 | [diff] [blame] | 58 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 59 | bool ThreadSpec::NameMatches(Thread &thread) const { |
| 60 | if (m_name.empty()) |
| 61 | return true; |
Jim Ingham | 0136309 | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 62 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 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 "); |
Jim Ingham | 0136309 | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 103 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 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 | } |
Jim Ingham | 0136309 | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 123 | } |