[Lldb-commits] [lldb] [lldb] Add SetValueFromCString API to SyntheticFronend (PR #67309)

via lldb-commits lldb-commits at lists.llvm.org
Mon Sep 25 03:55:06 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

<details>
<summary>Changes</summary>

It is a first of three patches neded for adding an ability to update std::string/wstring/etc during debug process. This patch adds to the synthetic child interface a “change value” method which goes back to the synthetic child provider and ask it if it knows how to change the underlying value that the synthetic child represents

Overall context is avaliable in the following question: https://discourse.llvm.org/t/clarify-hostaddress-loadaddress-logic/72175/3:

~~

Huawei RRI, OS Lab

---
Full diff: https://github.com/llvm/llvm-project/pull/67309.diff


3 Files Affected:

- (modified) lldb/include/lldb/Core/ValueObject.h (+11) 
- (modified) lldb/include/lldb/DataFormatters/TypeSynthetic.h (+7-1) 
- (modified) lldb/source/Core/ValueObject.cpp (+6-1) 


``````````diff
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..3a19804b22c196c 100644
--- a/lldb/include/lldb/DataFormatters/TypeSynthetic.h
+++ b/lldb/include/lldb/DataFormatters/TypeSynthetic.h
@@ -34,7 +34,9 @@ class SyntheticChildrenFrontEnd {
 
 public:
   SyntheticChildrenFrontEnd(ValueObject &backend)
-      : m_backend(backend), m_valid(true) {}
+      : m_backend(backend), m_valid(true) {
+    backend.SetSyntheticFrontend(this);
+  }
 
   virtual ~SyntheticChildrenFrontEnd() = default;
 
@@ -75,6 +77,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..cea3ea523020443 100644
--- a/lldb/source/Core/ValueObject.cpp
+++ b/lldb/source/Core/ValueObject.cpp
@@ -1535,7 +1535,12 @@ bool ValueObject::SetValueFromCString(const char *value_str, Status &error) {
     }
   } else {
     // We don't support setting things bigger than a scalar at present.
-    error.SetErrorString("unable to write aggregate data type");
+    // But maybe our frontend knows how to update the value.
+    if (auto *frontend = GetSyntheticFrontend()) {
+      return frontend->SetValueFromCString(value_str, error);
+    } else {
+      error.SetErrorString("unable to write aggregate data type");
+    }
     return false;
   }
 

``````````

</details>


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


More information about the lldb-commits mailing list