[Lldb-commits] [lldb] [lldb-dap] Create telemetry data only when built with telemetry. (PR #225785)
Ebuka Ezike via lldb-commits
lldb-commits at lists.llvm.org
Wed Sep 23 07:03:27 PDT 2026
https://github.com/da-viper created https://github.com/llvm/llvm-project/pull/225785
I am exploring fuzzing some parts of lldb-dap. but there is a fixed amount of memory lldb-dap can use before the fuzzing stops to catch memory leaks.
The telemetry dispatcher always creates telemetry regardless of if lldb is built with telemetry enabled.
`SBStructuredData::SetFromJSON` adds the telemetry string to the ConstString pool for every request and grows lldb-dap's memory usage rapidly.
>From ad1fcf389063694a07f49dcb88f9f64c39739f18 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <e_ezike at apple.com>
Date: Sat, 19 Sep 2026 13:04:26 +0100
Subject: [PATCH] [lldb-dap] Log telemetry only when built with telemetry.
I am exploring fuzzing some parts of lldb-dap. but there is a fixed
amount of memory lldb-dap can use before the fuzzing stops to catch
memory leaks.
The telemetry dispatcher always creates telemetry regardless of if
lldb is built with telemetry enabled.
`SBStructuredData::SetFromJSON` adds the telemetry string to the
ConstString pool for every request and grows lldb-dap's memory usage
rapidly.
---
lldb/tools/lldb-dap/DAP.cpp | 4 ++--
lldb/tools/lldb-dap/LLDBUtils.h | 34 +++++++++++++++++++++------------
2 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index cb87c314e46658..dda56e87b68d18 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -693,7 +693,7 @@ void DAP::SetTarget(const lldb::SBTarget target) { this->target = target; }
bool DAP::HandleObject(const Message &M) {
TelemetryDispatcher dispatcher(&debugger);
- dispatcher.Set("client_name", m_client_name.str());
+ dispatcher.Set("client_name", m_client_name);
if (const auto *req = std::get_if<Request>(&M)) {
{
std::lock_guard<std::mutex> guard(m_active_request_mutex);
@@ -759,7 +759,7 @@ bool DAP::HandleObject(const Message &M) {
}),
*resp->message);
}
- dispatcher.Set("error", message.str());
+ dispatcher.Set("error", message);
(*response_handler)(llvm::createStringError(
std::error_code(-1, std::generic_category()), message));
diff --git a/lldb/tools/lldb-dap/LLDBUtils.h b/lldb/tools/lldb-dap/LLDBUtils.h
index 30882b75fa3596..1c48c6f72d2400 100644
--- a/lldb/tools/lldb-dap/LLDBUtils.h
+++ b/lldb/tools/lldb-dap/LLDBUtils.h
@@ -23,8 +23,10 @@
#include "llvm/Support/JSON.h"
#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/Telemetry/Telemetry.h"
#include <chrono>
#include <string>
+#include <utility>
namespace lldb_dap {
@@ -139,26 +141,22 @@ std::string GetSBFileSpecPath(const lldb::SBFileSpec &file_spec);
lldb::SBLineEntry GetLineEntryForAddress(lldb::SBTarget &target,
const lldb::SBAddress &address);
-/// Helper for sending telemetry to lldb server, if client-telemetry is enabled.
-class TelemetryDispatcher {
+namespace detail {
+
+template <bool Enabled = llvm::telemetry::Config::BuildTimeEnableTelemetry>
+class TelemetryDispatcherImpl {
public:
- TelemetryDispatcher(lldb::SBDebugger *debugger) {
- m_telemetry_json = llvm::json::Object();
+ TelemetryDispatcherImpl(lldb::SBDebugger *debugger) : debugger(debugger) {
m_telemetry_json.try_emplace(
"start_time",
std::chrono::steady_clock::now().time_since_epoch().count());
- this->debugger = debugger;
- }
-
- void Set(std::string key, std::string value) {
- m_telemetry_json.try_emplace(key, value);
}
- void Set(std::string key, int64_t value) {
- m_telemetry_json.try_emplace(key, value);
+ template <typename T> void Set(llvm::StringRef key, T &&value) {
+ m_telemetry_json.try_emplace(key, std::forward<T>(value));
}
- ~TelemetryDispatcher() {
+ ~TelemetryDispatcherImpl() {
m_telemetry_json.try_emplace(
"end_time",
std::chrono::steady_clock::now().time_since_epoch().count());
@@ -176,6 +174,18 @@ class TelemetryDispatcher {
lldb::SBDebugger *debugger;
};
+template <> class TelemetryDispatcherImpl<false> {
+public:
+ TelemetryDispatcherImpl(lldb::SBDebugger *) {}
+ template <typename T> void Set(llvm::StringRef, T &&) {}
+};
+
+} // namespace detail
+
+/// Helper for sending telemetry to lldb server, if built with telemetry and
+/// client-telemetry is enabled.
+using TelemetryDispatcher = detail::TelemetryDispatcherImpl<>;
+
/// RAII utility to put the debugger temporarily into synchronous mode.
class ScopeSyncMode {
public:
More information about the lldb-commits
mailing list