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::SetCondition (const char *condition)
103 {
104     m_opaque_sp->SetCondition (condition);
105 }
106 
107 const char *
108 SBBreakpointLocation::GetCondition ()
109 {
110     return m_opaque_sp->GetConditionText ();
111 }
112 
113 void
114 SBBreakpointLocation::SetThreadID (tid_t thread_id)
115 {
116     if (m_opaque_sp)
117         m_opaque_sp->SetThreadID (thread_id);
118 }
119 
120 tid_t
121 SBBreakpointLocation::GetThreadID ()
122 {
123     tid_t sb_thread_id = (lldb::tid_t) LLDB_INVALID_THREAD_ID;
124     if (m_opaque_sp)
125         sb_thread_id = m_opaque_sp->GetLocationOptions()->GetThreadSpecNoCreate()->GetTID();
126     return sb_thread_id;
127 }
128 
129 void
130 SBBreakpointLocation::SetThreadIndex (uint32_t index)
131 {
132     if (m_opaque_sp)
133         m_opaque_sp->GetLocationOptions()->GetThreadSpec()->SetIndex (index);
134 }
135 
136 uint32_t
137 SBBreakpointLocation::GetThreadIndex() const
138 {
139     if (m_opaque_sp)
140     {
141         const ThreadSpec *thread_spec = m_opaque_sp->GetOptionsNoCreate()->GetThreadSpecNoCreate();
142         if (thread_spec == NULL)
143             return 0;
144         else
145             return thread_spec->GetIndex();
146     }
147     return 0;
148 }
149 
150 
151 void
152 SBBreakpointLocation::SetThreadName (const char *thread_name)
153 {
154     if (m_opaque_sp)
155         m_opaque_sp->GetLocationOptions()->GetThreadSpec()->SetName (thread_name);
156 }
157 
158 const char *
159 SBBreakpointLocation::GetThreadName () const
160 {
161     if (m_opaque_sp)
162     {
163         const ThreadSpec *thread_spec = m_opaque_sp->GetOptionsNoCreate()->GetThreadSpecNoCreate();
164         if (thread_spec == NULL)
165             return NULL;
166         else
167             return thread_spec->GetName();
168     }
169     return NULL;
170 }
171 
172 void
173 SBBreakpointLocation::SetQueueName (const char *queue_name)
174 {
175     if (m_opaque_sp)
176         m_opaque_sp->GetLocationOptions()->GetThreadSpec()->SetQueueName (queue_name);
177 }
178 
179 const char *
180 SBBreakpointLocation::GetQueueName () const
181 {
182     if (m_opaque_sp)
183     {
184         const ThreadSpec *thread_spec = m_opaque_sp->GetOptionsNoCreate()->GetThreadSpecNoCreate();
185         if (thread_spec == NULL)
186             return NULL;
187         else
188             return thread_spec->GetQueueName();
189     }
190     return NULL;
191 }
192 
193 bool
194 SBBreakpointLocation::IsResolved ()
195 {
196     if (m_opaque_sp)
197         return m_opaque_sp->IsResolved();
198     else
199         return false;
200 }
201 
202 void
203 SBBreakpointLocation::SetLocation (const lldb::BreakpointLocationSP &break_loc_sp)
204 {
205     if (m_opaque_sp)
206     {
207         // Uninstall the callbacks?
208     }
209     m_opaque_sp = break_loc_sp;
210 }
211 
212 bool
213 SBBreakpointLocation::GetDescription (const char *description_level, SBStream &description)
214 {
215     if (m_opaque_sp)
216     {
217         DescriptionLevel level;
218         if (strcmp (description_level, "brief") == 0)
219             level = eDescriptionLevelBrief;
220         else if (strcmp (description_level, "full") == 0)
221             level = eDescriptionLevelFull;
222         else if (strcmp (description_level, "verbose") == 0)
223             level = eDescriptionLevelVerbose;
224         else
225             level = eDescriptionLevelBrief;
226 
227         description.ref();
228         m_opaque_sp->GetDescription (description.get(), level);
229         description.get()->EOL();
230     }
231     else
232         description.Printf ("No value");
233 
234     return true;
235 }
236 
237 SBBreakpoint
238 SBBreakpointLocation::GetBreakpoint ()
239 {
240     SBBreakpoint sb_bp;
241     if (m_opaque_sp)
242         *sb_bp = m_opaque_sp->GetBreakpoint ().GetSP();
243     return sb_bp;
244 }
245 
246