15e8dce4dSJason Molenda //===-- SBQueueItem.cpp -----------------------------------------*- C++ -*-===// 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 //---------------------------------------------------------------------- 245e8dce4dSJason Molenda // Constructors 255e8dce4dSJason Molenda //---------------------------------------------------------------------- 26baf5664fSJonas Devlieghere SBQueueItem::SBQueueItem() : m_queue_item_sp() { 27baf5664fSJonas Devlieghere LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBQueueItem); 28baf5664fSJonas Devlieghere } 295e8dce4dSJason Molenda 30b9c1b51eSKate Stone SBQueueItem::SBQueueItem(const QueueItemSP &queue_item_sp) 31baf5664fSJonas Devlieghere : m_queue_item_sp(queue_item_sp) { 32baf5664fSJonas Devlieghere LLDB_RECORD_CONSTRUCTOR(SBQueueItem, (const lldb::QueueItemSP &), 33baf5664fSJonas Devlieghere queue_item_sp); 34baf5664fSJonas Devlieghere } 355e8dce4dSJason Molenda 365e8dce4dSJason Molenda //---------------------------------------------------------------------- 375e8dce4dSJason Molenda // Destructor 385e8dce4dSJason Molenda //---------------------------------------------------------------------- 39b9c1b51eSKate Stone SBQueueItem::~SBQueueItem() { m_queue_item_sp.reset(); } 405e8dce4dSJason Molenda 41b9c1b51eSKate Stone bool SBQueueItem::IsValid() const { 42baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBQueueItem, IsValid); 43baf5664fSJonas Devlieghere 44*581af8b0SJonas Devlieghere return m_queue_item_sp.get() != NULL; 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) { 835e8dce4dSJason Molenda 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 } 118