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/StreamFile.h"
23 #include "lldb/Core/UserSettingsController.h"
24 #include "lldb/Host/HostThread.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.
94   Broadcaster &GetBroadcaster() { return m_broadcaster; }
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 
141   lldb::FileSP GetInputFileSP() { return m_input_file_sp; }
142 
143   lldb::StreamFileSP GetOutputStreamSP() { return m_output_stream_sp; }
144 
145   lldb::StreamFileSP GetErrorStreamSP() { return m_error_stream_sp; }
146 
147   File &GetInputFile() { return *m_input_file_sp; }
148 
149   File &GetOutputFile() { return m_output_stream_sp->GetFile(); }
150 
151   File &GetErrorFile() { return m_error_stream_sp->GetFile(); }
152 
153   StreamFile &GetOutputStream() { return *m_output_stream_sp; }
154 
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 
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 
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 
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.
205   TargetList &GetTargetList() { return m_target_list; }
206 
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 GetCloseInputOnEOF() const;
245 
246   void SetCloseInputOnEOF(bool b);
247 
248   bool EnableLog(llvm::StringRef channel,
249                  llvm::ArrayRef<const char *> categories,
250                  llvm::StringRef log_file, uint32_t log_options,
251                  size_t buffer_size, LogHandlerKind log_handler_kind,
252                  llvm::raw_ostream &error_stream);
253 
254   void SetLoggingCallback(lldb::LogOutputCallback log_callback, void *baton);
255 
256   // Properties Functions
257   enum StopDisassemblyType {
258     eStopDisassemblyTypeNever = 0,
259     eStopDisassemblyTypeNoDebugInfo,
260     eStopDisassemblyTypeNoSource,
261     eStopDisassemblyTypeAlways
262   };
263 
264   Status SetPropertyValue(const ExecutionContext *exe_ctx,
265                           VarSetOperationType op, llvm::StringRef property_path,
266                           llvm::StringRef value) override;
267 
268   bool GetAutoConfirm() const;
269 
270   const FormatEntity::Entry *GetDisassemblyFormat() const;
271 
272   const FormatEntity::Entry *GetFrameFormat() const;
273 
274   const FormatEntity::Entry *GetFrameFormatUnique() const;
275 
276   uint64_t GetStopDisassemblyMaxSize() const;
277 
278   const FormatEntity::Entry *GetThreadFormat() const;
279 
280   const FormatEntity::Entry *GetThreadStopFormat() const;
281 
282   lldb::ScriptLanguage GetScriptLanguage() const;
283 
284   bool SetScriptLanguage(lldb::ScriptLanguage script_lang);
285 
286   lldb::LanguageType GetREPLLanguage() const;
287 
288   bool SetREPLLanguage(lldb::LanguageType repl_lang);
289 
290   uint64_t GetTerminalWidth() const;
291 
292   bool SetTerminalWidth(uint64_t term_width);
293 
294   llvm::StringRef GetPrompt() 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   bool GetUseSourceCache() const;
325 
326   bool SetUseSourceCache(bool use_source_cache);
327 
328   bool GetHighlightSource() const;
329 
330   lldb::StopShowColumn GetStopShowColumn() const;
331 
332   llvm::StringRef GetStopShowColumnAnsiPrefix() const;
333 
334   llvm::StringRef GetStopShowColumnAnsiSuffix() const;
335 
336   uint64_t GetStopSourceLineCount(bool before) const;
337 
338   StopDisassemblyType GetStopDisassemblyDisplay() const;
339 
340   uint64_t GetDisassemblyLineCount() const;
341 
342   llvm::StringRef GetStopShowLineMarkerAnsiPrefix() const;
343 
344   llvm::StringRef GetStopShowLineMarkerAnsiSuffix() const;
345 
346   bool GetAutoOneLineSummaries() const;
347 
348   bool GetAutoIndent() const;
349 
350   bool SetAutoIndent(bool b);
351 
352   bool GetPrintDecls() const;
353 
354   bool SetPrintDecls(bool b);
355 
356   uint64_t GetTabSize() const;
357 
358   bool SetTabSize(uint64_t tab_size);
359 
360   lldb::DWIMPrintVerbosity GetDWIMPrintVerbosity() const;
361 
362   bool GetEscapeNonPrintables() const;
363 
364   bool GetNotifyVoid() const;
365 
366   const std::string &GetInstanceName() { return m_instance_name; }
367 
368   bool LoadPlugin(const FileSpec &spec, Status &error);
369 
370   void RunIOHandlers();
371 
372   bool IsForwardingEvents();
373 
374   void EnableForwardEvents(const lldb::ListenerSP &listener_sp);
375 
376   void CancelForwardEvents(const lldb::ListenerSP &listener_sp);
377 
378   bool IsHandlingEvents() const { return m_event_handler_thread.IsJoinable(); }
379 
380   Status RunREPL(lldb::LanguageType language, const char *repl_options);
381 
382   /// Interruption in LLDB:
383   ///
384   /// This is a voluntary interruption mechanism, not preemptive.  Parts of lldb
385   /// that do work that can be safely interrupted call
386   /// Debugger::InterruptRequested and if that returns true, they should return
387   /// at a safe point, shortcutting the rest of the work they were to do.
388   ///
389   /// lldb clients can both offer a CommandInterpreter (through
390   /// RunCommandInterpreter) and use the SB API's for their own purposes, so it
391   /// is convenient to separate "interrupting the CommandInterpreter execution"
392   /// and interrupting the work it is doing with the SB API's.  So there are two
393   /// ways to cause an interrupt:
394   ///   * CommandInterpreter::InterruptCommand: Interrupts the command currently
395   ///     running in the command interpreter IOHandler thread
396   ///   * Debugger::RequestInterrupt: Interrupts are active on anything but the
397   ///     CommandInterpreter thread till CancelInterruptRequest is called.
398   ///
399   /// Since the two checks are mutually exclusive, however, it's also convenient
400   /// to have just one function to check the interrupt state.
401 
402   /// Bump the "interrupt requested" count on the debugger to support
403   /// cooperative interruption.  If this is non-zero, InterruptRequested will
404   /// return true.  Interruptible operations are expected to query the
405   /// InterruptRequested API periodically, and interrupt what they were doing
406   /// if it returns \b true.
407   ///
408   void RequestInterrupt();
409 
410   /// Decrement the "interrupt requested" counter.
411   void CancelInterruptRequest();
412 
413   /// This is the correct way to query the state of Interruption.
414   /// If you are on the RunCommandInterpreter thread, it will check the
415   /// command interpreter state, and if it is on another thread it will
416   /// check the debugger Interrupt Request state.
417   /// \param[in] cur_func
418   /// For reporting if the interruption was requested.  Don't provide this by
419   /// hand, use INTERRUPT_REQUESTED so this gets done consistently.
420   ///
421   /// \param[in] formatv
422   /// A formatv string for the interrupt message.  If the elements of the
423   /// message are expensive to compute, you can use the no-argument form of
424   /// InterruptRequested, then make up the report using REPORT_INTERRUPTION.
425   ///
426   /// \return
427   ///  A boolean value, if \b true an interruptible operation should interrupt
428   ///  itself.
429   template <typename... Args>
430   bool InterruptRequested(const char *cur_func,
431                           const char *formatv, Args &&... args) {
432     bool ret_val = InterruptRequested();
433     if (ret_val) {
434       if (!formatv)
435         formatv = "Unknown message";
436       if (!cur_func)
437         cur_func = "<UNKNOWN>";
438       ReportInterruption(InterruptionReport(cur_func,
439                                             llvm::formatv(formatv,
440                                             std::forward<Args>(args)...)));
441     }
442     return ret_val;
443   }
444 
445 
446   /// This handy define will keep you from having to generate a report for the
447   /// interruption by hand.  Use this except in the case where the arguments to
448   /// the message description are expensive to compute.
449 #define INTERRUPT_REQUESTED(debugger, ...) \
450     (debugger).InterruptRequested(__func__, __VA_ARGS__)
451 
452   // This form just queries for whether to interrupt, and does no reporting:
453   bool InterruptRequested();
454 
455   // FIXME: Do we want to capture a backtrace at the interruption point?
456   class InterruptionReport {
457   public:
458     InterruptionReport(std::string function_name, std::string description) :
459         m_function_name(std::move(function_name)),
460         m_description(std::move(description)),
461         m_interrupt_time(std::chrono::system_clock::now()),
462         m_thread_id(llvm::get_threadid()) {}
463 
464     InterruptionReport(std::string function_name,
465         const llvm::formatv_object_base &payload);
466 
467   template <typename... Args>
468   InterruptionReport(std::string function_name,
469               const char *format, Args &&... args) :
470     InterruptionReport(function_name, llvm::formatv(format, std::forward<Args>(args)...)) {}
471 
472     std::string m_function_name;
473     std::string m_description;
474     const std::chrono::time_point<std::chrono::system_clock> m_interrupt_time;
475     const uint64_t m_thread_id;
476   };
477   void ReportInterruption(const InterruptionReport &report);
478 #define REPORT_INTERRUPTION(debugger, ...) \
479     (debugger).ReportInterruption(Debugger::InterruptionReport(__func__, \
480                                                         __VA_ARGS__))
481 
482   static DebuggerList DebuggersRequestingInterruption();
483 
484 public:
485 
486   // This is for use in the command interpreter, when you either want the
487   // selected target, or if no target is present you want to prime the dummy
488   // target with entities that will be copied over to new targets.
489   Target &GetSelectedOrDummyTarget(bool prefer_dummy = false);
490   Target &GetDummyTarget() { return *m_dummy_target_sp; }
491 
492   lldb::BroadcasterManagerSP GetBroadcasterManager() {
493     return m_broadcaster_manager_sp;
494   }
495 
496   /// Shared thread poll. Use only with ThreadPoolTaskGroup.
497   static llvm::ThreadPool &GetThreadPool();
498 
499   /// Report warning events.
500   ///
501   /// Warning events will be delivered to any debuggers that have listeners
502   /// for the eBroadcastBitWarning.
503   ///
504   /// \param[in] message
505   ///   The warning message to be reported.
506   ///
507   /// \param [in] debugger_id
508   ///   If this optional parameter has a value, it indicates the unique
509   ///   debugger identifier that this diagnostic should be delivered to. If
510   ///   this optional parameter does not have a value, the diagnostic event
511   ///   will be delivered to all debuggers.
512   ///
513   /// \param [in] once
514   ///   If a pointer is passed to a std::once_flag, then it will be used to
515   ///   ensure the given warning is only broadcast once.
516   static void
517   ReportWarning(std::string message,
518                 std::optional<lldb::user_id_t> debugger_id = std::nullopt,
519                 std::once_flag *once = nullptr);
520 
521   /// Report error events.
522   ///
523   /// Error events will be delivered to any debuggers that have listeners
524   /// for the eBroadcastBitError.
525   ///
526   /// \param[in] message
527   ///   The error message to be reported.
528   ///
529   /// \param [in] debugger_id
530   ///   If this optional parameter has a value, it indicates the unique
531   ///   debugger identifier that this diagnostic should be delivered to. If
532   ///   this optional parameter does not have a value, the diagnostic event
533   ///   will be delivered to all debuggers.
534   ///
535   /// \param [in] once
536   ///   If a pointer is passed to a std::once_flag, then it will be used to
537   ///   ensure the given error is only broadcast once.
538   static void
539   ReportError(std::string message,
540               std::optional<lldb::user_id_t> debugger_id = std::nullopt,
541               std::once_flag *once = nullptr);
542 
543   /// Report info events.
544   ///
545   /// Unlike warning and error events, info events are not broadcast but are
546   /// logged for diagnostic purposes.
547   ///
548   /// \param[in] message
549   ///   The info message to be reported.
550   ///
551   /// \param [in] debugger_id
552   ///   If this optional parameter has a value, it indicates this diagnostic is
553   ///   associated with a unique debugger instance.
554   ///
555   /// \param [in] once
556   ///   If a pointer is passed to a std::once_flag, then it will be used to
557   ///   ensure the given info is only logged once.
558   static void
559   ReportInfo(std::string message,
560              std::optional<lldb::user_id_t> debugger_id = std::nullopt,
561              std::once_flag *once = nullptr);
562 
563   static void ReportSymbolChange(const ModuleSpec &module_spec);
564 
565   void
566   SetDestroyCallback(lldb_private::DebuggerDestroyCallback destroy_callback,
567                      void *baton);
568 
569   /// Manually start the global event handler thread. It is useful to plugins
570   /// that directly use the \a lldb_private namespace and want to use the
571   /// debugger's default event handler thread instead of defining their own.
572   bool StartEventHandlerThread();
573 
574   /// Manually stop the debugger's default event handler.
575   void StopEventHandlerThread();
576 
577   /// Force flushing the process's pending stdout and stderr to the debugger's
578   /// asynchronous stdout and stderr streams.
579   void FlushProcessOutput(Process &process, bool flush_stdout,
580                           bool flush_stderr);
581 
582   SourceManager::SourceFileCache &GetSourceFileCache() {
583     return m_source_file_cache;
584   }
585 
586 protected:
587   friend class CommandInterpreter;
588   friend class REPL;
589   friend class Progress;
590 
591   /// Report progress events.
592   ///
593   /// Progress events will be delivered to any debuggers that have listeners
594   /// for the eBroadcastBitProgress. This function is called by the
595   /// lldb_private::Progress class to deliver the events to any debuggers that
596   /// qualify.
597   ///
598   /// \param [in] progress_id
599   ///   The unique integer identifier for the progress to report.
600   ///
601   /// \param[in] message
602   ///   The title of the progress dialog to display in the UI.
603   ///
604   /// \param [in] completed
605   ///   The amount of work completed. If \a completed is zero, then this event
606   ///   is a progress started event. If \a completed is equal to \a total, then
607   ///   this event is a progress end event. Otherwise completed indicates the
608   ///   current progress compare to the total value.
609   ///
610   /// \param [in] total
611   ///   The total amount of work units that need to be completed. If this value
612   ///   is UINT64_MAX, then an indeterminate progress indicator should be
613   ///   displayed.
614   ///
615   /// \param [in] debugger_id
616   ///   If this optional parameter has a value, it indicates the unique
617   ///   debugger identifier that this progress should be delivered to. If this
618   ///   optional parameter does not have a value, the progress will be
619   ///   delivered to all debuggers.
620   static void ReportProgress(uint64_t progress_id, std::string title,
621                              std::string details, uint64_t completed,
622                              uint64_t total,
623                              std::optional<lldb::user_id_t> debugger_id);
624 
625   static void ReportDiagnosticImpl(DiagnosticEventData::Type type,
626                                    std::string message,
627                                    std::optional<lldb::user_id_t> debugger_id,
628                                    std::once_flag *once);
629 
630   void HandleDestroyCallback();
631 
632   void PrintProgress(const ProgressEventData &data);
633 
634   void PushIOHandler(const lldb::IOHandlerSP &reader_sp,
635                      bool cancel_top_handler = true);
636 
637   bool PopIOHandler(const lldb::IOHandlerSP &reader_sp);
638 
639   bool HasIOHandlerThread() const;
640 
641   bool StartIOHandlerThread();
642 
643   void StopIOHandlerThread();
644 
645   // Sets the IOHandler thread to the new_thread, and returns
646   // the previous IOHandler thread.
647   HostThread SetIOHandlerThread(HostThread &new_thread);
648 
649   void JoinIOHandlerThread();
650 
651   bool IsIOHandlerThreadCurrentThread() const;
652 
653   lldb::thread_result_t IOHandlerThread();
654 
655   lldb::thread_result_t DefaultEventHandler();
656 
657   void HandleBreakpointEvent(const lldb::EventSP &event_sp);
658 
659   void HandleProcessEvent(const lldb::EventSP &event_sp);
660 
661   void HandleThreadEvent(const lldb::EventSP &event_sp);
662 
663   void HandleProgressEvent(const lldb::EventSP &event_sp);
664 
665   void HandleDiagnosticEvent(const lldb::EventSP &event_sp);
666 
667   // Ensures two threads don't attempt to flush process output in parallel.
668   std::mutex m_output_flush_mutex;
669 
670   void InstanceInitialize();
671 
672   // these should never be NULL
673   lldb::FileSP m_input_file_sp;
674   lldb::StreamFileSP m_output_stream_sp;
675   lldb::StreamFileSP m_error_stream_sp;
676 
677   /// Used for shadowing the input file when capturing a reproducer.
678   repro::DataRecorder *m_input_recorder;
679 
680   lldb::BroadcasterManagerSP m_broadcaster_manager_sp; // The debugger acts as a
681                                                        // broadcaster manager of
682                                                        // last resort.
683   // It needs to get constructed before the target_list or any other member
684   // that might want to broadcast through the debugger.
685 
686   TerminalState m_terminal_state;
687   TargetList m_target_list;
688 
689   PlatformList m_platform_list;
690   lldb::ListenerSP m_listener_sp;
691   std::unique_ptr<SourceManager> m_source_manager_up; // This is a scratch
692                                                       // source manager that we
693                                                       // return if we have no
694                                                       // targets.
695   SourceManager::SourceFileCache m_source_file_cache; // All the source managers
696                                                       // for targets created in
697                                                       // this debugger used this
698                                                       // shared
699                                                       // source file cache.
700   std::unique_ptr<CommandInterpreter> m_command_interpreter_up;
701 
702   std::recursive_mutex m_script_interpreter_mutex;
703   std::array<lldb::ScriptInterpreterSP, lldb::eScriptLanguageUnknown>
704       m_script_interpreters;
705 
706   IOHandlerStack m_io_handler_stack;
707   std::recursive_mutex m_io_handler_synchronous_mutex;
708 
709   std::optional<uint64_t> m_current_event_id;
710 
711   llvm::StringMap<std::weak_ptr<LogHandler>> m_stream_handlers;
712   std::shared_ptr<CallbackLogHandler> m_callback_handler_sp;
713   const std::string m_instance_name;
714   static LoadPluginCallbackType g_load_plugin_callback;
715   typedef std::vector<llvm::sys::DynamicLibrary> LoadedPluginsList;
716   LoadedPluginsList m_loaded_plugins;
717   HostThread m_event_handler_thread;
718   HostThread m_io_handler_thread;
719   Broadcaster m_sync_broadcaster; ///< Private debugger synchronization.
720   Broadcaster m_broadcaster;      ///< Public Debugger event broadcaster.
721   lldb::ListenerSP m_forward_listener_sp;
722   llvm::once_flag m_clear_once;
723   lldb::TargetSP m_dummy_target_sp;
724   Diagnostics::CallbackID m_diagnostics_callback_id;
725 
726   lldb_private::DebuggerDestroyCallback m_destroy_callback = nullptr;
727   void *m_destroy_callback_baton = nullptr;
728 
729   uint32_t m_interrupt_requested = 0; ///< Tracks interrupt requests
730   std::mutex m_interrupt_mutex;
731 
732   // Events for m_sync_broadcaster
733   enum {
734     eBroadcastBitEventThreadIsListening = (1 << 0),
735   };
736 
737 private:
738   // Use Debugger::CreateInstance() to get a shared pointer to a new debugger
739   // object
740   Debugger(lldb::LogOutputCallback m_log_callback, void *baton);
741 
742   Debugger(const Debugger &) = delete;
743   const Debugger &operator=(const Debugger &) = delete;
744 };
745 
746 } // namespace lldb_private
747 
748 #endif // LLDB_CORE_DEBUGGER_H
749