12#include "llvm/Support/Error.h"
13#include "llvm/Support/FileSystem.h"
14#include "llvm/Support/raw_ostream.h"
36 static std::optional<Diagnostics> g_diagnostics;
61 if (!diagnostics_dir) {
62 stream <<
"unable to create diagnostic dir: "
63 <<
toString(diagnostics_dir.takeError()) <<
'\n';
67 return Dump(stream, *diagnostics_dir);
71 stream <<
"LLDB diagnostics will be written to " << dir.
GetPath() <<
"\n";
72 stream <<
"Please include the directory content when filing a bug report\n";
83 SmallString<128> diagnostics_dir;
85 sys::fs::createUniqueDirectory(
"diagnostics", diagnostics_dir);
87 return errorCodeToError(ec);
88 return FileSpec(diagnostics_dir.str());
96 if (
Error err = e.callback(dir))
100 return Error::success();
106 llvm::raw_fd_ostream stream(log_file.
GetPath(), ec, llvm::sys::fs::OF_None);
108 return errorCodeToError(ec);
110 return Error::success();
static llvm::raw_ostream & error(Stream &strm)
static constexpr size_t g_num_log_messages
Diagnostics are a collection of files to help investigate bugs and troubleshoot issues.
RotatingLogHandler m_log_handler
bool Dump(llvm::raw_ostream &stream)
Gather diagnostics and print a message to the given output stream.
CallbackID AddCallback(Callback callback)
void Report(llvm::StringRef message)
llvm::Error DumpDiangosticsLog(const FileSpec &dir) const
llvm::SmallVector< CallbackEntry, 4 > m_callbacks
List of callback entries.
llvm::Error Create(const FileSpec &dir)
Gather diagnostics in the given directory.
CallbackID m_callback_id
Monotonically increasing callback identifier.
std::mutex m_callbacks_mutex
Mutex to protect callback list and callback identifier.
static llvm::Expected< FileSpec > CreateUniqueDirectory()
Create a unique diagnostic directory.
static std::optional< Diagnostics > & InstanceImpl()
std::function< llvm::Error(const FileSpec &)> Callback
void RemoveCallback(CallbackID id)
static Diagnostics & Instance()
FileSpec CopyByAppendingPathComponent(llvm::StringRef component) const
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
void Dump(llvm::raw_ostream &stream) const
void Emit(llvm::StringRef message) override
A class that represents a running process on the host machine.
const char * toString(AppleArm64ExceptionClass EC)