[Lldb-commits] [lldb] [lldb] Scaffolding for extended variable support. (PR #181500)

Aman LaChapelle via lldb-commits lldb-commits at lists.llvm.org
Wed Apr 15 22:52:31 PDT 2026


https://github.com/bzcheeseman updated https://github.com/llvm/llvm-project/pull/181500

>From 694a0dd25dfd485f5ff2da5a08429d18b74c3bfb Mon Sep 17 00:00:00 2001
From: bzcheeseman <aman.lachapelle at gmail.com>
Date: Sat, 14 Feb 2026 10:55:50 -0800
Subject: [PATCH] [lldb] Scaffolding for synthetic variable support.

This patch handles most of the scaffolding for synthetic variable support that isn't directly tied to functional changes. This patch will be used by one following patch that actually modifies the lldb_private::StackFrame API to allow us to fetch synthetic variables.

There were a couple important/interesting decisions made in this patch that should be noted:
- Any value type may be synthetic, which is why it's a mask applied over the top of another value type.
- When printing frame variables with `fr v`, default to showing synthetic variables.

This new value type mask makes some of the ValueType handling more interesting, but since nothing generates objects with this mask until the next patch, we can land the concept in this patch in some amount of isolation.

stack-info: PR: https://github.com/llvm/llvm-project/pull/181500, branch: users/bzcheeseman/stack/8
---
 lldb/include/lldb/API/SBVariablesOptions.h    |  4 +++
 .../lldb/Interpreter/OptionGroupVariable.h    |  5 +--
 lldb/include/lldb/Utility/ValueType.h         | 32 +++++++++++++++++++
 lldb/include/lldb/lldb-enumerations.h         |  6 ++++
 lldb/source/API/SBVariablesOptions.cpp        | 21 ++++++++++--
 .../Interpreter/OptionGroupVariable.cpp       | 19 +++++++++--
 6 files changed, 81 insertions(+), 6 deletions(-)
 create mode 100644 lldb/include/lldb/Utility/ValueType.h

diff --git a/lldb/include/lldb/API/SBVariablesOptions.h b/lldb/include/lldb/API/SBVariablesOptions.h
index 53ab4b7e14f2f..87680012d4a1a 100644
--- a/lldb/include/lldb/API/SBVariablesOptions.h
+++ b/lldb/include/lldb/API/SBVariablesOptions.h
@@ -46,6 +46,10 @@ class LLDB_API SBVariablesOptions {
 
   void SetIncludeStatics(bool);
 
+  bool GetIncludeSynthetic() const;
+
+  void SetIncludeSynthetic(bool);
+
   bool GetInScopeOnly() const;
 
   void SetInScopeOnly(bool);
diff --git a/lldb/include/lldb/Interpreter/OptionGroupVariable.h b/lldb/include/lldb/Interpreter/OptionGroupVariable.h
index c1fbeb8e78b26..ec158a9f6ffc4 100644
--- a/lldb/include/lldb/Interpreter/OptionGroupVariable.h
+++ b/lldb/include/lldb/Interpreter/OptionGroupVariable.h
@@ -33,8 +33,9 @@ class OptionGroupVariable : public OptionGroup {
       show_args : 1, // Frame option only (include_frame_options == true)
       show_recognized_args : 1, // Frame option only (include_frame_options ==
                                 // true)
-      show_locals : 1,  // Frame option only (include_frame_options == true)
-      show_globals : 1, // Frame option only (include_frame_options == true)
+      show_locals : 1,    // Frame option only (include_frame_options == true)
+      show_globals : 1,   // Frame option only (include_frame_options == true)
+      show_synthetic : 1, // Frame option only (include_frame_options == true)
       use_regex : 1, show_scope : 1, show_decl : 1;
   OptionValueString summary;        // the name of a named summary
   OptionValueString summary_string; // a summary string
diff --git a/lldb/include/lldb/Utility/ValueType.h b/lldb/include/lldb/Utility/ValueType.h
new file mode 100644
index 0000000000000..e286eeab1b0b1
--- /dev/null
+++ b/lldb/include/lldb/Utility/ValueType.h
@@ -0,0 +1,32 @@
+//===-- State.h -------------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_UTILITY_VALUETYPE_H
+#define LLDB_UTILITY_VALUETYPE_H
+
+#include "lldb/lldb-enumerations.h"
+
+namespace lldb_private {
+/// Get the base value type - for when we don't care if the value is synthetic
+/// or not, or when we've already handled that case.
+constexpr lldb::ValueType GetBaseValueType(lldb::ValueType vt) {
+  return lldb::ValueType(vt & ~lldb::ValueTypeSyntheticMask);
+}
+
+/// Given a base value type, return a version that carries the synthetic bit.
+constexpr lldb::ValueType GetSyntheticValueType(lldb::ValueType base) {
+  return lldb::ValueType(base | lldb::ValueTypeSyntheticMask);
+}
+
+/// Return true if vt represents a synthetic value, false if not.
+constexpr bool IsSyntheticValueType(lldb::ValueType vt) {
+  return vt & lldb::ValueTypeSyntheticMask;
+}
+} // namespace lldb_private
+
+#endif // LLDB_UTILITY_VALUETYPE_H
diff --git a/lldb/include/lldb/lldb-enumerations.h b/lldb/include/lldb/lldb-enumerations.h
index 4cbbabbf879ad..fa2e548bbdfaa 100644
--- a/lldb/include/lldb/lldb-enumerations.h
+++ b/lldb/include/lldb/lldb-enumerations.h
@@ -340,6 +340,12 @@ enum ValueType {
   eValueTypeVTableEntry = 10, ///< function pointer in virtual function table
 };
 
+/// A mask that we can use to check if the value type is synthetic or not.
+// NOTE: This limits the number of value types to 31, but that's 3x more than
+// what we currently have now. See lldb/Utility/ValueType.h for helpers for
+// working with synthetic value types.
+static constexpr unsigned ValueTypeSyntheticMask = 0x20;
+
 /// Token size/granularities for Input Readers.
 
 enum InputReaderGranularity {
diff --git a/lldb/source/API/SBVariablesOptions.cpp b/lldb/source/API/SBVariablesOptions.cpp
index 989d159139cca..4d4eba0c635ce 100644
--- a/lldb/source/API/SBVariablesOptions.cpp
+++ b/lldb/source/API/SBVariablesOptions.cpp
@@ -20,8 +20,8 @@ class VariablesOptionsImpl {
 public:
   VariablesOptionsImpl()
       : m_include_arguments(false), m_include_locals(false),
-        m_include_statics(false), m_in_scope_only(false),
-        m_include_runtime_support_values(false) {}
+        m_include_statics(false), m_include_synthetic(false),
+        m_in_scope_only(false), m_include_runtime_support_values(false) {}
 
   VariablesOptionsImpl(const VariablesOptionsImpl &) = default;
 
@@ -51,6 +51,10 @@ class VariablesOptionsImpl {
 
   void SetIncludeStatics(bool b) { m_include_statics = b; }
 
+  bool GetIncludeSynthetic() const { return m_include_synthetic; }
+
+  void SetIncludeSynthetic(bool b) { m_include_synthetic = b; }
+
   bool GetInScopeOnly() const { return m_in_scope_only; }
 
   void SetInScopeOnly(bool b) { m_in_scope_only = b; }
@@ -71,6 +75,7 @@ class VariablesOptionsImpl {
   bool m_include_arguments : 1;
   bool m_include_locals : 1;
   bool m_include_statics : 1;
+  bool m_include_synthetic : 1;
   bool m_in_scope_only : 1;
   bool m_include_runtime_support_values : 1;
   LazyBool m_include_recognized_arguments =
@@ -157,6 +162,18 @@ void SBVariablesOptions::SetIncludeStatics(bool statics) {
   m_opaque_up->SetIncludeStatics(statics);
 }
 
+bool SBVariablesOptions::GetIncludeSynthetic() const {
+  LLDB_INSTRUMENT_VA(this);
+
+  return m_opaque_up->GetIncludeSynthetic();
+}
+
+void SBVariablesOptions::SetIncludeSynthetic(bool synthetic) {
+  LLDB_INSTRUMENT_VA(this, synthetic);
+
+  m_opaque_up->SetIncludeSynthetic(synthetic);
+}
+
 bool SBVariablesOptions::GetInScopeOnly() const {
   LLDB_INSTRUMENT_VA(this);
 
diff --git a/lldb/source/Interpreter/OptionGroupVariable.cpp b/lldb/source/Interpreter/OptionGroupVariable.cpp
index 065b70a460c2f..0024b4294791e 100644
--- a/lldb/source/Interpreter/OptionGroupVariable.cpp
+++ b/lldb/source/Interpreter/OptionGroupVariable.cpp
@@ -60,6 +60,16 @@ static constexpr OptionDefinition g_variable_options[] = {
      0,
      eArgTypeNone,
      "Show the current frame source file global and static variables."},
+    {LLDB_OPT_SET_1 | LLDB_OPT_SET_2,
+     false,
+     "no-synthetic",
+     'e', // Use 'e' for synthEtic - s and y are both taken.
+     OptionParser::eNoArgument,
+     nullptr,
+     {},
+     0,
+     eArgTypeNone,
+     "Omit extended variables."},
     {LLDB_OPT_SET_1 | LLDB_OPT_SET_2,
      false,
      "show-declaration",
@@ -140,8 +150,9 @@ static Status ValidateSummaryString(const char *str, void *) {
 OptionGroupVariable::OptionGroupVariable(bool show_frame_options)
     : include_frame_options(show_frame_options), show_args(false),
       show_recognized_args(false), show_locals(false), show_globals(false),
-      use_regex(false), show_scope(false), show_decl(false),
-      summary(ValidateNamedSummary), summary_string(ValidateSummaryString) {}
+      show_synthetic(true), use_regex(false), show_scope(false),
+      show_decl(false), summary(ValidateNamedSummary),
+      summary_string(ValidateSummaryString) {}
 
 Status
 OptionGroupVariable::SetOptionValue(uint32_t option_idx,
@@ -164,6 +175,9 @@ OptionGroupVariable::SetOptionValue(uint32_t option_idx,
   case 'g':
     show_globals = true;
     break;
+  case 'e':
+    show_synthetic = false;
+    break;
   case 'c':
     show_decl = true;
     break;
@@ -192,6 +206,7 @@ void OptionGroupVariable::OptionParsingStarting(
   show_recognized_args = true; // Frame option only
   show_locals = true;          // Frame option only
   show_globals = false;        // Frame option only
+  show_synthetic = true;       // Frame option only
   show_decl = false;
   use_regex = false;
   show_scope = false;



More information about the lldb-commits mailing list