blob: e7a199b9f0b43746f694f3f6af781d6edfaa18e7 [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
Jason Molenda5e8dce42013-12-13 00:29:16 +000010#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 Molendaac605f42014-03-08 01:34:55 +000016#include "lldb/Core/Log.h"
Jason Molendaa8ff5432014-03-06 06:31:18 +000017#include "lldb/Target/Process.h"
Jason Molenda5e8dce42013-12-13 00:29:16 +000018#include "lldb/Target/QueueItem.h"
Jason Molenda2fd83352014-02-05 05:44:54 +000019#include "lldb/Target/Thread.h"
Jason Molenda5e8dce42013-12-13 00:29:16 +000020
21using namespace lldb;
22using namespace lldb_private;
23
24//----------------------------------------------------------------------
25// Constructors
26//----------------------------------------------------------------------
27SBQueueItem::SBQueueItem () :
28 m_queue_item_sp()
29{
30}
31
32SBQueueItem::SBQueueItem (const QueueItemSP& queue_item_sp) :
33 m_queue_item_sp (queue_item_sp)
34{
35}
36
37//----------------------------------------------------------------------
38// Destructor
39//----------------------------------------------------------------------
40SBQueueItem::~SBQueueItem()
41{
42 m_queue_item_sp.reset();
43}
44
45bool
46SBQueueItem::IsValid() const
47{
Jason Molendaac605f42014-03-08 01:34:55 +000048 bool is_valid = m_queue_item_sp.get() != NULL;
49 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
50 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000051 log->Printf("SBQueueItem(%p)::IsValid() == %s",
52 static_cast<void*>(m_queue_item_sp.get()),
53 is_valid ? "true" : "false");
Jason Molendaac605f42014-03-08 01:34:55 +000054 return is_valid;
Jason Molenda5e8dce42013-12-13 00:29:16 +000055}
56
57
58void
59SBQueueItem::Clear ()
60{
Jason Molendaac605f42014-03-08 01:34:55 +000061 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
62 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000063 log->Printf("SBQueueItem(%p)::Clear()",
64 static_cast<void*>(m_queue_item_sp.get()));
Jason Molenda5e8dce42013-12-13 00:29:16 +000065 m_queue_item_sp.reset();
66}
67
68
69void
70SBQueueItem::SetQueueItem (const QueueItemSP& queue_item_sp)
71{
72 m_queue_item_sp = queue_item_sp;
73}
74
75
76lldb::QueueItemKind
77SBQueueItem::GetKind () const
78{
79 QueueItemKind result = eQueueItemKindUnknown;
Jason Molendaac605f42014-03-08 01:34:55 +000080 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jason Molenda5e8dce42013-12-13 00:29:16 +000081 if (m_queue_item_sp)
82 {
83 result = m_queue_item_sp->GetKind ();
84 }
Jason Molendaac605f42014-03-08 01:34:55 +000085 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000086 log->Printf("SBQueueItem(%p)::GetKind() == %d",
87 static_cast<void*>(m_queue_item_sp.get()),
88 static_cast<int>(result));
Jason Molenda5e8dce42013-12-13 00:29:16 +000089 return result;
90}
91
92void
93SBQueueItem::SetKind (lldb::QueueItemKind kind)
94{
95 if (m_queue_item_sp)
96 {
97 m_queue_item_sp->SetKind (kind);
98 }
99}
100
101SBAddress
102SBQueueItem::GetAddress () const
103{
104 SBAddress result;
Jason Molendaac605f42014-03-08 01:34:55 +0000105 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jason Molenda5e8dce42013-12-13 00:29:16 +0000106 if (m_queue_item_sp)
107 {
108 result.SetAddress (&m_queue_item_sp->GetAddress());
109 }
Jason Molendaac605f42014-03-08 01:34:55 +0000110 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 Abdulrasool324a1032014-04-04 04:06:10 +0000117 static_cast<void*>(m_queue_item_sp.get()),
118 static_cast<void*>(result.get()), sstr.GetData());
Jason Molendaac605f42014-03-08 01:34:55 +0000119 }
Jason Molenda5e8dce42013-12-13 00:29:16 +0000120 return result;
121}
122
123void
124SBQueueItem::SetAddress (SBAddress addr)
125{
126 if (m_queue_item_sp)
127 {
128 m_queue_item_sp->SetAddress (addr.ref());
129 }
130}
131
132SBThread
133SBQueueItem::GetExtendedBacktraceThread (const char *type)
134{
135 SBThread result;
Jason Molendaac605f42014-03-08 01:34:55 +0000136 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jason Molenda5e8dce42013-12-13 00:29:16 +0000137 if (m_queue_item_sp)
138 {
Jason Molendaa8ff5432014-03-06 06:31:18 +0000139 ProcessSP process_sp = m_queue_item_sp->GetProcessSP();
140 Process::StopLocker stop_locker;
141 if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock()))
Jason Molenda5e8dce42013-12-13 00:29:16 +0000142 {
Jason Molendaa8ff5432014-03-06 06:31:18 +0000143 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 Molendaac605f42014-03-08 01:34:55 +0000152 if (log)
153 {
154 const char *queue_name = thread_sp->GetQueueName();
155 if (queue_name == NULL)
156 queue_name = "";
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000157 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 Molendaac605f42014-03-08 01:34:55 +0000162 }
Jason Molendaa8ff5432014-03-06 06:31:18 +0000163 }
Jason Molenda5e8dce42013-12-13 00:29:16 +0000164 }
165 }
166 return result;
167}