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 GetLabelAnsiPrefix() const;
348
349 llvm::StringRef GetLabelAnsiSuffix() const;
350
351 llvm::StringRef GetTitleAnsiPrefix() const;
352
353 llvm::StringRef GetTitleAnsiSuffix() const;
354
355 llvm::StringRef GetDividerAnsiPrefix() const;
356
357 llvm::StringRef GetDividerAnsiSuffix() const;
358
359 llvm::StringRef GetDisabledAnsiPrefix() const;
360
361 llvm::StringRef GetDisabledAnsiSuffix() const;
362
364
365 llvm::StringRef GetAutosuggestionAnsiPrefix() const;
366
367 llvm::StringRef GetAutosuggestionAnsiSuffix() const;
368
369 llvm::StringRef GetRegexMatchAnsiPrefix() const;
370
371 llvm::StringRef GetRegexMatchAnsiSuffix() const;
372
373 bool GetShowDontUsePoHint() const;
374
375 bool GetUseSourceCache() const;
376
377 bool SetUseSourceCache(bool use_source_cache);
378
379 bool GetMarkHiddenFrames() const;
380
381 bool GetHighlightSource() const;
382
384
385 llvm::StringRef GetStopShowColumnAnsiPrefix() const;
386
387 llvm::StringRef GetStopShowColumnAnsiSuffix() const;
388
389 uint64_t GetStopSourceLineCount(bool before) const;
390
392
393 uint64_t GetDisassemblyLineCount() const;
394
395 llvm::StringRef GetStopShowLineMarkerAnsiPrefix() const;
396
397 llvm::StringRef GetStopShowLineMarkerAnsiSuffix() const;
398
399 bool GetAutoOneLineSummaries() const;
400
401 bool GetAutoIndent() const;
402
403 bool SetAutoIndent(bool b);
404
405 bool GetPrintDecls() const;
406
407 bool SetPrintDecls(bool b);
408
409 uint64_t GetTabSize() const;
410
411 bool SetTabSize(uint64_t tab_size);
412
414
415 bool GetEscapeNonPrintables() const;
416
417 bool GetNotifyVoid() const;
418
419 const std::string &GetInstanceName() const { return m_instance_name; }
420
421 bool GetShowInlineDiagnostics() const;
422
423 bool SetShowInlineDiagnostics(bool);
424
425 bool LoadPlugin(const FileSpec &spec, Status &error);
426
427 void RunIOHandlers();
428
429 bool IsForwardingEvents();
430
431 void EnableForwardEvents(const lldb::ListenerSP &listener_sp);
432
433 void CancelForwardEvents(const lldb::ListenerSP &listener_sp);
434
435 bool IsHandlingEvents() const { return m_event_handler_thread.IsJoinable(); }
436
437 Status RunREPL(lldb::LanguageType language, const char *repl_options);
438
439 /// Interruption in LLDB:
440 ///
441 /// This is a voluntary interruption mechanism, not preemptive. Parts of lldb
442 /// that do work that can be safely interrupted call
443 /// Debugger::InterruptRequested and if that returns true, they should return
444 /// at a safe point, shortcutting the rest of the work they were to do.
445 ///
446 /// lldb clients can both offer a CommandInterpreter (through
447 /// RunCommandInterpreter) and use the SB API's for their own purposes, so it
448 /// is convenient to separate "interrupting the CommandInterpreter execution"
449 /// and interrupting the work it is doing with the SB API's. So there are two
450 /// ways to cause an interrupt:
451 /// * CommandInterpreter::InterruptCommand: Interrupts the command currently
452 /// running in the command interpreter IOHandler thread
453 /// * Debugger::RequestInterrupt: Interrupts are active on anything but the
454 /// CommandInterpreter thread till CancelInterruptRequest is called.
455 ///
456 /// Since the two checks are mutually exclusive, however, it's also convenient
457 /// to have just one function to check the interrupt state.
458
459 /// Bump the "interrupt requested" count on the debugger to support
460 /// cooperative interruption. If this is non-zero, InterruptRequested will
461 /// return true. Interruptible operations are expected to query the
462 /// InterruptRequested API periodically, and interrupt what they were doing
463 /// if it returns \b true.
464 ///
465 void RequestInterrupt();
466
467 /// Decrement the "interrupt requested" counter.
469
470 /// Redraw the statusline if enabled.
471 void RedrawStatusline(std::optional<ExecutionContextRef> exe_ctx_ref);
472
473 /// Whether the statusline can be drawn: show-statusline is enabled and the
474 /// output is an escape-code-capable terminal.
475 bool StatuslineSupported();
476
477 /// Flush cached state (e.g. stale execution context in the statusline).
478 void FlushStatusLine();
479
480 /// This is the correct way to query the state of Interruption.
481 /// If you are on the RunCommandInterpreter thread, it will check the
482 /// command interpreter state, and if it is on another thread it will
483 /// check the debugger Interrupt Request state.
484 /// \param[in] cur_func
485 /// For reporting if the interruption was requested. Don't provide this by
486 /// hand, use INTERRUPT_REQUESTED so this gets done consistently.
487 ///
488 /// \param[in] formatv
489 /// A formatv string for the interrupt message. If the elements of the
490 /// message are expensive to compute, you can use the no-argument form of
491 /// InterruptRequested, then make up the report using REPORT_INTERRUPTION.
492 ///
493 /// \return
494 /// A boolean value, if \b true an interruptible operation should interrupt
495 /// itself.
496 template <typename... Args>
497 bool InterruptRequested(const char *cur_func, const char *formatv,
498 Args &&...args) {
499 bool ret_val = InterruptRequested();
500 if (ret_val) {
501 if (!formatv)
502 formatv = "Unknown message";
503 if (!cur_func)
504 cur_func = "<UNKNOWN>";
506 cur_func, llvm::formatv(formatv, std::forward<Args>(args)...)));
507 }
508 return ret_val;
509 }
510
511 /// This handy define will keep you from having to generate a report for the
512 /// interruption by hand. Use this except in the case where the arguments to
513 /// the message description are expensive to compute.
514#define INTERRUPT_REQUESTED(debugger, ...) \
515 (debugger).InterruptRequested(__func__, __VA_ARGS__)
516
517 // This form just queries for whether to interrupt, and does no reporting:
518 bool InterruptRequested();
519
520 // FIXME: Do we want to capture a backtrace at the interruption point?
522 public:
523 InterruptionReport(std::string function_name, std::string description)
524 : m_function_name(std::move(function_name)),
525 m_description(std::move(description)),
526 m_interrupt_time(std::chrono::system_clock::now()),
527 m_thread_id(llvm::get_threadid()) {}
528
529 InterruptionReport(std::string function_name,
530 const llvm::formatv_object_base &payload);
531
532 template <typename... Args>
533 InterruptionReport(std::string function_name, const char *format,
534 Args &&...args)
536 function_name,
537 llvm::formatv(format, std::forward<Args>(args)...)) {}
538
539 std::string m_function_name;
540 std::string m_description;
541 const std::chrono::time_point<std::chrono::system_clock> m_interrupt_time;
542 const uint64_t m_thread_id;
543 };
544 void ReportInterruption(const InterruptionReport &report);
545#define REPORT_INTERRUPTION(debugger, ...) \
546 (debugger).ReportInterruption( \
547 Debugger::InterruptionReport(__func__, __VA_ARGS__))
548
550
551public:
552 // This is for use in the command interpreter, when you either want the
553 // selected target, or if no target is present you want to prime the dummy
554 // target with entities that will be copied over to new targets.
555 Target &GetSelectedOrDummyTarget(bool prefer_dummy = false);
557
561
562 /// Shared thread pool. Use only with ThreadPoolTaskGroup.
563 static llvm::ThreadPoolInterface &GetThreadPool();
564
565 /// Report warning events.
566 ///
567 /// Warning events will be delivered to any debuggers that have listeners
568 /// for the eBroadcastBitWarning.
569 ///
570 /// \param[in] message
571 /// The warning message to be reported.
572 ///
573 /// \param [in] debugger_id
574 /// If this optional parameter has a value, it indicates the unique
575 /// debugger identifier that this diagnostic should be delivered to. If
576 /// this optional parameter does not have a value, the diagnostic event
577 /// will be delivered to all debuggers.
578 ///
579 /// \param [in] once
580 /// If a pointer is passed to a std::once_flag, then it will be used to
581 /// ensure the given warning is only broadcast once.
582 static void
583 ReportWarning(std::string message,
584 std::optional<lldb::user_id_t> debugger_id = std::nullopt,
585 std::once_flag *once = nullptr);
586
587 /// Report error events.
588 ///
589 /// Error events will be delivered to any debuggers that have listeners
590 /// for the eBroadcastBitError.
591 ///
592 /// \param[in] message
593 /// The error message to be reported.
594 ///
595 /// \param [in] debugger_id
596 /// If this optional parameter has a value, it indicates the unique
597 /// debugger identifier that this diagnostic should be delivered to. If
598 /// this optional parameter does not have a value, the diagnostic event
599 /// will be delivered to all debuggers.
600 ///
601 /// \param [in] once
602 /// If a pointer is passed to a std::once_flag, then it will be used to
603 /// ensure the given error is only broadcast once.
604 static void
605 ReportError(std::string message,
606 std::optional<lldb::user_id_t> debugger_id = std::nullopt,
607 std::once_flag *once = nullptr);
608
609 /// Report info events.
610 ///
611 /// Unlike warning and error events, info events are not broadcast but are
612 /// logged for diagnostic purposes.
613 ///
614 /// \param[in] message
615 /// The info message to be reported.
616 ///
617 /// \param [in] debugger_id
618 /// If this optional parameter has a value, it indicates this diagnostic is
619 /// associated with a unique debugger instance.
620 ///
621 /// \param [in] once
622 /// If a pointer is passed to a std::once_flag, then it will be used to
623 /// ensure the given info is only logged once.
624 static void
625 ReportInfo(std::string message,
626 std::optional<lldb::user_id_t> debugger_id = std::nullopt,
627 std::once_flag *once = nullptr);
628
629 static void ReportSymbolChange(const ModuleSpec &module_spec);
630
631 /// DEPRECATED: We used to only support one Destroy callback. Now that we
632 /// support Add and Remove, you should only remove callbacks that you added.
633 /// Use Add and Remove instead.
634 ///
635 /// Clear all previously added callbacks and only add the given one.
636 void
638 void *baton);
639
640 /// Add a callback for when the debugger is destroyed. Return a token, which
641 /// can be used to remove said callback. Multiple callbacks can be added by
642 /// calling this function multiple times, and will be invoked in FIFO order.
645 void *baton);
646
647 /// Remove the specified callback. Return true if successful.
649
650 /// Manually start the global event handler thread. It is useful to plugins
651 /// that directly use the \a lldb_private namespace and want to use the
652 /// debugger's default event handler thread instead of defining their own.
654
655 /// Manually stop the debugger's default event handler.
657
658 /// Force flushing the process's pending stdout and stderr to the debugger's
659 /// asynchronous stdout and stderr streams.
660 void FlushProcessOutput(Process &process, bool flush_stdout,
661 bool flush_stderr);
662
666
668 uint64_t id;
669 uint64_t completed;
670 uint64_t total;
671 std::string message;
672 };
673 std::optional<ProgressReport> GetCurrentProgressReport() const;
674
676
677protected:
678 friend class CommandInterpreter;
679 friend class REPL;
680 friend class Progress;
681 friend class ProgressManager;
682 friend class Statusline;
683
684 /// Report progress events.
685 ///
686 /// Progress events will be delivered to any debuggers that have listeners
687 /// for the eBroadcastBitProgress. This function is called by the
688 /// lldb_private::Progress class to deliver the events to any debuggers that
689 /// qualify.
690 ///
691 /// \param [in] progress_id
692 /// The unique integer identifier for the progress to report.
693 ///
694 /// \param[in] message
695 /// The title of the progress dialog to display in the UI.
696 ///
697 /// \param [in] completed
698 /// The amount of work completed. If \a completed is zero, then this event
699 /// is a progress started event. If \a completed is equal to \a total, then
700 /// this event is a progress end event. Otherwise completed indicates the
701 /// current progress compare to the total value.
702 ///
703 /// \param [in] total
704 /// The total amount of work units that need to be completed. If this value
705 /// is UINT64_MAX, then an indeterminate progress indicator should be
706 /// displayed.
707 ///
708 /// \param [in] debugger_id
709 /// If this optional parameter has a value, it indicates the unique
710 /// debugger identifier that this progress should be delivered to. If this
711 /// optional parameter does not have a value, the progress will be
712 /// delivered to all debuggers.
713 static void
714 ReportProgress(uint64_t progress_id, std::string title, std::string details,
715 uint64_t completed, uint64_t total,
716 std::optional<lldb::user_id_t> debugger_id,
717 uint32_t progress_category_bit = lldb::eBroadcastBitProgress);
718
719 static void ReportDiagnosticImpl(lldb::Severity severity, std::string message,
720 std::optional<lldb::user_id_t> debugger_id,
721 std::once_flag *once);
722
724
726
727 /// Except for Debugger and IOHandler, GetOutputStreamSP and GetErrorStreamSP
728 /// should not be used directly. Use GetAsyncOutputStream and
729 /// GetAsyncErrorStream instead.
730 /// @{
733 /// @}
734
736
737 void PushIOHandler(const lldb::IOHandlerSP &reader_sp,
738 bool cancel_top_handler = true);
739
740 bool PopIOHandler(const lldb::IOHandlerSP &reader_sp);
741
742 bool HasIOHandlerThread() const;
743
745
746 void StopIOHandlerThread();
747
748 // Sets the IOHandler thread to the new_thread, and returns
749 // the previous IOHandler thread.
751
752 void JoinIOHandlerThread();
753
755
757
759
760 void HandleBreakpointEvent(const lldb::EventSP &event_sp);
761
763
765
766 void HandleProgressEvent(const lldb::EventSP &event_sp);
767
768 void HandleDiagnosticEvent(const lldb::EventSP &event_sp);
769
770 // Ensures two threads don't attempt to flush process output in parallel.
772
773 void InstanceInitialize();
774
775 // these should never be NULL
780
782 // broadcaster manager of
783 // last resort.
784 // It needs to get constructed before the target_list or any other member
785 // that might want to broadcast through the debugger.
786
789
792 std::unique_ptr<SourceManager> m_source_manager_up; // This is a scratch
793 // source manager that we
794 // return if we have no
795 // targets.
797 // for targets created in
798 // this debugger used this
799 // shared
800 // source file cache.
801 std::unique_ptr<CommandInterpreter> m_command_interpreter_up;
802
803 std::recursive_mutex m_script_interpreter_mutex;
804 std::array<lldb::ScriptInterpreterSP, lldb::eScriptLanguageUnknown>
806
808 std::recursive_mutex m_io_handler_synchronous_mutex;
809
810 /// Mutex protecting the m_statusline member.
812 std::optional<Statusline> m_statusline;
813
814 llvm::StringMap<std::weak_ptr<LogHandler>> m_stream_handlers;
815 std::shared_ptr<CallbackLogHandler> m_callback_handler_sp;
816 const std::string m_instance_name;
818 typedef std::vector<llvm::sys::DynamicLibrary> LoadedPluginsList;
822 Broadcaster m_sync_broadcaster; ///< Private debugger synchronization.
823 Broadcaster m_broadcaster; ///< Public Debugger event broadcaster.
825 llvm::once_flag m_clear_once;
827
828 /// Bookkeeping for command line progress events.
829 /// @{
830 llvm::SmallVector<ProgressReport, 4> m_progress_reports;
831 mutable std::mutex m_progress_reports_mutex;
832 /// @}
833
846 llvm::SmallVector<DestroyCallbackInfo, 2> m_destroy_callbacks;
847
848 uint32_t m_interrupt_requested = 0; ///< Tracks interrupt requests
850
851 // Events for m_sync_broadcaster
852 enum {
854 };
855
856private:
857 // Use Debugger::CreateInstance() to get a shared pointer to a new debugger
858 // object
859 Debugger(lldb::LogOutputCallback m_log_callback, void *baton);
860
861 Debugger(const Debugger &) = delete;
862 const Debugger &operator=(const Debugger &) = delete;
863};
864
865} // namespace lldb_private
866
867#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:541
InterruptionReport(std::string function_name, std::string description)
Definition Debugger.h:523
InterruptionReport(std::string function_name, const char *format, Args &&...args)
Definition Debugger.h:533
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:790
HostThread m_event_handler_thread
Definition Debugger.h:820
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:777
bool SetExternalEditor(llvm::StringRef editor)
Definition Debugger.cpp:538
void RequestInterrupt()
Interruption in LLDB:
void ReportInterruption(const InterruptionReport &report)
const std::string m_instance_name
Definition Debugger.h:816
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:680
SourceManager::SourceFileCache & GetSourceFileCache()
Definition Debugger.h:663
void CancelForwardEvents(const lldb::ListenerSP &listener_sp)
bool GetPrintDecls() const
Definition Debugger.cpp:798
lldb::FileSP GetInputFileSP()
Definition Debugger.h:155
bool GetHighlightSource() const
Definition Debugger.cpp:718
llvm::StringMap< std::weak_ptr< LogHandler > > m_stream_handlers
Definition Debugger.h:814
llvm::StringRef GetLabelAnsiSuffix() const
Definition Debugger.cpp:587
CommandInterpreter & GetCommandInterpreter()
Definition Debugger.h:182
FormatEntity::Entry GetStatuslineFormat() const
Definition Debugger.cpp:623
llvm::StringRef GetDividerAnsiPrefix() const
Definition Debugger.cpp:605
LoadedPluginsList m_loaded_plugins
Definition Debugger.h:819
bool GetShowInlineDiagnostics() const
Definition Debugger.cpp:827
std::vector< llvm::sys::DynamicLibrary > LoadedPluginsList
Definition Debugger.h:818
Debugger(const Debugger &)=delete
bool SetTabSize(uint64_t tab_size)
Definition Debugger.cpp:815
bool IsHandlingEvents() const
Definition Debugger.h:435
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:791
void PushIOHandler(const lldb::IOHandlerSP &reader_sp, bool cancel_top_handler=true)
std::mutex m_destroy_callback_mutex
Definition Debugger.h:834
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:787
lldb::StreamUP GetAsyncErrorStream()
TargetList & GetTargetList()
Get accessor for the target list.
Definition Debugger.h:220
bool GetEscapeNonPrintables() const
Definition Debugger.cpp:781
lldb::TargetSP m_dummy_target_sp
Definition Debugger.h:826
llvm::SmallVector< DestroyCallbackInfo, 2 > m_destroy_callbacks
Definition Debugger.h:846
std::unique_ptr< CommandInterpreter > m_command_interpreter_up
Definition Debugger.h:801
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:779
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:830
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:995
lldb::FileSP GetErrorFileSP()
Definition Debugger.h:162
std::mutex m_progress_reports_mutex
Definition Debugger.h:831
lldb::ProcessSP HandleProcessEvent(const lldb::EventSP &event_sp)
lldb::ListenerSP m_forward_listener_sp
Definition Debugger.h:824
std::array< lldb::ScriptInterpreterSP, lldb::eScriptLanguageUnknown > m_script_interpreters
Definition Debugger.h:805
std::shared_ptr< CallbackLogHandler > m_callback_handler_sp
Definition Debugger.h:815
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:823
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:849
std::recursive_mutex m_io_handler_synchronous_mutex
Definition Debugger.h:808
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:497
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:679
std::optional< Statusline > m_statusline
Definition Debugger.h:812
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:781
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:817
bool GetShowStatusline() const
Definition Debugger.cpp:617
std::recursive_mutex m_script_interpreter_mutex
Definition Debugger.h:803
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:731
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:822
friend class Statusline
Definition Debugger.h:682
llvm::StringRef GetTitleAnsiSuffix() const
Definition Debugger.cpp:599
bool GetUseSourceCache() const
Definition Debugger.cpp:697
HostThread m_io_handler_thread
Definition Debugger.h:821
llvm::StringRef GetRegexMatchAnsiSuffix() const
Definition Debugger.cpp:685
static llvm::StringRef GetStaticBroadcasterClass()
lldb::FileSP m_input_file_sp
Definition Debugger.h:776
const Broadcaster & GetBroadcaster() const
Definition Debugger.h:108
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:788
lldb::ScriptLanguage GetScriptLanguage() const
Definition Debugger.cpp:458
lldb::callback_token_t m_destroy_callback_next_token
Definition Debugger.h:835
std::unique_ptr< SourceManager > m_source_manager_up
Definition Debugger.h:792
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:778
bool SetShowInlineDiagnostics(bool)
Definition Debugger.cpp:833
const std::string & GetInstanceName() const
Definition Debugger.h:419
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:222
Target & GetDummyTarget()
Definition Debugger.h:556
lldb::ListenerSP GetListener()
Definition Debugger.h:191
static void Destroy(lldb::DebuggerSP &debugger_sp)
SourceManager::SourceFileCache m_source_file_cache
Definition Debugger.h:796
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:107
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:771
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:811
const char * GetIOHandlerHelpPrologue()
Status SetInputString(const char *data)
llvm::StringRef GetLabelAnsiPrefix() const
Definition Debugger.cpp:581
friend class ProgressManager
Definition Debugger.h:681
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:807
llvm::once_flag m_clear_once
Definition Debugger.h:825
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:848
lldb::DWIMPrintVerbosity GetDWIMPrintVerbosity() const
Definition Debugger.cpp:820
bool GetMarkHiddenFrames() const
Definition Debugger.cpp:712
lldb::BroadcasterManagerSP GetBroadcasterManager()
Definition Debugger.h:558
lldb::thread_result_t DefaultEventHandler()
void PrintAsync(const char *s, size_t len, bool is_stdout)
lldb::LockableStreamFileSP GetErrorStreamSP()
Definition Debugger.h:732
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:102
bool SetAutoIndent(bool b)
Definition Debugger.cpp:793
const Debugger & operator=(const Debugger &)=delete
friend class CommandInterpreter
Definition Debugger.h:678
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:368
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: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:838
lldb_private::DebuggerDestroyCallback callback
Definition Debugger.h:843
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