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 | |
| 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" |
Jason Molenda | ac605f4 | 2014-03-08 01:34:55 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Log.h" |
Jason Molenda | a8ff543 | 2014-03-06 06:31:18 +0000 | [diff] [blame] | 18 | #include "lldb/Target/Process.h" |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 19 | #include "lldb/Target/QueueItem.h" |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 20 | #include "lldb/Target/Thread.h" |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 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 | { |
Jason Molenda | ac605f4 | 2014-03-08 01:34:55 +0000 | [diff] [blame] | 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; |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | |
| 57 | void |
| 58 | SBQueueItem::Clear () |
| 59 | { |
Jason Molenda | ac605f4 | 2014-03-08 01:34:55 +0000 | [diff] [blame] | 60 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 61 | if (log) |
| 62 | log->Printf("SBQueueItem(%p)::Clear()", m_queue_item_sp.get()); |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 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; |
Jason Molenda | ac605f4 | 2014-03-08 01:34:55 +0000 | [diff] [blame] | 78 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 79 | if (m_queue_item_sp) |
| 80 | { |
| 81 | result = m_queue_item_sp->GetKind (); |
| 82 | } |
Jason Molenda | ac605f4 | 2014-03-08 01:34:55 +0000 | [diff] [blame] | 83 | if (log) |
| 84 | log->Printf("SBQueueItem(%p)::GetKind() == %d", m_queue_item_sp.get(), (int) result); |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 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; |
Jason Molenda | ac605f4 | 2014-03-08 01:34:55 +0000 | [diff] [blame] | 101 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 102 | if (m_queue_item_sp) |
| 103 | { |
| 104 | result.SetAddress (&m_queue_item_sp->GetAddress()); |
| 105 | } |
Jason Molenda | ac605f4 | 2014-03-08 01:34:55 +0000 | [diff] [blame] | 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 | } |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 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; |
Jason Molenda | ac605f4 | 2014-03-08 01:34:55 +0000 | [diff] [blame] | 131 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 132 | if (m_queue_item_sp) |
| 133 | { |
Jason Molenda | a8ff543 | 2014-03-06 06:31:18 +0000 | [diff] [blame] | 134 | ProcessSP process_sp = m_queue_item_sp->GetProcessSP(); |
| 135 | Process::StopLocker stop_locker; |
| 136 | if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 137 | { |
Jason Molenda | a8ff543 | 2014-03-06 06:31:18 +0000 | [diff] [blame] | 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); |
Jason Molenda | ac605f4 | 2014-03-08 01:34:55 +0000 | [diff] [blame] | 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 | } |
Jason Molenda | a8ff543 | 2014-03-06 06:31:18 +0000 | [diff] [blame] | 154 | } |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | return result; |
| 158 | } |