]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/API/SBQueueItem.cpp
MFV r304057:
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / 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 () :
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     bool is_valid = m_queue_item_sp.get() != NULL;
49     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
50     if (log)
51         log->Printf("SBQueueItem(%p)::IsValid() == %s",
52                     static_cast<void*>(m_queue_item_sp.get()),
53                     is_valid ? "true" : "false");
54     return is_valid;
55 }
56
57
58 void
59 SBQueueItem::Clear ()
60 {
61     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
62     if (log)
63         log->Printf("SBQueueItem(%p)::Clear()",
64                     static_cast<void*>(m_queue_item_sp.get()));
65     m_queue_item_sp.reset();
66 }
67
68
69 void
70 SBQueueItem::SetQueueItem (const QueueItemSP& queue_item_sp)
71 {
72     m_queue_item_sp = queue_item_sp;
73 }
74
75
76 lldb::QueueItemKind
77 SBQueueItem::GetKind () const
78 {
79     QueueItemKind result = eQueueItemKindUnknown;
80     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
81     if (m_queue_item_sp)
82     {
83         result = m_queue_item_sp->GetKind ();
84     }
85     if (log)
86         log->Printf("SBQueueItem(%p)::GetKind() == %d",
87                     static_cast<void*>(m_queue_item_sp.get()),
88                     static_cast<int>(result));
89     return result;
90 }
91
92 void
93 SBQueueItem::SetKind (lldb::QueueItemKind kind)
94 {
95     if (m_queue_item_sp)
96     {
97         m_queue_item_sp->SetKind (kind);
98     }
99 }
100
101 SBAddress
102 SBQueueItem::GetAddress () const
103 {
104     SBAddress result;
105     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
106     if (m_queue_item_sp)
107     {
108         result.SetAddress (&m_queue_item_sp->GetAddress());
109     }
110     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",
117                      static_cast<void*>(m_queue_item_sp.get()),
118                      static_cast<void*>(result.get()), sstr.GetData());
119     }
120     return result;
121 }
122
123 void
124 SBQueueItem::SetAddress (SBAddress addr)
125 {
126     if (m_queue_item_sp)
127     {
128         m_queue_item_sp->SetAddress (addr.ref());
129     }
130 }
131
132 SBThread
133 SBQueueItem::GetExtendedBacktraceThread (const char *type)
134 {
135     SBThread result;
136     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
137     if (m_queue_item_sp)
138     {
139         ProcessSP process_sp = m_queue_item_sp->GetProcessSP();
140         Process::StopLocker stop_locker;
141         if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock()))
142         {
143             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);
152                 if (log)
153                 {
154                     const char *queue_name = thread_sp->GetQueueName();
155                     if (queue_name == NULL)
156                         queue_name = "";
157                     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);
162                 }
163             }
164         }
165     }
166     return result;
167 }