SBBreakpointLocation.cpp revision 9a29f00d3dae2e368bd01226388633fe8653808e
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/SBDebugger.h"
13#include "lldb/API/SBStream.h"
14
15#include "lldb/lldb-types.h"
16#include "lldb/lldb-defines.h"
17#include "lldb/Breakpoint/Breakpoint.h"
18#include "lldb/Breakpoint/BreakpointLocation.h"
19#include "lldb/Target/ThreadSpec.h"
20#include "lldb/Core/Log.h"
21#include "lldb/Core/Stream.h"
22#include "lldb/Core/StreamFile.h"
23#include "lldb/Target/Target.h"
24#include "lldb/Target/ThreadSpec.h"
25
26using namespace lldb;
27using namespace lldb_private;
28
29
30SBBreakpointLocation::SBBreakpointLocation () :
31    m_opaque_sp ()
32{
33}
34
35SBBreakpointLocation::SBBreakpointLocation (const lldb::BreakpointLocationSP &break_loc_sp) :
36    m_opaque_sp (break_loc_sp)
37{
38    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
39
40    if (log)
41    {
42        SBStream sstr;
43        GetDescription (sstr, lldb::eDescriptionLevelBrief);
44        log->Printf ("SBBreakpointLocation::SBBreakpointLocaiton (const lldb::BreakpointLocationsSP &break_loc_sp"
45                     "=%p)  => this.sp = %p (%s)", break_loc_sp.get(), m_opaque_sp.get(), sstr.GetData());
46    }
47}
48
49SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs) :
50    m_opaque_sp (rhs.m_opaque_sp)
51{
52}
53
54const SBBreakpointLocation &
55SBBreakpointLocation::operator = (const SBBreakpointLocation &rhs)
56{
57    if (this != &rhs)
58        m_opaque_sp = rhs.m_opaque_sp;
59    return *this;
60}
61
62
63SBBreakpointLocation::~SBBreakpointLocation ()
64{
65}
66
67bool
68SBBreakpointLocation::IsValid() const
69{
70    return m_opaque_sp.get() != NULL;
71}
72
73SBAddress
74SBBreakpointLocation::GetAddress ()
75{
76    if (m_opaque_sp)
77        return SBAddress(&m_opaque_sp->GetAddress());
78    else
79        return SBAddress();
80}
81
82addr_t
83SBBreakpointLocation::GetLoadAddress ()
84{
85    addr_t ret_addr = LLDB_INVALID_ADDRESS;
86
87    if (m_opaque_sp)
88    {
89        Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
90        ret_addr = m_opaque_sp->GetLoadAddress();
91    }
92
93    return ret_addr;
94}
95
96void
97SBBreakpointLocation::SetEnabled (bool enabled)
98{
99    if (m_opaque_sp)
100    {
101        Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
102        m_opaque_sp->SetEnabled (enabled);
103    }
104}
105
106bool
107SBBreakpointLocation::IsEnabled ()
108{
109    if (m_opaque_sp)
110    {
111        Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
112        return m_opaque_sp->IsEnabled();
113    }
114    else
115        return false;
116}
117
118uint32_t
119SBBreakpointLocation::GetIgnoreCount ()
120{
121    if (m_opaque_sp)
122    {
123        Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
124        return m_opaque_sp->GetIgnoreCount();
125    }
126    else
127        return 0;
128}
129
130void
131SBBreakpointLocation::SetIgnoreCount (uint32_t n)
132{
133    if (m_opaque_sp)
134    {
135        Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
136        m_opaque_sp->SetIgnoreCount (n);
137    }
138}
139
140void
141SBBreakpointLocation::SetCondition (const char *condition)
142{
143    if (m_opaque_sp)
144    {
145        Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
146        m_opaque_sp->SetCondition (condition);
147    }
148}
149
150const char *
151SBBreakpointLocation::GetCondition ()
152{
153    if (m_opaque_sp)
154    {
155        Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
156        return m_opaque_sp->GetConditionText ();
157    }
158    return NULL;
159}
160
161void
162SBBreakpointLocation::SetThreadID (tid_t thread_id)
163{
164    if (m_opaque_sp)
165    {
166        Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
167        m_opaque_sp->SetThreadID (thread_id);
168    }
169}
170
171tid_t
172SBBreakpointLocation::GetThreadID ()
173{
174    tid_t tid = LLDB_INVALID_THREAD_ID;
175    if (m_opaque_sp)
176    {
177        Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
178        const ThreadSpec *thread_spec = m_opaque_sp->GetLocationOptions()->GetThreadSpecNoCreate();
179        if (thread_spec)
180            tid = thread_spec->GetTID();
181    }
182    return tid;
183}
184
185void
186SBBreakpointLocation::SetThreadIndex (uint32_t index)
187{
188    if (m_opaque_sp)
189    {
190        Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
191        m_opaque_sp->GetLocationOptions()->GetThreadSpec()->SetIndex (index);
192    }
193}
194
195uint32_t
196SBBreakpointLocation::GetThreadIndex() const
197{
198    uint32_t thread_idx = UINT32_MAX;
199    if (m_opaque_sp)
200    {
201        Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
202        const ThreadSpec *thread_spec = m_opaque_sp->GetOptionsNoCreate()->GetThreadSpecNoCreate();
203        if (thread_spec)
204            thread_idx = thread_spec->GetIndex();
205    }
206    return thread_idx;
207}
208
209
210void
211SBBreakpointLocation::SetThreadName (const char *thread_name)
212{
213    if (m_opaque_sp)
214    {
215        Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
216        m_opaque_sp->GetLocationOptions()->GetThreadSpec()->SetName (thread_name);
217    }
218}
219
220const char *
221SBBreakpointLocation::GetThreadName () const
222{
223    if (m_opaque_sp)
224    {
225        Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
226        const ThreadSpec *thread_spec = m_opaque_sp->GetOptionsNoCreate()->GetThreadSpecNoCreate();
227        if (thread_spec)
228            return thread_spec->GetName();
229    }
230    return NULL;
231}
232
233void
234SBBreakpointLocation::SetQueueName (const char *queue_name)
235{
236    if (m_opaque_sp)
237    {
238        Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
239        m_opaque_sp->GetLocationOptions()->GetThreadSpec()->SetQueueName (queue_name);
240    }
241}
242
243const char *
244SBBreakpointLocation::GetQueueName () const
245{
246    if (m_opaque_sp)
247    {
248        Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
249        const ThreadSpec *thread_spec = m_opaque_sp->GetOptionsNoCreate()->GetThreadSpecNoCreate();
250        if (thread_spec)
251            return thread_spec->GetQueueName();
252    }
253    return NULL;
254}
255
256bool
257SBBreakpointLocation::IsResolved ()
258{
259    if (m_opaque_sp)
260    {
261        Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
262        return m_opaque_sp->IsResolved();
263    }
264    return false;
265}
266
267void
268SBBreakpointLocation::SetLocation (const lldb::BreakpointLocationSP &break_loc_sp)
269{
270    // Uninstall the callbacks?
271    m_opaque_sp = break_loc_sp;
272}
273
274bool
275SBBreakpointLocation::GetDescription (SBStream &description, DescriptionLevel level)
276{
277    if (m_opaque_sp)
278    {
279        Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
280        description.ref();
281        m_opaque_sp->GetDescription (description.get(), level);
282        description.get()->EOL();
283    }
284    else
285        description.Printf ("No value");
286
287    return true;
288}
289
290SBBreakpoint
291SBBreakpointLocation::GetBreakpoint ()
292{
293    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
294
295    //if (log)
296    //    log->Printf ("SBBreakpointLocation::GetBreakpoint ()");
297
298    SBBreakpoint sb_bp;
299    if (m_opaque_sp)
300    {
301        Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
302        *sb_bp = m_opaque_sp->GetBreakpoint ().GetSP();
303    }
304
305    if (log)
306    {
307        SBStream sstr;
308        sb_bp.GetDescription (sstr);
309        log->Printf ("SBBreakpointLocation(%p)::GetBreakpoint () => SBBreakpoint(%p) %s",
310                     m_opaque_sp.get(), sb_bp.get(), sstr.GetData());
311    }
312    return sb_bp;
313}
314
315