Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SBBreakpoint.cpp ----------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "lldb/API/SBBreakpoint.h" |
| 11 | #include "lldb/API/SBBreakpointLocation.h" |
| 12 | #include "lldb/API/SBDebugger.h" |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 13 | #include "lldb/API/SBEvent.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 14 | #include "lldb/API/SBProcess.h" |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 15 | #include "lldb/API/SBStream.h" |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 16 | #include "lldb/API/SBStringList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/API/SBThread.h" |
| 18 | |
| 19 | #include "lldb/Breakpoint/Breakpoint.h" |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 20 | #include "lldb/Breakpoint/BreakpointIDList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | #include "lldb/Breakpoint/BreakpointLocation.h" |
Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 22 | #include "lldb/Breakpoint/BreakpointResolver.h" |
| 23 | #include "lldb/Breakpoint/BreakpointResolverScripted.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | #include "lldb/Breakpoint/StoppointCallbackContext.h" |
| 25 | #include "lldb/Core/Address.h" |
Jim Ingham | d80102e | 2014-04-02 01:04:55 +0000 | [diff] [blame] | 26 | #include "lldb/Core/Debugger.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | #include "lldb/Core/StreamFile.h" |
Jim Ingham | d80102e | 2014-04-02 01:04:55 +0000 | [diff] [blame] | 28 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 29 | #include "lldb/Interpreter/ScriptInterpreter.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/Target/Process.h" |
Greg Clayton | d5944cd | 2013-12-06 01:12:00 +0000 | [diff] [blame] | 31 | #include "lldb/Target/SectionLoadList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | #include "lldb/Target/Target.h" |
Jim Ingham | 62b02c6 | 2010-06-18 01:47:08 +0000 | [diff] [blame] | 33 | #include "lldb/Target/Thread.h" |
| 34 | #include "lldb/Target/ThreadSpec.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 35 | #include "lldb/Utility/Log.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 36 | #include "lldb/Utility/Stream.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 38 | #include "SBBreakpointOptionCommon.h" |
| 39 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 40 | #include "lldb/lldb-enumerations.h" |
| 41 | |
Zachary Turner | 4e4fbe8 | 2016-09-13 17:53:38 +0000 | [diff] [blame] | 42 | #include "llvm/ADT/STLExtras.h" |
| 43 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | using namespace lldb; |
| 45 | using namespace lldb_private; |
| 46 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 47 | SBBreakpoint::SBBreakpoint() {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 48 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 49 | SBBreakpoint::SBBreakpoint(const SBBreakpoint &rhs) |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 50 | : m_opaque_wp(rhs.m_opaque_wp) {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 51 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 52 | SBBreakpoint::SBBreakpoint(const lldb::BreakpointSP &bp_sp) |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 53 | : m_opaque_wp(bp_sp) {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | |
Eugene Zelenko | dbb0abb | 2015-10-31 01:22:59 +0000 | [diff] [blame] | 55 | SBBreakpoint::~SBBreakpoint() = default; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 56 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 57 | const SBBreakpoint &SBBreakpoint::operator=(const SBBreakpoint &rhs) { |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 58 | m_opaque_wp = rhs.m_opaque_wp; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 59 | return *this; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 62 | bool SBBreakpoint::operator==(const lldb::SBBreakpoint &rhs) { |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 63 | return m_opaque_wp.lock() == rhs.m_opaque_wp.lock(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | bool SBBreakpoint::operator!=(const lldb::SBBreakpoint &rhs) { |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 67 | return m_opaque_wp.lock() != rhs.m_opaque_wp.lock(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | break_id_t SBBreakpoint::GetID() const { |
| 71 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 72 | |
| 73 | break_id_t break_id = LLDB_INVALID_BREAK_ID; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 74 | BreakpointSP bkpt_sp = GetSP(); |
| 75 | if (bkpt_sp) |
| 76 | break_id = bkpt_sp->GetID(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 77 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 78 | LLDB_LOG(log, "breakpoint = {0}, id = {1}", bkpt_sp.get(), break_id); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 79 | return break_id; |
| 80 | } |
| 81 | |
| 82 | bool SBBreakpoint::IsValid() const { |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 83 | BreakpointSP bkpt_sp = GetSP(); |
| 84 | if (!bkpt_sp) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 85 | return false; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 86 | else if (bkpt_sp->GetTarget().GetBreakpointByID(bkpt_sp->GetID())) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 87 | return true; |
| 88 | else |
Greg Clayton | ac2eb9b | 2010-12-12 19:25:26 +0000 | [diff] [blame] | 89 | return false; |
| 90 | } |
| 91 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 92 | void SBBreakpoint::ClearAllBreakpointSites() { |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 93 | BreakpointSP bkpt_sp = GetSP(); |
| 94 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 95 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 96 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 97 | bkpt_sp->ClearAllBreakpointSites(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 98 | } |
Enrico Granata | c338733 | 2013-05-03 01:29:27 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 101 | SBBreakpointLocation SBBreakpoint::FindLocationByAddress(addr_t vm_addr) { |
| 102 | SBBreakpointLocation sb_bp_location; |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 103 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 104 | BreakpointSP bkpt_sp = GetSP(); |
| 105 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 106 | if (vm_addr != LLDB_INVALID_ADDRESS) { |
| 107 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 108 | bkpt_sp->GetTarget().GetAPIMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 109 | Address address; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 110 | Target &target = bkpt_sp->GetTarget(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 111 | if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) { |
| 112 | address.SetRawAddress(vm_addr); |
| 113 | } |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 114 | sb_bp_location.SetLocation(bkpt_sp->FindLocationByAddress(address)); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 115 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 116 | } |
| 117 | return sb_bp_location; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 120 | break_id_t SBBreakpoint::FindLocationIDByAddress(addr_t vm_addr) { |
| 121 | break_id_t break_id = LLDB_INVALID_BREAK_ID; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 122 | BreakpointSP bkpt_sp = GetSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 123 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 124 | if (bkpt_sp && vm_addr != LLDB_INVALID_ADDRESS) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 125 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 126 | bkpt_sp->GetTarget().GetAPIMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 127 | Address address; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 128 | Target &target = bkpt_sp->GetTarget(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 129 | if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) { |
| 130 | address.SetRawAddress(vm_addr); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 131 | } |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 132 | break_id = bkpt_sp->FindLocationIDByAddress(address); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | return break_id; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 138 | SBBreakpointLocation SBBreakpoint::FindLocationByID(break_id_t bp_loc_id) { |
| 139 | SBBreakpointLocation sb_bp_location; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 140 | BreakpointSP bkpt_sp = GetSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 141 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 142 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 143 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 144 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 145 | sb_bp_location.SetLocation(bkpt_sp->FindLocationByID(bp_loc_id)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | return sb_bp_location; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 151 | SBBreakpointLocation SBBreakpoint::GetLocationAtIndex(uint32_t index) { |
| 152 | SBBreakpointLocation sb_bp_location; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 153 | BreakpointSP bkpt_sp = GetSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 154 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 155 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 156 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 157 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 158 | sb_bp_location.SetLocation(bkpt_sp->GetLocationAtIndex(index)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 159 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 160 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 161 | return sb_bp_location; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 164 | void SBBreakpoint::SetEnabled(bool enable) { |
| 165 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 166 | BreakpointSP bkpt_sp = GetSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 167 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 168 | LLDB_LOG(log, "breakpoint = {0}, enable = {1}", bkpt_sp.get(), enable); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 169 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 170 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 171 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 172 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 173 | bkpt_sp->SetEnabled(enable); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 174 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 177 | bool SBBreakpoint::IsEnabled() { |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 178 | BreakpointSP bkpt_sp = GetSP(); |
| 179 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 180 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 181 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 182 | return bkpt_sp->IsEnabled(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 183 | } else |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 184 | return false; |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 187 | void SBBreakpoint::SetOneShot(bool one_shot) { |
| 188 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 189 | BreakpointSP bkpt_sp = GetSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 190 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 191 | LLDB_LOG(log, "breakpoint = {0}, one_shot = {1}", bkpt_sp.get(), one_shot); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 192 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 193 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 194 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 195 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 196 | bkpt_sp->SetOneShot(one_shot); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 197 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 200 | bool SBBreakpoint::IsOneShot() const { |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 201 | BreakpointSP bkpt_sp = GetSP(); |
| 202 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 203 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 204 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 205 | return bkpt_sp->IsOneShot(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 206 | } else |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 207 | return false; |
| 208 | } |
| 209 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 210 | bool SBBreakpoint::IsInternal() { |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 211 | BreakpointSP bkpt_sp = GetSP(); |
| 212 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 213 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 214 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 215 | return bkpt_sp->IsInternal(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 216 | } else |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 217 | return false; |
| 218 | } |
| 219 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 220 | void SBBreakpoint::SetIgnoreCount(uint32_t count) { |
| 221 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 222 | BreakpointSP bkpt_sp = GetSP(); |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 223 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 224 | LLDB_LOG(log, "breakpoint = {0}, count = {1}", bkpt_sp.get(), count); |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 225 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 226 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 227 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 228 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 229 | bkpt_sp->SetIgnoreCount(count); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | |
| 233 | void SBBreakpoint::SetCondition(const char *condition) { |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 234 | BreakpointSP bkpt_sp = GetSP(); |
| 235 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 236 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 237 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 238 | bkpt_sp->SetCondition(condition); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | |
| 242 | const char *SBBreakpoint::GetCondition() { |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 243 | BreakpointSP bkpt_sp = GetSP(); |
| 244 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 245 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 246 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 247 | return bkpt_sp->GetConditionText(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 248 | } |
| 249 | return nullptr; |
| 250 | } |
| 251 | |
Jim Ingham | f08f5c9 | 2017-08-03 18:13:24 +0000 | [diff] [blame] | 252 | void SBBreakpoint::SetAutoContinue(bool auto_continue) { |
| 253 | BreakpointSP bkpt_sp = GetSP(); |
| 254 | if (bkpt_sp) { |
| 255 | std::lock_guard<std::recursive_mutex> guard( |
| 256 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 257 | bkpt_sp->SetAutoContinue(auto_continue); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | bool SBBreakpoint::GetAutoContinue() { |
| 262 | BreakpointSP bkpt_sp = GetSP(); |
| 263 | if (bkpt_sp) { |
| 264 | std::lock_guard<std::recursive_mutex> guard( |
| 265 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 266 | return bkpt_sp->IsAutoContinue(); |
| 267 | } |
Jim Ingham | 1c7dc82 | 2017-08-03 19:38:38 +0000 | [diff] [blame] | 268 | return false; |
Jim Ingham | f08f5c9 | 2017-08-03 18:13:24 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 271 | uint32_t SBBreakpoint::GetHitCount() const { |
| 272 | uint32_t count = 0; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 273 | BreakpointSP bkpt_sp = GetSP(); |
| 274 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 275 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 276 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 277 | count = bkpt_sp->GetHitCount(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 281 | LLDB_LOG(log, "breakpoint = {0}, count = {1}", bkpt_sp.get(), count); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 282 | |
| 283 | return count; |
| 284 | } |
| 285 | |
| 286 | uint32_t SBBreakpoint::GetIgnoreCount() const { |
| 287 | uint32_t count = 0; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 288 | BreakpointSP bkpt_sp = GetSP(); |
| 289 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 290 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 291 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 292 | count = bkpt_sp->GetIgnoreCount(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 296 | LLDB_LOG(log, "breakpoint = {0}, count = {1}", bkpt_sp.get(), count); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 297 | |
| 298 | return count; |
| 299 | } |
| 300 | |
| 301 | void SBBreakpoint::SetThreadID(tid_t tid) { |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 302 | BreakpointSP bkpt_sp = GetSP(); |
| 303 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 304 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 305 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 306 | bkpt_sp->SetThreadID(tid); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 307 | } |
| 308 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 309 | LLDB_LOG(log, "breakpoint = {0}, tid = {1:x}", bkpt_sp.get(), tid); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | tid_t SBBreakpoint::GetThreadID() { |
| 313 | tid_t tid = LLDB_INVALID_THREAD_ID; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 314 | BreakpointSP bkpt_sp = GetSP(); |
| 315 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 316 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 317 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 318 | tid = bkpt_sp->GetThreadID(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 322 | LLDB_LOG(log, "breakpoint = {0}, tid = {1:x}", bkpt_sp.get(), tid); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 323 | return tid; |
| 324 | } |
| 325 | |
| 326 | void SBBreakpoint::SetThreadIndex(uint32_t index) { |
| 327 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 328 | BreakpointSP bkpt_sp = GetSP(); |
| 329 | LLDB_LOG(log, "breakpoint = {0}, index = {1}", bkpt_sp.get(), index); |
| 330 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 331 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 332 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 333 | bkpt_sp->GetOptions()->GetThreadSpec()->SetIndex(index); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | |
| 337 | uint32_t SBBreakpoint::GetThreadIndex() const { |
| 338 | uint32_t thread_idx = UINT32_MAX; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 339 | BreakpointSP bkpt_sp = GetSP(); |
| 340 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 341 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 342 | bkpt_sp->GetTarget().GetAPIMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 343 | const ThreadSpec *thread_spec = |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 344 | bkpt_sp->GetOptions()->GetThreadSpecNoCreate(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 345 | if (thread_spec != nullptr) |
| 346 | thread_idx = thread_spec->GetIndex(); |
| 347 | } |
| 348 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 349 | LLDB_LOG(log, "breakpoint = {0}, index = {1}", bkpt_sp.get(), thread_idx); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 350 | |
| 351 | return thread_idx; |
| 352 | } |
| 353 | |
| 354 | void SBBreakpoint::SetThreadName(const char *thread_name) { |
| 355 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 356 | BreakpointSP bkpt_sp = GetSP(); |
| 357 | LLDB_LOG(log, "breakpoint = {0}, name = {1}", bkpt_sp.get(), thread_name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 358 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 359 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 360 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 361 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 362 | bkpt_sp->GetOptions()->GetThreadSpec()->SetName(thread_name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | |
| 366 | const char *SBBreakpoint::GetThreadName() const { |
| 367 | const char *name = nullptr; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 368 | BreakpointSP bkpt_sp = GetSP(); |
| 369 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 370 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 371 | bkpt_sp->GetTarget().GetAPIMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 372 | const ThreadSpec *thread_spec = |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 373 | bkpt_sp->GetOptions()->GetThreadSpecNoCreate(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 374 | if (thread_spec != nullptr) |
| 375 | name = thread_spec->GetName(); |
| 376 | } |
| 377 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 378 | LLDB_LOG(log, "breakpoint = {0}, name = {1}", bkpt_sp.get(), name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 379 | |
| 380 | return name; |
| 381 | } |
| 382 | |
| 383 | void SBBreakpoint::SetQueueName(const char *queue_name) { |
| 384 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 385 | BreakpointSP bkpt_sp = GetSP(); |
| 386 | LLDB_LOG(log, "breakpoint = {0}, queue_name = {1}", bkpt_sp.get(), |
| 387 | queue_name); |
| 388 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 389 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 390 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 391 | bkpt_sp->GetOptions()->GetThreadSpec()->SetQueueName(queue_name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | |
| 395 | const char *SBBreakpoint::GetQueueName() const { |
| 396 | const char *name = nullptr; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 397 | BreakpointSP bkpt_sp = GetSP(); |
| 398 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 399 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 400 | bkpt_sp->GetTarget().GetAPIMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 401 | const ThreadSpec *thread_spec = |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 402 | bkpt_sp->GetOptions()->GetThreadSpecNoCreate(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 403 | if (thread_spec) |
| 404 | name = thread_spec->GetQueueName(); |
| 405 | } |
| 406 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 407 | LLDB_LOG(log, "breakpoint = {0}, name = {1}", bkpt_sp.get(), name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 408 | |
| 409 | return name; |
| 410 | } |
| 411 | |
| 412 | size_t SBBreakpoint::GetNumResolvedLocations() const { |
| 413 | size_t num_resolved = 0; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 414 | BreakpointSP bkpt_sp = GetSP(); |
| 415 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 416 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 417 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 418 | num_resolved = bkpt_sp->GetNumResolvedLocations(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 419 | } |
| 420 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 421 | LLDB_LOG(log, "breakpoint = {0}, num_resolved = {1}", bkpt_sp.get(), |
| 422 | num_resolved); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 423 | return num_resolved; |
| 424 | } |
| 425 | |
| 426 | size_t SBBreakpoint::GetNumLocations() const { |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 427 | BreakpointSP bkpt_sp = GetSP(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 428 | size_t num_locs = 0; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 429 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 430 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 431 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 432 | num_locs = bkpt_sp->GetNumLocations(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 433 | } |
| 434 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 435 | LLDB_LOG(log, "breakpoint = {0}, num_locs = {1}", bkpt_sp.get(), num_locs); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 436 | return num_locs; |
| 437 | } |
| 438 | |
Jim Ingham | 92d1960 | 2016-09-20 22:54:49 +0000 | [diff] [blame] | 439 | void SBBreakpoint::SetCommandLineCommands(SBStringList &commands) { |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 440 | BreakpointSP bkpt_sp = GetSP(); |
| 441 | if (!bkpt_sp) |
Jim Ingham | 92d1960 | 2016-09-20 22:54:49 +0000 | [diff] [blame] | 442 | return; |
| 443 | if (commands.GetSize() == 0) |
| 444 | return; |
| 445 | |
| 446 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 447 | bkpt_sp->GetTarget().GetAPIMutex()); |
Jim Ingham | 92d1960 | 2016-09-20 22:54:49 +0000 | [diff] [blame] | 448 | std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up( |
Jim Ingham | f7e0725 | 2016-09-26 19:47:37 +0000 | [diff] [blame] | 449 | new BreakpointOptions::CommandData(*commands, eScriptLanguageNone)); |
Jim Ingham | 92d1960 | 2016-09-20 22:54:49 +0000 | [diff] [blame] | 450 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 451 | bkpt_sp->GetOptions()->SetCommandDataCallback(cmd_data_up); |
Jim Ingham | 92d1960 | 2016-09-20 22:54:49 +0000 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | bool SBBreakpoint::GetCommandLineCommands(SBStringList &commands) { |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 455 | BreakpointSP bkpt_sp = GetSP(); |
| 456 | if (!bkpt_sp) |
Jim Ingham | 92d1960 | 2016-09-20 22:54:49 +0000 | [diff] [blame] | 457 | return false; |
| 458 | StringList command_list; |
| 459 | bool has_commands = |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 460 | bkpt_sp->GetOptions()->GetCommandLineCallbacks(command_list); |
Jim Ingham | 92d1960 | 2016-09-20 22:54:49 +0000 | [diff] [blame] | 461 | if (has_commands) |
| 462 | commands.AppendList(command_list); |
| 463 | return has_commands; |
| 464 | } |
| 465 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 466 | bool SBBreakpoint::GetDescription(SBStream &s) { |
Jim Ingham | 6d1e469 | 2016-09-16 01:41:27 +0000 | [diff] [blame] | 467 | return GetDescription(s, true); |
| 468 | } |
| 469 | |
| 470 | bool SBBreakpoint::GetDescription(SBStream &s, bool include_locations) { |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 471 | BreakpointSP bkpt_sp = GetSP(); |
| 472 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 473 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 474 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 475 | s.Printf("SBBreakpoint: id = %i, ", bkpt_sp->GetID()); |
| 476 | bkpt_sp->GetResolverDescription(s.get()); |
| 477 | bkpt_sp->GetFilterDescription(s.get()); |
Jim Ingham | 6d1e469 | 2016-09-16 01:41:27 +0000 | [diff] [blame] | 478 | if (include_locations) { |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 479 | const size_t num_locations = bkpt_sp->GetNumLocations(); |
Jim Ingham | 6d1e469 | 2016-09-16 01:41:27 +0000 | [diff] [blame] | 480 | s.Printf(", locations = %" PRIu64, (uint64_t)num_locations); |
| 481 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 482 | return true; |
| 483 | } |
| 484 | s.Printf("No value"); |
| 485 | return false; |
| 486 | } |
| 487 | |
Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 488 | SBError |
| 489 | SBBreakpoint::AddLocation(SBAddress &address) { |
| 490 | BreakpointSP bkpt_sp = GetSP(); |
| 491 | SBError error; |
| 492 | |
| 493 | if (!address.IsValid()) { |
| 494 | error.SetErrorString("Can't add an invalid address."); |
| 495 | return error; |
| 496 | } |
| 497 | |
| 498 | if (!bkpt_sp) { |
| 499 | error.SetErrorString("No breakpoint to add a location to."); |
| 500 | return error; |
| 501 | } |
| 502 | |
| 503 | if (!llvm::isa<BreakpointResolverScripted>(bkpt_sp->GetResolver().get())) { |
| 504 | error.SetErrorString("Only a scripted resolver can add locations."); |
| 505 | return error; |
| 506 | } |
| 507 | |
| 508 | if (bkpt_sp->GetSearchFilter()->AddressPasses(address.ref())) |
| 509 | bkpt_sp->AddLocation(address.ref()); |
| 510 | else |
| 511 | { |
| 512 | StreamString s; |
| 513 | address.get()->Dump(&s, &bkpt_sp->GetTarget(), |
| 514 | Address::DumpStyleModuleWithFileAddress); |
| 515 | error.SetErrorStringWithFormat("Address: %s didn't pass the filter.", |
| 516 | s.GetData()); |
| 517 | } |
| 518 | return error; |
| 519 | } |
| 520 | |
| 521 | |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 522 | void SBBreakpoint |
| 523 | ::SetCallback(SBBreakpointHitCallback callback, |
| 524 | void *baton) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 525 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 526 | BreakpointSP bkpt_sp = GetSP(); |
| 527 | LLDB_LOG(log, "breakpoint = {0}, callback = {1}, baton = {2}", bkpt_sp.get(), |
| 528 | callback, baton); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 529 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 530 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 531 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 532 | bkpt_sp->GetTarget().GetAPIMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 533 | BatonSP baton_sp(new SBBreakpointCallbackBaton(callback, baton)); |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 534 | bkpt_sp->SetCallback(SBBreakpointCallbackBaton |
| 535 | ::PrivateBreakpointHitCallback, baton_sp, |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 536 | false); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 537 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 538 | } |
| 539 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 540 | void SBBreakpoint::SetScriptCallbackFunction( |
| 541 | const char *callback_function_name) { |
| 542 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 543 | BreakpointSP bkpt_sp = GetSP(); |
| 544 | LLDB_LOG(log, "breakpoint = {0}, callback = {1}", bkpt_sp.get(), |
| 545 | callback_function_name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 546 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 547 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 548 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 549 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 550 | BreakpointOptions *bp_options = bkpt_sp->GetOptions(); |
| 551 | bkpt_sp->GetTarget() |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 552 | .GetDebugger() |
| 553 | .GetCommandInterpreter() |
| 554 | .GetScriptInterpreter() |
| 555 | ->SetBreakpointCommandCallbackFunction(bp_options, |
| 556 | callback_function_name); |
| 557 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 558 | } |
| 559 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 560 | SBError SBBreakpoint::SetScriptCallbackBody(const char *callback_body_text) { |
| 561 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 562 | BreakpointSP bkpt_sp = GetSP(); |
| 563 | LLDB_LOG(log, "breakpoint = {0}, callback body:\n{1}", bkpt_sp.get(), |
| 564 | callback_body_text); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 565 | |
| 566 | SBError sb_error; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 567 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 568 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 569 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 570 | BreakpointOptions *bp_options = bkpt_sp->GetOptions(); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 571 | Status error = |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 572 | bkpt_sp->GetTarget() |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 573 | .GetDebugger() |
| 574 | .GetCommandInterpreter() |
| 575 | .GetScriptInterpreter() |
| 576 | ->SetBreakpointCommandCallback(bp_options, callback_body_text); |
| 577 | sb_error.SetError(error); |
| 578 | } else |
| 579 | sb_error.SetErrorString("invalid breakpoint"); |
| 580 | |
| 581 | return sb_error; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 582 | } |
| 583 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 584 | bool SBBreakpoint::AddName(const char *new_name) { |
| 585 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 586 | BreakpointSP bkpt_sp = GetSP(); |
| 587 | LLDB_LOG(log, "breakpoint = {0}, name = {1}", bkpt_sp.get(), new_name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 588 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 589 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 590 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 591 | bkpt_sp->GetTarget().GetAPIMutex()); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 592 | Status error; // Think I'm just going to swallow the error here, it's |
| 593 | // probably more annoying to have to provide it. |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 594 | bkpt_sp->GetTarget().AddNameToBreakpoint(bkpt_sp, new_name, error); |
| 595 | if (error.Fail()) |
| 596 | { |
| 597 | if (log) |
| 598 | log->Printf("Failed to add name: '%s' to breakpoint: %s", |
| 599 | new_name, error.AsCString()); |
| 600 | return false; |
| 601 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 602 | } |
| 603 | |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 604 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 605 | } |
| 606 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 607 | void SBBreakpoint::RemoveName(const char *name_to_remove) { |
| 608 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 609 | BreakpointSP bkpt_sp = GetSP(); |
| 610 | LLDB_LOG(log, "breakpoint = {0}, name = {1}", bkpt_sp.get(), name_to_remove); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 611 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 612 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 613 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 614 | bkpt_sp->GetTarget().GetAPIMutex()); |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 615 | bkpt_sp->GetTarget().RemoveNameFromBreakpoint(bkpt_sp, |
| 616 | ConstString(name_to_remove)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 617 | } |
| 618 | } |
| 619 | |
| 620 | bool SBBreakpoint::MatchesName(const char *name) { |
| 621 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 622 | BreakpointSP bkpt_sp = GetSP(); |
| 623 | LLDB_LOG(log, "breakpoint = {0}, name = {1}", bkpt_sp.get(), name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 624 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 625 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 626 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 627 | bkpt_sp->GetTarget().GetAPIMutex()); |
| 628 | return bkpt_sp->MatchesName(name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | return false; |
| 632 | } |
| 633 | |
| 634 | void SBBreakpoint::GetNames(SBStringList &names) { |
| 635 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 636 | BreakpointSP bkpt_sp = GetSP(); |
| 637 | LLDB_LOG(log, "breakpoint = {0}", bkpt_sp.get()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 638 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 639 | if (bkpt_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 640 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 641 | bkpt_sp->GetTarget().GetAPIMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 642 | std::vector<std::string> names_vec; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 643 | bkpt_sp->GetNames(names_vec); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 644 | for (std::string name : names_vec) { |
| 645 | names.AppendString(name.c_str()); |
| 646 | } |
| 647 | } |
| 648 | } |
| 649 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 650 | bool SBBreakpoint::EventIsBreakpointEvent(const lldb::SBEvent &event) { |
| 651 | return Breakpoint::BreakpointEventData::GetEventDataFromEvent(event.get()) != |
| 652 | nullptr; |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 655 | BreakpointEventType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 656 | SBBreakpoint::GetBreakpointEventTypeFromEvent(const SBEvent &event) { |
| 657 | if (event.IsValid()) |
| 658 | return Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent( |
| 659 | event.GetSP()); |
| 660 | return eBreakpointEventTypeInvalidType; |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 661 | } |
| 662 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 663 | SBBreakpoint SBBreakpoint::GetBreakpointFromEvent(const lldb::SBEvent &event) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 664 | if (event.IsValid()) |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 665 | return SBBreakpoint( |
| 666 | Breakpoint::BreakpointEventData::GetBreakpointFromEvent(event.GetSP())); |
| 667 | return SBBreakpoint(); |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | SBBreakpointLocation |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 671 | SBBreakpoint::GetBreakpointLocationAtIndexFromEvent(const lldb::SBEvent &event, |
| 672 | uint32_t loc_idx) { |
| 673 | SBBreakpointLocation sb_breakpoint_loc; |
| 674 | if (event.IsValid()) |
| 675 | sb_breakpoint_loc.SetLocation( |
| 676 | Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent( |
| 677 | event.GetSP(), loc_idx)); |
| 678 | return sb_breakpoint_loc; |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 679 | } |
| 680 | |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 681 | uint32_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 682 | SBBreakpoint::GetNumBreakpointLocationsFromEvent(const lldb::SBEvent &event) { |
| 683 | uint32_t num_locations = 0; |
| 684 | if (event.IsValid()) |
| 685 | num_locations = |
| 686 | (Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent( |
| 687 | event.GetSP())); |
| 688 | return num_locations; |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 689 | } |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 690 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 691 | BreakpointSP SBBreakpoint::GetSP() const { return m_opaque_wp.lock(); } |
| 692 | |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 693 | // This is simple collection of breakpoint id's and their target. |
Todd Fiala | 653e3f4 | 2016-11-11 21:06:40 +0000 | [diff] [blame] | 694 | class SBBreakpointListImpl { |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 695 | public: |
Todd Fiala | 653e3f4 | 2016-11-11 21:06:40 +0000 | [diff] [blame] | 696 | SBBreakpointListImpl(lldb::TargetSP target_sp) : m_target_wp() { |
| 697 | if (target_sp && target_sp->IsValid()) |
| 698 | m_target_wp = target_sp; |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | ~SBBreakpointListImpl() = default; |
| 702 | |
| 703 | size_t GetSize() { return m_break_ids.size(); } |
| 704 | |
| 705 | BreakpointSP GetBreakpointAtIndex(size_t idx) { |
| 706 | if (idx >= m_break_ids.size()) |
| 707 | return BreakpointSP(); |
| 708 | TargetSP target_sp = m_target_wp.lock(); |
| 709 | if (!target_sp) |
| 710 | return BreakpointSP(); |
| 711 | lldb::break_id_t bp_id = m_break_ids[idx]; |
| 712 | return target_sp->GetBreakpointList().FindBreakpointByID(bp_id); |
| 713 | } |
| 714 | |
Jim Ingham | 6d1e469 | 2016-09-16 01:41:27 +0000 | [diff] [blame] | 715 | BreakpointSP FindBreakpointByID(lldb::break_id_t desired_id) { |
| 716 | TargetSP target_sp = m_target_wp.lock(); |
| 717 | if (!target_sp) |
| 718 | return BreakpointSP(); |
| 719 | |
| 720 | for (lldb::break_id_t &break_id : m_break_ids) { |
| 721 | if (break_id == desired_id) |
| 722 | return target_sp->GetBreakpointList().FindBreakpointByID(break_id); |
| 723 | } |
| 724 | return BreakpointSP(); |
| 725 | } |
| 726 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 727 | bool Append(BreakpointSP bkpt) { |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 728 | TargetSP target_sp = m_target_wp.lock(); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 729 | if (!target_sp || !bkpt) |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 730 | return false; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 731 | if (bkpt->GetTargetSP() != target_sp) |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 732 | return false; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 733 | m_break_ids.push_back(bkpt->GetID()); |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 734 | return true; |
| 735 | } |
| 736 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 737 | bool AppendIfUnique(BreakpointSP bkpt) { |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 738 | TargetSP target_sp = m_target_wp.lock(); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 739 | if (!target_sp || !bkpt) |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 740 | return false; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 741 | if (bkpt->GetTargetSP() != target_sp) |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 742 | return false; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 743 | lldb::break_id_t bp_id = bkpt->GetID(); |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 744 | if (find(m_break_ids.begin(), m_break_ids.end(), bp_id) == |
| 745 | m_break_ids.end()) |
| 746 | return false; |
| 747 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 748 | m_break_ids.push_back(bkpt->GetID()); |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 749 | return true; |
| 750 | } |
| 751 | |
| 752 | bool AppendByID(lldb::break_id_t id) { |
| 753 | TargetSP target_sp = m_target_wp.lock(); |
| 754 | if (!target_sp) |
| 755 | return false; |
| 756 | if (id == LLDB_INVALID_BREAK_ID) |
| 757 | return false; |
| 758 | m_break_ids.push_back(id); |
| 759 | return true; |
| 760 | } |
| 761 | |
| 762 | void Clear() { m_break_ids.clear(); } |
| 763 | |
| 764 | void CopyToBreakpointIDList(lldb_private::BreakpointIDList &bp_list) { |
| 765 | for (lldb::break_id_t id : m_break_ids) { |
| 766 | bp_list.AddBreakpointID(BreakpointID(id)); |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | TargetSP GetTarget() { return m_target_wp.lock(); } |
| 771 | |
| 772 | private: |
| 773 | std::vector<lldb::break_id_t> m_break_ids; |
| 774 | TargetWP m_target_wp; |
| 775 | }; |
| 776 | |
| 777 | SBBreakpointList::SBBreakpointList(SBTarget &target) |
Todd Fiala | 653e3f4 | 2016-11-11 21:06:40 +0000 | [diff] [blame] | 778 | : m_opaque_sp(new SBBreakpointListImpl(target.GetSP())) {} |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 779 | |
| 780 | SBBreakpointList::~SBBreakpointList() {} |
| 781 | |
| 782 | size_t SBBreakpointList::GetSize() const { |
| 783 | if (!m_opaque_sp) |
| 784 | return 0; |
| 785 | else |
| 786 | return m_opaque_sp->GetSize(); |
| 787 | } |
| 788 | |
| 789 | SBBreakpoint SBBreakpointList::GetBreakpointAtIndex(size_t idx) { |
| 790 | if (!m_opaque_sp) |
| 791 | return SBBreakpoint(); |
| 792 | |
| 793 | BreakpointSP bkpt_sp = m_opaque_sp->GetBreakpointAtIndex(idx); |
| 794 | return SBBreakpoint(bkpt_sp); |
| 795 | } |
| 796 | |
Jim Ingham | 6d1e469 | 2016-09-16 01:41:27 +0000 | [diff] [blame] | 797 | SBBreakpoint SBBreakpointList::FindBreakpointByID(lldb::break_id_t id) { |
| 798 | if (!m_opaque_sp) |
| 799 | return SBBreakpoint(); |
| 800 | BreakpointSP bkpt_sp = m_opaque_sp->FindBreakpointByID(id); |
| 801 | return SBBreakpoint(bkpt_sp); |
| 802 | } |
| 803 | |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 804 | void SBBreakpointList::Append(const SBBreakpoint &sb_bkpt) { |
| 805 | if (!sb_bkpt.IsValid()) |
| 806 | return; |
| 807 | if (!m_opaque_sp) |
| 808 | return; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 809 | m_opaque_sp->Append(sb_bkpt.m_opaque_wp.lock()); |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | void SBBreakpointList::AppendByID(lldb::break_id_t id) { |
| 813 | if (!m_opaque_sp) |
| 814 | return; |
| 815 | m_opaque_sp->AppendByID(id); |
| 816 | } |
| 817 | |
| 818 | bool SBBreakpointList::AppendIfUnique(const SBBreakpoint &sb_bkpt) { |
| 819 | if (!sb_bkpt.IsValid()) |
| 820 | return false; |
| 821 | if (!m_opaque_sp) |
| 822 | return false; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 823 | return m_opaque_sp->AppendIfUnique(sb_bkpt.GetSP()); |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | void SBBreakpointList::Clear() { |
| 827 | if (m_opaque_sp) |
| 828 | m_opaque_sp->Clear(); |
| 829 | } |
| 830 | |
| 831 | void SBBreakpointList::CopyToBreakpointIDList( |
| 832 | lldb_private::BreakpointIDList &bp_id_list) { |
| 833 | if (m_opaque_sp) |
| 834 | m_opaque_sp->CopyToBreakpointIDList(bp_id_list); |
| 835 | } |