1import lldb
2
3
4class jasSynthProvider:
5
6    def __init__(self, valobj, dict):
7        self.valobj = valobj
8
9    def num_children(self):
10        return 2
11
12    def get_child_at_index(self, index):
13        child = None
14        if index == 0:
15            child = self.valobj.GetChildMemberWithName('A')
16        if index == 1:
17            child = self.valobj.CreateValueFromExpression('X', '(int)1')
18        return child
19
20    def get_child_index(self, name):
21        if name == 'A':
22            return 0
23        if name == 'X':
24            return 1
25        return None
26
27
28def ccc_summary(sbvalue, internal_dict):
29    sbvalue = sbvalue.GetNonSyntheticValue()
30    # This tests that the SBValue.GetNonSyntheticValue() actually returns a
31    # non-synthetic value. If it does not, then sbvalue.GetChildMemberWithName("a")
32    # in the following statement will call the 'get_child_index' method of the
33    # synthetic child provider CCCSynthProvider below (which raises an
34    # exception).
35    return "CCC object with leading value " + \
36        str(sbvalue.GetChildMemberWithName("a"))
37
38
39class CCCSynthProvider(object):
40
41    def __init__(self, sbvalue, internal_dict):
42        self._sbvalue = sbvalue
43
44    def num_children(self):
45        return 3
46
47    def get_child_index(self, name):
48        raise RuntimeError("I don't want to be called!")
49
50    def get_child_at_index(self, index):
51        if index == 0:
52            return self._sbvalue.GetChildMemberWithName("a")
53        if index == 1:
54            return self._sbvalue.GetChildMemberWithName("b")
55        if index == 2:
56            return self._sbvalue.GetChildMemberWithName("c")
57
58
59def empty1_summary(sbvalue, internal_dict):
60    return "I am an empty Empty1"
61
62
63class Empty1SynthProvider(object):
64
65    def __init__(self, sbvalue, internal_dict):
66        self._sbvalue = sbvalue
67
68    def num_children(self):
69        return 0
70
71    def get_child_at_index(self, index):
72        return None
73
74
75def empty2_summary(sbvalue, internal_dict):
76    return "I am an empty Empty2"
77
78
79class Empty2SynthProvider(object):
80
81    def __init__(self, sbvalue, internal_dict):
82        self._sbvalue = sbvalue
83
84    def num_children(self):
85        return 0
86
87    def get_child_at_index(self, index):
88        return None
89
90
91def __lldb_init_module(debugger, dict):
92    debugger.CreateCategory("JASSynth").AddTypeSynthetic(
93        lldb.SBTypeNameSpecifier("JustAStruct"),
94        lldb.SBTypeSynthetic.CreateWithClassName("synth.jasSynthProvider"))
95    cat = debugger.CreateCategory("CCCSynth")
96    cat.AddTypeSynthetic(
97        lldb.SBTypeNameSpecifier("CCC"),
98        lldb.SBTypeSynthetic.CreateWithClassName("synth.CCCSynthProvider",
99                                                 lldb.eTypeOptionCascade))
100    cat.AddTypeSummary(
101        lldb.SBTypeNameSpecifier("CCC"),
102        lldb.SBTypeSummary.CreateWithFunctionName("synth.ccc_summary",
103                                                  lldb.eTypeOptionCascade))
104    cat.AddTypeSynthetic(
105        lldb.SBTypeNameSpecifier("Empty1"),
106        lldb.SBTypeSynthetic.CreateWithClassName("synth.Empty1SynthProvider"))
107    cat.AddTypeSummary(
108        lldb.SBTypeNameSpecifier("Empty1"),
109        lldb.SBTypeSummary.CreateWithFunctionName("synth.empty1_summary"))
110    cat.AddTypeSynthetic(
111        lldb.SBTypeNameSpecifier("Empty2"),
112        lldb.SBTypeSynthetic.CreateWithClassName("synth.Empty2SynthProvider"))
113    cat.AddTypeSummary(
114        lldb.SBTypeNameSpecifier("Empty2"),
115        lldb.SBTypeSummary.CreateWithFunctionName(
116            "synth.empty2_summary",
117            lldb.eTypeOptionHideEmptyAggregates))
118