[Lldb-commits] [lldb] [lldb] Add SetValueFromCString API to SyntheticFronend (PR #67309)
Pavel Kosov via lldb-commits
lldb-commits at lists.llvm.org
Mon Sep 25 03:53:58 PDT 2023
https://github.com/kpdev created https://github.com/llvm/llvm-project/pull/67309
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
>From 07f943e3c243a41f1e7395379ca09a1ee79f2a93 Mon Sep 17 00:00:00 2001
From: Pavel Kosov <kpdev42 at gmail.com>
Date: Mon, 25 Sep 2023 13:41:03 +0300
Subject: [PATCH] [lldb] Add SetValueFromCString API to SyntheticFronend
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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
---
lldb/include/lldb/Core/ValueObject.h | 11 +++++++++++
lldb/include/lldb/DataFormatters/TypeSynthetic.h | 8 +++++++-
lldb/source/Core/ValueObject.cpp | 7 ++++++-
3 files changed, 24 insertions(+), 2 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..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;
}
More information about the lldb-commits
mailing list