blob: d6bbb5faf041a7aefcec261e5a9ea205c5967179 [file] [log] [blame]
Raphael Isemann80814282020-01-24 08:23:27 +01001//===-- SBBreakpointLocation.cpp ------------------------------------------===//
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002//
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 Ingham738af7a2019-10-25 14:05:07 -070015#include "lldb/API/SBStructuredData.h"
Jim Inghamaf26b222017-08-02 00:16:10 +000016#include "lldb/API/SBStringList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017
Greg Clayton4e78f602010-11-18 18:52:36 +000018#include "lldb/Breakpoint/Breakpoint.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Breakpoint/BreakpointLocation.h"
Jim Inghamd80102e2014-04-02 01:04:55 +000020#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021#include "lldb/Core/StreamFile.h"
Jim Ingham738af7a2019-10-25 14:05:07 -070022#include "lldb/Core/StructuredDataImpl.h"
Jim Inghamd80102e2014-04-02 01:04:55 +000023#include "lldb/Interpreter/CommandInterpreter.h"
24#include "lldb/Interpreter/ScriptInterpreter.h"
Greg Claytonaf67cec2010-12-20 20:49:23 +000025#include "lldb/Target/Target.h"
Jim Ingham62b02c62010-06-18 01:47:08 +000026#include "lldb/Target/ThreadSpec.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000027#include "lldb/Utility/Stream.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000028#include "lldb/lldb-defines.h"
29#include "lldb/lldb-types.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030
31using namespace lldb;
32using namespace lldb_private;
33
Jonas Devliegherebaf56642019-03-06 00:06:00 +000034SBBreakpointLocation::SBBreakpointLocation() {
35 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBBreakpointLocation);
36}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037
Kate Stoneb9c1b512016-09-06 20:57:50 +000038SBBreakpointLocation::SBBreakpointLocation(
39 const lldb::BreakpointLocationSP &break_loc_sp)
Pavel Labathc5789432017-03-01 10:08:48 +000040 : m_opaque_wp(break_loc_sp) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000041 LLDB_RECORD_CONSTRUCTOR(SBBreakpointLocation,
42 (const lldb::BreakpointLocationSP &), break_loc_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043}
44
Kate Stoneb9c1b512016-09-06 20:57:50 +000045SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs)
Jonas Devliegherebaf56642019-03-06 00:06:00 +000046 : m_opaque_wp(rhs.m_opaque_wp) {
47 LLDB_RECORD_CONSTRUCTOR(SBBreakpointLocation,
48 (const lldb::SBBreakpointLocation &), rhs);
49}
Caroline Ticeceb6b132010-10-26 03:11:13 +000050
Kate Stoneb9c1b512016-09-06 20:57:50 +000051const SBBreakpointLocation &SBBreakpointLocation::
52operator=(const SBBreakpointLocation &rhs) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000053 LLDB_RECORD_METHOD(
54 const lldb::SBBreakpointLocation &,
55 SBBreakpointLocation, operator=,(const lldb::SBBreakpointLocation &),
56 rhs);
57
Pavel Labathc5789432017-03-01 10:08:48 +000058 m_opaque_wp = rhs.m_opaque_wp;
Jonas Devlieghere306809f2019-04-03 21:31:22 +000059 return LLDB_RECORD_RESULT(*this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060}
61
Jonas Devlieghere866b7a62020-02-17 22:57:06 -080062SBBreakpointLocation::~SBBreakpointLocation() = default;
Kate Stoneb9c1b512016-09-06 20:57:50 +000063
Pavel Labathc5789432017-03-01 10:08:48 +000064BreakpointLocationSP SBBreakpointLocation::GetSP() const {
65 return m_opaque_wp.lock();
66}
67
Jonas Devliegherebaf56642019-03-06 00:06:00 +000068bool SBBreakpointLocation::IsValid() const {
69 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBreakpointLocation, IsValid);
Pavel Labath7f5237b2019-03-11 13:58:46 +000070 return this->operator bool();
71}
72SBBreakpointLocation::operator bool() const {
73 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBreakpointLocation, operator bool);
Jonas Devliegherebaf56642019-03-06 00:06:00 +000074
75 return bool(GetSP());
76}
Kate Stoneb9c1b512016-09-06 20:57:50 +000077
78SBAddress SBBreakpointLocation::GetAddress() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000079 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBAddress, SBBreakpointLocation, GetAddress);
80
Pavel Labathc5789432017-03-01 10:08:48 +000081 BreakpointLocationSP loc_sp = GetSP();
Jonas Devliegherebaf56642019-03-06 00:06:00 +000082 if (loc_sp) {
Jonas Devlieghere6cd4a4c2020-09-25 11:15:44 -070083 return LLDB_RECORD_RESULT(SBAddress(loc_sp->GetAddress()));
Jonas Devliegherebaf56642019-03-06 00:06:00 +000084 }
85
86 return LLDB_RECORD_RESULT(SBAddress());
Greg Claytonefabb122010-11-05 23:17:00 +000087}
88
Kate Stoneb9c1b512016-09-06 20:57:50 +000089addr_t SBBreakpointLocation::GetLoadAddress() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000090 LLDB_RECORD_METHOD_NO_ARGS(lldb::addr_t, SBBreakpointLocation,
91 GetLoadAddress);
92
Kate Stoneb9c1b512016-09-06 20:57:50 +000093 addr_t ret_addr = LLDB_INVALID_ADDRESS;
Pavel Labathc5789432017-03-01 10:08:48 +000094 BreakpointLocationSP loc_sp = GetSP();
Kate Stoneb9c1b512016-09-06 20:57:50 +000095
Pavel Labathc5789432017-03-01 10:08:48 +000096 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +000097 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +000098 loc_sp->GetTarget().GetAPIMutex());
99 ret_addr = loc_sp->GetLoadAddress();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000100 }
101
102 return ret_addr;
Greg Claytonefabb122010-11-05 23:17:00 +0000103}
104
Kate Stoneb9c1b512016-09-06 20:57:50 +0000105void SBBreakpointLocation::SetEnabled(bool enabled) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000106 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetEnabled, (bool), enabled);
107
Pavel Labathc5789432017-03-01 10:08:48 +0000108 BreakpointLocationSP loc_sp = GetSP();
109 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000110 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000111 loc_sp->GetTarget().GetAPIMutex());
112 loc_sp->SetEnabled(enabled);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000113 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000114}
115
Kate Stoneb9c1b512016-09-06 20:57:50 +0000116bool SBBreakpointLocation::IsEnabled() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000117 LLDB_RECORD_METHOD_NO_ARGS(bool, SBBreakpointLocation, IsEnabled);
118
Pavel Labathc5789432017-03-01 10:08:48 +0000119 BreakpointLocationSP loc_sp = GetSP();
120 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000121 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000122 loc_sp->GetTarget().GetAPIMutex());
123 return loc_sp->IsEnabled();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000124 } else
Greg Claytonaf67cec2010-12-20 20:49:23 +0000125 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000126}
127
Bruce Mitchenerccbf7982017-07-19 14:31:19 +0000128uint32_t SBBreakpointLocation::GetHitCount() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000129 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBBreakpointLocation, GetHitCount);
130
Bruce Mitchenerccbf7982017-07-19 14:31:19 +0000131 BreakpointLocationSP loc_sp = GetSP();
132 if (loc_sp) {
133 std::lock_guard<std::recursive_mutex> guard(
134 loc_sp->GetTarget().GetAPIMutex());
135 return loc_sp->GetHitCount();
136 } else
137 return 0;
138}
139
Kate Stoneb9c1b512016-09-06 20:57:50 +0000140uint32_t SBBreakpointLocation::GetIgnoreCount() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000141 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBBreakpointLocation, GetIgnoreCount);
142
Pavel Labathc5789432017-03-01 10:08:48 +0000143 BreakpointLocationSP loc_sp = GetSP();
144 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000145 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000146 loc_sp->GetTarget().GetAPIMutex());
147 return loc_sp->GetIgnoreCount();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000148 } else
149 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000150}
151
Kate Stoneb9c1b512016-09-06 20:57:50 +0000152void SBBreakpointLocation::SetIgnoreCount(uint32_t n) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000153 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetIgnoreCount, (uint32_t), n);
154
Pavel Labathc5789432017-03-01 10:08:48 +0000155 BreakpointLocationSP loc_sp = GetSP();
156 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000157 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000158 loc_sp->GetTarget().GetAPIMutex());
159 loc_sp->SetIgnoreCount(n);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000160 }
Caroline Ticedde9cff2010-09-20 05:20:02 +0000161}
162
Kate Stoneb9c1b512016-09-06 20:57:50 +0000163void SBBreakpointLocation::SetCondition(const char *condition) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000164 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetCondition, (const char *),
165 condition);
166
Pavel Labathc5789432017-03-01 10:08:48 +0000167 BreakpointLocationSP loc_sp = GetSP();
168 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000169 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000170 loc_sp->GetTarget().GetAPIMutex());
171 loc_sp->SetCondition(condition);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000172 }
Jim Inghamb08a9442012-05-16 00:51:15 +0000173}
174
Kate Stoneb9c1b512016-09-06 20:57:50 +0000175const char *SBBreakpointLocation::GetCondition() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000176 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBBreakpointLocation, GetCondition);
177
Pavel Labathc5789432017-03-01 10:08:48 +0000178 BreakpointLocationSP loc_sp = GetSP();
179 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000180 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000181 loc_sp->GetTarget().GetAPIMutex());
182 return loc_sp->GetConditionText();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000183 }
Konrad Kleine248a1302019-05-23 11:14:47 +0000184 return nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000185}
186
Jim Inghamf08f5c92017-08-03 18:13:24 +0000187void SBBreakpointLocation::SetAutoContinue(bool auto_continue) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000188 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetAutoContinue, (bool),
189 auto_continue);
190
Jim Inghamf08f5c92017-08-03 18:13:24 +0000191 BreakpointLocationSP loc_sp = GetSP();
192 if (loc_sp) {
193 std::lock_guard<std::recursive_mutex> guard(
194 loc_sp->GetTarget().GetAPIMutex());
195 loc_sp->SetAutoContinue(auto_continue);
196 }
197}
198
199bool SBBreakpointLocation::GetAutoContinue() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000200 LLDB_RECORD_METHOD_NO_ARGS(bool, SBBreakpointLocation, GetAutoContinue);
201
Jim Inghamf08f5c92017-08-03 18:13:24 +0000202 BreakpointLocationSP loc_sp = GetSP();
203 if (loc_sp) {
204 std::lock_guard<std::recursive_mutex> guard(
205 loc_sp->GetTarget().GetAPIMutex());
206 return loc_sp->IsAutoContinue();
207 }
Jim Ingham1c7dc822017-08-03 19:38:38 +0000208 return false;
Jim Inghamf08f5c92017-08-03 18:13:24 +0000209}
210
Kate Stoneb9c1b512016-09-06 20:57:50 +0000211void SBBreakpointLocation::SetScriptCallbackFunction(
Jim Ingham738af7a2019-10-25 14:05:07 -0700212 const char *callback_function_name) {
213LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetScriptCallbackFunction,
214 (const char *), callback_function_name);
215}
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000216
Jim Ingham738af7a2019-10-25 14:05:07 -0700217SBError SBBreakpointLocation::SetScriptCallbackFunction(
218 const char *callback_function_name,
219 SBStructuredData &extra_args) {
220 LLDB_RECORD_METHOD(SBError, SBBreakpointLocation, SetScriptCallbackFunction,
Jonas Devlieghere6cd4a4c2020-09-25 11:15:44 -0700221 (const char *, SBStructuredData &), callback_function_name,
222 extra_args);
Jim Ingham738af7a2019-10-25 14:05:07 -0700223 SBError sb_error;
Pavel Labathc5789432017-03-01 10:08:48 +0000224 BreakpointLocationSP loc_sp = GetSP();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000225
Pavel Labathc5789432017-03-01 10:08:48 +0000226 if (loc_sp) {
Jim Ingham738af7a2019-10-25 14:05:07 -0700227 Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000228 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000229 loc_sp->GetTarget().GetAPIMutex());
230 BreakpointOptions *bp_options = loc_sp->GetLocationOptions();
Jim Ingham738af7a2019-10-25 14:05:07 -0700231 error = loc_sp->GetBreakpoint()
Kate Stoneb9c1b512016-09-06 20:57:50 +0000232 .GetTarget()
233 .GetDebugger()
Kate Stoneb9c1b512016-09-06 20:57:50 +0000234 .GetScriptInterpreter()
235 ->SetBreakpointCommandCallbackFunction(bp_options,
Jim Ingham738af7a2019-10-25 14:05:07 -0700236 callback_function_name,
237 extra_args.m_impl_up
238 ->GetObjectSP());
239 sb_error.SetError(error);
240 } else
241 sb_error.SetErrorString("invalid breakpoint");
Jonas Devlieghere6cd4a4c2020-09-25 11:15:44 -0700242
Jim Ingham738af7a2019-10-25 14:05:07 -0700243 return LLDB_RECORD_RESULT(sb_error);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000244}
245
246SBError
247SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000248 LLDB_RECORD_METHOD(lldb::SBError, SBBreakpointLocation, SetScriptCallbackBody,
249 (const char *), callback_body_text);
250
Pavel Labathc5789432017-03-01 10:08:48 +0000251 BreakpointLocationSP loc_sp = GetSP();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000252
253 SBError sb_error;
Pavel Labathc5789432017-03-01 10:08:48 +0000254 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000255 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000256 loc_sp->GetTarget().GetAPIMutex());
257 BreakpointOptions *bp_options = loc_sp->GetLocationOptions();
Zachary Turner97206d52017-05-12 04:51:55 +0000258 Status error =
Pavel Labathc5789432017-03-01 10:08:48 +0000259 loc_sp->GetBreakpoint()
Kate Stoneb9c1b512016-09-06 20:57:50 +0000260 .GetTarget()
261 .GetDebugger()
Kate Stoneb9c1b512016-09-06 20:57:50 +0000262 .GetScriptInterpreter()
263 ->SetBreakpointCommandCallback(bp_options, callback_body_text);
264 sb_error.SetError(error);
265 } else
266 sb_error.SetErrorString("invalid breakpoint");
267
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000268 return LLDB_RECORD_RESULT(sb_error);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000269}
270
Jim Inghamaf26b222017-08-02 00:16:10 +0000271void SBBreakpointLocation::SetCommandLineCommands(SBStringList &commands) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000272 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetCommandLineCommands,
273 (lldb::SBStringList &), commands);
274
Jim Inghamaf26b222017-08-02 00:16:10 +0000275 BreakpointLocationSP loc_sp = GetSP();
276 if (!loc_sp)
277 return;
278 if (commands.GetSize() == 0)
279 return;
280
281 std::lock_guard<std::recursive_mutex> guard(
282 loc_sp->GetTarget().GetAPIMutex());
283 std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
284 new BreakpointOptions::CommandData(*commands, eScriptLanguageNone));
285
286 loc_sp->GetLocationOptions()->SetCommandDataCallback(cmd_data_up);
287}
288
289bool SBBreakpointLocation::GetCommandLineCommands(SBStringList &commands) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000290 LLDB_RECORD_METHOD(bool, SBBreakpointLocation, GetCommandLineCommands,
291 (lldb::SBStringList &), commands);
292
Jim Inghamaf26b222017-08-02 00:16:10 +0000293 BreakpointLocationSP loc_sp = GetSP();
294 if (!loc_sp)
295 return false;
296 StringList command_list;
297 bool has_commands =
298 loc_sp->GetLocationOptions()->GetCommandLineCallbacks(command_list);
299 if (has_commands)
300 commands.AppendList(command_list);
301 return has_commands;
302}
303
Kate Stoneb9c1b512016-09-06 20:57:50 +0000304void SBBreakpointLocation::SetThreadID(tid_t thread_id) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000305 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetThreadID, (lldb::tid_t),
306 thread_id);
307
Pavel Labathc5789432017-03-01 10:08:48 +0000308 BreakpointLocationSP loc_sp = GetSP();
309 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000310 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000311 loc_sp->GetTarget().GetAPIMutex());
312 loc_sp->SetThreadID(thread_id);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000313 }
314}
315
316tid_t SBBreakpointLocation::GetThreadID() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000317 LLDB_RECORD_METHOD_NO_ARGS(lldb::tid_t, SBBreakpointLocation, GetThreadID);
318
Kate Stoneb9c1b512016-09-06 20:57:50 +0000319 tid_t tid = LLDB_INVALID_THREAD_ID;
Pavel Labathc5789432017-03-01 10:08:48 +0000320 BreakpointLocationSP loc_sp = GetSP();
321 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000322 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000323 loc_sp->GetTarget().GetAPIMutex());
324 return loc_sp->GetThreadID();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000325 }
326 return tid;
327}
328
329void SBBreakpointLocation::SetThreadIndex(uint32_t index) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000330 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetThreadIndex, (uint32_t),
331 index);
332
Pavel Labathc5789432017-03-01 10:08:48 +0000333 BreakpointLocationSP loc_sp = GetSP();
334 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000335 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000336 loc_sp->GetTarget().GetAPIMutex());
337 loc_sp->SetThreadIndex(index);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000338 }
339}
340
341uint32_t SBBreakpointLocation::GetThreadIndex() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000342 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBBreakpointLocation,
343 GetThreadIndex);
344
Kate Stoneb9c1b512016-09-06 20:57:50 +0000345 uint32_t thread_idx = UINT32_MAX;
Pavel Labathc5789432017-03-01 10:08:48 +0000346 BreakpointLocationSP loc_sp = GetSP();
347 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000348 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000349 loc_sp->GetTarget().GetAPIMutex());
350 return loc_sp->GetThreadIndex();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000351 }
352 return thread_idx;
353}
354
355void SBBreakpointLocation::SetThreadName(const char *thread_name) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000356 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetThreadName, (const char *),
357 thread_name);
358
Pavel Labathc5789432017-03-01 10:08:48 +0000359 BreakpointLocationSP loc_sp = GetSP();
360 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000361 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000362 loc_sp->GetTarget().GetAPIMutex());
363 loc_sp->SetThreadName(thread_name);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000364 }
365}
366
367const char *SBBreakpointLocation::GetThreadName() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000368 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBBreakpointLocation,
369 GetThreadName);
370
Pavel Labathc5789432017-03-01 10:08:48 +0000371 BreakpointLocationSP loc_sp = GetSP();
372 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000373 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000374 loc_sp->GetTarget().GetAPIMutex());
375 return loc_sp->GetThreadName();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000376 }
Konrad Kleine248a1302019-05-23 11:14:47 +0000377 return nullptr;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000378}
379
380void SBBreakpointLocation::SetQueueName(const char *queue_name) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000381 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetQueueName, (const char *),
382 queue_name);
383
Pavel Labathc5789432017-03-01 10:08:48 +0000384 BreakpointLocationSP loc_sp = GetSP();
385 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000386 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000387 loc_sp->GetTarget().GetAPIMutex());
388 loc_sp->SetQueueName(queue_name);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000389 }
390}
391
392const char *SBBreakpointLocation::GetQueueName() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000393 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBBreakpointLocation,
394 GetQueueName);
395
Pavel Labathc5789432017-03-01 10:08:48 +0000396 BreakpointLocationSP loc_sp = GetSP();
397 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000398 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000399 loc_sp->GetTarget().GetAPIMutex());
400 loc_sp->GetQueueName();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000401 }
Konrad Kleine248a1302019-05-23 11:14:47 +0000402 return nullptr;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000403}
404
405bool SBBreakpointLocation::IsResolved() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000406 LLDB_RECORD_METHOD_NO_ARGS(bool, SBBreakpointLocation, IsResolved);
407
Pavel Labathc5789432017-03-01 10:08:48 +0000408 BreakpointLocationSP loc_sp = GetSP();
409 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000410 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000411 loc_sp->GetTarget().GetAPIMutex());
412 return loc_sp->IsResolved();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000413 }
414 return false;
415}
416
417void SBBreakpointLocation::SetLocation(
418 const lldb::BreakpointLocationSP &break_loc_sp) {
419 // Uninstall the callbacks?
Pavel Labathc5789432017-03-01 10:08:48 +0000420 m_opaque_wp = break_loc_sp;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000421}
422
423bool SBBreakpointLocation::GetDescription(SBStream &description,
424 DescriptionLevel level) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000425 LLDB_RECORD_METHOD(bool, SBBreakpointLocation, GetDescription,
426 (lldb::SBStream &, lldb::DescriptionLevel), description,
427 level);
428
Kate Stoneb9c1b512016-09-06 20:57:50 +0000429 Stream &strm = description.ref();
Pavel Labathc5789432017-03-01 10:08:48 +0000430 BreakpointLocationSP loc_sp = GetSP();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000431
Pavel Labathc5789432017-03-01 10:08:48 +0000432 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000433 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000434 loc_sp->GetTarget().GetAPIMutex());
435 loc_sp->GetDescription(&strm, level);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000436 strm.EOL();
437 } else
438 strm.PutCString("No value");
439
440 return true;
441}
442
443break_id_t SBBreakpointLocation::GetID() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000444 LLDB_RECORD_METHOD_NO_ARGS(lldb::break_id_t, SBBreakpointLocation, GetID);
445
Pavel Labathc5789432017-03-01 10:08:48 +0000446 BreakpointLocationSP loc_sp = GetSP();
447 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000448 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000449 loc_sp->GetTarget().GetAPIMutex());
450 return loc_sp->GetID();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000451 } else
452 return LLDB_INVALID_BREAK_ID;
453}
454
455SBBreakpoint SBBreakpointLocation::GetBreakpoint() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000456 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBBreakpoint, SBBreakpointLocation,
457 GetBreakpoint);
458
Pavel Labathc5789432017-03-01 10:08:48 +0000459 BreakpointLocationSP loc_sp = GetSP();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000460
461 SBBreakpoint sb_bp;
Pavel Labathc5789432017-03-01 10:08:48 +0000462 if (loc_sp) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000463 std::lock_guard<std::recursive_mutex> guard(
Pavel Labathc5789432017-03-01 10:08:48 +0000464 loc_sp->GetTarget().GetAPIMutex());
465 sb_bp = loc_sp->GetBreakpoint().shared_from_this();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000466 }
467
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000468 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000469}
Michal Gornyae211ec2019-03-19 17:13:13 +0000470
471namespace lldb_private {
472namespace repro {
473
474template <>
475void RegisterMethods<SBBreakpointLocation>(Registry &R) {
476 LLDB_REGISTER_CONSTRUCTOR(SBBreakpointLocation, ());
477 LLDB_REGISTER_CONSTRUCTOR(SBBreakpointLocation,
478 (const lldb::BreakpointLocationSP &));
479 LLDB_REGISTER_CONSTRUCTOR(SBBreakpointLocation,
480 (const lldb::SBBreakpointLocation &));
481 LLDB_REGISTER_METHOD(
482 const lldb::SBBreakpointLocation &,
483 SBBreakpointLocation, operator=,(const lldb::SBBreakpointLocation &));
484 LLDB_REGISTER_METHOD_CONST(bool, SBBreakpointLocation, IsValid, ());
485 LLDB_REGISTER_METHOD_CONST(bool, SBBreakpointLocation, operator bool, ());
486 LLDB_REGISTER_METHOD(lldb::SBAddress, SBBreakpointLocation, GetAddress, ());
487 LLDB_REGISTER_METHOD(lldb::addr_t, SBBreakpointLocation, GetLoadAddress,
488 ());
489 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetEnabled, (bool));
490 LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, IsEnabled, ());
491 LLDB_REGISTER_METHOD(uint32_t, SBBreakpointLocation, GetHitCount, ());
492 LLDB_REGISTER_METHOD(uint32_t, SBBreakpointLocation, GetIgnoreCount, ());
493 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetIgnoreCount,
494 (uint32_t));
495 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetCondition,
496 (const char *));
497 LLDB_REGISTER_METHOD(const char *, SBBreakpointLocation, GetCondition, ());
498 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetAutoContinue, (bool));
499 LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, GetAutoContinue, ());
500 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetScriptCallbackFunction,
501 (const char *));
Jim Ingham738af7a2019-10-25 14:05:07 -0700502 LLDB_REGISTER_METHOD(SBError, SBBreakpointLocation, SetScriptCallbackFunction,
503 (const char *, SBStructuredData &));
Michal Gornyae211ec2019-03-19 17:13:13 +0000504 LLDB_REGISTER_METHOD(lldb::SBError, SBBreakpointLocation,
505 SetScriptCallbackBody, (const char *));
506 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetCommandLineCommands,
507 (lldb::SBStringList &));
508 LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, GetCommandLineCommands,
509 (lldb::SBStringList &));
510 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetThreadID,
511 (lldb::tid_t));
512 LLDB_REGISTER_METHOD(lldb::tid_t, SBBreakpointLocation, GetThreadID, ());
513 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetThreadIndex,
514 (uint32_t));
515 LLDB_REGISTER_METHOD_CONST(uint32_t, SBBreakpointLocation, GetThreadIndex,
516 ());
517 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetThreadName,
518 (const char *));
519 LLDB_REGISTER_METHOD_CONST(const char *, SBBreakpointLocation,
520 GetThreadName, ());
521 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetQueueName,
522 (const char *));
523 LLDB_REGISTER_METHOD_CONST(const char *, SBBreakpointLocation, GetQueueName,
524 ());
525 LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, IsResolved, ());
526 LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, GetDescription,
527 (lldb::SBStream &, lldb::DescriptionLevel));
528 LLDB_REGISTER_METHOD(lldb::break_id_t, SBBreakpointLocation, GetID, ());
529 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBBreakpointLocation,
530 GetBreakpoint, ());
531}
532
533}
534}