]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/API/SBBreakpointLocation.cpp
Import the skein hashing algorithm, based on the threefish block cipher
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / API / SBBreakpointLocation.cpp
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 #include "lldb/API/SBBreakpointLocation.h"
11 #include "lldb/API/SBDefines.h"
12 #include "lldb/API/SBAddress.h"
13 #include "lldb/API/SBDebugger.h"
14 #include "lldb/API/SBStream.h"
15
16 #include "lldb/lldb-types.h"
17 #include "lldb/lldb-defines.h"
18 #include "lldb/Breakpoint/Breakpoint.h"
19 #include "lldb/Breakpoint/BreakpointLocation.h"
20 #include "lldb/Core/Debugger.h"
21 #include "lldb/Core/Log.h"
22 #include "lldb/Core/Stream.h"
23 #include "lldb/Core/StreamFile.h"
24 #include "lldb/Interpreter/CommandInterpreter.h"
25 #include "lldb/Interpreter/ScriptInterpreter.h"
26 #include "lldb/Target/ThreadSpec.h"
27 #include "lldb/Target/Target.h"
28 #include "lldb/Target/ThreadSpec.h"
29
30 using namespace lldb;
31 using namespace lldb_private;
32
33
34 SBBreakpointLocation::SBBreakpointLocation () :
35     m_opaque_sp ()
36 {
37 }
38
39 SBBreakpointLocation::SBBreakpointLocation (const lldb::BreakpointLocationSP &break_loc_sp) :
40     m_opaque_sp (break_loc_sp)
41 {
42     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
43
44     if (log)
45     {
46         SBStream sstr;
47         GetDescription (sstr, lldb::eDescriptionLevelBrief);
48         log->Printf ("SBBreakpointLocation::SBBreakpointLocaiton (const lldb::BreakpointLocationsSP &break_loc_sp"
49                      "=%p)  => this.sp = %p (%s)",
50                      static_cast<void*>(break_loc_sp.get()),
51                      static_cast<void*>(m_opaque_sp.get()), sstr.GetData());
52     }
53 }
54
55 SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs) :
56     m_opaque_sp (rhs.m_opaque_sp)
57 {
58 }
59
60 const SBBreakpointLocation &
61 SBBreakpointLocation::operator = (const SBBreakpointLocation &rhs)
62 {
63     if (this != &rhs)
64         m_opaque_sp = rhs.m_opaque_sp;
65     return *this;
66 }
67
68
69 SBBreakpointLocation::~SBBreakpointLocation ()
70 {
71 }
72
73 bool
74 SBBreakpointLocation::IsValid() const
75 {
76     return m_opaque_sp.get() != NULL;
77 }
78
79 SBAddress
80 SBBreakpointLocation::GetAddress ()
81 {
82     if (m_opaque_sp)
83         return SBAddress(&m_opaque_sp->GetAddress());
84     else
85         return SBAddress();
86 }
87
88 addr_t
89 SBBreakpointLocation::GetLoadAddress ()
90 {
91     addr_t ret_addr = LLDB_INVALID_ADDRESS;
92
93     if (m_opaque_sp)
94     {
95         Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
96         ret_addr = m_opaque_sp->GetLoadAddress();
97     }
98
99     return ret_addr;
100 }
101
102 void
103 SBBreakpointLocation::SetEnabled (bool enabled)
104 {
105     if (m_opaque_sp)
106     {
107         Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
108         m_opaque_sp->SetEnabled (enabled);
109     }
110 }
111
112 bool
113 SBBreakpointLocation::IsEnabled ()
114 {
115     if (m_opaque_sp)
116     {
117         Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
118         return m_opaque_sp->IsEnabled();
119     }
120     else
121         return false;
122 }
123
124 uint32_t
125 SBBreakpointLocation::GetIgnoreCount ()
126 {
127     if (m_opaque_sp)
128     {
129         Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
130         return m_opaque_sp->GetIgnoreCount();
131     }
132     else
133         return 0;
134 }
135
136 void
137 SBBreakpointLocation::SetIgnoreCount (uint32_t n)
138 {
139     if (m_opaque_sp)
140     {
141         Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
142         m_opaque_sp->SetIgnoreCount (n);
143     }
144 }
145
146 void
147 SBBreakpointLocation::SetCondition (const char *condition)
148 {
149     if (m_opaque_sp)
150     {
151         Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
152         m_opaque_sp->SetCondition (condition);
153     }
154 }
155
156 const char *
157 SBBreakpointLocation::GetCondition ()
158 {
159     if (m_opaque_sp)
160     {
161         Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
162         return m_opaque_sp->GetConditionText ();
163     }
164     return NULL;
165 }
166
167 void
168 SBBreakpointLocation::SetScriptCallbackFunction (const char *callback_function_name)
169 {
170     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
171
172     if (log)
173         log->Printf ("SBBreakpointLocation(%p)::SetScriptCallbackFunction (callback=%s)",
174                      static_cast<void*>(m_opaque_sp.get()),
175                      callback_function_name);
176
177     if (m_opaque_sp)
178     {
179         Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
180         BreakpointOptions *bp_options = m_opaque_sp->GetLocationOptions();
181         m_opaque_sp->GetBreakpoint().GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter()->SetBreakpointCommandCallbackFunction (bp_options,
182                                                                                                                                      callback_function_name);
183     }
184 }
185
186 SBError
187 SBBreakpointLocation::SetScriptCallbackBody (const char *callback_body_text)
188 {
189     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
190
191     if (log)
192         log->Printf ("SBBreakpoint(%p)::SetScriptCallbackBody: callback body:\n%s)",
193                      static_cast<void*>(m_opaque_sp.get()), callback_body_text);
194
195     SBError sb_error;
196     if (m_opaque_sp)
197     {
198         Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
199         BreakpointOptions *bp_options = m_opaque_sp->GetLocationOptions();
200         Error error = m_opaque_sp->GetBreakpoint().GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter()->SetBreakpointCommandCallback (bp_options,
201                                                                                                                                                            callback_body_text);
202         sb_error.SetError(error);
203     }
204     else
205         sb_error.SetErrorString("invalid breakpoint");
206
207     return sb_error;
208 }
209
210 void
211 SBBreakpointLocation::SetThreadID (tid_t thread_id)
212 {
213     if (m_opaque_sp)
214     {
215         Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
216         m_opaque_sp->SetThreadID (thread_id);
217     }
218 }
219
220 tid_t
221 SBBreakpointLocation::GetThreadID ()
222 {
223     tid_t tid = LLDB_INVALID_THREAD_ID;
224     if (m_opaque_sp)
225     {
226         Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
227         return m_opaque_sp->GetThreadID();
228     }
229     return tid;
230 }
231
232 void
233 SBBreakpointLocation::SetThreadIndex (uint32_t index)
234 {
235     if (m_opaque_sp)
236     {
237         Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
238         m_opaque_sp->SetThreadIndex (index);
239     }
240 }
241
242 uint32_t
243 SBBreakpointLocation::GetThreadIndex() const
244 {
245     uint32_t thread_idx = UINT32_MAX;
246     if (m_opaque_sp)
247     {
248         Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
249         return m_opaque_sp->GetThreadIndex();
250     }
251     return thread_idx;
252 }
253     
254
255 void
256 SBBreakpointLocation::SetThreadName (const char *thread_name)
257 {
258     if (m_opaque_sp)
259     {
260         Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
261         m_opaque_sp->SetThreadName (thread_name);
262     }
263 }
264
265 const char *
266 SBBreakpointLocation::GetThreadName () const
267 {
268     if (m_opaque_sp)
269     {
270         Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
271         return m_opaque_sp->GetThreadName();
272     }
273     return NULL;
274 }
275
276 void
277 SBBreakpointLocation::SetQueueName (const char *queue_name)
278 {
279     if (m_opaque_sp)
280     {
281         Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
282         m_opaque_sp->SetQueueName (queue_name);
283     }
284 }
285
286 const char *
287 SBBreakpointLocation::GetQueueName () const
288 {
289     if (m_opaque_sp)
290     {
291         Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
292         m_opaque_sp->GetQueueName ();
293     }
294     return NULL;
295 }
296
297 bool
298 SBBreakpointLocation::IsResolved ()
299 {
300     if (m_opaque_sp)
301     {
302         Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
303         return m_opaque_sp->IsResolved();
304     }
305     return false;
306 }
307
308 void
309 SBBreakpointLocation::SetLocation (const lldb::BreakpointLocationSP &break_loc_sp)
310 {
311     // Uninstall the callbacks?
312     m_opaque_sp = break_loc_sp;
313 }
314
315 bool
316 SBBreakpointLocation::GetDescription (SBStream &description, DescriptionLevel level)
317 {
318     Stream &strm = description.ref();
319
320     if (m_opaque_sp)
321     {
322         Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
323         m_opaque_sp->GetDescription (&strm, level);
324         strm.EOL();
325     }
326     else
327         strm.PutCString ("No value");
328
329     return true;
330 }
331
332 break_id_t
333 SBBreakpointLocation::GetID ()
334 {
335     if (m_opaque_sp)
336     {
337         Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
338         return m_opaque_sp->GetID ();
339     }
340     else
341         return LLDB_INVALID_BREAK_ID;
342 }
343
344 SBBreakpoint
345 SBBreakpointLocation::GetBreakpoint ()
346 {
347     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
348
349     //if (log)
350     //    log->Printf ("SBBreakpointLocation::GetBreakpoint ()");
351
352     SBBreakpoint sb_bp;
353     if (m_opaque_sp)
354     {
355         Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
356         *sb_bp = m_opaque_sp->GetBreakpoint ().shared_from_this();
357     }
358
359     if (log)
360     {
361         SBStream sstr;
362         sb_bp.GetDescription (sstr);
363         log->Printf ("SBBreakpointLocation(%p)::GetBreakpoint () => SBBreakpoint(%p) %s",
364                      static_cast<void*>(m_opaque_sp.get()),
365                      static_cast<void*>(sb_bp.get()), sstr.GetData());
366     }
367     return sb_bp;
368 }
369