-
Notifications
You must be signed in to change notification settings - Fork 10.8k
/
Diagnostics.cpp
74 lines (59 loc) · 2.01 KB
/
Diagnostics.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//===-- Diagnostics.cpp ---------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "lldb/Utility/Diagnostics.h"
#include "lldb/Utility/LLDBAssert.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/raw_ostream.h"
using namespace lldb_private;
using namespace lldb;
using namespace llvm;
void Diagnostics::Initialize() {
lldbassert(!InstanceImpl() && "Already initialized.");
InstanceImpl().emplace();
}
void Diagnostics::Terminate() {
lldbassert(InstanceImpl() && "Already terminated.");
InstanceImpl().reset();
}
Optional<Diagnostics> &Diagnostics::InstanceImpl() {
static Optional<Diagnostics> g_diagnostics;
return g_diagnostics;
}
Diagnostics &Diagnostics::Instance() { return *InstanceImpl(); }
Diagnostics::Diagnostics() {}
Diagnostics::~Diagnostics() {}
void Diagnostics::AddCallback(Callback callback) {
std::lock_guard<std::mutex> guard(m_callbacks_mutex);
m_callbacks.push_back(callback);
}
bool Diagnostics::Dump(raw_ostream &stream) {
SmallString<128> diagnostics_dir;
std::error_code ec =
sys::fs::createUniqueDirectory("diagnostics", diagnostics_dir);
if (ec) {
stream << "unable to create diagnostic dir: "
<< toString(errorCodeToError(ec)) << '\n';
return false;
}
stream << "LLDB diagnostics written to " << diagnostics_dir << "\n";
stream << "Please include the directory content when filing a bug report\n";
Error error = Create(FileSpec(diagnostics_dir.str()));
if (error) {
stream << toString(std::move(error)) << '\n';
return false;
}
return true;
}
Error Diagnostics::Create(const FileSpec &dir) {
for (Callback c : m_callbacks) {
if (Error err = c(dir))
return err;
}
return Error::success();
}