[Lldb-commits] [lldb] [LLDB][Telemetry]Define DebuggerTelemetryInfo and related methods (PR #127696)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed Feb 19 01:58:01 PST 2025


================
@@ -56,13 +60,83 @@ struct LLDBBaseTelemetryInfo : public llvm::telemetry::TelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
+/// Describes the exit status of a debugger.
+struct ExitDescription {
+  int exit_code;
+  std::string description;
+};
+
+struct DebuggerTelemetryInfo : public LLDBBaseTelemetryInfo {
+  std::string username;
+  std::string lldb_git_sha;
+  std::string lldb_path;
+  std::string cwd;
+  std::optional<ExitDescription> exit_desc;
+
+  DebuggerTelemetryInfo() = default;
+
+  // Provide a copy ctor because we may need to make a copy before
+  // sanitizing the data.
+  // (The sanitization might differ between different Destination classes).
----------------
labath wrote:

That makes sense to me, but it doesn't explain why we need to spell out the copying by hand. It's very easy to forget to update it (and it looks like even this implementation does not copy entries from the base class).

I thought this had something to do with this being being a polymorphic class (which usually have their copy constructors deleted -- for a reason), but AFAICT, all of the bases actually have their copy constructors (implicitly) defined. The possibility of object slicing is another complaint I have about this design (and I'm surprised it doesn't trigger any static analysis warnings).

In order to prevent object slicing, and avoid spelling out copy operations, how about we do something like [this](https://godbolt.org/z/GT591beeY). Basically, divide the two classes in the hierarchy into two kinds:
- abstract classes: these cannot be instantiated, so there's no danger of slicing. They still have a copy constructor, but they cannot be copied on their own.
- concrete final classes: these can be copied (using the default copy constructor implementation). However, they cannot be inherited from, which means they cannot slice anything.

https://github.com/llvm/llvm-project/pull/127696


More information about the lldb-commits mailing list