blob: d8779ffe2ba8a7b9876b9d2502774eca9868e896 [file] [log] [blame]
Chris Lattner30fdc8d2010-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"
Greg Claytonf644ddf2011-09-24 01:37:21 +000011#include "lldb/API/SBAddress.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/API/SBDebugger.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000013#include "lldb/API/SBDefines.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000014#include "lldb/API/SBStream.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015
Greg Clayton4e78f602010-11-18 18:52:36 +000016#include "lldb/Breakpoint/Breakpoint.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "lldb/Breakpoint/BreakpointLocation.h"
Jim Inghamd80102e2014-04-02 01:04:55 +000018#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Core/StreamFile.h"
Jim Inghamd80102e2014-04-02 01:04:55 +000020#include "lldb/Interpreter/CommandInterpreter.h"
21#include "lldb/Interpreter/ScriptInterpreter.h"
Greg Claytonaf67cec2010-12-20 20:49:23 +000022#include "lldb/Target/Target.h"
Jim Ingham62b02c62010-06-18 01:47:08 +000023#include "lldb/Target/ThreadSpec.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000024#include "lldb/Utility/Log.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000025#include "lldb/Utility/Stream.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000026#include "lldb/lldb-defines.h"
27#include "lldb/lldb-types.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028
29using namespace lldb;
30using namespace lldb_private;
31
Pavel Labathc5789432017-03-01 10:08:48 +000032SBBreakpointLocation::SBBreakpointLocation() {}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033
Kate Stoneb9c1b512016-09-06 20:57:50 +000034SBBreakpointLocation::SBBreakpointLocation(
35 const lldb::BreakpointLocationSP &break_loc_sp)
Pavel Labathc5789432017-03-01 10:08:48 +000036 : m_opaque_wp(break_loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +000037 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
38
39 if (log) {
40 SBStream sstr;
41 GetDescription(sstr, lldb::eDescriptionLevelBrief);
Pavel Labathc5789432017-03-01 10:08:48 +000042 LLDB_LOG(log, "location = {0} ({1})", break_loc_sp.get(), sstr.GetData());
Kate Stoneb9c1b512016-09-06 20:57:50 +000043 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000044}
45
Kate Stoneb9c1b512016-09-06 20:57:50 +000046SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs)
Pavel Labathc5789432017-03-01 10:08:48 +000047 : m_opaque_wp(rhs.m_opaque_wp) {}
Caroline Ticeceb6b132010-10-26 03:11:13 +000048
Kate Stoneb9c1b512016-09-06 20:57:50 +000049const SBBreakpointLocation &SBBreakpointLocation::
50operator=(const SBBreakpointLocation &rhs) {
Pavel Labathc5789432017-03-01 10:08:48 +000051 m_opaque_wp = rhs.m_opaque_wp;
Kate Stoneb9c1b512016-09-06 20:57:50 +000052 return *this;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053}
54
Kate Stoneb9c1b512016-09-06 20:57:50 +000055SBBreakpointLocation::~SBBreakpointLocation() {}
56
Pavel Labathc5789432017-03-01 10:08:48 +000057BreakpointLocationSP SBBreakpointLocation::GetSP() const {
58 return m_opaque_wp.lock();
59}
60
61bool SBBreakpointLocation::IsValid() const { return bool(GetSP()); }
Kate Stoneb9c1b512016-09-06 20:57:50 +000062
63SBAddress SBBreakpointLocation::GetAddress() {
Pavel Labathc5789432017-03-01 10:08:48 +000064 BreakpointLocationSP loc_sp = GetSP();
65 if (loc_sp)
66 return SBAddress(&loc_sp->GetAddress());
Kate Stoneb9c1b512016-09-06 20:57:50 +000067 else
68 return SBAddress();
Greg Claytonefabb122010-11-05 23:17:00 +000069}
70
Kate Stoneb9c1b512016-09-06 20:57:50 +000071addr_t SBBreakpointLocation::GetLoadAddress() {
72 addr_t ret_addr = LLDB_INVALID_ADDRESS;
Pavel Labathc5789432017-03-01 10:08:48 +000073 BreakpointLocationSP loc_sp = GetSP();
Kate Stoneb9c1b512016-09-06 20:57:50 +000074
Pavel Labathc5789432017-03-01 10:08:48 +000075 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +000076 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +000077 loc_sp->GetTarget().GetAPIMutex());
78 ret_addr = loc_sp->GetLoadAddress();
Kate Stoneb9c1b512016-09-06 20:57:50 +000079 }
80
81 return ret_addr;
Greg Claytonefabb122010-11-05 23:17:00 +000082}
83
Kate Stoneb9c1b512016-09-06 20:57:50 +000084void SBBreakpointLocation::SetEnabled(bool enabled) {
Pavel Labathc5789432017-03-01 10:08:48 +000085 BreakpointLocationSP loc_sp = GetSP();
86 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +000087 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +000088 loc_sp->GetTarget().GetAPIMutex());
89 loc_sp->SetEnabled(enabled);
Kate Stoneb9c1b512016-09-06 20:57:50 +000090 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000091}
92
Kate Stoneb9c1b512016-09-06 20:57:50 +000093bool SBBreakpointLocation::IsEnabled() {
Pavel Labathc5789432017-03-01 10:08:48 +000094 BreakpointLocationSP loc_sp = GetSP();
95 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +000096 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +000097 loc_sp->GetTarget().GetAPIMutex());
98 return loc_sp->IsEnabled();
Kate Stoneb9c1b512016-09-06 20:57:50 +000099 } else
Greg Claytonaf67cec2010-12-20 20:49:23 +0000100 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000101}
102
Kate Stoneb9c1b512016-09-06 20:57:50 +0000103uint32_t SBBreakpointLocation::GetIgnoreCount() {
Pavel Labathc5789432017-03-01 10:08:48 +0000104 BreakpointLocationSP loc_sp = GetSP();
105 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000106 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000107 loc_sp->GetTarget().GetAPIMutex());
108 return loc_sp->GetIgnoreCount();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000109 } else
110 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111}
112
Kate Stoneb9c1b512016-09-06 20:57:50 +0000113void SBBreakpointLocation::SetIgnoreCount(uint32_t n) {
Pavel Labathc5789432017-03-01 10:08:48 +0000114 BreakpointLocationSP loc_sp = GetSP();
115 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000116 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000117 loc_sp->GetTarget().GetAPIMutex());
118 loc_sp->SetIgnoreCount(n);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000119 }
Caroline Ticedde9cff2010-09-20 05:20:02 +0000120}
121
Kate Stoneb9c1b512016-09-06 20:57:50 +0000122void SBBreakpointLocation::SetCondition(const char *condition) {
Pavel Labathc5789432017-03-01 10:08:48 +0000123 BreakpointLocationSP loc_sp = GetSP();
124 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000125 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000126 loc_sp->GetTarget().GetAPIMutex());
127 loc_sp->SetCondition(condition);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000128 }
Jim Inghamb08a9442012-05-16 00:51:15 +0000129}
130
Kate Stoneb9c1b512016-09-06 20:57:50 +0000131const char *SBBreakpointLocation::GetCondition() {
Pavel Labathc5789432017-03-01 10:08:48 +0000132 BreakpointLocationSP loc_sp = GetSP();
133 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000134 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000135 loc_sp->GetTarget().GetAPIMutex());
136 return loc_sp->GetConditionText();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000137 }
138 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000139}
140
Kate Stoneb9c1b512016-09-06 20:57:50 +0000141void SBBreakpointLocation::SetScriptCallbackFunction(
142 const char *callback_function_name) {
143 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
Pavel Labathc5789432017-03-01 10:08:48 +0000144 BreakpointLocationSP loc_sp = GetSP();
145 LLDB_LOG(log, "location = {0}, callback = {1}", loc_sp.get(),
146 callback_function_name);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000147
Pavel Labathc5789432017-03-01 10:08:48 +0000148 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000149 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000150 loc_sp->GetTarget().GetAPIMutex());
151 BreakpointOptions *bp_options = loc_sp->GetLocationOptions();
152 loc_sp->GetBreakpoint()
Kate Stoneb9c1b512016-09-06 20:57:50 +0000153 .GetTarget()
154 .GetDebugger()
155 .GetCommandInterpreter()
156 .GetScriptInterpreter()
157 ->SetBreakpointCommandCallbackFunction(bp_options,
158 callback_function_name);
159 }
160}
161
162SBError
163SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) {
164 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
Pavel Labathc5789432017-03-01 10:08:48 +0000165 BreakpointLocationSP loc_sp = GetSP();
166 LLDB_LOG(log, "location = {0}: callback body:\n{1}", loc_sp.get(),
167 callback_body_text);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000168
169 SBError sb_error;
Pavel Labathc5789432017-03-01 10:08:48 +0000170 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000171 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000172 loc_sp->GetTarget().GetAPIMutex());
173 BreakpointOptions *bp_options = loc_sp->GetLocationOptions();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000174 Error error =
Pavel Labathc5789432017-03-01 10:08:48 +0000175 loc_sp->GetBreakpoint()
Kate Stoneb9c1b512016-09-06 20:57:50 +0000176 .GetTarget()
177 .GetDebugger()
178 .GetCommandInterpreter()
179 .GetScriptInterpreter()
180 ->SetBreakpointCommandCallback(bp_options, callback_body_text);
181 sb_error.SetError(error);
182 } else
183 sb_error.SetErrorString("invalid breakpoint");
184
185 return sb_error;
186}
187
188void SBBreakpointLocation::SetThreadID(tid_t thread_id) {
Pavel Labathc5789432017-03-01 10:08:48 +0000189 BreakpointLocationSP loc_sp = GetSP();
190 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000191 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000192 loc_sp->GetTarget().GetAPIMutex());
193 loc_sp->SetThreadID(thread_id);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000194 }
195}
196
197tid_t SBBreakpointLocation::GetThreadID() {
198 tid_t tid = LLDB_INVALID_THREAD_ID;
Pavel Labathc5789432017-03-01 10:08:48 +0000199 BreakpointLocationSP loc_sp = GetSP();
200 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000201 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000202 loc_sp->GetTarget().GetAPIMutex());
203 return loc_sp->GetThreadID();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000204 }
205 return tid;
206}
207
208void SBBreakpointLocation::SetThreadIndex(uint32_t index) {
Pavel Labathc5789432017-03-01 10:08:48 +0000209 BreakpointLocationSP loc_sp = GetSP();
210 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000211 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000212 loc_sp->GetTarget().GetAPIMutex());
213 loc_sp->SetThreadIndex(index);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000214 }
215}
216
217uint32_t SBBreakpointLocation::GetThreadIndex() const {
218 uint32_t thread_idx = UINT32_MAX;
Pavel Labathc5789432017-03-01 10:08:48 +0000219 BreakpointLocationSP loc_sp = GetSP();
220 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000221 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000222 loc_sp->GetTarget().GetAPIMutex());
223 return loc_sp->GetThreadIndex();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000224 }
225 return thread_idx;
226}
227
228void SBBreakpointLocation::SetThreadName(const char *thread_name) {
Pavel Labathc5789432017-03-01 10:08:48 +0000229 BreakpointLocationSP loc_sp = GetSP();
230 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000231 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000232 loc_sp->GetTarget().GetAPIMutex());
233 loc_sp->SetThreadName(thread_name);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000234 }
235}
236
237const char *SBBreakpointLocation::GetThreadName() const {
Pavel Labathc5789432017-03-01 10:08:48 +0000238 BreakpointLocationSP loc_sp = GetSP();
239 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000240 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000241 loc_sp->GetTarget().GetAPIMutex());
242 return loc_sp->GetThreadName();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000243 }
244 return NULL;
245}
246
247void SBBreakpointLocation::SetQueueName(const char *queue_name) {
Pavel Labathc5789432017-03-01 10:08:48 +0000248 BreakpointLocationSP loc_sp = GetSP();
249 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000250 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000251 loc_sp->GetTarget().GetAPIMutex());
252 loc_sp->SetQueueName(queue_name);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000253 }
254}
255
256const char *SBBreakpointLocation::GetQueueName() const {
Pavel Labathc5789432017-03-01 10:08:48 +0000257 BreakpointLocationSP loc_sp = GetSP();
258 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000259 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000260 loc_sp->GetTarget().GetAPIMutex());
261 loc_sp->GetQueueName();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000262 }
263 return NULL;
264}
265
266bool SBBreakpointLocation::IsResolved() {
Pavel Labathc5789432017-03-01 10:08:48 +0000267 BreakpointLocationSP loc_sp = GetSP();
268 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000269 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000270 loc_sp->GetTarget().GetAPIMutex());
271 return loc_sp->IsResolved();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000272 }
273 return false;
274}
275
276void SBBreakpointLocation::SetLocation(
277 const lldb::BreakpointLocationSP &break_loc_sp) {
278 // Uninstall the callbacks?
Pavel Labathc5789432017-03-01 10:08:48 +0000279 m_opaque_wp = break_loc_sp;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000280}
281
282bool SBBreakpointLocation::GetDescription(SBStream &description,
283 DescriptionLevel level) {
284 Stream &strm = description.ref();
Pavel Labathc5789432017-03-01 10:08:48 +0000285 BreakpointLocationSP loc_sp = GetSP();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000286
Pavel Labathc5789432017-03-01 10:08:48 +0000287 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000288 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000289 loc_sp->GetTarget().GetAPIMutex());
290 loc_sp->GetDescription(&strm, level);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000291 strm.EOL();
292 } else
293 strm.PutCString("No value");
294
295 return true;
296}
297
298break_id_t SBBreakpointLocation::GetID() {
Pavel Labathc5789432017-03-01 10:08:48 +0000299 BreakpointLocationSP loc_sp = GetSP();
300 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000301 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000302 loc_sp->GetTarget().GetAPIMutex());
303 return loc_sp->GetID();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000304 } else
305 return LLDB_INVALID_BREAK_ID;
306}
307
308SBBreakpoint SBBreakpointLocation::GetBreakpoint() {
309 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
Pavel Labathc5789432017-03-01 10:08:48 +0000310 BreakpointLocationSP loc_sp = GetSP();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000311
312 SBBreakpoint sb_bp;
Pavel Labathc5789432017-03-01 10:08:48 +0000313 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000314 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000315 loc_sp->GetTarget().GetAPIMutex());
316 sb_bp = loc_sp->GetBreakpoint().shared_from_this();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000317 }
318
319 if (log) {
320 SBStream sstr;
321 sb_bp.GetDescription(sstr);
Pavel Labathc5789432017-03-01 10:08:48 +0000322 LLDB_LOG(log, "location = {0}, breakpoint = {1} ({2})", loc_sp.get(),
323 sb_bp.GetSP().get(), sstr.GetData());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000324 }
325 return sb_bp;
326}