xref: /src/contrib/llvm-project/lldb/source/API/SBQueueItem.cpp (revision 04eeddc0aa8e0a417a16eaf9d7d095207f4a8623)
1cfca06d7SDimitry Andric //===-- SBQueueItem.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/lldb-forward.h"
10866dcdacSEd Maste 
11866dcdacSEd Maste #include "lldb/API/SBAddress.h"
12866dcdacSEd Maste #include "lldb/API/SBQueueItem.h"
13866dcdacSEd Maste #include "lldb/API/SBThread.h"
14866dcdacSEd Maste #include "lldb/Core/Address.h"
150cac4ca3SEd Maste #include "lldb/Target/Process.h"
16866dcdacSEd Maste #include "lldb/Target/QueueItem.h"
17866dcdacSEd Maste #include "lldb/Target/Thread.h"
186f8fc217SDimitry Andric #include "lldb/Utility/Instrumentation.h"
19866dcdacSEd Maste 
20866dcdacSEd Maste using namespace lldb;
21866dcdacSEd Maste using namespace lldb_private;
22866dcdacSEd Maste 
23866dcdacSEd Maste // Constructors
SBQueueItem()246f8fc217SDimitry Andric SBQueueItem::SBQueueItem() { LLDB_INSTRUMENT_VA(this); }
25866dcdacSEd Maste 
SBQueueItem(const QueueItemSP & queue_item_sp)2614f1b3e8SDimitry Andric SBQueueItem::SBQueueItem(const QueueItemSP &queue_item_sp)
275f29bb8aSDimitry Andric     : m_queue_item_sp(queue_item_sp) {
286f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, queue_item_sp);
295f29bb8aSDimitry Andric }
30866dcdacSEd Maste 
31866dcdacSEd Maste // Destructor
~SBQueueItem()3214f1b3e8SDimitry Andric SBQueueItem::~SBQueueItem() { m_queue_item_sp.reset(); }
33866dcdacSEd Maste 
IsValid() const3414f1b3e8SDimitry Andric bool SBQueueItem::IsValid() const {
356f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
365f29bb8aSDimitry Andric   return this->operator bool();
375f29bb8aSDimitry Andric }
operator bool() const385f29bb8aSDimitry Andric SBQueueItem::operator bool() const {
396f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
405f29bb8aSDimitry Andric 
415f29bb8aSDimitry Andric   return m_queue_item_sp.get() != nullptr;
42866dcdacSEd Maste }
43866dcdacSEd Maste 
Clear()4414f1b3e8SDimitry Andric void SBQueueItem::Clear() {
456f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
465f29bb8aSDimitry Andric 
47866dcdacSEd Maste   m_queue_item_sp.reset();
48866dcdacSEd Maste }
49866dcdacSEd Maste 
SetQueueItem(const QueueItemSP & queue_item_sp)5014f1b3e8SDimitry Andric void SBQueueItem::SetQueueItem(const QueueItemSP &queue_item_sp) {
516f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, queue_item_sp);
525f29bb8aSDimitry Andric 
53866dcdacSEd Maste   m_queue_item_sp = queue_item_sp;
54866dcdacSEd Maste }
55866dcdacSEd Maste 
GetKind() const5614f1b3e8SDimitry Andric lldb::QueueItemKind SBQueueItem::GetKind() const {
576f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
585f29bb8aSDimitry Andric 
59866dcdacSEd Maste   QueueItemKind result = eQueueItemKindUnknown;
6014f1b3e8SDimitry Andric   if (m_queue_item_sp) {
61866dcdacSEd Maste     result = m_queue_item_sp->GetKind();
62866dcdacSEd Maste   }
63866dcdacSEd Maste   return result;
64866dcdacSEd Maste }
65866dcdacSEd Maste 
SetKind(lldb::QueueItemKind kind)6614f1b3e8SDimitry Andric void SBQueueItem::SetKind(lldb::QueueItemKind kind) {
676f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, kind);
685f29bb8aSDimitry Andric 
6914f1b3e8SDimitry Andric   if (m_queue_item_sp) {
70866dcdacSEd Maste     m_queue_item_sp->SetKind(kind);
71866dcdacSEd Maste   }
72866dcdacSEd Maste }
73866dcdacSEd Maste 
GetAddress() const7414f1b3e8SDimitry Andric SBAddress SBQueueItem::GetAddress() const {
756f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
765f29bb8aSDimitry Andric 
77866dcdacSEd Maste   SBAddress result;
7814f1b3e8SDimitry Andric   if (m_queue_item_sp) {
79b60736ecSDimitry Andric     result.SetAddress(m_queue_item_sp->GetAddress());
80866dcdacSEd Maste   }
816f8fc217SDimitry Andric   return result;
82866dcdacSEd Maste }
83866dcdacSEd Maste 
SetAddress(SBAddress addr)8414f1b3e8SDimitry Andric void SBQueueItem::SetAddress(SBAddress addr) {
856f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, addr);
865f29bb8aSDimitry Andric 
8714f1b3e8SDimitry Andric   if (m_queue_item_sp) {
88866dcdacSEd Maste     m_queue_item_sp->SetAddress(addr.ref());
89866dcdacSEd Maste   }
90866dcdacSEd Maste }
91866dcdacSEd Maste 
GetExtendedBacktraceThread(const char * type)9214f1b3e8SDimitry Andric SBThread SBQueueItem::GetExtendedBacktraceThread(const char *type) {
936f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, type);
945f29bb8aSDimitry Andric 
95866dcdacSEd Maste   SBThread result;
9614f1b3e8SDimitry Andric   if (m_queue_item_sp) {
970cac4ca3SEd Maste     ProcessSP process_sp = m_queue_item_sp->GetProcessSP();
980cac4ca3SEd Maste     Process::StopLocker stop_locker;
9914f1b3e8SDimitry Andric     if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) {
100866dcdacSEd Maste       ThreadSP thread_sp;
101866dcdacSEd Maste       ConstString type_const(type);
102866dcdacSEd Maste       thread_sp = m_queue_item_sp->GetExtendedBacktraceThread(type_const);
10314f1b3e8SDimitry Andric       if (thread_sp) {
10414f1b3e8SDimitry Andric         // Save this in the Process' ExtendedThreadList so a strong pointer
105f73363f1SDimitry Andric         // retains the object
1060cac4ca3SEd Maste         process_sp->GetExtendedThreadList().AddThread(thread_sp);
107866dcdacSEd Maste         result.SetThread(thread_sp);
1080cac4ca3SEd Maste       }
1090cac4ca3SEd Maste     }
110866dcdacSEd Maste   }
1116f8fc217SDimitry Andric   return result;
112866dcdacSEd Maste }
113