1 //===-- ThreadSpec.h ------------------------------------------------*- 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 #ifndef liblldb_ThreadSpec_h_ 11 #define liblldb_ThreadSpec_h_ 12 13 #include <map> 14 #include <string> 15 16 #include "lldb/lldb-private.h" 17 18 namespace lldb_private { 19 20 // Note: For now the thread spec has only fixed elements - 21 // Thread ID 22 // Thread Index 23 // Thread Name 24 // Thread Queue Name 25 // 26 // But if we need more generality, we can hang a key/value map off of this structure. 27 // That's why the thread matches spec test is done as a virtual method in Thread::MatchesSpec, 28 // since it is the native thread that would know how to interpret the keys. 29 // I was going to do the Queue Name this way out of sheer orneriness, but that seems a 30 // sufficiently general concept, so I put it in here on its own. 31 32 class ThreadSpec 33 { 34 public: 35 ThreadSpec (); 36 37 ThreadSpec (const ThreadSpec &rhs); 38 39 const ThreadSpec & 40 operator=(const ThreadSpec &rhs); 41 42 void SetIndex(uint32_t index)43 SetIndex (uint32_t index) 44 { 45 m_index = index; 46 } 47 48 void SetTID(lldb::tid_t tid)49 SetTID (lldb::tid_t tid) 50 { 51 m_tid = tid; 52 } 53 54 void SetName(const char * name)55 SetName (const char *name) 56 { 57 m_name = name; 58 } 59 60 void SetQueueName(const char * queue_name)61 SetQueueName (const char *queue_name) 62 { 63 m_queue_name = queue_name; 64 } 65 66 uint32_t GetIndex()67 GetIndex () const 68 { 69 return m_index; 70 } 71 72 lldb::tid_t GetTID()73 GetTID () const 74 { 75 return m_tid; 76 } 77 78 const char * 79 GetName () const; 80 81 const char * 82 GetQueueName () const; 83 84 bool TIDMatches(lldb::tid_t thread_id)85 TIDMatches (lldb::tid_t thread_id) const 86 { 87 if (m_tid == LLDB_INVALID_THREAD_ID || thread_id == LLDB_INVALID_THREAD_ID) 88 return true; 89 else 90 return thread_id == m_tid; 91 } 92 93 bool 94 TIDMatches (Thread &thread) const; 95 96 bool IndexMatches(uint32_t index)97 IndexMatches (uint32_t index) const 98 { 99 if (m_index == UINT32_MAX || index == UINT32_MAX) 100 return true; 101 else 102 return index == m_index; 103 } 104 105 bool 106 IndexMatches (Thread &thread) const; 107 108 bool NameMatches(const char * name)109 NameMatches (const char *name) const 110 { 111 if (m_name.empty()) 112 return true; 113 else if (name == NULL) 114 return false; 115 else 116 return m_name == name; 117 } 118 119 bool 120 NameMatches (Thread &thread) const; 121 122 bool QueueNameMatches(const char * queue_name)123 QueueNameMatches (const char *queue_name) const 124 { 125 if (m_queue_name.empty()) 126 return true; 127 else if (queue_name == NULL) 128 return false; 129 else 130 return m_queue_name == queue_name; 131 } 132 133 bool 134 QueueNameMatches (Thread &thread) const; 135 136 bool 137 ThreadPassesBasicTests (Thread &thread) const; 138 139 bool 140 HasSpecification () const; 141 142 void 143 GetDescription (Stream *s, lldb::DescriptionLevel level) const; 144 145 protected: 146 private: 147 uint32_t m_index; 148 lldb::tid_t m_tid; 149 std::string m_name; 150 std::string m_queue_name; 151 }; 152 153 } // namespace lldb_private 154 155 #endif // liblldb_ThreadSpec_h_ 156