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