Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / examples / summaries / sp_cp.py
blob549ab27f9066fb628c0709b49e6939daa917b8a1
1 """
2 Summary and synthetic providers for LLDB-specific shared pointers
4 Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 See https://llvm.org/LICENSE.txt for license information.
6 SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 """
10 class SharedPtr_SyntheticChildrenProvider:
11 def __init__(self, valobj, dict):
12 self.valobj = valobj
13 self.update()
15 def update(self):
16 pass
18 def num_children(self):
19 return 1
21 def get_child_index(self, name):
22 if name == "ptr":
23 return 0
24 if name == "count":
25 return 1
26 return None
28 def get_child_at_index(self, index):
29 if index == 0:
30 return self.valobj.GetChildMemberWithName("_M_ptr")
31 if index == 1:
32 return (
33 self.valobj.GetChildMemberWithName("_M_refcount")
34 .GetChildMemberWithName("_M_pi")
35 .GetChildMemberWithName("_M_use_count")
37 return None
40 def SharedPtr_SummaryProvider(valobj, dict):
41 return "use = " + str(valobj.GetChildMemberWithName("count").GetValueAsUnsigned())
44 class ValueObjectSP_SyntheticChildrenProvider:
45 def __init__(self, valobj, dict):
46 self.valobj = valobj
47 self.update()
49 def update(self):
50 pass
52 def num_children(self):
53 return 1
55 def get_child_index(self, name):
56 if name == "ptr":
57 return 0
58 if name == "count":
59 return 1
60 return None
62 def get_child_at_index(self, index):
63 if index == 0:
64 return self.valobj.GetChildMemberWithName("ptr_")
65 if index == 1:
66 return self.valobj.GetChildMemberWithName("cntrl_").GetChildMemberWithName(
67 "shared_owners_"
69 return None
72 def ValueObjectSP_SummaryProvider(valobj, dict):
73 return "use = " + str(
74 1 + valobj.GetChildMemberWithName("count").GetValueAsUnsigned()
78 def __lldb_init_module(debugger, dict):
79 debugger.HandleCommand(
80 'type summary add -x ".*ValueObjectSP" --expand -F sp_cp.ValueObjectSP_SummaryProvider'
82 debugger.HandleCommand(
83 'type synthetic add -x ".*ValueObjectSP" -l sp_cp.ValueObjectSP_SyntheticChildrenProvider'
85 debugger.HandleCommand(
86 'type summary add -x ".*SP" --expand -F sp_cp.SharedPtr_SummaryProvider'
88 debugger.HandleCommand(
89 'type synthetic add -x ".*SP" -l sp_cp.SharedPtr_SyntheticChildrenProvider'