]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/API/SBQueueItem.cpp
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / source / API / SBQueueItem.cpp
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-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"
16 #include "lldb/Core/Log.h"
17 #include "lldb/Target/Process.h"
18 #include "lldb/Target/QueueItem.h"
19 #include "lldb/Target/Thread.h"
20
21 using namespace lldb;
22 using namespace lldb_private;
23
24 //----------------------------------------------------------------------
25 // Constructors
26 //----------------------------------------------------------------------
27 SBQueueItem::SBQueueItem() : m_queue_item_sp() {}
28
29 SBQueueItem::SBQueueItem(const QueueItemSP &queue_item_sp)
30     : m_queue_item_sp(queue_item_sp) {}
31
32 //----------------------------------------------------------------------
33 // Destructor
34 //----------------------------------------------------------------------
35 SBQueueItem::~SBQueueItem() { m_queue_item_sp.reset(); }
36
37 bool SBQueueItem::IsValid() const {
38   bool is_valid = m_queue_item_sp.get() != NULL;
39   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
40   if (log)
41     log->Printf("SBQueueItem(%p)::IsValid() == %s",
42                 static_cast<void *>(m_queue_item_sp.get()),
43                 is_valid ? "true" : "false");
44   return is_valid;
45 }
46
47 void SBQueueItem::Clear() {
48   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
49   if (log)
50     log->Printf("SBQueueItem(%p)::Clear()",
51                 static_cast<void *>(m_queue_item_sp.get()));
52   m_queue_item_sp.reset();
53 }
54
55 void SBQueueItem::SetQueueItem(const QueueItemSP &queue_item_sp) {
56   m_queue_item_sp = queue_item_sp;
57 }
58
59 lldb::QueueItemKind SBQueueItem::GetKind() const {
60   QueueItemKind result = eQueueItemKindUnknown;
61   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
62   if (m_queue_item_sp) {
63     result = m_queue_item_sp->GetKind();
64   }
65   if (log)
66     log->Printf("SBQueueItem(%p)::GetKind() == %d",
67                 static_cast<void *>(m_queue_item_sp.get()),
68                 static_cast<int>(result));
69   return result;
70 }
71
72 void SBQueueItem::SetKind(lldb::QueueItemKind kind) {
73   if (m_queue_item_sp) {
74     m_queue_item_sp->SetKind(kind);
75   }
76 }
77
78 SBAddress SBQueueItem::GetAddress() const {
79   SBAddress result;
80   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
81   if (m_queue_item_sp) {
82     result.SetAddress(&m_queue_item_sp->GetAddress());
83   }
84   if (log) {
85     StreamString sstr;
86     const Address *addr = result.get();
87     if (addr)
88       addr->Dump(&sstr, NULL, Address::DumpStyleModuleWithFileAddress,
89                  Address::DumpStyleInvalid, 4);
90     log->Printf("SBQueueItem(%p)::GetAddress() == SBAddress(%p): %s",
91                 static_cast<void *>(m_queue_item_sp.get()),
92                 static_cast<void *>(result.get()), sstr.GetData());
93   }
94   return result;
95 }
96
97 void SBQueueItem::SetAddress(SBAddress addr) {
98   if (m_queue_item_sp) {
99     m_queue_item_sp->SetAddress(addr.ref());
100   }
101 }
102
103 SBThread SBQueueItem::GetExtendedBacktraceThread(const char *type) {
104   SBThread result;
105   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
106   if (m_queue_item_sp) {
107     ProcessSP process_sp = m_queue_item_sp->GetProcessSP();
108     Process::StopLocker stop_locker;
109     if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) {
110       ThreadSP thread_sp;
111       ConstString type_const(type);
112       thread_sp = m_queue_item_sp->GetExtendedBacktraceThread(type_const);
113       if (thread_sp) {
114         // Save this in the Process' ExtendedThreadList so a strong pointer
115         // retains the
116         // object
117         process_sp->GetExtendedThreadList().AddThread(thread_sp);
118         result.SetThread(thread_sp);
119         if (log) {
120           const char *queue_name = thread_sp->GetQueueName();
121           if (queue_name == NULL)
122             queue_name = "";
123           log->Printf(
124               "SBQueueItem(%p)::GetExtendedBacktraceThread() = new extended "
125               "Thread created (%p) with queue_id 0x%" PRIx64 " queue name '%s'",
126               static_cast<void *>(m_queue_item_sp.get()),
127               static_cast<void *>(thread_sp.get()),
128               static_cast<uint64_t>(thread_sp->GetQueueID()), queue_name);
129         }
130       }
131     }
132   }
133   return result;
134 }