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