aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2023-02-26 22:11:41 -0500
committerJacob Young <jacobly0@users.noreply.github.com>2023-02-27 05:37:03 -0500
commita3529c2dea579e0a15dcde1b8ee71d9ec9c75330 (patch)
treea06d6819520fbecc5c5c8d64de7739ac528ab280 /src
parent9e519727014fcc484714d8230a0a8bce8744998d (diff)
downloadzig-a3529c2dea579e0a15dcde1b8ee71d9ec9c75330.tar.gz
zig-a3529c2dea579e0a15dcde1b8ee71d9ec9c75330.zip
tools: implement more lldb pretty printers
Diffstat (limited to 'src')
-rw-r--r--src/type.zig30
-rw-r--r--src/value.zig30
2 files changed, 60 insertions, 0 deletions
diff --git a/src/type.zig b/src/type.zig
index ec4db8689f..15525f14eb 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -1,4 +1,5 @@
const std = @import("std");
+const builtin = @import("builtin");
const Value = @import("value.zig").Value;
const assert = std.debug.assert;
const Allocator = std.mem.Allocator;
@@ -6694,4 +6695,33 @@ pub const Type = extern union {
/// This is only used for comptime asserts. Bump this number when you make a change
/// to packed struct layout to find out all the places in the codebase you need to edit!
pub const packed_struct_layout_version = 2;
+
+ /// 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: *Type, 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;
+ }
+ }
};
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 = .{