LLDB mainline
Diagnostics.h
Go to the documentation of this file.
1//===-- Diagnostics.h -------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_UTILITY_DIAGNOSTICS_H
10#define LLDB_UTILITY_DIAGNOSTICS_H
11
13#include "lldb/Utility/Log.h"
14#include "llvm/ADT/SmallVector.h"
15#include "llvm/ADT/StringSet.h"
16#include "llvm/Support/Error.h"
17
18#include <functional>
19#include <mutex>
20#include <optional>
21#include <vector>
22
23namespace lldb_private {
24
25/// Diagnostics are a collection of files to help investigate bugs and
26/// troubleshoot issues. Any part of the debugger can register itself with the
27/// help of a callback to emit one or more files into the diagnostic directory.
29public:
32
33 /// Gather diagnostics in the given directory.
34 llvm::Error Create(const FileSpec &dir);
35
36 /// Gather diagnostics and print a message to the given output stream.
37 /// @{
38 bool Dump(llvm::raw_ostream &stream);
39 bool Dump(llvm::raw_ostream &stream, const FileSpec &dir);
40 /// @}
41
42 void Report(llvm::StringRef message);
43
44 using Callback = std::function<llvm::Error(const FileSpec &)>;
45 using CallbackID = uint64_t;
46
49
50 static Diagnostics &Instance();
51
52 static bool Enabled();
53 static void Initialize();
54 static void Terminate();
55
56 /// Create a unique diagnostic directory.
57 static llvm::Expected<FileSpec> CreateUniqueDirectory();
58
59private:
60 static std::optional<Diagnostics> &InstanceImpl();
61
62 llvm::Error DumpDiangosticsLog(const FileSpec &dir) const;
63
65
68 : id(id), callback(std::move(callback)) {}
71 };
72
73 /// Monotonically increasing callback identifier. Unique per Diagnostic
74 /// instance.
76
77 /// List of callback entries.
78 llvm::SmallVector<CallbackEntry, 4> m_callbacks;
79
80 /// Mutex to protect callback list and callback identifier.
82};
83
84} // namespace lldb_private
85
86#endif
Diagnostics are a collection of files to help investigate bugs and troubleshoot issues.
Definition: Diagnostics.h:28
RotatingLogHandler m_log_handler
Definition: Diagnostics.h:64
bool Dump(llvm::raw_ostream &stream)
Gather diagnostics and print a message to the given output stream.
Definition: Diagnostics.cpp:59
CallbackID AddCallback(Callback callback)
Definition: Diagnostics.cpp:46
void Report(llvm::StringRef message)
llvm::Error DumpDiangosticsLog(const FileSpec &dir) const
llvm::SmallVector< CallbackEntry, 4 > m_callbacks
List of callback entries.
Definition: Diagnostics.h:78
llvm::Error Create(const FileSpec &dir)
Gather diagnostics in the given directory.
Definition: Diagnostics.cpp:91
CallbackID m_callback_id
Monotonically increasing callback identifier.
Definition: Diagnostics.h:75
std::mutex m_callbacks_mutex
Mutex to protect callback list and callback identifier.
Definition: Diagnostics.h:81
static llvm::Expected< FileSpec > CreateUniqueDirectory()
Create a unique diagnostic directory.
Definition: Diagnostics.cpp:82
static std::optional< Diagnostics > & InstanceImpl()
Definition: Diagnostics.cpp:35
std::function< llvm::Error(const FileSpec &)> Callback
Definition: Diagnostics.h:44
void RemoveCallback(CallbackID id)
Definition: Diagnostics.cpp:53
static Diagnostics & Instance()
Definition: Diagnostics.cpp:40
A file utility class.
Definition: FileSpec.h:56
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
CallbackEntry(CallbackID id, Callback callback)
Definition: Diagnostics.h:67