15ffd83dbSDimitry Andric //===-- SBBreakpointLocation.cpp ------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "lldb/API/SBBreakpointLocation.h"
100b57cec5SDimitry Andric #include "lldb/API/SBAddress.h"
110b57cec5SDimitry Andric #include "lldb/API/SBDebugger.h"
120b57cec5SDimitry Andric #include "lldb/API/SBDefines.h"
130b57cec5SDimitry Andric #include "lldb/API/SBStream.h"
140b57cec5SDimitry Andric #include "lldb/API/SBStringList.h"
1504eeddc0SDimitry Andric #include "lldb/API/SBStructuredData.h"
1604eeddc0SDimitry Andric #include "lldb/Utility/Instrumentation.h"
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric #include "lldb/Breakpoint/Breakpoint.h"
190b57cec5SDimitry Andric #include "lldb/Breakpoint/BreakpointLocation.h"
200b57cec5SDimitry Andric #include "lldb/Core/Debugger.h"
21480093f4SDimitry Andric #include "lldb/Core/StructuredDataImpl.h"
220b57cec5SDimitry Andric #include "lldb/Interpreter/CommandInterpreter.h"
230b57cec5SDimitry Andric #include "lldb/Interpreter/ScriptInterpreter.h"
240b57cec5SDimitry Andric #include "lldb/Target/Target.h"
250b57cec5SDimitry Andric #include "lldb/Target/ThreadSpec.h"
260b57cec5SDimitry Andric #include "lldb/Utility/Stream.h"
270b57cec5SDimitry Andric #include "lldb/lldb-defines.h"
280b57cec5SDimitry Andric #include "lldb/lldb-types.h"
290b57cec5SDimitry Andric 
30bdd1243dSDimitry Andric #include "SBBreakpointOptionCommon.h"
31bdd1243dSDimitry Andric 
320b57cec5SDimitry Andric using namespace lldb;
330b57cec5SDimitry Andric using namespace lldb_private;
340b57cec5SDimitry Andric 
SBBreakpointLocation()3504eeddc0SDimitry Andric SBBreakpointLocation::SBBreakpointLocation() { LLDB_INSTRUMENT_VA(this); }
360b57cec5SDimitry Andric 
SBBreakpointLocation(const lldb::BreakpointLocationSP & break_loc_sp)370b57cec5SDimitry Andric SBBreakpointLocation::SBBreakpointLocation(
380b57cec5SDimitry Andric     const lldb::BreakpointLocationSP &break_loc_sp)
390b57cec5SDimitry Andric     : m_opaque_wp(break_loc_sp) {
4004eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, break_loc_sp);
410b57cec5SDimitry Andric }
420b57cec5SDimitry Andric 
SBBreakpointLocation(const SBBreakpointLocation & rhs)430b57cec5SDimitry Andric SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs)
440b57cec5SDimitry Andric     : m_opaque_wp(rhs.m_opaque_wp) {
4504eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, rhs);
460b57cec5SDimitry Andric }
470b57cec5SDimitry Andric 
480b57cec5SDimitry Andric const SBBreakpointLocation &SBBreakpointLocation::
operator =(const SBBreakpointLocation & rhs)490b57cec5SDimitry Andric operator=(const SBBreakpointLocation &rhs) {
5004eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, rhs);
510b57cec5SDimitry Andric 
520b57cec5SDimitry Andric   m_opaque_wp = rhs.m_opaque_wp;
5304eeddc0SDimitry Andric   return *this;
540b57cec5SDimitry Andric }
550b57cec5SDimitry Andric 
565ffd83dbSDimitry Andric SBBreakpointLocation::~SBBreakpointLocation() = default;
570b57cec5SDimitry Andric 
GetSP() const580b57cec5SDimitry Andric BreakpointLocationSP SBBreakpointLocation::GetSP() const {
590b57cec5SDimitry Andric   return m_opaque_wp.lock();
600b57cec5SDimitry Andric }
610b57cec5SDimitry Andric 
IsValid() const620b57cec5SDimitry Andric bool SBBreakpointLocation::IsValid() const {
6304eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
640b57cec5SDimitry Andric   return this->operator bool();
650b57cec5SDimitry Andric }
operator bool() const660b57cec5SDimitry Andric SBBreakpointLocation::operator bool() const {
6704eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
680b57cec5SDimitry Andric 
690b57cec5SDimitry Andric   return bool(GetSP());
700b57cec5SDimitry Andric }
710b57cec5SDimitry Andric 
GetAddress()720b57cec5SDimitry Andric SBAddress SBBreakpointLocation::GetAddress() {
7304eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
740b57cec5SDimitry Andric 
750b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
760b57cec5SDimitry Andric   if (loc_sp) {
7704eeddc0SDimitry Andric     return SBAddress(loc_sp->GetAddress());
780b57cec5SDimitry Andric   }
790b57cec5SDimitry Andric 
8004eeddc0SDimitry Andric   return SBAddress();
810b57cec5SDimitry Andric }
820b57cec5SDimitry Andric 
GetLoadAddress()830b57cec5SDimitry Andric addr_t SBBreakpointLocation::GetLoadAddress() {
8404eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
850b57cec5SDimitry Andric 
860b57cec5SDimitry Andric   addr_t ret_addr = LLDB_INVALID_ADDRESS;
870b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
880b57cec5SDimitry Andric 
890b57cec5SDimitry Andric   if (loc_sp) {
900b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
910b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
920b57cec5SDimitry Andric     ret_addr = loc_sp->GetLoadAddress();
930b57cec5SDimitry Andric   }
940b57cec5SDimitry Andric 
950b57cec5SDimitry Andric   return ret_addr;
960b57cec5SDimitry Andric }
970b57cec5SDimitry Andric 
SetEnabled(bool enabled)980b57cec5SDimitry Andric void SBBreakpointLocation::SetEnabled(bool enabled) {
9904eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, enabled);
1000b57cec5SDimitry Andric 
1010b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
1020b57cec5SDimitry Andric   if (loc_sp) {
1030b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
1040b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
1050b57cec5SDimitry Andric     loc_sp->SetEnabled(enabled);
1060b57cec5SDimitry Andric   }
1070b57cec5SDimitry Andric }
1080b57cec5SDimitry Andric 
IsEnabled()1090b57cec5SDimitry Andric bool SBBreakpointLocation::IsEnabled() {
11004eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
1110b57cec5SDimitry Andric 
1120b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
1130b57cec5SDimitry Andric   if (loc_sp) {
1140b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
1150b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
1160b57cec5SDimitry Andric     return loc_sp->IsEnabled();
1170b57cec5SDimitry Andric   } else
1180b57cec5SDimitry Andric     return false;
1190b57cec5SDimitry Andric }
1200b57cec5SDimitry Andric 
GetHitCount()1210b57cec5SDimitry Andric uint32_t SBBreakpointLocation::GetHitCount() {
12204eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
1230b57cec5SDimitry Andric 
1240b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
1250b57cec5SDimitry Andric   if (loc_sp) {
1260b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
1270b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
1280b57cec5SDimitry Andric     return loc_sp->GetHitCount();
1290b57cec5SDimitry Andric   } else
1300b57cec5SDimitry Andric     return 0;
1310b57cec5SDimitry Andric }
1320b57cec5SDimitry Andric 
GetIgnoreCount()1330b57cec5SDimitry Andric uint32_t SBBreakpointLocation::GetIgnoreCount() {
13404eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
1350b57cec5SDimitry Andric 
1360b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
1370b57cec5SDimitry Andric   if (loc_sp) {
1380b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
1390b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
1400b57cec5SDimitry Andric     return loc_sp->GetIgnoreCount();
1410b57cec5SDimitry Andric   } else
1420b57cec5SDimitry Andric     return 0;
1430b57cec5SDimitry Andric }
1440b57cec5SDimitry Andric 
SetIgnoreCount(uint32_t n)1450b57cec5SDimitry Andric void SBBreakpointLocation::SetIgnoreCount(uint32_t n) {
14604eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, n);
1470b57cec5SDimitry Andric 
1480b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
1490b57cec5SDimitry Andric   if (loc_sp) {
1500b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
1510b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
1520b57cec5SDimitry Andric     loc_sp->SetIgnoreCount(n);
1530b57cec5SDimitry Andric   }
1540b57cec5SDimitry Andric }
1550b57cec5SDimitry Andric 
SetCondition(const char * condition)1560b57cec5SDimitry Andric void SBBreakpointLocation::SetCondition(const char *condition) {
15704eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, condition);
1580b57cec5SDimitry Andric 
1590b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
1600b57cec5SDimitry Andric   if (loc_sp) {
1610b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
1620b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
1630b57cec5SDimitry Andric     loc_sp->SetCondition(condition);
1640b57cec5SDimitry Andric   }
1650b57cec5SDimitry Andric }
1660b57cec5SDimitry Andric 
GetCondition()1670b57cec5SDimitry Andric const char *SBBreakpointLocation::GetCondition() {
16804eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
1690b57cec5SDimitry Andric 
1700b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
171*fe013be4SDimitry Andric   if (!loc_sp)
172*fe013be4SDimitry Andric     return nullptr;
173*fe013be4SDimitry Andric 
1740b57cec5SDimitry Andric   std::lock_guard<std::recursive_mutex> guard(
1750b57cec5SDimitry Andric       loc_sp->GetTarget().GetAPIMutex());
176*fe013be4SDimitry Andric   return ConstString(loc_sp->GetConditionText()).GetCString();
1770b57cec5SDimitry Andric }
1780b57cec5SDimitry Andric 
SetAutoContinue(bool auto_continue)1790b57cec5SDimitry Andric void SBBreakpointLocation::SetAutoContinue(bool auto_continue) {
18004eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, auto_continue);
1810b57cec5SDimitry Andric 
1820b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
1830b57cec5SDimitry Andric   if (loc_sp) {
1840b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
1850b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
1860b57cec5SDimitry Andric     loc_sp->SetAutoContinue(auto_continue);
1870b57cec5SDimitry Andric   }
1880b57cec5SDimitry Andric }
1890b57cec5SDimitry Andric 
GetAutoContinue()1900b57cec5SDimitry Andric bool SBBreakpointLocation::GetAutoContinue() {
19104eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
1920b57cec5SDimitry Andric 
1930b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
1940b57cec5SDimitry Andric   if (loc_sp) {
1950b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
1960b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
1970b57cec5SDimitry Andric     return loc_sp->IsAutoContinue();
1980b57cec5SDimitry Andric   }
1990b57cec5SDimitry Andric   return false;
2000b57cec5SDimitry Andric }
2010b57cec5SDimitry Andric 
SetCallback(SBBreakpointHitCallback callback,void * baton)202bdd1243dSDimitry Andric void SBBreakpointLocation::SetCallback(SBBreakpointHitCallback callback,
203bdd1243dSDimitry Andric                                        void *baton) {
204bdd1243dSDimitry Andric   LLDB_INSTRUMENT_VA(this, callback, baton);
205bdd1243dSDimitry Andric 
206bdd1243dSDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
207bdd1243dSDimitry Andric 
208bdd1243dSDimitry Andric   if (loc_sp) {
209bdd1243dSDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
210bdd1243dSDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
211bdd1243dSDimitry Andric     BatonSP baton_sp(new SBBreakpointCallbackBaton(callback, baton));
212bdd1243dSDimitry Andric     loc_sp->SetCallback(SBBreakpointCallbackBaton::PrivateBreakpointHitCallback,
213bdd1243dSDimitry Andric                         baton_sp, false);
214bdd1243dSDimitry Andric   }
215bdd1243dSDimitry Andric }
216bdd1243dSDimitry Andric 
SetScriptCallbackFunction(const char * callback_function_name)2170b57cec5SDimitry Andric void SBBreakpointLocation::SetScriptCallbackFunction(
2180b57cec5SDimitry Andric   const char *callback_function_name) {
21904eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, callback_function_name);
220480093f4SDimitry Andric }
2210b57cec5SDimitry Andric 
SetScriptCallbackFunction(const char * callback_function_name,SBStructuredData & extra_args)222480093f4SDimitry Andric SBError SBBreakpointLocation::SetScriptCallbackFunction(
223480093f4SDimitry Andric     const char *callback_function_name,
224480093f4SDimitry Andric     SBStructuredData &extra_args) {
22504eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, callback_function_name, extra_args);
226480093f4SDimitry Andric   SBError sb_error;
2270b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
2280b57cec5SDimitry Andric 
2290b57cec5SDimitry Andric   if (loc_sp) {
230480093f4SDimitry Andric     Status error;
2310b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
2320b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
233fe6060f1SDimitry Andric     BreakpointOptions &bp_options = loc_sp->GetLocationOptions();
234480093f4SDimitry Andric     error = loc_sp->GetBreakpoint()
2350b57cec5SDimitry Andric         .GetTarget()
2360b57cec5SDimitry Andric         .GetDebugger()
2370b57cec5SDimitry Andric         .GetScriptInterpreter()
2380b57cec5SDimitry Andric         ->SetBreakpointCommandCallbackFunction(bp_options,
239480093f4SDimitry Andric                                                callback_function_name,
240480093f4SDimitry Andric                                                extra_args.m_impl_up
241480093f4SDimitry Andric                                                    ->GetObjectSP());
242480093f4SDimitry Andric       sb_error.SetError(error);
243480093f4SDimitry Andric     } else
244480093f4SDimitry Andric       sb_error.SetErrorString("invalid breakpoint");
245480093f4SDimitry Andric 
24604eeddc0SDimitry Andric     return sb_error;
2470b57cec5SDimitry Andric }
2480b57cec5SDimitry Andric 
2490b57cec5SDimitry Andric SBError
SetScriptCallbackBody(const char * callback_body_text)2500b57cec5SDimitry Andric SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) {
25104eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, callback_body_text);
2520b57cec5SDimitry Andric 
2530b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
2540b57cec5SDimitry Andric 
2550b57cec5SDimitry Andric   SBError sb_error;
2560b57cec5SDimitry Andric   if (loc_sp) {
2570b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
2580b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
259fe6060f1SDimitry Andric     BreakpointOptions &bp_options = loc_sp->GetLocationOptions();
2600b57cec5SDimitry Andric     Status error =
2610b57cec5SDimitry Andric         loc_sp->GetBreakpoint()
2620b57cec5SDimitry Andric             .GetTarget()
2630b57cec5SDimitry Andric             .GetDebugger()
2640b57cec5SDimitry Andric             .GetScriptInterpreter()
265*fe013be4SDimitry Andric             ->SetBreakpointCommandCallback(bp_options, callback_body_text,
266*fe013be4SDimitry Andric                                            /*is_callback=*/false);
2670b57cec5SDimitry Andric     sb_error.SetError(error);
2680b57cec5SDimitry Andric   } else
2690b57cec5SDimitry Andric     sb_error.SetErrorString("invalid breakpoint");
2700b57cec5SDimitry Andric 
27104eeddc0SDimitry Andric   return sb_error;
2720b57cec5SDimitry Andric }
2730b57cec5SDimitry Andric 
SetCommandLineCommands(SBStringList & commands)2740b57cec5SDimitry Andric void SBBreakpointLocation::SetCommandLineCommands(SBStringList &commands) {
27504eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, commands);
2760b57cec5SDimitry Andric 
2770b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
2780b57cec5SDimitry Andric   if (!loc_sp)
2790b57cec5SDimitry Andric     return;
2800b57cec5SDimitry Andric   if (commands.GetSize() == 0)
2810b57cec5SDimitry Andric     return;
2820b57cec5SDimitry Andric 
2830b57cec5SDimitry Andric   std::lock_guard<std::recursive_mutex> guard(
2840b57cec5SDimitry Andric       loc_sp->GetTarget().GetAPIMutex());
2850b57cec5SDimitry Andric   std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
2860b57cec5SDimitry Andric       new BreakpointOptions::CommandData(*commands, eScriptLanguageNone));
2870b57cec5SDimitry Andric 
288fe6060f1SDimitry Andric   loc_sp->GetLocationOptions().SetCommandDataCallback(cmd_data_up);
2890b57cec5SDimitry Andric }
2900b57cec5SDimitry Andric 
GetCommandLineCommands(SBStringList & commands)2910b57cec5SDimitry Andric bool SBBreakpointLocation::GetCommandLineCommands(SBStringList &commands) {
29204eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, commands);
2930b57cec5SDimitry Andric 
2940b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
2950b57cec5SDimitry Andric   if (!loc_sp)
2960b57cec5SDimitry Andric     return false;
2970b57cec5SDimitry Andric   StringList command_list;
2980b57cec5SDimitry Andric   bool has_commands =
299fe6060f1SDimitry Andric       loc_sp->GetLocationOptions().GetCommandLineCallbacks(command_list);
3000b57cec5SDimitry Andric   if (has_commands)
3010b57cec5SDimitry Andric     commands.AppendList(command_list);
3020b57cec5SDimitry Andric   return has_commands;
3030b57cec5SDimitry Andric }
3040b57cec5SDimitry Andric 
SetThreadID(tid_t thread_id)3050b57cec5SDimitry Andric void SBBreakpointLocation::SetThreadID(tid_t thread_id) {
30604eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, thread_id);
3070b57cec5SDimitry Andric 
3080b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
3090b57cec5SDimitry Andric   if (loc_sp) {
3100b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
3110b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
3120b57cec5SDimitry Andric     loc_sp->SetThreadID(thread_id);
3130b57cec5SDimitry Andric   }
3140b57cec5SDimitry Andric }
3150b57cec5SDimitry Andric 
GetThreadID()3160b57cec5SDimitry Andric tid_t SBBreakpointLocation::GetThreadID() {
31704eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
3180b57cec5SDimitry Andric 
3190b57cec5SDimitry Andric   tid_t tid = LLDB_INVALID_THREAD_ID;
3200b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
3210b57cec5SDimitry Andric   if (loc_sp) {
3220b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
3230b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
3240b57cec5SDimitry Andric     return loc_sp->GetThreadID();
3250b57cec5SDimitry Andric   }
3260b57cec5SDimitry Andric   return tid;
3270b57cec5SDimitry Andric }
3280b57cec5SDimitry Andric 
SetThreadIndex(uint32_t index)3290b57cec5SDimitry Andric void SBBreakpointLocation::SetThreadIndex(uint32_t index) {
33004eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, index);
3310b57cec5SDimitry Andric 
3320b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
3330b57cec5SDimitry Andric   if (loc_sp) {
3340b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
3350b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
3360b57cec5SDimitry Andric     loc_sp->SetThreadIndex(index);
3370b57cec5SDimitry Andric   }
3380b57cec5SDimitry Andric }
3390b57cec5SDimitry Andric 
GetThreadIndex() const3400b57cec5SDimitry Andric uint32_t SBBreakpointLocation::GetThreadIndex() const {
34104eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
3420b57cec5SDimitry Andric 
3430b57cec5SDimitry Andric   uint32_t thread_idx = UINT32_MAX;
3440b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
3450b57cec5SDimitry Andric   if (loc_sp) {
3460b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
3470b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
3480b57cec5SDimitry Andric     return loc_sp->GetThreadIndex();
3490b57cec5SDimitry Andric   }
3500b57cec5SDimitry Andric   return thread_idx;
3510b57cec5SDimitry Andric }
3520b57cec5SDimitry Andric 
SetThreadName(const char * thread_name)3530b57cec5SDimitry Andric void SBBreakpointLocation::SetThreadName(const char *thread_name) {
35404eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, thread_name);
3550b57cec5SDimitry Andric 
3560b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
3570b57cec5SDimitry Andric   if (loc_sp) {
3580b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
3590b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
3600b57cec5SDimitry Andric     loc_sp->SetThreadName(thread_name);
3610b57cec5SDimitry Andric   }
3620b57cec5SDimitry Andric }
3630b57cec5SDimitry Andric 
GetThreadName() const3640b57cec5SDimitry Andric const char *SBBreakpointLocation::GetThreadName() const {
36504eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
3660b57cec5SDimitry Andric 
3670b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
368*fe013be4SDimitry Andric   if (!loc_sp)
369*fe013be4SDimitry Andric     return nullptr;
370*fe013be4SDimitry Andric 
3710b57cec5SDimitry Andric   std::lock_guard<std::recursive_mutex> guard(
3720b57cec5SDimitry Andric       loc_sp->GetTarget().GetAPIMutex());
373*fe013be4SDimitry Andric   return ConstString(loc_sp->GetThreadName()).GetCString();
3740b57cec5SDimitry Andric }
3750b57cec5SDimitry Andric 
SetQueueName(const char * queue_name)3760b57cec5SDimitry Andric void SBBreakpointLocation::SetQueueName(const char *queue_name) {
37704eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, queue_name);
3780b57cec5SDimitry Andric 
3790b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
3800b57cec5SDimitry Andric   if (loc_sp) {
3810b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
3820b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
3830b57cec5SDimitry Andric     loc_sp->SetQueueName(queue_name);
3840b57cec5SDimitry Andric   }
3850b57cec5SDimitry Andric }
3860b57cec5SDimitry Andric 
GetQueueName() const3870b57cec5SDimitry Andric const char *SBBreakpointLocation::GetQueueName() const {
38804eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
3890b57cec5SDimitry Andric 
3900b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
391*fe013be4SDimitry Andric   if (!loc_sp)
392*fe013be4SDimitry Andric     return nullptr;
393*fe013be4SDimitry Andric 
3940b57cec5SDimitry Andric   std::lock_guard<std::recursive_mutex> guard(
3950b57cec5SDimitry Andric       loc_sp->GetTarget().GetAPIMutex());
396*fe013be4SDimitry Andric   return ConstString(loc_sp->GetQueueName()).GetCString();
3970b57cec5SDimitry Andric }
3980b57cec5SDimitry Andric 
IsResolved()3990b57cec5SDimitry Andric bool SBBreakpointLocation::IsResolved() {
40004eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
4010b57cec5SDimitry Andric 
4020b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
4030b57cec5SDimitry Andric   if (loc_sp) {
4040b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
4050b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
4060b57cec5SDimitry Andric     return loc_sp->IsResolved();
4070b57cec5SDimitry Andric   }
4080b57cec5SDimitry Andric   return false;
4090b57cec5SDimitry Andric }
4100b57cec5SDimitry Andric 
SetLocation(const lldb::BreakpointLocationSP & break_loc_sp)4110b57cec5SDimitry Andric void SBBreakpointLocation::SetLocation(
4120b57cec5SDimitry Andric     const lldb::BreakpointLocationSP &break_loc_sp) {
4130b57cec5SDimitry Andric   // Uninstall the callbacks?
4140b57cec5SDimitry Andric   m_opaque_wp = break_loc_sp;
4150b57cec5SDimitry Andric }
4160b57cec5SDimitry Andric 
GetDescription(SBStream & description,DescriptionLevel level)4170b57cec5SDimitry Andric bool SBBreakpointLocation::GetDescription(SBStream &description,
4180b57cec5SDimitry Andric                                           DescriptionLevel level) {
41904eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, description, level);
4200b57cec5SDimitry Andric 
4210b57cec5SDimitry Andric   Stream &strm = description.ref();
4220b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
4230b57cec5SDimitry Andric 
4240b57cec5SDimitry Andric   if (loc_sp) {
4250b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
4260b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
4270b57cec5SDimitry Andric     loc_sp->GetDescription(&strm, level);
4280b57cec5SDimitry Andric     strm.EOL();
4290b57cec5SDimitry Andric   } else
4300b57cec5SDimitry Andric     strm.PutCString("No value");
4310b57cec5SDimitry Andric 
4320b57cec5SDimitry Andric   return true;
4330b57cec5SDimitry Andric }
4340b57cec5SDimitry Andric 
GetID()4350b57cec5SDimitry Andric break_id_t SBBreakpointLocation::GetID() {
43604eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
4370b57cec5SDimitry Andric 
4380b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
4390b57cec5SDimitry Andric   if (loc_sp) {
4400b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
4410b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
4420b57cec5SDimitry Andric     return loc_sp->GetID();
4430b57cec5SDimitry Andric   } else
4440b57cec5SDimitry Andric     return LLDB_INVALID_BREAK_ID;
4450b57cec5SDimitry Andric }
4460b57cec5SDimitry Andric 
GetBreakpoint()4470b57cec5SDimitry Andric SBBreakpoint SBBreakpointLocation::GetBreakpoint() {
44804eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
4490b57cec5SDimitry Andric 
4500b57cec5SDimitry Andric   BreakpointLocationSP loc_sp = GetSP();
4510b57cec5SDimitry Andric 
4520b57cec5SDimitry Andric   SBBreakpoint sb_bp;
4530b57cec5SDimitry Andric   if (loc_sp) {
4540b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(
4550b57cec5SDimitry Andric         loc_sp->GetTarget().GetAPIMutex());
4560b57cec5SDimitry Andric     sb_bp = loc_sp->GetBreakpoint().shared_from_this();
4570b57cec5SDimitry Andric   }
4580b57cec5SDimitry Andric 
45904eeddc0SDimitry Andric   return sb_bp;
4600b57cec5SDimitry Andric }
461