Enrico Granata | 9123950 | 2012-05-08 19:21:13 +0000 | [diff] [blame] | 1 | """ |
| 2 | Summary and synthetic providers for LLDB-specific shared pointers |
| 3 | |
| 4 | part of The LLVM Compiler Infrastructure |
| 5 | This file is distributed under the University of Illinois Open Source |
| 6 | License. See LICENSE.TXT for details. |
| 7 | """ |
| 8 | |
Enrico Granata | 9123950 | 2012-05-08 19:21:13 +0000 | [diff] [blame] | 9 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10 | class 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 | |
| 38 | def SharedPtr_SummaryProvider(valobj, dict): |
| 39 | return 'use = ' + \ |
| 40 | str(valobj.GetChildMemberWithName("count").GetValueAsUnsigned()) |
| 41 | |
Enrico Granata | 9123950 | 2012-05-08 19:21:13 +0000 | [diff] [blame] | 42 | |
| 43 | class ValueObjectSP_SyntheticChildrenProvider: |
Enrico Granata | 9123950 | 2012-05-08 19:21:13 +0000 | [diff] [blame] | 44 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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 | |
| 71 | def ValueObjectSP_SummaryProvider(valobj, dict): |
| 72 | return 'use = ' + \ |
| 73 | str(1 + valobj.GetChildMemberWithName("count").GetValueAsUnsigned()) |
| 74 | |
Enrico Granata | 9123950 | 2012-05-08 19:21:13 +0000 | [diff] [blame] | 75 | |
| 76 | def __lldb_init_module(debugger, dict): |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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') |