112b93ac6SEd Maste //===-- QueueItem.cpp -------------------------------------------*- C++ -*-===// 212b93ac6SEd Maste // 312b93ac6SEd Maste // The LLVM Compiler Infrastructure 412b93ac6SEd Maste // 512b93ac6SEd Maste // This file is distributed under the University of Illinois Open Source 612b93ac6SEd Maste // License. See LICENSE.TXT for details. 712b93ac6SEd Maste // 812b93ac6SEd Maste //===----------------------------------------------------------------------===// 912b93ac6SEd Maste 1012b93ac6SEd Maste #include "lldb/Target/Queue.h" 1112b93ac6SEd Maste #include "lldb/Target/Process.h" 1212b93ac6SEd Maste #include "lldb/Target/QueueItem.h" 1312b93ac6SEd Maste #include "lldb/Target/SystemRuntime.h" 1412b93ac6SEd Maste 1512b93ac6SEd Maste using namespace lldb; 1612b93ac6SEd Maste using namespace lldb_private; 1712b93ac6SEd Maste 18435933ddSDimitry Andric QueueItem::QueueItem(QueueSP queue_sp, ProcessSP process_sp, 19435933ddSDimitry Andric lldb::addr_t item_ref, lldb_private::Address address) 20435933ddSDimitry Andric : m_queue_wp(), m_process_wp(), m_item_ref(item_ref), m_address(address), 21435933ddSDimitry Andric m_have_fetched_entire_item(false), m_kind(eQueueItemKindUnknown), 2212b93ac6SEd Maste m_item_that_enqueued_this_ref(LLDB_INVALID_ADDRESS), 2312b93ac6SEd Maste m_enqueueing_thread_id(LLDB_INVALID_THREAD_ID), 2412b93ac6SEd Maste m_enqueueing_queue_id(LLDB_INVALID_QUEUE_ID), 25435933ddSDimitry Andric m_target_queue_id(LLDB_INVALID_QUEUE_ID), m_stop_id(0), m_backtrace(), 26435933ddSDimitry Andric m_thread_label(), m_queue_label(), m_target_queue_label() { 2712b93ac6SEd Maste m_queue_wp = queue_sp; 280127ef0fSEd Maste m_process_wp = process_sp; 2912b93ac6SEd Maste } 3012b93ac6SEd Maste 31435933ddSDimitry Andric QueueItem::~QueueItem() {} 3212b93ac6SEd Maste 33435933ddSDimitry Andric QueueItemKind QueueItem::GetKind() { 340127ef0fSEd Maste FetchEntireItem(); 3512b93ac6SEd Maste return m_kind; 3612b93ac6SEd Maste } 3712b93ac6SEd Maste 38435933ddSDimitry Andric void QueueItem::SetKind(QueueItemKind item_kind) { m_kind = item_kind; } 3912b93ac6SEd Maste 40435933ddSDimitry Andric Address &QueueItem::GetAddress() { return m_address; } 4112b93ac6SEd Maste 42435933ddSDimitry Andric void QueueItem::SetAddress(Address addr) { m_address = addr; } 4312b93ac6SEd Maste 44435933ddSDimitry Andric ThreadSP QueueItem::GetExtendedBacktraceThread(ConstString type) { 450127ef0fSEd Maste FetchEntireItem(); 4612b93ac6SEd Maste ThreadSP return_thread; 4712b93ac6SEd Maste QueueSP queue_sp = m_queue_wp.lock(); 48435933ddSDimitry Andric if (queue_sp) { 4912b93ac6SEd Maste ProcessSP process_sp = queue_sp->GetProcess(); 50435933ddSDimitry Andric if (process_sp && process_sp->GetSystemRuntime()) { 51435933ddSDimitry Andric return_thread = 52435933ddSDimitry Andric process_sp->GetSystemRuntime()->GetExtendedBacktraceForQueueItem( 53435933ddSDimitry Andric this->shared_from_this(), type); 5412b93ac6SEd Maste } 5512b93ac6SEd Maste } 5612b93ac6SEd Maste return return_thread; 5712b93ac6SEd Maste } 580127ef0fSEd Maste 59435933ddSDimitry Andric lldb::addr_t QueueItem::GetItemThatEnqueuedThis() { 600127ef0fSEd Maste FetchEntireItem(); 610127ef0fSEd Maste return m_item_that_enqueued_this_ref; 620127ef0fSEd Maste } 630127ef0fSEd Maste 64435933ddSDimitry Andric lldb::tid_t QueueItem::GetEnqueueingThreadID() { 650127ef0fSEd Maste FetchEntireItem(); 660127ef0fSEd Maste return m_enqueueing_thread_id; 670127ef0fSEd Maste } 680127ef0fSEd Maste 69435933ddSDimitry Andric lldb::queue_id_t QueueItem::GetEnqueueingQueueID() { 700127ef0fSEd Maste FetchEntireItem(); 710127ef0fSEd Maste return m_enqueueing_queue_id; 720127ef0fSEd Maste } 730127ef0fSEd Maste 74435933ddSDimitry Andric uint32_t QueueItem::GetStopID() { 750127ef0fSEd Maste FetchEntireItem(); 760127ef0fSEd Maste return m_stop_id; 770127ef0fSEd Maste } 780127ef0fSEd Maste 79435933ddSDimitry Andric std::vector<lldb::addr_t> &QueueItem::GetEnqueueingBacktrace() { 800127ef0fSEd Maste FetchEntireItem(); 810127ef0fSEd Maste return m_backtrace; 820127ef0fSEd Maste } 830127ef0fSEd Maste 84435933ddSDimitry Andric std::string QueueItem::GetThreadLabel() { 850127ef0fSEd Maste FetchEntireItem(); 860127ef0fSEd Maste return m_thread_label; 870127ef0fSEd Maste } 880127ef0fSEd Maste 89435933ddSDimitry Andric std::string QueueItem::GetQueueLabel() { 900127ef0fSEd Maste FetchEntireItem(); 910127ef0fSEd Maste return m_queue_label; 920127ef0fSEd Maste } 930127ef0fSEd Maste 94435933ddSDimitry Andric ProcessSP QueueItem::GetProcessSP() { return m_process_wp.lock(); } 950127ef0fSEd Maste 96435933ddSDimitry Andric void QueueItem::FetchEntireItem() { 970127ef0fSEd Maste if (m_have_fetched_entire_item == true) 980127ef0fSEd Maste return; 990127ef0fSEd Maste ProcessSP process_sp = m_process_wp.lock(); 100435933ddSDimitry Andric if (process_sp) { 1010127ef0fSEd Maste SystemRuntime *runtime = process_sp->GetSystemRuntime(); 102435933ddSDimitry Andric if (runtime) { 1030127ef0fSEd Maste runtime->CompleteQueueItem(this, m_item_ref); 1040127ef0fSEd Maste m_have_fetched_entire_item = true; 1050127ef0fSEd Maste } 1060127ef0fSEd Maste } 1070127ef0fSEd Maste } 108