Dwarf: include comptime-only values in debug info

This commit is contained in:
Jacob Young 2024-12-16 15:11:15 -05:00
parent 5af7404655
commit 8c0628d0e2
5 changed files with 1002 additions and 204 deletions

View file

@ -224,6 +224,8 @@ pub const ZIG_parent = 0x2ccd;
pub const ZIG_padding = 0x2cce; pub const ZIG_padding = 0x2cce;
pub const ZIG_relative_decl = 0x2cd0; pub const ZIG_relative_decl = 0x2cd0;
pub const ZIG_decl_line_relative = 0x2cd1; pub const ZIG_decl_line_relative = 0x2cd1;
pub const ZIG_comptime_value = 0x2cd2;
pub const ZIG_comptime_default_value = 0x2cd3;
pub const ZIG_sentinel = 0x2ce2; pub const ZIG_sentinel = 0x2ce2;
// UPC extension. // UPC extension.

View file

@ -119,3 +119,4 @@ pub const PGI_interface_block = 0xA020;
// ZIG extensions. // ZIG extensions.
pub const ZIG_padding = 0xfdb1; pub const ZIG_padding = 0xfdb1;
pub const ZIG_comptime_value = 0xfdb2;

View file

@ -4704,9 +4704,45 @@ pub const Index = enum(u32) {
} }
comptime { comptime {
if (builtin.zig_backend == .stage2_llvm and !builtin.strip_debug_info) { if (!builtin.strip_debug_info) switch (builtin.zig_backend) {
_ = &dbHelper; .stage2_llvm => _ = &dbHelper,
} .stage2_x86_64 => {
for (@typeInfo(Tag).@"enum".fields) |tag| {
if (!@hasField(@TypeOf(Tag.encodings), tag.name)) {
if (false) @compileLog("missing: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name);
continue;
}
const encoding = @field(Tag.encodings, tag.name);
for (@typeInfo(encoding.trailing).@"struct".fields) |field| {
struct {
fn checkConfig(name: []const u8) void {
if (!@hasField(@TypeOf(encoding.config), name)) @compileError("missing field: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name ++ ".config.@\"" ++ name ++ "\"");
const FieldType = @TypeOf(@field(encoding.config, name));
if (@typeInfo(FieldType) != .enum_literal) @compileError("expected enum literal: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name ++ ".config.@\"" ++ name ++ "\": " ++ @typeName(FieldType));
}
fn checkField(name: []const u8, Type: type) void {
switch (@typeInfo(Type)) {
.int => {},
.@"enum" => {},
.@"struct" => |info| assert(info.layout == .@"packed"),
.optional => |info| {
checkConfig(name ++ ".?");
checkField(name ++ ".?", info.child);
},
.pointer => |info| {
assert(info.size == .Slice);
checkConfig(name ++ ".len");
checkField(name ++ "[0]", info.child);
},
else => @compileError("unsupported type: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name ++ "." ++ name ++ ": " ++ @typeName(Type)),
}
}
}.checkField("trailing." ++ field.name, field.type);
}
}
},
else => {},
};
} }
}; };
@ -5302,6 +5338,39 @@ pub const Tag = enum(u8) {
}; };
} }
const encodings = .{
.type_struct = .{
.payload = TypeStruct,
.trailing = struct {
captures_len: ?u32,
captures: ?[]CaptureValue,
type_hash: ?u64,
field_types: []Index,
field_inits: ?[]Index,
field_aligns: ?[]Alignment,
field_is_comptime_bits: ?[]u32,
field_index: ?[]LoadedStructType.RuntimeOrder,
field_offset: []u32,
},
.config = .{
.@"trailing.captures_len.?" = .@"payload.flags.any_captures",
.@"trailing.captures.?" = .@"payload.flags.any_captures",
.@"trailing.captures.?.len" = .@"trailing.captures_len",
.@"trailing.type_hash.?" = .@"payload.flags.is_reified",
.@"trailing.field_types.len" = .@"payload.fields_len",
.@"trailing.field_inits.?" = .@"payload.flags.any_default_inits",
.@"trailing.field_inits.?.len" = .@"payload.fields_len",
.@"trailing.field_aligns.?" = .@"payload.flags.any_aligned_fields",
.@"trailing.field_aligns.?.len" = .@"payload.fields_len",
.@"trailing.field_is_comptime_bits.?" = .@"payload.flags.any_comptime_fields",
.@"trailing.field_is_comptime_bits.?.len" = .@"(payload.fields_len + 31) / 32",
.@"trailing.field_index.?" = .@"!payload.flags.is_extern",
.@"trailing.field_index.?.len" = .@"!payload.flags.is_extern",
.@"trailing.field_offset.len" = .@"payload.fields_len",
},
},
};
pub const Variable = struct { pub const Variable = struct {
ty: Index, ty: Index,
/// May be `none`. /// May be `none`.

View file

@ -4126,6 +4126,7 @@ pub const @"anyframe": Type = .{ .ip_index = .anyframe_type };
pub const @"null": Type = .{ .ip_index = .null_type }; pub const @"null": Type = .{ .ip_index = .null_type };
pub const @"undefined": Type = .{ .ip_index = .undefined_type }; pub const @"undefined": Type = .{ .ip_index = .undefined_type };
pub const @"noreturn": Type = .{ .ip_index = .noreturn_type }; pub const @"noreturn": Type = .{ .ip_index = .noreturn_type };
pub const enum_literal: Type = .{ .ip_index = .enum_literal_type };
pub const @"c_char": Type = .{ .ip_index = .c_char_type }; pub const @"c_char": Type = .{ .ip_index = .c_char_type };
pub const @"c_short": Type = .{ .ip_index = .c_short_type }; pub const @"c_short": Type = .{ .ip_index = .c_short_type };

File diff suppressed because it is too large Load diff