9#ifndef LLDB_CORE_DEBUGGER_H
10#define LLDB_CORE_DEBUGGER_H
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"
60class ThreadPoolInterface;
65class CallbackLogHandler;
66class CommandInterpreter;
78class Debugger :
public std::enable_shared_from_this<Debugger>,
94 void *baton =
nullptr);
125 static void AssertCallback(llvm::StringRef message, llvm::StringRef backtrace,
126 llvm::StringRef prompt);
170 std::optional<lldb::ScriptLanguage> language = {});
217 bool cancel_top_handler =
true);
230 void PrintAsync(
const char *s,
size_t len,
bool is_stdout);
243 llvm::ArrayRef<const char *> categories,
244 llvm::StringRef log_file, uint32_t log_options,
246 llvm::raw_ostream &error_stream);
252 llvm::StringRef value)
override;
448 template <
typename...
Args>
454 formatv =
"Unknown message";
456 cur_func =
"<UNKNOWN>";
458 cur_func, llvm::formatv(formatv, std::forward<Args>(args)...)));
466#define INTERRUPT_REQUESTED(debugger, ...) \
467 (debugger).InterruptRequested(__func__, __VA_ARGS__)
482 const llvm::formatv_object_base &payload);
484 template <
typename...
Args>
489 llvm::formatv(format, std::forward<
Args>(args)...)) {}
497#define REPORT_INTERRUPTION(debugger, ...) \
498 (debugger).ReportInterruption( \
499 Debugger::InterruptionReport(__func__, __VA_ARGS__))
536 std::optional<lldb::user_id_t> debugger_id = std::nullopt,
537 std::once_flag *once =
nullptr);
558 std::optional<lldb::user_id_t> debugger_id = std::nullopt,
559 std::once_flag *once =
nullptr);
578 std::optional<lldb::user_id_t> debugger_id = std::nullopt,
579 std::once_flag *once =
nullptr);
664 ReportProgress(uint64_t progress_id, std::string title, std::string details,
665 uint64_t completed, uint64_t total,
666 std::optional<lldb::user_id_t> debugger_id,
670 std::optional<lldb::user_id_t> debugger_id,
671 std::once_flag *once);
688 bool cancel_top_handler =
true);
754 std::array<lldb::ScriptInterpreterSP, lldb::eScriptLanguageUnknown>
static llvm::raw_ostream & error(Stream &strm)
A section + offset based address class.
A command line argument class.
An event broadcasting class.
std::string m_function_name
const std::chrono::time_point< std::chrono::system_clock > m_interrupt_time
const uint64_t m_thread_id
InterruptionReport(std::string function_name, std::string description)
InterruptionReport(std::string function_name, const char *format, Args &&...args)
std::string m_description
static void AssertCallback(llvm::StringRef message, llvm::StringRef backtrace, llvm::StringRef prompt)
@ eBroadcastBitEventThreadIsListening
llvm::StringRef GetAutosuggestionAnsiPrefix() const
bool SetUseExternalEditor(bool use_external_editor_p)
PlatformList m_platform_list
HostThread m_event_handler_thread
static lldb::TargetSP FindTargetWithProcessID(lldb::pid_t pid)
FormatEntity::Entry GetDisassemblyFormat() const
uint64_t GetDisassemblyLineCount() const
lldb::TargetSP GetSelectedTarget()
llvm::StringRef GetDisabledAnsiSuffix() const
uint64_t GetTerminalHeight() const
lldb::LockableStreamFileSP m_output_stream_sp
bool SetExternalEditor(llvm::StringRef editor)
void RequestInterrupt()
Interruption in LLDB:
void ReportInterruption(const InterruptionReport &report)
ExecutionContext GetSelectedExecutionContext()
Get the execution context representing the selected entities in the selected target.
const std::string m_instance_name
lldb::ThreadSP HandleThreadEvent(const lldb::EventSP &event_sp)
void HandleProgressEvent(const lldb::EventSP &event_sp)
SourceManager & GetSourceManager()
bool SetShowProgress(bool show_progress)
bool StartEventHandlerThread()
Manually start the global event handler thread.
bool SetUseSourceCache(bool use_source_cache)
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)
HostThread SetIOHandlerThread(HostThread &new_thread)
SourceManager::SourceFileCache & GetSourceFileCache()
void CancelForwardEvents(const lldb::ListenerSP &listener_sp)
bool GetPrintDecls() const
lldb::FileSP GetInputFileSP()
void StopIOHandlerThread()
bool GetHighlightSource() const
llvm::StringMap< std::weak_ptr< LogHandler > > m_stream_handlers
CommandInterpreter & GetCommandInterpreter()
FormatEntity::Entry GetStatuslineFormat() const
void SaveInputTerminalState()
LoadedPluginsList m_loaded_plugins
bool GetShowInlineDiagnostics() const
void InstanceInitialize()
std::vector< llvm::sys::DynamicLibrary > LoadedPluginsList
Debugger(const Debugger &)=delete
bool SetTabSize(uint64_t tab_size)
bool IsHandlingEvents() const
void HandleDiagnosticEvent(const lldb::EventSP &event_sp)
bool StartIOHandlerThread()
static lldb::DebuggerSP GetDebuggerAtIndex(size_t index)
llvm::StringRef GetAutosuggestionAnsiSuffix() const
lldb::ListenerSP m_listener_sp
void PushIOHandler(const lldb::IOHandlerSP &reader_sp, bool cancel_top_handler=true)
std::mutex m_destroy_callback_mutex
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
std::optional< ProgressReport > GetCurrentProgressReport() const
static lldb::TargetSP FindTargetWithProcess(Process *process)
llvm::StringRef GetDisabledAnsiPrefix() const
bool GetUseExternalEditor() const
TerminalState m_terminal_state
lldb::StreamUP GetAsyncErrorStream()
TargetList & GetTargetList()
Get accessor for the target list.
bool InterruptRequested()
bool GetEscapeNonPrintables() const
lldb::TargetSP m_dummy_target_sp
llvm::SmallVector< DestroyCallbackInfo, 2 > m_destroy_callbacks
std::unique_ptr< CommandInterpreter > m_command_interpreter_up
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()
LockableStreamFile::Mutex m_output_mutex
static llvm::ThreadPoolInterface & GetThreadPool()
Shared thread pool. Use only with ThreadPoolTaskGroup.
llvm::StringRef GetShowProgressAnsiSuffix() const
bool IsTopIOHandler(const lldb::IOHandlerSP &reader_sp)
bool HasIOHandlerThread() const
void DispatchInputEndOfFile()
llvm::SmallVector< ProgressReport, 4 > m_progress_reports
Bookkeeping for command line progress events.
bool IsIOHandlerThreadCurrentThread() const
void DispatchClientTelemetry(const lldb_private::StructuredDataImpl &entry)
lldb::FileSP GetErrorFileSP()
std::mutex m_progress_reports_mutex
lldb::ProcessSP HandleProcessEvent(const lldb::EventSP &event_sp)
lldb::ListenerSP m_forward_listener_sp
std::array< lldb::ScriptInterpreterSP, lldb::eScriptLanguageUnknown > m_script_interpreters
std::shared_ptr< CallbackLogHandler > m_callback_handler_sp
void SetDestroyCallback(lldb_private::DebuggerDestroyCallback destroy_callback, void *baton)
DEPRECATED: We used to only support one Destroy callback.
lldb::FileSP GetOutputFileSP()
Broadcaster m_broadcaster
Public Debugger event broadcaster.
void DispatchInputInterrupt()
static void Initialize(LoadPluginCallbackType load_plugin_callback)
static lldb::DebuggerSP FindDebuggerWithInstanceName(llvm::StringRef instance_name)
uint64_t GetTerminalWidth() const
std::mutex m_interrupt_mutex
std::recursive_mutex m_io_handler_synchronous_mutex
bool InterruptRequested(const char *cur_func, const char *formatv, Args &&...args)
This is the correct way to query the state of Interruption.
bool RemoveIOHandler(const lldb::IOHandlerSP &reader_sp)
Remove the given IO handler if it's currently active.
Diagnostics::CallbackID m_diagnostics_callback_id
void SetPrompt(const char *)=delete
bool GetAutoOneLineSummaries() const
const char * GetIOHandlerCommandPrefix()
std::optional< Statusline > m_statusline
lldb::BroadcasterManagerSP m_broadcaster_manager_sp
Status RunREPL(lldb::LanguageType language, const char *repl_options)
bool PopIOHandler(const lldb::IOHandlerSP &reader_sp)
bool RemoveDestroyCallback(lldb::callback_token_t token)
Remove the specified callback. Return true if successful.
static LoadPluginCallbackType g_load_plugin_callback
bool GetShowStatusline() const
std::recursive_mutex m_script_interpreter_mutex
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...
void SetPrompt(llvm::StringRef p)
llvm::StringRef GetSeparator() const
bool StatuslineSupported()
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
bool SetTerminalHeight(uint64_t term_height)
Broadcaster m_sync_broadcaster
Private debugger synchronization.
void RestoreInputTerminalState()
bool GetUseSourceCache() const
HostThread m_io_handler_thread
llvm::StringRef GetRegexMatchAnsiSuffix() const
static llvm::StringRef GetStaticBroadcasterClass()
lldb::FileSP m_input_file_sp
const Broadcaster & GetBroadcaster() const
bool SetREPLLanguage(lldb::LanguageType repl_lang)
bool GetAutoIndent() const
llvm::StringRef GetStopShowColumnAnsiSuffix() const
Status SetPropertyValue(const ExecutionContext *exe_ctx, VarSetOperationType op, llvm::StringRef property_path, llvm::StringRef value) override
llvm::StringRef GetPromptAnsiSuffix() const
FormatEntity::Entry GetThreadStopFormat() const
void SetErrorFile(lldb::FileSP file)
bool GetAutoConfirm() const
lldb::ScriptLanguage GetScriptLanguage() const
lldb::callback_token_t m_destroy_callback_next_token
std::unique_ptr< SourceManager > m_source_manager_up
static lldb::DebuggerSP CreateInstance(lldb::LogOutputCallback log_callback=nullptr, void *baton=nullptr)
lldb::StopShowColumn GetStopShowColumn() const
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)
bool SetScriptLanguage(lldb::ScriptLanguage script_lang)
lldb::LockableStreamFileSP m_error_stream_sp
bool SetShowInlineDiagnostics(bool)
const std::string & GetInstanceName() const
bool LoadPlugin(const FileSpec &spec, Status &error)
void SetOutputFile(lldb::FileSP file)
uint64_t GetStopSourceLineCount(bool before) const
bool SetStatuslineFormat(const FormatEntity::Entry &format)
void EnableForwardEvents(const lldb::ListenerSP &listener_sp)
static lldb::DebuggerSP FindDebuggerWithID(lldb::user_id_t id)
void HandleBreakpointEvent(const lldb::EventSP &event_sp)
void JoinIOHandlerThread()
bool CheckTopIOHandlerTypes(IOHandler::Type top_type, IOHandler::Type second_top_type)
PlatformList & GetPlatformList()
Target & GetDummyTarget()
lldb::ListenerSP GetListener()
static void Destroy(lldb::DebuggerSP &debugger_sp)
SourceManager::SourceFileCache m_source_file_cache
ExecutionContextRef GetSelectedExecutionContextRef()
Similar to GetSelectedExecutionContext but returns a ExecutionContextRef, and will hold the dummy tar...
llvm::StringRef GetPromptAnsiPrefix() const
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.
llvm::StringRef GetStopShowLineMarkerAnsiPrefix() const
bool GetShowDontUsePoHint() const
uint64_t GetTabSize() const
bool GetShowProgress() const
llvm::StringRef GetRegexMatchAnsiPrefix() const
void HandleDestroyCallback()
std::mutex m_output_flush_mutex
llvm::StringRef GetStopShowLineMarkerAnsiSuffix() const
void PrintProgress(const ProgressEventData &data)
bool SetSeparator(llvm::StringRef s)
bool SetUseColor(bool use_color)
std::mutex m_statusline_mutex
Mutex protecting the m_statusline member.
const char * GetIOHandlerHelpPrologue()
Status SetInputString(const char *data)
bool GetUseAutosuggestion() const
friend class ProgressManager
Target & GetSelectedOrDummyTarget(bool prefer_dummy=false)
IOHandlerStack m_io_handler_stack
llvm::once_flag m_clear_once
static void SettingsTerminate()
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
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)
Debugger(lldb::LogOutputCallback m_log_callback, void *baton)
llvm::StringRef GetExternalEditor() const
static size_t GetNumDebuggers()
FormatEntity::Entry GetThreadFormat() const
uint32_t m_interrupt_requested
Tracks interrupt requests.
lldb::DWIMPrintVerbosity GetDWIMPrintVerbosity() const
lldb::BroadcasterManagerSP GetBroadcasterManager()
lldb::thread_result_t DefaultEventHandler()
void PrintAsync(const char *s, size_t len, bool is_stdout)
lldb::LockableStreamFileSP GetErrorStreamSP()
bool IsForwardingEvents()
llvm::StringRef GetPrompt() const
bool GetNotifyVoid() const
llvm::StringRef GetShowProgressAnsiPrefix() const
void AdoptTopIOHandlerFilesIfInvalid(lldb::FileSP &in, lldb::LockableStreamFileSP &out, lldb::LockableStreamFileSP &err)
FormatEntity::Entry GetFrameFormat() const
lldb::StopDisassemblyType GetStopDisassemblyDisplay() const
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
bool SetAutoIndent(bool b)
const Debugger & operator=(const Debugger &)=delete
friend class CommandInterpreter
llvm::StringRef GetStopShowColumnAnsiPrefix() const
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.
An abstract base class for files.
std::recursive_mutex Mutex
A plug-in interface definition class for debugging a process.
The SourceFileCache class separates the source manager from the cache of source files.
A stream class that can stream formatted output to a file.
Defines a symbol context baton that can be handed other debug core functions.
A RAII-friendly terminal state saving/restoring class.
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
std::shared_ptr< lldb_private::IOHandler > IOHandlerSP
std::shared_ptr< lldb_private::Thread > ThreadSP
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
std::shared_ptr< lldb_private::LockableStreamFile > LockableStreamFileSP
void(* LogOutputCallback)(const char *, void *baton)
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)
lldb_private::DebuggerDestroyCallback callback
lldb::callback_token_t token
UserID(lldb::user_id_t uid=LLDB_INVALID_UID)
Construct with optional user ID.