authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-09-10 17:31:06-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-09-10 17:31:06-04:00
log8ec68c63fa1d0f7e267ff92c054e8aa335f91da4
treee2fbdd384dbc2509c4a3b633b41e651a6e01b157
parent90075345519f165a0164c52b62b78453068c6ce6
parent6aa6d088d93174767d3a8387d536f4083c39e14f
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #21323 from jacobly0/dwarf-decls

Dwarf: implement more decls

26 files changed, 1354 insertions(+), 695 deletions(-)

ci/x86_64-linux-debug.sh+1-1
......@@ -64,7 +64,7 @@ stage3-debug/bin/zig build \
6464
6565stage3-debug/bin/zig build test docs \
6666 --maxrss 21000000000 \
67 -Dlldb=$HOME/deps/lldb-zig/Debug-befcd57a8/bin/lldb \
67 -Dlldb=$HOME/deps/lldb-zig/Debug-4a44163df/bin/lldb \
6868 -fqemu \
6969 -fwasmtime \
7070 -Dstatic-llvm \
ci/x86_64-linux-release.sh+1-1
......@@ -64,7 +64,7 @@ stage3-release/bin/zig build \
6464
6565stage3-release/bin/zig build test docs \
6666 --maxrss 21000000000 \
67 -Dlldb=$HOME/deps/lldb-zig/Release-befcd57a8/bin/lldb \
67 -Dlldb=$HOME/deps/lldb-zig/Release-4a44163df/bin/lldb \
6868 -fqemu \
6969 -fwasmtime \
7070 -Dstatic-llvm \
lib/std/hash_map.zig+5-3
......@@ -1767,9 +1767,11 @@ pub fn HashMapUnmanaged(
17671767 }
17681768
17691769 comptime {
1770 if (!builtin.strip_debug_info) {
1771 _ = &dbHelper;
1772 }
1770 if (!builtin.strip_debug_info) _ = switch (builtin.zig_backend) {
1771 .stage2_llvm => &dbHelper,
1772 .stage2_x86_64 => KV,
1773 else => {},
1774 };
17731775 }
17741776 };
17751777}
lib/std/multi_array_list.zig+1-1
......@@ -573,7 +573,7 @@ pub fn MultiArrayList(comptime T: type) type {
573573 }
574574
575575 comptime {
576 if (!builtin.strip_debug_info) {
576 if (builtin.zig_backend == .stage2_llvm and !builtin.strip_debug_info) {
577577 _ = &dbHelper;
578578 _ = &Slice.dbHelper;
579579 }
src/InternPool.zig+1-1
......@@ -4723,7 +4723,7 @@ pub const Index = enum(u32) {
47234723 }
47244724
47254725 comptime {
4726 if (!builtin.strip_debug_info) {
4726 if (builtin.zig_backend == .stage2_llvm and !builtin.strip_debug_info) {
47274727 _ = &dbHelper;
47284728 }
47294729 }
src/arch/aarch64/CodeGen.zig+2-3
......@@ -25,7 +25,6 @@ const Alignment = InternPool.Alignment;
2525
2626const CodeGenError = codegen.CodeGenError;
2727const Result = codegen.Result;
28const DebugInfoOutput = codegen.DebugInfoOutput;
2928
3029const bits = @import("bits.zig");
3130const abi = @import("abi.zig");
......@@ -48,7 +47,7 @@ pt: Zcu.PerThread,
4847air: Air,
4948liveness: Liveness,
5049bin_file: *link.File,
51debug_output: DebugInfoOutput,
50debug_output: link.File.DebugInfoOutput,
5251target: *const std.Target,
5352func_index: InternPool.Index,
5453owner_nav: InternPool.Nav.Index,
......@@ -327,7 +326,7 @@ pub fn generate(
327326 air: Air,
328327 liveness: Liveness,
329328 code: *std.ArrayList(u8),
330 debug_output: DebugInfoOutput,
329 debug_output: link.File.DebugInfoOutput,
331330) CodeGenError!Result {
332331 const zcu = pt.zcu;
333332 const gpa = zcu.gpa;
src/arch/aarch64/Emit.zig+1-2
......@@ -13,11 +13,10 @@ const assert = std.debug.assert;
1313const Instruction = bits.Instruction;
1414const Register = bits.Register;
1515const log = std.log.scoped(.aarch64_emit);
16const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput;
1716
1817mir: Mir,
1918bin_file: *link.File,
20debug_output: DebugInfoOutput,
19debug_output: link.File.DebugInfoOutput,
2120target: *const std.Target,
2221err_msg: ?*ErrorMsg = null,
2322src_loc: Zcu.LazySrcLoc,
src/arch/arm/CodeGen.zig+2-3
......@@ -25,7 +25,6 @@ const Alignment = InternPool.Alignment;
2525
2626const Result = codegen.Result;
2727const CodeGenError = codegen.CodeGenError;
28const DebugInfoOutput = codegen.DebugInfoOutput;
2928
3029const bits = @import("bits.zig");
3130const abi = @import("abi.zig");
......@@ -49,7 +48,7 @@ pt: Zcu.PerThread,
4948air: Air,
5049liveness: Liveness,
5150bin_file: *link.File,
52debug_output: DebugInfoOutput,
51debug_output: link.File.DebugInfoOutput,
5352target: *const std.Target,
5453func_index: InternPool.Index,
5554err_msg: ?*ErrorMsg,
......@@ -335,7 +334,7 @@ pub fn generate(
335334 air: Air,
336335 liveness: Liveness,
337336 code: *std.ArrayList(u8),
338 debug_output: DebugInfoOutput,
337 debug_output: link.File.DebugInfoOutput,
339338) CodeGenError!Result {
340339 const zcu = pt.zcu;
341340 const gpa = zcu.gpa;
src/arch/arm/Emit.zig+1-2
......@@ -16,12 +16,11 @@ const assert = std.debug.assert;
1616const Instruction = bits.Instruction;
1717const Register = bits.Register;
1818const log = std.log.scoped(.aarch32_emit);
19const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput;
2019const CodeGen = @import("CodeGen.zig");
2120
2221mir: Mir,
2322bin_file: *link.File,
24debug_output: DebugInfoOutput,
23debug_output: link.File.DebugInfoOutput,
2524target: *const std.Target,
2625err_msg: ?*ErrorMsg = null,
2726src_loc: Zcu.LazySrcLoc,
src/arch/riscv64/CodeGen.zig+3-4
......@@ -32,7 +32,6 @@ const Alignment = InternPool.Alignment;
3232
3333const CodeGenError = codegen.CodeGenError;
3434const Result = codegen.Result;
35const DebugInfoOutput = codegen.DebugInfoOutput;
3635
3736const bits = @import("bits.zig");
3837const abi = @import("abi.zig");
......@@ -61,7 +60,7 @@ gpa: Allocator,
6160
6261mod: *Package.Module,
6362target: *const std.Target,
64debug_output: DebugInfoOutput,
63debug_output: link.File.DebugInfoOutput,
6564err_msg: ?*ErrorMsg,
6665args: []MCValue,
6766ret_mcv: InstTracking,
......@@ -760,7 +759,7 @@ pub fn generate(
760759 air: Air,
761760 liveness: Liveness,
762761 code: *std.ArrayList(u8),
763 debug_output: DebugInfoOutput,
762 debug_output: link.File.DebugInfoOutput,
764763) CodeGenError!Result {
765764 const zcu = pt.zcu;
766765 const comp = zcu.comp;
......@@ -928,7 +927,7 @@ pub fn generateLazy(
928927 src_loc: Zcu.LazySrcLoc,
929928 lazy_sym: link.File.LazySymbol,
930929 code: *std.ArrayList(u8),
931 debug_output: DebugInfoOutput,
930 debug_output: link.File.DebugInfoOutput,
932931) CodeGenError!Result {
933932 const comp = bin_file.comp;
934933 const gpa = comp.gpa;
src/arch/riscv64/Emit.zig+1-2
......@@ -2,7 +2,7 @@
22
33bin_file: *link.File,
44lower: Lower,
5debug_output: DebugInfoOutput,
5debug_output: link.File.DebugInfoOutput,
66code: *std.ArrayList(u8),
77
88prev_di_line: u32,
......@@ -216,7 +216,6 @@ const log = std.log.scoped(.emit);
216216const mem = std.mem;
217217const std = @import("std");
218218
219const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput;
220219const Emit = @This();
221220const Lower = @import("Lower.zig");
222221const Mir = @import("Mir.zig");
src/arch/sparc64/CodeGen.zig+2-3
......@@ -22,7 +22,6 @@ const Liveness = @import("../../Liveness.zig");
2222const Type = @import("../../Type.zig");
2323const CodeGenError = codegen.CodeGenError;
2424const Result = @import("../../codegen.zig").Result;
25const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput;
2625const Endian = std.builtin.Endian;
2726const Alignment = InternPool.Alignment;
2827
......@@ -57,7 +56,7 @@ bin_file: *link.File,
5756target: *const std.Target,
5857func_index: InternPool.Index,
5958code: *std.ArrayList(u8),
60debug_output: DebugInfoOutput,
59debug_output: link.File.DebugInfoOutput,
6160err_msg: ?*ErrorMsg,
6261args: []MCValue,
6362ret_mcv: MCValue,
......@@ -268,7 +267,7 @@ pub fn generate(
268267 air: Air,
269268 liveness: Liveness,
270269 code: *std.ArrayList(u8),
271 debug_output: DebugInfoOutput,
270 debug_output: link.File.DebugInfoOutput,
272271) CodeGenError!Result {
273272 const zcu = pt.zcu;
274273 const gpa = zcu.gpa;
src/arch/sparc64/Emit.zig+1-2
......@@ -9,7 +9,6 @@ const Zcu = @import("../../Zcu.zig");
99const ErrorMsg = Zcu.ErrorMsg;
1010const Liveness = @import("../../Liveness.zig");
1111const log = std.log.scoped(.sparcv9_emit);
12const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput;
1312
1413const Emit = @This();
1514const Mir = @import("Mir.zig");
......@@ -19,7 +18,7 @@ const Register = bits.Register;
1918
2019mir: Mir,
2120bin_file: *link.File,
22debug_output: DebugInfoOutput,
21debug_output: link.File.DebugInfoOutput,
2322target: *const std.Target,
2423err_msg: ?*ErrorMsg = null,
2524src_loc: Zcu.LazySrcLoc,
src/arch/wasm/CodeGen.zig+2-2
......@@ -648,7 +648,7 @@ block_depth: u32 = 0,
648648air: Air,
649649liveness: Liveness,
650650gpa: mem.Allocator,
651debug_output: codegen.DebugInfoOutput,
651debug_output: link.File.DebugInfoOutput,
652652func_index: InternPool.Index,
653653/// Contains a list of current branches.
654654/// When we return from a branch, the branch will be popped from this list,
......@@ -1211,7 +1211,7 @@ pub fn generate(
12111211 air: Air,
12121212 liveness: Liveness,
12131213 code: *std.ArrayList(u8),
1214 debug_output: codegen.DebugInfoOutput,
1214 debug_output: link.File.DebugInfoOutput,
12151215) codegen.CodeGenError!codegen.Result {
12161216 const zcu = pt.zcu;
12171217 const gpa = zcu.gpa;
src/arch/wasm/Emit.zig+1-1
......@@ -26,7 +26,7 @@ owner_nav: InternPool.Nav.Index,
2626
2727// Debug information
2828/// Holds the debug information for this emission
29dbg_output: codegen.DebugInfoOutput,
29dbg_output: link.File.DebugInfoOutput,
3030/// Previous debug info line
3131prev_di_line: u32,
3232/// Previous debug info column
src/arch/x86_64/CodeGen.zig+3-4
......@@ -17,7 +17,6 @@ const Air = @import("../../Air.zig");
1717const Allocator = mem.Allocator;
1818const CodeGenError = codegen.CodeGenError;
1919const Compilation = @import("../../Compilation.zig");
20const DebugInfoOutput = codegen.DebugInfoOutput;
2120const ErrorMsg = Zcu.ErrorMsg;
2221const Result = codegen.Result;
2322const Emit = @import("Emit.zig");
......@@ -53,7 +52,7 @@ pt: Zcu.PerThread,
5352air: Air,
5453liveness: Liveness,
5554bin_file: *link.File,
56debug_output: DebugInfoOutput,
55debug_output: link.File.DebugInfoOutput,
5756target: *const std.Target,
5857owner: Owner,
5958inline_func: InternPool.Index,
......@@ -819,7 +818,7 @@ pub fn generate(
819818 air: Air,
820819 liveness: Liveness,
821820 code: *std.ArrayList(u8),
822 debug_output: DebugInfoOutput,
821 debug_output: link.File.DebugInfoOutput,
823822) CodeGenError!Result {
824823 const zcu = pt.zcu;
825824 const comp = zcu.comp;
......@@ -1000,7 +999,7 @@ pub fn generateLazy(
1000999 src_loc: Zcu.LazySrcLoc,
10011000 lazy_sym: link.File.LazySymbol,
10021001 code: *std.ArrayList(u8),
1003 debug_output: DebugInfoOutput,
1002 debug_output: link.File.DebugInfoOutput,
10041003) CodeGenError!Result {
10051004 const comp = bin_file.comp;
10061005 const gpa = comp.gpa;
src/arch/x86_64/Emit.zig+1-2
......@@ -3,7 +3,7 @@
33air: Air,
44lower: Lower,
55atom_index: u32,
6debug_output: DebugInfoOutput,
6debug_output: link.File.DebugInfoOutput,
77code: *std.ArrayList(u8),
88
99prev_di_line: u32,
......@@ -546,7 +546,6 @@ const log = std.log.scoped(.emit);
546546const std = @import("std");
547547
548548const Air = @import("../../Air.zig");
549const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput;
550549const Emit = @This();
551550const Lower = @import("Lower.zig");
552551const Mir = @import("Mir.zig");
src/codegen.zig+34-60
......@@ -38,12 +38,6 @@ pub const CodeGenError = error{
3838 CodegenFail,
3939} || link.File.UpdateDebugInfoError;
4040
41pub const DebugInfoOutput = union(enum) {
42 dwarf: *link.File.Dwarf.WipNav,
43 plan9: *link.File.Plan9.DebugInfoOutput,
44 none,
45};
46
4741fn devFeatureForBackend(comptime backend: std.builtin.CompilerBackend) dev.Feature {
4842 comptime assert(mem.startsWith(u8, @tagName(backend), "stage2_"));
4943 return @field(dev.Feature, @tagName(backend)["stage2_".len..] ++ "_backend");
......@@ -69,7 +63,7 @@ pub fn generateFunction(
6963 air: Air,
7064 liveness: Liveness,
7165 code: *std.ArrayList(u8),
72 debug_output: DebugInfoOutput,
66 debug_output: link.File.DebugInfoOutput,
7367) CodeGenError!Result {
7468 const zcu = pt.zcu;
7569 const func = zcu.funcInfo(func_index);
......@@ -95,7 +89,7 @@ pub fn generateLazyFunction(
9589 src_loc: Zcu.LazySrcLoc,
9690 lazy_sym: link.File.LazySymbol,
9791 code: *std.ArrayList(u8),
98 debug_output: DebugInfoOutput,
92 debug_output: link.File.DebugInfoOutput,
9993) CodeGenError!Result {
10094 const zcu = pt.zcu;
10195 const file = Type.fromInterned(lazy_sym.ty).typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(&zcu.intern_pool);
......@@ -127,10 +121,10 @@ pub fn generateLazySymbol(
127121 // TODO don't use an "out" parameter like this; put it in the result instead
128122 alignment: *Alignment,
129123 code: *std.ArrayList(u8),
130 debug_output: DebugInfoOutput,
131 reloc_info: RelocInfo,
124 debug_output: link.File.DebugInfoOutput,
125 reloc_parent: link.File.RelocInfo.Parent,
132126) CodeGenError!Result {
133 _ = reloc_info;
127 _ = reloc_parent;
134128
135129 const tracy = trace(@src());
136130 defer tracy.end();
......@@ -192,8 +186,7 @@ pub fn generateSymbol(
192186 src_loc: Zcu.LazySrcLoc,
193187 val: Value,
194188 code: *std.ArrayList(u8),
195 debug_output: DebugInfoOutput,
196 reloc_info: RelocInfo,
189 reloc_parent: link.File.RelocInfo.Parent,
197190) CodeGenError!Result {
198191 const tracy = trace(@src());
199192 defer tracy.end();
......@@ -290,7 +283,7 @@ pub fn generateSymbol(
290283 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(switch (error_union.val) {
291284 .err_name => try pt.intern(.{ .undef = payload_ty.toIntern() }),
292285 .payload => |payload| payload,
293 }), code, debug_output, reloc_info)) {
286 }), code, reloc_parent)) {
294287 .ok => {},
295288 .fail => |em| return .{ .fail = em },
296289 }
......@@ -318,7 +311,7 @@ pub fn generateSymbol(
318311 },
319312 .enum_tag => |enum_tag| {
320313 const int_tag_ty = ty.intTagType(zcu);
321 switch (try generateSymbol(bin_file, pt, src_loc, try pt.getCoerced(Value.fromInterned(enum_tag.int), int_tag_ty), code, debug_output, reloc_info)) {
314 switch (try generateSymbol(bin_file, pt, src_loc, try pt.getCoerced(Value.fromInterned(enum_tag.int), int_tag_ty), code, reloc_parent)) {
322315 .ok => {},
323316 .fail => |em| return .{ .fail = em },
324317 }
......@@ -334,16 +327,16 @@ pub fn generateSymbol(
334327 },
335328 .f128 => |f128_val| writeFloat(f128, f128_val, target, endian, try code.addManyAsArray(16)),
336329 },
337 .ptr => switch (try lowerPtr(bin_file, pt, src_loc, val.toIntern(), code, debug_output, reloc_info, 0)) {
330 .ptr => switch (try lowerPtr(bin_file, pt, src_loc, val.toIntern(), code, reloc_parent, 0)) {
338331 .ok => {},
339332 .fail => |em| return .{ .fail = em },
340333 },
341334 .slice => |slice| {
342 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(slice.ptr), code, debug_output, reloc_info)) {
335 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(slice.ptr), code, reloc_parent)) {
343336 .ok => {},
344337 .fail => |em| return .{ .fail = em },
345338 }
346 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(slice.len), code, debug_output, reloc_info)) {
339 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(slice.len), code, reloc_parent)) {
347340 .ok => {},
348341 .fail => |em| return .{ .fail = em },
349342 }
......@@ -355,7 +348,7 @@ pub fn generateSymbol(
355348
356349 if (ty.optionalReprIsPayload(zcu)) {
357350 if (payload_val) |value| {
358 switch (try generateSymbol(bin_file, pt, src_loc, value, code, debug_output, reloc_info)) {
351 switch (try generateSymbol(bin_file, pt, src_loc, value, code, reloc_parent)) {
359352 .ok => {},
360353 .fail => |em| return Result{ .fail = em },
361354 }
......@@ -368,7 +361,7 @@ pub fn generateSymbol(
368361 const value = payload_val orelse Value.fromInterned(try pt.intern(.{
369362 .undef = payload_type.toIntern(),
370363 }));
371 switch (try generateSymbol(bin_file, pt, src_loc, value, code, debug_output, reloc_info)) {
364 switch (try generateSymbol(bin_file, pt, src_loc, value, code, reloc_parent)) {
372365 .ok => {},
373366 .fail => |em| return Result{ .fail = em },
374367 }
......@@ -390,7 +383,7 @@ pub fn generateSymbol(
390383 elem
391384 else
392385 array_type.sentinel,
393 }), code, debug_output, reloc_info)) {
386 }), code, reloc_parent)) {
394387 .ok => {},
395388 .fail => |em| return .{ .fail = em },
396389 }
......@@ -449,7 +442,7 @@ pub fn generateSymbol(
449442 math.cast(usize, index) orelse return error.Overflow
450443 ],
451444 .repeated_elem => |elem| elem,
452 }), code, debug_output, reloc_info)) {
445 }), code, reloc_parent)) {
453446 .ok => {},
454447 .fail => |em| return .{ .fail = em },
455448 }
......@@ -482,7 +475,7 @@ pub fn generateSymbol(
482475 .repeated_elem => |elem| elem,
483476 };
484477
485 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(field_val), code, debug_output, reloc_info)) {
478 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(field_val), code, reloc_parent)) {
486479 .ok => {},
487480 .fail => |em| return Result{ .fail = em },
488481 }
......@@ -524,7 +517,7 @@ pub fn generateSymbol(
524517 return error.Overflow;
525518 var tmp_list = try std.ArrayList(u8).initCapacity(code.allocator, field_size);
526519 defer tmp_list.deinit();
527 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(field_val), &tmp_list, debug_output, reloc_info)) {
520 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(field_val), &tmp_list, reloc_parent)) {
528521 .ok => @memcpy(code.items[current_pos..][0..tmp_list.items.len], tmp_list.items),
529522 .fail => |em| return Result{ .fail = em },
530523 }
......@@ -559,7 +552,7 @@ pub fn generateSymbol(
559552 ) orelse return error.Overflow;
560553 if (padding > 0) try code.appendNTimes(0, padding);
561554
562 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(field_val), code, debug_output, reloc_info)) {
555 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(field_val), code, reloc_parent)) {
563556 .ok => {},
564557 .fail => |em| return Result{ .fail = em },
565558 }
......@@ -583,12 +576,12 @@ pub fn generateSymbol(
583576 const layout = ty.unionGetLayout(zcu);
584577
585578 if (layout.payload_size == 0) {
586 return generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.tag), code, debug_output, reloc_info);
579 return generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.tag), code, reloc_parent);
587580 }
588581
589582 // Check if we should store the tag first.
590583 if (layout.tag_size > 0 and layout.tag_align.compare(.gte, layout.payload_align)) {
591 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.tag), code, debug_output, reloc_info)) {
584 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.tag), code, reloc_parent)) {
592585 .ok => {},
593586 .fail => |em| return Result{ .fail = em },
594587 }
......@@ -601,7 +594,7 @@ pub fn generateSymbol(
601594 if (!field_ty.hasRuntimeBits(zcu)) {
602595 try code.appendNTimes(0xaa, math.cast(usize, layout.payload_size) orelse return error.Overflow);
603596 } else {
604 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.val), code, debug_output, reloc_info)) {
597 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.val), code, reloc_parent)) {
605598 .ok => {},
606599 .fail => |em| return Result{ .fail = em },
607600 }
......@@ -612,14 +605,14 @@ pub fn generateSymbol(
612605 }
613606 }
614607 } else {
615 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.val), code, debug_output, reloc_info)) {
608 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.val), code, reloc_parent)) {
616609 .ok => {},
617610 .fail => |em| return Result{ .fail = em },
618611 }
619612 }
620613
621614 if (layout.tag_size > 0 and layout.tag_align.compare(.lt, layout.payload_align)) {
622 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.tag), code, debug_output, reloc_info)) {
615 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.tag), code, reloc_parent)) {
623616 .ok => {},
624617 .fail => |em| return Result{ .fail = em },
625618 }
......@@ -640,40 +633,29 @@ fn lowerPtr(
640633 src_loc: Zcu.LazySrcLoc,
641634 ptr_val: InternPool.Index,
642635 code: *std.ArrayList(u8),
643 debug_output: DebugInfoOutput,
644 reloc_info: RelocInfo,
636 reloc_parent: link.File.RelocInfo.Parent,
645637 prev_offset: u64,
646638) CodeGenError!Result {
647639 const zcu = pt.zcu;
648640 const ptr = zcu.intern_pool.indexToKey(ptr_val).ptr;
649641 const offset: u64 = prev_offset + ptr.byte_offset;
650642 return switch (ptr.base_addr) {
651 .nav => |nav| try lowerNavRef(bin_file, pt, src_loc, nav, code, debug_output, reloc_info, offset),
652 .uav => |uav| try lowerUavRef(bin_file, pt, src_loc, uav, code, debug_output, reloc_info, offset),
653 .int => try generateSymbol(bin_file, pt, src_loc, try pt.intValue(Type.usize, offset), code, debug_output, reloc_info),
643 .nav => |nav| try lowerNavRef(bin_file, pt, src_loc, nav, code, reloc_parent, offset),
644 .uav => |uav| try lowerUavRef(bin_file, pt, src_loc, uav, code, reloc_parent, offset),
645 .int => try generateSymbol(bin_file, pt, src_loc, try pt.intValue(Type.usize, offset), code, reloc_parent),
654646 .eu_payload => |eu_ptr| try lowerPtr(
655647 bin_file,
656648 pt,
657649 src_loc,
658650 eu_ptr,
659651 code,
660 debug_output,
661 reloc_info,
652 reloc_parent,
662653 offset + errUnionPayloadOffset(
663654 Value.fromInterned(eu_ptr).typeOf(zcu).childType(zcu).errorUnionPayload(zcu),
664655 zcu,
665656 ),
666657 ),
667 .opt_payload => |opt_ptr| try lowerPtr(
668 bin_file,
669 pt,
670 src_loc,
671 opt_ptr,
672 code,
673 debug_output,
674 reloc_info,
675 offset,
676 ),
658 .opt_payload => |opt_ptr| try lowerPtr(bin_file, pt, src_loc, opt_ptr, code, reloc_parent, offset),
677659 .field => |field| {
678660 const base_ptr = Value.fromInterned(field.base);
679661 const base_ty = base_ptr.typeOf(zcu).childType(zcu);
......@@ -692,27 +674,21 @@ fn lowerPtr(
692674 },
693675 else => unreachable,
694676 };
695 return lowerPtr(bin_file, pt, src_loc, field.base, code, debug_output, reloc_info, offset + field_off);
677 return lowerPtr(bin_file, pt, src_loc, field.base, code, reloc_parent, offset + field_off);
696678 },
697679 .arr_elem, .comptime_field, .comptime_alloc => unreachable,
698680 };
699681}
700682
701const RelocInfo = struct {
702 parent_atom_index: u32,
703};
704
705683fn lowerUavRef(
706684 lf: *link.File,
707685 pt: Zcu.PerThread,
708686 src_loc: Zcu.LazySrcLoc,
709687 uav: InternPool.Key.Ptr.BaseAddr.Uav,
710688 code: *std.ArrayList(u8),
711 debug_output: DebugInfoOutput,
712 reloc_info: RelocInfo,
689 reloc_parent: link.File.RelocInfo.Parent,
713690 offset: u64,
714691) CodeGenError!Result {
715 _ = debug_output;
716692 const zcu = pt.zcu;
717693 const ip = &zcu.intern_pool;
718694 const target = lf.comp.root_mod.resolved_target.result;
......@@ -735,7 +711,7 @@ fn lowerUavRef(
735711 }
736712
737713 const vaddr = try lf.getUavVAddr(uav_val, .{
738 .parent_atom_index = reloc_info.parent_atom_index,
714 .parent = reloc_parent,
739715 .offset = code.items.len,
740716 .addend = @intCast(offset),
741717 });
......@@ -756,12 +732,10 @@ fn lowerNavRef(
756732 src_loc: Zcu.LazySrcLoc,
757733 nav_index: InternPool.Nav.Index,
758734 code: *std.ArrayList(u8),
759 debug_output: DebugInfoOutput,
760 reloc_info: RelocInfo,
735 reloc_parent: link.File.RelocInfo.Parent,
761736 offset: u64,
762737) CodeGenError!Result {
763738 _ = src_loc;
764 _ = debug_output;
765739 const zcu = pt.zcu;
766740 const ip = &zcu.intern_pool;
767741 const target = zcu.navFileScope(nav_index).mod.resolved_target.result;
......@@ -775,7 +749,7 @@ fn lowerNavRef(
775749 }
776750
777751 const vaddr = try lf.getNavVAddr(pt, nav_index, .{
778 .parent_atom_index = reloc_info.parent_atom_index,
752 .parent = reloc_parent,
779753 .offset = code.items.len,
780754 .addend = @intCast(offset),
781755 });
src/link.zig+11-1
......@@ -330,6 +330,11 @@ pub const File = struct {
330330 }
331331 }
332332
333 pub const DebugInfoOutput = union(enum) {
334 dwarf: *Dwarf.WipNav,
335 plan9: *Plan9.DebugInfoOutput,
336 none,
337 };
333338 pub const UpdateDebugInfoError = Dwarf.UpdateError;
334339 pub const FlushDebugInfoError = Dwarf.FlushError;
335340
......@@ -673,9 +678,14 @@ pub const File = struct {
673678 }
674679
675680 pub const RelocInfo = struct {
676 parent_atom_index: u32,
681 parent: Parent,
677682 offset: u64,
678683 addend: u32,
684
685 pub const Parent = union(enum) {
686 atom_index: u32,
687 debug_output: DebugInfoOutput,
688 };
679689 };
680690
681691 /// Get allocated `Nav`'s address in virtual memory.
src/link/Coff.zig+12-7
......@@ -1163,8 +1163,8 @@ fn lowerConst(
11631163 try self.setSymbolName(sym, name);
11641164 sym.section_number = @as(coff.SectionNumber, @enumFromInt(sect_id + 1));
11651165
1166 const res = try codegen.generateSymbol(&self.base, pt, src_loc, val, &code_buffer, .none, .{
1167 .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?,
1166 const res = try codegen.generateSymbol(&self.base, pt, src_loc, val, &code_buffer, .{
1167 .atom_index = self.getAtom(atom_index).getSymbolIndex().?,
11681168 });
11691169 const code = switch (res) {
11701170 .ok => code_buffer.items,
......@@ -1235,8 +1235,7 @@ pub fn updateNav(
12351235 zcu.navSrcLoc(nav_index),
12361236 nav_init,
12371237 &code_buffer,
1238 .none,
1239 .{ .parent_atom_index = atom.getSymbolIndex().? },
1238 .{ .atom_index = atom.getSymbolIndex().? },
12401239 );
12411240 const code = switch (res) {
12421241 .ok => code_buffer.items,
......@@ -1284,7 +1283,7 @@ fn updateLazySymbolAtom(
12841283 &required_alignment,
12851284 &code_buffer,
12861285 .none,
1287 .{ .parent_atom_index = local_sym_index },
1286 .{ .atom_index = local_sym_index },
12881287 );
12891288 const code = switch (res) {
12901289 .ok => code_buffer.items,
......@@ -1823,7 +1822,10 @@ pub fn getNavVAddr(
18231822 .@"extern" => |@"extern"| try self.getGlobalSymbol(nav.name.toSlice(ip), @"extern".lib_name.toSlice(ip)),
18241823 else => self.getAtom(try self.getOrCreateAtomForNav(nav_index)).getSymbolIndex().?,
18251824 };
1826 const atom_index = self.getAtomIndexForSymbol(.{ .sym_index = reloc_info.parent_atom_index, .file = null }).?;
1825 const atom_index = self.getAtomIndexForSymbol(.{
1826 .sym_index = reloc_info.parent.atom_index,
1827 .file = null,
1828 }).?;
18271829 const target = SymbolWithLoc{ .sym_index = sym_index, .file = null };
18281830 try Atom.addRelocation(self, atom_index, .{
18291831 .type = .direct,
......@@ -1901,7 +1903,10 @@ pub fn getUavVAddr(
19011903
19021904 const this_atom_index = self.uavs.get(uav).?.atom;
19031905 const sym_index = self.getAtom(this_atom_index).getSymbolIndex().?;
1904 const atom_index = self.getAtomIndexForSymbol(.{ .sym_index = reloc_info.parent_atom_index, .file = null }).?;
1906 const atom_index = self.getAtomIndexForSymbol(.{
1907 .sym_index = reloc_info.parent.atom_index,
1908 .file = null,
1909 }).?;
19051910 const target = SymbolWithLoc{ .sym_index = sym_index, .file = null };
19061911 try Atom.addRelocation(self, atom_index, .{
19071912 .type = .direct,
src/link/Dwarf.zig+538-476
......@@ -19,8 +19,8 @@ debug_rnglists: DebugRngLists,
1919debug_str: StringSection,
2020
2121pub const UpdateError = error{
22 CodegenFail,
2223 ReinterpretDeclRef,
23 IllDefinedMemoryLayout,
2424 Unimplemented,
2525 OutOfMemory,
2626 EndOfStream,
......@@ -847,10 +847,11 @@ const Entry = struct {
847847 unit.len -| (unit.header_len + unit.trailer_len);
848848 if (entry_ptr.off + len > end) {
849849 if (entry_ptr.next.unwrap()) |next_entry| {
850 if (entry_ptr.prev.unwrap()) |prev_entry|
851 unit.getEntry(prev_entry).next = entry_ptr.next
852 else
853 unit.first = entry_ptr.next;
850 if (entry_ptr.prev.unwrap()) |prev_entry| {
851 const prev_entry_ptr = unit.getEntry(prev_entry);
852 prev_entry_ptr.next = entry_ptr.next;
853 try prev_entry_ptr.pad(unit, sec, dwarf);
854 } else unit.first = entry_ptr.next;
854855 const next_entry_ptr = unit.getEntry(next_entry);
855856 const entry = next_entry_ptr.prev;
856857 next_entry_ptr.prev = entry_ptr.prev;
......@@ -860,6 +861,7 @@ const Entry = struct {
860861 entry_ptr.next = .none;
861862 entry_ptr.off = last_entry_ptr.off + sec.padToIdeal(last_entry_ptr.len);
862863 unit.last = entry;
864 try last_entry_ptr.pad(unit, sec, dwarf);
863865 }
864866 try unit.resize(sec, dwarf, 0, @intCast(unit.header_len + entry_ptr.off + sec.padToIdeal(len) + unit.trailer_len));
865867 }
......@@ -1582,6 +1584,18 @@ pub const WipNav = struct {
15821584 wip_nav.func = func;
15831585 }
15841586
1587 fn externalReloc(wip_nav: *WipNav, sec: *Section, reloc: ExternalReloc) std.mem.Allocator.Error!void {
1588 try sec.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs.append(wip_nav.dwarf.gpa, reloc);
1589 }
1590
1591 pub fn infoExternalReloc(wip_nav: *WipNav, reloc: ExternalReloc) std.mem.Allocator.Error!void {
1592 try wip_nav.externalReloc(&wip_nav.dwarf.debug_info.section, reloc);
1593 }
1594
1595 fn frameExternalReloc(wip_nav: *WipNav, reloc: ExternalReloc) std.mem.Allocator.Error!void {
1596 try wip_nav.externalReloc(&wip_nav.dwarf.debug_frame.section, reloc);
1597 }
1598
15851599 fn abbrevCode(wip_nav: *WipNav, abbrev_code: AbbrevCode) UpdateError!void {
15861600 try uleb128(wip_nav.debug_info.writer(wip_nav.dwarf.gpa), try wip_nav.dwarf.refAbbrevCode(abbrev_code));
15871601 }
......@@ -1658,12 +1672,11 @@ pub const WipNav = struct {
16581672 }
16591673
16601674 fn infoAddrSym(wip_nav: *WipNav, sym_index: u32) UpdateError!void {
1661 const dwarf = wip_nav.dwarf;
1662 try dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs.append(dwarf.gpa, .{
1675 try wip_nav.infoExternalReloc(.{
16631676 .source_off = @intCast(wip_nav.debug_info.items.len),
16641677 .target_sym = sym_index,
16651678 });
1666 try wip_nav.debug_info.appendNTimes(dwarf.gpa, 0, @intFromEnum(dwarf.address_size));
1679 try wip_nav.debug_info.appendNTimes(wip_nav.dwarf.gpa, 0, @intFromEnum(wip_nav.dwarf.address_size));
16671680 }
16681681
16691682 fn frameExprloc(wip_nav: *WipNav, loc: Loc) UpdateError!void {
......@@ -1690,12 +1703,11 @@ pub const WipNav = struct {
16901703 }
16911704
16921705 fn frameAddrSym(wip_nav: *WipNav, sym_index: u32) UpdateError!void {
1693 const dwarf = wip_nav.dwarf;
1694 try dwarf.debug_frame.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs.append(dwarf.gpa, .{
1706 try wip_nav.frameExternalReloc(.{
16951707 .source_off = @intCast(wip_nav.debug_frame.items.len),
16961708 .target_sym = sym_index,
16971709 });
1698 try wip_nav.debug_frame.appendNTimes(dwarf.gpa, 0, @intFromEnum(dwarf.address_size));
1710 try wip_nav.debug_frame.appendNTimes(wip_nav.dwarf.gpa, 0, @intFromEnum(wip_nav.dwarf.address_size));
16991711 }
17001712
17011713 fn getTypeEntry(wip_nav: *WipNav, ty: Type) UpdateError!struct { Unit.Index, Entry.Index } {
......@@ -1747,6 +1759,27 @@ pub const WipNav = struct {
17471759 reloc.target_off = @intCast(wip_nav.debug_info.items.len);
17481760 }
17491761
1762 fn blockValue(wip_nav: *WipNav, src_loc: Zcu.LazySrcLoc, val: Value) UpdateError!void {
1763 const ty = val.typeOf(wip_nav.pt.zcu);
1764 const diw = wip_nav.debug_info.writer(wip_nav.dwarf.gpa);
1765 const bytes = if (ty.hasRuntimeBits(wip_nav.pt.zcu)) ty.abiSize(wip_nav.pt.zcu) else 0;
1766 try uleb128(diw, bytes);
1767 if (bytes == 0) return;
1768 var dim = wip_nav.debug_info.toManaged(wip_nav.dwarf.gpa);
1769 defer wip_nav.debug_info = dim.moveToUnmanaged();
1770 switch (try codegen.generateSymbol(
1771 wip_nav.dwarf.bin_file,
1772 wip_nav.pt,
1773 src_loc,
1774 val,
1775 &dim,
1776 .{ .debug_output = .{ .dwarf = wip_nav } },
1777 )) {
1778 .ok => assert(dim.items.len == wip_nav.debug_info.items.len + bytes),
1779 .fail => unreachable,
1780 }
1781 }
1782
17501783 fn enumConstValue(
17511784 wip_nav: *WipNav,
17521785 loaded_enum: InternPool.LoadedEnumType,
......@@ -1812,8 +1845,8 @@ pub const WipNav = struct {
18121845 }
18131846 }
18141847
1815 fn flush(wip_nav: *WipNav) UpdateError!void {
1816 while (wip_nav.pending_types.popOrNull()) |ty| try wip_nav.dwarf.updateType(wip_nav.pt, ty, &wip_nav.pending_types);
1848 fn flush(wip_nav: *WipNav, src_loc: Zcu.LazySrcLoc) UpdateError!void {
1849 while (wip_nav.pending_types.popOrNull()) |ty| try wip_nav.dwarf.updateType(wip_nav.pt, src_loc, ty, &wip_nav.pending_types);
18171850 }
18181851};
18191852
......@@ -2169,15 +2202,15 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
21692202 try diw.writeByte(accessibility);
21702203 try wip_nav.strp(nav.name.toSlice(ip));
21712204 try wip_nav.strp(nav.fqn.toSlice(ip));
2172 const ty = nav_val.typeOf(zcu);
2173 const ty_reloc_index = try wip_nav.refForward();
2205 const nav_ty = nav_val.typeOf(zcu);
2206 const nav_ty_reloc_index = try wip_nav.refForward();
21742207 try wip_nav.exprloc(.{ .addr = .{ .sym = sym_index } });
21752208 try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse
2176 ty.abiAlignment(zcu).toByteUnits().?);
2209 nav_ty.abiAlignment(zcu).toByteUnits().?);
21772210 try diw.writeByte(@intFromBool(false));
2178 wip_nav.finishForward(ty_reloc_index);
2211 wip_nav.finishForward(nav_ty_reloc_index);
21792212 try wip_nav.abbrevCode(.is_const);
2180 try wip_nav.refType(ty);
2213 try wip_nav.refType(nav_ty);
21812214 },
21822215 .variable => |variable| {
21832216 assert(file.zir_loaded);
......@@ -2286,20 +2319,16 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
22862319 .source_off = @intCast(wip_nav.debug_frame.items.len),
22872320 });
22882321 try dfw.writeByteNTimes(0, dwarf.sectionOffsetBytes());
2289 try entry.external_relocs.append(dwarf.gpa, .{
2290 .source_off = @intCast(wip_nav.debug_frame.items.len),
2291 .target_sym = sym_index,
2292 });
2293 try dfw.writeByteNTimes(0, @intFromEnum(dwarf.address_size));
2322 try wip_nav.frameAddrSym(sym_index);
22942323 try dfw.writeByteNTimes(undefined, @intFromEnum(dwarf.address_size));
22952324 },
22962325 .eh_frame => {
22972326 try dfw.writeInt(u32, undefined, dwarf.endian);
2298 try entry.external_relocs.append(dwarf.gpa, .{
2327 try wip_nav.frameExternalReloc(.{
22992328 .source_off = @intCast(wip_nav.debug_frame.items.len),
23002329 .target_sym = sym_index,
23012330 });
2302 try dfw.writeByteNTimes(0, dwarf.sectionOffsetBytes());
2331 try dfw.writeInt(u32, 0, dwarf.endian);
23032332 try dfw.writeInt(u32, undefined, dwarf.endian);
23042333 try uleb128(dfw, 0);
23052334 },
......@@ -2479,12 +2508,13 @@ pub fn finishWipNav(
24792508 }
24802509 try dwarf.debug_loclists.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_loclists.items);
24812510
2482 try wip_nav.flush();
2511 try wip_nav.flush(zcu.navSrcLoc(nav_index));
24832512}
24842513
24852514pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) UpdateError!void {
24862515 const zcu = pt.zcu;
24872516 const ip = &zcu.intern_pool;
2517 const nav_src_loc = zcu.navSrcLoc(nav_index);
24882518 const nav_val = zcu.navValue(nav_index);
24892519
24902520 const nav = ip.getNav(nav_index);
......@@ -2507,6 +2537,19 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
25072537 return;
25082538 }
25092539
2540 const parent_type, const accessibility: u8 = if (nav.analysis_owner.unwrap()) |cau| parent: {
2541 const parent_namespace_ptr = ip.namespacePtr(ip.getCau(cau).namespace);
2542 break :parent .{
2543 parent_namespace_ptr.owner_type,
2544 if (parent_namespace_ptr.pub_decls.containsContext(nav_index, .{ .zcu = zcu }))
2545 DW.ACCESS.public
2546 else if (parent_namespace_ptr.priv_decls.containsContext(nav_index, .{ .zcu = zcu }))
2547 DW.ACCESS.private
2548 else
2549 unreachable,
2550 };
2551 } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private };
2552
25102553 const tree = try file.getTree(dwarf.gpa);
25112554 const loc = tree.tokenLocation(0, tree.nodes.items(.main_token)[decl_inst.data.declaration.src_node]);
25122555 assert(loc.line == zcu.navSrcLine(nav_index));
......@@ -2532,8 +2575,341 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
25322575
25332576 const nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, nav_index);
25342577 errdefer _ = dwarf.navs.pop();
2535 switch (ip.indexToKey(nav_val.toIntern())) {
2536 .func => |func| {
2578
2579 const tag: enum { done, decl_alias, decl_var, decl_const } = switch (ip.indexToKey(nav_val.toIntern())) {
2580 .int_type,
2581 .ptr_type,
2582 .array_type,
2583 .vector_type,
2584 .opt_type,
2585 .anyframe_type,
2586 .error_union_type,
2587 .simple_type,
2588 .anon_struct_type,
2589 .func_type,
2590 .error_set_type,
2591 .inferred_error_set_type,
2592 => .decl_alias,
2593 .struct_type => tag: {
2594 const loaded_struct = ip.loadStructType(nav_val.toIntern());
2595 if (loaded_struct.zir_index == .none) break :tag .decl_alias;
2596
2597 const type_inst_info = loaded_struct.zir_index.unwrap().?.resolveFull(ip).?;
2598 if (type_inst_info.file != inst_info.file) break :tag .decl_alias;
2599
2600 const value_inst = value_inst: {
2601 const decl_value_body = decl_extra.data.getBodies(@intCast(decl_extra.end), file.zir).value_body;
2602 const break_inst = file.zir.instructions.get(@intFromEnum(decl_value_body[decl_value_body.len - 1]));
2603 if (break_inst.tag != .break_inline) break :value_inst null;
2604 assert(file.zir.extraData(Zir.Inst.Break, break_inst.data.@"break".payload_index).data.block_inst == inst_info.inst);
2605 var value_inst = break_inst.data.@"break".operand.toIndex();
2606 while (value_inst) |value_inst_index| switch (file.zir.instructions.items(.tag)[@intFromEnum(value_inst_index)]) {
2607 else => break,
2608 .as_node => value_inst = file.zir.extraData(
2609 Zir.Inst.As,
2610 file.zir.instructions.items(.data)[@intFromEnum(value_inst_index)].pl_node.payload_index,
2611 ).data.operand.toIndex(),
2612 };
2613 break :value_inst value_inst;
2614 };
2615 if (type_inst_info.inst != value_inst) break :tag .decl_alias;
2616
2617 const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern());
2618 if (type_gop.found_existing) {
2619 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).clear();
2620 nav_gop.value_ptr.* = type_gop.value_ptr.*;
2621 } else {
2622 if (nav_gop.found_existing)
2623 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(nav_gop.value_ptr.*).clear()
2624 else
2625 nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit);
2626 type_gop.value_ptr.* = nav_gop.value_ptr.*;
2627 }
2628 wip_nav.entry = nav_gop.value_ptr.*;
2629
2630 const diw = wip_nav.debug_info.writer(dwarf.gpa);
2631
2632 switch (loaded_struct.layout) {
2633 .auto, .@"extern" => {
2634 try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .decl_namespace_struct else .decl_struct);
2635 try wip_nav.refType(Type.fromInterned(parent_type));
2636 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2637 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2638 try uleb128(diw, loc.column + 1);
2639 try diw.writeByte(accessibility);
2640 try wip_nav.strp(nav.name.toSlice(ip));
2641 if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else {
2642 try uleb128(diw, nav_val.toType().abiSize(zcu));
2643 try uleb128(diw, nav_val.toType().abiAlignment(zcu).toByteUnits().?);
2644 for (0..loaded_struct.field_types.len) |field_index| {
2645 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
2646 const field_init = if (loaded_struct.haveFieldInits(ip))
2647 loaded_struct.fieldInit(ip, field_index)
2648 else
2649 .none;
2650 try wip_nav.abbrevCode(if (is_comptime)
2651 .struct_field_comptime
2652 else if (field_init != .none)
2653 .struct_field_default
2654 else
2655 .struct_field);
2656 if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name| try wip_nav.strp(field_name.toSlice(ip)) else {
2657 const field_name = try std.fmt.allocPrint(dwarf.gpa, "{d}", .{field_index});
2658 defer dwarf.gpa.free(field_name);
2659 try wip_nav.strp(field_name);
2660 }
2661 if (is_comptime and field_init == .none) {
2662 // workaround frontend bug
2663 try wip_nav.refType(Type.void);
2664 try wip_nav.blockValue(nav_src_loc, Value.void);
2665 } else {
2666 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
2667 try wip_nav.refType(field_type);
2668 if (!is_comptime) {
2669 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
2670 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
2671 field_type.abiAlignment(zcu).toByteUnits().?);
2672 }
2673 if (field_init != .none) try wip_nav.blockValue(nav_src_loc, Value.fromInterned(field_init));
2674 }
2675 }
2676 try uleb128(diw, @intFromEnum(AbbrevCode.null));
2677 }
2678 },
2679 .@"packed" => {
2680 try wip_nav.abbrevCode(.decl_packed_struct);
2681 try wip_nav.refType(Type.fromInterned(parent_type));
2682 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2683 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2684 try uleb128(diw, loc.column + 1);
2685 try diw.writeByte(accessibility);
2686 try wip_nav.strp(nav.name.toSlice(ip));
2687 try wip_nav.refType(Type.fromInterned(loaded_struct.backingIntTypeUnordered(ip)));
2688 var field_bit_offset: u16 = 0;
2689 for (0..loaded_struct.field_types.len) |field_index| {
2690 try wip_nav.abbrevCode(.packed_struct_field);
2691 try wip_nav.strp(loaded_struct.fieldName(ip, field_index).unwrap().?.toSlice(ip));
2692 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
2693 try wip_nav.refType(field_type);
2694 try uleb128(diw, field_bit_offset);
2695 field_bit_offset += @intCast(field_type.bitSize(zcu));
2696 }
2697 try uleb128(diw, @intFromEnum(AbbrevCode.null));
2698 },
2699 }
2700 break :tag .done;
2701 },
2702 .enum_type => tag: {
2703 const loaded_enum = ip.loadEnumType(nav_val.toIntern());
2704 if (loaded_enum.zir_index == .none) break :tag .decl_alias;
2705
2706 const type_inst_info = loaded_enum.zir_index.unwrap().?.resolveFull(ip).?;
2707 if (type_inst_info.file != inst_info.file) break :tag .decl_alias;
2708
2709 const value_inst = value_inst: {
2710 const decl_value_body = decl_extra.data.getBodies(@intCast(decl_extra.end), file.zir).value_body;
2711 const break_inst = file.zir.instructions.get(@intFromEnum(decl_value_body[decl_value_body.len - 1]));
2712 if (break_inst.tag != .break_inline) break :value_inst null;
2713 assert(file.zir.extraData(Zir.Inst.Break, break_inst.data.@"break".payload_index).data.block_inst == inst_info.inst);
2714 var value_inst = break_inst.data.@"break".operand.toIndex();
2715 while (value_inst) |value_inst_index| switch (file.zir.instructions.items(.tag)[@intFromEnum(value_inst_index)]) {
2716 else => break,
2717 .as_node => value_inst = file.zir.extraData(
2718 Zir.Inst.As,
2719 file.zir.instructions.items(.data)[@intFromEnum(value_inst_index)].pl_node.payload_index,
2720 ).data.operand.toIndex(),
2721 };
2722 break :value_inst value_inst;
2723 };
2724 if (type_inst_info.inst != value_inst) break :tag .decl_alias;
2725
2726 const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern());
2727 if (type_gop.found_existing) {
2728 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).clear();
2729 nav_gop.value_ptr.* = type_gop.value_ptr.*;
2730 } else {
2731 if (nav_gop.found_existing)
2732 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(nav_gop.value_ptr.*).clear()
2733 else
2734 nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit);
2735 type_gop.value_ptr.* = nav_gop.value_ptr.*;
2736 }
2737 wip_nav.entry = nav_gop.value_ptr.*;
2738 const diw = wip_nav.debug_info.writer(dwarf.gpa);
2739 try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .decl_enum else .decl_empty_enum);
2740 try wip_nav.refType(Type.fromInterned(parent_type));
2741 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2742 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2743 try uleb128(diw, loc.column + 1);
2744 try diw.writeByte(accessibility);
2745 try wip_nav.strp(nav.name.toSlice(ip));
2746 try wip_nav.refType(Type.fromInterned(loaded_enum.tag_ty));
2747 for (0..loaded_enum.names.len) |field_index| {
2748 try wip_nav.enumConstValue(loaded_enum, .{
2749 .sdata = .signed_enum_field,
2750 .udata = .unsigned_enum_field,
2751 .block = .big_enum_field,
2752 }, field_index);
2753 try wip_nav.strp(loaded_enum.names.get(ip)[field_index].toSlice(ip));
2754 }
2755 if (loaded_enum.names.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null));
2756 break :tag .done;
2757 },
2758 .union_type => tag: {
2759 const loaded_union = ip.loadUnionType(nav_val.toIntern());
2760
2761 const type_inst_info = loaded_union.zir_index.resolveFull(ip).?;
2762 if (type_inst_info.file != inst_info.file) break :tag .decl_alias;
2763
2764 const value_inst = value_inst: {
2765 const decl_value_body = decl_extra.data.getBodies(@intCast(decl_extra.end), file.zir).value_body;
2766 const break_inst = file.zir.instructions.get(@intFromEnum(decl_value_body[decl_value_body.len - 1]));
2767 if (break_inst.tag != .break_inline) break :value_inst null;
2768 assert(file.zir.extraData(Zir.Inst.Break, break_inst.data.@"break".payload_index).data.block_inst == inst_info.inst);
2769 var value_inst = break_inst.data.@"break".operand.toIndex();
2770 while (value_inst) |value_inst_index| switch (file.zir.instructions.items(.tag)[@intFromEnum(value_inst_index)]) {
2771 else => break,
2772 .as_node => value_inst = file.zir.extraData(
2773 Zir.Inst.As,
2774 file.zir.instructions.items(.data)[@intFromEnum(value_inst_index)].pl_node.payload_index,
2775 ).data.operand.toIndex(),
2776 };
2777 break :value_inst value_inst;
2778 };
2779 if (type_inst_info.inst != value_inst) break :tag .decl_alias;
2780
2781 const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern());
2782 if (type_gop.found_existing) {
2783 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).clear();
2784 nav_gop.value_ptr.* = type_gop.value_ptr.*;
2785 } else {
2786 if (nav_gop.found_existing)
2787 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(nav_gop.value_ptr.*).clear()
2788 else
2789 nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit);
2790 type_gop.value_ptr.* = nav_gop.value_ptr.*;
2791 }
2792 wip_nav.entry = nav_gop.value_ptr.*;
2793 const diw = wip_nav.debug_info.writer(dwarf.gpa);
2794 try wip_nav.abbrevCode(.decl_union);
2795 try wip_nav.refType(Type.fromInterned(parent_type));
2796 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2797 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2798 try uleb128(diw, loc.column + 1);
2799 try diw.writeByte(accessibility);
2800 try wip_nav.strp(nav.name.toSlice(ip));
2801 const union_layout = Type.getUnionLayout(loaded_union, zcu);
2802 try uleb128(diw, union_layout.abi_size);
2803 try uleb128(diw, union_layout.abi_align.toByteUnits().?);
2804 const loaded_tag = loaded_union.loadTagType(ip);
2805 if (loaded_union.hasTag(ip)) {
2806 try wip_nav.abbrevCode(.tagged_union);
2807 try wip_nav.infoSectionOffset(
2808 .debug_info,
2809 wip_nav.unit,
2810 wip_nav.entry,
2811 @intCast(wip_nav.debug_info.items.len + dwarf.sectionOffsetBytes()),
2812 );
2813 {
2814 try wip_nav.abbrevCode(.generated_field);
2815 try wip_nav.strp("tag");
2816 try wip_nav.refType(Type.fromInterned(loaded_union.enum_tag_ty));
2817 try uleb128(diw, union_layout.tagOffset());
2818
2819 for (0..loaded_union.field_types.len) |field_index| {
2820 try wip_nav.enumConstValue(loaded_tag, .{
2821 .sdata = .signed_tagged_union_field,
2822 .udata = .unsigned_tagged_union_field,
2823 .block = .big_tagged_union_field,
2824 }, field_index);
2825 {
2826 try wip_nav.abbrevCode(.struct_field);
2827 try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip));
2828 const field_type = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
2829 try wip_nav.refType(field_type);
2830 try uleb128(diw, union_layout.payloadOffset());
2831 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse
2832 if (field_type.isNoReturn(zcu)) 1 else field_type.abiAlignment(zcu).toByteUnits().?);
2833 }
2834 try uleb128(diw, @intFromEnum(AbbrevCode.null));
2835 }
2836 }
2837 try uleb128(diw, @intFromEnum(AbbrevCode.null));
2838 } else for (0..loaded_union.field_types.len) |field_index| {
2839 try wip_nav.abbrevCode(.untagged_union_field);
2840 try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip));
2841 const field_type = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
2842 try wip_nav.refType(field_type);
2843 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse
2844 field_type.abiAlignment(zcu).toByteUnits().?);
2845 }
2846 try uleb128(diw, @intFromEnum(AbbrevCode.null));
2847 break :tag .done;
2848 },
2849 .opaque_type => tag: {
2850 const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern());
2851
2852 const type_inst_info = loaded_opaque.zir_index.resolveFull(ip).?;
2853 if (type_inst_info.file != inst_info.file) break :tag .decl_alias;
2854
2855 const value_inst = value_inst: {
2856 const decl_value_body = decl_extra.data.getBodies(@intCast(decl_extra.end), file.zir).value_body;
2857 const break_inst = file.zir.instructions.get(@intFromEnum(decl_value_body[decl_value_body.len - 1]));
2858 if (break_inst.tag != .break_inline) break :value_inst null;
2859 assert(file.zir.extraData(Zir.Inst.Break, break_inst.data.@"break".payload_index).data.block_inst == inst_info.inst);
2860 var value_inst = break_inst.data.@"break".operand.toIndex();
2861 while (value_inst) |value_inst_index| switch (file.zir.instructions.items(.tag)[@intFromEnum(value_inst_index)]) {
2862 else => break,
2863 .as_node => value_inst = file.zir.extraData(
2864 Zir.Inst.As,
2865 file.zir.instructions.items(.data)[@intFromEnum(value_inst_index)].pl_node.payload_index,
2866 ).data.operand.toIndex(),
2867 };
2868 break :value_inst value_inst;
2869 };
2870 if (type_inst_info.inst != value_inst) break :tag .decl_alias;
2871
2872 const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern());
2873 if (type_gop.found_existing) {
2874 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).clear();
2875 nav_gop.value_ptr.* = type_gop.value_ptr.*;
2876 } else {
2877 if (nav_gop.found_existing)
2878 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(nav_gop.value_ptr.*).clear()
2879 else
2880 nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit);
2881 type_gop.value_ptr.* = nav_gop.value_ptr.*;
2882 }
2883 wip_nav.entry = nav_gop.value_ptr.*;
2884 const diw = wip_nav.debug_info.writer(dwarf.gpa);
2885 try wip_nav.abbrevCode(.decl_namespace_struct);
2886 try wip_nav.refType(Type.fromInterned(parent_type));
2887 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2888 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2889 try uleb128(diw, loc.column + 1);
2890 try diw.writeByte(accessibility);
2891 try wip_nav.strp(nav.name.toSlice(ip));
2892 try diw.writeByte(@intFromBool(false));
2893 break :tag .done;
2894 },
2895 .undef,
2896 .simple_value,
2897 .@"extern",
2898 .int,
2899 .err,
2900 .error_union,
2901 .enum_literal,
2902 .enum_tag,
2903 .empty_enum_value,
2904 .float,
2905 .ptr,
2906 .slice,
2907 .opt,
2908 .aggregate,
2909 .un,
2910 => .decl_const,
2911 .variable => .decl_var,
2912 .func => |func| tag: {
25372913 if (nav_gop.found_existing) {
25382914 const unit_ptr = dwarf.debug_info.section.getUnit(wip_nav.unit);
25392915 const entry_ptr = unit_ptr.getEntry(nav_gop.value_ptr.*);
......@@ -2557,19 +2933,6 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
25572933 } else nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit);
25582934 wip_nav.entry = nav_gop.value_ptr.*;
25592935
2560 const parent_type, const accessibility: u8 = if (nav.analysis_owner.unwrap()) |cau| parent: {
2561 const parent_namespace_ptr = ip.namespacePtr(ip.getCau(cau).namespace);
2562 break :parent .{
2563 parent_namespace_ptr.owner_type,
2564 if (parent_namespace_ptr.pub_decls.containsContext(nav_index, .{ .zcu = zcu }))
2565 DW.ACCESS.public
2566 else if (parent_namespace_ptr.priv_decls.containsContext(nav_index, .{ .zcu = zcu }))
2567 DW.ACCESS.private
2568 else
2569 unreachable,
2570 };
2571 } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private };
2572
25732936 const func_type = ip.indexToKey(func.ty).func_type;
25742937 const diw = wip_nav.debug_info.writer(dwarf.gpa);
25752938 try wip_nav.abbrevCode(if (func_type.param_types.len > 0 or func_type.is_var_args)
......@@ -2591,208 +2954,21 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
25912954 if (func_type.is_var_args) try wip_nav.abbrevCode(.is_var_args);
25922955 try uleb128(diw, @intFromEnum(AbbrevCode.null));
25932956 }
2957 break :tag .done;
25942958 },
2595 .struct_type => done: {
2596 const loaded_struct = ip.loadStructType(nav_val.toIntern());
2597
2598 const parent_type, const accessibility: u8 = if (nav.analysis_owner.unwrap()) |cau| parent: {
2599 const parent_namespace_ptr = ip.namespacePtr(ip.getCau(cau).namespace);
2600 break :parent .{
2601 parent_namespace_ptr.owner_type,
2602 if (parent_namespace_ptr.pub_decls.containsContext(nav_index, .{ .zcu = zcu }))
2603 DW.ACCESS.public
2604 else if (parent_namespace_ptr.priv_decls.containsContext(nav_index, .{ .zcu = zcu }))
2605 DW.ACCESS.private
2606 else
2607 unreachable,
2608 };
2609 } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private };
2610
2611 decl_struct: {
2612 if (loaded_struct.zir_index == .none) break :decl_struct;
2613
2614 const type_inst_info = loaded_struct.zir_index.unwrap().?.resolveFull(ip).?;
2615 if (type_inst_info.file != inst_info.file) break :decl_struct;
2616
2617 const value_inst = value_inst: {
2618 const decl_value_body = decl_extra.data.getBodies(@intCast(decl_extra.end), file.zir).value_body;
2619 const break_inst = file.zir.instructions.get(@intFromEnum(decl_value_body[decl_value_body.len - 1]));
2620 if (break_inst.tag != .break_inline) break :value_inst null;
2621 assert(file.zir.extraData(Zir.Inst.Break, break_inst.data.@"break".payload_index).data.block_inst == inst_info.inst);
2622 var value_inst = break_inst.data.@"break".operand.toIndex();
2623 while (value_inst) |value_inst_index| switch (file.zir.instructions.items(.tag)[@intFromEnum(value_inst_index)]) {
2624 else => break,
2625 .as_node => value_inst = file.zir.extraData(
2626 Zir.Inst.As,
2627 file.zir.instructions.items(.data)[@intFromEnum(value_inst_index)].pl_node.payload_index,
2628 ).data.operand.toIndex(),
2629 };
2630 break :value_inst value_inst;
2631 };
2632 if (type_inst_info.inst != value_inst) break :decl_struct;
2633
2634 const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern());
2635 if (type_gop.found_existing) {
2636 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).clear();
2637 nav_gop.value_ptr.* = type_gop.value_ptr.*;
2638 } else {
2639 if (nav_gop.found_existing)
2640 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(nav_gop.value_ptr.*).clear()
2641 else
2642 nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit);
2643 type_gop.value_ptr.* = nav_gop.value_ptr.*;
2644 }
2645 wip_nav.entry = nav_gop.value_ptr.*;
2646
2647 const diw = wip_nav.debug_info.writer(dwarf.gpa);
2648
2649 switch (loaded_struct.layout) {
2650 .auto, .@"extern" => {
2651 try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .decl_namespace_struct else .decl_struct);
2652 try wip_nav.refType(Type.fromInterned(parent_type));
2653 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2654 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2655 try uleb128(diw, loc.column + 1);
2656 try diw.writeByte(accessibility);
2657 try wip_nav.strp(nav.name.toSlice(ip));
2658 if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else {
2659 try uleb128(diw, nav_val.toType().abiSize(zcu));
2660 try uleb128(diw, nav_val.toType().abiAlignment(zcu).toByteUnits().?);
2661 for (0..loaded_struct.field_types.len) |field_index| {
2662 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
2663 try wip_nav.abbrevCode(if (is_comptime) .struct_field_comptime else .struct_field);
2664 if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name| try wip_nav.strp(field_name.toSlice(ip)) else {
2665 const field_name = try std.fmt.allocPrint(dwarf.gpa, "{d}", .{field_index});
2666 defer dwarf.gpa.free(field_name);
2667 try wip_nav.strp(field_name);
2668 }
2669 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
2670 try wip_nav.refType(field_type);
2671 if (!is_comptime) {
2672 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
2673 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
2674 field_type.abiAlignment(zcu).toByteUnits().?);
2675 }
2676 }
2677 try uleb128(diw, @intFromEnum(AbbrevCode.null));
2678 }
2679 },
2680 .@"packed" => {
2681 try wip_nav.abbrevCode(.decl_packed_struct);
2682 try wip_nav.refType(Type.fromInterned(parent_type));
2683 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2684 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2685 try uleb128(diw, loc.column + 1);
2686 try diw.writeByte(accessibility);
2687 try wip_nav.strp(nav.name.toSlice(ip));
2688 try wip_nav.refType(Type.fromInterned(loaded_struct.backingIntTypeUnordered(ip)));
2689 var field_bit_offset: u16 = 0;
2690 for (0..loaded_struct.field_types.len) |field_index| {
2691 try wip_nav.abbrevCode(.packed_struct_field);
2692 try wip_nav.strp(loaded_struct.fieldName(ip, field_index).unwrap().?.toSlice(ip));
2693 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
2694 try wip_nav.refType(field_type);
2695 try uleb128(diw, field_bit_offset);
2696 field_bit_offset += @intCast(field_type.bitSize(zcu));
2697 }
2698 try uleb128(diw, @intFromEnum(AbbrevCode.null));
2699 },
2700 }
2701 break :done;
2702 }
2703
2704 if (nav_gop.found_existing)
2705 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(nav_gop.value_ptr.*).clear()
2706 else
2707 nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit);
2708 wip_nav.entry = nav_gop.value_ptr.*;
2709 const diw = wip_nav.debug_info.writer(dwarf.gpa);
2710 try wip_nav.abbrevCode(.decl_alias);
2711 try wip_nav.refType(Type.fromInterned(parent_type));
2712 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2713 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2714 try uleb128(diw, loc.column + 1);
2715 try diw.writeByte(accessibility);
2716 try wip_nav.strp(nav.name.toSlice(ip));
2717 try wip_nav.refType(nav_val.toType());
2718 },
2719 .enum_type => done: {
2720 const loaded_enum = ip.loadEnumType(nav_val.toIntern());
2721
2722 const parent_type, const accessibility: u8 = if (nav.analysis_owner.unwrap()) |cau| parent: {
2723 const parent_namespace_ptr = ip.namespacePtr(ip.getCau(cau).namespace);
2724 break :parent .{
2725 parent_namespace_ptr.owner_type,
2726 if (parent_namespace_ptr.pub_decls.containsContext(nav_index, .{ .zcu = zcu }))
2727 DW.ACCESS.public
2728 else if (parent_namespace_ptr.priv_decls.containsContext(nav_index, .{ .zcu = zcu }))
2729 DW.ACCESS.private
2730 else
2731 unreachable,
2732 };
2733 } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private };
2734
2735 decl_enum: {
2736 if (loaded_enum.zir_index == .none) break :decl_enum;
2737
2738 const type_inst_info = loaded_enum.zir_index.unwrap().?.resolveFull(ip).?;
2739 if (type_inst_info.file != inst_info.file) break :decl_enum;
2740
2741 const value_inst = value_inst: {
2742 const decl_value_body = decl_extra.data.getBodies(@intCast(decl_extra.end), file.zir).value_body;
2743 const break_inst = file.zir.instructions.get(@intFromEnum(decl_value_body[decl_value_body.len - 1]));
2744 if (break_inst.tag != .break_inline) break :value_inst null;
2745 assert(file.zir.extraData(Zir.Inst.Break, break_inst.data.@"break".payload_index).data.block_inst == inst_info.inst);
2746 var value_inst = break_inst.data.@"break".operand.toIndex();
2747 while (value_inst) |value_inst_index| switch (file.zir.instructions.items(.tag)[@intFromEnum(value_inst_index)]) {
2748 else => break,
2749 .as_node => value_inst = file.zir.extraData(
2750 Zir.Inst.As,
2751 file.zir.instructions.items(.data)[@intFromEnum(value_inst_index)].pl_node.payload_index,
2752 ).data.operand.toIndex(),
2753 };
2754 break :value_inst value_inst;
2755 };
2756 if (type_inst_info.inst != value_inst) break :decl_enum;
2757
2758 const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern());
2759 if (type_gop.found_existing) {
2760 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).clear();
2761 nav_gop.value_ptr.* = type_gop.value_ptr.*;
2762 } else {
2763 if (nav_gop.found_existing)
2764 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(nav_gop.value_ptr.*).clear()
2765 else
2766 nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit);
2767 type_gop.value_ptr.* = nav_gop.value_ptr.*;
2768 }
2769 wip_nav.entry = nav_gop.value_ptr.*;
2770 const diw = wip_nav.debug_info.writer(dwarf.gpa);
2771 try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .decl_enum else .decl_empty_enum);
2772 try wip_nav.refType(Type.fromInterned(parent_type));
2773 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2774 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2775 try uleb128(diw, loc.column + 1);
2776 try diw.writeByte(accessibility);
2777 try wip_nav.strp(nav.name.toSlice(ip));
2778 try wip_nav.refType(Type.fromInterned(loaded_enum.tag_ty));
2779 for (0..loaded_enum.names.len) |field_index| {
2780 try wip_nav.enumConstValue(loaded_enum, .{
2781 .sdata = .signed_enum_field,
2782 .udata = .unsigned_enum_field,
2783 .block = .big_enum_field,
2784 }, field_index);
2785 try wip_nav.strp(loaded_enum.names.get(ip)[field_index].toSlice(ip));
2786 }
2787 if (loaded_enum.names.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null));
2788 break :done;
2789 }
2790
2791 if (nav_gop.found_existing)
2792 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(nav_gop.value_ptr.*).clear()
2793 else
2794 nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit);
2795 wip_nav.entry = nav_gop.value_ptr.*;
2959 // memoization, not types
2960 .memoized_call => unreachable,
2961 };
2962 if (tag != .done) {
2963 if (nav_gop.found_existing)
2964 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(nav_gop.value_ptr.*).clear()
2965 else
2966 nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit);
2967 wip_nav.entry = nav_gop.value_ptr.*;
2968 }
2969 switch (tag) {
2970 .done => {},
2971 .decl_alias => {
27962972 const diw = wip_nav.debug_info.writer(dwarf.gpa);
27972973 try wip_nav.abbrevCode(.decl_alias);
27982974 try wip_nav.refType(Type.fromInterned(parent_type));
......@@ -2803,215 +2979,52 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
28032979 try wip_nav.strp(nav.name.toSlice(ip));
28042980 try wip_nav.refType(nav_val.toType());
28052981 },
2806 .union_type => done: {
2807 const loaded_union = ip.loadUnionType(nav_val.toIntern());
2808
2809 const parent_type, const accessibility: u8 = if (nav.analysis_owner.unwrap()) |cau| parent: {
2810 const parent_namespace_ptr = ip.namespacePtr(ip.getCau(cau).namespace);
2811 break :parent .{
2812 parent_namespace_ptr.owner_type,
2813 if (parent_namespace_ptr.pub_decls.containsContext(nav_index, .{ .zcu = zcu }))
2814 DW.ACCESS.public
2815 else if (parent_namespace_ptr.priv_decls.containsContext(nav_index, .{ .zcu = zcu }))
2816 DW.ACCESS.private
2817 else
2818 unreachable,
2819 };
2820 } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private };
2821
2822 decl_union: {
2823 const type_inst_info = loaded_union.zir_index.resolveFull(ip).?;
2824 if (type_inst_info.file != inst_info.file) break :decl_union;
2825
2826 const value_inst = value_inst: {
2827 const decl_value_body = decl_extra.data.getBodies(@intCast(decl_extra.end), file.zir).value_body;
2828 const break_inst = file.zir.instructions.get(@intFromEnum(decl_value_body[decl_value_body.len - 1]));
2829 if (break_inst.tag != .break_inline) break :value_inst null;
2830 assert(file.zir.extraData(Zir.Inst.Break, break_inst.data.@"break".payload_index).data.block_inst == inst_info.inst);
2831 var value_inst = break_inst.data.@"break".operand.toIndex();
2832 while (value_inst) |value_inst_index| switch (file.zir.instructions.items(.tag)[@intFromEnum(value_inst_index)]) {
2833 else => break,
2834 .as_node => value_inst = file.zir.extraData(
2835 Zir.Inst.As,
2836 file.zir.instructions.items(.data)[@intFromEnum(value_inst_index)].pl_node.payload_index,
2837 ).data.operand.toIndex(),
2838 };
2839 break :value_inst value_inst;
2840 };
2841 if (type_inst_info.inst != value_inst) break :decl_union;
2842
2843 const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern());
2844 if (type_gop.found_existing) {
2845 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).clear();
2846 nav_gop.value_ptr.* = type_gop.value_ptr.*;
2847 } else {
2848 if (nav_gop.found_existing)
2849 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(nav_gop.value_ptr.*).clear()
2850 else
2851 nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit);
2852 type_gop.value_ptr.* = nav_gop.value_ptr.*;
2853 }
2854 wip_nav.entry = nav_gop.value_ptr.*;
2855 const diw = wip_nav.debug_info.writer(dwarf.gpa);
2856 try wip_nav.abbrevCode(.decl_union);
2857 try wip_nav.refType(Type.fromInterned(parent_type));
2858 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2859 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2860 try uleb128(diw, loc.column + 1);
2861 try diw.writeByte(accessibility);
2862 try wip_nav.strp(nav.name.toSlice(ip));
2863 const union_layout = Type.getUnionLayout(loaded_union, zcu);
2864 try uleb128(diw, union_layout.abi_size);
2865 try uleb128(diw, union_layout.abi_align.toByteUnits().?);
2866 const loaded_tag = loaded_union.loadTagType(ip);
2867 if (loaded_union.hasTag(ip)) {
2868 try wip_nav.abbrevCode(.tagged_union);
2869 try wip_nav.infoSectionOffset(
2870 .debug_info,
2871 wip_nav.unit,
2872 wip_nav.entry,
2873 @intCast(wip_nav.debug_info.items.len + dwarf.sectionOffsetBytes()),
2874 );
2875 {
2876 try wip_nav.abbrevCode(.generated_field);
2877 try wip_nav.strp("tag");
2878 try wip_nav.refType(Type.fromInterned(loaded_union.enum_tag_ty));
2879 try uleb128(diw, union_layout.tagOffset());
2880
2881 for (0..loaded_union.field_types.len) |field_index| {
2882 try wip_nav.enumConstValue(loaded_tag, .{
2883 .sdata = .signed_tagged_union_field,
2884 .udata = .unsigned_tagged_union_field,
2885 .block = .big_tagged_union_field,
2886 }, field_index);
2887 {
2888 try wip_nav.abbrevCode(.struct_field);
2889 try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip));
2890 const field_type = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
2891 try wip_nav.refType(field_type);
2892 try uleb128(diw, union_layout.payloadOffset());
2893 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse
2894 if (field_type.isNoReturn(zcu)) 1 else field_type.abiAlignment(zcu).toByteUnits().?);
2895 }
2896 try uleb128(diw, @intFromEnum(AbbrevCode.null));
2897 }
2898 }
2899 try uleb128(diw, @intFromEnum(AbbrevCode.null));
2900 } else for (0..loaded_union.field_types.len) |field_index| {
2901 try wip_nav.abbrevCode(.untagged_union_field);
2902 try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip));
2903 const field_type = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
2904 try wip_nav.refType(field_type);
2905 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse
2906 field_type.abiAlignment(zcu).toByteUnits().?);
2907 }
2908 try uleb128(diw, @intFromEnum(AbbrevCode.null));
2909 break :done;
2910 }
2911
2912 if (nav_gop.found_existing)
2913 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(nav_gop.value_ptr.*).clear()
2914 else
2915 nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit);
2916 wip_nav.entry = nav_gop.value_ptr.*;
2982 .decl_var => {
29172983 const diw = wip_nav.debug_info.writer(dwarf.gpa);
2918 try wip_nav.abbrevCode(.decl_alias);
2984 try wip_nav.abbrevCode(.decl_var);
29192985 try wip_nav.refType(Type.fromInterned(parent_type));
29202986 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
29212987 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
29222988 try uleb128(diw, loc.column + 1);
29232989 try diw.writeByte(accessibility);
29242990 try wip_nav.strp(nav.name.toSlice(ip));
2925 try wip_nav.refType(nav_val.toType());
2991 try wip_nav.strp(nav.fqn.toSlice(ip));
2992 const nav_ty = nav_val.typeOf(zcu);
2993 try wip_nav.refType(nav_ty);
2994 try wip_nav.blockValue(nav_src_loc, nav_val);
2995 try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse
2996 nav_ty.abiAlignment(zcu).toByteUnits().?);
2997 try diw.writeByte(@intFromBool(false));
29262998 },
2927 .opaque_type => done: {
2928 const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern());
2929
2930 const parent_type, const accessibility: u8 = if (nav.analysis_owner.unwrap()) |cau| parent: {
2931 const parent_namespace_ptr = ip.namespacePtr(ip.getCau(cau).namespace);
2932 break :parent .{
2933 parent_namespace_ptr.owner_type,
2934 if (parent_namespace_ptr.pub_decls.containsContext(nav_index, .{ .zcu = zcu }))
2935 DW.ACCESS.public
2936 else if (parent_namespace_ptr.priv_decls.containsContext(nav_index, .{ .zcu = zcu }))
2937 DW.ACCESS.private
2938 else
2939 unreachable,
2940 };
2941 } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private };
2942
2943 decl_opaque: {
2944 const type_inst_info = loaded_opaque.zir_index.resolveFull(ip).?;
2945 if (type_inst_info.file != inst_info.file) break :decl_opaque;
2946
2947 const value_inst = value_inst: {
2948 const decl_value_body = decl_extra.data.getBodies(@intCast(decl_extra.end), file.zir).value_body;
2949 const break_inst = file.zir.instructions.get(@intFromEnum(decl_value_body[decl_value_body.len - 1]));
2950 if (break_inst.tag != .break_inline) break :value_inst null;
2951 assert(file.zir.extraData(Zir.Inst.Break, break_inst.data.@"break".payload_index).data.block_inst == inst_info.inst);
2952 var value_inst = break_inst.data.@"break".operand.toIndex();
2953 while (value_inst) |value_inst_index| switch (file.zir.instructions.items(.tag)[@intFromEnum(value_inst_index)]) {
2954 else => break,
2955 .as_node => value_inst = file.zir.extraData(
2956 Zir.Inst.As,
2957 file.zir.instructions.items(.data)[@intFromEnum(value_inst_index)].pl_node.payload_index,
2958 ).data.operand.toIndex(),
2959 };
2960 break :value_inst value_inst;
2961 };
2962 if (type_inst_info.inst != value_inst) break :decl_opaque;
2963
2964 const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern());
2965 if (type_gop.found_existing) {
2966 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(type_gop.value_ptr.*).clear();
2967 nav_gop.value_ptr.* = type_gop.value_ptr.*;
2968 } else {
2969 if (nav_gop.found_existing)
2970 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(nav_gop.value_ptr.*).clear()
2971 else
2972 nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit);
2973 type_gop.value_ptr.* = nav_gop.value_ptr.*;
2974 }
2975 wip_nav.entry = nav_gop.value_ptr.*;
2976 const diw = wip_nav.debug_info.writer(dwarf.gpa);
2977 try wip_nav.abbrevCode(.decl_namespace_struct);
2978 try wip_nav.refType(Type.fromInterned(parent_type));
2979 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
2980 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
2981 try uleb128(diw, loc.column + 1);
2982 try diw.writeByte(accessibility);
2983 try wip_nav.strp(nav.name.toSlice(ip));
2984 try diw.writeByte(@intFromBool(false));
2985 break :done;
2986 }
2987
2988 if (nav_gop.found_existing)
2989 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(nav_gop.value_ptr.*).clear()
2990 else
2991 nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit);
2992 wip_nav.entry = nav_gop.value_ptr.*;
2999 .decl_const => {
29933000 const diw = wip_nav.debug_info.writer(dwarf.gpa);
2994 try wip_nav.abbrevCode(.decl_alias);
3001 try wip_nav.abbrevCode(.decl_const);
29953002 try wip_nav.refType(Type.fromInterned(parent_type));
29963003 assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf));
29973004 try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian);
29983005 try uleb128(diw, loc.column + 1);
29993006 try diw.writeByte(accessibility);
30003007 try wip_nav.strp(nav.name.toSlice(ip));
3001 try wip_nav.refType(nav_val.toType());
3002 },
3003 else => {
3004 _ = dwarf.navs.pop();
3005 return;
3008 try wip_nav.strp(nav.fqn.toSlice(ip));
3009 const nav_ty = nav_val.typeOf(zcu);
3010 const nav_ty_reloc_index = try wip_nav.refForward();
3011 try wip_nav.blockValue(nav_src_loc, nav_val);
3012 try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse
3013 nav_ty.abiAlignment(zcu).toByteUnits().?);
3014 try diw.writeByte(@intFromBool(false));
3015 wip_nav.finishForward(nav_ty_reloc_index);
3016 try wip_nav.abbrevCode(.is_const);
3017 try wip_nav.refType(nav_ty);
30063018 },
30073019 }
30083020 try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items);
3009 try wip_nav.flush();
3021 try wip_nav.flush(nav_src_loc);
30103022}
30113023
30123024fn updateType(
30133025 dwarf: *Dwarf,
30143026 pt: Zcu.PerThread,
3027 src_loc: Zcu.LazySrcLoc,
30153028 type_index: InternPool.Index,
30163029 pending_types: *std.ArrayListUnmanaged(InternPool.Index),
30173030) UpdateError!void {
......@@ -3068,15 +3081,10 @@ fn updateType(
30683081 const ptr_child_type = Type.fromInterned(ptr_type.child);
30693082 try wip_nav.abbrevCode(if (ptr_type.sentinel == .none) .ptr_type else .ptr_sentinel_type);
30703083 try wip_nav.strp(name);
3071 if (ptr_type.sentinel != .none) {
3072 const bytes = ptr_child_type.abiSize(zcu);
3073 try uleb128(diw, bytes);
3074 const mem = try wip_nav.debug_info.addManyAsSlice(dwarf.gpa, @intCast(bytes));
3075 Value.fromInterned(ptr_type.sentinel).writeToMemory(pt, mem) catch |err| switch (err) {
3076 error.IllDefinedMemoryLayout => @memset(mem, 0),
3077 else => |e| return e,
3078 };
3079 }
3084 if (ptr_type.sentinel != .none) try wip_nav.blockValue(
3085 src_loc,
3086 Value.fromInterned(ptr_type.sentinel),
3087 );
30803088 try uleb128(diw, ptr_type.flags.alignment.toByteUnits() orelse
30813089 ptr_child_type.abiAlignment(zcu).toByteUnits().?);
30823090 try diw.writeByte(@intFromEnum(ptr_type.flags.address_space));
......@@ -3122,15 +3130,10 @@ fn updateType(
31223130 const array_child_type = Type.fromInterned(array_type.child);
31233131 try wip_nav.abbrevCode(if (array_type.sentinel == .none) .array_type else .array_sentinel_type);
31243132 try wip_nav.strp(name);
3125 if (array_type.sentinel != .none) {
3126 const bytes = array_child_type.abiSize(zcu);
3127 try uleb128(diw, bytes);
3128 const mem = try wip_nav.debug_info.addManyAsSlice(dwarf.gpa, @intCast(bytes));
3129 Value.fromInterned(array_type.sentinel).writeToMemory(pt, mem) catch |err| switch (err) {
3130 error.IllDefinedMemoryLayout => @memset(mem, 0),
3131 else => |e| return e,
3132 };
3133 }
3133 if (array_type.sentinel != .none) try wip_nav.blockValue(
3134 src_loc,
3135 Value.fromInterned(array_type.sentinel),
3136 );
31343137 try wip_nav.refType(array_child_type);
31353138 try wip_nav.abbrevCode(.array_index);
31363139 try wip_nav.refType(Type.usize);
......@@ -3360,7 +3363,10 @@ fn updateType(
33603363 }
33613364 const field_type = Type.fromInterned(anon_struct_type.types.get(ip)[field_index]);
33623365 try wip_nav.refType(field_type);
3363 if (comptime_value == .none) {
3366 if (comptime_value != .none) try wip_nav.blockValue(
3367 src_loc,
3368 Value.fromInterned(comptime_value),
3369 ) else {
33643370 const field_align = field_type.abiAlignment(zcu);
33653371 field_byte_offset = field_align.forward(field_byte_offset);
33663372 try uleb128(diw, field_byte_offset);
......@@ -3427,16 +3433,13 @@ fn updateType(
34273433 }
34283434 if (error_set_type.names.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null));
34293435 },
3430 .inferred_error_set_type => |func| switch (ip.funcIesResolvedUnordered(func)) {
3431 .none => {
3432 try wip_nav.abbrevCode(.void_type);
3433 try wip_nav.strp(name);
3434 },
3435 else => |ies| {
3436 try wip_nav.abbrevCode(.inferred_error_set_type);
3437 try wip_nav.strp(name);
3438 try wip_nav.refType(Type.fromInterned(ies));
3439 },
3436 .inferred_error_set_type => |func| {
3437 try wip_nav.abbrevCode(.inferred_error_set_type);
3438 try wip_nav.strp(name);
3439 try wip_nav.refType(Type.fromInterned(switch (ip.funcIesResolvedUnordered(func)) {
3440 .none => .anyerror_type,
3441 else => |ies| ies,
3442 }));
34403443 },
34413444
34423445 // values, not types
......@@ -3468,6 +3471,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
34683471 const zcu = pt.zcu;
34693472 const ip = &zcu.intern_pool;
34703473 const ty = Type.fromInterned(type_index);
3474 const ty_src_loc = ty.srcLoc(zcu);
34713475 log.debug("updateContainerType({}({d}))", .{ ty.fmt(pt), @intFromEnum(type_index) });
34723476
34733477 const inst_info = ty.typeDeclInst(zcu).?.resolveFull(ip).?;
......@@ -3507,25 +3511,41 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
35073511 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
35083512 for (0..loaded_struct.field_types.len) |field_index| {
35093513 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
3510 try wip_nav.abbrevCode(if (is_comptime) .struct_field_comptime else .struct_field);
3514 const field_init = if (loaded_struct.haveFieldInits(ip))
3515 loaded_struct.fieldInit(ip, field_index)
3516 else
3517 .none;
3518 try wip_nav.abbrevCode(if (is_comptime)
3519 .struct_field_comptime
3520 else if (field_init != .none)
3521 .struct_field_default
3522 else
3523 .struct_field);
35113524 if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name| try wip_nav.strp(field_name.toSlice(ip)) else {
35123525 const field_name = try std.fmt.allocPrint(dwarf.gpa, "{d}", .{field_index});
35133526 defer dwarf.gpa.free(field_name);
35143527 try wip_nav.strp(field_name);
35153528 }
3516 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
3517 try wip_nav.refType(field_type);
3518 if (!is_comptime) {
3519 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
3520 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
3521 field_type.abiAlignment(zcu).toByteUnits().?);
3529 if (is_comptime and field_init == .none) {
3530 // workaround frontend bug
3531 try wip_nav.refType(Type.void);
3532 try wip_nav.blockValue(ty_src_loc, Value.void);
3533 } else {
3534 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
3535 try wip_nav.refType(field_type);
3536 if (!is_comptime) {
3537 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
3538 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
3539 field_type.abiAlignment(zcu).toByteUnits().?);
3540 }
3541 if (field_init != .none) try wip_nav.blockValue(ty_src_loc, Value.fromInterned(field_init));
35223542 }
35233543 }
35243544 try uleb128(diw, @intFromEnum(AbbrevCode.null));
35253545 }
35263546
35273547 try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items);
3528 try wip_nav.flush();
3548 try wip_nav.flush(ty_src_loc);
35293549 } else {
35303550 const decl_inst = file.zir.instructions.get(@intFromEnum(inst_info.inst));
35313551 assert(decl_inst.tag == .extended);
......@@ -3575,18 +3595,34 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
35753595 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
35763596 for (0..loaded_struct.field_types.len) |field_index| {
35773597 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
3578 try wip_nav.abbrevCode(if (is_comptime) .struct_field_comptime else .struct_field);
3598 const field_init = if (loaded_struct.haveFieldInits(ip))
3599 loaded_struct.fieldInit(ip, field_index)
3600 else
3601 .none;
3602 try wip_nav.abbrevCode(if (is_comptime)
3603 .struct_field_comptime
3604 else if (field_init != .none)
3605 .struct_field_default
3606 else
3607 .struct_field);
35793608 if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name| try wip_nav.strp(field_name.toSlice(ip)) else {
35803609 const field_name = try std.fmt.allocPrint(dwarf.gpa, "{d}", .{field_index});
35813610 defer dwarf.gpa.free(field_name);
35823611 try wip_nav.strp(field_name);
35833612 }
3584 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
3585 try wip_nav.refType(field_type);
3586 if (!is_comptime) {
3587 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
3588 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
3589 field_type.abiAlignment(zcu).toByteUnits().?);
3613 if (is_comptime and field_init == .none) {
3614 // workaround frontend bug
3615 try wip_nav.refType(Type.void);
3616 try wip_nav.blockValue(ty_src_loc, Value.void);
3617 } else {
3618 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
3619 try wip_nav.refType(field_type);
3620 if (!is_comptime) {
3621 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
3622 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
3623 field_type.abiAlignment(zcu).toByteUnits().?);
3624 }
3625 if (field_init != .none) try wip_nav.blockValue(ty_src_loc, Value.fromInterned(field_init));
35903626 }
35913627 }
35923628 try uleb128(diw, @intFromEnum(AbbrevCode.null));
......@@ -3684,7 +3720,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
36843720 }
36853721 try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items);
36863722 try dwarf.debug_loclists.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_loclists.items);
3687 try wip_nav.flush();
3723 try wip_nav.flush(ty_src_loc);
36883724 }
36893725}
36903726
......@@ -3732,12 +3768,15 @@ fn refAbbrevCode(dwarf: *Dwarf, abbrev_code: AbbrevCode) UpdateError!@typeInfo(A
37323768pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void {
37333769 const zcu = pt.zcu;
37343770 const ip = &zcu.intern_pool;
3735 if (dwarf.types.get(.anyerror_type)) |entry| {
3771
3772 {
3773 const type_gop = try dwarf.types.getOrPut(dwarf.gpa, .anyerror_type);
3774 if (!type_gop.found_existing) type_gop.value_ptr.* = try dwarf.addCommonEntry(.main);
37363775 var wip_nav: WipNav = .{
37373776 .dwarf = dwarf,
37383777 .pt = pt,
37393778 .unit = .main,
3740 .entry = entry,
3779 .entry = type_gop.value_ptr.*,
37413780 .any_children = false,
37423781 .func = .none,
37433782 .func_sym_index = undefined,
......@@ -4150,6 +4189,7 @@ const AbbrevCode = enum {
41504189 decl_packed_struct,
41514190 decl_union,
41524191 decl_var,
4192 decl_const,
41534193 decl_func,
41544194 decl_empty_func,
41554195 decl_func_generic,
......@@ -4164,6 +4204,7 @@ const AbbrevCode = enum {
41644204 big_enum_field,
41654205 generated_field,
41664206 struct_field,
4207 struct_field_default,
41674208 struct_field_comptime,
41684209 packed_struct_field,
41694210 untagged_union_field,
......@@ -4285,6 +4326,16 @@ const AbbrevCode = enum {
42854326 .{ .external, .flag },
42864327 },
42874328 },
4329 .decl_const = .{
4330 .tag = .constant,
4331 .attrs = decl_abbrev_common_attrs ++ .{
4332 .{ .linkage_name, .strp },
4333 .{ .type, .ref_addr },
4334 .{ .const_value, .block },
4335 .{ .alignment, .udata },
4336 .{ .external, .flag },
4337 },
4338 },
42884339 .decl_func = .{
42894340 .tag = .subprogram,
42904341 .children = true,
......@@ -4401,12 +4452,23 @@ const AbbrevCode = enum {
44014452 .{ .alignment, .udata },
44024453 },
44034454 },
4404 .struct_field_comptime = .{
4455 .struct_field_default = .{
44054456 .tag = .member,
44064457 .attrs = &.{
44074458 .{ .name, .strp },
44084459 .{ .type, .ref_addr },
4460 .{ .data_member_location, .udata },
4461 .{ .alignment, .udata },
4462 .{ .default_value, .block },
4463 },
4464 },
4465 .struct_field_comptime = .{
4466 .tag = .member,
4467 .attrs = &.{
44094468 .{ .const_expr, .flag_present },
4469 .{ .name, .strp },
4470 .{ .type, .ref_addr },
4471 .{ .const_value, .block },
44104472 },
44114473 },
44124474 .packed_struct_field = .{
src/link/Elf/ZigObject.zig+43-20
......@@ -957,13 +957,26 @@ pub fn getNavVAddr(
957957 };
958958 const this_sym = self.symbol(this_sym_index);
959959 const vaddr = this_sym.address(.{}, elf_file);
960 const parent_atom = self.symbol(reloc_info.parent_atom_index).atom(elf_file).?;
961 const r_type = relocation.encode(.abs, elf_file.getTarget().cpu.arch);
962 try parent_atom.addReloc(elf_file.base.comp.gpa, .{
963 .r_offset = reloc_info.offset,
964 .r_info = (@as(u64, @intCast(this_sym_index)) << 32) | r_type,
965 .r_addend = reloc_info.addend,
966 }, self);
960 switch (reloc_info.parent) {
961 .atom_index => |atom_index| {
962 const parent_atom = self.symbol(atom_index).atom(elf_file).?;
963 const r_type = relocation.encode(.abs, elf_file.getTarget().cpu.arch);
964 try parent_atom.addReloc(elf_file.base.comp.gpa, .{
965 .r_offset = reloc_info.offset,
966 .r_info = (@as(u64, @intCast(this_sym_index)) << 32) | r_type,
967 .r_addend = reloc_info.addend,
968 }, self);
969 },
970 .debug_output => |debug_output| switch (debug_output) {
971 .dwarf => |wip_nav| try wip_nav.infoExternalReloc(.{
972 .source_off = @intCast(reloc_info.offset),
973 .target_sym = this_sym_index,
974 .target_off = reloc_info.addend,
975 }),
976 .plan9 => unreachable,
977 .none => unreachable,
978 },
979 }
967980 return @intCast(vaddr);
968981}
969982
......@@ -976,13 +989,26 @@ pub fn getUavVAddr(
976989 const sym_index = self.uavs.get(uav).?.symbol_index;
977990 const sym = self.symbol(sym_index);
978991 const vaddr = sym.address(.{}, elf_file);
979 const parent_atom = self.symbol(reloc_info.parent_atom_index).atom(elf_file).?;
980 const r_type = relocation.encode(.abs, elf_file.getTarget().cpu.arch);
981 try parent_atom.addReloc(elf_file.base.comp.gpa, .{
982 .r_offset = reloc_info.offset,
983 .r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type,
984 .r_addend = reloc_info.addend,
985 }, self);
992 switch (reloc_info.parent) {
993 .atom_index => |atom_index| {
994 const parent_atom = self.symbol(atom_index).atom(elf_file).?;
995 const r_type = relocation.encode(.abs, elf_file.getTarget().cpu.arch);
996 try parent_atom.addReloc(elf_file.base.comp.gpa, .{
997 .r_offset = reloc_info.offset,
998 .r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type,
999 .r_addend = reloc_info.addend,
1000 }, self);
1001 },
1002 .debug_output => |debug_output| switch (debug_output) {
1003 .dwarf => |wip_nav| try wip_nav.infoExternalReloc(.{
1004 .source_off = @intCast(reloc_info.offset),
1005 .target_sym = sym_index,
1006 .target_off = reloc_info.addend,
1007 }),
1008 .plan9 => unreachable,
1009 .none => unreachable,
1010 },
1011 }
9861012 return @intCast(vaddr);
9871013}
9881014
......@@ -1600,15 +1626,13 @@ pub fn updateNav(
16001626 var debug_wip_nav = if (self.dwarf) |*dwarf| try dwarf.initWipNav(pt, nav_index, sym_index) else null;
16011627 defer if (debug_wip_nav) |*wip_nav| wip_nav.deinit();
16021628
1603 // TODO implement .debug_info for global variables
16041629 const res = try codegen.generateSymbol(
16051630 &elf_file.base,
16061631 pt,
16071632 zcu.navSrcLoc(nav_index),
16081633 Value.fromInterned(nav_init),
16091634 &code_buffer,
1610 if (debug_wip_nav) |*wip_nav| .{ .dwarf = wip_nav } else .none,
1611 .{ .parent_atom_index = sym_index },
1635 .{ .atom_index = sym_index },
16121636 );
16131637
16141638 const code = switch (res) {
......@@ -1691,7 +1715,7 @@ fn updateLazySymbol(
16911715 &required_alignment,
16921716 &code_buffer,
16931717 .none,
1694 .{ .parent_atom_index = symbol_index },
1718 .{ .atom_index = symbol_index },
16951719 );
16961720 const code = switch (res) {
16971721 .ok => code_buffer.items,
......@@ -1780,8 +1804,7 @@ fn lowerConst(
17801804 src_loc,
17811805 val,
17821806 &code_buffer,
1783 .{ .none = {} },
1784 .{ .parent_atom_index = sym_index },
1807 .{ .atom_index = sym_index },
17851808 );
17861809 const code = switch (res) {
17871810 .ok => code_buffer.items,
src/link/MachO/ZigObject.zig+62-34
......@@ -633,20 +633,33 @@ pub fn getNavVAddr(
633633 };
634634 const sym = self.symbols.items[sym_index];
635635 const vaddr = sym.getAddress(.{}, macho_file);
636 const parent_atom = self.symbols.items[reloc_info.parent_atom_index].getAtom(macho_file).?;
637 try parent_atom.addReloc(macho_file, .{
638 .tag = .@"extern",
639 .offset = @intCast(reloc_info.offset),
640 .target = sym_index,
641 .addend = reloc_info.addend,
642 .type = .unsigned,
643 .meta = .{
644 .pcrel = false,
645 .has_subtractor = false,
646 .length = 3,
647 .symbolnum = @intCast(sym.nlist_idx),
636 switch (reloc_info.parent) {
637 .atom_index => |atom_index| {
638 const parent_atom = self.symbols.items[atom_index].getAtom(macho_file).?;
639 try parent_atom.addReloc(macho_file, .{
640 .tag = .@"extern",
641 .offset = @intCast(reloc_info.offset),
642 .target = sym_index,
643 .addend = reloc_info.addend,
644 .type = .unsigned,
645 .meta = .{
646 .pcrel = false,
647 .has_subtractor = false,
648 .length = 3,
649 .symbolnum = @intCast(sym.nlist_idx),
650 },
651 });
648652 },
649 });
653 .debug_output => |debug_output| switch (debug_output) {
654 .dwarf => |wip_nav| try wip_nav.infoExternalReloc(.{
655 .source_off = @intCast(reloc_info.offset),
656 .target_sym = sym_index,
657 .target_off = reloc_info.addend,
658 }),
659 .plan9 => unreachable,
660 .none => unreachable,
661 },
662 }
650663 return vaddr;
651664}
652665
......@@ -659,20 +672,33 @@ pub fn getUavVAddr(
659672 const sym_index = self.uavs.get(uav).?.symbol_index;
660673 const sym = self.symbols.items[sym_index];
661674 const vaddr = sym.getAddress(.{}, macho_file);
662 const parent_atom = self.symbols.items[reloc_info.parent_atom_index].getAtom(macho_file).?;
663 try parent_atom.addReloc(macho_file, .{
664 .tag = .@"extern",
665 .offset = @intCast(reloc_info.offset),
666 .target = sym_index,
667 .addend = reloc_info.addend,
668 .type = .unsigned,
669 .meta = .{
670 .pcrel = false,
671 .has_subtractor = false,
672 .length = 3,
673 .symbolnum = @intCast(sym.nlist_idx),
675 switch (reloc_info.parent) {
676 .atom_index => |atom_index| {
677 const parent_atom = self.symbols.items[atom_index].getAtom(macho_file).?;
678 try parent_atom.addReloc(macho_file, .{
679 .tag = .@"extern",
680 .offset = @intCast(reloc_info.offset),
681 .target = sym_index,
682 .addend = reloc_info.addend,
683 .type = .unsigned,
684 .meta = .{
685 .pcrel = false,
686 .has_subtractor = false,
687 .length = 3,
688 .symbolnum = @intCast(sym.nlist_idx),
689 },
690 });
674691 },
675 });
692 .debug_output => |debug_output| switch (debug_output) {
693 .dwarf => |wip_nav| try wip_nav.infoExternalReloc(.{
694 .source_off = @intCast(reloc_info.offset),
695 .target_sym = sym_index,
696 .target_off = reloc_info.addend,
697 }),
698 .plan9 => unreachable,
699 .none => unreachable,
700 },
701 }
676702 return vaddr;
677703}
678704
......@@ -903,8 +929,7 @@ pub fn updateNav(
903929 zcu.navSrcLoc(nav_index),
904930 Value.fromInterned(nav_init),
905931 &code_buffer,
906 if (debug_wip_nav) |*wip_nav| .{ .dwarf = wip_nav } else .none,
907 .{ .parent_atom_index = sym_index },
932 .{ .atom_index = sym_index },
908933 );
909934
910935 const code = switch (res) {
......@@ -1212,11 +1237,14 @@ fn lowerConst(
12121237 const name_str = try self.addString(gpa, name);
12131238 const sym_index = try self.newSymbolWithAtom(gpa, name_str, macho_file);
12141239
1215 const res = try codegen.generateSymbol(&macho_file.base, pt, src_loc, val, &code_buffer, .{
1216 .none = {},
1217 }, .{
1218 .parent_atom_index = sym_index,
1219 });
1240 const res = try codegen.generateSymbol(
1241 &macho_file.base,
1242 pt,
1243 src_loc,
1244 val,
1245 &code_buffer,
1246 .{ .atom_index = sym_index },
1247 );
12201248 const code = switch (res) {
12211249 .ok => code_buffer.items,
12221250 .fail => |em| return .{ .fail = em },
......@@ -1378,7 +1406,7 @@ fn updateLazySymbol(
13781406 &required_alignment,
13791407 &code_buffer,
13801408 .none,
1381 .{ .parent_atom_index = symbol_index },
1409 .{ .atom_index = symbol_index },
13821410 );
13831411 const code = switch (res) {
13841412 .ok => code_buffer.items,
src/link/Plan9.zig+17-18
......@@ -422,10 +422,7 @@ pub fn updateFunc(self: *Plan9, pt: Zcu.PerThread, func_index: InternPool.Index,
422422 );
423423 const code = switch (res) {
424424 .ok => try code_buffer.toOwnedSlice(),
425 .fail => |em| {
426 try zcu.failed_codegen.put(gpa, func.owner_nav, em);
427 return;
428 },
425 .fail => |em| return zcu.failed_codegen.put(gpa, func.owner_nav, em),
429426 };
430427 self.getAtomPtr(atom_idx).code = .{
431428 .code_ptr = null,
......@@ -463,15 +460,17 @@ pub fn updateNav(self: *Plan9, pt: Zcu.PerThread, nav_index: InternPool.Nav.Inde
463460 var code_buffer = std.ArrayList(u8).init(gpa);
464461 defer code_buffer.deinit();
465462 // TODO we need the symbol index for symbol in the table of locals for the containing atom
466 const res = try codegen.generateSymbol(&self.base, pt, zcu.navSrcLoc(nav_index), nav_init, &code_buffer, .none, .{
467 .parent_atom_index = @intCast(atom_idx),
468 });
463 const res = try codegen.generateSymbol(
464 &self.base,
465 pt,
466 zcu.navSrcLoc(nav_index),
467 nav_init,
468 &code_buffer,
469 .{ .atom_index = @intCast(atom_idx) },
470 );
469471 const code = switch (res) {
470472 .ok => code_buffer.items,
471 .fail => |em| {
472 try zcu.failed_codegen.put(gpa, nav_index, em);
473 return;
474 },
473 .fail => |em| return zcu.failed_codegen.put(gpa, nav_index, em),
475474 };
476475 try self.data_nav_table.ensureUnusedCapacity(gpa, 1);
477476 const duped_code = try gpa.dupe(u8, code);
......@@ -1116,7 +1115,7 @@ fn updateLazySymbolAtom(self: *Plan9, pt: Zcu.PerThread, sym: File.LazySymbol, a
11161115 &required_alignment,
11171116 &code_buffer,
11181117 .none,
1119 .{ .parent_atom_index = @as(Atom.Index, @intCast(atom_index)) },
1118 .{ .atom_index = @intCast(atom_index) },
11201119 );
11211120 const code = switch (res) {
11221121 .ok => code_buffer.items,
......@@ -1373,21 +1372,21 @@ pub fn getNavVAddr(
13731372 log.debug("getDeclVAddr for {}", .{nav.name.fmt(ip)});
13741373 if (ip.indexToKey(nav.status.resolved.val) == .@"extern") {
13751374 if (nav.name.eqlSlice("etext", ip)) {
1376 try self.addReloc(reloc_info.parent_atom_index, .{
1375 try self.addReloc(reloc_info.parent.atom_index, .{
13771376 .target = undefined,
13781377 .offset = reloc_info.offset,
13791378 .addend = reloc_info.addend,
13801379 .type = .special_etext,
13811380 });
13821381 } else if (nav.name.eqlSlice("edata", ip)) {
1383 try self.addReloc(reloc_info.parent_atom_index, .{
1382 try self.addReloc(reloc_info.parent.atom_index, .{
13841383 .target = undefined,
13851384 .offset = reloc_info.offset,
13861385 .addend = reloc_info.addend,
13871386 .type = .special_edata,
13881387 });
13891388 } else if (nav.name.eqlSlice("end", ip)) {
1390 try self.addReloc(reloc_info.parent_atom_index, .{
1389 try self.addReloc(reloc_info.parent.atom_index, .{
13911390 .target = undefined,
13921391 .offset = reloc_info.offset,
13931392 .addend = reloc_info.addend,
......@@ -1400,7 +1399,7 @@ pub fn getNavVAddr(
14001399 // otherwise, we just add a relocation
14011400 const atom_index = try self.seeNav(pt, nav_index);
14021401 // the parent_atom_index in this case is just the decl_index of the parent
1403 try self.addReloc(reloc_info.parent_atom_index, .{
1402 try self.addReloc(reloc_info.parent.atom_index, .{
14041403 .target = atom_index,
14051404 .offset = reloc_info.offset,
14061405 .addend = reloc_info.addend,
......@@ -1435,7 +1434,7 @@ pub fn lowerUav(
14351434 gop.value_ptr.* = index;
14361435 // we need to free name latex
14371436 var code_buffer = std.ArrayList(u8).init(gpa);
1438 const res = try codegen.generateSymbol(&self.base, pt, src_loc, val, &code_buffer, .{ .none = {} }, .{ .parent_atom_index = index });
1437 const res = try codegen.generateSymbol(&self.base, pt, src_loc, val, &code_buffer, .{ .atom_index = index });
14391438 const code = switch (res) {
14401439 .ok => code_buffer.items,
14411440 .fail => |em| return .{ .fail = em },
......@@ -1459,7 +1458,7 @@ pub fn lowerUav(
14591458
14601459pub fn getUavVAddr(self: *Plan9, uav: InternPool.Index, reloc_info: link.File.RelocInfo) !u64 {
14611460 const atom_index = self.uavs.get(uav).?;
1462 try self.addReloc(reloc_info.parent_atom_index, .{
1461 try self.addReloc(reloc_info.parent.atom_index, .{
14631462 .target = atom_index,
14641463 .offset = reloc_info.offset,
14651464 .addend = reloc_info.addend,
src/link/Wasm/ZigObject.zig+11-9
......@@ -277,8 +277,7 @@ pub fn updateNav(
277277 zcu.navSrcLoc(nav_index),
278278 nav_init,
279279 &code_writer,
280 .none,
281 .{ .parent_atom_index = @intFromEnum(atom.sym_index) },
280 .{ .atom_index = @intFromEnum(atom.sym_index) },
282281 );
283282
284283 const code = switch (res) {
......@@ -520,10 +519,7 @@ fn lowerConst(
520519 src_loc,
521520 val,
522521 &value_bytes,
523 .none,
524 .{
525 .parent_atom_index = @intFromEnum(atom.sym_index),
526 },
522 .{ .atom_index = @intFromEnum(atom.sym_index) },
527523 );
528524 break :code switch (result) {
529525 .ok => value_bytes.items,
......@@ -762,8 +758,11 @@ pub fn getNavVAddr(
762758 else => {},
763759 }
764760
765 std.debug.assert(reloc_info.parent_atom_index != 0);
766 const atom_index = wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = @enumFromInt(reloc_info.parent_atom_index) }).?;
761 std.debug.assert(reloc_info.parent.atom_index != 0);
762 const atom_index = wasm_file.symbol_atom.get(.{
763 .file = zig_object.index,
764 .index = @enumFromInt(reloc_info.parent.atom_index),
765 }).?;
767766 const atom = wasm_file.getAtomPtr(atom_index);
768767 const is_wasm32 = target.cpu.arch == .wasm32;
769768 if (ip.isFunctionType(ip.getNav(nav_index).typeOf(ip))) {
......@@ -800,7 +799,10 @@ pub fn getUavVAddr(
800799 const atom_index = zig_object.uavs.get(uav).?;
801800 const target_symbol_index = @intFromEnum(wasm_file.getAtom(atom_index).sym_index);
802801
803 const parent_atom_index = wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = @enumFromInt(reloc_info.parent_atom_index) }).?;
802 const parent_atom_index = wasm_file.symbol_atom.get(.{
803 .file = zig_object.index,
804 .index = @enumFromInt(reloc_info.parent.atom_index),
805 }).?;
804806 const parent_atom = wasm_file.getAtomPtr(parent_atom_index);
805807 const is_wasm32 = target.cpu.arch == .wasm32;
806808 const zcu = wasm_file.base.comp.zcu.?;
test/src/Debugger.zig+597-33
......@@ -107,11 +107,11 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
107107 },
108108 \\breakpoint set --file basic.zig --source-pattern-regexp '_ = basic;'
109109 \\process launch
110 \\frame variable --show-types basic
110 \\frame variable --show-types -- basic
111111 \\breakpoint delete --force 1
112112 ,
113113 &.{
114 \\(lldb) frame variable --show-types basic
114 \\(lldb) frame variable --show-types -- basic
115115 \\(root.basic.Basic) basic = {
116116 \\ (void) void = {}
117117 \\ (bool) bool_false = false
......@@ -243,11 +243,11 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
243243 },
244244 \\breakpoint set --file pointers.zig --source-pattern-regexp '_ = pointers;'
245245 \\process launch
246 \\frame variable --show-types pointers
246 \\frame variable --show-types -- pointers
247247 \\breakpoint delete --force 1
248248 ,
249249 &.{
250 \\(lldb) frame variable --show-types pointers
250 \\(lldb) frame variable --show-types -- pointers
251251 \\(root.pointers.Pointers) pointers = {
252252 \\ (*u32) single = 0x0000000000001010
253253 \\ (*const u32) single_const = 0x0000000000001014
......@@ -330,13 +330,13 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
330330 },
331331 \\breakpoint set --file strings.zig --source-pattern-regexp '_ = strings;'
332332 \\process launch
333 \\frame variable --show-types strings.slice
334 \\frame variable --show-types --format character strings.slice
335 \\frame variable --show-types --format c-string strings
333 \\frame variable --show-types -- strings.slice
334 \\frame variable --show-types --format character -- strings.slice
335 \\frame variable --show-types --format c-string -- strings
336336 \\breakpoint delete --force 1
337337 ,
338338 &.{
339 \\(lldb) frame variable --show-types strings.slice
339 \\(lldb) frame variable --show-types -- strings.slice
340340 \\([:0]const u8) strings.slice = len=9 {
341341 \\ (u8) [0] = 115
342342 \\ (u8) [1] = 108
......@@ -348,7 +348,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
348348 \\ (u8) [7] = 92
349349 \\ (u8) [8] = 0
350350 \\}
351 \\(lldb) frame variable --show-types --format character strings.slice
351 \\(lldb) frame variable --show-types --format character -- strings.slice
352352 \\([:0]const u8) strings.slice = len=9 {
353353 \\ (u8) [0] = 's'
354354 \\ (u8) [1] = 'l'
......@@ -360,7 +360,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
360360 \\ (u8) [7] = '\\'
361361 \\ (u8) [8] = '\x00'
362362 \\}
363 \\(lldb) frame variable --show-types --format c-string strings
363 \\(lldb) frame variable --show-types --format c-string -- strings
364364 \\(root.strings.Strings) strings = {
365365 \\ ([*c]const u8) c_ptr = "c_ptr\x07\x08\t"
366366 \\ ([*:0]const u8) many_ptr = "many_ptr\n\x0b\x0c"
......@@ -411,11 +411,28 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
411411 },
412412 \\breakpoint set --file enums.zig --source-pattern-regexp '_ = enums;'
413413 \\process launch
414 \\frame variable --show-types enums
414 \\expression --show-types -- Enums
415 \\frame variable --show-types -- enums
415416 \\breakpoint delete --force 1
416417 ,
417418 &.{
418 \\(lldb) frame variable --show-types enums
419 \\(lldb) expression --show-types -- Enums
420 \\(type) Enums = struct {
421 \\ (type) Zero = enum {}
422 \\ (type) One = enum {
423 \\ (root.enums.Enums.One) first = .first
424 \\ }
425 \\ (type) Two = enum {
426 \\ (root.enums.Enums.Two) first = .first
427 \\ (root.enums.Enums.Two) second = .second
428 \\ }
429 \\ (type) Three = enum {
430 \\ (root.enums.Enums.Three) first = .first
431 \\ (root.enums.Enums.Three) second = .second
432 \\ (root.enums.Enums.Three) third = .third
433 \\ }
434 \\}
435 \\(lldb) frame variable --show-types -- enums
419436 \\(root.enums.Enums) enums = {
420437 \\ (root.enums.Enums.Zero) zero = @enumFromInt(13)
421438 \\ (root.enums.Enums.One) one = .first
......@@ -434,12 +451,17 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
434451 .path = "errors.zig",
435452 .source =
436453 \\const Errors = struct {
437 \\ one: error{One} = error.One,
438 \\ two: error{One,Two} = error.Two,
439 \\ three: error{One,Two,Three} = error.Three,
454 \\ const Zero = error{};
455 \\ const One = Zero || error{One};
456 \\ const Two = One || error{Two};
457 \\ const Three = Two || error{Three};
458 \\
459 \\ one: One = error.One,
460 \\ two: Two = error.Two,
461 \\ three: Three = error.Three,
440462 \\ any: anyerror = error.Any,
441463 \\ any_void: anyerror!void = error.NotVoid,
442 \\ any_u32: error{One}!u32 = 42,
464 \\ any_u32: One!u32 = 42,
443465 \\};
444466 \\fn testErrors(errors: Errors) void {
445467 \\ _ = errors;
......@@ -453,11 +475,28 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
453475 },
454476 \\breakpoint set --file errors.zig --source-pattern-regexp '_ = errors;'
455477 \\process launch
456 \\frame variable --show-types errors
478 \\expression --show-types -- Errors
479 \\frame variable --show-types -- errors
457480 \\breakpoint delete --force 1
458481 ,
459482 &.{
460 \\(lldb) frame variable --show-types errors
483 \\(lldb) expression --show-types -- Errors
484 \\(type) Errors = struct {
485 \\ (type) Zero = error {}
486 \\ (type) One = error {
487 \\ (error{One}) One = error.One
488 \\ }
489 \\ (type) Two = error {
490 \\ (error{One,Two}) One = error.One
491 \\ (error{One,Two}) Two = error.Two
492 \\ }
493 \\ (type) Three = error {
494 \\ (error{One,Two,Three}) One = error.One
495 \\ (error{One,Two,Three}) Two = error.Two
496 \\ (error{One,Two,Three}) Three = error.Three
497 \\ }
498 \\}
499 \\(lldb) frame variable --show-types -- errors
461500 \\(root.errors.Errors) errors = {
462501 \\ (error{One}) one = error.One
463502 \\ (error{One,Two}) two = error.Two
......@@ -496,23 +535,23 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
496535 },
497536 \\breakpoint set --file optionals.zig --source-pattern-regexp 'maybe_u32 = 123;'
498537 \\process launch
499 \\frame variable null_u32 maybe_u32 nonnull_u32
538 \\frame variable -- null_u32 maybe_u32 nonnull_u32
500539 \\breakpoint delete --force 1
501540 \\
502 \\breakpoint set --file optionals.zig --source-pattern-regexp '_ = .{ &null_u32, &nonnull_u32 };'
541 \\breakpoint set --file optionals.zig --source-pattern-regexp '_ = \.{ &null_u32, &nonnull_u32 };'
503542 \\process continue
504 \\frame variable --show-types null_u32 maybe_u32 nonnull_u32
543 \\frame variable --show-types -- null_u32 maybe_u32 nonnull_u32
505544 \\breakpoint delete --force 2
506545 ,
507546 &.{
508 \\(lldb) frame variable null_u32 maybe_u32 nonnull_u32
547 \\(lldb) frame variable -- null_u32 maybe_u32 nonnull_u32
509548 \\(?u32) null_u32 = null
510549 \\(?u32) maybe_u32 = null
511550 \\(?u32) nonnull_u32 = (nonnull_u32.? = 456)
512551 \\(lldb) breakpoint delete --force 1
513552 \\1 breakpoints deleted; 0 breakpoint locations disabled.
514553 ,
515 \\(lldb) frame variable --show-types null_u32 maybe_u32 nonnull_u32
554 \\(lldb) frame variable --show-types -- null_u32 maybe_u32 nonnull_u32
516555 \\(?u32) null_u32 = null
517556 \\(?u32) maybe_u32 = {
518557 \\ (u32) maybe_u32.? = 123
......@@ -565,11 +604,31 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
565604 },
566605 \\breakpoint set --file unions.zig --source-pattern-regexp '_ = unions;'
567606 \\process launch
568 \\frame variable --show-types unions
607 \\expression --show-types -- Unions
608 \\frame variable --show-types -- unions
569609 \\breakpoint delete --force 1
570610 ,
571611 &.{
572 \\(lldb) frame variable --show-types unions
612 \\(lldb) expression --show-types -- Unions
613 \\(type) Unions = struct {
614 \\ (type) Untagged = union {}
615 \\ (type) SafetyTagged = union(enum) {
616 \\ (@typeInfo(unions.Unions.SafetyTagged).@"union".tag_type.?) void = .void
617 \\ (@typeInfo(unions.Unions.SafetyTagged).@"union".tag_type.?) en = .en
618 \\ (@typeInfo(unions.Unions.SafetyTagged).@"union".tag_type.?) eu = .eu
619 \\ }
620 \\ (type) Enum = enum {
621 \\ (root.unions.Unions.Enum) first = .first
622 \\ (root.unions.Unions.Enum) second = .second
623 \\ (root.unions.Unions.Enum) third = .third
624 \\ }
625 \\ (type) Tagged = union(enum) {
626 \\ (@typeInfo(unions.Unions.Tagged).@"union".tag_type.?) void = .void
627 \\ (@typeInfo(unions.Unions.Tagged).@"union".tag_type.?) en = .en
628 \\ (@typeInfo(unions.Unions.Tagged).@"union".tag_type.?) eu = .eu
629 \\ }
630 \\}
631 \\(lldb) frame variable --show-types -- unions
573632 \\(root.unions.Unions) unions = {
574633 \\ (root.unions.Unions.Untagged) untagged = {
575634 \\ (u32) u32 = 3217031168
......@@ -635,17 +694,17 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
635694 },
636695 \\breakpoint set --file storage.zig --source-pattern-regexp 'local_var = local_var;'
637696 \\process launch
638 \\target variable --show-types --format hex global_const global_var global_threadlocal1 global_threadlocal2
639 \\frame variable --show-types --format hex param1 param2 param3 param4 param5 param6 param7 param8 local_comptime_val local_comptime_ptr.0 local_const local_var
697 \\target variable --show-types --format hex -- global_const global_var global_threadlocal1 global_threadlocal2
698 \\frame variable --show-types --format hex -- param1 param2 param3 param4 param5 param6 param7 param8 local_comptime_val local_comptime_ptr.0 local_const local_var
640699 \\breakpoint delete --force 1
641700 ,
642701 &.{
643 \\(lldb) target variable --show-types --format hex global_const global_var global_threadlocal1 global_threadlocal2
702 \\(lldb) target variable --show-types --format hex -- global_const global_var global_threadlocal1 global_threadlocal2
644703 \\(u64) global_const = 0x19e50dc8d6002077
645704 \\(u64) global_var = 0xcc423cec08622e32
646705 \\(u64) global_threadlocal1 = 0xb4d643528c042121
647706 \\(u64) global_threadlocal2 = 0x43faea1cf5ad7a22
648 \\(lldb) frame variable --show-types --format hex param1 param2 param3 param4 param5 param6 param7 param8 local_comptime_val local_comptime_ptr.0 local_const local_var
707 \\(lldb) frame variable --show-types --format hex -- param1 param2 param3 param4 param5 param6 param7 param8 local_comptime_val local_comptime_ptr.0 local_const local_var
649708 \\(u64) param1 = 0x6a607e08125c7e00
650709 \\(u64) param2 = 0x98944cb2a45a8b51
651710 \\(u64) param3 = 0xa320cf10601ee6fb
......@@ -1240,31 +1299,536 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
12401299 \\ x = fabsf(x);
12411300 \\ _ = &x;
12421301 \\}
1302 \\
12431303 ,
12441304 },
12451305 },
12461306 \\breakpoint set --file main.zig --source-pattern-regexp 'x = fabsf\(x\);'
12471307 \\process launch
1248 \\frame variable x
1308 \\frame variable -- x
12491309 \\breakpoint delete --force 1
12501310 \\
12511311 \\breakpoint set --file main.zig --source-pattern-regexp '_ = &x;'
12521312 \\process continue
1253 \\frame variable x
1313 \\frame variable -- x
12541314 \\breakpoint delete --force 2
12551315 ,
12561316 &.{
1257 \\(lldb) frame variable x
1317 \\(lldb) frame variable -- x
12581318 \\(f32) x = -1234.5
12591319 \\(lldb) breakpoint delete --force 1
12601320 \\1 breakpoints deleted; 0 breakpoint locations disabled.
12611321 ,
1262 \\(lldb) frame variable x
1322 \\(lldb) frame variable -- x
12631323 \\(f32) x = 1234.5
12641324 \\(lldb) breakpoint delete --force 2
12651325 \\1 breakpoints deleted; 0 breakpoint locations disabled.
12661326 },
12671327 );
1328 db.addLldbTest(
1329 "hash_map",
1330 target,
1331 &.{
1332 .{
1333 .path = "main.zig",
1334 .source =
1335 \\const std = @import("std");
1336 \\const Context = struct {
1337 \\ pub fn hash(_: Context, key: u32) Map.Hash {
1338 \\ return key;
1339 \\ }
1340 \\ pub fn eql(_: Context, lhs: u32, rhs: u32) bool {
1341 \\ return lhs == rhs;
1342 \\ }
1343 \\};
1344 \\const Map = std.HashMap(u32, u32, Context, 63);
1345 \\fn testHashMap(map: Map) void {
1346 \\ _ = map;
1347 \\}
1348 \\pub fn main() !void {
1349 \\ var map = Map.init(std.heap.page_allocator);
1350 \\ defer map.deinit();
1351 \\ try map.ensureTotalCapacity(10);
1352 \\ map.putAssumeCapacity(0, 1);
1353 \\ map.putAssumeCapacity(2, 3);
1354 \\ map.putAssumeCapacity(4, 5);
1355 \\ map.putAssumeCapacity(6, 7);
1356 \\ map.putAssumeCapacity(8, 9);
1357 \\
1358 \\ testHashMap(map);
1359 \\}
1360 \\
1361 ,
1362 },
1363 },
1364 \\breakpoint set --file main.zig --source-pattern-regexp '_ = map;'
1365 \\process launch
1366 \\frame variable --show-types -- map.unmanaged
1367 \\breakpoint delete --force 1
1368 ,
1369 &.{
1370 \\(lldb) frame variable --show-types -- map.unmanaged
1371 \\(std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63)) map.unmanaged = len=5 capacity=16 {
1372 \\ (std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63).KV) [0] = {
1373 \\ (u32) key = 0
1374 \\ (u32) value = 1
1375 \\ }
1376 \\ (std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63).KV) [1] = {
1377 \\ (u32) key = 2
1378 \\ (u32) value = 3
1379 \\ }
1380 \\ (std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63).KV) [2] = {
1381 \\ (u32) key = 4
1382 \\ (u32) value = 5
1383 \\ }
1384 \\ (std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63).KV) [3] = {
1385 \\ (u32) key = 6
1386 \\ (u32) value = 7
1387 \\ }
1388 \\ (std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63).KV) [4] = {
1389 \\ (u32) key = 8
1390 \\ (u32) value = 9
1391 \\ }
1392 \\}
1393 \\(lldb) breakpoint delete --force 1
1394 \\1 breakpoints deleted; 0 breakpoint locations disabled.
1395 },
1396 );
1397 db.addLldbTest(
1398 "multi_array_list",
1399 target,
1400 &.{
1401 .{
1402 .path = "main.zig",
1403 .source =
1404 \\const std = @import("std");
1405 \\const Elem0 = struct { u32, u8, u16 };
1406 \\const Elem1 = struct { a: u32, b: u8, c: u16 };
1407 \\fn testMultiArrayList(
1408 \\ list0: std.MultiArrayList(Elem0),
1409 \\ slice0: std.MultiArrayList(Elem0).Slice,
1410 \\ list1: std.MultiArrayList(Elem1),
1411 \\ slice1: std.MultiArrayList(Elem1).Slice,
1412 \\) void {
1413 \\ _ = .{ list0, slice0, list1, slice1 };
1414 \\}
1415 \\pub fn main() !void {
1416 \\ var list0: std.MultiArrayList(Elem0) = .{};
1417 \\ defer list0.deinit(std.heap.page_allocator);
1418 \\ try list0.setCapacity(std.heap.page_allocator, 8);
1419 \\ list0.appendAssumeCapacity(.{ 1, 2, 3 });
1420 \\ list0.appendAssumeCapacity(.{ 4, 5, 6 });
1421 \\ list0.appendAssumeCapacity(.{ 7, 8, 9 });
1422 \\ const slice0 = list0.slice();
1423 \\
1424 \\ var list1: std.MultiArrayList(Elem1) = .{};
1425 \\ defer list1.deinit(std.heap.page_allocator);
1426 \\ try list1.setCapacity(std.heap.page_allocator, 12);
1427 \\ list1.appendAssumeCapacity(.{ .a = 1, .b = 2, .c = 3 });
1428 \\ list1.appendAssumeCapacity(.{ .a = 4, .b = 5, .c = 6 });
1429 \\ list1.appendAssumeCapacity(.{ .a = 7, .b = 8, .c = 9 });
1430 \\ const slice1 = list1.slice();
1431 \\
1432 \\ testMultiArrayList(list0, slice0, list1, slice1);
1433 \\}
1434 \\
1435 ,
1436 },
1437 },
1438 \\breakpoint set --file main.zig --source-pattern-regexp '_ = \.{ list0, slice0, list1, slice1 };'
1439 \\process launch
1440 \\frame variable --show-types -- list0 list0.len list0.capacity list0[0] list0[1] list0[2] list0.0 list0.1 list0.2
1441 \\frame variable --show-types -- slice0 slice0.len slice0.capacity slice0[0] slice0[1] slice0[2] slice0.0 slice0.1 slice0.2
1442 \\frame variable --show-types -- list1 list1.len list1.capacity list1[0] list1[1] list1[2] list1.a list1.b list1.c
1443 \\frame variable --show-types -- slice1 slice1.len slice1.capacity slice1[0] slice1[1] slice1[2] slice1.a slice1.b slice1.c
1444 \\breakpoint delete --force 1
1445 ,
1446 &.{
1447 \\(lldb) frame variable --show-types -- list0 list0.len list0.capacity list0[0] list0[1] list0[2] list0.0 list0.1 list0.2
1448 \\(std.multi_array_list.MultiArrayList(main.Elem0)) list0 = len=3 capacity=8 {
1449 \\ (root.main.Elem0) [0] = {
1450 \\ (u32) 0 = 1
1451 \\ (u8) 1 = 2
1452 \\ (u16) 2 = 3
1453 \\ }
1454 \\ (root.main.Elem0) [1] = {
1455 \\ (u32) 0 = 4
1456 \\ (u8) 1 = 5
1457 \\ (u16) 2 = 6
1458 \\ }
1459 \\ (root.main.Elem0) [2] = {
1460 \\ (u32) 0 = 7
1461 \\ (u8) 1 = 8
1462 \\ (u16) 2 = 9
1463 \\ }
1464 \\}
1465 \\(usize) list0.len = 3
1466 \\(usize) list0.capacity = 8
1467 \\(root.main.Elem0) list0[0] = {
1468 \\ (u32) 0 = 1
1469 \\ (u8) 1 = 2
1470 \\ (u16) 2 = 3
1471 \\}
1472 \\(root.main.Elem0) list0[1] = {
1473 \\ (u32) 0 = 4
1474 \\ (u8) 1 = 5
1475 \\ (u16) 2 = 6
1476 \\}
1477 \\(root.main.Elem0) list0[2] = {
1478 \\ (u32) 0 = 7
1479 \\ (u8) 1 = 8
1480 \\ (u16) 2 = 9
1481 \\}
1482 \\([3]u32) list0.0 = {
1483 \\ (u32) [0] = 1
1484 \\ (u32) [1] = 4
1485 \\ (u32) [2] = 7
1486 \\}
1487 \\([3]u8) list0.1 = {
1488 \\ (u8) [0] = 2
1489 \\ (u8) [1] = 5
1490 \\ (u8) [2] = 8
1491 \\}
1492 \\([3]u16) list0.2 = {
1493 \\ (u16) [0] = 3
1494 \\ (u16) [1] = 6
1495 \\ (u16) [2] = 9
1496 \\}
1497 \\(lldb) frame variable --show-types -- slice0 slice0.len slice0.capacity slice0[0] slice0[1] slice0[2] slice0.0 slice0.1 slice0.2
1498 \\(std.multi_array_list.MultiArrayList(main.Elem0).Slice) slice0 = len=3 capacity=8 {
1499 \\ (root.main.Elem0) [0] = {
1500 \\ (u32) 0 = 1
1501 \\ (u8) 1 = 2
1502 \\ (u16) 2 = 3
1503 \\ }
1504 \\ (root.main.Elem0) [1] = {
1505 \\ (u32) 0 = 4
1506 \\ (u8) 1 = 5
1507 \\ (u16) 2 = 6
1508 \\ }
1509 \\ (root.main.Elem0) [2] = {
1510 \\ (u32) 0 = 7
1511 \\ (u8) 1 = 8
1512 \\ (u16) 2 = 9
1513 \\ }
1514 \\}
1515 \\(usize) slice0.len = 3
1516 \\(usize) slice0.capacity = 8
1517 \\(root.main.Elem0) slice0[0] = {
1518 \\ (u32) 0 = 1
1519 \\ (u8) 1 = 2
1520 \\ (u16) 2 = 3
1521 \\}
1522 \\(root.main.Elem0) slice0[1] = {
1523 \\ (u32) 0 = 4
1524 \\ (u8) 1 = 5
1525 \\ (u16) 2 = 6
1526 \\}
1527 \\(root.main.Elem0) slice0[2] = {
1528 \\ (u32) 0 = 7
1529 \\ (u8) 1 = 8
1530 \\ (u16) 2 = 9
1531 \\}
1532 \\([3]u32) slice0.0 = {
1533 \\ (u32) [0] = 1
1534 \\ (u32) [1] = 4
1535 \\ (u32) [2] = 7
1536 \\}
1537 \\([3]u8) slice0.1 = {
1538 \\ (u8) [0] = 2
1539 \\ (u8) [1] = 5
1540 \\ (u8) [2] = 8
1541 \\}
1542 \\([3]u16) slice0.2 = {
1543 \\ (u16) [0] = 3
1544 \\ (u16) [1] = 6
1545 \\ (u16) [2] = 9
1546 \\}
1547 \\(lldb) frame variable --show-types -- list1 list1.len list1.capacity list1[0] list1[1] list1[2] list1.a list1.b list1.c
1548 \\(std.multi_array_list.MultiArrayList(main.Elem1)) list1 = len=3 capacity=12 {
1549 \\ (root.main.Elem1) [0] = {
1550 \\ (u32) a = 1
1551 \\ (u8) b = 2
1552 \\ (u16) c = 3
1553 \\ }
1554 \\ (root.main.Elem1) [1] = {
1555 \\ (u32) a = 4
1556 \\ (u8) b = 5
1557 \\ (u16) c = 6
1558 \\ }
1559 \\ (root.main.Elem1) [2] = {
1560 \\ (u32) a = 7
1561 \\ (u8) b = 8
1562 \\ (u16) c = 9
1563 \\ }
1564 \\}
1565 \\(usize) list1.len = 3
1566 \\(usize) list1.capacity = 12
1567 \\(root.main.Elem1) list1[0] = {
1568 \\ (u32) a = 1
1569 \\ (u8) b = 2
1570 \\ (u16) c = 3
1571 \\}
1572 \\(root.main.Elem1) list1[1] = {
1573 \\ (u32) a = 4
1574 \\ (u8) b = 5
1575 \\ (u16) c = 6
1576 \\}
1577 \\(root.main.Elem1) list1[2] = {
1578 \\ (u32) a = 7
1579 \\ (u8) b = 8
1580 \\ (u16) c = 9
1581 \\}
1582 \\([3]u32) list1.a = {
1583 \\ (u32) [0] = 1
1584 \\ (u32) [1] = 4
1585 \\ (u32) [2] = 7
1586 \\}
1587 \\([3]u8) list1.b = {
1588 \\ (u8) [0] = 2
1589 \\ (u8) [1] = 5
1590 \\ (u8) [2] = 8
1591 \\}
1592 \\([3]u16) list1.c = {
1593 \\ (u16) [0] = 3
1594 \\ (u16) [1] = 6
1595 \\ (u16) [2] = 9
1596 \\}
1597 \\(lldb) frame variable --show-types -- slice1 slice1.len slice1.capacity slice1[0] slice1[1] slice1[2] slice1.a slice1.b slice1.c
1598 \\(std.multi_array_list.MultiArrayList(main.Elem1).Slice) slice1 = len=3 capacity=12 {
1599 \\ (root.main.Elem1) [0] = {
1600 \\ (u32) a = 1
1601 \\ (u8) b = 2
1602 \\ (u16) c = 3
1603 \\ }
1604 \\ (root.main.Elem1) [1] = {
1605 \\ (u32) a = 4
1606 \\ (u8) b = 5
1607 \\ (u16) c = 6
1608 \\ }
1609 \\ (root.main.Elem1) [2] = {
1610 \\ (u32) a = 7
1611 \\ (u8) b = 8
1612 \\ (u16) c = 9
1613 \\ }
1614 \\}
1615 \\(usize) slice1.len = 3
1616 \\(usize) slice1.capacity = 12
1617 \\(root.main.Elem1) slice1[0] = {
1618 \\ (u32) a = 1
1619 \\ (u8) b = 2
1620 \\ (u16) c = 3
1621 \\}
1622 \\(root.main.Elem1) slice1[1] = {
1623 \\ (u32) a = 4
1624 \\ (u8) b = 5
1625 \\ (u16) c = 6
1626 \\}
1627 \\(root.main.Elem1) slice1[2] = {
1628 \\ (u32) a = 7
1629 \\ (u8) b = 8
1630 \\ (u16) c = 9
1631 \\}
1632 \\([3]u32) slice1.a = {
1633 \\ (u32) [0] = 1
1634 \\ (u32) [1] = 4
1635 \\ (u32) [2] = 7
1636 \\}
1637 \\([3]u8) slice1.b = {
1638 \\ (u8) [0] = 2
1639 \\ (u8) [1] = 5
1640 \\ (u8) [2] = 8
1641 \\}
1642 \\([3]u16) slice1.c = {
1643 \\ (u16) [0] = 3
1644 \\ (u16) [1] = 6
1645 \\ (u16) [2] = 9
1646 \\}
1647 \\(lldb) breakpoint delete --force 1
1648 \\1 breakpoints deleted; 0 breakpoint locations disabled.
1649 },
1650 );
1651 db.addLldbTest(
1652 "segmented_list",
1653 target,
1654 &.{
1655 .{
1656 .path = "main.zig",
1657 .source =
1658 \\const std = @import("std");
1659 \\fn testSegmentedList() void {}
1660 \\pub fn main() !void {
1661 \\ var list0: std.SegmentedList(usize, 0) = .{};
1662 \\ defer list0.deinit(std.heap.page_allocator);
1663 \\
1664 \\ var list1: std.SegmentedList(usize, 1) = .{};
1665 \\ defer list1.deinit(std.heap.page_allocator);
1666 \\
1667 \\ var list2: std.SegmentedList(usize, 2) = .{};
1668 \\ defer list2.deinit(std.heap.page_allocator);
1669 \\
1670 \\ var list4: std.SegmentedList(usize, 4) = .{};
1671 \\ defer list4.deinit(std.heap.page_allocator);
1672 \\
1673 \\ for (0..32) |i| {
1674 \\ try list0.append(std.heap.page_allocator, i);
1675 \\ try list1.append(std.heap.page_allocator, i);
1676 \\ try list2.append(std.heap.page_allocator, i);
1677 \\ try list4.append(std.heap.page_allocator, i);
1678 \\ }
1679 \\ testSegmentedList();
1680 \\}
1681 \\
1682 ,
1683 },
1684 },
1685 \\breakpoint set --file main.zig --source-pattern-regexp 'testSegmentedList\(\);'
1686 \\process launch
1687 \\frame variable -- list0 list1 list2 list4
1688 \\breakpoint delete --force 1
1689 ,
1690 &.{
1691 \\(lldb) frame variable -- list0 list1 list2 list4
1692 \\(std.segmented_list.SegmentedList(usize,0)) list0 = len=32 {
1693 \\ [0] = 0
1694 \\ [1] = 1
1695 \\ [2] = 2
1696 \\ [3] = 3
1697 \\ [4] = 4
1698 \\ [5] = 5
1699 \\ [6] = 6
1700 \\ [7] = 7
1701 \\ [8] = 8
1702 \\ [9] = 9
1703 \\ [10] = 10
1704 \\ [11] = 11
1705 \\ [12] = 12
1706 \\ [13] = 13
1707 \\ [14] = 14
1708 \\ [15] = 15
1709 \\ [16] = 16
1710 \\ [17] = 17
1711 \\ [18] = 18
1712 \\ [19] = 19
1713 \\ [20] = 20
1714 \\ [21] = 21
1715 \\ [22] = 22
1716 \\ [23] = 23
1717 \\ [24] = 24
1718 \\ [25] = 25
1719 \\ [26] = 26
1720 \\ [27] = 27
1721 \\ [28] = 28
1722 \\ [29] = 29
1723 \\ [30] = 30
1724 \\ [31] = 31
1725 \\}
1726 \\(std.segmented_list.SegmentedList(usize,1)) list1 = len=32 {
1727 \\ [0] = 0
1728 \\ [1] = 1
1729 \\ [2] = 2
1730 \\ [3] = 3
1731 \\ [4] = 4
1732 \\ [5] = 5
1733 \\ [6] = 6
1734 \\ [7] = 7
1735 \\ [8] = 8
1736 \\ [9] = 9
1737 \\ [10] = 10
1738 \\ [11] = 11
1739 \\ [12] = 12
1740 \\ [13] = 13
1741 \\ [14] = 14
1742 \\ [15] = 15
1743 \\ [16] = 16
1744 \\ [17] = 17
1745 \\ [18] = 18
1746 \\ [19] = 19
1747 \\ [20] = 20
1748 \\ [21] = 21
1749 \\ [22] = 22
1750 \\ [23] = 23
1751 \\ [24] = 24
1752 \\ [25] = 25
1753 \\ [26] = 26
1754 \\ [27] = 27
1755 \\ [28] = 28
1756 \\ [29] = 29
1757 \\ [30] = 30
1758 \\ [31] = 31
1759 \\}
1760 \\(std.segmented_list.SegmentedList(usize,2)) list2 = len=32 {
1761 \\ [0] = 0
1762 \\ [1] = 1
1763 \\ [2] = 2
1764 \\ [3] = 3
1765 \\ [4] = 4
1766 \\ [5] = 5
1767 \\ [6] = 6
1768 \\ [7] = 7
1769 \\ [8] = 8
1770 \\ [9] = 9
1771 \\ [10] = 10
1772 \\ [11] = 11
1773 \\ [12] = 12
1774 \\ [13] = 13
1775 \\ [14] = 14
1776 \\ [15] = 15
1777 \\ [16] = 16
1778 \\ [17] = 17
1779 \\ [18] = 18
1780 \\ [19] = 19
1781 \\ [20] = 20
1782 \\ [21] = 21
1783 \\ [22] = 22
1784 \\ [23] = 23
1785 \\ [24] = 24
1786 \\ [25] = 25
1787 \\ [26] = 26
1788 \\ [27] = 27
1789 \\ [28] = 28
1790 \\ [29] = 29
1791 \\ [30] = 30
1792 \\ [31] = 31
1793 \\}
1794 \\(std.segmented_list.SegmentedList(usize,4)) list4 = len=32 {
1795 \\ [0] = 0
1796 \\ [1] = 1
1797 \\ [2] = 2
1798 \\ [3] = 3
1799 \\ [4] = 4
1800 \\ [5] = 5
1801 \\ [6] = 6
1802 \\ [7] = 7
1803 \\ [8] = 8
1804 \\ [9] = 9
1805 \\ [10] = 10
1806 \\ [11] = 11
1807 \\ [12] = 12
1808 \\ [13] = 13
1809 \\ [14] = 14
1810 \\ [15] = 15
1811 \\ [16] = 16
1812 \\ [17] = 17
1813 \\ [18] = 18
1814 \\ [19] = 19
1815 \\ [20] = 20
1816 \\ [21] = 21
1817 \\ [22] = 22
1818 \\ [23] = 23
1819 \\ [24] = 24
1820 \\ [25] = 25
1821 \\ [26] = 26
1822 \\ [27] = 27
1823 \\ [28] = 28
1824 \\ [29] = 29
1825 \\ [30] = 30
1826 \\ [31] = 31
1827 \\}
1828 \\(lldb) breakpoint delete --force 1
1829 \\1 breakpoints deleted; 0 breakpoint locations disabled.
1830 },
1831 );
12681832}
12691833
12701834const File = struct { import: ?[]const u8 = null, path: []const u8, source: []const u8 };