15ffd83dbSDimitry Andric //===-- SBBreakpointLocation.cpp ------------------------------------------===//
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 "lldb/API/SBAddress.h"
11*0b57cec5SDimitry Andric #include "lldb/API/SBDebugger.h"
12*0b57cec5SDimitry Andric #include "lldb/API/SBDefines.h"
13*0b57cec5SDimitry Andric #include "lldb/API/SBStream.h"
14*0b57cec5SDimitry Andric #include "lldb/API/SBStringList.h"
1504eeddc0SDimitry Andric #include "lldb/API/SBStructuredData.h"
1604eeddc0SDimitry Andric #include "lldb/Utility/Instrumentation.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 
31bdd1243dSDimitry Andric #include "SBBreakpointOptionCommon.h"
32bdd1243dSDimitry Andric 
33*0b57cec5SDimitry Andric using namespace lldb;
34*0b57cec5SDimitry Andric using namespace lldb_private;
35*0b57cec5SDimitry Andric 
3604eeddc0SDimitry Andric SBBreakpointLocation::SBBreakpointLocation() { LLDB_INSTRUMENT_VA(this); }
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) {
4104eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, break_loc_sp);
42*0b57cec5SDimitry Andric }
43*0b57cec5SDimitry Andric 
44*0b57cec5SDimitry Andric SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs)
45*0b57cec5SDimitry Andric     : m_opaque_wp(rhs.m_opaque_wp) {
4604eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, rhs);
47*0b57cec5SDimitry Andric }
48*0b57cec5SDimitry Andric 
49*0b57cec5SDimitry Andric const SBBreakpointLocation &SBBreakpointLocation::
50*0b57cec5SDimitry Andric operator=(const SBBreakpointLocation &rhs) {
5104eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, rhs);
52*0b57cec5SDimitry Andric 
53*0b57cec5SDimitry Andric   m_opaque_wp = rhs.m_opaque_wp;
5404eeddc0SDimitry Andric   return *this;
55*0b57cec5SDimitry Andric }
56*0b57cec5SDimitry Andric 
575ffd83dbSDimitry Andric SBBreakpointLocation::~SBBreakpointLocation() = default;
58*0b57cec5SDimitry Andric 
59*0b57cec5SDimitry Andric BreakpointLocationSP SBBreakpointLocation::GetSP() const {
60*0b57cec5SDimitry Andric   return m_opaque_wp.lock();
61*0b57cec5SDimitry Andric }
62*0b57cec5SDimitry Andric 
63*0b57cec5SDimitry Andric bool SBBreakpointLocation::IsValid() const {
6404eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
65*0b57cec5SDimitry Andric   return this->operator bool();
66*0b57cec5SDimitry Andric }
67*0b57cec5SDimitry Andric SBBreakpointLocation::operator bool() const {
6804eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
69*0b57cec5SDimitry Andric 
70*0b57cec5SDimitry Andric   return bool(GetSP());
71*0b57cec5SDimitry Andric }
72*0b57cec5SDimitry Andric 
73*0b57cec5SDimitry Andric SBAddress SBBreakpointLocation::GetAddress() {
7404eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
75*0b57cec5SDimitry Andric 
76*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
77*0b57cec5SDimitry Andric   if (loc_sp) {
7804eeddc0SDimitry Andric     return SBAddress(loc_sp->GetAddress());
79*0b57cec5SDimitry Andric   }
80*0b57cec5SDimitry Andric 
8104eeddc0SDimitry Andric   return SBAddress();
82*0b57cec5SDimitry Andric }
83*0b57cec5SDimitry Andric 
84*0b57cec5SDimitry Andric addr_t SBBreakpointLocation::GetLoadAddress() {
8504eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
86*0b57cec5SDimitry Andric 
87*0b57cec5SDimitry Andric   addr_t ret_addr = LLDB_INVALID_ADDRESS;
88*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
89*0b57cec5SDimitry Andric 
90*0b57cec5SDimitry Andric   if (loc_sp) {
91*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
92*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
93*0b57cec5SDimitry Andric     ret_addr = loc_sp->GetLoadAddress();
94*0b57cec5SDimitry Andric   }
95*0b57cec5SDimitry Andric 
96*0b57cec5SDimitry Andric   return ret_addr;
97*0b57cec5SDimitry Andric }
98*0b57cec5SDimitry Andric 
99*0b57cec5SDimitry Andric void SBBreakpointLocation::SetEnabled(bool enabled) {
10004eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, enabled);
101*0b57cec5SDimitry Andric 
102*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
103*0b57cec5SDimitry Andric   if (loc_sp) {
104*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
105*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
106*0b57cec5SDimitry Andric     loc_sp->SetEnabled(enabled);
107*0b57cec5SDimitry Andric   }
108*0b57cec5SDimitry Andric }
109*0b57cec5SDimitry Andric 
110*0b57cec5SDimitry Andric bool SBBreakpointLocation::IsEnabled() {
11104eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
112*0b57cec5SDimitry Andric 
113*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
114*0b57cec5SDimitry Andric   if (loc_sp) {
115*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
116*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
117*0b57cec5SDimitry Andric     return loc_sp->IsEnabled();
118*0b57cec5SDimitry Andric   } else
119*0b57cec5SDimitry Andric     return false;
120*0b57cec5SDimitry Andric }
121*0b57cec5SDimitry Andric 
122*0b57cec5SDimitry Andric uint32_t SBBreakpointLocation::GetHitCount() {
12304eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
124*0b57cec5SDimitry Andric 
125*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
126*0b57cec5SDimitry Andric   if (loc_sp) {
127*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
128*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
129*0b57cec5SDimitry Andric     return loc_sp->GetHitCount();
130*0b57cec5SDimitry Andric   } else
131*0b57cec5SDimitry Andric     return 0;
132*0b57cec5SDimitry Andric }
133*0b57cec5SDimitry Andric 
134*0b57cec5SDimitry Andric uint32_t SBBreakpointLocation::GetIgnoreCount() {
13504eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
136*0b57cec5SDimitry Andric 
137*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
138*0b57cec5SDimitry Andric   if (loc_sp) {
139*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
140*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
141*0b57cec5SDimitry Andric     return loc_sp->GetIgnoreCount();
142*0b57cec5SDimitry Andric   } else
143*0b57cec5SDimitry Andric     return 0;
144*0b57cec5SDimitry Andric }
145*0b57cec5SDimitry Andric 
146*0b57cec5SDimitry Andric void SBBreakpointLocation::SetIgnoreCount(uint32_t n) {
14704eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, n);
148*0b57cec5SDimitry Andric 
149*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
150*0b57cec5SDimitry Andric   if (loc_sp) {
151*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
152*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
153*0b57cec5SDimitry Andric     loc_sp->SetIgnoreCount(n);
154*0b57cec5SDimitry Andric   }
155*0b57cec5SDimitry Andric }
156*0b57cec5SDimitry Andric 
157*0b57cec5SDimitry Andric void SBBreakpointLocation::SetCondition(const char *condition) {
15804eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, condition);
159*0b57cec5SDimitry Andric 
160*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
161*0b57cec5SDimitry Andric   if (loc_sp) {
162*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
163*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
164*0b57cec5SDimitry Andric     loc_sp->SetCondition(condition);
165*0b57cec5SDimitry Andric   }
166*0b57cec5SDimitry Andric }
167*0b57cec5SDimitry Andric 
168*0b57cec5SDimitry Andric const char *SBBreakpointLocation::GetCondition() {
16904eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
170*0b57cec5SDimitry Andric 
171*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
172*0b57cec5SDimitry Andric   if (loc_sp) {
173*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
174*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
175*0b57cec5SDimitry Andric     return loc_sp->GetConditionText();
176*0b57cec5SDimitry Andric   }
177*0b57cec5SDimitry Andric   return nullptr;
178*0b57cec5SDimitry Andric }
179*0b57cec5SDimitry Andric 
180*0b57cec5SDimitry Andric void SBBreakpointLocation::SetAutoContinue(bool auto_continue) {
18104eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, auto_continue);
182*0b57cec5SDimitry Andric 
183*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
184*0b57cec5SDimitry Andric   if (loc_sp) {
185*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
186*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
187*0b57cec5SDimitry Andric     loc_sp->SetAutoContinue(auto_continue);
188*0b57cec5SDimitry Andric   }
189*0b57cec5SDimitry Andric }
190*0b57cec5SDimitry Andric 
191*0b57cec5SDimitry Andric bool SBBreakpointLocation::GetAutoContinue() {
19204eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
193*0b57cec5SDimitry Andric 
194*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
195*0b57cec5SDimitry Andric   if (loc_sp) {
196*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
197*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
198*0b57cec5SDimitry Andric     return loc_sp->IsAutoContinue();
199*0b57cec5SDimitry Andric   }
200*0b57cec5SDimitry Andric   return false;
201*0b57cec5SDimitry Andric }
202*0b57cec5SDimitry Andric 
203bdd1243dSDimitry Andric void SBBreakpointLocation::SetCallback(SBBreakpointHitCallback callback,
204bdd1243dSDimitry Andric                                        void *baton) {
205bdd1243dSDimitry Andric   LLDB_INSTRUMENT_VA(this, callback, baton);
206bdd1243dSDimitry Andric 
207bdd1243dSDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
208bdd1243dSDimitry Andric 
209bdd1243dSDimitry Andric   if (loc_sp) {
210bdd1243dSDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
211bdd1243dSDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
212bdd1243dSDimitry Andric     BatonSP baton_sp(new SBBreakpointCallbackBaton(callback, baton));
213bdd1243dSDimitry Andric     loc_sp->SetCallback(SBBreakpointCallbackBaton::PrivateBreakpointHitCallback,
214bdd1243dSDimitry Andric                         baton_sp, false);
215bdd1243dSDimitry Andric   }
216bdd1243dSDimitry Andric }
217bdd1243dSDimitry Andric 
218*0b57cec5SDimitry Andric void SBBreakpointLocation::SetScriptCallbackFunction(
219*0b57cec5SDimitry Andric   const char *callback_function_name) {
22004eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, callback_function_name);
221480093f4SDimitry Andric }
222*0b57cec5SDimitry Andric 
223480093f4SDimitry Andric SBError SBBreakpointLocation::SetScriptCallbackFunction(
224480093f4SDimitry Andric     const char *callback_function_name,
225480093f4SDimitry Andric     SBStructuredData &extra_args) {
22604eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, callback_function_name, extra_args);
227480093f4SDimitry Andric   SBError sb_error;
228*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
229*0b57cec5SDimitry Andric 
230*0b57cec5SDimitry Andric   if (loc_sp) {
231480093f4SDimitry Andric     Status error;
232*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
233*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
234fe6060f1SDimitry Andric     BreakpointOptions &bp_options = loc_sp->GetLocationOptions();
235480093f4SDimitry Andric     error = loc_sp->GetBreakpoint()
236*0b57cec5SDimitry Andric         .GetTarget()
237*0b57cec5SDimitry Andric         .GetDebugger()
238*0b57cec5SDimitry Andric         .GetScriptInterpreter()
239*0b57cec5SDimitry Andric         ->SetBreakpointCommandCallbackFunction(bp_options,
240480093f4SDimitry Andric                                                callback_function_name,
241480093f4SDimitry Andric                                                extra_args.m_impl_up
242480093f4SDimitry Andric                                                    ->GetObjectSP());
243480093f4SDimitry Andric       sb_error.SetError(error);
244480093f4SDimitry Andric     } else
245480093f4SDimitry Andric       sb_error.SetErrorString("invalid breakpoint");
246480093f4SDimitry Andric 
24704eeddc0SDimitry Andric     return sb_error;
248*0b57cec5SDimitry Andric }
249*0b57cec5SDimitry Andric 
250*0b57cec5SDimitry Andric SBError
251*0b57cec5SDimitry Andric SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) {
25204eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, callback_body_text);
253*0b57cec5SDimitry Andric 
254*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
255*0b57cec5SDimitry Andric 
256*0b57cec5SDimitry Andric   SBError sb_error;
257*0b57cec5SDimitry Andric   if (loc_sp) {
258*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
259*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
260fe6060f1SDimitry Andric     BreakpointOptions &bp_options = loc_sp->GetLocationOptions();
261*0b57cec5SDimitry Andric     Status error =
262*0b57cec5SDimitry Andric         loc_sp->GetBreakpoint()
263*0b57cec5SDimitry Andric             .GetTarget()
264*0b57cec5SDimitry Andric             .GetDebugger()
265*0b57cec5SDimitry Andric             .GetScriptInterpreter()
266*0b57cec5SDimitry Andric             ->SetBreakpointCommandCallback(bp_options, callback_body_text);
267*0b57cec5SDimitry Andric     sb_error.SetError(error);
268*0b57cec5SDimitry Andric   } else
269*0b57cec5SDimitry Andric     sb_error.SetErrorString("invalid breakpoint");
270*0b57cec5SDimitry Andric 
27104eeddc0SDimitry Andric   return sb_error;
272*0b57cec5SDimitry Andric }
273*0b57cec5SDimitry Andric 
274*0b57cec5SDimitry Andric void SBBreakpointLocation::SetCommandLineCommands(SBStringList &commands) {
27504eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, commands);
276*0b57cec5SDimitry Andric 
277*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
278*0b57cec5SDimitry Andric   if (!loc_sp)
279*0b57cec5SDimitry Andric     return;
280*0b57cec5SDimitry Andric   if (commands.GetSize() == 0)
281*0b57cec5SDimitry Andric     return;
282*0b57cec5SDimitry Andric 
283*0b57cec5SDimitry Andric   std::lock_guard<std::recursive_mutex> guard(
284*0b57cec5SDimitry Andric       loc_sp->GetTarget().GetAPIMutex());
285*0b57cec5SDimitry Andric   std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
286*0b57cec5SDimitry Andric       new BreakpointOptions::CommandData(*commands, eScriptLanguageNone));
287*0b57cec5SDimitry Andric 
288fe6060f1SDimitry Andric   loc_sp->GetLocationOptions().SetCommandDataCallback(cmd_data_up);
289*0b57cec5SDimitry Andric }
290*0b57cec5SDimitry Andric 
291*0b57cec5SDimitry Andric bool SBBreakpointLocation::GetCommandLineCommands(SBStringList &commands) {
29204eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, commands);
293*0b57cec5SDimitry Andric 
294*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
295*0b57cec5SDimitry Andric   if (!loc_sp)
296*0b57cec5SDimitry Andric     return false;
297*0b57cec5SDimitry Andric   StringList command_list;
298*0b57cec5SDimitry Andric   bool has_commands =
299fe6060f1SDimitry Andric       loc_sp->GetLocationOptions().GetCommandLineCallbacks(command_list);
300*0b57cec5SDimitry Andric   if (has_commands)
301*0b57cec5SDimitry Andric     commands.AppendList(command_list);
302*0b57cec5SDimitry Andric   return has_commands;
303*0b57cec5SDimitry Andric }
304*0b57cec5SDimitry Andric 
305*0b57cec5SDimitry Andric void SBBreakpointLocation::SetThreadID(tid_t thread_id) {
30604eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, 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() {
31704eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
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) {
33004eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, index);
331*0b57cec5SDimitry Andric 
332*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
333*0b57cec5SDimitry Andric   if (loc_sp) {
334*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
335*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
336*0b57cec5SDimitry Andric     loc_sp->SetThreadIndex(index);
337*0b57cec5SDimitry Andric   }
338*0b57cec5SDimitry Andric }
339*0b57cec5SDimitry Andric 
340*0b57cec5SDimitry Andric uint32_t SBBreakpointLocation::GetThreadIndex() const {
34104eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
342*0b57cec5SDimitry Andric 
343*0b57cec5SDimitry Andric   uint32_t thread_idx = UINT32_MAX;
344*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
345*0b57cec5SDimitry Andric   if (loc_sp) {
346*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
347*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
348*0b57cec5SDimitry Andric     return loc_sp->GetThreadIndex();
349*0b57cec5SDimitry Andric   }
350*0b57cec5SDimitry Andric   return thread_idx;
351*0b57cec5SDimitry Andric }
352*0b57cec5SDimitry Andric 
353*0b57cec5SDimitry Andric void SBBreakpointLocation::SetThreadName(const char *thread_name) {
35404eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, thread_name);
355*0b57cec5SDimitry Andric 
356*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
357*0b57cec5SDimitry Andric   if (loc_sp) {
358*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
359*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
360*0b57cec5SDimitry Andric     loc_sp->SetThreadName(thread_name);
361*0b57cec5SDimitry Andric   }
362*0b57cec5SDimitry Andric }
363*0b57cec5SDimitry Andric 
364*0b57cec5SDimitry Andric const char *SBBreakpointLocation::GetThreadName() const {
36504eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
366*0b57cec5SDimitry Andric 
367*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
368*0b57cec5SDimitry Andric   if (loc_sp) {
369*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
370*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
371*0b57cec5SDimitry Andric     return loc_sp->GetThreadName();
372*0b57cec5SDimitry Andric   }
373*0b57cec5SDimitry Andric   return nullptr;
374*0b57cec5SDimitry Andric }
375*0b57cec5SDimitry Andric 
376*0b57cec5SDimitry Andric void SBBreakpointLocation::SetQueueName(const char *queue_name) {
37704eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, queue_name);
378*0b57cec5SDimitry Andric 
379*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
380*0b57cec5SDimitry Andric   if (loc_sp) {
381*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
382*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
383*0b57cec5SDimitry Andric     loc_sp->SetQueueName(queue_name);
384*0b57cec5SDimitry Andric   }
385*0b57cec5SDimitry Andric }
386*0b57cec5SDimitry Andric 
387*0b57cec5SDimitry Andric const char *SBBreakpointLocation::GetQueueName() const {
38804eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
389*0b57cec5SDimitry Andric 
390*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
391*0b57cec5SDimitry Andric   if (loc_sp) {
392*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
393*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
394bdd1243dSDimitry Andric     return loc_sp->GetQueueName();
395*0b57cec5SDimitry Andric   }
396*0b57cec5SDimitry Andric   return nullptr;
397*0b57cec5SDimitry Andric }
398*0b57cec5SDimitry Andric 
399*0b57cec5SDimitry Andric bool SBBreakpointLocation::IsResolved() {
40004eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
401*0b57cec5SDimitry Andric 
402*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
403*0b57cec5SDimitry Andric   if (loc_sp) {
404*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
405*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
406*0b57cec5SDimitry Andric     return loc_sp->IsResolved();
407*0b57cec5SDimitry Andric   }
408*0b57cec5SDimitry Andric   return false;
409*0b57cec5SDimitry Andric }
410*0b57cec5SDimitry Andric 
411*0b57cec5SDimitry Andric void SBBreakpointLocation::SetLocation(
412*0b57cec5SDimitry Andric     const lldb::BreakpointLocationSP &break_loc_sp) {
413*0b57cec5SDimitry Andric   // Uninstall the callbacks?
414*0b57cec5SDimitry Andric   m_opaque_wp = break_loc_sp;
415*0b57cec5SDimitry Andric }
416*0b57cec5SDimitry Andric 
417*0b57cec5SDimitry Andric bool SBBreakpointLocation::GetDescription(SBStream &description,
418*0b57cec5SDimitry Andric                                           DescriptionLevel level) {
41904eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, description, level);
420*0b57cec5SDimitry Andric 
421*0b57cec5SDimitry Andric   Stream &strm = description.ref();
422*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
423*0b57cec5SDimitry Andric 
424*0b57cec5SDimitry Andric   if (loc_sp) {
425*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
426*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
427*0b57cec5SDimitry Andric     loc_sp->GetDescription(&strm, level);
428*0b57cec5SDimitry Andric     strm.EOL();
429*0b57cec5SDimitry Andric   } else
430*0b57cec5SDimitry Andric     strm.PutCString("No value");
431*0b57cec5SDimitry Andric 
432*0b57cec5SDimitry Andric   return true;
433*0b57cec5SDimitry Andric }
434*0b57cec5SDimitry Andric 
435*0b57cec5SDimitry Andric break_id_t SBBreakpointLocation::GetID() {
43604eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
437*0b57cec5SDimitry Andric 
438*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
439*0b57cec5SDimitry Andric   if (loc_sp) {
440*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
441*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
442*0b57cec5SDimitry Andric     return loc_sp->GetID();
443*0b57cec5SDimitry Andric   } else
444*0b57cec5SDimitry Andric     return LLDB_INVALID_BREAK_ID;
445*0b57cec5SDimitry Andric }
446*0b57cec5SDimitry Andric 
447*0b57cec5SDimitry Andric SBBreakpoint SBBreakpointLocation::GetBreakpoint() {
44804eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
449*0b57cec5SDimitry Andric 
450*0b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
451*0b57cec5SDimitry Andric 
452*0b57cec5SDimitry Andric   SBBreakpoint sb_bp;
453*0b57cec5SDimitry Andric   if (loc_sp) {
454*0b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
455*0b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
456*0b57cec5SDimitry Andric     sb_bp = loc_sp->GetBreakpoint().shared_from_this();
457*0b57cec5SDimitry Andric   }
458*0b57cec5SDimitry Andric 
45904eeddc0SDimitry Andric   return sb_bp;
460*0b57cec5SDimitry Andric }
461