1cfca06d7SDimitry Andric //===-- QueueItem.cpp -----------------------------------------------------===//
2866dcdacSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6866dcdacSEd Maste //
7866dcdacSEd Maste //===----------------------------------------------------------------------===//
8866dcdacSEd Maste
9866dcdacSEd Maste #include "lldb/Target/Queue.h"
10866dcdacSEd Maste #include "lldb/Target/Process.h"
11866dcdacSEd Maste #include "lldb/Target/QueueItem.h"
12866dcdacSEd Maste #include "lldb/Target/SystemRuntime.h"
13866dcdacSEd Maste
14866dcdacSEd Maste using namespace lldb;
15866dcdacSEd Maste using namespace lldb_private;
16866dcdacSEd Maste
QueueItem(QueueSP queue_sp,ProcessSP process_sp,lldb::addr_t item_ref,lldb_private::Address address)1714f1b3e8SDimitry Andric QueueItem::QueueItem(QueueSP queue_sp, ProcessSP process_sp,
1814f1b3e8SDimitry Andric lldb::addr_t item_ref, lldb_private::Address address)
1914f1b3e8SDimitry Andric : m_queue_wp(), m_process_wp(), m_item_ref(item_ref), m_address(address),
2014f1b3e8SDimitry Andric m_have_fetched_entire_item(false), m_kind(eQueueItemKindUnknown),
21866dcdacSEd Maste m_item_that_enqueued_this_ref(LLDB_INVALID_ADDRESS),
22866dcdacSEd Maste m_enqueueing_thread_id(LLDB_INVALID_THREAD_ID),
23866dcdacSEd Maste m_enqueueing_queue_id(LLDB_INVALID_QUEUE_ID),
2414f1b3e8SDimitry Andric m_target_queue_id(LLDB_INVALID_QUEUE_ID), m_stop_id(0), m_backtrace(),
2514f1b3e8SDimitry Andric m_thread_label(), m_queue_label(), m_target_queue_label() {
26866dcdacSEd Maste m_queue_wp = queue_sp;
270cac4ca3SEd Maste m_process_wp = process_sp;
28866dcdacSEd Maste }
29866dcdacSEd Maste
30344a3780SDimitry Andric QueueItem::~QueueItem() = default;
31866dcdacSEd Maste
GetKind()3214f1b3e8SDimitry Andric QueueItemKind QueueItem::GetKind() {
330cac4ca3SEd Maste FetchEntireItem();
34866dcdacSEd Maste return m_kind;
35866dcdacSEd Maste }
36866dcdacSEd Maste
SetKind(QueueItemKind item_kind)3714f1b3e8SDimitry Andric void QueueItem::SetKind(QueueItemKind item_kind) { m_kind = item_kind; }
38866dcdacSEd Maste
GetAddress()3914f1b3e8SDimitry Andric Address &QueueItem::GetAddress() { return m_address; }
40866dcdacSEd Maste
SetAddress(Address addr)4114f1b3e8SDimitry Andric void QueueItem::SetAddress(Address addr) { m_address = addr; }
42866dcdacSEd Maste
GetExtendedBacktraceThread(ConstString type)4314f1b3e8SDimitry Andric ThreadSP QueueItem::GetExtendedBacktraceThread(ConstString type) {
440cac4ca3SEd Maste FetchEntireItem();
45866dcdacSEd Maste ThreadSP return_thread;
46866dcdacSEd Maste QueueSP queue_sp = m_queue_wp.lock();
4714f1b3e8SDimitry Andric if (queue_sp) {
48866dcdacSEd Maste ProcessSP process_sp = queue_sp->GetProcess();
4914f1b3e8SDimitry Andric if (process_sp && process_sp->GetSystemRuntime()) {
5014f1b3e8SDimitry Andric return_thread =
5114f1b3e8SDimitry Andric process_sp->GetSystemRuntime()->GetExtendedBacktraceForQueueItem(
5214f1b3e8SDimitry Andric this->shared_from_this(), type);
53866dcdacSEd Maste }
54866dcdacSEd Maste }
55866dcdacSEd Maste return return_thread;
56866dcdacSEd Maste }
570cac4ca3SEd Maste
GetItemThatEnqueuedThis()5814f1b3e8SDimitry Andric lldb::addr_t QueueItem::GetItemThatEnqueuedThis() {
590cac4ca3SEd Maste FetchEntireItem();
600cac4ca3SEd Maste return m_item_that_enqueued_this_ref;
610cac4ca3SEd Maste }
620cac4ca3SEd Maste
GetEnqueueingThreadID()6314f1b3e8SDimitry Andric lldb::tid_t QueueItem::GetEnqueueingThreadID() {
640cac4ca3SEd Maste FetchEntireItem();
650cac4ca3SEd Maste return m_enqueueing_thread_id;
660cac4ca3SEd Maste }
670cac4ca3SEd Maste
GetEnqueueingQueueID()6814f1b3e8SDimitry Andric lldb::queue_id_t QueueItem::GetEnqueueingQueueID() {
690cac4ca3SEd Maste FetchEntireItem();
700cac4ca3SEd Maste return m_enqueueing_queue_id;
710cac4ca3SEd Maste }
720cac4ca3SEd Maste
GetStopID()7314f1b3e8SDimitry Andric uint32_t QueueItem::GetStopID() {
740cac4ca3SEd Maste FetchEntireItem();
750cac4ca3SEd Maste return m_stop_id;
760cac4ca3SEd Maste }
770cac4ca3SEd Maste
GetEnqueueingBacktrace()7814f1b3e8SDimitry Andric std::vector<lldb::addr_t> &QueueItem::GetEnqueueingBacktrace() {
790cac4ca3SEd Maste FetchEntireItem();
800cac4ca3SEd Maste return m_backtrace;
810cac4ca3SEd Maste }
820cac4ca3SEd Maste
GetThreadLabel()8314f1b3e8SDimitry Andric std::string QueueItem::GetThreadLabel() {
840cac4ca3SEd Maste FetchEntireItem();
850cac4ca3SEd Maste return m_thread_label;
860cac4ca3SEd Maste }
870cac4ca3SEd Maste
GetQueueLabel()8814f1b3e8SDimitry Andric std::string QueueItem::GetQueueLabel() {
890cac4ca3SEd Maste FetchEntireItem();
900cac4ca3SEd Maste return m_queue_label;
910cac4ca3SEd Maste }
920cac4ca3SEd Maste
GetProcessSP()9314f1b3e8SDimitry Andric ProcessSP QueueItem::GetProcessSP() { return m_process_wp.lock(); }
940cac4ca3SEd Maste
FetchEntireItem()9514f1b3e8SDimitry Andric void QueueItem::FetchEntireItem() {
9694994d37SDimitry Andric if (m_have_fetched_entire_item)
970cac4ca3SEd Maste return;
980cac4ca3SEd Maste ProcessSP process_sp = m_process_wp.lock();
9914f1b3e8SDimitry Andric if (process_sp) {
1000cac4ca3SEd Maste SystemRuntime *runtime = process_sp->GetSystemRuntime();
10114f1b3e8SDimitry Andric if (runtime) {
1020cac4ca3SEd Maste runtime->CompleteQueueItem(this, m_item_ref);
1030cac4ca3SEd Maste m_have_fetched_entire_item = true;
1040cac4ca3SEd Maste }
1050cac4ca3SEd Maste }
1060cac4ca3SEd Maste }
107