From a3529c2dea579e0a15dcde1b8ee71d9ec9c75330 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Sun, 26 Feb 2023 22:11:41 -0500 Subject: tools: implement more lldb pretty printers --- src/value.zig | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/value.zig') diff --git a/src/value.zig b/src/value.zig index 5646a837ad..4a5683df36 100644 --- a/src/value.zig +++ b/src/value.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const Type = @import("type.zig").Type; const log2 = std.math.log2; const assert = std.debug.assert; @@ -5584,6 +5585,35 @@ pub const Value = extern union { ri.* = @intToEnum(RuntimeIndex, @enumToInt(ri.*) + 1); } }; + + /// This function is used in the debugger pretty formatters in tools/ to fetch the + /// Tag to Payload mapping to facilitate fancy debug printing for this type. + fn dbHelper(self: *Value, tag_to_payload_map: *map: { + const tags = @typeInfo(Tag).Enum.fields; + var fields: [tags.len]std.builtin.Type.StructField = undefined; + for (&fields, tags) |*field, t| field.* = .{ + .name = t.name, + .type = *if (t.value < Tag.no_payload_count) void else @field(Tag, t.name).Type(), + .default_value = null, + .is_comptime = false, + .alignment = 0, + }; + break :map @Type(.{ .Struct = .{ + .layout = .Extern, + .fields = &fields, + .decls = &.{}, + .is_tuple = false, + } }); + }) void { + _ = self; + _ = tag_to_payload_map; + } + + comptime { + if (builtin.mode == .Debug) { + _ = dbHelper; + } + } }; var negative_one_payload: Value.Payload.I64 = .{ -- cgit v1.2.3