Skip to content

Commit d77e3c6

Browse files
committed
[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
1 parent f8b9035 commit d77e3c6

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

lldb/include/lldb/Core/ValueObject.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class TypeSummaryOptions;
102102
/// Shared Pointer to the contained ValueObject,
103103
/// just do so by calling GetSP() on the contained object.
104104

105-
class ValueObject : public UserID {
105+
class ValueObject {
106106
public:
107107
enum GetExpressionPathFormat {
108108
eGetExpressionPathFormatDereferencePointers = 1,
@@ -457,6 +457,9 @@ class ValueObject : public UserID {
457457

458458
ConstString GetName() const;
459459

460+
/// Returns a unique id for this ValueObject.
461+
lldb::user_id_t GetID() const { return m_id.GetID(); }
462+
460463
virtual lldb::ValueObjectSP GetChildAtIndex(size_t idx, bool can_create);
461464

462465
// this will always create the children if necessary
@@ -885,6 +888,9 @@ class ValueObject : public UserID {
885888

886889
uint64_t m_language_flags = 0;
887890

891+
/// Unique identifier for every value object.
892+
UserID m_id;
893+
888894
// Utility class for initializing all bitfields in ValueObject's constructors.
889895
// FIXME: This could be done via default initializers once we have C++20.
890896
struct Bitflags {

lldb/source/Core/ValueObject.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,8 @@ static user_id_t g_value_obj_uid = 0;
7676

7777
// ValueObject constructor
7878
ValueObject::ValueObject(ValueObject &parent)
79-
: UserID(++g_value_obj_uid), // Unique identifier for every value object
80-
m_parent(&parent), m_update_point(parent.GetUpdatePoint()),
81-
m_manager(parent.GetManager()) {
79+
: m_parent(&parent), m_update_point(parent.GetUpdatePoint()),
80+
m_manager(parent.GetManager()), m_id(++g_value_obj_uid) {
8281
m_flags.m_is_synthetic_children_generated =
8382
parent.m_flags.m_is_synthetic_children_generated;
8483
m_data.SetByteOrder(parent.GetDataExtractor().GetByteOrder());
@@ -90,9 +89,9 @@ ValueObject::ValueObject(ValueObject &parent)
9089
ValueObject::ValueObject(ExecutionContextScope *exe_scope,
9190
ValueObjectManager &manager,
9291
AddressType child_ptr_or_ref_addr_type)
93-
: UserID(++g_value_obj_uid), // Unique identifier for every value object
94-
m_update_point(exe_scope), m_manager(&manager),
95-
m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type) {
92+
: m_update_point(exe_scope), m_manager(&manager),
93+
m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
94+
m_id(++g_value_obj_uid) {
9695
if (exe_scope) {
9796
TargetSP target_sp(exe_scope->CalculateTarget());
9897
if (target_sp) {

lldb/source/DataFormatters/TypeSynthetic.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ ScriptedSyntheticChildren::FrontEnd::FrontEnd(std::string pclass,
128128
ValueObject &backend)
129129
: SyntheticChildrenFrontEnd(backend), m_python_class(pclass),
130130
m_wrapper_sp(), m_interpreter(nullptr) {
131-
if (backend == LLDB_INVALID_UID)
131+
if (backend.GetID() == LLDB_INVALID_UID)
132132
return;
133133

134134
TargetSP target_sp = backend.GetTargetSP();

0 commit comments

Comments
 (0)