LLDB mainline
lldb_private::Diagnostics Class Reference

Diagnostics maintain an always-on, in-memory log of recent diagnostic messages that can be written out to help investigate bugs and troubleshoot issues. More...

#include <Diagnostics.h>

Classes

struct  ArtifactProviderEntry
struct  Attachments
 The bundle directory and the files written into it, recorded as each one is created so a file that could not be written is simply absent. More...
struct  Report
 The state a triager needs to make sense of a bug report. More...

Public Types

using ArtifactProvider = std::function<std::string()>
 Supplies an artifact's contents on demand.
using ArtifactProviderID = uint64_t

Public Member Functions

 Diagnostics ()
 ~Diagnostics ()
llvm::Error Create (const FileSpec &dir)
 Write the in-memory diagnostic log into the given directory.
llvm::Expected< ReportCollect (Debugger &debugger, const ExecutionContext &exe_ctx, const FileSpec &dir)
 Collect a full diagnostics bundle into dir and return its report.
void Record (llvm::StringRef message)
 Record a diagnostic message into the always-on, in-memory log.
ArtifactProviderID AddArtifactProvider (std::string name, ArtifactProvider provider)
 Register provider to contribute file name.
void RemoveArtifactProvider (ArtifactProviderID id)
 Unregister a provider. Thread-safe.
bool Dump (llvm::raw_ostream &stream)
 Write the diagnostic log into a directory and print a message to the given output stream.
bool Dump (llvm::raw_ostream &stream, const FileSpec &dir)

Static Public Member Functions

static DiagnosticsInstance ()
static DiagnosticsPropertiesGetGlobalProperties ()
static bool Enabled ()
static void Initialize ()
static void Terminate ()
static llvm::Expected< FileSpecCreateUniqueDirectory ()
 Create a unique diagnostic directory.

Private Member Functions

llvm::Error DumpDiangosticsLog (const FileSpec &dir) const

Static Private Member Functions

static std::optional< Diagnostics > & InstanceImpl ()
static std::string GetHostDescription (const ExecutionContext &exe_ctx)
 Scalars carried in the report rather than written as files.
static std::string GetInvocation ()

Private Attributes

RotatingLogHandler m_log_handler
ArtifactProviderID m_next_artifact_provider_id = 0
 Registered artifact providers, guarded by the mutex.
std::vector< ArtifactProviderEntrym_artifact_providers
std::mutex m_artifact_providers_mutex
static void CollectStatistics (Debugger &debugger, const ExecutionContext &exe_ctx, const FileSpec &dir, std::vector< std::string > &files)
static void CollectCommands (Debugger &debugger, const ExecutionContext &exe_ctx, const FileSpec &dir, std::vector< std::string > &files)
static void CollectBinaries (const ExecutionContext &exe_ctx, const FileSpec &dir, std::vector< std::string > &files)
void CollectLogs (Debugger &debugger, const FileSpec &dir, std::vector< std::string > &files)
 Collect the individual parts of the bundle into dir, appending the name of each file to files as it is written.
void CollectArtifactProviders (const FileSpec &dir, std::vector< std::string > &files)

Detailed Description

Diagnostics maintain an always-on, in-memory log of recent diagnostic messages that can be written out to help investigate bugs and troubleshoot issues.

Definition at line 47 of file Diagnostics.h.

Member Typedef Documentation

◆ ArtifactProvider

using lldb_private::Diagnostics::ArtifactProvider = std::function<std::string()>

Supplies an artifact's contents on demand.

Subsystems register a provider so Core need not depend on them. Each runs when a bundle is collected.

Definition at line 97 of file Diagnostics.h.

◆ ArtifactProviderID

Definition at line 98 of file Diagnostics.h.

Constructor & Destructor Documentation

◆ Diagnostics()

Diagnostics::Diagnostics ( )

Definition at line 97 of file Diagnostics.cpp.

References g_num_log_messages, and m_log_handler.

Referenced by Instance().

◆ ~Diagnostics()

Diagnostics::~Diagnostics ( )

Definition at line 99 of file Diagnostics.cpp.

Member Function Documentation

◆ AddArtifactProvider()

Diagnostics::ArtifactProviderID Diagnostics::AddArtifactProvider ( std::string name,
ArtifactProvider provider )

Register provider to contribute file name.

Returns an id for RemoveArtifactProvider. Thread-safe.

Definition at line 155 of file Diagnostics.cpp.

References m_artifact_providers, m_artifact_providers_mutex, and m_next_artifact_provider_id.

Referenced by lldb_private::process_gdb_remote::ProcessGDBRemote::ProcessGDBRemote().

◆ Collect()

llvm::Expected< Diagnostics::Report > Diagnostics::Collect ( Debugger & debugger,
const ExecutionContext & exe_ctx,
const FileSpec & dir )

Collect a full diagnostics bundle into dir and return its report.

Writes the always-on log, the debugger's file-backed logs, statistics, and a snapshot of the commands a triager runs first. When the collect-binaries setting is enabled it also copies the executable, its symbol file, and the core file. Collection is best-effort: a failure to produce one artifact never aborts the rest, so a partial bundle is always better than none.

Definition at line 257 of file Diagnostics.cpp.

References lldb_private::Diagnostics::Report::attachments, CollectArtifactProviders(), CollectBinaries(), CollectCommands(), CollectLogs(), CollectStatistics(), lldb_private::Diagnostics::Attachments::directory, lldb_private::Diagnostics::Attachments::files, GetGlobalProperties(), GetHostDescription(), GetInvocation(), lldb_private::FileSpec::GetPath(), lldb_private::GetVersion(), lldb_private::Diagnostics::Report::invocation, lldb_private::Diagnostics::Report::os, and lldb_private::Diagnostics::Report::version.

Referenced by CommandObjectDiagnosticsDump::DoExecute(), and CommandObjectDiagnosticsReport::DoExecute().

◆ CollectArtifactProviders()

void Diagnostics::CollectArtifactProviders ( const FileSpec & dir,
std::vector< std::string > & files )
private

Definition at line 337 of file Diagnostics.cpp.

References m_artifact_providers, m_artifact_providers_mutex, and WriteArtifact().

Referenced by Collect().

◆ CollectBinaries()

void Diagnostics::CollectBinaries ( const ExecutionContext & exe_ctx,
const FileSpec & dir,
std::vector< std::string > & files )
staticprivate

◆ CollectCommands()

void Diagnostics::CollectCommands ( Debugger & debugger,
const ExecutionContext & exe_ctx,
const FileSpec & dir,
std::vector< std::string > & files )
staticprivate

Definition at line 306 of file Diagnostics.cpp.

References Available(), CaptureCommand(), g_triage_commands, and WriteArtifact().

Referenced by Collect().

◆ CollectLogs()

void Diagnostics::CollectLogs ( Debugger & debugger,
const FileSpec & dir,
std::vector< std::string > & files )
private

Collect the individual parts of the bundle into dir, appending the name of each file to files as it is written.

Definition at line 280 of file Diagnostics.cpp.

References lldb_private::Debugger::CopyLogFilesToDirectory(), Create(), and error().

Referenced by Collect().

◆ CollectStatistics()

void Diagnostics::CollectStatistics ( Debugger & debugger,
const ExecutionContext & exe_ctx,
const FileSpec & dir,
std::vector< std::string > & files )
staticprivate

◆ Create()

Error Diagnostics::Create ( const FileSpec & dir)

Write the in-memory diagnostic log into the given directory.

Definition at line 133 of file Diagnostics.cpp.

References DumpDiangosticsLog().

Referenced by CollectLogs(), and Dump().

◆ CreateUniqueDirectory()

llvm::Expected< FileSpec > Diagnostics::CreateUniqueDirectory ( )
static

Create a unique diagnostic directory.

Definition at line 124 of file Diagnostics.cpp.

Referenced by Dump(), CommandObjectDiagnosticsDump::GetDirectory(), and CommandObjectDiagnosticsReport::GetDirectory().

◆ Dump() [1/2]

bool Diagnostics::Dump ( llvm::raw_ostream & stream)

Write the diagnostic log into a directory and print a message to the given output stream.

Definition at line 101 of file Diagnostics.cpp.

References CreateUniqueDirectory(), Dump(), and lldb_private::toString().

Referenced by Dump(), and DumpDiagnostics().

◆ Dump() [2/2]

bool Diagnostics::Dump ( llvm::raw_ostream & stream,
const FileSpec & dir )

◆ DumpDiangosticsLog()

llvm::Error Diagnostics::DumpDiangosticsLog ( const FileSpec & dir) const
private

◆ Enabled()

◆ GetGlobalProperties()

DiagnosticsProperties & Diagnostics::GetGlobalProperties ( )
static

Definition at line 71 of file Diagnostics.cpp.

Referenced by Collect(), and lldb_private::Debugger::Debugger().

◆ GetHostDescription()

std::string Diagnostics::GetHostDescription ( const ExecutionContext & exe_ctx)
staticprivate

Scalars carried in the report rather than written as files.

Definition at line 350 of file Diagnostics.cpp.

References lldb_private::Target::GetPlatform(), and lldb_private::ExecutionContext::GetTargetPtr().

Referenced by Collect().

◆ GetInvocation()

◆ Initialize()

void Diagnostics::Initialize ( )
static

Definition at line 78 of file Diagnostics.cpp.

References InstanceImpl(), and lldbassert.

Referenced by lldb_private::SystemInitializerCommon::Initialize().

◆ Instance()

◆ InstanceImpl()

std::optional< Diagnostics > & Diagnostics::InstanceImpl ( )
staticprivate

Definition at line 90 of file Diagnostics.cpp.

Referenced by Enabled(), Initialize(), Instance(), and Terminate().

◆ Record()

void Diagnostics::Record ( llvm::StringRef message)

Record a diagnostic message into the always-on, in-memory log.

Definition at line 150 of file Diagnostics.cpp.

References m_log_handler.

Referenced by lldb_private::Debugger::ReportDiagnosticImpl().

◆ RemoveArtifactProvider()

void Diagnostics::RemoveArtifactProvider ( ArtifactProviderID id)

◆ Terminate()

void Diagnostics::Terminate ( )
static

Definition at line 83 of file Diagnostics.cpp.

References InstanceImpl(), and lldbassert.

Referenced by lldb_private::SystemInitializerCommon::Terminate().

Member Data Documentation

◆ m_artifact_providers

std::vector<ArtifactProviderEntry> lldb_private::Diagnostics::m_artifact_providers
private

◆ m_artifact_providers_mutex

std::mutex lldb_private::Diagnostics::m_artifact_providers_mutex
private

◆ m_log_handler

RotatingLogHandler lldb_private::Diagnostics::m_log_handler
private

Definition at line 150 of file Diagnostics.h.

Referenced by Diagnostics(), DumpDiangosticsLog(), and Record().

◆ m_next_artifact_provider_id

ArtifactProviderID lldb_private::Diagnostics::m_next_artifact_provider_id = 0
private

Registered artifact providers, guarded by the mutex.

Definition at line 160 of file Diagnostics.h.

Referenced by AddArtifactProvider().


The documentation for this class was generated from the following files: