[Lldb-commits] [lldb] include telemetry session-id in diagnostic msg when enabled (PR #135924)

Vy Nguyen via lldb-commits lldb-commits at lists.llvm.org
Wed Apr 16 00:12:16 PDT 2025


https://github.com/oontvoo created https://github.com/llvm/llvm-project/pull/135924

If LLDB crashes, it often helpful to know what the user was doing up to the point of the crash. Reporting the session-id helps us looking up the relevant logs.

(Given Telemetry is disabled upstream, this change should mostly be a no-op change)

>From 77e4045f5f48fb02237af45f1a12464ae218a168 Mon Sep 17 00:00:00 2001
From: Vy Nguyen <vyng at google.com>
Date: Wed, 16 Apr 2025 03:10:01 -0400
Subject: [PATCH] include telemetry session-id in diagnostic msg when enabled

---
 lldb/include/lldb/Core/Telemetry.h  |  2 ++
 lldb/source/Core/Telemetry.cpp      |  2 ++
 lldb/source/Utility/Diagnostics.cpp |  3 +++
 lldb/source/Utility/LLDBAssert.cpp  | 10 +++++++---
 4 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/lldb/include/lldb/Core/Telemetry.h b/lldb/include/lldb/Core/Telemetry.h
index fa01e2e4af90f..f21efe0a9c533 100644
--- a/lldb/include/lldb/Core/Telemetry.h
+++ b/lldb/include/lldb/Core/Telemetry.h
@@ -219,6 +219,8 @@ class TelemetryManager : public llvm::telemetry::Manager {
 
   virtual llvm::StringRef GetInstanceName() const = 0;
 
+  llvm::StringRef GetSessionId() const;
+
   static TelemetryManager *GetInstance();
 
 protected:
diff --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp
index 8db29889e0846..8497c4f866c18 100644
--- a/lldb/source/Core/Telemetry.cpp
+++ b/lldb/source/Core/Telemetry.cpp
@@ -112,6 +112,8 @@ llvm::Error TelemetryManager::preDispatch(TelemetryInfo *entry) {
   return llvm::Error::success();
 }
 
+llvm::StringRef TelemetryManager::GetSessionid() const { return m_id; }
+
 class NoOpTelemetryManager : public TelemetryManager {
 public:
   llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override {
diff --git a/lldb/source/Utility/Diagnostics.cpp b/lldb/source/Utility/Diagnostics.cpp
index b2a08165dd6ca..9c9e24bc9659f 100644
--- a/lldb/source/Utility/Diagnostics.cpp
+++ b/lldb/source/Utility/Diagnostics.cpp
@@ -70,6 +70,9 @@ bool Diagnostics::Dump(raw_ostream &stream) {
 bool Diagnostics::Dump(raw_ostream &stream, const FileSpec &dir) {
   stream << "LLDB diagnostics will be written to " << dir.GetPath() << "\n";
   stream << "Please include the directory content when filing a bug report\n";
+  TelemetryManager *manager = TelemetryManager::GetInstance();
+  if (manager->GetConfig()->EnableTelemetry)
+    stream << "Telemetry-SessionId: " << manager->GetSessionid() << "\n";
 
   if (Error error = Create(dir)) {
     stream << toString(std::move(error)) << '\n';
diff --git a/lldb/source/Utility/LLDBAssert.cpp b/lldb/source/Utility/LLDBAssert.cpp
index 611ad43cd071b..dc1e4d53031cc 100644
--- a/lldb/source/Utility/LLDBAssert.cpp
+++ b/lldb/source/Utility/LLDBAssert.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "lldb/Utility/LLDBAssert.h"
+#include "lldb/Core/Telemetry.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Signals.h"
@@ -51,11 +52,14 @@ void _lldb_assert(bool expression, const char *expr_text, const char *func,
     std::string buffer;
     llvm::raw_string_ostream backtrace(buffer);
     llvm::sys::PrintStackTrace(backtrace);
-
+    std::string extra_detail;
+    TelemetryManager *manager = TelemetryManager::GetInstance();
+    if (manager->GetConfig()->EnableTelemetry)
+      extra_detail = ". Telemetry-SessionId:" + manager->GetSessionId();
     (*g_lldb_assert_callback.load())(
         llvm::formatv(
-            "Assertion failed: ({0}), function {1}, file {2}, line {3}",
-            expr_text, func, file, line)
+            "Assertion failed: ({0}), function {1}, file {2}, line {3}{4}",
+            expr_text, func, file, line, extra_detail)
             .str(),
         buffer,
         "Please file a bug report against lldb and include the backtrace, the "



More information about the lldb-commits mailing list