15ffd83dbSDimitry Andric //===-- SBQueueItem.cpp ---------------------------------------------------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric #include "lldb/lldb-forward.h" 100b57cec5SDimitry Andric 110b57cec5SDimitry Andric #include "lldb/API/SBAddress.h" 120b57cec5SDimitry Andric #include "lldb/API/SBQueueItem.h" 130b57cec5SDimitry Andric #include "lldb/API/SBThread.h" 140b57cec5SDimitry Andric #include "lldb/Core/Address.h" 150b57cec5SDimitry Andric #include "lldb/Target/Process.h" 160b57cec5SDimitry Andric #include "lldb/Target/QueueItem.h" 170b57cec5SDimitry Andric #include "lldb/Target/Thread.h" 18*04eeddc0SDimitry Andric #include "lldb/Utility/Instrumentation.h" 190b57cec5SDimitry Andric 200b57cec5SDimitry Andric using namespace lldb; 210b57cec5SDimitry Andric using namespace lldb_private; 220b57cec5SDimitry Andric 230b57cec5SDimitry Andric // Constructors SBQueueItem()24*04eeddc0SDimitry AndricSBQueueItem::SBQueueItem() { LLDB_INSTRUMENT_VA(this); } 250b57cec5SDimitry Andric SBQueueItem(const QueueItemSP & queue_item_sp)260b57cec5SDimitry AndricSBQueueItem::SBQueueItem(const QueueItemSP &queue_item_sp) 270b57cec5SDimitry Andric : m_queue_item_sp(queue_item_sp) { 28*04eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, queue_item_sp); 290b57cec5SDimitry Andric } 300b57cec5SDimitry Andric 310b57cec5SDimitry Andric // Destructor ~SBQueueItem()320b57cec5SDimitry AndricSBQueueItem::~SBQueueItem() { m_queue_item_sp.reset(); } 330b57cec5SDimitry Andric IsValid() const340b57cec5SDimitry Andricbool SBQueueItem::IsValid() const { 35*04eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this); 360b57cec5SDimitry Andric return this->operator bool(); 370b57cec5SDimitry Andric } operator bool() const380b57cec5SDimitry AndricSBQueueItem::operator bool() const { 39*04eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this); 400b57cec5SDimitry Andric 410b57cec5SDimitry Andric return m_queue_item_sp.get() != nullptr; 420b57cec5SDimitry Andric } 430b57cec5SDimitry Andric Clear()440b57cec5SDimitry Andricvoid SBQueueItem::Clear() { 45*04eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this); 460b57cec5SDimitry Andric 470b57cec5SDimitry Andric m_queue_item_sp.reset(); 480b57cec5SDimitry Andric } 490b57cec5SDimitry Andric SetQueueItem(const QueueItemSP & queue_item_sp)500b57cec5SDimitry Andricvoid SBQueueItem::SetQueueItem(const QueueItemSP &queue_item_sp) { 51*04eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, queue_item_sp); 520b57cec5SDimitry Andric 530b57cec5SDimitry Andric m_queue_item_sp = queue_item_sp; 540b57cec5SDimitry Andric } 550b57cec5SDimitry Andric GetKind() const560b57cec5SDimitry Andriclldb::QueueItemKind SBQueueItem::GetKind() const { 57*04eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this); 580b57cec5SDimitry Andric 590b57cec5SDimitry Andric QueueItemKind result = eQueueItemKindUnknown; 600b57cec5SDimitry Andric if (m_queue_item_sp) { 610b57cec5SDimitry Andric result = m_queue_item_sp->GetKind(); 620b57cec5SDimitry Andric } 630b57cec5SDimitry Andric return result; 640b57cec5SDimitry Andric } 650b57cec5SDimitry Andric SetKind(lldb::QueueItemKind kind)660b57cec5SDimitry Andricvoid SBQueueItem::SetKind(lldb::QueueItemKind kind) { 67*04eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, kind); 680b57cec5SDimitry Andric 690b57cec5SDimitry Andric if (m_queue_item_sp) { 700b57cec5SDimitry Andric m_queue_item_sp->SetKind(kind); 710b57cec5SDimitry Andric } 720b57cec5SDimitry Andric } 730b57cec5SDimitry Andric GetAddress() const740b57cec5SDimitry AndricSBAddress SBQueueItem::GetAddress() const { 75*04eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this); 760b57cec5SDimitry Andric 770b57cec5SDimitry Andric SBAddress result; 780b57cec5SDimitry Andric if (m_queue_item_sp) { 79e8d8bef9SDimitry Andric result.SetAddress(m_queue_item_sp->GetAddress()); 800b57cec5SDimitry Andric } 81*04eeddc0SDimitry Andric return result; 820b57cec5SDimitry Andric } 830b57cec5SDimitry Andric SetAddress(SBAddress addr)840b57cec5SDimitry Andricvoid SBQueueItem::SetAddress(SBAddress addr) { 85*04eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, addr); 860b57cec5SDimitry Andric 870b57cec5SDimitry Andric if (m_queue_item_sp) { 880b57cec5SDimitry Andric m_queue_item_sp->SetAddress(addr.ref()); 890b57cec5SDimitry Andric } 900b57cec5SDimitry Andric } 910b57cec5SDimitry Andric GetExtendedBacktraceThread(const char * type)920b57cec5SDimitry AndricSBThread SBQueueItem::GetExtendedBacktraceThread(const char *type) { 93*04eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, type); 940b57cec5SDimitry Andric 950b57cec5SDimitry Andric SBThread result; 960b57cec5SDimitry Andric if (m_queue_item_sp) { 970b57cec5SDimitry Andric ProcessSP process_sp = m_queue_item_sp->GetProcessSP(); 980b57cec5SDimitry Andric Process::StopLocker stop_locker; 990b57cec5SDimitry Andric if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) { 1000b57cec5SDimitry Andric ThreadSP thread_sp; 1010b57cec5SDimitry Andric ConstString type_const(type); 1020b57cec5SDimitry Andric thread_sp = m_queue_item_sp->GetExtendedBacktraceThread(type_const); 1030b57cec5SDimitry Andric if (thread_sp) { 1040b57cec5SDimitry Andric // Save this in the Process' ExtendedThreadList so a strong pointer 1050b57cec5SDimitry Andric // retains the object 1060b57cec5SDimitry Andric process_sp->GetExtendedThreadList().AddThread(thread_sp); 1070b57cec5SDimitry Andric result.SetThread(thread_sp); 1080b57cec5SDimitry Andric } 1090b57cec5SDimitry Andric } 1100b57cec5SDimitry Andric } 111*04eeddc0SDimitry Andric return result; 1120b57cec5SDimitry Andric } 113