Skip to content

Commit 82af559

Browse files
v-bulleVincent Belliard
and
Vincent Belliard
authored
[API] add GetSyntheticValue (#95959)
Adds GetSyntheticValue to the API on top of GetNonSyntheticValue. --------- Co-authored-by: Vincent Belliard <[email protected]>
1 parent 365f5b4 commit 82af559

File tree

5 files changed

+83
-2
lines changed

5 files changed

+83
-2
lines changed

lldb/include/lldb/API/SBValue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ class LLDB_API SBValue {
8989

9090
lldb::SBValue GetNonSyntheticValue();
9191

92+
lldb::SBValue GetSyntheticValue();
93+
9294
lldb::DynamicValueType GetPreferDynamicValue();
9395

9496
void SetPreferDynamicValue(lldb::DynamicValueType use_dynamic);

lldb/source/API/SBValue.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,21 @@ lldb::SBValue SBValue::GetNonSyntheticValue() {
764764
return value_sb;
765765
}
766766

767+
lldb::SBValue SBValue::GetSyntheticValue() {
768+
LLDB_INSTRUMENT_VA(this);
769+
770+
SBValue value_sb;
771+
if (IsValid()) {
772+
ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),
773+
m_opaque_sp->GetUseDynamic(), true));
774+
value_sb.SetSP(proxy_sp);
775+
if (!value_sb.IsSynthetic()) {
776+
return {};
777+
}
778+
}
779+
return value_sb;
780+
}
781+
767782
lldb::DynamicValueType SBValue::GetPreferDynamicValue() {
768783
LLDB_INSTRUMENT_VA(this);
769784

lldb/test/API/python_api/formatters/TestFormattersSBAPI.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,19 @@ def cleanup():
143143
self.dbg.GetCategory("JASSynth").SetEnabled(True)
144144
self.expect("frame variable foo", matching=True, substrs=["X = 1"])
145145

146+
self.dbg.GetCategory("CCCSynth2").SetEnabled(True)
147+
self.expect(
148+
"frame variable ccc",
149+
matching=True,
150+
substrs=[
151+
"CCC object with leading synthetic value (int) b = 222",
152+
"a = 111",
153+
"b = 222",
154+
"c = 333",
155+
],
156+
)
157+
self.dbg.GetCategory("CCCSynth2").SetEnabled(False)
158+
146159
self.dbg.GetCategory("CCCSynth").SetEnabled(True)
147160
self.expect(
148161
"frame variable ccc",
@@ -155,6 +168,15 @@ def cleanup():
155168
],
156169
)
157170

171+
self.dbg.GetCategory("BarIntSynth").SetEnabled(True)
172+
self.expect(
173+
"frame variable bar_int",
174+
matching=True,
175+
substrs=[
176+
"(int) bar_int = 20 bar_int synthetic: No value",
177+
],
178+
)
179+
158180
foo_var = (
159181
self.dbg.GetSelectedTarget()
160182
.GetProcess()

lldb/test/API/python_api/formatters/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ int main(int argc, char const *argv[]) {
5252

5353
CCC ccc = {111, 222, 333};
5454

55+
int bar_int = 20;
56+
5557
Empty1 e1;
5658
Empty2 e2;
5759

lldb/test/API/python_api/formatters/synth.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,28 @@ def ccc_summary(sbvalue, internal_dict):
2929
# This tests that the SBValue.GetNonSyntheticValue() actually returns a
3030
# non-synthetic value. If it does not, then sbvalue.GetChildMemberWithName("a")
3131
# in the following statement will call the 'get_child_index' method of the
32-
# synthetic child provider CCCSynthProvider below (which raises an
33-
# exception).
32+
# synthetic child provider CCCSynthProvider below (which return the "b" field").
3433
return "CCC object with leading value " + str(sbvalue.GetChildMemberWithName("a"))
3534

3635

36+
def ccc_synthetic(sbvalue, internal_dict):
37+
sbvalue = sbvalue.GetSyntheticValue()
38+
# This tests that the SBValue.GetSyntheticValue() actually returns a
39+
# synthetic value. If it does, then sbvalue.GetChildMemberWithName("a")
40+
# in the following statement will call the 'get_child_index' method of the
41+
# synthetic child provider CCCSynthProvider below (which return the "b" field").
42+
return "CCC object with leading synthetic value " + str(
43+
sbvalue.GetChildMemberWithName("a")
44+
)
45+
46+
47+
def bar_int_synthetic(sbvalue, internal_dict):
48+
sbvalue = sbvalue.GetSyntheticValue()
49+
# This tests that the SBValue.GetSyntheticValue() actually returns no
50+
# value when the value has no synthetic representation.
51+
return "bar_int synthetic: " + str(sbvalue)
52+
53+
3754
class CCCSynthProvider(object):
3855
def __init__(self, sbvalue, internal_dict):
3956
self._sbvalue = sbvalue
@@ -42,6 +59,9 @@ def num_children(self):
4259
return 3
4360

4461
def get_child_index(self, name):
62+
if name == "a":
63+
# Return b for test.
64+
return 1
4565
raise RuntimeError("I don't want to be called!")
4666

4767
def get_child_at_index(self, index):
@@ -119,3 +139,23 @@ def __lldb_init_module(debugger, dict):
119139
"synth.empty2_summary", lldb.eTypeOptionHideEmptyAggregates
120140
),
121141
)
142+
cat2 = debugger.CreateCategory("CCCSynth2")
143+
cat2.AddTypeSynthetic(
144+
lldb.SBTypeNameSpecifier("CCC"),
145+
lldb.SBTypeSynthetic.CreateWithClassName(
146+
"synth.CCCSynthProvider", lldb.eTypeOptionCascade
147+
),
148+
)
149+
cat2.AddTypeSummary(
150+
lldb.SBTypeNameSpecifier("CCC"),
151+
lldb.SBTypeSummary.CreateWithFunctionName(
152+
"synth.ccc_synthetic", lldb.eTypeOptionCascade
153+
),
154+
)
155+
cat3 = debugger.CreateCategory("BarIntSynth")
156+
cat3.AddTypeSummary(
157+
lldb.SBTypeNameSpecifier("int"),
158+
lldb.SBTypeSummary.CreateWithFunctionName(
159+
"synth.bar_int_synthetic", lldb.eTypeOptionCascade
160+
),
161+
)

0 commit comments

Comments
 (0)