blob: af6894266cdbfbe87249397152681627fb25a456 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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"
Caroline Tice98f930f2010-09-20 05:20:02 +000013#include "lldb/API/SBStream.h"
Chris Lattner24943d22010-06-08 16:52:24 +000014
15#include "lldb/lldb-types.h"
16#include "lldb/lldb-defines.h"
Greg Clayton640dc6b2010-11-18 18:52:36 +000017#include "lldb/Breakpoint/Breakpoint.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018#include "lldb/Breakpoint/BreakpointLocation.h"
Jim Ingham3c7b5b92010-06-16 02:00:15 +000019#include "lldb/Target/ThreadSpec.h"
Caroline Tice7826c882010-10-26 03:11:13 +000020#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000021#include "lldb/Core/Stream.h"
22#include "lldb/Core/StreamFile.h"
Jim Ingham8e5e38f2010-06-18 01:47:08 +000023#include "lldb/Target/ThreadSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000024
25using namespace lldb;
26using namespace lldb_private;
27
28
Greg Clayton538eb822010-11-05 23:17:00 +000029SBBreakpointLocation::SBBreakpointLocation () :
30 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000031{
32}
33
34SBBreakpointLocation::SBBreakpointLocation (const lldb::BreakpointLocationSP &break_loc_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000035 m_opaque_sp (break_loc_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000036{
Greg Claytone005f2c2010-11-06 01:53:30 +000037 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000038
39 if (log)
40 {
41 SBStream sstr;
42 GetDescription (lldb::eDescriptionLevelBrief, sstr);
Caroline Tice61ba7ec2010-10-26 23:49:36 +000043 log->Printf ("SBBreakpointLocation::SBBreakpointLocaiton (const lldb::BreakpointLocationsSP &break_loc_sp"
44 "=%p) => this.sp = %p (%s)", break_loc_sp.get(), m_opaque_sp.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +000045 }
Chris Lattner24943d22010-06-08 16:52:24 +000046}
47
Greg Clayton538eb822010-11-05 23:17:00 +000048SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs) :
49 m_opaque_sp (rhs.m_opaque_sp)
50{
51}
52
53const SBBreakpointLocation &
54SBBreakpointLocation::operator = (const SBBreakpointLocation &rhs)
55{
56 if (this != &rhs)
57 m_opaque_sp = rhs.m_opaque_sp;
58 return *this;
59}
60
61
Chris Lattner24943d22010-06-08 16:52:24 +000062SBBreakpointLocation::~SBBreakpointLocation ()
63{
64}
65
66bool
67SBBreakpointLocation::IsValid() const
68{
Greg Clayton63094e02010-06-23 01:19:29 +000069 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000070}
71
72addr_t
73SBBreakpointLocation::GetLoadAddress ()
74{
75 addr_t ret_addr = LLDB_INVALID_ADDRESS;
76
Greg Clayton63094e02010-06-23 01:19:29 +000077 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000078 {
Greg Clayton63094e02010-06-23 01:19:29 +000079 ret_addr = m_opaque_sp->GetLoadAddress();
Chris Lattner24943d22010-06-08 16:52:24 +000080 }
81
82 return ret_addr;
83}
84
85void
86SBBreakpointLocation::SetEnabled (bool enabled)
87{
Greg Clayton63094e02010-06-23 01:19:29 +000088 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000089 {
Greg Clayton63094e02010-06-23 01:19:29 +000090 m_opaque_sp->SetEnabled (enabled);
Chris Lattner24943d22010-06-08 16:52:24 +000091 }
92}
93
94bool
95SBBreakpointLocation::IsEnabled ()
96{
Greg Clayton63094e02010-06-23 01:19:29 +000097 if (m_opaque_sp)
98 return m_opaque_sp->IsEnabled();
Chris Lattner24943d22010-06-08 16:52:24 +000099 else
100 return false;
101}
102
Greg Clayton54e7afa2010-07-09 20:39:50 +0000103uint32_t
Chris Lattner24943d22010-06-08 16:52:24 +0000104SBBreakpointLocation::GetIgnoreCount ()
105{
Greg Clayton63094e02010-06-23 01:19:29 +0000106 if (m_opaque_sp)
107 return m_opaque_sp->GetIgnoreCount();
Chris Lattner24943d22010-06-08 16:52:24 +0000108 else
109 return 0;
110}
111
112void
Greg Clayton54e7afa2010-07-09 20:39:50 +0000113SBBreakpointLocation::SetIgnoreCount (uint32_t n)
Chris Lattner24943d22010-06-08 16:52:24 +0000114{
Greg Clayton63094e02010-06-23 01:19:29 +0000115 if (m_opaque_sp)
116 m_opaque_sp->SetIgnoreCount (n);
Chris Lattner24943d22010-06-08 16:52:24 +0000117}
118
119void
Jim Inghame3740832010-10-22 01:15:49 +0000120SBBreakpointLocation::SetCondition (const char *condition)
121{
122 m_opaque_sp->SetCondition (condition);
123}
124
125const char *
126SBBreakpointLocation::GetCondition ()
127{
128 return m_opaque_sp->GetConditionText ();
129}
130
131void
Chris Lattner24943d22010-06-08 16:52:24 +0000132SBBreakpointLocation::SetThreadID (tid_t thread_id)
133{
Greg Clayton63094e02010-06-23 01:19:29 +0000134 if (m_opaque_sp)
135 m_opaque_sp->SetThreadID (thread_id);
Chris Lattner24943d22010-06-08 16:52:24 +0000136}
137
138tid_t
139SBBreakpointLocation::GetThreadID ()
140{
141 tid_t sb_thread_id = (lldb::tid_t) LLDB_INVALID_THREAD_ID;
Greg Clayton63094e02010-06-23 01:19:29 +0000142 if (m_opaque_sp)
143 sb_thread_id = m_opaque_sp->GetLocationOptions()->GetThreadSpecNoCreate()->GetTID();
Chris Lattner24943d22010-06-08 16:52:24 +0000144 return sb_thread_id;
145}
146
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000147void
148SBBreakpointLocation::SetThreadIndex (uint32_t index)
149{
Greg Clayton63094e02010-06-23 01:19:29 +0000150 if (m_opaque_sp)
151 m_opaque_sp->GetLocationOptions()->GetThreadSpec()->SetIndex (index);
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000152}
153
154uint32_t
155SBBreakpointLocation::GetThreadIndex() const
156{
Greg Clayton63094e02010-06-23 01:19:29 +0000157 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000158 {
Greg Clayton63094e02010-06-23 01:19:29 +0000159 const ThreadSpec *thread_spec = m_opaque_sp->GetOptionsNoCreate()->GetThreadSpecNoCreate();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000160 if (thread_spec == NULL)
161 return 0;
162 else
163 return thread_spec->GetIndex();
164 }
165 return 0;
166}
167
168
169void
170SBBreakpointLocation::SetThreadName (const char *thread_name)
171{
Greg Clayton63094e02010-06-23 01:19:29 +0000172 if (m_opaque_sp)
173 m_opaque_sp->GetLocationOptions()->GetThreadSpec()->SetName (thread_name);
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000174}
175
176const char *
177SBBreakpointLocation::GetThreadName () const
178{
Greg Clayton63094e02010-06-23 01:19:29 +0000179 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000180 {
Greg Clayton63094e02010-06-23 01:19:29 +0000181 const ThreadSpec *thread_spec = m_opaque_sp->GetOptionsNoCreate()->GetThreadSpecNoCreate();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000182 if (thread_spec == NULL)
183 return NULL;
184 else
185 return thread_spec->GetName();
186 }
187 return NULL;
188}
189
190void
191SBBreakpointLocation::SetQueueName (const char *queue_name)
192{
Greg Clayton63094e02010-06-23 01:19:29 +0000193 if (m_opaque_sp)
194 m_opaque_sp->GetLocationOptions()->GetThreadSpec()->SetQueueName (queue_name);
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000195}
196
197const char *
198SBBreakpointLocation::GetQueueName () const
199{
Greg Clayton63094e02010-06-23 01:19:29 +0000200 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000201 {
Greg Clayton63094e02010-06-23 01:19:29 +0000202 const ThreadSpec *thread_spec = m_opaque_sp->GetOptionsNoCreate()->GetThreadSpecNoCreate();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000203 if (thread_spec == NULL)
204 return NULL;
205 else
206 return thread_spec->GetQueueName();
207 }
208 return NULL;
209}
210
Chris Lattner24943d22010-06-08 16:52:24 +0000211bool
212SBBreakpointLocation::IsResolved ()
213{
Greg Clayton63094e02010-06-23 01:19:29 +0000214 if (m_opaque_sp)
215 return m_opaque_sp->IsResolved();
Chris Lattner24943d22010-06-08 16:52:24 +0000216 else
217 return false;
218}
219
220void
221SBBreakpointLocation::SetLocation (const lldb::BreakpointLocationSP &break_loc_sp)
222{
Greg Clayton63094e02010-06-23 01:19:29 +0000223 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000224 {
225 // Uninstall the callbacks?
226 }
Greg Clayton63094e02010-06-23 01:19:29 +0000227 m_opaque_sp = break_loc_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000228}
229
Caroline Tice98f930f2010-09-20 05:20:02 +0000230bool
Caroline Tice7826c882010-10-26 03:11:13 +0000231SBBreakpointLocation::GetDescription (DescriptionLevel level, SBStream &description)
Chris Lattner24943d22010-06-08 16:52:24 +0000232{
Greg Clayton63094e02010-06-23 01:19:29 +0000233 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000234 {
Caroline Ticee49ec182010-09-22 23:01:29 +0000235 description.ref();
Caroline Tice98f930f2010-09-20 05:20:02 +0000236 m_opaque_sp->GetDescription (description.get(), level);
237 description.get()->EOL();
Chris Lattner24943d22010-06-08 16:52:24 +0000238 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000239 else
240 description.Printf ("No value");
241
242 return true;
243}
244
Chris Lattner24943d22010-06-08 16:52:24 +0000245SBBreakpoint
246SBBreakpointLocation::GetBreakpoint ()
247{
Greg Claytone005f2c2010-11-06 01:53:30 +0000248 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000249
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000250 //if (log)
251 // log->Printf ("SBBreakpointLocation::GetBreakpoint ()");
Caroline Tice7826c882010-10-26 03:11:13 +0000252
Chris Lattner24943d22010-06-08 16:52:24 +0000253 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000254 if (m_opaque_sp)
255 *sb_bp = m_opaque_sp->GetBreakpoint ().GetSP();
Caroline Tice7826c882010-10-26 03:11:13 +0000256
257 if (log)
258 {
259 SBStream sstr;
260 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000261 log->Printf ("SBBreakpointLocation(%p)::GetBreakpoint () => SBBreakpoint(%p) %s",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000262 m_opaque_sp.get(), sb_bp.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000263 }
Chris Lattner24943d22010-06-08 16:52:24 +0000264 return sb_bp;
265}
266