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);
437f5237bcSPavel Labath   return this->operator bool();
447f5237bcSPavel Labath }
457f5237bcSPavel Labath SBQueueItem::operator bool() const {
467f5237bcSPavel Labath   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBQueueItem, operator bool);
47baf5664fSJonas Devlieghere 
48581af8b0SJonas Devlieghere   return m_queue_item_sp.get() != NULL;
495e8dce4dSJason Molenda }
505e8dce4dSJason Molenda 
51b9c1b51eSKate Stone void SBQueueItem::Clear() {
52baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(void, SBQueueItem, Clear);
53baf5664fSJonas Devlieghere 
545e8dce4dSJason Molenda   m_queue_item_sp.reset();
555e8dce4dSJason Molenda }
565e8dce4dSJason Molenda 
57b9c1b51eSKate Stone void SBQueueItem::SetQueueItem(const QueueItemSP &queue_item_sp) {
58baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBQueueItem, SetQueueItem,
59baf5664fSJonas Devlieghere                      (const lldb::QueueItemSP &), queue_item_sp);
60baf5664fSJonas Devlieghere 
615e8dce4dSJason Molenda   m_queue_item_sp = queue_item_sp;
625e8dce4dSJason Molenda }
635e8dce4dSJason Molenda 
64b9c1b51eSKate Stone lldb::QueueItemKind SBQueueItem::GetKind() const {
65baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::QueueItemKind, SBQueueItem, GetKind);
66baf5664fSJonas Devlieghere 
675e8dce4dSJason Molenda   QueueItemKind result = eQueueItemKindUnknown;
68b9c1b51eSKate Stone   if (m_queue_item_sp) {
695e8dce4dSJason Molenda     result = m_queue_item_sp->GetKind();
705e8dce4dSJason Molenda   }
715e8dce4dSJason Molenda   return result;
725e8dce4dSJason Molenda }
735e8dce4dSJason Molenda 
74b9c1b51eSKate Stone void SBQueueItem::SetKind(lldb::QueueItemKind kind) {
75baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBQueueItem, SetKind, (lldb::QueueItemKind), kind);
76baf5664fSJonas Devlieghere 
77b9c1b51eSKate Stone   if (m_queue_item_sp) {
785e8dce4dSJason Molenda     m_queue_item_sp->SetKind(kind);
795e8dce4dSJason Molenda   }
805e8dce4dSJason Molenda }
815e8dce4dSJason Molenda 
82b9c1b51eSKate Stone SBAddress SBQueueItem::GetAddress() const {
83baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBAddress, SBQueueItem, GetAddress);
84baf5664fSJonas Devlieghere 
855e8dce4dSJason Molenda   SBAddress result;
86b9c1b51eSKate Stone   if (m_queue_item_sp) {
875e8dce4dSJason Molenda     result.SetAddress(&m_queue_item_sp->GetAddress());
885e8dce4dSJason Molenda   }
89baf5664fSJonas Devlieghere   return LLDB_RECORD_RESULT(result);
905e8dce4dSJason Molenda }
915e8dce4dSJason Molenda 
92b9c1b51eSKate Stone void SBQueueItem::SetAddress(SBAddress addr) {
93baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBQueueItem, SetAddress, (lldb::SBAddress), addr);
94baf5664fSJonas Devlieghere 
95b9c1b51eSKate Stone   if (m_queue_item_sp) {
965e8dce4dSJason Molenda     m_queue_item_sp->SetAddress(addr.ref());
975e8dce4dSJason Molenda   }
985e8dce4dSJason Molenda }
995e8dce4dSJason Molenda 
100b9c1b51eSKate Stone SBThread SBQueueItem::GetExtendedBacktraceThread(const char *type) {
101baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThread, SBQueueItem, GetExtendedBacktraceThread,
102baf5664fSJonas Devlieghere                      (const char *), type);
103baf5664fSJonas Devlieghere 
1045e8dce4dSJason Molenda   SBThread result;
105b9c1b51eSKate Stone   if (m_queue_item_sp) {
106a8ff543cSJason Molenda     ProcessSP process_sp = m_queue_item_sp->GetProcessSP();
107a8ff543cSJason Molenda     Process::StopLocker stop_locker;
108b9c1b51eSKate Stone     if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) {
1095e8dce4dSJason Molenda       ThreadSP thread_sp;
1105e8dce4dSJason Molenda       ConstString type_const(type);
1115e8dce4dSJason Molenda       thread_sp = m_queue_item_sp->GetExtendedBacktraceThread(type_const);
112b9c1b51eSKate Stone       if (thread_sp) {
113b9c1b51eSKate Stone         // Save this in the Process' ExtendedThreadList so a strong pointer
11405097246SAdrian Prantl         // retains the object
115a8ff543cSJason Molenda         process_sp->GetExtendedThreadList().AddThread(thread_sp);
1165e8dce4dSJason Molenda         result.SetThread(thread_sp);
1175e8dce4dSJason Molenda       }
1185e8dce4dSJason Molenda     }
119a8ff543cSJason Molenda   }
120baf5664fSJonas Devlieghere   return LLDB_RECORD_RESULT(result);
1215e8dce4dSJason Molenda }
122*ae211eceSMichal Gorny 
123*ae211eceSMichal Gorny namespace lldb_private {
124*ae211eceSMichal Gorny namespace repro {
125*ae211eceSMichal Gorny 
126*ae211eceSMichal Gorny template <>
127*ae211eceSMichal Gorny void RegisterMethods<SBQueueItem>(Registry &R) {
128*ae211eceSMichal Gorny   LLDB_REGISTER_CONSTRUCTOR(SBQueueItem, ());
129*ae211eceSMichal Gorny   LLDB_REGISTER_CONSTRUCTOR(SBQueueItem, (const lldb::QueueItemSP &));
130*ae211eceSMichal Gorny   LLDB_REGISTER_METHOD_CONST(bool, SBQueueItem, IsValid, ());
131*ae211eceSMichal Gorny   LLDB_REGISTER_METHOD_CONST(bool, SBQueueItem, operator bool, ());
132*ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(void, SBQueueItem, Clear, ());
133*ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(void, SBQueueItem, SetQueueItem,
134*ae211eceSMichal Gorny                        (const lldb::QueueItemSP &));
135*ae211eceSMichal Gorny   LLDB_REGISTER_METHOD_CONST(lldb::QueueItemKind, SBQueueItem, GetKind, ());
136*ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(void, SBQueueItem, SetKind, (lldb::QueueItemKind));
137*ae211eceSMichal Gorny   LLDB_REGISTER_METHOD_CONST(lldb::SBAddress, SBQueueItem, GetAddress, ());
138*ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(void, SBQueueItem, SetAddress, (lldb::SBAddress));
139*ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(lldb::SBThread, SBQueueItem,
140*ae211eceSMichal Gorny                        GetExtendedBacktraceThread, (const char *));
141*ae211eceSMichal Gorny }
142*ae211eceSMichal Gorny 
143*ae211eceSMichal Gorny }
144*ae211eceSMichal Gorny }
145