[Lldb-commits] [lldb] d77e3c6 - [lldb][NFC] Don't inherit from UserID in ValueObject

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Tue Feb 23 01:16:09 PST 2021


Author: Raphael Isemann
Date: 2021-02-23T10:15:42+01:00
New Revision: d77e3c6aec2916fdf7b8ab0ca08c550230244695

URL: https://github.com/llvm/llvm-project/commit/d77e3c6aec2916fdf7b8ab0ca08c550230244695
DIFF: https://github.com/llvm/llvm-project/commit/d77e3c6aec2916fdf7b8ab0ca08c550230244695.diff

LOG: [lldb][NFC] Don't inherit from UserID in ValueObject

ValueObject inherits from UserID which is just a bad idea:

* The inheritance gives ValueObject some member functions that are at best
  misleading (such as `Clear()` which doesn't clear any value beside `id`).

* It allows passing ValueObject to the overloaded operators for UserID (such as
  `==` or `<<` which won't actually compare or print anything in the ValueObject).

* It exposes the `SetID` and `Clear` which both allow users to change the
  internal id value.

Similar to D91699 which did the same for Process

Reviewed By: #lldb, JDevlieghere

Differential Revision: https://reviews.llvm.org/D97205

Added: 
    

Modified: 
    lldb/include/lldb/Core/ValueObject.h
    lldb/source/Core/ValueObject.cpp
    lldb/source/DataFormatters/TypeSynthetic.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Core/ValueObject.h b/lldb/include/lldb/Core/ValueObject.h
index e8c7defa330c..308e0795efe6 100644
--- a/lldb/include/lldb/Core/ValueObject.h
+++ b/lldb/include/lldb/Core/ValueObject.h
@@ -102,7 +102,7 @@ class TypeSummaryOptions;
 /// Shared Pointer to the contained ValueObject,
 /// just do so by calling GetSP() on the contained object.
 
-class ValueObject : public UserID {
+class ValueObject {
 public:
   enum GetExpressionPathFormat {
     eGetExpressionPathFormatDereferencePointers = 1,
@@ -457,6 +457,9 @@ class ValueObject : public UserID {
 
   ConstString GetName() const;
 
+  /// Returns a unique id for this ValueObject.
+  lldb::user_id_t GetID() const { return m_id.GetID(); }
+
   virtual lldb::ValueObjectSP GetChildAtIndex(size_t idx, bool can_create);
 
   // this will always create the children if necessary
@@ -885,6 +888,9 @@ class ValueObject : public UserID {
 
   uint64_t m_language_flags = 0;
 
+  /// Unique identifier for every value object.
+  UserID m_id;
+
   // Utility class for initializing all bitfields in ValueObject's constructors.
   // FIXME: This could be done via default initializers once we have C++20.
   struct Bitflags {

diff  --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp
index 8f1d4e8cc7e5..6f736c3edfb7 100644
--- a/lldb/source/Core/ValueObject.cpp
+++ b/lldb/source/Core/ValueObject.cpp
@@ -76,9 +76,8 @@ static user_id_t g_value_obj_uid = 0;
 
 // ValueObject constructor
 ValueObject::ValueObject(ValueObject &parent)
-    : UserID(++g_value_obj_uid), // Unique identifier for every value object
-      m_parent(&parent), m_update_point(parent.GetUpdatePoint()),
-      m_manager(parent.GetManager()) {
+    : m_parent(&parent), m_update_point(parent.GetUpdatePoint()),
+      m_manager(parent.GetManager()), m_id(++g_value_obj_uid) {
   m_flags.m_is_synthetic_children_generated =
       parent.m_flags.m_is_synthetic_children_generated;
   m_data.SetByteOrder(parent.GetDataExtractor().GetByteOrder());
@@ -90,9 +89,9 @@ ValueObject::ValueObject(ValueObject &parent)
 ValueObject::ValueObject(ExecutionContextScope *exe_scope,
                          ValueObjectManager &manager,
                          AddressType child_ptr_or_ref_addr_type)
-    : UserID(++g_value_obj_uid), // Unique identifier for every value object
-      m_update_point(exe_scope), m_manager(&manager),
-      m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type) {
+    : m_update_point(exe_scope), m_manager(&manager),
+      m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
+      m_id(++g_value_obj_uid) {
   if (exe_scope) {
     TargetSP target_sp(exe_scope->CalculateTarget());
     if (target_sp) {

diff  --git a/lldb/source/DataFormatters/TypeSynthetic.cpp b/lldb/source/DataFormatters/TypeSynthetic.cpp
index 75388a93cc64..ba806ca7cfbc 100644
--- a/lldb/source/DataFormatters/TypeSynthetic.cpp
+++ b/lldb/source/DataFormatters/TypeSynthetic.cpp
@@ -128,7 +128,7 @@ ScriptedSyntheticChildren::FrontEnd::FrontEnd(std::string pclass,
                                               ValueObject &backend)
     : SyntheticChildrenFrontEnd(backend), m_python_class(pclass),
       m_wrapper_sp(), m_interpreter(nullptr) {
-  if (backend == LLDB_INVALID_UID)
+  if (backend.GetID() == LLDB_INVALID_UID)
     return;
 
   TargetSP target_sp = backend.GetTargetSP();


        


More information about the lldb-commits mailing list