9#ifndef LLDB_CORE_DEBUGGER_H
10#define LLDB_CORE_DEBUGGER_H
42#include "llvm/ADT/ArrayRef.h"
43#include "llvm/ADT/SmallVector.h"
44#include "llvm/ADT/StringMap.h"
45#include "llvm/ADT/StringRef.h"
46#include "llvm/Support/DynamicLibrary.h"
47#include "llvm/Support/FormatVariadic.h"
48#include "llvm/Support/Threading.h"
56class ThreadPoolInterface;
61class CallbackLogHandler;
62class 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);
175 std::optional<lldb::ScriptLanguage> language = {});
214 bool cancel_top_handler =
true);
227 void PrintAsync(
const char *s,
size_t len,
bool is_stdout);
238 llvm::ArrayRef<const char *> categories,
239 llvm::StringRef log_file, uint32_t log_options,
241 llvm::raw_ostream &error_stream);
255 llvm::StringRef value)
override;
428 template <
typename...
Args>
434 formatv =
"Unknown message";
436 cur_func =
"<UNKNOWN>";
438 cur_func, llvm::formatv(formatv, std::forward<Args>(args)...)));
446#define INTERRUPT_REQUESTED(debugger, ...) \
447 (debugger).InterruptRequested(__func__, __VA_ARGS__)
462 const llvm::formatv_object_base &payload);
464 template <
typename...
Args>
469 llvm::formatv(format, std::forward<
Args>(args)...)) {}
477#define REPORT_INTERRUPTION(debugger, ...) \
478 (debugger).ReportInterruption( \
479 Debugger::InterruptionReport(__func__, __VA_ARGS__))
516 std::optional<lldb::user_id_t> debugger_id = std::nullopt,
517 std::once_flag *once =
nullptr);
538 std::optional<lldb::user_id_t> debugger_id = std::nullopt,
539 std::once_flag *once =
nullptr);
558 std::optional<lldb::user_id_t> debugger_id = std::nullopt,
559 std::once_flag *once =
nullptr);
635 ReportProgress(uint64_t progress_id, std::string title, std::string details,
636 uint64_t completed, uint64_t total,
637 std::optional<lldb::user_id_t> debugger_id,
641 std::optional<lldb::user_id_t> debugger_id,
642 std::once_flag *once);
649 bool cancel_top_handler =
true);
717 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
A class to manage flag bits.
static void AssertCallback(llvm::StringRef message, llvm::StringRef backtrace, llvm::StringRef prompt)
llvm::StringRef GetAutosuggestionAnsiPrefix() const
repro::DataRecorder * GetInputRecorder()
lldb::StreamFileSP m_error_stream_sp
@ eBroadcastBitEventThreadIsListening
bool SetUseExternalEditor(bool use_external_editor_p)
PlatformList m_platform_list
HostThread m_event_handler_thread
static lldb::TargetSP FindTargetWithProcessID(lldb::pid_t pid)
uint64_t GetDisassemblyLineCount() const
lldb::TargetSP GetSelectedTarget()
bool SetExternalEditor(llvm::StringRef editor)
void RequestInterrupt()
Interruption in LLDB:
void ReportInterruption(const InterruptionReport &report)
StreamFile & GetOutputStream()
ExecutionContext GetSelectedExecutionContext()
const std::string m_instance_name
void HandleProgressEvent(const lldb::EventSP &event_sp)
SourceManager & GetSourceManager()
bool SetShowProgress(bool show_progress)
lldb::StreamSP GetAsyncOutputStream()
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()
void SaveInputTerminalState()
LoadedPluginsList m_loaded_plugins
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
StreamFile & GetErrorStream()
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()
static lldb::TargetSP FindTargetWithProcess(Process *process)
bool GetUseExternalEditor() const
TerminalState m_terminal_state
const FormatEntity::Entry * GetThreadStopFormat() const
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()
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()
bool IsIOHandlerThreadCurrentThread() const
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.
StopDisassemblyType GetStopDisassemblyDisplay() const
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()
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
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::StreamFileSP GetErrorStreamSP()
void SetPrompt(llvm::StringRef p)
lldb::StreamSP GetAsyncErrorStream()
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
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)
const FormatEntity::Entry * GetDisassemblyFormat() const
bool GetAutoIndent() const
llvm::StringRef GetStopShowColumnAnsiSuffix() const
@ eStopDisassemblyTypeNever
@ eStopDisassemblyTypeNoDebugInfo
@ eStopDisassemblyTypeNoSource
@ eStopDisassemblyTypeAlways
Status SetPropertyValue(const ExecutionContext *exe_ctx, VarSetOperationType op, llvm::StringRef property_path, llvm::StringRef value) override
llvm::StringRef GetPromptAnsiSuffix() 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)
bool LoadPlugin(const FileSpec &spec, Status &error)
void SetOutputFile(lldb::FileSP file)
uint64_t GetStopSourceLineCount(bool before) const
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()
const FormatEntity::Entry * GetFrameFormat() const
lldb::ListenerSP GetListener()
static void Destroy(lldb::DebuggerSP &debugger_sp)
SourceManager::SourceFileCache m_source_file_cache
llvm::StringRef GetPromptAnsiPrefix() const
std::optional< uint64_t > m_current_event_id
void RunIOHandlerSync(const lldb::IOHandlerSP &reader_sp)
Run the given IO handler and block until it's complete.
const FormatEntity::Entry * GetThreadFormat() const
Broadcaster & GetBroadcaster()
Get the public broadcaster for this debugger.
llvm::StringRef GetStopShowLineMarkerAnsiPrefix() const
bool GetShowDontUsePoHint() const
uint64_t GetTabSize() const
lldb::StreamFileSP m_output_stream_sp
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 SetUseColor(bool use_color)
const char * GetIOHandlerHelpPrologue()
Status SetInputString(const char *data)
bool GetUseAutosuggestion() const
Target & GetSelectedOrDummyTarget(bool prefer_dummy=false)
void HandleProcessEvent(const lldb::EventSP &event_sp)
IOHandlerStack m_io_handler_stack
repro::DataRecorder * m_input_recorder
Used for shadowing the input file when capturing a reproducer.
lldb::StreamFileSP GetOutputStreamSP()
llvm::once_flag m_clear_once
void AdoptTopIOHandlerFilesIfInvalid(lldb::FileSP &in, lldb::StreamFileSP &out, lldb::StreamFileSP &err)
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)
llvm::StringRef GetExternalEditor() const
void HandleThreadEvent(const lldb::EventSP &event_sp)
static size_t GetNumDebuggers()
uint32_t m_interrupt_requested
Tracks interrupt requests.
lldb::DWIMPrintVerbosity GetDWIMPrintVerbosity() const
const std::string & GetInstanceName()
lldb::BroadcasterManagerSP GetBroadcasterManager()
lldb::thread_result_t DefaultEventHandler()
void PrintAsync(const char *s, size_t len, bool is_stdout)
bool IsForwardingEvents()
llvm::StringRef GetPrompt() const
bool GetNotifyVoid() const
llvm::StringRef GetShowProgressAnsiPrefix() const
const FormatEntity::Entry * GetFrameFormatUnique() 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
llvm::StringRef GetStopShowColumnAnsiPrefix() const
static DebuggerList DebuggersRequestingInterruption()
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
An abstract base class for files.
A plug-in interface definition class for debugging a process.
A class used to group progress reports by category.
A Progress indicator helper class.
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.
lldb::TargetSP GetSelectedTarget()
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
DWIMPrintVerbosity
Enum to control the verbosity level of dwim-print execution.
LanguageType
Programming language type.
std::shared_ptr< lldb_private::Stream > StreamSP
std::shared_ptr< lldb_private::Debugger > DebuggerSP
std::shared_ptr< lldb_private::Event > EventSP
std::shared_ptr< lldb_private::Listener > ListenerSP
std::shared_ptr< lldb_private::StreamFile > StreamFileSP
void(* LogOutputCallback)(const char *, void *baton)
std::shared_ptr< lldb_private::Target > TargetSP
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
A mix in class that contains a generic user ID.