1 //===-- SBQueueItem.cpp -----------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/lldb-python.h" 11 #include "lldb/lldb-forward.h" 12 13 #include "lldb/API/SBAddress.h" 14 #include "lldb/API/SBQueueItem.h" 15 #include "lldb/API/SBThread.h" 16 #include "lldb/Core/Address.h" 17 #include "lldb/Core/Log.h" 18 #include "lldb/Target/Process.h" 19 #include "lldb/Target/QueueItem.h" 20 #include "lldb/Target/Thread.h" 21 22 using namespace lldb; 23 using namespace lldb_private; 24 25 //---------------------------------------------------------------------- 26 // Constructors 27 //---------------------------------------------------------------------- 28 SBQueueItem::SBQueueItem () : 29 m_queue_item_sp() 30 { 31 } 32 33 SBQueueItem::SBQueueItem (const QueueItemSP& queue_item_sp) : 34 m_queue_item_sp (queue_item_sp) 35 { 36 } 37 38 //---------------------------------------------------------------------- 39 // Destructor 40 //---------------------------------------------------------------------- 41 SBQueueItem::~SBQueueItem() 42 { 43 m_queue_item_sp.reset(); 44 } 45 46 bool 47 SBQueueItem::IsValid() const 48 { 49 bool is_valid = m_queue_item_sp.get() != NULL; 50 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 51 if (log) 52 log->Printf("SBQueueItem(%p)::IsValid() == %s", m_queue_item_sp.get(), is_valid ? "true" : "false"); 53 return is_valid; 54 } 55 56 57 void 58 SBQueueItem::Clear () 59 { 60 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 61 if (log) 62 log->Printf("SBQueueItem(%p)::Clear()", m_queue_item_sp.get()); 63 m_queue_item_sp.reset(); 64 } 65 66 67 void 68 SBQueueItem::SetQueueItem (const QueueItemSP& queue_item_sp) 69 { 70 m_queue_item_sp = queue_item_sp; 71 } 72 73 74 lldb::QueueItemKind 75 SBQueueItem::GetKind () const 76 { 77 QueueItemKind result = eQueueItemKindUnknown; 78 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 79 if (m_queue_item_sp) 80 { 81 result = m_queue_item_sp->GetKind (); 82 } 83 if (log) 84 log->Printf("SBQueueItem(%p)::GetKind() == %d", m_queue_item_sp.get(), (int) result); 85 return result; 86 } 87 88 void 89 SBQueueItem::SetKind (lldb::QueueItemKind kind) 90 { 91 if (m_queue_item_sp) 92 { 93 m_queue_item_sp->SetKind (kind); 94 } 95 } 96 97 SBAddress 98 SBQueueItem::GetAddress () const 99 { 100 SBAddress result; 101 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 102 if (m_queue_item_sp) 103 { 104 result.SetAddress (&m_queue_item_sp->GetAddress()); 105 } 106 if (log) 107 { 108 StreamString sstr; 109 const Address *addr = result.get(); 110 if (addr) 111 addr->Dump (&sstr, NULL, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleInvalid, 4); 112 log->Printf ("SBQueueItem(%p)::GetAddress() == SBAddress(%p): %s", 113 m_queue_item_sp.get(), result.get(), sstr.GetData()); 114 } 115 return result; 116 } 117 118 void 119 SBQueueItem::SetAddress (SBAddress addr) 120 { 121 if (m_queue_item_sp) 122 { 123 m_queue_item_sp->SetAddress (addr.ref()); 124 } 125 } 126 127 SBThread 128 SBQueueItem::GetExtendedBacktraceThread (const char *type) 129 { 130 SBThread result; 131 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 132 if (m_queue_item_sp) 133 { 134 ProcessSP process_sp = m_queue_item_sp->GetProcessSP(); 135 Process::StopLocker stop_locker; 136 if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) 137 { 138 ThreadSP thread_sp; 139 ConstString type_const (type); 140 thread_sp = m_queue_item_sp->GetExtendedBacktraceThread (type_const); 141 if (thread_sp) 142 { 143 // Save this in the Process' ExtendedThreadList so a strong pointer retains the 144 // object 145 process_sp->GetExtendedThreadList().AddThread (thread_sp); 146 result.SetThread (thread_sp); 147 if (log) 148 { 149 const char *queue_name = thread_sp->GetQueueName(); 150 if (queue_name == NULL) 151 queue_name = ""; 152 log->Printf ("SBQueueItem(%p)::GetExtendedBacktraceThread() = new extended Thread created (%p) with queue_id 0x%" PRIx64 " queue name '%s'", m_queue_item_sp.get(), thread_sp.get(), (uint64_t) thread_sp->GetQueueID(), queue_name); 153 } 154 } 155 } 156 } 157 return result; 158 } 159