Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1 | //===-- SBBreakpointName.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 | // C Includes |
| 11 | // C++ Includes |
| 12 | // Other libraries and framework includes |
| 13 | // Project includes |
| 14 | #include "lldb/API/SBBreakpointName.h" |
| 15 | #include "lldb/API/SBDebugger.h" |
| 16 | #include "lldb/API/SBError.h" |
| 17 | #include "lldb/API/SBStream.h" |
| 18 | #include "lldb/API/SBStringList.h" |
| 19 | #include "lldb/API/SBTarget.h" |
| 20 | |
| 21 | #include "lldb/Breakpoint/BreakpointName.h" |
| 22 | #include "lldb/Breakpoint/StoppointCallbackContext.h" |
| 23 | #include "lldb/Core/Debugger.h" |
| 24 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 25 | #include "lldb/Interpreter/ScriptInterpreter.h" |
| 26 | #include "lldb/Target/Target.h" |
| 27 | #include "lldb/Target/ThreadSpec.h" |
| 28 | #include "lldb/Utility/Log.h" |
| 29 | #include "lldb/Utility/Stream.h" |
| 30 | |
| 31 | #include "SBBreakpointOptionCommon.h" |
| 32 | |
| 33 | using namespace lldb; |
| 34 | using namespace lldb_private; |
| 35 | |
| 36 | namespace lldb |
| 37 | { |
| 38 | class SBBreakpointNameImpl { |
| 39 | public: |
| 40 | SBBreakpointNameImpl(SBTarget &sb_target, const char *name) |
| 41 | { |
| 42 | if (!name || name[0] == '\0') |
| 43 | return; |
| 44 | m_name.assign(name); |
| 45 | |
| 46 | if (!sb_target.IsValid()) |
| 47 | return; |
| 48 | |
| 49 | TargetSP target_sp = sb_target.GetSP(); |
| 50 | if (!target_sp) |
| 51 | return; |
| 52 | |
| 53 | m_target_wp = target_sp; |
| 54 | } |
| 55 | |
| 56 | SBBreakpointNameImpl(TargetSP target_sp, const char *name) |
| 57 | { |
| 58 | if (!name || name[0] == '\0') |
| 59 | return; |
| 60 | m_name.assign(name); |
| 61 | |
| 62 | if (!target_sp) |
| 63 | return; |
| 64 | |
| 65 | m_target_wp = target_sp; |
| 66 | } |
| 67 | |
| 68 | bool operator==(const SBBreakpointNameImpl &rhs) { |
| 69 | return m_name == rhs.m_name |
| 70 | && m_target_wp.lock() == rhs.m_target_wp.lock(); |
| 71 | } |
| 72 | |
| 73 | bool operator!=(const SBBreakpointNameImpl &rhs) { |
| 74 | return m_name != rhs.m_name |
| 75 | || m_target_wp.lock() != rhs.m_target_wp.lock(); |
| 76 | } |
| 77 | // For now we take a simple approach and only keep the name, and relook |
| 78 | // up the location when we need it. |
| 79 | |
Jim Ingham | 576628b | 2017-09-15 17:54:37 +0000 | [diff] [blame] | 80 | TargetSP GetTarget() const { |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 81 | return m_target_wp.lock(); |
| 82 | } |
| 83 | |
Jim Ingham | 576628b | 2017-09-15 17:54:37 +0000 | [diff] [blame] | 84 | const char *GetName() const { |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 85 | return m_name.c_str(); |
| 86 | } |
| 87 | |
Jim Ingham | 576628b | 2017-09-15 17:54:37 +0000 | [diff] [blame] | 88 | bool IsValid() const { |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 89 | return !m_name.empty() && m_target_wp.lock(); |
| 90 | } |
| 91 | |
| 92 | lldb_private::BreakpointName *GetBreakpointName() |
| 93 | { |
| 94 | if (!IsValid()) |
| 95 | return nullptr; |
| 96 | TargetSP target_sp = GetTarget(); |
| 97 | if (!target_sp) |
| 98 | return nullptr; |
| 99 | Status error; |
| 100 | return target_sp->FindBreakpointName(ConstString(m_name), true, error); |
| 101 | } |
| 102 | |
| 103 | const lldb_private::BreakpointName *GetBreakpointName() const |
| 104 | { |
Jim Ingham | 576628b | 2017-09-15 17:54:37 +0000 | [diff] [blame] | 105 | if (!IsValid()) |
| 106 | return nullptr; |
| 107 | TargetSP target_sp = GetTarget(); |
| 108 | if (!target_sp) |
| 109 | return nullptr; |
| 110 | Status error; |
| 111 | return target_sp->FindBreakpointName(ConstString(m_name), true, error); |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | private: |
| 115 | TargetWP m_target_wp; |
| 116 | std::string m_name; |
| 117 | }; |
| 118 | } // namespace lldb |
| 119 | |
| 120 | SBBreakpointName::SBBreakpointName() {} |
| 121 | |
| 122 | SBBreakpointName::SBBreakpointName(SBTarget &sb_target, const char *name) |
| 123 | { |
| 124 | m_impl_up.reset(new SBBreakpointNameImpl(sb_target, name)); |
| 125 | // Call FindBreakpointName here to make sure the name is valid, reset if |
| 126 | // not: |
| 127 | BreakpointName *bp_name = GetBreakpointName(); |
| 128 | if (!bp_name) |
| 129 | m_impl_up.reset(); |
| 130 | } |
| 131 | |
| 132 | SBBreakpointName::SBBreakpointName(SBBreakpoint &sb_bkpt, const char *name) |
| 133 | { |
| 134 | if (!sb_bkpt.IsValid()) { |
| 135 | m_impl_up.reset(); |
| 136 | return; |
| 137 | } |
| 138 | BreakpointSP bkpt_sp = sb_bkpt.GetSP(); |
| 139 | Target &target = bkpt_sp->GetTarget(); |
| 140 | |
| 141 | m_impl_up.reset(new SBBreakpointNameImpl(target.shared_from_this(), name)); |
| 142 | |
| 143 | // Call FindBreakpointName here to make sure the name is valid, reset if |
| 144 | // not: |
| 145 | BreakpointName *bp_name = GetBreakpointName(); |
| 146 | if (!bp_name) { |
| 147 | m_impl_up.reset(); |
| 148 | return; |
| 149 | } |
| 150 | |
| 151 | // Now copy over the breakpoint's options: |
| 152 | target.ConfigureBreakpointName(*bp_name, *bkpt_sp->GetOptions(), |
| 153 | BreakpointName::Permissions()); |
| 154 | } |
| 155 | |
| 156 | SBBreakpointName::SBBreakpointName(const SBBreakpointName &rhs) |
| 157 | { |
| 158 | if (!rhs.m_impl_up) |
| 159 | return; |
| 160 | else |
| 161 | m_impl_up.reset(new SBBreakpointNameImpl(rhs.m_impl_up->GetTarget(), |
| 162 | rhs.m_impl_up->GetName())); |
| 163 | } |
| 164 | |
| 165 | SBBreakpointName::~SBBreakpointName() = default; |
| 166 | |
| 167 | const SBBreakpointName &SBBreakpointName::operator=(const SBBreakpointName &rhs) |
| 168 | { |
| 169 | if (!rhs.m_impl_up) { |
| 170 | m_impl_up.reset(); |
| 171 | return *this; |
| 172 | } |
| 173 | |
| 174 | m_impl_up.reset(new SBBreakpointNameImpl(rhs.m_impl_up->GetTarget(), |
| 175 | rhs.m_impl_up->GetName())); |
| 176 | return *this; |
| 177 | } |
| 178 | |
| 179 | bool SBBreakpointName::operator==(const lldb::SBBreakpointName &rhs) { |
| 180 | return *m_impl_up.get() == *rhs.m_impl_up.get(); |
| 181 | } |
| 182 | |
| 183 | bool SBBreakpointName::operator!=(const lldb::SBBreakpointName &rhs) { |
| 184 | return *m_impl_up.get() != *rhs.m_impl_up.get(); |
| 185 | } |
| 186 | |
| 187 | bool SBBreakpointName::IsValid() const { |
| 188 | if (!m_impl_up) |
| 189 | return false; |
| 190 | return m_impl_up->IsValid(); |
| 191 | } |
| 192 | |
| 193 | const char *SBBreakpointName::GetName() const { |
| 194 | if (!m_impl_up) |
| 195 | return "<Invalid Breakpoint Name Object>"; |
| 196 | return m_impl_up->GetName(); |
| 197 | } |
| 198 | |
| 199 | void SBBreakpointName::SetEnabled(bool enable) { |
| 200 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 201 | |
| 202 | BreakpointName *bp_name = GetBreakpointName(); |
| 203 | if (!bp_name) |
| 204 | return; |
| 205 | |
| 206 | LLDB_LOG(log, "Name: {0} enabled: {1}\n", bp_name->GetName(), enable); |
| 207 | std::lock_guard<std::recursive_mutex> guard( |
| 208 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 209 | |
| 210 | bp_name->GetOptions().SetEnabled(enable); |
| 211 | } |
| 212 | |
| 213 | void SBBreakpointName::UpdateName(BreakpointName &bp_name) { |
| 214 | if (!IsValid()) |
| 215 | return; |
| 216 | |
| 217 | TargetSP target_sp = m_impl_up->GetTarget(); |
| 218 | if (!target_sp) |
| 219 | return; |
| 220 | target_sp->ApplyNameToBreakpoints(bp_name); |
| 221 | |
| 222 | } |
| 223 | |
| 224 | bool SBBreakpointName::IsEnabled() { |
| 225 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 226 | |
| 227 | BreakpointName *bp_name = GetBreakpointName(); |
| 228 | if (!bp_name) |
| 229 | return false; |
| 230 | |
| 231 | LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); |
| 232 | std::lock_guard<std::recursive_mutex> guard( |
| 233 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 234 | |
| 235 | return bp_name->GetOptions().IsEnabled(); |
| 236 | } |
| 237 | |
| 238 | void SBBreakpointName::SetOneShot(bool one_shot) { |
| 239 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 240 | |
| 241 | BreakpointName *bp_name = GetBreakpointName(); |
| 242 | if (!bp_name) |
| 243 | return; |
| 244 | |
| 245 | LLDB_LOG(log, "Name: {0} one_shot: {1}\n", bp_name->GetName(), one_shot); |
| 246 | std::lock_guard<std::recursive_mutex> guard( |
| 247 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 248 | |
| 249 | bp_name->GetOptions().SetOneShot(one_shot); |
| 250 | UpdateName(*bp_name); |
| 251 | } |
| 252 | |
| 253 | bool SBBreakpointName::IsOneShot() const { |
| 254 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 255 | |
| 256 | const BreakpointName *bp_name = GetBreakpointName(); |
| 257 | if (!bp_name) |
| 258 | return false; |
| 259 | |
| 260 | LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); |
| 261 | std::lock_guard<std::recursive_mutex> guard( |
| 262 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 263 | |
| 264 | return bp_name->GetOptions().IsOneShot(); |
| 265 | } |
| 266 | |
| 267 | void SBBreakpointName::SetIgnoreCount(uint32_t count) { |
| 268 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 269 | |
| 270 | BreakpointName *bp_name = GetBreakpointName(); |
| 271 | if (!bp_name) |
| 272 | return; |
| 273 | |
| 274 | LLDB_LOG(log, "Name: {0} one_shot: {1}\n", bp_name->GetName(), count); |
| 275 | std::lock_guard<std::recursive_mutex> guard( |
| 276 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 277 | |
| 278 | bp_name->GetOptions().SetIgnoreCount(count); |
| 279 | UpdateName(*bp_name); |
| 280 | } |
| 281 | |
| 282 | uint32_t SBBreakpointName::GetIgnoreCount() const { |
| 283 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 284 | |
| 285 | BreakpointName *bp_name = GetBreakpointName(); |
| 286 | if (!bp_name) |
| 287 | return false; |
| 288 | |
| 289 | LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); |
| 290 | std::lock_guard<std::recursive_mutex> guard( |
| 291 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 292 | |
| 293 | return bp_name->GetOptions().GetIgnoreCount(); |
| 294 | } |
| 295 | |
| 296 | void SBBreakpointName::SetCondition(const char *condition) { |
| 297 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 298 | |
| 299 | BreakpointName *bp_name = GetBreakpointName(); |
| 300 | if (!bp_name) |
| 301 | return; |
| 302 | |
| 303 | LLDB_LOG(log, "Name: {0} one_shot: {1}\n", bp_name->GetName(), |
| 304 | condition ? condition : "<NULL>"); |
| 305 | |
| 306 | std::lock_guard<std::recursive_mutex> guard( |
| 307 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 308 | |
| 309 | bp_name->GetOptions().SetCondition(condition); |
| 310 | UpdateName(*bp_name); |
| 311 | } |
| 312 | |
| 313 | const char *SBBreakpointName::GetCondition() { |
| 314 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 315 | |
| 316 | BreakpointName *bp_name = GetBreakpointName(); |
| 317 | if (!bp_name) |
| 318 | return nullptr; |
| 319 | |
| 320 | LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); |
| 321 | std::lock_guard<std::recursive_mutex> guard( |
| 322 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 323 | |
| 324 | return bp_name->GetOptions().GetConditionText(); |
| 325 | } |
| 326 | |
| 327 | void SBBreakpointName::SetAutoContinue(bool auto_continue) { |
| 328 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 329 | |
| 330 | BreakpointName *bp_name = GetBreakpointName(); |
| 331 | if (!bp_name) |
| 332 | return; |
| 333 | |
| 334 | LLDB_LOG(log, "Name: {0} auto-continue: {1}\n", bp_name->GetName(), auto_continue); |
| 335 | |
| 336 | std::lock_guard<std::recursive_mutex> guard( |
| 337 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 338 | |
| 339 | bp_name->GetOptions().SetAutoContinue(auto_continue); |
| 340 | UpdateName(*bp_name); |
| 341 | } |
| 342 | |
| 343 | bool SBBreakpointName::GetAutoContinue() { |
| 344 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 345 | |
| 346 | BreakpointName *bp_name = GetBreakpointName(); |
| 347 | if (!bp_name) |
Jim Ingham | 576628b | 2017-09-15 17:54:37 +0000 | [diff] [blame] | 348 | return false; |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 349 | |
| 350 | LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); |
| 351 | std::lock_guard<std::recursive_mutex> guard( |
| 352 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 353 | |
| 354 | return bp_name->GetOptions().IsAutoContinue(); |
| 355 | } |
| 356 | |
| 357 | void SBBreakpointName::SetThreadID(tid_t tid) { |
| 358 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 359 | |
| 360 | BreakpointName *bp_name = GetBreakpointName(); |
| 361 | if (!bp_name) |
| 362 | return; |
| 363 | |
| 364 | LLDB_LOG(log, "Name: {0} tid: {1:x}\n", bp_name->GetName(), tid); |
| 365 | |
| 366 | std::lock_guard<std::recursive_mutex> guard( |
| 367 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 368 | |
| 369 | bp_name->GetOptions().SetThreadID(tid); |
| 370 | UpdateName(*bp_name); |
| 371 | } |
| 372 | |
| 373 | tid_t SBBreakpointName::GetThreadID() { |
| 374 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 375 | |
| 376 | BreakpointName *bp_name = GetBreakpointName(); |
| 377 | if (!bp_name) |
| 378 | return LLDB_INVALID_THREAD_ID; |
| 379 | |
| 380 | LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); |
| 381 | std::lock_guard<std::recursive_mutex> guard( |
| 382 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 383 | |
| 384 | return bp_name->GetOptions().GetThreadSpec()->GetTID(); |
| 385 | } |
| 386 | |
| 387 | void SBBreakpointName::SetThreadIndex(uint32_t index) { |
| 388 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 389 | |
| 390 | BreakpointName *bp_name = GetBreakpointName(); |
| 391 | if (!bp_name) |
| 392 | return; |
| 393 | |
| 394 | LLDB_LOG(log, "Name: {0} thread index: {1}\n", bp_name->GetName(), index); |
| 395 | |
| 396 | std::lock_guard<std::recursive_mutex> guard( |
| 397 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 398 | |
| 399 | bp_name->GetOptions().GetThreadSpec()->SetIndex(index); |
| 400 | UpdateName(*bp_name); |
| 401 | } |
| 402 | |
| 403 | uint32_t SBBreakpointName::GetThreadIndex() const { |
| 404 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 405 | |
| 406 | BreakpointName *bp_name = GetBreakpointName(); |
| 407 | if (!bp_name) |
| 408 | return LLDB_INVALID_THREAD_ID; |
| 409 | |
| 410 | LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); |
| 411 | std::lock_guard<std::recursive_mutex> guard( |
| 412 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 413 | |
| 414 | return bp_name->GetOptions().GetThreadSpec()->GetIndex(); |
| 415 | } |
| 416 | |
| 417 | void SBBreakpointName::SetThreadName(const char *thread_name) { |
| 418 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 419 | |
| 420 | BreakpointName *bp_name = GetBreakpointName(); |
| 421 | if (!bp_name) |
| 422 | return; |
| 423 | |
| 424 | LLDB_LOG(log, "Name: {0} thread name: {1}\n", bp_name->GetName(), thread_name); |
| 425 | |
| 426 | std::lock_guard<std::recursive_mutex> guard( |
| 427 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 428 | |
| 429 | bp_name->GetOptions().GetThreadSpec()->SetName(thread_name); |
| 430 | UpdateName(*bp_name); |
| 431 | } |
| 432 | |
| 433 | const char *SBBreakpointName::GetThreadName() const { |
| 434 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 435 | |
| 436 | BreakpointName *bp_name = GetBreakpointName(); |
| 437 | if (!bp_name) |
| 438 | return nullptr; |
| 439 | |
| 440 | LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); |
| 441 | std::lock_guard<std::recursive_mutex> guard( |
| 442 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 443 | |
| 444 | return bp_name->GetOptions().GetThreadSpec()->GetName(); |
| 445 | } |
| 446 | |
| 447 | void SBBreakpointName::SetQueueName(const char *queue_name) { |
| 448 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 449 | |
| 450 | BreakpointName *bp_name = GetBreakpointName(); |
| 451 | if (!bp_name) |
| 452 | return; |
| 453 | |
| 454 | LLDB_LOG(log, "Name: {0} queue name: {1}\n", bp_name->GetName(), queue_name); |
| 455 | |
| 456 | std::lock_guard<std::recursive_mutex> guard( |
| 457 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 458 | |
| 459 | bp_name->GetOptions().GetThreadSpec()->SetQueueName(queue_name); |
| 460 | UpdateName(*bp_name); |
| 461 | } |
| 462 | |
| 463 | const char *SBBreakpointName::GetQueueName() const { |
| 464 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 465 | |
| 466 | BreakpointName *bp_name = GetBreakpointName(); |
| 467 | if (!bp_name) |
| 468 | return nullptr; |
| 469 | |
| 470 | LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); |
| 471 | std::lock_guard<std::recursive_mutex> guard( |
| 472 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 473 | |
| 474 | return bp_name->GetOptions().GetThreadSpec()->GetQueueName(); |
| 475 | } |
| 476 | |
| 477 | void SBBreakpointName::SetCommandLineCommands(SBStringList &commands) { |
| 478 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 479 | BreakpointName *bp_name = GetBreakpointName(); |
| 480 | if (!bp_name) |
| 481 | return; |
| 482 | if (commands.GetSize() == 0) |
| 483 | return; |
| 484 | |
| 485 | LLDB_LOG(log, "Name: {0} commands\n", bp_name->GetName()); |
| 486 | |
| 487 | std::lock_guard<std::recursive_mutex> guard( |
| 488 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 489 | std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up( |
| 490 | new BreakpointOptions::CommandData(*commands, eScriptLanguageNone)); |
| 491 | |
| 492 | bp_name->GetOptions().SetCommandDataCallback(cmd_data_up); |
| 493 | UpdateName(*bp_name); |
| 494 | } |
| 495 | |
| 496 | bool SBBreakpointName::GetCommandLineCommands(SBStringList &commands) { |
| 497 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 498 | |
| 499 | BreakpointName *bp_name = GetBreakpointName(); |
| 500 | if (!bp_name) |
| 501 | return false; |
| 502 | |
| 503 | LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); |
| 504 | StringList command_list; |
| 505 | bool has_commands = |
| 506 | bp_name->GetOptions().GetCommandLineCallbacks(command_list); |
| 507 | if (has_commands) |
| 508 | commands.AppendList(command_list); |
| 509 | return has_commands; |
| 510 | } |
| 511 | |
Jim Ingham | e9632eb | 2017-09-15 00:52:35 +0000 | [diff] [blame] | 512 | const char *SBBreakpointName::GetHelpString() const { |
| 513 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 514 | |
| 515 | BreakpointName *bp_name = GetBreakpointName(); |
| 516 | if (!bp_name) |
| 517 | return ""; |
| 518 | |
| 519 | LLDB_LOG(log, "Help: {0}\n", bp_name->GetHelp()); |
| 520 | return bp_name->GetHelp(); |
| 521 | } |
| 522 | |
| 523 | void SBBreakpointName::SetHelpString(const char *help_string) { |
| 524 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 525 | BreakpointName *bp_name = GetBreakpointName(); |
| 526 | if (!bp_name) |
| 527 | return; |
| 528 | |
| 529 | LLDB_LOG(log, "Name: {0} help: {1}\n", bp_name->GetName(), help_string); |
| 530 | |
| 531 | std::lock_guard<std::recursive_mutex> guard( |
| 532 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 533 | bp_name->SetHelp(help_string); |
| 534 | } |
| 535 | |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 536 | bool SBBreakpointName::GetDescription(SBStream &s) { |
| 537 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 538 | |
| 539 | BreakpointName *bp_name = GetBreakpointName(); |
| 540 | if (!bp_name) |
| 541 | { |
| 542 | s.Printf("No value"); |
| 543 | return false; |
| 544 | } |
| 545 | |
| 546 | LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); |
| 547 | std::lock_guard<std::recursive_mutex> guard( |
| 548 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 549 | bp_name->GetDescription(s.get(), eDescriptionLevelFull); |
| 550 | return true; |
| 551 | } |
| 552 | |
| 553 | void SBBreakpointName::SetCallback(SBBreakpointHitCallback callback, |
| 554 | void *baton) { |
| 555 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 556 | BreakpointName *bp_name = GetBreakpointName(); |
| 557 | if (!bp_name) |
| 558 | return; |
| 559 | LLDB_LOG(log, "callback = {1}, baton = {2}", callback, baton); |
| 560 | std::lock_guard<std::recursive_mutex> guard( |
| 561 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 562 | |
| 563 | BatonSP baton_sp(new SBBreakpointCallbackBaton(callback, baton)); |
| 564 | bp_name->GetOptions().SetCallback(SBBreakpointCallbackBaton |
| 565 | ::PrivateBreakpointHitCallback, |
| 566 | baton_sp, |
| 567 | false); |
| 568 | UpdateName(*bp_name); |
| 569 | } |
| 570 | |
| 571 | void SBBreakpointName::SetScriptCallbackFunction( |
| 572 | const char *callback_function_name) { |
| 573 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 574 | |
| 575 | BreakpointName *bp_name = GetBreakpointName(); |
| 576 | if (!bp_name) |
| 577 | return; |
| 578 | |
| 579 | LLDB_LOG(log, "Name: {0} callback: {1}\n", bp_name->GetName(), |
| 580 | callback_function_name); |
| 581 | |
| 582 | std::lock_guard<std::recursive_mutex> guard( |
| 583 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 584 | |
| 585 | BreakpointOptions &bp_options = bp_name->GetOptions(); |
| 586 | m_impl_up->GetTarget() |
| 587 | ->GetDebugger() |
| 588 | .GetCommandInterpreter() |
| 589 | .GetScriptInterpreter() |
| 590 | ->SetBreakpointCommandCallbackFunction(&bp_options, |
| 591 | callback_function_name); |
| 592 | UpdateName(*bp_name); |
| 593 | } |
| 594 | |
| 595 | SBError SBBreakpointName::SetScriptCallbackBody(const char *callback_body_text) |
| 596 | { |
| 597 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 598 | SBError sb_error; |
| 599 | BreakpointName *bp_name = GetBreakpointName(); |
| 600 | if (!bp_name) |
| 601 | return sb_error; |
| 602 | |
| 603 | LLDB_LOG(log, "Name: {0} callback: {1}\n", bp_name->GetName(), |
| 604 | callback_body_text); |
| 605 | |
| 606 | std::lock_guard<std::recursive_mutex> guard( |
| 607 | m_impl_up->GetTarget()->GetAPIMutex()); |
| 608 | |
| 609 | BreakpointOptions &bp_options = bp_name->GetOptions(); |
| 610 | Status error = |
| 611 | m_impl_up->GetTarget() |
| 612 | ->GetDebugger() |
| 613 | .GetCommandInterpreter() |
| 614 | .GetScriptInterpreter() |
| 615 | ->SetBreakpointCommandCallback(&bp_options, callback_body_text); |
| 616 | sb_error.SetError(error); |
| 617 | if (!sb_error.Fail()) |
| 618 | UpdateName(*bp_name); |
| 619 | |
| 620 | return sb_error; |
| 621 | } |
| 622 | |
| 623 | bool SBBreakpointName::GetAllowList() const |
| 624 | { |
| 625 | BreakpointName *bp_name = GetBreakpointName(); |
| 626 | if (!bp_name) |
| 627 | return false; |
| 628 | return bp_name->GetPermissions().GetAllowList(); |
| 629 | } |
| 630 | |
| 631 | void SBBreakpointName::SetAllowList(bool value) |
| 632 | { |
| 633 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 634 | |
| 635 | BreakpointName *bp_name = GetBreakpointName(); |
| 636 | if (!bp_name) |
| 637 | return; |
| 638 | if (log) |
| 639 | log->Printf("Setting allow list to %u for %s.", value, |
| 640 | bp_name->GetName().AsCString()); |
| 641 | bp_name->GetPermissions().SetAllowList(value); |
| 642 | } |
| 643 | |
| 644 | bool SBBreakpointName::GetAllowDelete() |
| 645 | { |
| 646 | BreakpointName *bp_name = GetBreakpointName(); |
| 647 | if (!bp_name) |
| 648 | return false; |
| 649 | return bp_name->GetPermissions().GetAllowDelete(); |
| 650 | } |
| 651 | |
| 652 | void SBBreakpointName::SetAllowDelete(bool value) |
| 653 | { |
| 654 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 655 | |
| 656 | BreakpointName *bp_name = GetBreakpointName(); |
| 657 | if (!bp_name) |
| 658 | return; |
| 659 | if (log) |
| 660 | log->Printf("Setting allow delete to %u for %s.", value, |
| 661 | bp_name->GetName().AsCString()); |
| 662 | bp_name->GetPermissions().SetAllowDelete(value); |
| 663 | } |
| 664 | |
| 665 | bool SBBreakpointName::GetAllowDisable() |
| 666 | { |
| 667 | BreakpointName *bp_name = GetBreakpointName(); |
| 668 | if (!bp_name) |
| 669 | return false; |
| 670 | return bp_name->GetPermissions().GetAllowDisable(); |
| 671 | } |
| 672 | |
| 673 | void SBBreakpointName::SetAllowDisable(bool value) |
| 674 | { |
| 675 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 676 | |
| 677 | BreakpointName *bp_name = GetBreakpointName(); |
| 678 | if (!bp_name) |
| 679 | return; |
| 680 | if (log) |
| 681 | log->Printf("Setting allow disable to %u for %s.", value, |
| 682 | bp_name->GetName().AsCString()); |
| 683 | bp_name->GetPermissions().SetAllowDisable(value); |
| 684 | } |
| 685 | |
| 686 | lldb_private::BreakpointName *SBBreakpointName::GetBreakpointName() const |
| 687 | { |
| 688 | if (!IsValid()) |
| 689 | return nullptr; |
| 690 | return m_impl_up->GetBreakpointName(); |
| 691 | } |
| 692 | |