[Lldb-commits] [lldb] 1cc5657 - [lldb-dap] Create telemetry data only when built with telemetry. (#225785)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Sep 25 01:51:08 PDT 2026
Author: Ebuka Ezike
Date: 2026-09-25T09:51:00+01:00
New Revision: 1cc5657c4ff663f1284d8a4ba4ef156e4b1664ae
URL: https://github.com/llvm/llvm-project/commit/1cc5657c4ff663f1284d8a4ba4ef156e4b1664ae
DIFF: https://github.com/llvm/llvm-project/commit/1cc5657c4ff663f1284d8a4ba4ef156e4b1664ae.diff
LOG: [lldb-dap] Create telemetry data only when built with telemetry. (#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.
Added:
Modified:
lldb/tools/lldb-dap/DAP.cpp
lldb/tools/lldb-dap/LLDBUtils.h
Removed:
################################################################################
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index cb87c314e4665..dda56e87b68d1 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 30882b75fa359..1c48c6f72d240 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