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