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