180814287SRaphael Isemann //===-- SBQueueItem.cpp ---------------------------------------------------===// 25e8dce4dSJason Molenda // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 65e8dce4dSJason Molenda // 75e8dce4dSJason Molenda //===----------------------------------------------------------------------===// 85e8dce4dSJason Molenda 95e8dce4dSJason Molenda #include "lldb/lldb-forward.h" 105e8dce4dSJason Molenda 11*d51402acSJonas Devlieghere #include "lldb/Utility/ReproducerInstrumentation.h" 125e8dce4dSJason Molenda #include "lldb/API/SBAddress.h" 135e8dce4dSJason Molenda #include "lldb/API/SBQueueItem.h" 145e8dce4dSJason Molenda #include "lldb/API/SBThread.h" 155e8dce4dSJason Molenda #include "lldb/Core/Address.h" 16a8ff543cSJason Molenda #include "lldb/Target/Process.h" 175e8dce4dSJason Molenda #include "lldb/Target/QueueItem.h" 182fd83355SJason Molenda #include "lldb/Target/Thread.h" 195e8dce4dSJason Molenda 205e8dce4dSJason Molenda using namespace lldb; 215e8dce4dSJason Molenda using namespace lldb_private; 225e8dce4dSJason Molenda 235e8dce4dSJason Molenda // Constructors 24a3436f73SKazu Hirata SBQueueItem::SBQueueItem() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBQueueItem); } 255e8dce4dSJason Molenda 26b9c1b51eSKate Stone SBQueueItem::SBQueueItem(const QueueItemSP &queue_item_sp) 27baf5664fSJonas Devlieghere : m_queue_item_sp(queue_item_sp) { 28baf5664fSJonas Devlieghere LLDB_RECORD_CONSTRUCTOR(SBQueueItem, (const lldb::QueueItemSP &), 29baf5664fSJonas Devlieghere queue_item_sp); 30baf5664fSJonas Devlieghere } 315e8dce4dSJason Molenda 325e8dce4dSJason Molenda // Destructor 33b9c1b51eSKate Stone SBQueueItem::~SBQueueItem() { m_queue_item_sp.reset(); } 345e8dce4dSJason Molenda 35b9c1b51eSKate Stone bool SBQueueItem::IsValid() const { 36baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBQueueItem, IsValid); 377f5237bcSPavel Labath return this->operator bool(); 387f5237bcSPavel Labath } 397f5237bcSPavel Labath SBQueueItem::operator bool() const { 407f5237bcSPavel Labath LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBQueueItem, operator bool); 41baf5664fSJonas Devlieghere 42248a1305SKonrad Kleine return m_queue_item_sp.get() != nullptr; 435e8dce4dSJason Molenda } 445e8dce4dSJason Molenda 45b9c1b51eSKate Stone void SBQueueItem::Clear() { 46baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_NO_ARGS(void, SBQueueItem, Clear); 47baf5664fSJonas Devlieghere 485e8dce4dSJason Molenda m_queue_item_sp.reset(); 495e8dce4dSJason Molenda } 505e8dce4dSJason Molenda 51b9c1b51eSKate Stone void SBQueueItem::SetQueueItem(const QueueItemSP &queue_item_sp) { 52baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(void, SBQueueItem, SetQueueItem, 53baf5664fSJonas Devlieghere (const lldb::QueueItemSP &), queue_item_sp); 54baf5664fSJonas Devlieghere 555e8dce4dSJason Molenda m_queue_item_sp = queue_item_sp; 565e8dce4dSJason Molenda } 575e8dce4dSJason Molenda 58b9c1b51eSKate Stone lldb::QueueItemKind SBQueueItem::GetKind() const { 59baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::QueueItemKind, SBQueueItem, GetKind); 60baf5664fSJonas Devlieghere 615e8dce4dSJason Molenda QueueItemKind result = eQueueItemKindUnknown; 62b9c1b51eSKate Stone if (m_queue_item_sp) { 635e8dce4dSJason Molenda result = m_queue_item_sp->GetKind(); 645e8dce4dSJason Molenda } 655e8dce4dSJason Molenda return result; 665e8dce4dSJason Molenda } 675e8dce4dSJason Molenda 68b9c1b51eSKate Stone void SBQueueItem::SetKind(lldb::QueueItemKind kind) { 69baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(void, SBQueueItem, SetKind, (lldb::QueueItemKind), kind); 70baf5664fSJonas Devlieghere 71b9c1b51eSKate Stone if (m_queue_item_sp) { 725e8dce4dSJason Molenda m_queue_item_sp->SetKind(kind); 735e8dce4dSJason Molenda } 745e8dce4dSJason Molenda } 755e8dce4dSJason Molenda 76b9c1b51eSKate Stone SBAddress SBQueueItem::GetAddress() const { 77baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBAddress, SBQueueItem, GetAddress); 78baf5664fSJonas Devlieghere 795e8dce4dSJason Molenda SBAddress result; 80b9c1b51eSKate Stone if (m_queue_item_sp) { 816cd4a4cdSJonas Devlieghere result.SetAddress(m_queue_item_sp->GetAddress()); 825e8dce4dSJason Molenda } 83baf5664fSJonas Devlieghere return LLDB_RECORD_RESULT(result); 845e8dce4dSJason Molenda } 855e8dce4dSJason Molenda 86b9c1b51eSKate Stone void SBQueueItem::SetAddress(SBAddress addr) { 87baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(void, SBQueueItem, SetAddress, (lldb::SBAddress), addr); 88baf5664fSJonas Devlieghere 89b9c1b51eSKate Stone if (m_queue_item_sp) { 905e8dce4dSJason Molenda m_queue_item_sp->SetAddress(addr.ref()); 915e8dce4dSJason Molenda } 925e8dce4dSJason Molenda } 935e8dce4dSJason Molenda 94b9c1b51eSKate Stone SBThread SBQueueItem::GetExtendedBacktraceThread(const char *type) { 95baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(lldb::SBThread, SBQueueItem, GetExtendedBacktraceThread, 96baf5664fSJonas Devlieghere (const char *), type); 97baf5664fSJonas Devlieghere 985e8dce4dSJason Molenda SBThread result; 99b9c1b51eSKate Stone if (m_queue_item_sp) { 100a8ff543cSJason Molenda ProcessSP process_sp = m_queue_item_sp->GetProcessSP(); 101a8ff543cSJason Molenda Process::StopLocker stop_locker; 102b9c1b51eSKate Stone if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) { 1035e8dce4dSJason Molenda ThreadSP thread_sp; 1045e8dce4dSJason Molenda ConstString type_const(type); 1055e8dce4dSJason Molenda thread_sp = m_queue_item_sp->GetExtendedBacktraceThread(type_const); 106b9c1b51eSKate Stone if (thread_sp) { 107b9c1b51eSKate Stone // Save this in the Process' ExtendedThreadList so a strong pointer 10805097246SAdrian Prantl // retains the object 109a8ff543cSJason Molenda process_sp->GetExtendedThreadList().AddThread(thread_sp); 1105e8dce4dSJason Molenda result.SetThread(thread_sp); 1115e8dce4dSJason Molenda } 1125e8dce4dSJason Molenda } 113a8ff543cSJason Molenda } 114baf5664fSJonas Devlieghere return LLDB_RECORD_RESULT(result); 1155e8dce4dSJason Molenda } 116