Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 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() : |
Greg Clayton | a625387 | 2010-12-15 20:50:06 +0000 | [diff] [blame] | 17 | m_index (UINT32_MAX), |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 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 | } |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 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 | { |
Greg Clayton | a625387 | 2010-12-15 20:50:06 +0000 | [diff] [blame] | 86 | return (m_index != UINT32_MAX || m_tid != LLDB_INVALID_THREAD_ID || !m_name.empty() || !m_queue_name.empty()); |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 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) |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 107 | s->Printf("tid: 0x%x ", GetTID()); |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 108 | |
Greg Clayton | a625387 | 2010-12-15 20:50:06 +0000 | [diff] [blame] | 109 | if (GetIndex() != UINT32_MAX) |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 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 | } |