xref: /openbsd-src/gnu/llvm/lldb/examples/summaries/sp_cp.py (revision 061da546b983eb767bad15e67af1174fb0bcf31c)
1*061da546Spatrick"""
2*061da546SpatrickSummary and synthetic providers for LLDB-specific shared pointers
3*061da546Spatrick
4*061da546SpatrickPart of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*061da546SpatrickSee https://llvm.org/LICENSE.txt for license information.
6*061da546SpatrickSPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7*061da546Spatrick"""
8*061da546Spatrick
9*061da546Spatrick
10*061da546Spatrickclass SharedPtr_SyntheticChildrenProvider:
11*061da546Spatrick
12*061da546Spatrick    def __init__(self, valobj, dict):
13*061da546Spatrick        self.valobj = valobj
14*061da546Spatrick        self.update()
15*061da546Spatrick
16*061da546Spatrick    def update(self):
17*061da546Spatrick        pass
18*061da546Spatrick
19*061da546Spatrick    def num_children(self):
20*061da546Spatrick        return 1
21*061da546Spatrick
22*061da546Spatrick    def get_child_index(self, name):
23*061da546Spatrick        if name == "ptr":
24*061da546Spatrick            return 0
25*061da546Spatrick        if name == "count":
26*061da546Spatrick            return 1
27*061da546Spatrick        return None
28*061da546Spatrick
29*061da546Spatrick    def get_child_at_index(self, index):
30*061da546Spatrick        if index == 0:
31*061da546Spatrick            return self.valobj.GetChildMemberWithName('_M_ptr')
32*061da546Spatrick        if index == 1:
33*061da546Spatrick            return self.valobj.GetChildMemberWithName('_M_refcount').GetChildMemberWithName(
34*061da546Spatrick                '_M_pi').GetChildMemberWithName('_M_use_count')
35*061da546Spatrick        return None
36*061da546Spatrick
37*061da546Spatrick
38*061da546Spatrickdef SharedPtr_SummaryProvider(valobj, dict):
39*061da546Spatrick    return 'use = ' + \
40*061da546Spatrick        str(valobj.GetChildMemberWithName("count").GetValueAsUnsigned())
41*061da546Spatrick
42*061da546Spatrick
43*061da546Spatrickclass ValueObjectSP_SyntheticChildrenProvider:
44*061da546Spatrick
45*061da546Spatrick    def __init__(self, valobj, dict):
46*061da546Spatrick        self.valobj = valobj
47*061da546Spatrick        self.update()
48*061da546Spatrick
49*061da546Spatrick    def update(self):
50*061da546Spatrick        pass
51*061da546Spatrick
52*061da546Spatrick    def num_children(self):
53*061da546Spatrick        return 1
54*061da546Spatrick
55*061da546Spatrick    def get_child_index(self, name):
56*061da546Spatrick        if name == "ptr":
57*061da546Spatrick            return 0
58*061da546Spatrick        if name == "count":
59*061da546Spatrick            return 1
60*061da546Spatrick        return None
61*061da546Spatrick
62*061da546Spatrick    def get_child_at_index(self, index):
63*061da546Spatrick        if index == 0:
64*061da546Spatrick            return self.valobj.GetChildMemberWithName('ptr_')
65*061da546Spatrick        if index == 1:
66*061da546Spatrick            return self.valobj.GetChildMemberWithName(
67*061da546Spatrick                'cntrl_').GetChildMemberWithName('shared_owners_')
68*061da546Spatrick        return None
69*061da546Spatrick
70*061da546Spatrick
71*061da546Spatrickdef ValueObjectSP_SummaryProvider(valobj, dict):
72*061da546Spatrick    return 'use = ' + \
73*061da546Spatrick        str(1 + valobj.GetChildMemberWithName("count").GetValueAsUnsigned())
74*061da546Spatrick
75*061da546Spatrick
76*061da546Spatrickdef __lldb_init_module(debugger, dict):
77*061da546Spatrick    debugger.HandleCommand(
78*061da546Spatrick        'type summary add -x ".*ValueObjectSP" --expand -F sp_cp.ValueObjectSP_SummaryProvider')
79*061da546Spatrick    debugger.HandleCommand(
80*061da546Spatrick        'type synthetic add -x ".*ValueObjectSP" -l sp_cp.ValueObjectSP_SyntheticChildrenProvider')
81*061da546Spatrick    debugger.HandleCommand(
82*061da546Spatrick        'type summary add -x ".*SP" --expand -F sp_cp.SharedPtr_SummaryProvider')
83*061da546Spatrick    debugger.HandleCommand(
84*061da546Spatrick        'type synthetic add -x ".*SP" -l sp_cp.SharedPtr_SyntheticChildrenProvider')
85