• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- QueueItem.cpp -----------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "lldb/Target/Queue.h"
10 #include "lldb/Target/Process.h"
11 #include "lldb/Target/QueueItem.h"
12 #include "lldb/Target/SystemRuntime.h"
13 
14 using namespace lldb;
15 using namespace lldb_private;
16 
QueueItem(QueueSP queue_sp,ProcessSP process_sp,lldb::addr_t item_ref,lldb_private::Address address)17 QueueItem::QueueItem(QueueSP queue_sp, ProcessSP process_sp,
18                      lldb::addr_t item_ref, lldb_private::Address address)
19     : m_queue_wp(), m_process_wp(), m_item_ref(item_ref), m_address(address),
20       m_have_fetched_entire_item(false), m_kind(eQueueItemKindUnknown),
21       m_item_that_enqueued_this_ref(LLDB_INVALID_ADDRESS),
22       m_enqueueing_thread_id(LLDB_INVALID_THREAD_ID),
23       m_enqueueing_queue_id(LLDB_INVALID_QUEUE_ID),
24       m_target_queue_id(LLDB_INVALID_QUEUE_ID), m_stop_id(0), m_backtrace(),
25       m_thread_label(), m_queue_label(), m_target_queue_label() {
26   m_queue_wp = queue_sp;
27   m_process_wp = process_sp;
28 }
29 
~QueueItem()30 QueueItem::~QueueItem() {}
31 
GetKind()32 QueueItemKind QueueItem::GetKind() {
33   FetchEntireItem();
34   return m_kind;
35 }
36 
SetKind(QueueItemKind item_kind)37 void QueueItem::SetKind(QueueItemKind item_kind) { m_kind = item_kind; }
38 
GetAddress()39 Address &QueueItem::GetAddress() { return m_address; }
40 
SetAddress(Address addr)41 void QueueItem::SetAddress(Address addr) { m_address = addr; }
42 
GetExtendedBacktraceThread(ConstString type)43 ThreadSP QueueItem::GetExtendedBacktraceThread(ConstString type) {
44   FetchEntireItem();
45   ThreadSP return_thread;
46   QueueSP queue_sp = m_queue_wp.lock();
47   if (queue_sp) {
48     ProcessSP process_sp = queue_sp->GetProcess();
49     if (process_sp && process_sp->GetSystemRuntime()) {
50       return_thread =
51           process_sp->GetSystemRuntime()->GetExtendedBacktraceForQueueItem(
52               this->shared_from_this(), type);
53     }
54   }
55   return return_thread;
56 }
57 
GetItemThatEnqueuedThis()58 lldb::addr_t QueueItem::GetItemThatEnqueuedThis() {
59   FetchEntireItem();
60   return m_item_that_enqueued_this_ref;
61 }
62 
GetEnqueueingThreadID()63 lldb::tid_t QueueItem::GetEnqueueingThreadID() {
64   FetchEntireItem();
65   return m_enqueueing_thread_id;
66 }
67 
GetEnqueueingQueueID()68 lldb::queue_id_t QueueItem::GetEnqueueingQueueID() {
69   FetchEntireItem();
70   return m_enqueueing_queue_id;
71 }
72 
GetStopID()73 uint32_t QueueItem::GetStopID() {
74   FetchEntireItem();
75   return m_stop_id;
76 }
77 
GetEnqueueingBacktrace()78 std::vector<lldb::addr_t> &QueueItem::GetEnqueueingBacktrace() {
79   FetchEntireItem();
80   return m_backtrace;
81 }
82 
GetThreadLabel()83 std::string QueueItem::GetThreadLabel() {
84   FetchEntireItem();
85   return m_thread_label;
86 }
87 
GetQueueLabel()88 std::string QueueItem::GetQueueLabel() {
89   FetchEntireItem();
90   return m_queue_label;
91 }
92 
GetProcessSP()93 ProcessSP QueueItem::GetProcessSP() { return m_process_wp.lock(); }
94 
FetchEntireItem()95 void QueueItem::FetchEntireItem() {
96   if (m_have_fetched_entire_item)
97     return;
98   ProcessSP process_sp = m_process_wp.lock();
99   if (process_sp) {
100     SystemRuntime *runtime = process_sp->GetSystemRuntime();
101     if (runtime) {
102       runtime->CompleteQueueItem(this, m_item_ref);
103       m_have_fetched_entire_item = true;
104     }
105   }
106 }
107