https://github.com/v-bulle updated https://github.com/llvm/llvm-project/pull/95959
>From 27a00b54bc991dfb4747e0d37b15878beebaabba Mon Sep 17 00:00:00 2001 From: Vincent Belliard <v-bu...@github.com> Date: Wed, 12 Jun 2024 14:23:15 -0700 Subject: [PATCH 1/2] [API] add GetSyntheticValue --- lldb/include/lldb/API/SBValue.h | 2 ++ lldb/source/API/SBValue.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/lldb/include/lldb/API/SBValue.h b/lldb/include/lldb/API/SBValue.h index 65920c76df7a8..bec816fb45184 100644 --- a/lldb/include/lldb/API/SBValue.h +++ b/lldb/include/lldb/API/SBValue.h @@ -89,6 +89,8 @@ class LLDB_API SBValue { lldb::SBValue GetNonSyntheticValue(); + lldb::SBValue GetSyntheticValue(); + lldb::DynamicValueType GetPreferDynamicValue(); void SetPreferDynamicValue(lldb::DynamicValueType use_dynamic); diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp index 9d7efba024d11..6b77c0e95cedd 100644 --- a/lldb/source/API/SBValue.cpp +++ b/lldb/source/API/SBValue.cpp @@ -761,6 +761,18 @@ lldb::SBValue SBValue::GetNonSyntheticValue() { return value_sb; } +lldb::SBValue SBValue::GetSyntheticValue() { + LLDB_INSTRUMENT_VA(this); + + SBValue value_sb; + if (IsValid()) { + ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(), + m_opaque_sp->GetUseDynamic(), true)); + value_sb.SetSP(proxy_sp); + } + return value_sb; +} + lldb::DynamicValueType SBValue::GetPreferDynamicValue() { LLDB_INSTRUMENT_VA(this); >From e0ed752849486f67d9fddbef3767a1756afd1ab2 Mon Sep 17 00:00:00 2001 From: Vincent Belliard <v-bu...@github.com> Date: Thu, 20 Jun 2024 17:04:15 -0700 Subject: [PATCH 2/2] add test --- .../formatters/TestFormattersSBAPI.py | 12 ++++++++ lldb/test/API/python_api/formatters/synth.py | 28 +++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py b/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py index 7e802f92da352..460afbc1202cf 100644 --- a/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py +++ b/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py @@ -155,6 +155,18 @@ def cleanup(): ], ) + self.dbg.GetCategory("CCCSynth2").SetEnabled(True) + self.expect( + "frame variable ccc", + matching=True, + substrs=[ + "CCC object with leading synthetic value (int) b = 222", + "a = 111", + "b = 222", + "c = 333", + ], + ) + foo_var = ( self.dbg.GetSelectedTarget() .GetProcess() diff --git a/lldb/test/API/python_api/formatters/synth.py b/lldb/test/API/python_api/formatters/synth.py index 474c18bc62ebd..2b8f7c86ac6f1 100644 --- a/lldb/test/API/python_api/formatters/synth.py +++ b/lldb/test/API/python_api/formatters/synth.py @@ -29,11 +29,19 @@ def ccc_summary(sbvalue, internal_dict): # This tests that the SBValue.GetNonSyntheticValue() actually returns a # non-synthetic value. If it does not, then sbvalue.GetChildMemberWithName("a") # in the following statement will call the 'get_child_index' method of the - # synthetic child provider CCCSynthProvider below (which raises an - # exception). + # synthetic child provider CCCSynthProvider below (which return the "b" field"). return "CCC object with leading value " + str(sbvalue.GetChildMemberWithName("a")) +def ccc_synthetic(sbvalue, internal_dict): + sbvalue = sbvalue.GetSyntheticValue() + # This tests that the SBValue.GetNonSyntheticValue() actually returns a + # synthetic value. If it does, then sbvalue.GetChildMemberWithName("a") + # in the following statement will call the 'get_child_index' method of the + # synthetic child provider CCCSynthProvider below (which return the "b" field"). + return "CCC object with leading synthetic value " + str(sbvalue.GetChildMemberWithName("a")) + + class CCCSynthProvider(object): def __init__(self, sbvalue, internal_dict): self._sbvalue = sbvalue @@ -42,6 +50,9 @@ def num_children(self): return 3 def get_child_index(self, name): + if name == "a": + # Return b for test. + return 1 raise RuntimeError("I don't want to be called!") def get_child_at_index(self, index): @@ -119,3 +130,16 @@ def __lldb_init_module(debugger, dict): "synth.empty2_summary", lldb.eTypeOptionHideEmptyAggregates ), ) + cat2 = debugger.CreateCategory("CCCSynth2") + cat2.AddTypeSynthetic( + lldb.SBTypeNameSpecifier("CCC"), + lldb.SBTypeSynthetic.CreateWithClassName( + "synth.CCCSynthProvider", lldb.eTypeOptionCascade + ), + ) + cat2.AddTypeSummary( + lldb.SBTypeNameSpecifier("CCC"), + lldb.SBTypeSummary.CreateWithFunctionName( + "synth.ccc_synthetic", lldb.eTypeOptionCascade + ), + ) _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits