Files
clang-r547379/include/lldb/Utility/Diagnostics.h
Ryan Prichard 6024e5c395 Update prebuilt Clang to r547379 (20.0.0).
clang 20.0.0 (based on r547379) from build 12806354.

Bug: http://b/379133546
Test: N/A
Change-Id: I2eb8938af55d809de674be63cb30cf27e801862b

Upstream-Commit: ad834e67b1105d15ef907f6255d4c96e8e733f57
2025-11-26 14:59:46 -05:00

87 lines
2.3 KiB
C++

//===-- Diagnostics.h -------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLDB_UTILITY_DIAGNOSTICS_H
#define LLDB_UTILITY_DIAGNOSTICS_H
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Log.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/Error.h"
#include <functional>
#include <mutex>
#include <optional>
#include <vector>
namespace lldb_private {
/// Diagnostics are a collection of files to help investigate bugs and
/// troubleshoot issues. Any part of the debugger can register itself with the
/// help of a callback to emit one or more files into the diagnostic directory.
class Diagnostics {
public:
Diagnostics();
~Diagnostics();
/// Gather diagnostics in the given directory.
llvm::Error Create(const FileSpec &dir);
/// Gather diagnostics and print a message to the given output stream.
/// @{
bool Dump(llvm::raw_ostream &stream);
bool Dump(llvm::raw_ostream &stream, const FileSpec &dir);
/// @}
void Report(llvm::StringRef message);
using Callback = std::function<llvm::Error(const FileSpec &)>;
using CallbackID = uint64_t;
CallbackID AddCallback(Callback callback);
void RemoveCallback(CallbackID id);
static Diagnostics &Instance();
static bool Enabled();
static void Initialize();
static void Terminate();
/// Create a unique diagnostic directory.
static llvm::Expected<FileSpec> CreateUniqueDirectory();
private:
static std::optional<Diagnostics> &InstanceImpl();
llvm::Error DumpDiangosticsLog(const FileSpec &dir) const;
RotatingLogHandler m_log_handler;
struct CallbackEntry {
CallbackEntry(CallbackID id, Callback callback)
: id(id), callback(std::move(callback)) {}
CallbackID id;
Callback callback;
};
/// Monotonically increasing callback identifier. Unique per Diagnostic
/// instance.
CallbackID m_callback_id;
/// List of callback entries.
llvm::SmallVector<CallbackEntry, 4> m_callbacks;
/// Mutex to protect callback list and callback identifier.
std::mutex m_callbacks_mutex;
};
} // namespace lldb_private
#endif