180814287SRaphael Isemann //===-- SBBreakpoint.cpp --------------------------------------------------===//
230fdc8d8SChris Lattner //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
630fdc8d8SChris Lattner //
730fdc8d8SChris Lattner //===----------------------------------------------------------------------===//
830fdc8d8SChris Lattner
930fdc8d8SChris Lattner #include "lldb/API/SBBreakpoint.h"
1030fdc8d8SChris Lattner #include "lldb/API/SBBreakpointLocation.h"
1130fdc8d8SChris Lattner #include "lldb/API/SBDebugger.h"
129fed0d85SGreg Clayton #include "lldb/API/SBEvent.h"
1330fdc8d8SChris Lattner #include "lldb/API/SBProcess.h"
14dde9cff3SCaroline Tice #include "lldb/API/SBStream.h"
155e09c8c3SJim Ingham #include "lldb/API/SBStringList.h"
16738af7a6SJim Ingham #include "lldb/API/SBStructuredData.h"
1730fdc8d8SChris Lattner #include "lldb/API/SBThread.h"
181755f5b1SJonas Devlieghere #include "lldb/Utility/Instrumentation.h"
1930fdc8d8SChris Lattner
2030fdc8d8SChris Lattner #include "lldb/Breakpoint/Breakpoint.h"
2101f16664SJim Ingham #include "lldb/Breakpoint/BreakpointIDList.h"
2230fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointLocation.h"
233815e702SJim Ingham #include "lldb/Breakpoint/BreakpointResolver.h"
243815e702SJim Ingham #include "lldb/Breakpoint/BreakpointResolverScripted.h"
2530fdc8d8SChris Lattner #include "lldb/Breakpoint/StoppointCallbackContext.h"
2630fdc8d8SChris Lattner #include "lldb/Core/Address.h"
27d80102e4SJim Ingham #include "lldb/Core/Debugger.h"
2830fdc8d8SChris Lattner #include "lldb/Core/StreamFile.h"
29738af7a6SJim Ingham #include "lldb/Core/StructuredDataImpl.h"
30d80102e4SJim Ingham #include "lldb/Interpreter/CommandInterpreter.h"
31d80102e4SJim Ingham #include "lldb/Interpreter/ScriptInterpreter.h"
3230fdc8d8SChris Lattner #include "lldb/Target/Process.h"
33d5944cd1SGreg Clayton #include "lldb/Target/SectionLoadList.h"
3430fdc8d8SChris Lattner #include "lldb/Target/Target.h"
3562b02c61SJim Ingham #include "lldb/Target/Thread.h"
3662b02c61SJim Ingham #include "lldb/Target/ThreadSpec.h"
37bf9a7730SZachary Turner #include "lldb/Utility/Stream.h"
3830fdc8d8SChris Lattner
39b842f2ecSJim Ingham #include "SBBreakpointOptionCommon.h"
40b842f2ecSJim Ingham
4130fdc8d8SChris Lattner #include "lldb/lldb-enumerations.h"
4230fdc8d8SChris Lattner
434e4fbe82SZachary Turner #include "llvm/ADT/STLExtras.h"
444e4fbe82SZachary Turner
4530fdc8d8SChris Lattner using namespace lldb;
4630fdc8d8SChris Lattner using namespace lldb_private;
4730fdc8d8SChris Lattner
SBBreakpoint()481755f5b1SJonas Devlieghere SBBreakpoint::SBBreakpoint() { LLDB_INSTRUMENT_VA(this); }
4930fdc8d8SChris Lattner
SBBreakpoint(const SBBreakpoint & rhs)50b9c1b51eSKate Stone SBBreakpoint::SBBreakpoint(const SBBreakpoint &rhs)
51baf5664fSJonas Devlieghere : m_opaque_wp(rhs.m_opaque_wp) {
521755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, rhs);
53baf5664fSJonas Devlieghere }
5430fdc8d8SChris Lattner
SBBreakpoint(const lldb::BreakpointSP & bp_sp)55b9c1b51eSKate Stone SBBreakpoint::SBBreakpoint(const lldb::BreakpointSP &bp_sp)
56baf5664fSJonas Devlieghere : m_opaque_wp(bp_sp) {
571755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, bp_sp);
58baf5664fSJonas Devlieghere }
5930fdc8d8SChris Lattner
60dbb0abbfSEugene Zelenko SBBreakpoint::~SBBreakpoint() = default;
6130fdc8d8SChris Lattner
operator =(const SBBreakpoint & rhs)62b9c1b51eSKate Stone const SBBreakpoint &SBBreakpoint::operator=(const SBBreakpoint &rhs) {
631755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, rhs);
64baf5664fSJonas Devlieghere
656ac84034SPavel Labath m_opaque_wp = rhs.m_opaque_wp;
66d232abc3SJonas Devlieghere return *this;
6730fdc8d8SChris Lattner }
6830fdc8d8SChris Lattner
operator ==(const lldb::SBBreakpoint & rhs)69b9c1b51eSKate Stone bool SBBreakpoint::operator==(const lldb::SBBreakpoint &rhs) {
701755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, rhs);
71baf5664fSJonas Devlieghere
726ac84034SPavel Labath return m_opaque_wp.lock() == rhs.m_opaque_wp.lock();
73ac2eb9b1SGreg Clayton }
74ac2eb9b1SGreg Clayton
operator !=(const lldb::SBBreakpoint & rhs)75b9c1b51eSKate Stone bool SBBreakpoint::operator!=(const lldb::SBBreakpoint &rhs) {
761755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, rhs);
77baf5664fSJonas Devlieghere
786ac84034SPavel Labath return m_opaque_wp.lock() != rhs.m_opaque_wp.lock();
79c3387333SEnrico Granata }
80c3387333SEnrico Granata
GetTarget() const816754caa9SJim Ingham SBTarget SBBreakpoint::GetTarget() const {
821755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
836754caa9SJim Ingham
846754caa9SJim Ingham BreakpointSP bkpt_sp = GetSP();
856754caa9SJim Ingham if (bkpt_sp)
86d232abc3SJonas Devlieghere return SBTarget(bkpt_sp->GetTargetSP());
876754caa9SJim Ingham
88d232abc3SJonas Devlieghere return SBTarget();
896754caa9SJim Ingham }
906754caa9SJim Ingham
GetID() const91b9c1b51eSKate Stone break_id_t SBBreakpoint::GetID() const {
921755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
93baf5664fSJonas Devlieghere
94af67cecdSGreg Clayton break_id_t break_id = LLDB_INVALID_BREAK_ID;
956ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
966ac84034SPavel Labath if (bkpt_sp)
976ac84034SPavel Labath break_id = bkpt_sp->GetID();
98af67cecdSGreg Clayton
99af67cecdSGreg Clayton return break_id;
10030fdc8d8SChris Lattner }
10130fdc8d8SChris Lattner
IsValid() const102b9c1b51eSKate Stone bool SBBreakpoint::IsValid() const {
1031755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
1047f5237bcSPavel Labath return this->operator bool();
1057f5237bcSPavel Labath }
operator bool() const1067f5237bcSPavel Labath SBBreakpoint::operator bool() const {
1071755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
108baf5664fSJonas Devlieghere
1096ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
1106ac84034SPavel Labath if (!bkpt_sp)
111e029fa57SJim Ingham return false;
1126ac84034SPavel Labath else if (bkpt_sp->GetTarget().GetBreakpointByID(bkpt_sp->GetID()))
113e029fa57SJim Ingham return true;
114e029fa57SJim Ingham else
115e029fa57SJim Ingham return false;
11630fdc8d8SChris Lattner }
11730fdc8d8SChris Lattner
ClearAllBreakpointSites()118b9c1b51eSKate Stone void SBBreakpoint::ClearAllBreakpointSites() {
1191755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
120baf5664fSJonas Devlieghere
1216ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
1226ac84034SPavel Labath if (bkpt_sp) {
123b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
1246ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
1256ac84034SPavel Labath bkpt_sp->ClearAllBreakpointSites();
12630fdc8d8SChris Lattner }
127af67cecdSGreg Clayton }
12830fdc8d8SChris Lattner
FindLocationByAddress(addr_t vm_addr)129b9c1b51eSKate Stone SBBreakpointLocation SBBreakpoint::FindLocationByAddress(addr_t vm_addr) {
1301755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, vm_addr);
131baf5664fSJonas Devlieghere
13230fdc8d8SChris Lattner SBBreakpointLocation sb_bp_location;
13330fdc8d8SChris Lattner
1346ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
1356ac84034SPavel Labath if (bkpt_sp) {
136b9c1b51eSKate Stone if (vm_addr != LLDB_INVALID_ADDRESS) {
137b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
1386ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
13930fdc8d8SChris Lattner Address address;
1406ac84034SPavel Labath Target &target = bkpt_sp->GetTarget();
141b9c1b51eSKate Stone if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) {
142e72dfb32SGreg Clayton address.SetRawAddress(vm_addr);
14330fdc8d8SChris Lattner }
1446ac84034SPavel Labath sb_bp_location.SetLocation(bkpt_sp->FindLocationByAddress(address));
14530fdc8d8SChris Lattner }
14630fdc8d8SChris Lattner }
147d232abc3SJonas Devlieghere return sb_bp_location;
14830fdc8d8SChris Lattner }
14930fdc8d8SChris Lattner
FindLocationIDByAddress(addr_t vm_addr)150b9c1b51eSKate Stone break_id_t SBBreakpoint::FindLocationIDByAddress(addr_t vm_addr) {
1511755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, vm_addr);
152baf5664fSJonas Devlieghere
153af67cecdSGreg Clayton break_id_t break_id = LLDB_INVALID_BREAK_ID;
1546ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
15530fdc8d8SChris Lattner
1566ac84034SPavel Labath if (bkpt_sp && vm_addr != LLDB_INVALID_ADDRESS) {
157b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
1586ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
15930fdc8d8SChris Lattner Address address;
1606ac84034SPavel Labath Target &target = bkpt_sp->GetTarget();
161b9c1b51eSKate Stone if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) {
162e72dfb32SGreg Clayton address.SetRawAddress(vm_addr);
16330fdc8d8SChris Lattner }
1646ac84034SPavel Labath break_id = bkpt_sp->FindLocationIDByAddress(address);
16530fdc8d8SChris Lattner }
16630fdc8d8SChris Lattner
167af67cecdSGreg Clayton return break_id;
16830fdc8d8SChris Lattner }
16930fdc8d8SChris Lattner
FindLocationByID(break_id_t bp_loc_id)170b9c1b51eSKate Stone SBBreakpointLocation SBBreakpoint::FindLocationByID(break_id_t bp_loc_id) {
1711755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, bp_loc_id);
172baf5664fSJonas Devlieghere
17330fdc8d8SChris Lattner SBBreakpointLocation sb_bp_location;
1746ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
17530fdc8d8SChris Lattner
1766ac84034SPavel Labath if (bkpt_sp) {
177b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
1786ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
1796ac84034SPavel Labath sb_bp_location.SetLocation(bkpt_sp->FindLocationByID(bp_loc_id));
180af67cecdSGreg Clayton }
18130fdc8d8SChris Lattner
182d232abc3SJonas Devlieghere return sb_bp_location;
18330fdc8d8SChris Lattner }
18430fdc8d8SChris Lattner
GetLocationAtIndex(uint32_t index)185b9c1b51eSKate Stone SBBreakpointLocation SBBreakpoint::GetLocationAtIndex(uint32_t index) {
1861755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, index);
187baf5664fSJonas Devlieghere
18830fdc8d8SChris Lattner SBBreakpointLocation sb_bp_location;
1896ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
19030fdc8d8SChris Lattner
1916ac84034SPavel Labath if (bkpt_sp) {
192b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
1936ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
1946ac84034SPavel Labath sb_bp_location.SetLocation(bkpt_sp->GetLocationAtIndex(index));
195af67cecdSGreg Clayton }
19630fdc8d8SChris Lattner
197d232abc3SJonas Devlieghere return sb_bp_location;
19830fdc8d8SChris Lattner }
19930fdc8d8SChris Lattner
SetEnabled(bool enable)200b9c1b51eSKate Stone void SBBreakpoint::SetEnabled(bool enable) {
2011755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, enable);
202baf5664fSJonas Devlieghere
2036ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
204ceb6b139SCaroline Tice
2056ac84034SPavel Labath if (bkpt_sp) {
206b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
2076ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
2086ac84034SPavel Labath bkpt_sp->SetEnabled(enable);
20930fdc8d8SChris Lattner }
210af67cecdSGreg Clayton }
21130fdc8d8SChris Lattner
IsEnabled()212b9c1b51eSKate Stone bool SBBreakpoint::IsEnabled() {
2131755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
214baf5664fSJonas Devlieghere
2156ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
2166ac84034SPavel Labath if (bkpt_sp) {
217b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
2186ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
2196ac84034SPavel Labath return bkpt_sp->IsEnabled();
220b9c1b51eSKate Stone } else
22130fdc8d8SChris Lattner return false;
22230fdc8d8SChris Lattner }
22330fdc8d8SChris Lattner
SetOneShot(bool one_shot)224b9c1b51eSKate Stone void SBBreakpoint::SetOneShot(bool one_shot) {
2251755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, one_shot);
226baf5664fSJonas Devlieghere
2276ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
228ca36cd16SJim Ingham
2296ac84034SPavel Labath if (bkpt_sp) {
230b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
2316ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
2326ac84034SPavel Labath bkpt_sp->SetOneShot(one_shot);
233ca36cd16SJim Ingham }
234ca36cd16SJim Ingham }
235ca36cd16SJim Ingham
IsOneShot() const236b9c1b51eSKate Stone bool SBBreakpoint::IsOneShot() const {
2371755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
238baf5664fSJonas Devlieghere
2396ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
2406ac84034SPavel Labath if (bkpt_sp) {
241b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
2426ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
2436ac84034SPavel Labath return bkpt_sp->IsOneShot();
244b9c1b51eSKate Stone } else
245ca36cd16SJim Ingham return false;
246ca36cd16SJim Ingham }
247ca36cd16SJim Ingham
IsInternal()248b9c1b51eSKate Stone bool SBBreakpoint::IsInternal() {
2491755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
250baf5664fSJonas Devlieghere
2516ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
2526ac84034SPavel Labath if (bkpt_sp) {
253b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
2546ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
2556ac84034SPavel Labath return bkpt_sp->IsInternal();
256b9c1b51eSKate Stone } else
25711c8108dSJim Ingham return false;
25811c8108dSJim Ingham }
25911c8108dSJim Ingham
SetIgnoreCount(uint32_t count)260b9c1b51eSKate Stone void SBBreakpoint::SetIgnoreCount(uint32_t count) {
2611755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, count);
262baf5664fSJonas Devlieghere
2636ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
264ceb6b139SCaroline Tice
2656ac84034SPavel Labath if (bkpt_sp) {
266b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
2676ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
2686ac84034SPavel Labath bkpt_sp->SetIgnoreCount(count);
26930fdc8d8SChris Lattner }
270af67cecdSGreg Clayton }
27130fdc8d8SChris Lattner
SetCondition(const char * condition)272b9c1b51eSKate Stone void SBBreakpoint::SetCondition(const char *condition) {
2731755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, condition);
274baf5664fSJonas Devlieghere
2756ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
2766ac84034SPavel Labath if (bkpt_sp) {
277b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
2786ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
2796ac84034SPavel Labath bkpt_sp->SetCondition(condition);
280041a12fcSJim Ingham }
281af67cecdSGreg Clayton }
282041a12fcSJim Ingham
GetCondition()283b9c1b51eSKate Stone const char *SBBreakpoint::GetCondition() {
2841755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
285baf5664fSJonas Devlieghere
2866ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
2876ac84034SPavel Labath if (bkpt_sp) {
288b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
2896ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
2906ac84034SPavel Labath return bkpt_sp->GetConditionText();
291041a12fcSJim Ingham }
292dbb0abbfSEugene Zelenko return nullptr;
293af67cecdSGreg Clayton }
294041a12fcSJim Ingham
SetAutoContinue(bool auto_continue)295f08f5c99SJim Ingham void SBBreakpoint::SetAutoContinue(bool auto_continue) {
2961755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, auto_continue);
297baf5664fSJonas Devlieghere
298f08f5c99SJim Ingham BreakpointSP bkpt_sp = GetSP();
299f08f5c99SJim Ingham if (bkpt_sp) {
300f08f5c99SJim Ingham std::lock_guard<std::recursive_mutex> guard(
301f08f5c99SJim Ingham bkpt_sp->GetTarget().GetAPIMutex());
302f08f5c99SJim Ingham bkpt_sp->SetAutoContinue(auto_continue);
303f08f5c99SJim Ingham }
304f08f5c99SJim Ingham }
305f08f5c99SJim Ingham
GetAutoContinue()306f08f5c99SJim Ingham bool SBBreakpoint::GetAutoContinue() {
3071755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
308baf5664fSJonas Devlieghere
309f08f5c99SJim Ingham BreakpointSP bkpt_sp = GetSP();
310f08f5c99SJim Ingham if (bkpt_sp) {
311f08f5c99SJim Ingham std::lock_guard<std::recursive_mutex> guard(
312f08f5c99SJim Ingham bkpt_sp->GetTarget().GetAPIMutex());
313f08f5c99SJim Ingham return bkpt_sp->IsAutoContinue();
314f08f5c99SJim Ingham }
3151c7dc829SJim Ingham return false;
316f08f5c99SJim Ingham }
317f08f5c99SJim Ingham
GetHitCount() const318b9c1b51eSKate Stone uint32_t SBBreakpoint::GetHitCount() const {
3191755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
320baf5664fSJonas Devlieghere
3214838131bSGreg Clayton uint32_t count = 0;
3226ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
3236ac84034SPavel Labath if (bkpt_sp) {
324b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
3256ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
3266ac84034SPavel Labath count = bkpt_sp->GetHitCount();
327af67cecdSGreg Clayton }
3284838131bSGreg Clayton
3294838131bSGreg Clayton return count;
330ceb6b139SCaroline Tice }
3319fed0d85SGreg Clayton
GetIgnoreCount() const332b9c1b51eSKate Stone uint32_t SBBreakpoint::GetIgnoreCount() const {
3331755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
334baf5664fSJonas Devlieghere
3354838131bSGreg Clayton uint32_t count = 0;
3366ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
3376ac84034SPavel Labath if (bkpt_sp) {
338b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
3396ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
3406ac84034SPavel Labath count = bkpt_sp->GetIgnoreCount();
341af67cecdSGreg Clayton }
3424838131bSGreg Clayton
3434838131bSGreg Clayton return count;
34430fdc8d8SChris Lattner }
34530fdc8d8SChris Lattner
SetThreadID(tid_t tid)346b9c1b51eSKate Stone void SBBreakpoint::SetThreadID(tid_t tid) {
3471755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, tid);
348baf5664fSJonas Devlieghere
3496ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
3506ac84034SPavel Labath if (bkpt_sp) {
351b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
3526ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
3536ac84034SPavel Labath bkpt_sp->SetThreadID(tid);
354af67cecdSGreg Clayton }
35530fdc8d8SChris Lattner }
35630fdc8d8SChris Lattner
GetThreadID()357b9c1b51eSKate Stone tid_t SBBreakpoint::GetThreadID() {
3581755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
359baf5664fSJonas Devlieghere
3604838131bSGreg Clayton tid_t tid = LLDB_INVALID_THREAD_ID;
3616ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
3626ac84034SPavel Labath if (bkpt_sp) {
363b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
3646ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
3656ac84034SPavel Labath tid = bkpt_sp->GetThreadID();
366af67cecdSGreg Clayton }
36730fdc8d8SChris Lattner
3684838131bSGreg Clayton return tid;
36930fdc8d8SChris Lattner }
37030fdc8d8SChris Lattner
SetThreadIndex(uint32_t index)371b9c1b51eSKate Stone void SBBreakpoint::SetThreadIndex(uint32_t index) {
3721755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, index);
373baf5664fSJonas Devlieghere
3746ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
3756ac84034SPavel Labath if (bkpt_sp) {
376b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
3776ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
378cfb96d84SJim Ingham bkpt_sp->GetOptions().GetThreadSpec()->SetIndex(index);
37962b02c61SJim Ingham }
380af67cecdSGreg Clayton }
38162b02c61SJim Ingham
GetThreadIndex() const382b9c1b51eSKate Stone uint32_t SBBreakpoint::GetThreadIndex() const {
3831755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
384baf5664fSJonas Devlieghere
385bdf4c6acSGreg Clayton uint32_t thread_idx = UINT32_MAX;
3866ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
3876ac84034SPavel Labath if (bkpt_sp) {
388b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
3896ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
390b9c1b51eSKate Stone const ThreadSpec *thread_spec =
391cfb96d84SJim Ingham bkpt_sp->GetOptions().GetThreadSpecNoCreate();
392dbb0abbfSEugene Zelenko if (thread_spec != nullptr)
3934838131bSGreg Clayton thread_idx = thread_spec->GetIndex();
39462b02c61SJim Ingham }
3954838131bSGreg Clayton
396763d1a17SJohnny Chen return thread_idx;
39762b02c61SJim Ingham }
39862b02c61SJim Ingham
SetThreadName(const char * thread_name)399b9c1b51eSKate Stone void SBBreakpoint::SetThreadName(const char *thread_name) {
4001755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, thread_name);
401baf5664fSJonas Devlieghere
4026ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
4034838131bSGreg Clayton
4046ac84034SPavel Labath if (bkpt_sp) {
405b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
4066ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
407cfb96d84SJim Ingham bkpt_sp->GetOptions().GetThreadSpec()->SetName(thread_name);
40862b02c61SJim Ingham }
409af67cecdSGreg Clayton }
41062b02c61SJim Ingham
GetThreadName() const411b9c1b51eSKate Stone const char *SBBreakpoint::GetThreadName() const {
4121755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
413baf5664fSJonas Devlieghere
414dbb0abbfSEugene Zelenko const char *name = nullptr;
4156ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
4166ac84034SPavel Labath if (bkpt_sp) {
417b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
4186ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
419b9c1b51eSKate Stone const ThreadSpec *thread_spec =
420cfb96d84SJim Ingham bkpt_sp->GetOptions().GetThreadSpecNoCreate();
421dbb0abbfSEugene Zelenko if (thread_spec != nullptr)
4224838131bSGreg Clayton name = thread_spec->GetName();
42362b02c61SJim Ingham }
4244838131bSGreg Clayton
4254838131bSGreg Clayton return name;
42662b02c61SJim Ingham }
42762b02c61SJim Ingham
SetQueueName(const char * queue_name)428b9c1b51eSKate Stone void SBBreakpoint::SetQueueName(const char *queue_name) {
4291755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, queue_name);
430baf5664fSJonas Devlieghere
4316ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
4326ac84034SPavel Labath if (bkpt_sp) {
433b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
4346ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
435cfb96d84SJim Ingham bkpt_sp->GetOptions().GetThreadSpec()->SetQueueName(queue_name);
43662b02c61SJim Ingham }
437af67cecdSGreg Clayton }
43862b02c61SJim Ingham
GetQueueName() const439b9c1b51eSKate Stone const char *SBBreakpoint::GetQueueName() const {
4401755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
441baf5664fSJonas Devlieghere
442dbb0abbfSEugene Zelenko const char *name = nullptr;
4436ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
4446ac84034SPavel Labath if (bkpt_sp) {
445b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
4466ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
447b9c1b51eSKate Stone const ThreadSpec *thread_spec =
448cfb96d84SJim Ingham bkpt_sp->GetOptions().GetThreadSpecNoCreate();
449af67cecdSGreg Clayton if (thread_spec)
4504838131bSGreg Clayton name = thread_spec->GetQueueName();
45162b02c61SJim Ingham }
4524838131bSGreg Clayton
4534838131bSGreg Clayton return name;
45462b02c61SJim Ingham }
45562b02c61SJim Ingham
GetNumResolvedLocations() const456b9c1b51eSKate Stone size_t SBBreakpoint::GetNumResolvedLocations() const {
4571755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
458baf5664fSJonas Devlieghere
4594838131bSGreg Clayton size_t num_resolved = 0;
4606ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
4616ac84034SPavel Labath if (bkpt_sp) {
462b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
4636ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
4646ac84034SPavel Labath num_resolved = bkpt_sp->GetNumResolvedLocations();
465af67cecdSGreg Clayton }
4664838131bSGreg Clayton return num_resolved;
46730fdc8d8SChris Lattner }
46830fdc8d8SChris Lattner
GetNumLocations() const469b9c1b51eSKate Stone size_t SBBreakpoint::GetNumLocations() const {
4701755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
471baf5664fSJonas Devlieghere
4726ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
4734838131bSGreg Clayton size_t num_locs = 0;
4746ac84034SPavel Labath if (bkpt_sp) {
475b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
4766ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
4776ac84034SPavel Labath num_locs = bkpt_sp->GetNumLocations();
478af67cecdSGreg Clayton }
4794838131bSGreg Clayton return num_locs;
48030fdc8d8SChris Lattner }
48130fdc8d8SChris Lattner
SetCommandLineCommands(SBStringList & commands)48292d1960eSJim Ingham void SBBreakpoint::SetCommandLineCommands(SBStringList &commands) {
4831755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, commands);
484baf5664fSJonas Devlieghere
4856ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
4866ac84034SPavel Labath if (!bkpt_sp)
48792d1960eSJim Ingham return;
48892d1960eSJim Ingham if (commands.GetSize() == 0)
48992d1960eSJim Ingham return;
49092d1960eSJim Ingham
49192d1960eSJim Ingham std::lock_guard<std::recursive_mutex> guard(
4926ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
49392d1960eSJim Ingham std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
494f7e07256SJim Ingham new BreakpointOptions::CommandData(*commands, eScriptLanguageNone));
49592d1960eSJim Ingham
496cfb96d84SJim Ingham bkpt_sp->GetOptions().SetCommandDataCallback(cmd_data_up);
49792d1960eSJim Ingham }
49892d1960eSJim Ingham
GetCommandLineCommands(SBStringList & commands)49992d1960eSJim Ingham bool SBBreakpoint::GetCommandLineCommands(SBStringList &commands) {
5001755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, commands);
501baf5664fSJonas Devlieghere
5026ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
5036ac84034SPavel Labath if (!bkpt_sp)
50492d1960eSJim Ingham return false;
50592d1960eSJim Ingham StringList command_list;
50692d1960eSJim Ingham bool has_commands =
507cfb96d84SJim Ingham bkpt_sp->GetOptions().GetCommandLineCallbacks(command_list);
50892d1960eSJim Ingham if (has_commands)
50992d1960eSJim Ingham commands.AppendList(command_list);
51092d1960eSJim Ingham return has_commands;
51192d1960eSJim Ingham }
51292d1960eSJim Ingham
GetDescription(SBStream & s)513b9c1b51eSKate Stone bool SBBreakpoint::GetDescription(SBStream &s) {
5141755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, s);
515baf5664fSJonas Devlieghere
5166d1e4696SJim Ingham return GetDescription(s, true);
5176d1e4696SJim Ingham }
5186d1e4696SJim Ingham
GetDescription(SBStream & s,bool include_locations)5196d1e4696SJim Ingham bool SBBreakpoint::GetDescription(SBStream &s, bool include_locations) {
5201755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, s, include_locations);
521baf5664fSJonas Devlieghere
5226ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
5236ac84034SPavel Labath if (bkpt_sp) {
524b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
5256ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
5266ac84034SPavel Labath s.Printf("SBBreakpoint: id = %i, ", bkpt_sp->GetID());
5276ac84034SPavel Labath bkpt_sp->GetResolverDescription(s.get());
5286ac84034SPavel Labath bkpt_sp->GetFilterDescription(s.get());
5296d1e4696SJim Ingham if (include_locations) {
5306ac84034SPavel Labath const size_t num_locations = bkpt_sp->GetNumLocations();
531d01b2953SDaniel Malea s.Printf(", locations = %" PRIu64, (uint64_t)num_locations);
5326d1e4696SJim Ingham }
533dde9cff3SCaroline Tice return true;
534dde9cff3SCaroline Tice }
53505faeb71SGreg Clayton s.Printf("No value");
53605faeb71SGreg Clayton return false;
53705faeb71SGreg Clayton }
538dde9cff3SCaroline Tice
AddLocation(SBAddress & address)539baf5664fSJonas Devlieghere SBError SBBreakpoint::AddLocation(SBAddress &address) {
5401755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, address);
541baf5664fSJonas Devlieghere
5423815e702SJim Ingham BreakpointSP bkpt_sp = GetSP();
5433815e702SJim Ingham SBError error;
5443815e702SJim Ingham
5453815e702SJim Ingham if (!address.IsValid()) {
5463815e702SJim Ingham error.SetErrorString("Can't add an invalid address.");
547d232abc3SJonas Devlieghere return error;
5483815e702SJim Ingham }
5493815e702SJim Ingham
5503815e702SJim Ingham if (!bkpt_sp) {
5513815e702SJim Ingham error.SetErrorString("No breakpoint to add a location to.");
552d232abc3SJonas Devlieghere return error;
5533815e702SJim Ingham }
5543815e702SJim Ingham
5553815e702SJim Ingham if (!llvm::isa<BreakpointResolverScripted>(bkpt_sp->GetResolver().get())) {
5563815e702SJim Ingham error.SetErrorString("Only a scripted resolver can add locations.");
557d232abc3SJonas Devlieghere return error;
5583815e702SJim Ingham }
5593815e702SJim Ingham
5603815e702SJim Ingham if (bkpt_sp->GetSearchFilter()->AddressPasses(address.ref()))
5613815e702SJim Ingham bkpt_sp->AddLocation(address.ref());
562baf5664fSJonas Devlieghere else {
5633815e702SJim Ingham StreamString s;
5643815e702SJim Ingham address.get()->Dump(&s, &bkpt_sp->GetTarget(),
5653815e702SJim Ingham Address::DumpStyleModuleWithFileAddress);
5663815e702SJim Ingham error.SetErrorStringWithFormat("Address: %s didn't pass the filter.",
5673815e702SJim Ingham s.GetData());
5683815e702SJim Ingham }
569d232abc3SJonas Devlieghere return error;
5703815e702SJim Ingham }
5713815e702SJim Ingham
SerializeToStructuredData()5724da8fa45SMed Ismail Bennani SBStructuredData SBBreakpoint::SerializeToStructuredData() {
5731755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
5744da8fa45SMed Ismail Bennani
5754da8fa45SMed Ismail Bennani SBStructuredData data;
5764da8fa45SMed Ismail Bennani BreakpointSP bkpt_sp = GetSP();
5774da8fa45SMed Ismail Bennani
5784da8fa45SMed Ismail Bennani if (!bkpt_sp)
579d232abc3SJonas Devlieghere return data;
5804da8fa45SMed Ismail Bennani
5814da8fa45SMed Ismail Bennani StructuredData::ObjectSP bkpt_dict = bkpt_sp->SerializeToStructuredData();
5824da8fa45SMed Ismail Bennani data.m_impl_up->SetObjectSP(bkpt_dict);
583d232abc3SJonas Devlieghere return data;
5844da8fa45SMed Ismail Bennani }
5854da8fa45SMed Ismail Bennani
SetCallback(SBBreakpointHitCallback callback,void * baton)5860d7b0c96SJonas Devlieghere void SBBreakpoint::SetCallback(SBBreakpointHitCallback callback, void *baton) {
5871755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, callback, baton);
5880d7b0c96SJonas Devlieghere
5896ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
590ceb6b139SCaroline Tice
5916ac84034SPavel Labath if (bkpt_sp) {
592b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
5936ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
59430fdc8d8SChris Lattner BatonSP baton_sp(new SBBreakpointCallbackBaton(callback, baton));
595b842f2ecSJim Ingham bkpt_sp->SetCallback(SBBreakpointCallbackBaton
596b842f2ecSJim Ingham ::PrivateBreakpointHitCallback, baton_sp,
5976ac84034SPavel Labath false);
59830fdc8d8SChris Lattner }
59930fdc8d8SChris Lattner }
60030fdc8d8SChris Lattner
SetScriptCallbackFunction(const char * callback_function_name)601b9c1b51eSKate Stone void SBBreakpoint::SetScriptCallbackFunction(
602b9c1b51eSKate Stone const char *callback_function_name) {
6031755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, callback_function_name);
604738af7a6SJim Ingham SBStructuredData empty_args;
605738af7a6SJim Ingham SetScriptCallbackFunction(callback_function_name, empty_args);
606738af7a6SJim Ingham }
607baf5664fSJonas Devlieghere
SetScriptCallbackFunction(const char * callback_function_name,SBStructuredData & extra_args)608738af7a6SJim Ingham SBError SBBreakpoint::SetScriptCallbackFunction(
609738af7a6SJim Ingham const char *callback_function_name,
610738af7a6SJim Ingham SBStructuredData &extra_args) {
6111755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, callback_function_name, extra_args);
612738af7a6SJim Ingham SBError sb_error;
6136ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
614d80102e4SJim Ingham
6156ac84034SPavel Labath if (bkpt_sp) {
616738af7a6SJim Ingham Status error;
617b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
6186ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
619cfb96d84SJim Ingham BreakpointOptions &bp_options = bkpt_sp->GetOptions();
620738af7a6SJim Ingham error = bkpt_sp->GetTarget()
621b9c1b51eSKate Stone .GetDebugger()
622b9c1b51eSKate Stone .GetScriptInterpreter()
623b9c1b51eSKate Stone ->SetBreakpointCommandCallbackFunction(bp_options,
624738af7a6SJim Ingham callback_function_name,
625738af7a6SJim Ingham extra_args.m_impl_up
626738af7a6SJim Ingham ->GetObjectSP());
627738af7a6SJim Ingham sb_error.SetError(error);
628738af7a6SJim Ingham } else
629738af7a6SJim Ingham sb_error.SetErrorString("invalid breakpoint");
630738af7a6SJim Ingham
631d232abc3SJonas Devlieghere return sb_error;
632d80102e4SJim Ingham }
633d80102e4SJim Ingham
SetScriptCallbackBody(const char * callback_body_text)634b9c1b51eSKate Stone SBError SBBreakpoint::SetScriptCallbackBody(const char *callback_body_text) {
6351755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, callback_body_text);
636baf5664fSJonas Devlieghere
6376ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
638d80102e4SJim Ingham
639d80102e4SJim Ingham SBError sb_error;
6406ac84034SPavel Labath if (bkpt_sp) {
641b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
6426ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
643cfb96d84SJim Ingham BreakpointOptions &bp_options = bkpt_sp->GetOptions();
64497206d57SZachary Turner Status error =
6456ac84034SPavel Labath bkpt_sp->GetTarget()
646b9c1b51eSKate Stone .GetDebugger()
647b9c1b51eSKate Stone .GetScriptInterpreter()
648b9c1b51eSKate Stone ->SetBreakpointCommandCallback(bp_options, callback_body_text);
649d80102e4SJim Ingham sb_error.SetError(error);
650b9c1b51eSKate Stone } else
651d80102e4SJim Ingham sb_error.SetErrorString("invalid breakpoint");
652d80102e4SJim Ingham
653d232abc3SJonas Devlieghere return sb_error;
654d80102e4SJim Ingham }
65530fdc8d8SChris Lattner
AddName(const char * new_name)656b9c1b51eSKate Stone bool SBBreakpoint::AddName(const char *new_name) {
6571755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, new_name);
658baf5664fSJonas Devlieghere
659f70cad26SMed Ismail Bennani SBError status = AddNameWithErrorHandling(new_name);
660f70cad26SMed Ismail Bennani return status.Success();
661f70cad26SMed Ismail Bennani }
662f70cad26SMed Ismail Bennani
AddNameWithErrorHandling(const char * new_name)663f70cad26SMed Ismail Bennani SBError SBBreakpoint::AddNameWithErrorHandling(const char *new_name) {
6641755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, new_name);
665f70cad26SMed Ismail Bennani
6666ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
6675e09c8c3SJim Ingham
668f70cad26SMed Ismail Bennani SBError status;
6696ac84034SPavel Labath if (bkpt_sp) {
670b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
6716ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
672f70cad26SMed Ismail Bennani Status error;
673b842f2ecSJim Ingham bkpt_sp->GetTarget().AddNameToBreakpoint(bkpt_sp, new_name, error);
674f70cad26SMed Ismail Bennani status.SetError(error);
675f70cad26SMed Ismail Bennani } else {
676f70cad26SMed Ismail Bennani status.SetErrorString("invalid breakpoint");
677b842f2ecSJim Ingham }
6785e09c8c3SJim Ingham
679d232abc3SJonas Devlieghere return status;
6805e09c8c3SJim Ingham }
6815e09c8c3SJim Ingham
RemoveName(const char * name_to_remove)682b9c1b51eSKate Stone void SBBreakpoint::RemoveName(const char *name_to_remove) {
6831755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, name_to_remove);
684baf5664fSJonas Devlieghere
6856ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
6865e09c8c3SJim Ingham
6876ac84034SPavel Labath if (bkpt_sp) {
688b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
6896ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
690b842f2ecSJim Ingham bkpt_sp->GetTarget().RemoveNameFromBreakpoint(bkpt_sp,
691b842f2ecSJim Ingham ConstString(name_to_remove));
6925e09c8c3SJim Ingham }
6935e09c8c3SJim Ingham }
6945e09c8c3SJim Ingham
MatchesName(const char * name)695b9c1b51eSKate Stone bool SBBreakpoint::MatchesName(const char *name) {
6961755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, name);
697baf5664fSJonas Devlieghere
6986ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
6995e09c8c3SJim Ingham
7006ac84034SPavel Labath if (bkpt_sp) {
701b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
7026ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
7036ac84034SPavel Labath return bkpt_sp->MatchesName(name);
7045e09c8c3SJim Ingham }
7055e09c8c3SJim Ingham
7065e09c8c3SJim Ingham return false;
7075e09c8c3SJim Ingham }
7085e09c8c3SJim Ingham
GetNames(SBStringList & names)709b9c1b51eSKate Stone void SBBreakpoint::GetNames(SBStringList &names) {
7101755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, names);
711baf5664fSJonas Devlieghere
7126ac84034SPavel Labath BreakpointSP bkpt_sp = GetSP();
7135e09c8c3SJim Ingham
7146ac84034SPavel Labath if (bkpt_sp) {
715b9c1b51eSKate Stone std::lock_guard<std::recursive_mutex> guard(
7166ac84034SPavel Labath bkpt_sp->GetTarget().GetAPIMutex());
7175e09c8c3SJim Ingham std::vector<std::string> names_vec;
7186ac84034SPavel Labath bkpt_sp->GetNames(names_vec);
719b9c1b51eSKate Stone for (std::string name : names_vec) {
7205e09c8c3SJim Ingham names.AppendString(name.c_str());
7215e09c8c3SJim Ingham }
7225e09c8c3SJim Ingham }
7235e09c8c3SJim Ingham }
7245e09c8c3SJim Ingham
EventIsBreakpointEvent(const lldb::SBEvent & event)725b9c1b51eSKate Stone bool SBBreakpoint::EventIsBreakpointEvent(const lldb::SBEvent &event) {
7261755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(event);
727baf5664fSJonas Devlieghere
728b9c1b51eSKate Stone return Breakpoint::BreakpointEventData::GetEventDataFromEvent(event.get()) !=
729b9c1b51eSKate Stone nullptr;
730e6bc6cb9SJim Ingham }
731e6bc6cb9SJim Ingham
7329fed0d85SGreg Clayton BreakpointEventType
GetBreakpointEventTypeFromEvent(const SBEvent & event)733b9c1b51eSKate Stone SBBreakpoint::GetBreakpointEventTypeFromEvent(const SBEvent &event) {
7341755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(event);
735baf5664fSJonas Devlieghere
7369fed0d85SGreg Clayton if (event.IsValid())
737b9c1b51eSKate Stone return Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent(
738b9c1b51eSKate Stone event.GetSP());
7399fed0d85SGreg Clayton return eBreakpointEventTypeInvalidType;
7409fed0d85SGreg Clayton }
7419fed0d85SGreg Clayton
GetBreakpointFromEvent(const lldb::SBEvent & event)742b9c1b51eSKate Stone SBBreakpoint SBBreakpoint::GetBreakpointFromEvent(const lldb::SBEvent &event) {
7431755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(event);
744baf5664fSJonas Devlieghere
7459fed0d85SGreg Clayton if (event.IsValid())
746d232abc3SJonas Devlieghere return SBBreakpoint(
747d232abc3SJonas Devlieghere Breakpoint::BreakpointEventData::GetBreakpointFromEvent(event.GetSP()));
748d232abc3SJonas Devlieghere return SBBreakpoint();
7499fed0d85SGreg Clayton }
7509fed0d85SGreg Clayton
7519fed0d85SGreg Clayton SBBreakpointLocation
GetBreakpointLocationAtIndexFromEvent(const lldb::SBEvent & event,uint32_t loc_idx)752b9c1b51eSKate Stone SBBreakpoint::GetBreakpointLocationAtIndexFromEvent(const lldb::SBEvent &event,
753b9c1b51eSKate Stone uint32_t loc_idx) {
7541755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(event, loc_idx);
755baf5664fSJonas Devlieghere
7569fed0d85SGreg Clayton SBBreakpointLocation sb_breakpoint_loc;
7579fed0d85SGreg Clayton if (event.IsValid())
758b9c1b51eSKate Stone sb_breakpoint_loc.SetLocation(
759b9c1b51eSKate Stone Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent(
760b9c1b51eSKate Stone event.GetSP(), loc_idx));
761d232abc3SJonas Devlieghere return sb_breakpoint_loc;
7629fed0d85SGreg Clayton }
7639fed0d85SGreg Clayton
764e6bc6cb9SJim Ingham uint32_t
GetNumBreakpointLocationsFromEvent(const lldb::SBEvent & event)765b9c1b51eSKate Stone SBBreakpoint::GetNumBreakpointLocationsFromEvent(const lldb::SBEvent &event) {
7661755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(event);
767baf5664fSJonas Devlieghere
768e6bc6cb9SJim Ingham uint32_t num_locations = 0;
769e6bc6cb9SJim Ingham if (event.IsValid())
770b9c1b51eSKate Stone num_locations =
771b9c1b51eSKate Stone (Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent(
772b9c1b51eSKate Stone event.GetSP()));
773e6bc6cb9SJim Ingham return num_locations;
774e6bc6cb9SJim Ingham }
77501f16664SJim Ingham
IsHardware() const776e103ae92SJonas Devlieghere bool SBBreakpoint::IsHardware() const {
7771755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
778baf5664fSJonas Devlieghere
779e103ae92SJonas Devlieghere BreakpointSP bkpt_sp = GetSP();
780e103ae92SJonas Devlieghere if (bkpt_sp)
781e103ae92SJonas Devlieghere return bkpt_sp->IsHardware();
782e103ae92SJonas Devlieghere return false;
783e103ae92SJonas Devlieghere }
784e103ae92SJonas Devlieghere
GetSP() const7856ac84034SPavel Labath BreakpointSP SBBreakpoint::GetSP() const { return m_opaque_wp.lock(); }
7866ac84034SPavel Labath
78701f16664SJim Ingham // This is simple collection of breakpoint id's and their target.
788653e3f4eSTodd Fiala class SBBreakpointListImpl {
78901f16664SJim Ingham public:
SBBreakpointListImpl(lldb::TargetSP target_sp)790a3436f73SKazu Hirata SBBreakpointListImpl(lldb::TargetSP target_sp) {
791653e3f4eSTodd Fiala if (target_sp && target_sp->IsValid())
792653e3f4eSTodd Fiala m_target_wp = target_sp;
79301f16664SJim Ingham }
79401f16664SJim Ingham
79501f16664SJim Ingham ~SBBreakpointListImpl() = default;
79601f16664SJim Ingham
GetSize()79701f16664SJim Ingham size_t GetSize() { return m_break_ids.size(); }
79801f16664SJim Ingham
GetBreakpointAtIndex(size_t idx)79901f16664SJim Ingham BreakpointSP GetBreakpointAtIndex(size_t idx) {
80001f16664SJim Ingham if (idx >= m_break_ids.size())
80101f16664SJim Ingham return BreakpointSP();
80201f16664SJim Ingham TargetSP target_sp = m_target_wp.lock();
80301f16664SJim Ingham if (!target_sp)
80401f16664SJim Ingham return BreakpointSP();
80501f16664SJim Ingham lldb::break_id_t bp_id = m_break_ids[idx];
80601f16664SJim Ingham return target_sp->GetBreakpointList().FindBreakpointByID(bp_id);
80701f16664SJim Ingham }
80801f16664SJim Ingham
FindBreakpointByID(lldb::break_id_t desired_id)8096d1e4696SJim Ingham BreakpointSP FindBreakpointByID(lldb::break_id_t desired_id) {
8106d1e4696SJim Ingham TargetSP target_sp = m_target_wp.lock();
8116d1e4696SJim Ingham if (!target_sp)
8126d1e4696SJim Ingham return BreakpointSP();
8136d1e4696SJim Ingham
8146d1e4696SJim Ingham for (lldb::break_id_t &break_id : m_break_ids) {
8156d1e4696SJim Ingham if (break_id == desired_id)
8166d1e4696SJim Ingham return target_sp->GetBreakpointList().FindBreakpointByID(break_id);
8176d1e4696SJim Ingham }
8186d1e4696SJim Ingham return BreakpointSP();
8196d1e4696SJim Ingham }
8206d1e4696SJim Ingham
Append(BreakpointSP bkpt)8216ac84034SPavel Labath bool Append(BreakpointSP bkpt) {
82201f16664SJim Ingham TargetSP target_sp = m_target_wp.lock();
8236ac84034SPavel Labath if (!target_sp || !bkpt)
82401f16664SJim Ingham return false;
8256ac84034SPavel Labath if (bkpt->GetTargetSP() != target_sp)
82601f16664SJim Ingham return false;
8276ac84034SPavel Labath m_break_ids.push_back(bkpt->GetID());
82801f16664SJim Ingham return true;
82901f16664SJim Ingham }
83001f16664SJim Ingham
AppendIfUnique(BreakpointSP bkpt)8316ac84034SPavel Labath bool AppendIfUnique(BreakpointSP bkpt) {
83201f16664SJim Ingham TargetSP target_sp = m_target_wp.lock();
8336ac84034SPavel Labath if (!target_sp || !bkpt)
83401f16664SJim Ingham return false;
8356ac84034SPavel Labath if (bkpt->GetTargetSP() != target_sp)
83601f16664SJim Ingham return false;
8376ac84034SPavel Labath lldb::break_id_t bp_id = bkpt->GetID();
838*360c1111SKazu Hirata if (!llvm::is_contained(m_break_ids, bp_id))
83901f16664SJim Ingham return false;
84001f16664SJim Ingham
8416ac84034SPavel Labath m_break_ids.push_back(bkpt->GetID());
84201f16664SJim Ingham return true;
84301f16664SJim Ingham }
84401f16664SJim Ingham
AppendByID(lldb::break_id_t id)84501f16664SJim Ingham bool AppendByID(lldb::break_id_t id) {
84601f16664SJim Ingham TargetSP target_sp = m_target_wp.lock();
84701f16664SJim Ingham if (!target_sp)
84801f16664SJim Ingham return false;
84901f16664SJim Ingham if (id == LLDB_INVALID_BREAK_ID)
85001f16664SJim Ingham return false;
85101f16664SJim Ingham m_break_ids.push_back(id);
85201f16664SJim Ingham return true;
85301f16664SJim Ingham }
85401f16664SJim Ingham
Clear()85501f16664SJim Ingham void Clear() { m_break_ids.clear(); }
85601f16664SJim Ingham
CopyToBreakpointIDList(lldb_private::BreakpointIDList & bp_list)85701f16664SJim Ingham void CopyToBreakpointIDList(lldb_private::BreakpointIDList &bp_list) {
85801f16664SJim Ingham for (lldb::break_id_t id : m_break_ids) {
85901f16664SJim Ingham bp_list.AddBreakpointID(BreakpointID(id));
86001f16664SJim Ingham }
86101f16664SJim Ingham }
86201f16664SJim Ingham
GetTarget()86301f16664SJim Ingham TargetSP GetTarget() { return m_target_wp.lock(); }
86401f16664SJim Ingham
86501f16664SJim Ingham private:
86601f16664SJim Ingham std::vector<lldb::break_id_t> m_break_ids;
86701f16664SJim Ingham TargetWP m_target_wp;
86801f16664SJim Ingham };
86901f16664SJim Ingham
SBBreakpointList(SBTarget & target)87001f16664SJim Ingham SBBreakpointList::SBBreakpointList(SBTarget &target)
871baf5664fSJonas Devlieghere : m_opaque_sp(new SBBreakpointListImpl(target.GetSP())) {
8721755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, target);
873baf5664fSJonas Devlieghere }
87401f16664SJim Ingham
875866b7a65SJonas Devlieghere SBBreakpointList::~SBBreakpointList() = default;
87601f16664SJim Ingham
GetSize() const87701f16664SJim Ingham size_t SBBreakpointList::GetSize() const {
8781755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
879baf5664fSJonas Devlieghere
88001f16664SJim Ingham if (!m_opaque_sp)
88101f16664SJim Ingham return 0;
88201f16664SJim Ingham else
88301f16664SJim Ingham return m_opaque_sp->GetSize();
88401f16664SJim Ingham }
88501f16664SJim Ingham
GetBreakpointAtIndex(size_t idx)88601f16664SJim Ingham SBBreakpoint SBBreakpointList::GetBreakpointAtIndex(size_t idx) {
8871755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, idx);
888baf5664fSJonas Devlieghere
88901f16664SJim Ingham if (!m_opaque_sp)
890d232abc3SJonas Devlieghere return SBBreakpoint();
89101f16664SJim Ingham
89201f16664SJim Ingham BreakpointSP bkpt_sp = m_opaque_sp->GetBreakpointAtIndex(idx);
893d232abc3SJonas Devlieghere return SBBreakpoint(bkpt_sp);
89401f16664SJim Ingham }
89501f16664SJim Ingham
FindBreakpointByID(lldb::break_id_t id)8966d1e4696SJim Ingham SBBreakpoint SBBreakpointList::FindBreakpointByID(lldb::break_id_t id) {
8971755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, id);
898baf5664fSJonas Devlieghere
8996d1e4696SJim Ingham if (!m_opaque_sp)
900d232abc3SJonas Devlieghere return SBBreakpoint();
9016d1e4696SJim Ingham BreakpointSP bkpt_sp = m_opaque_sp->FindBreakpointByID(id);
902d232abc3SJonas Devlieghere return SBBreakpoint(bkpt_sp);
9036d1e4696SJim Ingham }
9046d1e4696SJim Ingham
Append(const SBBreakpoint & sb_bkpt)90501f16664SJim Ingham void SBBreakpointList::Append(const SBBreakpoint &sb_bkpt) {
9061755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, sb_bkpt);
907baf5664fSJonas Devlieghere
90801f16664SJim Ingham if (!sb_bkpt.IsValid())
90901f16664SJim Ingham return;
91001f16664SJim Ingham if (!m_opaque_sp)
91101f16664SJim Ingham return;
9126ac84034SPavel Labath m_opaque_sp->Append(sb_bkpt.m_opaque_wp.lock());
91301f16664SJim Ingham }
91401f16664SJim Ingham
AppendByID(lldb::break_id_t id)91501f16664SJim Ingham void SBBreakpointList::AppendByID(lldb::break_id_t id) {
9161755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, id);
917baf5664fSJonas Devlieghere
91801f16664SJim Ingham if (!m_opaque_sp)
91901f16664SJim Ingham return;
92001f16664SJim Ingham m_opaque_sp->AppendByID(id);
92101f16664SJim Ingham }
92201f16664SJim Ingham
AppendIfUnique(const SBBreakpoint & sb_bkpt)92301f16664SJim Ingham bool SBBreakpointList::AppendIfUnique(const SBBreakpoint &sb_bkpt) {
9241755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, sb_bkpt);
925baf5664fSJonas Devlieghere
92601f16664SJim Ingham if (!sb_bkpt.IsValid())
92701f16664SJim Ingham return false;
92801f16664SJim Ingham if (!m_opaque_sp)
92901f16664SJim Ingham return false;
9306ac84034SPavel Labath return m_opaque_sp->AppendIfUnique(sb_bkpt.GetSP());
93101f16664SJim Ingham }
93201f16664SJim Ingham
Clear()93301f16664SJim Ingham void SBBreakpointList::Clear() {
9341755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
935baf5664fSJonas Devlieghere
93601f16664SJim Ingham if (m_opaque_sp)
93701f16664SJim Ingham m_opaque_sp->Clear();
93801f16664SJim Ingham }
93901f16664SJim Ingham
CopyToBreakpointIDList(lldb_private::BreakpointIDList & bp_id_list)94001f16664SJim Ingham void SBBreakpointList::CopyToBreakpointIDList(
94101f16664SJim Ingham lldb_private::BreakpointIDList &bp_id_list) {
94201f16664SJim Ingham if (m_opaque_sp)
94301f16664SJim Ingham m_opaque_sp->CopyToBreakpointIDList(bp_id_list);
94401f16664SJim Ingham }
945