blob: 6fdf59f38b4aa3bd76695b9b040775cb97c6d734 [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"
Greg Clayton980c7502011-09-24 01:37:21 +000012#include "lldb/API/SBAddress.h"
Chris Lattner24943d22010-06-08 16:52:24 +000013#include "lldb/API/SBDebugger.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000014#include "lldb/API/SBStream.h"
Chris Lattner24943d22010-06-08 16:52:24 +000015
16#include "lldb/lldb-types.h"
17#include "lldb/lldb-defines.h"
Greg Clayton640dc6b2010-11-18 18:52:36 +000018#include "lldb/Breakpoint/Breakpoint.h"
Chris Lattner24943d22010-06-08 16:52:24 +000019#include "lldb/Breakpoint/BreakpointLocation.h"
Jim Ingham3c7b5b92010-06-16 02:00:15 +000020#include "lldb/Target/ThreadSpec.h"
Caroline Tice7826c882010-10-26 03:11:13 +000021#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022#include "lldb/Core/Stream.h"
23#include "lldb/Core/StreamFile.h"
Greg Claytonbdcda462010-12-20 20:49:23 +000024#include "lldb/Target/Target.h"
Jim Ingham8e5e38f2010-06-18 01:47:08 +000025#include "lldb/Target/ThreadSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000026
27using namespace lldb;
28using namespace lldb_private;
29
30
Greg Clayton538eb822010-11-05 23:17:00 +000031SBBreakpointLocation::SBBreakpointLocation () :
32 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000033{
34}
35
36SBBreakpointLocation::SBBreakpointLocation (const lldb::BreakpointLocationSP &break_loc_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000037 m_opaque_sp (break_loc_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000038{
Greg Clayton952e9dc2013-03-27 23:08:40 +000039 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000040
41 if (log)
42 {
43 SBStream sstr;
Johnny Chenbdc36bd2011-04-25 20:23:05 +000044 GetDescription (sstr, lldb::eDescriptionLevelBrief);
Caroline Tice61ba7ec2010-10-26 23:49:36 +000045 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());
Caroline Tice7826c882010-10-26 03:11:13 +000047 }
Chris Lattner24943d22010-06-08 16:52:24 +000048}
49
Greg Clayton538eb822010-11-05 23:17:00 +000050SBBreakpointLocation::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
Chris Lattner24943d22010-06-08 16:52:24 +000064SBBreakpointLocation::~SBBreakpointLocation ()
65{
66}
67
68bool
69SBBreakpointLocation::IsValid() const
70{
Greg Clayton63094e02010-06-23 01:19:29 +000071 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000072}
73
Jim Ingham9a29f002011-09-24 01:04:57 +000074SBAddress
75SBBreakpointLocation::GetAddress ()
76{
77 if (m_opaque_sp)
78 return SBAddress(&m_opaque_sp->GetAddress());
79 else
80 return SBAddress();
81}
82
Chris Lattner24943d22010-06-08 16:52:24 +000083addr_t
84SBBreakpointLocation::GetLoadAddress ()
85{
86 addr_t ret_addr = LLDB_INVALID_ADDRESS;
87
Greg Clayton63094e02010-06-23 01:19:29 +000088 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000089 {
Greg Claytonbdcda462010-12-20 20:49:23 +000090 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +000091 ret_addr = m_opaque_sp->GetLoadAddress();
Chris Lattner24943d22010-06-08 16:52:24 +000092 }
93
94 return ret_addr;
95}
96
97void
98SBBreakpointLocation::SetEnabled (bool enabled)
99{
Greg Clayton63094e02010-06-23 01:19:29 +0000100 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000101 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000102 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000103 m_opaque_sp->SetEnabled (enabled);
Chris Lattner24943d22010-06-08 16:52:24 +0000104 }
105}
106
107bool
108SBBreakpointLocation::IsEnabled ()
109{
Greg Clayton63094e02010-06-23 01:19:29 +0000110 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000111 {
112 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000113 return m_opaque_sp->IsEnabled();
Greg Claytonbdcda462010-12-20 20:49:23 +0000114 }
Chris Lattner24943d22010-06-08 16:52:24 +0000115 else
116 return false;
117}
118
Greg Clayton54e7afa2010-07-09 20:39:50 +0000119uint32_t
Chris Lattner24943d22010-06-08 16:52:24 +0000120SBBreakpointLocation::GetIgnoreCount ()
121{
Greg Clayton63094e02010-06-23 01:19:29 +0000122 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000123 {
124 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000125 return m_opaque_sp->GetIgnoreCount();
Greg Claytonbdcda462010-12-20 20:49:23 +0000126 }
Chris Lattner24943d22010-06-08 16:52:24 +0000127 else
128 return 0;
129}
130
131void
Greg Clayton54e7afa2010-07-09 20:39:50 +0000132SBBreakpointLocation::SetIgnoreCount (uint32_t n)
Chris Lattner24943d22010-06-08 16:52:24 +0000133{
Greg Clayton63094e02010-06-23 01:19:29 +0000134 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000135 {
136 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000137 m_opaque_sp->SetIgnoreCount (n);
Greg Claytonbdcda462010-12-20 20:49:23 +0000138 }
Chris Lattner24943d22010-06-08 16:52:24 +0000139}
140
141void
Jim Inghame3740832010-10-22 01:15:49 +0000142SBBreakpointLocation::SetCondition (const char *condition)
143{
Greg Claytonbdcda462010-12-20 20:49:23 +0000144 if (m_opaque_sp)
145 {
146 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
147 m_opaque_sp->SetCondition (condition);
148 }
Jim Inghame3740832010-10-22 01:15:49 +0000149}
150
151const char *
152SBBreakpointLocation::GetCondition ()
153{
Greg Claytonbdcda462010-12-20 20:49:23 +0000154 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;
Jim Inghame3740832010-10-22 01:15:49 +0000160}
161
162void
Chris Lattner24943d22010-06-08 16:52:24 +0000163SBBreakpointLocation::SetThreadID (tid_t thread_id)
164{
Greg Clayton63094e02010-06-23 01:19:29 +0000165 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000166 {
167 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000168 m_opaque_sp->SetThreadID (thread_id);
Greg Claytonbdcda462010-12-20 20:49:23 +0000169 }
Chris Lattner24943d22010-06-08 16:52:24 +0000170}
171
172tid_t
173SBBreakpointLocation::GetThreadID ()
174{
Greg Claytonbdcda462010-12-20 20:49:23 +0000175 tid_t tid = LLDB_INVALID_THREAD_ID;
Greg Clayton63094e02010-06-23 01:19:29 +0000176 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000177 {
178 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Jim Ingham28e23862012-02-08 05:23:15 +0000179 return m_opaque_sp->GetThreadID();
Greg Claytonbdcda462010-12-20 20:49:23 +0000180 }
181 return tid;
Chris Lattner24943d22010-06-08 16:52:24 +0000182}
183
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000184void
185SBBreakpointLocation::SetThreadIndex (uint32_t index)
186{
Greg Clayton63094e02010-06-23 01:19:29 +0000187 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000188 {
189 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Jim Ingham28e23862012-02-08 05:23:15 +0000190 m_opaque_sp->SetThreadIndex (index);
Greg Claytonbdcda462010-12-20 20:49:23 +0000191 }
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000192}
193
194uint32_t
195SBBreakpointLocation::GetThreadIndex() const
196{
Greg Claytonbdcda462010-12-20 20:49:23 +0000197 uint32_t thread_idx = UINT32_MAX;
Greg Clayton63094e02010-06-23 01:19:29 +0000198 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000199 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000200 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Jim Ingham28e23862012-02-08 05:23:15 +0000201 return m_opaque_sp->GetThreadIndex();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000202 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000203 return thread_idx;
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000204}
205
206
207void
208SBBreakpointLocation::SetThreadName (const char *thread_name)
209{
Greg Clayton63094e02010-06-23 01:19:29 +0000210 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000211 {
212 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Jim Ingham28e23862012-02-08 05:23:15 +0000213 m_opaque_sp->SetThreadName (thread_name);
Greg Claytonbdcda462010-12-20 20:49:23 +0000214 }
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000215}
216
217const char *
218SBBreakpointLocation::GetThreadName () const
219{
Greg Clayton63094e02010-06-23 01:19:29 +0000220 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000221 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000222 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Jim Ingham28e23862012-02-08 05:23:15 +0000223 return m_opaque_sp->GetThreadName();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000224 }
225 return NULL;
226}
227
228void
229SBBreakpointLocation::SetQueueName (const char *queue_name)
230{
Greg Clayton63094e02010-06-23 01:19:29 +0000231 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000232 {
233 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Jim Ingham28e23862012-02-08 05:23:15 +0000234 m_opaque_sp->SetQueueName (queue_name);
Greg Claytonbdcda462010-12-20 20:49:23 +0000235 }
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000236}
237
238const char *
239SBBreakpointLocation::GetQueueName () const
240{
Greg Clayton63094e02010-06-23 01:19:29 +0000241 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000242 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000243 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Jim Ingham28e23862012-02-08 05:23:15 +0000244 m_opaque_sp->GetQueueName ();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000245 }
246 return NULL;
247}
248
Chris Lattner24943d22010-06-08 16:52:24 +0000249bool
250SBBreakpointLocation::IsResolved ()
251{
Greg Clayton63094e02010-06-23 01:19:29 +0000252 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000253 {
254 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000255 return m_opaque_sp->IsResolved();
Greg Claytonbdcda462010-12-20 20:49:23 +0000256 }
257 return false;
Chris Lattner24943d22010-06-08 16:52:24 +0000258}
259
260void
261SBBreakpointLocation::SetLocation (const lldb::BreakpointLocationSP &break_loc_sp)
262{
Greg Claytonbdcda462010-12-20 20:49:23 +0000263 // Uninstall the callbacks?
Greg Clayton63094e02010-06-23 01:19:29 +0000264 m_opaque_sp = break_loc_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000265}
266
Caroline Tice98f930f2010-09-20 05:20:02 +0000267bool
Johnny Chenbdc36bd2011-04-25 20:23:05 +0000268SBBreakpointLocation::GetDescription (SBStream &description, DescriptionLevel level)
Chris Lattner24943d22010-06-08 16:52:24 +0000269{
Greg Clayton96154be2011-11-13 06:57:31 +0000270 Stream &strm = description.ref();
271
Greg Clayton63094e02010-06-23 01:19:29 +0000272 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000273 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000274 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton96154be2011-11-13 06:57:31 +0000275 m_opaque_sp->GetDescription (&strm, level);
276 strm.EOL();
Chris Lattner24943d22010-06-08 16:52:24 +0000277 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000278 else
Greg Clayton96154be2011-11-13 06:57:31 +0000279 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +0000280
281 return true;
282}
283
Jim Ingham1c4ae3e2012-05-16 00:51:15 +0000284break_id_t
285SBBreakpointLocation::GetID ()
286{
287 if (m_opaque_sp)
288 {
289 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
290 return m_opaque_sp->GetID ();
291 }
292 else
293 return LLDB_INVALID_BREAK_ID;
294}
295
Chris Lattner24943d22010-06-08 16:52:24 +0000296SBBreakpoint
297SBBreakpointLocation::GetBreakpoint ()
298{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000299 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000300
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000301 //if (log)
302 // log->Printf ("SBBreakpointLocation::GetBreakpoint ()");
Caroline Tice7826c882010-10-26 03:11:13 +0000303
Chris Lattner24943d22010-06-08 16:52:24 +0000304 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000305 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000306 {
307 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton13d24fb2012-01-29 20:56:30 +0000308 *sb_bp = m_opaque_sp->GetBreakpoint ().shared_from_this();
Greg Claytonbdcda462010-12-20 20:49:23 +0000309 }
Caroline Tice7826c882010-10-26 03:11:13 +0000310
311 if (log)
312 {
313 SBStream sstr;
314 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000315 log->Printf ("SBBreakpointLocation(%p)::GetBreakpoint () => SBBreakpoint(%p) %s",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000316 m_opaque_sp.get(), sb_bp.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000317 }
Chris Lattner24943d22010-06-08 16:52:24 +0000318 return sb_bp;
319}
320