Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:56

0001 //===-- ThreadSpec.h --------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_TARGET_THREADSPEC_H
0010 #define LLDB_TARGET_THREADSPEC_H
0011 
0012 #include "lldb/Utility/StructuredData.h"
0013 #include "lldb/lldb-private.h"
0014 #include <string>
0015 
0016 namespace lldb_private {
0017 
0018 // Note: For now the thread spec has only fixed elements -
0019 //   Thread ID
0020 //   Thread Index
0021 //   Thread Name
0022 //   Thread Queue Name
0023 //
0024 //  But if we need more generality, we can hang a key/value map off of this
0025 //  structure.
0026 //  That's why the thread matches spec test is done as a virtual method in
0027 //  Thread::MatchesSpec,
0028 //  since it is the native thread that would know how to interpret the keys.
0029 //  I was going to do the Queue Name this way out of sheer orneriness, but that
0030 //  seems a
0031 //  sufficiently general concept, so I put it in here on its own.
0032 
0033 class ThreadSpec {
0034 public:
0035   ThreadSpec();
0036 
0037   static std::unique_ptr<ThreadSpec>
0038   CreateFromStructuredData(const StructuredData::Dictionary &data_dict,
0039                            Status &error);
0040 
0041   StructuredData::ObjectSP SerializeToStructuredData();
0042 
0043   static const char *GetSerializationKey() { return "ThreadSpec"; }
0044 
0045   void SetIndex(uint32_t index) { m_index = index; }
0046 
0047   void SetTID(lldb::tid_t tid) { m_tid = tid; }
0048 
0049   void SetName(llvm::StringRef name) { m_name = std::string(name); }
0050 
0051   void SetQueueName(llvm::StringRef queue_name) {
0052     m_queue_name = std::string(queue_name);
0053   }
0054 
0055   uint32_t GetIndex() const { return m_index; }
0056 
0057   lldb::tid_t GetTID() const { return m_tid; }
0058 
0059   const char *GetName() const;
0060 
0061   const char *GetQueueName() const;
0062 
0063   bool TIDMatches(lldb::tid_t thread_id) const {
0064     if (m_tid == LLDB_INVALID_THREAD_ID || thread_id == LLDB_INVALID_THREAD_ID)
0065       return true;
0066     else
0067       return thread_id == m_tid;
0068   }
0069 
0070   bool TIDMatches(Thread &thread) const;
0071 
0072   bool IndexMatches(uint32_t index) const {
0073     if (m_index == UINT32_MAX || index == UINT32_MAX)
0074       return true;
0075     else
0076       return index == m_index;
0077   }
0078 
0079   bool IndexMatches(Thread &thread) const;
0080 
0081   bool NameMatches(const char *name) const {
0082     if (m_name.empty())
0083       return true;
0084     else if (name == nullptr)
0085       return false;
0086     else
0087       return m_name == name;
0088   }
0089 
0090   bool NameMatches(Thread &thread) const;
0091 
0092   bool QueueNameMatches(const char *queue_name) const {
0093     if (m_queue_name.empty())
0094       return true;
0095     else if (queue_name == nullptr)
0096       return false;
0097     else
0098       return m_queue_name == queue_name;
0099   }
0100 
0101   bool QueueNameMatches(Thread &thread) const;
0102 
0103   bool ThreadPassesBasicTests(Thread &thread) const;
0104 
0105   bool HasSpecification() const;
0106 
0107   void GetDescription(Stream *s, lldb::DescriptionLevel level) const;
0108 
0109 private:
0110   enum class OptionNames {
0111     ThreadIndex = 0,
0112     ThreadID,
0113     ThreadName,
0114     QueueName,
0115     LastOptionName
0116   };
0117   static const char *g_option_names[(size_t)OptionNames::LastOptionName];
0118 
0119   static const char *GetKey(OptionNames enum_value) {
0120     return g_option_names[(size_t) enum_value];
0121   }
0122 
0123   uint32_t m_index = UINT32_MAX;
0124   lldb::tid_t m_tid = LLDB_INVALID_THREAD_ID;
0125   std::string m_name;
0126   std::string m_queue_name;
0127 };
0128 
0129 } // namespace lldb_private
0130 
0131 #endif // LLDB_TARGET_THREADSPEC_H