LLDB mainline
Debugger.h
Go to the documentation of this file.
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 <atomic>
13#include <cstdint>
14
15#include <memory>
16#include <optional>
17#include <vector>
18
22#include "lldb/Core/IOHandler.h"
26#include "lldb/Core/Telemetry.h"
30#include "lldb/Host/Terminal.h"
38#include "lldb/Utility/Status.h"
41#include "lldb/Utility/UserID.h"
42#include "lldb/lldb-defines.h"
44#include "lldb/lldb-forward.h"
47#include "lldb/lldb-types.h"
48
49#include "llvm/ADT/ArrayRef.h"
50#include "llvm/ADT/SmallVector.h"
51#include "llvm/ADT/StringMap.h"
52#include "llvm/ADT/StringRef.h"
53#include "llvm/Support/DynamicLibrary.h"
54#include "llvm/Support/FormatVariadic.h"
55#include "llvm/Support/Threading.h"
56
57#include <cassert>
58#include <cstddef>
59#include <cstdio>
60
61namespace llvm {
62class raw_ostream;
63class ThreadPoolInterface;
64} // namespace llvm
65
66namespace lldb_private {
67class Address;
68class CallbackLogHandler;
69class CommandInterpreter;
70class LogHandler;
71class Process;
72class Stream;
73class SymbolContext;
74class Target;
75
76#ifndef NDEBUG
77/// Global properties used in the LLDB testsuite.
80 bool GetInjectVarLocListError() const;
82
83 /// Overwrites the testing.safe-auto-load-paths settings.
85
86 /// Appends a path to the testing.safe-auto-load-paths setting.
88
89private:
90 friend Target;
91
92 /// Callers should use Debugger::GetSafeAutoLoadPaths since it
93 /// accounts for default paths configured via CMake.
95};
96#endif
97
98/// A class to manage flag bits.
99///
100/// Provides a global root objects for the debugger core.
101class Debugger : public std::enable_shared_from_this<Debugger>,
102 public UserID,
103 public Properties {
104public:
105 using DebuggerList = std::vector<lldb::DebuggerSP>;
106
107 static llvm::StringRef GetStaticBroadcasterClass();
108
109 /// Get the public broadcaster for this debugger.
111 const Broadcaster &GetBroadcaster() const { return m_broadcaster; }
112
113 ~Debugger() override;
114
115 static lldb::DebuggerSP
116 CreateInstance(lldb::LogOutputCallback log_callback = nullptr,
117 void *baton = nullptr);
118
119 static void Initialize(LoadPluginCallbackType load_plugin_callback);
120
121 static void Terminate();
122
123 static void SettingsInitialize();
124
125 static void SettingsTerminate();
126
127 static void Destroy(lldb::DebuggerSP &debugger_sp);
128
129 /// Get the build configuration as structured data.
131
133
134 static lldb::DebuggerSP
135 FindDebuggerWithInstanceName(llvm::StringRef instance_name);
136
137 static size_t GetNumDebuggers();
138
139 static lldb::DebuggerSP GetDebuggerAtIndex(size_t index);
140
141 static bool FormatDisassemblerAddress(const FormatEntity::Entry *format,
142 const SymbolContext *sc,
143 const SymbolContext *prev_sc,
144 const ExecutionContext *exe_ctx,
145 const Address *addr, Stream &s);
146
147 static void AssertCallback(llvm::StringRef message, llvm::StringRef backtrace,
148 llvm::StringRef prompt);
149
150 void Clear();
151
153
154 bool GetAsyncExecution();
155
156 void SetAsyncExecution(bool async);
157
160
162 return m_output_stream_sp->GetUnlockedFileSP();
163 }
164
166 return m_error_stream_sp->GetUnlockedFileSP();
167 }
168
169 Status SetInputString(const char *data);
170
171 void SetInputFile(lldb::FileSP file);
172
173 void SetOutputFile(lldb::FileSP file);
174
175 void SetErrorFile(lldb::FileSP file);
176
178
180
182
184
189
191 GetScriptInterpreter(bool can_create = true,
192 std::optional<lldb::ScriptLanguage> language = {});
193
195
196 // This returns the Debugger's scratch source manager. It won't be able to
197 // look up files in debug information, but it can look up files by absolute
198 // path and display them to you. To get the target's source manager, call
199 // GetSourceManager on the target instead.
201
202 /// Get the execution context representing the selected entities in the
203 /// selected target. If no target is selected, the execution context will
204 /// contain the dummy target if adopt_dummy_target is true.
205 ///
206 // Ideally, adopt_dummy_target would be the default. However, there are a
207 // bunch of operations that don't make sense on the dummy target but we lack
208 // a mechanism to enforce that. The explicit argument forces the caller to
209 // consider the dummy target.
210 ExecutionContext GetSelectedExecutionContext(bool adopt_dummy_target);
211
212 /// Like GetSelectedExecutionContext but returns an ExecutionContextRef.
214
215 /// Get accessor for the target list.
216 ///
217 /// The target list is part of the global debugger object. This the single
218 /// debugger shared instance to control where targets get created and to
219 /// allow for tracking and searching for targets based on certain criteria.
220 ///
221 /// \return
222 /// A global shared target list.
224
226
228
230
232
233 // If any of the streams are not set, set them to the in/out/err stream of
234 // the top most input reader to ensure they at least have something
238
239 /// Run the given IO handler and return immediately.
240 void RunIOHandlerAsync(const lldb::IOHandlerSP &reader_sp,
241 bool cancel_top_handler = true);
242
243 /// Run the given IO handler and block until it's complete.
244 void RunIOHandlerSync(const lldb::IOHandlerSP &reader_sp);
245
246 /// Remove the given IO handler if it's currently active.
247 bool RemoveIOHandler(const lldb::IOHandlerSP &reader_sp);
248
249 bool IsTopIOHandler(const lldb::IOHandlerSP &reader_sp);
250
252 IOHandler::Type second_top_type);
253
254 void PrintAsync(const char *s, size_t len, bool is_stdout);
255
256 llvm::StringRef GetTopIOHandlerControlSequence(char ch);
257
258 const char *GetIOHandlerCommandPrefix();
259
260 const char *GetIOHandlerHelpPrologue();
261
262 void RefreshIOHandler();
263
264 void ClearIOHandlers();
265
266 llvm::Error EnableLog(llvm::StringRef channel,
267 llvm::ArrayRef<const char *> categories,
268 llvm::StringRef log_file, uint32_t log_options,
269 size_t buffer_size, LogHandlerKind log_handler_kind);
270
271 void SetLoggingCallback(lldb::LogOutputCallback log_callback, void *baton);
272
273 /// Copy this debugger's file-backed log files into the given directory, for
274 /// inclusion in a diagnostics bundle. Returns the names of the files that
275 /// were copied. Best-effort: files that cannot be copied are skipped.
276 std::vector<std::string> CopyLogFilesToDirectory(const FileSpec &dir);
277
279 VarSetOperationType op, llvm::StringRef property_path,
280 llvm::StringRef value) override;
281
282 bool GetAutoConfirm() const;
283
285
287
289
290 uint64_t GetStopDisassemblyMaxSize() const;
291
293
295
297
298 bool SetScriptLanguage(lldb::ScriptLanguage script_lang);
299
301
302 bool SetREPLLanguage(lldb::LanguageType repl_lang);
303
304 uint64_t GetTerminalWidth() const;
305
306 bool SetTerminalWidth(uint64_t term_width);
307
308 uint64_t GetTerminalHeight() const;
309
310 bool SetTerminalHeight(uint64_t term_height);
311
312 /// Set the terminal width and height together, so observers are notified
313 /// once with both dimensions current.
314 bool SetTerminalDimensions(uint64_t term_width, uint64_t term_height);
315
316 llvm::StringRef GetPrompt() const;
317
318 llvm::StringRef GetPromptAnsiPrefix() const;
319
320 llvm::StringRef GetPromptAnsiSuffix() const;
321
322 void SetPrompt(llvm::StringRef p);
323 void SetPrompt(const char *) = delete;
324
325 bool GetUseExternalEditor() const;
326 bool SetUseExternalEditor(bool use_external_editor_p);
327
328 llvm::StringRef GetExternalEditor() const;
329
330 bool SetExternalEditor(llvm::StringRef editor);
331
332 bool GetUseColor() const;
333
334 bool SetUseColor(bool use_color);
335
336 bool GetShowProgress() const;
337
338 bool SetShowProgress(bool show_progress);
339
340 bool GetShowStatusline() const;
341
343 bool SetStatuslineFormat(const FormatEntity::Entry &format);
344
345 llvm::StringRef GetSeparator() const;
346 bool SetSeparator(llvm::StringRef s);
347
348 llvm::StringRef GetShowProgressAnsiPrefix() const;
349
350 llvm::StringRef GetShowProgressAnsiSuffix() const;
351
352 llvm::StringRef GetLabelAnsiPrefix() const;
353
354 llvm::StringRef GetLabelAnsiSuffix() const;
355
356 llvm::StringRef GetTitleAnsiPrefix() const;
357
358 llvm::StringRef GetTitleAnsiSuffix() const;
359
360 llvm::StringRef GetDividerAnsiPrefix() const;
361
362 llvm::StringRef GetDividerAnsiSuffix() const;
363
364 llvm::StringRef GetDisabledAnsiPrefix() const;
365
366 llvm::StringRef GetDisabledAnsiSuffix() const;
367
369
370 llvm::StringRef GetAutosuggestionAnsiPrefix() const;
371
372 llvm::StringRef GetAutosuggestionAnsiSuffix() const;
373
374 llvm::StringRef GetRegexMatchAnsiPrefix() const;
375
376 llvm::StringRef GetRegexMatchAnsiSuffix() const;
377
378 bool GetShowDontUsePoHint() const;
379
380 bool GetUseSourceCache() const;
381
382 bool SetUseSourceCache(bool use_source_cache);
383
384 bool GetMarkHiddenFrames() const;
385
386 bool GetHighlightSource() const;
387
389
390 llvm::StringRef GetStopShowColumnAnsiPrefix() const;
391
392 llvm::StringRef GetStopShowColumnAnsiSuffix() const;
393
394 uint64_t GetStopSourceLineCount(bool before) const;
395
397
398 uint64_t GetDisassemblyLineCount() const;
399
400 llvm::StringRef GetStopShowLineMarkerAnsiPrefix() const;
401
402 llvm::StringRef GetStopShowLineMarkerAnsiSuffix() const;
403
404 bool GetAutoOneLineSummaries() const;
405
406 bool GetAutoIndent() const;
407
408 bool SetAutoIndent(bool b);
409
410 bool GetPrintDecls() const;
411
412 bool SetPrintDecls(bool b);
413
414 uint64_t GetTabSize() const;
415
416 bool SetTabSize(uint64_t tab_size);
417
419
420 bool GetEscapeNonPrintables() const;
421
422 bool GetNotifyVoid() const;
423
424 const std::string &GetInstanceName() const { return m_instance_name; }
425
426 /// The pool for strings handed out through the SB API that belong to this
427 /// debugger.
429
430 bool GetShowInlineDiagnostics() const;
431
432 bool SetShowInlineDiagnostics(bool);
433
434 bool LoadPlugin(const FileSpec &spec, Status &error);
435
436 void RunIOHandlers();
437
438 bool IsForwardingEvents();
439
440 void EnableForwardEvents(const lldb::ListenerSP &listener_sp);
441
442 void CancelForwardEvents(const lldb::ListenerSP &listener_sp);
443
444 bool IsHandlingEvents() const { return m_event_handler_thread.IsJoinable(); }
445
446 Status RunREPL(lldb::LanguageType language, const char *repl_options);
447
448 /// Interruption in LLDB:
449 ///
450 /// This is a voluntary interruption mechanism, not preemptive. Parts of lldb
451 /// that do work that can be safely interrupted call
452 /// Debugger::InterruptRequested and if that returns true, they should return
453 /// at a safe point, shortcutting the rest of the work they were to do.
454 ///
455 /// lldb clients can both offer a CommandInterpreter (through
456 /// RunCommandInterpreter) and use the SB API's for their own purposes, so it
457 /// is convenient to separate "interrupting the CommandInterpreter execution"
458 /// and interrupting the work it is doing with the SB API's. So there are two
459 /// ways to cause an interrupt:
460 /// * CommandInterpreter::InterruptCommand: Interrupts the command currently
461 /// running in the command interpreter IOHandler thread
462 /// * Debugger::RequestInterrupt: Interrupts are active on anything but the
463 /// CommandInterpreter thread till CancelInterruptRequest is called.
464 ///
465 /// Since the two checks are mutually exclusive, however, it's also convenient
466 /// to have just one function to check the interrupt state.
467
468 /// Bump the "interrupt requested" count on the debugger to support
469 /// cooperative interruption. If this is non-zero, InterruptRequested will
470 /// return true. Interruptible operations are expected to query the
471 /// InterruptRequested API periodically, and interrupt what they were doing
472 /// if it returns \b true.
473 ///
474 void RequestInterrupt();
475
476 /// Decrement the "interrupt requested" counter.
478
479 /// Redraw the statusline if enabled.
480 void RedrawStatusline(std::optional<ExecutionContextRef> exe_ctx_ref);
481
482 /// Whether the statusline can be drawn: show-statusline is enabled and the
483 /// output is an escape-code-capable terminal.
484 bool StatuslineSupported();
485
486 /// Discard the statusline's cached frame at its next redraw. This function
487 /// is thread-safe and takes no lock, so callers may hold the target API
488 /// mutex.
489 void FlushStatusLine();
490
491 /// This is the correct way to query the state of Interruption.
492 /// If you are on the RunCommandInterpreter thread, it will check the
493 /// command interpreter state, and if it is on another thread it will
494 /// check the debugger Interrupt Request state.
495 /// \param[in] cur_func
496 /// For reporting if the interruption was requested. Don't provide this by
497 /// hand, use INTERRUPT_REQUESTED so this gets done consistently.
498 ///
499 /// \param[in] formatv
500 /// A formatv string for the interrupt message. If the elements of the
501 /// message are expensive to compute, you can use the no-argument form of
502 /// InterruptRequested, then make up the report using REPORT_INTERRUPTION.
503 ///
504 /// \return
505 /// A boolean value, if \b true an interruptible operation should interrupt
506 /// itself.
507 template <typename... Args>
508 bool InterruptRequested(const char *cur_func, const char *formatv,
509 Args &&...args) {
510 bool ret_val = InterruptRequested();
511 if (ret_val) {
512 if (!formatv)
513 formatv = "Unknown message";
514 if (!cur_func)
515 cur_func = "<UNKNOWN>";
517 cur_func, llvm::formatv(formatv, std::forward<Args>(args)...)));
518 }
519 return ret_val;
520 }
521
522 /// This handy define will keep you from having to generate a report for the
523 /// interruption by hand. Use this except in the case where the arguments to
524 /// the message description are expensive to compute.
525#define INTERRUPT_REQUESTED(debugger, ...) \
526 (debugger).InterruptRequested(__func__, __VA_ARGS__)
527
528 // This form just queries for whether to interrupt, and does no reporting:
529 bool InterruptRequested();
530
531 // FIXME: Do we want to capture a backtrace at the interruption point?
533 public:
534 InterruptionReport(std::string function_name, std::string description)
535 : m_function_name(std::move(function_name)),
536 m_description(std::move(description)),
537 m_interrupt_time(std::chrono::system_clock::now()),
538 m_thread_id(llvm::get_threadid()) {}
539
540 InterruptionReport(std::string function_name,
541 const llvm::formatv_object_base &payload);
542
543 template <typename... Args>
544 InterruptionReport(std::string function_name, const char *format,
545 Args &&...args)
547 function_name,
548 llvm::formatv(format, std::forward<Args>(args)...)) {}
549
550 std::string m_function_name;
551 std::string m_description;
552 const std::chrono::time_point<std::chrono::system_clock> m_interrupt_time;
553 const uint64_t m_thread_id;
554 };
555 void ReportInterruption(const InterruptionReport &report);
556#define REPORT_INTERRUPTION(debugger, ...) \
557 (debugger).ReportInterruption( \
558 Debugger::InterruptionReport(__func__, __VA_ARGS__))
559
561
562public:
563 // This is for use in the command interpreter, when you either want the
564 // selected target, or if no target is present you want to prime the dummy
565 // target with entities that will be copied over to new targets.
566 Target &GetSelectedOrDummyTarget(bool prefer_dummy = false);
568
572
573 /// Shared thread pool. Use only with ThreadPoolTaskGroup.
574 static llvm::ThreadPoolInterface &GetThreadPool();
575
576 /// Report warning events.
577 ///
578 /// Warning events will be delivered to any debuggers that have listeners
579 /// for the eBroadcastBitWarning.
580 ///
581 /// \param[in] message
582 /// The warning message to be reported.
583 ///
584 /// \param [in] debugger_id
585 /// If this optional parameter has a value, it indicates the unique
586 /// debugger identifier that this diagnostic should be delivered to. If
587 /// this optional parameter does not have a value, the diagnostic event
588 /// will be delivered to all debuggers.
589 ///
590 /// \param [in] once
591 /// If a pointer is passed to a std::once_flag, then it will be used to
592 /// ensure the given warning is only broadcast once.
593 static void
594 ReportWarning(std::string message,
595 std::optional<lldb::user_id_t> debugger_id = std::nullopt,
596 std::once_flag *once = nullptr);
597
598 /// Report error events.
599 ///
600 /// Error events will be delivered to any debuggers that have listeners
601 /// for the eBroadcastBitError.
602 ///
603 /// \param[in] message
604 /// The error message to be reported.
605 ///
606 /// \param [in] debugger_id
607 /// If this optional parameter has a value, it indicates the unique
608 /// debugger identifier that this diagnostic should be delivered to. If
609 /// this optional parameter does not have a value, the diagnostic event
610 /// will be delivered to all debuggers.
611 ///
612 /// \param [in] once
613 /// If a pointer is passed to a std::once_flag, then it will be used to
614 /// ensure the given error is only broadcast once.
615 static void
616 ReportError(std::string message,
617 std::optional<lldb::user_id_t> debugger_id = std::nullopt,
618 std::once_flag *once = nullptr);
619
620 /// Report info events.
621 ///
622 /// Unlike warning and error events, info events are not broadcast but are
623 /// logged for diagnostic purposes.
624 ///
625 /// \param[in] message
626 /// The info message to be reported.
627 ///
628 /// \param [in] debugger_id
629 /// If this optional parameter has a value, it indicates this diagnostic is
630 /// associated with a unique debugger instance.
631 ///
632 /// \param [in] once
633 /// If a pointer is passed to a std::once_flag, then it will be used to
634 /// ensure the given info is only logged once.
635 static void
636 ReportInfo(std::string message,
637 std::optional<lldb::user_id_t> debugger_id = std::nullopt,
638 std::once_flag *once = nullptr);
639
640 static void ReportSymbolChange(const ModuleSpec &module_spec);
641
642 /// DEPRECATED: We used to only support one Destroy callback. Now that we
643 /// support Add and Remove, you should only remove callbacks that you added.
644 /// Use Add and Remove instead.
645 ///
646 /// Clear all previously added callbacks and only add the given one.
647 void
649 void *baton);
650
651 /// Add a callback for when the debugger is destroyed. Return a token, which
652 /// can be used to remove said callback. Multiple callbacks can be added by
653 /// calling this function multiple times, and will be invoked in FIFO order.
656 void *baton);
657
658 /// Remove the specified callback. Return true if successful.
660
661 /// Manually start the global event handler thread. It is useful to plugins
662 /// that directly use the \a lldb_private namespace and want to use the
663 /// debugger's default event handler thread instead of defining their own.
665
666 /// Manually stop the debugger's default event handler.
668
669 /// Force flushing the process's pending stdout and stderr to the debugger's
670 /// asynchronous stdout and stderr streams.
671 void FlushProcessOutput(Process &process, bool flush_stdout,
672 bool flush_stderr);
673
677
679 uint64_t id;
680 uint64_t completed;
681 uint64_t total;
682 std::string message;
683 };
684 std::optional<ProgressReport> GetCurrentProgressReport() const;
685
687
688protected:
689 friend class CommandInterpreter;
690 friend class REPL;
691 friend class Progress;
692 friend class ProgressManager;
693 friend class Statusline;
694
695 /// Report progress events.
696 ///
697 /// Progress events will be delivered to any debuggers that have listeners
698 /// for the eBroadcastBitProgress. This function is called by the
699 /// lldb_private::Progress class to deliver the events to any debuggers that
700 /// qualify.
701 ///
702 /// \param [in] progress_id
703 /// The unique integer identifier for the progress to report.
704 ///
705 /// \param[in] message
706 /// The title of the progress dialog to display in the UI.
707 ///
708 /// \param [in] completed
709 /// The amount of work completed. If \a completed is zero, then this event
710 /// is a progress started event. If \a completed is equal to \a total, then
711 /// this event is a progress end event. Otherwise completed indicates the
712 /// current progress compare to the total value.
713 ///
714 /// \param [in] total
715 /// The total amount of work units that need to be completed. If this value
716 /// is UINT64_MAX, then an indeterminate progress indicator should be
717 /// displayed.
718 ///
719 /// \param [in] debugger_id
720 /// If this optional parameter has a value, it indicates the unique
721 /// debugger identifier that this progress should be delivered to. If this
722 /// optional parameter does not have a value, the progress will be
723 /// delivered to all debuggers.
724 static void
725 ReportProgress(uint64_t progress_id, std::string title, std::string details,
726 uint64_t completed, uint64_t total,
727 std::optional<lldb::user_id_t> debugger_id,
728 uint32_t progress_category_bit = lldb::eBroadcastBitProgress);
729
730 static void ReportDiagnosticImpl(lldb::Severity severity, std::string message,
731 std::optional<lldb::user_id_t> debugger_id,
732 std::once_flag *once);
733
735
737
738 /// Except for Debugger and IOHandler, GetOutputStreamSP and GetErrorStreamSP
739 /// should not be used directly. Use GetAsyncOutputStream and
740 /// GetAsyncErrorStream instead.
741 /// @{
744 /// @}
745
747
748 void PushIOHandler(const lldb::IOHandlerSP &reader_sp,
749 bool cancel_top_handler = true);
750
751 bool PopIOHandler(const lldb::IOHandlerSP &reader_sp);
752
753 bool HasIOHandlerThread() const;
754
756
757 void StopIOHandlerThread();
758
759 // Sets the IOHandler thread to the new_thread, and returns
760 // the previous IOHandler thread.
762
763 void JoinIOHandlerThread();
764
766
768
770
771 void HandleBreakpointEvent(const lldb::EventSP &event_sp);
772
774
776
777 void HandleProgressEvent(const lldb::EventSP &event_sp);
778
779 void HandleDiagnosticEvent(const lldb::EventSP &event_sp);
780
781 // Ensures two threads don't attempt to flush process output in parallel.
783
784 void InstanceInitialize();
785
786 // these should never be NULL
791
793 // broadcaster manager of
794 // last resort.
795 // It needs to get constructed before the target_list or any other member
796 // that might want to broadcast through the debugger.
797
801
804 std::unique_ptr<SourceManager> m_source_manager_up; // This is a scratch
805 // source manager that we
806 // return if we have no
807 // targets.
809 // for targets created in
810 // this debugger used this
811 // shared
812 // source file cache.
813 std::unique_ptr<CommandInterpreter> m_command_interpreter_up;
814
815 std::recursive_mutex m_script_interpreter_mutex;
816 std::array<lldb::ScriptInterpreterSP, lldb::eScriptLanguageUnknown>
818
820 std::recursive_mutex m_io_handler_synchronous_mutex;
821
822 /// Mutex protecting the m_statusline member.
824 std::optional<Statusline> m_statusline;
825 /// Raised by FlushStatusLine to request a flush at the next redraw.
826 std::atomic<bool> m_flush_statusline = false;
827
828 llvm::StringMap<std::weak_ptr<LogHandler>> m_stream_handlers;
829 std::shared_ptr<CallbackLogHandler> m_callback_handler_sp;
830 const std::string m_instance_name;
833 typedef std::vector<llvm::sys::DynamicLibrary> LoadedPluginsList;
837 Broadcaster m_sync_broadcaster; ///< Private debugger synchronization.
838 Broadcaster m_broadcaster; ///< Public Debugger event broadcaster.
840 llvm::once_flag m_clear_once;
842
843 /// Bookkeeping for command line progress events.
844 /// @{
845 llvm::SmallVector<ProgressReport, 4> m_progress_reports;
846 mutable std::mutex m_progress_reports_mutex;
847 /// @}
848
861 llvm::SmallVector<DestroyCallbackInfo, 2> m_destroy_callbacks;
862
863 uint32_t m_interrupt_requested = 0; ///< Tracks interrupt requests
865
866 // Events for m_sync_broadcaster
867 enum {
869 };
870
871private:
872 // Use Debugger::CreateInstance() to get a shared pointer to a new debugger
873 // object
874 Debugger(lldb::LogOutputCallback m_log_callback, void *baton);
875
876 Debugger(const Debugger &) = delete;
877 const Debugger &operator=(const Debugger &) = delete;
878};
879
880} // namespace lldb_private
881
882#endif // LLDB_CORE_DEBUGGER_H
static llvm::raw_ostream & error(Stream &strm)
A section + offset based address class.
Definition Address.h:62
A command line argument class.
Definition Args.h:33
An event broadcasting class.
const std::chrono::time_point< std::chrono::system_clock > m_interrupt_time
Definition Debugger.h:552
InterruptionReport(std::string function_name, std::string description)
Definition Debugger.h:534
InterruptionReport(std::string function_name, const char *format, Args &&...args)
Definition Debugger.h:544
static void AssertCallback(llvm::StringRef message, llvm::StringRef backtrace, llvm::StringRef prompt)
llvm::StringRef GetAutosuggestionAnsiPrefix() const
Definition Debugger.cpp:667
bool SetUseExternalEditor(bool use_external_editor_p)
Definition Debugger.cpp:527
PlatformList m_platform_list
Definition Debugger.h:802
HostThread m_event_handler_thread
Definition Debugger.h:835
FormatEntity::Entry GetDisassemblyFormat() const
Definition Debugger.cpp:392
uint64_t GetDisassemblyLineCount() const
Definition Debugger.cpp:769
llvm::StringRef GetDisabledAnsiSuffix() const
Definition Debugger.cpp:647
uint64_t GetTerminalHeight() const
Definition Debugger.cpp:490
lldb::LockableStreamFileSP m_output_stream_sp
Definition Debugger.h:788
bool SetExternalEditor(llvm::StringRef editor)
Definition Debugger.cpp:538
void RequestInterrupt()
Interruption in LLDB:
void ReportInterruption(const InterruptionReport &report)
StringPoolRef m_string_pool
Definition Debugger.h:831
const std::string m_instance_name
Definition Debugger.h:830
static void Terminate()
Definition Debugger.cpp:856
lldb::ThreadSP HandleThreadEvent(const lldb::EventSP &event_sp)
void HandleProgressEvent(const lldb::EventSP &event_sp)
SourceManager & GetSourceManager()
bool SetTerminalDimensions(uint64_t term_width, uint64_t term_height)
Set the terminal width and height together, so observers are notified once with both dimensions curre...
Definition Debugger.cpp:500
bool SetShowProgress(bool show_progress)
Definition Debugger.cpp:564
bool StartEventHandlerThread()
Manually start the global event handler thread.
bool SetUseSourceCache(bool use_source_cache)
Definition Debugger.cpp:703
static const FileSpecList & GetDefaultSafeAutoLoadPaths()
Definition Debugger.cpp:237
void StopEventHandlerThread()
Manually stop the debugger's default event handler.
static void ReportInfo(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report info events.
void SetAsyncExecution(bool async)
ExecutionContext GetSelectedExecutionContext(bool adopt_dummy_target)
Get the execution context representing the selected entities in the selected target.
HostThread SetIOHandlerThread(HostThread &new_thread)
friend class Progress
Definition Debugger.h:691
SourceManager::SourceFileCache & GetSourceFileCache()
Definition Debugger.h:674
void CancelForwardEvents(const lldb::ListenerSP &listener_sp)
bool GetPrintDecls() const
Definition Debugger.cpp:798
lldb::FileSP GetInputFileSP()
Definition Debugger.h:158
bool GetHighlightSource() const
Definition Debugger.cpp:718
llvm::StringMap< std::weak_ptr< LogHandler > > m_stream_handlers
Definition Debugger.h:828
llvm::StringRef GetLabelAnsiSuffix() const
Definition Debugger.cpp:587
CommandInterpreter & GetCommandInterpreter()
Definition Debugger.h:185
FormatEntity::Entry GetStatuslineFormat() const
Definition Debugger.cpp:623
llvm::StringRef GetDividerAnsiPrefix() const
Definition Debugger.cpp:605
LoadedPluginsList m_loaded_plugins
Definition Debugger.h:834
bool GetShowInlineDiagnostics() const
Definition Debugger.cpp:827
std::vector< llvm::sys::DynamicLibrary > LoadedPluginsList
Definition Debugger.h:833
Debugger(const Debugger &)=delete
bool SetTabSize(uint64_t tab_size)
Definition Debugger.cpp:815
bool IsHandlingEvents() const
Definition Debugger.h:444
void HandleDiagnosticEvent(const lldb::EventSP &event_sp)
static lldb::DebuggerSP GetDebuggerAtIndex(size_t index)
llvm::StringRef GetAutosuggestionAnsiSuffix() const
Definition Debugger.cpp:673
lldb::ListenerSP m_listener_sp
Definition Debugger.h:803
void PushIOHandler(const lldb::IOHandlerSP &reader_sp, bool cancel_top_handler=true)
std::mutex m_destroy_callback_mutex
Definition Debugger.h:849
lldb::callback_token_t AddDestroyCallback(lldb_private::DebuggerDestroyCallback destroy_callback, void *baton)
Add a callback for when the debugger is destroyed.
lldb::thread_result_t IOHandlerThread()
FormatEntity::Entry GetFrameFormatUnique() const
Definition Debugger.cpp:402
std::optional< ProgressReport > GetCurrentProgressReport() const
llvm::StringRef GetDisabledAnsiPrefix() const
Definition Debugger.cpp:641
bool GetUseExternalEditor() const
Definition Debugger.cpp:521
TerminalState m_terminal_state
Definition Debugger.h:798
lldb::StreamUP GetAsyncErrorStream()
TargetList & GetTargetList()
Get accessor for the target list.
Definition Debugger.h:223
bool GetEscapeNonPrintables() const
Definition Debugger.cpp:781
lldb::TargetSP m_dummy_target_sp
Definition Debugger.h:841
llvm::SmallVector< DestroyCallbackInfo, 2 > m_destroy_callbacks
Definition Debugger.h:861
std::unique_ptr< CommandInterpreter > m_command_interpreter_up
Definition Debugger.h:813
static void ReportWarning(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report warning events.
static bool FormatDisassemblerAddress(const FormatEntity::Entry *format, const SymbolContext *sc, const SymbolContext *prev_sc, const ExecutionContext *exe_ctx, const Address *addr, Stream &s)
static void SettingsInitialize()
Definition Debugger.cpp:885
LockableStreamFile::Mutex m_output_mutex
Definition Debugger.h:790
static llvm::ThreadPoolInterface & GetThreadPool()
Shared thread pool. Use only with ThreadPoolTaskGroup.
llvm::StringRef GetShowProgressAnsiSuffix() const
Definition Debugger.cpp:575
bool IsTopIOHandler(const lldb::IOHandlerSP &reader_sp)
bool HasIOHandlerThread() const
llvm::SmallVector< ProgressReport, 4 > m_progress_reports
Bookkeeping for command line progress events.
Definition Debugger.h:845
bool IsIOHandlerThreadCurrentThread() const
ExecutionContextRef GetSelectedExecutionContextRef(bool adopt_dummy_target)
Like GetSelectedExecutionContext but returns an ExecutionContextRef.
TargetGroupList & GetTargetGroupList()
Definition Debugger.h:225
void DispatchClientTelemetry(const lldb_private::StructuredDataImpl &entry)
Definition Debugger.cpp:995
lldb::FileSP GetErrorFileSP()
Definition Debugger.h:165
std::mutex m_progress_reports_mutex
Definition Debugger.h:846
lldb::ProcessSP HandleProcessEvent(const lldb::EventSP &event_sp)
lldb::ListenerSP m_forward_listener_sp
Definition Debugger.h:839
std::array< lldb::ScriptInterpreterSP, lldb::eScriptLanguageUnknown > m_script_interpreters
Definition Debugger.h:817
std::atomic< bool > m_flush_statusline
Raised by FlushStatusLine to request a flush at the next redraw.
Definition Debugger.h:826
std::shared_ptr< CallbackLogHandler > m_callback_handler_sp
Definition Debugger.h:829
void SetDestroyCallback(lldb_private::DebuggerDestroyCallback destroy_callback, void *baton)
DEPRECATED: We used to only support one Destroy callback.
lldb::FileSP GetOutputFileSP()
Definition Debugger.h:161
Broadcaster m_broadcaster
Public Debugger event broadcaster.
Definition Debugger.h:838
static void Initialize(LoadPluginCallbackType load_plugin_callback)
Definition Debugger.cpp:847
static lldb::DebuggerSP FindDebuggerWithInstanceName(llvm::StringRef instance_name)
uint64_t GetTerminalWidth() const
Definition Debugger.cpp:480
std::mutex m_interrupt_mutex
Definition Debugger.h:864
std::recursive_mutex m_io_handler_synchronous_mutex
Definition Debugger.h:820
bool InterruptRequested(const char *cur_func, const char *formatv, Args &&...args)
This is the correct way to query the state of Interruption.
Definition Debugger.h:508
bool RemoveIOHandler(const lldb::IOHandlerSP &reader_sp)
Remove the given IO handler if it's currently active.
void SetPrompt(const char *)=delete
bool GetAutoOneLineSummaries() const
Definition Debugger.cpp:775
const char * GetIOHandlerCommandPrefix()
friend class REPL
Definition Debugger.h:690
std::optional< Statusline > m_statusline
Definition Debugger.h:824
llvm::StringRef GetDividerAnsiSuffix() const
Definition Debugger.cpp:611
bool GetUseColor() const
Definition Debugger.cpp:543
llvm::StringRef GetTitleAnsiPrefix() const
Definition Debugger.cpp:593
lldb::BroadcasterManagerSP m_broadcaster_manager_sp
Definition Debugger.h:792
void FlushStatusLine()
Discard the statusline's cached frame at its next redraw.
Status RunREPL(lldb::LanguageType language, const char *repl_options)
bool PopIOHandler(const lldb::IOHandlerSP &reader_sp)
static StructuredData::DictionarySP GetBuildConfiguration()
Get the build configuration as structured data.
bool RemoveDestroyCallback(lldb::callback_token_t token)
Remove the specified callback. Return true if successful.
static LoadPluginCallbackType g_load_plugin_callback
Definition Debugger.h:832
bool GetShowStatusline() const
Definition Debugger.cpp:617
std::recursive_mutex m_script_interpreter_mutex
Definition Debugger.h:815
void RunIOHandlerAsync(const lldb::IOHandlerSP &reader_sp, bool cancel_top_handler=true)
Run the given IO handler and return immediately.
void SetInputFile(lldb::FileSP file)
lldb::LockableStreamFileSP GetOutputStreamSP()
Except for Debugger and IOHandler, GetOutputStreamSP and GetErrorStreamSP should not be used directly...
Definition Debugger.h:742
void SetPrompt(llvm::StringRef p)
Definition Debugger.cpp:437
llvm::StringRef GetSeparator() const
Definition Debugger.cpp:635
bool StatuslineSupported()
Whether the statusline can be drawn: show-statusline is enabled and the output is an escape-code-capa...
uint64_t GetStopDisassemblyMaxSize() const
Definition Debugger.cpp:407
bool SetTerminalHeight(uint64_t term_height)
Definition Debugger.cpp:496
Broadcaster m_sync_broadcaster
Private debugger synchronization.
Definition Debugger.h:837
friend class Statusline
Definition Debugger.h:693
llvm::StringRef GetTitleAnsiSuffix() const
Definition Debugger.cpp:599
bool GetUseSourceCache() const
Definition Debugger.cpp:697
HostThread m_io_handler_thread
Definition Debugger.h:836
llvm::StringRef GetRegexMatchAnsiSuffix() const
Definition Debugger.cpp:685
static llvm::StringRef GetStaticBroadcasterClass()
lldb::FileSP m_input_file_sp
Definition Debugger.h:787
const Broadcaster & GetBroadcaster() const
Definition Debugger.h:111
bool SetREPLLanguage(lldb::LanguageType repl_lang)
Definition Debugger.cpp:475
bool GetAutoIndent() const
Definition Debugger.cpp:787
AutosuggestionMode GetAutosuggestionMode() const
Definition Debugger.cpp:660
llvm::StringRef GetStopShowColumnAnsiSuffix() const
Definition Debugger.cpp:737
Status SetPropertyValue(const ExecutionContext *exe_ctx, VarSetOperationType op, llvm::StringRef property_path, llvm::StringRef value) override
Definition Debugger.cpp:299
llvm::StringRef GetPromptAnsiSuffix() const
Definition Debugger.cpp:431
FormatEntity::Entry GetThreadStopFormat() const
Definition Debugger.cpp:453
void SetErrorFile(lldb::FileSP file)
bool GetAutoConfirm() const
Definition Debugger.cpp:386
TargetList m_target_list
Definition Debugger.h:799
lldb::ScriptLanguage GetScriptLanguage() const
Definition Debugger.cpp:458
lldb::callback_token_t m_destroy_callback_next_token
Definition Debugger.h:850
std::unique_ptr< SourceManager > m_source_manager_up
Definition Debugger.h:804
static lldb::DebuggerSP CreateInstance(lldb::LogOutputCallback log_callback=nullptr, void *baton=nullptr)
Definition Debugger.cpp:977
lldb::StopShowColumn GetStopShowColumn() const
Definition Debugger.cpp:724
static void ReportSymbolChange(const ModuleSpec &module_spec)
static void ReportError(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report error events.
bool SetPrintDecls(bool b)
Definition Debugger.cpp:804
bool SetScriptLanguage(lldb::ScriptLanguage script_lang)
Definition Debugger.cpp:465
lldb::LockableStreamFileSP m_error_stream_sp
Definition Debugger.h:789
bool SetShowInlineDiagnostics(bool)
Definition Debugger.cpp:833
const std::string & GetInstanceName() const
Definition Debugger.h:424
bool LoadPlugin(const FileSpec &spec, Status &error)
Definition Debugger.cpp:889
void SetOutputFile(lldb::FileSP file)
uint64_t GetStopSourceLineCount(bool before) const
Definition Debugger.cpp:755
bool SetStatuslineFormat(const FormatEntity::Entry &format)
Definition Debugger.cpp:628
void EnableForwardEvents(const lldb::ListenerSP &listener_sp)
static lldb::DebuggerSP FindDebuggerWithID(lldb::user_id_t id)
void HandleBreakpointEvent(const lldb::EventSP &event_sp)
bool CheckTopIOHandlerTypes(IOHandler::Type top_type, IOHandler::Type second_top_type)
PlatformList & GetPlatformList()
Definition Debugger.h:227
Target & GetDummyTarget()
Definition Debugger.h:567
TargetGroupList m_target_group_list
Definition Debugger.h:800
lldb::ListenerSP GetListener()
Definition Debugger.h:194
static void Destroy(lldb::DebuggerSP &debugger_sp)
SourceManager::SourceFileCache m_source_file_cache
Definition Debugger.h:808
llvm::StringRef GetPromptAnsiPrefix() const
Definition Debugger.cpp:425
lldb::StreamUP GetAsyncOutputStream()
void RedrawStatusline(std::optional< ExecutionContextRef > exe_ctx_ref)
Redraw the statusline if enabled.
void RunIOHandlerSync(const lldb::IOHandlerSP &reader_sp)
Run the given IO handler and block until it's complete.
Broadcaster & GetBroadcaster()
Get the public broadcaster for this debugger.
Definition Debugger.h:110
llvm::StringRef GetStopShowLineMarkerAnsiPrefix() const
Definition Debugger.cpp:743
bool GetShowDontUsePoHint() const
Definition Debugger.cpp:691
uint64_t GetTabSize() const
Definition Debugger.cpp:809
bool GetShowProgress() const
Definition Debugger.cpp:558
llvm::StringRef GetRegexMatchAnsiPrefix() const
Definition Debugger.cpp:679
std::mutex m_output_flush_mutex
Definition Debugger.h:782
llvm::StringRef GetStopShowLineMarkerAnsiSuffix() const
Definition Debugger.cpp:749
void PrintProgress(const ProgressEventData &data)
bool SetSeparator(llvm::StringRef s)
Definition Debugger.cpp:653
bool SetUseColor(bool use_color)
Definition Debugger.cpp:549
std::mutex m_statusline_mutex
Mutex protecting the m_statusline member.
Definition Debugger.h:823
const char * GetIOHandlerHelpPrologue()
Status SetInputString(const char *data)
llvm::StringRef GetLabelAnsiPrefix() const
Definition Debugger.cpp:581
friend class ProgressManager
Definition Debugger.h:692
Target & GetSelectedOrDummyTarget(bool prefer_dummy=false)
std::vector< std::string > CopyLogFilesToDirectory(const FileSpec &dir)
Copy this debugger's file-backed log files into the given directory, for inclusion in a diagnostics b...
IOHandlerStack m_io_handler_stack
Definition Debugger.h:819
llvm::once_flag m_clear_once
Definition Debugger.h:840
static void SettingsTerminate()
Definition Debugger.cpp:887
static void ReportProgress(uint64_t progress_id, std::string title, std::string details, uint64_t completed, uint64_t total, std::optional< lldb::user_id_t > debugger_id, uint32_t progress_category_bit=lldb::eBroadcastBitProgress)
Report progress events.
lldb::LanguageType GetREPLLanguage() const
Definition Debugger.cpp:470
ScriptInterpreter * GetScriptInterpreter(bool can_create=true, std::optional< lldb::ScriptLanguage > language={})
void SetLoggingCallback(lldb::LogOutputCallback log_callback, void *baton)
bool SetTerminalWidth(uint64_t term_width)
Definition Debugger.cpp:486
Debugger(lldb::LogOutputCallback m_log_callback, void *baton)
llvm::StringRef GetExternalEditor() const
Definition Debugger.cpp:532
static size_t GetNumDebuggers()
FormatEntity::Entry GetThreadFormat() const
Definition Debugger.cpp:448
uint32_t m_interrupt_requested
Tracks interrupt requests.
Definition Debugger.h:863
lldb::DWIMPrintVerbosity GetDWIMPrintVerbosity() const
Definition Debugger.cpp:820
StringPoolRef GetStringPool() const
The pool for strings handed out through the SB API that belong to this debugger.
Definition Debugger.h:428
bool GetMarkHiddenFrames() const
Definition Debugger.cpp:712
lldb::BroadcasterManagerSP GetBroadcasterManager()
Definition Debugger.h:569
lldb::thread_result_t DefaultEventHandler()
void PrintAsync(const char *s, size_t len, bool is_stdout)
lldb::LockableStreamFileSP GetErrorStreamSP()
Definition Debugger.h:743
llvm::Error EnableLog(llvm::StringRef channel, llvm::ArrayRef< const char * > categories, llvm::StringRef log_file, uint32_t log_options, size_t buffer_size, LogHandlerKind log_handler_kind)
llvm::StringRef GetPrompt() const
Definition Debugger.cpp:419
bool GetNotifyVoid() const
Definition Debugger.cpp:413
llvm::StringRef GetShowProgressAnsiPrefix() const
Definition Debugger.cpp:569
void AdoptTopIOHandlerFilesIfInvalid(lldb::FileSP &in, lldb::LockableStreamFileSP &out, lldb::LockableStreamFileSP &err)
FormatEntity::Entry GetFrameFormat() const
Definition Debugger.cpp:397
lldb::StopDisassemblyType GetStopDisassemblyDisplay() const
Definition Debugger.cpp:762
llvm::StringRef GetTopIOHandlerControlSequence(char ch)
void FlushProcessOutput(Process &process, bool flush_stdout, bool flush_stderr)
Force flushing the process's pending stdout and stderr to the debugger's asynchronous stdout and stde...
void CancelInterruptRequest()
Decrement the "interrupt requested" counter.
static void ReportDiagnosticImpl(lldb::Severity severity, std::string message, std::optional< lldb::user_id_t > debugger_id, std::once_flag *once)
std::vector< lldb::DebuggerSP > DebuggerList
Definition Debugger.h:105
bool SetAutoIndent(bool b)
Definition Debugger.cpp:793
const Debugger & operator=(const Debugger &)=delete
friend class CommandInterpreter
Definition Debugger.h:689
llvm::StringRef GetStopShowColumnAnsiPrefix() const
Definition Debugger.cpp:731
static DebuggerList DebuggersRequestingInterruption()
Execution context objects refer to objects in the execution of the program that is being debugged.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A file collection class.
A file utility class.
Definition FileSpec.h:56
An abstract base class for files.
Definition FileBase.h:34
std::recursive_mutex Mutex
Definition StreamFile.h:77
A plug-in interface definition class for debugging a process.
Definition Process.h:369
The SourceFileCache class separates the source manager from the cache of source files.
An error handling class.
Definition Status.h:118
A stream class that can stream formatted output to a file.
Definition Stream.h:28
A handle to a StringPool that does not own it.
Definition StringPool.h:72
std::shared_ptr< Dictionary > DictionarySP
Defines a symbol context baton that can be handed other debug core functions.
A thread-safe collection of target groups.
A RAII-friendly terminal state saving/restoring class.
Definition Terminal.h:99
A class that represents a running process on the host machine.
void(* DebuggerDestroyCallback)(lldb::user_id_t debugger_id, void *baton)
llvm::sys::DynamicLibrary(* LoadPluginCallbackType)(const lldb::DebuggerSP &debugger_sp, const FileSpec &spec, Status &error)
VarSetOperationType
Settable state variable types.
AutosuggestionMode
Controls how the show-autosuggestion setting drives inline suggestions in the interactive command lin...
ScriptLanguage
Script interpreter types.
Severity
Used for expressing severity in logs and diagnostics.
std::shared_ptr< lldb_private::BroadcasterManager > BroadcasterManagerSP
@ eBroadcastBitProgress
std::shared_ptr< lldb_private::IOHandler > IOHandlerSP
std::shared_ptr< lldb_private::Thread > ThreadSP
void * thread_result_t
Definition lldb-types.h:62
DWIMPrintVerbosity
Enum to control the verbosity level of dwim-print execution.
LanguageType
Programming language type.
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Debugger > DebuggerSP
StopDisassemblyType
Used to determine when to show disassembly.
std::shared_ptr< lldb_private::Event > EventSP
std::shared_ptr< lldb_private::Listener > ListenerSP
int32_t callback_token_t
Definition lldb-types.h:82
uint64_t user_id_t
Definition lldb-types.h:83
std::shared_ptr< lldb_private::LockableStreamFile > LockableStreamFileSP
void(* LogOutputCallback)(const char *, void *baton)
Definition lldb-types.h:73
std::shared_ptr< lldb_private::Target > TargetSP
std::unique_ptr< lldb_private::Stream > StreamUP
std::shared_ptr< lldb_private::File > FileSP
DestroyCallbackInfo(lldb::callback_token_t token, lldb_private::DebuggerDestroyCallback callback, void *baton)
Definition Debugger.h:853
lldb_private::DebuggerDestroyCallback callback
Definition Debugger.h:858
void AppendSafeAutoLoadPaths(FileSpec path)
Appends a path to the testing.safe-auto-load-paths setting.
Definition Debugger.cpp:283
static TestingProperties & GetGlobalTestingProperties()
Definition Debugger.cpp:270
FileSpecList GetSafeAutoLoadPaths() const
Callers should use Debugger::GetSafeAutoLoadPaths since it accounts for default paths configured via ...
Definition Debugger.cpp:291
void SetSafeAutoLoadPaths(FileSpecList paths)
Overwrites the testing.safe-auto-load-paths settings.
Definition Debugger.cpp:275
UserID(lldb::user_id_t uid=LLDB_INVALID_UID)
Construct with optional user ID.
Definition UserID.h:33