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 | 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 | { |
| 48 | return m_queue_item_sp.get() != NULL; |
| 49 | } |
| 50 | |
| 51 | |
| 52 | void |
| 53 | SBQueueItem::Clear () |
| 54 | { |
| 55 | m_queue_item_sp.reset(); |
| 56 | } |
| 57 | |
| 58 | |
| 59 | void |
| 60 | SBQueueItem::SetQueueItem (const QueueItemSP& queue_item_sp) |
| 61 | { |
| 62 | m_queue_item_sp = queue_item_sp; |
| 63 | } |
| 64 | |
| 65 | |
| 66 | lldb::QueueItemKind |
| 67 | SBQueueItem::GetKind () const |
| 68 | { |
| 69 | QueueItemKind result = eQueueItemKindUnknown; |
| 70 | if (m_queue_item_sp) |
| 71 | { |
| 72 | result = m_queue_item_sp->GetKind (); |
| 73 | } |
| 74 | return result; |
| 75 | } |
| 76 | |
| 77 | void |
| 78 | SBQueueItem::SetKind (lldb::QueueItemKind kind) |
| 79 | { |
| 80 | if (m_queue_item_sp) |
| 81 | { |
| 82 | m_queue_item_sp->SetKind (kind); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | SBAddress |
| 87 | SBQueueItem::GetAddress () const |
| 88 | { |
| 89 | SBAddress result; |
| 90 | if (m_queue_item_sp) |
| 91 | { |
| 92 | result.SetAddress (&m_queue_item_sp->GetAddress()); |
| 93 | } |
| 94 | return result; |
| 95 | } |
| 96 | |
| 97 | void |
| 98 | SBQueueItem::SetAddress (SBAddress addr) |
| 99 | { |
| 100 | if (m_queue_item_sp) |
| 101 | { |
| 102 | m_queue_item_sp->SetAddress (addr.ref()); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | SBThread |
| 107 | SBQueueItem::GetExtendedBacktraceThread (const char *type) |
| 108 | { |
| 109 | SBThread result; |
| 110 | if (m_queue_item_sp) |
| 111 | { |
Jason Molenda | a8ff543 | 2014-03-06 06:31:18 +0000 | [diff] [blame^] | 112 | ProcessSP process_sp = m_queue_item_sp->GetProcessSP(); |
| 113 | Process::StopLocker stop_locker; |
| 114 | if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 115 | { |
Jason Molenda | a8ff543 | 2014-03-06 06:31:18 +0000 | [diff] [blame^] | 116 | ThreadSP thread_sp; |
| 117 | ConstString type_const (type); |
| 118 | thread_sp = m_queue_item_sp->GetExtendedBacktraceThread (type_const); |
| 119 | if (thread_sp) |
| 120 | { |
| 121 | // Save this in the Process' ExtendedThreadList so a strong pointer retains the |
| 122 | // object |
| 123 | process_sp->GetExtendedThreadList().AddThread (thread_sp); |
| 124 | result.SetThread (thread_sp); |
| 125 | } |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | return result; |
| 129 | } |