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
20#include "lldb/Core/IOHandler.h"
24#include "lldb/Core/Telemetry.h"
28#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
200 return m_target_list.GetSelectedTarget();
201 }
202
203 /// Get the execution context representing the selected entities in the
204 /// selected target. If no target is selected, the execution context will
205 /// contain the dummy target if adopt_dummy_target is true.
206 ///
207 // Ideally, adopt_dummy_target would be the default. However, there are a
208 // bunch of operations that don't make sense on the dummy target but we lack
209 // a mechanism to enforce that. The explicit argument forces the caller to
210 // consider the dummy target.
211 ExecutionContext GetSelectedExecutionContext(bool adopt_dummy_target);
212
213 /// Like GetSelectedExecutionContext but returns an ExecutionContextRef.
215
216 /// Get accessor for the target list.
217 ///
218 /// The target list is part of the global debugger object. This the single
219 /// debugger shared instance to control where targets get created and to
220 /// allow for tracking and searching for targets based on certain criteria.
221 ///
222 /// \return
223 /// A global shared target list.
225
227
229
231
232 // If any of the streams are not set, set them to the in/out/err stream of
233 // the top most input reader to ensure they at least have something
237
238 /// Run the given IO handler and return immediately.
239 void RunIOHandlerAsync(const lldb::IOHandlerSP &reader_sp,
240 bool cancel_top_handler = true);
241
242 /// Run the given IO handler and block until it's complete.
243 void RunIOHandlerSync(const lldb::IOHandlerSP &reader_sp);
244
245 /// Remove the given IO handler if it's currently active.
246 bool RemoveIOHandler(const lldb::IOHandlerSP &reader_sp);
247
248 bool IsTopIOHandler(const lldb::IOHandlerSP &reader_sp);
249
251 IOHandler::Type second_top_type);
252
253 void PrintAsync(const char *s, size_t len, bool is_stdout);
254
255 llvm::StringRef GetTopIOHandlerControlSequence(char ch);
256
257 const char *GetIOHandlerCommandPrefix();
258
259 const char *GetIOHandlerHelpPrologue();
260
261 void RefreshIOHandler();
262
263 void ClearIOHandlers();
264
265 bool EnableLog(llvm::StringRef channel,
266 llvm::ArrayRef<const char *> categories,
267 llvm::StringRef log_file, uint32_t log_options,
268 size_t buffer_size, LogHandlerKind log_handler_kind,
269 llvm::raw_ostream &error_stream);
270
271 void SetLoggingCallback(lldb::LogOutputCallback log_callback, void *baton);
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 llvm::StringRef GetPrompt() const;
308
309 llvm::StringRef GetPromptAnsiPrefix() const;
310
311 llvm::StringRef GetPromptAnsiSuffix() const;
312
313 void SetPrompt(llvm::StringRef p);
314 void SetPrompt(const char *) = delete;
315
316 bool GetUseExternalEditor() const;
317 bool SetUseExternalEditor(bool use_external_editor_p);
318
319 llvm::StringRef GetExternalEditor() const;
320
321 bool SetExternalEditor(llvm::StringRef editor);
322
323 bool GetUseColor() const;
324
325 bool SetUseColor(bool use_color);
326
327 bool GetShowProgress() const;
328
329 bool SetShowProgress(bool show_progress);
330
331 bool GetShowStatusline() const;
332
334 bool SetStatuslineFormat(const FormatEntity::Entry &format);
335
336 llvm::StringRef GetSeparator() const;
337 bool SetSeparator(llvm::StringRef s);
338
339 llvm::StringRef GetShowProgressAnsiPrefix() const;
340
341 llvm::StringRef GetShowProgressAnsiSuffix() const;
342
343 llvm::StringRef GetDisabledAnsiPrefix() const;
344
345 llvm::StringRef GetDisabledAnsiSuffix() const;
346
347 bool GetUseAutosuggestion() const;
348
349 llvm::StringRef GetAutosuggestionAnsiPrefix() const;
350
351 llvm::StringRef GetAutosuggestionAnsiSuffix() const;
352
353 llvm::StringRef GetRegexMatchAnsiPrefix() const;
354
355 llvm::StringRef GetRegexMatchAnsiSuffix() const;
356
357 bool GetShowDontUsePoHint() const;
358
359 bool GetUseSourceCache() const;
360
361 bool SetUseSourceCache(bool use_source_cache);
362
363 bool GetMarkHiddenFrames() const;
364
365 bool GetHighlightSource() const;
366
368
369 llvm::StringRef GetStopShowColumnAnsiPrefix() const;
370
371 llvm::StringRef GetStopShowColumnAnsiSuffix() const;
372
373 uint64_t GetStopSourceLineCount(bool before) const;
374
376
377 uint64_t GetDisassemblyLineCount() const;
378
379 llvm::StringRef GetStopShowLineMarkerAnsiPrefix() const;
380
381 llvm::StringRef GetStopShowLineMarkerAnsiSuffix() const;
382
383 bool GetAutoOneLineSummaries() const;
384
385 bool GetAutoIndent() const;
386
387 bool SetAutoIndent(bool b);
388
389 bool GetPrintDecls() const;
390
391 bool SetPrintDecls(bool b);
392
393 uint64_t GetTabSize() const;
394
395 bool SetTabSize(uint64_t tab_size);
396
398
399 bool GetEscapeNonPrintables() const;
400
401 bool GetNotifyVoid() const;
402
403 const std::string &GetInstanceName() const { return m_instance_name; }
404
405 bool GetShowInlineDiagnostics() const;
406
407 bool SetShowInlineDiagnostics(bool);
408
409 bool LoadPlugin(const FileSpec &spec, Status &error);
410
411 void RunIOHandlers();
412
413 bool IsForwardingEvents();
414
415 void EnableForwardEvents(const lldb::ListenerSP &listener_sp);
416
417 void CancelForwardEvents(const lldb::ListenerSP &listener_sp);
418
419 bool IsHandlingEvents() const { return m_event_handler_thread.IsJoinable(); }
420
421 Status RunREPL(lldb::LanguageType language, const char *repl_options);
422
423 /// Interruption in LLDB:
424 ///
425 /// This is a voluntary interruption mechanism, not preemptive. Parts of lldb
426 /// that do work that can be safely interrupted call
427 /// Debugger::InterruptRequested and if that returns true, they should return
428 /// at a safe point, shortcutting the rest of the work they were to do.
429 ///
430 /// lldb clients can both offer a CommandInterpreter (through
431 /// RunCommandInterpreter) and use the SB API's for their own purposes, so it
432 /// is convenient to separate "interrupting the CommandInterpreter execution"
433 /// and interrupting the work it is doing with the SB API's. So there are two
434 /// ways to cause an interrupt:
435 /// * CommandInterpreter::InterruptCommand: Interrupts the command currently
436 /// running in the command interpreter IOHandler thread
437 /// * Debugger::RequestInterrupt: Interrupts are active on anything but the
438 /// CommandInterpreter thread till CancelInterruptRequest is called.
439 ///
440 /// Since the two checks are mutually exclusive, however, it's also convenient
441 /// to have just one function to check the interrupt state.
442
443 /// Bump the "interrupt requested" count on the debugger to support
444 /// cooperative interruption. If this is non-zero, InterruptRequested will
445 /// return true. Interruptible operations are expected to query the
446 /// InterruptRequested API periodically, and interrupt what they were doing
447 /// if it returns \b true.
448 ///
449 void RequestInterrupt();
450
451 /// Decrement the "interrupt requested" counter.
453
454 /// Redraw the statusline if enabled.
455 void RedrawStatusline(std::optional<ExecutionContextRef> exe_ctx_ref);
456
457 /// Flush cached state (e.g. stale execution context in the statusline).
458 void FlushStatusLine();
459
460 /// This is the correct way to query the state of Interruption.
461 /// If you are on the RunCommandInterpreter thread, it will check the
462 /// command interpreter state, and if it is on another thread it will
463 /// check the debugger Interrupt Request state.
464 /// \param[in] cur_func
465 /// For reporting if the interruption was requested. Don't provide this by
466 /// hand, use INTERRUPT_REQUESTED so this gets done consistently.
467 ///
468 /// \param[in] formatv
469 /// A formatv string for the interrupt message. If the elements of the
470 /// message are expensive to compute, you can use the no-argument form of
471 /// InterruptRequested, then make up the report using REPORT_INTERRUPTION.
472 ///
473 /// \return
474 /// A boolean value, if \b true an interruptible operation should interrupt
475 /// itself.
476 template <typename... Args>
477 bool InterruptRequested(const char *cur_func, const char *formatv,
478 Args &&...args) {
479 bool ret_val = InterruptRequested();
480 if (ret_val) {
481 if (!formatv)
482 formatv = "Unknown message";
483 if (!cur_func)
484 cur_func = "<UNKNOWN>";
486 cur_func, llvm::formatv(formatv, std::forward<Args>(args)...)));
487 }
488 return ret_val;
489 }
490
491 /// This handy define will keep you from having to generate a report for the
492 /// interruption by hand. Use this except in the case where the arguments to
493 /// the message description are expensive to compute.
494#define INTERRUPT_REQUESTED(debugger, ...) \
495 (debugger).InterruptRequested(__func__, __VA_ARGS__)
496
497 // This form just queries for whether to interrupt, and does no reporting:
498 bool InterruptRequested();
499
500 // FIXME: Do we want to capture a backtrace at the interruption point?
502 public:
503 InterruptionReport(std::string function_name, std::string description)
504 : m_function_name(std::move(function_name)),
505 m_description(std::move(description)),
506 m_interrupt_time(std::chrono::system_clock::now()),
507 m_thread_id(llvm::get_threadid()) {}
508
509 InterruptionReport(std::string function_name,
510 const llvm::formatv_object_base &payload);
511
512 template <typename... Args>
513 InterruptionReport(std::string function_name, const char *format,
514 Args &&...args)
516 function_name,
517 llvm::formatv(format, std::forward<Args>(args)...)) {}
518
519 std::string m_function_name;
520 std::string m_description;
521 const std::chrono::time_point<std::chrono::system_clock> m_interrupt_time;
522 const uint64_t m_thread_id;
523 };
524 void ReportInterruption(const InterruptionReport &report);
525#define REPORT_INTERRUPTION(debugger, ...) \
526 (debugger).ReportInterruption( \
527 Debugger::InterruptionReport(__func__, __VA_ARGS__))
528
530
531public:
532 // This is for use in the command interpreter, when you either want the
533 // selected target, or if no target is present you want to prime the dummy
534 // target with entities that will be copied over to new targets.
535 Target &GetSelectedOrDummyTarget(bool prefer_dummy = false);
537
541
542 /// Shared thread pool. Use only with ThreadPoolTaskGroup.
543 static llvm::ThreadPoolInterface &GetThreadPool();
544
545 /// Report warning events.
546 ///
547 /// Warning events will be delivered to any debuggers that have listeners
548 /// for the eBroadcastBitWarning.
549 ///
550 /// \param[in] message
551 /// The warning message to be reported.
552 ///
553 /// \param [in] debugger_id
554 /// If this optional parameter has a value, it indicates the unique
555 /// debugger identifier that this diagnostic should be delivered to. If
556 /// this optional parameter does not have a value, the diagnostic event
557 /// will be delivered to all debuggers.
558 ///
559 /// \param [in] once
560 /// If a pointer is passed to a std::once_flag, then it will be used to
561 /// ensure the given warning is only broadcast once.
562 static void
563 ReportWarning(std::string message,
564 std::optional<lldb::user_id_t> debugger_id = std::nullopt,
565 std::once_flag *once = nullptr);
566
567 /// Report error events.
568 ///
569 /// Error events will be delivered to any debuggers that have listeners
570 /// for the eBroadcastBitError.
571 ///
572 /// \param[in] message
573 /// The error message to be reported.
574 ///
575 /// \param [in] debugger_id
576 /// If this optional parameter has a value, it indicates the unique
577 /// debugger identifier that this diagnostic should be delivered to. If
578 /// this optional parameter does not have a value, the diagnostic event
579 /// will be delivered to all debuggers.
580 ///
581 /// \param [in] once
582 /// If a pointer is passed to a std::once_flag, then it will be used to
583 /// ensure the given error is only broadcast once.
584 static void
585 ReportError(std::string message,
586 std::optional<lldb::user_id_t> debugger_id = std::nullopt,
587 std::once_flag *once = nullptr);
588
589 /// Report info events.
590 ///
591 /// Unlike warning and error events, info events are not broadcast but are
592 /// logged for diagnostic purposes.
593 ///
594 /// \param[in] message
595 /// The info message to be reported.
596 ///
597 /// \param [in] debugger_id
598 /// If this optional parameter has a value, it indicates this diagnostic is
599 /// associated with a unique debugger instance.
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 info is only logged once.
604 static void
605 ReportInfo(std::string message,
606 std::optional<lldb::user_id_t> debugger_id = std::nullopt,
607 std::once_flag *once = nullptr);
608
609 static void ReportSymbolChange(const ModuleSpec &module_spec);
610
611 /// DEPRECATED: We used to only support one Destroy callback. Now that we
612 /// support Add and Remove, you should only remove callbacks that you added.
613 /// Use Add and Remove instead.
614 ///
615 /// Clear all previously added callbacks and only add the given one.
616 void
618 void *baton);
619
620 /// Add a callback for when the debugger is destroyed. Return a token, which
621 /// can be used to remove said callback. Multiple callbacks can be added by
622 /// calling this function multiple times, and will be invoked in FIFO order.
625 void *baton);
626
627 /// Remove the specified callback. Return true if successful.
629
630 /// Manually start the global event handler thread. It is useful to plugins
631 /// that directly use the \a lldb_private namespace and want to use the
632 /// debugger's default event handler thread instead of defining their own.
634
635 /// Manually stop the debugger's default event handler.
637
638 /// Force flushing the process's pending stdout and stderr to the debugger's
639 /// asynchronous stdout and stderr streams.
640 void FlushProcessOutput(Process &process, bool flush_stdout,
641 bool flush_stderr);
642
646
648 uint64_t id;
649 uint64_t completed;
650 uint64_t total;
651 std::string message;
652 };
653 std::optional<ProgressReport> GetCurrentProgressReport() const;
654
656
657protected:
658 friend class CommandInterpreter;
659 friend class REPL;
660 friend class Progress;
661 friend class ProgressManager;
662 friend class Statusline;
663
664 /// Report progress events.
665 ///
666 /// Progress events will be delivered to any debuggers that have listeners
667 /// for the eBroadcastBitProgress. This function is called by the
668 /// lldb_private::Progress class to deliver the events to any debuggers that
669 /// qualify.
670 ///
671 /// \param [in] progress_id
672 /// The unique integer identifier for the progress to report.
673 ///
674 /// \param[in] message
675 /// The title of the progress dialog to display in the UI.
676 ///
677 /// \param [in] completed
678 /// The amount of work completed. If \a completed is zero, then this event
679 /// is a progress started event. If \a completed is equal to \a total, then
680 /// this event is a progress end event. Otherwise completed indicates the
681 /// current progress compare to the total value.
682 ///
683 /// \param [in] total
684 /// The total amount of work units that need to be completed. If this value
685 /// is UINT64_MAX, then an indeterminate progress indicator should be
686 /// displayed.
687 ///
688 /// \param [in] debugger_id
689 /// If this optional parameter has a value, it indicates the unique
690 /// debugger identifier that this progress should be delivered to. If this
691 /// optional parameter does not have a value, the progress will be
692 /// delivered to all debuggers.
693 static void
694 ReportProgress(uint64_t progress_id, std::string title, std::string details,
695 uint64_t completed, uint64_t total,
696 std::optional<lldb::user_id_t> debugger_id,
697 uint32_t progress_category_bit = lldb::eBroadcastBitProgress);
698
699 static void ReportDiagnosticImpl(lldb::Severity severity, std::string message,
700 std::optional<lldb::user_id_t> debugger_id,
701 std::once_flag *once);
702
704
706
707 /// Except for Debugger and IOHandler, GetOutputStreamSP and GetErrorStreamSP
708 /// should not be used directly. Use GetAsyncOutputStream and
709 /// GetAsyncErrorStream instead.
710 /// @{
713 /// @}
714
716 bool StatuslineSupported();
717
718 void PushIOHandler(const lldb::IOHandlerSP &reader_sp,
719 bool cancel_top_handler = true);
720
721 bool PopIOHandler(const lldb::IOHandlerSP &reader_sp);
722
723 bool HasIOHandlerThread() const;
724
726
727 void StopIOHandlerThread();
728
729 // Sets the IOHandler thread to the new_thread, and returns
730 // the previous IOHandler thread.
732
733 void JoinIOHandlerThread();
734
736
738
740
741 void HandleBreakpointEvent(const lldb::EventSP &event_sp);
742
744
746
747 void HandleProgressEvent(const lldb::EventSP &event_sp);
748
749 void HandleDiagnosticEvent(const lldb::EventSP &event_sp);
750
751 // Ensures two threads don't attempt to flush process output in parallel.
753
754 void InstanceInitialize();
755
756 // these should never be NULL
761
763 // broadcaster manager of
764 // last resort.
765 // It needs to get constructed before the target_list or any other member
766 // that might want to broadcast through the debugger.
767
770
773 std::unique_ptr<SourceManager> m_source_manager_up; // This is a scratch
774 // source manager that we
775 // return if we have no
776 // targets.
778 // for targets created in
779 // this debugger used this
780 // shared
781 // source file cache.
782 std::unique_ptr<CommandInterpreter> m_command_interpreter_up;
783
784 std::recursive_mutex m_script_interpreter_mutex;
785 std::array<lldb::ScriptInterpreterSP, lldb::eScriptLanguageUnknown>
787
789 std::recursive_mutex m_io_handler_synchronous_mutex;
790
791 /// Mutex protecting the m_statusline member.
793 std::optional<Statusline> m_statusline;
794
795 llvm::StringMap<std::weak_ptr<LogHandler>> m_stream_handlers;
796 std::shared_ptr<CallbackLogHandler> m_callback_handler_sp;
797 const std::string m_instance_name;
799 typedef std::vector<llvm::sys::DynamicLibrary> LoadedPluginsList;
803 Broadcaster m_sync_broadcaster; ///< Private debugger synchronization.
804 Broadcaster m_broadcaster; ///< Public Debugger event broadcaster.
806 llvm::once_flag m_clear_once;
809
810 /// Bookkeeping for command line progress events.
811 /// @{
812 llvm::SmallVector<ProgressReport, 4> m_progress_reports;
813 mutable std::mutex m_progress_reports_mutex;
814 /// @}
815
828 llvm::SmallVector<DestroyCallbackInfo, 2> m_destroy_callbacks;
829
830 uint32_t m_interrupt_requested = 0; ///< Tracks interrupt requests
832
833 // Events for m_sync_broadcaster
834 enum {
836 };
837
838private:
839 // Use Debugger::CreateInstance() to get a shared pointer to a new debugger
840 // object
841 Debugger(lldb::LogOutputCallback m_log_callback, void *baton);
842
843 Debugger(const Debugger &) = delete;
844 const Debugger &operator=(const Debugger &) = delete;
845};
846
847} // namespace lldb_private
848
849#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:521
InterruptionReport(std::string function_name, std::string description)
Definition Debugger.h:503
InterruptionReport(std::string function_name, const char *format, Args &&...args)
Definition Debugger.h:513
static void AssertCallback(llvm::StringRef message, llvm::StringRef backtrace, llvm::StringRef prompt)
llvm::StringRef GetAutosuggestionAnsiPrefix() const
Definition Debugger.cpp:612
bool SetUseExternalEditor(bool use_external_editor_p)
Definition Debugger.cpp:509
PlatformList m_platform_list
Definition Debugger.h:771
HostThread m_event_handler_thread
Definition Debugger.h:801
FormatEntity::Entry GetDisassemblyFormat() const
Definition Debugger.cpp:371
uint64_t GetDisassemblyLineCount() const
Definition Debugger.cpp:714
lldb::TargetSP GetSelectedTarget()
Definition Debugger.h:199
llvm::StringRef GetDisabledAnsiSuffix() const
Definition Debugger.cpp:593
uint64_t GetTerminalHeight() const
Definition Debugger.cpp:481
lldb::LockableStreamFileSP m_output_stream_sp
Definition Debugger.h:758
bool SetExternalEditor(llvm::StringRef editor)
Definition Debugger.cpp:520
void RequestInterrupt()
Interruption in LLDB:
void ReportInterruption(const InterruptionReport &report)
const std::string m_instance_name
Definition Debugger.h:797
static void Terminate()
Definition Debugger.cpp:801
lldb::ThreadSP HandleThreadEvent(const lldb::EventSP &event_sp)
void HandleProgressEvent(const lldb::EventSP &event_sp)
SourceManager & GetSourceManager()
bool SetShowProgress(bool show_progress)
Definition Debugger.cpp:546
bool StartEventHandlerThread()
Manually start the global event handler thread.
bool SetUseSourceCache(bool use_source_cache)
Definition Debugger.cpp:648
static const FileSpecList & GetDefaultSafeAutoLoadPaths()
Definition Debugger.cpp:216
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:660
SourceManager::SourceFileCache & GetSourceFileCache()
Definition Debugger.h:643
void CancelForwardEvents(const lldb::ListenerSP &listener_sp)
bool GetPrintDecls() const
Definition Debugger.cpp:743
lldb::FileSP GetInputFileSP()
Definition Debugger.h:155
bool GetHighlightSource() const
Definition Debugger.cpp:663
llvm::StringMap< std::weak_ptr< LogHandler > > m_stream_handlers
Definition Debugger.h:795
CommandInterpreter & GetCommandInterpreter()
Definition Debugger.h:182
FormatEntity::Entry GetStatuslineFormat() const
Definition Debugger.cpp:569
LoadedPluginsList m_loaded_plugins
Definition Debugger.h:800
bool GetShowInlineDiagnostics() const
Definition Debugger.cpp:772
std::vector< llvm::sys::DynamicLibrary > LoadedPluginsList
Definition Debugger.h:799
Debugger(const Debugger &)=delete
bool SetTabSize(uint64_t tab_size)
Definition Debugger.cpp:760
bool IsHandlingEvents() const
Definition Debugger.h:419
void HandleDiagnosticEvent(const lldb::EventSP &event_sp)
static lldb::DebuggerSP GetDebuggerAtIndex(size_t index)
llvm::StringRef GetAutosuggestionAnsiSuffix() const
Definition Debugger.cpp:618
lldb::ListenerSP m_listener_sp
Definition Debugger.h:772
void PushIOHandler(const lldb::IOHandlerSP &reader_sp, bool cancel_top_handler=true)
std::mutex m_destroy_callback_mutex
Definition Debugger.h:816
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:381
std::optional< ProgressReport > GetCurrentProgressReport() const
llvm::StringRef GetDisabledAnsiPrefix() const
Definition Debugger.cpp:587
bool GetUseExternalEditor() const
Definition Debugger.cpp:503
TerminalState m_terminal_state
Definition Debugger.h:768
lldb::StreamUP GetAsyncErrorStream()
TargetList & GetTargetList()
Get accessor for the target list.
Definition Debugger.h:224
bool GetEscapeNonPrintables() const
Definition Debugger.cpp:726
lldb::TargetSP m_dummy_target_sp
Definition Debugger.h:807
llvm::SmallVector< DestroyCallbackInfo, 2 > m_destroy_callbacks
Definition Debugger.h:828
std::unique_ptr< CommandInterpreter > m_command_interpreter_up
Definition Debugger.h:782
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:830
LockableStreamFile::Mutex m_output_mutex
Definition Debugger.h:760
static llvm::ThreadPoolInterface & GetThreadPool()
Shared thread pool. Use only with ThreadPoolTaskGroup.
llvm::StringRef GetShowProgressAnsiSuffix() const
Definition Debugger.cpp:557
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:812
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:940
lldb::FileSP GetErrorFileSP()
Definition Debugger.h:162
std::mutex m_progress_reports_mutex
Definition Debugger.h:813
lldb::ProcessSP HandleProcessEvent(const lldb::EventSP &event_sp)
lldb::ListenerSP m_forward_listener_sp
Definition Debugger.h:805
std::array< lldb::ScriptInterpreterSP, lldb::eScriptLanguageUnknown > m_script_interpreters
Definition Debugger.h:786
std::shared_ptr< CallbackLogHandler > m_callback_handler_sp
Definition Debugger.h:796
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:804
static void Initialize(LoadPluginCallbackType load_plugin_callback)
Definition Debugger.cpp:792
static lldb::DebuggerSP FindDebuggerWithInstanceName(llvm::StringRef instance_name)
Definition Debugger.cpp:998
uint64_t GetTerminalWidth() const
Definition Debugger.cpp:459
std::mutex m_interrupt_mutex
Definition Debugger.h:831
std::recursive_mutex m_io_handler_synchronous_mutex
Definition Debugger.h:789
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:477
bool RemoveIOHandler(const lldb::IOHandlerSP &reader_sp)
Remove the given IO handler if it's currently active.
Diagnostics::CallbackID m_diagnostics_callback_id
Definition Debugger.h:808
void SetPrompt(const char *)=delete
bool GetAutoOneLineSummaries() const
Definition Debugger.cpp:720
const char * GetIOHandlerCommandPrefix()
friend class REPL
Definition Debugger.h:659
std::optional< Statusline > m_statusline
Definition Debugger.h:793
bool GetUseColor() const
Definition Debugger.cpp:525
lldb::BroadcasterManagerSP m_broadcaster_manager_sp
Definition Debugger.h:762
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:798
bool GetShowStatusline() const
Definition Debugger.cpp:563
std::recursive_mutex m_script_interpreter_mutex
Definition Debugger.h:784
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:711
void SetPrompt(llvm::StringRef p)
Definition Debugger.cpp:416
llvm::StringRef GetSeparator() const
Definition Debugger.cpp:581
bool 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::raw_ostream &error_stream)
uint64_t GetStopDisassemblyMaxSize() const
Definition Debugger.cpp:386
bool SetTerminalHeight(uint64_t term_height)
Definition Debugger.cpp:487
Broadcaster m_sync_broadcaster
Private debugger synchronization.
Definition Debugger.h:803
friend class Statusline
Definition Debugger.h:662
bool GetUseSourceCache() const
Definition Debugger.cpp:642
HostThread m_io_handler_thread
Definition Debugger.h:802
llvm::StringRef GetRegexMatchAnsiSuffix() const
Definition Debugger.cpp:630
static llvm::StringRef GetStaticBroadcasterClass()
lldb::FileSP m_input_file_sp
Definition Debugger.h:757
const Broadcaster & GetBroadcaster() const
Definition Debugger.h:108
bool SetREPLLanguage(lldb::LanguageType repl_lang)
Definition Debugger.cpp:454
bool GetAutoIndent() const
Definition Debugger.cpp:732
llvm::StringRef GetStopShowColumnAnsiSuffix() const
Definition Debugger.cpp:682
Status SetPropertyValue(const ExecutionContext *exe_ctx, VarSetOperationType op, llvm::StringRef property_path, llvm::StringRef value) override
Definition Debugger.cpp:278
llvm::StringRef GetPromptAnsiSuffix() const
Definition Debugger.cpp:410
FormatEntity::Entry GetThreadStopFormat() const
Definition Debugger.cpp:432
void SetErrorFile(lldb::FileSP file)
bool GetAutoConfirm() const
Definition Debugger.cpp:365
TargetList m_target_list
Definition Debugger.h:769
lldb::ScriptLanguage GetScriptLanguage() const
Definition Debugger.cpp:437
lldb::callback_token_t m_destroy_callback_next_token
Definition Debugger.h:817
std::unique_ptr< SourceManager > m_source_manager_up
Definition Debugger.h:773
static lldb::DebuggerSP CreateInstance(lldb::LogOutputCallback log_callback=nullptr, void *baton=nullptr)
Definition Debugger.cpp:922
lldb::StopShowColumn GetStopShowColumn() const
Definition Debugger.cpp:669
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:749
bool SetScriptLanguage(lldb::ScriptLanguage script_lang)
Definition Debugger.cpp:444
lldb::LockableStreamFileSP m_error_stream_sp
Definition Debugger.h:759
bool SetShowInlineDiagnostics(bool)
Definition Debugger.cpp:778
const std::string & GetInstanceName() const
Definition Debugger.h:403
bool LoadPlugin(const FileSpec &spec, Status &error)
Definition Debugger.cpp:834
void SetOutputFile(lldb::FileSP file)
uint64_t GetStopSourceLineCount(bool before) const
Definition Debugger.cpp:700
bool SetStatuslineFormat(const FormatEntity::Entry &format)
Definition Debugger.cpp:574
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:226
Target & GetDummyTarget()
Definition Debugger.h:536
lldb::ListenerSP GetListener()
Definition Debugger.h:191
static void Destroy(lldb::DebuggerSP &debugger_sp)
Definition Debugger.cpp:966
SourceManager::SourceFileCache m_source_file_cache
Definition Debugger.h:777
llvm::StringRef GetPromptAnsiPrefix() const
Definition Debugger.cpp:404
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:688
bool GetShowDontUsePoHint() const
Definition Debugger.cpp:636
uint64_t GetTabSize() const
Definition Debugger.cpp:754
bool GetShowProgress() const
Definition Debugger.cpp:540
llvm::StringRef GetRegexMatchAnsiPrefix() const
Definition Debugger.cpp:624
std::mutex m_output_flush_mutex
Definition Debugger.h:752
llvm::StringRef GetStopShowLineMarkerAnsiSuffix() const
Definition Debugger.cpp:694
void PrintProgress(const ProgressEventData &data)
bool SetSeparator(llvm::StringRef s)
Definition Debugger.cpp:599
bool SetUseColor(bool use_color)
Definition Debugger.cpp:531
std::mutex m_statusline_mutex
Mutex protecting the m_statusline member.
Definition Debugger.h:792
const char * GetIOHandlerHelpPrologue()
Status SetInputString(const char *data)
bool GetUseAutosuggestion() const
Definition Debugger.cpp:606
friend class ProgressManager
Definition Debugger.h:661
Target & GetSelectedOrDummyTarget(bool prefer_dummy=false)
IOHandlerStack m_io_handler_stack
Definition Debugger.h:788
llvm::once_flag m_clear_once
Definition Debugger.h:806
static void SettingsTerminate()
Definition Debugger.cpp:832
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:449
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:465
Debugger(lldb::LogOutputCallback m_log_callback, void *baton)
llvm::StringRef GetExternalEditor() const
Definition Debugger.cpp:514
static size_t GetNumDebuggers()
FormatEntity::Entry GetThreadFormat() const
Definition Debugger.cpp:427
uint32_t m_interrupt_requested
Tracks interrupt requests.
Definition Debugger.h:830
lldb::DWIMPrintVerbosity GetDWIMPrintVerbosity() const
Definition Debugger.cpp:765
bool GetMarkHiddenFrames() const
Definition Debugger.cpp:657
lldb::BroadcasterManagerSP GetBroadcasterManager()
Definition Debugger.h:538
lldb::thread_result_t DefaultEventHandler()
void PrintAsync(const char *s, size_t len, bool is_stdout)
lldb::LockableStreamFileSP GetErrorStreamSP()
Definition Debugger.h:712
llvm::StringRef GetPrompt() const
Definition Debugger.cpp:398
bool GetNotifyVoid() const
Definition Debugger.cpp:392
llvm::StringRef GetShowProgressAnsiPrefix() const
Definition Debugger.cpp:551
void AdoptTopIOHandlerFilesIfInvalid(lldb::FileSP &in, lldb::LockableStreamFileSP &out, lldb::LockableStreamFileSP &err)
FormatEntity::Entry GetFrameFormat() const
Definition Debugger.cpp:376
lldb::StopDisassemblyType GetStopDisassemblyDisplay() const
Definition Debugger.cpp:707
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:738
const Debugger & operator=(const Debugger &)=delete
friend class CommandInterpreter
Definition Debugger.h:658
llvm::StringRef GetStopShowColumnAnsiPrefix() const
Definition Debugger.cpp:676
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 File.h:36
std::recursive_mutex Mutex
Definition StreamFile.h:77
A plug-in interface definition class for debugging a process.
Definition Process.h:355
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.
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:820
lldb_private::DebuggerDestroyCallback callback
Definition Debugger.h:825
void AppendSafeAutoLoadPaths(FileSpec path)
Appends a path to the testing.safe-auto-load-paths setting.
Definition Debugger.cpp:262
static TestingProperties & GetGlobalTestingProperties()
Definition Debugger.cpp:249
FileSpecList GetSafeAutoLoadPaths() const
Callers should use Debugger::GetSafeAutoLoadPaths since it accounts for default paths configured via ...
Definition Debugger.cpp:270
void SetSafeAutoLoadPaths(FileSpecList paths)
Overwrites the testing.safe-auto-load-paths settings.
Definition Debugger.cpp:254
UserID(lldb::user_id_t uid=LLDB_INVALID_UID)
Construct with optional user ID.
Definition UserID.h:33