1*0b57cec5SDimitry Andric //===-- SBBreakpointLocation.cpp --------------------------------*- C++ -*-===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric 
9*0b57cec5SDimitry Andric #include "lldb/API/SBBreakpointLocation.h"
10*0b57cec5SDimitry Andric #include "SBReproducerPrivate.h"
11*0b57cec5SDimitry Andric #include "lldb/API/SBAddress.h"
12*0b57cec5SDimitry Andric #include "lldb/API/SBDebugger.h"
13*0b57cec5SDimitry Andric #include "lldb/API/SBDefines.h"
14*0b57cec5SDimitry Andric #include "lldb/API/SBStream.h"
15480093f4SDimitry Andric #include "lldb/API/SBStructuredData.h"
16*0b57cec5SDimitry Andric #include "lldb/API/SBStringList.h"
17*0b57cec5SDimitry Andric 
18*0b57cec5SDimitry Andric #include "lldb/Breakpoint/Breakpoint.h"
19*0b57cec5SDimitry Andric #include "lldb/Breakpoint/BreakpointLocation.h"
20*0b57cec5SDimitry Andric #include "lldb/Core/Debugger.h"
21*0b57cec5SDimitry Andric #include "lldb/Core/StreamFile.h"
22480093f4SDimitry Andric #include "lldb/Core/StructuredDataImpl.h"
23*0b57cec5SDimitry Andric #include "lldb/Interpreter/CommandInterpreter.h"
24*0b57cec5SDimitry Andric #include "lldb/Interpreter/ScriptInterpreter.h"
25*0b57cec5SDimitry Andric #include "lldb/Target/Target.h"
26*0b57cec5SDimitry Andric #include "lldb/Target/ThreadSpec.h"
27*0b57cec5SDimitry Andric #include "lldb/Utility/Stream.h"
28*0b57cec5SDimitry Andric #include "lldb/lldb-defines.h"
29*0b57cec5SDimitry Andric #include "lldb/lldb-types.h"
30*0b57cec5SDimitry Andric 
31*0b57cec5SDimitry Andric using namespace lldb;
32*0b57cec5SDimitry Andric using namespace lldb_private;
33*0b57cec5SDimitry Andric 
34*0b57cec5SDimitry Andric SBBreakpointLocation::SBBreakpointLocation() {
35*0b57cec5SDimitry Andric   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBBreakpointLocation);
36*0b57cec5SDimitry Andric }
37*0b57cec5SDimitry Andric 
38*0b57cec5SDimitry Andric SBBreakpointLocation::SBBreakpointLocation(
39*0b57cec5SDimitry Andric     const lldb::BreakpointLocationSP &break_loc_sp)
40*0b57cec5SDimitry Andric     : m_opaque_wp(break_loc_sp) {
41*0b57cec5SDimitry Andric   LLDB_RECORD_CONSTRUCTOR(SBBreakpointLocation,
42*0b57cec5SDimitry Andric                           (const lldb::BreakpointLocationSP &), break_loc_sp);
43*0b57cec5SDimitry Andric }
44*0b57cec5SDimitry Andric 
45*0b57cec5SDimitry Andric SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs)
46*0b57cec5SDimitry Andric     : m_opaque_wp(rhs.m_opaque_wp) {
47*0b57cec5SDimitry Andric   LLDB_RECORD_CONSTRUCTOR(SBBreakpointLocation,
48*0b57cec5SDimitry Andric                           (const lldb::SBBreakpointLocation &), rhs);
49*0b57cec5SDimitry Andric }
50*0b57cec5SDimitry Andric 
51*0b57cec5SDimitry Andric const SBBreakpointLocation &SBBreakpointLocation::
52*0b57cec5SDimitry Andric operator=(const SBBreakpointLocation &rhs) {
53*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(
54*0b57cec5SDimitry Andric       const lldb::SBBreakpointLocation &,
55*0b57cec5SDimitry Andric       SBBreakpointLocation, operator=,(const lldb::SBBreakpointLocation &),
56*0b57cec5SDimitry Andric       rhs);
57*0b57cec5SDimitry Andric 
58*0b57cec5SDimitry Andric   m_opaque_wp = rhs.m_opaque_wp;
59*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(*this);
60*0b57cec5SDimitry Andric }
61*0b57cec5SDimitry Andric 
62*0b57cec5SDimitry Andric SBBreakpointLocation::~SBBreakpointLocation() {}
63*0b57cec5SDimitry Andric 
64*0b57cec5SDimitry Andric BreakpointLocationSP SBBreakpointLocation::GetSP() const {
65*0b57cec5SDimitry Andric   return m_opaque_wp.lock();
66*0b57cec5SDimitry Andric }
67*0b57cec5SDimitry Andric 
68*0b57cec5SDimitry Andric bool SBBreakpointLocation::IsValid() const {
69*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBreakpointLocation, IsValid);
70*0b57cec5SDimitry Andric   return this->operator bool();
71*0b57cec5SDimitry Andric }
72*0b57cec5SDimitry Andric SBBreakpointLocation::operator bool() const {
73*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBreakpointLocation, operator bool);
74*0b57cec5SDimitry Andric 
75*0b57cec5SDimitry Andric   return bool(GetSP());
76*0b57cec5SDimitry Andric }
77*0b57cec5SDimitry Andric 
78*0b57cec5SDimitry Andric SBAddress SBBreakpointLocation::GetAddress() {
79*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBAddress, SBBreakpointLocation, GetAddress);
80*0b57cec5SDimitry Andric 
81*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
82*0b57cec5SDimitry Andric   if (loc_sp) {
83*0b57cec5SDimitry Andric     return LLDB_RECORD_RESULT(SBAddress(&loc_sp->GetAddress()));
84*0b57cec5SDimitry Andric   }
85*0b57cec5SDimitry Andric 
86*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(SBAddress());
87*0b57cec5SDimitry Andric }
88*0b57cec5SDimitry Andric 
89*0b57cec5SDimitry Andric addr_t SBBreakpointLocation::GetLoadAddress() {
90*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(lldb::addr_t, SBBreakpointLocation,
91*0b57cec5SDimitry Andric                              GetLoadAddress);
92*0b57cec5SDimitry Andric 
93*0b57cec5SDimitry Andric   addr_t ret_addr = LLDB_INVALID_ADDRESS;
94*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
95*0b57cec5SDimitry Andric 
96*0b57cec5SDimitry Andric   if (loc_sp) {
97*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
98*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
99*0b57cec5SDimitry Andric     ret_addr = loc_sp->GetLoadAddress();
100*0b57cec5SDimitry Andric   }
101*0b57cec5SDimitry Andric 
102*0b57cec5SDimitry Andric   return ret_addr;
103*0b57cec5SDimitry Andric }
104*0b57cec5SDimitry Andric 
105*0b57cec5SDimitry Andric void SBBreakpointLocation::SetEnabled(bool enabled) {
106*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetEnabled, (bool), enabled);
107*0b57cec5SDimitry Andric 
108*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
109*0b57cec5SDimitry Andric   if (loc_sp) {
110*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
111*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
112*0b57cec5SDimitry Andric     loc_sp->SetEnabled(enabled);
113*0b57cec5SDimitry Andric   }
114*0b57cec5SDimitry Andric }
115*0b57cec5SDimitry Andric 
116*0b57cec5SDimitry Andric bool SBBreakpointLocation::IsEnabled() {
117*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(bool, SBBreakpointLocation, IsEnabled);
118*0b57cec5SDimitry Andric 
119*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
120*0b57cec5SDimitry Andric   if (loc_sp) {
121*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
122*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
123*0b57cec5SDimitry Andric     return loc_sp->IsEnabled();
124*0b57cec5SDimitry Andric   } else
125*0b57cec5SDimitry Andric     return false;
126*0b57cec5SDimitry Andric }
127*0b57cec5SDimitry Andric 
128*0b57cec5SDimitry Andric uint32_t SBBreakpointLocation::GetHitCount() {
129*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBBreakpointLocation, GetHitCount);
130*0b57cec5SDimitry Andric 
131*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
132*0b57cec5SDimitry Andric   if (loc_sp) {
133*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
134*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
135*0b57cec5SDimitry Andric     return loc_sp->GetHitCount();
136*0b57cec5SDimitry Andric   } else
137*0b57cec5SDimitry Andric     return 0;
138*0b57cec5SDimitry Andric }
139*0b57cec5SDimitry Andric 
140*0b57cec5SDimitry Andric uint32_t SBBreakpointLocation::GetIgnoreCount() {
141*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBBreakpointLocation, GetIgnoreCount);
142*0b57cec5SDimitry Andric 
143*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
144*0b57cec5SDimitry Andric   if (loc_sp) {
145*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
146*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
147*0b57cec5SDimitry Andric     return loc_sp->GetIgnoreCount();
148*0b57cec5SDimitry Andric   } else
149*0b57cec5SDimitry Andric     return 0;
150*0b57cec5SDimitry Andric }
151*0b57cec5SDimitry Andric 
152*0b57cec5SDimitry Andric void SBBreakpointLocation::SetIgnoreCount(uint32_t n) {
153*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetIgnoreCount, (uint32_t), n);
154*0b57cec5SDimitry Andric 
155*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
156*0b57cec5SDimitry Andric   if (loc_sp) {
157*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
158*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
159*0b57cec5SDimitry Andric     loc_sp->SetIgnoreCount(n);
160*0b57cec5SDimitry Andric   }
161*0b57cec5SDimitry Andric }
162*0b57cec5SDimitry Andric 
163*0b57cec5SDimitry Andric void SBBreakpointLocation::SetCondition(const char *condition) {
164*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetCondition, (const char *),
165*0b57cec5SDimitry Andric                      condition);
166*0b57cec5SDimitry Andric 
167*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
168*0b57cec5SDimitry Andric   if (loc_sp) {
169*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
170*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
171*0b57cec5SDimitry Andric     loc_sp->SetCondition(condition);
172*0b57cec5SDimitry Andric   }
173*0b57cec5SDimitry Andric }
174*0b57cec5SDimitry Andric 
175*0b57cec5SDimitry Andric const char *SBBreakpointLocation::GetCondition() {
176*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBBreakpointLocation, GetCondition);
177*0b57cec5SDimitry Andric 
178*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
179*0b57cec5SDimitry Andric   if (loc_sp) {
180*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
181*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
182*0b57cec5SDimitry Andric     return loc_sp->GetConditionText();
183*0b57cec5SDimitry Andric   }
184*0b57cec5SDimitry Andric   return nullptr;
185*0b57cec5SDimitry Andric }
186*0b57cec5SDimitry Andric 
187*0b57cec5SDimitry Andric void SBBreakpointLocation::SetAutoContinue(bool auto_continue) {
188*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetAutoContinue, (bool),
189*0b57cec5SDimitry Andric                      auto_continue);
190*0b57cec5SDimitry Andric 
191*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
192*0b57cec5SDimitry Andric   if (loc_sp) {
193*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
194*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
195*0b57cec5SDimitry Andric     loc_sp->SetAutoContinue(auto_continue);
196*0b57cec5SDimitry Andric   }
197*0b57cec5SDimitry Andric }
198*0b57cec5SDimitry Andric 
199*0b57cec5SDimitry Andric bool SBBreakpointLocation::GetAutoContinue() {
200*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(bool, SBBreakpointLocation, GetAutoContinue);
201*0b57cec5SDimitry Andric 
202*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
203*0b57cec5SDimitry Andric   if (loc_sp) {
204*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
205*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
206*0b57cec5SDimitry Andric     return loc_sp->IsAutoContinue();
207*0b57cec5SDimitry Andric   }
208*0b57cec5SDimitry Andric   return false;
209*0b57cec5SDimitry Andric }
210*0b57cec5SDimitry Andric 
211*0b57cec5SDimitry Andric void SBBreakpointLocation::SetScriptCallbackFunction(
212*0b57cec5SDimitry Andric   const char *callback_function_name) {
213*0b57cec5SDimitry Andric LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetScriptCallbackFunction,
214*0b57cec5SDimitry Andric                    (const char *), callback_function_name);
215480093f4SDimitry Andric }
216*0b57cec5SDimitry Andric 
217480093f4SDimitry Andric SBError SBBreakpointLocation::SetScriptCallbackFunction(
218480093f4SDimitry Andric     const char *callback_function_name,
219480093f4SDimitry Andric     SBStructuredData &extra_args) {
220480093f4SDimitry Andric   LLDB_RECORD_METHOD(SBError, SBBreakpointLocation, SetScriptCallbackFunction,
221480093f4SDimitry Andric                      (const char *, SBStructuredData &),
222480093f4SDimitry Andric                      callback_function_name, extra_args);
223480093f4SDimitry Andric   SBError sb_error;
224*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
225*0b57cec5SDimitry Andric 
226*0b57cec5SDimitry Andric   if (loc_sp) {
227480093f4SDimitry Andric     Status error;
228*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
229*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
230*0b57cec5SDimitry Andric     BreakpointOptions *bp_options = loc_sp->GetLocationOptions();
231480093f4SDimitry Andric     error = loc_sp->GetBreakpoint()
232*0b57cec5SDimitry Andric         .GetTarget()
233*0b57cec5SDimitry Andric         .GetDebugger()
234*0b57cec5SDimitry Andric         .GetScriptInterpreter()
235*0b57cec5SDimitry Andric         ->SetBreakpointCommandCallbackFunction(bp_options,
236480093f4SDimitry Andric                                                callback_function_name,
237480093f4SDimitry Andric                                                extra_args.m_impl_up
238480093f4SDimitry Andric                                                    ->GetObjectSP());
239480093f4SDimitry Andric       sb_error.SetError(error);
240480093f4SDimitry Andric     } else
241480093f4SDimitry Andric       sb_error.SetErrorString("invalid breakpoint");
242480093f4SDimitry Andric 
243480093f4SDimitry Andric     return LLDB_RECORD_RESULT(sb_error);
244*0b57cec5SDimitry Andric }
245*0b57cec5SDimitry Andric 
246*0b57cec5SDimitry Andric SBError
247*0b57cec5SDimitry Andric SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) {
248*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBError, SBBreakpointLocation, SetScriptCallbackBody,
249*0b57cec5SDimitry Andric                      (const char *), callback_body_text);
250*0b57cec5SDimitry Andric 
251*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
252*0b57cec5SDimitry Andric 
253*0b57cec5SDimitry Andric   SBError sb_error;
254*0b57cec5SDimitry Andric   if (loc_sp) {
255*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
256*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
257*0b57cec5SDimitry Andric     BreakpointOptions *bp_options = loc_sp->GetLocationOptions();
258*0b57cec5SDimitry Andric     Status error =
259*0b57cec5SDimitry Andric         loc_sp->GetBreakpoint()
260*0b57cec5SDimitry Andric             .GetTarget()
261*0b57cec5SDimitry Andric             .GetDebugger()
262*0b57cec5SDimitry Andric             .GetScriptInterpreter()
263*0b57cec5SDimitry Andric             ->SetBreakpointCommandCallback(bp_options, callback_body_text);
264*0b57cec5SDimitry Andric     sb_error.SetError(error);
265*0b57cec5SDimitry Andric   } else
266*0b57cec5SDimitry Andric     sb_error.SetErrorString("invalid breakpoint");
267*0b57cec5SDimitry Andric 
268*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_error);
269*0b57cec5SDimitry Andric }
270*0b57cec5SDimitry Andric 
271*0b57cec5SDimitry Andric void SBBreakpointLocation::SetCommandLineCommands(SBStringList &commands) {
272*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetCommandLineCommands,
273*0b57cec5SDimitry Andric                      (lldb::SBStringList &), commands);
274*0b57cec5SDimitry Andric 
275*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
276*0b57cec5SDimitry Andric   if (!loc_sp)
277*0b57cec5SDimitry Andric     return;
278*0b57cec5SDimitry Andric   if (commands.GetSize() == 0)
279*0b57cec5SDimitry Andric     return;
280*0b57cec5SDimitry Andric 
281*0b57cec5SDimitry Andric   std::lock_guard<std::recursive_mutex> guard(
282*0b57cec5SDimitry Andric       loc_sp->GetTarget().GetAPIMutex());
283*0b57cec5SDimitry Andric   std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
284*0b57cec5SDimitry Andric       new BreakpointOptions::CommandData(*commands, eScriptLanguageNone));
285*0b57cec5SDimitry Andric 
286*0b57cec5SDimitry Andric   loc_sp->GetLocationOptions()->SetCommandDataCallback(cmd_data_up);
287*0b57cec5SDimitry Andric }
288*0b57cec5SDimitry Andric 
289*0b57cec5SDimitry Andric bool SBBreakpointLocation::GetCommandLineCommands(SBStringList &commands) {
290*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(bool, SBBreakpointLocation, GetCommandLineCommands,
291*0b57cec5SDimitry Andric                      (lldb::SBStringList &), commands);
292*0b57cec5SDimitry Andric 
293*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
294*0b57cec5SDimitry Andric   if (!loc_sp)
295*0b57cec5SDimitry Andric     return false;
296*0b57cec5SDimitry Andric   StringList command_list;
297*0b57cec5SDimitry Andric   bool has_commands =
298*0b57cec5SDimitry Andric       loc_sp->GetLocationOptions()->GetCommandLineCallbacks(command_list);
299*0b57cec5SDimitry Andric   if (has_commands)
300*0b57cec5SDimitry Andric     commands.AppendList(command_list);
301*0b57cec5SDimitry Andric   return has_commands;
302*0b57cec5SDimitry Andric }
303*0b57cec5SDimitry Andric 
304*0b57cec5SDimitry Andric void SBBreakpointLocation::SetThreadID(tid_t thread_id) {
305*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetThreadID, (lldb::tid_t),
306*0b57cec5SDimitry Andric                      thread_id);
307*0b57cec5SDimitry Andric 
308*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
309*0b57cec5SDimitry Andric   if (loc_sp) {
310*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
311*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
312*0b57cec5SDimitry Andric     loc_sp->SetThreadID(thread_id);
313*0b57cec5SDimitry Andric   }
314*0b57cec5SDimitry Andric }
315*0b57cec5SDimitry Andric 
316*0b57cec5SDimitry Andric tid_t SBBreakpointLocation::GetThreadID() {
317*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(lldb::tid_t, SBBreakpointLocation, GetThreadID);
318*0b57cec5SDimitry Andric 
319*0b57cec5SDimitry Andric   tid_t tid = LLDB_INVALID_THREAD_ID;
320*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
321*0b57cec5SDimitry Andric   if (loc_sp) {
322*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
323*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
324*0b57cec5SDimitry Andric     return loc_sp->GetThreadID();
325*0b57cec5SDimitry Andric   }
326*0b57cec5SDimitry Andric   return tid;
327*0b57cec5SDimitry Andric }
328*0b57cec5SDimitry Andric 
329*0b57cec5SDimitry Andric void SBBreakpointLocation::SetThreadIndex(uint32_t index) {
330*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetThreadIndex, (uint32_t),
331*0b57cec5SDimitry Andric                      index);
332*0b57cec5SDimitry Andric 
333*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
334*0b57cec5SDimitry Andric   if (loc_sp) {
335*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
336*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
337*0b57cec5SDimitry Andric     loc_sp->SetThreadIndex(index);
338*0b57cec5SDimitry Andric   }
339*0b57cec5SDimitry Andric }
340*0b57cec5SDimitry Andric 
341*0b57cec5SDimitry Andric uint32_t SBBreakpointLocation::GetThreadIndex() const {
342*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBBreakpointLocation,
343*0b57cec5SDimitry Andric                                    GetThreadIndex);
344*0b57cec5SDimitry Andric 
345*0b57cec5SDimitry Andric   uint32_t thread_idx = UINT32_MAX;
346*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
347*0b57cec5SDimitry Andric   if (loc_sp) {
348*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
349*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
350*0b57cec5SDimitry Andric     return loc_sp->GetThreadIndex();
351*0b57cec5SDimitry Andric   }
352*0b57cec5SDimitry Andric   return thread_idx;
353*0b57cec5SDimitry Andric }
354*0b57cec5SDimitry Andric 
355*0b57cec5SDimitry Andric void SBBreakpointLocation::SetThreadName(const char *thread_name) {
356*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetThreadName, (const char *),
357*0b57cec5SDimitry Andric                      thread_name);
358*0b57cec5SDimitry Andric 
359*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
360*0b57cec5SDimitry Andric   if (loc_sp) {
361*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
362*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
363*0b57cec5SDimitry Andric     loc_sp->SetThreadName(thread_name);
364*0b57cec5SDimitry Andric   }
365*0b57cec5SDimitry Andric }
366*0b57cec5SDimitry Andric 
367*0b57cec5SDimitry Andric const char *SBBreakpointLocation::GetThreadName() const {
368*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBBreakpointLocation,
369*0b57cec5SDimitry Andric                                    GetThreadName);
370*0b57cec5SDimitry Andric 
371*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
372*0b57cec5SDimitry Andric   if (loc_sp) {
373*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
374*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
375*0b57cec5SDimitry Andric     return loc_sp->GetThreadName();
376*0b57cec5SDimitry Andric   }
377*0b57cec5SDimitry Andric   return nullptr;
378*0b57cec5SDimitry Andric }
379*0b57cec5SDimitry Andric 
380*0b57cec5SDimitry Andric void SBBreakpointLocation::SetQueueName(const char *queue_name) {
381*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetQueueName, (const char *),
382*0b57cec5SDimitry Andric                      queue_name);
383*0b57cec5SDimitry Andric 
384*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
385*0b57cec5SDimitry Andric   if (loc_sp) {
386*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
387*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
388*0b57cec5SDimitry Andric     loc_sp->SetQueueName(queue_name);
389*0b57cec5SDimitry Andric   }
390*0b57cec5SDimitry Andric }
391*0b57cec5SDimitry Andric 
392*0b57cec5SDimitry Andric const char *SBBreakpointLocation::GetQueueName() const {
393*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBBreakpointLocation,
394*0b57cec5SDimitry Andric                                    GetQueueName);
395*0b57cec5SDimitry Andric 
396*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
397*0b57cec5SDimitry Andric   if (loc_sp) {
398*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
399*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
400*0b57cec5SDimitry Andric     loc_sp->GetQueueName();
401*0b57cec5SDimitry Andric   }
402*0b57cec5SDimitry Andric   return nullptr;
403*0b57cec5SDimitry Andric }
404*0b57cec5SDimitry Andric 
405*0b57cec5SDimitry Andric bool SBBreakpointLocation::IsResolved() {
406*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(bool, SBBreakpointLocation, IsResolved);
407*0b57cec5SDimitry Andric 
408*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
409*0b57cec5SDimitry Andric   if (loc_sp) {
410*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
411*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
412*0b57cec5SDimitry Andric     return loc_sp->IsResolved();
413*0b57cec5SDimitry Andric   }
414*0b57cec5SDimitry Andric   return false;
415*0b57cec5SDimitry Andric }
416*0b57cec5SDimitry Andric 
417*0b57cec5SDimitry Andric void SBBreakpointLocation::SetLocation(
418*0b57cec5SDimitry Andric     const lldb::BreakpointLocationSP &break_loc_sp) {
419*0b57cec5SDimitry Andric   // Uninstall the callbacks?
420*0b57cec5SDimitry Andric   m_opaque_wp = break_loc_sp;
421*0b57cec5SDimitry Andric }
422*0b57cec5SDimitry Andric 
423*0b57cec5SDimitry Andric bool SBBreakpointLocation::GetDescription(SBStream &description,
424*0b57cec5SDimitry Andric                                           DescriptionLevel level) {
425*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(bool, SBBreakpointLocation, GetDescription,
426*0b57cec5SDimitry Andric                      (lldb::SBStream &, lldb::DescriptionLevel), description,
427*0b57cec5SDimitry Andric                      level);
428*0b57cec5SDimitry Andric 
429*0b57cec5SDimitry Andric   Stream &strm = description.ref();
430*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
431*0b57cec5SDimitry Andric 
432*0b57cec5SDimitry Andric   if (loc_sp) {
433*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
434*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
435*0b57cec5SDimitry Andric     loc_sp->GetDescription(&strm, level);
436*0b57cec5SDimitry Andric     strm.EOL();
437*0b57cec5SDimitry Andric   } else
438*0b57cec5SDimitry Andric     strm.PutCString("No value");
439*0b57cec5SDimitry Andric 
440*0b57cec5SDimitry Andric   return true;
441*0b57cec5SDimitry Andric }
442*0b57cec5SDimitry Andric 
443*0b57cec5SDimitry Andric break_id_t SBBreakpointLocation::GetID() {
444*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(lldb::break_id_t, SBBreakpointLocation, GetID);
445*0b57cec5SDimitry Andric 
446*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
447*0b57cec5SDimitry Andric   if (loc_sp) {
448*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
449*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
450*0b57cec5SDimitry Andric     return loc_sp->GetID();
451*0b57cec5SDimitry Andric   } else
452*0b57cec5SDimitry Andric     return LLDB_INVALID_BREAK_ID;
453*0b57cec5SDimitry Andric }
454*0b57cec5SDimitry Andric 
455*0b57cec5SDimitry Andric SBBreakpoint SBBreakpointLocation::GetBreakpoint() {
456*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBBreakpoint, SBBreakpointLocation,
457*0b57cec5SDimitry Andric                              GetBreakpoint);
458*0b57cec5SDimitry Andric 
459*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
460*0b57cec5SDimitry Andric 
461*0b57cec5SDimitry Andric   SBBreakpoint sb_bp;
462*0b57cec5SDimitry Andric   if (loc_sp) {
463*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
464*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
465*0b57cec5SDimitry Andric     sb_bp = loc_sp->GetBreakpoint().shared_from_this();
466*0b57cec5SDimitry Andric   }
467*0b57cec5SDimitry Andric 
468*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_bp);
469*0b57cec5SDimitry Andric }
470*0b57cec5SDimitry Andric 
471*0b57cec5SDimitry Andric namespace lldb_private {
472*0b57cec5SDimitry Andric namespace repro {
473*0b57cec5SDimitry Andric 
474*0b57cec5SDimitry Andric template <>
475*0b57cec5SDimitry Andric void RegisterMethods<SBBreakpointLocation>(Registry &R) {
476*0b57cec5SDimitry Andric   LLDB_REGISTER_CONSTRUCTOR(SBBreakpointLocation, ());
477*0b57cec5SDimitry Andric   LLDB_REGISTER_CONSTRUCTOR(SBBreakpointLocation,
478*0b57cec5SDimitry Andric                             (const lldb::BreakpointLocationSP &));
479*0b57cec5SDimitry Andric   LLDB_REGISTER_CONSTRUCTOR(SBBreakpointLocation,
480*0b57cec5SDimitry Andric                             (const lldb::SBBreakpointLocation &));
481*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(
482*0b57cec5SDimitry Andric       const lldb::SBBreakpointLocation &,
483*0b57cec5SDimitry Andric       SBBreakpointLocation, operator=,(const lldb::SBBreakpointLocation &));
484*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(bool, SBBreakpointLocation, IsValid, ());
485*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(bool, SBBreakpointLocation, operator bool, ());
486*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBAddress, SBBreakpointLocation, GetAddress, ());
487*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::addr_t, SBBreakpointLocation, GetLoadAddress,
488*0b57cec5SDimitry Andric                        ());
489*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetEnabled, (bool));
490*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, IsEnabled, ());
491*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(uint32_t, SBBreakpointLocation, GetHitCount, ());
492*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(uint32_t, SBBreakpointLocation, GetIgnoreCount, ());
493*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetIgnoreCount,
494*0b57cec5SDimitry Andric                        (uint32_t));
495*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetCondition,
496*0b57cec5SDimitry Andric                        (const char *));
497*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(const char *, SBBreakpointLocation, GetCondition, ());
498*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetAutoContinue, (bool));
499*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, GetAutoContinue, ());
500*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetScriptCallbackFunction,
501*0b57cec5SDimitry Andric                        (const char *));
502480093f4SDimitry Andric   LLDB_REGISTER_METHOD(SBError, SBBreakpointLocation, SetScriptCallbackFunction,
503480093f4SDimitry Andric                        (const char *, SBStructuredData &));
504*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBError, SBBreakpointLocation,
505*0b57cec5SDimitry Andric                        SetScriptCallbackBody, (const char *));
506*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetCommandLineCommands,
507*0b57cec5SDimitry Andric                        (lldb::SBStringList &));
508*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, GetCommandLineCommands,
509*0b57cec5SDimitry Andric                        (lldb::SBStringList &));
510*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetThreadID,
511*0b57cec5SDimitry Andric                        (lldb::tid_t));
512*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::tid_t, SBBreakpointLocation, GetThreadID, ());
513*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetThreadIndex,
514*0b57cec5SDimitry Andric                        (uint32_t));
515*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(uint32_t, SBBreakpointLocation, GetThreadIndex,
516*0b57cec5SDimitry Andric                              ());
517*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetThreadName,
518*0b57cec5SDimitry Andric                        (const char *));
519*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(const char *, SBBreakpointLocation,
520*0b57cec5SDimitry Andric                              GetThreadName, ());
521*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetQueueName,
522*0b57cec5SDimitry Andric                        (const char *));
523*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(const char *, SBBreakpointLocation, GetQueueName,
524*0b57cec5SDimitry Andric                              ());
525*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, IsResolved, ());
526*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, GetDescription,
527*0b57cec5SDimitry Andric                        (lldb::SBStream &, lldb::DescriptionLevel));
528*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::break_id_t, SBBreakpointLocation, GetID, ());
529*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBBreakpointLocation,
530*0b57cec5SDimitry Andric                        GetBreakpoint, ());
531*0b57cec5SDimitry Andric }
532*0b57cec5SDimitry Andric 
533*0b57cec5SDimitry Andric }
534*0b57cec5SDimitry Andric }
535