Skip to content

Commit d7b1275

Browse files
committed
try reporting the crash from a crash handler
1 parent 7ad8360 commit d7b1275

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

lldb/source/API/SBDebugger.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "lldb/DataFormatters/DataVisualization.h"
4444
#include "lldb/Host/Config.h"
4545
#include "lldb/Host/StreamFile.h"
46+
#include "lldb/Core/Telemetry.h"
4647
#include "lldb/Host/XML.h"
4748
#include "lldb/Initialization/SystemLifetimeManager.h"
4849
#include "lldb/Interpreter/CommandInterpreter.h"
@@ -226,13 +227,45 @@ lldb::SBError SBDebugger::InitializeWithErrorHandling() {
226227
return error;
227228
}
228229

230+
#if LLVM_ENABLE_TELEMETRY
231+
#if ENABLE_BACKTRACES
232+
static void TelemetryHandler(void *) {
233+
// TODO: get the bt into the msg?
234+
// Also need to pre-alloc the memory for this entry?
235+
lldb_private::telemetry::DebuggerInfo entry;
236+
entry.exit_desc = {-1, ""};
237+
if (auto* instance = lldb_private::telemetry::TelemeryManager::getInstance()) {
238+
if (instance->GetConfig()->EnableTelemetry()) {
239+
instance->AtDebuggerExit(&entry);
240+
}
241+
}
242+
}
243+
244+
static bool RegisterTelemetryHander() {
245+
sys::AddSignalHandler(TelemetryHandler, nullptr);
246+
return false;
247+
}
248+
#endif
249+
#endif
250+
251+
static void InstallCrashTelemetryReporter() {
252+
#if LLVM_ENABLE_TELEMETRY
253+
254+
#if ENABLE_BACKTRACES
255+
static bool HandlerRegistered = RegisterTelemeryHandler();
256+
(void)HandlerRegistered;
257+
#endif
258+
#endif
259+
}
260+
229261
void SBDebugger::PrintStackTraceOnError() {
230262
LLDB_INSTRUMENT();
231263

232264
llvm::EnablePrettyStackTrace();
233265
static std::string executable =
234266
llvm::sys::fs::getMainExecutable(nullptr, nullptr);
235267
llvm::sys::PrintStackTraceOnErrorSignal(executable);
268+
InstallCrashTelemetryReporter();
236269
}
237270

238271
static void DumpDiagnostics(void *cookie) {

0 commit comments

Comments
 (0)