Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 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 | |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 10 | #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 Molenda | a8ff543 | 2014-03-06 06:31:18 +0000 | [diff] [blame] | 16 | #include "lldb/Target/Process.h" |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 17 | #include "lldb/Target/QueueItem.h" |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 18 | #include "lldb/Target/Thread.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 19 | #include "lldb/Utility/Log.h" |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace lldb; |
| 22 | using namespace lldb_private; |
| 23 | |
| 24 | //---------------------------------------------------------------------- |
| 25 | // Constructors |
| 26 | //---------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 27 | SBQueueItem::SBQueueItem() : m_queue_item_sp() {} |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 28 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 29 | SBQueueItem::SBQueueItem(const QueueItemSP &queue_item_sp) |
| 30 | : m_queue_item_sp(queue_item_sp) {} |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 31 | |
| 32 | //---------------------------------------------------------------------- |
| 33 | // Destructor |
| 34 | //---------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 35 | SBQueueItem::~SBQueueItem() { m_queue_item_sp.reset(); } |
| 36 | |
| 37 | bool 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 Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 47 | void 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 Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 55 | void SBQueueItem::SetQueueItem(const QueueItemSP &queue_item_sp) { |
| 56 | m_queue_item_sp = queue_item_sp; |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 59 | lldb::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 Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 72 | void SBQueueItem::SetKind(lldb::QueueItemKind kind) { |
| 73 | if (m_queue_item_sp) { |
| 74 | m_queue_item_sp->SetKind(kind); |
| 75 | } |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 78 | SBAddress 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 Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 97 | void SBQueueItem::SetAddress(SBAddress addr) { |
| 98 | if (m_queue_item_sp) { |
| 99 | m_queue_item_sp->SetAddress(addr.ref()); |
| 100 | } |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 103 | SBThread 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 Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 115 | // retains the object |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 116 | 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 Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 128 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 129 | } |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 130 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 131 | } |
| 132 | return result; |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 133 | } |