1 //===-- SBDebugger.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/SBDebugger.h" 11 12 #include "lldb/lldb-private.h" 13 14 #include "lldb/API/SBListener.h" 15 #include "lldb/API/SBBroadcaster.h" 16 #include "lldb/API/SBCommandInterpreter.h" 17 #include "lldb/API/SBCommandReturnObject.h" 18 #include "lldb/API/SBError.h" 19 #include "lldb/API/SBEvent.h" 20 #include "lldb/API/SBFrame.h" 21 #include "lldb/API/SBInputReader.h" 22 #include "lldb/API/SBProcess.h" 23 #include "lldb/API/SBSourceManager.h" 24 #include "lldb/API/SBStream.h" 25 #include "lldb/API/SBStringList.h" 26 #include "lldb/API/SBTarget.h" 27 #include "lldb/API/SBThread.h" 28 #include "lldb/Core/Debugger.h" 29 #include "lldb/Core/State.h" 30 #include "lldb/Interpreter/Args.h" 31 #include "lldb/Interpreter/CommandInterpreter.h" 32 #include "lldb/Interpreter/OptionGroupPlatform.h" 33 #include "lldb/Target/Process.h" 34 #include "lldb/Target/TargetList.h" 35 36 using namespace lldb; 37 using namespace lldb_private; 38 39 void 40 SBDebugger::Initialize () 41 { 42 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 43 44 if (log) 45 log->Printf ("SBDebugger::Initialize ()"); 46 47 SBCommandInterpreter::InitializeSWIG (); 48 49 Debugger::Initialize(); 50 } 51 52 void 53 SBDebugger::Terminate () 54 { 55 Debugger::Terminate(); 56 } 57 58 void 59 SBDebugger::Clear () 60 { 61 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 62 63 if (log) 64 log->Printf ("SBDebugger(%p)::Clear ()", m_opaque_sp.get()); 65 66 if (m_opaque_sp) 67 m_opaque_sp->CleanUpInputReaders (); 68 69 m_opaque_sp.reset(); 70 } 71 72 SBDebugger 73 SBDebugger::Create() 74 { 75 return SBDebugger::Create(false); 76 } 77 78 SBDebugger 79 SBDebugger::Create(bool source_init_files) 80 { 81 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 82 83 SBDebugger debugger; 84 debugger.reset(Debugger::CreateInstance()); 85 86 if (log) 87 { 88 SBStream sstr; 89 debugger.GetDescription (sstr); 90 log->Printf ("SBDebugger::Create () => SBDebugger(%p): %s", debugger.m_opaque_sp.get(), sstr.GetData()); 91 } 92 93 SBCommandInterpreter interp = debugger.GetCommandInterpreter(); 94 if (source_init_files) 95 { 96 interp.get()->SkipLLDBInitFiles(false); 97 interp.get()->SkipAppInitFiles (false); 98 SBCommandReturnObject result; 99 interp.SourceInitFileInHomeDirectory(result); 100 } 101 else 102 { 103 interp.get()->SkipLLDBInitFiles(true); 104 interp.get()->SkipAppInitFiles (true); 105 } 106 return debugger; 107 } 108 109 void 110 SBDebugger::Destroy (SBDebugger &debugger) 111 { 112 LogSP log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 113 114 if (log) 115 { 116 SBStream sstr; 117 debugger.GetDescription (sstr); 118 log->Printf ("SBDebugger::Destroy () => SBDebugger(%p): %s", debugger.m_opaque_sp.get(), sstr.GetData()); 119 } 120 121 Debugger::Destroy (debugger.m_opaque_sp); 122 123 if (debugger.m_opaque_sp.get() != NULL) 124 debugger.m_opaque_sp.reset(); 125 } 126 127 SBDebugger::SBDebugger () : 128 m_opaque_sp () 129 { 130 } 131 132 SBDebugger::SBDebugger(const lldb::DebuggerSP &debugger_sp) : 133 m_opaque_sp(debugger_sp) 134 { 135 } 136 137 SBDebugger::SBDebugger(const SBDebugger &rhs) : 138 m_opaque_sp (rhs.m_opaque_sp) 139 { 140 } 141 142 SBDebugger & 143 SBDebugger::operator = (const SBDebugger &rhs) 144 { 145 if (this != &rhs) 146 { 147 m_opaque_sp = rhs.m_opaque_sp; 148 } 149 return *this; 150 } 151 152 SBDebugger::~SBDebugger () 153 { 154 } 155 156 bool 157 SBDebugger::IsValid() const 158 { 159 return m_opaque_sp.get() != NULL; 160 } 161 162 163 void 164 SBDebugger::SetAsync (bool b) 165 { 166 if (m_opaque_sp) 167 m_opaque_sp->SetAsyncExecution(b); 168 } 169 170 bool 171 SBDebugger::GetAsync () 172 { 173 if (m_opaque_sp) 174 return m_opaque_sp->GetAsyncExecution(); 175 else 176 return false; 177 } 178 179 void 180 SBDebugger::SkipLLDBInitFiles (bool b) 181 { 182 if (m_opaque_sp) 183 m_opaque_sp->GetCommandInterpreter().SkipLLDBInitFiles (b); 184 } 185 186 void 187 SBDebugger::SkipAppInitFiles (bool b) 188 { 189 if (m_opaque_sp) 190 m_opaque_sp->GetCommandInterpreter().SkipAppInitFiles (b); 191 } 192 193 // Shouldn't really be settable after initialization as this could cause lots of problems; don't want users 194 // trying to switch modes in the middle of a debugging session. 195 void 196 SBDebugger::SetInputFileHandle (FILE *fh, bool transfer_ownership) 197 { 198 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 199 200 if (log) 201 log->Printf ("SBDebugger(%p)::SetInputFileHandle (fh=%p, transfer_ownership=%i)", m_opaque_sp.get(), 202 fh, transfer_ownership); 203 204 if (m_opaque_sp) 205 m_opaque_sp->SetInputFileHandle (fh, transfer_ownership); 206 } 207 208 void 209 SBDebugger::SetOutputFileHandle (FILE *fh, bool transfer_ownership) 210 { 211 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 212 213 214 if (log) 215 log->Printf ("SBDebugger(%p)::SetOutputFileHandle (fh=%p, transfer_ownership=%i)", m_opaque_sp.get(), 216 fh, transfer_ownership); 217 218 if (m_opaque_sp) 219 m_opaque_sp->SetOutputFileHandle (fh, transfer_ownership); 220 } 221 222 void 223 SBDebugger::SetErrorFileHandle (FILE *fh, bool transfer_ownership) 224 { 225 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 226 227 228 if (log) 229 log->Printf ("SBDebugger(%p)::SetErrorFileHandle (fh=%p, transfer_ownership=%i)", m_opaque_sp.get(), 230 fh, transfer_ownership); 231 232 if (m_opaque_sp) 233 m_opaque_sp->SetErrorFileHandle (fh, transfer_ownership); 234 } 235 236 FILE * 237 SBDebugger::GetInputFileHandle () 238 { 239 if (m_opaque_sp) 240 return m_opaque_sp->GetInputFile().GetStream(); 241 return NULL; 242 } 243 244 FILE * 245 SBDebugger::GetOutputFileHandle () 246 { 247 if (m_opaque_sp) 248 return m_opaque_sp->GetOutputFile().GetStream(); 249 return NULL; 250 } 251 252 FILE * 253 SBDebugger::GetErrorFileHandle () 254 { 255 if (m_opaque_sp) 256 return m_opaque_sp->GetErrorFile().GetStream(); 257 return NULL; 258 } 259 260 SBCommandInterpreter 261 SBDebugger::GetCommandInterpreter () 262 { 263 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 264 265 SBCommandInterpreter sb_interpreter; 266 if (m_opaque_sp) 267 sb_interpreter.reset (&m_opaque_sp->GetCommandInterpreter()); 268 269 if (log) 270 log->Printf ("SBDebugger(%p)::GetCommandInterpreter () => SBCommandInterpreter(%p)", 271 m_opaque_sp.get(), sb_interpreter.get()); 272 273 return sb_interpreter; 274 } 275 276 void 277 SBDebugger::HandleCommand (const char *command) 278 { 279 if (m_opaque_sp) 280 { 281 TargetSP target_sp (m_opaque_sp->GetSelectedTarget()); 282 Mutex::Locker api_locker; 283 if (target_sp) 284 api_locker.Reset(target_sp->GetAPIMutex().GetMutex()); 285 286 SBCommandInterpreter sb_interpreter(GetCommandInterpreter ()); 287 SBCommandReturnObject result; 288 289 sb_interpreter.HandleCommand (command, result, false); 290 291 if (GetErrorFileHandle() != NULL) 292 result.PutError (GetErrorFileHandle()); 293 if (GetOutputFileHandle() != NULL) 294 result.PutOutput (GetOutputFileHandle()); 295 296 if (m_opaque_sp->GetAsyncExecution() == false) 297 { 298 SBProcess process(GetCommandInterpreter().GetProcess ()); 299 if (process.IsValid()) 300 { 301 EventSP event_sp; 302 Listener &lldb_listener = m_opaque_sp->GetListener(); 303 while (lldb_listener.GetNextEventForBroadcaster (process.get(), event_sp)) 304 { 305 SBEvent event(event_sp); 306 HandleProcessEvent (process, event, GetOutputFileHandle(), GetErrorFileHandle()); 307 } 308 } 309 } 310 } 311 } 312 313 SBListener 314 SBDebugger::GetListener () 315 { 316 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 317 318 SBListener sb_listener; 319 if (m_opaque_sp) 320 sb_listener.reset(&m_opaque_sp->GetListener(), false); 321 322 if (log) 323 log->Printf ("SBDebugger(%p)::GetListener () => SBListener(%p)", m_opaque_sp.get(), 324 sb_listener.get()); 325 326 return sb_listener; 327 } 328 329 void 330 SBDebugger::HandleProcessEvent (const SBProcess &process, const SBEvent &event, FILE *out, FILE *err) 331 { 332 if (!process.IsValid()) 333 return; 334 335 const uint32_t event_type = event.GetType(); 336 char stdio_buffer[1024]; 337 size_t len; 338 339 Mutex::Locker api_locker (process.GetTarget()->GetAPIMutex()); 340 341 if (event_type & (Process::eBroadcastBitSTDOUT | Process::eBroadcastBitStateChanged)) 342 { 343 // Drain stdout when we stop just in case we have any bytes 344 while ((len = process.GetSTDOUT (stdio_buffer, sizeof (stdio_buffer))) > 0) 345 if (out != NULL) 346 ::fwrite (stdio_buffer, 1, len, out); 347 } 348 349 if (event_type & (Process::eBroadcastBitSTDERR | Process::eBroadcastBitStateChanged)) 350 { 351 // Drain stderr when we stop just in case we have any bytes 352 while ((len = process.GetSTDERR (stdio_buffer, sizeof (stdio_buffer))) > 0) 353 if (err != NULL) 354 ::fwrite (stdio_buffer, 1, len, err); 355 } 356 357 if (event_type & Process::eBroadcastBitStateChanged) 358 { 359 StateType event_state = SBProcess::GetStateFromEvent (event); 360 361 if (event_state == eStateInvalid) 362 return; 363 364 bool is_stopped = StateIsStoppedState (event_state); 365 if (!is_stopped) 366 process.ReportEventState (event, out); 367 } 368 } 369 370 SBSourceManager 371 SBDebugger::GetSourceManager () 372 { 373 SBSourceManager sb_source_manager (*this); 374 return sb_source_manager; 375 } 376 377 378 bool 379 SBDebugger::GetDefaultArchitecture (char *arch_name, size_t arch_name_len) 380 { 381 if (arch_name && arch_name_len) 382 { 383 ArchSpec default_arch = Target::GetDefaultArchitecture (); 384 385 if (default_arch.IsValid()) 386 { 387 const std::string &triple_str = default_arch.GetTriple().str(); 388 if (!triple_str.empty()) 389 ::snprintf (arch_name, arch_name_len, "%s", triple_str.c_str()); 390 else 391 ::snprintf (arch_name, arch_name_len, "%s", default_arch.GetArchitectureName()); 392 return true; 393 } 394 } 395 if (arch_name && arch_name_len) 396 arch_name[0] = '\0'; 397 return false; 398 } 399 400 401 bool 402 SBDebugger::SetDefaultArchitecture (const char *arch_name) 403 { 404 if (arch_name) 405 { 406 ArchSpec arch (arch_name, NULL); 407 if (arch.IsValid()) 408 { 409 Target::SetDefaultArchitecture (arch); 410 return true; 411 } 412 } 413 return false; 414 } 415 416 ScriptLanguage 417 SBDebugger::GetScriptingLanguage (const char *script_language_name) 418 { 419 420 return Args::StringToScriptLanguage (script_language_name, 421 eScriptLanguageDefault, 422 NULL); 423 } 424 425 const char * 426 SBDebugger::GetVersionString () 427 { 428 return GetVersion(); 429 } 430 431 const char * 432 SBDebugger::StateAsCString (StateType state) 433 { 434 return lldb_private::StateAsCString (state); 435 } 436 437 bool 438 SBDebugger::StateIsRunningState (StateType state) 439 { 440 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 441 442 const bool result = lldb_private::StateIsRunningState (state); 443 if (log) 444 log->Printf ("SBDebugger::StateIsRunningState (state=%s) => %i", 445 StateAsCString (state), result); 446 447 return result; 448 } 449 450 bool 451 SBDebugger::StateIsStoppedState (StateType state) 452 { 453 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 454 455 const bool result = lldb_private::StateIsStoppedState (state); 456 if (log) 457 log->Printf ("SBDebugger::StateIsStoppedState (state=%s) => %i", 458 StateAsCString (state), result); 459 460 return result; 461 } 462 463 lldb::SBTarget 464 SBDebugger::CreateTarget (const char *filename, 465 const char *target_triple, 466 const char *platform_name, 467 bool add_dependent_modules, 468 lldb::SBError& sb_error) 469 { 470 SBTarget sb_target; 471 if (m_opaque_sp) 472 { 473 sb_error.Clear(); 474 FileSpec filename_spec (filename, true); 475 OptionGroupPlatform platform_options (false); 476 platform_options.SetPlatformName (platform_name); 477 478 TargetSP target_sp; 479 sb_error.ref() = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, 480 filename_spec, 481 target_triple, 482 add_dependent_modules, 483 &platform_options, 484 target_sp); 485 486 if (sb_error.Success()) 487 sb_target.reset (target_sp); 488 } 489 else 490 { 491 sb_error.SetErrorString("invalid target"); 492 } 493 494 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 495 if (log) 496 { 497 log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\", triple=%s, platform_name=%s, add_dependent_modules=%u, error=%s) => SBTarget(%p)", 498 m_opaque_sp.get(), 499 filename, 500 target_triple, 501 platform_name, 502 add_dependent_modules, 503 sb_error.GetCString(), 504 sb_target.get()); 505 } 506 507 return sb_target; 508 } 509 510 SBTarget 511 SBDebugger::CreateTargetWithFileAndTargetTriple (const char *filename, 512 const char *target_triple) 513 { 514 SBTarget target; 515 if (m_opaque_sp) 516 { 517 FileSpec file_spec (filename, true); 518 TargetSP target_sp; 519 const bool add_dependent_modules = true; 520 Error error (m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, 521 file_spec, 522 target_triple, 523 add_dependent_modules, 524 NULL, 525 target_sp)); 526 target.reset (target_sp); 527 } 528 529 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 530 if (log) 531 { 532 log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndTargetTriple (filename=\"%s\", triple=%s) => SBTarget(%p)", 533 m_opaque_sp.get(), filename, target_triple, target.get()); 534 } 535 536 return target; 537 } 538 539 SBTarget 540 SBDebugger::CreateTargetWithFileAndArch (const char *filename, const char *arch_cstr) 541 { 542 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 543 544 SBTarget target; 545 if (m_opaque_sp) 546 { 547 FileSpec file (filename, true); 548 TargetSP target_sp; 549 Error error; 550 const bool add_dependent_modules = true; 551 552 error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, 553 file, 554 arch_cstr, 555 add_dependent_modules, 556 NULL, 557 target_sp); 558 559 if (error.Success()) 560 { 561 m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get()); 562 target.reset(target_sp); 563 } 564 } 565 566 if (log) 567 { 568 log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", arch=%s) => SBTarget(%p)", 569 m_opaque_sp.get(), filename, arch_cstr, target.get()); 570 } 571 572 return target; 573 } 574 575 SBTarget 576 SBDebugger::CreateTarget (const char *filename) 577 { 578 SBTarget target; 579 if (m_opaque_sp) 580 { 581 FileSpec file (filename, true); 582 ArchSpec arch = Target::GetDefaultArchitecture (); 583 TargetSP target_sp; 584 Error error; 585 const bool add_dependent_modules = true; 586 587 error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, 588 file, 589 arch, 590 add_dependent_modules, 591 m_opaque_sp->GetPlatformList().GetSelectedPlatform(), 592 target_sp); 593 594 if (error.Success()) 595 { 596 m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get()); 597 target.reset (target_sp); 598 } 599 } 600 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 601 if (log) 602 { 603 log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)", 604 m_opaque_sp.get(), filename, target.get()); 605 } 606 return target; 607 } 608 609 bool 610 SBDebugger::DeleteTarget (lldb::SBTarget &target) 611 { 612 bool result = false; 613 if (m_opaque_sp) 614 { 615 // No need to lock, the target list is thread safe 616 result = m_opaque_sp->GetTargetList().DeleteTarget (target.m_opaque_sp); 617 target->Destroy(); 618 target.Clear(); 619 ModuleList::RemoveOrphanSharedModules(); 620 } 621 622 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 623 if (log) 624 { 625 log->Printf ("SBDebugger(%p)::DeleteTarget (SBTarget(%p)) => %i", m_opaque_sp.get(), target.m_opaque_sp.get(), result); 626 } 627 628 return result; 629 } 630 SBTarget 631 SBDebugger::GetTargetAtIndex (uint32_t idx) 632 { 633 SBTarget sb_target; 634 if (m_opaque_sp) 635 { 636 // No need to lock, the target list is thread safe 637 sb_target.reset(m_opaque_sp->GetTargetList().GetTargetAtIndex (idx)); 638 } 639 return sb_target; 640 } 641 642 SBTarget 643 SBDebugger::FindTargetWithProcessID (pid_t pid) 644 { 645 SBTarget sb_target; 646 if (m_opaque_sp) 647 { 648 // No need to lock, the target list is thread safe 649 sb_target.reset(m_opaque_sp->GetTargetList().FindTargetWithProcessID (pid)); 650 } 651 return sb_target; 652 } 653 654 SBTarget 655 SBDebugger::FindTargetWithFileAndArch (const char *filename, const char *arch_name) 656 { 657 SBTarget sb_target; 658 if (m_opaque_sp && filename && filename[0]) 659 { 660 // No need to lock, the target list is thread safe 661 ArchSpec arch (arch_name, m_opaque_sp->GetPlatformList().GetSelectedPlatform().get()); 662 TargetSP target_sp (m_opaque_sp->GetTargetList().FindTargetWithExecutableAndArchitecture (FileSpec(filename, false), arch_name ? &arch : NULL)); 663 sb_target.reset(target_sp); 664 } 665 return sb_target; 666 } 667 668 SBTarget 669 SBDebugger::FindTargetWithLLDBProcess (const ProcessSP &process_sp) 670 { 671 SBTarget sb_target; 672 if (m_opaque_sp) 673 { 674 // No need to lock, the target list is thread safe 675 sb_target.reset(m_opaque_sp->GetTargetList().FindTargetWithProcess (process_sp.get())); 676 } 677 return sb_target; 678 } 679 680 681 uint32_t 682 SBDebugger::GetNumTargets () 683 { 684 if (m_opaque_sp) 685 { 686 // No need to lock, the target list is thread safe 687 return m_opaque_sp->GetTargetList().GetNumTargets (); 688 } 689 return 0; 690 } 691 692 SBTarget 693 SBDebugger::GetSelectedTarget () 694 { 695 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 696 697 SBTarget sb_target; 698 if (m_opaque_sp) 699 { 700 // No need to lock, the target list is thread safe 701 sb_target.reset(m_opaque_sp->GetTargetList().GetSelectedTarget ()); 702 } 703 704 if (log) 705 { 706 SBStream sstr; 707 sb_target.GetDescription (sstr, eDescriptionLevelBrief); 708 log->Printf ("SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s", m_opaque_sp.get(), 709 sb_target.get(), sstr.GetData()); 710 } 711 712 return sb_target; 713 } 714 715 void 716 SBDebugger::SetSelectedTarget (SBTarget &sb_target) 717 { 718 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 719 720 if (m_opaque_sp) 721 { 722 m_opaque_sp->GetTargetList().SetSelectedTarget (sb_target.get()); 723 } 724 if (log) 725 { 726 SBStream sstr; 727 sb_target.GetDescription (sstr, eDescriptionLevelBrief); 728 log->Printf ("SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s", m_opaque_sp.get(), 729 sb_target.get(), sstr.GetData()); 730 } 731 } 732 733 void 734 SBDebugger::DispatchInput (void *baton, const void *data, size_t data_len) 735 { 736 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 737 738 if (log) 739 log->Printf ("SBDebugger(%p)::DispatchInput (baton=%p, data=\"%.*s\", size_t=%zu)", m_opaque_sp.get(), 740 baton, (int) data_len, (const char *) data, data_len); 741 742 if (m_opaque_sp) 743 m_opaque_sp->DispatchInput ((const char *) data, data_len); 744 } 745 746 void 747 SBDebugger::DispatchInputInterrupt () 748 { 749 if (m_opaque_sp) 750 m_opaque_sp->DispatchInputInterrupt (); 751 } 752 753 void 754 SBDebugger::DispatchInputEndOfFile () 755 { 756 if (m_opaque_sp) 757 m_opaque_sp->DispatchInputEndOfFile (); 758 } 759 760 bool 761 SBDebugger::InputReaderIsTopReader (const lldb::SBInputReader &reader) 762 { 763 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 764 765 if (log) 766 log->Printf ("SBDebugger(%p)::InputReaderIsTopReader (SBInputReader(%p))", m_opaque_sp.get(), &reader); 767 768 if (m_opaque_sp && reader.IsValid()) 769 { 770 InputReaderSP reader_sp (*reader); 771 return m_opaque_sp->InputReaderIsTopReader (reader_sp); 772 } 773 774 return false; 775 } 776 777 778 void 779 SBDebugger::PushInputReader (SBInputReader &reader) 780 { 781 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 782 783 if (log) 784 log->Printf ("SBDebugger(%p)::PushInputReader (SBInputReader(%p))", m_opaque_sp.get(), &reader); 785 786 if (m_opaque_sp && reader.IsValid()) 787 { 788 TargetSP target_sp (m_opaque_sp->GetSelectedTarget()); 789 Mutex::Locker api_locker; 790 if (target_sp) 791 api_locker.Reset(target_sp->GetAPIMutex().GetMutex()); 792 InputReaderSP reader_sp(*reader); 793 m_opaque_sp->PushInputReader (reader_sp); 794 } 795 } 796 797 void 798 SBDebugger::NotifyTopInputReader (InputReaderAction notification) 799 { 800 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 801 802 if (log) 803 log->Printf ("SBDebugger(%p)::NotifyTopInputReader (%d)", m_opaque_sp.get(), notification); 804 805 if (m_opaque_sp) 806 m_opaque_sp->NotifyTopInputReader (notification); 807 } 808 809 void 810 SBDebugger::reset (const DebuggerSP &debugger_sp) 811 { 812 m_opaque_sp = debugger_sp; 813 } 814 815 Debugger * 816 SBDebugger::get () const 817 { 818 return m_opaque_sp.get(); 819 } 820 821 Debugger & 822 SBDebugger::ref () const 823 { 824 assert (m_opaque_sp.get()); 825 return *m_opaque_sp; 826 } 827 828 const lldb::DebuggerSP & 829 SBDebugger::get_sp () const 830 { 831 return m_opaque_sp; 832 } 833 834 SBDebugger 835 SBDebugger::FindDebuggerWithID (int id) 836 { 837 // No need to lock, the debugger list is thread safe 838 SBDebugger sb_debugger; 839 DebuggerSP debugger_sp = Debugger::FindDebuggerWithID (id); 840 if (debugger_sp) 841 sb_debugger.reset (debugger_sp); 842 return sb_debugger; 843 } 844 845 const char * 846 SBDebugger::GetInstanceName() 847 { 848 if (m_opaque_sp) 849 return m_opaque_sp->GetInstanceName().AsCString(); 850 else 851 return NULL; 852 } 853 854 SBError 855 SBDebugger::SetInternalVariable (const char *var_name, const char *value, const char *debugger_instance_name) 856 { 857 UserSettingsControllerSP root_settings_controller = Debugger::GetSettingsController(); 858 859 Error err = root_settings_controller->SetVariable (var_name, 860 value, 861 eVarSetOperationAssign, 862 true, 863 debugger_instance_name); 864 SBError sb_error; 865 sb_error.SetError (err); 866 867 return sb_error; 868 } 869 870 SBStringList 871 SBDebugger::GetInternalVariableValue (const char *var_name, const char *debugger_instance_name) 872 { 873 SBStringList ret_value; 874 SettableVariableType var_type; 875 Error err; 876 877 UserSettingsControllerSP root_settings_controller = Debugger::GetSettingsController(); 878 879 StringList value = root_settings_controller->GetVariable (var_name, var_type, debugger_instance_name, err); 880 881 if (err.Success()) 882 { 883 for (unsigned i = 0; i != value.GetSize(); ++i) 884 ret_value.AppendString (value.GetStringAtIndex(i)); 885 } 886 else 887 { 888 ret_value.AppendString (err.AsCString()); 889 } 890 891 892 return ret_value; 893 } 894 895 uint32_t 896 SBDebugger::GetTerminalWidth () const 897 { 898 if (m_opaque_sp) 899 return m_opaque_sp->GetTerminalWidth (); 900 return 0; 901 } 902 903 void 904 SBDebugger::SetTerminalWidth (uint32_t term_width) 905 { 906 if (m_opaque_sp) 907 m_opaque_sp->SetTerminalWidth (term_width); 908 } 909 910 const char * 911 SBDebugger::GetPrompt() const 912 { 913 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 914 915 if (log) 916 log->Printf ("SBDebugger(%p)::GetPrompt () => \"%s\"", m_opaque_sp.get(), 917 (m_opaque_sp ? m_opaque_sp->GetPrompt() : "")); 918 919 if (m_opaque_sp) 920 return m_opaque_sp->GetPrompt (); 921 return 0; 922 } 923 924 void 925 SBDebugger::SetPrompt (const char *prompt) 926 { 927 if (m_opaque_sp) 928 m_opaque_sp->SetPrompt (prompt); 929 } 930 931 932 ScriptLanguage 933 SBDebugger::GetScriptLanguage() const 934 { 935 if (m_opaque_sp) 936 return m_opaque_sp->GetScriptLanguage (); 937 return eScriptLanguageNone; 938 } 939 940 void 941 SBDebugger::SetScriptLanguage (ScriptLanguage script_lang) 942 { 943 if (m_opaque_sp) 944 { 945 m_opaque_sp->SetScriptLanguage (script_lang); 946 } 947 } 948 949 bool 950 SBDebugger::SetUseExternalEditor (bool value) 951 { 952 if (m_opaque_sp) 953 return m_opaque_sp->SetUseExternalEditor (value); 954 return false; 955 } 956 957 bool 958 SBDebugger::GetUseExternalEditor () 959 { 960 if (m_opaque_sp) 961 return m_opaque_sp->GetUseExternalEditor (); 962 return false; 963 } 964 965 bool 966 SBDebugger::GetDescription (SBStream &description) 967 { 968 if (m_opaque_sp) 969 { 970 const char *name = m_opaque_sp->GetInstanceName().AsCString(); 971 user_id_t id = m_opaque_sp->GetID(); 972 description.Printf ("Debugger (instance: \"%s\", id: %d)", name, id); 973 } 974 else 975 description.Printf ("No value"); 976 977 return true; 978 } 979 980 user_id_t 981 SBDebugger::GetID() 982 { 983 if (m_opaque_sp) 984 return m_opaque_sp->GetID(); 985 return LLDB_INVALID_UID; 986 } 987 988 989 SBError 990 SBDebugger::SetCurrentPlatform (const char *platform_name) 991 { 992 SBError sb_error; 993 if (m_opaque_sp) 994 { 995 PlatformSP platform_sp (Platform::Create (platform_name, sb_error.ref())); 996 997 if (platform_sp) 998 { 999 bool make_selected = true; 1000 m_opaque_sp->GetPlatformList().Append (platform_sp, make_selected); 1001 } 1002 } 1003 return sb_error; 1004 } 1005 1006 bool 1007 SBDebugger::SetCurrentPlatformSDKRoot (const char *sysroot) 1008 { 1009 if (m_opaque_sp) 1010 { 1011 PlatformSP platform_sp (m_opaque_sp->GetPlatformList().GetSelectedPlatform()); 1012 1013 if (platform_sp) 1014 { 1015 platform_sp->SetSDKRootDirectory (ConstString (sysroot)); 1016 return true; 1017 } 1018 } 1019 return false; 1020 } 1021 1022 bool 1023 SBDebugger::GetCloseInputOnEOF () const 1024 { 1025 if (m_opaque_sp) 1026 return m_opaque_sp->GetCloseInputOnEOF (); 1027 return false; 1028 } 1029 1030 void 1031 SBDebugger::SetCloseInputOnEOF (bool b) 1032 { 1033 if (m_opaque_sp) 1034 m_opaque_sp->SetCloseInputOnEOF (b); 1035 } 1036