1254721Semaste//===-- SBBreakpoint.cpp ----------------------------------------*- C++ -*-===//
2254721Semaste//
3254721Semaste//                     The LLVM Compiler Infrastructure
4254721Semaste//
5254721Semaste// This file is distributed under the University of Illinois Open Source
6254721Semaste// License. See LICENSE.TXT for details.
7254721Semaste//
8254721Semaste//===----------------------------------------------------------------------===//
9254721Semaste
10254721Semaste#include "lldb/API/SBBreakpoint.h"
11254721Semaste#include "lldb/API/SBBreakpointLocation.h"
12254721Semaste#include "lldb/API/SBDebugger.h"
13254721Semaste#include "lldb/API/SBEvent.h"
14254721Semaste#include "lldb/API/SBProcess.h"
15254721Semaste#include "lldb/API/SBStream.h"
16254721Semaste#include "lldb/API/SBThread.h"
17254721Semaste
18254721Semaste#include "lldb/Breakpoint/Breakpoint.h"
19254721Semaste#include "lldb/Breakpoint/BreakpointLocation.h"
20254721Semaste#include "lldb/Breakpoint/StoppointCallbackContext.h"
21254721Semaste#include "lldb/Core/Address.h"
22254721Semaste#include "lldb/Core/Log.h"
23254721Semaste#include "lldb/Core/Stream.h"
24254721Semaste#include "lldb/Core/StreamFile.h"
25254721Semaste#include "lldb/Target/Process.h"
26254721Semaste#include "lldb/Target/Target.h"
27254721Semaste#include "lldb/Target/Thread.h"
28254721Semaste#include "lldb/Target/ThreadSpec.h"
29254721Semaste
30254721Semaste
31254721Semaste#include "lldb/lldb-enumerations.h"
32254721Semaste
33254721Semasteusing namespace lldb;
34254721Semasteusing namespace lldb_private;
35254721Semaste
36254721Semastestruct CallbackData
37254721Semaste{
38254721Semaste    SBBreakpoint::BreakpointHitCallback callback;
39254721Semaste    void *callback_baton;
40254721Semaste};
41254721Semaste
42254721Semasteclass SBBreakpointCallbackBaton : public Baton
43254721Semaste{
44254721Semastepublic:
45254721Semaste
46254721Semaste    SBBreakpointCallbackBaton (SBBreakpoint::BreakpointHitCallback callback, void *baton) :
47254721Semaste        Baton (new CallbackData)
48254721Semaste    {
49254721Semaste        CallbackData *data = (CallbackData *)m_data;
50254721Semaste        data->callback = callback;
51254721Semaste        data->callback_baton = baton;
52254721Semaste    }
53254721Semaste
54254721Semaste    virtual ~SBBreakpointCallbackBaton()
55254721Semaste    {
56254721Semaste        CallbackData *data = (CallbackData *)m_data;
57254721Semaste
58254721Semaste        if (data)
59254721Semaste        {
60254721Semaste            delete data;
61254721Semaste            m_data = NULL;
62254721Semaste        }
63254721Semaste    }
64254721Semaste};
65254721Semaste
66254721Semaste
67254721SemasteSBBreakpoint::SBBreakpoint () :
68254721Semaste    m_opaque_sp ()
69254721Semaste{
70254721Semaste}
71254721Semaste
72254721SemasteSBBreakpoint::SBBreakpoint (const SBBreakpoint& rhs) :
73254721Semaste    m_opaque_sp (rhs.m_opaque_sp)
74254721Semaste{
75254721Semaste}
76254721Semaste
77254721Semaste
78254721SemasteSBBreakpoint::SBBreakpoint (const lldb::BreakpointSP &bp_sp) :
79254721Semaste    m_opaque_sp (bp_sp)
80254721Semaste{
81254721Semaste}
82254721Semaste
83254721SemasteSBBreakpoint::~SBBreakpoint()
84254721Semaste{
85254721Semaste}
86254721Semaste
87254721Semasteconst SBBreakpoint &
88254721SemasteSBBreakpoint::operator = (const SBBreakpoint& rhs)
89254721Semaste{
90254721Semaste    if (this != &rhs)
91254721Semaste        m_opaque_sp = rhs.m_opaque_sp;
92254721Semaste    return *this;
93254721Semaste}
94254721Semaste
95254721Semastebool
96254721SemasteSBBreakpoint::operator == (const lldb::SBBreakpoint& rhs)
97254721Semaste{
98254721Semaste    if (m_opaque_sp && rhs.m_opaque_sp)
99254721Semaste        return m_opaque_sp.get() == rhs.m_opaque_sp.get();
100254721Semaste    return false;
101254721Semaste}
102254721Semaste
103254721Semastebool
104254721SemasteSBBreakpoint::operator != (const lldb::SBBreakpoint& rhs)
105254721Semaste{
106254721Semaste    if (m_opaque_sp && rhs.m_opaque_sp)
107254721Semaste        return m_opaque_sp.get() != rhs.m_opaque_sp.get();
108254721Semaste    return (m_opaque_sp && !rhs.m_opaque_sp) || (rhs.m_opaque_sp && !m_opaque_sp);
109254721Semaste}
110254721Semaste
111254721Semastebreak_id_t
112254721SemasteSBBreakpoint::GetID () const
113254721Semaste{
114254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
115254721Semaste
116254721Semaste    break_id_t break_id = LLDB_INVALID_BREAK_ID;
117254721Semaste    if (m_opaque_sp)
118254721Semaste        break_id = m_opaque_sp->GetID();
119254721Semaste
120254721Semaste    if (log)
121254721Semaste    {
122254721Semaste        if (break_id == LLDB_INVALID_BREAK_ID)
123254721Semaste            log->Printf ("SBBreakpoint(%p)::GetID () => LLDB_INVALID_BREAK_ID", m_opaque_sp.get());
124254721Semaste        else
125254721Semaste            log->Printf ("SBBreakpoint(%p)::GetID () => %u", m_opaque_sp.get(), break_id);
126254721Semaste    }
127254721Semaste
128254721Semaste    return break_id;
129254721Semaste}
130254721Semaste
131254721Semaste
132254721Semastebool
133254721SemasteSBBreakpoint::IsValid() const
134254721Semaste{
135254721Semaste    return (bool) m_opaque_sp;
136254721Semaste}
137254721Semaste
138254721Semastevoid
139254721SemasteSBBreakpoint::ClearAllBreakpointSites ()
140254721Semaste{
141254721Semaste    if (m_opaque_sp)
142254721Semaste    {
143254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
144254721Semaste        m_opaque_sp->ClearAllBreakpointSites ();
145254721Semaste    }
146254721Semaste}
147254721Semaste
148254721SemasteSBBreakpointLocation
149254721SemasteSBBreakpoint::FindLocationByAddress (addr_t vm_addr)
150254721Semaste{
151254721Semaste    SBBreakpointLocation sb_bp_location;
152254721Semaste
153254721Semaste    if (m_opaque_sp)
154254721Semaste    {
155254721Semaste        if (vm_addr != LLDB_INVALID_ADDRESS)
156254721Semaste        {
157254721Semaste            Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
158254721Semaste            Address address;
159254721Semaste            Target &target = m_opaque_sp->GetTarget();
160254721Semaste            if (target.GetSectionLoadList().ResolveLoadAddress (vm_addr, address) == false)
161254721Semaste            {
162254721Semaste                address.SetRawAddress (vm_addr);
163254721Semaste            }
164254721Semaste            sb_bp_location.SetLocation (m_opaque_sp->FindLocationByAddress (address));
165254721Semaste        }
166254721Semaste    }
167254721Semaste    return sb_bp_location;
168254721Semaste}
169254721Semaste
170254721Semastebreak_id_t
171254721SemasteSBBreakpoint::FindLocationIDByAddress (addr_t vm_addr)
172254721Semaste{
173254721Semaste    break_id_t break_id = LLDB_INVALID_BREAK_ID;
174254721Semaste
175254721Semaste    if (m_opaque_sp && vm_addr != LLDB_INVALID_ADDRESS)
176254721Semaste    {
177254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
178254721Semaste        Address address;
179254721Semaste        Target &target = m_opaque_sp->GetTarget();
180254721Semaste        if (target.GetSectionLoadList().ResolveLoadAddress (vm_addr, address) == false)
181254721Semaste        {
182254721Semaste            address.SetRawAddress (vm_addr);
183254721Semaste        }
184254721Semaste        break_id = m_opaque_sp->FindLocationIDByAddress (address);
185254721Semaste    }
186254721Semaste
187254721Semaste    return break_id;
188254721Semaste}
189254721Semaste
190254721SemasteSBBreakpointLocation
191254721SemasteSBBreakpoint::FindLocationByID (break_id_t bp_loc_id)
192254721Semaste{
193254721Semaste    SBBreakpointLocation sb_bp_location;
194254721Semaste
195254721Semaste    if (m_opaque_sp)
196254721Semaste    {
197254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
198254721Semaste        sb_bp_location.SetLocation (m_opaque_sp->FindLocationByID (bp_loc_id));
199254721Semaste    }
200254721Semaste
201254721Semaste    return sb_bp_location;
202254721Semaste}
203254721Semaste
204254721SemasteSBBreakpointLocation
205254721SemasteSBBreakpoint::GetLocationAtIndex (uint32_t index)
206254721Semaste{
207254721Semaste    SBBreakpointLocation sb_bp_location;
208254721Semaste
209254721Semaste    if (m_opaque_sp)
210254721Semaste    {
211254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
212254721Semaste        sb_bp_location.SetLocation (m_opaque_sp->GetLocationAtIndex (index));
213254721Semaste    }
214254721Semaste
215254721Semaste    return sb_bp_location;
216254721Semaste}
217254721Semaste
218254721Semastevoid
219254721SemasteSBBreakpoint::SetEnabled (bool enable)
220254721Semaste{
221254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
222254721Semaste
223254721Semaste    if (log)
224254721Semaste        log->Printf ("SBBreakpoint(%p)::SetEnabled (enabled=%i)", m_opaque_sp.get(), enable);
225254721Semaste
226254721Semaste    if (m_opaque_sp)
227254721Semaste    {
228254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
229254721Semaste        m_opaque_sp->SetEnabled (enable);
230254721Semaste    }
231254721Semaste}
232254721Semaste
233254721Semastebool
234254721SemasteSBBreakpoint::IsEnabled ()
235254721Semaste{
236254721Semaste    if (m_opaque_sp)
237254721Semaste    {
238254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
239254721Semaste        return m_opaque_sp->IsEnabled();
240254721Semaste    }
241254721Semaste    else
242254721Semaste        return false;
243254721Semaste}
244254721Semaste
245254721Semastevoid
246254721SemasteSBBreakpoint::SetOneShot (bool one_shot)
247254721Semaste{
248254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
249254721Semaste
250254721Semaste    if (log)
251254721Semaste        log->Printf ("SBBreakpoint(%p)::SetOneShot (one_shot=%i)", m_opaque_sp.get(), one_shot);
252254721Semaste
253254721Semaste    if (m_opaque_sp)
254254721Semaste    {
255254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
256254721Semaste        m_opaque_sp->SetOneShot (one_shot);
257254721Semaste    }
258254721Semaste}
259254721Semaste
260254721Semastebool
261254721SemasteSBBreakpoint::IsOneShot () const
262254721Semaste{
263254721Semaste    if (m_opaque_sp)
264254721Semaste    {
265254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
266254721Semaste        return m_opaque_sp->IsOneShot();
267254721Semaste    }
268254721Semaste    else
269254721Semaste        return false;
270254721Semaste}
271254721Semaste
272254721Semastebool
273254721SemasteSBBreakpoint::IsInternal ()
274254721Semaste{
275254721Semaste    if (m_opaque_sp)
276254721Semaste    {
277254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
278254721Semaste        return m_opaque_sp->IsInternal();
279254721Semaste    }
280254721Semaste    else
281254721Semaste        return false;
282254721Semaste}
283254721Semaste
284254721Semastevoid
285254721SemasteSBBreakpoint::SetIgnoreCount (uint32_t count)
286254721Semaste{
287254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
288254721Semaste
289254721Semaste    if (log)
290254721Semaste        log->Printf ("SBBreakpoint(%p)::SetIgnoreCount (count=%u)", m_opaque_sp.get(), count);
291254721Semaste
292254721Semaste    if (m_opaque_sp)
293254721Semaste    {
294254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
295254721Semaste        m_opaque_sp->SetIgnoreCount (count);
296254721Semaste    }
297254721Semaste}
298254721Semaste
299254721Semastevoid
300254721SemasteSBBreakpoint::SetCondition (const char *condition)
301254721Semaste{
302254721Semaste    if (m_opaque_sp)
303254721Semaste    {
304254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
305254721Semaste        m_opaque_sp->SetCondition (condition);
306254721Semaste    }
307254721Semaste}
308254721Semaste
309254721Semasteconst char *
310254721SemasteSBBreakpoint::GetCondition ()
311254721Semaste{
312254721Semaste    if (m_opaque_sp)
313254721Semaste    {
314254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
315254721Semaste        return m_opaque_sp->GetConditionText ();
316254721Semaste    }
317254721Semaste    return NULL;
318254721Semaste}
319254721Semaste
320254721Semasteuint32_t
321254721SemasteSBBreakpoint::GetHitCount () const
322254721Semaste{
323254721Semaste    uint32_t count = 0;
324254721Semaste    if (m_opaque_sp)
325254721Semaste    {
326254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
327254721Semaste        count = m_opaque_sp->GetHitCount();
328254721Semaste    }
329254721Semaste
330254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
331254721Semaste    if (log)
332254721Semaste        log->Printf ("SBBreakpoint(%p)::GetHitCount () => %u", m_opaque_sp.get(), count);
333254721Semaste
334254721Semaste    return count;
335254721Semaste}
336254721Semaste
337254721Semasteuint32_t
338254721SemasteSBBreakpoint::GetIgnoreCount () const
339254721Semaste{
340254721Semaste    uint32_t count = 0;
341254721Semaste    if (m_opaque_sp)
342254721Semaste    {
343254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
344254721Semaste        count = m_opaque_sp->GetIgnoreCount();
345254721Semaste    }
346254721Semaste
347254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
348254721Semaste    if (log)
349254721Semaste        log->Printf ("SBBreakpoint(%p)::GetIgnoreCount () => %u", m_opaque_sp.get(), count);
350254721Semaste
351254721Semaste    return count;
352254721Semaste}
353254721Semaste
354254721Semastevoid
355254721SemasteSBBreakpoint::SetThreadID (tid_t tid)
356254721Semaste{
357254721Semaste    if (m_opaque_sp)
358254721Semaste    {
359254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
360254721Semaste        m_opaque_sp->SetThreadID (tid);
361254721Semaste    }
362254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
363254721Semaste    if (log)
364254721Semaste        log->Printf ("SBBreakpoint(%p)::SetThreadID (tid=0x%4.4" PRIx64 ")", m_opaque_sp.get(), tid);
365254721Semaste
366254721Semaste}
367254721Semaste
368254721Semastetid_t
369254721SemasteSBBreakpoint::GetThreadID ()
370254721Semaste{
371254721Semaste    tid_t tid = LLDB_INVALID_THREAD_ID;
372254721Semaste    if (m_opaque_sp)
373254721Semaste    {
374254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
375254721Semaste        tid = m_opaque_sp->GetThreadID();
376254721Semaste    }
377254721Semaste
378254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
379254721Semaste    if (log)
380254721Semaste        log->Printf ("SBBreakpoint(%p)::GetThreadID () => 0x%4.4" PRIx64, m_opaque_sp.get(), tid);
381254721Semaste    return tid;
382254721Semaste}
383254721Semaste
384254721Semastevoid
385254721SemasteSBBreakpoint::SetThreadIndex (uint32_t index)
386254721Semaste{
387254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
388254721Semaste    if (log)
389254721Semaste        log->Printf ("SBBreakpoint(%p)::SetThreadIndex (%u)", m_opaque_sp.get(), index);
390254721Semaste    if (m_opaque_sp)
391254721Semaste    {
392254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
393254721Semaste        m_opaque_sp->GetOptions()->GetThreadSpec()->SetIndex (index);
394254721Semaste    }
395254721Semaste}
396254721Semaste
397254721Semasteuint32_t
398254721SemasteSBBreakpoint::GetThreadIndex() const
399254721Semaste{
400254721Semaste    uint32_t thread_idx = UINT32_MAX;
401254721Semaste    if (m_opaque_sp)
402254721Semaste    {
403254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
404254721Semaste        const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
405254721Semaste        if (thread_spec != NULL)
406254721Semaste            thread_idx = thread_spec->GetIndex();
407254721Semaste    }
408254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
409254721Semaste    if (log)
410254721Semaste        log->Printf ("SBBreakpoint(%p)::GetThreadIndex () => %u", m_opaque_sp.get(), thread_idx);
411254721Semaste
412254721Semaste    return thread_idx;
413254721Semaste}
414254721Semaste
415254721Semaste
416254721Semastevoid
417254721SemasteSBBreakpoint::SetThreadName (const char *thread_name)
418254721Semaste{
419254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
420254721Semaste    if (log)
421254721Semaste        log->Printf ("SBBreakpoint(%p)::SetThreadName (%s)", m_opaque_sp.get(), thread_name);
422254721Semaste
423254721Semaste    if (m_opaque_sp)
424254721Semaste    {
425254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
426254721Semaste        m_opaque_sp->GetOptions()->GetThreadSpec()->SetName (thread_name);
427254721Semaste    }
428254721Semaste}
429254721Semaste
430254721Semasteconst char *
431254721SemasteSBBreakpoint::GetThreadName () const
432254721Semaste{
433254721Semaste    const char *name = NULL;
434254721Semaste    if (m_opaque_sp)
435254721Semaste    {
436254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
437254721Semaste        const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
438254721Semaste        if (thread_spec != NULL)
439254721Semaste            name = thread_spec->GetName();
440254721Semaste    }
441254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
442254721Semaste    if (log)
443254721Semaste        log->Printf ("SBBreakpoint(%p)::GetThreadName () => %s", m_opaque_sp.get(), name);
444254721Semaste
445254721Semaste    return name;
446254721Semaste}
447254721Semaste
448254721Semastevoid
449254721SemasteSBBreakpoint::SetQueueName (const char *queue_name)
450254721Semaste{
451254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
452254721Semaste    if (log)
453254721Semaste        log->Printf ("SBBreakpoint(%p)::SetQueueName (%s)", m_opaque_sp.get(), queue_name);
454254721Semaste    if (m_opaque_sp)
455254721Semaste    {
456254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
457254721Semaste        m_opaque_sp->GetOptions()->GetThreadSpec()->SetQueueName (queue_name);
458254721Semaste    }
459254721Semaste}
460254721Semaste
461254721Semasteconst char *
462254721SemasteSBBreakpoint::GetQueueName () const
463254721Semaste{
464254721Semaste    const char *name = NULL;
465254721Semaste    if (m_opaque_sp)
466254721Semaste    {
467254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
468254721Semaste        const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
469254721Semaste        if (thread_spec)
470254721Semaste            name = thread_spec->GetQueueName();
471254721Semaste    }
472254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
473254721Semaste    if (log)
474254721Semaste        log->Printf ("SBBreakpoint(%p)::GetQueueName () => %s", m_opaque_sp.get(), name);
475254721Semaste
476254721Semaste    return name;
477254721Semaste}
478254721Semaste
479254721Semastesize_t
480254721SemasteSBBreakpoint::GetNumResolvedLocations() const
481254721Semaste{
482254721Semaste    size_t num_resolved = 0;
483254721Semaste    if (m_opaque_sp)
484254721Semaste    {
485254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
486254721Semaste        num_resolved = m_opaque_sp->GetNumResolvedLocations();
487254721Semaste    }
488254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
489254721Semaste    if (log)
490254721Semaste        log->Printf ("SBBreakpoint(%p)::GetNumResolvedLocations () => %" PRIu64, m_opaque_sp.get(), (uint64_t)num_resolved);
491254721Semaste    return num_resolved;
492254721Semaste}
493254721Semaste
494254721Semastesize_t
495254721SemasteSBBreakpoint::GetNumLocations() const
496254721Semaste{
497254721Semaste    size_t num_locs = 0;
498254721Semaste    if (m_opaque_sp)
499254721Semaste    {
500254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
501254721Semaste        num_locs = m_opaque_sp->GetNumLocations();
502254721Semaste    }
503254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
504254721Semaste    if (log)
505254721Semaste        log->Printf ("SBBreakpoint(%p)::GetNumLocations () => %" PRIu64, m_opaque_sp.get(), (uint64_t)num_locs);
506254721Semaste    return num_locs;
507254721Semaste}
508254721Semaste
509254721Semastebool
510254721SemasteSBBreakpoint::GetDescription (SBStream &s)
511254721Semaste{
512254721Semaste    if (m_opaque_sp)
513254721Semaste    {
514254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
515254721Semaste        s.Printf("SBBreakpoint: id = %i, ", m_opaque_sp->GetID());
516254721Semaste        m_opaque_sp->GetResolverDescription (s.get());
517254721Semaste        m_opaque_sp->GetFilterDescription (s.get());
518254721Semaste        const size_t num_locations = m_opaque_sp->GetNumLocations ();
519254721Semaste        s.Printf(", locations = %" PRIu64, (uint64_t)num_locations);
520254721Semaste        return true;
521254721Semaste    }
522254721Semaste    s.Printf ("No value");
523254721Semaste    return false;
524254721Semaste}
525254721Semaste
526254721Semastebool
527254721SemasteSBBreakpoint::PrivateBreakpointHitCallback
528254721Semaste(
529254721Semaste    void *baton,
530254721Semaste    StoppointCallbackContext *ctx,
531254721Semaste    lldb::user_id_t break_id,
532254721Semaste    lldb::user_id_t break_loc_id
533254721Semaste)
534254721Semaste{
535254721Semaste    ExecutionContext exe_ctx (ctx->exe_ctx_ref);
536254721Semaste    BreakpointSP bp_sp(exe_ctx.GetTargetRef().GetBreakpointList().FindBreakpointByID(break_id));
537254721Semaste    if (baton && bp_sp)
538254721Semaste    {
539254721Semaste        CallbackData *data = (CallbackData *)baton;
540254721Semaste        lldb_private::Breakpoint *bp = bp_sp.get();
541254721Semaste        if (bp && data->callback)
542254721Semaste        {
543254721Semaste            Process *process = exe_ctx.GetProcessPtr();
544254721Semaste            if (process)
545254721Semaste            {
546254721Semaste                SBProcess sb_process (process->shared_from_this());
547254721Semaste                SBThread sb_thread;
548254721Semaste                SBBreakpointLocation sb_location;
549254721Semaste                assert (bp_sp);
550254721Semaste                sb_location.SetLocation (bp_sp->FindLocationByID (break_loc_id));
551254721Semaste                Thread *thread = exe_ctx.GetThreadPtr();
552254721Semaste                if (thread)
553254721Semaste                    sb_thread.SetThread(thread->shared_from_this());
554254721Semaste
555254721Semaste                return data->callback (data->callback_baton,
556254721Semaste                                          sb_process,
557254721Semaste                                          sb_thread,
558254721Semaste                                          sb_location);
559254721Semaste            }
560254721Semaste        }
561254721Semaste    }
562254721Semaste    return true;    // Return true if we should stop at this breakpoint
563254721Semaste}
564254721Semaste
565254721Semastevoid
566254721SemasteSBBreakpoint::SetCallback (BreakpointHitCallback callback, void *baton)
567254721Semaste{
568254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
569254721Semaste
570254721Semaste    if (log)
571254721Semaste        log->Printf ("SBBreakpoint(%p)::SetCallback (callback=%p, baton=%p)", m_opaque_sp.get(), callback, baton);
572254721Semaste
573254721Semaste    if (m_opaque_sp)
574254721Semaste    {
575254721Semaste        Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
576254721Semaste        BatonSP baton_sp(new SBBreakpointCallbackBaton (callback, baton));
577254721Semaste        m_opaque_sp->SetCallback (SBBreakpoint::PrivateBreakpointHitCallback, baton_sp, false);
578254721Semaste    }
579254721Semaste}
580254721Semaste
581254721Semaste
582254721Semastelldb_private::Breakpoint *
583254721SemasteSBBreakpoint::operator->() const
584254721Semaste{
585254721Semaste    return m_opaque_sp.get();
586254721Semaste}
587254721Semaste
588254721Semastelldb_private::Breakpoint *
589254721SemasteSBBreakpoint::get() const
590254721Semaste{
591254721Semaste    return m_opaque_sp.get();
592254721Semaste}
593254721Semaste
594254721Semastelldb::BreakpointSP &
595254721SemasteSBBreakpoint::operator *()
596254721Semaste{
597254721Semaste    return m_opaque_sp;
598254721Semaste}
599254721Semaste
600254721Semasteconst lldb::BreakpointSP &
601254721SemasteSBBreakpoint::operator *() const
602254721Semaste{
603254721Semaste    return m_opaque_sp;
604254721Semaste}
605254721Semaste
606254721Semastebool
607254721SemasteSBBreakpoint::EventIsBreakpointEvent (const lldb::SBEvent &event)
608254721Semaste{
609254721Semaste    return Breakpoint::BreakpointEventData::GetEventDataFromEvent(event.get()) != NULL;
610254721Semaste
611254721Semaste}
612254721Semaste
613254721SemasteBreakpointEventType
614254721SemasteSBBreakpoint::GetBreakpointEventTypeFromEvent (const SBEvent& event)
615254721Semaste{
616254721Semaste    if (event.IsValid())
617254721Semaste        return Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (event.GetSP());
618254721Semaste    return eBreakpointEventTypeInvalidType;
619254721Semaste}
620254721Semaste
621254721SemasteSBBreakpoint
622254721SemasteSBBreakpoint::GetBreakpointFromEvent (const lldb::SBEvent& event)
623254721Semaste{
624254721Semaste    SBBreakpoint sb_breakpoint;
625254721Semaste    if (event.IsValid())
626254721Semaste        sb_breakpoint.m_opaque_sp = Breakpoint::BreakpointEventData::GetBreakpointFromEvent (event.GetSP());
627254721Semaste    return sb_breakpoint;
628254721Semaste}
629254721Semaste
630254721SemasteSBBreakpointLocation
631254721SemasteSBBreakpoint::GetBreakpointLocationAtIndexFromEvent (const lldb::SBEvent& event, uint32_t loc_idx)
632254721Semaste{
633254721Semaste    SBBreakpointLocation sb_breakpoint_loc;
634254721Semaste    if (event.IsValid())
635254721Semaste        sb_breakpoint_loc.SetLocation (Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent (event.GetSP(), loc_idx));
636254721Semaste    return sb_breakpoint_loc;
637254721Semaste}
638254721Semaste
639254721Semasteuint32_t
640254721SemasteSBBreakpoint::GetNumBreakpointLocationsFromEvent (const lldb::SBEvent &event)
641254721Semaste{
642254721Semaste    uint32_t num_locations = 0;
643254721Semaste    if (event.IsValid())
644254721Semaste        num_locations = (Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent (event.GetSP()));
645254721Semaste    return num_locations;
646254721Semaste}
647254721Semaste
648254721Semaste
649