From 6ecda979d7979e60b406bf50349615a8e2da4b75 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Fri, 20 Dec 2024 16:37:25 -0500 Subject: [PATCH] lldb: add pretty printer for cau and nav indices --- src/InternPool.zig | 126 +++++++++++++++++++++++----------- tools/lldb_pretty_printers.py | 47 ++++++++++++- 2 files changed, 129 insertions(+), 44 deletions(-) diff --git a/src/InternPool.zig b/src/InternPool.zig index e037c67bba0a..f923332f88e7 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -470,6 +470,8 @@ pub const Cau = struct { _ => @enumFromInt(@intFromEnum(opt)), }; } + + const debug_state = InternPool.debug_state; }; pub fn toOptional(i: Cau.Index) Optional { return @enumFromInt(@intFromEnum(i)); @@ -491,6 +493,8 @@ pub const Cau = struct { .index = @intFromEnum(cau_index) & ip.getIndexMask(u31), }; } + + const debug_state = InternPool.debug_state; }; }; @@ -568,6 +572,8 @@ pub const Nav = struct { _ => @enumFromInt(@intFromEnum(opt)), }; } + + const debug_state = InternPool.debug_state; }; pub fn toOptional(i: Nav.Index) Optional { return @enumFromInt(@intFromEnum(i)); @@ -589,6 +595,8 @@ pub const Nav = struct { .index = @intFromEnum(nav_index) & ip.getIndexMask(u32), }; } + + const debug_state = InternPool.debug_state; }; /// The compact in-memory representation of a `Nav`. @@ -5271,17 +5279,26 @@ pub const Tag = enum(u8) { .type_int_signed = .{ .summary = .@"i{.data%value}", .data = u32 }, .type_int_unsigned = .{ .summary = .@"u{.data%value}", .data = u32 }, - .type_array_big = .{ .summary = .@"[{.payload.len1%value} << 32 | {.payload.len0%value}:{.payload.sentinel%summary}]{.payload.child%summary}", .payload = Array }, + .type_array_big = .{ + .summary = .@"[{.payload.len1%value} << 32 | {.payload.len0%value}:{.payload.sentinel%summary}]{.payload.child%summary}", + .payload = Array, + }, .type_array_small = .{ .summary = .@"[{.payload.len%value}]{.payload.child%summary}", .payload = Vector }, .type_vector = .{ .summary = .@"@Vector({.payload.len%value}, {.payload.child%summary})", .payload = Vector }, .type_pointer = .{ .summary = .@"*... {.payload.child%summary}", .payload = TypePointer }, .type_slice = .{ .summary = .@"[]... {.data.unwrapped.payload.child%summary}", .data = Index }, .type_optional = .{ .summary = .@"?{.data%summary}", .data = Index }, .type_anyframe = .{ .summary = .@"anyframe->{.data%summary}", .data = Index }, - .type_error_union = .{ .summary = .@"{.payload.error_set_type%summary}!{.payload.payload_type%summary}", .payload = ErrorUnionType }, + .type_error_union = .{ + .summary = .@"{.payload.error_set_type%summary}!{.payload.payload_type%summary}", + .payload = ErrorUnionType, + }, .type_anyerror_union = .{ .summary = .@"anyerror!{.data%summary}", .data = Index }, .type_error_set = .{ .summary = .@"error{...}", .payload = ErrorSet }, - .type_inferred_error_set = .{ .summary = .@"@typeInfo(@typeInfo(@TypeOf({.data%summary})).@\"fn\".return_type.?).error_union.error_set", .data = Index }, + .type_inferred_error_set = .{ + .summary = .@"@typeInfo(@typeInfo(@TypeOf({.data%summary})).@\"fn\".return_type.?).error_union.error_set", + .data = Index, + }, .type_enum_auto = .{ .summary = .@"{.payload.name%summary#\"}", .payload = EnumAuto, @@ -5307,12 +5324,8 @@ pub const Tag = enum(u8) { .type_opaque = .{ .summary = .@"{.payload.name%summary#\"}", .payload = TypeOpaque, - .trailing = struct { - captures: []CaptureValue, - }, - .config = .{ - .@"trailing.captures.len" = .@"payload.captures_len", - }, + .trailing = struct { captures: []CaptureValue }, + .config = .{ .@"trailing.captures.len" = .@"payload.captures_len" }, }, .type_struct = .{ .summary = .@"{.payload.name%summary#\"}", @@ -5438,17 +5451,50 @@ pub const Tag = enum(u8) { .undef = .{ .summary = .@"@as({.data%summary}, undefined)", .data = Index }, .simple_value = .{ .summary = .@"{.index%value#.}", .index = SimpleValue }, - .ptr_nav = .{ .payload = PtrNav }, - .ptr_comptime_alloc = .{ .payload = PtrComptimeAlloc }, - .ptr_uav = .{ .payload = PtrUav }, - .ptr_uav_aligned = .{ .payload = PtrUavAligned }, - .ptr_comptime_field = .{ .payload = PtrComptimeField }, - .ptr_int = .{ .payload = PtrInt }, - .ptr_eu_payload = .{ .payload = PtrBase }, - .ptr_opt_payload = .{ .payload = PtrBase }, - .ptr_elem = .{ .payload = PtrBaseIndex }, - .ptr_field = .{ .payload = PtrBaseIndex }, - .ptr_slice = .{ .payload = PtrSlice }, + .ptr_nav = .{ + .summary = .@"@as({.payload.ty%summary}, @ptrFromInt(@intFromPtr(&{.payload.nav.fqn%summary#\"}) + ({.payload.byte_offset_a%value} << 32 | {.payload.byte_offset_b%value})))", + .payload = PtrNav, + }, + .ptr_comptime_alloc = .{ + .summary = .@"@as({.payload.ty%summary}, @ptrFromInt(@intFromPtr(&comptime_allocs[{.payload.index%summary}]) + ({.payload.byte_offset_a%value} << 32 | {.payload.byte_offset_b%value})))", + .payload = PtrComptimeAlloc, + }, + .ptr_uav = .{ + .summary = .@"@as({.payload.ty%summary}, @ptrFromInt(@intFromPtr(&{.payload.val%summary}) + ({.payload.byte_offset_a%value} << 32 | {.payload.byte_offset_b%value})))", + .payload = PtrUav, + }, + .ptr_uav_aligned = .{ + .summary = .@"@as({.payload.ty%summary}, @ptrFromInt(@intFromPtr(@as({.payload.orig_ty%summary}, &{.payload.val%summary})) + ({.payload.byte_offset_a%value} << 32 | {.payload.byte_offset_b%value})))", + .payload = PtrUavAligned, + }, + .ptr_comptime_field = .{ + .summary = .@"@as({.payload.ty%summary}, @ptrFromInt(@intFromPtr(&{.payload.field_val%summary}) + ({.payload.byte_offset_a%value} << 32 | {.payload.byte_offset_b%value})))", + .payload = PtrComptimeField, + }, + .ptr_int = .{ + .summary = .@"@as({.payload.ty%summary}, @ptrFromInt({.payload.byte_offset_a%value} << 32 | {.payload.byte_offset_b%value}))", + .payload = PtrInt, + }, + .ptr_eu_payload = .{ + .summary = .@"@as({.payload.ty%summary}, @ptrFromInt(@intFromPtr(&({.payload.base%summary} catch unreachable)) + ({.payload.byte_offset_a%value} << 32 | {.payload.byte_offset_b%value})))", + .payload = PtrBase, + }, + .ptr_opt_payload = .{ + .summary = .@"@as({.payload.ty%summary}, @ptrFromInt(@intFromPtr(&{.payload.base%summary}.?) + ({.payload.byte_offset_a%value} << 32 | {.payload.byte_offset_b%value})))", + .payload = PtrBase, + }, + .ptr_elem = .{ + .summary = .@"@as({.payload.ty%summary}, @ptrFromInt(@intFromPtr(&{.payload.base%summary}[{.payload.index%summary}]) + ({.payload.byte_offset_a%value} << 32 | {.payload.byte_offset_b%value})))", + .payload = PtrBaseIndex, + }, + .ptr_field = .{ + .summary = .@"@as({.payload.ty%summary}, @ptrFromInt(@intFromPtr(&{.payload.base%summary}[{.payload.index%summary}]) + ({.payload.byte_offset_a%value} << 32 | {.payload.byte_offset_b%value})))", + .payload = PtrBaseIndex, + }, + .ptr_slice = .{ + .summary = .@"{.payload.ptr%summary}[0..{.payload.len%summary}]", + .payload = PtrSlice, + }, .opt_payload = .{ .summary = .@"@as({.payload.ty%summary}, {.payload.val%summary})", .payload = TypeValue }, .opt_null = .{ .summary = .@"@as({.data%summary}, null)", .data = Index }, .int_u8 = .{ .summary = .@"@as(u8, {.data%value})", .data = u8 }, @@ -5476,18 +5522,16 @@ pub const Tag = enum(u8) { .float_c_longdouble_f80 = .{ .summary = .@"@as(c_longdouble, {.payload%value})", .payload = f80 }, .float_c_longdouble_f128 = .{ .summary = .@"@as(c_longdouble, {.payload%value})", .payload = f128 }, .float_comptime_float = .{ .summary = .@"{.payload%value}", .payload = f128 }, - .variable = .{ .payload = Variable }, - .@"extern" = .{ .payload = Extern }, + .variable = .{ .summary = .@"{.payload.owner_nav.fqn%summary#\"}", .payload = Variable }, + .@"extern" = .{ .summary = .@"{.payload.owner_nav.fqn%summary#\"}", .payload = Extern }, .func_decl = .{ + .summary = .@"{.payload.owner_nav.fqn%summary#\"}", .payload = FuncDecl, - .trailing = struct { - inferred_error_set: ?Index, - }, - .config = .{ - .@"trailing.inferred_error_set.?" = .@"payload.analysis.inferred_error_set", - }, + .trailing = struct { inferred_error_set: ?Index }, + .config = .{ .@"trailing.inferred_error_set.?" = .@"payload.analysis.inferred_error_set" }, }, .func_instance = .{ + .summary = .@"{.payload.owner_nav.fqn%summary#\"}", .payload = FuncInstance, .trailing = struct { inferred_error_set: ?Index, @@ -5498,30 +5542,26 @@ pub const Tag = enum(u8) { .@"trailing.param_values.len" = .@"payload.ty.payload.params_len", }, }, - .func_coerced = .{ .payload = FuncCoerced }, + .func_coerced = .{ + .summary = .@"@as(*const {.payload.ty%summary}, @ptrCast(&{.payload.func%summary})).*", + .payload = FuncCoerced, + }, .only_possible_value = .{ .summary = .@"@as({.data%summary}, undefined)", .data = Index }, .union_value = .{ .summary = .@"@as({.payload.ty%summary}, {})", .payload = Union }, .bytes = .{ .summary = .@"@as({.payload.ty%summary}, {.payload.bytes%summary}.*)", .payload = Bytes }, .aggregate = .{ .summary = .@"@as({.payload.ty%summary}, .{...})", .payload = Aggregate, - .trailing = struct { - elements: []Index, - }, - .config = .{ - .@"trailing.elements.len" = .@"payload.ty.payload.fields_len", - }, + .trailing = struct { elements: []Index }, + .config = .{ .@"trailing.elements.len" = .@"payload.ty.payload.fields_len" }, }, .repeated = .{ .summary = .@"@as({.payload.ty%summary}, @splat({.payload.elem_val%summary}))", .payload = Repeated }, .memoized_call = .{ + .summary = .@"@memoize({.payload.func%summary})", .payload = MemoizedCall, - .trailing = struct { - arg_values: []Index, - }, - .config = .{ - .@"trailing.arg_values.len" = .@"payload.args_len", - }, + .trailing = struct { arg_values: []Index }, + .config = .{ .@"trailing.arg_values.len" = .@"payload.args_len" }, }, }; fn Payload(comptime tag: Tag) type { @@ -6490,6 +6530,10 @@ pub fn activate(ip: *const InternPool) void { _ = OptionalString.debug_state; _ = NullTerminatedString.debug_state; _ = OptionalNullTerminatedString.debug_state; + _ = Cau.Index.debug_state; + _ = Cau.Index.Optional.debug_state; + _ = Nav.Index.debug_state; + _ = Nav.Index.Optional.debug_state; std.debug.assert(debug_state.intern_pool == null); debug_state.intern_pool = ip; } diff --git a/tools/lldb_pretty_printers.py b/tools/lldb_pretty_printers.py index 68086fd62220..acfebb5b76e1 100644 --- a/tools/lldb_pretty_printers.py +++ b/tools/lldb_pretty_printers.py @@ -731,6 +731,7 @@ def get_child_at_index(self, index): expr_path_re = re.compile(r'\{([^}]+)%([^%#}]+)(?:#([^%#}]+))?\}') def root_InternPool_Index_SummaryProvider(value, _=None): unwrapped = value.GetChildMemberWithName('unwrapped') + if not unwrapped: return '' # .none tag = unwrapped.GetChildMemberWithName('tag') tag_value = tag.value summary = tag.CreateValueFromType(tag.type).GetChildMemberWithName('encodings').GetChildMemberWithName(tag_value.removeprefix('.')).GetChildMemberWithName('summary') @@ -749,8 +750,8 @@ def update(self): if wrapped == (1 << 32) - 1: return unwrapped_type = self.value.type.FindDirectNestedType('Unwrapped') ip = self.value.CreateValueFromType(unwrapped_type).GetChildMemberWithName('debug_state').GetChildMemberWithName('intern_pool').GetNonSyntheticValue().GetChildMemberWithName('?') - tid_width, tid_shift_30 = ip.GetChildMemberWithName('tid_width').unsigned, ip.GetChildMemberWithName('tid_shift_30').unsigned - self.unwrapped = create_struct(self.value, '.unwrapped', unwrapped_type, { 'tid': wrapped >> tid_shift_30 & (1 << tid_width) - 1, 'index': wrapped & (1 << tid_shift_30) - 1 }) + tid_shift_30 = ip.GetChildMemberWithName('tid_shift_30').unsigned + self.unwrapped = create_struct(self.value, '.unwrapped', unwrapped_type, { 'tid': wrapped >> tid_shift_30, 'index': wrapped & (1 << tid_shift_30) - 1 }) def has_children(self): return True def num_children(self): return 0 def get_child_index(self, name): @@ -870,9 +871,9 @@ def get_child_at_index(self, index): except: pass def root_InternPool_String_SummaryProvider(value, _=None): + wrapped = value.unsigned ip = value.CreateValueFromType(value.type).GetChildMemberWithName('debug_state').GetChildMemberWithName('intern_pool').GetNonSyntheticValue().GetChildMemberWithName('?') tid_shift_32 = ip.GetChildMemberWithName('tid_shift_32').unsigned - wrapped = value.unsigned locals_value = ip.GetChildMemberWithName('locals').GetSyntheticValue() local_value = locals_value.child[wrapped >> tid_shift_32] if local_value is None: @@ -882,6 +883,44 @@ def root_InternPool_String_SummaryProvider(value, _=None): string.format = lldb.eFormatCString return string.value +class root_InternPool_Cau_Index_SynthProvider: + def __init__(self, value, _=None): self.value = value + def update(self): + self.cau = None + wrapped = self.value.unsigned + if wrapped == (1 << 32) - 1: return + ip = self.value.CreateValueFromType(self.value.type).GetChildMemberWithName('debug_state').GetChildMemberWithName('intern_pool').GetNonSyntheticValue().GetChildMemberWithName('?') + tid_shift_31 = ip.GetChildMemberWithName('tid_shift_31').unsigned + locals_value = ip.GetChildMemberWithName('locals').GetSyntheticValue() + local_value = locals_value.child[wrapped >> tid_shift_31] + if local_value is None: + wrapped = 0 + local_value = locals_value.child[0] + self.cau = local_value.GetChildMemberWithName('shared').GetChildMemberWithName('caus').GetChildMemberWithName('view').GetChildMemberWithName('0').child[wrapped & (1 << tid_shift_31) - 1] + def has_children(self): return self.cau.GetNumChildren(1) > 0 + def num_children(self): return self.cau.GetNumChildren() + def get_child_index(self, name): return self.cau.GetIndexOfChildWithName(name) + def get_child_at_index(self, index): return self.cau.GetChildAtIndex(index) + +class root_InternPool_Nav_Index_SynthProvider: + def __init__(self, value, _=None): self.value = value + def update(self): + self.nav = None + wrapped = self.value.unsigned + if wrapped == (1 << 32) - 1: return + ip = self.value.CreateValueFromType(self.value.type).GetChildMemberWithName('debug_state').GetChildMemberWithName('intern_pool').GetNonSyntheticValue().GetChildMemberWithName('?') + tid_shift_32 = ip.GetChildMemberWithName('tid_shift_32').unsigned + locals_value = ip.GetChildMemberWithName('locals').GetSyntheticValue() + local_value = locals_value.child[wrapped >> tid_shift_32] + if local_value is None: + wrapped = 0 + local_value = locals_value.child[0] + self.nav = local_value.GetChildMemberWithName('shared').GetChildMemberWithName('navs').GetChildMemberWithName('view').child[wrapped & (1 << tid_shift_32) - 1] + def has_children(self): return self.nav.GetNumChildren(1) > 0 + def num_children(self): return self.nav.GetNumChildren() + def get_child_index(self, name): return self.nav.GetIndexOfChildWithName(name) + def get_child_at_index(self, index): return self.nav.GetChildAtIndex(index) + # Initialize def add(debugger, *, category, regex=False, type, identifier=None, synth=False, inline_children=False, expand=False, summary=False): @@ -937,3 +976,5 @@ def __lldb_init_module(debugger, _=None): add(debugger, category='zig', type='root.InternPool.Index', synth=True, summary=True) add(debugger, category='zig', type='root.InternPool.Index.Unwrapped', synth=True) add(debugger, category='zig', regex=True, type=r'^root\.InternPool\.(Optional)?(NullTerminated)?String$', identifier='root_InternPool_String', summary=True) + add(debugger, category='zig', regex=True, type=r'^root\.InternPool\.Cau\.Index(\.Optional)?$', identifier='root_InternPool_Cau_Index', synth=True) + add(debugger, category='zig', regex=True, type=r'^root\.InternPool\.Nav\.Index(\.Optional)?$', identifier='root_InternPool_Nav_Index', synth=True)