blob: 6a1aa7bec61a2a4bb98da1758844c0036b8d3435 [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)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000052 log->Printf("SBQueueItem(%p)::IsValid() == %s",
53 static_cast<void*>(m_queue_item_sp.get()),
54 is_valid ? "true" : "false");
Jason Molendaac605f42014-03-08 01:34:55 +000055 return is_valid;
Jason Molenda5e8dce42013-12-13 00:29:16 +000056}
57
58
59void
60SBQueueItem::Clear ()
61{
Jason Molendaac605f42014-03-08 01:34:55 +000062 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
63 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000064 log->Printf("SBQueueItem(%p)::Clear()",
65 static_cast<void*>(m_queue_item_sp.get()));
Jason Molenda5e8dce42013-12-13 00:29:16 +000066 m_queue_item_sp.reset();
67}
68
69
70void
71SBQueueItem::SetQueueItem (const QueueItemSP& queue_item_sp)
72{
73 m_queue_item_sp = queue_item_sp;
74}
75
76
77lldb::QueueItemKind
78SBQueueItem::GetKind () const
79{
80 QueueItemKind result = eQueueItemKindUnknown;
Jason Molendaac605f42014-03-08 01:34:55 +000081 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jason Molenda5e8dce42013-12-13 00:29:16 +000082 if (m_queue_item_sp)
83 {
84 result = m_queue_item_sp->GetKind ();
85 }
Jason Molendaac605f42014-03-08 01:34:55 +000086 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000087 log->Printf("SBQueueItem(%p)::GetKind() == %d",
88 static_cast<void*>(m_queue_item_sp.get()),
89 static_cast<int>(result));
Jason Molenda5e8dce42013-12-13 00:29:16 +000090 return result;
91}
92
93void
94SBQueueItem::SetKind (lldb::QueueItemKind kind)
95{
96 if (m_queue_item_sp)
97 {
98 m_queue_item_sp->SetKind (kind);
99 }
100}
101
102SBAddress
103SBQueueItem::GetAddress () const
104{
105 SBAddress result;
Jason Molendaac605f42014-03-08 01:34:55 +0000106 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jason Molenda5e8dce42013-12-13 00:29:16 +0000107 if (m_queue_item_sp)
108 {
109 result.SetAddress (&m_queue_item_sp->GetAddress());
110 }
Jason Molendaac605f42014-03-08 01:34:55 +0000111 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 Abdulrasool324a1032014-04-04 04:06:10 +0000118 static_cast<void*>(m_queue_item_sp.get()),
119 static_cast<void*>(result.get()), sstr.GetData());
Jason Molendaac605f42014-03-08 01:34:55 +0000120 }
Jason Molenda5e8dce42013-12-13 00:29:16 +0000121 return result;
122}
123
124void
125SBQueueItem::SetAddress (SBAddress addr)
126{
127 if (m_queue_item_sp)
128 {
129 m_queue_item_sp->SetAddress (addr.ref());
130 }
131}
132
133SBThread
134SBQueueItem::GetExtendedBacktraceThread (const char *type)
135{
136 SBThread result;
Jason Molendaac605f42014-03-08 01:34:55 +0000137 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jason Molenda5e8dce42013-12-13 00:29:16 +0000138 if (m_queue_item_sp)
139 {
Jason Molendaa8ff5432014-03-06 06:31:18 +0000140 ProcessSP process_sp = m_queue_item_sp->GetProcessSP();
141 Process::StopLocker stop_locker;
142 if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock()))
Jason Molenda5e8dce42013-12-13 00:29:16 +0000143 {
Jason Molendaa8ff5432014-03-06 06:31:18 +0000144 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 Molendaac605f42014-03-08 01:34:55 +0000153 if (log)
154 {
155 const char *queue_name = thread_sp->GetQueueName();
156 if (queue_name == NULL)
157 queue_name = "";
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000158 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 Molendaac605f42014-03-08 01:34:55 +0000163 }
Jason Molendaa8ff5432014-03-06 06:31:18 +0000164 }
Jason Molenda5e8dce42013-12-13 00:29:16 +0000165 }
166 }
167 return result;
168}