Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===-- QueueItem.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_QUEUEITEM_H
0010 #define LLDB_TARGET_QUEUEITEM_H
0011 
0012 #include <memory>
0013 #include <string>
0014 #include <vector>
0015 
0016 #include "lldb/lldb-enumerations.h"
0017 #include "lldb/lldb-forward.h"
0018 #include "lldb/lldb-private.h"
0019 
0020 #include "lldb/Core/Address.h"
0021 #include "lldb/Utility/ConstString.h"
0022 
0023 namespace lldb_private {
0024 
0025 // QueueItem:
0026 // This class represents a work item enqueued on a libdispatch aka Grand
0027 // Central Dispatch (GCD) queue.  Most often, this will be a function or block.
0028 // "enqueued" here means that the work item has been added to a queue but it
0029 // has not yet started executing.  When it is "dequeued", execution of the item
0030 // begins.
0031 
0032 class QueueItem : public std::enable_shared_from_this<QueueItem> {
0033 public:
0034   QueueItem(lldb::QueueSP queue_sp, lldb::ProcessSP process_sp,
0035             lldb::addr_t item_ref, lldb_private::Address address);
0036 
0037   ~QueueItem();
0038 
0039   /// Get the kind of work item this is
0040   ///
0041   /// \return
0042   ///     The type of work item that this QueueItem object
0043   ///     represents.  eQueueItemKindUnknown may be returned.
0044   lldb::QueueItemKind GetKind();
0045 
0046   /// Set the type of work item this is
0047   ///
0048   /// \param [in] item_kind
0049   ///     Set the kind of this work item object.
0050   void SetKind(lldb::QueueItemKind item_kind);
0051 
0052   /// Get the code address that will be executed when this work item
0053   /// is executed.
0054   ///
0055   /// \return
0056   ///     The address that will be invoked when this work item is
0057   ///     executed.  Not all types of QueueItems will have an
0058   ///     address associated with them; check that the returned
0059   ///     Address is valid, or check that the WorkItemKind is a
0060   ///     kind that involves an address, such as eQueueItemKindFunction
0061   ///     or eQueueItemKindBlock.
0062   lldb_private::Address &GetAddress();
0063 
0064   /// Set the work item address for this object
0065   ///
0066   /// \param [in] addr
0067   ///     The address that will be invoked when this work item
0068   ///     is executed.
0069   void SetAddress(lldb_private::Address addr);
0070 
0071   /// Check if this QueueItem object is valid
0072   ///
0073   /// If the weak pointer to the parent Queue cannot be revivified,
0074   /// it is invalid.
0075   ///
0076   /// \return
0077   ///     True if this object is valid.
0078   bool IsValid() { return m_queue_wp.lock() != nullptr; }
0079 
0080   /// Get an extended backtrace thread for this queue item, if available
0081   ///
0082   /// If the backtrace/thread information was collected when this item
0083   /// was enqueued, this call will provide it.
0084   ///
0085   /// \param [in] type
0086   ///     The type of extended backtrace being requested, e.g. "libdispatch"
0087   ///     or "pthread".
0088   ///
0089   /// \return
0090   ///     A thread shared pointer which will have a reference to an extended
0091   ///     thread if one was available.
0092   lldb::ThreadSP GetExtendedBacktraceThread(ConstString type);
0093 
0094   void SetItemThatEnqueuedThis(lldb::addr_t address_of_item) {
0095     m_item_that_enqueued_this_ref = address_of_item;
0096   }
0097 
0098   lldb::addr_t GetItemThatEnqueuedThis();
0099 
0100   void SetEnqueueingThreadID(lldb::tid_t tid) { m_enqueueing_thread_id = tid; }
0101 
0102   lldb::tid_t GetEnqueueingThreadID();
0103 
0104   void SetEnqueueingQueueID(lldb::queue_id_t qid) {
0105     m_enqueueing_queue_id = qid;
0106   }
0107 
0108   lldb::queue_id_t GetEnqueueingQueueID();
0109 
0110   void SetTargetQueueID(lldb::queue_id_t qid) { m_target_queue_id = qid; }
0111 
0112   void SetStopID(uint32_t stop_id) { m_stop_id = stop_id; }
0113 
0114   uint32_t GetStopID();
0115 
0116   void SetEnqueueingBacktrace(std::vector<lldb::addr_t> backtrace) {
0117     m_backtrace = backtrace;
0118   }
0119 
0120   std::vector<lldb::addr_t> &GetEnqueueingBacktrace();
0121 
0122   void SetThreadLabel(std::string thread_name) { m_thread_label = thread_name; }
0123 
0124   std::string GetThreadLabel();
0125 
0126   void SetQueueLabel(std::string queue_name) { m_queue_label = queue_name; }
0127 
0128   std::string GetQueueLabel();
0129 
0130   void SetTargetQueueLabel(std::string queue_name) {
0131     m_target_queue_label = queue_name;
0132   }
0133 
0134   lldb::ProcessSP GetProcessSP();
0135 
0136 protected:
0137   void FetchEntireItem();
0138 
0139   lldb::QueueWP m_queue_wp;
0140   lldb::ProcessWP m_process_wp;
0141 
0142   lldb::addr_t m_item_ref; // the token we can be used to fetch more information
0143                            // about this queue item
0144   lldb_private::Address m_address;
0145   bool m_have_fetched_entire_item;
0146 
0147   lldb::QueueItemKind m_kind;
0148   lldb::addr_t m_item_that_enqueued_this_ref; // a handle that we can pass into
0149                                               // libBacktraceRecording
0150   // to get the QueueItem that enqueued this item
0151   lldb::tid_t m_enqueueing_thread_id; // thread that enqueued this item
0152   lldb::queue_id_t
0153       m_enqueueing_queue_id; // Queue that enqueued this item, if it was a queue
0154   lldb::queue_id_t m_target_queue_id;
0155   uint32_t m_stop_id; // indicates when this backtrace was recorded in time
0156   std::vector<lldb::addr_t> m_backtrace;
0157   std::string m_thread_label;
0158   std::string m_queue_label;
0159   std::string m_target_queue_label;
0160 
0161 private:
0162   QueueItem(const QueueItem &) = delete;
0163   const QueueItem &operator=(const QueueItem &) = delete;
0164 };
0165 
0166 } // namespace lldb_private
0167 
0168 #endif // LLDB_TARGET_QUEUEITEM_H