Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SBBreakpointLocation.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/SBBreakpointLocation.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 | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 25 | #include "lldb/Utility/Log.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 26 | #include "lldb/Utility/Stream.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 27 | #include "lldb/lldb-defines.h" |
| 28 | #include "lldb/lldb-types.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | |
| 30 | using namespace lldb; |
| 31 | using namespace lldb_private; |
| 32 | |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 33 | SBBreakpointLocation::SBBreakpointLocation() {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 35 | SBBreakpointLocation::SBBreakpointLocation( |
| 36 | const lldb::BreakpointLocationSP &break_loc_sp) |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 37 | : m_opaque_wp(break_loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 38 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 39 | |
| 40 | if (log) { |
| 41 | SBStream sstr; |
| 42 | GetDescription(sstr, lldb::eDescriptionLevelBrief); |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 43 | LLDB_LOG(log, "location = {0} ({1})", break_loc_sp.get(), sstr.GetData()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 44 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 47 | SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs) |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 48 | : m_opaque_wp(rhs.m_opaque_wp) {} |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 49 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 50 | const SBBreakpointLocation &SBBreakpointLocation:: |
| 51 | operator=(const SBBreakpointLocation &rhs) { |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 52 | m_opaque_wp = rhs.m_opaque_wp; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 53 | return *this; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | SBBreakpointLocation::~SBBreakpointLocation() {} |
| 57 | |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 58 | BreakpointLocationSP SBBreakpointLocation::GetSP() const { |
| 59 | return m_opaque_wp.lock(); |
| 60 | } |
| 61 | |
| 62 | bool SBBreakpointLocation::IsValid() const { return bool(GetSP()); } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 63 | |
| 64 | SBAddress SBBreakpointLocation::GetAddress() { |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 65 | BreakpointLocationSP loc_sp = GetSP(); |
| 66 | if (loc_sp) |
| 67 | return SBAddress(&loc_sp->GetAddress()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 68 | else |
| 69 | return SBAddress(); |
Greg Clayton | efabb12 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 72 | addr_t SBBreakpointLocation::GetLoadAddress() { |
| 73 | addr_t ret_addr = LLDB_INVALID_ADDRESS; |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 74 | BreakpointLocationSP loc_sp = GetSP(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 75 | |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 76 | if (loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 77 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 78 | loc_sp->GetTarget().GetAPIMutex()); |
| 79 | ret_addr = loc_sp->GetLoadAddress(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | return ret_addr; |
Greg Clayton | efabb12 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 85 | void SBBreakpointLocation::SetEnabled(bool enabled) { |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 86 | BreakpointLocationSP loc_sp = GetSP(); |
| 87 | if (loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 88 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 89 | loc_sp->GetTarget().GetAPIMutex()); |
| 90 | loc_sp->SetEnabled(enabled); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 91 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 94 | bool SBBreakpointLocation::IsEnabled() { |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 95 | BreakpointLocationSP loc_sp = GetSP(); |
| 96 | if (loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 97 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 98 | loc_sp->GetTarget().GetAPIMutex()); |
| 99 | return loc_sp->IsEnabled(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 100 | } else |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 101 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Bruce Mitchener | ccbf798 | 2017-07-19 14:31:19 +0000 | [diff] [blame] | 104 | uint32_t SBBreakpointLocation::GetHitCount() { |
| 105 | BreakpointLocationSP loc_sp = GetSP(); |
| 106 | if (loc_sp) { |
| 107 | std::lock_guard<std::recursive_mutex> guard( |
| 108 | loc_sp->GetTarget().GetAPIMutex()); |
| 109 | return loc_sp->GetHitCount(); |
| 110 | } else |
| 111 | return 0; |
| 112 | } |
| 113 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 114 | uint32_t SBBreakpointLocation::GetIgnoreCount() { |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 115 | BreakpointLocationSP loc_sp = GetSP(); |
| 116 | if (loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 117 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 118 | loc_sp->GetTarget().GetAPIMutex()); |
| 119 | return loc_sp->GetIgnoreCount(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 120 | } else |
| 121 | return 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 124 | void SBBreakpointLocation::SetIgnoreCount(uint32_t n) { |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 125 | BreakpointLocationSP loc_sp = GetSP(); |
| 126 | if (loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 127 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 128 | loc_sp->GetTarget().GetAPIMutex()); |
| 129 | loc_sp->SetIgnoreCount(n); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 130 | } |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 133 | void SBBreakpointLocation::SetCondition(const char *condition) { |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 134 | BreakpointLocationSP loc_sp = GetSP(); |
| 135 | if (loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 136 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 137 | loc_sp->GetTarget().GetAPIMutex()); |
| 138 | loc_sp->SetCondition(condition); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 139 | } |
Jim Ingham | b08a944 | 2012-05-16 00:51:15 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 142 | const char *SBBreakpointLocation::GetCondition() { |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 143 | BreakpointLocationSP loc_sp = GetSP(); |
| 144 | if (loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 145 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 146 | loc_sp->GetTarget().GetAPIMutex()); |
| 147 | return loc_sp->GetConditionText(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 148 | } |
| 149 | return NULL; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Jim Ingham | f08f5c9 | 2017-08-03 18:13:24 +0000 | [diff] [blame] | 152 | void SBBreakpointLocation::SetAutoContinue(bool auto_continue) { |
| 153 | BreakpointLocationSP loc_sp = GetSP(); |
| 154 | if (loc_sp) { |
| 155 | std::lock_guard<std::recursive_mutex> guard( |
| 156 | loc_sp->GetTarget().GetAPIMutex()); |
| 157 | loc_sp->SetAutoContinue(auto_continue); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | bool SBBreakpointLocation::GetAutoContinue() { |
| 162 | BreakpointLocationSP loc_sp = GetSP(); |
| 163 | if (loc_sp) { |
| 164 | std::lock_guard<std::recursive_mutex> guard( |
| 165 | loc_sp->GetTarget().GetAPIMutex()); |
| 166 | return loc_sp->IsAutoContinue(); |
| 167 | } |
Jim Ingham | 1c7dc82 | 2017-08-03 19:38:38 +0000 | [diff] [blame] | 168 | return false; |
Jim Ingham | f08f5c9 | 2017-08-03 18:13:24 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 171 | void SBBreakpointLocation::SetScriptCallbackFunction( |
| 172 | const char *callback_function_name) { |
| 173 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 174 | BreakpointLocationSP loc_sp = GetSP(); |
| 175 | LLDB_LOG(log, "location = {0}, callback = {1}", loc_sp.get(), |
| 176 | callback_function_name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 177 | |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 178 | if (loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 179 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 180 | loc_sp->GetTarget().GetAPIMutex()); |
| 181 | BreakpointOptions *bp_options = loc_sp->GetLocationOptions(); |
| 182 | loc_sp->GetBreakpoint() |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 183 | .GetTarget() |
| 184 | .GetDebugger() |
| 185 | .GetCommandInterpreter() |
| 186 | .GetScriptInterpreter() |
| 187 | ->SetBreakpointCommandCallbackFunction(bp_options, |
| 188 | callback_function_name); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | SBError |
| 193 | SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) { |
| 194 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 195 | BreakpointLocationSP loc_sp = GetSP(); |
| 196 | LLDB_LOG(log, "location = {0}: callback body:\n{1}", loc_sp.get(), |
| 197 | callback_body_text); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 198 | |
| 199 | SBError sb_error; |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 200 | if (loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 201 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 202 | loc_sp->GetTarget().GetAPIMutex()); |
| 203 | BreakpointOptions *bp_options = loc_sp->GetLocationOptions(); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 204 | Status error = |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 205 | loc_sp->GetBreakpoint() |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 206 | .GetTarget() |
| 207 | .GetDebugger() |
| 208 | .GetCommandInterpreter() |
| 209 | .GetScriptInterpreter() |
| 210 | ->SetBreakpointCommandCallback(bp_options, callback_body_text); |
| 211 | sb_error.SetError(error); |
| 212 | } else |
| 213 | sb_error.SetErrorString("invalid breakpoint"); |
| 214 | |
| 215 | return sb_error; |
| 216 | } |
| 217 | |
Jim Ingham | af26b22 | 2017-08-02 00:16:10 +0000 | [diff] [blame] | 218 | void SBBreakpointLocation::SetCommandLineCommands(SBStringList &commands) { |
| 219 | BreakpointLocationSP loc_sp = GetSP(); |
| 220 | if (!loc_sp) |
| 221 | return; |
| 222 | if (commands.GetSize() == 0) |
| 223 | return; |
| 224 | |
| 225 | std::lock_guard<std::recursive_mutex> guard( |
| 226 | loc_sp->GetTarget().GetAPIMutex()); |
| 227 | std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up( |
| 228 | new BreakpointOptions::CommandData(*commands, eScriptLanguageNone)); |
| 229 | |
| 230 | loc_sp->GetLocationOptions()->SetCommandDataCallback(cmd_data_up); |
| 231 | } |
| 232 | |
| 233 | bool SBBreakpointLocation::GetCommandLineCommands(SBStringList &commands) { |
| 234 | BreakpointLocationSP loc_sp = GetSP(); |
| 235 | if (!loc_sp) |
| 236 | return false; |
| 237 | StringList command_list; |
| 238 | bool has_commands = |
| 239 | loc_sp->GetLocationOptions()->GetCommandLineCallbacks(command_list); |
| 240 | if (has_commands) |
| 241 | commands.AppendList(command_list); |
| 242 | return has_commands; |
| 243 | } |
| 244 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 245 | void SBBreakpointLocation::SetThreadID(tid_t thread_id) { |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 246 | BreakpointLocationSP loc_sp = GetSP(); |
| 247 | if (loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 248 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 249 | loc_sp->GetTarget().GetAPIMutex()); |
| 250 | loc_sp->SetThreadID(thread_id); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
| 254 | tid_t SBBreakpointLocation::GetThreadID() { |
| 255 | tid_t tid = LLDB_INVALID_THREAD_ID; |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 256 | BreakpointLocationSP loc_sp = GetSP(); |
| 257 | if (loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 258 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 259 | loc_sp->GetTarget().GetAPIMutex()); |
| 260 | return loc_sp->GetThreadID(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 261 | } |
| 262 | return tid; |
| 263 | } |
| 264 | |
| 265 | void SBBreakpointLocation::SetThreadIndex(uint32_t index) { |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 266 | BreakpointLocationSP loc_sp = GetSP(); |
| 267 | if (loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 268 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 269 | loc_sp->GetTarget().GetAPIMutex()); |
| 270 | loc_sp->SetThreadIndex(index); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | |
| 274 | uint32_t SBBreakpointLocation::GetThreadIndex() const { |
| 275 | uint32_t thread_idx = UINT32_MAX; |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 276 | BreakpointLocationSP loc_sp = GetSP(); |
| 277 | if (loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 278 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 279 | loc_sp->GetTarget().GetAPIMutex()); |
| 280 | return loc_sp->GetThreadIndex(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 281 | } |
| 282 | return thread_idx; |
| 283 | } |
| 284 | |
| 285 | void SBBreakpointLocation::SetThreadName(const char *thread_name) { |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 286 | BreakpointLocationSP loc_sp = GetSP(); |
| 287 | if (loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 288 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 289 | loc_sp->GetTarget().GetAPIMutex()); |
| 290 | loc_sp->SetThreadName(thread_name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | |
| 294 | const char *SBBreakpointLocation::GetThreadName() const { |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 295 | BreakpointLocationSP loc_sp = GetSP(); |
| 296 | if (loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 297 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 298 | loc_sp->GetTarget().GetAPIMutex()); |
| 299 | return loc_sp->GetThreadName(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 300 | } |
| 301 | return NULL; |
| 302 | } |
| 303 | |
| 304 | void SBBreakpointLocation::SetQueueName(const char *queue_name) { |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 305 | BreakpointLocationSP loc_sp = GetSP(); |
| 306 | if (loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 307 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 308 | loc_sp->GetTarget().GetAPIMutex()); |
| 309 | loc_sp->SetQueueName(queue_name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | |
| 313 | const char *SBBreakpointLocation::GetQueueName() const { |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 314 | BreakpointLocationSP loc_sp = GetSP(); |
| 315 | if (loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 316 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 317 | loc_sp->GetTarget().GetAPIMutex()); |
| 318 | loc_sp->GetQueueName(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 319 | } |
| 320 | return NULL; |
| 321 | } |
| 322 | |
| 323 | bool SBBreakpointLocation::IsResolved() { |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 324 | BreakpointLocationSP loc_sp = GetSP(); |
| 325 | if (loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 326 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 327 | loc_sp->GetTarget().GetAPIMutex()); |
| 328 | return loc_sp->IsResolved(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 329 | } |
| 330 | return false; |
| 331 | } |
| 332 | |
| 333 | void SBBreakpointLocation::SetLocation( |
| 334 | const lldb::BreakpointLocationSP &break_loc_sp) { |
| 335 | // Uninstall the callbacks? |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 336 | m_opaque_wp = break_loc_sp; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | bool SBBreakpointLocation::GetDescription(SBStream &description, |
| 340 | DescriptionLevel level) { |
| 341 | Stream &strm = description.ref(); |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 342 | BreakpointLocationSP loc_sp = GetSP(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 343 | |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 344 | if (loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 345 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 346 | loc_sp->GetTarget().GetAPIMutex()); |
| 347 | loc_sp->GetDescription(&strm, level); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 348 | strm.EOL(); |
| 349 | } else |
| 350 | strm.PutCString("No value"); |
| 351 | |
| 352 | return true; |
| 353 | } |
| 354 | |
| 355 | break_id_t SBBreakpointLocation::GetID() { |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 356 | BreakpointLocationSP loc_sp = GetSP(); |
| 357 | if (loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 358 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 359 | loc_sp->GetTarget().GetAPIMutex()); |
| 360 | return loc_sp->GetID(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 361 | } else |
| 362 | return LLDB_INVALID_BREAK_ID; |
| 363 | } |
| 364 | |
| 365 | SBBreakpoint SBBreakpointLocation::GetBreakpoint() { |
| 366 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 367 | BreakpointLocationSP loc_sp = GetSP(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 368 | |
| 369 | SBBreakpoint sb_bp; |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 370 | if (loc_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 371 | std::lock_guard<std::recursive_mutex> guard( |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 372 | loc_sp->GetTarget().GetAPIMutex()); |
| 373 | sb_bp = loc_sp->GetBreakpoint().shared_from_this(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | if (log) { |
| 377 | SBStream sstr; |
| 378 | sb_bp.GetDescription(sstr); |
Pavel Labath | c578943 | 2017-03-01 10:08:48 +0000 | [diff] [blame] | 379 | LLDB_LOG(log, "location = {0}, breakpoint = {1} ({2})", loc_sp.get(), |
| 380 | sb_bp.GetSP().get(), sstr.GetData()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 381 | } |
| 382 | return sb_bp; |
| 383 | } |