1 //===-- SBDebugger.cpp ------------------------------------------*- C++ -*-===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "SBReproducerPrivate.h" 10 #include "SystemInitializerFull.h" 11 12 #include "lldb/API/SBDebugger.h" 13 14 #include "lldb/lldb-private.h" 15 16 #include "lldb/API/SBBroadcaster.h" 17 #include "lldb/API/SBCommandInterpreter.h" 18 #include "lldb/API/SBCommandReturnObject.h" 19 #include "lldb/API/SBError.h" 20 #include "lldb/API/SBEvent.h" 21 #include "lldb/API/SBFile.h" 22 #include "lldb/API/SBFrame.h" 23 #include "lldb/API/SBListener.h" 24 #include "lldb/API/SBProcess.h" 25 #include "lldb/API/SBSourceManager.h" 26 #include "lldb/API/SBStream.h" 27 #include "lldb/API/SBStringList.h" 28 #include "lldb/API/SBStructuredData.h" 29 #include "lldb/API/SBTarget.h" 30 #include "lldb/API/SBThread.h" 31 #include "lldb/API/SBTypeCategory.h" 32 #include "lldb/API/SBTypeFilter.h" 33 #include "lldb/API/SBTypeFormat.h" 34 #include "lldb/API/SBTypeNameSpecifier.h" 35 #include "lldb/API/SBTypeSummary.h" 36 #include "lldb/API/SBTypeSynthetic.h" 37 38 #include "lldb/Core/Debugger.h" 39 #include "lldb/Core/PluginManager.h" 40 #include "lldb/Core/StreamFile.h" 41 #include "lldb/Core/StructuredDataImpl.h" 42 #include "lldb/DataFormatters/DataVisualization.h" 43 #include "lldb/Host/Config.h" 44 #include "lldb/Host/XML.h" 45 #include "lldb/Initialization/SystemLifetimeManager.h" 46 #include "lldb/Interpreter/CommandInterpreter.h" 47 #include "lldb/Interpreter/OptionArgParser.h" 48 #include "lldb/Interpreter/OptionGroupPlatform.h" 49 #include "lldb/Target/Process.h" 50 #include "lldb/Target/TargetList.h" 51 #include "lldb/Utility/Args.h" 52 #include "lldb/Utility/State.h" 53 54 #include "llvm/ADT/STLExtras.h" 55 #include "llvm/ADT/StringRef.h" 56 #include "llvm/Support/DynamicLibrary.h" 57 #include "llvm/Support/ManagedStatic.h" 58 59 using namespace lldb; 60 using namespace lldb_private; 61 62 static llvm::sys::DynamicLibrary LoadPlugin(const lldb::DebuggerSP &debugger_sp, 63 const FileSpec &spec, 64 Status &error) { 65 llvm::sys::DynamicLibrary dynlib = 66 llvm::sys::DynamicLibrary::getPermanentLibrary(spec.GetPath().c_str()); 67 if (dynlib.isValid()) { 68 typedef bool (*LLDBCommandPluginInit)(lldb::SBDebugger & debugger); 69 70 lldb::SBDebugger debugger_sb(debugger_sp); 71 // This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger) 72 // function. 73 // TODO: mangle this differently for your system - on OSX, the first 74 // underscore needs to be removed and the second one stays 75 LLDBCommandPluginInit init_func = 76 (LLDBCommandPluginInit)(uintptr_t)dynlib.getAddressOfSymbol( 77 "_ZN4lldb16PluginInitializeENS_10SBDebuggerE"); 78 if (init_func) { 79 if (init_func(debugger_sb)) 80 return dynlib; 81 else 82 error.SetErrorString("plug-in refused to load " 83 "(lldb::PluginInitialize(lldb::SBDebugger) " 84 "returned false)"); 85 } else { 86 error.SetErrorString("plug-in is missing the required initialization: " 87 "lldb::PluginInitialize(lldb::SBDebugger)"); 88 } 89 } else { 90 if (FileSystem::Instance().Exists(spec)) 91 error.SetErrorString("this file does not represent a loadable dylib"); 92 else 93 error.SetErrorString("no such file"); 94 } 95 return llvm::sys::DynamicLibrary(); 96 } 97 98 static llvm::ManagedStatic<SystemLifetimeManager> g_debugger_lifetime; 99 100 SBError SBInputReader::Initialize( 101 lldb::SBDebugger &sb_debugger, 102 unsigned long (*callback)(void *, lldb::SBInputReader *, 103 lldb::InputReaderAction, char const *, 104 unsigned long), 105 void *a, lldb::InputReaderGranularity b, char const *c, char const *d, 106 bool e) { 107 LLDB_RECORD_DUMMY( 108 lldb::SBError, SBInputReader, Initialize, 109 (lldb::SBDebugger &, 110 unsigned long (*)(void *, lldb::SBInputReader *, lldb::InputReaderAction, 111 const char *, unsigned long), 112 void *, lldb::InputReaderGranularity, const char *, const char *, bool), 113 sb_debugger, callback, a, b, c, d, e); 114 115 return SBError(); 116 } 117 118 void SBInputReader::SetIsDone(bool b) { 119 LLDB_RECORD_METHOD(void, SBInputReader, SetIsDone, (bool), b); 120 } 121 122 bool SBInputReader::IsActive() const { 123 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBInputReader, IsActive); 124 125 return false; 126 } 127 128 SBDebugger::SBDebugger() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBDebugger); } 129 130 SBDebugger::SBDebugger(const lldb::DebuggerSP &debugger_sp) 131 : m_opaque_sp(debugger_sp) { 132 LLDB_RECORD_CONSTRUCTOR(SBDebugger, (const lldb::DebuggerSP &), debugger_sp); 133 } 134 135 SBDebugger::SBDebugger(const SBDebugger &rhs) : m_opaque_sp(rhs.m_opaque_sp) { 136 LLDB_RECORD_CONSTRUCTOR(SBDebugger, (const lldb::SBDebugger &), rhs); 137 } 138 139 SBDebugger::~SBDebugger() = default; 140 141 SBDebugger &SBDebugger::operator=(const SBDebugger &rhs) { 142 LLDB_RECORD_METHOD(lldb::SBDebugger &, 143 SBDebugger, operator=,(const lldb::SBDebugger &), rhs); 144 145 if (this != &rhs) { 146 m_opaque_sp = rhs.m_opaque_sp; 147 } 148 return LLDB_RECORD_RESULT(*this); 149 } 150 151 void SBDebugger::Initialize() { 152 LLDB_RECORD_STATIC_METHOD_NO_ARGS(void, SBDebugger, Initialize); 153 SBError ignored = SBDebugger::InitializeWithErrorHandling(); 154 } 155 156 lldb::SBError SBDebugger::InitializeWithErrorHandling() { 157 LLDB_RECORD_STATIC_METHOD_NO_ARGS(lldb::SBError, SBDebugger, 158 InitializeWithErrorHandling); 159 160 SBError error; 161 if (auto e = g_debugger_lifetime->Initialize( 162 std::make_unique<SystemInitializerFull>(), LoadPlugin)) { 163 error.SetError(Status(std::move(e))); 164 } 165 return LLDB_RECORD_RESULT(error); 166 } 167 168 void SBDebugger::Terminate() { 169 LLDB_RECORD_STATIC_METHOD_NO_ARGS(void, SBDebugger, Terminate); 170 171 g_debugger_lifetime->Terminate(); 172 } 173 174 void SBDebugger::Clear() { 175 LLDB_RECORD_METHOD_NO_ARGS(void, SBDebugger, Clear); 176 177 if (m_opaque_sp) 178 m_opaque_sp->ClearIOHandlers(); 179 180 m_opaque_sp.reset(); 181 } 182 183 SBDebugger SBDebugger::Create() { 184 LLDB_RECORD_STATIC_METHOD_NO_ARGS(lldb::SBDebugger, SBDebugger, Create); 185 186 return LLDB_RECORD_RESULT(SBDebugger::Create(false, nullptr, nullptr)); 187 } 188 189 SBDebugger SBDebugger::Create(bool source_init_files) { 190 LLDB_RECORD_STATIC_METHOD(lldb::SBDebugger, SBDebugger, Create, (bool), 191 source_init_files); 192 193 return LLDB_RECORD_RESULT( 194 SBDebugger::Create(source_init_files, nullptr, nullptr)); 195 } 196 197 SBDebugger SBDebugger::Create(bool source_init_files, 198 lldb::LogOutputCallback callback, void *baton) 199 200 { 201 LLDB_RECORD_DUMMY(lldb::SBDebugger, SBDebugger, Create, 202 (bool, lldb::LogOutputCallback, void *), source_init_files, 203 callback, baton); 204 205 SBDebugger debugger; 206 207 // Currently we have issues if this function is called simultaneously on two 208 // different threads. The issues mainly revolve around the fact that the 209 // lldb_private::FormatManager uses global collections and having two threads 210 // parsing the .lldbinit files can cause mayhem. So to get around this for 211 // now we need to use a mutex to prevent bad things from happening. 212 static std::recursive_mutex g_mutex; 213 std::lock_guard<std::recursive_mutex> guard(g_mutex); 214 215 debugger.reset(Debugger::CreateInstance(callback, baton)); 216 217 SBCommandInterpreter interp = debugger.GetCommandInterpreter(); 218 if (source_init_files) { 219 interp.get()->SkipLLDBInitFiles(false); 220 interp.get()->SkipAppInitFiles(false); 221 SBCommandReturnObject result; 222 interp.SourceInitFileInHomeDirectory(result); 223 } else { 224 interp.get()->SkipLLDBInitFiles(true); 225 interp.get()->SkipAppInitFiles(true); 226 } 227 return debugger; 228 } 229 230 void SBDebugger::Destroy(SBDebugger &debugger) { 231 LLDB_RECORD_STATIC_METHOD(void, SBDebugger, Destroy, (lldb::SBDebugger &), 232 debugger); 233 234 Debugger::Destroy(debugger.m_opaque_sp); 235 236 if (debugger.m_opaque_sp.get() != nullptr) 237 debugger.m_opaque_sp.reset(); 238 } 239 240 void SBDebugger::MemoryPressureDetected() { 241 LLDB_RECORD_STATIC_METHOD_NO_ARGS(void, SBDebugger, MemoryPressureDetected); 242 243 // Since this function can be call asynchronously, we allow it to be non- 244 // mandatory. We have seen deadlocks with this function when called so we 245 // need to safeguard against this until we can determine what is causing the 246 // deadlocks. 247 248 const bool mandatory = false; 249 250 ModuleList::RemoveOrphanSharedModules(mandatory); 251 } 252 253 bool SBDebugger::IsValid() const { 254 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBDebugger, IsValid); 255 return this->operator bool(); 256 } 257 SBDebugger::operator bool() const { 258 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBDebugger, operator bool); 259 260 return m_opaque_sp.get() != nullptr; 261 } 262 263 void SBDebugger::SetAsync(bool b) { 264 LLDB_RECORD_METHOD(void, SBDebugger, SetAsync, (bool), b); 265 266 if (m_opaque_sp) 267 m_opaque_sp->SetAsyncExecution(b); 268 } 269 270 bool SBDebugger::GetAsync() { 271 LLDB_RECORD_METHOD_NO_ARGS(bool, SBDebugger, GetAsync); 272 273 return (m_opaque_sp ? m_opaque_sp->GetAsyncExecution() : false); 274 } 275 276 void SBDebugger::SkipLLDBInitFiles(bool b) { 277 LLDB_RECORD_METHOD(void, SBDebugger, SkipLLDBInitFiles, (bool), b); 278 279 if (m_opaque_sp) 280 m_opaque_sp->GetCommandInterpreter().SkipLLDBInitFiles(b); 281 } 282 283 void SBDebugger::SkipAppInitFiles(bool b) { 284 LLDB_RECORD_METHOD(void, SBDebugger, SkipAppInitFiles, (bool), b); 285 286 if (m_opaque_sp) 287 m_opaque_sp->GetCommandInterpreter().SkipAppInitFiles(b); 288 } 289 290 void SBDebugger::SetInputFileHandle(FILE *fh, bool transfer_ownership) { 291 LLDB_RECORD_METHOD(void, SBDebugger, SetInputFileHandle, (FILE *, bool), fh, 292 transfer_ownership); 293 SetInputFile((FileSP)std::make_shared<NativeFile>(fh, transfer_ownership)); 294 } 295 296 SBError SBDebugger::SetInputFile(FileSP file_sp) { 297 LLDB_RECORD_METHOD(SBError, SBDebugger, SetInputFile, (FileSP), file_sp); 298 return LLDB_RECORD_RESULT(SetInputFile(SBFile(file_sp))); 299 } 300 301 // Shouldn't really be settable after initialization as this could cause lots 302 // of problems; don't want users trying to switch modes in the middle of a 303 // debugging session. 304 SBError SBDebugger::SetInputFile(SBFile file) { 305 LLDB_RECORD_METHOD(SBError, SBDebugger, SetInputFile, (SBFile), file); 306 307 SBError error; 308 if (!m_opaque_sp) { 309 error.ref().SetErrorString("invalid debugger"); 310 return LLDB_RECORD_RESULT(error); 311 } 312 313 repro::DataRecorder *recorder = nullptr; 314 if (repro::Generator *g = repro::Reproducer::Instance().GetGenerator()) 315 recorder = g->GetOrCreate<repro::CommandProvider>().GetNewDataRecorder(); 316 317 FileSP file_sp = file.m_opaque_sp; 318 319 static std::unique_ptr<repro::MultiLoader<repro::CommandProvider>> loader = 320 repro::MultiLoader<repro::CommandProvider>::Create( 321 repro::Reproducer::Instance().GetLoader()); 322 if (loader) { 323 llvm::Optional<std::string> nextfile = loader->GetNextFile(); 324 FILE *fh = nextfile ? FileSystem::Instance().Fopen(nextfile->c_str(), "r") 325 : nullptr; 326 // FIXME Jonas Devlieghere: shouldn't this error be propagated out to the 327 // reproducer somehow if fh is NULL? 328 if (fh) { 329 file_sp = std::make_shared<NativeFile>(fh, true); 330 } 331 } 332 333 if (!file_sp || !file_sp->IsValid()) { 334 error.ref().SetErrorString("invalid file"); 335 return LLDB_RECORD_RESULT(error); 336 } 337 338 m_opaque_sp->SetInputFile(file_sp, recorder); 339 return LLDB_RECORD_RESULT(error); 340 } 341 342 SBError SBDebugger::SetOutputFile(FileSP file_sp) { 343 LLDB_RECORD_METHOD(SBError, SBDebugger, SetOutputFile, (FileSP), file_sp); 344 return LLDB_RECORD_RESULT(SetOutputFile(SBFile(file_sp))); 345 } 346 347 void SBDebugger::SetOutputFileHandle(FILE *fh, bool transfer_ownership) { 348 LLDB_RECORD_METHOD(void, SBDebugger, SetOutputFileHandle, (FILE *, bool), fh, 349 transfer_ownership); 350 SetOutputFile((FileSP)std::make_shared<NativeFile>(fh, transfer_ownership)); 351 } 352 353 SBError SBDebugger::SetOutputFile(SBFile file) { 354 LLDB_RECORD_METHOD(SBError, SBDebugger, SetOutputFile, (SBFile file), file); 355 SBError error; 356 if (!m_opaque_sp) { 357 error.ref().SetErrorString("invalid debugger"); 358 return LLDB_RECORD_RESULT(error); 359 } 360 if (!file) { 361 error.ref().SetErrorString("invalid file"); 362 return LLDB_RECORD_RESULT(error); 363 } 364 m_opaque_sp->SetOutputFile(file.m_opaque_sp); 365 return LLDB_RECORD_RESULT(error); 366 } 367 368 void SBDebugger::SetErrorFileHandle(FILE *fh, bool transfer_ownership) { 369 LLDB_RECORD_METHOD(void, SBDebugger, SetErrorFileHandle, (FILE *, bool), fh, 370 transfer_ownership); 371 SetErrorFile((FileSP)std::make_shared<NativeFile>(fh, transfer_ownership)); 372 } 373 374 SBError SBDebugger::SetErrorFile(FileSP file_sp) { 375 LLDB_RECORD_METHOD(SBError, SBDebugger, SetErrorFile, (FileSP), file_sp); 376 return LLDB_RECORD_RESULT(SetErrorFile(SBFile(file_sp))); 377 } 378 379 SBError SBDebugger::SetErrorFile(SBFile file) { 380 LLDB_RECORD_METHOD(SBError, SBDebugger, SetErrorFile, (SBFile file), file); 381 SBError error; 382 if (!m_opaque_sp) { 383 error.ref().SetErrorString("invalid debugger"); 384 return LLDB_RECORD_RESULT(error); 385 } 386 if (!file) { 387 error.ref().SetErrorString("invalid file"); 388 return LLDB_RECORD_RESULT(error); 389 } 390 m_opaque_sp->SetErrorFile(file.m_opaque_sp); 391 return LLDB_RECORD_RESULT(error); 392 } 393 394 FILE *SBDebugger::GetInputFileHandle() { 395 LLDB_RECORD_METHOD_NO_ARGS(FILE *, SBDebugger, GetInputFileHandle); 396 if (m_opaque_sp) { 397 File &file_sp = m_opaque_sp->GetInputFile(); 398 return LLDB_RECORD_RESULT(file_sp.GetStream()); 399 } 400 return LLDB_RECORD_RESULT(nullptr); 401 } 402 403 SBFile SBDebugger::GetInputFile() { 404 LLDB_RECORD_METHOD_NO_ARGS(SBFile, SBDebugger, GetInputFile); 405 if (m_opaque_sp) { 406 return LLDB_RECORD_RESULT(SBFile(m_opaque_sp->GetInputFileSP())); 407 } 408 return LLDB_RECORD_RESULT(SBFile()); 409 } 410 411 FILE *SBDebugger::GetOutputFileHandle() { 412 LLDB_RECORD_METHOD_NO_ARGS(FILE *, SBDebugger, GetOutputFileHandle); 413 if (m_opaque_sp) { 414 StreamFile &stream_file = m_opaque_sp->GetOutputStream(); 415 return LLDB_RECORD_RESULT(stream_file.GetFile().GetStream()); 416 } 417 return LLDB_RECORD_RESULT(nullptr); 418 } 419 420 SBFile SBDebugger::GetOutputFile() { 421 LLDB_RECORD_METHOD_NO_ARGS(SBFile, SBDebugger, GetOutputFile); 422 if (m_opaque_sp) { 423 SBFile file(m_opaque_sp->GetOutputStream().GetFileSP()); 424 return LLDB_RECORD_RESULT(file); 425 } 426 return LLDB_RECORD_RESULT(SBFile()); 427 } 428 429 FILE *SBDebugger::GetErrorFileHandle() { 430 LLDB_RECORD_METHOD_NO_ARGS(FILE *, SBDebugger, GetErrorFileHandle); 431 432 if (m_opaque_sp) { 433 StreamFile &stream_file = m_opaque_sp->GetErrorStream(); 434 return LLDB_RECORD_RESULT(stream_file.GetFile().GetStream()); 435 } 436 return LLDB_RECORD_RESULT(nullptr); 437 } 438 439 SBFile SBDebugger::GetErrorFile() { 440 LLDB_RECORD_METHOD_NO_ARGS(SBFile, SBDebugger, GetErrorFile); 441 SBFile file; 442 if (m_opaque_sp) { 443 SBFile file(m_opaque_sp->GetErrorStream().GetFileSP()); 444 return LLDB_RECORD_RESULT(file); 445 } 446 return LLDB_RECORD_RESULT(SBFile()); 447 } 448 449 void SBDebugger::SaveInputTerminalState() { 450 LLDB_RECORD_DUMMY_NO_ARGS(void, SBDebugger, SaveInputTerminalState); 451 452 if (m_opaque_sp) 453 m_opaque_sp->SaveInputTerminalState(); 454 } 455 456 void SBDebugger::RestoreInputTerminalState() { 457 LLDB_RECORD_DUMMY_NO_ARGS(void, SBDebugger, RestoreInputTerminalState); 458 459 if (m_opaque_sp) 460 m_opaque_sp->RestoreInputTerminalState(); 461 } 462 SBCommandInterpreter SBDebugger::GetCommandInterpreter() { 463 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBCommandInterpreter, SBDebugger, 464 GetCommandInterpreter); 465 466 SBCommandInterpreter sb_interpreter; 467 if (m_opaque_sp) 468 sb_interpreter.reset(&m_opaque_sp->GetCommandInterpreter()); 469 470 return LLDB_RECORD_RESULT(sb_interpreter); 471 } 472 473 void SBDebugger::HandleCommand(const char *command) { 474 LLDB_RECORD_METHOD(void, SBDebugger, HandleCommand, (const char *), command); 475 476 if (m_opaque_sp) { 477 TargetSP target_sp(m_opaque_sp->GetSelectedTarget()); 478 std::unique_lock<std::recursive_mutex> lock; 479 if (target_sp) 480 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex()); 481 482 SBCommandInterpreter sb_interpreter(GetCommandInterpreter()); 483 SBCommandReturnObject result; 484 485 sb_interpreter.HandleCommand(command, result, false); 486 487 result.PutError(m_opaque_sp->GetErrorStream().GetFileSP()); 488 result.PutOutput(m_opaque_sp->GetOutputStream().GetFileSP()); 489 490 if (!m_opaque_sp->GetAsyncExecution()) { 491 SBProcess process(GetCommandInterpreter().GetProcess()); 492 ProcessSP process_sp(process.GetSP()); 493 if (process_sp) { 494 EventSP event_sp; 495 ListenerSP lldb_listener_sp = m_opaque_sp->GetListener(); 496 while (lldb_listener_sp->GetEventForBroadcaster( 497 process_sp.get(), event_sp, std::chrono::seconds(0))) { 498 SBEvent event(event_sp); 499 HandleProcessEvent(process, event, GetOutputFile(), GetErrorFile()); 500 } 501 } 502 } 503 } 504 } 505 506 SBListener SBDebugger::GetListener() { 507 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBListener, SBDebugger, GetListener); 508 509 SBListener sb_listener; 510 if (m_opaque_sp) 511 sb_listener.reset(m_opaque_sp->GetListener()); 512 513 return LLDB_RECORD_RESULT(sb_listener); 514 } 515 516 void SBDebugger::HandleProcessEvent(const SBProcess &process, 517 const SBEvent &event, SBFile out, 518 SBFile err) { 519 LLDB_RECORD_METHOD( 520 void, SBDebugger, HandleProcessEvent, 521 (const lldb::SBProcess &, const lldb::SBEvent &, SBFile, SBFile), process, 522 event, out, err); 523 524 return HandleProcessEvent(process, event, out.m_opaque_sp, err.m_opaque_sp); 525 } 526 527 void SBDebugger::HandleProcessEvent(const SBProcess &process, 528 const SBEvent &event, FILE *out, 529 FILE *err) { 530 LLDB_RECORD_METHOD( 531 void, SBDebugger, HandleProcessEvent, 532 (const lldb::SBProcess &, const lldb::SBEvent &, FILE *, FILE *), process, 533 event, out, err); 534 535 FileSP outfile = std::make_shared<NativeFile>(out, false); 536 FileSP errfile = std::make_shared<NativeFile>(err, false); 537 return HandleProcessEvent(process, event, outfile, errfile); 538 } 539 540 void SBDebugger::HandleProcessEvent(const SBProcess &process, 541 const SBEvent &event, FileSP out_sp, 542 FileSP err_sp) { 543 544 LLDB_RECORD_METHOD( 545 void, SBDebugger, HandleProcessEvent, 546 (const lldb::SBProcess &, const lldb::SBEvent &, FileSP, FileSP), process, 547 event, out_sp, err_sp); 548 549 if (!process.IsValid()) 550 return; 551 552 TargetSP target_sp(process.GetTarget().GetSP()); 553 if (!target_sp) 554 return; 555 556 const uint32_t event_type = event.GetType(); 557 char stdio_buffer[1024]; 558 size_t len; 559 560 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 561 562 if (event_type & 563 (Process::eBroadcastBitSTDOUT | Process::eBroadcastBitStateChanged)) { 564 // Drain stdout when we stop just in case we have any bytes 565 while ((len = process.GetSTDOUT(stdio_buffer, sizeof(stdio_buffer))) > 0) 566 if (out_sp) 567 out_sp->Write(stdio_buffer, len); 568 } 569 570 if (event_type & 571 (Process::eBroadcastBitSTDERR | Process::eBroadcastBitStateChanged)) { 572 // Drain stderr when we stop just in case we have any bytes 573 while ((len = process.GetSTDERR(stdio_buffer, sizeof(stdio_buffer))) > 0) 574 if (err_sp) 575 err_sp->Write(stdio_buffer, len); 576 } 577 578 if (event_type & Process::eBroadcastBitStateChanged) { 579 StateType event_state = SBProcess::GetStateFromEvent(event); 580 581 if (event_state == eStateInvalid) 582 return; 583 584 bool is_stopped = StateIsStoppedState(event_state); 585 if (!is_stopped) 586 process.ReportEventState(event, out_sp); 587 } 588 } 589 590 SBSourceManager SBDebugger::GetSourceManager() { 591 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBSourceManager, SBDebugger, 592 GetSourceManager); 593 594 SBSourceManager sb_source_manager(*this); 595 return LLDB_RECORD_RESULT(sb_source_manager); 596 } 597 598 bool SBDebugger::GetDefaultArchitecture(char *arch_name, size_t arch_name_len) { 599 LLDB_RECORD_STATIC_METHOD(bool, SBDebugger, GetDefaultArchitecture, 600 (char *, size_t), "", arch_name_len); 601 602 if (arch_name && arch_name_len) { 603 ArchSpec default_arch = Target::GetDefaultArchitecture(); 604 605 if (default_arch.IsValid()) { 606 const std::string &triple_str = default_arch.GetTriple().str(); 607 if (!triple_str.empty()) 608 ::snprintf(arch_name, arch_name_len, "%s", triple_str.c_str()); 609 else 610 ::snprintf(arch_name, arch_name_len, "%s", 611 default_arch.GetArchitectureName()); 612 return true; 613 } 614 } 615 if (arch_name && arch_name_len) 616 arch_name[0] = '\0'; 617 return false; 618 } 619 620 bool SBDebugger::SetDefaultArchitecture(const char *arch_name) { 621 LLDB_RECORD_STATIC_METHOD(bool, SBDebugger, SetDefaultArchitecture, 622 (const char *), arch_name); 623 624 if (arch_name) { 625 ArchSpec arch(arch_name); 626 if (arch.IsValid()) { 627 Target::SetDefaultArchitecture(arch); 628 return true; 629 } 630 } 631 return false; 632 } 633 634 ScriptLanguage 635 SBDebugger::GetScriptingLanguage(const char *script_language_name) { 636 LLDB_RECORD_METHOD(lldb::ScriptLanguage, SBDebugger, GetScriptingLanguage, 637 (const char *), script_language_name); 638 639 if (!script_language_name) 640 return eScriptLanguageDefault; 641 return OptionArgParser::ToScriptLanguage( 642 llvm::StringRef(script_language_name), eScriptLanguageDefault, nullptr); 643 } 644 645 const char *SBDebugger::GetVersionString() { 646 LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBDebugger, GetVersionString); 647 648 return lldb_private::GetVersion(); 649 } 650 651 const char *SBDebugger::StateAsCString(StateType state) { 652 LLDB_RECORD_STATIC_METHOD(const char *, SBDebugger, StateAsCString, 653 (lldb::StateType), state); 654 655 return lldb_private::StateAsCString(state); 656 } 657 658 static void AddBoolConfigEntry(StructuredData::Dictionary &dict, 659 llvm::StringRef name, bool value, 660 llvm::StringRef description) { 661 auto entry_up = std::make_unique<StructuredData::Dictionary>(); 662 entry_up->AddBooleanItem("value", value); 663 entry_up->AddStringItem("description", description); 664 dict.AddItem(name, std::move(entry_up)); 665 } 666 667 static void AddLLVMTargets(StructuredData::Dictionary &dict) { 668 auto array_up = std::make_unique<StructuredData::Array>(); 669 #define LLVM_TARGET(target) \ 670 array_up->AddItem(std::make_unique<StructuredData::String>(#target)); 671 #include "llvm/Config/Targets.def" 672 auto entry_up = std::make_unique<StructuredData::Dictionary>(); 673 entry_up->AddItem("value", std::move(array_up)); 674 entry_up->AddStringItem("description", "A list of configured LLVM targets."); 675 dict.AddItem("targets", std::move(entry_up)); 676 } 677 678 SBStructuredData SBDebugger::GetBuildConfiguration() { 679 LLDB_RECORD_STATIC_METHOD_NO_ARGS(lldb::SBStructuredData, SBDebugger, 680 GetBuildConfiguration); 681 682 auto config_up = std::make_unique<StructuredData::Dictionary>(); 683 AddBoolConfigEntry( 684 *config_up, "xml", XMLDocument::XMLEnabled(), 685 "A boolean value that indicates if XML support is enabled in LLDB"); 686 bool have_curses = true; 687 #ifdef LLDB_DISABLE_CURSES 688 have_curses = false; 689 #endif 690 AddBoolConfigEntry( 691 *config_up, "curses", have_curses, 692 "A boolean value that indicates if curses support is enabled in LLDB"); 693 AddLLVMTargets(*config_up); 694 695 SBStructuredData data; 696 data.m_impl_up->SetObjectSP(std::move(config_up)); 697 return LLDB_RECORD_RESULT(data); 698 } 699 700 bool SBDebugger::StateIsRunningState(StateType state) { 701 LLDB_RECORD_STATIC_METHOD(bool, SBDebugger, StateIsRunningState, 702 (lldb::StateType), state); 703 704 const bool result = lldb_private::StateIsRunningState(state); 705 706 return result; 707 } 708 709 bool SBDebugger::StateIsStoppedState(StateType state) { 710 LLDB_RECORD_STATIC_METHOD(bool, SBDebugger, StateIsStoppedState, 711 (lldb::StateType), state); 712 713 const bool result = lldb_private::StateIsStoppedState(state, false); 714 715 return result; 716 } 717 718 lldb::SBTarget SBDebugger::CreateTarget(const char *filename, 719 const char *target_triple, 720 const char *platform_name, 721 bool add_dependent_modules, 722 lldb::SBError &sb_error) { 723 LLDB_RECORD_METHOD( 724 lldb::SBTarget, SBDebugger, CreateTarget, 725 (const char *, const char *, const char *, bool, lldb::SBError &), 726 filename, target_triple, platform_name, add_dependent_modules, sb_error); 727 728 SBTarget sb_target; 729 TargetSP target_sp; 730 if (m_opaque_sp) { 731 sb_error.Clear(); 732 OptionGroupPlatform platform_options(false); 733 platform_options.SetPlatformName(platform_name); 734 735 sb_error.ref() = m_opaque_sp->GetTargetList().CreateTarget( 736 *m_opaque_sp, filename, target_triple, 737 add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, 738 &platform_options, target_sp); 739 740 if (sb_error.Success()) 741 sb_target.SetSP(target_sp); 742 } else { 743 sb_error.SetErrorString("invalid debugger"); 744 } 745 746 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 747 LLDB_LOGF(log, 748 "SBDebugger(%p)::CreateTarget (filename=\"%s\", triple=%s, " 749 "platform_name=%s, add_dependent_modules=%u, error=%s) => " 750 "SBTarget(%p)", 751 static_cast<void *>(m_opaque_sp.get()), filename, target_triple, 752 platform_name, add_dependent_modules, sb_error.GetCString(), 753 static_cast<void *>(target_sp.get())); 754 755 return LLDB_RECORD_RESULT(sb_target); 756 } 757 758 SBTarget 759 SBDebugger::CreateTargetWithFileAndTargetTriple(const char *filename, 760 const char *target_triple) { 761 LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, 762 CreateTargetWithFileAndTargetTriple, 763 (const char *, const char *), filename, target_triple); 764 765 SBTarget sb_target; 766 TargetSP target_sp; 767 if (m_opaque_sp) { 768 const bool add_dependent_modules = true; 769 Status error(m_opaque_sp->GetTargetList().CreateTarget( 770 *m_opaque_sp, filename, target_triple, 771 add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, nullptr, 772 target_sp)); 773 sb_target.SetSP(target_sp); 774 } 775 776 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 777 LLDB_LOGF(log, 778 "SBDebugger(%p)::CreateTargetWithFileAndTargetTriple " 779 "(filename=\"%s\", triple=%s) => SBTarget(%p)", 780 static_cast<void *>(m_opaque_sp.get()), filename, target_triple, 781 static_cast<void *>(target_sp.get())); 782 783 return LLDB_RECORD_RESULT(sb_target); 784 } 785 786 SBTarget SBDebugger::CreateTargetWithFileAndArch(const char *filename, 787 const char *arch_cstr) { 788 LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, CreateTargetWithFileAndArch, 789 (const char *, const char *), filename, arch_cstr); 790 791 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 792 793 SBTarget sb_target; 794 TargetSP target_sp; 795 if (m_opaque_sp) { 796 Status error; 797 const bool add_dependent_modules = true; 798 799 error = m_opaque_sp->GetTargetList().CreateTarget( 800 *m_opaque_sp, filename, arch_cstr, 801 add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, nullptr, 802 target_sp); 803 804 if (error.Success()) { 805 m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp.get()); 806 sb_target.SetSP(target_sp); 807 } 808 } 809 810 LLDB_LOGF(log, 811 "SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", " 812 "arch=%s) => SBTarget(%p)", 813 static_cast<void *>(m_opaque_sp.get()), filename, arch_cstr, 814 static_cast<void *>(target_sp.get())); 815 816 return LLDB_RECORD_RESULT(sb_target); 817 } 818 819 SBTarget SBDebugger::CreateTarget(const char *filename) { 820 LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, CreateTarget, (const char *), 821 filename); 822 823 SBTarget sb_target; 824 TargetSP target_sp; 825 if (m_opaque_sp) { 826 Status error; 827 const bool add_dependent_modules = true; 828 error = m_opaque_sp->GetTargetList().CreateTarget( 829 *m_opaque_sp, filename, "", 830 add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, nullptr, 831 target_sp); 832 833 if (error.Success()) { 834 m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp.get()); 835 sb_target.SetSP(target_sp); 836 } 837 } 838 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 839 LLDB_LOGF(log, 840 "SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)", 841 static_cast<void *>(m_opaque_sp.get()), filename, 842 static_cast<void *>(target_sp.get())); 843 return LLDB_RECORD_RESULT(sb_target); 844 } 845 846 SBTarget SBDebugger::GetDummyTarget() { 847 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTarget, SBDebugger, GetDummyTarget); 848 849 SBTarget sb_target; 850 if (m_opaque_sp) { 851 sb_target.SetSP(m_opaque_sp->GetDummyTarget()->shared_from_this()); 852 } 853 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 854 LLDB_LOGF(log, "SBDebugger(%p)::GetDummyTarget() => SBTarget(%p)", 855 static_cast<void *>(m_opaque_sp.get()), 856 static_cast<void *>(sb_target.GetSP().get())); 857 return LLDB_RECORD_RESULT(sb_target); 858 } 859 860 bool SBDebugger::DeleteTarget(lldb::SBTarget &target) { 861 LLDB_RECORD_METHOD(bool, SBDebugger, DeleteTarget, (lldb::SBTarget &), 862 target); 863 864 bool result = false; 865 if (m_opaque_sp) { 866 TargetSP target_sp(target.GetSP()); 867 if (target_sp) { 868 // No need to lock, the target list is thread safe 869 result = m_opaque_sp->GetTargetList().DeleteTarget(target_sp); 870 target_sp->Destroy(); 871 target.Clear(); 872 const bool mandatory = true; 873 ModuleList::RemoveOrphanSharedModules(mandatory); 874 } 875 } 876 877 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 878 LLDB_LOGF(log, "SBDebugger(%p)::DeleteTarget (SBTarget(%p)) => %i", 879 static_cast<void *>(m_opaque_sp.get()), 880 static_cast<void *>(target.m_opaque_sp.get()), result); 881 882 return result; 883 } 884 885 SBTarget SBDebugger::GetTargetAtIndex(uint32_t idx) { 886 LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, GetTargetAtIndex, (uint32_t), 887 idx); 888 889 SBTarget sb_target; 890 if (m_opaque_sp) { 891 // No need to lock, the target list is thread safe 892 sb_target.SetSP(m_opaque_sp->GetTargetList().GetTargetAtIndex(idx)); 893 } 894 return LLDB_RECORD_RESULT(sb_target); 895 } 896 897 uint32_t SBDebugger::GetIndexOfTarget(lldb::SBTarget target) { 898 LLDB_RECORD_METHOD(uint32_t, SBDebugger, GetIndexOfTarget, (lldb::SBTarget), 899 target); 900 901 lldb::TargetSP target_sp = target.GetSP(); 902 if (!target_sp) 903 return UINT32_MAX; 904 905 if (!m_opaque_sp) 906 return UINT32_MAX; 907 908 return m_opaque_sp->GetTargetList().GetIndexOfTarget(target.GetSP()); 909 } 910 911 SBTarget SBDebugger::FindTargetWithProcessID(lldb::pid_t pid) { 912 LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, FindTargetWithProcessID, 913 (lldb::pid_t), pid); 914 915 SBTarget sb_target; 916 if (m_opaque_sp) { 917 // No need to lock, the target list is thread safe 918 sb_target.SetSP(m_opaque_sp->GetTargetList().FindTargetWithProcessID(pid)); 919 } 920 return LLDB_RECORD_RESULT(sb_target); 921 } 922 923 SBTarget SBDebugger::FindTargetWithFileAndArch(const char *filename, 924 const char *arch_name) { 925 LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, FindTargetWithFileAndArch, 926 (const char *, const char *), filename, arch_name); 927 928 SBTarget sb_target; 929 if (m_opaque_sp && filename && filename[0]) { 930 // No need to lock, the target list is thread safe 931 ArchSpec arch = Platform::GetAugmentedArchSpec( 932 m_opaque_sp->GetPlatformList().GetSelectedPlatform().get(), arch_name); 933 TargetSP target_sp( 934 m_opaque_sp->GetTargetList().FindTargetWithExecutableAndArchitecture( 935 FileSpec(filename), arch_name ? &arch : nullptr)); 936 sb_target.SetSP(target_sp); 937 } 938 return LLDB_RECORD_RESULT(sb_target); 939 } 940 941 SBTarget SBDebugger::FindTargetWithLLDBProcess(const ProcessSP &process_sp) { 942 SBTarget sb_target; 943 if (m_opaque_sp) { 944 // No need to lock, the target list is thread safe 945 sb_target.SetSP( 946 m_opaque_sp->GetTargetList().FindTargetWithProcess(process_sp.get())); 947 } 948 return sb_target; 949 } 950 951 uint32_t SBDebugger::GetNumTargets() { 952 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBDebugger, GetNumTargets); 953 954 if (m_opaque_sp) { 955 // No need to lock, the target list is thread safe 956 return m_opaque_sp->GetTargetList().GetNumTargets(); 957 } 958 return 0; 959 } 960 961 SBTarget SBDebugger::GetSelectedTarget() { 962 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTarget, SBDebugger, GetSelectedTarget); 963 964 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 965 966 SBTarget sb_target; 967 TargetSP target_sp; 968 if (m_opaque_sp) { 969 // No need to lock, the target list is thread safe 970 target_sp = m_opaque_sp->GetTargetList().GetSelectedTarget(); 971 sb_target.SetSP(target_sp); 972 } 973 974 if (log) { 975 SBStream sstr; 976 sb_target.GetDescription(sstr, eDescriptionLevelBrief); 977 LLDB_LOGF(log, "SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s", 978 static_cast<void *>(m_opaque_sp.get()), 979 static_cast<void *>(target_sp.get()), sstr.GetData()); 980 } 981 982 return LLDB_RECORD_RESULT(sb_target); 983 } 984 985 void SBDebugger::SetSelectedTarget(SBTarget &sb_target) { 986 LLDB_RECORD_METHOD(void, SBDebugger, SetSelectedTarget, (lldb::SBTarget &), 987 sb_target); 988 989 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 990 991 TargetSP target_sp(sb_target.GetSP()); 992 if (m_opaque_sp) { 993 m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp.get()); 994 } 995 if (log) { 996 SBStream sstr; 997 sb_target.GetDescription(sstr, eDescriptionLevelBrief); 998 LLDB_LOGF(log, "SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s", 999 static_cast<void *>(m_opaque_sp.get()), 1000 static_cast<void *>(target_sp.get()), sstr.GetData()); 1001 } 1002 } 1003 1004 SBPlatform SBDebugger::GetSelectedPlatform() { 1005 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBPlatform, SBDebugger, GetSelectedPlatform); 1006 1007 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1008 1009 SBPlatform sb_platform; 1010 DebuggerSP debugger_sp(m_opaque_sp); 1011 if (debugger_sp) { 1012 sb_platform.SetSP(debugger_sp->GetPlatformList().GetSelectedPlatform()); 1013 } 1014 LLDB_LOGF(log, "SBDebugger(%p)::GetSelectedPlatform () => SBPlatform(%p): %s", 1015 static_cast<void *>(m_opaque_sp.get()), 1016 static_cast<void *>(sb_platform.GetSP().get()), 1017 sb_platform.GetName()); 1018 return LLDB_RECORD_RESULT(sb_platform); 1019 } 1020 1021 void SBDebugger::SetSelectedPlatform(SBPlatform &sb_platform) { 1022 LLDB_RECORD_METHOD(void, SBDebugger, SetSelectedPlatform, 1023 (lldb::SBPlatform &), sb_platform); 1024 1025 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1026 1027 DebuggerSP debugger_sp(m_opaque_sp); 1028 if (debugger_sp) { 1029 debugger_sp->GetPlatformList().SetSelectedPlatform(sb_platform.GetSP()); 1030 } 1031 1032 LLDB_LOGF(log, "SBDebugger(%p)::SetSelectedPlatform (SBPlatform(%p) %s)", 1033 static_cast<void *>(m_opaque_sp.get()), 1034 static_cast<void *>(sb_platform.GetSP().get()), 1035 sb_platform.GetName()); 1036 } 1037 1038 uint32_t SBDebugger::GetNumPlatforms() { 1039 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBDebugger, GetNumPlatforms); 1040 1041 if (m_opaque_sp) { 1042 // No need to lock, the platform list is thread safe 1043 return m_opaque_sp->GetPlatformList().GetSize(); 1044 } 1045 return 0; 1046 } 1047 1048 SBPlatform SBDebugger::GetPlatformAtIndex(uint32_t idx) { 1049 LLDB_RECORD_METHOD(lldb::SBPlatform, SBDebugger, GetPlatformAtIndex, 1050 (uint32_t), idx); 1051 1052 SBPlatform sb_platform; 1053 if (m_opaque_sp) { 1054 // No need to lock, the platform list is thread safe 1055 sb_platform.SetSP(m_opaque_sp->GetPlatformList().GetAtIndex(idx)); 1056 } 1057 return LLDB_RECORD_RESULT(sb_platform); 1058 } 1059 1060 uint32_t SBDebugger::GetNumAvailablePlatforms() { 1061 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBDebugger, GetNumAvailablePlatforms); 1062 1063 uint32_t idx = 0; 1064 while (true) { 1065 if (!PluginManager::GetPlatformPluginNameAtIndex(idx)) { 1066 break; 1067 } 1068 ++idx; 1069 } 1070 // +1 for the host platform, which should always appear first in the list. 1071 return idx + 1; 1072 } 1073 1074 SBStructuredData SBDebugger::GetAvailablePlatformInfoAtIndex(uint32_t idx) { 1075 LLDB_RECORD_METHOD(lldb::SBStructuredData, SBDebugger, 1076 GetAvailablePlatformInfoAtIndex, (uint32_t), idx); 1077 1078 SBStructuredData data; 1079 auto platform_dict = std::make_unique<StructuredData::Dictionary>(); 1080 llvm::StringRef name_str("name"), desc_str("description"); 1081 1082 if (idx == 0) { 1083 PlatformSP host_platform_sp(Platform::GetHostPlatform()); 1084 platform_dict->AddStringItem( 1085 name_str, host_platform_sp->GetPluginName().GetStringRef()); 1086 platform_dict->AddStringItem( 1087 desc_str, llvm::StringRef(host_platform_sp->GetDescription())); 1088 } else if (idx > 0) { 1089 const char *plugin_name = 1090 PluginManager::GetPlatformPluginNameAtIndex(idx - 1); 1091 if (!plugin_name) { 1092 return LLDB_RECORD_RESULT(data); 1093 } 1094 platform_dict->AddStringItem(name_str, llvm::StringRef(plugin_name)); 1095 1096 const char *plugin_desc = 1097 PluginManager::GetPlatformPluginDescriptionAtIndex(idx - 1); 1098 if (!plugin_desc) { 1099 return LLDB_RECORD_RESULT(data); 1100 } 1101 platform_dict->AddStringItem(desc_str, llvm::StringRef(plugin_desc)); 1102 } 1103 1104 data.m_impl_up->SetObjectSP( 1105 StructuredData::ObjectSP(platform_dict.release())); 1106 return LLDB_RECORD_RESULT(data); 1107 } 1108 1109 void SBDebugger::DispatchInput(void *baton, const void *data, size_t data_len) { 1110 LLDB_RECORD_DUMMY(void, SBDebugger, DispatchInput, 1111 (void *, const void *, size_t), baton, data, data_len); 1112 1113 DispatchInput(data, data_len); 1114 } 1115 1116 void SBDebugger::DispatchInput(const void *data, size_t data_len) { 1117 LLDB_RECORD_DUMMY(void, SBDebugger, DispatchInput, (const void *, size_t), 1118 data, data_len); 1119 1120 // Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1121 // 1122 // if (log) 1123 // LLDB_LOGF(log, "SBDebugger(%p)::DispatchInput (data=\"%.*s\", 1124 // size_t=%" PRIu64 ")", 1125 // m_opaque_sp.get(), 1126 // (int) data_len, 1127 // (const char *) data, 1128 // (uint64_t)data_len); 1129 // 1130 // if (m_opaque_sp) 1131 // m_opaque_sp->DispatchInput ((const char *) data, data_len); 1132 } 1133 1134 void SBDebugger::DispatchInputInterrupt() { 1135 LLDB_RECORD_DUMMY_NO_ARGS(void, SBDebugger, DispatchInputInterrupt); 1136 1137 if (m_opaque_sp) 1138 m_opaque_sp->DispatchInputInterrupt(); 1139 } 1140 1141 void SBDebugger::DispatchInputEndOfFile() { 1142 LLDB_RECORD_METHOD_NO_ARGS(void, SBDebugger, DispatchInputEndOfFile); 1143 1144 if (m_opaque_sp) 1145 m_opaque_sp->DispatchInputEndOfFile(); 1146 } 1147 1148 void SBDebugger::PushInputReader(SBInputReader &reader) { 1149 LLDB_RECORD_METHOD(void, SBDebugger, PushInputReader, (lldb::SBInputReader &), 1150 reader); 1151 } 1152 1153 void SBDebugger::RunCommandInterpreter(bool auto_handle_events, 1154 bool spawn_thread) { 1155 LLDB_RECORD_METHOD(void, SBDebugger, RunCommandInterpreter, (bool, bool), 1156 auto_handle_events, spawn_thread); 1157 1158 if (m_opaque_sp) { 1159 CommandInterpreterRunOptions options; 1160 1161 m_opaque_sp->GetCommandInterpreter().RunCommandInterpreter( 1162 auto_handle_events, spawn_thread, options); 1163 } 1164 } 1165 1166 void SBDebugger::RunCommandInterpreter(bool auto_handle_events, 1167 bool spawn_thread, 1168 SBCommandInterpreterRunOptions &options, 1169 int &num_errors, bool &quit_requested, 1170 bool &stopped_for_crash) 1171 1172 { 1173 LLDB_RECORD_METHOD(void, SBDebugger, RunCommandInterpreter, 1174 (bool, bool, lldb::SBCommandInterpreterRunOptions &, int &, 1175 bool &, bool &), 1176 auto_handle_events, spawn_thread, options, num_errors, 1177 quit_requested, stopped_for_crash); 1178 1179 if (m_opaque_sp) { 1180 CommandInterpreter &interp = m_opaque_sp->GetCommandInterpreter(); 1181 interp.RunCommandInterpreter(auto_handle_events, spawn_thread, 1182 options.ref()); 1183 num_errors = interp.GetNumErrors(); 1184 quit_requested = interp.GetQuitRequested(); 1185 stopped_for_crash = interp.GetStoppedForCrash(); 1186 } 1187 } 1188 1189 SBError SBDebugger::RunREPL(lldb::LanguageType language, 1190 const char *repl_options) { 1191 LLDB_RECORD_METHOD(lldb::SBError, SBDebugger, RunREPL, 1192 (lldb::LanguageType, const char *), language, 1193 repl_options); 1194 1195 SBError error; 1196 if (m_opaque_sp) 1197 error.ref() = m_opaque_sp->RunREPL(language, repl_options); 1198 else 1199 error.SetErrorString("invalid debugger"); 1200 return LLDB_RECORD_RESULT(error); 1201 } 1202 1203 void SBDebugger::reset(const DebuggerSP &debugger_sp) { 1204 m_opaque_sp = debugger_sp; 1205 } 1206 1207 Debugger *SBDebugger::get() const { return m_opaque_sp.get(); } 1208 1209 Debugger &SBDebugger::ref() const { 1210 assert(m_opaque_sp.get()); 1211 return *m_opaque_sp; 1212 } 1213 1214 const lldb::DebuggerSP &SBDebugger::get_sp() const { return m_opaque_sp; } 1215 1216 SBDebugger SBDebugger::FindDebuggerWithID(int id) { 1217 LLDB_RECORD_STATIC_METHOD(lldb::SBDebugger, SBDebugger, FindDebuggerWithID, 1218 (int), id); 1219 1220 // No need to lock, the debugger list is thread safe 1221 SBDebugger sb_debugger; 1222 DebuggerSP debugger_sp = Debugger::FindDebuggerWithID(id); 1223 if (debugger_sp) 1224 sb_debugger.reset(debugger_sp); 1225 return LLDB_RECORD_RESULT(sb_debugger); 1226 } 1227 1228 const char *SBDebugger::GetInstanceName() { 1229 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBDebugger, GetInstanceName); 1230 1231 return (m_opaque_sp ? m_opaque_sp->GetInstanceName().AsCString() : nullptr); 1232 } 1233 1234 SBError SBDebugger::SetInternalVariable(const char *var_name, const char *value, 1235 const char *debugger_instance_name) { 1236 LLDB_RECORD_STATIC_METHOD(lldb::SBError, SBDebugger, SetInternalVariable, 1237 (const char *, const char *, const char *), 1238 var_name, value, debugger_instance_name); 1239 1240 SBError sb_error; 1241 DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName( 1242 ConstString(debugger_instance_name))); 1243 Status error; 1244 if (debugger_sp) { 1245 ExecutionContext exe_ctx( 1246 debugger_sp->GetCommandInterpreter().GetExecutionContext()); 1247 error = debugger_sp->SetPropertyValue(&exe_ctx, eVarSetOperationAssign, 1248 var_name, value); 1249 } else { 1250 error.SetErrorStringWithFormat("invalid debugger instance name '%s'", 1251 debugger_instance_name); 1252 } 1253 if (error.Fail()) 1254 sb_error.SetError(error); 1255 return LLDB_RECORD_RESULT(sb_error); 1256 } 1257 1258 SBStringList 1259 SBDebugger::GetInternalVariableValue(const char *var_name, 1260 const char *debugger_instance_name) { 1261 LLDB_RECORD_STATIC_METHOD( 1262 lldb::SBStringList, SBDebugger, GetInternalVariableValue, 1263 (const char *, const char *), var_name, debugger_instance_name); 1264 1265 SBStringList ret_value; 1266 DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName( 1267 ConstString(debugger_instance_name))); 1268 Status error; 1269 if (debugger_sp) { 1270 ExecutionContext exe_ctx( 1271 debugger_sp->GetCommandInterpreter().GetExecutionContext()); 1272 lldb::OptionValueSP value_sp( 1273 debugger_sp->GetPropertyValue(&exe_ctx, var_name, false, error)); 1274 if (value_sp) { 1275 StreamString value_strm; 1276 value_sp->DumpValue(&exe_ctx, value_strm, OptionValue::eDumpOptionValue); 1277 const std::string &value_str = value_strm.GetString(); 1278 if (!value_str.empty()) { 1279 StringList string_list; 1280 string_list.SplitIntoLines(value_str); 1281 return LLDB_RECORD_RESULT(SBStringList(&string_list)); 1282 } 1283 } 1284 } 1285 return LLDB_RECORD_RESULT(SBStringList()); 1286 } 1287 1288 uint32_t SBDebugger::GetTerminalWidth() const { 1289 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBDebugger, GetTerminalWidth); 1290 1291 return (m_opaque_sp ? m_opaque_sp->GetTerminalWidth() : 0); 1292 } 1293 1294 void SBDebugger::SetTerminalWidth(uint32_t term_width) { 1295 LLDB_RECORD_DUMMY(void, SBDebugger, SetTerminalWidth, (uint32_t), term_width); 1296 1297 if (m_opaque_sp) 1298 m_opaque_sp->SetTerminalWidth(term_width); 1299 } 1300 1301 const char *SBDebugger::GetPrompt() const { 1302 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBDebugger, GetPrompt); 1303 1304 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1305 1306 LLDB_LOGF(log, "SBDebugger(%p)::GetPrompt () => \"%s\"", 1307 static_cast<void *>(m_opaque_sp.get()), 1308 (m_opaque_sp ? m_opaque_sp->GetPrompt().str().c_str() : "")); 1309 1310 return (m_opaque_sp ? ConstString(m_opaque_sp->GetPrompt()).GetCString() 1311 : nullptr); 1312 } 1313 1314 void SBDebugger::SetPrompt(const char *prompt) { 1315 LLDB_RECORD_METHOD(void, SBDebugger, SetPrompt, (const char *), prompt); 1316 1317 if (m_opaque_sp) 1318 m_opaque_sp->SetPrompt(llvm::StringRef::withNullAsEmpty(prompt)); 1319 } 1320 1321 const char *SBDebugger::GetReproducerPath() const { 1322 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBDebugger, GetReproducerPath); 1323 1324 return (m_opaque_sp 1325 ? ConstString(m_opaque_sp->GetReproducerPath()).GetCString() 1326 : nullptr); 1327 } 1328 1329 ScriptLanguage SBDebugger::GetScriptLanguage() const { 1330 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::ScriptLanguage, SBDebugger, 1331 GetScriptLanguage); 1332 1333 return (m_opaque_sp ? m_opaque_sp->GetScriptLanguage() : eScriptLanguageNone); 1334 } 1335 1336 void SBDebugger::SetScriptLanguage(ScriptLanguage script_lang) { 1337 LLDB_RECORD_METHOD(void, SBDebugger, SetScriptLanguage, 1338 (lldb::ScriptLanguage), script_lang); 1339 1340 if (m_opaque_sp) { 1341 m_opaque_sp->SetScriptLanguage(script_lang); 1342 } 1343 } 1344 1345 bool SBDebugger::SetUseExternalEditor(bool value) { 1346 LLDB_RECORD_METHOD(bool, SBDebugger, SetUseExternalEditor, (bool), value); 1347 1348 return (m_opaque_sp ? m_opaque_sp->SetUseExternalEditor(value) : false); 1349 } 1350 1351 bool SBDebugger::GetUseExternalEditor() { 1352 LLDB_RECORD_METHOD_NO_ARGS(bool, SBDebugger, GetUseExternalEditor); 1353 1354 return (m_opaque_sp ? m_opaque_sp->GetUseExternalEditor() : false); 1355 } 1356 1357 bool SBDebugger::SetUseColor(bool value) { 1358 LLDB_RECORD_METHOD(bool, SBDebugger, SetUseColor, (bool), value); 1359 1360 return (m_opaque_sp ? m_opaque_sp->SetUseColor(value) : false); 1361 } 1362 1363 bool SBDebugger::GetUseColor() const { 1364 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBDebugger, GetUseColor); 1365 1366 return (m_opaque_sp ? m_opaque_sp->GetUseColor() : false); 1367 } 1368 1369 bool SBDebugger::GetDescription(SBStream &description) { 1370 LLDB_RECORD_METHOD(bool, SBDebugger, GetDescription, (lldb::SBStream &), 1371 description); 1372 1373 Stream &strm = description.ref(); 1374 1375 if (m_opaque_sp) { 1376 const char *name = m_opaque_sp->GetInstanceName().AsCString(); 1377 user_id_t id = m_opaque_sp->GetID(); 1378 strm.Printf("Debugger (instance: \"%s\", id: %" PRIu64 ")", name, id); 1379 } else 1380 strm.PutCString("No value"); 1381 1382 return true; 1383 } 1384 1385 user_id_t SBDebugger::GetID() { 1386 LLDB_RECORD_METHOD_NO_ARGS(lldb::user_id_t, SBDebugger, GetID); 1387 1388 return (m_opaque_sp ? m_opaque_sp->GetID() : LLDB_INVALID_UID); 1389 } 1390 1391 SBError SBDebugger::SetCurrentPlatform(const char *platform_name_cstr) { 1392 LLDB_RECORD_METHOD(lldb::SBError, SBDebugger, SetCurrentPlatform, 1393 (const char *), platform_name_cstr); 1394 1395 SBError sb_error; 1396 if (m_opaque_sp) { 1397 if (platform_name_cstr && platform_name_cstr[0]) { 1398 ConstString platform_name(platform_name_cstr); 1399 PlatformSP platform_sp(Platform::Find(platform_name)); 1400 1401 if (platform_sp) { 1402 // Already have a platform with this name, just select it 1403 m_opaque_sp->GetPlatformList().SetSelectedPlatform(platform_sp); 1404 } else { 1405 // We don't have a platform by this name yet, create one 1406 platform_sp = Platform::Create(platform_name, sb_error.ref()); 1407 if (platform_sp) { 1408 // We created the platform, now append and select it 1409 bool make_selected = true; 1410 m_opaque_sp->GetPlatformList().Append(platform_sp, make_selected); 1411 } 1412 } 1413 } else { 1414 sb_error.ref().SetErrorString("invalid platform name"); 1415 } 1416 } else { 1417 sb_error.ref().SetErrorString("invalid debugger"); 1418 } 1419 return LLDB_RECORD_RESULT(sb_error); 1420 } 1421 1422 bool SBDebugger::SetCurrentPlatformSDKRoot(const char *sysroot) { 1423 LLDB_RECORD_METHOD(bool, SBDebugger, SetCurrentPlatformSDKRoot, 1424 (const char *), sysroot); 1425 1426 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1427 if (m_opaque_sp) { 1428 PlatformSP platform_sp( 1429 m_opaque_sp->GetPlatformList().GetSelectedPlatform()); 1430 1431 if (platform_sp) { 1432 if (log && sysroot) 1433 LLDB_LOGF(log, "SBDebugger::SetCurrentPlatformSDKRoot (\"%s\")", 1434 sysroot); 1435 platform_sp->SetSDKRootDirectory(ConstString(sysroot)); 1436 return true; 1437 } 1438 } 1439 return false; 1440 } 1441 1442 bool SBDebugger::GetCloseInputOnEOF() const { 1443 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBDebugger, GetCloseInputOnEOF); 1444 1445 return (m_opaque_sp ? m_opaque_sp->GetCloseInputOnEOF() : false); 1446 } 1447 1448 void SBDebugger::SetCloseInputOnEOF(bool b) { 1449 LLDB_RECORD_METHOD(void, SBDebugger, SetCloseInputOnEOF, (bool), b); 1450 1451 if (m_opaque_sp) 1452 m_opaque_sp->SetCloseInputOnEOF(b); 1453 } 1454 1455 SBTypeCategory SBDebugger::GetCategory(const char *category_name) { 1456 LLDB_RECORD_METHOD(lldb::SBTypeCategory, SBDebugger, GetCategory, 1457 (const char *), category_name); 1458 1459 if (!category_name || *category_name == 0) 1460 return LLDB_RECORD_RESULT(SBTypeCategory()); 1461 1462 TypeCategoryImplSP category_sp; 1463 1464 if (DataVisualization::Categories::GetCategory(ConstString(category_name), 1465 category_sp, false)) { 1466 return LLDB_RECORD_RESULT(SBTypeCategory(category_sp)); 1467 } else { 1468 return LLDB_RECORD_RESULT(SBTypeCategory()); 1469 } 1470 } 1471 1472 SBTypeCategory SBDebugger::GetCategory(lldb::LanguageType lang_type) { 1473 LLDB_RECORD_METHOD(lldb::SBTypeCategory, SBDebugger, GetCategory, 1474 (lldb::LanguageType), lang_type); 1475 1476 TypeCategoryImplSP category_sp; 1477 if (DataVisualization::Categories::GetCategory(lang_type, category_sp)) { 1478 return LLDB_RECORD_RESULT(SBTypeCategory(category_sp)); 1479 } else { 1480 return LLDB_RECORD_RESULT(SBTypeCategory()); 1481 } 1482 } 1483 1484 SBTypeCategory SBDebugger::CreateCategory(const char *category_name) { 1485 LLDB_RECORD_METHOD(lldb::SBTypeCategory, SBDebugger, CreateCategory, 1486 (const char *), category_name); 1487 1488 if (!category_name || *category_name == 0) 1489 return LLDB_RECORD_RESULT(SBTypeCategory()); 1490 1491 TypeCategoryImplSP category_sp; 1492 1493 if (DataVisualization::Categories::GetCategory(ConstString(category_name), 1494 category_sp, true)) { 1495 return LLDB_RECORD_RESULT(SBTypeCategory(category_sp)); 1496 } else { 1497 return LLDB_RECORD_RESULT(SBTypeCategory()); 1498 } 1499 } 1500 1501 bool SBDebugger::DeleteCategory(const char *category_name) { 1502 LLDB_RECORD_METHOD(bool, SBDebugger, DeleteCategory, (const char *), 1503 category_name); 1504 1505 if (!category_name || *category_name == 0) 1506 return false; 1507 1508 return DataVisualization::Categories::Delete(ConstString(category_name)); 1509 } 1510 1511 uint32_t SBDebugger::GetNumCategories() { 1512 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBDebugger, GetNumCategories); 1513 1514 return DataVisualization::Categories::GetCount(); 1515 } 1516 1517 SBTypeCategory SBDebugger::GetCategoryAtIndex(uint32_t index) { 1518 LLDB_RECORD_METHOD(lldb::SBTypeCategory, SBDebugger, GetCategoryAtIndex, 1519 (uint32_t), index); 1520 1521 return LLDB_RECORD_RESULT( 1522 SBTypeCategory(DataVisualization::Categories::GetCategoryAtIndex(index))); 1523 } 1524 1525 SBTypeCategory SBDebugger::GetDefaultCategory() { 1526 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTypeCategory, SBDebugger, 1527 GetDefaultCategory); 1528 1529 return LLDB_RECORD_RESULT(GetCategory("default")); 1530 } 1531 1532 SBTypeFormat SBDebugger::GetFormatForType(SBTypeNameSpecifier type_name) { 1533 LLDB_RECORD_METHOD(lldb::SBTypeFormat, SBDebugger, GetFormatForType, 1534 (lldb::SBTypeNameSpecifier), type_name); 1535 1536 SBTypeCategory default_category_sb = GetDefaultCategory(); 1537 if (default_category_sb.GetEnabled()) 1538 return LLDB_RECORD_RESULT(default_category_sb.GetFormatForType(type_name)); 1539 return LLDB_RECORD_RESULT(SBTypeFormat()); 1540 } 1541 1542 SBTypeSummary SBDebugger::GetSummaryForType(SBTypeNameSpecifier type_name) { 1543 LLDB_RECORD_METHOD(lldb::SBTypeSummary, SBDebugger, GetSummaryForType, 1544 (lldb::SBTypeNameSpecifier), type_name); 1545 1546 if (!type_name.IsValid()) 1547 return LLDB_RECORD_RESULT(SBTypeSummary()); 1548 return LLDB_RECORD_RESULT( 1549 SBTypeSummary(DataVisualization::GetSummaryForType(type_name.GetSP()))); 1550 } 1551 1552 SBTypeFilter SBDebugger::GetFilterForType(SBTypeNameSpecifier type_name) { 1553 LLDB_RECORD_METHOD(lldb::SBTypeFilter, SBDebugger, GetFilterForType, 1554 (lldb::SBTypeNameSpecifier), type_name); 1555 1556 if (!type_name.IsValid()) 1557 return LLDB_RECORD_RESULT(SBTypeFilter()); 1558 return LLDB_RECORD_RESULT( 1559 SBTypeFilter(DataVisualization::GetFilterForType(type_name.GetSP()))); 1560 } 1561 1562 SBTypeSynthetic SBDebugger::GetSyntheticForType(SBTypeNameSpecifier type_name) { 1563 LLDB_RECORD_METHOD(lldb::SBTypeSynthetic, SBDebugger, GetSyntheticForType, 1564 (lldb::SBTypeNameSpecifier), type_name); 1565 1566 if (!type_name.IsValid()) 1567 return LLDB_RECORD_RESULT(SBTypeSynthetic()); 1568 return LLDB_RECORD_RESULT(SBTypeSynthetic( 1569 DataVisualization::GetSyntheticForType(type_name.GetSP()))); 1570 } 1571 1572 static llvm::ArrayRef<const char *> GetCategoryArray(const char **categories) { 1573 if (categories == nullptr) 1574 return {}; 1575 size_t len = 0; 1576 while (categories[len] != nullptr) 1577 ++len; 1578 return llvm::makeArrayRef(categories, len); 1579 } 1580 1581 bool SBDebugger::EnableLog(const char *channel, const char **categories) { 1582 LLDB_RECORD_METHOD(bool, SBDebugger, EnableLog, (const char *, const char **), 1583 channel, categories); 1584 1585 if (m_opaque_sp) { 1586 uint32_t log_options = 1587 LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME; 1588 std::string error; 1589 llvm::raw_string_ostream error_stream(error); 1590 return m_opaque_sp->EnableLog(channel, GetCategoryArray(categories), "", 1591 log_options, error_stream); 1592 } else 1593 return false; 1594 } 1595 1596 void SBDebugger::SetLoggingCallback(lldb::LogOutputCallback log_callback, 1597 void *baton) { 1598 LLDB_RECORD_DUMMY(void, SBDebugger, SetLoggingCallback, 1599 (lldb::LogOutputCallback, void *), log_callback, baton); 1600 1601 if (m_opaque_sp) { 1602 return m_opaque_sp->SetLoggingCallback(log_callback, baton); 1603 } 1604 } 1605 1606 namespace lldb_private { 1607 namespace repro { 1608 1609 template <> void RegisterMethods<SBInputReader>(Registry &R) { 1610 LLDB_REGISTER_METHOD(void, SBInputReader, SetIsDone, (bool)); 1611 LLDB_REGISTER_METHOD_CONST(bool, SBInputReader, IsActive, ()); 1612 } 1613 1614 static void SetFileHandleRedirect(SBDebugger *, FILE *, bool) { 1615 // Do nothing. 1616 } 1617 1618 static SBError SetFileRedirect(SBDebugger *, SBFile file) { return SBError(); } 1619 1620 static SBError SetFileRedirect(SBDebugger *, FileSP file) { return SBError(); } 1621 1622 static bool GetDefaultArchitectureRedirect(char *arch_name, 1623 size_t arch_name_len) { 1624 // The function is writing to its argument. Without the redirect it would 1625 // write into the replay buffer. 1626 char buffer[1024]; 1627 return SBDebugger::GetDefaultArchitecture(buffer, arch_name_len); 1628 } 1629 1630 template <> void RegisterMethods<SBDebugger>(Registry &R) { 1631 // Custom implementation. 1632 R.Register(&invoke<void (SBDebugger::*)( 1633 FILE *, bool)>::method<&SBDebugger::SetErrorFileHandle>::doit, 1634 &SetFileHandleRedirect); 1635 R.Register(&invoke<void (SBDebugger::*)( 1636 FILE *, bool)>::method<&SBDebugger::SetOutputFileHandle>::doit, 1637 &SetFileHandleRedirect); 1638 R.Register<bool(char *, size_t)>(static_cast<bool (*)(char *, size_t)>( 1639 &SBDebugger::GetDefaultArchitecture), 1640 &GetDefaultArchitectureRedirect); 1641 1642 R.Register(&invoke<SBError (SBDebugger::*)( 1643 SBFile)>::method<&SBDebugger::SetInputFile>::doit, 1644 &SetFileRedirect); 1645 R.Register(&invoke<SBError (SBDebugger::*)( 1646 SBFile)>::method<&SBDebugger::SetOutputFile>::doit, 1647 &SetFileRedirect); 1648 R.Register(&invoke<SBError (SBDebugger::*)( 1649 SBFile)>::method<&SBDebugger::SetErrorFile>::doit, 1650 &SetFileRedirect); 1651 1652 R.Register(&invoke<SBError (SBDebugger::*)( 1653 FileSP)>::method<&SBDebugger::SetInputFile>::doit, 1654 &SetFileRedirect); 1655 R.Register(&invoke<SBError (SBDebugger::*)( 1656 FileSP)>::method<&SBDebugger::SetOutputFile>::doit, 1657 &SetFileRedirect); 1658 R.Register(&invoke<SBError (SBDebugger::*)( 1659 FileSP)>::method<&SBDebugger::SetErrorFile>::doit, 1660 &SetFileRedirect); 1661 1662 LLDB_REGISTER_CONSTRUCTOR(SBDebugger, ()); 1663 LLDB_REGISTER_CONSTRUCTOR(SBDebugger, (const lldb::DebuggerSP &)); 1664 LLDB_REGISTER_CONSTRUCTOR(SBDebugger, (const lldb::SBDebugger &)); 1665 LLDB_REGISTER_METHOD(lldb::SBDebugger &, 1666 SBDebugger, operator=,(const lldb::SBDebugger &)); 1667 LLDB_REGISTER_STATIC_METHOD(void, SBDebugger, Initialize, ()); 1668 LLDB_REGISTER_STATIC_METHOD(lldb::SBError, SBDebugger, 1669 InitializeWithErrorHandling, ()); 1670 LLDB_REGISTER_STATIC_METHOD(void, SBDebugger, Terminate, ()); 1671 LLDB_REGISTER_METHOD(void, SBDebugger, Clear, ()); 1672 LLDB_REGISTER_STATIC_METHOD(lldb::SBDebugger, SBDebugger, Create, ()); 1673 LLDB_REGISTER_STATIC_METHOD(lldb::SBDebugger, SBDebugger, Create, (bool)); 1674 LLDB_REGISTER_STATIC_METHOD(void, SBDebugger, Destroy, (lldb::SBDebugger &)); 1675 LLDB_REGISTER_STATIC_METHOD(void, SBDebugger, MemoryPressureDetected, ()); 1676 LLDB_REGISTER_METHOD_CONST(bool, SBDebugger, IsValid, ()); 1677 LLDB_REGISTER_METHOD_CONST(bool, SBDebugger, operator bool,()); 1678 LLDB_REGISTER_METHOD(void, SBDebugger, SetAsync, (bool)); 1679 LLDB_REGISTER_METHOD(bool, SBDebugger, GetAsync, ()); 1680 LLDB_REGISTER_METHOD(void, SBDebugger, SkipLLDBInitFiles, (bool)); 1681 LLDB_REGISTER_METHOD(void, SBDebugger, SkipAppInitFiles, (bool)); 1682 LLDB_REGISTER_METHOD(void, SBDebugger, SetInputFileHandle, (FILE *, bool)); 1683 LLDB_REGISTER_METHOD(FILE *, SBDebugger, GetInputFileHandle, ()); 1684 LLDB_REGISTER_METHOD(FILE *, SBDebugger, GetOutputFileHandle, ()); 1685 LLDB_REGISTER_METHOD(FILE *, SBDebugger, GetErrorFileHandle, ()); 1686 LLDB_REGISTER_METHOD(SBFile, SBDebugger, GetInputFile, ()); 1687 LLDB_REGISTER_METHOD(SBFile, SBDebugger, GetOutputFile, ()); 1688 LLDB_REGISTER_METHOD(SBFile, SBDebugger, GetErrorFile, ()); 1689 LLDB_REGISTER_METHOD(void, SBDebugger, SaveInputTerminalState, ()); 1690 LLDB_REGISTER_METHOD(void, SBDebugger, RestoreInputTerminalState, ()); 1691 LLDB_REGISTER_METHOD(lldb::SBCommandInterpreter, SBDebugger, 1692 GetCommandInterpreter, ()); 1693 LLDB_REGISTER_METHOD(void, SBDebugger, HandleCommand, (const char *)); 1694 LLDB_REGISTER_METHOD(lldb::SBListener, SBDebugger, GetListener, ()); 1695 LLDB_REGISTER_METHOD( 1696 void, SBDebugger, HandleProcessEvent, 1697 (const lldb::SBProcess &, const lldb::SBEvent &, FILE *, FILE *)); 1698 LLDB_REGISTER_METHOD( 1699 void, SBDebugger, HandleProcessEvent, 1700 (const lldb::SBProcess &, const lldb::SBEvent &, SBFile, SBFile)); 1701 LLDB_REGISTER_METHOD( 1702 void, SBDebugger, HandleProcessEvent, 1703 (const lldb::SBProcess &, const lldb::SBEvent &, FileSP, FileSP)); 1704 LLDB_REGISTER_METHOD(lldb::SBSourceManager, SBDebugger, GetSourceManager, ()); 1705 LLDB_REGISTER_STATIC_METHOD(bool, SBDebugger, SetDefaultArchitecture, 1706 (const char *)); 1707 LLDB_REGISTER_METHOD(lldb::ScriptLanguage, SBDebugger, GetScriptingLanguage, 1708 (const char *)); 1709 LLDB_REGISTER_STATIC_METHOD(const char *, SBDebugger, GetVersionString, ()); 1710 LLDB_REGISTER_STATIC_METHOD(const char *, SBDebugger, StateAsCString, 1711 (lldb::StateType)); 1712 LLDB_REGISTER_STATIC_METHOD(lldb::SBStructuredData, SBDebugger, 1713 GetBuildConfiguration, ()); 1714 LLDB_REGISTER_STATIC_METHOD(bool, SBDebugger, StateIsRunningState, 1715 (lldb::StateType)); 1716 LLDB_REGISTER_STATIC_METHOD(bool, SBDebugger, StateIsStoppedState, 1717 (lldb::StateType)); 1718 LLDB_REGISTER_METHOD( 1719 lldb::SBTarget, SBDebugger, CreateTarget, 1720 (const char *, const char *, const char *, bool, lldb::SBError &)); 1721 LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger, 1722 CreateTargetWithFileAndTargetTriple, 1723 (const char *, const char *)); 1724 LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger, CreateTargetWithFileAndArch, 1725 (const char *, const char *)); 1726 LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger, CreateTarget, 1727 (const char *)); 1728 LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger, GetDummyTarget, ()); 1729 LLDB_REGISTER_METHOD(bool, SBDebugger, DeleteTarget, (lldb::SBTarget &)); 1730 LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger, GetTargetAtIndex, 1731 (uint32_t)); 1732 LLDB_REGISTER_METHOD(uint32_t, SBDebugger, GetIndexOfTarget, 1733 (lldb::SBTarget)); 1734 LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger, FindTargetWithProcessID, 1735 (lldb::pid_t)); 1736 LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger, FindTargetWithFileAndArch, 1737 (const char *, const char *)); 1738 LLDB_REGISTER_METHOD(uint32_t, SBDebugger, GetNumTargets, ()); 1739 LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger, GetSelectedTarget, ()); 1740 LLDB_REGISTER_METHOD(void, SBDebugger, SetSelectedTarget, (lldb::SBTarget &)); 1741 LLDB_REGISTER_METHOD(lldb::SBPlatform, SBDebugger, GetSelectedPlatform, ()); 1742 LLDB_REGISTER_METHOD(void, SBDebugger, SetSelectedPlatform, 1743 (lldb::SBPlatform &)); 1744 LLDB_REGISTER_METHOD(uint32_t, SBDebugger, GetNumPlatforms, ()); 1745 LLDB_REGISTER_METHOD(lldb::SBPlatform, SBDebugger, GetPlatformAtIndex, 1746 (uint32_t)); 1747 LLDB_REGISTER_METHOD(uint32_t, SBDebugger, GetNumAvailablePlatforms, ()); 1748 LLDB_REGISTER_METHOD(lldb::SBStructuredData, SBDebugger, 1749 GetAvailablePlatformInfoAtIndex, (uint32_t)); 1750 LLDB_REGISTER_METHOD(void, SBDebugger, DispatchInputInterrupt, ()); 1751 LLDB_REGISTER_METHOD(void, SBDebugger, DispatchInputEndOfFile, ()); 1752 LLDB_REGISTER_METHOD(void, SBDebugger, PushInputReader, 1753 (lldb::SBInputReader &)); 1754 LLDB_REGISTER_METHOD(void, SBDebugger, RunCommandInterpreter, (bool, bool)); 1755 LLDB_REGISTER_METHOD(void, SBDebugger, RunCommandInterpreter, 1756 (bool, bool, lldb::SBCommandInterpreterRunOptions &, 1757 int &, bool &, bool &)); 1758 LLDB_REGISTER_METHOD(lldb::SBError, SBDebugger, RunREPL, 1759 (lldb::LanguageType, const char *)); 1760 LLDB_REGISTER_STATIC_METHOD(lldb::SBDebugger, SBDebugger, FindDebuggerWithID, 1761 (int)); 1762 LLDB_REGISTER_METHOD(const char *, SBDebugger, GetInstanceName, ()); 1763 LLDB_REGISTER_STATIC_METHOD(lldb::SBError, SBDebugger, SetInternalVariable, 1764 (const char *, const char *, const char *)); 1765 LLDB_REGISTER_STATIC_METHOD(lldb::SBStringList, SBDebugger, 1766 GetInternalVariableValue, 1767 (const char *, const char *)); 1768 LLDB_REGISTER_METHOD_CONST(uint32_t, SBDebugger, GetTerminalWidth, ()); 1769 LLDB_REGISTER_METHOD(void, SBDebugger, SetTerminalWidth, (uint32_t)); 1770 LLDB_REGISTER_METHOD_CONST(const char *, SBDebugger, GetPrompt, ()); 1771 LLDB_REGISTER_METHOD(void, SBDebugger, SetPrompt, (const char *)); 1772 LLDB_REGISTER_METHOD_CONST(const char *, SBDebugger, GetReproducerPath, ()); 1773 LLDB_REGISTER_METHOD_CONST(lldb::ScriptLanguage, SBDebugger, 1774 GetScriptLanguage, ()); 1775 LLDB_REGISTER_METHOD(void, SBDebugger, SetScriptLanguage, 1776 (lldb::ScriptLanguage)); 1777 LLDB_REGISTER_METHOD(bool, SBDebugger, SetUseExternalEditor, (bool)); 1778 LLDB_REGISTER_METHOD(bool, SBDebugger, GetUseExternalEditor, ()); 1779 LLDB_REGISTER_METHOD(bool, SBDebugger, SetUseColor, (bool)); 1780 LLDB_REGISTER_METHOD_CONST(bool, SBDebugger, GetUseColor, ()); 1781 LLDB_REGISTER_METHOD(bool, SBDebugger, GetDescription, (lldb::SBStream &)); 1782 LLDB_REGISTER_METHOD(lldb::user_id_t, SBDebugger, GetID, ()); 1783 LLDB_REGISTER_METHOD(lldb::SBError, SBDebugger, SetCurrentPlatform, 1784 (const char *)); 1785 LLDB_REGISTER_METHOD(bool, SBDebugger, SetCurrentPlatformSDKRoot, 1786 (const char *)); 1787 LLDB_REGISTER_METHOD_CONST(bool, SBDebugger, GetCloseInputOnEOF, ()); 1788 LLDB_REGISTER_METHOD(void, SBDebugger, SetCloseInputOnEOF, (bool)); 1789 LLDB_REGISTER_METHOD(lldb::SBTypeCategory, SBDebugger, GetCategory, 1790 (const char *)); 1791 LLDB_REGISTER_METHOD(lldb::SBTypeCategory, SBDebugger, GetCategory, 1792 (lldb::LanguageType)); 1793 LLDB_REGISTER_METHOD(lldb::SBTypeCategory, SBDebugger, CreateCategory, 1794 (const char *)); 1795 LLDB_REGISTER_METHOD(bool, SBDebugger, DeleteCategory, (const char *)); 1796 LLDB_REGISTER_METHOD(uint32_t, SBDebugger, GetNumCategories, ()); 1797 LLDB_REGISTER_METHOD(lldb::SBTypeCategory, SBDebugger, GetCategoryAtIndex, 1798 (uint32_t)); 1799 LLDB_REGISTER_METHOD(lldb::SBTypeCategory, SBDebugger, GetDefaultCategory, 1800 ()); 1801 LLDB_REGISTER_METHOD(lldb::SBTypeFormat, SBDebugger, GetFormatForType, 1802 (lldb::SBTypeNameSpecifier)); 1803 LLDB_REGISTER_METHOD(lldb::SBTypeSummary, SBDebugger, GetSummaryForType, 1804 (lldb::SBTypeNameSpecifier)); 1805 LLDB_REGISTER_METHOD(lldb::SBTypeSynthetic, SBDebugger, GetSyntheticForType, 1806 (lldb::SBTypeNameSpecifier)); 1807 LLDB_REGISTER_METHOD(lldb::SBTypeFilter, SBDebugger, GetFilterForType, 1808 (lldb::SBTypeNameSpecifier)); 1809 LLDB_REGISTER_METHOD(bool, SBDebugger, EnableLog, 1810 (const char *, const char **)); 1811 } 1812 1813 } // namespace repro 1814 } // namespace lldb_private 1815