authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-12-23 15:55:03-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-12-23 15:55:03-05:00
logaf5e731729592af4a5716edd3b1e03264d66ea46
treee0d804ee5280c48654e9789c2bade7eca6c1fbc5
parentb976e89c16b4cfd97986f0dd642f987c9ca6ec64
parent5776d8f27022926b0538e818c7408f760bf2d144
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #22280 from jacobly0/stage2-pp

lldb: add more stage2 pretty printers

15 files changed, 725 insertions(+), 287 deletions(-)

lib/std/dwarf/AT.zig-1
......@@ -225,7 +225,6 @@ pub const ZIG_padding = 0x2cce;
225225pub const ZIG_relative_decl = 0x2cd0;
226226pub const ZIG_decl_line_relative = 0x2cd1;
227227pub const ZIG_comptime_value = 0x2cd2;
228pub const ZIG_comptime_default_value = 0x2cd3;
229228pub const ZIG_sentinel = 0x2ce2;
230229
231230// UPC extension.
src/Compilation.zig+16-8
......@@ -2181,7 +2181,8 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
21812181 }
21822182
21832183 if (comp.zcu) |zcu| {
2184 const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = .main };
2184 const pt: Zcu.PerThread = .activate(zcu, .main);
2185 defer pt.deactivate();
21852186
21862187 zcu.compile_log_text.shrinkAndFree(gpa, 0);
21872188
......@@ -2251,7 +2252,8 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
22512252 try comp.performAllTheWork(main_progress_node);
22522253
22532254 if (comp.zcu) |zcu| {
2254 const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = .main };
2255 const pt: Zcu.PerThread = .activate(zcu, .main);
2256 defer pt.deactivate();
22552257
22562258 if (build_options.enable_debug_extensions and comp.verbose_intern_pool) {
22572259 std.debug.print("intern pool stats for '{s}':\n", .{
......@@ -3609,7 +3611,8 @@ fn performAllTheWorkInner(
36093611 }
36103612
36113613 if (comp.zcu) |zcu| {
3612 const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = .main };
3614 const pt: Zcu.PerThread = .activate(zcu, .main);
3615 defer pt.deactivate();
36133616 if (comp.incremental) {
36143617 const update_zir_refs_node = main_progress_node.start("Update ZIR References", 0);
36153618 defer update_zir_refs_node.end();
......@@ -3683,14 +3686,16 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre
36833686 const named_frame = tracy.namedFrame("analyze_func");
36843687 defer named_frame.end();
36853688
3686 const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
3689 const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));
3690 defer pt.deactivate();
36873691 pt.ensureFuncBodyAnalyzed(func) catch |err| switch (err) {
36883692 error.OutOfMemory => return error.OutOfMemory,
36893693 error.AnalysisFail => return,
36903694 };
36913695 },
36923696 .analyze_cau => |cau_index| {
3693 const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
3697 const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));
3698 defer pt.deactivate();
36943699 pt.ensureCauAnalyzed(cau_index) catch |err| switch (err) {
36953700 error.OutOfMemory => return error.OutOfMemory,
36963701 error.AnalysisFail => return,
......@@ -3719,7 +3724,8 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre
37193724 const named_frame = tracy.namedFrame("resolve_type_fully");
37203725 defer named_frame.end();
37213726
3722 const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
3727 const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));
3728 defer pt.deactivate();
37233729 Type.fromInterned(ty).resolveFully(pt) catch |err| switch (err) {
37243730 error.OutOfMemory => return error.OutOfMemory,
37253731 error.AnalysisFail => return,
......@@ -3729,7 +3735,8 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre
37293735 const named_frame = tracy.namedFrame("analyze_mod");
37303736 defer named_frame.end();
37313737
3732 const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
3738 const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));
3739 defer pt.deactivate();
37333740 pt.semaPkg(mod) catch |err| switch (err) {
37343741 error.OutOfMemory => return error.OutOfMemory,
37353742 error.AnalysisFail => return,
......@@ -4183,7 +4190,8 @@ fn workerAstGenFile(
41834190 const child_prog_node = prog_node.start(file.sub_file_path, 0);
41844191 defer child_prog_node.end();
41854192
4186 const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
4193 const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));
4194 defer pt.deactivate();
41874195 pt.astGenFile(file, path_digest) catch |err| switch (err) {
41884196 error.AnalysisFail => return,
41894197 else => {
src/InternPool.zig+357-119
......@@ -470,6 +470,8 @@ pub const Cau = struct {
470470 _ => @enumFromInt(@intFromEnum(opt)),
471471 };
472472 }
473
474 const debug_state = InternPool.debug_state;
473475 };
474476 pub fn toOptional(i: Cau.Index) Optional {
475477 return @enumFromInt(@intFromEnum(i));
......@@ -491,6 +493,8 @@ pub const Cau = struct {
491493 .index = @intFromEnum(cau_index) & ip.getIndexMask(u31),
492494 };
493495 }
496
497 const debug_state = InternPool.debug_state;
494498 };
495499};
496500
......@@ -568,6 +572,8 @@ pub const Nav = struct {
568572 _ => @enumFromInt(@intFromEnum(opt)),
569573 };
570574 }
575
576 const debug_state = InternPool.debug_state;
571577 };
572578 pub fn toOptional(i: Nav.Index) Optional {
573579 return @enumFromInt(@intFromEnum(i));
......@@ -589,6 +595,8 @@ pub const Nav = struct {
589595 .index = @intFromEnum(nav_index) & ip.getIndexMask(u32),
590596 };
591597 }
598
599 const debug_state = InternPool.debug_state;
592600 };
593601
594602 /// The compact in-memory representation of a `Nav`.
......@@ -1580,6 +1588,8 @@ pub const String = enum(u32) {
15801588 const strings = ip.getLocalShared(unwrapped_string.tid).strings.acquire();
15811589 return strings.view().items(.@"0")[unwrapped_string.index..];
15821590 }
1591
1592 const debug_state = InternPool.debug_state;
15831593};
15841594
15851595/// An index into `strings` which might be `none`.
......@@ -1596,6 +1606,8 @@ pub const OptionalString = enum(u32) {
15961606 pub fn toSlice(string: OptionalString, len: u64, ip: *const InternPool) ?[]const u8 {
15971607 return (string.unwrap() orelse return null).toSlice(len, ip);
15981608 }
1609
1610 const debug_state = InternPool.debug_state;
15991611};
16001612
16011613/// An index into `strings`.
......@@ -1692,6 +1704,8 @@ pub const NullTerminatedString = enum(u32) {
16921704 pub fn fmt(string: NullTerminatedString, ip: *const InternPool) std.fmt.Formatter(format) {
16931705 return .{ .data = .{ .string = string, .ip = ip } };
16941706 }
1707
1708 const debug_state = InternPool.debug_state;
16951709};
16961710
16971711/// An index into `strings` which might be `none`.
......@@ -1708,6 +1722,8 @@ pub const OptionalNullTerminatedString = enum(u32) {
17081722 pub fn toSlice(string: OptionalNullTerminatedString, ip: *const InternPool) ?[:0]const u8 {
17091723 return (string.unwrap() orelse return null).toSlice(ip);
17101724 }
1725
1726 const debug_state = InternPool.debug_state;
17111727};
17121728
17131729/// A single value captured in the closure of a namespace type. This is not a plain
......@@ -4519,6 +4535,8 @@ pub const Index = enum(u32) {
45194535 .data_ptr = &slice.items(.data)[unwrapped.index],
45204536 };
45214537 }
4538
4539 const debug_state = InternPool.debug_state;
45224540 };
45234541 pub fn unwrap(index: Index, ip: *const InternPool) Unwrapped {
45244542 return if (single_threaded) .{
......@@ -4532,7 +4550,6 @@ pub const Index = enum(u32) {
45324550
45334551 /// This function is used in the debugger pretty formatters in tools/ to fetch the
45344552 /// Tag to encoding mapping to facilitate fancy debug printing for this type.
4535 /// TODO merge this with `Tag.Payload`.
45364553 fn dbHelper(self: *Index, tag_to_encoding_map: *struct {
45374554 const DataIsIndex = struct { data: Index };
45384555 const DataIsExtraIndexOfEnumExplicit = struct {
......@@ -4689,44 +4706,38 @@ pub const Index = enum(u32) {
46894706 }
46904707 }
46914708 }
4692
46934709 comptime {
46944710 if (!builtin.strip_debug_info) switch (builtin.zig_backend) {
46954711 .stage2_llvm => _ = &dbHelper,
4696 .stage2_x86_64 => {
4697 for (@typeInfo(Tag).@"enum".fields) |tag| {
4698 if (!@hasField(@TypeOf(Tag.encodings), tag.name)) {
4699 if (false) @compileLog("missing: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name);
4700 continue;
4701 }
4702 const encoding = @field(Tag.encodings, tag.name);
4703 for (@typeInfo(encoding.trailing).@"struct".fields) |field| {
4704 struct {
4705 fn checkConfig(name: []const u8) void {
4706 if (!@hasField(@TypeOf(encoding.config), name)) @compileError("missing field: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name ++ ".config.@\"" ++ name ++ "\"");
4707 const FieldType = @TypeOf(@field(encoding.config, name));
4708 if (@typeInfo(FieldType) != .enum_literal) @compileError("expected enum literal: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name ++ ".config.@\"" ++ name ++ "\": " ++ @typeName(FieldType));
4709 }
4710 fn checkField(name: []const u8, Type: type) void {
4711 switch (@typeInfo(Type)) {
4712 .int => {},
4713 .@"enum" => {},
4714 .@"struct" => |info| assert(info.layout == .@"packed"),
4715 .optional => |info| {
4716 checkConfig(name ++ ".?");
4717 checkField(name ++ ".?", info.child);
4718 },
4719 .pointer => |info| {
4720 assert(info.size == .Slice);
4721 checkConfig(name ++ ".len");
4722 checkField(name ++ "[0]", info.child);
4723 },
4724 else => @compileError("unsupported type: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name ++ "." ++ name ++ ": " ++ @typeName(Type)),
4725 }
4712 .stage2_x86_64 => for (@typeInfo(Tag).@"enum".fields) |tag| {
4713 if (!@hasField(@TypeOf(Tag.encodings), tag.name)) @compileLog("missing: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name);
4714 const encoding = @field(Tag.encodings, tag.name);
4715 if (@hasField(@TypeOf(encoding), "trailing")) for (@typeInfo(encoding.trailing).@"struct".fields) |field| {
4716 struct {
4717 fn checkConfig(name: []const u8) void {
4718 if (!@hasField(@TypeOf(encoding.config), name)) @compileError("missing field: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name ++ ".config.@\"" ++ name ++ "\"");
4719 const FieldType = @TypeOf(@field(encoding.config, name));
4720 if (@typeInfo(FieldType) != .enum_literal) @compileError("expected enum literal: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name ++ ".config.@\"" ++ name ++ "\": " ++ @typeName(FieldType));
4721 }
4722 fn checkField(name: []const u8, Type: type) void {
4723 switch (@typeInfo(Type)) {
4724 .int => {},
4725 .@"enum" => {},
4726 .@"struct" => |info| assert(info.layout == .@"packed"),
4727 .optional => |info| {
4728 checkConfig(name ++ ".?");
4729 checkField(name ++ ".?", info.child);
4730 },
4731 .pointer => |info| {
4732 assert(info.size == .Slice);
4733 checkConfig(name ++ ".len");
4734 checkField(name ++ "[0]", info.child);
4735 },
4736 else => @compileError("unsupported type: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name ++ "." ++ name ++ ": " ++ @typeName(Type)),
47264737 }
4727 }.checkField("trailing." ++ field.name, field.type);
4728 }
4729 }
4738 }
4739 }.checkField("trailing." ++ field.name, field.type);
4740 };
47304741 },
47314742 else => {},
47324743 };
......@@ -5035,7 +5046,6 @@ pub const Tag = enum(u8) {
50355046 /// data is payload index to `EnumExplicit`.
50365047 type_enum_nonexhaustive,
50375048 /// A type that can be represented with only an enum tag.
5038 /// data is SimpleType enum value.
50395049 simple_type,
50405050 /// An opaque type.
50415051 /// data is index of Tag.TypeOpaque in extra.
......@@ -5064,7 +5074,6 @@ pub const Tag = enum(u8) {
50645074 /// Untyped `undefined` is stored instead via `simple_value`.
50655075 undef,
50665076 /// A value that can be represented with only an enum tag.
5067 /// data is SimpleValue enum value.
50685077 simple_value,
50695078 /// A pointer to a `Nav`.
50705079 /// data is extra index of `PtrNav`, which contains the type and address.
......@@ -5244,95 +5253,90 @@ pub const Tag = enum(u8) {
52445253 const Union = Key.Union;
52455254 const TypePointer = Key.PtrType;
52465255
5247 fn Payload(comptime tag: Tag) type {
5248 return switch (tag) {
5249 .removed => unreachable,
5250 .type_int_signed => unreachable,
5251 .type_int_unsigned => unreachable,
5252 .type_array_big => Array,
5253 .type_array_small => Vector,
5254 .type_vector => Vector,
5255 .type_pointer => TypePointer,
5256 .type_slice => unreachable,
5257 .type_optional => unreachable,
5258 .type_anyframe => unreachable,
5259 .type_error_union => ErrorUnionType,
5260 .type_anyerror_union => unreachable,
5261 .type_error_set => ErrorSet,
5262 .type_inferred_error_set => unreachable,
5263 .type_enum_auto => EnumAuto,
5264 .type_enum_explicit => EnumExplicit,
5265 .type_enum_nonexhaustive => EnumExplicit,
5266 .simple_type => unreachable,
5267 .type_opaque => TypeOpaque,
5268 .type_struct => TypeStruct,
5269 .type_struct_packed, .type_struct_packed_inits => TypeStructPacked,
5270 .type_tuple => TypeTuple,
5271 .type_union => TypeUnion,
5272 .type_function => TypeFunction,
5273
5274 .undef => unreachable,
5275 .simple_value => unreachable,
5276 .ptr_nav => PtrNav,
5277 .ptr_comptime_alloc => PtrComptimeAlloc,
5278 .ptr_uav => PtrUav,
5279 .ptr_uav_aligned => PtrUavAligned,
5280 .ptr_comptime_field => PtrComptimeField,
5281 .ptr_int => PtrInt,
5282 .ptr_eu_payload => PtrBase,
5283 .ptr_opt_payload => PtrBase,
5284 .ptr_elem => PtrBaseIndex,
5285 .ptr_field => PtrBaseIndex,
5286 .ptr_slice => PtrSlice,
5287 .opt_payload => TypeValue,
5288 .opt_null => unreachable,
5289 .int_u8 => unreachable,
5290 .int_u16 => unreachable,
5291 .int_u32 => unreachable,
5292 .int_i32 => unreachable,
5293 .int_usize => unreachable,
5294 .int_comptime_int_u32 => unreachable,
5295 .int_comptime_int_i32 => unreachable,
5296 .int_small => IntSmall,
5297 .int_positive => unreachable,
5298 .int_negative => unreachable,
5299 .int_lazy_align => IntLazy,
5300 .int_lazy_size => IntLazy,
5301 .error_set_error => Error,
5302 .error_union_error => Error,
5303 .error_union_payload => TypeValue,
5304 .enum_literal => unreachable,
5305 .enum_tag => EnumTag,
5306 .float_f16 => unreachable,
5307 .float_f32 => unreachable,
5308 .float_f64 => unreachable,
5309 .float_f80 => unreachable,
5310 .float_f128 => unreachable,
5311 .float_c_longdouble_f80 => unreachable,
5312 .float_c_longdouble_f128 => unreachable,
5313 .float_comptime_float => unreachable,
5314 .variable => Variable,
5315 .@"extern" => Extern,
5316 .func_decl => FuncDecl,
5317 .func_instance => FuncInstance,
5318 .func_coerced => FuncCoerced,
5319 .only_possible_value => unreachable,
5320 .union_value => Union,
5321 .bytes => Bytes,
5322 .aggregate => Aggregate,
5323 .repeated => Repeated,
5324 .memoized_call => MemoizedCall,
5325 };
5326 }
5327
5256 const enum_explicit_encoding = .{
5257 .summary = .@"{.payload.name%summary#\"}",
5258 .payload = EnumExplicit,
5259 .trailing = struct {
5260 owner_union: Index,
5261 cau: ?Cau.Index,
5262 captures: ?[]CaptureValue,
5263 type_hash: ?u64,
5264 field_names: []NullTerminatedString,
5265 tag_values: []Index,
5266 },
5267 .config = .{
5268 .@"trailing.owner_union.?" = .@"payload.zir_index == .none",
5269 .@"trailing.cau.?" = .@"payload.zir_index != .none",
5270 .@"trailing.captures.?" = .@"payload.captures_len < 0xffffffff",
5271 .@"trailing.captures.?.len" = .@"payload.captures_len",
5272 .@"trailing.type_hash.?" = .@"payload.captures_len == 0xffffffff",
5273 .@"trailing.field_names.len" = .@"payload.fields_len",
5274 .@"trailing.tag_values.len" = .@"payload.fields_len",
5275 },
5276 };
53285277 const encodings = .{
5278 .removed = .{},
5279
5280 .type_int_signed = .{ .summary = .@"i{.data%value}", .data = u32 },
5281 .type_int_unsigned = .{ .summary = .@"u{.data%value}", .data = u32 },
5282 .type_array_big = .{
5283 .summary = .@"[{.payload.len1%value} << 32 | {.payload.len0%value}:{.payload.sentinel%summary}]{.payload.child%summary}",
5284 .payload = Array,
5285 },
5286 .type_array_small = .{ .summary = .@"[{.payload.len%value}]{.payload.child%summary}", .payload = Vector },
5287 .type_vector = .{ .summary = .@"@Vector({.payload.len%value}, {.payload.child%summary})", .payload = Vector },
5288 .type_pointer = .{ .summary = .@"*... {.payload.child%summary}", .payload = TypePointer },
5289 .type_slice = .{ .summary = .@"[]... {.data.unwrapped.payload.child%summary}", .data = Index },
5290 .type_optional = .{ .summary = .@"?{.data%summary}", .data = Index },
5291 .type_anyframe = .{ .summary = .@"anyframe->{.data%summary}", .data = Index },
5292 .type_error_union = .{
5293 .summary = .@"{.payload.error_set_type%summary}!{.payload.payload_type%summary}",
5294 .payload = ErrorUnionType,
5295 },
5296 .type_anyerror_union = .{ .summary = .@"anyerror!{.data%summary}", .data = Index },
5297 .type_error_set = .{ .summary = .@"error{...}", .payload = ErrorSet },
5298 .type_inferred_error_set = .{
5299 .summary = .@"@typeInfo(@typeInfo(@TypeOf({.data%summary})).@\"fn\".return_type.?).error_union.error_set",
5300 .data = Index,
5301 },
5302 .type_enum_auto = .{
5303 .summary = .@"{.payload.name%summary#\"}",
5304 .payload = EnumAuto,
5305 .trailing = struct {
5306 owner_union: ?Index,
5307 cau: ?Cau.Index,
5308 captures: ?[]CaptureValue,
5309 type_hash: ?u64,
5310 field_names: []NullTerminatedString,
5311 },
5312 .config = .{
5313 .@"trailing.owner_union.?" = .@"payload.zir_index == .none",
5314 .@"trailing.cau.?" = .@"payload.zir_index != .none",
5315 .@"trailing.captures.?" = .@"payload.captures_len < 0xffffffff",
5316 .@"trailing.captures.?.len" = .@"payload.captures_len",
5317 .@"trailing.type_hash.?" = .@"payload.captures_len == 0xffffffff",
5318 .@"trailing.field_names.len" = .@"payload.fields_len",
5319 },
5320 },
5321 .type_enum_explicit = enum_explicit_encoding,
5322 .type_enum_nonexhaustive = enum_explicit_encoding,
5323 .simple_type = .{ .summary = .@"{.index%value#.}", .index = SimpleType },
5324 .type_opaque = .{
5325 .summary = .@"{.payload.name%summary#\"}",
5326 .payload = TypeOpaque,
5327 .trailing = struct { captures: []CaptureValue },
5328 .config = .{ .@"trailing.captures.len" = .@"payload.captures_len" },
5329 },
53295330 .type_struct = .{
5331 .summary = .@"{.payload.name%summary#\"}",
53305332 .payload = TypeStruct,
53315333 .trailing = struct {
53325334 captures_len: ?u32,
53335335 captures: ?[]CaptureValue,
53345336 type_hash: ?u64,
53355337 field_types: []Index,
5338 field_names_map: OptionalMapIndex,
5339 field_names: []NullTerminatedString,
53365340 field_inits: ?[]Index,
53375341 field_aligns: ?[]Alignment,
53385342 field_is_comptime_bits: ?[]u32,
......@@ -5342,9 +5346,10 @@ pub const Tag = enum(u8) {
53425346 .config = .{
53435347 .@"trailing.captures_len.?" = .@"payload.flags.any_captures",
53445348 .@"trailing.captures.?" = .@"payload.flags.any_captures",
5345 .@"trailing.captures.?.len" = .@"trailing.captures_len",
5349 .@"trailing.captures.?.len" = .@"trailing.captures_len.?",
53465350 .@"trailing.type_hash.?" = .@"payload.flags.is_reified",
53475351 .@"trailing.field_types.len" = .@"payload.fields_len",
5352 .@"trailing.field_names.len" = .@"payload.fields_len",
53485353 .@"trailing.field_inits.?" = .@"payload.flags.any_default_inits",
53495354 .@"trailing.field_inits.?.len" = .@"payload.fields_len",
53505355 .@"trailing.field_aligns.?" = .@"payload.flags.any_aligned_fields",
......@@ -5356,7 +5361,212 @@ pub const Tag = enum(u8) {
53565361 .@"trailing.field_offset.len" = .@"payload.fields_len",
53575362 },
53585363 },
5364 .type_struct_packed = .{
5365 .summary = .@"{.payload.name%summary#\"}",
5366 .payload = TypeStructPacked,
5367 .trailing = struct {
5368 captures_len: ?u32,
5369 captures: ?[]CaptureValue,
5370 type_hash: ?u64,
5371 field_types: []Index,
5372 field_names: []NullTerminatedString,
5373 },
5374 .config = .{
5375 .@"trailing.captures_len.?" = .@"payload.flags.any_captures",
5376 .@"trailing.captures.?" = .@"payload.flags.any_captures",
5377 .@"trailing.captures.?.len" = .@"trailing.captures_len.?",
5378 .@"trailing.type_hash.?" = .@"payload.is_flags.is_reified",
5379 .@"trailing.field_types.len" = .@"payload.fields_len",
5380 .@"trailing.field_names.len" = .@"payload.fields_len",
5381 },
5382 },
5383 .type_struct_packed_inits = .{
5384 .summary = .@"{.payload.name%summary#\"}",
5385 .payload = TypeStructPacked,
5386 .trailing = struct {
5387 captures_len: ?u32,
5388 captures: ?[]CaptureValue,
5389 type_hash: ?u64,
5390 field_types: []Index,
5391 field_names: []NullTerminatedString,
5392 field_inits: []Index,
5393 },
5394 .config = .{
5395 .@"trailing.captures_len.?" = .@"payload.flags.any_captures",
5396 .@"trailing.captures.?" = .@"payload.flags.any_captures",
5397 .@"trailing.captures.?.len" = .@"trailing.captures_len.?",
5398 .@"trailing.type_hash.?" = .@"payload.is_flags.is_reified",
5399 .@"trailing.field_types.len" = .@"payload.fields_len",
5400 .@"trailing.field_names.len" = .@"payload.fields_len",
5401 .@"trailing.field_inits.len" = .@"payload.fields_len",
5402 },
5403 },
5404 .type_tuple = .{
5405 .summary = .@"struct {...}",
5406 .payload = TypeTuple,
5407 .trailing = struct {
5408 field_types: []Index,
5409 field_values: []Index,
5410 },
5411 .config = .{
5412 .@"trailing.field_types.len" = .@"payload.fields_len",
5413 .@"trailing.field_values.len" = .@"payload.fields_len",
5414 },
5415 },
5416 .type_union = .{
5417 .summary = .@"{.payload.name%summary#\"#\"}",
5418 .payload = TypeUnion,
5419 .trailing = struct {
5420 captures_len: ?u32,
5421 captures: ?[]CaptureValue,
5422 type_hash: ?u64,
5423 field_types: []Index,
5424 field_aligns: []Alignment,
5425 },
5426 .config = .{
5427 .@"trailing.captures_len.?" = .@"payload.flags.any_captures",
5428 .@"trailing.captures.?" = .@"payload.flags.any_captures",
5429 .@"trailing.captures.?.len" = .@"trailing.captures_len.?",
5430 .@"trailing.type_hash.?" = .@"payload.is_flags.is_reified",
5431 .@"trailing.field_types.len" = .@"payload.fields_len",
5432 .@"trailing.field_aligns.len" = .@"payload.fields_len",
5433 },
5434 },
5435 .type_function = .{
5436 .summary = .@"fn (...) ... {.payload.return_type%summary}",
5437 .payload = TypeFunction,
5438 .trailing = struct {
5439 param_comptime_bits: ?[]u32,
5440 param_noalias_bits: ?[]u32,
5441 param_type: []Index,
5442 },
5443 .config = .{
5444 .@"trailing.param_comptime_bits.?" = .@"payload.flags.has_comptime_bits",
5445 .@"trailing.param_comptime_bits.?.len" = .@"(payload.params_len + 31) / 32",
5446 .@"trailing.param_noalias_bits.?" = .@"payload.flags.has_noalias_bits",
5447 .@"trailing.param_noalias_bits.?.len" = .@"(payload.params_len + 31) / 32",
5448 .@"trailing.param_type.len" = .@"payload.params_len",
5449 },
5450 },
5451
5452 .undef = .{ .summary = .@"@as({.data%summary}, undefined)", .data = Index },
5453 .simple_value = .{ .summary = .@"{.index%value#.}", .index = SimpleValue },
5454 .ptr_nav = .{
5455 .summary = .@"@as({.payload.ty%summary}, @ptrFromInt(@intFromPtr(&{.payload.nav.fqn%summary#\"}) + ({.payload.byte_offset_a%value} << 32 | {.payload.byte_offset_b%value})))",
5456 .payload = PtrNav,
5457 },
5458 .ptr_comptime_alloc = .{
5459 .summary = .@"@as({.payload.ty%summary}, @ptrFromInt(@intFromPtr(&comptime_allocs[{.payload.index%summary}]) + ({.payload.byte_offset_a%value} << 32 | {.payload.byte_offset_b%value})))",
5460 .payload = PtrComptimeAlloc,
5461 },
5462 .ptr_uav = .{
5463 .summary = .@"@as({.payload.ty%summary}, @ptrFromInt(@intFromPtr(&{.payload.val%summary}) + ({.payload.byte_offset_a%value} << 32 | {.payload.byte_offset_b%value})))",
5464 .payload = PtrUav,
5465 },
5466 .ptr_uav_aligned = .{
5467 .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})))",
5468 .payload = PtrUavAligned,
5469 },
5470 .ptr_comptime_field = .{
5471 .summary = .@"@as({.payload.ty%summary}, @ptrFromInt(@intFromPtr(&{.payload.field_val%summary}) + ({.payload.byte_offset_a%value} << 32 | {.payload.byte_offset_b%value})))",
5472 .payload = PtrComptimeField,
5473 },
5474 .ptr_int = .{
5475 .summary = .@"@as({.payload.ty%summary}, @ptrFromInt({.payload.byte_offset_a%value} << 32 | {.payload.byte_offset_b%value}))",
5476 .payload = PtrInt,
5477 },
5478 .ptr_eu_payload = .{
5479 .summary = .@"@as({.payload.ty%summary}, @ptrFromInt(@intFromPtr(&({.payload.base%summary} catch unreachable)) + ({.payload.byte_offset_a%value} << 32 | {.payload.byte_offset_b%value})))",
5480 .payload = PtrBase,
5481 },
5482 .ptr_opt_payload = .{
5483 .summary = .@"@as({.payload.ty%summary}, @ptrFromInt(@intFromPtr(&{.payload.base%summary}.?) + ({.payload.byte_offset_a%value} << 32 | {.payload.byte_offset_b%value})))",
5484 .payload = PtrBase,
5485 },
5486 .ptr_elem = .{
5487 .summary = .@"@as({.payload.ty%summary}, @ptrFromInt(@intFromPtr(&{.payload.base%summary}[{.payload.index%summary}]) + ({.payload.byte_offset_a%value} << 32 | {.payload.byte_offset_b%value})))",
5488 .payload = PtrBaseIndex,
5489 },
5490 .ptr_field = .{
5491 .summary = .@"@as({.payload.ty%summary}, @ptrFromInt(@intFromPtr(&{.payload.base%summary}[{.payload.index%summary}]) + ({.payload.byte_offset_a%value} << 32 | {.payload.byte_offset_b%value})))",
5492 .payload = PtrBaseIndex,
5493 },
5494 .ptr_slice = .{
5495 .summary = .@"{.payload.ptr%summary}[0..{.payload.len%summary}]",
5496 .payload = PtrSlice,
5497 },
5498 .opt_payload = .{ .summary = .@"@as({.payload.ty%summary}, {.payload.val%summary})", .payload = TypeValue },
5499 .opt_null = .{ .summary = .@"@as({.data%summary}, null)", .data = Index },
5500 .int_u8 = .{ .summary = .@"@as(u8, {.data%value})", .data = u8 },
5501 .int_u16 = .{ .summary = .@"@as(u16, {.data%value})", .data = u16 },
5502 .int_u32 = .{ .summary = .@"@as(u32, {.data%value})", .data = u32 },
5503 .int_i32 = .{ .summary = .@"@as(i32, {.data%value})", .data = i32 },
5504 .int_usize = .{ .summary = .@"@as(usize, {.data%value})", .data = u32 },
5505 .int_comptime_int_u32 = .{ .summary = .@"{.data%value}", .data = u32 },
5506 .int_comptime_int_i32 = .{ .summary = .@"{.data%value}", .data = i32 },
5507 .int_small = .{ .summary = .@"@as({.payload.ty%summary}, {.payload.value%value})", .payload = IntSmall },
5508 .int_positive = .{},
5509 .int_negative = .{},
5510 .int_lazy_align = .{ .summary = .@"@as({.payload.ty%summary}, @alignOf({.payload.lazy_ty%summary}))", .payload = IntLazy },
5511 .int_lazy_size = .{ .summary = .@"@as({.payload.ty%summary}, @sizeOf({.payload.lazy_ty%summary}))", .payload = IntLazy },
5512 .error_set_error = .{ .summary = .@"@as({.payload.ty%summary}, error.@{.payload.name%summary})", .payload = Error },
5513 .error_union_error = .{ .summary = .@"@as({.payload.ty%summary}, error.@{.payload.name%summary})", .payload = Error },
5514 .error_union_payload = .{ .summary = .@"@as({.payload.ty%summary}, {.payload.val%summary})", .payload = TypeValue },
5515 .enum_literal = .{ .summary = .@".@{.data%summary}", .data = NullTerminatedString },
5516 .enum_tag = .{ .summary = .@"@as({.payload.ty%summary}, @enumFromInt({.payload.int%summary}))", .payload = EnumTag },
5517 .float_f16 = .{ .summary = .@"@as(f16, {.data%value})", .data = f16 },
5518 .float_f32 = .{ .summary = .@"@as(f32, {.data%value})", .data = f32 },
5519 .float_f64 = .{ .summary = .@"@as(f64, {.payload%value})", .payload = f64 },
5520 .float_f80 = .{ .summary = .@"@as(f80, {.payload%value})", .payload = f80 },
5521 .float_f128 = .{ .summary = .@"@as(f128, {.payload%value})", .payload = f128 },
5522 .float_c_longdouble_f80 = .{ .summary = .@"@as(c_longdouble, {.payload%value})", .payload = f80 },
5523 .float_c_longdouble_f128 = .{ .summary = .@"@as(c_longdouble, {.payload%value})", .payload = f128 },
5524 .float_comptime_float = .{ .summary = .@"{.payload%value}", .payload = f128 },
5525 .variable = .{ .summary = .@"{.payload.owner_nav.fqn%summary#\"}", .payload = Variable },
5526 .@"extern" = .{ .summary = .@"{.payload.owner_nav.fqn%summary#\"}", .payload = Extern },
5527 .func_decl = .{
5528 .summary = .@"{.payload.owner_nav.fqn%summary#\"}",
5529 .payload = FuncDecl,
5530 .trailing = struct { inferred_error_set: ?Index },
5531 .config = .{ .@"trailing.inferred_error_set.?" = .@"payload.analysis.inferred_error_set" },
5532 },
5533 .func_instance = .{
5534 .summary = .@"{.payload.owner_nav.fqn%summary#\"}",
5535 .payload = FuncInstance,
5536 .trailing = struct {
5537 inferred_error_set: ?Index,
5538 param_values: []Index,
5539 },
5540 .config = .{
5541 .@"trailing.inferred_error_set.?" = .@"payload.analysis.inferred_error_set",
5542 .@"trailing.param_values.len" = .@"payload.ty.payload.params_len",
5543 },
5544 },
5545 .func_coerced = .{
5546 .summary = .@"@as(*const {.payload.ty%summary}, @ptrCast(&{.payload.func%summary})).*",
5547 .payload = FuncCoerced,
5548 },
5549 .only_possible_value = .{ .summary = .@"@as({.data%summary}, undefined)", .data = Index },
5550 .union_value = .{ .summary = .@"@as({.payload.ty%summary}, {})", .payload = Union },
5551 .bytes = .{ .summary = .@"@as({.payload.ty%summary}, {.payload.bytes%summary}.*)", .payload = Bytes },
5552 .aggregate = .{
5553 .summary = .@"@as({.payload.ty%summary}, .{...})",
5554 .payload = Aggregate,
5555 .trailing = struct { elements: []Index },
5556 .config = .{ .@"trailing.elements.len" = .@"payload.ty.payload.fields_len" },
5557 },
5558 .repeated = .{ .summary = .@"@as({.payload.ty%summary}, @splat({.payload.elem_val%summary}))", .payload = Repeated },
5559
5560 .memoized_call = .{
5561 .summary = .@"@memoize({.payload.func%summary})",
5562 .payload = MemoizedCall,
5563 .trailing = struct { arg_values: []Index },
5564 .config = .{ .@"trailing.arg_values.len" = .@"payload.args_len" },
5565 },
53595566 };
5567 fn Payload(comptime tag: Tag) type {
5568 return @field(encodings, @tagName(tag)).payload;
5569 }
53605570
53615571 pub const Variable = struct {
53625572 ty: Index,
......@@ -6271,6 +6481,8 @@ pub fn init(ip: *InternPool, gpa: Allocator, available_threads: usize) !void {
62716481}
62726482
62736483pub fn deinit(ip: *InternPool, gpa: Allocator) void {
6484 if (!builtin.strip_debug_info) std.debug.assert(debug_state.intern_pool == null);
6485
62746486 ip.file_deps.deinit(gpa);
62756487 ip.src_hash_deps.deinit(gpa);
62766488 ip.nav_val_deps.deinit(gpa);
......@@ -6311,6 +6523,32 @@ pub fn deinit(ip: *InternPool, gpa: Allocator) void {
63116523 ip.* = undefined;
63126524}
63136525
6526pub fn activate(ip: *const InternPool) void {
6527 if (builtin.strip_debug_info) return;
6528 _ = Index.Unwrapped.debug_state;
6529 _ = String.debug_state;
6530 _ = OptionalString.debug_state;
6531 _ = NullTerminatedString.debug_state;
6532 _ = OptionalNullTerminatedString.debug_state;
6533 _ = Cau.Index.debug_state;
6534 _ = Cau.Index.Optional.debug_state;
6535 _ = Nav.Index.debug_state;
6536 _ = Nav.Index.Optional.debug_state;
6537 std.debug.assert(debug_state.intern_pool == null);
6538 debug_state.intern_pool = ip;
6539}
6540
6541pub fn deactivate(ip: *const InternPool) void {
6542 if (builtin.strip_debug_info) return;
6543 std.debug.assert(debug_state.intern_pool == ip);
6544 debug_state.intern_pool = null;
6545}
6546
6547/// For debugger access only.
6548const debug_state = struct {
6549 threadlocal var intern_pool: ?*const InternPool = null;
6550};
6551
63146552pub fn indexToKey(ip: *const InternPool, index: Index) Key {
63156553 assert(index != .none);
63166554 const unwrapped_index = index.unwrap(ip);
src/Type.zig+1-1
......@@ -891,7 +891,7 @@ pub const ResolveStratLazy = enum {
891891};
892892
893893/// The chosen strategy can be easily optimized away in release builds.
894/// However, in debug builds, it helps to avoid acceidentally resolving types in backends.
894/// However, in debug builds, it helps to avoid accidentally resolving types in backends.
895895pub const ResolveStrat = enum {
896896 /// Assert that all necessary resolution is completed.
897897 /// Backends should typically use this, since they must not perform type resolution.
src/Zcu.zig+67-65
......@@ -2169,90 +2169,92 @@ pub fn init(zcu: *Zcu, thread_count: usize) !void {
21692169}
21702170
21712171pub fn deinit(zcu: *Zcu) void {
2172 const pt: Zcu.PerThread = .{ .tid = .main, .zcu = zcu };
21732172 const gpa = zcu.gpa;
2173 {
2174 const pt: Zcu.PerThread = .activate(zcu, .main);
2175 defer pt.deactivate();
21742176
2175 if (zcu.llvm_object) |llvm_object| llvm_object.deinit();
2176
2177 for (zcu.import_table.keys()) |key| {
2178 gpa.free(key);
2179 }
2180 for (zcu.import_table.values()) |file_index| {
2181 pt.destroyFile(file_index);
2182 }
2183 zcu.import_table.deinit(gpa);
2177 if (zcu.llvm_object) |llvm_object| llvm_object.deinit();
21842178
2185 for (zcu.embed_table.keys(), zcu.embed_table.values()) |path, embed_file| {
2186 gpa.free(path);
2187 gpa.destroy(embed_file);
2188 }
2189 zcu.embed_table.deinit(gpa);
2179 for (zcu.import_table.keys()) |key| {
2180 gpa.free(key);
2181 }
2182 for (zcu.import_table.values()) |file_index| {
2183 pt.destroyFile(file_index);
2184 }
2185 zcu.import_table.deinit(gpa);
21902186
2191 zcu.compile_log_text.deinit(gpa);
2187 for (zcu.embed_table.keys(), zcu.embed_table.values()) |path, embed_file| {
2188 gpa.free(path);
2189 gpa.destroy(embed_file);
2190 }
2191 zcu.embed_table.deinit(gpa);
21922192
2193 zcu.local_zir_cache.handle.close();
2194 zcu.global_zir_cache.handle.close();
2193 zcu.compile_log_text.deinit(gpa);
21952194
2196 for (zcu.failed_analysis.values()) |value| {
2197 value.destroy(gpa);
2198 }
2199 for (zcu.failed_codegen.values()) |value| {
2200 value.destroy(gpa);
2201 }
2202 zcu.analysis_in_progress.deinit(gpa);
2203 zcu.failed_analysis.deinit(gpa);
2204 zcu.transitive_failed_analysis.deinit(gpa);
2205 zcu.failed_codegen.deinit(gpa);
2195 zcu.local_zir_cache.handle.close();
2196 zcu.global_zir_cache.handle.close();
22062197
2207 for (zcu.failed_files.values()) |value| {
2208 if (value) |msg| msg.destroy(gpa);
2209 }
2210 zcu.failed_files.deinit(gpa);
2198 for (zcu.failed_analysis.values()) |value| {
2199 value.destroy(gpa);
2200 }
2201 for (zcu.failed_codegen.values()) |value| {
2202 value.destroy(gpa);
2203 }
2204 zcu.analysis_in_progress.deinit(gpa);
2205 zcu.failed_analysis.deinit(gpa);
2206 zcu.transitive_failed_analysis.deinit(gpa);
2207 zcu.failed_codegen.deinit(gpa);
22112208
2212 for (zcu.failed_embed_files.values()) |msg| {
2213 msg.destroy(gpa);
2214 }
2215 zcu.failed_embed_files.deinit(gpa);
2209 for (zcu.failed_files.values()) |value| {
2210 if (value) |msg| msg.destroy(gpa);
2211 }
2212 zcu.failed_files.deinit(gpa);
22162213
2217 for (zcu.failed_exports.values()) |value| {
2218 value.destroy(gpa);
2219 }
2220 zcu.failed_exports.deinit(gpa);
2214 for (zcu.failed_embed_files.values()) |msg| {
2215 msg.destroy(gpa);
2216 }
2217 zcu.failed_embed_files.deinit(gpa);
22212218
2222 for (zcu.cimport_errors.values()) |*errs| {
2223 errs.deinit(gpa);
2224 }
2225 zcu.cimport_errors.deinit(gpa);
2219 for (zcu.failed_exports.values()) |value| {
2220 value.destroy(gpa);
2221 }
2222 zcu.failed_exports.deinit(gpa);
22262223
2227 zcu.compile_log_sources.deinit(gpa);
2224 for (zcu.cimport_errors.values()) |*errs| {
2225 errs.deinit(gpa);
2226 }
2227 zcu.cimport_errors.deinit(gpa);
22282228
2229 zcu.all_exports.deinit(gpa);
2230 zcu.free_exports.deinit(gpa);
2231 zcu.single_exports.deinit(gpa);
2232 zcu.multi_exports.deinit(gpa);
2229 zcu.compile_log_sources.deinit(gpa);
22332230
2234 zcu.potentially_outdated.deinit(gpa);
2235 zcu.outdated.deinit(gpa);
2236 zcu.outdated_ready.deinit(gpa);
2237 zcu.retryable_failures.deinit(gpa);
2231 zcu.all_exports.deinit(gpa);
2232 zcu.free_exports.deinit(gpa);
2233 zcu.single_exports.deinit(gpa);
2234 zcu.multi_exports.deinit(gpa);
22382235
2239 zcu.test_functions.deinit(gpa);
2236 zcu.potentially_outdated.deinit(gpa);
2237 zcu.outdated.deinit(gpa);
2238 zcu.outdated_ready.deinit(gpa);
2239 zcu.retryable_failures.deinit(gpa);
22402240
2241 for (zcu.global_assembly.values()) |s| {
2242 gpa.free(s);
2243 }
2244 zcu.global_assembly.deinit(gpa);
2241 zcu.test_functions.deinit(gpa);
22452242
2246 zcu.reference_table.deinit(gpa);
2247 zcu.all_references.deinit(gpa);
2248 zcu.free_references.deinit(gpa);
2243 for (zcu.global_assembly.values()) |s| {
2244 gpa.free(s);
2245 }
2246 zcu.global_assembly.deinit(gpa);
22492247
2250 zcu.type_reference_table.deinit(gpa);
2251 zcu.all_type_references.deinit(gpa);
2252 zcu.free_type_references.deinit(gpa);
2248 zcu.reference_table.deinit(gpa);
2249 zcu.all_references.deinit(gpa);
2250 zcu.free_references.deinit(gpa);
22532251
2254 if (zcu.resolved_references) |*r| r.deinit(gpa);
2252 zcu.type_reference_table.deinit(gpa);
2253 zcu.all_type_references.deinit(gpa);
2254 zcu.free_type_references.deinit(gpa);
22552255
2256 if (zcu.resolved_references) |*r| r.deinit(gpa);
2257 }
22562258 zcu.intern_pool.deinit(gpa);
22572259}
22582260
src/Zcu/PerThread.zig+9
......@@ -35,6 +35,15 @@ tid: Id,
3535pub const IdBacking = u7;
3636pub const Id = if (InternPool.single_threaded) enum { main } else enum(IdBacking) { main, _ };
3737
38pub fn activate(zcu: *Zcu, tid: Id) Zcu.PerThread {
39 zcu.intern_pool.activate();
40 return .{ .zcu = zcu, .tid = tid };
41}
42
43pub fn deactivate(pt: Zcu.PerThread) void {
44 pt.zcu.intern_pool.deactivate();
45}
46
3847fn deinitFile(pt: Zcu.PerThread, file_index: Zcu.File.Index) void {
3948 const zcu = pt.zcu;
4049 const gpa = zcu.gpa;
src/link.zig+6-3
......@@ -1537,20 +1537,23 @@ pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {
15371537 };
15381538 },
15391539 .codegen_nav => |nav_index| {
1540 const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
1540 const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));
1541 defer pt.deactivate();
15411542 pt.linkerUpdateNav(nav_index) catch |err| switch (err) {
15421543 error.OutOfMemory => diags.setAllocFailure(),
15431544 };
15441545 },
15451546 .codegen_func => |func| {
1546 const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
1547 const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));
1548 defer pt.deactivate();
15471549 // This call takes ownership of `func.air`.
15481550 pt.linkerUpdateFunc(func.func, func.air) catch |err| switch (err) {
15491551 error.OutOfMemory => diags.setAllocFailure(),
15501552 };
15511553 },
15521554 .codegen_type => |ty| {
1553 const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
1555 const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));
1556 defer pt.deactivate();
15541557 pt.linkerUpdateContainerType(ty) catch |err| switch (err) {
15551558 error.OutOfMemory => diags.setAllocFailure(),
15561559 };
src/link/C.zig+2-1
......@@ -419,7 +419,8 @@ pub fn flushModule(self: *C, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
419419 const gpa = comp.gpa;
420420 const zcu = self.base.comp.zcu.?;
421421 const ip = &zcu.intern_pool;
422 const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = tid };
422 const pt: Zcu.PerThread = .activate(zcu, tid);
423 defer pt.deactivate();
423424
424425 {
425426 var i: usize = 0;
src/link/Coff.zig+5-4
......@@ -2218,10 +2218,11 @@ pub fn flushModule(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
22182218 const sub_prog_node = prog_node.start("COFF Flush", 0);
22192219 defer sub_prog_node.end();
22202220
2221 const pt: Zcu.PerThread = .{
2222 .zcu = comp.zcu orelse return error.LinkingWithoutZigSourceUnimplemented,
2223 .tid = tid,
2224 };
2221 const pt: Zcu.PerThread = .activate(
2222 comp.zcu orelse return error.LinkingWithoutZigSourceUnimplemented,
2223 tid,
2224 );
2225 defer pt.deactivate();
22252226
22262227 if (coff.lazy_syms.getPtr(.anyerror_type)) |metadata| {
22272228 // Most lazy symbols can be updated on first use, but
src/link/Dwarf.zig+27-66
......@@ -2687,23 +2687,19 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
26872687 },
26882688 };
26892689 try wip_nav.abbrevCode(if (is_comptime)
2690 if (has_runtime_bits and has_comptime_state)
2691 .struct_field_comptime_runtime_bits_comptime_state
2692 else if (has_comptime_state)
2690 if (has_comptime_state)
26932691 .struct_field_comptime_comptime_state
26942692 else if (has_runtime_bits)
26952693 .struct_field_comptime_runtime_bits
26962694 else
26972695 .struct_field_comptime
26982696 else if (field_init != .none)
2699 if (has_runtime_bits and has_comptime_state)
2700 .struct_field_default_runtime_bits_comptime_state
2701 else if (has_comptime_state)
2697 if (has_comptime_state)
27022698 .struct_field_default_comptime_state
27032699 else if (has_runtime_bits)
27042700 .struct_field_default_runtime_bits
27052701 else
2706 .struct_field_default
2702 .struct_field
27072703 else
27082704 .struct_field);
27092705 if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name| try wip_nav.strp(field_name.toSlice(ip)) else {
......@@ -2717,8 +2713,10 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
27172713 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
27182714 field_type.abiAlignment(zcu).toByteUnits().?);
27192715 }
2720 if (has_runtime_bits) try wip_nav.blockValue(nav_src_loc, .fromInterned(field_init));
2721 if (has_comptime_state) try wip_nav.refValue(.fromInterned(field_init));
2716 if (has_comptime_state)
2717 try wip_nav.refValue(.fromInterned(field_init))
2718 else if (has_runtime_bits)
2719 try wip_nav.blockValue(nav_src_loc, .fromInterned(field_init));
27222720 }
27232721 try uleb128(diw, @intFromEnum(AbbrevCode.null));
27242722 }
......@@ -3363,9 +3361,7 @@ fn updateLazyType(
33633361 field_type.comptimeOnly(zcu) and try field_type.onePossibleValue(pt) == null,
33643362 },
33653363 };
3366 try wip_nav.abbrevCode(if (has_runtime_bits and has_comptime_state)
3367 .struct_field_comptime_runtime_bits_comptime_state
3368 else if (has_comptime_state)
3364 try wip_nav.abbrevCode(if (has_comptime_state)
33693365 .struct_field_comptime_comptime_state
33703366 else if (has_runtime_bits)
33713367 .struct_field_comptime_runtime_bits
......@@ -3386,8 +3382,10 @@ fn updateLazyType(
33863382 try uleb128(diw, field_type.abiAlignment(zcu).toByteUnits().?);
33873383 field_byte_offset += field_type.abiSize(zcu);
33883384 }
3389 if (has_runtime_bits) try wip_nav.blockValue(src_loc, .fromInterned(comptime_value));
3390 if (has_comptime_state) try wip_nav.refValue(.fromInterned(comptime_value));
3385 if (has_comptime_state)
3386 try wip_nav.refValue(.fromInterned(comptime_value))
3387 else if (has_runtime_bits)
3388 try wip_nav.blockValue(src_loc, .fromInterned(comptime_value));
33913389 }
33923390 try uleb128(diw, @intFromEnum(AbbrevCode.null));
33933391 },
......@@ -3956,23 +3954,19 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
39563954 },
39573955 };
39583956 try wip_nav.abbrevCode(if (is_comptime)
3959 if (has_runtime_bits and has_comptime_state)
3960 .struct_field_comptime_runtime_bits_comptime_state
3961 else if (has_comptime_state)
3957 if (has_comptime_state)
39623958 .struct_field_comptime_comptime_state
39633959 else if (has_runtime_bits)
39643960 .struct_field_comptime_runtime_bits
39653961 else
39663962 .struct_field_comptime
39673963 else if (field_init != .none)
3968 if (has_runtime_bits and has_comptime_state)
3969 .struct_field_default_runtime_bits_comptime_state
3970 else if (has_comptime_state)
3964 if (has_comptime_state)
39713965 .struct_field_default_comptime_state
39723966 else if (has_runtime_bits)
39733967 .struct_field_default_runtime_bits
39743968 else
3975 .struct_field_default
3969 .struct_field
39763970 else
39773971 .struct_field);
39783972 if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name| try wip_nav.strp(field_name.toSlice(ip)) else {
......@@ -3986,8 +3980,10 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
39863980 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
39873981 field_type.abiAlignment(zcu).toByteUnits().?);
39883982 }
3989 if (has_runtime_bits) try wip_nav.blockValue(ty_src_loc, .fromInterned(field_init));
3990 if (has_comptime_state) try wip_nav.refValue(.fromInterned(field_init));
3983 if (has_comptime_state)
3984 try wip_nav.refValue(.fromInterned(field_init))
3985 else if (has_runtime_bits)
3986 try wip_nav.blockValue(ty_src_loc, .fromInterned(field_init));
39913987 }
39923988 try uleb128(diw, @intFromEnum(AbbrevCode.null));
39933989 }
......@@ -4064,23 +4060,19 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
40644060 },
40654061 };
40664062 try wip_nav.abbrevCode(if (is_comptime)
4067 if (has_runtime_bits and has_comptime_state)
4068 .struct_field_comptime_runtime_bits_comptime_state
4069 else if (has_comptime_state)
4063 if (has_comptime_state)
40704064 .struct_field_comptime_comptime_state
40714065 else if (has_runtime_bits)
40724066 .struct_field_comptime_runtime_bits
40734067 else
40744068 .struct_field_comptime
40754069 else if (field_init != .none)
4076 if (has_runtime_bits and has_comptime_state)
4077 .struct_field_default_runtime_bits_comptime_state
4078 else if (has_comptime_state)
4070 if (has_comptime_state)
40794071 .struct_field_default_comptime_state
40804072 else if (has_runtime_bits)
40814073 .struct_field_default_runtime_bits
40824074 else
4083 .struct_field_default
4075 .struct_field
40844076 else
40854077 .struct_field);
40864078 if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name| try wip_nav.strp(field_name.toSlice(ip)) else {
......@@ -4094,8 +4086,10 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
40944086 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
40954087 field_type.abiAlignment(zcu).toByteUnits().?);
40964088 }
4097 if (has_runtime_bits) try wip_nav.blockValue(ty_src_loc, .fromInterned(field_init));
4098 if (has_comptime_state) try wip_nav.refValue(.fromInterned(field_init));
4089 if (has_comptime_state)
4090 try wip_nav.refValue(.fromInterned(field_init))
4091 else if (has_runtime_bits)
4092 try wip_nav.blockValue(ty_src_loc, .fromInterned(field_init));
40994093 }
41004094 try uleb128(diw, @intFromEnum(AbbrevCode.null));
41014095 }
......@@ -4680,14 +4674,11 @@ const AbbrevCode = enum {
46804674 big_enum_field,
46814675 generated_field,
46824676 struct_field,
4683 struct_field_default,
46844677 struct_field_default_runtime_bits,
46854678 struct_field_default_comptime_state,
4686 struct_field_default_runtime_bits_comptime_state,
46874679 struct_field_comptime,
46884680 struct_field_comptime_runtime_bits,
46894681 struct_field_comptime_comptime_state,
4690 struct_field_comptime_runtime_bits_comptime_state,
46914682 packed_struct_field,
46924683 untagged_union_field,
46934684 tagged_union,
......@@ -4980,15 +4971,6 @@ const AbbrevCode = enum {
49804971 .{ .alignment, .udata },
49814972 },
49824973 },
4983 .struct_field_default = .{
4984 .tag = .member,
4985 .attrs = &.{
4986 .{ .name, .strp },
4987 .{ .type, .ref_addr },
4988 .{ .data_member_location, .udata },
4989 .{ .alignment, .udata },
4990 },
4991 },
49924974 .struct_field_default_runtime_bits = .{
49934975 .tag = .member,
49944976 .attrs = &.{
......@@ -5006,18 +4988,7 @@ const AbbrevCode = enum {
50064988 .{ .type, .ref_addr },
50074989 .{ .data_member_location, .udata },
50084990 .{ .alignment, .udata },
5009 .{ .ZIG_comptime_default_value, .ref_addr },
5010 },
5011 },
5012 .struct_field_default_runtime_bits_comptime_state = .{
5013 .tag = .member,
5014 .attrs = &.{
5015 .{ .name, .strp },
5016 .{ .type, .ref_addr },
5017 .{ .data_member_location, .udata },
5018 .{ .alignment, .udata },
5019 .{ .default_value, .block },
5020 .{ .ZIG_comptime_default_value, .ref_addr },
4991 .{ .ZIG_comptime_value, .ref_addr },
50214992 },
50224993 },
50234994 .struct_field_comptime = .{
......@@ -5046,16 +5017,6 @@ const AbbrevCode = enum {
50465017 .{ .ZIG_comptime_value, .ref_addr },
50475018 },
50485019 },
5049 .struct_field_comptime_runtime_bits_comptime_state = .{
5050 .tag = .member,
5051 .attrs = &.{
5052 .{ .const_expr, .flag_present },
5053 .{ .name, .strp },
5054 .{ .type, .ref_addr },
5055 .{ .const_value, .block },
5056 .{ .ZIG_comptime_value, .ref_addr },
5057 },
5058 },
50595020 .packed_struct_field = .{
50605021 .tag = .member,
50615022 .attrs = &.{
src/link/Elf/ZigObject.zig+6-3
......@@ -267,7 +267,8 @@ pub fn deinit(self: *ZigObject, allocator: Allocator) void {
267267pub fn flush(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !void {
268268 // Handle any lazy symbols that were emitted by incremental compilation.
269269 if (self.lazy_syms.getPtr(.anyerror_type)) |metadata| {
270 const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.zcu.?, .tid = tid };
270 const pt: Zcu.PerThread = .activate(elf_file.base.comp.zcu.?, tid);
271 defer pt.deactivate();
271272
272273 // Most lazy symbols can be updated on first use, but
273274 // anyerror needs to wait for everything to be flushed.
......@@ -296,7 +297,8 @@ pub fn flush(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !void {
296297 }
297298
298299 if (build_options.enable_logging) {
299 const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.zcu.?, .tid = tid };
300 const pt: Zcu.PerThread = .activate(elf_file.base.comp.zcu.?, tid);
301 defer pt.deactivate();
300302 for (self.navs.keys(), self.navs.values()) |nav_index, meta| {
301303 checkNavAllocated(pt, nav_index, meta);
302304 }
......@@ -306,7 +308,8 @@ pub fn flush(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !void {
306308 }
307309
308310 if (self.dwarf) |*dwarf| {
309 const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.zcu.?, .tid = tid };
311 const pt: Zcu.PerThread = .activate(elf_file.base.comp.zcu.?, tid);
312 defer pt.deactivate();
310313 try dwarf.flushModule(pt);
311314
312315 const gpa = elf_file.base.comp.gpa;
src/link/MachO/ZigObject.zig+4-2
......@@ -549,7 +549,8 @@ pub fn getInputSection(self: ZigObject, atom: Atom, macho_file: *MachO) macho.se
549549pub fn flushModule(self: *ZigObject, macho_file: *MachO, tid: Zcu.PerThread.Id) !void {
550550 // Handle any lazy symbols that were emitted by incremental compilation.
551551 if (self.lazy_syms.getPtr(.anyerror_type)) |metadata| {
552 const pt: Zcu.PerThread = .{ .zcu = macho_file.base.comp.zcu.?, .tid = tid };
552 const pt: Zcu.PerThread = .activate(macho_file.base.comp.zcu.?, tid);
553 defer pt.deactivate();
553554
554555 // Most lazy symbols can be updated on first use, but
555556 // anyerror needs to wait for everything to be flushed.
......@@ -578,7 +579,8 @@ pub fn flushModule(self: *ZigObject, macho_file: *MachO, tid: Zcu.PerThread.Id)
578579 }
579580
580581 if (self.dwarf) |*dwarf| {
581 const pt: Zcu.PerThread = .{ .zcu = macho_file.base.comp.zcu.?, .tid = tid };
582 const pt: Zcu.PerThread = .activate(macho_file.base.comp.zcu.?, tid);
583 defer pt.deactivate();
582584 try dwarf.flushModule(pt);
583585
584586 self.debug_abbrev_dirty = false;
src/link/Plan9.zig+5-4
......@@ -604,10 +604,11 @@ pub fn flushModule(self: *Plan9, arena: Allocator, tid: Zcu.PerThread.Id, prog_n
604604
605605 defer assert(self.hdr.entry != 0x0);
606606
607 const pt: Zcu.PerThread = .{
608 .zcu = self.base.comp.zcu orelse return error.LinkingWithoutZigSourceUnimplemented,
609 .tid = tid,
610 };
607 const pt: Zcu.PerThread = .activate(
608 self.base.comp.zcu orelse return error.LinkingWithoutZigSourceUnimplemented,
609 tid,
610 );
611 defer pt.deactivate();
611612
612613 // finish up the lazy syms
613614 if (self.lazy_syms.getPtr(.none)) |metadata| {
src/link/Wasm/ZigObject.zig+2-1
......@@ -589,7 +589,8 @@ fn populateErrorNameTable(zig_object: *ZigObject, wasm: *Wasm, tid: Zcu.PerThrea
589589
590590 // Addend for each relocation to the table
591591 var addend: u32 = 0;
592 const pt: Zcu.PerThread = .{ .zcu = wasm.base.comp.zcu.?, .tid = tid };
592 const pt: Zcu.PerThread = .activate(wasm.base.comp.zcu.?, tid);
593 defer pt.deactivate();
593594 const slice_ty = Type.slice_const_u8_sentinel_0;
594595 const atom = wasm.getAtomPtr(atom_index);
595596 {
tools/lldb_pretty_printers.py+218-9
......@@ -13,21 +13,32 @@ page_size = 1 << 12
1313
1414def log2_int(i): return i.bit_length() - 1
1515
16def create_struct(name, struct_type, **inits):
17 struct_bytes = bytearray(struct_type.size)
18 struct_data = lldb.SBData()
16def create_struct(parent, name, struct_type, inits):
17 struct_bytes, struct_data = bytearray(struct_type.size), lldb.SBData()
1918 for field in struct_type.fields:
2019 field_size = field.type.size
21 field_bytes = inits[field.name].data.uint8[:field_size]
20 field_init = inits[field.name]
21 if isinstance(field_init, int):
22 match struct_data.byte_order:
23 case lldb.eByteOrderLittle:
24 byte_order = 'little'
25 case lldb.eByteOrderBig:
26 byte_order = 'big'
27 field_bytes = field_init.to_bytes(field_size, byte_order, signed=field.type.GetTypeFlags() & lldb.eTypeIsSigned != 0)
28 elif isinstance(field_init_type, lldb.SBValue):
29 field_bytes = field_init.data.uint8
30 else: return
2231 match struct_data.byte_order:
2332 case lldb.eByteOrderLittle:
33 field_bytes = field_bytes[:field_size]
2434 field_start = field.byte_offset
2535 struct_bytes[field_start:field_start + len(field_bytes)] = field_bytes
2636 case lldb.eByteOrderBig:
37 field_bytes = field_bytes[-field_size:]
2738 field_end = field.byte_offset + field_size
2839 struct_bytes[field_end - len(field_bytes):field_end] = field_bytes
2940 struct_data.SetData(lldb.SBError(), struct_bytes, struct_data.byte_order, struct_data.GetAddressByteSize())
30 return next(iter(inits.values())).CreateValueFromData(name, struct_data, struct_type)
41 return parent.CreateValueFromData(name, struct_data, struct_type)
3142
3243# Define Zig Language
3344
......@@ -292,6 +303,8 @@ class std_MultiArrayList_Slice_SynthProvider:
292303 return self.ptrs.CreateValueFromData('[%d]' % index, data, self.entry_type)
293304 except: return None
294305
306def MultiArrayList_Entry(type): return '^multi_array_list\\.MultiArrayList\\(%s\\)\\.Entry__struct_[1-9][0-9]*$' % type
307
295308class std_HashMapUnmanaged_SynthProvider:
296309 def __init__(self, value, _=None): self.value = value
297310 def update(self):
......@@ -702,7 +715,7 @@ class root_InternPool_Local_List_SynthProvider:
702715 def __init__(self, value, _=None): self.value = value
703716 def update(self):
704717 capacity = self.value.EvaluateExpression('@as(*@This().Header, @alignCast(@ptrCast(@this().bytes - @This().bytes_offset))).capacity')
705 self.view = create_struct('view', self.value.EvaluateExpression('@This().View').GetValueAsType(), bytes=self.value.GetChildMemberWithName('bytes'), len=capacity, capacity=capacity).GetNonSyntheticValue()
718 self.view = create_struct(self.value, '.view', self.value.type.FindDirectNestedType('View'), { 'bytes': self.value.GetChildMemberWithName('bytes'), 'len': capacity, 'capacity': capacity }).GetNonSyntheticValue()
706719 def has_children(self): return True
707720 def num_children(self): return 1
708721 def get_child_index(self, name):
......@@ -712,6 +725,199 @@ class root_InternPool_Local_List_SynthProvider:
712725 try: return (self.view,)[index]
713726 except: pass
714727
728expr_path_re = re.compile(r'\{([^}]+)%([^%#}]+)(?:#([^%#}]+))?\}')
729def root_InternPool_Index_SummaryProvider(value, _=None):
730 unwrapped = value.GetChildMemberWithName('unwrapped')
731 if not unwrapped: return '' # .none
732 tag = unwrapped.GetChildMemberWithName('tag')
733 tag_value = tag.value
734 summary = tag.CreateValueFromType(tag.type).GetChildMemberWithName('encodings').GetChildMemberWithName(tag_value.removeprefix('.')).GetChildMemberWithName('summary')
735 if not summary: return tag_value
736 return re.sub(
737 expr_path_re,
738 lambda matchobj: getattr(unwrapped.GetValueForExpressionPath(matchobj[1]), matchobj[2]).strip(matchobj[3] or ''),
739 summary.summary.removeprefix('.').removeprefix('@"').removesuffix('"').replace(r'\"', '"'),
740 )
741
742class root_InternPool_Index_SynthProvider:
743 def __init__(self, value, _=None): self.value = value
744 def update(self):
745 self.unwrapped = None
746 wrapped = self.value.unsigned
747 if wrapped == (1 << 32) - 1: return
748 unwrapped_type = self.value.type.FindDirectNestedType('Unwrapped')
749 ip = self.value.CreateValueFromType(unwrapped_type).GetChildMemberWithName('debug_state').GetChildMemberWithName('intern_pool').GetNonSyntheticValue().GetChildMemberWithName('?')
750 tid_shift_30 = ip.GetChildMemberWithName('tid_shift_30').unsigned
751 self.unwrapped = create_struct(self.value, '.unwrapped', unwrapped_type, { 'tid': wrapped >> tid_shift_30, 'index': wrapped & (1 << tid_shift_30) - 1 })
752 def has_children(self): return True
753 def num_children(self): return 0
754 def get_child_index(self, name):
755 try: return ('unwrapped',).index(name)
756 except: pass
757 def get_child_at_index(self, index):
758 try: return (self.unwrapped,)[index]
759 except: pass
760
761class root_InternPool_Index_Unwrapped_SynthProvider:
762 def __init__(self, value, _=None): self.value = value
763 def update(self):
764 self.tag, self.index, self.data, self.payload, self.trailing = None, None, None, None, None
765 index = self.value.GetChildMemberWithName('index')
766 ip = self.value.CreateValueFromType(self.value.type).GetChildMemberWithName('debug_state').GetChildMemberWithName('intern_pool').GetNonSyntheticValue().GetChildMemberWithName('?')
767 shared = ip.GetChildMemberWithName('locals').GetSyntheticValue().child[self.value.GetChildMemberWithName('tid').unsigned].GetChildMemberWithName('shared')
768 item = shared.GetChildMemberWithName('items').GetChildMemberWithName('view').child[index.unsigned]
769 self.tag, item_data = item.GetChildMemberWithName('tag'), item.GetChildMemberWithName('data')
770 encoding = self.tag.CreateValueFromType(self.tag.type).GetChildMemberWithName('encodings').GetChildMemberWithName(self.tag.value.removeprefix('.'))
771 encoding_index, encoding_data, encoding_payload, encoding_trailing, encoding_config = encoding.GetChildMemberWithName('index'), encoding.GetChildMemberWithName('data'), encoding.GetChildMemberWithName('payload'), encoding.GetChildMemberWithName('trailing'), encoding.GetChildMemberWithName('config')
772 if encoding_index:
773 index_type = encoding_index.GetValueAsType()
774 index_bytes, index_data = index.data.uint8, lldb.SBData()
775 match index_data.byte_order:
776 case lldb.eByteOrderLittle:
777 index_bytes = bytes(index_bytes[:index_type.size])
778 case lldb.eByteOrderBig:
779 index_bytes = bytes(index_bytes[-index_type.size:])
780 index_data.SetData(lldb.SBError(), index_bytes, index_data.byte_order, index_data.GetAddressByteSize())
781 self.index = self.value.CreateValueFromData('.index', index_data, index_type)
782 elif encoding_data:
783 data_type = encoding_data.GetValueAsType()
784 data_bytes, data_data = item_data.data.uint8, lldb.SBData()
785 match data_data.byte_order:
786 case lldb.eByteOrderLittle:
787 data_bytes = bytes(data_bytes[:data_type.size])
788 case lldb.eByteOrderBig:
789 data_bytes = bytes(data_bytes[-data_type.size:])
790 data_data.SetData(lldb.SBError(), data_bytes, data_data.byte_order, data_data.GetAddressByteSize())
791 self.data = self.value.CreateValueFromData('.data', data_data, data_type)
792 elif encoding_payload:
793 extra = shared.GetChildMemberWithName('extra').GetChildMemberWithName('view').GetChildMemberWithName('0')
794 extra_index = item_data.unsigned
795 payload_type = encoding_payload.GetValueAsType()
796 payload_fields = dict()
797 for payload_field in payload_type.fields:
798 payload_fields[payload_field.name] = extra.child[extra_index]
799 extra_index += 1
800 self.payload = create_struct(self.value, '.payload', payload_type, payload_fields)
801 if encoding_trailing and encoding_config:
802 trailing_type = encoding_trailing.GetValueAsType()
803 trailing_bytes, trailing_data = bytearray(trailing_type.size), lldb.SBData()
804 def eval_config(config_name):
805 expr = encoding_config.GetChildMemberWithName(config_name).summary.removeprefix('.').removeprefix('@"').removesuffix('"').replace(r'\"', '"')
806 if 'payload.' in expr:
807 return self.payload.EvaluateExpression(expr.replace('payload.', '@this().'))
808 elif expr.startswith('trailing.'):
809 field_type, field_byte_offset = trailing_type, 0
810 expr_parts = expr.split('.')
811 for expr_part in expr_parts[1:]:
812 field = next(filter(lambda field: field.name == expr_part, field_type.fields))
813 field_type = field.type
814 field_byte_offset += field.byte_offset
815 field_data = lldb.SBData()
816 field_bytes = trailing_bytes[field_byte_offset:field_byte_offset + field_type.size]
817 field_data.SetData(lldb.SBError(), field_bytes, field_data.byte_order, field_data.GetAddressByteSize())
818 return self.value.CreateValueFromData('.%s' % expr_parts[-1], field_data, field_type)
819 else:
820 return self.value.frame.EvaluateExpression(expr)
821 for trailing_field in trailing_type.fields:
822 trailing_field_type = trailing_field.type
823 trailing_field_name = 'trailing.%s' % trailing_field.name
824 trailing_field_byte_offset = trailing_field.byte_offset
825 while True:
826 match [trailing_field_type_field.name for trailing_field_type_field in trailing_field_type.fields]:
827 case ['has_value', '?']:
828 has_value_field, child_field = trailing_field_type.fields
829 trailing_field_name = '%s.%s' % (trailing_field_name, child_field.name)
830 match eval_config(trailing_field_name).value:
831 case 'true':
832 if has_value_field.type.name == 'bool':
833 trailing_bytes[trailing_field_byte_offset + has_value_field.byte_offset] = True
834 trailing_field_type = child_field.type
835 trailing_field_byte_offset += child_field.byte_offset
836 case 'false':
837 break
838 case ['ptr', 'len']:
839 ptr_field, len_field = trailing_field_type.fields
840 ptr_field_byte_offset, len_field_byte_offset = trailing_field_byte_offset + ptr_field.byte_offset, trailing_field_byte_offset + len_field.byte_offset
841 trailing_bytes[ptr_field_byte_offset:ptr_field_byte_offset + ptr_field.type.size] = extra.child[extra_index].address_of.data.uint8
842 len_field_value = eval_config('%s.len' % trailing_field_name)
843 len_field_size = len_field.type.size
844 match trailing_data.byte_order:
845 case lldb.eByteOrderLittle:
846 len_field_bytes = len_field_value.data.uint8[:len_field_size]
847 trailing_bytes[len_field_byte_offset:len_field_byte_offset + len(len_field_bytes)] = len_field_bytes
848 case lldb.eByteOrderBig:
849 len_field_bytes = len_field_value.data.uint8[-len_field_size:]
850 len_field_end = len_field_byte_offset + len_field_size
851 trailing_bytes[len_field_end - len(len_field_bytes):len_field_end] = len_field_bytes
852 extra_index += (ptr_field.type.GetPointeeType().size * len_field_value.unsigned + 3) // 4
853 break
854 case _:
855 for offset in range(0, trailing_field_type.size, 4):
856 trailing_bytes[trailing_field_byte_offset + offset:trailing_field_byte_offset + offset + 4] = extra.child[extra_index].data.uint8
857 extra_index += 1
858 break
859 trailing_data.SetData(lldb.SBError(), trailing_bytes, trailing_data.byte_order, trailing_data.GetAddressByteSize())
860 self.trailing = self.value.CreateValueFromData('.trailing', trailing_data, trailing_type)
861 def has_children(self): return True
862 def num_children(self): return 1 + ((self.index or self.data or self.payload) is not None) + (self.trailing is not None)
863 def get_child_index(self, name):
864 try: return ('tag', 'index' if self.index is not None else 'data' if self.data is not None else 'payload', 'trailing').index(name)
865 except: pass
866 def get_child_at_index(self, index):
867 try: return (self.tag, self.index or self.data or self.payload, self.trailing)[index]
868 except: pass
869
870def root_InternPool_String_SummaryProvider(value, _=None):
871 wrapped = value.unsigned
872 ip = value.CreateValueFromType(value.type).GetChildMemberWithName('debug_state').GetChildMemberWithName('intern_pool').GetNonSyntheticValue().GetChildMemberWithName('?')
873 tid_shift_32 = ip.GetChildMemberWithName('tid_shift_32').unsigned
874 locals_value = ip.GetChildMemberWithName('locals').GetSyntheticValue()
875 local_value = locals_value.child[wrapped >> tid_shift_32]
876 if local_value is None:
877 wrapped = 0
878 local_value = locals_value.child[0]
879 string = local_value.GetChildMemberWithName('shared').GetChildMemberWithName('strings').GetChildMemberWithName('view').GetChildMemberWithName('0').child[wrapped & (1 << tid_shift_32) - 1].address_of
880 string.format = lldb.eFormatCString
881 return string.value
882
883class root_InternPool_Cau_Index_SynthProvider:
884 def __init__(self, value, _=None): self.value = value
885 def update(self):
886 self.cau = None
887 wrapped = self.value.unsigned
888 if wrapped == (1 << 32) - 1: return
889 ip = self.value.CreateValueFromType(self.value.type).GetChildMemberWithName('debug_state').GetChildMemberWithName('intern_pool').GetNonSyntheticValue().GetChildMemberWithName('?')
890 tid_shift_31 = ip.GetChildMemberWithName('tid_shift_31').unsigned
891 locals_value = ip.GetChildMemberWithName('locals').GetSyntheticValue()
892 local_value = locals_value.child[wrapped >> tid_shift_31]
893 if local_value is None:
894 wrapped = 0
895 local_value = locals_value.child[0]
896 self.cau = local_value.GetChildMemberWithName('shared').GetChildMemberWithName('caus').GetChildMemberWithName('view').GetChildMemberWithName('0').child[wrapped & (1 << tid_shift_31) - 1]
897 def has_children(self): return self.cau.GetNumChildren(1) > 0
898 def num_children(self): return self.cau.GetNumChildren()
899 def get_child_index(self, name): return self.cau.GetIndexOfChildWithName(name)
900 def get_child_at_index(self, index): return self.cau.GetChildAtIndex(index)
901
902class root_InternPool_Nav_Index_SynthProvider:
903 def __init__(self, value, _=None): self.value = value
904 def update(self):
905 self.nav = None
906 wrapped = self.value.unsigned
907 if wrapped == (1 << 32) - 1: return
908 ip = self.value.CreateValueFromType(self.value.type).GetChildMemberWithName('debug_state').GetChildMemberWithName('intern_pool').GetNonSyntheticValue().GetChildMemberWithName('?')
909 tid_shift_32 = ip.GetChildMemberWithName('tid_shift_32').unsigned
910 locals_value = ip.GetChildMemberWithName('locals').GetSyntheticValue()
911 local_value = locals_value.child[wrapped >> tid_shift_32]
912 if local_value is None:
913 wrapped = 0
914 local_value = locals_value.child[0]
915 self.nav = local_value.GetChildMemberWithName('shared').GetChildMemberWithName('navs').GetChildMemberWithName('view').child[wrapped & (1 << tid_shift_32) - 1]
916 def has_children(self): return self.nav.GetNumChildren(1) > 0
917 def num_children(self): return self.nav.GetNumChildren()
918 def get_child_index(self, name): return self.nav.GetIndexOfChildWithName(name)
919 def get_child_at_index(self, index): return self.nav.GetChildAtIndex(index)
920
715921# Initialize
716922
717923def add(debugger, *, category, regex=False, type, identifier=None, synth=False, inline_children=False, expand=False, summary=False):
......@@ -719,8 +925,6 @@ def add(debugger, *, category, regex=False, type, identifier=None, synth=False,
719925 if summary: debugger.HandleCommand('type summary add --category %s%s%s "%s"' % (category, ' --inline-children' if inline_children else ''.join((' --expand' if expand else '', ' --python-function %s_SummaryProvider' % prefix if summary == True else ' --summary-string "%s"' % summary)), ' --regex' if regex else '', type))
720926 if synth: debugger.HandleCommand('type synthetic add --category %s%s --python-class %s_SynthProvider "%s"' % (category, ' --regex' if regex else '', prefix, type))
721927
722def MultiArrayList_Entry(type): return '^multi_array_list\\.MultiArrayList\\(%s\\)\\.Entry__struct_[1-9][0-9]*$' % type
723
724928def __lldb_init_module(debugger, _=None):
725929 # Initialize Zig Categories
726930 debugger.HandleCommand('type category define --language c99 zig.lang zig.std')
......@@ -765,4 +969,9 @@ def __lldb_init_module(debugger, _=None):
765969 add(debugger, category='zig.stage2', type='arch.x86_64.CodeGen.MCValue', identifier='zig_TaggedUnion', synth=True, inline_children=True, summary=True)
766970
767971 # Initialize Zig Stage2 Compiler (compiled with the self-hosted backend)
768 add(debugger, category='zig', regex=True, type='^root\\.InternPool\\.Local\\.List\\(.*\\)$', identifier='root_InternPool_Local_List', synth=True, expand=True, summary='capacity=${var%#}')
972 add(debugger, category='zig', regex=True, type=r'^root\.InternPool\.Local\.List\(.*\)$', identifier='root_InternPool_Local_List', synth=True, expand=True, summary='capacity=${var%#}')
973 add(debugger, category='zig', type='root.InternPool.Index', synth=True, summary=True)
974 add(debugger, category='zig', type='root.InternPool.Index.Unwrapped', synth=True)
975 add(debugger, category='zig', regex=True, type=r'^root\.InternPool\.(Optional)?(NullTerminated)?String$', identifier='root_InternPool_String', summary=True)
976 add(debugger, category='zig', regex=True, type=r'^root\.InternPool\.Cau\.Index(\.Optional)?$', identifier='root_InternPool_Cau_Index', synth=True)
977 add(debugger, category='zig', regex=True, type=r'^root\.InternPool\.Nav\.Index(\.Optional)?$', identifier='root_InternPool_Nav_Index', synth=True)