blob: 10d036ab88009a3821e4dc7e9f4f55a74a68adc6 [file] [log] [blame]
Jason Molenda5e8dce42013-12-13 00:29:16 +00001//===-- 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 Molendaac605f42014-03-08 01:34:55 +000017#include "lldb/Core/Log.h"
Jason Molendaa8ff5432014-03-06 06:31:18 +000018#include "lldb/Target/Process.h"
Jason Molenda5e8dce42013-12-13 00:29:16 +000019#include "lldb/Target/QueueItem.h"
Jason Molenda2fd83352014-02-05 05:44:54 +000020#include "lldb/Target/Thread.h"
Jason Molenda5e8dce42013-12-13 00:29:16 +000021
22using namespace lldb;
23using namespace lldb_private;
24
25//----------------------------------------------------------------------
26// Constructors
27//----------------------------------------------------------------------
28SBQueueItem::SBQueueItem () :
29 m_queue_item_sp()
30{
31}
32
33SBQueueItem::SBQueueItem (const QueueItemSP& queue_item_sp) :
34 m_queue_item_sp (queue_item_sp)
35{
36}
37
38//----------------------------------------------------------------------
39// Destructor
40//----------------------------------------------------------------------
41SBQueueItem::~SBQueueItem()
42{
43 m_queue_item_sp.reset();
44}
45
46bool
47SBQueueItem::IsValid() const
48{
Jason Molendaac605f42014-03-08 01:34:55 +000049 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 Molenda5e8dce42013-12-13 00:29:16 +000054}
55
56
57void
58SBQueueItem::Clear ()
59{
Jason Molendaac605f42014-03-08 01:34:55 +000060 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
61 if (log)
62 log->Printf("SBQueueItem(%p)::Clear()", m_queue_item_sp.get());
Jason Molenda5e8dce42013-12-13 00:29:16 +000063 m_queue_item_sp.reset();
64}
65
66
67void
68SBQueueItem::SetQueueItem (const QueueItemSP& queue_item_sp)
69{
70 m_queue_item_sp = queue_item_sp;
71}
72
73
74lldb::QueueItemKind
75SBQueueItem::GetKind () const
76{
77 QueueItemKind result = eQueueItemKindUnknown;
Jason Molendaac605f42014-03-08 01:34:55 +000078 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jason Molenda5e8dce42013-12-13 00:29:16 +000079 if (m_queue_item_sp)
80 {
81 result = m_queue_item_sp->GetKind ();
82 }
Jason Molendaac605f42014-03-08 01:34:55 +000083 if (log)
84 log->Printf("SBQueueItem(%p)::GetKind() == %d", m_queue_item_sp.get(), (int) result);
Jason Molenda5e8dce42013-12-13 00:29:16 +000085 return result;
86}
87
88void
89SBQueueItem::SetKind (lldb::QueueItemKind kind)
90{
91 if (m_queue_item_sp)
92 {
93 m_queue_item_sp->SetKind (kind);
94 }
95}
96
97SBAddress
98SBQueueItem::GetAddress () const
99{
100 SBAddress result;
Jason Molendaac605f42014-03-08 01:34:55 +0000101 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jason Molenda5e8dce42013-12-13 00:29:16 +0000102 if (m_queue_item_sp)
103 {
104 result.SetAddress (&m_queue_item_sp->GetAddress());
105 }
Jason Molendaac605f42014-03-08 01:34:55 +0000106 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 Molenda5e8dce42013-12-13 00:29:16 +0000115 return result;
116}
117
118void
119SBQueueItem::SetAddress (SBAddress addr)
120{
121 if (m_queue_item_sp)
122 {
123 m_queue_item_sp->SetAddress (addr.ref());
124 }
125}
126
127SBThread
128SBQueueItem::GetExtendedBacktraceThread (const char *type)
129{
130 SBThread result;
Jason Molendaac605f42014-03-08 01:34:55 +0000131 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jason Molenda5e8dce42013-12-13 00:29:16 +0000132 if (m_queue_item_sp)
133 {
Jason Molendaa8ff5432014-03-06 06:31:18 +0000134 ProcessSP process_sp = m_queue_item_sp->GetProcessSP();
135 Process::StopLocker stop_locker;
136 if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock()))
Jason Molenda5e8dce42013-12-13 00:29:16 +0000137 {
Jason Molendaa8ff5432014-03-06 06:31:18 +0000138 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 Molendaac605f42014-03-08 01:34:55 +0000147 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 Molendaa8ff5432014-03-06 06:31:18 +0000154 }
Jason Molenda5e8dce42013-12-13 00:29:16 +0000155 }
156 }
157 return result;
158}