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 01/12] [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 65920c76df7a8d..bec816fb451844 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 9d7efba024d115..6b77c0e95cedd6 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 02/12] 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 7e802f92da352a..460afbc1202cfd 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 474c18bc62ebd9..2b8f7c86ac6f12 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 + ), + ) >From 0273cff054763b80f33a8e646b804f1c0becb657 Mon Sep 17 00:00:00 2001 From: Vincent Belliard <v-bu...@github.com> Date: Thu, 20 Jun 2024 17:28:31 -0700 Subject: [PATCH 03/12] formatting --- lldb/test/API/python_api/formatters/synth.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lldb/test/API/python_api/formatters/synth.py b/lldb/test/API/python_api/formatters/synth.py index 2b8f7c86ac6f12..146206900eb66f 100644 --- a/lldb/test/API/python_api/formatters/synth.py +++ b/lldb/test/API/python_api/formatters/synth.py @@ -39,7 +39,9 @@ def ccc_synthetic(sbvalue, internal_dict): # 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")) + return "CCC object with leading synthetic value " + str( + sbvalue.GetChildMemberWithName("a") + ) class CCCSynthProvider(object): >From d016e5f97d2cd0d4a853d4b071cc102c3799d7f9 Mon Sep 17 00:00:00 2001 From: Vincent Belliard <v-bu...@github.com> Date: Fri, 21 Jun 2024 08:47:25 -0700 Subject: [PATCH 04/12] disable category CCCSynth before enabling CCCSynth2 --- lldb/test/API/python_api/formatters/TestFormattersSBAPI.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py b/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py index 460afbc1202cfd..8307ef1cbaad25 100644 --- a/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py +++ b/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py @@ -154,6 +154,7 @@ def cleanup(): "c = 333", ], ) + self.dbg.GetCategory("CCCSynth").SetEnabled(False) self.dbg.GetCategory("CCCSynth2").SetEnabled(True) self.expect( >From 6387fd03d80c75d4a8506a1fee4aa14daf00fa8d 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 05/12] [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 65920c76df7a8d..bec816fb451844 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 10a691c4034195..a1afc6846e1ba6 100644 --- a/lldb/source/API/SBValue.cpp +++ b/lldb/source/API/SBValue.cpp @@ -764,6 +764,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 8de687318021b3282bd875724cb72280dc8e78ad 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 06/12] 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 7e802f92da352a..460afbc1202cfd 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 474c18bc62ebd9..2b8f7c86ac6f12 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 + ), + ) >From 7bd84ed2e7c8c1f851179921a9216147f8abdc3a Mon Sep 17 00:00:00 2001 From: Vincent Belliard <v-bu...@github.com> Date: Thu, 20 Jun 2024 17:28:31 -0700 Subject: [PATCH 07/12] formatting --- lldb/test/API/python_api/formatters/synth.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lldb/test/API/python_api/formatters/synth.py b/lldb/test/API/python_api/formatters/synth.py index 2b8f7c86ac6f12..146206900eb66f 100644 --- a/lldb/test/API/python_api/formatters/synth.py +++ b/lldb/test/API/python_api/formatters/synth.py @@ -39,7 +39,9 @@ def ccc_synthetic(sbvalue, internal_dict): # 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")) + return "CCC object with leading synthetic value " + str( + sbvalue.GetChildMemberWithName("a") + ) class CCCSynthProvider(object): >From c449f6c674eaca8246db8d4e84665b18d59430d6 Mon Sep 17 00:00:00 2001 From: Vincent Belliard <v-bu...@github.com> Date: Fri, 21 Jun 2024 08:47:25 -0700 Subject: [PATCH 08/12] disable category CCCSynth before enabling CCCSynth2 --- lldb/test/API/python_api/formatters/TestFormattersSBAPI.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py b/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py index 460afbc1202cfd..8307ef1cbaad25 100644 --- a/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py +++ b/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py @@ -154,6 +154,7 @@ def cleanup(): "c = 333", ], ) + self.dbg.GetCategory("CCCSynth").SetEnabled(False) self.dbg.GetCategory("CCCSynth2").SetEnabled(True) self.expect( >From 2ee16658de5b46ef6394d995cc5981d60db8367a Mon Sep 17 00:00:00 2001 From: Vincent Belliard <v-bu...@github.com> Date: Wed, 3 Jul 2024 08:55:37 -0700 Subject: [PATCH 09/12] GetSyntheticValue returns an empty value if it's not synthetic --- lldb/source/API/SBValue.cpp | 3 +++ .../formatters/TestFormattersSBAPI.py | 19 ++++++++++++++----- lldb/test/API/python_api/formatters/main.cpp | 2 ++ lldb/test/API/python_api/formatters/synth.py | 16 +++++++++++++++- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp index a1afc6846e1ba6..96670481eca3fc 100644 --- a/lldb/source/API/SBValue.cpp +++ b/lldb/source/API/SBValue.cpp @@ -772,6 +772,9 @@ lldb::SBValue SBValue::GetSyntheticValue() { ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(), m_opaque_sp->GetUseDynamic(), true)); value_sb.SetSP(proxy_sp); + if (!value_sb.IsSynthetic()) { + return {}; + } } return value_sb; } diff --git a/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py b/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py index 8307ef1cbaad25..c01c466b70c82a 100644 --- a/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py +++ b/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py @@ -143,31 +143,40 @@ def cleanup(): self.dbg.GetCategory("JASSynth").SetEnabled(True) self.expect("frame variable foo", matching=True, substrs=["X = 1"]) - self.dbg.GetCategory("CCCSynth").SetEnabled(True) + self.dbg.GetCategory("CCCSynth2").SetEnabled(True) self.expect( "frame variable ccc", matching=True, substrs=[ - "CCC object with leading value (int) a = 111", + "CCC object with leading synthetic value (int) b = 222", "a = 111", "b = 222", "c = 333", ], ) - self.dbg.GetCategory("CCCSynth").SetEnabled(False) + self.dbg.GetCategory("CCCSynth2").SetEnabled(False) - self.dbg.GetCategory("CCCSynth2").SetEnabled(True) + self.dbg.GetCategory("CCCSynth").SetEnabled(True) self.expect( "frame variable ccc", matching=True, substrs=[ - "CCC object with leading synthetic value (int) b = 222", + "CCC object with leading value (int) a = 111", "a = 111", "b = 222", "c = 333", ], ) + self.dbg.GetCategory("BarIntSynth").SetEnabled(True) + self.expect( + "frame variable bar_int", + matching=True, + substrs=[ + "(int) bar_int = 20 bar_int synthetic: No value", + ], + ) + foo_var = ( self.dbg.GetSelectedTarget() .GetProcess() diff --git a/lldb/test/API/python_api/formatters/main.cpp b/lldb/test/API/python_api/formatters/main.cpp index f21c956144c29b..f731fd2c7b5676 100644 --- a/lldb/test/API/python_api/formatters/main.cpp +++ b/lldb/test/API/python_api/formatters/main.cpp @@ -52,6 +52,8 @@ int main(int argc, char const *argv[]) { CCC ccc = {111, 222, 333}; + int bar_int = 20; + Empty1 e1; Empty2 e2; diff --git a/lldb/test/API/python_api/formatters/synth.py b/lldb/test/API/python_api/formatters/synth.py index 146206900eb66f..91afb26af84361 100644 --- a/lldb/test/API/python_api/formatters/synth.py +++ b/lldb/test/API/python_api/formatters/synth.py @@ -35,7 +35,7 @@ def ccc_summary(sbvalue, internal_dict): def ccc_synthetic(sbvalue, internal_dict): sbvalue = sbvalue.GetSyntheticValue() - # This tests that the SBValue.GetNonSyntheticValue() actually returns a + # This tests that the SBValue.GetSyntheticValue() 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"). @@ -44,6 +44,13 @@ def ccc_synthetic(sbvalue, internal_dict): ) +def bar_int_synthetic(sbvalue, internal_dict): + sbvalue = sbvalue.GetSyntheticValue() + # This tests that the SBValue.GetSyntheticValue() actually returns no + # value when the value has no synthetic representation. + return "bar_int synthetic: " + str(sbvalue) + + class CCCSynthProvider(object): def __init__(self, sbvalue, internal_dict): self._sbvalue = sbvalue @@ -145,3 +152,10 @@ def __lldb_init_module(debugger, dict): "synth.ccc_synthetic", lldb.eTypeOptionCascade ), ) + cat3 = debugger.CreateCategory("BarIntSynth") + cat3.AddTypeSummary( + lldb.SBTypeNameSpecifier("int"), + lldb.SBTypeSummary.CreateWithFunctionName( + "synth.bar_int_synthetic", lldb.eTypeOptionCascade + ), + ) >From bcfebfbcbc4196daa9ab03874a58b53d44afeb3c Mon Sep 17 00:00:00 2001 From: Vincent Belliard <v-bu...@github.com> Date: Wed, 3 Jul 2024 10:10:53 -0700 Subject: [PATCH 10/12] fix --- .../python_api/formatters/TestFormattersSBAPI.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py b/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py index 463af5d86520d4..c01c466b70c82a 100644 --- a/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py +++ b/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py @@ -167,19 +167,6 @@ def cleanup(): "c = 333", ], ) - self.dbg.GetCategory("CCCSynth").SetEnabled(False) - - 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", - ], - ) self.dbg.GetCategory("BarIntSynth").SetEnabled(True) self.expect( >From 88777c327462f95d0377029a9f5cfc9ac092aa0f Mon Sep 17 00:00:00 2001 From: Vincent Belliard <v-bu...@github.com> Date: Wed, 3 Jul 2024 10:17:40 -0700 Subject: [PATCH 11/12] format --- lldb/test/API/python_api/formatters/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/test/API/python_api/formatters/main.cpp b/lldb/test/API/python_api/formatters/main.cpp index f731fd2c7b5676..588b1cf8eac617 100644 --- a/lldb/test/API/python_api/formatters/main.cpp +++ b/lldb/test/API/python_api/formatters/main.cpp @@ -52,7 +52,7 @@ int main(int argc, char const *argv[]) { CCC ccc = {111, 222, 333}; - int bar_int = 20; + int bar_int = 20; Empty1 e1; Empty2 e2; >From e6c9db3b2aa8cd77abf5622ec6829bdda5056a2b Mon Sep 17 00:00:00 2001 From: Vincent Belliard <v-bu...@github.com> Date: Wed, 3 Jul 2024 10:29:50 -0700 Subject: [PATCH 12/12] format --- lldb/test/API/python_api/formatters/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/test/API/python_api/formatters/main.cpp b/lldb/test/API/python_api/formatters/main.cpp index 588b1cf8eac617..d54a6a56119ba5 100644 --- a/lldb/test/API/python_api/formatters/main.cpp +++ b/lldb/test/API/python_api/formatters/main.cpp @@ -52,7 +52,7 @@ int main(int argc, char const *argv[]) { CCC ccc = {111, 222, 333}; - int bar_int = 20; + int bar_int = 20; Empty1 e1; Empty2 e2; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits