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