blob: aac5844240fba10adc9cac2fd6d3b7263291a1c5 [file] [log] [blame]
Jason Molenda5e8dce42013-12-13 00:29:16 +00001//===-- 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
Jason Molenda5e8dce42013-12-13 00:29:16 +000010#include "lldb/lldb-forward.h"
11
12#include "lldb/API/SBAddress.h"
13#include "lldb/API/SBQueueItem.h"
14#include "lldb/API/SBThread.h"
15#include "lldb/Core/Address.h"
Jason Molendaa8ff5432014-03-06 06:31:18 +000016#include "lldb/Target/Process.h"
Jason Molenda5e8dce42013-12-13 00:29:16 +000017#include "lldb/Target/QueueItem.h"
Jason Molenda2fd83352014-02-05 05:44:54 +000018#include "lldb/Target/Thread.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000019#include "lldb/Utility/Log.h"
Jason Molenda5e8dce42013-12-13 00:29:16 +000020
21using namespace lldb;
22using namespace lldb_private;
23
24//----------------------------------------------------------------------
25// Constructors
26//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +000027SBQueueItem::SBQueueItem() : m_queue_item_sp() {}
Jason Molenda5e8dce42013-12-13 00:29:16 +000028
Kate Stoneb9c1b512016-09-06 20:57:50 +000029SBQueueItem::SBQueueItem(const QueueItemSP &queue_item_sp)
30 : m_queue_item_sp(queue_item_sp) {}
Jason Molenda5e8dce42013-12-13 00:29:16 +000031
32//----------------------------------------------------------------------
33// Destructor
34//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +000035SBQueueItem::~SBQueueItem() { m_queue_item_sp.reset(); }
36
37bool SBQueueItem::IsValid() const {
38 bool is_valid = m_queue_item_sp.get() != NULL;
39 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
40 if (log)
41 log->Printf("SBQueueItem(%p)::IsValid() == %s",
42 static_cast<void *>(m_queue_item_sp.get()),
43 is_valid ? "true" : "false");
44 return is_valid;
Jason Molenda5e8dce42013-12-13 00:29:16 +000045}
46
Kate Stoneb9c1b512016-09-06 20:57:50 +000047void SBQueueItem::Clear() {
48 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
49 if (log)
50 log->Printf("SBQueueItem(%p)::Clear()",
51 static_cast<void *>(m_queue_item_sp.get()));
52 m_queue_item_sp.reset();
Jason Molenda5e8dce42013-12-13 00:29:16 +000053}
54
Kate Stoneb9c1b512016-09-06 20:57:50 +000055void SBQueueItem::SetQueueItem(const QueueItemSP &queue_item_sp) {
56 m_queue_item_sp = queue_item_sp;
Jason Molenda5e8dce42013-12-13 00:29:16 +000057}
58
Kate Stoneb9c1b512016-09-06 20:57:50 +000059lldb::QueueItemKind SBQueueItem::GetKind() const {
60 QueueItemKind result = eQueueItemKindUnknown;
61 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
62 if (m_queue_item_sp) {
63 result = m_queue_item_sp->GetKind();
64 }
65 if (log)
66 log->Printf("SBQueueItem(%p)::GetKind() == %d",
67 static_cast<void *>(m_queue_item_sp.get()),
68 static_cast<int>(result));
69 return result;
Jason Molenda5e8dce42013-12-13 00:29:16 +000070}
71
Kate Stoneb9c1b512016-09-06 20:57:50 +000072void SBQueueItem::SetKind(lldb::QueueItemKind kind) {
73 if (m_queue_item_sp) {
74 m_queue_item_sp->SetKind(kind);
75 }
Jason Molenda5e8dce42013-12-13 00:29:16 +000076}
77
Kate Stoneb9c1b512016-09-06 20:57:50 +000078SBAddress SBQueueItem::GetAddress() const {
79 SBAddress result;
80 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
81 if (m_queue_item_sp) {
82 result.SetAddress(&m_queue_item_sp->GetAddress());
83 }
84 if (log) {
85 StreamString sstr;
86 const Address *addr = result.get();
87 if (addr)
88 addr->Dump(&sstr, NULL, Address::DumpStyleModuleWithFileAddress,
89 Address::DumpStyleInvalid, 4);
90 log->Printf("SBQueueItem(%p)::GetAddress() == SBAddress(%p): %s",
91 static_cast<void *>(m_queue_item_sp.get()),
92 static_cast<void *>(result.get()), sstr.GetData());
93 }
94 return result;
Jason Molenda5e8dce42013-12-13 00:29:16 +000095}
96
Kate Stoneb9c1b512016-09-06 20:57:50 +000097void SBQueueItem::SetAddress(SBAddress addr) {
98 if (m_queue_item_sp) {
99 m_queue_item_sp->SetAddress(addr.ref());
100 }
Jason Molenda5e8dce42013-12-13 00:29:16 +0000101}
102
Kate Stoneb9c1b512016-09-06 20:57:50 +0000103SBThread SBQueueItem::GetExtendedBacktraceThread(const char *type) {
104 SBThread result;
105 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
106 if (m_queue_item_sp) {
107 ProcessSP process_sp = m_queue_item_sp->GetProcessSP();
108 Process::StopLocker stop_locker;
109 if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) {
110 ThreadSP thread_sp;
111 ConstString type_const(type);
112 thread_sp = m_queue_item_sp->GetExtendedBacktraceThread(type_const);
113 if (thread_sp) {
114 // Save this in the Process' ExtendedThreadList so a strong pointer
Adrian Prantl05097242018-04-30 16:49:04 +0000115 // retains the object
Kate Stoneb9c1b512016-09-06 20:57:50 +0000116 process_sp->GetExtendedThreadList().AddThread(thread_sp);
117 result.SetThread(thread_sp);
118 if (log) {
119 const char *queue_name = thread_sp->GetQueueName();
120 if (queue_name == NULL)
121 queue_name = "";
122 log->Printf(
123 "SBQueueItem(%p)::GetExtendedBacktraceThread() = new extended "
124 "Thread created (%p) with queue_id 0x%" PRIx64 " queue name '%s'",
125 static_cast<void *>(m_queue_item_sp.get()),
126 static_cast<void *>(thread_sp.get()),
127 static_cast<uint64_t>(thread_sp->GetQueueID()), queue_name);
Jason Molenda5e8dce42013-12-13 00:29:16 +0000128 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000129 }
Jason Molenda5e8dce42013-12-13 00:29:16 +0000130 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000131 }
132 return result;
Jason Molenda5e8dce42013-12-13 00:29:16 +0000133}