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