https://github.com/kpdev updated https://github.com/llvm/llvm-project/pull/67309
>From 94d31eabaea7edd2cb139a45fdc8b85d2768f29d Mon Sep 17 00:00:00 2001 From: Pavel Kosov <kpde...@gmail.com> Date: Mon, 25 Sep 2023 13:41:03 +0300 Subject: [PATCH] [lldb] Add SetValueFromCString API to SyntheticFronend It is a first of three patches neded for adding an ability to update std::string/wstring/etc during debug process. Add SetValueFromCString API to SyntheticFronend Overall context is avaliable in the following discussion: https://discourse.llvm.org/t/clarify-hostaddress-loadaddress-logic/72175/3: ~~ Huawei RRI, OS Lab --- lldb/include/lldb/Core/ValueObject.h | 11 +++++++++++ lldb/include/lldb/DataFormatters/TypeSynthetic.h | 12 ++++++++++-- lldb/source/Core/ValueObject.cpp | 5 ++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lldb/include/lldb/Core/ValueObject.h b/lldb/include/lldb/Core/ValueObject.h index 3af94f0a86e2fcc..892f5d0dea4f650 100644 --- a/lldb/include/lldb/Core/ValueObject.h +++ b/lldb/include/lldb/Core/ValueObject.h @@ -589,6 +589,14 @@ class ValueObject { virtual bool IsSynthetic() { return false; } + void SetSyntheticFrontend(SyntheticChildrenFrontEnd *synth_front) { + m_synthetic_frontend = synth_front; + } + + SyntheticChildrenFrontEnd *GetSyntheticFrontend() const { + return m_synthetic_frontend; + } + lldb::ValueObjectSP GetQualifiedRepresentationIfAvailable(lldb::DynamicValueType dynValue, bool synthValue); @@ -898,6 +906,9 @@ class ValueObject { /// Unique identifier for every value object. UserID m_id; + // If frontend exist - we may try to update our value through it + SyntheticChildrenFrontEnd *m_synthetic_frontend = nullptr; + // 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/include/lldb/DataFormatters/TypeSynthetic.h b/lldb/include/lldb/DataFormatters/TypeSynthetic.h index 41be9b7efda8fdb..8e9bf9da77211ba 100644 --- a/lldb/include/lldb/DataFormatters/TypeSynthetic.h +++ b/lldb/include/lldb/DataFormatters/TypeSynthetic.h @@ -34,9 +34,13 @@ class SyntheticChildrenFrontEnd { public: SyntheticChildrenFrontEnd(ValueObject &backend) - : m_backend(backend), m_valid(true) {} + : m_backend(backend), m_valid(true) { + m_backend.SetSyntheticFrontend(this); + } - virtual ~SyntheticChildrenFrontEnd() = default; + virtual ~SyntheticChildrenFrontEnd() { + m_backend.SetSyntheticFrontend(nullptr); + } virtual size_t CalculateNumChildren() = 0; @@ -75,6 +79,10 @@ class SyntheticChildrenFrontEnd { // display purposes virtual ConstString GetSyntheticTypeName() { return ConstString(); } + virtual bool SetValueFromCString(const char *value_str, Status &error) { + return false; + } + typedef std::shared_ptr<SyntheticChildrenFrontEnd> SharedPointer; typedef std::unique_ptr<SyntheticChildrenFrontEnd> AutoPointer; diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index ebfc1cf4d6fe9e1..c93c7dd32e0c7f2 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -1479,7 +1479,7 @@ bool ValueObject::SetValueFromCString(const char *value_str, Status &error) { if (value_type == Value::ValueType::Scalar) { // If the value is already a scalar, then let the scalar change itself: m_value.GetScalar().SetValueFromCString(value_str, encoding, byte_size); - } else if (byte_size <= 16) { + } else if (byte_size <= 16 && encoding != eEncodingInvalid) { // If the value fits in a scalar, then make a new scalar and again let the // scalar code do the conversion, then figure out where to put the new // value. @@ -1535,6 +1535,9 @@ bool ValueObject::SetValueFromCString(const char *value_str, Status &error) { } } else { // We don't support setting things bigger than a scalar at present. + // But maybe our frontend knows how to update the value. + if (auto *frontend = GetSyntheticFrontend()) + return frontend->SetValueFromCString(value_str, error); error.SetErrorString("unable to write aggregate data type"); return false; } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits