| ... | @@ -3,13 +3,55 @@ | ... | @@ -3,13 +3,55 @@ |
| 3 | import re | 3 | import re |
| 4 | import gdb.printing | 4 | import gdb.printing |
| 5 | | 5 | |
| 6 | import sys | | |
| 7 | from pathlib import Path | | |
| 8 | sys.path.insert(0, str(Path(__file__).parent)) | | |
| 9 | import stage2_pretty_printers_common as common | | |
| 10 | | | |
| 11 | | | |
| 12 | class TypePrinter: | 6 | class TypePrinter: |
| | 7 | no_payload_count = 4096 |
| | 8 | |
| | 9 | # Keep in sync with src/type.zig |
| | 10 | # Types which have no payload do not need to be entered here. |
| | 11 | payload_type_names = { |
| | 12 | 'array_u8': 'Type.Payload.Len', |
| | 13 | 'array_u8_sentinel_0': 'Type.Payload.Len', |
| | 14 | |
| | 15 | 'single_const_pointer': 'Type.Payload.ElemType', |
| | 16 | 'single_mut_pointer': 'Type.Payload.ElemType', |
| | 17 | 'many_const_pointer': 'Type.Payload.ElemType', |
| | 18 | 'many_mut_pointer': 'Type.Payload.ElemType', |
| | 19 | 'c_const_pointer': 'Type.Payload.ElemType', |
| | 20 | 'c_mut_pointer': 'Type.Payload.ElemType', |
| | 21 | 'const_slice': 'Type.Payload.ElemType', |
| | 22 | 'mut_slice': 'Type.Payload.ElemType', |
| | 23 | 'optional': 'Type.Payload.ElemType', |
| | 24 | 'optional_single_mut_pointer': 'Type.Payload.ElemType', |
| | 25 | 'optional_single_const_pointer': 'Type.Payload.ElemType', |
| | 26 | 'anyframe_T': 'Type.Payload.ElemType', |
| | 27 | |
| | 28 | 'int_signed': 'Type.Payload.Bits', |
| | 29 | 'int_unsigned': 'Type.Payload.Bits', |
| | 30 | |
| | 31 | 'error_set': 'Type.Payload.ErrorSet', |
| | 32 | 'error_set_inferred': 'Type.Payload.ErrorSetInferred', |
| | 33 | 'error_set_merged': 'Type.Payload.ErrorSetMerged', |
| | 34 | |
| | 35 | 'array': 'Type.Payload.Array', |
| | 36 | 'vector': 'Type.Payload.Array', |
| | 37 | |
| | 38 | 'array_sentinel': 'Type.Payload.ArraySentinel', |
| | 39 | 'pointer': 'Type.Payload.Pointer', |
| | 40 | 'function': 'Type.Payload.Function', |
| | 41 | 'error_union': 'Type.Payload.ErrorUnion', |
| | 42 | 'error_set_single': 'Type.Payload.Name', |
| | 43 | 'opaque': 'Type.Payload.Opaque', |
| | 44 | 'struct': 'Type.Payload.Struct', |
| | 45 | 'union': 'Type.Payload.Union', |
| | 46 | 'union_tagged': 'Type.Payload.Union', |
| | 47 | 'enum_full, .enum_nonexhaustive': 'Type.Payload.EnumFull', |
| | 48 | 'enum_simple': 'Type.Payload.EnumSimple', |
| | 49 | 'enum_numbered': 'Type.Payload.EnumNumbered', |
| | 50 | 'empty_struct': 'Type.Payload.ContainerScope', |
| | 51 | 'tuple': 'Type.Payload.Tuple', |
| | 52 | 'anon_struct': 'Type.Payload.AnonStruct', |
| | 53 | } |
| | 54 | |
| 13 | def __init__(self, val): | 55 | def __init__(self, val): |
| 14 | self.val = val | 56 | self.val = val |
| 15 | | 57 | |
| ... | @@ -17,7 +59,7 @@ class TypePrinter: | ... | @@ -17,7 +59,7 @@ class TypePrinter: |
| 17 | tag_if_small_enough = self.val['tag_if_small_enough'] | 59 | tag_if_small_enough = self.val['tag_if_small_enough'] |
| 18 | tag_type = tag_if_small_enough.type | 60 | tag_type = tag_if_small_enough.type |
| 19 | | 61 | |
| 20 | if tag_if_small_enough < common.Type.no_payload_count: | 62 | if tag_if_small_enough < TypePrinter.no_payload_count: |
| 21 | return tag_if_small_enough | 63 | return tag_if_small_enough |
| 22 | else: | 64 | else: |
| 23 | return self.val['ptr_otherwise'].dereference()['tag'] | 65 | return self.val['ptr_otherwise'].dereference()['tag'] |
| ... | @@ -27,7 +69,7 @@ class TypePrinter: | ... | @@ -27,7 +69,7 @@ class TypePrinter: |
| 27 | if tag is None: | 69 | if tag is None: |
| 28 | return None | 70 | return None |
| 29 | | 71 | |
| 30 | type_name = common.Type.payload_type_names.get(str(tag)) | 72 | type_name = TypePrinter.payload_type_names.get(str(tag)) |
| 31 | if type_name is None: | 73 | if type_name is None: |
| 32 | return None | 74 | return None |
| 33 | return gdb.lookup_type('struct type.%s' % type_name) | 75 | return gdb.lookup_type('struct type.%s' % type_name) |
| ... | @@ -36,12 +78,12 @@ class TypePrinter: | ... | @@ -36,12 +78,12 @@ class TypePrinter: |
| 36 | tag = self.tag() | 78 | tag = self.tag() |
| 37 | if tag is None: | 79 | if tag is None: |
| 38 | return '(invalid type)' | 80 | return '(invalid type)' |
| 39 | if self.val['tag_if_small_enough'] < common.Type.no_payload_count: | 81 | if self.val['tag_if_small_enough'] < TypePrinter.no_payload_count: |
| 40 | return '.%s' % str(tag) | 82 | return '.%s' % str(tag) |
| 41 | return None | 83 | return None |
| 42 | | 84 | |
| 43 | def children(self): | 85 | def children(self): |
| 44 | if self.val['tag_if_small_enough'] < common.Type.no_payload_count: | 86 | if self.val['tag_if_small_enough'] < TypePrinter.no_payload_count: |
| 45 | return | 87 | return |
| 46 | | 88 | |
| 47 | yield ('tag', '.%s' % str(self.tag())) | 89 | yield ('tag', '.%s' % str(self.tag())) |
| ... | @@ -51,6 +93,55 @@ class TypePrinter: | ... | @@ -51,6 +93,55 @@ class TypePrinter: |
| 51 | yield ('payload', self.val['ptr_otherwise'].cast(payload_type.pointer()).dereference()['data']) | 93 | yield ('payload', self.val['ptr_otherwise'].cast(payload_type.pointer()).dereference()['data']) |
| 52 | | 94 | |
| 53 | class ValuePrinter: | 95 | class ValuePrinter: |
| | 96 | no_payload_count = 4096 |
| | 97 | |
| | 98 | # Keep in sync with src/value.zig |
| | 99 | # Values which have no payload do not need to be entered here. |
| | 100 | payload_type_names = { |
| | 101 | 'big_int_positive': 'Value.Payload.BigInt', |
| | 102 | 'big_int_negative': 'Value.Payload.BigInt', |
| | 103 | |
| | 104 | 'extern_fn': 'Value.Payload.ExternFn', |
| | 105 | |
| | 106 | 'decl_ref': 'Value.Payload.Decl', |
| | 107 | |
| | 108 | 'repeated': 'Value.Payload.SubValue', |
| | 109 | 'eu_payload': 'Value.Payload.SubValue', |
| | 110 | 'opt_payload': 'Value.Payload.SubValue', |
| | 111 | 'empty_array_sentinel': 'Value.Payload.SubValue', |
| | 112 | |
| | 113 | 'eu_payload_ptr': 'Value.Payload.PayloadPtr', |
| | 114 | 'opt_payload_ptr': 'Value.Payload.PayloadPtr', |
| | 115 | |
| | 116 | 'bytes': 'Value.Payload.Bytes', |
| | 117 | 'enum_literal': 'Value.Payload.Bytes', |
| | 118 | |
| | 119 | 'slice': 'Value.Payload.Slice', |
| | 120 | |
| | 121 | 'enum_field_index': 'Value.Payload.U32', |
| | 122 | |
| | 123 | 'ty': 'Value.Payload.Ty', |
| | 124 | 'int_type': 'Value.Payload.IntType', |
| | 125 | 'int_u64': 'Value.Payload.U64', |
| | 126 | 'int_i64': 'Value.Payload.I64', |
| | 127 | 'function': 'Value.Payload.Function', |
| | 128 | 'variable': 'Value.Payload.Variable', |
| | 129 | 'decl_ref_mut': 'Value.Payload.DeclRefMut', |
| | 130 | 'elem_ptr': 'Value.Payload.ElemPtr', |
| | 131 | 'field_ptr': 'Value.Payload.FieldPtr', |
| | 132 | 'float_16': 'Value.Payload.Float_16', |
| | 133 | 'float_32': 'Value.Payload.Float_32', |
| | 134 | 'float_64': 'Value.Payload.Float_64', |
| | 135 | 'float_80': 'Value.Payload.Float_80', |
| | 136 | 'float_128': 'Value.Payload.Float_128', |
| | 137 | 'error': 'Value.Payload.Error', |
| | 138 | 'inferred_alloc': 'Value.Payload.InferredAlloc', |
| | 139 | 'inferred_alloc_comptime': 'Value.Payload.InferredAllocComptime', |
| | 140 | 'aggregate': 'Value.Payload.Aggregate', |
| | 141 | 'union': 'Value.Payload.Union', |
| | 142 | 'bound_fn': 'Value.Payload.BoundFn', |
| | 143 | } |
| | 144 | |
| 54 | def __init__(self, val): | 145 | def __init__(self, val): |
| 55 | self.val = val | 146 | self.val = val |
| 56 | | 147 | |
| ... | @@ -58,7 +149,7 @@ class ValuePrinter: | ... | @@ -58,7 +149,7 @@ class ValuePrinter: |
| 58 | tag_if_small_enough = self.val['tag_if_small_enough'] | 149 | tag_if_small_enough = self.val['tag_if_small_enough'] |
| 59 | tag_type = tag_if_small_enough.type | 150 | tag_type = tag_if_small_enough.type |
| 60 | | 151 | |
| 61 | if tag_if_small_enough < common.Value.no_payload_count: | 152 | if tag_if_small_enough < ValuePrinter.no_payload_count: |
| 62 | return tag_if_small_enough | 153 | return tag_if_small_enough |
| 63 | else: | 154 | else: |
| 64 | return self.val['ptr_otherwise'].dereference()['tag'] | 155 | return self.val['ptr_otherwise'].dereference()['tag'] |
| ... | @@ -68,7 +159,7 @@ class ValuePrinter: | ... | @@ -68,7 +159,7 @@ class ValuePrinter: |
| 68 | if tag is None: | 159 | if tag is None: |
| 69 | return None | 160 | return None |
| 70 | | 161 | |
| 71 | type_name = Comman.Value.payload_type_names.get(str(tag)) | 162 | type_name = ValuePrinter.payload_type_names.get(str(tag)) |
| 72 | if type_name is None: | 163 | if type_name is None: |
| 73 | return None | 164 | return None |
| 74 | return gdb.lookup_type('struct value.%s' % type_name) | 165 | return gdb.lookup_type('struct value.%s' % type_name) |
| ... | @@ -77,12 +168,12 @@ class ValuePrinter: | ... | @@ -77,12 +168,12 @@ class ValuePrinter: |
| 77 | tag = self.tag() | 168 | tag = self.tag() |
| 78 | if tag is None: | 169 | if tag is None: |
| 79 | return '(invalid value)' | 170 | return '(invalid value)' |
| 80 | if self.val['tag_if_small_enough'] < common.Value.no_payload_count: | 171 | if self.val['tag_if_small_enough'] < ValuePrinter.no_payload_count: |
| 81 | return '.%s' % str(tag) | 172 | return '.%s' % str(tag) |
| 82 | return None | 173 | return None |
| 83 | | 174 | |
| 84 | def children(self): | 175 | def children(self): |
| 85 | if self.val['tag_if_small_enough'] < common.Value.no_payload_count: | 176 | if self.val['tag_if_small_enough'] < ValuePrinter.no_payload_count: |
| 86 | return | 177 | return |
| 87 | | 178 | |
| 88 | yield ('tag', '.%s' % str(self.tag())) | 179 | yield ('tag', '.%s' % str(self.tag())) |