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