|
43 | 43 | #include "lldb/DataFormatters/DataVisualization.h" |
44 | 44 | #include "lldb/Host/Config.h" |
45 | 45 | #include "lldb/Host/StreamFile.h" |
| 46 | +#include "lldb/Core/Telemetry.h" |
46 | 47 | #include "lldb/Host/XML.h" |
47 | 48 | #include "lldb/Initialization/SystemLifetimeManager.h" |
48 | 49 | #include "lldb/Interpreter/CommandInterpreter.h" |
@@ -226,13 +227,45 @@ lldb::SBError SBDebugger::InitializeWithErrorHandling() { |
226 | 227 | return error; |
227 | 228 | } |
228 | 229 |
|
| 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 | + |
229 | 261 | void SBDebugger::PrintStackTraceOnError() { |
230 | 262 | LLDB_INSTRUMENT(); |
231 | 263 |
|
232 | 264 | llvm::EnablePrettyStackTrace(); |
233 | 265 | static std::string executable = |
234 | 266 | llvm::sys::fs::getMainExecutable(nullptr, nullptr); |
235 | 267 | llvm::sys::PrintStackTraceOnErrorSignal(executable); |
| 268 | + InstallCrashTelemetryReporter(); |
236 | 269 | } |
237 | 270 |
|
238 | 271 | static void DumpDiagnostics(void *cookie) { |
|
0 commit comments