blob: 640545f55ef974a8d4134f7b57bd7bd70face250 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SBBreakpointLocation.cpp --------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "lldb/API/SBBreakpointLocation.h"
Jonas Devliegherebaf56642019-03-06 00:06:00 +000010#include "SBReproducerPrivate.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"
Jim Inghamaf26b222017-08-02 00:16:10 +000015#include "lldb/API/SBStringList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000016
Greg Clayton4e78f602010-11-18 18:52:36 +000017#include "lldb/Breakpoint/Breakpoint.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018#include "lldb/Breakpoint/BreakpointLocation.h"
Jim Inghamd80102e2014-04-02 01:04:55 +000019#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Core/StreamFile.h"
Jim Inghamd80102e2014-04-02 01:04:55 +000021#include "lldb/Interpreter/CommandInterpreter.h"
22#include "lldb/Interpreter/ScriptInterpreter.h"
Greg Claytonaf67cec2010-12-20 20:49:23 +000023#include "lldb/Target/Target.h"
Jim Ingham62b02c62010-06-18 01:47:08 +000024#include "lldb/Target/ThreadSpec.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
Jonas Devliegherebaf56642019-03-06 00:06:00 +000032SBBreakpointLocation::SBBreakpointLocation() {
33 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBBreakpointLocation);
34}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035
Kate Stoneb9c1b512016-09-06 20:57:50 +000036SBBreakpointLocation::SBBreakpointLocation(
37 const lldb::BreakpointLocationSP &break_loc_sp)
Pavel Labathc5789432017-03-01 10:08:48 +000038 : m_opaque_wp(break_loc_sp) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000039 LLDB_RECORD_CONSTRUCTOR(SBBreakpointLocation,
40 (const lldb::BreakpointLocationSP &), break_loc_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041}
42
Kate Stoneb9c1b512016-09-06 20:57:50 +000043SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs)
Jonas Devliegherebaf56642019-03-06 00:06:00 +000044 : m_opaque_wp(rhs.m_opaque_wp) {
45 LLDB_RECORD_CONSTRUCTOR(SBBreakpointLocation,
46 (const lldb::SBBreakpointLocation &), rhs);
47}
Caroline Ticeceb6b132010-10-26 03:11:13 +000048
Kate Stoneb9c1b512016-09-06 20:57:50 +000049const SBBreakpointLocation &SBBreakpointLocation::
50operator=(const SBBreakpointLocation &rhs) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000051 LLDB_RECORD_METHOD(
52 const lldb::SBBreakpointLocation &,
53 SBBreakpointLocation, operator=,(const lldb::SBBreakpointLocation &),
54 rhs);
55
Pavel Labathc5789432017-03-01 10:08:48 +000056 m_opaque_wp = rhs.m_opaque_wp;
Jonas Devlieghere306809f2019-04-03 21:31:22 +000057 return LLDB_RECORD_RESULT(*this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058}
59
Kate Stoneb9c1b512016-09-06 20:57:50 +000060SBBreakpointLocation::~SBBreakpointLocation() {}
61
Pavel Labathc5789432017-03-01 10:08:48 +000062BreakpointLocationSP SBBreakpointLocation::GetSP() const {
63 return m_opaque_wp.lock();
64}
65
Jonas Devliegherebaf56642019-03-06 00:06:00 +000066bool SBBreakpointLocation::IsValid() const {
67 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBreakpointLocation, IsValid);
Pavel Labath7f5237b2019-03-11 13:58:46 +000068 return this->operator bool();
69}
70SBBreakpointLocation::operator bool() const {
71 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBreakpointLocation, operator bool);
Jonas Devliegherebaf56642019-03-06 00:06:00 +000072
73 return bool(GetSP());
74}
Kate Stoneb9c1b512016-09-06 20:57:50 +000075
76SBAddress SBBreakpointLocation::GetAddress() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000077 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBAddress, SBBreakpointLocation, GetAddress);
78
Pavel Labathc5789432017-03-01 10:08:48 +000079 BreakpointLocationSP loc_sp = GetSP();
Jonas Devliegherebaf56642019-03-06 00:06:00 +000080 if (loc_sp) {
81 return LLDB_RECORD_RESULT(SBAddress(&loc_sp->GetAddress()));
82 }
83
84 return LLDB_RECORD_RESULT(SBAddress());
Greg Claytonefabb122010-11-05 23:17:00 +000085}
86
Kate Stoneb9c1b512016-09-06 20:57:50 +000087addr_t SBBreakpointLocation::GetLoadAddress() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000088 LLDB_RECORD_METHOD_NO_ARGS(lldb::addr_t, SBBreakpointLocation,
89 GetLoadAddress);
90
Kate Stoneb9c1b512016-09-06 20:57:50 +000091 addr_t ret_addr = LLDB_INVALID_ADDRESS;
Pavel Labathc5789432017-03-01 10:08:48 +000092 BreakpointLocationSP loc_sp = GetSP();
Kate Stoneb9c1b512016-09-06 20:57:50 +000093
Pavel Labathc5789432017-03-01 10:08:48 +000094 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +000095 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +000096 loc_sp->GetTarget().GetAPIMutex());
97 ret_addr = loc_sp->GetLoadAddress();
Kate Stoneb9c1b512016-09-06 20:57:50 +000098 }
99
100 return ret_addr;
Greg Claytonefabb122010-11-05 23:17:00 +0000101}
102
Kate Stoneb9c1b512016-09-06 20:57:50 +0000103void SBBreakpointLocation::SetEnabled(bool enabled) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000104 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetEnabled, (bool), enabled);
105
Pavel Labathc5789432017-03-01 10:08:48 +0000106 BreakpointLocationSP loc_sp = GetSP();
107 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000108 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000109 loc_sp->GetTarget().GetAPIMutex());
110 loc_sp->SetEnabled(enabled);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000111 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000112}
113
Kate Stoneb9c1b512016-09-06 20:57:50 +0000114bool SBBreakpointLocation::IsEnabled() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000115 LLDB_RECORD_METHOD_NO_ARGS(bool, SBBreakpointLocation, IsEnabled);
116
Pavel Labathc5789432017-03-01 10:08:48 +0000117 BreakpointLocationSP loc_sp = GetSP();
118 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000119 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000120 loc_sp->GetTarget().GetAPIMutex());
121 return loc_sp->IsEnabled();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000122 } else
Greg Claytonaf67cec2010-12-20 20:49:23 +0000123 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000124}
125
Bruce Mitchenerccbf7982017-07-19 14:31:19 +0000126uint32_t SBBreakpointLocation::GetHitCount() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000127 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBBreakpointLocation, GetHitCount);
128
Bruce Mitchenerccbf7982017-07-19 14:31:19 +0000129 BreakpointLocationSP loc_sp = GetSP();
130 if (loc_sp) {
131 std::lock_guard<std::recursive_mutex> guard(
132 loc_sp->GetTarget().GetAPIMutex());
133 return loc_sp->GetHitCount();
134 } else
135 return 0;
136}
137
Kate Stoneb9c1b512016-09-06 20:57:50 +0000138uint32_t SBBreakpointLocation::GetIgnoreCount() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000139 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBBreakpointLocation, GetIgnoreCount);
140
Pavel Labathc5789432017-03-01 10:08:48 +0000141 BreakpointLocationSP loc_sp = GetSP();
142 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000143 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000144 loc_sp->GetTarget().GetAPIMutex());
145 return loc_sp->GetIgnoreCount();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000146 } else
147 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000148}
149
Kate Stoneb9c1b512016-09-06 20:57:50 +0000150void SBBreakpointLocation::SetIgnoreCount(uint32_t n) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000151 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetIgnoreCount, (uint32_t), n);
152
Pavel Labathc5789432017-03-01 10:08:48 +0000153 BreakpointLocationSP loc_sp = GetSP();
154 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000155 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000156 loc_sp->GetTarget().GetAPIMutex());
157 loc_sp->SetIgnoreCount(n);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000158 }
Caroline Ticedde9cff2010-09-20 05:20:02 +0000159}
160
Kate Stoneb9c1b512016-09-06 20:57:50 +0000161void SBBreakpointLocation::SetCondition(const char *condition) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000162 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetCondition, (const char *),
163 condition);
164
Pavel Labathc5789432017-03-01 10:08:48 +0000165 BreakpointLocationSP loc_sp = GetSP();
166 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000167 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000168 loc_sp->GetTarget().GetAPIMutex());
169 loc_sp->SetCondition(condition);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000170 }
Jim Inghamb08a9442012-05-16 00:51:15 +0000171}
172
Kate Stoneb9c1b512016-09-06 20:57:50 +0000173const char *SBBreakpointLocation::GetCondition() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000174 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBBreakpointLocation, GetCondition);
175
Pavel Labathc5789432017-03-01 10:08:48 +0000176 BreakpointLocationSP loc_sp = GetSP();
177 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000178 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000179 loc_sp->GetTarget().GetAPIMutex());
180 return loc_sp->GetConditionText();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000181 }
Konrad Kleine248a1302019-05-23 11:14:47 +0000182 return nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000183}
184
Jim Inghamf08f5c92017-08-03 18:13:24 +0000185void SBBreakpointLocation::SetAutoContinue(bool auto_continue) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000186 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetAutoContinue, (bool),
187 auto_continue);
188
Jim Inghamf08f5c92017-08-03 18:13:24 +0000189 BreakpointLocationSP loc_sp = GetSP();
190 if (loc_sp) {
191 std::lock_guard<std::recursive_mutex> guard(
192 loc_sp->GetTarget().GetAPIMutex());
193 loc_sp->SetAutoContinue(auto_continue);
194 }
195}
196
197bool SBBreakpointLocation::GetAutoContinue() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000198 LLDB_RECORD_METHOD_NO_ARGS(bool, SBBreakpointLocation, GetAutoContinue);
199
Jim Inghamf08f5c92017-08-03 18:13:24 +0000200 BreakpointLocationSP loc_sp = GetSP();
201 if (loc_sp) {
202 std::lock_guard<std::recursive_mutex> guard(
203 loc_sp->GetTarget().GetAPIMutex());
204 return loc_sp->IsAutoContinue();
205 }
Jim Ingham1c7dc822017-08-03 19:38:38 +0000206 return false;
Jim Inghamf08f5c92017-08-03 18:13:24 +0000207}
208
Kate Stoneb9c1b512016-09-06 20:57:50 +0000209void SBBreakpointLocation::SetScriptCallbackFunction(
210 const char *callback_function_name) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000211 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetScriptCallbackFunction,
212 (const char *), callback_function_name);
213
Pavel Labathc5789432017-03-01 10:08:48 +0000214 BreakpointLocationSP loc_sp = GetSP();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000215
Pavel Labathc5789432017-03-01 10:08:48 +0000216 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000217 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000218 loc_sp->GetTarget().GetAPIMutex());
219 BreakpointOptions *bp_options = loc_sp->GetLocationOptions();
220 loc_sp->GetBreakpoint()
Kate Stoneb9c1b512016-09-06 20:57:50 +0000221 .GetTarget()
222 .GetDebugger()
Kate Stoneb9c1b512016-09-06 20:57:50 +0000223 .GetScriptInterpreter()
224 ->SetBreakpointCommandCallbackFunction(bp_options,
225 callback_function_name);
226 }
227}
228
229SBError
230SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000231 LLDB_RECORD_METHOD(lldb::SBError, SBBreakpointLocation, SetScriptCallbackBody,
232 (const char *), callback_body_text);
233
Pavel Labathc5789432017-03-01 10:08:48 +0000234 BreakpointLocationSP loc_sp = GetSP();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000235
236 SBError sb_error;
Pavel Labathc5789432017-03-01 10:08:48 +0000237 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000238 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000239 loc_sp->GetTarget().GetAPIMutex());
240 BreakpointOptions *bp_options = loc_sp->GetLocationOptions();
Zachary Turner97206d52017-05-12 04:51:55 +0000241 Status error =
Pavel Labathc5789432017-03-01 10:08:48 +0000242 loc_sp->GetBreakpoint()
Kate Stoneb9c1b512016-09-06 20:57:50 +0000243 .GetTarget()
244 .GetDebugger()
Kate Stoneb9c1b512016-09-06 20:57:50 +0000245 .GetScriptInterpreter()
246 ->SetBreakpointCommandCallback(bp_options, callback_body_text);
247 sb_error.SetError(error);
248 } else
249 sb_error.SetErrorString("invalid breakpoint");
250
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000251 return LLDB_RECORD_RESULT(sb_error);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000252}
253
Jim Inghamaf26b222017-08-02 00:16:10 +0000254void SBBreakpointLocation::SetCommandLineCommands(SBStringList &commands) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000255 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetCommandLineCommands,
256 (lldb::SBStringList &), commands);
257
Jim Inghamaf26b222017-08-02 00:16:10 +0000258 BreakpointLocationSP loc_sp = GetSP();
259 if (!loc_sp)
260 return;
261 if (commands.GetSize() == 0)
262 return;
263
264 std::lock_guard<std::recursive_mutex> guard(
265 loc_sp->GetTarget().GetAPIMutex());
266 std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
267 new BreakpointOptions::CommandData(*commands, eScriptLanguageNone));
268
269 loc_sp->GetLocationOptions()->SetCommandDataCallback(cmd_data_up);
270}
271
272bool SBBreakpointLocation::GetCommandLineCommands(SBStringList &commands) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000273 LLDB_RECORD_METHOD(bool, SBBreakpointLocation, GetCommandLineCommands,
274 (lldb::SBStringList &), commands);
275
Jim Inghamaf26b222017-08-02 00:16:10 +0000276 BreakpointLocationSP loc_sp = GetSP();
277 if (!loc_sp)
278 return false;
279 StringList command_list;
280 bool has_commands =
281 loc_sp->GetLocationOptions()->GetCommandLineCallbacks(command_list);
282 if (has_commands)
283 commands.AppendList(command_list);
284 return has_commands;
285}
286
Kate Stoneb9c1b512016-09-06 20:57:50 +0000287void SBBreakpointLocation::SetThreadID(tid_t thread_id) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000288 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetThreadID, (lldb::tid_t),
289 thread_id);
290
Pavel Labathc5789432017-03-01 10:08:48 +0000291 BreakpointLocationSP loc_sp = GetSP();
292 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000293 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000294 loc_sp->GetTarget().GetAPIMutex());
295 loc_sp->SetThreadID(thread_id);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000296 }
297}
298
299tid_t SBBreakpointLocation::GetThreadID() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000300 LLDB_RECORD_METHOD_NO_ARGS(lldb::tid_t, SBBreakpointLocation, GetThreadID);
301
Kate Stoneb9c1b512016-09-06 20:57:50 +0000302 tid_t tid = LLDB_INVALID_THREAD_ID;
Pavel Labathc5789432017-03-01 10:08:48 +0000303 BreakpointLocationSP loc_sp = GetSP();
304 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000305 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000306 loc_sp->GetTarget().GetAPIMutex());
307 return loc_sp->GetThreadID();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000308 }
309 return tid;
310}
311
312void SBBreakpointLocation::SetThreadIndex(uint32_t index) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000313 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetThreadIndex, (uint32_t),
314 index);
315
Pavel Labathc5789432017-03-01 10:08:48 +0000316 BreakpointLocationSP loc_sp = GetSP();
317 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000318 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000319 loc_sp->GetTarget().GetAPIMutex());
320 loc_sp->SetThreadIndex(index);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000321 }
322}
323
324uint32_t SBBreakpointLocation::GetThreadIndex() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000325 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBBreakpointLocation,
326 GetThreadIndex);
327
Kate Stoneb9c1b512016-09-06 20:57:50 +0000328 uint32_t thread_idx = UINT32_MAX;
Pavel Labathc5789432017-03-01 10:08:48 +0000329 BreakpointLocationSP loc_sp = GetSP();
330 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000331 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000332 loc_sp->GetTarget().GetAPIMutex());
333 return loc_sp->GetThreadIndex();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000334 }
335 return thread_idx;
336}
337
338void SBBreakpointLocation::SetThreadName(const char *thread_name) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000339 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetThreadName, (const char *),
340 thread_name);
341
Pavel Labathc5789432017-03-01 10:08:48 +0000342 BreakpointLocationSP loc_sp = GetSP();
343 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000344 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000345 loc_sp->GetTarget().GetAPIMutex());
346 loc_sp->SetThreadName(thread_name);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000347 }
348}
349
350const char *SBBreakpointLocation::GetThreadName() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000351 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBBreakpointLocation,
352 GetThreadName);
353
Pavel Labathc5789432017-03-01 10:08:48 +0000354 BreakpointLocationSP loc_sp = GetSP();
355 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000356 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000357 loc_sp->GetTarget().GetAPIMutex());
358 return loc_sp->GetThreadName();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000359 }
Konrad Kleine248a1302019-05-23 11:14:47 +0000360 return nullptr;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000361}
362
363void SBBreakpointLocation::SetQueueName(const char *queue_name) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000364 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetQueueName, (const char *),
365 queue_name);
366
Pavel Labathc5789432017-03-01 10:08:48 +0000367 BreakpointLocationSP loc_sp = GetSP();
368 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000369 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000370 loc_sp->GetTarget().GetAPIMutex());
371 loc_sp->SetQueueName(queue_name);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000372 }
373}
374
375const char *SBBreakpointLocation::GetQueueName() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000376 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBBreakpointLocation,
377 GetQueueName);
378
Pavel Labathc5789432017-03-01 10:08:48 +0000379 BreakpointLocationSP loc_sp = GetSP();
380 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000381 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000382 loc_sp->GetTarget().GetAPIMutex());
383 loc_sp->GetQueueName();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000384 }
Konrad Kleine248a1302019-05-23 11:14:47 +0000385 return nullptr;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000386}
387
388bool SBBreakpointLocation::IsResolved() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000389 LLDB_RECORD_METHOD_NO_ARGS(bool, SBBreakpointLocation, IsResolved);
390
Pavel Labathc5789432017-03-01 10:08:48 +0000391 BreakpointLocationSP loc_sp = GetSP();
392 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000393 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000394 loc_sp->GetTarget().GetAPIMutex());
395 return loc_sp->IsResolved();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000396 }
397 return false;
398}
399
400void SBBreakpointLocation::SetLocation(
401 const lldb::BreakpointLocationSP &break_loc_sp) {
402 // Uninstall the callbacks?
Pavel Labathc5789432017-03-01 10:08:48 +0000403 m_opaque_wp = break_loc_sp;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000404}
405
406bool SBBreakpointLocation::GetDescription(SBStream &description,
407 DescriptionLevel level) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000408 LLDB_RECORD_METHOD(bool, SBBreakpointLocation, GetDescription,
409 (lldb::SBStream &, lldb::DescriptionLevel), description,
410 level);
411
Kate Stoneb9c1b512016-09-06 20:57:50 +0000412 Stream &strm = description.ref();
Pavel Labathc5789432017-03-01 10:08:48 +0000413 BreakpointLocationSP loc_sp = GetSP();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000414
Pavel Labathc5789432017-03-01 10:08:48 +0000415 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000416 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000417 loc_sp->GetTarget().GetAPIMutex());
418 loc_sp->GetDescription(&strm, level);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000419 strm.EOL();
420 } else
421 strm.PutCString("No value");
422
423 return true;
424}
425
426break_id_t SBBreakpointLocation::GetID() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000427 LLDB_RECORD_METHOD_NO_ARGS(lldb::break_id_t, SBBreakpointLocation, GetID);
428
Pavel Labathc5789432017-03-01 10:08:48 +0000429 BreakpointLocationSP loc_sp = GetSP();
430 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000431 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000432 loc_sp->GetTarget().GetAPIMutex());
433 return loc_sp->GetID();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000434 } else
435 return LLDB_INVALID_BREAK_ID;
436}
437
438SBBreakpoint SBBreakpointLocation::GetBreakpoint() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000439 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBBreakpoint, SBBreakpointLocation,
440 GetBreakpoint);
441
Pavel Labathc5789432017-03-01 10:08:48 +0000442 BreakpointLocationSP loc_sp = GetSP();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000443
444 SBBreakpoint sb_bp;
Pavel Labathc5789432017-03-01 10:08:48 +0000445 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000446 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000447 loc_sp->GetTarget().GetAPIMutex());
448 sb_bp = loc_sp->GetBreakpoint().shared_from_this();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000449 }
450
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000451 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000452}
Michal Gornyae211ec2019-03-19 17:13:13 +0000453
454namespace lldb_private {
455namespace repro {
456
457template <>
458void RegisterMethods<SBBreakpointLocation>(Registry &R) {
459 LLDB_REGISTER_CONSTRUCTOR(SBBreakpointLocation, ());
460 LLDB_REGISTER_CONSTRUCTOR(SBBreakpointLocation,
461 (const lldb::BreakpointLocationSP &));
462 LLDB_REGISTER_CONSTRUCTOR(SBBreakpointLocation,
463 (const lldb::SBBreakpointLocation &));
464 LLDB_REGISTER_METHOD(
465 const lldb::SBBreakpointLocation &,
466 SBBreakpointLocation, operator=,(const lldb::SBBreakpointLocation &));
467 LLDB_REGISTER_METHOD_CONST(bool, SBBreakpointLocation, IsValid, ());
468 LLDB_REGISTER_METHOD_CONST(bool, SBBreakpointLocation, operator bool, ());
469 LLDB_REGISTER_METHOD(lldb::SBAddress, SBBreakpointLocation, GetAddress, ());
470 LLDB_REGISTER_METHOD(lldb::addr_t, SBBreakpointLocation, GetLoadAddress,
471 ());
472 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetEnabled, (bool));
473 LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, IsEnabled, ());
474 LLDB_REGISTER_METHOD(uint32_t, SBBreakpointLocation, GetHitCount, ());
475 LLDB_REGISTER_METHOD(uint32_t, SBBreakpointLocation, GetIgnoreCount, ());
476 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetIgnoreCount,
477 (uint32_t));
478 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetCondition,
479 (const char *));
480 LLDB_REGISTER_METHOD(const char *, SBBreakpointLocation, GetCondition, ());
481 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetAutoContinue, (bool));
482 LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, GetAutoContinue, ());
483 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetScriptCallbackFunction,
484 (const char *));
485 LLDB_REGISTER_METHOD(lldb::SBError, SBBreakpointLocation,
486 SetScriptCallbackBody, (const char *));
487 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetCommandLineCommands,
488 (lldb::SBStringList &));
489 LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, GetCommandLineCommands,
490 (lldb::SBStringList &));
491 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetThreadID,
492 (lldb::tid_t));
493 LLDB_REGISTER_METHOD(lldb::tid_t, SBBreakpointLocation, GetThreadID, ());
494 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetThreadIndex,
495 (uint32_t));
496 LLDB_REGISTER_METHOD_CONST(uint32_t, SBBreakpointLocation, GetThreadIndex,
497 ());
498 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetThreadName,
499 (const char *));
500 LLDB_REGISTER_METHOD_CONST(const char *, SBBreakpointLocation,
501 GetThreadName, ());
502 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetQueueName,
503 (const char *));
504 LLDB_REGISTER_METHOD_CONST(const char *, SBBreakpointLocation, GetQueueName,
505 ());
506 LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, IsResolved, ());
507 LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, GetDescription,
508 (lldb::SBStream &, lldb::DescriptionLevel));
509 LLDB_REGISTER_METHOD(lldb::break_id_t, SBBreakpointLocation, GetID, ());
510 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBBreakpointLocation,
511 GetBreakpoint, ());
512}
513
514}
515}