[Lldb-commits] [lldb] Define Telemetry plugin for LLDB. (PR #126588)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Thu Feb 13 08:54:42 PST 2025
================
@@ -0,0 +1,34 @@
+//===-- TestFakePlugin.cpp ------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Core/PluginInterface.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/Telemetry.h"
+#include "plugin/FakePlugin.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Telemetry/Telemetry.h"
+#include "gtest/gtest.h"
+
+#include <memory>
+
+TEST(TelemetryTest, PluginTest) {
+ // This would have been called by the plugin reg in a "real" plugin
+ // For tests, we just call it directly.
+ lldb_private::FakePlugin::Initialize();
+
+ auto ins = lldb_private::telemetry::TelemetryManager::getInstance();
+
+ ASSERT_NE(ins, nullptr);
+ lldb_private::FakeTelemetryInfo entry;
+ entry.msg = "";
+
+ auto stat = ins->preDispatch(&entry);
----------------
labath wrote:
> the preDispatch() should be at least accessible by the subclasses
That's ok, but there's big a [difference](https://godbolt.org/z/33Pqbczxs) between "begin able to access (call) a method" and "being able to override a method". C++ methods are always overridable. Access specifiers only control accessibility. So you don't need to make it public if all you want is overridability (customizability of behavior).
> And the preDispatch() was a way to let the subclasses have a chance to add or remove data from the entries before them being sent off
That makes sense, but then I also wonder why is `dispatch` virtual, because `preDispatch` is basically equivalent to overriding `dispatch` to do the custom thing and then delegate to base class. There is actually a school of OO design which says that public methods should never be virtual (the idea is to separate the "interface for the outside world (users)" from the "interface for inheritance"). I'm not saying we're particularly strong adherents of this philosophy, but this (pre)dispatch certainly looks like it was taken from one of their books.
https://github.com/llvm/llvm-project/pull/126588
More information about the lldb-commits
mailing list