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