1import lldb
2
3
4class PythonObjectSyntheticChildProvider(object):
5
6    def __init__(self, value, internal_dict):
7        self.value = value
8        self.values = self.make_children()
9        self.built_values = {}
10        self.bo = self.value.target.byte_order
11        self.ps = self.value.target.addr_size
12
13    def make_children(self):
14        pass
15
16    def num_children(self):
17        return len(self.values)
18
19    def get_child_index(self, name):
20        i = 0
21        for N, value in self.values:
22            if N == name:
23                return i
24            i += 1
25        return None
26
27    def update(self):
28        pass
29
30    def has_children(self):
31        return len(self.values) > 0
32
33    def gen_child(self, name, value):
34        data = None
35        type = None
36        import six
37        if isinstance(value, six.integer_types):
38            data = lldb.SBData.CreateDataFromUInt64Array(
39                self.bo, self.ps, [value])
40            type = self.value.target.GetBasicType(lldb.eBasicTypeLong)
41        elif isinstance(value, float):
42            data = lldb.SBData.CreateDataFromDoubleArray(
43                self.bo, self.ps, [value])
44            type = self.value.target.GetBasicType(lldb.eBasicTypeDouble)
45        elif isinstance(value, str):
46            data = lldb.SBData.CreateDataFromCString(self.bo, self.ps, value)
47            type = self.value.target.GetBasicType(
48                lldb.eBasicTypeChar).GetArrayType(
49                len(value))
50        if (data is not None) and (type is not None):
51            return self.value.CreateValueFromData(name, data, type)
52        return None
53
54    def get_child_at_index(self, index):
55        if index in self.built_values:
56            return self.built_values[index]
57
58        bv = None
59
60        name, value = self.values[index]
61        bv = self.gen_child(name, value)
62        self.built_values[index] = bv
63        return bv
64