1 //===-- SBBreakpointLocation.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 // In order to guarantee correct working with Python, Python.h *MUST* be
11 // the *FIRST* header file included:
12 
13 #include <Python.h>
14 
15 #include "lldb/API/SBBreakpointLocation.h"
16 #include "lldb/API/SBDefines.h"
17 #include "lldb/API/SBDebugger.h"
18 #include "lldb/API/SBStream.h"
19 
20 #include "lldb/lldb-types.h"
21 #include "lldb/lldb-defines.h"
22 #include "lldb/Breakpoint/BreakpointLocation.h"
23 #include "lldb/Target/ThreadSpec.h"
24 #include "lldb/Core/Stream.h"
25 #include "lldb/Core/StreamFile.h"
26 #include "lldb/Target/ThreadSpec.h"
27 
28 using namespace lldb;
29 using namespace lldb_private;
30 
31 
32 
33 //class SBBreakpointLocation
34 
35 SBBreakpointLocation::SBBreakpointLocation ()
36 {
37 }
38 
39 SBBreakpointLocation::SBBreakpointLocation (const lldb::BreakpointLocationSP &break_loc_sp) :
40     m_opaque_sp (break_loc_sp)
41 {
42 }
43 
44 SBBreakpointLocation::~SBBreakpointLocation ()
45 {
46 }
47 
48 bool
49 SBBreakpointLocation::IsValid() const
50 {
51     return m_opaque_sp.get() != NULL;
52 }
53 
54 addr_t
55 SBBreakpointLocation::GetLoadAddress ()
56 {
57     addr_t ret_addr = LLDB_INVALID_ADDRESS;
58 
59     if (m_opaque_sp)
60     {
61         ret_addr = m_opaque_sp->GetLoadAddress();
62     }
63 
64     return ret_addr;
65 }
66 
67 void
68 SBBreakpointLocation::SetEnabled (bool enabled)
69 {
70     if (m_opaque_sp)
71     {
72         m_opaque_sp->SetEnabled (enabled);
73     }
74 }
75 
76 bool
77 SBBreakpointLocation::IsEnabled ()
78 {
79     if (m_opaque_sp)
80         return m_opaque_sp->IsEnabled();
81     else
82         return false;
83 }
84 
85 uint32_t
86 SBBreakpointLocation::GetIgnoreCount ()
87 {
88     if (m_opaque_sp)
89         return m_opaque_sp->GetIgnoreCount();
90     else
91         return 0;
92 }
93 
94 void
95 SBBreakpointLocation::SetIgnoreCount (uint32_t n)
96 {
97     if (m_opaque_sp)
98         m_opaque_sp->SetIgnoreCount (n);
99 }
100 
101 void
102 SBBreakpointLocation::SetThreadID (tid_t thread_id)
103 {
104     if (m_opaque_sp)
105         m_opaque_sp->SetThreadID (thread_id);
106 }
107 
108 tid_t
109 SBBreakpointLocation::GetThreadID ()
110 {
111     tid_t sb_thread_id = (lldb::tid_t) LLDB_INVALID_THREAD_ID;
112     if (m_opaque_sp)
113         sb_thread_id = m_opaque_sp->GetLocationOptions()->GetThreadSpecNoCreate()->GetTID();
114     return sb_thread_id;
115 }
116 
117 void
118 SBBreakpointLocation::SetThreadIndex (uint32_t index)
119 {
120     if (m_opaque_sp)
121         m_opaque_sp->GetLocationOptions()->GetThreadSpec()->SetIndex (index);
122 }
123 
124 uint32_t
125 SBBreakpointLocation::GetThreadIndex() const
126 {
127     if (m_opaque_sp)
128     {
129         const ThreadSpec *thread_spec = m_opaque_sp->GetOptionsNoCreate()->GetThreadSpecNoCreate();
130         if (thread_spec == NULL)
131             return 0;
132         else
133             return thread_spec->GetIndex();
134     }
135     return 0;
136 }
137 
138 
139 void
140 SBBreakpointLocation::SetThreadName (const char *thread_name)
141 {
142     if (m_opaque_sp)
143         m_opaque_sp->GetLocationOptions()->GetThreadSpec()->SetName (thread_name);
144 }
145 
146 const char *
147 SBBreakpointLocation::GetThreadName () const
148 {
149     if (m_opaque_sp)
150     {
151         const ThreadSpec *thread_spec = m_opaque_sp->GetOptionsNoCreate()->GetThreadSpecNoCreate();
152         if (thread_spec == NULL)
153             return NULL;
154         else
155             return thread_spec->GetName();
156     }
157     return NULL;
158 }
159 
160 void
161 SBBreakpointLocation::SetQueueName (const char *queue_name)
162 {
163     if (m_opaque_sp)
164         m_opaque_sp->GetLocationOptions()->GetThreadSpec()->SetQueueName (queue_name);
165 }
166 
167 const char *
168 SBBreakpointLocation::GetQueueName () const
169 {
170     if (m_opaque_sp)
171     {
172         const ThreadSpec *thread_spec = m_opaque_sp->GetOptionsNoCreate()->GetThreadSpecNoCreate();
173         if (thread_spec == NULL)
174             return NULL;
175         else
176             return thread_spec->GetQueueName();
177     }
178     return NULL;
179 }
180 
181 bool
182 SBBreakpointLocation::IsResolved ()
183 {
184     if (m_opaque_sp)
185         return m_opaque_sp->IsResolved();
186     else
187         return false;
188 }
189 
190 void
191 SBBreakpointLocation::SetLocation (const lldb::BreakpointLocationSP &break_loc_sp)
192 {
193     if (m_opaque_sp)
194     {
195         // Uninstall the callbacks?
196     }
197     m_opaque_sp = break_loc_sp;
198 }
199 
200 bool
201 SBBreakpointLocation::GetDescription (const char *description_level, SBStream &description)
202 {
203     if (m_opaque_sp)
204     {
205         DescriptionLevel level;
206         if (strcmp (description_level, "brief") == 0)
207             level = eDescriptionLevelBrief;
208         else if (strcmp (description_level, "full") == 0)
209             level = eDescriptionLevelFull;
210         else if (strcmp (description_level, "verbose") == 0)
211             level = eDescriptionLevelVerbose;
212         else
213             level = eDescriptionLevelBrief;
214 
215         description.ref();
216         m_opaque_sp->GetDescription (description.get(), level);
217         description.get()->EOL();
218     }
219     else
220         description.Printf ("No value");
221 
222     return true;
223 }
224 
225 SBBreakpoint
226 SBBreakpointLocation::GetBreakpoint ()
227 {
228     SBBreakpoint sb_bp;
229     if (m_opaque_sp)
230         *sb_bp = m_opaque_sp->GetBreakpoint ().GetSP();
231     return sb_bp;
232 }
233 
234