1 //===-- Debugger.h ----------------------------------------------*- 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 #ifndef LLDB_CORE_DEBUGGER_H 10 #define LLDB_CORE_DEBUGGER_H 11 12 #include <cstdint> 13 14 #include <memory> 15 #include <optional> 16 #include <vector> 17 18 #include "lldb/Core/DebuggerEvents.h" 19 #include "lldb/Core/FormatEntity.h" 20 #include "lldb/Core/IOHandler.h" 21 #include "lldb/Core/SourceManager.h" 22 #include "lldb/Core/UserSettingsController.h" 23 #include "lldb/Host/HostThread.h" 24 #include "lldb/Host/StreamFile.h" 25 #include "lldb/Host/Terminal.h" 26 #include "lldb/Target/ExecutionContext.h" 27 #include "lldb/Target/Platform.h" 28 #include "lldb/Target/TargetList.h" 29 #include "lldb/Utility/Broadcaster.h" 30 #include "lldb/Utility/ConstString.h" 31 #include "lldb/Utility/Diagnostics.h" 32 #include "lldb/Utility/FileSpec.h" 33 #include "lldb/Utility/Status.h" 34 #include "lldb/Utility/UserID.h" 35 #include "lldb/lldb-defines.h" 36 #include "lldb/lldb-enumerations.h" 37 #include "lldb/lldb-forward.h" 38 #include "lldb/lldb-private-enumerations.h" 39 #include "lldb/lldb-private-types.h" 40 #include "lldb/lldb-types.h" 41 42 #include "llvm/ADT/ArrayRef.h" 43 #include "llvm/ADT/SmallVector.h" 44 #include "llvm/ADT/StringMap.h" 45 #include "llvm/ADT/StringRef.h" 46 #include "llvm/Support/DynamicLibrary.h" 47 #include "llvm/Support/FormatVariadic.h" 48 #include "llvm/Support/Threading.h" 49 50 #include <cassert> 51 #include <cstddef> 52 #include <cstdio> 53 54 namespace llvm { 55 class raw_ostream; 56 class ThreadPoolInterface; 57 } // namespace llvm 58 59 namespace lldb_private { 60 class Address; 61 class CallbackLogHandler; 62 class CommandInterpreter; 63 class LogHandler; 64 class Process; 65 class Stream; 66 class SymbolContext; 67 class Target; 68 69 namespace repro { 70 class DataRecorder; 71 } 72 73 /// \class Debugger Debugger.h "lldb/Core/Debugger.h" 74 /// A class to manage flag bits. 75 /// 76 /// Provides a global root objects for the debugger core. 77 78 class Debugger : public std::enable_shared_from_this<Debugger>, 79 public UserID, 80 public Properties { 81 public: 82 using DebuggerList = std::vector<lldb::DebuggerSP>; 83 84 static llvm::StringRef GetStaticBroadcasterClass(); 85 86 /// Get the public broadcaster for this debugger. 87 Broadcaster &GetBroadcaster() { return m_broadcaster; } 88 const Broadcaster &GetBroadcaster() const { return m_broadcaster; } 89 90 ~Debugger() override; 91 92 static lldb::DebuggerSP 93 CreateInstance(lldb::LogOutputCallback log_callback = nullptr, 94 void *baton = nullptr); 95 96 static lldb::TargetSP FindTargetWithProcessID(lldb::pid_t pid); 97 98 static lldb::TargetSP FindTargetWithProcess(Process *process); 99 100 static void Initialize(LoadPluginCallbackType load_plugin_callback); 101 102 static void Terminate(); 103 104 static void SettingsInitialize(); 105 106 static void SettingsTerminate(); 107 108 static void Destroy(lldb::DebuggerSP &debugger_sp); 109 110 static lldb::DebuggerSP FindDebuggerWithID(lldb::user_id_t id); 111 112 static lldb::DebuggerSP 113 FindDebuggerWithInstanceName(llvm::StringRef instance_name); 114 115 static size_t GetNumDebuggers(); 116 117 static lldb::DebuggerSP GetDebuggerAtIndex(size_t index); 118 119 static bool FormatDisassemblerAddress(const FormatEntity::Entry *format, 120 const SymbolContext *sc, 121 const SymbolContext *prev_sc, 122 const ExecutionContext *exe_ctx, 123 const Address *addr, Stream &s); 124 125 static void AssertCallback(llvm::StringRef message, llvm::StringRef backtrace, 126 llvm::StringRef prompt); 127 128 void Clear(); 129 130 bool GetAsyncExecution(); 131 132 void SetAsyncExecution(bool async); 133 134 lldb::FileSP GetInputFileSP() { return m_input_file_sp; } 135 136 lldb::StreamFileSP GetOutputStreamSP() { return m_output_stream_sp; } 137 138 lldb::StreamFileSP GetErrorStreamSP() { return m_error_stream_sp; } 139 140 File &GetInputFile() { return *m_input_file_sp; } 141 142 File &GetOutputFile() { return m_output_stream_sp->GetFile(); } 143 144 File &GetErrorFile() { return m_error_stream_sp->GetFile(); } 145 146 StreamFile &GetOutputStream() { return *m_output_stream_sp; } 147 148 StreamFile &GetErrorStream() { return *m_error_stream_sp; } 149 150 repro::DataRecorder *GetInputRecorder(); 151 152 Status SetInputString(const char *data); 153 154 void SetInputFile(lldb::FileSP file); 155 156 void SetOutputFile(lldb::FileSP file); 157 158 void SetErrorFile(lldb::FileSP file); 159 160 void SaveInputTerminalState(); 161 162 void RestoreInputTerminalState(); 163 164 lldb::StreamSP GetAsyncOutputStream(); 165 166 lldb::StreamSP GetAsyncErrorStream(); 167 168 CommandInterpreter &GetCommandInterpreter() { 169 assert(m_command_interpreter_up.get()); 170 return *m_command_interpreter_up; 171 } 172 173 ScriptInterpreter * 174 GetScriptInterpreter(bool can_create = true, 175 std::optional<lldb::ScriptLanguage> language = {}); 176 177 lldb::ListenerSP GetListener() { return m_listener_sp; } 178 179 // This returns the Debugger's scratch source manager. It won't be able to 180 // look up files in debug information, but it can look up files by absolute 181 // path and display them to you. To get the target's source manager, call 182 // GetSourceManager on the target instead. 183 SourceManager &GetSourceManager(); 184 185 lldb::TargetSP GetSelectedTarget() { 186 return m_target_list.GetSelectedTarget(); 187 } 188 189 ExecutionContext GetSelectedExecutionContext(); 190 /// Get accessor for the target list. 191 /// 192 /// The target list is part of the global debugger object. This the single 193 /// debugger shared instance to control where targets get created and to 194 /// allow for tracking and searching for targets based on certain criteria. 195 /// 196 /// \return 197 /// A global shared target list. 198 TargetList &GetTargetList() { return m_target_list; } 199 200 PlatformList &GetPlatformList() { return m_platform_list; } 201 202 void DispatchInputInterrupt(); 203 204 void DispatchInputEndOfFile(); 205 206 // If any of the streams are not set, set them to the in/out/err stream of 207 // the top most input reader to ensure they at least have something 208 void AdoptTopIOHandlerFilesIfInvalid(lldb::FileSP &in, 209 lldb::StreamFileSP &out, 210 lldb::StreamFileSP &err); 211 212 /// Run the given IO handler and return immediately. 213 void RunIOHandlerAsync(const lldb::IOHandlerSP &reader_sp, 214 bool cancel_top_handler = true); 215 216 /// Run the given IO handler and block until it's complete. 217 void RunIOHandlerSync(const lldb::IOHandlerSP &reader_sp); 218 219 /// Remove the given IO handler if it's currently active. 220 bool RemoveIOHandler(const lldb::IOHandlerSP &reader_sp); 221 222 bool IsTopIOHandler(const lldb::IOHandlerSP &reader_sp); 223 224 bool CheckTopIOHandlerTypes(IOHandler::Type top_type, 225 IOHandler::Type second_top_type); 226 227 void PrintAsync(const char *s, size_t len, bool is_stdout); 228 229 llvm::StringRef GetTopIOHandlerControlSequence(char ch); 230 231 const char *GetIOHandlerCommandPrefix(); 232 233 const char *GetIOHandlerHelpPrologue(); 234 235 void ClearIOHandlers(); 236 237 bool EnableLog(llvm::StringRef channel, 238 llvm::ArrayRef<const char *> categories, 239 llvm::StringRef log_file, uint32_t log_options, 240 size_t buffer_size, LogHandlerKind log_handler_kind, 241 llvm::raw_ostream &error_stream); 242 243 void SetLoggingCallback(lldb::LogOutputCallback log_callback, void *baton); 244 245 // Properties Functions 246 enum StopDisassemblyType { 247 eStopDisassemblyTypeNever = 0, 248 eStopDisassemblyTypeNoDebugInfo, 249 eStopDisassemblyTypeNoSource, 250 eStopDisassemblyTypeAlways 251 }; 252 253 Status SetPropertyValue(const ExecutionContext *exe_ctx, 254 VarSetOperationType op, llvm::StringRef property_path, 255 llvm::StringRef value) override; 256 257 bool GetAutoConfirm() const; 258 259 const FormatEntity::Entry *GetDisassemblyFormat() const; 260 261 const FormatEntity::Entry *GetFrameFormat() const; 262 263 const FormatEntity::Entry *GetFrameFormatUnique() const; 264 265 uint64_t GetStopDisassemblyMaxSize() const; 266 267 const FormatEntity::Entry *GetThreadFormat() const; 268 269 const FormatEntity::Entry *GetThreadStopFormat() const; 270 271 lldb::ScriptLanguage GetScriptLanguage() const; 272 273 bool SetScriptLanguage(lldb::ScriptLanguage script_lang); 274 275 lldb::LanguageType GetREPLLanguage() const; 276 277 bool SetREPLLanguage(lldb::LanguageType repl_lang); 278 279 uint64_t GetTerminalWidth() const; 280 281 bool SetTerminalWidth(uint64_t term_width); 282 283 uint64_t GetTerminalHeight() const; 284 285 bool SetTerminalHeight(uint64_t term_height); 286 287 llvm::StringRef GetPrompt() const; 288 289 llvm::StringRef GetPromptAnsiPrefix() const; 290 291 llvm::StringRef GetPromptAnsiSuffix() const; 292 293 void SetPrompt(llvm::StringRef p); 294 void SetPrompt(const char *) = delete; 295 296 bool GetUseExternalEditor() const; 297 bool SetUseExternalEditor(bool use_external_editor_p); 298 299 llvm::StringRef GetExternalEditor() const; 300 301 bool SetExternalEditor(llvm::StringRef editor); 302 303 bool GetUseColor() const; 304 305 bool SetUseColor(bool use_color); 306 307 bool GetShowProgress() const; 308 309 bool SetShowProgress(bool show_progress); 310 311 llvm::StringRef GetShowProgressAnsiPrefix() const; 312 313 llvm::StringRef GetShowProgressAnsiSuffix() const; 314 315 bool GetUseAutosuggestion() const; 316 317 llvm::StringRef GetAutosuggestionAnsiPrefix() const; 318 319 llvm::StringRef GetAutosuggestionAnsiSuffix() const; 320 321 llvm::StringRef GetRegexMatchAnsiPrefix() const; 322 323 llvm::StringRef GetRegexMatchAnsiSuffix() const; 324 325 bool GetShowDontUsePoHint() const; 326 327 bool GetUseSourceCache() const; 328 329 bool SetUseSourceCache(bool use_source_cache); 330 331 bool GetHighlightSource() const; 332 333 lldb::StopShowColumn GetStopShowColumn() const; 334 335 llvm::StringRef GetStopShowColumnAnsiPrefix() const; 336 337 llvm::StringRef GetStopShowColumnAnsiSuffix() const; 338 339 uint64_t GetStopSourceLineCount(bool before) const; 340 341 StopDisassemblyType GetStopDisassemblyDisplay() const; 342 343 uint64_t GetDisassemblyLineCount() const; 344 345 llvm::StringRef GetStopShowLineMarkerAnsiPrefix() const; 346 347 llvm::StringRef GetStopShowLineMarkerAnsiSuffix() const; 348 349 bool GetAutoOneLineSummaries() const; 350 351 bool GetAutoIndent() const; 352 353 bool SetAutoIndent(bool b); 354 355 bool GetPrintDecls() const; 356 357 bool SetPrintDecls(bool b); 358 359 uint64_t GetTabSize() const; 360 361 bool SetTabSize(uint64_t tab_size); 362 363 lldb::DWIMPrintVerbosity GetDWIMPrintVerbosity() const; 364 365 bool GetEscapeNonPrintables() const; 366 367 bool GetNotifyVoid() const; 368 369 const std::string &GetInstanceName() { return m_instance_name; } 370 371 bool GetShowInlineDiagnostics() const; 372 373 bool SetShowInlineDiagnostics(bool); 374 375 bool LoadPlugin(const FileSpec &spec, Status &error); 376 377 void RunIOHandlers(); 378 379 bool IsForwardingEvents(); 380 381 void EnableForwardEvents(const lldb::ListenerSP &listener_sp); 382 383 void CancelForwardEvents(const lldb::ListenerSP &listener_sp); 384 385 bool IsHandlingEvents() const { return m_event_handler_thread.IsJoinable(); } 386 387 Status RunREPL(lldb::LanguageType language, const char *repl_options); 388 389 /// Interruption in LLDB: 390 /// 391 /// This is a voluntary interruption mechanism, not preemptive. Parts of lldb 392 /// that do work that can be safely interrupted call 393 /// Debugger::InterruptRequested and if that returns true, they should return 394 /// at a safe point, shortcutting the rest of the work they were to do. 395 /// 396 /// lldb clients can both offer a CommandInterpreter (through 397 /// RunCommandInterpreter) and use the SB API's for their own purposes, so it 398 /// is convenient to separate "interrupting the CommandInterpreter execution" 399 /// and interrupting the work it is doing with the SB API's. So there are two 400 /// ways to cause an interrupt: 401 /// * CommandInterpreter::InterruptCommand: Interrupts the command currently 402 /// running in the command interpreter IOHandler thread 403 /// * Debugger::RequestInterrupt: Interrupts are active on anything but the 404 /// CommandInterpreter thread till CancelInterruptRequest is called. 405 /// 406 /// Since the two checks are mutually exclusive, however, it's also convenient 407 /// to have just one function to check the interrupt state. 408 409 /// Bump the "interrupt requested" count on the debugger to support 410 /// cooperative interruption. If this is non-zero, InterruptRequested will 411 /// return true. Interruptible operations are expected to query the 412 /// InterruptRequested API periodically, and interrupt what they were doing 413 /// if it returns \b true. 414 /// 415 void RequestInterrupt(); 416 417 /// Decrement the "interrupt requested" counter. 418 void CancelInterruptRequest(); 419 420 /// This is the correct way to query the state of Interruption. 421 /// If you are on the RunCommandInterpreter thread, it will check the 422 /// command interpreter state, and if it is on another thread it will 423 /// check the debugger Interrupt Request state. 424 /// \param[in] cur_func 425 /// For reporting if the interruption was requested. Don't provide this by 426 /// hand, use INTERRUPT_REQUESTED so this gets done consistently. 427 /// 428 /// \param[in] formatv 429 /// A formatv string for the interrupt message. If the elements of the 430 /// message are expensive to compute, you can use the no-argument form of 431 /// InterruptRequested, then make up the report using REPORT_INTERRUPTION. 432 /// 433 /// \return 434 /// A boolean value, if \b true an interruptible operation should interrupt 435 /// itself. 436 template <typename... Args> 437 bool InterruptRequested(const char *cur_func, const char *formatv, 438 Args &&...args) { 439 bool ret_val = InterruptRequested(); 440 if (ret_val) { 441 if (!formatv) 442 formatv = "Unknown message"; 443 if (!cur_func) 444 cur_func = "<UNKNOWN>"; 445 ReportInterruption(InterruptionReport( 446 cur_func, llvm::formatv(formatv, std::forward<Args>(args)...))); 447 } 448 return ret_val; 449 } 450 451 /// This handy define will keep you from having to generate a report for the 452 /// interruption by hand. Use this except in the case where the arguments to 453 /// the message description are expensive to compute. 454 #define INTERRUPT_REQUESTED(debugger, ...) \ 455 (debugger).InterruptRequested(__func__, __VA_ARGS__) 456 457 // This form just queries for whether to interrupt, and does no reporting: 458 bool InterruptRequested(); 459 460 // FIXME: Do we want to capture a backtrace at the interruption point? 461 class InterruptionReport { 462 public: 463 InterruptionReport(std::string function_name, std::string description) 464 : m_function_name(std::move(function_name)), 465 m_description(std::move(description)), 466 m_interrupt_time(std::chrono::system_clock::now()), 467 m_thread_id(llvm::get_threadid()) {} 468 469 InterruptionReport(std::string function_name, 470 const llvm::formatv_object_base &payload); 471 472 template <typename... Args> 473 InterruptionReport(std::string function_name, const char *format, 474 Args &&...args) 475 : InterruptionReport( 476 function_name, 477 llvm::formatv(format, std::forward<Args>(args)...)) {} 478 479 std::string m_function_name; 480 std::string m_description; 481 const std::chrono::time_point<std::chrono::system_clock> m_interrupt_time; 482 const uint64_t m_thread_id; 483 }; 484 void ReportInterruption(const InterruptionReport &report); 485 #define REPORT_INTERRUPTION(debugger, ...) \ 486 (debugger).ReportInterruption( \ 487 Debugger::InterruptionReport(__func__, __VA_ARGS__)) 488 489 static DebuggerList DebuggersRequestingInterruption(); 490 491 public: 492 // This is for use in the command interpreter, when you either want the 493 // selected target, or if no target is present you want to prime the dummy 494 // target with entities that will be copied over to new targets. 495 Target &GetSelectedOrDummyTarget(bool prefer_dummy = false); 496 Target &GetDummyTarget() { return *m_dummy_target_sp; } 497 498 lldb::BroadcasterManagerSP GetBroadcasterManager() { 499 return m_broadcaster_manager_sp; 500 } 501 502 /// Shared thread pool. Use only with ThreadPoolTaskGroup. 503 static llvm::ThreadPoolInterface &GetThreadPool(); 504 505 /// Report warning events. 506 /// 507 /// Warning events will be delivered to any debuggers that have listeners 508 /// for the eBroadcastBitWarning. 509 /// 510 /// \param[in] message 511 /// The warning message to be reported. 512 /// 513 /// \param [in] debugger_id 514 /// If this optional parameter has a value, it indicates the unique 515 /// debugger identifier that this diagnostic should be delivered to. If 516 /// this optional parameter does not have a value, the diagnostic event 517 /// will be delivered to all debuggers. 518 /// 519 /// \param [in] once 520 /// If a pointer is passed to a std::once_flag, then it will be used to 521 /// ensure the given warning is only broadcast once. 522 static void 523 ReportWarning(std::string message, 524 std::optional<lldb::user_id_t> debugger_id = std::nullopt, 525 std::once_flag *once = nullptr); 526 527 /// Report error events. 528 /// 529 /// Error events will be delivered to any debuggers that have listeners 530 /// for the eBroadcastBitError. 531 /// 532 /// \param[in] message 533 /// The error message to be reported. 534 /// 535 /// \param [in] debugger_id 536 /// If this optional parameter has a value, it indicates the unique 537 /// debugger identifier that this diagnostic should be delivered to. If 538 /// this optional parameter does not have a value, the diagnostic event 539 /// will be delivered to all debuggers. 540 /// 541 /// \param [in] once 542 /// If a pointer is passed to a std::once_flag, then it will be used to 543 /// ensure the given error is only broadcast once. 544 static void 545 ReportError(std::string message, 546 std::optional<lldb::user_id_t> debugger_id = std::nullopt, 547 std::once_flag *once = nullptr); 548 549 /// Report info events. 550 /// 551 /// Unlike warning and error events, info events are not broadcast but are 552 /// logged for diagnostic purposes. 553 /// 554 /// \param[in] message 555 /// The info message to be reported. 556 /// 557 /// \param [in] debugger_id 558 /// If this optional parameter has a value, it indicates this diagnostic is 559 /// associated with a unique debugger instance. 560 /// 561 /// \param [in] once 562 /// If a pointer is passed to a std::once_flag, then it will be used to 563 /// ensure the given info is only logged once. 564 static void 565 ReportInfo(std::string message, 566 std::optional<lldb::user_id_t> debugger_id = std::nullopt, 567 std::once_flag *once = nullptr); 568 569 static void ReportSymbolChange(const ModuleSpec &module_spec); 570 571 /// DEPRECATED: We used to only support one Destroy callback. Now that we 572 /// support Add and Remove, you should only remove callbacks that you added. 573 /// Use Add and Remove instead. 574 /// 575 /// Clear all previously added callbacks and only add the given one. 576 void 577 SetDestroyCallback(lldb_private::DebuggerDestroyCallback destroy_callback, 578 void *baton); 579 580 /// Add a callback for when the debugger is destroyed. Return a token, which 581 /// can be used to remove said callback. Multiple callbacks can be added by 582 /// calling this function multiple times, and will be invoked in FIFO order. 583 lldb::callback_token_t 584 AddDestroyCallback(lldb_private::DebuggerDestroyCallback destroy_callback, 585 void *baton); 586 587 /// Remove the specified callback. Return true if successful. 588 bool RemoveDestroyCallback(lldb::callback_token_t token); 589 590 /// Manually start the global event handler thread. It is useful to plugins 591 /// that directly use the \a lldb_private namespace and want to use the 592 /// debugger's default event handler thread instead of defining their own. 593 bool StartEventHandlerThread(); 594 595 /// Manually stop the debugger's default event handler. 596 void StopEventHandlerThread(); 597 598 /// Force flushing the process's pending stdout and stderr to the debugger's 599 /// asynchronous stdout and stderr streams. 600 void FlushProcessOutput(Process &process, bool flush_stdout, 601 bool flush_stderr); 602 603 SourceManager::SourceFileCache &GetSourceFileCache() { 604 return m_source_file_cache; 605 } 606 607 protected: 608 friend class CommandInterpreter; 609 friend class REPL; 610 friend class Progress; 611 friend class ProgressManager; 612 613 /// Report progress events. 614 /// 615 /// Progress events will be delivered to any debuggers that have listeners 616 /// for the eBroadcastBitProgress. This function is called by the 617 /// lldb_private::Progress class to deliver the events to any debuggers that 618 /// qualify. 619 /// 620 /// \param [in] progress_id 621 /// The unique integer identifier for the progress to report. 622 /// 623 /// \param[in] message 624 /// The title of the progress dialog to display in the UI. 625 /// 626 /// \param [in] completed 627 /// The amount of work completed. If \a completed is zero, then this event 628 /// is a progress started event. If \a completed is equal to \a total, then 629 /// this event is a progress end event. Otherwise completed indicates the 630 /// current progress compare to the total value. 631 /// 632 /// \param [in] total 633 /// The total amount of work units that need to be completed. If this value 634 /// is UINT64_MAX, then an indeterminate progress indicator should be 635 /// displayed. 636 /// 637 /// \param [in] debugger_id 638 /// If this optional parameter has a value, it indicates the unique 639 /// debugger identifier that this progress should be delivered to. If this 640 /// optional parameter does not have a value, the progress will be 641 /// delivered to all debuggers. 642 static void 643 ReportProgress(uint64_t progress_id, std::string title, std::string details, 644 uint64_t completed, uint64_t total, 645 std::optional<lldb::user_id_t> debugger_id, 646 uint32_t progress_category_bit = lldb::eBroadcastBitProgress); 647 648 static void ReportDiagnosticImpl(lldb::Severity severity, std::string message, 649 std::optional<lldb::user_id_t> debugger_id, 650 std::once_flag *once); 651 652 void HandleDestroyCallback(); 653 654 void PrintProgress(const ProgressEventData &data); 655 656 void PushIOHandler(const lldb::IOHandlerSP &reader_sp, 657 bool cancel_top_handler = true); 658 659 bool PopIOHandler(const lldb::IOHandlerSP &reader_sp); 660 661 bool HasIOHandlerThread() const; 662 663 bool StartIOHandlerThread(); 664 665 void StopIOHandlerThread(); 666 667 // Sets the IOHandler thread to the new_thread, and returns 668 // the previous IOHandler thread. 669 HostThread SetIOHandlerThread(HostThread &new_thread); 670 671 void JoinIOHandlerThread(); 672 673 bool IsIOHandlerThreadCurrentThread() const; 674 675 lldb::thread_result_t IOHandlerThread(); 676 677 lldb::thread_result_t DefaultEventHandler(); 678 679 void HandleBreakpointEvent(const lldb::EventSP &event_sp); 680 681 void HandleProcessEvent(const lldb::EventSP &event_sp); 682 683 void HandleThreadEvent(const lldb::EventSP &event_sp); 684 685 void HandleProgressEvent(const lldb::EventSP &event_sp); 686 687 void HandleDiagnosticEvent(const lldb::EventSP &event_sp); 688 689 // Ensures two threads don't attempt to flush process output in parallel. 690 std::mutex m_output_flush_mutex; 691 692 void InstanceInitialize(); 693 694 // these should never be NULL 695 lldb::FileSP m_input_file_sp; 696 lldb::StreamFileSP m_output_stream_sp; 697 lldb::StreamFileSP m_error_stream_sp; 698 699 /// Used for shadowing the input file when capturing a reproducer. 700 repro::DataRecorder *m_input_recorder; 701 702 lldb::BroadcasterManagerSP m_broadcaster_manager_sp; // The debugger acts as a 703 // broadcaster manager of 704 // last resort. 705 // It needs to get constructed before the target_list or any other member 706 // that might want to broadcast through the debugger. 707 708 TerminalState m_terminal_state; 709 TargetList m_target_list; 710 711 PlatformList m_platform_list; 712 lldb::ListenerSP m_listener_sp; 713 std::unique_ptr<SourceManager> m_source_manager_up; // This is a scratch 714 // source manager that we 715 // return if we have no 716 // targets. 717 SourceManager::SourceFileCache m_source_file_cache; // All the source managers 718 // for targets created in 719 // this debugger used this 720 // shared 721 // source file cache. 722 std::unique_ptr<CommandInterpreter> m_command_interpreter_up; 723 724 std::recursive_mutex m_script_interpreter_mutex; 725 std::array<lldb::ScriptInterpreterSP, lldb::eScriptLanguageUnknown> 726 m_script_interpreters; 727 728 IOHandlerStack m_io_handler_stack; 729 std::recursive_mutex m_io_handler_synchronous_mutex; 730 731 std::optional<uint64_t> m_current_event_id; 732 733 llvm::StringMap<std::weak_ptr<LogHandler>> m_stream_handlers; 734 std::shared_ptr<CallbackLogHandler> m_callback_handler_sp; 735 const std::string m_instance_name; 736 static LoadPluginCallbackType g_load_plugin_callback; 737 typedef std::vector<llvm::sys::DynamicLibrary> LoadedPluginsList; 738 LoadedPluginsList m_loaded_plugins; 739 HostThread m_event_handler_thread; 740 HostThread m_io_handler_thread; 741 Broadcaster m_sync_broadcaster; ///< Private debugger synchronization. 742 Broadcaster m_broadcaster; ///< Public Debugger event broadcaster. 743 lldb::ListenerSP m_forward_listener_sp; 744 llvm::once_flag m_clear_once; 745 lldb::TargetSP m_dummy_target_sp; 746 Diagnostics::CallbackID m_diagnostics_callback_id; 747 748 std::mutex m_destroy_callback_mutex; 749 lldb::callback_token_t m_destroy_callback_next_token = 0; 750 struct DestroyCallbackInfo { 751 DestroyCallbackInfo() {} 752 DestroyCallbackInfo(lldb::callback_token_t token, 753 lldb_private::DebuggerDestroyCallback callback, 754 void *baton) 755 : token(token), callback(callback), baton(baton) {} 756 lldb::callback_token_t token; 757 lldb_private::DebuggerDestroyCallback callback; 758 void *baton; 759 }; 760 llvm::SmallVector<DestroyCallbackInfo, 2> m_destroy_callbacks; 761 762 uint32_t m_interrupt_requested = 0; ///< Tracks interrupt requests 763 std::mutex m_interrupt_mutex; 764 765 // Events for m_sync_broadcaster 766 enum { 767 eBroadcastBitEventThreadIsListening = (1 << 0), 768 }; 769 770 private: 771 // Use Debugger::CreateInstance() to get a shared pointer to a new debugger 772 // object 773 Debugger(lldb::LogOutputCallback m_log_callback, void *baton); 774 775 Debugger(const Debugger &) = delete; 776 const Debugger &operator=(const Debugger &) = delete; 777 }; 778 779 } // namespace lldb_private 780 781 #endif // LLDB_CORE_DEBUGGER_H 782