| ... | ... | @@ -7,10 +7,28 @@ |
| 7 | 7 | import lldb |
| 8 | 8 | import re |
| 9 | 9 | |
| 10 | # Helpers |
| 11 | |
| 10 | 12 | page_size = 1 << 12 |
| 11 | 13 | |
| 12 | 14 | def log2_int(i): return i.bit_length() - 1 |
| 13 | 15 | |
| 16 | def create_struct(name, struct_type, **inits): |
| 17 | struct_bytes = bytearray(struct_type.size) |
| 18 | struct_data = lldb.SBData() |
| 19 | for field in struct_type.fields: |
| 20 | field_size = field.type.size |
| 21 | field_bytes = inits[field.name].data.uint8[:field_size] |
| 22 | match struct_data.byte_order: |
| 23 | case lldb.eByteOrderLittle: |
| 24 | field_start = field.byte_offset |
| 25 | struct_bytes[field_start:field_start + len(field_bytes)] = field_bytes |
| 26 | case lldb.eByteOrderBig: |
| 27 | field_end = field.byte_offset + field_size |
| 28 | struct_bytes[field_end - len(field_bytes):field_end] = field_bytes |
| 29 | struct_data.SetData(lldb.SBError(), struct_bytes, struct_data.byte_order, struct_data.GetAddressByteSize()) |
| 30 | return next(iter(inits.values())).CreateValueFromData(name, struct_data, struct_type) |
| 31 | |
| 14 | 32 | # Define Zig Language |
| 15 | 33 | |
| 16 | 34 | zig_keywords = { |
| ... | ... | @@ -678,6 +696,22 @@ value_tag_handlers = { |
| 678 | 696 | 'lazy_size': lambda payload: '@sizeOf(%s)' % type_Type_SummaryProvider(payload), |
| 679 | 697 | } |
| 680 | 698 | |
| 699 | # Define Zig Stage2 Compiler (compiled with the self-hosted backend) |
| 700 | |
| 701 | class root_InternPool_Local_List_SynthProvider: |
| 702 | def __init__(self, value, _=None): self.value = value |
| 703 | def update(self): |
| 704 | capacity = self.value.EvaluateExpression('@as(*@This().Header, @alignCast(@ptrCast(@this().bytes - @This().bytes_offset))).capacity') |
| 705 | self.view = create_struct('view', self.value.EvaluateExpression('@This().View').GetValueAsType(), bytes=self.value.GetChildMemberWithName('bytes'), len=capacity, capacity=capacity).GetNonSyntheticValue() |
| 706 | def has_children(self): return True |
| 707 | def num_children(self): return 1 |
| 708 | def get_child_index(self, name): |
| 709 | try: return ('view',).index(name) |
| 710 | except: pass |
| 711 | def get_child_at_index(self, index): |
| 712 | try: return (self.view,)[index] |
| 713 | except: pass |
| 714 | |
| 681 | 715 | # Initialize |
| 682 | 716 | |
| 683 | 717 | def add(debugger, *, category, regex=False, type, identifier=None, synth=False, inline_children=False, expand=False, summary=False): |
| ... | ... | @@ -729,3 +763,6 @@ def __lldb_init_module(debugger, _=None): |
| 729 | 763 | add(debugger, category='zig.stage2', type='InternPool.Key.Ptr.Addr', identifier='zig_TaggedUnion', synth=True) |
| 730 | 764 | add(debugger, category='zig.stage2', type='InternPool.Key.Aggregate.Storage', identifier='zig_TaggedUnion', synth=True) |
| 731 | 765 | add(debugger, category='zig.stage2', type='arch.x86_64.CodeGen.MCValue', identifier='zig_TaggedUnion', synth=True, inline_children=True, summary=True) |
| 766 | |
| 767 | # Initialize Zig Stage2 Compiler (compiled with the self-hosted backend) |
| 768 | add(debugger, category='zig', regex=True, type='^root\\.InternPool\\.Local\\.List\\(.*\\)$', identifier='root_InternPool_Local_List', synth=True, expand=True, summary='capacity=${var%#}') |