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