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" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | |
Greg Clayton | 4e78f60 | 2010-11-18 18:52:36 +0000 | [diff] [blame] | 16 | #include "lldb/Breakpoint/Breakpoint.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/Breakpoint/BreakpointLocation.h" |
Jim Ingham | d80102e | 2014-04-02 01:04:55 +0000 | [diff] [blame] | 18 | #include "lldb/Core/Debugger.h" |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 19 | #include "lldb/Core/Log.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | #include "lldb/Core/Stream.h" |
| 21 | #include "lldb/Core/StreamFile.h" |
Jim Ingham | d80102e | 2014-04-02 01:04:55 +0000 | [diff] [blame] | 22 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 23 | #include "lldb/Interpreter/ScriptInterpreter.h" |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 24 | #include "lldb/Target/Target.h" |
Jim Ingham | 62b02c6 | 2010-06-18 01:47:08 +0000 | [diff] [blame] | 25 | #include "lldb/Target/ThreadSpec.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 26 | #include "lldb/Target/ThreadSpec.h" |
| 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 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 33 | SBBreakpointLocation::SBBreakpointLocation() : m_opaque_sp() {} |
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) |
| 37 | : m_opaque_sp(break_loc_sp) { |
| 38 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 39 | |
| 40 | if (log) { |
| 41 | SBStream sstr; |
| 42 | GetDescription(sstr, lldb::eDescriptionLevelBrief); |
| 43 | log->Printf("SBBreakpointLocation::SBBreakpointLocaiton (const " |
| 44 | "lldb::BreakpointLocationsSP &break_loc_sp" |
| 45 | "=%p) => this.sp = %p (%s)", |
| 46 | static_cast<void *>(break_loc_sp.get()), |
| 47 | static_cast<void *>(m_opaque_sp.get()), sstr.GetData()); |
| 48 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 51 | SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs) |
| 52 | : m_opaque_sp(rhs.m_opaque_sp) {} |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 53 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 54 | const SBBreakpointLocation &SBBreakpointLocation:: |
| 55 | operator=(const SBBreakpointLocation &rhs) { |
| 56 | if (this != &rhs) |
| 57 | m_opaque_sp = rhs.m_opaque_sp; |
| 58 | return *this; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 61 | SBBreakpointLocation::~SBBreakpointLocation() {} |
| 62 | |
| 63 | bool SBBreakpointLocation::IsValid() const { return m_opaque_sp.get() != NULL; } |
| 64 | |
| 65 | SBAddress SBBreakpointLocation::GetAddress() { |
| 66 | if (m_opaque_sp) |
| 67 | return SBAddress(&m_opaque_sp->GetAddress()); |
| 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; |
| 74 | |
| 75 | if (m_opaque_sp) { |
| 76 | std::lock_guard<std::recursive_mutex> guard( |
| 77 | m_opaque_sp->GetTarget().GetAPIMutex()); |
| 78 | ret_addr = m_opaque_sp->GetLoadAddress(); |
| 79 | } |
| 80 | |
| 81 | return ret_addr; |
Greg Clayton | efabb12 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 84 | void SBBreakpointLocation::SetEnabled(bool enabled) { |
| 85 | if (m_opaque_sp) { |
| 86 | std::lock_guard<std::recursive_mutex> guard( |
| 87 | m_opaque_sp->GetTarget().GetAPIMutex()); |
| 88 | m_opaque_sp->SetEnabled(enabled); |
| 89 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 92 | bool SBBreakpointLocation::IsEnabled() { |
| 93 | if (m_opaque_sp) { |
| 94 | std::lock_guard<std::recursive_mutex> guard( |
| 95 | m_opaque_sp->GetTarget().GetAPIMutex()); |
| 96 | return m_opaque_sp->IsEnabled(); |
| 97 | } else |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 98 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 101 | uint32_t SBBreakpointLocation::GetIgnoreCount() { |
| 102 | if (m_opaque_sp) { |
| 103 | std::lock_guard<std::recursive_mutex> guard( |
| 104 | m_opaque_sp->GetTarget().GetAPIMutex()); |
| 105 | return m_opaque_sp->GetIgnoreCount(); |
| 106 | } else |
| 107 | return 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 110 | void SBBreakpointLocation::SetIgnoreCount(uint32_t n) { |
| 111 | if (m_opaque_sp) { |
| 112 | std::lock_guard<std::recursive_mutex> guard( |
| 113 | m_opaque_sp->GetTarget().GetAPIMutex()); |
| 114 | m_opaque_sp->SetIgnoreCount(n); |
| 115 | } |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 118 | void SBBreakpointLocation::SetCondition(const char *condition) { |
| 119 | if (m_opaque_sp) { |
| 120 | std::lock_guard<std::recursive_mutex> guard( |
| 121 | m_opaque_sp->GetTarget().GetAPIMutex()); |
| 122 | m_opaque_sp->SetCondition(condition); |
| 123 | } |
Jim Ingham | b08a944 | 2012-05-16 00:51:15 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 126 | const char *SBBreakpointLocation::GetCondition() { |
| 127 | if (m_opaque_sp) { |
| 128 | std::lock_guard<std::recursive_mutex> guard( |
| 129 | m_opaque_sp->GetTarget().GetAPIMutex()); |
| 130 | return m_opaque_sp->GetConditionText(); |
| 131 | } |
| 132 | return NULL; |
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 | void SBBreakpointLocation::SetScriptCallbackFunction( |
| 136 | const char *callback_function_name) { |
| 137 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 138 | |
| 139 | if (log) |
| 140 | log->Printf( |
| 141 | "SBBreakpointLocation(%p)::SetScriptCallbackFunction (callback=%s)", |
| 142 | static_cast<void *>(m_opaque_sp.get()), callback_function_name); |
| 143 | |
| 144 | if (m_opaque_sp) { |
| 145 | std::lock_guard<std::recursive_mutex> guard( |
| 146 | m_opaque_sp->GetTarget().GetAPIMutex()); |
| 147 | BreakpointOptions *bp_options = m_opaque_sp->GetLocationOptions(); |
| 148 | m_opaque_sp->GetBreakpoint() |
| 149 | .GetTarget() |
| 150 | .GetDebugger() |
| 151 | .GetCommandInterpreter() |
| 152 | .GetScriptInterpreter() |
| 153 | ->SetBreakpointCommandCallbackFunction(bp_options, |
| 154 | callback_function_name); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | SBError |
| 159 | SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) { |
| 160 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 161 | |
| 162 | if (log) |
| 163 | log->Printf("SBBreakpoint(%p)::SetScriptCallbackBody: callback body:\n%s)", |
| 164 | static_cast<void *>(m_opaque_sp.get()), callback_body_text); |
| 165 | |
| 166 | SBError sb_error; |
| 167 | if (m_opaque_sp) { |
| 168 | std::lock_guard<std::recursive_mutex> guard( |
| 169 | m_opaque_sp->GetTarget().GetAPIMutex()); |
| 170 | BreakpointOptions *bp_options = m_opaque_sp->GetLocationOptions(); |
| 171 | Error error = |
| 172 | m_opaque_sp->GetBreakpoint() |
| 173 | .GetTarget() |
| 174 | .GetDebugger() |
| 175 | .GetCommandInterpreter() |
| 176 | .GetScriptInterpreter() |
| 177 | ->SetBreakpointCommandCallback(bp_options, callback_body_text); |
| 178 | sb_error.SetError(error); |
| 179 | } else |
| 180 | sb_error.SetErrorString("invalid breakpoint"); |
| 181 | |
| 182 | return sb_error; |
| 183 | } |
| 184 | |
| 185 | void SBBreakpointLocation::SetThreadID(tid_t thread_id) { |
| 186 | if (m_opaque_sp) { |
| 187 | std::lock_guard<std::recursive_mutex> guard( |
| 188 | m_opaque_sp->GetTarget().GetAPIMutex()); |
| 189 | m_opaque_sp->SetThreadID(thread_id); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | tid_t SBBreakpointLocation::GetThreadID() { |
| 194 | tid_t tid = LLDB_INVALID_THREAD_ID; |
| 195 | if (m_opaque_sp) { |
| 196 | std::lock_guard<std::recursive_mutex> guard( |
| 197 | m_opaque_sp->GetTarget().GetAPIMutex()); |
| 198 | return m_opaque_sp->GetThreadID(); |
| 199 | } |
| 200 | return tid; |
| 201 | } |
| 202 | |
| 203 | void SBBreakpointLocation::SetThreadIndex(uint32_t index) { |
| 204 | if (m_opaque_sp) { |
| 205 | std::lock_guard<std::recursive_mutex> guard( |
| 206 | m_opaque_sp->GetTarget().GetAPIMutex()); |
| 207 | m_opaque_sp->SetThreadIndex(index); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | uint32_t SBBreakpointLocation::GetThreadIndex() const { |
| 212 | uint32_t thread_idx = UINT32_MAX; |
| 213 | if (m_opaque_sp) { |
| 214 | std::lock_guard<std::recursive_mutex> guard( |
| 215 | m_opaque_sp->GetTarget().GetAPIMutex()); |
| 216 | return m_opaque_sp->GetThreadIndex(); |
| 217 | } |
| 218 | return thread_idx; |
| 219 | } |
| 220 | |
| 221 | void SBBreakpointLocation::SetThreadName(const char *thread_name) { |
| 222 | if (m_opaque_sp) { |
| 223 | std::lock_guard<std::recursive_mutex> guard( |
| 224 | m_opaque_sp->GetTarget().GetAPIMutex()); |
| 225 | m_opaque_sp->SetThreadName(thread_name); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | const char *SBBreakpointLocation::GetThreadName() const { |
| 230 | if (m_opaque_sp) { |
| 231 | std::lock_guard<std::recursive_mutex> guard( |
| 232 | m_opaque_sp->GetTarget().GetAPIMutex()); |
| 233 | return m_opaque_sp->GetThreadName(); |
| 234 | } |
| 235 | return NULL; |
| 236 | } |
| 237 | |
| 238 | void SBBreakpointLocation::SetQueueName(const char *queue_name) { |
| 239 | if (m_opaque_sp) { |
| 240 | std::lock_guard<std::recursive_mutex> guard( |
| 241 | m_opaque_sp->GetTarget().GetAPIMutex()); |
| 242 | m_opaque_sp->SetQueueName(queue_name); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | const char *SBBreakpointLocation::GetQueueName() const { |
| 247 | if (m_opaque_sp) { |
| 248 | std::lock_guard<std::recursive_mutex> guard( |
| 249 | m_opaque_sp->GetTarget().GetAPIMutex()); |
| 250 | m_opaque_sp->GetQueueName(); |
| 251 | } |
| 252 | return NULL; |
| 253 | } |
| 254 | |
| 255 | bool SBBreakpointLocation::IsResolved() { |
| 256 | if (m_opaque_sp) { |
| 257 | std::lock_guard<std::recursive_mutex> guard( |
| 258 | m_opaque_sp->GetTarget().GetAPIMutex()); |
| 259 | return m_opaque_sp->IsResolved(); |
| 260 | } |
| 261 | return false; |
| 262 | } |
| 263 | |
| 264 | void SBBreakpointLocation::SetLocation( |
| 265 | const lldb::BreakpointLocationSP &break_loc_sp) { |
| 266 | // Uninstall the callbacks? |
| 267 | m_opaque_sp = break_loc_sp; |
| 268 | } |
| 269 | |
| 270 | bool SBBreakpointLocation::GetDescription(SBStream &description, |
| 271 | DescriptionLevel level) { |
| 272 | Stream &strm = description.ref(); |
| 273 | |
| 274 | if (m_opaque_sp) { |
| 275 | std::lock_guard<std::recursive_mutex> guard( |
| 276 | m_opaque_sp->GetTarget().GetAPIMutex()); |
| 277 | m_opaque_sp->GetDescription(&strm, level); |
| 278 | strm.EOL(); |
| 279 | } else |
| 280 | strm.PutCString("No value"); |
| 281 | |
| 282 | return true; |
| 283 | } |
| 284 | |
| 285 | break_id_t SBBreakpointLocation::GetID() { |
| 286 | if (m_opaque_sp) { |
| 287 | std::lock_guard<std::recursive_mutex> guard( |
| 288 | m_opaque_sp->GetTarget().GetAPIMutex()); |
| 289 | return m_opaque_sp->GetID(); |
| 290 | } else |
| 291 | return LLDB_INVALID_BREAK_ID; |
| 292 | } |
| 293 | |
| 294 | SBBreakpoint SBBreakpointLocation::GetBreakpoint() { |
| 295 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 296 | |
| 297 | // if (log) |
| 298 | // log->Printf ("SBBreakpointLocation::GetBreakpoint ()"); |
| 299 | |
| 300 | SBBreakpoint sb_bp; |
| 301 | if (m_opaque_sp) { |
| 302 | std::lock_guard<std::recursive_mutex> guard( |
| 303 | m_opaque_sp->GetTarget().GetAPIMutex()); |
| 304 | *sb_bp = m_opaque_sp->GetBreakpoint().shared_from_this(); |
| 305 | } |
| 306 | |
| 307 | if (log) { |
| 308 | SBStream sstr; |
| 309 | sb_bp.GetDescription(sstr); |
| 310 | log->Printf( |
| 311 | "SBBreakpointLocation(%p)::GetBreakpoint () => SBBreakpoint(%p) %s", |
| 312 | static_cast<void *>(m_opaque_sp.get()), |
| 313 | static_cast<void *>(sb_bp.get()), sstr.GetData()); |
| 314 | } |
| 315 | return sb_bp; |
| 316 | } |