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 | ac605f4 | 2014-03-08 01:34:55 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Log.h" |
Jason Molenda | a8ff543 | 2014-03-06 06:31:18 +0000 | [diff] [blame] | 17 | #include "lldb/Target/Process.h" |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 18 | #include "lldb/Target/QueueItem.h" |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 19 | #include "lldb/Target/Thread.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 | //---------------------------------------------------------------------- |
| 27 | SBQueueItem::SBQueueItem () : |
| 28 | m_queue_item_sp() |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | SBQueueItem::SBQueueItem (const QueueItemSP& queue_item_sp) : |
| 33 | m_queue_item_sp (queue_item_sp) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | //---------------------------------------------------------------------- |
| 38 | // Destructor |
| 39 | //---------------------------------------------------------------------- |
| 40 | SBQueueItem::~SBQueueItem() |
| 41 | { |
| 42 | m_queue_item_sp.reset(); |
| 43 | } |
| 44 | |
| 45 | bool |
| 46 | SBQueueItem::IsValid() const |
| 47 | { |
Jason Molenda | ac605f4 | 2014-03-08 01:34:55 +0000 | [diff] [blame] | 48 | bool is_valid = m_queue_item_sp.get() != NULL; |
| 49 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 50 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 51 | log->Printf("SBQueueItem(%p)::IsValid() == %s", |
| 52 | static_cast<void*>(m_queue_item_sp.get()), |
| 53 | is_valid ? "true" : "false"); |
Jason Molenda | ac605f4 | 2014-03-08 01:34:55 +0000 | [diff] [blame] | 54 | return is_valid; |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | |
| 58 | void |
| 59 | SBQueueItem::Clear () |
| 60 | { |
Jason Molenda | ac605f4 | 2014-03-08 01:34:55 +0000 | [diff] [blame] | 61 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 62 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 63 | log->Printf("SBQueueItem(%p)::Clear()", |
| 64 | static_cast<void*>(m_queue_item_sp.get())); |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 65 | m_queue_item_sp.reset(); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | void |
| 70 | SBQueueItem::SetQueueItem (const QueueItemSP& queue_item_sp) |
| 71 | { |
| 72 | m_queue_item_sp = queue_item_sp; |
| 73 | } |
| 74 | |
| 75 | |
| 76 | lldb::QueueItemKind |
| 77 | SBQueueItem::GetKind () const |
| 78 | { |
| 79 | QueueItemKind result = eQueueItemKindUnknown; |
Jason Molenda | ac605f4 | 2014-03-08 01:34:55 +0000 | [diff] [blame] | 80 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 81 | if (m_queue_item_sp) |
| 82 | { |
| 83 | result = m_queue_item_sp->GetKind (); |
| 84 | } |
Jason Molenda | ac605f4 | 2014-03-08 01:34:55 +0000 | [diff] [blame] | 85 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 86 | log->Printf("SBQueueItem(%p)::GetKind() == %d", |
| 87 | static_cast<void*>(m_queue_item_sp.get()), |
| 88 | static_cast<int>(result)); |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 89 | return result; |
| 90 | } |
| 91 | |
| 92 | void |
| 93 | SBQueueItem::SetKind (lldb::QueueItemKind kind) |
| 94 | { |
| 95 | if (m_queue_item_sp) |
| 96 | { |
| 97 | m_queue_item_sp->SetKind (kind); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | SBAddress |
| 102 | SBQueueItem::GetAddress () const |
| 103 | { |
| 104 | SBAddress result; |
Jason Molenda | ac605f4 | 2014-03-08 01:34:55 +0000 | [diff] [blame] | 105 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 106 | if (m_queue_item_sp) |
| 107 | { |
| 108 | result.SetAddress (&m_queue_item_sp->GetAddress()); |
| 109 | } |
Jason Molenda | ac605f4 | 2014-03-08 01:34:55 +0000 | [diff] [blame] | 110 | if (log) |
| 111 | { |
| 112 | StreamString sstr; |
| 113 | const Address *addr = result.get(); |
| 114 | if (addr) |
| 115 | addr->Dump (&sstr, NULL, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleInvalid, 4); |
| 116 | log->Printf ("SBQueueItem(%p)::GetAddress() == SBAddress(%p): %s", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 117 | static_cast<void*>(m_queue_item_sp.get()), |
| 118 | static_cast<void*>(result.get()), sstr.GetData()); |
Jason Molenda | ac605f4 | 2014-03-08 01:34:55 +0000 | [diff] [blame] | 119 | } |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 120 | return result; |
| 121 | } |
| 122 | |
| 123 | void |
| 124 | SBQueueItem::SetAddress (SBAddress addr) |
| 125 | { |
| 126 | if (m_queue_item_sp) |
| 127 | { |
| 128 | m_queue_item_sp->SetAddress (addr.ref()); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | SBThread |
| 133 | SBQueueItem::GetExtendedBacktraceThread (const char *type) |
| 134 | { |
| 135 | SBThread result; |
Jason Molenda | ac605f4 | 2014-03-08 01:34:55 +0000 | [diff] [blame] | 136 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 137 | if (m_queue_item_sp) |
| 138 | { |
Jason Molenda | a8ff543 | 2014-03-06 06:31:18 +0000 | [diff] [blame] | 139 | ProcessSP process_sp = m_queue_item_sp->GetProcessSP(); |
| 140 | Process::StopLocker stop_locker; |
| 141 | if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 142 | { |
Jason Molenda | a8ff543 | 2014-03-06 06:31:18 +0000 | [diff] [blame] | 143 | ThreadSP thread_sp; |
| 144 | ConstString type_const (type); |
| 145 | thread_sp = m_queue_item_sp->GetExtendedBacktraceThread (type_const); |
| 146 | if (thread_sp) |
| 147 | { |
| 148 | // Save this in the Process' ExtendedThreadList so a strong pointer retains the |
| 149 | // object |
| 150 | process_sp->GetExtendedThreadList().AddThread (thread_sp); |
| 151 | result.SetThread (thread_sp); |
Jason Molenda | ac605f4 | 2014-03-08 01:34:55 +0000 | [diff] [blame] | 152 | if (log) |
| 153 | { |
| 154 | const char *queue_name = thread_sp->GetQueueName(); |
| 155 | if (queue_name == NULL) |
| 156 | queue_name = ""; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 157 | log->Printf ("SBQueueItem(%p)::GetExtendedBacktraceThread() = new extended Thread created (%p) with queue_id 0x%" PRIx64 " queue name '%s'", |
| 158 | static_cast<void*>(m_queue_item_sp.get()), |
| 159 | static_cast<void*>(thread_sp.get()), |
| 160 | static_cast<uint64_t>(thread_sp->GetQueueID()), |
| 161 | queue_name); |
Jason Molenda | ac605f4 | 2014-03-08 01:34:55 +0000 | [diff] [blame] | 162 | } |
Jason Molenda | a8ff543 | 2014-03-06 06:31:18 +0000 | [diff] [blame] | 163 | } |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | return result; |
| 167 | } |