| 1 | //===-- SBQueueItem.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/lldb-forward.h" |
| 10 | |
| 11 | #include "lldb/API/SBAddress.h" |
| 12 | #include "lldb/API/SBQueueItem.h" |
| 13 | #include "lldb/API/SBThread.h" |
| 14 | #include "lldb/Core/Address.h" |
| 15 | #include "lldb/Target/Process.h" |
| 16 | #include "lldb/Target/QueueItem.h" |
| 17 | #include "lldb/Target/Thread.h" |
| 18 | #include "lldb/Utility/Instrumentation.h" |
| 19 | |
| 20 | using namespace lldb; |
| 21 | using namespace lldb_private; |
| 22 | |
| 23 | // Constructors |
| 24 | SBQueueItem::SBQueueItem() { LLDB_INSTRUMENT_VA(this); } |
| 25 | |
| 26 | SBQueueItem::SBQueueItem(const QueueItemSP &queue_item_sp) |
| 27 | : m_queue_item_sp(queue_item_sp) { |
| 28 | LLDB_INSTRUMENT_VA(this, queue_item_sp); |
| 29 | } |
| 30 | |
| 31 | // Destructor |
| 32 | SBQueueItem::~SBQueueItem() { m_queue_item_sp.reset(); } |
| 33 | |
| 34 | bool SBQueueItem::IsValid() const { |
| 35 | LLDB_INSTRUMENT_VA(this); |
| 36 | return this->operator bool(); |
| 37 | } |
| 38 | SBQueueItem::operator bool() const { |
| 39 | LLDB_INSTRUMENT_VA(this); |
| 40 | |
| 41 | return m_queue_item_sp.get() != nullptr; |
| 42 | } |
| 43 | |
| 44 | void SBQueueItem::Clear() { |
| 45 | LLDB_INSTRUMENT_VA(this); |
| 46 | |
| 47 | m_queue_item_sp.reset(); |
| 48 | } |
| 49 | |
| 50 | void SBQueueItem::SetQueueItem(const QueueItemSP &queue_item_sp) { |
| 51 | LLDB_INSTRUMENT_VA(this, queue_item_sp); |
| 52 | |
| 53 | m_queue_item_sp = queue_item_sp; |
| 54 | } |
| 55 | |
| 56 | lldb::QueueItemKind SBQueueItem::GetKind() const { |
| 57 | LLDB_INSTRUMENT_VA(this); |
| 58 | |
| 59 | QueueItemKind result = eQueueItemKindUnknown; |
| 60 | if (m_queue_item_sp) { |
| 61 | result = m_queue_item_sp->GetKind(); |
| 62 | } |
| 63 | return result; |
| 64 | } |
| 65 | |
| 66 | void SBQueueItem::SetKind(lldb::QueueItemKind kind) { |
| 67 | LLDB_INSTRUMENT_VA(this, kind); |
| 68 | |
| 69 | if (m_queue_item_sp) { |
| 70 | m_queue_item_sp->SetKind(kind); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | SBAddress SBQueueItem::GetAddress() const { |
| 75 | LLDB_INSTRUMENT_VA(this); |
| 76 | |
| 77 | SBAddress result; |
| 78 | if (m_queue_item_sp) { |
| 79 | result.SetAddress(m_queue_item_sp->GetAddress()); |
| 80 | } |
| 81 | return result; |
| 82 | } |
| 83 | |
| 84 | void SBQueueItem::SetAddress(SBAddress addr) { |
| 85 | LLDB_INSTRUMENT_VA(this, addr); |
| 86 | |
| 87 | if (m_queue_item_sp) { |
| 88 | m_queue_item_sp->SetAddress(addr.ref()); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | SBThread SBQueueItem::GetExtendedBacktraceThread(const char *type) { |
| 93 | LLDB_INSTRUMENT_VA(this, type); |
| 94 | |
| 95 | SBThread result; |
| 96 | if (m_queue_item_sp) { |
| 97 | ProcessSP process_sp = m_queue_item_sp->GetProcessSP(); |
| 98 | Process::StopLocker stop_locker; |
| 99 | if (process_sp && stop_locker.TryLock(lock: &process_sp->GetRunLock())) { |
| 100 | ThreadSP thread_sp; |
| 101 | ConstString type_const(type); |
| 102 | thread_sp = m_queue_item_sp->GetExtendedBacktraceThread(type: type_const); |
| 103 | if (thread_sp) { |
| 104 | // Save this in the Process' ExtendedThreadList so a strong pointer |
| 105 | // retains the object |
| 106 | process_sp->GetExtendedThreadList().AddThread(thread_sp); |
| 107 | result.SetThread(thread_sp); |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | return result; |
| 112 | } |
| 113 |
