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 11baf5664fSJonas Devlieghere #include "SBReproducerPrivate.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 24baf5664fSJonas Devlieghere SBQueueItem::SBQueueItem() : m_queue_item_sp() { 25baf5664fSJonas Devlieghere LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBQueueItem); 26baf5664fSJonas Devlieghere } 275e8dce4dSJason Molenda 28b9c1b51eSKate Stone SBQueueItem::SBQueueItem(const QueueItemSP &queue_item_sp) 29baf5664fSJonas Devlieghere : m_queue_item_sp(queue_item_sp) { 30baf5664fSJonas Devlieghere LLDB_RECORD_CONSTRUCTOR(SBQueueItem, (const lldb::QueueItemSP &), 31baf5664fSJonas Devlieghere queue_item_sp); 32baf5664fSJonas Devlieghere } 335e8dce4dSJason Molenda 345e8dce4dSJason Molenda // Destructor 35b9c1b51eSKate Stone SBQueueItem::~SBQueueItem() { m_queue_item_sp.reset(); } 365e8dce4dSJason Molenda 37b9c1b51eSKate Stone bool SBQueueItem::IsValid() const { 38baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBQueueItem, IsValid); 397f5237bcSPavel Labath return this->operator bool(); 407f5237bcSPavel Labath } 417f5237bcSPavel Labath SBQueueItem::operator bool() const { 427f5237bcSPavel Labath LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBQueueItem, operator bool); 43baf5664fSJonas Devlieghere 44248a1305SKonrad Kleine return m_queue_item_sp.get() != nullptr; 455e8dce4dSJason Molenda } 465e8dce4dSJason Molenda 47b9c1b51eSKate Stone void SBQueueItem::Clear() { 48baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_NO_ARGS(void, SBQueueItem, Clear); 49baf5664fSJonas Devlieghere 505e8dce4dSJason Molenda m_queue_item_sp.reset(); 515e8dce4dSJason Molenda } 525e8dce4dSJason Molenda 53b9c1b51eSKate Stone void SBQueueItem::SetQueueItem(const QueueItemSP &queue_item_sp) { 54baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(void, SBQueueItem, SetQueueItem, 55baf5664fSJonas Devlieghere (const lldb::QueueItemSP &), queue_item_sp); 56baf5664fSJonas Devlieghere 575e8dce4dSJason Molenda m_queue_item_sp = queue_item_sp; 585e8dce4dSJason Molenda } 595e8dce4dSJason Molenda 60b9c1b51eSKate Stone lldb::QueueItemKind SBQueueItem::GetKind() const { 61baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::QueueItemKind, SBQueueItem, GetKind); 62baf5664fSJonas Devlieghere 635e8dce4dSJason Molenda QueueItemKind result = eQueueItemKindUnknown; 64b9c1b51eSKate Stone if (m_queue_item_sp) { 655e8dce4dSJason Molenda result = m_queue_item_sp->GetKind(); 665e8dce4dSJason Molenda } 675e8dce4dSJason Molenda return result; 685e8dce4dSJason Molenda } 695e8dce4dSJason Molenda 70b9c1b51eSKate Stone void SBQueueItem::SetKind(lldb::QueueItemKind kind) { 71baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(void, SBQueueItem, SetKind, (lldb::QueueItemKind), kind); 72baf5664fSJonas Devlieghere 73b9c1b51eSKate Stone if (m_queue_item_sp) { 745e8dce4dSJason Molenda m_queue_item_sp->SetKind(kind); 755e8dce4dSJason Molenda } 765e8dce4dSJason Molenda } 775e8dce4dSJason Molenda 78b9c1b51eSKate Stone SBAddress SBQueueItem::GetAddress() const { 79baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBAddress, SBQueueItem, GetAddress); 80baf5664fSJonas Devlieghere 815e8dce4dSJason Molenda SBAddress result; 82b9c1b51eSKate Stone if (m_queue_item_sp) { 83*6cd4a4cdSJonas Devlieghere result.SetAddress(m_queue_item_sp->GetAddress()); 845e8dce4dSJason Molenda } 85baf5664fSJonas Devlieghere return LLDB_RECORD_RESULT(result); 865e8dce4dSJason Molenda } 875e8dce4dSJason Molenda 88b9c1b51eSKate Stone void SBQueueItem::SetAddress(SBAddress addr) { 89baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(void, SBQueueItem, SetAddress, (lldb::SBAddress), addr); 90baf5664fSJonas Devlieghere 91b9c1b51eSKate Stone if (m_queue_item_sp) { 925e8dce4dSJason Molenda m_queue_item_sp->SetAddress(addr.ref()); 935e8dce4dSJason Molenda } 945e8dce4dSJason Molenda } 955e8dce4dSJason Molenda 96b9c1b51eSKate Stone SBThread SBQueueItem::GetExtendedBacktraceThread(const char *type) { 97baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(lldb::SBThread, SBQueueItem, GetExtendedBacktraceThread, 98baf5664fSJonas Devlieghere (const char *), type); 99baf5664fSJonas Devlieghere 1005e8dce4dSJason Molenda SBThread result; 101b9c1b51eSKate Stone if (m_queue_item_sp) { 102a8ff543cSJason Molenda ProcessSP process_sp = m_queue_item_sp->GetProcessSP(); 103a8ff543cSJason Molenda Process::StopLocker stop_locker; 104b9c1b51eSKate Stone if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) { 1055e8dce4dSJason Molenda ThreadSP thread_sp; 1065e8dce4dSJason Molenda ConstString type_const(type); 1075e8dce4dSJason Molenda thread_sp = m_queue_item_sp->GetExtendedBacktraceThread(type_const); 108b9c1b51eSKate Stone if (thread_sp) { 109b9c1b51eSKate Stone // Save this in the Process' ExtendedThreadList so a strong pointer 11005097246SAdrian Prantl // retains the object 111a8ff543cSJason Molenda process_sp->GetExtendedThreadList().AddThread(thread_sp); 1125e8dce4dSJason Molenda result.SetThread(thread_sp); 1135e8dce4dSJason Molenda } 1145e8dce4dSJason Molenda } 115a8ff543cSJason Molenda } 116baf5664fSJonas Devlieghere return LLDB_RECORD_RESULT(result); 1175e8dce4dSJason Molenda } 118ae211eceSMichal Gorny 119ae211eceSMichal Gorny namespace lldb_private { 120ae211eceSMichal Gorny namespace repro { 121ae211eceSMichal Gorny 122ae211eceSMichal Gorny template <> 123ae211eceSMichal Gorny void RegisterMethods<SBQueueItem>(Registry &R) { 124ae211eceSMichal Gorny LLDB_REGISTER_CONSTRUCTOR(SBQueueItem, ()); 125ae211eceSMichal Gorny LLDB_REGISTER_CONSTRUCTOR(SBQueueItem, (const lldb::QueueItemSP &)); 126ae211eceSMichal Gorny LLDB_REGISTER_METHOD_CONST(bool, SBQueueItem, IsValid, ()); 127ae211eceSMichal Gorny LLDB_REGISTER_METHOD_CONST(bool, SBQueueItem, operator bool, ()); 128ae211eceSMichal Gorny LLDB_REGISTER_METHOD(void, SBQueueItem, Clear, ()); 129ae211eceSMichal Gorny LLDB_REGISTER_METHOD(void, SBQueueItem, SetQueueItem, 130ae211eceSMichal Gorny (const lldb::QueueItemSP &)); 131ae211eceSMichal Gorny LLDB_REGISTER_METHOD_CONST(lldb::QueueItemKind, SBQueueItem, GetKind, ()); 132ae211eceSMichal Gorny LLDB_REGISTER_METHOD(void, SBQueueItem, SetKind, (lldb::QueueItemKind)); 133ae211eceSMichal Gorny LLDB_REGISTER_METHOD_CONST(lldb::SBAddress, SBQueueItem, GetAddress, ()); 134ae211eceSMichal Gorny LLDB_REGISTER_METHOD(void, SBQueueItem, SetAddress, (lldb::SBAddress)); 135ae211eceSMichal Gorny LLDB_REGISTER_METHOD(lldb::SBThread, SBQueueItem, 136ae211eceSMichal Gorny GetExtendedBacktraceThread, (const char *)); 137ae211eceSMichal Gorny } 138ae211eceSMichal Gorny 139ae211eceSMichal Gorny } 140ae211eceSMichal Gorny } 141