[Lldb-commits] [lldb] [lldb] Update the calling convention of BytecodeSyntheticChildren (PR #182155)
via lldb-commits
lldb-commits at lists.llvm.org
Wed Feb 18 13:49:40 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Dave Lee (kastiglione)
<details>
<summary>Changes</summary>
This changes how "self" is constructed, where "self" is the data placed on the stack before calls to `num_children`, `get_child_at_index`, etc.
First, the return value of `init` is saved to its own member, `m_init_results`. Likewise, the return value of `update` is saved to a separate member, `m_update_results`.
Calls to both `init` and `update` recieve only the value object on their stack. This is done to simplify implementations of `update`. It makes them more "pure", in that the argument is always a single value (the value object). Previously `update` was called with the value of "self", which was shared between `init` and `update`, and was mutated by `update`.
Lastly, the results of `init` and `update` are concatenated to being the value of "self" when calling other methods.
---
Full diff: https://github.com/llvm/llvm-project/pull/182155.diff
2 Files Affected:
- (modified) lldb/include/lldb/DataFormatters/TypeSynthetic.h (+9-1)
- (modified) lldb/source/DataFormatters/TypeSynthetic.cpp (+20-10)
``````````diff
diff --git a/lldb/include/lldb/DataFormatters/TypeSynthetic.h b/lldb/include/lldb/DataFormatters/TypeSynthetic.h
index fbf1d060a92b2..ae51ab400ba3d 100644
--- a/lldb/include/lldb/DataFormatters/TypeSynthetic.h
+++ b/lldb/include/lldb/DataFormatters/TypeSynthetic.h
@@ -502,9 +502,17 @@ class BytecodeSyntheticChildren : public SyntheticChildren {
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
llvm::Expected<size_t> GetIndexOfChildWithName(ConstString name) override;
+ private:
+ /// The data stack representing "self". The value of "self" is the results
+ /// of `init` combined with the results of `update`. Together, these values
+ /// are placed on the stack when calling `num_children`,
+ /// `get_child_at_index`, etc.
+ FormatterBytecode::DataStack GetSelf();
+
private:
const SyntheticBytecodeImplementation &m_impl;
- FormatterBytecode::DataStack m_self;
+ FormatterBytecode::DataStack m_init_results;
+ FormatterBytecode::DataStack m_update_results;
};
public:
diff --git a/lldb/source/DataFormatters/TypeSynthetic.cpp b/lldb/source/DataFormatters/TypeSynthetic.cpp
index 10655cdca6f05..6e5721f357c6a 100644
--- a/lldb/source/DataFormatters/TypeSynthetic.cpp
+++ b/lldb/source/DataFormatters/TypeSynthetic.cpp
@@ -20,8 +20,10 @@
#include "lldb/Symbol/CompilerType.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/StreamString.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Error.h"
#include <cstdint>
+#include <iterator>
using namespace lldb;
using namespace lldb_private;
@@ -258,13 +260,11 @@ std::string ScriptedSyntheticChildren::GetDescription() {
BytecodeSyntheticChildren::FrontEnd::FrontEnd(
ValueObject &backend, SyntheticBytecodeImplementation &impl)
: SyntheticChildrenFrontEnd(backend), m_impl(impl) {
- FormatterBytecode::DataStack data(backend.GetSP());
- if (!m_impl.init) {
- m_self = std::move(data);
+ if (!m_impl.init)
return;
- }
FormatterBytecode::ControlStack control = {m_impl.init->getBuffer()};
+ FormatterBytecode::DataStack data = {backend.GetSP()};
llvm::Error error =
FormatterBytecode::Interpret(control, data, FormatterBytecode::sig_init);
if (error) {
@@ -274,7 +274,7 @@ BytecodeSyntheticChildren::FrontEnd::FrontEnd(
}
if (data.size() > 0)
- m_self = std::move(data);
+ m_init_results = std::move(data);
}
lldb::ChildCacheState BytecodeSyntheticChildren::FrontEnd::Update() {
@@ -282,7 +282,7 @@ lldb::ChildCacheState BytecodeSyntheticChildren::FrontEnd::Update() {
return ChildCacheState::eRefetch;
FormatterBytecode::ControlStack control = {m_impl.update->getBuffer()};
- FormatterBytecode::DataStack data = m_self;
+ FormatterBytecode::DataStack data = {m_backend.GetSP()};
llvm::Error error = FormatterBytecode::Interpret(
control, data, FormatterBytecode::sig_update);
if (error) {
@@ -292,7 +292,7 @@ lldb::ChildCacheState BytecodeSyntheticChildren::FrontEnd::Update() {
}
if (data.size() > 0)
- m_self = std::move(data);
+ m_update_results = std::move(data);
return ChildCacheState::eRefetch;
}
@@ -303,7 +303,7 @@ BytecodeSyntheticChildren::FrontEnd::CalculateNumChildren() {
return 0;
FormatterBytecode::ControlStack control = {m_impl.num_children->getBuffer()};
- FormatterBytecode::DataStack data = m_self;
+ FormatterBytecode::DataStack data = GetSelf();
llvm::Error error = FormatterBytecode::Interpret(
control, data, FormatterBytecode::sig_get_num_children);
if (error)
@@ -335,7 +335,7 @@ BytecodeSyntheticChildren::FrontEnd::GetChildAtIndex(uint32_t idx) {
FormatterBytecode::ControlStack control = {
m_impl.get_child_at_index->getBuffer()};
- FormatterBytecode::DataStack data = m_self;
+ FormatterBytecode::DataStack data = GetSelf();
data.emplace_back((uint64_t)idx);
llvm::Error error = FormatterBytecode::Interpret(
control, data, FormatterBytecode::sig_get_child_at_index);
@@ -365,7 +365,7 @@ BytecodeSyntheticChildren::FrontEnd::GetIndexOfChildWithName(ConstString name) {
FormatterBytecode::ControlStack control = {
m_impl.get_child_index->getBuffer()};
- FormatterBytecode::DataStack data = m_self;
+ FormatterBytecode::DataStack data = GetSelf();
data.emplace_back(name.GetString());
llvm::Error error = FormatterBytecode::Interpret(
control, data, FormatterBytecode::sig_get_child_index);
@@ -391,6 +391,16 @@ BytecodeSyntheticChildren::FrontEnd::GetIndexOfChildWithName(ConstString name) {
return llvm::createStringError("@get_child_index returned invalid value");
}
+FormatterBytecode::DataStack BytecodeSyntheticChildren::FrontEnd::GetSelf() {
+ FormatterBytecode::DataStack self;
+ llvm::copy(m_init_results, std::back_inserter(self));
+ llvm::copy(m_update_results, std::back_inserter(self));
+ if (self.empty())
+ // As a fallback, "self" is just the valobj.
+ self.emplace_back(m_backend.GetSP());
+ return self;
+}
+
std::string BytecodeSyntheticChildren::GetDescription() {
StreamString sstr;
sstr.Printf("%s%s%s Bytecode synthetic", Cascades() ? "" : " (not cascading)",
``````````
</details>
https://github.com/llvm/llvm-project/pull/182155
More information about the lldb-commits
mailing list