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  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 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.
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 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
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)
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.

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 34 of file Diagnostics.h.

Constructor & Destructor Documentation

◆ Diagnostics()

Diagnostics::Diagnostics ( )

Definition at line 59 of file Diagnostics.cpp.

References g_num_log_messages, and m_log_handler.

Referenced by Instance().

◆ ~Diagnostics()

Diagnostics::~Diagnostics ( )

Definition at line 61 of file Diagnostics.cpp.

Member Function Documentation

◆ 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. 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 183 of file Diagnostics.cpp.

References lldb_private::Diagnostics::Report::attachments, CollectCommands(), CollectLogs(), CollectStatistics(), lldb_private::Diagnostics::Attachments::directory, lldb_private::Diagnostics::Attachments::files, 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().

◆ CollectCommands()

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

Definition at line 229 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 203 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 95 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 86 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 63 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()

bool Diagnostics::Enabled ( )
static

Definition at line 50 of file Diagnostics.cpp.

References InstanceImpl().

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

◆ GetHostDescription()

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

Scalars carried in the report rather than written as files.

Definition at line 244 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 40 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 52 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 112 of file Diagnostics.cpp.

References m_log_handler.

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

◆ Terminate()

void Diagnostics::Terminate ( )
static

Definition at line 45 of file Diagnostics.cpp.

References InstanceImpl(), and lldbassert.

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

Member Data Documentation

◆ m_log_handler

RotatingLogHandler lldb_private::Diagnostics::m_log_handler
private

Definition at line 115 of file Diagnostics.h.

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


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