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
20using namespace lldb;
21using namespace lldb_private;
22
23// Constructors
24SBQueueItem::SBQueueItem() { LLDB_INSTRUMENT_VA(this); }
25
26SBQueueItem::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
32SBQueueItem::~SBQueueItem() { m_queue_item_sp.reset(); }
33
34bool SBQueueItem::IsValid() const {
35 LLDB_INSTRUMENT_VA(this);
36 return this->operator bool();
37}
38SBQueueItem::operator bool() const {
39 LLDB_INSTRUMENT_VA(this);
40
41 return m_queue_item_sp.get() != nullptr;
42}
43
44void SBQueueItem::Clear() {
45 LLDB_INSTRUMENT_VA(this);
46
47 m_queue_item_sp.reset();
48}
49
50void 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
56lldb::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
66void 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
74SBAddress 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
84void 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
92SBThread 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

source code of lldb/source/API/SBQueueItem.cpp