authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-09-09 00:41:27+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-09-09 00:41:27+02:00
log85e44dbae2af3ce6d71210f6d91014ca09b9597a
treed7c57d7e845e44b687d583806e61458259eba5f1
parent893c0c50b2bfe3b1ba3060e39902de43471ad064
parent48b8eb249d7e73109c8603bd5ebc06665d9b1a2f

Merge pull request 'Dwarf2: finish debug info' (#36789) from jacobly/dwarf2 into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36789 Reviewed-by: Andrew Kelley <andrew@ziglang.org>

10 files changed, 2577 insertions(+), 1250 deletions(-)

src/Zcu.zig+5-5
...@@ -2754,7 +2754,7 @@ pub const LazySrcLoc = struct {...@@ -2754,7 +2754,7 @@ pub const LazySrcLoc = struct {
2754 if (zir_inst == .main_struct_inst) return .{ file, .root };2754 if (zir_inst == .main_struct_inst) return .{ file, .root };
27552755
2756 // Otherwise, make sure ZIR is loaded.2756 // Otherwise, make sure ZIR is loaded.
2757 const zir = file.zir.?;2757 const zir = &file.zir.?;
27582758
2759 const inst = zir.instructions.get(@backingInt(zir_inst));2759 const inst = zir.instructions.get(@backingInt(zir_inst));
2760 const base_node: Ast.Node.Index = switch (inst.tag) {2760 const base_node: Ast.Node.Index = switch (inst.tag) {
...@@ -3045,7 +3045,7 @@ pub fn saveZirCache(...@@ -3045,7 +3045,7 @@ pub fn saveZirCache(
3045 gpa: Allocator,3045 gpa: Allocator,
3046 cache_file_writer: *Io.File.Writer,3046 cache_file_writer: *Io.File.Writer,
3047 stat: Io.File.Stat,3047 stat: Io.File.Stat,
3048 zir: Zir,3048 zir: *const Zir,
3049) (Io.File.Writer.Error || Allocator.Error)!void {3049) (Io.File.Writer.Error || Allocator.Error)!void {
3050 const safety_buffer = if (data_has_safety_tag)3050 const safety_buffer = if (data_has_safety_tag)
3051 try gpa.alloc([8]u8, zir.instructions.len)3051 try gpa.alloc([8]u8, zir.instructions.len)
...@@ -3085,7 +3085,7 @@ pub fn saveZirCache(...@@ -3085,7 +3085,7 @@ pub fn saveZirCache(
3085 };3085 };
3086}3086}
30873087
3088pub fn saveZoirCache(cache_file_writer: *Io.File.Writer, stat: Io.File.Stat, zoir: Zoir) Io.File.Writer.Error!void {3088pub fn saveZoirCache(cache_file_writer: *Io.File.Writer, stat: Io.File.Stat, zoir: *const Zoir) Io.File.Writer.Error!void {
3089 const header: Zoir.Header = .{3089 const header: Zoir.Header = .{
3090 .nodes_len = @intCast(zoir.nodes.len),3090 .nodes_len = @intCast(zoir.nodes.len),
3091 .extra_len = @intCast(zoir.extra.len),3091 .extra_len = @intCast(zoir.extra.len),
...@@ -3399,8 +3399,8 @@ pub fn flushRetryableFailures(zcu: *Zcu) !void {...@@ -3399,8 +3399,8 @@ pub fn flushRetryableFailures(zcu: *Zcu) !void {
33993399
3400pub fn mapOldZirToNew(3400pub fn mapOldZirToNew(
3401 gpa: Allocator,3401 gpa: Allocator,
3402 old_zir: Zir,3402 old_zir: *const Zir,
3403 new_zir: Zir,3403 new_zir: *const Zir,
3404 inst_map: *std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index),3404 inst_map: *std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index),
3405) Allocator.Error!void {3405) Allocator.Error!void {
3406 // Contain ZIR indexes of namespace declaration instructions, e.g. struct_decl, union_decl, etc.3406 // Contain ZIR indexes of namespace declaration instructions, e.g. struct_decl, union_decl, etc.
src/Zcu/PerThread.zig+42-23
...@@ -389,17 +389,18 @@ fn workerUpdateFile(...@@ -389,17 +389,18 @@ fn workerUpdateFile(
389 // Discover all imports in the file. Imports of modules we ignore for now since we don't389 // Discover all imports in the file. Imports of modules we ignore for now since we don't
390 // know which module we're in, but imports of file paths might need us to queue up other390 // know which module we're in, but imports of file paths might need us to queue up other
391 // AstGen jobs.391 // AstGen jobs.
392 const imports_index = file.zir.?.extra[@backingInt(Zir.ExtraIndex.imports)];392 const zir = &file.zir.?;
393 const imports_index = zir.extra[@backingInt(Zir.ExtraIndex.imports)];
393 if (imports_index != 0) {394 if (imports_index != 0) {
394 const extra = file.zir.?.extraData(Zir.Inst.Imports, imports_index);395 const extra = zir.extraData(Zir.Inst.Imports, imports_index);
395 var import_i: u32 = 0;396 var import_i: u32 = 0;
396 var extra_index = extra.end;397 var extra_index = extra.end;
397398
398 while (import_i < extra.data.imports_len) : (import_i += 1) {399 while (import_i < extra.data.imports_len) : (import_i += 1) {
399 const item = file.zir.?.extraData(Zir.Inst.Imports.Item, extra_index);400 const item = zir.extraData(Zir.Inst.Imports.Item, extra_index);
400 extra_index = item.end;401 extra_index = item.end;
401402
402 const import_path = file.zir.?.nullTerminatedString(item.data.name);403 const import_path = zir.nullTerminatedString(item.data.name);
403404
404 if (active.pt.discoverImport(file.path, import_path)) |res| switch (res) {405 if (active.pt.discoverImport(file.path, import_path)) |res| switch (res) {
405 .module, .existing_file => {},406 .module, .existing_file => {},
...@@ -652,7 +653,7 @@ pub fn updateFile(...@@ -652,7 +653,7 @@ pub fn updateFile(
652 switch (file.getMode()) {653 switch (file.getMode()) {
653 .zig => {654 .zig => {
654 file.zir = try AstGen.generate(gpa, file.tree.?);655 file.zir = try AstGen.generate(gpa, file.tree.?);
655 Zcu.saveZirCache(gpa, &cache_file_writer, stat, file.zir.?) catch |err| switch (err) {656 Zcu.saveZirCache(gpa, &cache_file_writer, stat, &file.zir.?) catch |err| switch (err) {
656 error.OutOfMemory => |e| return e,657 error.OutOfMemory => |e| return e,
657 else => log.warn("unable to write cached ZIR code for {f} to {f}{s}: {t}", .{658 else => log.warn("unable to write cached ZIR code for {f} to {f}{s}: {t}", .{
658 file.path.fmt(comp), cache_directory, &hex_digest, err,659 file.path.fmt(comp), cache_directory, &hex_digest, err,
...@@ -661,7 +662,7 @@ pub fn updateFile(...@@ -661,7 +662,7 @@ pub fn updateFile(
661 },662 },
662 .zon => {663 .zon => {
663 file.zoir = try ZonGen.generate(gpa, file.tree.?, .{});664 file.zoir = try ZonGen.generate(gpa, file.tree.?, .{});
664 Zcu.saveZoirCache(&cache_file_writer, stat, file.zoir.?) catch |err| {665 Zcu.saveZoirCache(&cache_file_writer, stat, &file.zoir.?) catch |err| {
665 log.warn("unable to write cached ZOIR code for {f} to {f}{s}: {t}", .{666 log.warn("unable to write cached ZOIR code for {f} to {f}{s}: {t}", .{
666 file.path.fmt(comp), cache_directory, &hex_digest, err,667 file.path.fmt(comp), cache_directory, &hex_digest, err,
667 });668 });
...@@ -694,12 +695,13 @@ pub fn updateFile(...@@ -694,12 +695,13 @@ pub fn updateFile(
694695
695 switch (file.getMode()) {696 switch (file.getMode()) {
696 .zig => {697 .zig => {
697 if (file.zir.?.hasCompileErrors()) {698 const zir = &file.zir.?;
699 if (zir.hasCompileErrors()) {
698 comp.mutex.lockUncancelable(io);700 comp.mutex.lockUncancelable(io);
699 defer comp.mutex.unlock(io);701 defer comp.mutex.unlock(io);
700 try zcu.failed_files.putNoClobber(gpa, file_index, null);702 try zcu.failed_files.putNoClobber(gpa, file_index, null);
701 }703 }
702 if (file.zir.?.loweringFailed()) {704 if (zir.loweringFailed()) {
703 file.status = .astgen_failure;705 file.status = .astgen_failure;
704 } else {706 } else {
705 file.status = .success;707 file.status = .success;
...@@ -829,14 +831,14 @@ fn updateZirRefs(pt: Zcu.PerThread) (Io.Cancelable || Allocator.Error)!void {...@@ -829,14 +831,14 @@ fn updateZirRefs(pt: Zcu.PerThread) (Io.Cancelable || Allocator.Error)!void {
829 },831 },
830 }832 }
831 const old_zir = file.prev_zir orelse continue;833 const old_zir = file.prev_zir orelse continue;
832 const new_zir = file.zir.?;834 const new_zir = &file.zir.?;
833 const gop = try updated_files.getOrPut(gpa, file_index);835 const gop = try updated_files.getOrPut(gpa, file_index);
834 assert(!gop.found_existing);836 assert(!gop.found_existing);
835 gop.value_ptr.* = .{837 gop.value_ptr.* = .{
836 .file = file,838 .file = file,
837 .inst_map = .{},839 .inst_map = .{},
838 };840 };
839 try Zcu.mapOldZirToNew(gpa, old_zir.*, new_zir, &gop.value_ptr.inst_map);841 try Zcu.mapOldZirToNew(gpa, old_zir, new_zir, &gop.value_ptr.inst_map);
840 }842 }
841843
842 if (updated_files.count() == 0)844 if (updated_files.count() == 0)
...@@ -870,7 +872,7 @@ fn updateZirRefs(pt: Zcu.PerThread) (Io.Cancelable || Allocator.Error)!void {...@@ -870,7 +872,7 @@ fn updateZirRefs(pt: Zcu.PerThread) (Io.Cancelable || Allocator.Error)!void {
870 const old_tag = old_zir.instructions.items(.tag)[@backingInt(old_inst)];872 const old_tag = old_zir.instructions.items(.tag)[@backingInt(old_inst)];
871 const old_data = old_zir.instructions.items(.data)[@backingInt(old_inst)];873 const old_data = old_zir.instructions.items(.data)[@backingInt(old_inst)];
872874
873 const new_zir = file.zir.?;875 const new_zir = &file.zir.?;
874 const new_data = new_zir.instructions.items(.data)[@backingInt(new_inst)];876 const new_data = new_zir.instructions.items(.data)[@backingInt(new_inst)];
875877
876 debug_update_line_number: {878 debug_update_line_number: {
...@@ -2640,7 +2642,7 @@ fn computeAliveFiles(pt: Zcu.PerThread) Allocator.Error!bool {...@@ -2640,7 +2642,7 @@ fn computeAliveFiles(pt: Zcu.PerThread) Allocator.Error!bool {
26402642
2641 if (file.status != .success) continue; // ZIR not valid if there was a file failure2643 if (file.status != .success) continue; // ZIR not valid if there was a file failure
26422644
2643 const zir = file.zir.?;2645 const zir = &file.zir.?;
2644 const imports_index = zir.extra[@backingInt(Zir.ExtraIndex.imports)];2646 const imports_index = zir.extra[@backingInt(Zir.ExtraIndex.imports)];
2645 if (imports_index == 0) continue; // this Zig file has no imports2647 if (imports_index == 0) continue; // this Zig file has no imports
2646 const extra = zir.extraData(Zir.Inst.Imports, imports_index);2648 const extra = zir.extraData(Zir.Inst.Imports, imports_index);
...@@ -2655,7 +2657,13 @@ fn computeAliveFiles(pt: Zcu.PerThread) Allocator.Error!bool {...@@ -2655,7 +2657,13 @@ fn computeAliveFiles(pt: Zcu.PerThread) Allocator.Error!bool {
2655 // We've not necessarily generated builtin modules yet, so `doImport` could fail. Instead,2657 // We've not necessarily generated builtin modules yet, so `doImport` could fail. Instead,
2656 // create the module here. Then, since we know that `builtin.zig` doesn't have an error and2658 // create the module here. Then, since we know that `builtin.zig` doesn't have an error and
2657 // has no imports other than 'std', we can just continue onto the next import.2659 // has no imports other than 'std', we can just continue onto the next import.
2658 try pt.updateBuiltinModule(file.mod.?.getBuiltinOptions(comp.config));2660 const res = try pt.updateBuiltinModule(file.mod.?.getBuiltinOptions(comp.config));
2661 const gop = zcu.alive_files.getOrPutAssumeCapacity(res.file);
2662 if (!gop.found_existing) gop.value_ptr.* = .{ .import = .{
2663 .importer = file_idx,
2664 .tok = item.data.token,
2665 .module = res.module_root,
2666 } };
2659 continue;2667 continue;
2660 }2668 }
26612669
...@@ -2754,14 +2762,20 @@ fn computeAliveFiles(pt: Zcu.PerThread) Allocator.Error!bool {...@@ -2754,14 +2762,20 @@ fn computeAliveFiles(pt: Zcu.PerThread) Allocator.Error!bool {
2754/// up-to-date, setting a misc failure if updating it fails.2762/// up-to-date, setting a misc failure if updating it fails.
2755/// Asserts that the imported `builtin.zig` has no ZIR errors, and that it has only one2763/// Asserts that the imported `builtin.zig` has no ZIR errors, and that it has only one
2756/// import, which is 'std'.2764/// import, which is 'std'.
2757pub fn updateBuiltinModule(pt: Zcu.PerThread, opts: Builtin) Allocator.Error!void {2765fn updateBuiltinModule(pt: Zcu.PerThread, opts: Builtin) Allocator.Error!struct {
2766 file: Zcu.File.Index,
2767 module_root: *Module,
2768} {
2758 const zcu = pt.zcu;2769 const zcu = pt.zcu;
2759 const comp = zcu.comp;2770 const comp = zcu.comp;
2760 const gpa = comp.gpa;2771 const gpa = comp.gpa;
2761 const io = comp.io;2772 const io = comp.io;
27622773
2763 const gop = try zcu.builtin_modules.getOrPut(gpa, opts.hash());2774 const gop = try zcu.builtin_modules.getOrPut(gpa, opts.hash());
2764 if (gop.found_existing) return; // the `File` is up-to-date2775 if (gop.found_existing) return .{ // the `File` is up-to-date
2776 .file = zcu.module_roots.get(gop.value_ptr.*).?.unwrap().?,
2777 .module_root = gop.value_ptr.*,
2778 };
2765 errdefer _ = zcu.builtin_modules.pop();2779 errdefer _ = zcu.builtin_modules.pop();
27662780
2767 const mod: *Module = try .createBuiltin(comp.arena, opts, comp.dirs);2781 const mod: *Module = try .createBuiltin(comp.arena, opts, comp.dirs);
...@@ -2809,15 +2823,16 @@ pub fn updateBuiltinModule(pt: Zcu.PerThread, opts: Builtin) Allocator.Error!voi...@@ -2809,15 +2823,16 @@ pub fn updateBuiltinModule(pt: Zcu.PerThread, opts: Builtin) Allocator.Error!voi
2809 try opts.populateFile(gpa, file);2823 try opts.populateFile(gpa, file);
28102824
2811 assert(file.status == .success);2825 assert(file.status == .success);
2812 assert(!file.zir.?.hasCompileErrors());2826 const zir = &file.zir.?;
2827 assert(!zir.hasCompileErrors());
2813 {2828 {
2814 // Check that it has only one import, which is 'std'.2829 // Check that it has only one import, which is 'std'.
2815 const imports_idx = file.zir.?.extra[@backingInt(Zir.ExtraIndex.imports)];2830 const imports_idx = zir.extra[@backingInt(Zir.ExtraIndex.imports)];
2816 assert(imports_idx != 0); // there is an import2831 assert(imports_idx != 0); // there is an import
2817 const extra = file.zir.?.extraData(Zir.Inst.Imports, imports_idx);2832 const extra = zir.extraData(Zir.Inst.Imports, imports_idx);
2818 assert(extra.data.imports_len == 1); // there is exactly one import2833 assert(extra.data.imports_len == 1); // there is exactly one import
2819 const item = file.zir.?.extraData(Zir.Inst.Imports.Item, extra.end);2834 const item = zir.extraData(Zir.Inst.Imports.Item, extra.end);
2820 const import_path = file.zir.?.nullTerminatedString(item.data.name);2835 const import_path = zir.nullTerminatedString(item.data.name);
2821 assert(mem.eql(u8, import_path, "std")); // the single import is of 'std'2836 assert(mem.eql(u8, import_path, "std")); // the single import is of 'std'
2822 }2837 }
28232838
...@@ -2826,6 +2841,10 @@ pub fn updateBuiltinModule(pt: Zcu.PerThread, opts: Builtin) Allocator.Error!voi...@@ -2826,6 +2841,10 @@ pub fn updateBuiltinModule(pt: Zcu.PerThread, opts: Builtin) Allocator.Error!voi
2826 "unable to write '{f}': {s}",2841 "unable to write '{f}': {s}",
2827 .{ file.path.fmt(comp), @errorName(err) },2842 .{ file.path.fmt(comp), @errorName(err) },
2828 );2843 );
2844 return .{
2845 .file = file_index,
2846 .module_root = mod,
2847 };
2829}2848}
28302849
2831pub fn embedFile(2850pub fn embedFile(
...@@ -3137,7 +3156,7 @@ const ScanDeclIter = struct {...@@ -3137,7 +3156,7 @@ const ScanDeclIter = struct {
3137 const gpa = comp.gpa;3156 const gpa = comp.gpa;
3138 const io = comp.io;3157 const io = comp.io;
3139 const file = namespace.fileScope(zcu);3158 const file = namespace.fileScope(zcu);
3140 const zir = file.zir.?;3159 const zir = &file.zir.?;
3141 const ip = &zcu.intern_pool;3160 const ip = &zcu.intern_pool;
31423161
3143 const decl = zir.getDeclaration(decl_inst);3162 const decl = zir.getDeclaration(decl_inst);
...@@ -3572,11 +3591,11 @@ fn lockAndClearFileCompileError(pt: Zcu.PerThread, file_index: Zcu.File.Index, f...@@ -3572,11 +3591,11 @@ fn lockAndClearFileCompileError(pt: Zcu.PerThread, file_index: Zcu.File.Index, f
3572 .astgen_failure => true,3591 .astgen_failure => true,
3573 .success => switch (file.getMode()) {3592 .success => switch (file.getMode()) {
3574 .zig => has_error: {3593 .zig => has_error: {
3575 const zir = file.zir orelse break :has_error false;3594 const zir = &(file.zir orelse break :has_error false);
3576 break :has_error zir.hasCompileErrors();3595 break :has_error zir.hasCompileErrors();
3577 },3596 },
3578 .zon => has_error: {3597 .zon => has_error: {
3579 const zoir = file.zoir orelse break :has_error false;3598 const zoir = &(file.zoir orelse break :has_error false);
3580 break :has_error zoir.hasCompileErrors();3599 break :has_error zoir.hasCompileErrors();
3581 },3600 },
3582 },3601 },
src/codegen/x86_64/Emit.zig+18-13
...@@ -552,9 +552,9 @@ pub fn emitMir(emit: *Emit) Error!void {...@@ -552,9 +552,9 @@ pub fn emitMir(emit: *Emit) Error!void {
552 .pseudo_dbg_var_m,552 .pseudo_dbg_var_m,
553 => switch (emit.debug_output) {553 => switch (emit.debug_output) {
554 inline .dwarf, .dwarf2 => |dwarf, tag| {554 inline .dwarf, .dwarf2 => |dwarf, tag| {
555 const DwarfLoc = switch (tag) {555 const DwarfLoc, const addr_loc = switch (tag) {
556 .dwarf => link.File.Dwarf.Loc,556 .dwarf => .{ link.File.Dwarf.Loc, "addr_reloc" },
557 .dwarf2 => link.File.Dwarf2.Loc,557 .dwarf2 => .{ link.File.Dwarf2.Loc, "addrx_sym" },
558 .eh_frame, .none => comptime unreachable,558 .eh_frame, .none => comptime unreachable,
559 };559 };
560 var loc_buf: [2]DwarfLoc = undefined;560 var loc_buf: [2]DwarfLoc = undefined;
...@@ -597,16 +597,21 @@ pub fn emitMir(emit: *Emit) Error!void {...@@ -597,16 +597,21 @@ pub fn emitMir(emit: *Emit) Error!void {
597 .none => .{ .constu = 0 },597 .none => .{ .constu = 0 },
598 .reg => |reg| .{ .breg = reg.dwarfNum() },598 .reg => |reg| .{ .breg = reg.dwarfNum() },
599 .frame, .table, .rip_inst => unreachable,599 .frame, .table, .rip_inst => unreachable,
600 .nav => |nav| .{ .addr_reloc = try codegen.genNavRef(600 .nav => |nav| @unionInit(
601 emit.bin_file,601 DwarfLoc,
602 emit.pt,602 addr_loc,
603 nav,603 try codegen.genNavRef(emit.bin_file, emit.pt, nav),
604 ) },604 ),
605 .uav => |uav| .{ .addr_reloc = try emit.bin_file.lowerUav(605 .uav => |uav| @unionInit(
606 emit.pt,606 DwarfLoc,
607 uav.val,607 addr_loc,
608 Type.fromInterned(uav.orig_ty).ptrAlignment(emit.pt.zcu),608 try emit.bin_file.lowerUav(
609 ) },609 emit.pt,
610 uav.val,
611 Type.fromInterned(uav.orig_ty)
612 .ptrAlignment(emit.pt.zcu),
613 ),
614 ),
610 .lazy_sym, .extern_func => unreachable,615 .lazy_sym, .extern_func => unreachable,
611 };616 };
612 break :base &loc_buf[0];617 break :base &loc_buf[0];
src/codegen/x86_64/Mir.zig+1-1
...@@ -2009,7 +2009,7 @@ pub fn emit(...@@ -2009,7 +2009,7 @@ pub fn emit(
2009 .column = func.lbrace_column,2009 .column = func.lbrace_column,
2010 .is_stmt = switch (debug_output) {2010 .is_stmt = switch (debug_output) {
2011 .dwarf => |dwarf| dwarf.dwarf.debug_line.header.default_is_stmt,2011 .dwarf => |dwarf| dwarf.dwarf.debug_line.header.default_is_stmt,
2012 .dwarf2 => |dwarf| dwarf.wip_nav.dwarf.debug_line.header.default_is_stmt,2012 .dwarf2 => |dwarf| dwarf.wip_func.dwarf.debug_line.header.default_is_stmt,
2013 .eh_frame, .none => undefined,2013 .eh_frame, .none => undefined,
2014 },2014 },
2015 },2015 },
src/link.zig+2-2
...@@ -755,8 +755,8 @@ pub const File = struct {...@@ -755,8 +755,8 @@ pub const File = struct {
755755
756 pub const DebugInfoOutput = union(enum) {756 pub const DebugInfoOutput = union(enum) {
757 dwarf: *Dwarf.WipNav,757 dwarf: *Dwarf.WipNav,
758 eh_frame: *Dwarf2.WipNav,758 eh_frame: *Dwarf2.WipFunc,
759 dwarf2: *Dwarf2.WipNav.Debug,759 dwarf2: *Dwarf2.WipFunc.Debug,
760 none,760 none,
761 };761 };
762 pub const UpdateDebugInfoError = Dwarf.UpdateError;762 pub const UpdateDebugInfoError = Dwarf.UpdateError;
src/link/Dwarf2.zig+2096-1020
...@@ -10,9 +10,10 @@ consts: std.ArrayList(Const),...@@ -10,9 +10,10 @@ consts: std.ArrayList(Const),
10globals: std.array_hash_map.Auto(InternPool.Nav.Index, Global),10globals: std.array_hash_map.Auto(InternPool.Nav.Index, Global),
11funcs: std.array_hash_map.Auto(InternPool.Nav.Index, Func),11funcs: std.array_hash_map.Auto(InternPool.Nav.Index, Func),
12decls: std.array_hash_map.Auto(InternPool.TrackedInst.Index, Decl),12decls: std.array_hash_map.Auto(InternPool.TrackedInst.Index, Decl),
13pending_decl: struct { di: Decl.Index, instance_val: InternPool.Index },13pending_decl: struct { di: Decl.Index, instance: Decl.Instance },
1414
15debug_abbrev: Abbrev,15debug_abbrev: Abbrev,
16debug_addr: Addr,
16frame: Frame,17frame: Frame,
17debug_info: Info,18debug_info: Info,
18debug_line: Line,19debug_line: Line,
...@@ -81,6 +82,7 @@ pub const Unit = struct {...@@ -81,6 +82,7 @@ pub const Unit = struct {
81 ui: Unit.Index,82 ui: Unit.Index,
82 zfi: Zcu.File.Index,83 zfi: Zcu.File.Index,
83 ) std.mem.Allocator.Error!struct { DirIndex, FileIndex } {84 ) std.mem.Allocator.Error!struct { DirIndex, FileIndex } {
85 assert(unit.alive);
84 try unit.dirs.ensureUnusedCapacity(gpa, 1);86 try unit.dirs.ensureUnusedCapacity(gpa, 1);
85 try unit.files.ensureUnusedCapacity(gpa, 1);87 try unit.files.ensureUnusedCapacity(gpa, 1);
86 const dir_gop = unit.dirs.getOrPutAssumeCapacity(ui);88 const dir_gop = unit.dirs.getOrPutAssumeCapacity(ui);
...@@ -154,6 +156,12 @@ pub const Decl = struct {...@@ -154,6 +156,12 @@ pub const Decl = struct {
154 return &dwarf.decls.values()[@backingInt(di)];156 return &dwarf.decls.values()[@backingInt(di)];
155 }157 }
156 };158 };
159
160 const Instance = union(enum) {
161 none,
162 @"const": InternPool.Index,
163 global: InternPool.Nav.Index,
164 };
157};165};
158166
159pub const Frame = struct {167pub const Frame = struct {
...@@ -175,6 +183,29 @@ pub const Abbrev = struct {...@@ -175,6 +183,29 @@ pub const Abbrev = struct {
175 set: std.enums.EnumSet(AbbrevCode),183 set: std.enums.EnumSet(AbbrevCode),
176};184};
177185
186pub const Addr = struct {
187 ni: link.MappedFile.Node.Index.Optional,
188 pending_index: usize,
189 map: std.array_hash_map.Auto(link.File.SymbolId, void),
190
191 fn get(a: *Addr, gpa: std.mem.Allocator, si: link.File.SymbolId) std.mem.Allocator.Error!usize {
192 const gop = try a.map.getOrPut(gpa, si);
193 return gop.index;
194 }
195
196 fn tableOffset(dwarf: *Dwarf) usize {
197 return dwarf.unitLengthSize() + 2 + 1 + 1;
198 }
199
200 pub fn size(a: *Addr, dwarf: *Dwarf) usize {
201 return tableOffset(dwarf) + @backingInt(dwarf.address_size) * a.pending_index;
202 }
203
204 pub fn anyPending(a: *Addr) bool {
205 return a.map.count() - a.pending_index > 0;
206 }
207};
208
178pub const Info = struct {};209pub const Info = struct {};
179210
180pub const Line = struct {211pub const Line = struct {
...@@ -192,8 +223,8 @@ pub const Line = struct {...@@ -192,8 +223,8 @@ pub const Line = struct {
192223
193pub const Str = struct {224pub const Str = struct {
194 ni: link.MappedFile.Node.Index.Optional,225 ni: link.MappedFile.Node.Index.Optional,
195 offset: usize,226 end: usize,
196 map: std.HashMapUnmanaged(usize, void, Context, std.hash_map.default_max_load_percentage),227 map: std.array_hash_map.Custom(usize, void, Context, true),
197228
198 fn get(229 fn get(
199 s: *Str,230 s: *Str,
...@@ -210,21 +241,21 @@ pub const Str = struct {...@@ -210,21 +241,21 @@ pub const Str = struct {
210 .{ .slice = slice },241 .{ .slice = slice },
211 );242 );
212 if (!gop.found_existing) {243 if (!gop.found_existing) {
213 gop.key_ptr.* = s.offset;244 gop.key_ptr.* = s.end;
214 try ni.ensureMinimumSize(gpa, mf, s.offset + str.len + 1);245 try ni.ensureMinimumSize(gpa, mf, s.end + str.len + 1);
215 const slice_mut = ni.slice(mf);246 const slice_mut = ni.slice(mf);
216 @memcpy(slice_mut[s.offset..][0..str.len], str);247 @memcpy(slice_mut[s.end..][0..str.len], str);
217 s.offset += str.len;248 s.end += str.len;
218 slice_mut[s.offset] = 0;249 slice_mut[s.end] = 0;
219 s.offset += 1;250 s.end += 1;
220 }251 }
221 return gop.key_ptr.*;252 return gop.key_ptr.*;
222 }253 }
223254
224 const Context = struct {255 const Context = struct {
225 slice: []const u8,256 slice: []const u8,
226 pub fn hash(context: Context, offset: usize) u64 {257 pub fn hash(context: Context, offset: usize) u32 {
227 return std.hash.Wyhash.hash(0, std.mem.sliceTo(context.slice[offset..], 0));258 return @truncate(std.hash.Wyhash.hash(0, std.mem.sliceTo(context.slice[offset..], 0)));
228 }259 }
229 pub fn eql(_: Context, lhs_offset: usize, rhs_offset: usize) bool {260 pub fn eql(_: Context, lhs_offset: usize, rhs_offset: usize) bool {
230 return lhs_offset == rhs_offset;261 return lhs_offset == rhs_offset;
...@@ -233,10 +264,10 @@ pub const Str = struct {...@@ -233,10 +264,10 @@ pub const Str = struct {
233264
234 const Adapter = struct {265 const Adapter = struct {
235 slice: []const u8,266 slice: []const u8,
236 pub fn hash(_: Adapter, key: []const u8) u64 {267 pub fn hash(_: Adapter, key: []const u8) u32 {
237 return std.hash.Wyhash.hash(0, key);268 return @truncate(std.hash.Wyhash.hash(0, key));
238 }269 }
239 pub fn eql(adapter: Adapter, key: []const u8, rhs_offset: usize) bool {270 pub fn eql(adapter: Adapter, key: []const u8, rhs_offset: usize, _: usize) bool {
240 return std.mem.startsWith(u8, adapter.slice[rhs_offset..], key) and271 return std.mem.startsWith(u8, adapter.slice[rhs_offset..], key) and
241 adapter.slice[rhs_offset + key.len] == 0;272 adapter.slice[rhs_offset + key.len] == 0;
242 }273 }
...@@ -244,21 +275,60 @@ pub const Str = struct {...@@ -244,21 +275,60 @@ pub const Str = struct {
244};275};
245276
246pub const Rnglists = struct {277pub const Rnglists = struct {
247 fn offsetsTableOffset(dwarf: *Dwarf) usize {278 fn tableOffset(dwarf: *Dwarf) usize {
248 return dwarf.unitLengthSize() + 2 + 1 + 1 + 4;279 return dwarf.unitLengthSize() + 2 + 1 + 1 + 4;
249 }280 }
281
282 pub fn size(dwarf: *Dwarf, ui: Unit.Index) usize {
283 return ui.get(dwarf).debug_rnglists_end + 1;
284 }
250};285};
251286
252pub const StrOffsets = struct {287pub const StrOffsets = struct {
253 ni: link.MappedFile.Node.Index.Optional,288 ni: link.MappedFile.Node.Index.Optional,
254 offset: usize,289 pending_index: usize,
290 map: std.array_hash_map.Auto(usize, void),
291
292 fn get(
293 so: *StrOffsets,
294 dwarf: *Dwarf,
295 s: *Str,
296 mf: *link.MappedFile,
297 str: []const u8,
298 ) link.Error!usize {
299 const comp = dwarf.lf.comp;
300 try so.map.ensureUnusedCapacity(comp.gpa, 1);
301 const offset = s.get(comp.gpa, mf, str) catch |err| switch (err) {
302 else => |e| return e,
303 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{
304 mf.io_err.?,
305 }),
306 };
307 const gop = so.map.getOrPutAssumeCapacity(offset);
308 return gop.index;
309 }
310
311 fn tableOffset(dwarf: *Dwarf) usize {
312 return dwarf.unitLengthSize() + 2 + 2;
313 }
314
315 pub fn size(so: *StrOffsets, dwarf: *Dwarf) usize {
316 return tableOffset(dwarf) + dwarf.secOffsetSize() * so.pending_index;
317 }
318
319 pub fn anyPending(so: *StrOffsets) bool {
320 return so.map.count() - so.pending_index > 0;
321 }
255};322};
256323
257pub const SharedSection = enum { debug_abbrev, debug_line_str, debug_str, debug_str_offsets };324pub const SharedSection = enum { debug_abbrev, debug_line_str, debug_str };
258325
259pub const Loc = union(enum) {326pub const Loc = union(enum) {
260 empty,327 empty,
261 addr_reloc: link.File.SymbolId,328 addr_sym: struct {
329 si: link.File.SymbolId,
330 offset: usize = 0,
331 },
262 deref: *const Loc,332 deref: *const Loc,
263 constu: u64,333 constu: u64,
264 consts: i64,334 consts: i64,
...@@ -277,6 +347,8 @@ pub const Loc = union(enum) {...@@ -277,6 +347,8 @@ pub const Loc = union(enum) {
277 node: link.MappedFile.Node.Index,347 node: link.MappedFile.Node.Index,
278 offset: i65 = 0,348 offset: i65 = 0,
279 },349 },
350 addrx_sym: link.File.SymbolId,
351 constx_sym: link.File.SymbolId,
280 wasm_ext: union(enum) {352 wasm_ext: union(enum) {
281 local: u32,353 local: u32,
282 global: u32,354 global: u32,
...@@ -319,11 +391,11 @@ pub const Loc = union(enum) {...@@ -319,11 +391,11 @@ pub const Loc = union(enum) {
319 };391 };
320 switch (loc) {392 switch (loc) {
321 .empty => {},393 .empty => {},
322 .addr_reloc => |si| {394 .addr_sym => |sym| {
323 try w.writeByte(DW.OP.addr);395 try w.writeByte(DW.OP.addr);
324 switch (writer) {396 switch (writer) {
325 .io => try dwarf.addrPlaceholder(w),397 .io => try dwarf.addrPlaceholder(w),
326 .mf => |nw| try dwarf.addrSym(nw, si, 0),398 .mf => |nw| try dwarf.addrSym(nw, sym.si, sym.offset),
327 }399 }
328 },400 },
329 .deref => |addr| {401 .deref => |addr| {
...@@ -442,6 +514,14 @@ pub const Loc = union(enum) {...@@ -442,6 +514,14 @@ pub const Loc = union(enum) {
442 }514 }
443 try w.writeSleb128(implicit_pointer.offset);515 try w.writeSleb128(implicit_pointer.offset);
444 },516 },
517 .addrx_sym => |si| {
518 try w.writeByte(DW.OP.addrx);
519 try dwarf.addrxSym(w, si);
520 },
521 .constx_sym => |si| {
522 try w.writeByte(DW.OP.constx);
523 try dwarf.addrxSym(w, si);
524 },
445 .wasm_ext => |wasm_ext| {525 .wasm_ext => |wasm_ext| {
446 try w.writeByte(DW.OP.WASM_location);526 try w.writeByte(DW.OP.WASM_location);
447 switch (wasm_ext) {527 switch (wasm_ext) {
...@@ -490,33 +570,33 @@ pub const Cfa = union(enum) {...@@ -490,33 +570,33 @@ pub const Cfa = union(enum) {
490 const RegOff = struct { reg: u32, off: i64 };570 const RegOff = struct { reg: u32, off: i64 };
491 const RegExpr = struct { reg: u32, expr: Loc };571 const RegExpr = struct { reg: u32, expr: Loc };
492572
493 fn write(cfa: Cfa, wip_nav: *WipNav) link.EmitError!void {573 fn write(cfa: Cfa, wip_func: *WipFunc) link.EmitError!void {
494 const df_nw = &wip_nav.fde_writer;574 const df_nw = &wip_func.fde_writer;
495 const df_w = &df_nw.interface;575 const df_w = &df_nw.interface;
496 switch (cfa) {576 switch (cfa) {
497 .nop => try df_w.writeByte(DW.CFA.nop),577 .nop => try df_w.writeByte(DW.CFA.nop),
498 .advance_loc => |loc| {578 .advance_loc => |loc| {
499 const delta =579 const delta =
500 @divExact(loc - wip_nav.cfi.loc, wip_nav.dwarf.frame.header.code_alignment_factor);580 @divExact(loc - wip_func.cfi.loc, wip_func.dwarf.frame.header.code_alignment_factor);
501 if (delta == 0) {} else if (std.math.cast(u6, delta)) |small_delta|581 if (delta == 0) {} else if (std.math.cast(u6, delta)) |small_delta|
502 try df_w.writeByte(@as(u8, DW.CFA.advance_loc) + small_delta)582 try df_w.writeByte(@as(u8, DW.CFA.advance_loc) + small_delta)
503 else if (std.math.cast(u8, delta)) |ubyte_delta|583 else if (std.math.cast(u8, delta)) |ubyte_delta|
504 try df_w.writeAll(&.{ DW.CFA.advance_loc1, ubyte_delta })584 try df_w.writeAll(&.{ DW.CFA.advance_loc1, ubyte_delta })
505 else if (std.math.cast(u16, delta)) |uhalf_delta| {585 else if (std.math.cast(u16, delta)) |uhalf_delta| {
506 try df_w.writeByte(DW.CFA.advance_loc2);586 try df_w.writeByte(DW.CFA.advance_loc2);
507 try df_w.writeInt(u16, uhalf_delta, wip_nav.dwarf.endian);587 try df_w.writeInt(u16, uhalf_delta, wip_func.dwarf.endian);
508 } else if (std.math.cast(u32, delta)) |uword_delta| {588 } else if (std.math.cast(u32, delta)) |uword_delta| {
509 try df_w.writeByte(DW.CFA.advance_loc4);589 try df_w.writeByte(DW.CFA.advance_loc4);
510 try df_w.writeInt(u32, uword_delta, wip_nav.dwarf.endian);590 try df_w.writeInt(u32, uword_delta, wip_func.dwarf.endian);
511 }591 }
512 wip_nav.cfi.loc = loc;592 wip_func.cfi.loc = loc;
513 },593 },
514 .offset, .rel_offset => |reg_off| {594 .offset, .rel_offset => |reg_off| {
515 const factored_off = @divExact(reg_off.off - switch (cfa) {595 const factored_off = @divExact(reg_off.off - switch (cfa) {
516 else => unreachable,596 else => unreachable,
517 .offset => 0,597 .offset => 0,
518 .rel_offset => wip_nav.cfi.cfa.off,598 .rel_offset => wip_func.cfi.cfa.off,
519 }, wip_nav.dwarf.frame.header.data_alignment_factor);599 }, wip_func.dwarf.frame.header.data_alignment_factor);
520 if (std.math.cast(u63, factored_off)) |unsigned_off| {600 if (std.math.cast(u63, factored_off)) |unsigned_off| {
521 if (std.math.cast(u6, reg_off.reg)) |small_reg| {601 if (std.math.cast(u6, reg_off.reg)) |small_reg| {
522 try df_w.writeByte(@as(u8, DW.CFA.offset) + small_reg);602 try df_w.writeByte(@as(u8, DW.CFA.offset) + small_reg);
...@@ -558,21 +638,21 @@ pub const Cfa = union(enum) {...@@ -558,21 +638,21 @@ pub const Cfa = union(enum) {
558 const reg_off: RegOff = switch (cfa) {638 const reg_off: RegOff = switch (cfa) {
559 else => unreachable,639 else => unreachable,
560 .def_cfa => |reg_off| reg_off,640 .def_cfa => |reg_off| reg_off,
561 .def_cfa_register => |reg| .{ .reg = reg, .off = wip_nav.cfi.cfa.off },641 .def_cfa_register => |reg| .{ .reg = reg, .off = wip_func.cfi.cfa.off },
562 .def_cfa_offset => |off| .{ .reg = wip_nav.cfi.cfa.reg, .off = off },642 .def_cfa_offset => |off| .{ .reg = wip_func.cfi.cfa.reg, .off = off },
563 .adjust_cfa_offset => |off| .{643 .adjust_cfa_offset => |off| .{
564 .reg = wip_nav.cfi.cfa.reg,644 .reg = wip_func.cfi.cfa.reg,
565 .off = wip_nav.cfi.cfa.off + off,645 .off = wip_func.cfi.cfa.off + off,
566 },646 },
567 };647 };
568 const changed_reg = reg_off.reg != wip_nav.cfi.cfa.reg;648 const changed_reg = reg_off.reg != wip_func.cfi.cfa.reg;
569 const unsigned_off = std.math.cast(u63, reg_off.off);649 const unsigned_off = std.math.cast(u63, reg_off.off);
570 if (reg_off.off == wip_nav.cfi.cfa.off) {650 if (reg_off.off == wip_func.cfi.cfa.off) {
571 if (changed_reg) {651 if (changed_reg) {
572 try df_w.writeByte(DW.CFA.def_cfa_register);652 try df_w.writeByte(DW.CFA.def_cfa_register);
573 try df_w.writeUleb128(reg_off.reg);653 try df_w.writeUleb128(reg_off.reg);
574 }654 }
575 } else if (switch (wip_nav.dwarf.frame.header.data_alignment_factor) {655 } else if (switch (wip_func.dwarf.frame.header.data_alignment_factor) {
576 0 => unreachable,656 0 => unreachable,
577 1 => unsigned_off != null,657 1 => unsigned_off != null,
578 else => |data_alignment_factor| @rem(reg_off.off, data_alignment_factor) != 0,658 else => |data_alignment_factor| @rem(reg_off.off, data_alignment_factor) != 0,
...@@ -584,23 +664,23 @@ pub const Cfa = union(enum) {...@@ -584,23 +664,23 @@ pub const Cfa = union(enum) {
584 try df_w.writeByte(if (changed_reg) DW.CFA.def_cfa_sf else DW.CFA.def_cfa_offset_sf);664 try df_w.writeByte(if (changed_reg) DW.CFA.def_cfa_sf else DW.CFA.def_cfa_offset_sf);
585 if (changed_reg) try df_w.writeUleb128(reg_off.reg);665 if (changed_reg) try df_w.writeUleb128(reg_off.reg);
586 try df_w.writeSleb128(666 try df_w.writeSleb128(
587 @divExact(reg_off.off, wip_nav.dwarf.frame.header.data_alignment_factor),667 @divExact(reg_off.off, wip_func.dwarf.frame.header.data_alignment_factor),
588 );668 );
589 }669 }
590 wip_nav.cfi.cfa = reg_off;670 wip_func.cfi.cfa = reg_off;
591 },671 },
592 .def_cfa_expression => |expr| {672 .def_cfa_expression => |expr| {
593 try df_w.writeByte(DW.CFA.def_cfa_expression);673 try df_w.writeByte(DW.CFA.def_cfa_expression);
594 try wip_nav.dwarf.exprLoc(df_nw, expr);674 try wip_func.dwarf.exprLoc(df_nw, expr);
595 },675 },
596 .expression => |reg_expr| {676 .expression => |reg_expr| {
597 try df_w.writeByte(DW.CFA.expression);677 try df_w.writeByte(DW.CFA.expression);
598 try df_w.writeUleb128(reg_expr.reg);678 try df_w.writeUleb128(reg_expr.reg);
599 try wip_nav.dwarf.exprLoc(df_nw, reg_expr.expr);679 try wip_func.dwarf.exprLoc(df_nw, reg_expr.expr);
600 },680 },
601 .val_offset => |reg_off| {681 .val_offset => |reg_off| {
602 const factored_off =682 const factored_off =
603 @divExact(reg_off.off, wip_nav.dwarf.frame.header.data_alignment_factor);683 @divExact(reg_off.off, wip_func.dwarf.frame.header.data_alignment_factor);
604 if (std.math.cast(u63, factored_off)) |unsigned_off| {684 if (std.math.cast(u63, factored_off)) |unsigned_off| {
605 try df_w.writeByte(DW.CFA.val_offset);685 try df_w.writeByte(DW.CFA.val_offset);
606 try df_w.writeUleb128(reg_off.reg);686 try df_w.writeUleb128(reg_off.reg);
...@@ -614,14 +694,14 @@ pub const Cfa = union(enum) {...@@ -614,14 +694,14 @@ pub const Cfa = union(enum) {
614 .val_expression => |reg_expr| {694 .val_expression => |reg_expr| {
615 try df_w.writeByte(DW.CFA.val_expression);695 try df_w.writeByte(DW.CFA.val_expression);
616 try df_w.writeUleb128(reg_expr.reg);696 try df_w.writeUleb128(reg_expr.reg);
617 try wip_nav.dwarf.exprLoc(df_nw, reg_expr.expr);697 try wip_func.dwarf.exprLoc(df_nw, reg_expr.expr);
618 },698 },
619 .escape => |bytes| try df_w.writeAll(bytes),699 .escape => |bytes| try df_w.writeAll(bytes),
620 }700 }
621 }701 }
622};702};
623703
624pub const WipNav = struct {704pub const WipFunc = struct {
625 dwarf: *Dwarf,705 dwarf: *Dwarf,
626 unit: Unit.Index,706 unit: Unit.Index,
627 func: InternPool.Index,707 func: InternPool.Index,
...@@ -635,44 +715,50 @@ pub const WipNav = struct {...@@ -635,44 +715,50 @@ pub const WipNav = struct {
635 frame_func_length: struct { offset: usize, size: AddressSize },715 frame_func_length: struct { offset: usize, size: AddressSize },
636716
637 pub const Debug = struct {717 pub const Debug = struct {
638 wip_nav: WipNav,718 wip_func: WipFunc,
639 pt: Zcu.PerThread,719 pt: Zcu.PerThread,
640 any_children: bool,720 is_empty: bool,
721 empty_abbrev_code: AbbrevCode,
641 blocks: std.ArrayList(struct {722 blocks: std.ArrayList(struct {
642 abbrev_code: u32,723 abbrev_code_offset: usize,
643 low_pc_off: usize,724 low_pc: usize,
644 high_pc: u32,725 high_pc_offset: usize,
645 }),726 }),
646 info_writer: link.MappedFile.Node.Writer,727 info_writer: link.MappedFile.Node.Writer,
647 info_func_length_offset: usize,728 info_func_length_offset: usize,
648 line_writer: link.MappedFile.Node.Writer,729 line_writer: link.MappedFile.Node.Writer,
649730
731 pub fn init(debug: *Debug, pt: Zcu.PerThread) void {
732 debug.pt = pt;
733 debug.is_empty = true;
734 debug.blocks = .empty;
735 }
736
650 pub fn deinit(debug: *Debug) void {737 pub fn deinit(debug: *Debug) void {
651 const gpa = debug.pt.zcu.gpa;738 const gpa = debug.pt.zcu.gpa;
652 debug.line_writer.deinit();739 debug.line_writer.deinit();
653 debug.info_writer.deinit();740 debug.info_writer.deinit();
654 debug.blocks.deinit(gpa);741 debug.blocks.deinit(gpa);
655 debug.wip_nav.deinit();742 debug.wip_func.deinit();
656 debug.* = undefined;743 debug.* = undefined;
657 }744 }
658745
659 pub fn genDebugFrame(debug: *Debug, loc: u32, cfa: Cfa) link.Error!void {746 pub fn genDebugFrame(debug: *Debug, loc: u32, cfa: Cfa) link.Error!void {
660 return debug.wip_nav.genDebugFrame(loc, cfa);747 return debug.wip_func.genDebugFrame(loc, cfa);
661 }748 }
662749
663 pub fn startFuncDebugInfo(debug: *Debug) link.Error!void {750 pub fn startDebugInfo(debug: *Debug) link.Error!void {
664 assert(debug.wip_nav.func != .none);751 debug.startDebugInfoInner() catch |err| switch (err) {
665 debug.startFuncDebugInfoInner() catch |err| switch (err) {
666 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
667 else => |e| return e,752 else => |e| return e,
753 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
668 };754 };
669 }755 }
670 fn startFuncDebugInfoInner(debug: *Debug) link.EmitError!void {756 fn startDebugInfoInner(debug: *Debug) link.EmitError!void {
671 const dwarf = debug.wip_nav.dwarf;757 const dwarf = debug.wip_func.dwarf;
672 const pt = debug.pt;758 const pt = debug.pt;
673 const zcu = pt.zcu;759 const zcu = pt.zcu;
674 const ip = &zcu.intern_pool;760 const ip = &zcu.intern_pool;
675 const func = zcu.funcInfo(debug.wip_nav.func);761 const func = zcu.funcInfo(debug.wip_func.func);
676 const nav = ip.getNav(func.owner_nav);762 const nav = ip.getNav(func.owner_nav);
677 const func_type = ip.indexToKey(func.ty).func_type;763 const func_type = ip.indexToKey(func.ty).func_type;
678 const inst_info = nav.srcInst(ip).resolveFull(ip).?;764 const inst_info = nav.srcInst(ip).resolveFull(ip).?;
...@@ -681,42 +767,52 @@ pub const WipNav = struct {...@@ -681,42 +767,52 @@ pub const WipNav = struct {
681 const decl = zf.zir.?.getDeclaration(inst_info.inst);767 const decl = zf.zir.?.getDeclaration(inst_info.inst);
682 const di_nw = &debug.info_writer;768 const di_nw = &debug.info_writer;
683 const di_w = &di_nw.interface;769 const di_w = &di_nw.interface;
684 try dwarf.abbrevCode(di_nw, .decl_func);770 const parent_ty: Type = .fromInterned(ip.namespacePtr(switch (func.generic_owner) {
685 try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr(switch (func.generic_owner) {
686 .none => nav,
687 else => |generic_owner| ip.getNav(zcu.funcInfo(generic_owner).owner_nav),771 else => |generic_owner| ip.getNav(zcu.funcInfo(generic_owner).owner_nav),
688 }.analysis.?.namespace).owner_type));772 .none => nav,
689 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);773 }.analysis.?.namespace).owner_type);
690 try di_w.writeUleb128(decl.src_column + 1);774 if (func.generic_owner != .none or parent_ty.getCaptures(zcu).len > 0) {
691 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);775 debug.empty_abbrev_code = .decl_instance_empty_func;
692 try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip));776 try dwarf.abbrevCode(di_nw, .decl_instance_func);
693 try dwarf.strp(&dwarf.debug_str, di_nw, switch (decl.linkage) {777 try dwarf.refType(pt, di_nw, parent_ty);
778 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, debug.wip_func.func), 0);
779 } else {
780 debug.empty_abbrev_code = .decl_empty_func;
781 try dwarf.abbrevCode(di_nw, .decl_func);
782 try dwarf.refType(pt, di_nw, parent_ty);
783 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
784 try di_w.writeUleb128(decl.src_column + 1);
785 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
786 try dwarf.strx(di_nw, nav.name.toSlice(ip));
787 }
788 try dwarf.strx(di_nw, switch (decl.linkage) {
694 .normal => nav.fqn,789 .normal => nav.fqn,
695 .@"extern", .@"export" => nav.name,790 .@"extern", .@"export" => nav.name,
696 }.toSlice(ip));791 }.toSlice(ip));
697 try dwarf.refType(pt, di_nw, .fromInterned(func_type.return_type));792 try dwarf.refType(pt, di_nw, .fromInterned(func_type.return_type));
698 try dwarf.addrSym(di_nw, debug.wip_nav.func_si, 0);793 try dwarf.addrxSym(di_w, debug.wip_func.func_si);
699 debug.info_func_length_offset = di_w.end;794 debug.info_func_length_offset = di_w.end;
700 try di_w.writeInt(u32, undefined, dwarf.endian);795 try di_w.writeInt(u32, undefined, dwarf.endian);
701 try di_w.writeUleb128(796 try di_w.writeUleb128(
702 target_info.minFunctionAlignment(target).max(nav.resolved.?.@"align").toByteUnits().?,797 target_info.minFunctionAlignment(target).max(nav.resolved.?.@"align").toByteUnits().?,
703 );798 );
704 try di_w.writeByte(@intFromBool(decl.linkage != .normal));799 try di_w.writeAll(&.{
705 try di_w.writeByte(@intFromBool(Type.fromInterned(func_type.return_type).isNoReturn(zcu)));800 @intFromBool(decl.linkage != .normal),
801 @intFromBool(Type.fromInterned(func_type.return_type).isNoReturn(zcu)),
802 });
706 }803 }
707804
708 pub fn startDebugLine(debug: *Debug) link.Error!void {805 pub fn startDebugLine(debug: *Debug) link.Error!void {
709 assert(debug.wip_nav.func != .none);
710 debug.startDebugLineInner() catch |err| switch (err) {806 debug.startDebugLineInner() catch |err| switch (err) {
711 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),
712 else => |e| return e,807 else => |e| return e,
808 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
713 };809 };
714 }810 }
715 fn startDebugLineInner(debug: *Debug) link.EmitError!void {811 fn startDebugLineInner(debug: *Debug) link.EmitError!void {
716 const dwarf = debug.wip_nav.dwarf;812 const dwarf = debug.wip_func.dwarf;
717 const zcu = debug.pt.zcu;813 const zcu = debug.pt.zcu;
718 const ip = &zcu.intern_pool;814 const ip = &zcu.intern_pool;
719 const func = zcu.funcInfo(debug.wip_nav.func);815 const func = zcu.funcInfo(debug.wip_func.func);
720 const inst_info = ip.getNav(func.owner_nav).srcInst(ip).resolveFull(ip).?;816 const inst_info = ip.getNav(func.owner_nav).srcInst(ip).resolveFull(ip).?;
721 const zf = zcu.fileByIndex(inst_info.file);817 const zf = zcu.fileByIndex(inst_info.file);
722 const decl = zf.zir.?.getDeclaration(inst_info.inst);818 const decl = zf.zir.?.getDeclaration(inst_info.inst);
...@@ -735,10 +831,10 @@ pub const WipNav = struct {...@@ -735,10 +831,10 @@ pub const WipNav = struct {
735 } else {831 } else {
736 try dl_w.writeUleb128(1 + @backingInt(dwarf.address_size));832 try dl_w.writeUleb128(1 + @backingInt(dwarf.address_size));
737 try dl_w.writeByte(DW.LNE.set_address);833 try dl_w.writeByte(DW.LNE.set_address);
738 try dwarf.addrSym(dl_nw, debug.wip_nav.func_si, 0);834 try dwarf.addrSym(dl_nw, debug.wip_func.func_si, 0);
739835
740 const unit = dwarf.getUnit(zf.mod.?);836 const ui = dwarf.getUnit(zf.mod.?);
741 _, const fi = try unit.get(dwarf).getFile(zcu.gpa, unit, inst_info.file);837 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, inst_info.file);
742 try dl_w.writeByte(DW.LNS.set_file);838 try dl_w.writeByte(DW.LNS.set_file);
743 try dl_w.writeUleb128(@backingInt(fi));839 try dl_w.writeUleb128(@backingInt(fi));
744840
...@@ -749,28 +845,32 @@ pub const WipNav = struct {...@@ -749,28 +845,32 @@ pub const WipNav = struct {
749 }845 }
750 }846 }
751847
752 pub fn finishFunc(debug: *Debug, func_length: u64) link.Error!void {848 pub fn finish(debug: *Debug, func_length: u64) link.Error!void {
753 assert(debug.wip_nav.func != .none);
754 const di_nw = &debug.info_writer;849 const di_nw = &debug.info_writer;
755 debug.finishDebugInfo(func_length) catch |err| switch (err) {850 debug.finishDebugInfo(func_length) catch |err| switch (err) {
756 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(di_nw),
757 else => |e| return e,851 else => |e| return e,
852 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(di_nw),
758 };853 };
759 debug.finishDebugLine() catch |err| switch (err) {854 debug.finishDebugLine() catch |err| switch (err) {
760 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(di_nw),
761 else => |e| return e,855 else => |e| return e,
856 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(di_nw),
762 };857 };
763 }858 }
764 fn finishDebugInfo(debug: *Debug, func_length: u64) link.EmitError!void {859 fn finishDebugInfo(debug: *Debug, func_length: u64) link.EmitError!void {
765 const dwarf = debug.wip_nav.dwarf;860 const dwarf = debug.wip_func.dwarf;
766 const di_w = &debug.info_writer.interface;861 const di_nw = &debug.info_writer;
862 const di_w = &di_nw.interface;
767 std.mem.writeInt(863 std.mem.writeInt(
768 u32,864 u32,
769 di_w.buffered()[debug.info_func_length_offset..][0..4],865 di_w.buffered()[debug.info_func_length_offset..][0..4],
770 @intCast(func_length),866 @intCast(func_length),
771 dwarf.endian,867 dwarf.endian,
772 );868 );
773 try di_w.writeUleb128(@backingInt(AbbrevCode.null));869 if (debug.is_empty) std.leb.writeUnsignedFixed(
870 AbbrevCode.decl_size,
871 di_w.buffered()[0..AbbrevCode.decl_size],
872 @intCast(try dwarf.refAbbrevCode(di_nw.mf, debug.empty_abbrev_code)),
873 ) else try di_w.writeUleb128(@backingInt(AbbrevCode.null));
774 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());874 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());
775 }875 }
776 fn finishDebugLine(debug: *Debug) link.EmitError!void {876 fn finishDebugLine(debug: *Debug) link.EmitError!void {
...@@ -787,8 +887,8 @@ pub const WipNav = struct {...@@ -787,8 +887,8 @@ pub const WipNav = struct {
787 loc: Loc,887 loc: Loc,
788 ) link.Error!void {888 ) link.Error!void {
789 return debug.genLocalVarDebugInfoInner(tag, opt_name, ty, loc) catch |err| switch (err) {889 return debug.genLocalVarDebugInfoInner(tag, opt_name, ty, loc) catch |err| switch (err) {
790 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
791 else => |e| e,890 else => |e| e,
891 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
792 };892 };
793 }893 }
794 fn genLocalVarDebugInfoInner(894 fn genLocalVarDebugInfoInner(
...@@ -798,17 +898,16 @@ pub const WipNav = struct {...@@ -798,17 +898,16 @@ pub const WipNav = struct {
798 ty: Type,898 ty: Type,
799 loc: Loc,899 loc: Loc,
800 ) link.EmitError!void {900 ) link.EmitError!void {
801 assert(debug.wip_nav.func != .none);901 const dwarf = debug.wip_func.dwarf;
802 const dwarf = debug.wip_nav.dwarf;
803 const di_nw = &debug.info_writer;902 const di_nw = &debug.info_writer;
804 try dwarf.abbrevCode(di_nw, switch (tag) {903 try dwarf.abbrevCode(di_nw, switch (tag) {
805 .arg => if (opt_name) |_| .arg else .unnamed_arg,904 .arg => if (opt_name) |_| .arg else .unnamed_arg,
806 .local_var => if (opt_name) |_| .local_var else unreachable,905 .local_var => if (opt_name) |_| .local_var else unreachable,
807 });906 });
808 if (opt_name) |name| try dwarf.strp(&dwarf.debug_str, di_nw, name);907 if (opt_name) |name| try dwarf.strx(di_nw, name);
809 try dwarf.refType(debug.pt, di_nw, ty);908 try dwarf.refType(debug.pt, di_nw, ty);
810 try dwarf.exprLoc(di_nw, loc);909 try dwarf.exprLoc(di_nw, loc);
811 debug.any_children = true;910 debug.is_empty = false;
812 }911 }
813912
814 pub const LocalConstTag = enum { comptime_arg, local_const };913 pub const LocalConstTag = enum { comptime_arg, local_const };
...@@ -819,8 +918,8 @@ pub const WipNav = struct {...@@ -819,8 +918,8 @@ pub const WipNav = struct {
819 val: Value,918 val: Value,
820 ) link.Error!void {919 ) link.Error!void {
821 return debug.genLocalConstDebugInfoInner(tag, opt_name, val) catch |err| switch (err) {920 return debug.genLocalConstDebugInfoInner(tag, opt_name, val) catch |err| switch (err) {
822 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
823 else => |e| e,921 else => |e| e,
922 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
824 };923 };
825 }924 }
826 fn genLocalConstDebugInfoInner(925 fn genLocalConstDebugInfoInner(
...@@ -829,8 +928,7 @@ pub const WipNav = struct {...@@ -829,8 +928,7 @@ pub const WipNav = struct {
829 opt_name: ?[]const u8,928 opt_name: ?[]const u8,
830 val: Value,929 val: Value,
831 ) link.EmitError!void {930 ) link.EmitError!void {
832 assert(debug.wip_nav.func != .none);931 const dwarf = debug.wip_func.dwarf;
833 const dwarf = debug.wip_nav.dwarf;
834 const pt = debug.pt;932 const pt = debug.pt;
835 const zcu = debug.pt.zcu;933 const zcu = debug.pt.zcu;
836 const ty = val.typeOf(zcu);934 const ty = val.typeOf(zcu);
...@@ -858,23 +956,22 @@ pub const WipNav = struct {...@@ -858,23 +956,22 @@ pub const WipNav = struct {
858 .fully_comptime => .local_const_fully_comptime,956 .fully_comptime => .local_const_fully_comptime,
859 } else unreachable,957 } else unreachable,
860 });958 });
861 if (opt_name) |name| try dwarf.strp(&dwarf.debug_str, di_nw, name);959 if (opt_name) |name| try dwarf.strx(di_nw, name);
862 try dwarf.refType(pt, di_nw, ty);960 try dwarf.refType(pt, di_nw, ty);
863 if (ty_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, val);961 if (ty_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, val);
864 if (ty_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, val);962 if (ty_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, val);
865 debug.any_children = true;963 debug.is_empty = false;
866 }964 }
867965
868 pub fn genVarArgsDebugInfo(debug: *Debug) link.Error!void {966 pub fn genVarArgsDebugInfo(debug: *Debug) link.Error!void {
869 return debug.genVarArgsDebugInfoInner() catch |err| switch (err) {967 return debug.genVarArgsDebugInfoInner() catch |err| switch (err) {
870 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
871 else => |e| e,968 else => |e| e,
969 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
872 };970 };
873 }971 }
874 fn genVarArgsDebugInfoInner(debug: *Debug) link.EmitError!void {972 fn genVarArgsDebugInfoInner(debug: *Debug) link.EmitError!void {
875 assert(debug.wip_nav.func != .none);973 try debug.wip_func.dwarf.abbrevCode(&debug.info_writer, .is_var_args);
876 try debug.wip_nav.dwarf.abbrevCode(&debug.info_writer, .is_var_args);974 debug.is_empty = false;
877 debug.any_children = true;
878 }975 }
879976
880 pub fn advanceLineAndPc(977 pub fn advanceLineAndPc(
...@@ -884,7 +981,7 @@ pub const WipNav = struct {...@@ -884,7 +981,7 @@ pub const WipNav = struct {
884 end: bool,981 end: bool,
885 ) link.Error!void {982 ) link.Error!void {
886 return debug.advanceLineAndPcInner(delta_line, delta_pc, end) catch |err| switch (err) {983 return debug.advanceLineAndPcInner(delta_line, delta_pc, end) catch |err| switch (err) {
887 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),984 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
888 };985 };
889 }986 }
890 fn advanceLineAndPcInner(987 fn advanceLineAndPcInner(
...@@ -895,7 +992,7 @@ pub const WipNav = struct {...@@ -895,7 +992,7 @@ pub const WipNav = struct {
895 ) std.Io.Writer.Error!void {992 ) std.Io.Writer.Error!void {
896 const dl_w = &debug.line_writer.interface;993 const dl_w = &debug.line_writer.interface;
897994
898 const header = debug.wip_nav.dwarf.debug_line.header;995 const header = debug.wip_func.dwarf.debug_line.header;
899 assert(header.maximum_operations_per_instruction == 1);996 assert(header.maximum_operations_per_instruction == 1);
900 const delta_op: u64 = 0;997 const delta_op: u64 = 0;
901998
...@@ -939,7 +1036,7 @@ pub const WipNav = struct {...@@ -939,7 +1036,7 @@ pub const WipNav = struct {
9391036
940 pub fn setColumn(debug: *Debug, column: u32) link.Error!void {1037 pub fn setColumn(debug: *Debug, column: u32) link.Error!void {
941 return debug.setColumnInner(column) catch |err| switch (err) {1038 return debug.setColumnInner(column) catch |err| switch (err) {
942 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),1039 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
943 };1040 };
944 }1041 }
945 fn setColumnInner(debug: *Debug, column: u32) std.Io.Writer.Error!void {1042 fn setColumnInner(debug: *Debug, column: u32) std.Io.Writer.Error!void {
...@@ -950,7 +1047,7 @@ pub const WipNav = struct {...@@ -950,7 +1047,7 @@ pub const WipNav = struct {
9501047
951 pub fn negateStmt(debug: *Debug) link.Error!void {1048 pub fn negateStmt(debug: *Debug) link.Error!void {
952 return debug.negateStmtInner() catch |err| switch (err) {1049 return debug.negateStmtInner() catch |err| switch (err) {
953 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),1050 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
954 };1051 };
955 }1052 }
956 fn negateStmtInner(debug: *Debug) std.Io.Writer.Error!void {1053 fn negateStmtInner(debug: *Debug) std.Io.Writer.Error!void {
...@@ -959,7 +1056,7 @@ pub const WipNav = struct {...@@ -959,7 +1056,7 @@ pub const WipNav = struct {
9591056
960 pub fn setPrologueEnd(debug: *Debug) link.Error!void {1057 pub fn setPrologueEnd(debug: *Debug) link.Error!void {
961 return debug.setPrologueEndInner() catch |err| switch (err) {1058 return debug.setPrologueEndInner() catch |err| switch (err) {
962 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),1059 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
963 };1060 };
964 }1061 }
965 fn setPrologueEndInner(debug: *Debug) std.Io.Writer.Error!void {1062 fn setPrologueEndInner(debug: *Debug) std.Io.Writer.Error!void {
...@@ -968,151 +1065,155 @@ pub const WipNav = struct {...@@ -968,151 +1065,155 @@ pub const WipNav = struct {
9681065
969 pub fn setEpilogueBegin(debug: *Debug) link.Error!void {1066 pub fn setEpilogueBegin(debug: *Debug) link.Error!void {
970 return debug.setEpilogueBeginInner() catch |err| switch (err) {1067 return debug.setEpilogueBeginInner() catch |err| switch (err) {
971 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),1068 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
972 };1069 };
973 }1070 }
974 fn setEpilogueBeginInner(debug: *Debug) std.Io.Writer.Error!void {1071 fn setEpilogueBeginInner(debug: *Debug) std.Io.Writer.Error!void {
975 try debug.line_writer.interface.writeByte(DW.LNS.set_epilogue_begin);1072 try debug.line_writer.interface.writeByte(DW.LNS.set_epilogue_begin);
976 }1073 }
9771074
978 pub fn enterBlock(debug: *Debug, code_off: usize) link.Error!void {1075 pub fn enterBlock(debug: *Debug, code_offset: usize) link.Error!void {
979 return debug.enterBlockInner(code_off) catch |err| switch (err) {1076 return debug.enterBlockInner(code_offset) catch |err| switch (err) {
980 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
981 else => |e| e,1077 else => |e| e,
1078 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
982 };1079 };
983 }1080 }
984 fn enterBlockInner(debug: *Debug, code_off: usize) link.EmitError!void {1081 fn enterBlockInner(debug: *Debug, code_offset: usize) link.EmitError!void {
985 const dwarf = debug.wip_nav.dwarf;1082 const dwarf = debug.wip_func.dwarf;
986 const block = try debug.blocks.addOne(dwarf.lf.comp.gpa);1083 const block = try debug.blocks.addOne(dwarf.lf.comp.gpa);
9871084
988 const di_nw = &debug.info_writer;1085 const di_nw = &debug.info_writer;
989 const di_w = &di_nw.interface;1086 const di_w = &di_nw.interface;
990 block.abbrev_code = @intCast(di_w.end);1087 block.abbrev_code_offset = di_w.end;
991 try dwarf.abbrevCode(di_nw, .block);1088 try dwarf.abbrevCode(di_nw, .block);
992 block.low_pc_off = code_off;1089 block.low_pc = code_offset;
993 try dwarf.addrSym(di_nw, debug.wip_nav.func_si, code_off);1090 try dwarf.addrSym(di_nw, debug.wip_func.func_si, code_offset);
994 block.high_pc = @intCast(di_w.end);1091 block.high_pc_offset = di_w.end;
995 try di_w.writeInt(u32, 0, dwarf.endian);1092 try di_w.writeInt(u32, 0, dwarf.endian);
996 debug.any_children = false;1093 debug.is_empty = true;
997 }1094 }
9981095
999 pub fn leaveBlock(debug: *Debug, code_off: usize) link.Error!void {1096 pub fn leaveBlock(debug: *Debug, code_offset: usize) link.Error!void {
1000 return debug.leaveBlockInner(code_off) catch |err| switch (err) {1097 return debug.leaveBlockInner(code_offset) catch |err| switch (err) {
1001 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
1002 else => |e| e,1098 else => |e| e,
1099 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
1003 };1100 };
1004 }1101 }
1005 fn leaveBlockInner(debug: *Debug, code_off: usize) link.EmitError!void {1102 fn leaveBlockInner(debug: *Debug, code_offset: usize) link.EmitError!void {
1006 const dwarf = debug.wip_nav.dwarf;1103 const dwarf = debug.wip_func.dwarf;
1007 const block_size = comptime uleb128Size(@backingInt(AbbrevCode.block));
1008 const block = debug.blocks.pop().?;1104 const block = debug.blocks.pop().?;
10091105
1010 const di_nw = &debug.info_writer;1106 const di_nw = &debug.info_writer;
1011 const di_w = &di_nw.interface;1107 const di_w = &di_nw.interface;
1012 if (debug.any_children)1108 const block_size = comptime uleb128Size(@backingInt(AbbrevCode.block));
1013 try di_w.writeUleb128(@backingInt(AbbrevCode.null))1109 if (debug.is_empty) std.leb.writeUnsignedFixed(
1014 else1110 block_size,
1015 std.leb.writeUnsignedFixed(1111 di_w.buffered()[block.abbrev_code_offset..][0..block_size],
1016 block_size,1112 @intCast(try dwarf.refAbbrevCode(di_nw.mf, .empty_block)),
1017 di_w.buffered()[block.abbrev_code..][0..block_size],1113 ) else try di_w.writeUleb128(@backingInt(AbbrevCode.null));
1018 @intCast(try dwarf.refAbbrevCode(di_nw.mf, .empty_block)),
1019 );
1020 std.mem.writeInt(1114 std.mem.writeInt(
1021 u32,1115 u32,
1022 di_nw.interface.buffered()[block.high_pc..][0..4],1116 di_nw.interface.buffered()[block.high_pc_offset..][0..4],
1023 @intCast(code_off - block.low_pc_off),1117 @intCast(code_offset - block.low_pc),
1024 dwarf.endian,1118 dwarf.endian,
1025 );1119 );
1026 debug.any_children = true;1120 debug.is_empty = false;
1027 }1121 }
10281122
1029 pub fn enterInlineFunc(1123 pub fn enterInlineFunc(
1030 debug: *Debug,1124 debug: *Debug,
1031 func: InternPool.Index,1125 func: InternPool.Index,
1032 code_off: usize,1126 code_offset: usize,
1033 line: u32,1127 line: u32,
1034 column: u32,1128 column: u32,
1035 ) link.Error!void {1129 ) link.Error!void {
1036 return debug.enterInlineFuncInner(func, code_off, line, column) catch |err| switch (err) {1130 return debug.enterInlineFuncInner(
1037 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),1131 func,
1132 code_offset,
1133 line,
1134 column,
1135 ) catch |err| switch (err) {
1038 else => |e| e,1136 else => |e| e,
1137 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
1039 };1138 };
1040 }1139 }
1041 fn enterInlineFuncInner(1140 fn enterInlineFuncInner(
1042 debug: *Debug,1141 debug: *Debug,
1043 func: InternPool.Index,1142 func: InternPool.Index,
1044 code_off: usize,1143 code_offset: usize,
1045 line: u32,1144 line: u32,
1046 column: u32,1145 column: u32,
1047 ) link.EmitError!void {1146 ) link.EmitError!void {
1048 const dwarf = debug.wip_nav.dwarf;1147 const dwarf = debug.wip_func.dwarf;
1049 const zcu = debug.pt.zcu;1148 const pt = debug.pt;
1149 const zcu = pt.zcu;
1050 const block = try debug.blocks.addOne(zcu.gpa);1150 const block = try debug.blocks.addOne(zcu.gpa);
10511151
1052 const di_nw = &debug.info_writer;1152 const di_nw = &debug.info_writer;
1053 const di_w = &di_nw.interface;1153 const di_w = &di_nw.interface;
1054 block.abbrev_code = @intCast(di_w.end);1154 block.abbrev_code_offset = di_w.end;
1055 try dwarf.abbrevCode(di_nw, .inlined_func);1155 try dwarf.abbrevCode(di_nw, .inlined_func);
1056 try debug.refFunc(func);1156 try dwarf.refConst(pt, di_nw, .fromInterned(func));
1057 try di_w.writeUleb128((if (zcu.comp.config.incremental)1157 try di_w.writeUleb128((if (zcu.comp.config.incremental)
1058 01158 0
1059 else1159 else
1060 zcu.navSrcLine(zcu.funcInfo(debug.wip_nav.func).owner_nav) + 1) + line);1160 zcu.navSrcLine(zcu.funcInfo(debug.wip_func.func).owner_nav) + 1) + line);
1061 try di_w.writeUleb128(column + 1);1161 try di_w.writeUleb128(column + 1);
1062 block.low_pc_off = code_off;1162 block.low_pc = code_offset;
1063 try dwarf.addrSym(di_nw, debug.wip_nav.func_si, code_off);1163 try dwarf.addrSym(di_nw, debug.wip_func.func_si, code_offset);
1064 block.high_pc = @intCast(di_w.end);1164 block.high_pc_offset = di_w.end;
1065 try di_w.writeInt(u32, 0, dwarf.endian);1165 try di_w.writeInt(u32, 0, dwarf.endian);
1066 try debug.setInlineFunc(func);1166 try debug.setInlineFunc(func);
1067 debug.any_children = false;1167 debug.is_empty = true;
1068 }1168 }
10691169
1070 pub fn leaveInlineFunc(debug: *Debug, func: InternPool.Index, code_off: usize) link.Error!void {1170 pub fn leaveInlineFunc(
1071 return debug.leaveInlineFuncInner(func, code_off) catch |err| switch (err) {1171 debug: *Debug,
1072 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),1172 func: InternPool.Index,
1173 code_offset: usize,
1174 ) link.Error!void {
1175 return debug.leaveInlineFuncInner(func, code_offset) catch |err| switch (err) {
1073 else => |e| e,1176 else => |e| e,
1177 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
1074 };1178 };
1075 }1179 }
1076 fn leaveInlineFuncInner(1180 fn leaveInlineFuncInner(
1077 debug: *Debug,1181 debug: *Debug,
1078 func: InternPool.Index,1182 func: InternPool.Index,
1079 code_off: usize,1183 code_offset: usize,
1080 ) link.EmitError!void {1184 ) link.EmitError!void {
1081 const dwarf = debug.wip_nav.dwarf;1185 const dwarf = debug.wip_func.dwarf;
1082 const inlined_func_size = comptime uleb128Size(@backingInt(AbbrevCode.inlined_func));
1083 const block = debug.blocks.pop().?;1186 const block = debug.blocks.pop().?;
10841187
1085 const di_nw = &debug.info_writer;1188 const di_nw = &debug.info_writer;
1086 const di_w = &di_nw.interface;1189 const di_w = &di_nw.interface;
1087 if (debug.any_children)1190 const inlined_func_size = comptime uleb128Size(@backingInt(AbbrevCode.inlined_func));
1088 try di_w.writeUleb128(@backingInt(AbbrevCode.null))1191 if (debug.is_empty) std.leb.writeUnsignedFixed(
1089 else1192 inlined_func_size,
1090 std.leb.writeUnsignedFixed(1193 di_w.buffered()[block.abbrev_code_offset..][0..inlined_func_size],
1091 inlined_func_size,1194 @intCast(try dwarf.refAbbrevCode(di_nw.mf, .empty_inlined_func)),
1092 di_w.buffered()[block.abbrev_code..][0..inlined_func_size],1195 ) else try di_w.writeUleb128(@backingInt(AbbrevCode.null));
1093 @intCast(try dwarf.refAbbrevCode(di_nw.mf, .empty_inlined_func)),
1094 );
1095 std.mem.writeInt(1196 std.mem.writeInt(
1096 u32,1197 u32,
1097 di_w.buffered()[block.high_pc..][0..4],1198 di_w.buffered()[block.high_pc_offset..][0..4],
1098 @intCast(code_off - block.low_pc_off),1199 @intCast(code_offset - block.low_pc),
1099 dwarf.endian,1200 dwarf.endian,
1100 );1201 );
1101 try debug.setInlineFunc(func);1202 try debug.setInlineFunc(func);
1102 debug.any_children = true;1203 debug.is_empty = false;
1103 }1204 }
11041205
1105 pub fn setInlineFunc(debug: *Debug, func: InternPool.Index) link.Error!void {1206 pub fn setInlineFunc(debug: *Debug, func: InternPool.Index) link.Error!void {
1106 return debug.setInlineFuncInner(func) catch |err| switch (err) {1207 return debug.setInlineFuncInner(func) catch |err| switch (err) {
1107 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),
1108 else => |e| e,1208 else => |e| e,
1209 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
1109 };1210 };
1110 }1211 }
1111 fn setInlineFuncInner(debug: *Debug, func: InternPool.Index) link.EmitError!void {1212 fn setInlineFuncInner(debug: *Debug, func: InternPool.Index) link.EmitError!void {
1112 const zcu = debug.pt.zcu;1213 const zcu = debug.pt.zcu;
1113 const ip = &zcu.intern_pool;1214 const ip = &zcu.intern_pool;
1114 const dwarf = debug.wip_nav.dwarf;1215 const dwarf = debug.wip_func.dwarf;
1115 if (debug.wip_nav.func == func) return;1216 if (debug.wip_func.func == func) return;
11161217
1117 const dl_nw = &debug.line_writer;1218 const dl_nw = &debug.line_writer;
1118 const dl_w = &dl_nw.interface;1219 const dl_w = &dl_nw.interface;
...@@ -1126,7 +1227,7 @@ pub const WipNav = struct {...@@ -1126,7 +1227,7 @@ pub const WipNav = struct {
1126 return;1227 return;
1127 }1228 }
11281229
1129 const old_owner_nav = zcu.funcInfo(debug.wip_nav.func).owner_nav;1230 const old_owner_nav = zcu.funcInfo(debug.wip_func.func).owner_nav;
1130 const old_inst_info = ip.getNav(old_owner_nav).srcInst(ip).resolveFull(ip).?;1231 const old_inst_info = ip.getNav(old_owner_nav).srcInst(ip).resolveFull(ip).?;
1131 const old_zf = zcu.fileByIndex(old_inst_info.file);1232 const old_zf = zcu.fileByIndex(old_inst_info.file);
1132 const new_inst_info = ip.getNav(new_owner_nav).srcInst(ip).resolveFull(ip).?;1233 const new_inst_info = ip.getNav(new_owner_nav).srcInst(ip).resolveFull(ip).?;
...@@ -1134,7 +1235,7 @@ pub const WipNav = struct {...@@ -1134,7 +1235,7 @@ pub const WipNav = struct {
1134 if (old_inst_info.file != new_inst_info.file) {1235 if (old_inst_info.file != new_inst_info.file) {
1135 const new_ui = dwarf.getUnit(new_zf.mod.?);1236 const new_ui = dwarf.getUnit(new_zf.mod.?);
1136 _, const new_fi =1237 _, const new_fi =
1137 try debug.wip_nav.unit.get(dwarf).getFile(zcu.gpa, new_ui, new_inst_info.file);1238 try debug.wip_func.unit.get(dwarf).getFile(zcu.gpa, new_ui, new_inst_info.file);
11381239
1139 try dl_w.writeByte(DW.LNS.set_file);1240 try dl_w.writeByte(DW.LNS.set_file);
1140 try dl_w.writeUleb128(@backingInt(new_fi));1241 try dl_w.writeUleb128(@backingInt(new_fi));
...@@ -1147,38 +1248,27 @@ pub const WipNav = struct {...@@ -1147,38 +1248,27 @@ pub const WipNav = struct {
1147 try dl_w.writeSleb128(new_src_line - old_src_line);1248 try dl_w.writeSleb128(new_src_line - old_src_line);
1148 }1249 }
11491250
1150 debug.wip_nav.func = func;1251 debug.wip_func.func = func;
1151 }
1152
1153 fn refFunc(debug: *Debug, func: InternPool.Index) link.EmitError!void {
1154 const dwarf = debug.wip_nav.dwarf;
1155 const fi = try dwarf.getFunc(debug.pt.zcu.funcInfo(func).owner_nav);
1156 try debug.wip_nav.dwarf.secOffset(
1157 &debug.info_writer,
1158 fi.get(dwarf).debug_info_ni.unwrap().?,
1159 0,
1160 );
1161 }1252 }
1162 };1253 };
11631254
1164 pub fn deinit(wip_nav: *WipNav) void {1255 pub fn deinit(wip_func: *WipFunc) void {
1165 wip_nav.fde_writer.deinit();1256 wip_func.fde_writer.deinit();
1166 wip_nav.* = undefined;1257 wip_func.* = undefined;
1167 }1258 }
11681259
1169 pub fn genDebugFrameHeader(wip_nav: *WipNav) link.Error!void {1260 pub fn genDebugFrameHeader(wip_func: *WipFunc) link.Error!void {
1170 wip_nav.genDebugFrameHeaderInner() catch |err| switch (err) {1261 wip_func.genDebugFrameHeaderInner() catch |err| switch (err) {
1171 error.WriteFailed => return wip_nav.dwarf.reportWriteError(&wip_nav.fde_writer),
1172 else => |e| return e,1262 else => |e| return e,
1263 error.WriteFailed => return wip_func.dwarf.reportWriteError(&wip_func.fde_writer),
1173 };1264 };
1174 }1265 }
1175 fn genDebugFrameHeaderInner(wip_nav: *WipNav) link.EmitError!void {1266 fn genDebugFrameHeaderInner(wip_func: *WipFunc) link.EmitError!void {
1176 assert(wip_nav.func != .none);1267 const dwarf = wip_func.dwarf;
1177 const dwarf = wip_nav.dwarf;1268 const df_nw = &wip_func.fde_writer;
1178 const df_nw = &wip_nav.fde_writer;
1179 const df_w = &df_nw.interface;1269 const df_w = &df_nw.interface;
1180 try dwarf.genUnitLength(df_w);1270 try dwarf.genUnitLength(df_w);
1181 switch (wip_nav.frame_format) {1271 switch (wip_func.frame_format) {
1182 .eh_frame => {1272 .eh_frame => {
1183 try df_w.writeInt(u32, undefined, dwarf.endian);1273 try df_w.writeInt(u32, undefined, dwarf.endian);
1184 {1274 {
...@@ -1187,51 +1277,50 @@ pub const WipNav = struct {...@@ -1187,51 +1277,50 @@ pub const WipNav = struct {
1187 if (dwarf.lf.cast(.elf2)) |elf| try elf.addReloc(1277 if (dwarf.lf.cast(.elf2)) |elf| try elf.addReloc(
1188 @bitCast(df_nw.ni),1278 @bitCast(df_nw.ni),
1189 offset,1279 offset,
1190 wip_nav.func_si,1280 wip_func.func_si,
1191 0,1281 0,
1192 .rel32(elf),1282 .rel32(elf),
1193 ) else unreachable;1283 ) else unreachable;
1194 }1284 }
1195 wip_nav.frame_func_length = .{ .offset = df_w.end, .size = .@"32" };1285 wip_func.frame_func_length = .{ .offset = df_w.end, .size = .@"32" };
1196 try df_w.writeInt(u32, undefined, dwarf.endian);1286 try df_w.writeInt(u32, undefined, dwarf.endian);
1197 try df_w.writeUleb128(0);1287 try df_w.writeUleb128(0);
1198 },1288 },
1199 .debug_frame => {1289 .debug_frame => {
1200 try dwarf.secOffset(df_nw, wip_nav.unit.get(dwarf).cie_ni.unwrap().?, 0);1290 try dwarf.secOffset(df_nw, wip_func.unit.get(dwarf).cie_ni.unwrap().?, 0);
1201 try dwarf.addrSym(df_nw, wip_nav.func_si, 0);1291 try dwarf.addrSym(df_nw, wip_func.func_si, 0);
1202 wip_nav.frame_func_length = .{ .offset = df_w.end, .size = dwarf.address_size };1292 wip_func.frame_func_length = .{ .offset = df_w.end, .size = dwarf.address_size };
1203 try dwarf.addrPlaceholder(df_w);1293 try dwarf.addrPlaceholder(df_w);
1204 },1294 },
1205 }1295 }
1206 }1296 }
12071297
1208 pub fn genDebugFrame(wip_nav: *WipNav, loc: u32, cfa: Cfa) link.Error!void {1298 pub fn genDebugFrame(wip_func: *WipFunc, loc: u32, cfa: Cfa) link.Error!void {
1209 return wip_nav.genDebugFrameInner(loc, cfa) catch |err| switch (err) {1299 return wip_func.genDebugFrameInner(loc, cfa) catch |err| switch (err) {
1210 error.WriteFailed => return wip_nav.dwarf.reportWriteError(&wip_nav.fde_writer),
1211 else => |e| return e,1300 else => |e| return e,
1301 error.WriteFailed => return wip_func.dwarf.reportWriteError(&wip_func.fde_writer),
1212 };1302 };
1213 }1303 }
1214 fn genDebugFrameInner(wip_nav: *WipNav, loc: u32, cfa: Cfa) link.EmitError!void {1304 fn genDebugFrameInner(wip_func: *WipFunc, loc: u32, cfa: Cfa) link.EmitError!void {
1215 assert(wip_nav.func != .none);
1216 const loc_cfa: Cfa = .{ .advance_loc = loc };1305 const loc_cfa: Cfa = .{ .advance_loc = loc };
1217 try loc_cfa.write(wip_nav);1306 try loc_cfa.write(wip_func);
1218 try cfa.write(wip_nav);1307 try cfa.write(wip_func);
1219 }1308 }
12201309
1221 pub fn finishDebugFrameFde(wip_nav: *WipNav, func_length: u64) void {1310 pub fn finishDebugFrameFde(wip_func: *WipFunc, func_length: u64) void {
1222 const dwarf = wip_nav.dwarf;1311 const dwarf = wip_func.dwarf;
1223 const df_w = &wip_nav.fde_writer.interface;1312 const df_w = &wip_func.fde_writer.interface;
1224 switch (wip_nav.frame_func_length.size) {1313 switch (wip_func.frame_func_length.size) {
1225 _ => unreachable,1314 _ => unreachable,
1226 .@"32" => std.mem.writeInt(1315 .@"32" => std.mem.writeInt(
1227 u32,1316 u32,
1228 df_w.buffered()[wip_nav.frame_func_length.offset..][0..4],1317 df_w.buffered()[wip_func.frame_func_length.offset..][0..4],
1229 @intCast(func_length),1318 @intCast(func_length),
1230 dwarf.endian,1319 dwarf.endian,
1231 ),1320 ),
1232 .@"64" => std.mem.writeInt(1321 .@"64" => std.mem.writeInt(
1233 u64,1322 u64,
1234 df_w.buffered()[wip_nav.frame_func_length.offset..][0..8],1323 df_w.buffered()[wip_func.frame_func_length.offset..][0..8],
1235 func_length,1324 func_length,
1236 dwarf.endian,1325 dwarf.endian,
1237 ),1326 ),
...@@ -1258,13 +1347,18 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf {...@@ -1258,13 +1347,18 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf {
1258 .globals = .empty,1347 .globals = .empty,
1259 .funcs = .empty,1348 .funcs = .empty,
1260 .decls = .empty,1349 .decls = .empty,
1261 .pending_decl = .{ .di = undefined, .instance_val = .none },1350 .pending_decl = .{ .di = undefined, .instance = .none },
12621351
1263 .debug_abbrev = .{1352 .debug_abbrev = .{
1264 .ni = .none,1353 .ni = .none,
1265 .end = 0,1354 .end = 0,
1266 .set = .empty,1355 .set = .empty,
1267 },1356 },
1357 .debug_addr = .{
1358 .ni = .none,
1359 .pending_index = 0,
1360 .map = .empty,
1361 },
1268 .frame = .{1362 .frame = .{
1269 .header = if (target.cpu.arch == .x86_64 and target.ofmt == .elf) header: {1363 .header = if (target.cpu.arch == .x86_64 and target.ofmt == .elf) header: {
1270 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });1364 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
...@@ -1308,18 +1402,19 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf {...@@ -1308,18 +1402,19 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf {
1308 },1402 },
1309 .debug_line_str = .{1403 .debug_line_str = .{
1310 .ni = .none,1404 .ni = .none,
1311 .offset = 0,1405 .end = 0,
1312 .map = .empty,1406 .map = .empty,
1313 },1407 },
1314 .debug_rnglists = .{},1408 .debug_rnglists = .{},
1315 .debug_str = .{1409 .debug_str = .{
1316 .ni = .none,1410 .ni = .none,
1317 .offset = 0,1411 .end = 0,
1318 .map = .empty,1412 .map = .empty,
1319 },1413 },
1320 .debug_str_offsets = .{1414 .debug_str_offsets = .{
1321 .ni = .none,1415 .ni = .none,
1322 .offset = 0,1416 .pending_index = 0,
1417 .map = .empty,
1323 },1418 },
1324 };1419 };
1325}1420}
...@@ -1333,8 +1428,10 @@ pub fn deinit(dwarf: *Dwarf) void {...@@ -1333,8 +1428,10 @@ pub fn deinit(dwarf: *Dwarf) void {
1333 dwarf.globals.deinit(gpa);1428 dwarf.globals.deinit(gpa);
1334 dwarf.funcs.deinit(gpa);1429 dwarf.funcs.deinit(gpa);
1335 dwarf.decls.deinit(gpa);1430 dwarf.decls.deinit(gpa);
1431 dwarf.debug_addr.map.deinit(gpa);
1336 dwarf.debug_line_str.map.deinit(gpa);1432 dwarf.debug_line_str.map.deinit(gpa);
1337 dwarf.debug_str.map.deinit(gpa);1433 dwarf.debug_str.map.deinit(gpa);
1434 dwarf.debug_str_offsets.map.deinit(gpa);
1338 dwarf.* = undefined;1435 dwarf.* = undefined;
1339}1436}
13401437
...@@ -1389,8 +1486,7 @@ pub fn getConst(dwarf: *Dwarf, pt: Zcu.PerThread, val: Value) link.Error!link.Co...@@ -1389,8 +1486,7 @@ pub fn getConst(dwarf: *Dwarf, pt: Zcu.PerThread, val: Value) link.Error!link.Co
13891486
1390pub fn getGlobal(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Global.Index {1487pub fn getGlobal(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Global.Index {
1391 const comp = dwarf.lf.comp;1488 const comp = dwarf.lf.comp;
1392 const gpa = comp.gpa;1489 const global_gop = try dwarf.globals.getOrPut(comp.gpa, nav);
1393 const global_gop = try dwarf.globals.getOrPut(gpa, nav);
1394 if (!global_gop.found_existing) global_gop.value_ptr.* = .{1490 if (!global_gop.found_existing) global_gop.value_ptr.* = .{
1395 .debug_info_ni = .none,1491 .debug_info_ni = .none,
1396 };1492 };
...@@ -1398,25 +1494,26 @@ pub fn getGlobal(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Global.Ind...@@ -1398,25 +1494,26 @@ pub fn getGlobal(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Global.Ind
1398 if (global_gop.value_ptr.debug_info_ni != .none) return gi;1494 if (global_gop.value_ptr.debug_info_ni != .none) return gi;
1399 const mod = comp.zcu.?.navFileScope(nav).mod.?;1495 const mod = comp.zcu.?.navFileScope(nav).mod.?;
1400 assert(!mod.strip);1496 assert(!mod.strip);
1401 const elf = dwarf.lf.cast(.elf2).?;1497 if (dwarf.lf.cast(.elf2)) |elf| {
1402 try elf.nodes.ensureUnusedCapacity(gpa, 1);1498 try elf.nodes.ensureUnusedCapacity(comp.gpa, 1);
1403 try elf.dwarf_globals.append(gpa, .{1499 try elf.dwarf_globals.append(comp.gpa, .{
1404 .debug_info_first_target_reloc = .none,1500 .debug_info_first_target_reloc = .none,
1405 .debug_info_first_node_reloc = .none,1501 .debug_info_first_node_reloc = .none,
1406 .debug_info_first_symbol_reloc = .none,1502 .debug_info_first_symbol_reloc = .none,
1407 });1503 });
1408 const unit = dwarf.getUnit(mod).get(dwarf);1504 const unit = dwarf.getUnit(mod).get(dwarf);
1409 global_gop.value_ptr.debug_info_ni = .wrap(elf.addNodeAssumeCapacity(1505 global_gop.value_ptr.debug_info_ni = .wrap(elf.addNodeAssumeCapacity(
1410 unit.debug_info_ni.unwrap().?.addFloatingChild(gpa, &elf.mf, .{1506 unit.debug_info_ni.unwrap().?.addFloatingChild(comp.gpa, &elf.mf, .{
1411 .enable_next_moved = true,1507 .enable_next_moved = true,
1412 }) catch |err| switch (err) {1508 }) catch |err| switch (err) {
1413 else => |e| return e,1509 else => |e| return e,
1414 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{1510 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{
1415 elf.mf.io_err.?,1511 elf.mf.io_err.?,
1416 }),1512 }),
1417 },1513 },
1418 .{ .global_debug_info = gi },1514 .{ .global_debug_info = gi },
1419 ));1515 ));
1516 } else unreachable;
1420 return gi;1517 return gi;
1421}1518}
1422pub fn getGlobalIfExists(dwarf: *Dwarf, nav: InternPool.Nav.Index) ?Global.Index {1519pub fn getGlobalIfExists(dwarf: *Dwarf, nav: InternPool.Nav.Index) ?Global.Index {
...@@ -1436,118 +1533,150 @@ pub fn getFunc(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Func.Index {...@@ -1436,118 +1533,150 @@ pub fn getFunc(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Func.Index {
1436 const fi: Func.Index = @fromBackingInt(@intCast(func_gop.index));1533 const fi: Func.Index = @fromBackingInt(@intCast(func_gop.index));
1437 if (func_gop.value_ptr.debug_info_ni != .none) return fi;1534 if (func_gop.value_ptr.debug_info_ni != .none) return fi;
1438 const mod = comp.zcu.?.navFileScope(nav).mod.?;1535 const mod = comp.zcu.?.navFileScope(nav).mod.?;
1439 const elf = dwarf.lf.cast(.elf2).?;1536 if (dwarf.lf.cast(.elf2)) |elf| {
1440 try elf.nodes.ensureUnusedCapacity(gpa, 1);1537 try elf.nodes.ensureUnusedCapacity(gpa, 1);
1441 try elf.dwarf_funcs.append(gpa, .{1538 try elf.dwarf_funcs.append(gpa, .{
1442 .frame_fde_first_symbol_reloc = .none,1539 .frame_fde_first_symbol_reloc = .none,
1443 .frame_fde_first_node_reloc = .none,1540 .frame_fde_first_node_reloc = .none,
1444 .debug_info_first_target_reloc = .none,1541 .debug_info_first_target_reloc = .none,
1445 .debug_info_first_symbol_reloc = .none,1542 .debug_info_first_symbol_reloc = .none,
1446 .debug_info_first_node_reloc = .none,1543 .debug_info_first_node_reloc = .none,
1447 .debug_line_first_symbol_reloc = .none,1544 .debug_line_first_symbol_reloc = .none,
1448 .debug_line_first_node_reloc = .none,1545 .debug_line_first_node_reloc = .none,
1449 });1546 });
1450 if (mod.strip) return fi;1547 if (mod.strip) return fi;
1451 const unit = dwarf.getUnit(mod).get(dwarf);1548 const unit = dwarf.getUnit(mod).get(dwarf);
1452 func_gop.value_ptr.debug_info_ni = .wrap(elf.addNodeAssumeCapacity(1549 func_gop.value_ptr.debug_info_ni = .wrap(elf.addNodeAssumeCapacity(
1453 unit.debug_info_ni.unwrap().?.addFloatingChild(gpa, &elf.mf, .{1550 unit.debug_info_ni.unwrap().?.addFloatingChild(gpa, &elf.mf, .{
1454 .enable_next_moved = true,1551 .enable_next_moved = true,
1455 }) catch |err| switch (err) {1552 }) catch |err| switch (err) {
1456 else => |e| return e,1553 else => |e| return e,
1457 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{1554 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{
1458 elf.mf.io_err.?,1555 elf.mf.io_err.?,
1459 }),1556 }),
1460 },1557 },
1461 .{ .func_debug_info = fi },1558 .{ .func_debug_info = fi },
1462 ));1559 ));
1560 } else unreachable;
1463 return fi;1561 return fi;
1464}1562}
1465pub fn getFuncIfExists(dwarf: *Dwarf, nav: InternPool.Nav.Index) ?Func.Index {1563pub fn getFuncIfExists(dwarf: *Dwarf, nav: InternPool.Nav.Index) ?Func.Index {
1466 return @fromBackingInt(@intCast(dwarf.funcs.getIndex(nav) orelse return null));1564 return @fromBackingInt(@intCast(dwarf.funcs.getIndex(nav) orelse return null));
1467}1565}
14681566
1469fn getDeclInst(dwarf: *Dwarf, val: InternPool.Index) ?InternPool.TrackedInst.Index {1567fn getConstDeclInst(dwarf: *Dwarf, @"const": InternPool.Index) union(enum) {
1470 const ip = &dwarf.lf.comp.zcu.?.intern_pool;1568 @"const": InternPool.Index,
1471 switch (ip.indexToKey(val)) {1569 src_inst: InternPool.TrackedInst.Index,
1570} {
1571 const zcu = dwarf.lf.comp.zcu.?;
1572 const ip = &zcu.intern_pool;
1573 switch (ip.indexToKey(@"const")) {
1472 else => unreachable,1574 else => unreachable,
1473 .struct_type, .union_type, .enum_type, .opaque_type => |container, tag| switch (container) {1575 .struct_type, .union_type, .enum_type, .opaque_type => |container, tag| switch (container) {
1474 .declared => |declared| switch (declared.captures.owned.len) {1576 .declared => |declared| switch (declared.captures.owned.len) {
1475 0 => return null,1577 0 => return .{ .@"const" = @"const" },
1476 else => switch (tag) {1578 else => return .{ .src_inst = src_inst: switch (tag) {
1477 else => unreachable,1579 else => unreachable,
1478 .struct_type => {1580 .struct_type => {
1479 const loaded_struct = ip.loadStructType(val);1581 const loaded_struct = ip.loadStructType(@"const");
1480 return ip.getNav(loaded_struct.name_nav.unwrap() orelse1582 break :src_inst ip.getNav(loaded_struct.name_nav.unwrap() orelse
1481 return loaded_struct.zir_index).srcInst(ip);1583 break :src_inst loaded_struct.zir_index).srcInst(ip);
1482 },1584 },
1483 .union_type => {1585 .union_type => {
1484 const loaded_union = ip.loadUnionType(val);1586 const loaded_union = ip.loadUnionType(@"const");
1485 return ip.getNav(loaded_union.name_nav.unwrap() orelse1587 break :src_inst ip.getNav(loaded_union.name_nav.unwrap() orelse
1486 return loaded_union.zir_index).srcInst(ip);1588 break :src_inst loaded_union.zir_index).srcInst(ip);
1487 },1589 },
1488 .enum_type => {1590 .enum_type => {
1489 const loaded_enum = ip.loadEnumType(val);1591 const loaded_enum = ip.loadEnumType(@"const");
1490 return ip.getNav(loaded_enum.name_nav.unwrap() orelse1592 break :src_inst ip.getNav(loaded_enum.name_nav.unwrap() orelse
1491 return loaded_enum.zir_index.unwrap().?).srcInst(ip);1593 break :src_inst loaded_enum.zir_index.unwrap().?).srcInst(ip);
1492 },1594 },
1493 .opaque_type => {1595 .opaque_type => {
1494 const loaded_opaque = ip.loadOpaqueType(val);1596 const loaded_opaque = ip.loadOpaqueType(@"const");
1495 return ip.getNav(loaded_opaque.name_nav.unwrap() orelse1597 break :src_inst ip.getNav(loaded_opaque.name_nav.unwrap() orelse
1496 return loaded_opaque.zir_index).srcInst(ip);1598 break :src_inst loaded_opaque.zir_index).srcInst(ip);
1497 },1599 },
1498 },1600 } },
1499 },1601 },
1500 .reified => |reified| {1602 .reified => |reified| {
1501 assert(reified.zir_index.resolve(ip).? != .main_struct_inst);1603 assert(reified.zir_index.resolve(ip).? != .main_struct_inst);
1502 return reified.zir_index;1604 return .{ .src_inst = reified.zir_index };
1503 },1605 },
1504 .generated_union_tag => unreachable,1606 .generated_union_tag => unreachable,
1505 },1607 },
1506 .func => |func| return ip.getNav(switch (func.generic_owner) {1608 .func => |func| switch (func.generic_owner) {
1507 .none => func.owner_nav,1609 else => |generic_owner| return .{ .@"const" = generic_owner },
1508 else => |generic_owner| ip.indexToKey(generic_owner).func.owner_nav,1610 .none => {
1509 }).srcInst(ip),1611 const owner_nav = ip.getNav(func.owner_nav);
1612 return switch (Type.fromInterned(
1613 ip.namespacePtr(owner_nav.analysis.?.namespace).owner_type,
1614 ).getCaptures(zcu).len) {
1615 0 => .{ .@"const" = @"const" },
1616 else => .{ .src_inst = owner_nav.srcInst(ip) },
1617 };
1618 },
1619 },
1620 }
1621}
1622pub fn getConstDecl(
1623 dwarf: *Dwarf,
1624 pt: Zcu.PerThread,
1625 instance_const: InternPool.Index,
1626) link.Error!link.MappedFile.Node.Index {
1627 switch (dwarf.getConstDeclInst(instance_const)) {
1628 .@"const" => |@"const"| {
1629 const cpi = try dwarf.getConst(pt, .fromInterned(@"const"));
1630 return Const.get(cpi, dwarf).debug_info_ni.unwrap().?;
1631 },
1632 .src_inst => |src_inst| return dwarf.getDecl(pt, src_inst, .{ .@"const" = instance_const }),
1510 }1633 }
1511}1634}
1512pub fn getDecl(1635pub fn getGlobalDecl(
1636 dwarf: *Dwarf,
1637 pt: Zcu.PerThread,
1638 instance_global: InternPool.Nav.Index,
1639) link.Error!link.MappedFile.Node.Index {
1640 const ip = &pt.zcu.intern_pool;
1641 return dwarf.getDecl(pt, ip.getNav(instance_global).srcInst(ip), .{ .global = instance_global });
1642}
1643fn getDecl(
1513 dwarf: *Dwarf,1644 dwarf: *Dwarf,
1514 pt: Zcu.PerThread,1645 pt: Zcu.PerThread,
1515 instance_val: InternPool.Index,1646 inst: InternPool.TrackedInst.Index,
1647 instance: Decl.Instance,
1516) link.Error!link.MappedFile.Node.Index {1648) link.Error!link.MappedFile.Node.Index {
1517 assert(dwarf.pending_decl.instance_val == .none);
1518 const comp = dwarf.lf.comp;1649 const comp = dwarf.lf.comp;
1519 const gpa = comp.gpa;1650 const gpa = comp.gpa;
1520 const zcu = pt.zcu;1651 const zcu = pt.zcu;
1521 const ip = &zcu.intern_pool;1652 const ip = &zcu.intern_pool;
1522 const inst = dwarf.getDeclInst(instance_val) orelse {
1523 const cpi = try dwarf.getConst(pt, .fromInterned(instance_val));
1524 return Const.get(cpi, dwarf).debug_info_ni.unwrap().?;
1525 };
1526 const decl_gop = try dwarf.decls.getOrPut(gpa, inst);1653 const decl_gop = try dwarf.decls.getOrPut(gpa, inst);
1527 if (!decl_gop.found_existing) decl_gop.value_ptr.* = .{1654 if (!decl_gop.found_existing) decl_gop.value_ptr.* = .{
1528 .debug_info_ni = .none,1655 .debug_info_ni = .none,
1529 };1656 };
1530 const di: Decl.Index = @fromBackingInt(@intCast(decl_gop.index));1657 const di: Decl.Index = @fromBackingInt(@intCast(decl_gop.index));
1531 if (decl_gop.value_ptr.debug_info_ni.unwrap()) |debug_info_ni| return debug_info_ni;1658 if (decl_gop.value_ptr.debug_info_ni.unwrap()) |debug_info_ni| return debug_info_ni;
1532 dwarf.pending_decl = .{ .di = di, .instance_val = instance_val };1659 dwarf.pending_decl = .{ .di = di, .instance = instance };
1533 const elf = dwarf.lf.cast(.elf2).?;1660 const debug_info_ni = if (dwarf.lf.cast(.elf2)) |elf| debug_info_ni: {
1534 try elf.nodes.ensureUnusedCapacity(gpa, 1);1661 try elf.nodes.ensureUnusedCapacity(gpa, 1);
1535 try elf.dwarf_decls.putNoClobber(gpa, di, .{1662 try elf.dwarf_decls.putNoClobber(gpa, di, .{
1536 .debug_info_first_target_reloc = .none,1663 .debug_info_first_target_reloc = .none,
1537 .debug_info_first_node_reloc = .none,1664 .debug_info_first_node_reloc = .none,
1538 });1665 });
1539 const unit = dwarf.getUnit(zcu.fileByIndex(di.srcInst(dwarf).resolveFile(ip)).mod.?).get(dwarf);1666 const unit = dwarf.getUnit(zcu.fileByIndex(di.srcInst(dwarf).resolveFile(ip)).mod.?).get(dwarf);
1540 const debug_info_ni = elf.addNodeAssumeCapacity(1667 const debug_info_ni = elf.addNodeAssumeCapacity(
1541 unit.debug_info_ni.unwrap().?.addFloatingChild(gpa, &elf.mf, .{1668 unit.debug_info_ni.unwrap().?.addFloatingChild(gpa, &elf.mf, .{
1542 .enable_next_moved = true,1669 .enable_next_moved = true,
1543 }) catch |err| switch (err) {1670 }) catch |err| switch (err) {
1544 else => |e| return e,1671 else => |e| return e,
1545 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{1672 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{
1546 elf.mf.io_err.?,1673 elf.mf.io_err.?,
1547 }),1674 }),
1548 },1675 },
1549 .{ .decl_debug_info = di },1676 .{ .decl_debug_info = di },
1550 );1677 );
1678 break :debug_info_ni debug_info_ni;
1679 } else unreachable;
1551 decl_gop.value_ptr.debug_info_ni = .wrap(debug_info_ni);1680 decl_gop.value_ptr.debug_info_ni = .wrap(debug_info_ni);
1552 return debug_info_ni;1681 return debug_info_ni;
1553}1682}
...@@ -1561,7 +1690,7 @@ pub fn unitLengthSize(dwarf: *Dwarf) usize {...@@ -1561,7 +1690,7 @@ pub fn unitLengthSize(dwarf: *Dwarf) usize {
1561 .@"64" => 4 + 8,1690 .@"64" => 4 + 8,
1562 };1691 };
1563}1692}
1564pub fn genUnitLength(dwarf: *Dwarf, w: *std.Io.Writer) std.Io.Writer.Error!void {1693fn genUnitLength(dwarf: *Dwarf, w: *std.Io.Writer) std.Io.Writer.Error!void {
1565 switch (dwarf.format) {1694 switch (dwarf.format) {
1566 .@"32" => try w.writeInt(u32, undefined, dwarf.endian),1695 .@"32" => try w.writeInt(u32, undefined, dwarf.endian),
1567 .@"64" => {1696 .@"64" => {
...@@ -1582,6 +1711,24 @@ pub fn genUnitPadding(dwarf: *Dwarf, w: *std.Io.Writer) std.Io.Writer.Error!void...@@ -1582,6 +1711,24 @@ pub fn genUnitPadding(dwarf: *Dwarf, w: *std.Io.Writer) std.Io.Writer.Error!void
1582 try w.writeInt(u16, 0, dwarf.endian);1711 try w.writeInt(u16, 0, dwarf.endian);
1583}1712}
15841713
1714pub fn genDebugAddrHeader(dwarf: *Dwarf, dah_w: *std.Io.Writer) std.Io.Writer.Error!void {
1715 try dwarf.genUnitLength(dah_w);
1716 try dah_w.writeInt(u16, 5, dwarf.endian);
1717 try dah_w.writeAll(&.{ @backingInt(dwarf.address_size), 0 });
1718 assert(dah_w.end == Addr.tableOffset(dwarf));
1719}
1720
1721pub fn genPendingDebugAddr(dwarf: *Dwarf, da_nw: *link.MappedFile.Node.Writer) link.Error!void {
1722 da_nw.interface.end = dwarf.debug_addr.size(dwarf);
1723 for (dwarf.debug_addr.map.keys()[dwarf.debug_addr.pending_index..]) |si| {
1724 dwarf.addrSym(da_nw, si, 0) catch |err| switch (err) {
1725 else => |e| return e,
1726 error.WriteFailed => return dwarf.reportWriteError(da_nw),
1727 };
1728 dwarf.debug_addr.pending_index += 1;
1729 }
1730}
1731
1585pub const EhFrameHdr = extern struct {1732pub const EhFrameHdr = extern struct {
1586 version: u8,1733 version: u8,
1587 eh_frame_ptr_enc: std.dwarf.EH.PE,1734 eh_frame_ptr_enc: std.dwarf.EH.PE,
...@@ -1637,11 +1784,7 @@ pub fn genDebugFrameCie(...@@ -1637,11 +1784,7 @@ pub fn genDebugFrameCie(
1637 const Register = @import("../codegen/x86_64/bits.zig").Register;1784 const Register = @import("../codegen/x86_64/bits.zig").Register;
1638 switch (format) {1785 switch (format) {
1639 .eh_frame => try df_w.writeAll("zR\x00"),1786 .eh_frame => try df_w.writeAll("zR\x00"),
1640 .debug_frame => {1787 .debug_frame => try df_w.writeAll("\x00" ++ .{ @backingInt(dwarf.address_size), 0 }),
1641 try df_w.writeAll("\x00");
1642 try df_w.writeByte(@backingInt(dwarf.address_size));
1643 try df_w.writeByte(0);
1644 },
1645 }1788 }
1646 try df_w.writeUleb128(dwarf.frame.header.code_alignment_factor);1789 try df_w.writeUleb128(dwarf.frame.header.code_alignment_factor);
1647 try df_w.writeSleb128(dwarf.frame.header.data_alignment_factor);1790 try df_w.writeSleb128(dwarf.frame.header.data_alignment_factor);
...@@ -1688,28 +1831,29 @@ pub fn genDebugInfoHeader(...@@ -1688,28 +1831,29 @@ pub fn genDebugInfoHeader(
1688 if (!unit.alive) return dwarf.genUnitPadding(dih_w);1831 if (!unit.alive) return dwarf.genUnitPadding(dih_w);
1689 try dwarf.genUnitLength(dih_w);1832 try dwarf.genUnitLength(dih_w);
1690 try dih_w.writeInt(u16, 5, dwarf.endian);1833 try dih_w.writeInt(u16, 5, dwarf.endian);
1691 try dih_w.writeByte(DW.UT.compile);1834 try dih_w.writeAll(&.{ DW.UT.compile, @backingInt(dwarf.address_size) });
1692 try dih_w.writeByte(@backingInt(dwarf.address_size));
1693 try dwarf.secOffset(dih_nw, dwarf.debug_abbrev.ni.unwrap().?, 0);1835 try dwarf.secOffset(dih_nw, dwarf.debug_abbrev.ni.unwrap().?, 0);
1694 const compile_unit_offset = dih_w.end;1836 const compile_unit_offset = dih_w.end;
1695 try dwarf.abbrevCode(dih_nw, .compile_unit);1837 try dwarf.abbrevCode(dih_nw, .compile_unit);
1696 try dih_w.writeByte(DW.LANG.Zig);1838 try dih_w.writeByte(DW.LANG.Zig);
1697 try dwarf.strp(&dwarf.debug_str, dih_nw, "zig " ++ @import("build_options").version);
1698 const root_dir_path = try mod.root.toAbsolute(&comp.dirs, comp.gpa);
1699 defer comp.gpa.free(root_dir_path);
1700 try dwarf.strp(&dwarf.debug_line_str, dih_nw, root_dir_path);
1701 try dwarf.strp(&dwarf.debug_line_str, dih_nw, mod.root_src_path);
1702 try dwarf.secOffset(1839 try dwarf.secOffset(
1703 dih_nw,1840 dih_nw,
1704 dwarf.getUnit(zcu.root_mod).get(dwarf).debug_info_header_ni.unwrap().?,1841 dwarf.getUnit(zcu.root_mod).get(dwarf).debug_info_header_ni.unwrap().?,
1705 compile_unit_offset,1842 compile_unit_offset,
1706 );1843 );
1707 try dwarf.secOffset(dih_nw, unit.debug_line_header_ni.unwrap().?, 0);1844 try dwarf.secOffset(dih_nw, unit.debug_line_header_ni.unwrap().?, 0);
1708 try dwarf.secOffset(dih_nw, unit.debug_rnglists_ni.unwrap().?, Rnglists.offsetsTableOffset(dwarf));1845 try dwarf.secOffset(dih_nw, dwarf.debug_addr.ni.unwrap().?, Addr.tableOffset(dwarf));
1846 try dwarf.secOffset(dih_nw, unit.debug_rnglists_ni.unwrap().?, Rnglists.tableOffset(dwarf));
1847 try dwarf.secOffset(dih_nw, dwarf.debug_str_offsets.ni.unwrap().?, StrOffsets.tableOffset(dwarf));
1848 try dwarf.strx1(dih_nw, "zig " ++ @import("build_options").version);
1849 const root_dir_path = try mod.root.toAbsolute(&comp.dirs, comp.gpa);
1850 defer comp.gpa.free(root_dir_path);
1851 try dwarf.strp(&dwarf.debug_line_str, dih_nw, root_dir_path);
1852 try dwarf.strp(&dwarf.debug_line_str, dih_nw, mod.root_src_path);
1709 try dih_w.writeUleb128(0);1853 try dih_w.writeUleb128(0);
1710 const module_offset = dih_w.end;1854 const module_offset = dih_w.end;
1711 try dwarf.abbrevCode(dih_nw, .module);1855 try dwarf.abbrevCode(dih_nw, .module);
1712 try dwarf.strp(&dwarf.debug_str, dih_nw, mod.fully_qualified_name);1856 try dwarf.strx(dih_nw, mod.fully_qualified_name);
1713 try dih_w.writeUleb128(0);1857 try dih_w.writeUleb128(0);
1714 try dwarf.genModuleDependency(1858 try dwarf.genModuleDependency(
1715 dih_nw,1859 dih_nw,
...@@ -1735,7 +1879,7 @@ fn genModuleDependency(...@@ -1735,7 +1879,7 @@ fn genModuleDependency(
1735 const dep_unit = dwarf.getUnit(dep).get(dwarf);1879 const dep_unit = dwarf.getUnit(dep).get(dwarf);
1736 if (!dep_unit.alive) return;1880 if (!dep_unit.alive) return;
1737 try dwarf.abbrevCode(di_nw, .module_dependency);1881 try dwarf.abbrevCode(di_nw, .module_dependency);
1738 try dwarf.strp(&dwarf.debug_str, di_nw, name);1882 try dwarf.strx(di_nw, name);
1739 try dwarf.secOffset(di_nw, dep_unit.debug_info_header_ni.unwrap().?, module_offset);1883 try dwarf.secOffset(di_nw, dep_unit.debug_info_header_ni.unwrap().?, module_offset);
1740}1884}
17411885
...@@ -1779,8 +1923,7 @@ pub fn genDebugLineHeader(...@@ -1779,8 +1923,7 @@ pub fn genDebugLineHeader(
1779 const dlh_w = &dlh_nw.interface;1923 const dlh_w = &dlh_nw.interface;
1780 try dwarf.genUnitLength(dlh_w);1924 try dwarf.genUnitLength(dlh_w);
1781 try dlh_w.writeInt(u16, 5, dwarf.endian);1925 try dlh_w.writeInt(u16, 5, dwarf.endian);
1782 try dlh_w.writeByte(@backingInt(dwarf.address_size));1926 try dlh_w.writeAll(&.{ @backingInt(dwarf.address_size), 0 });
1783 try dlh_w.writeByte(0);
1784 const header_length_offset = dlh_w.end;1927 const header_length_offset = dlh_w.end;
1785 switch (dwarf.format) {1928 switch (dwarf.format) {
1786 .@"32" => try dlh_w.writeInt(u32, undefined, dwarf.endian),1929 .@"32" => try dlh_w.writeInt(u32, undefined, dwarf.endian),
...@@ -1852,11 +1995,7 @@ pub fn genDebugLineHeader(...@@ -1852,11 +1995,7 @@ pub fn genDebugLineHeader(
1852 }1995 }
1853 try dlh_w.writeInt(i64, @truncate(zf.stat.mtime.nanoseconds), dwarf.endian);1996 try dlh_w.writeInt(i64, @truncate(zf.stat.mtime.nanoseconds), dwarf.endian);
1854 try dlh_w.writeInt(u64, zf.stat.size, dwarf.endian);1997 try dlh_w.writeInt(u64, zf.stat.size, dwarf.endian);
1855 try dwarf.strp(1998 try dwarf.strp(&dwarf.debug_line_str, dlh_nw, if (zf.is_builtin) zf.source.? else "");
1856 &dwarf.debug_line_str,
1857 dlh_nw,
1858 if (zf.is_builtin) zf.source.? else "",
1859 );
1860 }1999 }
1861 switch (dwarf.format) {2000 switch (dwarf.format) {
1862 .@"32" => std.mem.writeInt(2001 .@"32" => std.mem.writeInt(
...@@ -1915,10 +2054,9 @@ pub fn genDebugRnglistsHeader(...@@ -1915,10 +2054,9 @@ pub fn genDebugRnglistsHeader(
1915 const drh_w = &drh_nw.interface;2054 const drh_w = &drh_nw.interface;
1916 try dwarf.genUnitLength(drh_w);2055 try dwarf.genUnitLength(drh_w);
1917 try drh_w.writeInt(u16, 5, dwarf.endian);2056 try drh_w.writeInt(u16, 5, dwarf.endian);
1918 try drh_w.writeByte(@backingInt(dwarf.address_size));2057 try drh_w.writeAll(&.{ @backingInt(dwarf.address_size), 0 });
1919 try drh_w.writeByte(0);
1920 try drh_w.writeInt(u32, 1, dwarf.endian);2058 try drh_w.writeInt(u32, 1, dwarf.endian);
1921 assert(drh_w.end == Rnglists.offsetsTableOffset(dwarf));2059 assert(drh_w.end == Rnglists.tableOffset(dwarf));
1922 switch (dwarf.format) {2060 switch (dwarf.format) {
1923 .@"32" => try drh_w.writeInt(u32, 4, dwarf.endian),2061 .@"32" => try drh_w.writeInt(u32, 4, dwarf.endian),
1924 .@"64" => try drh_w.writeInt(u64, 8, dwarf.endian),2062 .@"64" => try drh_w.writeInt(u64, 8, dwarf.endian),
...@@ -1927,7 +2065,7 @@ pub fn genDebugRnglistsHeader(...@@ -1927,7 +2065,7 @@ pub fn genDebugRnglistsHeader(
1927 try drh_w.writeByte(DW.RLE.end_of_list);2065 try drh_w.writeByte(DW.RLE.end_of_list);
1928}2066}
19292067
1930pub fn genDebugRnglists(2068pub fn genDebugRnglistsRange(
1931 dwarf: *Dwarf,2069 dwarf: *Dwarf,
1932 unit: *Unit,2070 unit: *Unit,
1933 dr_nw: *link.MappedFile.Node.Writer,2071 dr_nw: *link.MappedFile.Node.Writer,
...@@ -1936,74 +2074,396 @@ pub fn genDebugRnglists(...@@ -1936,74 +2074,396 @@ pub fn genDebugRnglists(
1936) link.EmitError!void {2074) link.EmitError!void {
1937 const dr_w = &dr_nw.interface;2075 const dr_w = &dr_nw.interface;
1938 dr_w.end = unit.debug_rnglists_end;2076 dr_w.end = unit.debug_rnglists_end;
1939 try dr_w.writeByte(DW.RLE.start_length);2077 try dr_w.writeByte(DW.RLE.startx_length);
1940 try dwarf.addrSym(dr_nw, func_si, 0);2078 try dwarf.addrxSym(dr_w, func_si);
1941 try dr_w.writeUleb128(func_length);2079 try dr_w.writeUleb128(func_length);
1942 unit.debug_rnglists_end = dr_w.end;2080 unit.debug_rnglists_end = dr_w.end;
1943 try dr_w.writeByte(DW.RLE.end_of_list);2081 try dr_w.writeByte(DW.RLE.end_of_list);
1944}2082}
19452083
1946pub fn updateComptimeNav(2084pub fn genDebugStrOffsetsHeader(dwarf: *Dwarf, dsoh_w: *std.Io.Writer) std.Io.Writer.Error!void {
2085 try dwarf.genUnitLength(dsoh_w);
2086 try dsoh_w.writeInt(u16, 5, dwarf.endian);
2087 try dsoh_w.writeInt(u16, 0, dwarf.endian);
2088 assert(dsoh_w.end == StrOffsets.tableOffset(dwarf));
2089}
2090
2091pub fn genPendingDebugStrOffsets(dwarf: *Dwarf, dso_nw: *link.MappedFile.Node.Writer) link.Error!void {
2092 const debug_str_ni = dwarf.debug_str.ni.unwrap().?;
2093 dso_nw.interface.end = dwarf.debug_str_offsets.size(dwarf);
2094 for (dwarf.debug_str_offsets.map.keys()[dwarf.debug_str_offsets.pending_index..]) |offset| {
2095 dwarf.secOffset(dso_nw, debug_str_ni, offset) catch |err| switch (err) {
2096 else => |e| return e,
2097 error.WriteFailed => return dwarf.reportWriteError(dso_nw),
2098 };
2099 dwarf.debug_str_offsets.pending_index += 1;
2100 }
2101}
2102
2103pub fn updateExtern(
2104 dwarf: *Dwarf,
2105 pt: Zcu.PerThread,
2106 di_nw: *link.MappedFile.Node.Writer,
2107 arch: std.Target.Cpu.Arch,
2108 si: link.File.SymbolId,
2109 global: InternPool.Nav.Index,
2110) link.Error!void {
2111 dwarf.updateExternInner(pt, di_nw, arch, si, global) catch |err| switch (err) {
2112 else => |e| return e,
2113 error.WriteFailed => return dwarf.reportWriteError(di_nw),
2114 };
2115}
2116fn updateExternInner(
2117 dwarf: *Dwarf,
2118 pt: Zcu.PerThread,
2119 di_nw: *link.MappedFile.Node.Writer,
2120 arch: std.Target.Cpu.Arch,
2121 si: link.File.SymbolId,
2122 global: InternPool.Nav.Index,
2123) link.EmitError!void {
2124 const zcu = pt.zcu;
2125 const ip = &zcu.intern_pool;
2126 const nav = ip.getNav(global);
2127 log.debug("updateExtern({f})", .{nav.fqn.fmt(ip)});
2128 const nav_align, const nav_const, const nav_threadlocal, const nav_extern = nav_resolved: {
2129 const nav_resolved = nav.resolved.?;
2130 break :nav_resolved .{
2131 nav_resolved.@"align",
2132 nav_resolved.@"const",
2133 nav_resolved.@"threadlocal",
2134 ip.indexToKey(nav_resolved.value).@"extern",
2135 };
2136 };
2137 const inst_info = nav.srcInst(ip).resolveFull(ip).?;
2138 const decl = switch (nav_extern.source) {
2139 .builtin => undefined,
2140 .syntax => zcu.fileByIndex(inst_info.file).zir.?.getDeclaration(inst_info.inst),
2141 };
2142 const maybe_func_type = switch (ip.indexToKey(nav_extern.ty)) {
2143 .func_type => |func_type| func_type,
2144 else => null,
2145 };
2146 const is_empty = if (maybe_func_type) |func_type| func_type.param_types.len == 0 and
2147 !func_type.is_var_args else undefined;
2148 const di_w = &di_nw.interface;
2149 switch (nav_extern.source) {
2150 .builtin => {
2151 try dwarf.abbrevCode(di_nw, if (maybe_func_type) |_|
2152 if (is_empty) .builtin_extern_empty_func else .builtin_extern_func
2153 else
2154 .builtin_extern_var);
2155 try dwarf.refType(pt, di_nw, .fromInterned(zcu.fileRootType(inst_info.file)));
2156 },
2157 .syntax => if (maybe_func_type) |_| {
2158 try dwarf.abbrevCode(
2159 di_nw,
2160 if (is_empty) .decl_extern_empty_func else .decl_extern_func,
2161 );
2162 try dwarf.refType(pt, di_nw, .fromInterned(zcu.fileRootType(inst_info.file)));
2163 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
2164 try di_w.writeUleb128(decl.src_column + 1);
2165 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2166 try dwarf.strx(di_nw, nav.name.toSlice(ip));
2167 } else {
2168 try dwarf.abbrevCode(di_nw, .decl_var);
2169 try dwarf.refType(pt, di_nw, .fromInterned(zcu.fileRootType(inst_info.file)));
2170 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
2171 try di_w.writeUleb128(decl.src_column + 1);
2172 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2173 try dwarf.strx(di_nw, nav.name.toSlice(ip));
2174 },
2175 }
2176 try dwarf.strx(di_nw, nav_extern.name.toSlice(ip));
2177 if (maybe_func_type) |func_type| {
2178 try dwarf.refType(pt, di_nw, .fromInterned(func_type.return_type));
2179 try dwarf.addrSym(di_nw, si, 0);
2180 try di_w.writeByte(@intFromBool(Type.fromInterned(func_type.return_type).isNoReturn(zcu)));
2181 for (func_type.param_types.get(ip)) |param_type| {
2182 try dwarf.abbrevCode(di_nw, .extern_param);
2183 try dwarf.refType(pt, di_nw, .fromInterned(param_type));
2184 }
2185 if (func_type.is_var_args) try dwarf.abbrevCode(di_nw, .is_var_args);
2186 if (!is_empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
2187 } else {
2188 const addr: Loc = .{ .addr_sym = .{ .si = si } };
2189 const loc: Loc = if (nav_threadlocal) switch (arch) {
2190 .x86_64 => .{ .form_tls_address = &addr },
2191 else => unreachable,
2192 } else addr;
2193 const type_offset = di_w.end;
2194 if (nav_const)
2195 try dwarf.secOffsetPlaceholder(di_w)
2196 else
2197 try dwarf.refType(pt, di_nw, .fromInterned(nav_extern.ty));
2198 try dwarf.exprLoc(di_nw, loc);
2199 try di_w.writeUleb128(nav_align.toByteUnits() orelse
2200 Type.fromInterned(nav_extern.ty).abiAlignment(zcu).toByteUnits().?);
2201 switch (nav_extern.source) {
2202 .builtin => {},
2203 .syntax => try di_w.writeByte(@intFromBool(decl.linkage != .normal)),
2204 }
2205 if (nav_const) {
2206 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
2207 try dwarf.abbrevCode(di_nw, .is_const);
2208 try dwarf.refType(pt, di_nw, .fromInterned(nav_extern.ty));
2209 }
2210 }
2211 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());
2212}
2213
2214pub fn updateGlobal(
2215 dwarf: *Dwarf,
2216 pt: Zcu.PerThread,
2217 di_nw: *link.MappedFile.Node.Writer,
2218 arch: std.Target.Cpu.Arch,
2219 si: link.File.SymbolId,
2220 global: InternPool.Nav.Index,
2221) link.Error!void {
2222 const ip = &pt.zcu.intern_pool;
2223 log.debug("updateGlobal({f})", .{ip.getNav(global).fqn.fmt(ip)});
2224 dwarf.updateGlobalInner(pt, di_nw, arch, si, global) catch |err| switch (err) {
2225 else => |e| return e,
2226 error.WriteFailed => return dwarf.reportWriteError(di_nw),
2227 };
2228}
2229fn updateGlobalInner(
2230 dwarf: *Dwarf,
2231 pt: Zcu.PerThread,
2232 di_nw: *link.MappedFile.Node.Writer,
2233 arch: std.Target.Cpu.Arch,
2234 si: link.File.SymbolId,
2235 global: InternPool.Nav.Index,
2236) link.EmitError!void {
2237 const zcu = pt.zcu;
2238 const ip = &zcu.intern_pool;
2239 const nav = ip.getNav(global);
2240 const nav_ty: Type, const nav_align, const nav_const, const nav_threadlocal = nav_resolved: {
2241 const nav_resolved = nav.resolved.?;
2242 break :nav_resolved .{
2243 .fromInterned(nav_resolved.type),
2244 nav_resolved.@"align",
2245 nav_resolved.@"const",
2246 nav_resolved.@"threadlocal",
2247 };
2248 };
2249 const inst_info = nav.srcInst(ip).resolveFull(ip).?;
2250 const decl = zcu.fileByIndex(inst_info.file).zir.?.getDeclaration(inst_info.inst);
2251 switch (decl.kind) {
2252 .unnamed_test, .@"test", .decltest, .@"comptime" => unreachable,
2253 .@"const" => assert(nav_const),
2254 .@"var" => assert(!nav_const),
2255 }
2256 const parent_ty: Type = .fromInterned(ip.namespacePtr(nav.analysis.?.namespace).owner_type);
2257 const di_w = &di_nw.interface;
2258 if (parent_ty.getCaptures(zcu).len > 0) {
2259 try dwarf.abbrevCode(di_nw, .decl_instance_var);
2260 try dwarf.refType(pt, di_nw, parent_ty);
2261 try dwarf.secOffset(di_nw, try dwarf.getGlobalDecl(pt, global), 0);
2262 } else {
2263 const parent_ni = try dwarf.getConstDecl(pt, parent_ty.toIntern());
2264 try dwarf.abbrevCode(di_nw, .decl_var);
2265 try dwarf.secOffset(di_nw, parent_ni, 0);
2266 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
2267 try di_w.writeUleb128(decl.src_column + 1);
2268 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2269 try dwarf.strx(di_nw, nav.name.toSlice(ip));
2270 }
2271 try dwarf.strx(di_nw, switch (decl.linkage) {
2272 .normal => nav.fqn,
2273 .@"extern" => unreachable,
2274 .@"export" => nav.name,
2275 }.toSlice(ip));
2276 const addr: Loc = .{ .addr_sym = .{ .si = si } };
2277 const loc: Loc = if (nav_threadlocal) switch (arch) {
2278 .x86_64 => .{ .form_tls_address = &addr },
2279 else => unreachable,
2280 } else addr;
2281 const type_offset = di_w.end;
2282 if (nav_const) try dwarf.secOffsetPlaceholder(di_w) else try dwarf.refType(pt, di_nw, nav_ty);
2283 try dwarf.exprLoc(di_nw, loc);
2284 try di_w.writeUleb128(nav_align.toByteUnits() orelse nav_ty.abiAlignment(zcu).toByteUnits().?);
2285 try di_w.writeByte(@intFromBool(decl.linkage != .normal));
2286 if (nav_const) {
2287 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
2288 try dwarf.abbrevCode(di_nw, .is_const);
2289 try dwarf.refType(pt, di_nw, nav_ty);
2290 }
2291 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());
2292}
2293
2294pub fn updateComptimeGlobal(
1947 dwarf: *Dwarf,2295 dwarf: *Dwarf,
1948 pt: Zcu.PerThread,2296 pt: Zcu.PerThread,
1949 nav_index: InternPool.Nav.Index,2297 global: InternPool.Nav.Index,
1950) link.Error!void {2298) link.Error!void {
1951 const zcu = pt.zcu;2299 const zcu = pt.zcu;
1952 const ip = &zcu.intern_pool;2300 const ip = &zcu.intern_pool;
1953 const nav = ip.getNav(nav_index);2301 const nav = ip.getNav(global);
1954 log.debug("updateComptimeNav({f})", .{nav.fqn.fmt(ip)});2302 log.debug("updateComptimeGlobal({f})", .{nav.fqn.fmt(ip)});
1955 const inst_info = nav.srcInst(ip).resolveFull(ip).?;2303 const inst_info = nav.srcInst(ip).resolveFull(ip).?;
1956 const nav_val: Value = .fromInterned(nav.resolved.?.value);2304 const nav_val: Value = .fromInterned(nav.resolved.?.value);
1957 const zf = zcu.fileByIndex(inst_info.file);2305 const decl = zcu.fileByIndex(inst_info.file).zir.?.getDeclaration(inst_info.inst);
1958 const decl = zf.zir.?.getDeclaration(inst_info.inst);
1959 switch (decl.kind) {2306 switch (decl.kind) {
1960 .unnamed_test, .@"test", .decltest => return,2307 .unnamed_test, .@"test", .decltest => return,
1961 .@"comptime", .@"const", .@"var" => {},2308 .@"comptime", .@"const", .@"var" => {},
1962 }2309 }
1963 done: switch (ip.indexToKey(nav_val.toIntern())) {2310 switch (ip.indexToKey(nav_val.toIntern())) {
2311 .int_type,
2312 .ptr_type,
2313 .array_type,
2314 .vector_type,
2315 .opt_type,
2316 .error_union_type,
2317 .anyframe_type,
2318 .simple_type,
2319 .tuple_type,
2320 .func_type,
2321 .error_set_type,
2322 .inferred_error_set_type,
2323 .spirv_type,
2324 .undef,
2325 .simple_value,
2326 .int,
2327 .err,
2328 .error_union,
2329 .enum_literal,
2330 .enum_tag,
2331 .float,
2332 .ptr,
2333 .slice,
2334 .opt,
2335 .aggregate,
2336 .un,
2337 .bitpack,
2338 => try dwarf.genComptimeGlobal(pt, global, &decl),
1964 .struct_type => {2339 .struct_type => {
1965 const loaded_struct = ip.loadStructType(nav_val.toIntern());2340 const loaded_struct = ip.loadStructType(nav_val.toIntern());
1966 if (nav_index.toOptional() == loaded_struct.name_nav) {2341 if (loaded_struct.name_nav == global.toOptional()) {
1967 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());2342 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
1968 break :done;2343 } else try dwarf.genComptimeGlobal(pt, global, &decl);
1969 }
1970 return;
1971 },2344 },
1972 .enum_type => {2345 .enum_type => {
1973 const loaded_enum = ip.loadEnumType(nav_val.toIntern());2346 const loaded_enum = ip.loadEnumType(nav_val.toIntern());
1974 if (nav_index.toOptional() == loaded_enum.name_nav) {2347 if (loaded_enum.name_nav == global.toOptional()) {
1975 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());2348 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
1976 break :done;2349 } else try dwarf.genComptimeGlobal(pt, global, &decl);
1977 }
1978 return;
1979 },2350 },
1980 .union_type => {2351 .union_type => {
1981 const loaded_union = ip.loadUnionType(nav_val.toIntern());2352 const loaded_union = ip.loadUnionType(nav_val.toIntern());
1982 if (nav_index.toOptional() == loaded_union.name_nav) {2353 if (loaded_union.name_nav == global.toOptional()) {
1983 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());2354 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
1984 break :done;2355 } else try dwarf.genComptimeGlobal(pt, global, &decl);
1985 }
1986 return;
1987 },2356 },
1988 .opaque_type => {2357 .opaque_type => {
1989 const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern());2358 const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern());
1990 if (nav_index.toOptional() == loaded_opaque.name_nav) {2359 if (loaded_opaque.name_nav == global.toOptional()) {
1991 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());2360 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
1992 break :done;2361 } else try dwarf.genComptimeGlobal(pt, global, &decl);
1993 }
1994 return;
1995 },2362 },
1996 .func => |func| if (func.owner_nav == nav_index and func.generic_owner == .none) {2363 .@"extern" => unreachable,
2364 .func => |func| if (func.owner_nav == global) {
1997 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());2365 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
1998 break :done;2366 } else try dwarf.genComptimeGlobal(pt, global, &decl),
1999 } else return,2367 .memoized_call => unreachable, // not a value
20002368 }
2001 else => return,2369}
20022370fn genComptimeGlobal(
2003 // memoization, not values2371 dwarf: *Dwarf,
2004 .memoized_call => unreachable,2372 pt: Zcu.PerThread,
2373 global: InternPool.Nav.Index,
2374 decl: *const std.zig.Zir.Inst.Declaration.Unwrapped,
2375) link.Error!void {
2376 const gpa = pt.zcu.gpa;
2377 const gi = try dwarf.getGlobal(global);
2378 const debug_info_ni = gi.get(dwarf).debug_info_ni.unwrap().?;
2379 var di_nw: link.MappedFile.Node.Writer = undefined;
2380 if (dwarf.lf.cast(.elf2)) |elf| {
2381 try debug_info_ni.moved(gpa, &elf.mf);
2382 debug_info_ni.writer(gpa, &elf.mf, &di_nw);
2383 elf.resetNodeRelocs(debug_info_ni);
2384 } else unreachable;
2385 defer di_nw.deinit();
2386 dwarf.genComptimeGlobalInner(pt, &di_nw, global, decl) catch |err| switch (err) {
2387 else => |e| return e,
2388 error.WriteFailed => return dwarf.reportWriteError(&di_nw),
2389 };
2390}
2391fn genComptimeGlobalInner(
2392 dwarf: *Dwarf,
2393 pt: Zcu.PerThread,
2394 di_nw: *link.MappedFile.Node.Writer,
2395 global: InternPool.Nav.Index,
2396 decl: *const std.zig.Zir.Inst.Declaration.Unwrapped,
2397) link.EmitError!void {
2398 const zcu = pt.zcu;
2399 const ip = &zcu.intern_pool;
2400 const nav = ip.getNav(global);
2401 const nav_ty: Type, const nav_align, const nav_const, const nav_val: Value = nav_resolved: {
2402 const nav_resolved = nav.resolved.?;
2403 break :nav_resolved .{
2404 .fromInterned(nav_resolved.type),
2405 nav_resolved.@"align",
2406 nav_resolved.@"const",
2407 .fromInterned(nav_resolved.value),
2408 };
2409 };
2410 const nav_class = nav_ty.classify(zcu);
2411 const parent_ty: Type = .fromInterned(ip.namespacePtr(nav.analysis.?.namespace).owner_type);
2412 const di_w = &di_nw.interface;
2413 if (parent_ty.getCaptures(zcu).len > 0) {
2414 try dwarf.abbrevCode(di_nw, switch (nav_ty.toIntern()) {
2415 .type_type => .decl_instance_type,
2416 else => switch (nav_class) {
2417 .no_possible_value, .one_possible_value => .decl_instance_const,
2418 .runtime => .decl_instance_const_fully_runtime,
2419 .partially_comptime => .decl_instance_const_partially_comptime,
2420 .fully_comptime => .decl_instance_const_fully_comptime,
2421 },
2422 });
2423 try dwarf.refType(pt, di_nw, parent_ty);
2424 try dwarf.secOffset(di_nw, try dwarf.getGlobalDecl(pt, global), 0);
2425 } else {
2426 const parent_ni = try dwarf.getConstDecl(pt, parent_ty.toIntern());
2427 try dwarf.abbrevCode(di_nw, switch (nav_ty.toIntern()) {
2428 .type_type => .decl_type,
2429 else => switch (nav_class) {
2430 .no_possible_value, .one_possible_value => .decl_const,
2431 .runtime => .decl_const_fully_runtime,
2432 .partially_comptime => .decl_const_partially_comptime,
2433 .fully_comptime => .decl_const_fully_comptime,
2434 },
2435 });
2436 try dwarf.secOffset(di_nw, parent_ni, 0);
2437 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
2438 try di_w.writeUleb128(decl.src_column + 1);
2439 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2440 try dwarf.strx(di_nw, nav.name.toSlice(ip));
2441 }
2442 switch (nav_ty.toIntern()) {
2443 .type_type => try dwarf.refConst(pt, di_nw, nav_val),
2444 else => {
2445 try dwarf.strx(di_nw, switch (decl.linkage) {
2446 .normal => nav.fqn,
2447 .@"extern", .@"export" => nav.name,
2448 }.toSlice(ip));
2449 const type_offset = di_w.end;
2450 if (nav_const)
2451 try dwarf.secOffsetPlaceholder(di_w)
2452 else
2453 try dwarf.refType(pt, di_nw, nav_ty);
2454 try di_w.writeUleb128(nav_align.toByteUnits() orelse
2455 nav_ty.abiAlignment(zcu).toByteUnits().?);
2456 try di_w.writeByte(@intFromBool(decl.linkage != .normal));
2457 if (nav_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, nav_val);
2458 if (nav_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, nav_val);
2459 if (nav_const) {
2460 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
2461 try dwarf.abbrevCode(di_nw, .is_const);
2462 try dwarf.refType(pt, di_nw, nav_ty);
2463 }
2464 },
2005 }2465 }
2006 try dwarf.const_pool.flushPending(pt, dwarf.constPoolUser());2466 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());
2007}2467}
20082468
2009pub fn addConst(2469pub fn addConst(
...@@ -2041,9 +2501,11 @@ pub fn addConst(...@@ -2041,9 +2501,11 @@ pub fn addConst(
2041 const name_gi = try dwarf.getGlobal(name_nav);2501 const name_gi = try dwarf.getGlobal(name_nav);
2042 break :debug_info_ni name_gi.get(dwarf).debug_info_ni.unwrap().?;2502 break :debug_info_ni name_gi.get(dwarf).debug_info_ni.unwrap().?;
2043 }2503 }
2044 break :debug_info_ni try addConstNode(dwarf.lf, dwarf.getUnit(zcu.fileByIndex(2504 const mod = zcu.fileByIndex(
2045 Type.fromInterned(val).typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip),2505 Type.fromInterned(val).typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip),
2046 ).mod.?), cpi);2506 ).mod.?;
2507 assert(!mod.strip);
2508 break :debug_info_ni try addConstNode(dwarf.lf, dwarf.getUnit(mod), cpi);
2047 },2509 },
2048 }.toOptional(),2510 }.toOptional(),
2049 });2511 });
...@@ -2068,17 +2530,17 @@ fn updateConstInner(...@@ -2068,17 +2530,17 @@ fn updateConstInner(
2068 dwarf: *Dwarf,2530 dwarf: *Dwarf,
2069 pt: Zcu.PerThread,2531 pt: Zcu.PerThread,
2070 di_nw: *link.MappedFile.Node.Writer,2532 di_nw: *link.MappedFile.Node.Writer,
2071 val: InternPool.Index,2533 @"const": InternPool.Index,
2072) link.EmitError!void {2534) link.EmitError!void {
2073 const zcu = pt.zcu;2535 const zcu = pt.zcu;
2074 const ip = &zcu.intern_pool;2536 const ip = &zcu.intern_pool;
2075 const di_w = &di_nw.interface;2537 const di_w = &di_nw.interface;
2076 switch (ip.indexToKey(val)) {2538 switch (ip.indexToKey(@"const")) {
2077 .int_type => |int_type| {2539 .int_type => |int_type| {
2078 const ty: Type = .fromInterned(val);2540 const ty: Type = .fromInterned(@"const");
2079 try dwarf.abbrevCode(di_nw, .numeric_type);2541 try dwarf.abbrevCode(di_nw, .numeric_type);
2080 var name_buf: [std.fmt.count("i{d}", .{std.math.maxInt(u16)})]u8 = undefined;2542 var name_buf: [std.fmt.count("i{d}", .{std.math.maxInt(u16)})]u8 = undefined;
2081 try dwarf.strp(&dwarf.debug_str, di_nw, std.mem.print(&name_buf, "{f}", .{2543 try dwarf.strx(di_nw, std.mem.print(&name_buf, "{f}", .{
2082 ty.fmt(pt),2544 ty.fmt(pt),
2083 }) catch unreachable);2545 }) catch unreachable);
2084 try di_w.writeByte(switch (int_type.signedness) {2546 try di_w.writeByte(switch (int_type.signedness) {
...@@ -2091,56 +2553,54 @@ fn updateConstInner(...@@ -2091,56 +2553,54 @@ fn updateConstInner(
2091 },2553 },
2092 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {2554 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
2093 .one, .many, .c => {2555 .one, .many, .c => {
2094 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});2556 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)});
2095 defer zcu.gpa.free(name);2557 defer zcu.gpa.free(name);
2096 try dwarf.abbrevCode(di_nw, switch (ptr_type.sentinel) {2558 try dwarf.abbrevCode(di_nw, switch (ptr_type.sentinel) {
2097 .none => switch (ptr_type.flags.alignment) {2559 .none => .ptr_type,
2098 .none => .ptr_type,2560 else => .ptr_sentinel_type,
2099 else => .ptr_aligned_type,
2100 },
2101 else => switch (ptr_type.flags.alignment) {
2102 .none => .ptr_sentinel_type,
2103 else => .ptr_aligned_sentinel_type,
2104 },
2105 });2561 });
2106 try dwarf.strp(&dwarf.debug_str, di_nw, name);2562 try dwarf.strx(di_nw, name);
2107 switch (ptr_type.sentinel) {2563 switch (ptr_type.sentinel) {
2108 .none => {},2564 .none => {},
2109 else => |sentinel| try dwarf.blockConst(pt, di_nw, .fromInterned(sentinel)),2565 else => |sentinel| try dwarf.blockConst(pt, di_nw, .fromInterned(sentinel)),
2110 }2566 }
2111 if (ptr_type.flags.alignment.toByteUnits()) |a| try di_w.writeUleb128(a);
2112 try di_w.writeByte(@backingInt(ptr_type.flags.address_space));2567 try di_w.writeByte(@backingInt(ptr_type.flags.address_space));
2113 if (ptr_type.flags.is_const or ptr_type.flags.is_volatile) try dwarf.secOffset(2568 if (ptr_type.flags.alignment.toByteUnits()) |a| {
2114 di_nw,2569 const type_offset = di_w.end;
2115 di_nw.ni,2570 try dwarf.secOffsetPlaceholder(di_w);
2116 di_w.end + dwarf.secOffsetSize(),2571 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
2117 );2572 try dwarf.abbrevCode(di_nw, .is_aligned);
2573 try di_w.writeUleb128(a);
2574 }
2118 if (ptr_type.flags.is_const) {2575 if (ptr_type.flags.is_const) {
2576 const type_offset = di_w.end;
2577 try dwarf.secOffsetPlaceholder(di_w);
2578 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
2119 try dwarf.abbrevCode(di_nw, .is_const);2579 try dwarf.abbrevCode(di_nw, .is_const);
2120 if (ptr_type.flags.is_volatile) try dwarf.secOffset(
2121 di_nw,
2122 di_nw.ni,
2123 di_w.end + dwarf.secOffsetSize(),
2124 );
2125 }2580 }
2126 if (ptr_type.flags.is_volatile) try dwarf.abbrevCode(di_nw, .is_volatile);2581 if (ptr_type.flags.is_volatile) {
2582 const type_offset = di_w.end;
2583 try dwarf.secOffsetPlaceholder(di_w);
2584 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
2585 try dwarf.abbrevCode(di_nw, .is_volatile);
2586 }
2127 try dwarf.refType(pt, di_nw, .fromInterned(ptr_type.child));2587 try dwarf.refType(pt, di_nw, .fromInterned(ptr_type.child));
2128 },2588 },
2129 .slice => {2589 .slice => {
2130 const ty: Type = .fromInterned(val);2590 const ty: Type = .fromInterned(@"const");
2131 const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)});2591 const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)});
2132 defer zcu.gpa.free(name);2592 defer zcu.gpa.free(name);
2133 try dwarf.abbrevCode(di_nw, .generated_struct_type);2593 try dwarf.abbrevCode(di_nw, .generated_struct_type);
2134 try dwarf.strp(&dwarf.debug_str, di_nw, name);2594 try dwarf.strx(di_nw, name);
2135 try di_w.writeUleb128(ty.abiSize(zcu));2595 try di_w.writeUleb128(ty.abiSize(zcu));
2136 try di_w.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);2596 try di_w.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);
2137 try dwarf.abbrevCode(di_nw, .generated_field);2597 try dwarf.abbrevCode(di_nw, .generated_field);
2138 try dwarf.strp(&dwarf.debug_str, di_nw, "ptr");2598 try dwarf.strx(di_nw, "ptr");
2139 const ptr_field_ty = ty.slicePtrFieldType(zcu);2599 const ptr_field_ty = ty.slicePtrFieldType(zcu);
2140 try dwarf.refType(pt, di_nw, ptr_field_ty);2600 try dwarf.refType(pt, di_nw, ptr_field_ty);
2141 try di_w.writeUleb128(0);2601 try di_w.writeUleb128(0);
2142 try dwarf.abbrevCode(di_nw, .generated_field);2602 try dwarf.abbrevCode(di_nw, .generated_field);
2143 try dwarf.strp(&dwarf.debug_str, di_nw, "len");2603 try dwarf.strx(di_nw, "len");
2144 const len_field_ty: Type = .usize;2604 const len_field_ty: Type = .usize;
2145 try dwarf.refType(pt, di_nw, len_field_ty);2605 try dwarf.refType(pt, di_nw, len_field_ty);
2146 try di_w.writeUleb128(len_field_ty.abiAlignment(zcu).forward(ptr_field_ty.abiSize(zcu)));2606 try di_w.writeUleb128(len_field_ty.abiAlignment(zcu).forward(ptr_field_ty.abiSize(zcu)));
...@@ -2148,13 +2608,13 @@ fn updateConstInner(...@@ -2148,13 +2608,13 @@ fn updateConstInner(
2148 },2608 },
2149 },2609 },
2150 .array_type => |array_type| {2610 .array_type => |array_type| {
2151 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});2611 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)});
2152 defer zcu.gpa.free(name);2612 defer zcu.gpa.free(name);
2153 try dwarf.abbrevCode(2613 try dwarf.abbrevCode(
2154 di_nw,2614 di_nw,
2155 if (array_type.sentinel == .none) .array_type else .array_sentinel_type,2615 if (array_type.sentinel == .none) .array_type else .array_sentinel_type,
2156 );2616 );
2157 try dwarf.strp(&dwarf.debug_str, di_nw, name);2617 try dwarf.strx(di_nw, name);
2158 if (array_type.sentinel != .none)2618 if (array_type.sentinel != .none)
2159 try dwarf.blockConst(pt, di_nw, .fromInterned(array_type.sentinel));2619 try dwarf.blockConst(pt, di_nw, .fromInterned(array_type.sentinel));
2160 try dwarf.refType(pt, di_nw, .fromInterned(array_type.child));2620 try dwarf.refType(pt, di_nw, .fromInterned(array_type.child));
...@@ -2164,10 +2624,10 @@ fn updateConstInner(...@@ -2164,10 +2624,10 @@ fn updateConstInner(
2164 try di_w.writeUleb128(@backingInt(AbbrevCode.null));2624 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
2165 },2625 },
2166 .vector_type => |vector_type| {2626 .vector_type => |vector_type| {
2167 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});2627 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)});
2168 defer zcu.gpa.free(name);2628 defer zcu.gpa.free(name);
2169 try dwarf.abbrevCode(di_nw, .vector_type);2629 try dwarf.abbrevCode(di_nw, .vector_type);
2170 try dwarf.strp(&dwarf.debug_str, di_nw, name);2630 try dwarf.strx(di_nw, name);
2171 try dwarf.refType(pt, di_nw, .fromInterned(vector_type.child));2631 try dwarf.refType(pt, di_nw, .fromInterned(vector_type.child));
2172 try dwarf.abbrevCode(di_nw, .array_len);2632 try dwarf.abbrevCode(di_nw, .array_len);
2173 try dwarf.refType(pt, di_nw, .usize);2633 try dwarf.refType(pt, di_nw, .usize);
...@@ -2175,28 +2635,30 @@ fn updateConstInner(...@@ -2175,28 +2635,30 @@ fn updateConstInner(
2175 try di_w.writeUleb128(@backingInt(AbbrevCode.null));2635 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
2176 },2636 },
2177 .opt_type => |opt_child_type_index| {2637 .opt_type => |opt_child_type_index| {
2178 const opt_ty: Type = .fromInterned(val);2638 const opt_ty: Type = .fromInterned(@"const");
2179 const opt_child_ty: Type = .fromInterned(opt_child_type_index);2639 const opt_child_ty: Type = .fromInterned(opt_child_type_index);
2180 const opt_repr = optRepr(opt_child_ty, zcu);2640 const opt_repr = optRepr(opt_child_ty, zcu);
2181 const name = try zcu.gpa.print("{f}", .{opt_ty.fmt(pt)});2641 const name = try zcu.gpa.print("{f}", .{opt_ty.fmt(pt)});
2182 defer zcu.gpa.free(name);2642 defer zcu.gpa.free(name);
2183 try dwarf.abbrevCode(di_nw, .generated_union_type);2643 try dwarf.abbrevCode(di_nw, .generated_union_type);
2184 try dwarf.strp(&dwarf.debug_str, di_nw, name);2644 try dwarf.strx(di_nw, name);
2185 try di_w.writeUleb128(opt_ty.abiSize(zcu));2645 try di_w.writeUleb128(opt_ty.abiSize(zcu));
2186 try di_w.writeUleb128(opt_ty.abiAlignment(zcu).toByteUnits().?);2646 try di_w.writeUleb128(opt_ty.abiAlignment(zcu).toByteUnits().?);
2187 switch (opt_repr) {2647 switch (opt_repr) {
2188 .opv_null => {2648 .opv_null => {
2189 try dwarf.abbrevCode(di_nw, .generated_field);2649 try dwarf.abbrevCode(di_nw, .generated_field);
2190 try dwarf.strp(&dwarf.debug_str, di_nw, "null");2650 try dwarf.strx(di_nw, "null");
2191 try dwarf.refType(pt, di_nw, .null);2651 try dwarf.refType(pt, di_nw, .null);
2192 try di_w.writeUleb128(0);2652 try di_w.writeUleb128(0);
2193 },2653 },
2194 .unpacked, .error_set, .pointer => {2654 .unpacked, .error_set, .pointer => {
2195 try dwarf.abbrevCode(di_nw, .tagged_union);2655 try dwarf.abbrevCode(di_nw, .tagged_union);
2196 try dwarf.secOffset(di_nw, di_nw.ni, di_w.end + dwarf.secOffsetSize());2656 const discr_offset = di_w.end;
2657 try dwarf.secOffsetPlaceholder(di_w);
2197 {2658 {
2659 try dwarf.secOffsetFinish(di_nw, discr_offset, di_nw.ni, di_w.end);
2198 try dwarf.abbrevCode(di_nw, .generated_field);2660 try dwarf.abbrevCode(di_nw, .generated_field);
2199 try dwarf.strp(&dwarf.debug_str, di_nw, "has_value");2661 try dwarf.strx(di_nw, "has_value");
2200 switch (opt_repr) {2662 switch (opt_repr) {
2201 .opv_null => unreachable,2663 .opv_null => unreachable,
2202 .unpacked => {2664 .unpacked => {
...@@ -2207,7 +2669,10 @@ fn updateConstInner(...@@ -2207,7 +2669,10 @@ fn updateConstInner(
2207 0);2669 0);
2208 },2670 },
2209 .error_set => {2671 .error_set => {
2210 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));2672 try dwarf.refType(pt, di_nw, try pt.intType(
2673 .unsigned,
2674 zcu.errorSetBits(),
2675 ));
2211 try di_w.writeUleb128(0);2676 try di_w.writeUleb128(0);
2212 },2677 },
2213 .pointer => {2678 .pointer => {
...@@ -2221,7 +2686,7 @@ fn updateConstInner(...@@ -2221,7 +2686,7 @@ fn updateConstInner(
2221 try di_w.writeByte(0);2686 try di_w.writeByte(0);
2222 {2687 {
2223 try dwarf.abbrevCode(di_nw, .generated_field);2688 try dwarf.abbrevCode(di_nw, .generated_field);
2224 try dwarf.strp(&dwarf.debug_str, di_nw, "null");2689 try dwarf.strx(di_nw, "null");
2225 try dwarf.refType(pt, di_nw, .null);2690 try dwarf.refType(pt, di_nw, .null);
2226 try di_w.writeUleb128(0);2691 try di_w.writeUleb128(0);
2227 }2692 }
...@@ -2230,7 +2695,7 @@ fn updateConstInner(...@@ -2230,7 +2695,7 @@ fn updateConstInner(
2230 try dwarf.abbrevCode(di_nw, .tagged_union_default_field);2695 try dwarf.abbrevCode(di_nw, .tagged_union_default_field);
2231 {2696 {
2232 try dwarf.abbrevCode(di_nw, .generated_field);2697 try dwarf.abbrevCode(di_nw, .generated_field);
2233 try dwarf.strp(&dwarf.debug_str, di_nw, "?");2698 try dwarf.strx(di_nw, "?");
2234 try dwarf.refType(pt, di_nw, opt_child_ty);2699 try dwarf.refType(pt, di_nw, opt_child_ty);
2235 try di_w.writeUleb128(0);2700 try di_w.writeUleb128(0);
2236 }2701 }
...@@ -2243,7 +2708,7 @@ fn updateConstInner(...@@ -2243,7 +2708,7 @@ fn updateConstInner(
2243 },2708 },
2244 .anyframe_type => unreachable,2709 .anyframe_type => unreachable,
2245 .error_union_type => |error_union_type| {2710 .error_union_type => |error_union_type| {
2246 const eu_ty: Type = .fromInterned(val);2711 const eu_ty: Type = .fromInterned(@"const");
2247 const eu_error_set_ty: Type = .fromInterned(error_union_type.error_set_type);2712 const eu_error_set_ty: Type = .fromInterned(error_union_type.error_set_type);
2248 const eu_payload_ty: Type = .fromInterned(error_union_type.payload_type);2713 const eu_payload_ty: Type = .fromInterned(error_union_type.payload_type);
2249 const eu_error_set_offset, const eu_payload_offset = switch (error_union_type.payload_type) {2714 const eu_error_set_offset, const eu_payload_offset = switch (error_union_type.payload_type) {
...@@ -2257,7 +2722,7 @@ fn updateConstInner(...@@ -2257,7 +2722,7 @@ fn updateConstInner(
2257 defer zcu.gpa.free(name);2722 defer zcu.gpa.free(name);
22582723
2259 try dwarf.abbrevCode(di_nw, .generated_union_type);2724 try dwarf.abbrevCode(di_nw, .generated_union_type);
2260 try dwarf.strp(&dwarf.debug_str, di_nw, name);2725 try dwarf.strx(di_nw, name);
2261 if (error_union_type.error_set_type != .generic_poison_type and2726 if (error_union_type.error_set_type != .generic_poison_type and
2262 error_union_type.payload_type != .generic_poison_type)2727 error_union_type.payload_type != .generic_poison_type)
2263 {2728 {
...@@ -2269,10 +2734,12 @@ fn updateConstInner(...@@ -2269,10 +2734,12 @@ fn updateConstInner(
2269 }2734 }
2270 {2735 {
2271 try dwarf.abbrevCode(di_nw, .tagged_union);2736 try dwarf.abbrevCode(di_nw, .tagged_union);
2272 try dwarf.secOffset(di_nw, di_nw.ni, di_w.end + dwarf.secOffsetSize());2737 const discr_offset = di_w.end;
2738 try dwarf.secOffsetPlaceholder(di_w);
2273 {2739 {
2740 try dwarf.secOffsetFinish(di_nw, discr_offset, di_nw.ni, di_w.end);
2274 try dwarf.abbrevCode(di_nw, .generated_field);2741 try dwarf.abbrevCode(di_nw, .generated_field);
2275 try dwarf.strp(&dwarf.debug_str, di_nw, "is_error");2742 try dwarf.strx(di_nw, "is_error");
2276 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));2743 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));
2277 try di_w.writeUleb128(eu_error_set_offset);2744 try di_w.writeUleb128(eu_error_set_offset);
22782745
...@@ -2281,7 +2748,7 @@ fn updateConstInner(...@@ -2281,7 +2748,7 @@ fn updateConstInner(
2281 try di_w.writeUleb128(0);2748 try di_w.writeUleb128(0);
2282 {2749 {
2283 try dwarf.abbrevCode(di_nw, .generated_field);2750 try dwarf.abbrevCode(di_nw, .generated_field);
2284 try dwarf.strp(&dwarf.debug_str, di_nw, "value");2751 try dwarf.strx(di_nw, "value");
2285 try dwarf.refType(pt, di_nw, eu_payload_ty);2752 try dwarf.refType(pt, di_nw, eu_payload_ty);
2286 try di_w.writeUleb128(eu_payload_offset);2753 try di_w.writeUleb128(eu_payload_offset);
2287 }2754 }
...@@ -2290,7 +2757,7 @@ fn updateConstInner(...@@ -2290,7 +2757,7 @@ fn updateConstInner(
2290 try dwarf.abbrevCode(di_nw, .tagged_union_default_field);2757 try dwarf.abbrevCode(di_nw, .tagged_union_default_field);
2291 {2758 {
2292 try dwarf.abbrevCode(di_nw, .generated_field);2759 try dwarf.abbrevCode(di_nw, .generated_field);
2293 try dwarf.strp(&dwarf.debug_str, di_nw, "error");2760 try dwarf.strx(di_nw, "error");
2294 try dwarf.refType(pt, di_nw, eu_error_set_ty);2761 try dwarf.refType(pt, di_nw, eu_error_set_ty);
2295 try di_w.writeUleb128(eu_error_set_offset);2762 try di_w.writeUleb128(eu_error_set_offset);
2296 }2763 }
...@@ -2320,10 +2787,10 @@ fn updateConstInner(...@@ -2320,10 +2787,10 @@ fn updateConstInner(
2320 .c_longdouble,2787 .c_longdouble,
2321 .bool,2788 .bool,
2322 => {2789 => {
2323 const ty: Type = .fromInterned(val);2790 const ty: Type = .fromInterned(@"const");
2324 try dwarf.abbrevCode(di_nw, .numeric_type);2791 try dwarf.abbrevCode(di_nw, .numeric_type);
2325 try dwarf.strp(&dwarf.debug_str, di_nw, @tagName(simple_type));2792 try dwarf.strx(di_nw, @tagName(simple_type));
2326 try di_w.writeByte(if (val == .bool_type)2793 try di_w.writeByte(if (@"const" == .bool_type)
2327 DW.ATE.boolean2794 DW.ATE.boolean
2328 else if (ty.isRuntimeFloat())2795 else if (ty.isRuntimeFloat())
2329 DW.ATE.float2796 DW.ATE.float
...@@ -2339,7 +2806,7 @@ fn updateConstInner(...@@ -2339,7 +2806,7 @@ fn updateConstInner(
2339 },2806 },
2340 .generic_poison => {2807 .generic_poison => {
2341 try dwarf.abbrevCode(di_nw, .void_type);2808 try dwarf.abbrevCode(di_nw, .void_type);
2342 try dwarf.strp(&dwarf.debug_str, di_nw, "anytype");2809 try dwarf.strx(di_nw, "anytype");
2343 },2810 },
2344 .anyopaque,2811 .anyopaque,
2345 .void,2812 .void,
...@@ -2351,10 +2818,10 @@ fn updateConstInner(...@@ -2351,10 +2818,10 @@ fn updateConstInner(
2351 .undefined,2818 .undefined,
2352 .enum_literal,2819 .enum_literal,
2353 => {2820 => {
2354 const ty: Type = .fromInterned(val);2821 const ty: Type = .fromInterned(@"const");
2355 try dwarf.abbrevCode(di_nw, .void_type);2822 try dwarf.abbrevCode(di_nw, .void_type);
2356 var name_buf: ["@TypeOf(undefined)".len]u8 = undefined;2823 var name_buf: ["@TypeOf(undefined)".len]u8 = undefined;
2357 try dwarf.strp(&dwarf.debug_str, di_nw, std.mem.print(&name_buf, "{f}", .{2824 try dwarf.strx(di_nw, std.mem.print(&name_buf, "{f}", .{
2358 ty.fmt(pt),2825 ty.fmt(pt),
2359 }) catch unreachable);2826 }) catch unreachable);
2360 },2827 },
...@@ -2364,29 +2831,29 @@ fn updateConstInner(...@@ -2364,29 +2831,29 @@ fn updateConstInner(
2364 .generated_enum_type2831 .generated_enum_type
2365 else2832 else
2366 .generated_empty_enum_type);2833 .generated_empty_enum_type);
2367 try dwarf.strp(&dwarf.debug_str, di_nw, "anyerror");2834 try dwarf.strx(di_nw, "anyerror");
2368 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));2835 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));
2369 for (global_error_set_names, 1..) |name, value| {2836 for (global_error_set_names, 1..) |err_name, err_value| {
2370 try dwarf.abbrevCode(di_nw, .enum_field);2837 try dwarf.abbrevCode(di_nw, .enum_field);
2371 try di_w.writeUleb128(DW.FORM.udata);2838 try di_w.writeUleb128(DW.FORM.udata);
2372 try di_w.writeUleb128(value);2839 try di_w.writeUleb128(err_value);
2373 try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip));2840 try dwarf.strx(di_nw, err_name.toSlice(ip));
2374 }2841 }
2375 if (global_error_set_names.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null));2842 if (global_error_set_names.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
2376 },2843 },
2377 .adhoc_inferred_error_set => unreachable,2844 .adhoc_inferred_error_set => unreachable,
2378 },2845 },
2379 .tuple_type => |tuple_type| {2846 .tuple_type => |tuple_type| {
2380 const ty: Type = .fromInterned(val);2847 const ty: Type = .fromInterned(@"const");
2381 const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)});2848 const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)});
2382 defer zcu.gpa.free(name);2849 defer zcu.gpa.free(name);
2383 if (tuple_type.types.len == 0) {2850 if (tuple_type.types.len == 0) {
2384 try dwarf.abbrevCode(di_nw, .generated_empty_struct_type);2851 try dwarf.abbrevCode(di_nw, .generated_empty_struct_type);
2385 try dwarf.strp(&dwarf.debug_str, di_nw, name);2852 try dwarf.strx(di_nw, name);
2386 try di_w.writeByte(@intFromBool(false));2853 try di_w.writeByte(@intFromBool(false));
2387 } else {2854 } else {
2388 try dwarf.abbrevCode(di_nw, .generated_struct_type);2855 try dwarf.abbrevCode(di_nw, .generated_struct_type);
2389 try dwarf.strp(&dwarf.debug_str, di_nw, name);2856 try dwarf.strx(di_nw, name);
2390 try di_w.writeUleb128(ty.abiSize(zcu));2857 try di_w.writeUleb128(ty.abiSize(zcu));
2391 try di_w.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);2858 try di_w.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);
2392 var field_byte_offset: u64 = 0;2859 var field_byte_offset: u64 = 0;
...@@ -2407,7 +2874,7 @@ fn updateConstInner(...@@ -2407,7 +2874,7 @@ fn updateConstInner(
2407 },2874 },
2408 });2875 });
2409 var field_name_buf: [std.fmt.count("{d}", .{std.math.maxInt(u32)})]u8 = undefined;2876 var field_name_buf: [std.fmt.count("{d}", .{std.math.maxInt(u32)})]u8 = undefined;
2410 try dwarf.strp(&dwarf.debug_str, di_nw, std.mem.print(&field_name_buf, "{d}", .{2877 try dwarf.strx(di_nw, std.mem.print(&field_name_buf, "{d}", .{
2411 field_index,2878 field_index,
2412 }) catch unreachable);2879 }) catch unreachable);
2413 try dwarf.refType(pt, di_nw, field_ty);2880 try dwarf.refType(pt, di_nw, field_ty);
...@@ -2427,72 +2894,81 @@ fn updateConstInner(...@@ -2427,72 +2894,81 @@ fn updateConstInner(
2427 }2894 }
2428 },2895 },
2429 .struct_type => {2896 .struct_type => {
2430 const loaded_struct = ip.loadStructType(val);2897 const loaded_struct = ip.loadStructType(@"const");
2431 const zfi = loaded_struct.zir_index.resolveFile(ip);2898 const src_inst = loaded_struct.zir_index.resolveFull(ip).?;
2432 const zf = zcu.fileByIndex(zfi);2899 const zf = zcu.fileByIndex(src_inst.file);
2433 const src_inst = loaded_struct.zir_index.resolve(ip);2900 const is_empty = loaded_struct.captures.len == 0 and loaded_struct.field_types.len == 0;
2434 if (src_inst == .main_struct_inst) {2901 if (src_inst.inst == .main_struct_inst) {
2435 assert(loaded_struct.captures.len == 0);2902 assert(loaded_struct.captures.len == 0);
2436 const ui = dwarf.getUnit(zf.mod.?);2903 const ui = dwarf.getUnit(zf.mod.?);
2437 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, zfi);2904 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, src_inst.file);
2438 try dwarf.abbrevCode(di_nw, switch (loaded_struct.layout) {2905 try dwarf.abbrevCode(di_nw, switch (loaded_struct.layout) {
2439 .auto => if (loaded_struct.field_types.len > 0) .file else .empty_file,2906 .auto => if (is_empty) .empty_file else .file,
2440 .@"extern", .@"packed" => unreachable,2907 .@"extern", .@"packed" => unreachable,
2441 });2908 });
2442 try di_w.writeUleb128(@backingInt(fi));2909 try di_w.writeUleb128(@backingInt(fi));
2443 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.name.toSlice(ip));2910 try dwarf.strx(di_nw, loaded_struct.name.toSlice(ip));
2444 } else if (loaded_struct.captures.len > 0 or loaded_struct.is_reified) {2911 } else if (loaded_struct.captures.len > 0 or loaded_struct.is_reified) {
2445 try dwarf.abbrevCode(di_nw, if (loaded_struct.captures.len > 0 or2912 try dwarf.abbrevCode(di_nw, switch (loaded_struct.name_nav) {
2446 loaded_struct.field_types.len > 0) switch (loaded_struct.layout) {2913 else => if (is_empty) switch (loaded_struct.layout) {
2447 .auto, .@"extern" => .decl_instance_struct,2914 .auto, .@"extern" => .decl_instance_empty_struct,
2448 .@"packed" => .decl_instance_packed_struct,2915 .@"packed" => .decl_instance_empty_packed_struct,
2449 } else switch (loaded_struct.layout) {2916 } else switch (loaded_struct.layout) {
2450 .auto, .@"extern" => .decl_instance_empty_struct,2917 .auto, .@"extern" => .decl_instance_struct,
2451 .@"packed" => .decl_instance_empty_packed_struct,2918 .@"packed" => .decl_instance_packed_struct,
2919 },
2920 .none => if (is_empty) switch (loaded_struct.layout) {
2921 .auto, .@"extern" => .type_decl_instance_empty_struct,
2922 .@"packed" => .type_decl_instance_empty_packed_struct,
2923 } else switch (loaded_struct.layout) {
2924 .auto, .@"extern" => .type_decl_instance_struct,
2925 .@"packed" => .type_decl_instance_packed_struct,
2926 },
2452 });2927 });
2453 try dwarf.secOffset(di_nw, try dwarf.getDecl(pt, val), 0);2928 try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr(
2929 ip.namespacePtr(loaded_struct.namespace).parent.unwrap().?,
2930 ).owner_type));
2931 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, @"const"), 0);
2932 if (loaded_struct.name_nav == .none)
2933 try dwarf.strx(di_nw, loaded_struct.name.toSlice(ip));
2454 } else if (loaded_struct.name_nav.unwrap()) |name_ni| {2934 } else if (loaded_struct.name_nav.unwrap()) |name_ni| {
2455 const name_nav = ip.getNav(name_ni);2935 const name_nav = ip.getNav(name_ni);
2456 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);2936 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
2457 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(2937 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
2458 name_nav.analysis.?.namespace,2938 name_nav.analysis.?.namespace,
2459 ).owner_type);2939 ).owner_type);
2460 try dwarf.abbrevCode(di_nw, if (loaded_struct.field_types.len > 0)2940 try dwarf.abbrevCode(di_nw, if (is_empty) switch (loaded_struct.layout) {
2461 switch (loaded_struct.layout) {
2462 .auto, .@"extern" => .decl_struct,
2463 .@"packed" => .decl_packed_struct,
2464 }
2465 else switch (loaded_struct.layout) {
2466 .auto, .@"extern" => .decl_empty_struct,2941 .auto, .@"extern" => .decl_empty_struct,
2467 .@"packed" => .decl_empty_packed_struct,2942 .@"packed" => .decl_empty_packed_struct,
2943 } else switch (loaded_struct.layout) {
2944 .auto, .@"extern" => .decl_struct,
2945 .@"packed" => .decl_packed_struct,
2468 });2946 });
2469 try dwarf.secOffset(di_nw, parent_ni, 0);2947 try dwarf.secOffset(di_nw, parent_ni, 0);
2470 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);2948 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
2471 try di_w.writeUleb128(decl.src_column + 1);2949 try di_w.writeUleb128(decl.src_column + 1);
2472 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);2950 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2473 try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip));2951 try dwarf.strx(di_nw, name_nav.name.toSlice(ip));
2474 } else {2952 } else {
2475 const decl = zf.zir.?.getStructDecl(src_inst.?);2953 const decl = zf.zir.?.getStructDecl(src_inst.inst);
2476 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(2954 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
2477 ip.namespacePtr(loaded_struct.namespace).parent.unwrap().?,2955 ip.namespacePtr(loaded_struct.namespace).parent.unwrap().?,
2478 ).owner_type);2956 ).owner_type);
2479 try dwarf.abbrevCode(di_nw, if (loaded_struct.field_types.len > 0)2957 try dwarf.abbrevCode(di_nw, if (is_empty) switch (loaded_struct.layout) {
2480 switch (loaded_struct.layout) {
2481 .auto, .@"extern" => .type_decl_struct,
2482 .@"packed" => .type_decl_packed_struct,
2483 }
2484 else switch (loaded_struct.layout) {
2485 .auto, .@"extern" => .type_decl_empty_struct,2958 .auto, .@"extern" => .type_decl_empty_struct,
2486 .@"packed" => .type_decl_empty_packed_struct,2959 .@"packed" => .type_decl_empty_packed_struct,
2960 } else switch (loaded_struct.layout) {
2961 .auto, .@"extern" => .type_decl_struct,
2962 .@"packed" => .type_decl_packed_struct,
2487 });2963 });
2488 try dwarf.secOffset(di_nw, parent_ni, 0);2964 try dwarf.secOffset(di_nw, parent_ni, 0);
2489 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);2965 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
2490 try di_w.writeUleb128(decl.src_column + 1);2966 try di_w.writeUleb128(decl.src_column + 1);
2491 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.name.toSlice(ip));2967 try dwarf.strx(di_nw, loaded_struct.name.toSlice(ip));
2492 }2968 }
2493 switch (loaded_struct.layout) {2969 switch (loaded_struct.layout) {
2494 .auto, .@"extern" => {2970 .auto, .@"extern" => {
2495 const ty: Type = .fromInterned(val);2971 const ty: Type = .fromInterned(@"const");
2496 try di_w.writeUleb128(ty.abiSize(zcu));2972 try di_w.writeUleb128(ty.abiSize(zcu));
2497 try di_w.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);2973 try di_w.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);
2498 try dwarf.genCaptures(pt, di_nw, loaded_struct.captures);2974 try dwarf.genCaptures(pt, di_nw, loaded_struct.captures);
...@@ -2528,8 +3004,7 @@ fn updateConstInner(...@@ -2528,8 +3004,7 @@ fn updateConstInner(
2528 .partially_comptime => .field_default_partially_comptime,3004 .partially_comptime => .field_default_partially_comptime,
2529 .fully_comptime => .field_default_fully_comptime,3005 .fully_comptime => .field_default_fully_comptime,
2530 });3006 });
2531 try dwarf.strp(3007 try dwarf.strx(
2532 &dwarf.debug_str,
2533 di_nw,3008 di_nw,
2534 loaded_struct.field_names.get(ip)[field_index].toSlice(ip),3009 loaded_struct.field_names.get(ip)[field_index].toSlice(ip),
2535 );3010 );
...@@ -2553,8 +3028,7 @@ fn updateConstInner(...@@ -2553,8 +3028,7 @@ fn updateConstInner(
2553 var field_bit_offset: u16 = 0;3028 var field_bit_offset: u16 = 0;
2554 for (0..loaded_struct.field_types.len) |field_index| {3029 for (0..loaded_struct.field_types.len) |field_index| {
2555 try dwarf.abbrevCode(di_nw, .packed_field);3030 try dwarf.abbrevCode(di_nw, .packed_field);
2556 try dwarf.strp(3031 try dwarf.strx(
2557 &dwarf.debug_str,
2558 di_nw,3032 di_nw,
2559 loaded_struct.field_names.get(ip)[field_index].toSlice(ip),3033 loaded_struct.field_names.get(ip)[field_index].toSlice(ip),
2560 );3034 );
...@@ -2566,62 +3040,71 @@ fn updateConstInner(...@@ -2566,62 +3040,71 @@ fn updateConstInner(
2566 }3040 }
2567 },3041 },
2568 }3042 }
2569 if (loaded_struct.captures.len > 0 or loaded_struct.field_types.len > 0)3043 if (!is_empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
2570 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
2571 },3044 },
2572 .union_type => {3045 .union_type => {
2573 const loaded_union = ip.loadUnionType(val);3046 const loaded_union = ip.loadUnionType(@"const");
2574 const loaded_tag = ip.loadEnumType(loaded_union.enum_tag_type);3047 const loaded_tag = ip.loadEnumType(loaded_union.enum_tag_type);
2575 const zfi = loaded_union.zir_index.resolveFile(ip);3048 const zfi = loaded_union.zir_index.resolveFile(ip);
2576 const zf = zcu.fileByIndex(zfi);3049 const zf = zcu.fileByIndex(zfi);
3050 const is_empty = loaded_union.captures.len == 0 and loaded_union.field_types.len == 0;
2577 if (loaded_union.captures.len > 0 or loaded_union.is_reified) {3051 if (loaded_union.captures.len > 0 or loaded_union.is_reified) {
2578 try dwarf.abbrevCode(di_nw, if (loaded_union.captures.len > 0 or3052 try dwarf.abbrevCode(di_nw, switch (loaded_union.name_nav) {
2579 loaded_union.field_types.len > 0) switch (loaded_union.layout) {3053 else => if (is_empty) switch (loaded_union.layout) {
2580 .auto, .@"extern" => .decl_instance_union,3054 .auto, .@"extern" => .decl_instance_empty_union,
2581 .@"packed" => .decl_instance_packed_union,3055 .@"packed" => .decl_instance_empty_packed_union,
2582 } else switch (loaded_union.layout) {3056 } else switch (loaded_union.layout) {
2583 .auto, .@"extern" => .decl_instance_empty_union,3057 .auto, .@"extern" => .decl_instance_union,
2584 .@"packed" => .decl_instance_empty_packed_union,3058 .@"packed" => .decl_instance_packed_union,
3059 },
3060 .none => if (is_empty) switch (loaded_union.layout) {
3061 .auto, .@"extern" => .type_decl_instance_empty_union,
3062 .@"packed" => .type_decl_instance_empty_packed_union,
3063 } else switch (loaded_union.layout) {
3064 .auto, .@"extern" => .type_decl_instance_union,
3065 .@"packed" => .type_decl_instance_packed_union,
3066 },
2585 });3067 });
2586 try dwarf.secOffset(di_nw, try dwarf.getDecl(pt, val), 0);3068 try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr(
3069 ip.namespacePtr(loaded_union.namespace).parent.unwrap().?,
3070 ).owner_type));
3071 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, @"const"), 0);
3072 if (loaded_union.name_nav == .none)
3073 try dwarf.strx(di_nw, loaded_union.name.toSlice(ip));
2587 } else if (loaded_union.name_nav.unwrap()) |name_ni| {3074 } else if (loaded_union.name_nav.unwrap()) |name_ni| {
2588 const name_nav = ip.getNav(name_ni);3075 const name_nav = ip.getNav(name_ni);
2589 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);3076 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
2590 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(3077 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
2591 name_nav.analysis.?.namespace,3078 name_nav.analysis.?.namespace,
2592 ).owner_type);3079 ).owner_type);
2593 try dwarf.abbrevCode(di_nw, if (loaded_union.field_types.len > 0)3080 try dwarf.abbrevCode(di_nw, if (is_empty) switch (loaded_union.layout) {
2594 switch (loaded_union.layout) {
2595 .auto, .@"extern" => .decl_union,
2596 .@"packed" => .decl_packed_union,
2597 }
2598 else switch (loaded_union.layout) {
2599 .auto, .@"extern" => .decl_empty_union,3081 .auto, .@"extern" => .decl_empty_union,
2600 .@"packed" => .decl_empty_packed_union,3082 .@"packed" => .decl_empty_packed_union,
3083 } else switch (loaded_union.layout) {
3084 .auto, .@"extern" => .decl_union,
3085 .@"packed" => .decl_packed_union,
2601 });3086 });
2602 try dwarf.secOffset(di_nw, parent_ni, 0);3087 try dwarf.secOffset(di_nw, parent_ni, 0);
2603 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);3088 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
2604 try di_w.writeUleb128(decl.src_column + 1);3089 try di_w.writeUleb128(decl.src_column + 1);
2605 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);3090 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2606 try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip));3091 try dwarf.strx(di_nw, name_nav.name.toSlice(ip));
2607 } else {3092 } else {
2608 const decl = zf.zir.?.getUnionDecl(loaded_union.zir_index.resolve(ip).?);3093 const decl = zf.zir.?.getUnionDecl(loaded_union.zir_index.resolve(ip).?);
2609 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(3094 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
2610 ip.namespacePtr(loaded_union.namespace).parent.unwrap().?,3095 ip.namespacePtr(loaded_union.namespace).parent.unwrap().?,
2611 ).owner_type);3096 ).owner_type);
2612 try dwarf.abbrevCode(di_nw, if (loaded_union.field_types.len > 0)3097 try dwarf.abbrevCode(di_nw, if (is_empty) switch (loaded_union.layout) {
2613 switch (loaded_union.layout) {
2614 .auto, .@"extern" => .type_decl_union,
2615 .@"packed" => .type_decl_packed_union,
2616 }
2617 else switch (loaded_union.layout) {
2618 .auto, .@"extern" => .type_decl_empty_union,3098 .auto, .@"extern" => .type_decl_empty_union,
2619 .@"packed" => .type_decl_empty_packed_union,3099 .@"packed" => .type_decl_empty_packed_union,
3100 } else switch (loaded_union.layout) {
3101 .auto, .@"extern" => .type_decl_union,
3102 .@"packed" => .type_decl_packed_union,
2620 });3103 });
2621 try dwarf.secOffset(di_nw, parent_ni, 0);3104 try dwarf.secOffset(di_nw, parent_ni, 0);
2622 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);3105 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
2623 try di_w.writeUleb128(decl.src_column + 1);3106 try di_w.writeUleb128(decl.src_column + 1);
2624 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_union.name.toSlice(ip));3107 try dwarf.strx(di_nw, loaded_union.name.toSlice(ip));
2625 }3108 }
2626 switch (loaded_union.layout) {3109 switch (loaded_union.layout) {
2627 .auto, .@"extern" => {3110 .auto, .@"extern" => {
...@@ -2631,10 +3114,12 @@ fn updateConstInner(...@@ -2631,10 +3114,12 @@ fn updateConstInner(
2631 try dwarf.genCaptures(pt, di_nw, loaded_union.captures);3114 try dwarf.genCaptures(pt, di_nw, loaded_union.captures);
2632 if (loaded_union.has_runtime_tag) {3115 if (loaded_union.has_runtime_tag) {
2633 try dwarf.abbrevCode(di_nw, .tagged_union);3116 try dwarf.abbrevCode(di_nw, .tagged_union);
2634 try dwarf.secOffset(di_nw, di_nw.ni, di_w.end + dwarf.secOffsetSize());3117 const discr_offset = di_w.end;
3118 try dwarf.secOffsetPlaceholder(di_w);
2635 {3119 {
3120 try dwarf.secOffsetFinish(di_nw, discr_offset, di_nw.ni, di_w.end);
2636 try dwarf.abbrevCode(di_nw, .generated_field);3121 try dwarf.abbrevCode(di_nw, .generated_field);
2637 try dwarf.strp(&dwarf.debug_str, di_nw, "tag");3122 try dwarf.strx(di_nw, "tag");
2638 try dwarf.refType(pt, di_nw, .fromInterned(loaded_union.enum_tag_type));3123 try dwarf.refType(pt, di_nw, .fromInterned(loaded_union.enum_tag_type));
2639 try di_w.writeUleb128(union_layout.tagOffset());3124 try di_w.writeUleb128(union_layout.tagOffset());
26403125
...@@ -2643,8 +3128,7 @@ fn updateConstInner(...@@ -2643,8 +3128,7 @@ fn updateConstInner(
2643 try dwarf.enumConstValue(di_w, loaded_tag, field_index);3128 try dwarf.enumConstValue(di_w, loaded_tag, field_index);
2644 {3129 {
2645 try dwarf.abbrevCode(di_nw, .field);3130 try dwarf.abbrevCode(di_nw, .field);
2646 try dwarf.strp(3131 try dwarf.strx(
2647 &dwarf.debug_str,
2648 di_nw,3132 di_nw,
2649 loaded_tag.field_names.get(ip)[field_index].toSlice(ip),3133 loaded_tag.field_names.get(ip)[field_index].toSlice(ip),
2650 );3134 );
...@@ -2666,8 +3150,7 @@ fn updateConstInner(...@@ -2666,8 +3150,7 @@ fn updateConstInner(
2666 try di_w.writeUleb128(@backingInt(AbbrevCode.null));3150 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
2667 } else for (0..loaded_union.field_types.len) |field_index| {3151 } else for (0..loaded_union.field_types.len) |field_index| {
2668 try dwarf.abbrevCode(di_nw, .field);3152 try dwarf.abbrevCode(di_nw, .field);
2669 try dwarf.strp(3153 try dwarf.strx(
2670 &dwarf.debug_str,
2671 di_nw,3154 di_nw,
2672 loaded_tag.field_names.get(ip)[field_index].toSlice(ip),3155 loaded_tag.field_names.get(ip)[field_index].toSlice(ip),
2673 );3156 );
...@@ -2688,8 +3171,7 @@ fn updateConstInner(...@@ -2688,8 +3171,7 @@ fn updateConstInner(
2688 try dwarf.refType(pt, di_nw, .fromInterned(loaded_union.packed_backing_int_type));3171 try dwarf.refType(pt, di_nw, .fromInterned(loaded_union.packed_backing_int_type));
2689 for (0..loaded_union.field_types.len) |field_index| {3172 for (0..loaded_union.field_types.len) |field_index| {
2690 try dwarf.abbrevCode(di_nw, .packed_field);3173 try dwarf.abbrevCode(di_nw, .packed_field);
2691 try dwarf.strp(3174 try dwarf.strx(
2692 &dwarf.debug_str,
2693 di_nw,3175 di_nw,
2694 loaded_tag.field_names.get(ip)[field_index].toSlice(ip),3176 loaded_tag.field_names.get(ip)[field_index].toSlice(ip),
2695 );3177 );
...@@ -2700,83 +3182,86 @@ fn updateConstInner(...@@ -2700,83 +3182,86 @@ fn updateConstInner(
2700 }3182 }
2701 },3183 },
2702 }3184 }
2703 if (loaded_union.captures.len > 0 or loaded_union.field_types.len > 0)3185 if (!is_empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
2704 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
2705 },3186 },
2706 .enum_type => {3187 .enum_type => {
2707 const loaded_enum = ip.loadEnumType(val);3188 const loaded_enum = ip.loadEnumType(@"const");
3189 const is_empty = loaded_enum.captures.len == 0 and loaded_enum.field_names.len == 0;
2708 switch (loaded_enum.owner_union) {3190 switch (loaded_enum.owner_union) {
2709 .none => {3191 .none => {
2710 const zfi = loaded_enum.zir_index.unwrap().?.resolveFile(ip);3192 const zfi = loaded_enum.zir_index.unwrap().?.resolveFile(ip);
2711 const zf = zcu.fileByIndex(zfi);3193 const zf = zcu.fileByIndex(zfi);
3194 const zir = &zf.zir.?;
2712 if (loaded_enum.captures.len > 0 or loaded_enum.is_reified) {3195 if (loaded_enum.captures.len > 0 or loaded_enum.is_reified) {
2713 try dwarf.abbrevCode(di_nw, if (loaded_enum.captures.len > 0 or3196 try dwarf.abbrevCode(di_nw, switch (loaded_enum.name_nav) {
2714 loaded_enum.field_names.len > 0)3197 else => if (is_empty) .decl_instance_empty_enum else .decl_instance_enum,
2715 .decl_instance_enum3198 .none => if (is_empty)
2716 else3199 .type_decl_instance_empty_enum
2717 .decl_instance_empty_enum);3200 else
2718 try dwarf.secOffset(di_nw, try dwarf.getDecl(pt, val), 0);3201 .type_decl_instance_enum,
3202 });
3203 try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr(
3204 ip.namespacePtr(loaded_enum.namespace).parent.unwrap().?,
3205 ).owner_type));
3206 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, @"const"), 0);
3207 if (loaded_enum.name_nav == .none)
3208 try dwarf.strx(di_nw, loaded_enum.name.toSlice(ip));
2719 } else if (loaded_enum.name_nav.unwrap()) |name_ni| {3209 } else if (loaded_enum.name_nav.unwrap()) |name_ni| {
2720 const name_nav = ip.getNav(name_ni);3210 const name_nav = ip.getNav(name_ni);
2721 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);3211 const decl = zir.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
2722 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(3212 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
2723 name_nav.analysis.?.namespace,3213 name_nav.analysis.?.namespace,
2724 ).owner_type);3214 ).owner_type);
2725 try dwarf.abbrevCode(3215 try dwarf.abbrevCode(
2726 di_nw,3216 di_nw,
2727 if (loaded_enum.field_names.len > 0) .decl_enum else .decl_empty_enum,3217 if (is_empty) .decl_empty_enum else .decl_enum,
2728 );3218 );
2729 try dwarf.secOffset(di_nw, parent_ni, 0);3219 try dwarf.secOffset(di_nw, parent_ni, 0);
2730 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);3220 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
2731 try di_w.writeUleb128(decl.src_column + 1);3221 try di_w.writeUleb128(decl.src_column + 1);
2732 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);3222 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2733 try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip));3223 try dwarf.strx(di_nw, name_nav.name.toSlice(ip));
2734 } else {3224 } else {
2735 const decl =3225 const decl = zir.getEnumDecl(loaded_enum.zir_index.unwrap().?.resolve(ip).?);
2736 zf.zir.?.getEnumDecl(loaded_enum.zir_index.unwrap().?.resolve(ip).?);3226 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
2737 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2738 ip.namespacePtr(loaded_enum.namespace).parent.unwrap().?,3227 ip.namespacePtr(loaded_enum.namespace).parent.unwrap().?,
2739 ).owner_type);3228 ).owner_type);
2740 try dwarf.abbrevCode(di_nw, if (loaded_enum.field_names.len > 0)3229 try dwarf.abbrevCode(
2741 .type_decl_enum3230 di_nw,
2742 else3231 if (is_empty) .type_decl_empty_enum else .type_decl_enum,
2743 .type_decl_empty_enum);3232 );
2744 try dwarf.secOffset(di_nw, parent_ni, 0);3233 try dwarf.secOffset(di_nw, parent_ni, 0);
2745 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);3234 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
2746 try di_w.writeUleb128(decl.src_column + 1);3235 try di_w.writeUleb128(decl.src_column + 1);
2747 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.name.toSlice(ip));3236 try dwarf.strx(di_nw, loaded_enum.name.toSlice(ip));
2748 }3237 }
2749 },3238 },
2750 else => {3239 else => {
2751 try dwarf.abbrevCode(di_nw, if (loaded_enum.field_names.len > 0)3240 try dwarf.abbrevCode(
2752 .generated_enum_type3241 di_nw,
2753 else3242 if (is_empty) .generated_empty_enum_type else .generated_enum_type,
2754 .generated_empty_enum_type);3243 );
2755 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.fqn.toSlice(ip));3244 try dwarf.strx(di_nw, loaded_enum.fqn.toSlice(ip));
2756 },3245 },
2757 }3246 }
2758 try dwarf.refType(pt, di_nw, .fromInterned(loaded_enum.int_tag_type));3247 try dwarf.refType(pt, di_nw, .fromInterned(loaded_enum.int_tag_type));
3248 try dwarf.genCaptures(pt, di_nw, loaded_enum.captures);
2759 for (0..loaded_enum.field_names.len) |field_index| {3249 for (0..loaded_enum.field_names.len) |field_index| {
2760 try dwarf.abbrevCode(di_nw, .enum_field);3250 try dwarf.abbrevCode(di_nw, .enum_field);
2761 try dwarf.enumConstValue(di_w, loaded_enum, field_index);3251 try dwarf.enumConstValue(di_w, loaded_enum, field_index);
2762 try dwarf.strp(3252 try dwarf.strx(di_nw, loaded_enum.field_names.get(ip)[field_index].toSlice(ip));
2763 &dwarf.debug_str,
2764 di_nw,
2765 loaded_enum.field_names.get(ip)[field_index].toSlice(ip),
2766 );
2767 }3253 }
2768 if (loaded_enum.captures.len > 0 or loaded_enum.field_names.len > 0)3254 if (!is_empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
2769 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
2770 },3255 },
2771 // no defined size, so lowered the same as incomplete struct types3256 // no defined size, so lowered the same as incomplete struct types
2772 .opaque_type => return dwarf.updateConstIncompleteInner(pt, di_nw, val),3257 .opaque_type => return dwarf.updateConstIncompleteInner(pt, di_nw, @"const"),
2773 .spirv_type => unreachable,3258 .spirv_type => unreachable,
2774 .func_type => |func_type| {3259 .func_type => |func_type| {
2775 const is_nullary = func_type.param_types.len == 0 and !func_type.is_var_args;3260 const is_empty = func_type.param_types.len == 0 and !func_type.is_var_args;
2776 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});3261 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)});
2777 defer zcu.gpa.free(name);3262 defer zcu.gpa.free(name);
2778 try dwarf.abbrevCode(di_nw, if (is_nullary) .nullary_func_type else .func_type);3263 try dwarf.abbrevCode(di_nw, if (is_empty) .empty_func_type else .func_type);
2779 try dwarf.strp(&dwarf.debug_str, di_nw, name);3264 try dwarf.strx(di_nw, name);
2780 const cc: DW.CC = cc: {3265 const cc: DW.CC = cc: {
2781 if (zcu.getTarget().cCallingConvention()) |cc| {3266 if (zcu.getTarget().cCallingConvention()) |cc| {
2782 if (@as(std.lang.CallingConvention.Tag, cc) == func_type.cc) {3267 if (@as(std.lang.CallingConvention.Tag, cc) == func_type.cc) {
...@@ -2848,40 +3333,38 @@ fn updateConstInner(...@@ -2848,40 +3333,38 @@ fn updateConstInner(
2848 };3333 };
2849 try di_w.writeByte(@backingInt(cc));3334 try di_w.writeByte(@backingInt(cc));
2850 try dwarf.refType(pt, di_nw, .fromInterned(func_type.return_type));3335 try dwarf.refType(pt, di_nw, .fromInterned(func_type.return_type));
2851 if (!is_nullary) {3336 for (0..func_type.param_types.len) |param_index| {
2852 for (0..func_type.param_types.len) |param_index| {3337 try dwarf.abbrevCode(di_nw, .unnamed_param);
2853 try dwarf.abbrevCode(di_nw, .unnamed_param);3338 try dwarf.refType(pt, di_nw, .fromInterned(
2854 try dwarf.refType(pt, di_nw, .fromInterned(3339 func_type.param_types.get(ip)[param_index],
2855 func_type.param_types.get(ip)[param_index],3340 ));
2856 ));
2857 }
2858 if (func_type.is_var_args) try dwarf.abbrevCode(di_nw, .is_var_args);
2859 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
2860 }3341 }
3342 if (func_type.is_var_args) try dwarf.abbrevCode(di_nw, .is_var_args);
3343 if (!is_empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
2861 },3344 },
2862 .error_set_type => |error_set_type| {3345 .error_set_type => |error_set_type| {
2863 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});3346 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)});
2864 defer zcu.gpa.free(name);3347 defer zcu.gpa.free(name);
2865 try dwarf.abbrevCode(3348 try dwarf.abbrevCode(
2866 di_nw,3349 di_nw,
2867 if (error_set_type.names.len > 0) .generated_enum_type else .generated_empty_enum_type,3350 if (error_set_type.names.len > 0) .generated_enum_type else .generated_empty_enum_type,
2868 );3351 );
2869 try dwarf.strp(&dwarf.debug_str, di_nw, name);3352 try dwarf.strx(di_nw, name);
2870 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));3353 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));
2871 for (0..error_set_type.names.len) |field_index| {3354 for (0..error_set_type.names.len) |field_index| {
2872 const field_name = error_set_type.names.get(ip)[field_index];3355 const field_name = error_set_type.names.get(ip)[field_index];
2873 try dwarf.abbrevCode(di_nw, .enum_field);3356 try dwarf.abbrevCode(di_nw, .enum_field);
2874 try di_w.writeUleb128(DW.FORM.udata);3357 try di_w.writeUleb128(DW.FORM.udata);
2875 try di_w.writeUleb128(ip.getErrorValueIfExists(field_name).?);3358 try di_w.writeUleb128(ip.getErrorValueIfExists(field_name).?);
2876 try dwarf.strp(&dwarf.debug_str, di_nw, field_name.toSlice(ip));3359 try dwarf.strx(di_nw, field_name.toSlice(ip));
2877 }3360 }
2878 if (error_set_type.names.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null));3361 if (error_set_type.names.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
2879 },3362 },
2880 .inferred_error_set_type => |func| {3363 .inferred_error_set_type => |func| {
2881 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});3364 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)});
2882 defer zcu.gpa.free(name);3365 defer zcu.gpa.free(name);
2883 try dwarf.abbrevCode(di_nw, .inferred_error_set_type);3366 try dwarf.abbrevCode(di_nw, .inferred_error_set_type);
2884 try dwarf.strp(&dwarf.debug_str, di_nw, name);3367 try dwarf.strx(di_nw, name);
2885 try dwarf.refType(pt, di_nw, switch (ies: {3368 try dwarf.refType(pt, di_nw, switch (ies: {
2886 const fi = dwarf.getFuncIfExists(ip.indexToKey(func).func.owner_nav) orelse3369 const fi = dwarf.getFuncIfExists(ip.indexToKey(func).func.owner_nav) orelse
2887 break :ies .none;3370 break :ies .none;
...@@ -2895,38 +3378,468 @@ fn updateConstInner(...@@ -2895,38 +3378,468 @@ fn updateConstInner(
2895 });3378 });
2896 },3379 },
28973380
2898 else => return,3381 .undef => |ty| {
3382 try dwarf.abbrevCode(di_nw, .undefined_comptime_value);
3383 try dwarf.refType(pt, di_nw, .fromInterned(ty));
3384 },
3385 .simple_value => |simple_value| switch (simple_value) {
3386 .void => unreachable, // opv state
3387 .true, .false => unreachable, // runtime bits
3388 .@"unreachable" => unreachable, // not a value
3389 .null => {
3390 // TODO: proper representation for this
3391 try dwarf.abbrevCode(di_nw, .undefined_comptime_value);
3392 try dwarf.refType(pt, di_nw, .null);
3393 },
3394 },
3395 .@"extern" => unreachable,
2899 .func => |func| {3396 .func => |func| {
2900 const fn_ty = ip.indexToKey(func.ty).func_type;3397 const func_type = ip.indexToKey(func.ty).func_type;
2901 const nav = ip.getNav(func.owner_nav);3398 const nav = ip.getNav(func.owner_nav);
2902 const inst_info = nav.srcInst(ip).resolveFull(ip).?;3399 const inst_info = nav.srcInst(ip).resolveFull(ip).?;
2903 const zf = zcu.fileByIndex(inst_info.file);3400 const zir = &zcu.fileByIndex(inst_info.file).zir.?;
2904 const decl = zf.zir.?.getDeclaration(inst_info.inst);3401 const decl = zir.getDeclaration(inst_info.inst);
3402 const is_empty = func_type.param_types.len == 0 and !func_type.is_var_args;
2905 const parent_ty: Type = .fromInterned(ip.namespacePtr(nav.analysis.?.namespace).owner_type);3403 const parent_ty: Type = .fromInterned(ip.namespacePtr(nav.analysis.?.namespace).owner_type);
2906 try dwarf.abbrevCode(di_nw, .decl_func_generic);3404 if (func.generic_owner != .none or parent_ty.getCaptures(zcu).len > 0) {
2907 try dwarf.refType(pt, di_nw, parent_ty);3405 try dwarf.abbrevCode(
2908 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);3406 di_nw,
2909 try di_w.writeUleb128(decl.src_column + 1);3407 if (is_empty) .decl_instance_empty_func_generic else .decl_instance_func_generic,
2910 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);3408 );
2911 try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip));3409 try dwarf.refType(pt, di_nw, parent_ty);
2912 try dwarf.refType(pt, di_nw, .fromInterned(fn_ty.return_type));3410 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, @"const"), 0);
2913 var param_index: u32 = 0;3411 } else {
2914 for (zf.zir.?.getParamBody(func.zir_body_inst.resolve(ip).?)) |param_inst| {3412 try dwarf.abbrevCode(
2915 switch (zf.zir.?.getParamName(param_inst) orelse break) {3413 di_nw,
3414 if (is_empty) .decl_empty_func_generic else .decl_func_generic,
3415 );
3416 try dwarf.refType(pt, di_nw, parent_ty);
3417 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
3418 try di_w.writeUleb128(decl.src_column + 1);
3419 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
3420 try dwarf.strx(di_nw, nav.name.toSlice(ip));
3421 }
3422 try dwarf.refType(pt, di_nw, .fromInterned(func_type.return_type));
3423 for (
3424 zir.getParamBody(func.zir_body_inst.resolve(ip).?)[0..func_type.param_types.len],
3425 func_type.param_types.get(&zcu.intern_pool),
3426 ) |param_inst, param_ty| {
3427 switch (zir.getParamName(param_inst).?) {
2916 .empty => try dwarf.abbrevCode(di_nw, .unnamed_param),3428 .empty => try dwarf.abbrevCode(di_nw, .unnamed_param),
2917 else => |param_name| {3429 else => |param_name| {
2918 try dwarf.abbrevCode(di_nw, .param);3430 try dwarf.abbrevCode(di_nw, .param);
2919 try dwarf.strp(&dwarf.debug_str, di_nw, zf.zir.?.nullTerminatedString(3431 try dwarf.strx(di_nw, zir.nullTerminatedString(param_name));
2920 param_name,
2921 ));
2922 },3432 },
2923 }3433 }
2924 try dwarf.refType(pt, di_nw, .fromInterned(3434 try dwarf.refType(pt, di_nw, .fromInterned(param_ty));
2925 fn_ty.param_types.get(&zcu.intern_pool)[param_index],3435 }
2926 ));3436 if (func_type.is_var_args) try dwarf.abbrevCode(di_nw, .is_var_args);
2927 param_index += 1;3437 if (!is_empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
3438 },
3439 .int => |int| {
3440 var big_int_space: Value.BigIntSpace = undefined;
3441 try dwarf.abbrevCode(di_nw, .comptime_value);
3442 try dwarf.refType(pt, di_nw, .fromInterned(int.ty));
3443 try dwarf.bigIntConstValue(
3444 di_w,
3445 .fromInterned(int.ty),
3446 Value.fromInterned(@"const").toBigInt(&big_int_space, zcu),
3447 );
3448 },
3449 .bitpack => |bitpack| {
3450 var big_int_space: Value.BigIntSpace = undefined;
3451 const backing_int_val: Value = .fromInterned(bitpack.backing_int_val);
3452 try dwarf.abbrevCode(di_nw, .comptime_value);
3453 try dwarf.refType(pt, di_nw, .fromInterned(bitpack.ty));
3454 try dwarf.bigIntConstValue(
3455 di_w,
3456 backing_int_val.typeOf(zcu),
3457 backing_int_val.toBigInt(&big_int_space, zcu),
3458 );
3459 },
3460 .err => |err| {
3461 try dwarf.abbrevCode(di_nw, .comptime_value);
3462 try dwarf.refType(pt, di_nw, .fromInterned(err.ty));
3463 try di_w.writeUleb128(DW.FORM.udata);
3464 try di_w.writeUleb128(try pt.getErrorValue(err.name));
3465 },
3466 .error_union => |error_union| {
3467 try dwarf.abbrevCode(di_nw, .aggregate_undefined_comptime_value);
3468 try dwarf.refType(pt, di_nw, .fromInterned(error_union.ty));
3469 var err_buf: [4]u8 = undefined;
3470 const err_bytes = err_buf[0..@divCeil(zcu.errorSetBits(), 8)];
3471 const err_val = switch (error_union.val) {
3472 .err_name => |err_name| try pt.getErrorValue(err_name),
3473 .payload => 0,
3474 };
3475 switch (err_bytes.len) {
3476 else => unreachable,
3477 inline 0...4 => |len| std.mem.writeInt(
3478 @Int(.unsigned, 8 * len),
3479 err_bytes[0..len],
3480 @intCast(err_val),
3481 dwarf.endian,
3482 ),
3483 }
3484 {
3485 try dwarf.abbrevCode(di_nw, .comptime_value_field_runtime);
3486 try dwarf.strx(di_nw, "is_error");
3487 try di_w.writeUleb128(err_bytes.len);
3488 try di_w.writeAll(err_bytes);
3489 }
3490 payload_field: switch (error_union.val) {
3491 .err_name => {},
3492 .payload => |payload_val| {
3493 const payload_ty: Type = .fromInterned(ip.typeOf(payload_val));
3494 const payload_class = payload_ty.classify(zcu);
3495 try dwarf.abbrevCode(di_nw, if (payload_class.comptimeOnly())
3496 .comptime_value_field_comptime
3497 else if (payload_class.hasRuntimeBits())
3498 .comptime_value_field_runtime
3499 else
3500 break :payload_field);
3501 try dwarf.strx(di_nw, "value");
3502 if (payload_class.comptimeOnly())
3503 try dwarf.refConst(pt, di_nw, .fromInterned(payload_val))
3504 else if (payload_class.hasRuntimeBits())
3505 try dwarf.blockConst(pt, di_nw, .fromInterned(payload_val))
3506 else
3507 unreachable;
3508 },
3509 }
3510 {
3511 try dwarf.abbrevCode(di_nw, .comptime_value_field_runtime);
3512 try dwarf.strx(di_nw, "error");
3513 try di_w.writeUleb128(err_bytes.len);
3514 try di_w.writeAll(err_bytes);
3515 }
3516 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
3517 },
3518 .enum_literal => |enum_literal| {
3519 try dwarf.abbrevCode(di_nw, .comptime_value);
3520 try dwarf.refType(pt, di_nw, .enum_literal);
3521 try di_w.writeUleb128(DW.FORM.strx);
3522 try dwarf.strx(di_nw, enum_literal.toSlice(ip));
3523 },
3524 .enum_tag => |enum_tag| {
3525 var big_int_space: Value.BigIntSpace = undefined;
3526 const int = ip.indexToKey(enum_tag.int).int;
3527 try dwarf.abbrevCode(di_nw, .comptime_value);
3528 try dwarf.refType(pt, di_nw, .fromInterned(enum_tag.ty));
3529 try dwarf.bigIntConstValue(
3530 di_w,
3531 .fromInterned(int.ty),
3532 Value.fromInterned(@"const").toBigInt(&big_int_space, zcu),
3533 );
3534 },
3535 .float => |float| {
3536 try dwarf.abbrevCode(di_nw, .comptime_value);
3537 try dwarf.refType(pt, di_nw, .fromInterned(float.ty));
3538 switch (float.storage) {
3539 .f16 => |f16_val| {
3540 try di_w.writeUleb128(DW.FORM.data2);
3541 try di_w.writeInt(u16, @bitCast(f16_val), dwarf.endian);
3542 },
3543 .f32 => |f32_val| {
3544 try di_w.writeUleb128(DW.FORM.data4);
3545 try di_w.writeInt(u32, @bitCast(f32_val), dwarf.endian);
3546 },
3547 .f64 => |f64_val| {
3548 try di_w.writeUleb128(DW.FORM.data8);
3549 try di_w.writeInt(u64, @bitCast(f64_val), dwarf.endian);
3550 },
3551 .f80 => |f80_val| {
3552 try di_w.writeUleb128(DW.FORM.block);
3553 try di_w.writeUleb128(@divExact(80, 8));
3554 try di_w.writeInt(u80, @bitCast(f80_val), dwarf.endian);
3555 },
3556 .f128 => |f128_val| {
3557 try di_w.writeUleb128(DW.FORM.data16);
3558 try di_w.writeInt(u128, @bitCast(f128_val), dwarf.endian);
3559 },
3560 }
3561 },
3562 .ptr => |ptr| {
3563 const Access = union(enum) {
3564 index: u64,
3565 field: InternPool.NullTerminatedString,
3566 synthetic_field: []const u8,
3567 tuple_index: u32,
3568 };
3569 var zero_bit_accesses: std.ArrayList(Access) = .empty;
3570 defer zero_bit_accesses.deinit(zcu.gpa);
3571 location: {
3572 var base_addr = ptr.base_addr;
3573 var byte_offset = ptr.byte_offset;
3574 const base_ni = while (true) {
3575 const base_ptr, const access: Access = base_ptr_access: switch (base_addr) {
3576 .nav => |ni| break (try dwarf.getGlobal(ni)).get(dwarf).debug_info_ni,
3577 .comptime_alloc, .comptime_field => unreachable,
3578 .uav => |uav| {
3579 const uav_ty: Type = .fromInterned(ip.typeOf(uav.val));
3580 if (uav_ty.classify(zcu) == .one_possible_value) {
3581 try dwarf.abbrevCode(di_nw, if (zero_bit_accesses.items.len > 0)
3582 .aggregate_comptime_value
3583 else
3584 .comptime_value);
3585 try dwarf.refType(pt, di_nw, .fromInterned(ptr.ty));
3586 try di_w.writeUleb128(DW.FORM.udata);
3587 try di_w.writeUleb128(ip.indexToKey(uav.orig_ty)
3588 .ptr_type.flags.alignment.toByteUnits() orelse
3589 uav_ty.abiAlignment(zcu).toByteUnits().?);
3590 break :location;
3591 } else break Const.get(try dwarf.getConst(pt, .fromInterned(
3592 uav.val,
3593 )), dwarf).debug_info_ni;
3594 },
3595 .int => {
3596 try dwarf.abbrevCode(di_nw, if (zero_bit_accesses.items.len > 0)
3597 .aggregate_comptime_value
3598 else
3599 .comptime_value);
3600 try dwarf.refType(pt, di_nw, .fromInterned(ptr.ty));
3601 try di_w.writeUleb128(DW.FORM.udata);
3602 try di_w.writeUleb128(byte_offset);
3603 break :location;
3604 },
3605 .eu_payload => |eu_ptr| {
3606 const base_ptr = ip.indexToKey(eu_ptr).ptr;
3607 byte_offset += codegen.errUnionPayloadOffset(.fromInterned(ip.indexToKey(
3608 ip.indexToKey(base_ptr.ty).ptr_type.child,
3609 ).error_union_type.payload_type), zcu);
3610 break :base_ptr_access .{ base_ptr, .{ .synthetic_field = "value" } };
3611 },
3612 .opt_payload => |opt_ptr| .{ ip.indexToKey(opt_ptr).ptr, .{
3613 .synthetic_field = "?",
3614 } },
3615 .field => |field| {
3616 const base_ptr = ip.indexToKey(field.base).ptr;
3617 const agg_ty: Type =
3618 .fromInterned(ip.indexToKey(base_ptr.ty).ptr_type.child);
3619 break :base_ptr_access .{
3620 base_ptr,
3621 if (agg_ty.isSlice(zcu)) .{ .synthetic_field = switch (field.index) {
3622 Value.slice_ptr_index => "ptr",
3623 Value.slice_len_index => "len",
3624 else => unreachable,
3625 } } else if (agg_ty.structFieldName(
3626 @intCast(field.index),
3627 zcu,
3628 ).unwrap()) |field_name|
3629 .{ .field = field_name }
3630 else
3631 .{ .tuple_index = @intCast(field.index) },
3632 };
3633 },
3634 .arr_elem => |arr_elem| .{
3635 ip.indexToKey(arr_elem.base).ptr,
3636 .{ .index = arr_elem.index },
3637 },
3638 };
3639 base_addr = base_ptr.base_addr;
3640 byte_offset += base_ptr.byte_offset;
3641 if (Type.fromInterned(
3642 ip.indexToKey(base_ptr.ty).ptr_type.child,
3643 ).hasRuntimeBits(zcu))
3644 assert(access != .index)
3645 else
3646 try zero_bit_accesses.append(zcu.gpa, access);
3647 };
3648 try dwarf.abbrevCode(di_nw, if (zero_bit_accesses.items.len > 0)
3649 .aggregate_location_comptime_value
3650 else
3651 .location_comptime_value);
3652 try dwarf.refType(pt, di_nw, .fromInterned(ptr.ty));
3653 try dwarf.exprLoc(di_nw, .{ .implicit_pointer = .{
3654 .node = base_ni.unwrap().?,
3655 .offset = byte_offset,
3656 } });
3657 }
3658 if (zero_bit_accesses.items.len > 0) {
3659 for (zero_bit_accesses.items) |access| switch (access) {
3660 .index => |index| {
3661 try dwarf.abbrevCode(di_nw, .array_index);
3662 try di_w.writeUleb128(index);
3663 },
3664 .field => |field| {
3665 try dwarf.abbrevCode(di_nw, .access);
3666 try dwarf.strx(di_nw, field.toSlice(ip));
3667 },
3668 .synthetic_field => |field| {
3669 try dwarf.abbrevCode(di_nw, .access);
3670 try dwarf.strx(di_nw, field);
3671 },
3672 .tuple_index => |index| {
3673 try dwarf.abbrevCode(di_nw, .access);
3674 var field_name_buf: [std.fmt.count("{d}", .{std.math.maxInt(u32)})]u8 =
3675 undefined;
3676 const field_name = std.mem.print(&field_name_buf, "{d}", .{index}) catch
3677 unreachable;
3678 try dwarf.strx(di_nw, field_name);
3679 },
3680 };
3681 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
3682 }
3683 },
3684 .slice => |slice| {
3685 try dwarf.abbrevCode(di_nw, .aggregate_undefined_comptime_value);
3686 try dwarf.refType(pt, di_nw, .fromInterned(slice.ty));
3687 {
3688 try dwarf.abbrevCode(di_nw, .comptime_value_field_comptime);
3689 try dwarf.strx(di_nw, "ptr");
3690 try dwarf.refConst(pt, di_nw, .fromInterned(slice.ptr));
3691 }
3692 {
3693 try dwarf.abbrevCode(di_nw, .comptime_value_field_runtime);
3694 try dwarf.strx(di_nw, "len");
3695 try dwarf.blockConst(pt, di_nw, .fromInterned(slice.len));
3696 }
3697 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
3698 },
3699 .opt => |opt| {
3700 const opt_child_ty: Type = .fromInterned(ip.indexToKey(opt.ty).opt_type);
3701 try dwarf.abbrevCode(di_nw, .aggregate_undefined_comptime_value);
3702 try dwarf.refType(pt, di_nw, .fromInterned(opt.ty));
3703 {
3704 try dwarf.abbrevCode(di_nw, .comptime_value_field_runtime);
3705 try dwarf.strx(di_nw, "has_value");
3706 switch (optRepr(opt_child_ty, zcu)) {
3707 .opv_null => try di_w.writeUleb128(0),
3708 .unpacked => try dwarf.blockConst(pt, di_nw, .makeBool(opt.val != .none)),
3709 .error_set, .pointer => try dwarf.blockConst(pt, di_nw, .fromInterned(@"const")),
3710 }
3711 }
3712 if (opt.val != .none) child_field: {
3713 const opt_child_class = opt_child_ty.classify(zcu);
3714 try dwarf.abbrevCode(di_nw, if (opt_child_class.comptimeOnly())
3715 .comptime_value_field_comptime
3716 else if (opt_child_class.hasRuntimeBits())
3717 .comptime_value_field_runtime
3718 else
3719 break :child_field);
3720 try dwarf.strx(di_nw, "?");
3721 if (opt_child_class.comptimeOnly())
3722 try dwarf.refConst(pt, di_nw, .fromInterned(opt.val))
3723 else if (opt_child_class.hasRuntimeBits())
3724 try dwarf.blockConst(pt, di_nw, .fromInterned(opt.val))
3725 else
3726 unreachable;
3727 }
3728 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
3729 },
3730 .aggregate => |aggregate| {
3731 try dwarf.abbrevCode(di_nw, .aggregate_undefined_comptime_value);
3732 try dwarf.refType(pt, di_nw, .fromInterned(aggregate.ty));
3733 switch (ip.indexToKey(aggregate.ty)) {
3734 .struct_type => {
3735 const loaded_struct = ip.loadStructType(aggregate.ty);
3736 assert(loaded_struct.layout == .auto);
3737 for (0..loaded_struct.field_types.len) |field_index| {
3738 if (loaded_struct.field_is_comptime_bits.get(ip, field_index)) continue;
3739 const field_ty: Type =
3740 .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
3741 const field_class = field_ty.classify(zcu);
3742 try dwarf.abbrevCode(di_nw, if (field_class.comptimeOnly())
3743 .comptime_value_field_comptime
3744 else if (field_class.hasRuntimeBits())
3745 .comptime_value_field_runtime
3746 else
3747 continue);
3748 try dwarf.strx(
3749 di_nw,
3750 loaded_struct.field_names.get(ip)[field_index].toSlice(ip),
3751 );
3752 const field_value: Value = .fromInterned(switch (aggregate.storage) {
3753 .bytes => unreachable,
3754 .elems => |elems| elems[field_index],
3755 .repeated_elem => |repeated_elem| repeated_elem,
3756 });
3757 if (field_class.comptimeOnly())
3758 try dwarf.refConst(pt, di_nw, field_value)
3759 else if (field_class.hasRuntimeBits())
3760 try dwarf.blockConst(pt, di_nw, field_value)
3761 else
3762 unreachable;
3763 }
3764 },
3765 .tuple_type => |tuple_type| for (0..tuple_type.types.len) |field_index| {
3766 if (tuple_type.values.get(ip)[field_index] != .none) continue;
3767 const field_ty: Type = .fromInterned(tuple_type.types.get(ip)[field_index]);
3768 const field_class = field_ty.classify(zcu);
3769 try dwarf.abbrevCode(di_nw, if (field_class.comptimeOnly())
3770 .comptime_value_field_comptime
3771 else if (field_class.hasRuntimeBits())
3772 .comptime_value_field_runtime
3773 else
3774 continue);
3775 {
3776 var field_name_buf: [std.fmt.count("{d}", .{std.math.maxInt(u32)})]u8 =
3777 undefined;
3778 const field_name = std.mem.print(&field_name_buf, "{d}", .{field_index}) catch
3779 unreachable;
3780 try dwarf.strx(di_nw, field_name);
3781 }
3782 const field_value: Value = .fromInterned(switch (aggregate.storage) {
3783 .bytes => unreachable,
3784 .elems => |elems| elems[field_index],
3785 .repeated_elem => |repeated_elem| repeated_elem,
3786 });
3787 if (field_class.comptimeOnly())
3788 try dwarf.refConst(pt, di_nw, field_value)
3789 else if (field_class.hasRuntimeBits())
3790 try dwarf.blockConst(pt, di_nw, field_value)
3791 else
3792 unreachable;
3793 },
3794 inline .array_type, .vector_type => |sequence_type| {
3795 const child_ty: Type = .fromInterned(sequence_type.child);
3796 const child_class = child_ty.classify(zcu);
3797 for (switch (aggregate.storage) {
3798 .bytes => unreachable,
3799 .elems => |elems| elems,
3800 .repeated_elem => |*repeated_elem| repeated_elem[0..1],
3801 }) |elem| {
3802 try dwarf.abbrevCode(di_nw, if (child_class.comptimeOnly())
3803 .comptime_value_elem_comptime
3804 else if (child_class.hasRuntimeBits())
3805 .comptime_value_elem_runtime
3806 else
3807 break);
3808 if (child_class.comptimeOnly())
3809 try dwarf.refConst(pt, di_nw, .fromInterned(elem))
3810 else if (child_class.hasRuntimeBits())
3811 try dwarf.blockConst(pt, di_nw, .fromInterned(elem))
3812 else
3813 unreachable;
3814 }
3815 },
3816 else => unreachable,
3817 }
3818 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
3819 },
3820 .un => |un| {
3821 try dwarf.abbrevCode(di_nw, .aggregate_undefined_comptime_value);
3822 try dwarf.refType(pt, di_nw, .fromInterned(un.ty));
3823 {
3824 const loaded_union = ip.loadUnionType(un.ty);
3825 assert(loaded_union.layout == .auto);
3826 const field_index = zcu.unionTagFieldIndex(loaded_union, Value.fromInterned(un.tag)).?;
3827 const field_ty: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]);
3828 const field_class = field_ty.classify(zcu);
3829 const field_name =
3830 ip.loadEnumType(loaded_union.enum_tag_type).field_names.get(ip)[field_index];
3831 try dwarf.abbrevCode(di_nw, if (field_class.comptimeOnly())
3832 .comptime_value_field_comptime
3833 else if (field_class.hasRuntimeBits())
3834 .comptime_value_field_runtime
3835 else
3836 .access);
3837 try dwarf.strx(di_nw, field_name.toSlice(ip));
3838 if (field_class.comptimeOnly())
3839 try dwarf.refConst(pt, di_nw, .fromInterned(un.val))
3840 else if (field_class.hasRuntimeBits())
3841 try dwarf.blockConst(pt, di_nw, .fromInterned(un.val));
2928 }3842 }
2929 if (fn_ty.is_var_args) try dwarf.abbrevCode(di_nw, .is_var_args);
2930 try di_w.writeUleb128(@backingInt(AbbrevCode.null));3843 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
2931 },3844 },
29323845
...@@ -2935,11 +3848,11 @@ fn updateConstInner(...@@ -2935,11 +3848,11 @@ fn updateConstInner(
2935 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());3848 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());
2936}3849}
29373850
2938fn optRepr(opt_child_type: Type, zcu: *const Zcu) enum { unpacked, opv_null, error_set, pointer } {3851fn optRepr(opt_child_ty: Type, zcu: *const Zcu) enum { unpacked, opv_null, error_set, pointer } {
2939 if (opt_child_type.isNoReturn(zcu)) return .opv_null;3852 if (opt_child_ty.isNoReturn(zcu)) return .opv_null;
2940 return switch (opt_child_type.toIntern()) {3853 return switch (opt_child_ty.toIntern()) {
2941 .anyerror_type => .error_set,3854 .anyerror_type => .error_set,
2942 else => switch (zcu.intern_pool.indexToKey(opt_child_type.toIntern())) {3855 else => switch (zcu.intern_pool.indexToKey(opt_child_ty.toIntern())) {
2943 else => .unpacked,3856 else => .unpacked,
2944 .error_set_type, .inferred_error_set_type => .error_set,3857 .error_set_type, .inferred_error_set_type => .error_set,
2945 .ptr_type => |ptr_type| if (ptr_type.flags.is_allowzero) .unpacked else .pointer,3858 .ptr_type => |ptr_type| if (ptr_type.flags.is_allowzero) .unpacked else .pointer,
...@@ -2983,21 +3896,21 @@ fn updateConstIncompleteInner(...@@ -2983,21 +3896,21 @@ fn updateConstIncompleteInner(
2983 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, src_inst.file);3896 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, src_inst.file);
2984 try dwarf.abbrevCode(di_nw, .empty_file);3897 try dwarf.abbrevCode(di_nw, .empty_file);
2985 try di_w.writeUleb128(@backingInt(fi));3898 try di_w.writeUleb128(@backingInt(fi));
2986 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.name.toSlice(ip));3899 try dwarf.strx(di_nw, loaded_struct.name.toSlice(ip));
2987 try di_w.writeByte(@intFromBool(true));3900 try di_w.writeByte(@intFromBool(true));
2988 break :done;3901 break :done;
2989 },3902 },
2990 else => {3903 else => {
2991 const data =3904 const zir = &zf.zir.?;
2992 zf.zir.?.instructions.items(.data)[@backingInt(src_inst.inst)].extended;3905 const data = zir.instructions.items(.data)[@backingInt(src_inst.inst)].extended;
2993 const src_line, const src_column = src_loc: switch (data.opcode) {3906 const src_line, const src_column = src_loc: switch (data.opcode) {
2994 else => unreachable,3907 else => unreachable,
2995 .struct_decl => {3908 .struct_decl => {
2996 const decl = zf.zir.?.getStructDecl(src_inst.inst);3909 const decl = zir.getStructDecl(src_inst.inst);
2997 break :src_loc .{ decl.src_line, decl.src_column };3910 break :src_loc .{ decl.src_line, decl.src_column };
2998 },3911 },
2999 .reify_struct => {3912 .reify_struct => {
3000 const decl = zf.zir.?.extraData(3913 const decl = zir.extraData(
3001 std.zig.Zir.Inst.ReifyStruct,3914 std.zig.Zir.Inst.ReifyStruct,
3002 data.operand,3915 data.operand,
3003 ).data;3916 ).data;
...@@ -3025,15 +3938,16 @@ fn updateConstIncompleteInner(...@@ -3025,15 +3938,16 @@ fn updateConstIncompleteInner(
3025 break :done;3938 break :done;
3026 };3939 };
3027 const zf = zcu.fileByIndex(src_inst.file);3940 const zf = zcu.fileByIndex(src_inst.file);
3028 const data = zf.zir.?.instructions.items(.data)[@backingInt(src_inst.inst)].extended;3941 const zir = &zf.zir.?;
3942 const data = zir.instructions.items(.data)[@backingInt(src_inst.inst)].extended;
3029 const src_line, const src_column = src_loc: switch (data.opcode) {3943 const src_line, const src_column = src_loc: switch (data.opcode) {
3030 else => unreachable,3944 else => unreachable,
3031 .union_decl => {3945 .union_decl => {
3032 const decl = zf.zir.?.getUnionDecl(src_inst.inst);3946 const decl = zir.getUnionDecl(src_inst.inst);
3033 break :src_loc .{ decl.src_line, decl.src_column };3947 break :src_loc .{ decl.src_line, decl.src_column };
3034 },3948 },
3035 .reify_union => {3949 .reify_union => {
3036 const decl = zf.zir.?.extraData(std.zig.Zir.Inst.ReifyUnion, data.operand).data;3950 const decl = zir.extraData(std.zig.Zir.Inst.ReifyUnion, data.operand).data;
3037 break :src_loc .{ decl.src_line, decl.src_column };3951 break :src_loc .{ decl.src_line, decl.src_column };
3038 },3952 },
3039 };3953 };
...@@ -3053,7 +3967,7 @@ fn updateConstIncompleteInner(...@@ -3053,7 +3967,7 @@ fn updateConstIncompleteInner(
3053 const loaded_enum = ip.loadEnumType(val);3967 const loaded_enum = ip.loadEnumType(val);
3054 const zir_index = loaded_enum.zir_index.unwrap() orelse {3968 const zir_index = loaded_enum.zir_index.unwrap() orelse {
3055 try dwarf.abbrevCode(di_nw, .generated_empty_struct_type);3969 try dwarf.abbrevCode(di_nw, .generated_empty_struct_type);
3056 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.name.toSlice(ip));3970 try dwarf.strx(di_nw, loaded_enum.name.toSlice(ip));
3057 try di_w.writeByte(@intFromBool(true));3971 try di_w.writeByte(@intFromBool(true));
3058 break :done;3972 break :done;
3059 };3973 };
...@@ -3062,15 +3976,16 @@ fn updateConstIncompleteInner(...@@ -3062,15 +3976,16 @@ fn updateConstIncompleteInner(
3062 break :done;3976 break :done;
3063 };3977 };
3064 const zf = zcu.fileByIndex(src_inst.file);3978 const zf = zcu.fileByIndex(src_inst.file);
3065 const data = zf.zir.?.instructions.items(.data)[@backingInt(src_inst.inst)].extended;3979 const zir = &zf.zir.?;
3980 const data = zir.instructions.items(.data)[@backingInt(src_inst.inst)].extended;
3066 const src_line, const src_column = src_loc: switch (data.opcode) {3981 const src_line, const src_column = src_loc: switch (data.opcode) {
3067 else => unreachable,3982 else => unreachable,
3068 .enum_decl => {3983 .enum_decl => {
3069 const decl = zf.zir.?.getEnumDecl(src_inst.inst);3984 const decl = zir.getEnumDecl(src_inst.inst);
3070 break :src_loc .{ decl.src_line, decl.src_column };3985 break :src_loc .{ decl.src_line, decl.src_column };
3071 },3986 },
3072 .reify_enum => {3987 .reify_enum => {
3073 const decl = zf.zir.?.extraData(std.zig.Zir.Inst.ReifyEnum, data.operand).data;3988 const decl = zir.extraData(std.zig.Zir.Inst.ReifyEnum, data.operand).data;
3074 break :src_loc .{ decl.src_line, decl.src_column };3989 break :src_loc .{ decl.src_line, decl.src_column };
3075 },3990 },
3076 };3991 };
...@@ -3112,7 +4027,7 @@ fn updateConstIncompleteInner(...@@ -3112,7 +4027,7 @@ fn updateConstIncompleteInner(
3112 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});4027 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
3113 defer zcu.gpa.free(name);4028 defer zcu.gpa.free(name);
3114 try dwarf.abbrevCode(di_nw, .generated_empty_struct_type);4029 try dwarf.abbrevCode(di_nw, .generated_empty_struct_type);
3115 try dwarf.strp(&dwarf.debug_str, di_nw, name);4030 try dwarf.strx(di_nw, name);
3116 try di_w.writeByte(@intFromBool(true));4031 try di_w.writeByte(@intFromBool(true));
3117 },4032 },
3118 else => |ty| {4033 else => |ty| {
...@@ -3131,13 +4046,15 @@ fn updateConstIncompleteInner(...@@ -3131,13 +4046,15 @@ fn updateConstIncompleteInner(
3131 .@"union" => .decl_instance_empty_incomplete_union,4046 .@"union" => .decl_instance_empty_incomplete_union,
3132 .@"enum" => .decl_instance_empty_incomplete_enum,4047 .@"enum" => .decl_instance_empty_incomplete_enum,
3133 });4048 });
3134 try dwarf.secOffset(di_nw, try dwarf.getDecl(pt, val), 0);4049 try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr(
4050 ip.namespacePtr(namespace).parent.unwrap().?,
4051 ).owner_type));
4052 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, val), 0);
3135 } else if (maybe_name_nav.unwrap()) |name_ni| {4053 } else if (maybe_name_nav.unwrap()) |name_ni| {
3136 const name_nav = ip.getNav(name_ni);4054 const name_nav = ip.getNav(name_ni);
3137 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);4055 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
3138 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(4056 const parent_ni =
3139 name_nav.analysis.?.namespace,4057 try dwarf.getConstDecl(pt, ip.namespacePtr(name_nav.analysis.?.namespace).owner_type);
3140 ).owner_type);
3141 try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) {4058 try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) {
3142 .@"struct" => .decl_incomplete_struct,4059 .@"struct" => .decl_incomplete_struct,
3143 .@"union" => .decl_incomplete_union,4060 .@"union" => .decl_incomplete_union,
...@@ -3151,9 +4068,9 @@ fn updateConstIncompleteInner(...@@ -3151,9 +4068,9 @@ fn updateConstIncompleteInner(
3151 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);4068 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
3152 try di_w.writeUleb128(decl.src_column + 1);4069 try di_w.writeUleb128(decl.src_column + 1);
3153 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);4070 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
3154 try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip));4071 try dwarf.strx(di_nw, name_nav.name.toSlice(ip));
3155 } else {4072 } else {
3156 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(4073 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
3157 ip.namespacePtr(namespace).parent.unwrap().?,4074 ip.namespacePtr(namespace).parent.unwrap().?,
3158 ).owner_type);4075 ).owner_type);
3159 try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) {4076 try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) {
...@@ -3168,7 +4085,7 @@ fn updateConstIncompleteInner(...@@ -3168,7 +4085,7 @@ fn updateConstIncompleteInner(
3168 try dwarf.secOffset(di_nw, parent_ni, 0);4085 try dwarf.secOffset(di_nw, parent_ni, 0);
3169 try di_w.writeInt(u32, src_line + 1, dwarf.endian);4086 try di_w.writeInt(u32, src_line + 1, dwarf.endian);
3170 try di_w.writeUleb128(src_column + 1);4087 try di_w.writeUleb128(src_column + 1);
3171 try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip));4088 try dwarf.strx(di_nw, name.toSlice(ip));
3172 }4089 }
3173 try dwarf.genCaptures(pt, di_nw, captures);4090 try dwarf.genCaptures(pt, di_nw, captures);
3174 if (captures.len > 0) try di_w.writeByte(@backingInt(AbbrevCode.null));4091 if (captures.len > 0) try di_w.writeByte(@backingInt(AbbrevCode.null));
...@@ -3224,10 +4141,16 @@ pub fn genDecl(...@@ -3224,10 +4141,16 @@ pub fn genDecl(
3224 dwarf: *Dwarf,4141 dwarf: *Dwarf,
3225 pt: Zcu.PerThread,4142 pt: Zcu.PerThread,
3226 di_nw: *link.MappedFile.Node.Writer,4143 di_nw: *link.MappedFile.Node.Writer,
3227 instance_val: InternPool.Index,4144 instance: Decl.Instance,
3228) link.Error!void {4145) link.Error!void {
3229 log.debug("genDecl({f})", .{Value.fromInterned(instance_val).fmtValue(pt)});4146 switch (instance) {
3230 dwarf.genDeclInner(pt, di_nw, instance_val) catch |err| switch (err) {4147 .none => unreachable,
4148 .@"const" => |@"const"| log.debug("genDecl({f})", .{Value.fromInterned(@"const").fmtValue(pt)}),
4149 .global => |global| log.debug("genDecl({f})", .{
4150 pt.zcu.intern_pool.getNav(global).fqn.fmt(&pt.zcu.intern_pool),
4151 }),
4152 }
4153 dwarf.genDeclInner(pt, di_nw, instance) catch |err| switch (err) {
3231 else => |e| return e,4154 else => |e| return e,
3232 error.WriteFailed => return dwarf.reportWriteError(di_nw),4155 error.WriteFailed => return dwarf.reportWriteError(di_nw),
3233 };4156 };
...@@ -3236,216 +4159,255 @@ fn genDeclInner(...@@ -3236,216 +4159,255 @@ fn genDeclInner(
3236 dwarf: *Dwarf,4159 dwarf: *Dwarf,
3237 pt: Zcu.PerThread,4160 pt: Zcu.PerThread,
3238 di_nw: *link.MappedFile.Node.Writer,4161 di_nw: *link.MappedFile.Node.Writer,
3239 instance_val: InternPool.Index,4162 instance: Decl.Instance,
3240) link.EmitError!void {4163) link.EmitError!void {
3241 const zcu = pt.zcu;4164 const zcu = pt.zcu;
3242 const ip = &zcu.intern_pool;4165 const ip = &zcu.intern_pool;
3243 const di_w = &di_nw.interface;4166 const di_w = &di_nw.interface;
3244 done: {4167 done: switch (instance) {
3245 const kind: enum { @"struct", @"union", @"enum" }, const zf, const src_line, const src_column, const capture_names, const captures, const name, const maybe_name_nav, const namespace = container: switch (ip.indexToKey(instance_val)) {4168 .none => unreachable,
3246 else => unreachable,4169 .@"const" => |@"const"| {
3247 .struct_type => {4170 const kind: enum { @"struct", @"union", @"enum" }, const zf, const src_line, const src_column, const capture_names, const captures, const maybe_name_nav, const namespace = container: switch (ip.indexToKey(instance.@"const")) {
3248 const loaded_struct = ip.loadStructType(instance_val);4171 else => unreachable,
3249 const src_inst = loaded_struct.zir_index.resolveFull(ip) orelse {4172 .struct_type => {
3250 try dwarf.lostTracking(di_nw);4173 const loaded_struct = ip.loadStructType(@"const");
3251 break :done;4174 const src_inst = loaded_struct.zir_index.resolveFull(ip) orelse {
3252 };4175 try dwarf.lostTracking(di_nw);
3253 const zf = zcu.fileByIndex(src_inst.file);4176 break :done;
3254 const inst = zf.zir.?.instructions.get(@backingInt(src_inst.inst));4177 };
3255 const src_line, const src_column, const capture_names = decl: switch (inst.tag) {4178 const zf = zcu.fileByIndex(src_inst.file);
3256 else => unreachable,4179 const zir = &zf.zir.?;
3257 .struct_init, .struct_init_ref => {4180 const inst = zir.instructions.get(@backingInt(src_inst.inst));
3258 const decl = zf.zir.?.extraData(4181 const src_line, const src_column, const capture_names = decl: switch (inst.tag) {
3259 std.zig.Zir.Inst.StructInit,
3260 inst.data.pl_node.payload_index,
3261 ).data;
3262 break :decl .{ decl.src_line, decl.src_column, &.{} };
3263 },
3264 .struct_init_anon => {
3265 const decl = zf.zir.?.extraData(
3266 std.zig.Zir.Inst.StructInitAnon,
3267 inst.data.pl_node.payload_index,
3268 ).data;
3269 break :decl .{ decl.src_line, decl.src_column, &.{} };
3270 },
3271 .extended => switch (inst.data.extended.opcode) {
3272 else => unreachable,4182 else => unreachable,
3273 .struct_decl => {4183 .struct_init, .struct_init_ref => {
3274 const decl = zf.zir.?.getStructDecl(src_inst.inst);4184 const decl = zir.extraData(
3275 break :decl .{ decl.src_line, decl.src_column, decl.capture_names };4185 std.zig.Zir.Inst.StructInit,
3276 },4186 inst.data.pl_node.payload_index,
3277 .reify_struct => {
3278 const decl = zf.zir.?.extraData(
3279 std.zig.Zir.Inst.ReifyStruct,
3280 inst.data.extended.operand,
3281 ).data;4187 ).data;
3282 break :decl .{ decl.src_line, decl.src_column, &.{} };4188 break :decl .{ decl.src_line, decl.src_column, &.{} };
3283 },4189 },
3284 },4190 .struct_init_anon => {
3285 };4191 const decl = zir.extraData(
3286 break :container .{4192 std.zig.Zir.Inst.StructInitAnon,
3287 .@"struct",4193 inst.data.pl_node.payload_index,
3288 zf,
3289 src_line,
3290 src_column,
3291 capture_names,
3292 loaded_struct.captures,
3293 loaded_struct.name,
3294 loaded_struct.name_nav,
3295 loaded_struct.namespace,
3296 };
3297 },
3298 .union_type => {
3299 const loaded_union = ip.loadUnionType(instance_val);
3300 const src_inst = loaded_union.zir_index.resolveFull(ip) orelse {
3301 try dwarf.lostTracking(di_nw);
3302 break :done;
3303 };
3304 const zf = zcu.fileByIndex(src_inst.file);
3305 const inst = zf.zir.?.instructions.get(@backingInt(src_inst.inst));
3306 const src_line, const src_column, const capture_names = decl: switch (inst.tag) {
3307 else => unreachable,
3308 .extended => switch (inst.data.extended.opcode) {
3309 else => unreachable,
3310 .union_decl => {
3311 const decl = zf.zir.?.getUnionDecl(src_inst.inst);
3312 break :decl .{ decl.src_line, decl.src_column, decl.capture_names };
3313 },
3314 .reify_union => {
3315 const decl = zf.zir.?.extraData(
3316 std.zig.Zir.Inst.ReifyUnion,
3317 inst.data.extended.operand,
3318 ).data;4194 ).data;
3319 break :decl .{ decl.src_line, decl.src_column, &.{} };4195 break :decl .{ decl.src_line, decl.src_column, &.{} };
3320 },4196 },
3321 },4197 .extended => switch (inst.data.extended.opcode) {
3322 };4198 else => unreachable,
3323 break :container .{4199 .struct_decl => {
3324 .@"union",4200 const decl = zir.getStructDecl(src_inst.inst);
3325 zf,4201 break :decl .{ decl.src_line, decl.src_column, decl.capture_names };
3326 src_line,4202 },
3327 src_column,4203 .reify_struct => {
3328 capture_names,4204 const decl = zir.extraData(
3329 loaded_union.captures,4205 std.zig.Zir.Inst.ReifyStruct,
3330 loaded_union.name,4206 inst.data.extended.operand,
3331 loaded_union.name_nav,4207 ).data;
3332 loaded_union.namespace,4208 break :decl .{ decl.src_line, decl.src_column, &.{} };
3333 };4209 },
3334 },4210 },
3335 .enum_type => {4211 };
3336 const loaded_enum = ip.loadEnumType(instance_val);4212 break :container .{
3337 const src_inst = loaded_enum.zir_index.unwrap().?.resolveFull(ip) orelse {4213 .@"struct",
3338 try dwarf.lostTracking(di_nw);4214 zf,
3339 break :done;4215 src_line,
3340 };4216 src_column,
3341 const zf = zcu.fileByIndex(src_inst.file);4217 capture_names,
3342 const inst = zf.zir.?.instructions.get(@backingInt(src_inst.inst));4218 loaded_struct.captures,
3343 const src_line, const src_column, const capture_names = decl: switch (inst.tag) {4219 loaded_struct.name_nav,
3344 else => unreachable,4220 loaded_struct.namespace,
3345 .extended => switch (inst.data.extended.opcode) {4221 };
4222 },
4223 .union_type => {
4224 const loaded_union = ip.loadUnionType(@"const");
4225 const src_inst = loaded_union.zir_index.resolveFull(ip) orelse {
4226 try dwarf.lostTracking(di_nw);
4227 break :done;
4228 };
4229 const zf = zcu.fileByIndex(src_inst.file);
4230 const zir = &zf.zir.?;
4231 const inst = zir.instructions.get(@backingInt(src_inst.inst));
4232 const src_line, const src_column, const capture_names = decl: switch (inst.tag) {
3346 else => unreachable,4233 else => unreachable,
3347 .enum_decl => {4234 .extended => switch (inst.data.extended.opcode) {
3348 const decl = zf.zir.?.getEnumDecl(src_inst.inst);4235 else => unreachable,
3349 break :decl .{ decl.src_line, decl.src_column, decl.capture_names };4236 .union_decl => {
4237 const decl = zir.getUnionDecl(src_inst.inst);
4238 break :decl .{ decl.src_line, decl.src_column, decl.capture_names };
4239 },
4240 .reify_union => {
4241 const decl = zir.extraData(
4242 std.zig.Zir.Inst.ReifyUnion,
4243 inst.data.extended.operand,
4244 ).data;
4245 break :decl .{ decl.src_line, decl.src_column, &.{} };
4246 },
3350 },4247 },
3351 .reify_enum => {4248 };
3352 const decl = zf.zir.?.extraData(4249 break :container .{
3353 std.zig.Zir.Inst.ReifyEnum,4250 .@"union",
3354 inst.data.extended.operand,4251 zf,
3355 ).data;4252 src_line,
3356 break :decl .{ decl.src_line, decl.src_column, &.{} };4253 src_column,
4254 capture_names,
4255 loaded_union.captures,
4256 loaded_union.name_nav,
4257 loaded_union.namespace,
4258 };
4259 },
4260 .enum_type => {
4261 const loaded_enum = ip.loadEnumType(@"const");
4262 const src_inst = loaded_enum.zir_index.unwrap().?.resolveFull(ip) orelse {
4263 try dwarf.lostTracking(di_nw);
4264 break :done;
4265 };
4266 const zf = zcu.fileByIndex(src_inst.file);
4267 const zir = &zf.zir.?;
4268 const inst = zir.instructions.get(@backingInt(src_inst.inst));
4269 const src_line, const src_column, const capture_names = decl: switch (inst.tag) {
4270 else => unreachable,
4271 .extended => switch (inst.data.extended.opcode) {
4272 else => unreachable,
4273 .enum_decl => {
4274 const decl = zir.getEnumDecl(src_inst.inst);
4275 break :decl .{ decl.src_line, decl.src_column, decl.capture_names };
4276 },
4277 .reify_enum => {
4278 const decl = zir.extraData(
4279 std.zig.Zir.Inst.ReifyEnum,
4280 inst.data.extended.operand,
4281 ).data;
4282 break :decl .{ decl.src_line, decl.src_column, &.{} };
4283 },
3357 },4284 },
3358 },4285 };
3359 };4286 break :container .{
3360 break :container .{4287 .@"enum",
3361 .@"enum",4288 zf,
3362 zf,4289 src_line,
3363 src_line,4290 src_column,
3364 src_column,4291 capture_names,
3365 capture_names,4292 loaded_enum.captures,
3366 loaded_enum.captures,4293 loaded_enum.name_nav,
3367 loaded_enum.name,4294 loaded_enum.namespace,
3368 loaded_enum.name_nav,4295 };
3369 loaded_enum.namespace,4296 },
3370 };4297 .opaque_type => {
3371 },4298 const loaded_opaque = ip.loadOpaqueType(@"const");
3372 .opaque_type => {4299 const src_inst = loaded_opaque.zir_index.resolveFull(ip) orelse {
3373 const loaded_opaque = ip.loadOpaqueType(instance_val);4300 try dwarf.lostTracking(di_nw);
3374 const src_inst = loaded_opaque.zir_index.resolveFull(ip) orelse {4301 break :done;
3375 try dwarf.lostTracking(di_nw);4302 };
4303 const zf = zcu.fileByIndex(src_inst.file);
4304 const decl = zf.zir.?.getOpaqueDecl(src_inst.inst);
4305 break :container .{
4306 .@"struct",
4307 zf,
4308 decl.src_line,
4309 decl.src_column,
4310 decl.capture_names,
4311 loaded_opaque.captures,
4312 loaded_opaque.name_nav,
4313 loaded_opaque.namespace,
4314 };
4315 },
4316 .func => |func| {
4317 const owner_nav = ip.getNav(switch (func.generic_owner) {
4318 else => |generic_owner| zcu.funcInfo(generic_owner).owner_nav,
4319 .none => func.owner_nav,
4320 });
4321 const inst_info = owner_nav.srcInst(ip).resolveFull(ip).?;
4322 const decl = zcu.fileByIndex(inst_info.file).zir.?.getDeclaration(inst_info.inst);
4323 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
4324 owner_nav.analysis.?.namespace,
4325 ).owner_type);
4326 try dwarf.abbrevCode(di_nw, .decl_specification_func);
4327 try dwarf.secOffset(di_nw, parent_ni, 0);
4328 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
4329 try di_w.writeUleb128(decl.src_column + 1);
4330 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
4331 try dwarf.strx(di_nw, owner_nav.name.toSlice(ip));
3376 break :done;4332 break :done;
3377 };4333 },
3378 const zf = zcu.fileByIndex(src_inst.file);4334 };
3379 const decl = zf.zir.?.getOpaqueDecl(src_inst.inst);4335 const zir = &zf.zir.?;
3380 break :container .{4336 if (maybe_name_nav.unwrap()) |name_ni| {
3381 .@"struct",4337 const name_nav = ip.getNav(name_ni);
3382 zf,4338 const decl = zir.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
3383 decl.src_line,4339 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
3384 decl.src_column,4340 name_nav.analysis.?.namespace,
3385 decl.capture_names,4341 ).owner_type);
3386 loaded_opaque.captures,4342 try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) {
3387 loaded_opaque.name,4343 .@"struct" => .decl_specification_struct,
3388 loaded_opaque.name_nav,4344 .@"union" => .decl_specification_union,
3389 loaded_opaque.namespace,4345 .@"enum" => .decl_specification_enum,
3390 };4346 } else switch (kind) {
3391 },4347 .@"struct" => .decl_specification_empty_struct,
3392 };4348 .@"union" => .decl_specification_empty_union,
3393 if (maybe_name_nav.unwrap()) |name_ni| {4349 .@"enum" => .decl_specification_empty_enum,
3394 const name_nav = ip.getNav(name_ni);4350 });
3395 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);4351 try dwarf.secOffset(di_nw, parent_ni, 0);
3396 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(4352 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
3397 name_nav.analysis.?.namespace,4353 try di_w.writeUleb128(decl.src_column + 1);
3398 ).owner_type);4354 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
3399 try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) {4355 try dwarf.strx(di_nw, name_nav.name.toSlice(ip));
3400 .@"struct" => .decl_specification_struct,4356 } else {
3401 .@"union" => .decl_specification_union,4357 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
3402 .@"enum" => .decl_specification_enum,4358 ip.namespacePtr(namespace).parent.unwrap().?,
3403 } else switch (kind) {4359 ).owner_type);
3404 .@"struct" => .decl_specification_empty_struct,4360 try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) {
3405 .@"union" => .decl_specification_empty_union,4361 .@"struct" => .type_decl_specification_struct,
3406 .@"enum" => .decl_specification_empty_enum,4362 .@"union" => .type_decl_specification_union,
3407 });4363 .@"enum" => .type_decl_specification_enum,
3408 try dwarf.secOffset(di_nw, parent_ni, 0);4364 } else switch (kind) {
3409 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);4365 .@"struct" => .type_decl_specification_empty_struct,
3410 try di_w.writeUleb128(decl.src_column + 1);4366 .@"union" => .type_decl_specification_empty_union,
3411 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);4367 .@"enum" => .type_decl_specification_empty_enum,
3412 try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip));4368 });
3413 } else {4369 try dwarf.secOffset(di_nw, parent_ni, 0);
3414 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(4370 try di_w.writeInt(u32, src_line + 1, dwarf.endian);
3415 ip.namespacePtr(namespace).parent.unwrap().?,4371 try di_w.writeUleb128(src_column + 1);
4372 }
4373 for (capture_names, captures.get(ip)) |capture_name, capture| {
4374 try dwarf.abbrevCode(di_nw, .capture_specification);
4375 switch (capture.unwrap()) {
4376 .@"comptime",
4377 .runtime,
4378 .nav_val,
4379 => try dwarf.strx(di_nw, zir.nullTerminatedString(capture_name)),
4380 .nav_ref => {
4381 const capture_name_slice =
4382 try zcu.gpa.print("&{s}", .{zir.nullTerminatedString(capture_name)});
4383 defer zcu.gpa.free(capture_name_slice);
4384 try dwarf.strx(di_nw, capture_name_slice);
4385 },
4386 }
4387 }
4388 if (captures.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
4389 },
4390 .global => |global| {
4391 const nav = ip.getNav(global);
4392 const nav_const, const nav_ty = nav_resolved: {
4393 const nav_resolved = nav.resolved.?;
4394 break :nav_resolved .{ nav_resolved.@"const", nav_resolved.type };
4395 };
4396 const src_inst = nav.srcInst(ip).resolveFull(ip).?;
4397 const decl = zcu.fileByIndex(src_inst.file).zir.?.getDeclaration(src_inst.inst);
4398 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
4399 nav.analysis.?.namespace,
3416 ).owner_type);4400 ).owner_type);
3417 try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) {4401 try dwarf.abbrevCode(di_nw, switch (nav_ty) {
3418 .@"struct" => .type_decl_specification_struct,4402 .type_type => .decl_specification_type,
3419 .@"union" => .type_decl_specification_union,4403 else => if (nav_const) .decl_specification_const else .decl_specification_var,
3420 .@"enum" => .type_decl_specification_enum,
3421 } else switch (kind) {
3422 .@"struct" => .type_decl_specification_empty_struct,
3423 .@"union" => .type_decl_specification_empty_union,
3424 .@"enum" => .type_decl_specification_empty_enum,
3425 });4404 });
3426 try dwarf.secOffset(di_nw, parent_ni, 0);4405 try dwarf.secOffset(di_nw, parent_ni, 0);
3427 try di_w.writeInt(u32, src_line + 1, dwarf.endian);4406 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
3428 try di_w.writeUleb128(src_column + 1);4407 try di_w.writeUleb128(decl.src_column + 1);
3429 try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip));4408 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
3430 }4409 try dwarf.strx(di_nw, nav.name.toSlice(ip));
3431 for (capture_names, captures.get(ip)) |capture_name, capture| {4410 },
3432 try dwarf.abbrevCode(di_nw, .capture_specification);
3433 switch (capture.unwrap()) {
3434 .@"comptime", .runtime, .nav_val => try dwarf.strp(
3435 &dwarf.debug_str,
3436 di_nw,
3437 zf.zir.?.nullTerminatedString(capture_name),
3438 ),
3439 .nav_ref => {
3440 const capture_name_slice = try zcu.gpa.print("&{s}", .{
3441 zf.zir.?.nullTerminatedString(capture_name),
3442 });
3443 defer zcu.gpa.free(capture_name_slice);
3444 try dwarf.strp(&dwarf.debug_str, di_nw, capture_name_slice);
3445 },
3446 }
3447 }
3448 if (captures.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
3449 }4411 }
3450 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());4412 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());
3451}4413}
...@@ -3458,9 +4420,12 @@ pub fn updateLineNumber(...@@ -3458,9 +4420,12 @@ pub fn updateLineNumber(
3458) void {4420) void {
3459 const di = dwarf.getDeclIfExists(inst) orelse return;4421 const di = dwarf.getDeclIfExists(inst) orelse return;
3460 const decl_ni = di.get(dwarf).debug_info_ni.unwrap().?;4422 const decl_ni = di.get(dwarf).debug_info_ni.unwrap().?;
4423 comptime assert(AbbrevCode.common_decl_attrs[0][1] == .ref_addr);
4424 comptime assert(AbbrevCode.common_decl_attrs[1][0] == .decl_line);
4425 comptime assert(AbbrevCode.common_decl_attrs[1][1] == .data4);
3461 std.mem.writeInt(4426 std.mem.writeInt(
3462 u32,4427 u32,
3463 decl_ni.slice(mf)[AbbrevCode.decl_size..][0..4],4428 decl_ni.slice(mf)[AbbrevCode.decl_size + dwarf.secOffsetSize() ..][0..4],
3464 line + 1,4429 line + 1,
3465 dwarf.endian,4430 dwarf.endian,
3466 );4431 );
...@@ -3486,8 +4451,11 @@ fn refAbbrevCode(...@@ -3486,8 +4451,11 @@ fn refAbbrevCode(
3486 @branchHint(.likely);4451 @branchHint(.likely);
3487 return backing_int;4452 return backing_int;
3488 }4453 }
4454 const gpa = dwarf.lf.comp.gpa;
4455 const debug_abbrev_ni = dwarf.debug_abbrev.ni.unwrap().?;
4456 try debug_abbrev_ni.moved(gpa, mf);
3489 var da_nw: link.MappedFile.Node.Writer = undefined;4457 var da_nw: link.MappedFile.Node.Writer = undefined;
3490 dwarf.debug_abbrev.ni.unwrap().?.writer(dwarf.lf.comp.gpa, mf, &da_nw);4458 debug_abbrev_ni.writer(gpa, mf, &da_nw);
3491 defer da_nw.deinit();4459 defer da_nw.deinit();
3492 dwarf.genDebugAbbrev(&da_nw, abbrev_code) catch |err| switch (err) {4460 dwarf.genDebugAbbrev(&da_nw, abbrev_code) catch |err| switch (err) {
3493 else => |e| return e,4461 else => |e| return e,
...@@ -3526,15 +4494,12 @@ fn genDebugAbbrev(...@@ -3526,15 +4494,12 @@ fn genDebugAbbrev(
3526 dwarf.debug_abbrev.end = da_w.end;4494 dwarf.debug_abbrev.end = da_w.end;
3527}4495}
35284496
3529pub fn secOffsetSize(dwarf: *Dwarf) usize {4497fn secOffsetSize(dwarf: *Dwarf) usize {
3530 return switch (dwarf.format) {4498 return switch (dwarf.format) {
3531 .@"32" => 4,4499 .@"32" => 4,
3532 .@"64" => 8,4500 .@"64" => 8,
3533 };4501 };
3534}4502}
3535fn secOffsetPlaceholder(dwarf: *Dwarf, w: *std.Io.Writer) std.Io.Writer.Error!void {
3536 @memset(try w.writableSlice(dwarf.secOffsetSize()), undefined);
3537}
3538fn secOffset(4503fn secOffset(
3539 dwarf: *Dwarf,4504 dwarf: *Dwarf,
3540 nw: *link.MappedFile.Node.Writer,4505 nw: *link.MappedFile.Node.Writer,
...@@ -3543,6 +4508,18 @@ fn secOffset(...@@ -3543,6 +4508,18 @@ fn secOffset(
3543) link.EmitError!void {4508) link.EmitError!void {
3544 const offset = nw.interface.end;4509 const offset = nw.interface.end;
3545 try dwarf.secOffsetPlaceholder(&nw.interface);4510 try dwarf.secOffsetPlaceholder(&nw.interface);
4511 try dwarf.secOffsetFinish(nw, offset, target_ni, addend);
4512}
4513fn secOffsetPlaceholder(dwarf: *Dwarf, w: *std.Io.Writer) std.Io.Writer.Error!void {
4514 @memset(try w.writableSlice(dwarf.secOffsetSize()), undefined);
4515}
4516fn secOffsetFinish(
4517 dwarf: *Dwarf,
4518 nw: *link.MappedFile.Node.Writer,
4519 offset: usize,
4520 target_ni: link.MappedFile.Node.Index,
4521 addend: usize,
4522) link.Error!void {
3546 if (dwarf.lf.cast(.elf2)) |elf| try elf.addNodeReloc(4523 if (dwarf.lf.cast(.elf2)) |elf| try elf.addNodeReloc(
3547 nw.ni,4524 nw.ni,
3548 offset,4525 offset,
...@@ -3574,6 +4551,21 @@ fn addrSym(...@@ -3574,6 +4551,21 @@ fn addrSym(
3574 .absAddr(elf),4551 .absAddr(elf),
3575 ) else unreachable;4552 ) else unreachable;
3576}4553}
4554fn addrxSym(dwarf: *Dwarf, w: *std.Io.Writer, si: link.File.SymbolId) link.EmitError!void {
4555 try w.writeUleb128(try dwarf.debug_addr.get(dwarf.lf.comp.gpa, si));
4556}
4557fn addrx1Sym(dwarf: *Dwarf, w: *std.Io.Writer, si: link.File.SymbolId) link.EmitError!void {
4558 try w.writeByte(@intCast(try dwarf.debug_addr.get(dwarf.lf.comp.gpa, si)));
4559}
4560fn addrx2Sym(dwarf: *Dwarf, w: *std.Io.Writer, si: link.File.SymbolId) link.EmitError!void {
4561 try w.writeInt(u16, @intCast(try dwarf.debug_addr.get(dwarf.lf.comp.gpa, si)), dwarf.endian);
4562}
4563fn addrx3Sym(dwarf: *Dwarf, w: *std.Io.Writer, si: link.File.SymbolId) link.EmitError!void {
4564 try w.writeInt(u24, @intCast(try dwarf.debug_addr.get(dwarf.lf.comp.gpa, si)), dwarf.endian);
4565}
4566fn addrx4Sym(dwarf: *Dwarf, w: *std.Io.Writer, si: link.File.SymbolId) link.EmitError!void {
4567 try w.writeInt(u32, @intCast(try dwarf.debug_addr.get(dwarf.lf.comp.gpa, si)), dwarf.endian);
4568}
35774569
3578fn blockConst(4570fn blockConst(
3579 dwarf: *Dwarf,4571 dwarf: *Dwarf,
...@@ -3585,13 +4577,9 @@ fn blockConst(...@@ -3585,13 +4577,9 @@ fn blockConst(
3585 const size = ty.abiSize(pt.zcu);4577 const size = ty.abiSize(pt.zcu);
3586 try nw.interface.writeUleb128(size);4578 try nw.interface.writeUleb128(size);
3587 const start = nw.interface.end;4579 const start = nw.interface.end;
3588 if (size > 0) try codegen.generateSymbol(4580 if (size > 0) try codegen.generateSymbol(dwarf.lf, pt, val, &nw.interface, .{
3589 dwarf.lf,4581 .atom_index = @bitCast(nw.ni),
3590 pt,4582 });
3591 val,
3592 &nw.interface,
3593 .{ .atom_index = @bitCast(nw.ni) },
3594 );
3595 assert(start + size == nw.interface.end);4583 assert(start + size == nw.interface.end);
3596}4584}
35974585
...@@ -3691,13 +4679,37 @@ fn exprLoc(dwarf: *Dwarf, nw: *link.MappedFile.Node.Writer, loc: Loc) link.EmitE...@@ -3691,13 +4679,37 @@ fn exprLoc(dwarf: *Dwarf, nw: *link.MappedFile.Node.Writer, loc: Loc) link.EmitE
3691fn strp(dwarf: *Dwarf, s: *Str, nw: *link.MappedFile.Node.Writer, str: []const u8) link.EmitError!void {4679fn strp(dwarf: *Dwarf, s: *Str, nw: *link.MappedFile.Node.Writer, str: []const u8) link.EmitError!void {
3692 const comp = dwarf.lf.comp;4680 const comp = dwarf.lf.comp;
3693 try dwarf.secOffset(nw, s.ni.unwrap().?, s.get(comp.gpa, nw.mf, str) catch |err| switch (err) {4681 try dwarf.secOffset(nw, s.ni.unwrap().?, s.get(comp.gpa, nw.mf, str) catch |err| switch (err) {
4682 else => |e| return e,
3694 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{4683 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{
3695 nw.mf.io_err.?,4684 nw.mf.io_err.?,
3696 }),4685 }),
3697 else => |e| return e,
3698 });4686 });
3699}4687}
37004688
4689fn strx(dwarf: *Dwarf, nw: *link.MappedFile.Node.Writer, str: []const u8) link.EmitError!void {
4690 try nw.interface.writeUleb128(try dwarf.debug_str_offsets.get(dwarf, &dwarf.debug_str, nw.mf, str));
4691}
4692fn strx1(dwarf: *Dwarf, nw: *link.MappedFile.Node.Writer, str: []const u8) link.EmitError!void {
4693 try nw.interface.writeByte(@intCast(
4694 try dwarf.debug_str_offsets.get(dwarf, &dwarf.debug_str, nw.mf, str),
4695 ));
4696}
4697fn strx2(dwarf: *Dwarf, nw: *link.MappedFile.Node.Writer, str: []const u8) link.EmitError!void {
4698 try nw.interface.writeInt(u16, @intCast(
4699 try dwarf.debug_str_offsets.get(dwarf, &dwarf.debug_str, nw.mf, str),
4700 ), dwarf.endian);
4701}
4702fn strx3(dwarf: *Dwarf, nw: *link.MappedFile.Node.Writer, str: []const u8) link.EmitError!void {
4703 try nw.interface.writeInt(u24, @intCast(
4704 try dwarf.debug_str_offsets.get(dwarf, &dwarf.debug_str, nw.mf, str),
4705 ), dwarf.endian);
4706}
4707fn strx4(dwarf: *Dwarf, nw: *link.MappedFile.Node.Writer, str: []const u8) link.EmitError!void {
4708 try nw.interface.writeInt(u32, @intCast(
4709 try dwarf.debug_str_offsets.get(dwarf, &dwarf.debug_str, nw.mf, str),
4710 ), dwarf.endian);
4711}
4712
3701fn reportWriteError(dwarf: *Dwarf, nw: *const link.MappedFile.Node.Writer) link.Error {4713fn reportWriteError(dwarf: *Dwarf, nw: *const link.MappedFile.Node.Writer) link.Error {
3702 switch (nw.err.?) {4714 switch (nw.err.?) {
3703 else => |e| return e,4715 else => |e| return e,
...@@ -3744,7 +4756,6 @@ pub const AbbrevCode = enum {...@@ -3744,7 +4756,6 @@ pub const AbbrevCode = enum {
3744 pad_n,4756 pad_n,
3745 // decl, specification, and instance codes are assumed to all have the same uleb128 size4757 // decl, specification, and instance codes are assumed to all have the same uleb128 size
3746 decl_lost,4758 decl_lost,
3747 decl_alias,
3748 decl_empty_incomplete_enum,4759 decl_empty_incomplete_enum,
3749 decl_incomplete_enum,4760 decl_incomplete_enum,
3750 decl_empty_enum,4761 decl_empty_enum,
...@@ -3777,16 +4788,17 @@ pub const AbbrevCode = enum {...@@ -3777,16 +4788,17 @@ pub const AbbrevCode = enum {
3777 decl_packed_union,4788 decl_packed_union,
3778 type_decl_empty_packed_union,4789 type_decl_empty_packed_union,
3779 type_decl_packed_union,4790 type_decl_packed_union,
3780 decl_var,4791 decl_type,
3781 decl_const,4792 decl_const,
3782 decl_const_runtime_bits,4793 decl_const_fully_runtime,
3783 decl_const_comptime_state,4794 decl_const_partially_comptime,
3784 decl_const_runtime_bits_comptime_state,4795 decl_const_fully_comptime,
3785 decl_nullary_func,4796 decl_var,
4797 decl_empty_func,
3786 decl_func,4798 decl_func,
3787 decl_nullary_func_generic,4799 decl_empty_func_generic,
3788 decl_func_generic,4800 decl_func_generic,
3789 decl_extern_nullary_func,4801 decl_extern_empty_func,
3790 decl_extern_func,4802 decl_extern_func,
3791 decl_specification_empty_struct,4803 decl_specification_empty_struct,
3792 decl_specification_struct,4804 decl_specification_struct,
...@@ -3800,40 +4812,48 @@ pub const AbbrevCode = enum {...@@ -3800,40 +4812,48 @@ pub const AbbrevCode = enum {
3800 decl_specification_union,4812 decl_specification_union,
3801 type_decl_specification_empty_union,4813 type_decl_specification_empty_union,
3802 type_decl_specification_union,4814 type_decl_specification_union,
4815 decl_specification_type,
4816 decl_specification_const,
4817 decl_specification_var,
3803 decl_specification_func,4818 decl_specification_func,
3804 decl_instance_alias,
3805 decl_instance_empty_incomplete_enum,4819 decl_instance_empty_incomplete_enum,
3806 decl_instance_incomplete_enum,4820 decl_instance_incomplete_enum,
3807 decl_instance_empty_enum,4821 decl_instance_empty_enum,
3808 decl_instance_enum,4822 decl_instance_enum,
4823 type_decl_instance_empty_enum,
4824 type_decl_instance_enum,
3809 decl_instance_empty_incomplete_struct,4825 decl_instance_empty_incomplete_struct,
3810 decl_instance_incomplete_struct,4826 decl_instance_incomplete_struct,
3811 decl_instance_empty_struct,4827 decl_instance_empty_struct,
3812 decl_instance_struct,4828 decl_instance_struct,
4829 type_decl_instance_empty_struct,
4830 type_decl_instance_struct,
3813 decl_instance_empty_packed_struct,4831 decl_instance_empty_packed_struct,
3814 decl_instance_packed_struct,4832 decl_instance_packed_struct,
4833 type_decl_instance_empty_packed_struct,
4834 type_decl_instance_packed_struct,
3815 decl_instance_empty_incomplete_union,4835 decl_instance_empty_incomplete_union,
3816 decl_instance_incomplete_union,4836 decl_instance_incomplete_union,
3817 decl_instance_empty_union,4837 decl_instance_empty_union,
3818 decl_instance_union,4838 decl_instance_union,
4839 type_decl_instance_empty_union,
4840 type_decl_instance_union,
3819 decl_instance_empty_packed_union,4841 decl_instance_empty_packed_union,
3820 decl_instance_packed_union,4842 decl_instance_packed_union,
3821 decl_instance_var,4843 type_decl_instance_empty_packed_union,
4844 type_decl_instance_packed_union,
4845 decl_instance_type,
3822 decl_instance_const,4846 decl_instance_const,
3823 decl_instance_const_runtime_bits,4847 decl_instance_const_fully_runtime,
3824 decl_instance_const_comptime_state,4848 decl_instance_const_partially_comptime,
3825 decl_instance_const_runtime_bits_comptime_state,4849 decl_instance_const_fully_comptime,
3826 decl_instance_nullary_func,4850 decl_instance_var,
4851 decl_instance_empty_func,
3827 decl_instance_func,4852 decl_instance_func,
3828 decl_instance_nullary_func_generic,4853 decl_instance_empty_func_generic,
3829 decl_instance_func_generic,4854 decl_instance_func_generic,
3830 decl_instance_extern_nullary_func,
3831 decl_instance_extern_func,
3832 // the rest are unrestricted other than empty variants must not be longer4855 // the rest are unrestricted other than empty variants must not be longer
3833 // than the non-empty variant, and so should appear first4856 // than the non-empty variant, and so should appear first
3834 compile_unit,
3835 module,
3836 module_dependency,
3837 empty_file,4857 empty_file,
3838 file,4858 file,
3839 access,4859 access,
...@@ -3856,8 +4876,7 @@ pub const AbbrevCode = enum {...@@ -3856,8 +4876,7 @@ pub const AbbrevCode = enum {
3856 inferred_error_set_type,4876 inferred_error_set_type,
3857 ptr_type,4877 ptr_type,
3858 ptr_sentinel_type,4878 ptr_sentinel_type,
3859 ptr_aligned_type,4879 is_aligned,
3860 ptr_aligned_sentinel_type,
3861 is_const,4880 is_const,
3862 is_volatile,4881 is_volatile,
3863 array_type,4882 array_type,
...@@ -3865,7 +4884,7 @@ pub const AbbrevCode = enum {...@@ -3865,7 +4884,7 @@ pub const AbbrevCode = enum {
3865 vector_type,4884 vector_type,
3866 array_index,4885 array_index,
3867 array_len,4886 array_len,
3868 nullary_func_type,4887 empty_func_type,
3869 func_type,4888 func_type,
3870 param,4889 param,
3871 unnamed_param,4890 unnamed_param,
...@@ -3882,7 +4901,7 @@ pub const AbbrevCode = enum {...@@ -3882,7 +4901,7 @@ pub const AbbrevCode = enum {
3882 comptime_capture_fully_comptime,4901 comptime_capture_fully_comptime,
3883 runtime_capture,4902 runtime_capture,
3884 nav_capture,4903 nav_capture,
3885 builtin_extern_nullary_func,4904 builtin_extern_empty_func,
3886 builtin_extern_func,4905 builtin_extern_func,
3887 builtin_extern_var,4906 builtin_extern_var,
3888 empty_block,4907 empty_block,
...@@ -3911,44 +4930,51 @@ pub const AbbrevCode = enum {...@@ -3911,44 +4930,51 @@ pub const AbbrevCode = enum {
3911 aggregate_undefined_comptime_value,4930 aggregate_undefined_comptime_value,
3912 aggregate_comptime_value,4931 aggregate_comptime_value,
3913 aggregate_location_comptime_value,4932 aggregate_location_comptime_value,
3914 comptime_value_field_runtime_bits,4933 comptime_value_field_runtime,
3915 comptime_value_field_comptime_state,4934 comptime_value_field_comptime,
3916 comptime_value_elem_runtime_bits,4935 comptime_value_elem_runtime,
3917 comptime_value_elem_comptime_state,4936 comptime_value_elem_comptime,
4937 // low-frequency should appear last
4938 compile_unit,
4939 module,
4940 module_dependency,
39184941
3919 const decl_size = uleb128Size(@backingInt(AbbrevCode.decl_instance_extern_func));4942 const decl_size = uleb128Size(@backingInt(AbbrevCode.decl_func_generic));
3920 comptime {4943 comptime {
3921 assert(uleb128Size(@backingInt(AbbrevCode.pad_1)) == 1);4944 assert(uleb128Size(@backingInt(AbbrevCode.pad_1)) == 1);
3922 assert(uleb128Size(@backingInt(AbbrevCode.pad_n)) == 1);4945 assert(uleb128Size(@backingInt(AbbrevCode.pad_n)) == 1);
3923 assert(uleb128Size(@backingInt(AbbrevCode.decl_alias)) == decl_size);4946 assert(uleb128Size(@backingInt(AbbrevCode.decl_lost)) == decl_size);
3924 }4947 }
39254948
3926 const Attr = struct {4949 const Attr = struct {
3927 DeclValEnum(DW.AT),4950 DeclValEnum(DW.AT),
3928 DeclValEnum(DW.FORM),4951 DeclValEnum(DW.FORM),
3929 };4952 };
3930 const decl_attrs = &[_]Attr{4953 const common_decl_attrs = &[_]Attr{
3931 .{ .ZIG_parent, .ref_addr },4954 .{ .ZIG_parent, .ref_addr },
3932 .{ .decl_line, .data4 },4955 .{ .decl_line, .data4 },
3933 .{ .decl_column, .udata },4956 .{ .decl_column, .udata },
4957 };
4958 const decl_attrs = common_decl_attrs ++ .{
3934 .{ .accessibility, .data1 },4959 .{ .accessibility, .data1 },
3935 .{ .name, .strp },4960 .{ .name, .strx },
3936 };4961 };
3937 const type_decl_attrs = &[_]Attr{4962 const type_decl_attrs = common_decl_attrs ++ .{
3938 .{ .ZIG_parent, .ref_addr },4963 .{ .name, .strx },
3939 .{ .decl_line, .data4 },
3940 .{ .decl_column, .udata },
3941 .{ .name, .strp },
3942 };4964 };
3943 const decl_specification_attrs = decl_attrs ++ &[_]Attr{4965 const decl_specification_attrs = decl_attrs ++ &[_]Attr{
3944 .{ .declaration, .flag_present },4966 .{ .declaration, .flag_present },
3945 };4967 };
3946 const type_decl_specification_attrs = type_decl_attrs ++ &[_]Attr{4968 const type_decl_specification_attrs = common_decl_attrs ++ &[_]Attr{
3947 .{ .declaration, .flag_present },4969 .{ .declaration, .flag_present },
3948 };4970 };
3949 const decl_instance_attrs = &[_]Attr{4971 const decl_instance_attrs = &[_]Attr{
4972 .{ .ZIG_parent, .ref_addr },
3950 .{ .specification, .ref_addr },4973 .{ .specification, .ref_addr },
3951 };4974 };
4975 const type_decl_instance_attrs = decl_instance_attrs ++ .{
4976 .{ .name, .strx },
4977 };
39524978
3953 const abbrevs = std.EnumArray(AbbrevCode, struct {4979 const abbrevs = std.EnumArray(AbbrevCode, struct {
3954 tag: DeclValEnum(DW.TAG),4980 tag: DeclValEnum(DW.TAG),
...@@ -3968,12 +4994,6 @@ pub const AbbrevCode = enum {...@@ -3968,12 +4994,6 @@ pub const AbbrevCode = enum {
3968 .decl_lost = .{4994 .decl_lost = .{
3969 .tag = .ZIG_lost_declaration,4995 .tag = .ZIG_lost_declaration,
3970 },4996 },
3971 .decl_alias = .{
3972 .tag = .imported_declaration,
3973 .attrs = decl_attrs ++ .{
3974 .{ .import, .ref_addr },
3975 },
3976 },
3977 .decl_empty_incomplete_enum = .{4997 .decl_empty_incomplete_enum = .{
3978 .tag = .enumeration_type,4998 .tag = .enumeration_type,
3979 .attrs = decl_attrs,4999 .attrs = decl_attrs,
...@@ -4166,62 +5186,68 @@ pub const AbbrevCode = enum {...@@ -4166,62 +5186,68 @@ pub const AbbrevCode = enum {
4166 .{ .type, .ref_addr },5186 .{ .type, .ref_addr },
4167 },5187 },
4168 },5188 },
4169 .decl_var = .{5189 .decl_type = .{
4170 .tag = .variable,5190 .tag = .imported_declaration,
4171 .attrs = decl_attrs ++ .{5191 .attrs = decl_attrs ++ .{
4172 .{ .linkage_name, .strp },5192 .{ .import, .ref_addr },
4173 .{ .type, .ref_addr },
4174 .{ .location, .exprloc },
4175 .{ .alignment, .udata },
4176 .{ .external, .flag },
4177 },5193 },
4178 },5194 },
4179 .decl_const = .{5195 .decl_const = .{
4180 .tag = .constant,5196 .tag = .constant,
4181 .attrs = decl_attrs ++ .{5197 .attrs = decl_attrs ++ .{
4182 .{ .linkage_name, .strp },5198 .{ .linkage_name, .strx },
4183 .{ .type, .ref_addr },5199 .{ .type, .ref_addr },
4184 .{ .alignment, .udata },5200 .{ .alignment, .udata },
4185 .{ .external, .flag },5201 .{ .external, .flag },
4186 },5202 },
4187 },5203 },
4188 .decl_const_runtime_bits = .{5204 .decl_const_fully_runtime = .{
4189 .tag = .constant,5205 .tag = .constant,
4190 .attrs = decl_attrs ++ .{5206 .attrs = decl_attrs ++ .{
4191 .{ .linkage_name, .strp },5207 .{ .linkage_name, .strx },
4192 .{ .type, .ref_addr },5208 .{ .type, .ref_addr },
4193 .{ .alignment, .udata },5209 .{ .alignment, .udata },
4194 .{ .external, .flag },5210 .{ .external, .flag },
4195 .{ .const_value, .block },5211 .{ .const_value, .block },
4196 },5212 },
4197 },5213 },
4198 .decl_const_comptime_state = .{5214 .decl_const_partially_comptime = .{
4199 .tag = .constant,5215 .tag = .constant,
4200 .attrs = decl_attrs ++ .{5216 .attrs = decl_attrs ++ .{
4201 .{ .linkage_name, .strp },5217 .{ .linkage_name, .strx },
4202 .{ .type, .ref_addr },5218 .{ .type, .ref_addr },
4203 .{ .alignment, .udata },5219 .{ .alignment, .udata },
4204 .{ .external, .flag },5220 .{ .external, .flag },
5221 .{ .const_value, .block },
4205 .{ .ZIG_comptime_value, .ref_addr },5222 .{ .ZIG_comptime_value, .ref_addr },
4206 },5223 },
4207 },5224 },
4208 .decl_const_runtime_bits_comptime_state = .{5225 .decl_const_fully_comptime = .{
4209 .tag = .constant,5226 .tag = .constant,
4210 .attrs = decl_attrs ++ .{5227 .attrs = decl_attrs ++ .{
4211 .{ .linkage_name, .strp },5228 .{ .linkage_name, .strx },
4212 .{ .type, .ref_addr },5229 .{ .type, .ref_addr },
4213 .{ .alignment, .udata },5230 .{ .alignment, .udata },
4214 .{ .external, .flag },5231 .{ .external, .flag },
4215 .{ .const_value, .block },
4216 .{ .ZIG_comptime_value, .ref_addr },5232 .{ .ZIG_comptime_value, .ref_addr },
4217 },5233 },
4218 },5234 },
4219 .decl_nullary_func = .{5235 .decl_var = .{
5236 .tag = .variable,
5237 .attrs = decl_attrs ++ .{
5238 .{ .linkage_name, .strx },
5239 .{ .type, .ref_addr },
5240 .{ .location, .exprloc },
5241 .{ .alignment, .udata },
5242 .{ .external, .flag },
5243 },
5244 },
5245 .decl_empty_func = .{
4220 .tag = .subprogram,5246 .tag = .subprogram,
4221 .attrs = decl_attrs ++ .{5247 .attrs = decl_attrs ++ .{
4222 .{ .linkage_name, .strp },5248 .{ .linkage_name, .strx },
4223 .{ .type, .ref_addr },5249 .{ .type, .ref_addr },
4224 .{ .low_pc, .addr },5250 .{ .low_pc, .addrx },
4225 .{ .high_pc, .data4 },5251 .{ .high_pc, .data4 },
4226 .{ .alignment, .udata },5252 .{ .alignment, .udata },
4227 .{ .external, .flag },5253 .{ .external, .flag },
...@@ -4232,20 +5258,19 @@ pub const AbbrevCode = enum {...@@ -4232,20 +5258,19 @@ pub const AbbrevCode = enum {
4232 .tag = .subprogram,5258 .tag = .subprogram,
4233 .children = true,5259 .children = true,
4234 .attrs = decl_attrs ++ .{5260 .attrs = decl_attrs ++ .{
4235 .{ .linkage_name, .strp },5261 .{ .linkage_name, .strx },
4236 .{ .type, .ref_addr },5262 .{ .type, .ref_addr },
4237 .{ .low_pc, .addr },5263 .{ .low_pc, .addrx },
4238 .{ .high_pc, .data4 },5264 .{ .high_pc, .data4 },
4239 .{ .alignment, .udata },5265 .{ .alignment, .udata },
4240 .{ .external, .flag },5266 .{ .external, .flag },
4241 .{ .noreturn, .flag },5267 .{ .noreturn, .flag },
4242 },5268 },
4243 },5269 },
4244 .decl_nullary_func_generic = .{5270 .decl_empty_func_generic = .{
4245 .tag = .subprogram,5271 .tag = .subprogram,
4246 .attrs = decl_attrs ++ .{5272 .attrs = decl_attrs ++ .{
4247 .{ .type, .ref_addr },5273 .{ .type, .ref_addr },
4248 .{ .noreturn, .flag },
4249 },5274 },
4250 },5275 },
4251 .decl_func_generic = .{5276 .decl_func_generic = .{
...@@ -4255,10 +5280,10 @@ pub const AbbrevCode = enum {...@@ -4255,10 +5280,10 @@ pub const AbbrevCode = enum {
4255 .{ .type, .ref_addr },5280 .{ .type, .ref_addr },
4256 },5281 },
4257 },5282 },
4258 .decl_extern_nullary_func = .{5283 .decl_extern_empty_func = .{
4259 .tag = .subprogram,5284 .tag = .subprogram,
4260 .attrs = decl_attrs ++ .{5285 .attrs = decl_attrs ++ .{
4261 .{ .linkage_name, .strp },5286 .{ .linkage_name, .strx },
4262 .{ .type, .ref_addr },5287 .{ .type, .ref_addr },
4263 .{ .low_pc, .addr },5288 .{ .low_pc, .addr },
4264 .{ .external, .flag_present },5289 .{ .external, .flag_present },
...@@ -4269,7 +5294,7 @@ pub const AbbrevCode = enum {...@@ -4269,7 +5294,7 @@ pub const AbbrevCode = enum {
4269 .tag = .subprogram,5294 .tag = .subprogram,
4270 .children = true,5295 .children = true,
4271 .attrs = decl_attrs ++ .{5296 .attrs = decl_attrs ++ .{
4272 .{ .linkage_name, .strp },5297 .{ .linkage_name, .strx },
4273 .{ .type, .ref_addr },5298 .{ .type, .ref_addr },
4274 .{ .low_pc, .addr },5299 .{ .low_pc, .addr },
4275 .{ .external, .flag_present },5300 .{ .external, .flag_present },
...@@ -4330,16 +5355,22 @@ pub const AbbrevCode = enum {...@@ -4330,16 +5355,22 @@ pub const AbbrevCode = enum {
4330 .children = true,5355 .children = true,
4331 .attrs = type_decl_specification_attrs,5356 .attrs = type_decl_specification_attrs,
4332 },5357 },
5358 .decl_specification_type = .{
5359 .tag = .imported_declaration,
5360 .attrs = decl_specification_attrs,
5361 },
5362 .decl_specification_const = .{
5363 .tag = .constant,
5364 .attrs = decl_specification_attrs,
5365 },
5366 .decl_specification_var = .{
5367 .tag = .variable,
5368 .attrs = decl_specification_attrs,
5369 },
4333 .decl_specification_func = .{5370 .decl_specification_func = .{
4334 .tag = .subprogram,5371 .tag = .subprogram,
4335 .attrs = decl_specification_attrs,5372 .attrs = decl_specification_attrs,
4336 },5373 },
4337 .decl_instance_alias = .{
4338 .tag = .imported_declaration,
4339 .attrs = decl_instance_attrs ++ .{
4340 .{ .import, .ref_addr },
4341 },
4342 },
4343 .decl_instance_empty_incomplete_enum = .{5374 .decl_instance_empty_incomplete_enum = .{
4344 .tag = .enumeration_type,5375 .tag = .enumeration_type,
4345 .attrs = decl_instance_attrs,5376 .attrs = decl_instance_attrs,
...@@ -4362,6 +5393,19 @@ pub const AbbrevCode = enum {...@@ -4362,6 +5393,19 @@ pub const AbbrevCode = enum {
4362 .{ .type, .ref_addr },5393 .{ .type, .ref_addr },
4363 },5394 },
4364 },5395 },
5396 .type_decl_instance_empty_enum = .{
5397 .tag = .enumeration_type,
5398 .attrs = type_decl_instance_attrs ++ .{
5399 .{ .type, .ref_addr },
5400 },
5401 },
5402 .type_decl_instance_enum = .{
5403 .tag = .enumeration_type,
5404 .children = true,
5405 .attrs = type_decl_instance_attrs ++ .{
5406 .{ .type, .ref_addr },
5407 },
5408 },
4365 .decl_instance_empty_incomplete_struct = .{5409 .decl_instance_empty_incomplete_struct = .{
4366 .tag = .structure_type,5410 .tag = .structure_type,
4367 .attrs = decl_instance_attrs,5411 .attrs = decl_instance_attrs,
...@@ -4386,6 +5430,21 @@ pub const AbbrevCode = enum {...@@ -4386,6 +5430,21 @@ pub const AbbrevCode = enum {
4386 .{ .alignment, .udata },5430 .{ .alignment, .udata },
4387 },5431 },
4388 },5432 },
5433 .type_decl_instance_empty_struct = .{
5434 .tag = .structure_type,
5435 .attrs = type_decl_instance_attrs ++ .{
5436 .{ .byte_size, .udata },
5437 .{ .alignment, .udata },
5438 },
5439 },
5440 .type_decl_instance_struct = .{
5441 .tag = .structure_type,
5442 .children = true,
5443 .attrs = type_decl_instance_attrs ++ .{
5444 .{ .byte_size, .udata },
5445 .{ .alignment, .udata },
5446 },
5447 },
4389 .decl_instance_empty_packed_struct = .{5448 .decl_instance_empty_packed_struct = .{
4390 .tag = .structure_type,5449 .tag = .structure_type,
4391 .attrs = decl_instance_attrs ++ .{5450 .attrs = decl_instance_attrs ++ .{
...@@ -4399,6 +5458,19 @@ pub const AbbrevCode = enum {...@@ -4399,6 +5458,19 @@ pub const AbbrevCode = enum {
4399 .{ .type, .ref_addr },5458 .{ .type, .ref_addr },
4400 },5459 },
4401 },5460 },
5461 .type_decl_instance_empty_packed_struct = .{
5462 .tag = .structure_type,
5463 .attrs = type_decl_instance_attrs ++ .{
5464 .{ .type, .ref_addr },
5465 },
5466 },
5467 .type_decl_instance_packed_struct = .{
5468 .tag = .structure_type,
5469 .children = true,
5470 .attrs = type_decl_instance_attrs ++ .{
5471 .{ .type, .ref_addr },
5472 },
5473 },
4402 .decl_instance_empty_incomplete_union = .{5474 .decl_instance_empty_incomplete_union = .{
4403 .tag = .union_type,5475 .tag = .union_type,
4404 .attrs = decl_instance_attrs,5476 .attrs = decl_instance_attrs,
...@@ -4423,6 +5495,21 @@ pub const AbbrevCode = enum {...@@ -4423,6 +5495,21 @@ pub const AbbrevCode = enum {
4423 .{ .alignment, .udata },5495 .{ .alignment, .udata },
4424 },5496 },
4425 },5497 },
5498 .type_decl_instance_empty_union = .{
5499 .tag = .union_type,
5500 .attrs = type_decl_instance_attrs ++ .{
5501 .{ .byte_size, .udata },
5502 .{ .alignment, .udata },
5503 },
5504 },
5505 .type_decl_instance_union = .{
5506 .tag = .union_type,
5507 .children = true,
5508 .attrs = type_decl_instance_attrs ++ .{
5509 .{ .byte_size, .udata },
5510 .{ .alignment, .udata },
5511 },
5512 },
4426 .decl_instance_empty_packed_union = .{5513 .decl_instance_empty_packed_union = .{
4427 .tag = .union_type,5514 .tag = .union_type,
4428 .attrs = decl_instance_attrs ++ .{5515 .attrs = decl_instance_attrs ++ .{
...@@ -4436,150 +5523,118 @@ pub const AbbrevCode = enum {...@@ -4436,150 +5523,118 @@ pub const AbbrevCode = enum {
4436 .{ .type, .ref_addr },5523 .{ .type, .ref_addr },
4437 },5524 },
4438 },5525 },
4439 .decl_instance_var = .{5526 .type_decl_instance_empty_packed_union = .{
4440 .tag = .variable,5527 .tag = .union_type,
4441 .attrs = decl_instance_attrs ++ .{5528 .attrs = type_decl_instance_attrs ++ .{
4442 .{ .linkage_name, .strp },
4443 .{ .type, .ref_addr },5529 .{ .type, .ref_addr },
4444 .{ .location, .exprloc },5530 },
4445 .{ .alignment, .udata },5531 },
4446 .{ .external, .flag },5532 .type_decl_instance_packed_union = .{
5533 .tag = .union_type,
5534 .children = true,
5535 .attrs = type_decl_instance_attrs ++ .{
5536 .{ .type, .ref_addr },
5537 },
5538 },
5539 .decl_instance_type = .{
5540 .tag = .imported_declaration,
5541 .attrs = decl_instance_attrs ++ .{
5542 .{ .import, .ref_addr },
4447 },5543 },
4448 },5544 },
4449 .decl_instance_const = .{5545 .decl_instance_const = .{
4450 .tag = .constant,5546 .tag = .constant,
4451 .attrs = decl_instance_attrs ++ .{5547 .attrs = decl_instance_attrs ++ .{
4452 .{ .linkage_name, .strp },5548 .{ .linkage_name, .strx },
4453 .{ .type, .ref_addr },5549 .{ .type, .ref_addr },
4454 .{ .alignment, .udata },5550 .{ .alignment, .udata },
4455 .{ .external, .flag },5551 .{ .external, .flag },
4456 },5552 },
4457 },5553 },
4458 .decl_instance_const_runtime_bits = .{5554 .decl_instance_const_fully_runtime = .{
4459 .tag = .constant,5555 .tag = .constant,
4460 .attrs = decl_instance_attrs ++ .{5556 .attrs = decl_instance_attrs ++ .{
4461 .{ .linkage_name, .strp },5557 .{ .linkage_name, .strx },
4462 .{ .type, .ref_addr },5558 .{ .type, .ref_addr },
4463 .{ .alignment, .udata },5559 .{ .alignment, .udata },
4464 .{ .external, .flag },5560 .{ .external, .flag },
4465 .{ .const_value, .block },5561 .{ .const_value, .block },
4466 },5562 },
4467 },5563 },
4468 .decl_instance_const_comptime_state = .{5564 .decl_instance_const_partially_comptime = .{
4469 .tag = .constant,5565 .tag = .constant,
4470 .attrs = decl_instance_attrs ++ .{5566 .attrs = decl_instance_attrs ++ .{
4471 .{ .linkage_name, .strp },5567 .{ .linkage_name, .strx },
4472 .{ .type, .ref_addr },5568 .{ .type, .ref_addr },
4473 .{ .alignment, .udata },5569 .{ .alignment, .udata },
4474 .{ .external, .flag },5570 .{ .external, .flag },
5571 .{ .const_value, .block },
4475 .{ .ZIG_comptime_value, .ref_addr },5572 .{ .ZIG_comptime_value, .ref_addr },
4476 },5573 },
4477 },5574 },
4478 .decl_instance_const_runtime_bits_comptime_state = .{5575 .decl_instance_const_fully_comptime = .{
4479 .tag = .constant,5576 .tag = .constant,
4480 .attrs = decl_instance_attrs ++ .{5577 .attrs = decl_instance_attrs ++ .{
4481 .{ .linkage_name, .strp },5578 .{ .linkage_name, .strx },
4482 .{ .type, .ref_addr },5579 .{ .type, .ref_addr },
4483 .{ .alignment, .udata },5580 .{ .alignment, .udata },
4484 .{ .external, .flag },5581 .{ .external, .flag },
4485 .{ .const_value, .block },
4486 .{ .ZIG_comptime_value, .ref_addr },5582 .{ .ZIG_comptime_value, .ref_addr },
4487 },5583 },
4488 },5584 },
4489 .decl_instance_nullary_func = .{5585 .decl_instance_var = .{
4490 .tag = .subprogram,5586 .tag = .variable,
4491 .attrs = decl_instance_attrs ++ .{5587 .attrs = decl_instance_attrs ++ .{
4492 .{ .linkage_name, .strp },5588 .{ .linkage_name, .strx },
4493 .{ .type, .ref_addr },5589 .{ .type, .ref_addr },
4494 .{ .low_pc, .addr },5590 .{ .location, .exprloc },
4495 .{ .high_pc, .data4 },
4496 .{ .alignment, .udata },5591 .{ .alignment, .udata },
4497 .{ .external, .flag },5592 .{ .external, .flag },
4498 .{ .noreturn, .flag },
4499 },5593 },
4500 },5594 },
4501 .decl_instance_func = .{5595 .decl_instance_empty_func = .{
4502 .tag = .subprogram,5596 .tag = .subprogram,
4503 .children = true,
4504 .attrs = decl_instance_attrs ++ .{5597 .attrs = decl_instance_attrs ++ .{
4505 .{ .linkage_name, .strp },5598 .{ .linkage_name, .strx },
4506 .{ .type, .ref_addr },5599 .{ .type, .ref_addr },
4507 .{ .low_pc, .addr },5600 .{ .low_pc, .addrx },
4508 .{ .high_pc, .data4 },5601 .{ .high_pc, .data4 },
4509 .{ .alignment, .udata },5602 .{ .alignment, .udata },
4510 .{ .external, .flag },5603 .{ .external, .flag },
4511 .{ .noreturn, .flag },5604 .{ .noreturn, .flag },
4512 },5605 },
4513 },5606 },
4514 .decl_instance_nullary_func_generic = .{5607 .decl_instance_func = .{
4515 .tag = .subprogram,
4516 .attrs = decl_instance_attrs ++ .{
4517 .{ .type, .ref_addr },
4518 },
4519 },
4520 .decl_instance_func_generic = .{
4521 .tag = .subprogram,5608 .tag = .subprogram,
4522 .children = true,5609 .children = true,
4523 .attrs = decl_instance_attrs ++ .{5610 .attrs = decl_instance_attrs ++ .{
5611 .{ .linkage_name, .strx },
4524 .{ .type, .ref_addr },5612 .{ .type, .ref_addr },
5613 .{ .low_pc, .addrx },
5614 .{ .high_pc, .data4 },
5615 .{ .alignment, .udata },
5616 .{ .external, .flag },
5617 .{ .noreturn, .flag },
4525 },5618 },
4526 },5619 },
4527 .decl_instance_extern_nullary_func = .{5620 .decl_instance_empty_func_generic = .{
4528 .tag = .subprogram,5621 .tag = .subprogram,
4529 .attrs = decl_instance_attrs ++ .{5622 .attrs = decl_instance_attrs ++ .{
4530 .{ .linkage_name, .strp },
4531 .{ .type, .ref_addr },5623 .{ .type, .ref_addr },
4532 .{ .low_pc, .addr },
4533 .{ .external, .flag_present },
4534 .{ .noreturn, .flag },
4535 },5624 },
4536 },5625 },
4537 .decl_instance_extern_func = .{5626 .decl_instance_func_generic = .{
4538 .tag = .subprogram,5627 .tag = .subprogram,
4539 .children = true,5628 .children = true,
4540 .attrs = decl_instance_attrs ++ .{5629 .attrs = decl_instance_attrs ++ .{
4541 .{ .linkage_name, .strp },
4542 .{ .type, .ref_addr },5630 .{ .type, .ref_addr },
4543 .{ .low_pc, .addr },
4544 .{ .external, .flag_present },
4545 .{ .noreturn, .flag },
4546 },
4547 },
4548 .compile_unit = .{
4549 .tag = .compile_unit,
4550 .children = true,
4551 .attrs = &.{
4552 .{ .language, .data1 },
4553 .{ .producer, .strp },
4554 .{ .comp_dir, .line_strp },
4555 .{ .name, .line_strp },
4556 .{ .base_types, .ref_addr },
4557 .{ .stmt_list, .sec_offset },
4558 .{ .rnglists_base, .sec_offset },
4559 .{ .ranges, .rnglistx },
4560 .{ .use_UTF8, .flag_present },
4561 },
4562 },
4563 .module = .{
4564 .tag = .module,
4565 .children = true,
4566 .attrs = &.{
4567 .{ .name, .strp },
4568 .{ .ranges, .rnglistx },
4569 },
4570 },
4571 .module_dependency = .{
4572 .tag = .imported_module,
4573 .attrs = &.{
4574 .{ .name, .strp },
4575 .{ .import, .ref_addr },
4576 },5631 },
4577 },5632 },
4578 .empty_file = .{5633 .empty_file = .{
4579 .tag = .structure_type,5634 .tag = .structure_type,
4580 .attrs = &.{5635 .attrs = &.{
4581 .{ .decl_file, .udata },5636 .{ .decl_file, .udata },
4582 .{ .name, .strp },5637 .{ .name, .strx },
4583 .{ .declaration, .flag },5638 .{ .declaration, .flag },
4584 },5639 },
4585 },5640 },
...@@ -4588,7 +5643,7 @@ pub const AbbrevCode = enum {...@@ -4588,7 +5643,7 @@ pub const AbbrevCode = enum {
4588 .children = true,5643 .children = true,
4589 .attrs = &.{5644 .attrs = &.{
4590 .{ .decl_file, .udata },5645 .{ .decl_file, .udata },
4591 .{ .name, .strp },5646 .{ .name, .strx },
4592 .{ .byte_size, .udata },5647 .{ .byte_size, .udata },
4593 .{ .alignment, .udata },5648 .{ .alignment, .udata },
4594 },5649 },
...@@ -4596,20 +5651,20 @@ pub const AbbrevCode = enum {...@@ -4596,20 +5651,20 @@ pub const AbbrevCode = enum {
4596 .access = .{5651 .access = .{
4597 .tag = .member,5652 .tag = .member,
4598 .attrs = &.{5653 .attrs = &.{
4599 .{ .name, .strp },5654 .{ .name, .strx },
4600 },5655 },
4601 },5656 },
4602 .enum_field = .{5657 .enum_field = .{
4603 .tag = .enumerator,5658 .tag = .enumerator,
4604 .attrs = &.{5659 .attrs = &.{
4605 .{ .const_value, .indirect },5660 .{ .const_value, .indirect },
4606 .{ .name, .strp },5661 .{ .name, .strx },
4607 },5662 },
4608 },5663 },
4609 .generated_field = .{5664 .generated_field = .{
4610 .tag = .member,5665 .tag = .member,
4611 .attrs = &.{5666 .attrs = &.{
4612 .{ .name, .strp },5667 .{ .name, .strx },
4613 .{ .type, .ref_addr },5668 .{ .type, .ref_addr },
4614 .{ .data_member_location, .udata },5669 .{ .data_member_location, .udata },
4615 .{ .artificial, .flag_present },5670 .{ .artificial, .flag_present },
...@@ -4618,7 +5673,7 @@ pub const AbbrevCode = enum {...@@ -4618,7 +5673,7 @@ pub const AbbrevCode = enum {
4618 .field = .{5673 .field = .{
4619 .tag = .member,5674 .tag = .member,
4620 .attrs = &.{5675 .attrs = &.{
4621 .{ .name, .strp },5676 .{ .name, .strx },
4622 .{ .type, .ref_addr },5677 .{ .type, .ref_addr },
4623 .{ .data_member_location, .udata },5678 .{ .data_member_location, .udata },
4624 .{ .alignment, .udata },5679 .{ .alignment, .udata },
...@@ -4627,7 +5682,7 @@ pub const AbbrevCode = enum {...@@ -4627,7 +5682,7 @@ pub const AbbrevCode = enum {
4627 .field_default_fully_runtime = .{5682 .field_default_fully_runtime = .{
4628 .tag = .member,5683 .tag = .member,
4629 .attrs = &.{5684 .attrs = &.{
4630 .{ .name, .strp },5685 .{ .name, .strx },
4631 .{ .type, .ref_addr },5686 .{ .type, .ref_addr },
4632 .{ .data_member_location, .udata },5687 .{ .data_member_location, .udata },
4633 .{ .alignment, .udata },5688 .{ .alignment, .udata },
...@@ -4637,7 +5692,7 @@ pub const AbbrevCode = enum {...@@ -4637,7 +5692,7 @@ pub const AbbrevCode = enum {
4637 .field_default_partially_comptime = .{5692 .field_default_partially_comptime = .{
4638 .tag = .member,5693 .tag = .member,
4639 .attrs = &.{5694 .attrs = &.{
4640 .{ .name, .strp },5695 .{ .name, .strx },
4641 .{ .type, .ref_addr },5696 .{ .type, .ref_addr },
4642 .{ .data_member_location, .udata },5697 .{ .data_member_location, .udata },
4643 .{ .alignment, .udata },5698 .{ .alignment, .udata },
...@@ -4648,7 +5703,7 @@ pub const AbbrevCode = enum {...@@ -4648,7 +5703,7 @@ pub const AbbrevCode = enum {
4648 .field_default_fully_comptime = .{5703 .field_default_fully_comptime = .{
4649 .tag = .member,5704 .tag = .member,
4650 .attrs = &.{5705 .attrs = &.{
4651 .{ .name, .strp },5706 .{ .name, .strx },
4652 .{ .type, .ref_addr },5707 .{ .type, .ref_addr },
4653 .{ .data_member_location, .udata },5708 .{ .data_member_location, .udata },
4654 .{ .alignment, .udata },5709 .{ .alignment, .udata },
...@@ -4659,7 +5714,7 @@ pub const AbbrevCode = enum {...@@ -4659,7 +5714,7 @@ pub const AbbrevCode = enum {
4659 .tag = .member,5714 .tag = .member,
4660 .attrs = &.{5715 .attrs = &.{
4661 .{ .const_expr, .flag_present },5716 .{ .const_expr, .flag_present },
4662 .{ .name, .strp },5717 .{ .name, .strx },
4663 .{ .type, .ref_addr },5718 .{ .type, .ref_addr },
4664 },5719 },
4665 },5720 },
...@@ -4667,7 +5722,7 @@ pub const AbbrevCode = enum {...@@ -4667,7 +5722,7 @@ pub const AbbrevCode = enum {
4667 .tag = .member,5722 .tag = .member,
4668 .attrs = &.{5723 .attrs = &.{
4669 .{ .const_expr, .flag_present },5724 .{ .const_expr, .flag_present },
4670 .{ .name, .strp },5725 .{ .name, .strx },
4671 .{ .type, .ref_addr },5726 .{ .type, .ref_addr },
4672 .{ .const_value, .block },5727 .{ .const_value, .block },
4673 },5728 },
...@@ -4676,7 +5731,7 @@ pub const AbbrevCode = enum {...@@ -4676,7 +5731,7 @@ pub const AbbrevCode = enum {
4676 .tag = .member,5731 .tag = .member,
4677 .attrs = &.{5732 .attrs = &.{
4678 .{ .const_expr, .flag_present },5733 .{ .const_expr, .flag_present },
4679 .{ .name, .strp },5734 .{ .name, .strx },
4680 .{ .type, .ref_addr },5735 .{ .type, .ref_addr },
4681 .{ .const_value, .block },5736 .{ .const_value, .block },
4682 .{ .ZIG_comptime_value, .ref_addr },5737 .{ .ZIG_comptime_value, .ref_addr },
...@@ -4686,7 +5741,7 @@ pub const AbbrevCode = enum {...@@ -4686,7 +5741,7 @@ pub const AbbrevCode = enum {
4686 .tag = .member,5741 .tag = .member,
4687 .attrs = &.{5742 .attrs = &.{
4688 .{ .const_expr, .flag_present },5743 .{ .const_expr, .flag_present },
4689 .{ .name, .strp },5744 .{ .name, .strx },
4690 .{ .type, .ref_addr },5745 .{ .type, .ref_addr },
4691 .{ .ZIG_comptime_value, .ref_addr },5746 .{ .ZIG_comptime_value, .ref_addr },
4692 },5747 },
...@@ -4694,7 +5749,7 @@ pub const AbbrevCode = enum {...@@ -4694,7 +5749,7 @@ pub const AbbrevCode = enum {
4694 .packed_field = .{5749 .packed_field = .{
4695 .tag = .member,5750 .tag = .member,
4696 .attrs = &.{5751 .attrs = &.{
4697 .{ .name, .strp },5752 .{ .name, .strx },
4698 .{ .type, .ref_addr },5753 .{ .type, .ref_addr },
4699 .{ .data_bit_offset, .udata },5754 .{ .data_bit_offset, .udata },
4700 },5755 },
...@@ -4720,13 +5775,13 @@ pub const AbbrevCode = enum {...@@ -4720,13 +5775,13 @@ pub const AbbrevCode = enum {
4720 .void_type = .{5775 .void_type = .{
4721 .tag = .unspecified_type,5776 .tag = .unspecified_type,
4722 .attrs = &.{5777 .attrs = &.{
4723 .{ .name, .strp },5778 .{ .name, .strx },
4724 },5779 },
4725 },5780 },
4726 .numeric_type = .{5781 .numeric_type = .{
4727 .tag = .base_type,5782 .tag = .base_type,
4728 .attrs = &.{5783 .attrs = &.{
4729 .{ .name, .strp },5784 .{ .name, .strx },
4730 .{ .encoding, .data1 },5785 .{ .encoding, .data1 },
4731 .{ .bit_size, .udata },5786 .{ .bit_size, .udata },
4732 .{ .byte_size, .udata },5787 .{ .byte_size, .udata },
...@@ -4736,14 +5791,14 @@ pub const AbbrevCode = enum {...@@ -4736,14 +5791,14 @@ pub const AbbrevCode = enum {
4736 .inferred_error_set_type = .{5791 .inferred_error_set_type = .{
4737 .tag = .typedef,5792 .tag = .typedef,
4738 .attrs = &.{5793 .attrs = &.{
4739 .{ .name, .strp },5794 .{ .name, .strx },
4740 .{ .type, .ref_addr },5795 .{ .type, .ref_addr },
4741 },5796 },
4742 },5797 },
4743 .ptr_type = .{5798 .ptr_type = .{
4744 .tag = .pointer_type,5799 .tag = .pointer_type,
4745 .attrs = &.{5800 .attrs = &.{
4746 .{ .name, .strp },5801 .{ .name, .strx },
4747 .{ .address_class, .data1 },5802 .{ .address_class, .data1 },
4748 .{ .type, .ref_addr },5803 .{ .type, .ref_addr },
4749 },5804 },
...@@ -4751,28 +5806,16 @@ pub const AbbrevCode = enum {...@@ -4751,28 +5806,16 @@ pub const AbbrevCode = enum {
4751 .ptr_sentinel_type = .{5806 .ptr_sentinel_type = .{
4752 .tag = .pointer_type,5807 .tag = .pointer_type,
4753 .attrs = &.{5808 .attrs = &.{
4754 .{ .name, .strp },5809 .{ .name, .strx },
4755 .{ .ZIG_sentinel, .block },5810 .{ .ZIG_sentinel, .block },
4756 .{ .address_class, .data1 },5811 .{ .address_class, .data1 },
4757 .{ .type, .ref_addr },5812 .{ .type, .ref_addr },
4758 },5813 },
4759 },5814 },
4760 .ptr_aligned_type = .{5815 .is_aligned = .{
4761 .tag = .pointer_type,5816 .tag = .typedef,
4762 .attrs = &.{
4763 .{ .name, .strp },
4764 .{ .alignment, .udata },
4765 .{ .address_class, .data1 },
4766 .{ .type, .ref_addr },
4767 },
4768 },
4769 .ptr_aligned_sentinel_type = .{
4770 .tag = .pointer_type,
4771 .attrs = &.{5817 .attrs = &.{
4772 .{ .name, .strp },
4773 .{ .ZIG_sentinel, .block },
4774 .{ .alignment, .udata },5818 .{ .alignment, .udata },
4775 .{ .address_class, .data1 },
4776 .{ .type, .ref_addr },5819 .{ .type, .ref_addr },
4777 },5820 },
4778 },5821 },
...@@ -4792,7 +5835,7 @@ pub const AbbrevCode = enum {...@@ -4792,7 +5835,7 @@ pub const AbbrevCode = enum {
4792 .tag = .array_type,5835 .tag = .array_type,
4793 .children = true,5836 .children = true,
4794 .attrs = &.{5837 .attrs = &.{
4795 .{ .name, .strp },5838 .{ .name, .strx },
4796 .{ .type, .ref_addr },5839 .{ .type, .ref_addr },
4797 },5840 },
4798 },5841 },
...@@ -4800,7 +5843,7 @@ pub const AbbrevCode = enum {...@@ -4800,7 +5843,7 @@ pub const AbbrevCode = enum {
4800 .tag = .array_type,5843 .tag = .array_type,
4801 .children = true,5844 .children = true,
4802 .attrs = &.{5845 .attrs = &.{
4803 .{ .name, .strp },5846 .{ .name, .strx },
4804 .{ .ZIG_sentinel, .block },5847 .{ .ZIG_sentinel, .block },
4805 .{ .type, .ref_addr },5848 .{ .type, .ref_addr },
4806 },5849 },
...@@ -4809,7 +5852,7 @@ pub const AbbrevCode = enum {...@@ -4809,7 +5852,7 @@ pub const AbbrevCode = enum {
4809 .tag = .array_type,5852 .tag = .array_type,
4810 .children = true,5853 .children = true,
4811 .attrs = &.{5854 .attrs = &.{
4812 .{ .name, .strp },5855 .{ .name, .strx },
4813 .{ .type, .ref_addr },5856 .{ .type, .ref_addr },
4814 .{ .GNU_vector, .flag_present },5857 .{ .GNU_vector, .flag_present },
4815 },5858 },
...@@ -4827,10 +5870,10 @@ pub const AbbrevCode = enum {...@@ -4827,10 +5870,10 @@ pub const AbbrevCode = enum {
4827 .{ .count, .udata },5870 .{ .count, .udata },
4828 },5871 },
4829 },5872 },
4830 .nullary_func_type = .{5873 .empty_func_type = .{
4831 .tag = .subroutine_type,5874 .tag = .subroutine_type,
4832 .attrs = &.{5875 .attrs = &.{
4833 .{ .name, .strp },5876 .{ .name, .strx },
4834 .{ .calling_convention, .data1 },5877 .{ .calling_convention, .data1 },
4835 .{ .type, .ref_addr },5878 .{ .type, .ref_addr },
4836 },5879 },
...@@ -4839,7 +5882,7 @@ pub const AbbrevCode = enum {...@@ -4839,7 +5882,7 @@ pub const AbbrevCode = enum {
4839 .tag = .subroutine_type,5882 .tag = .subroutine_type,
4840 .children = true,5883 .children = true,
4841 .attrs = &.{5884 .attrs = &.{
4842 .{ .name, .strp },5885 .{ .name, .strx },
4843 .{ .calling_convention, .data1 },5886 .{ .calling_convention, .data1 },
4844 .{ .type, .ref_addr },5887 .{ .type, .ref_addr },
4845 },5888 },
...@@ -4847,7 +5890,7 @@ pub const AbbrevCode = enum {...@@ -4847,7 +5890,7 @@ pub const AbbrevCode = enum {
4847 .param = .{5890 .param = .{
4848 .tag = .formal_parameter,5891 .tag = .formal_parameter,
4849 .attrs = &.{5892 .attrs = &.{
4850 .{ .name, .strp },5893 .{ .name, .strx },
4851 .{ .type, .ref_addr },5894 .{ .type, .ref_addr },
4852 },5895 },
4853 },5896 },
...@@ -4863,7 +5906,7 @@ pub const AbbrevCode = enum {...@@ -4863,7 +5906,7 @@ pub const AbbrevCode = enum {
4863 .generated_empty_enum_type = .{5906 .generated_empty_enum_type = .{
4864 .tag = .enumeration_type,5907 .tag = .enumeration_type,
4865 .attrs = &.{5908 .attrs = &.{
4866 .{ .name, .strp },5909 .{ .name, .strx },
4867 .{ .type, .ref_addr },5910 .{ .type, .ref_addr },
4868 },5911 },
4869 },5912 },
...@@ -4871,14 +5914,14 @@ pub const AbbrevCode = enum {...@@ -4871,14 +5914,14 @@ pub const AbbrevCode = enum {
4871 .tag = .enumeration_type,5914 .tag = .enumeration_type,
4872 .children = true,5915 .children = true,
4873 .attrs = &.{5916 .attrs = &.{
4874 .{ .name, .strp },5917 .{ .name, .strx },
4875 .{ .type, .ref_addr },5918 .{ .type, .ref_addr },
4876 },5919 },
4877 },5920 },
4878 .generated_empty_struct_type = .{5921 .generated_empty_struct_type = .{
4879 .tag = .structure_type,5922 .tag = .structure_type,
4880 .attrs = &.{5923 .attrs = &.{
4881 .{ .name, .strp },5924 .{ .name, .strx },
4882 .{ .declaration, .flag },5925 .{ .declaration, .flag },
4883 },5926 },
4884 },5927 },
...@@ -4886,7 +5929,7 @@ pub const AbbrevCode = enum {...@@ -4886,7 +5929,7 @@ pub const AbbrevCode = enum {
4886 .tag = .structure_type,5929 .tag = .structure_type,
4887 .children = true,5930 .children = true,
4888 .attrs = &.{5931 .attrs = &.{
4889 .{ .name, .strp },5932 .{ .name, .strx },
4890 .{ .byte_size, .udata },5933 .{ .byte_size, .udata },
4891 .{ .alignment, .udata },5934 .{ .alignment, .udata },
4892 },5935 },
...@@ -4895,7 +5938,7 @@ pub const AbbrevCode = enum {...@@ -4895,7 +5938,7 @@ pub const AbbrevCode = enum {
4895 .tag = .union_type,5938 .tag = .union_type,
4896 .children = true,5939 .children = true,
4897 .attrs = &.{5940 .attrs = &.{
4898 .{ .name, .strp },5941 .{ .name, .strx },
4899 .{ .byte_size, .udata },5942 .{ .byte_size, .udata },
4900 .{ .alignment, .udata },5943 .{ .alignment, .udata },
4901 },5944 },
...@@ -4903,7 +5946,7 @@ pub const AbbrevCode = enum {...@@ -4903,7 +5946,7 @@ pub const AbbrevCode = enum {
4903 .capture_specification = .{5946 .capture_specification = .{
4904 .tag = .template_value_parameter,5947 .tag = .template_value_parameter,
4905 .attrs = &.{5948 .attrs = &.{
4906 .{ .name, .strp },5949 .{ .name, .strx },
4907 },5950 },
4908 },5951 },
4909 .comptime_capture = .{5952 .comptime_capture = .{
...@@ -4946,11 +5989,11 @@ pub const AbbrevCode = enum {...@@ -4946,11 +5989,11 @@ pub const AbbrevCode = enum {
4946 .{ .location, .exprloc },5989 .{ .location, .exprloc },
4947 },5990 },
4948 },5991 },
4949 .builtin_extern_nullary_func = .{5992 .builtin_extern_empty_func = .{
4950 .tag = .subprogram,5993 .tag = .subprogram,
4951 .attrs = &.{5994 .attrs = &.{
4952 .{ .ZIG_parent, .ref_addr },5995 .{ .ZIG_parent, .ref_addr },
4953 .{ .linkage_name, .strp },5996 .{ .linkage_name, .strx },
4954 .{ .type, .ref_addr },5997 .{ .type, .ref_addr },
4955 .{ .low_pc, .addr },5998 .{ .low_pc, .addr },
4956 .{ .external, .flag_present },5999 .{ .external, .flag_present },
...@@ -4962,7 +6005,7 @@ pub const AbbrevCode = enum {...@@ -4962,7 +6005,7 @@ pub const AbbrevCode = enum {
4962 .children = true,6005 .children = true,
4963 .attrs = &.{6006 .attrs = &.{
4964 .{ .ZIG_parent, .ref_addr },6007 .{ .ZIG_parent, .ref_addr },
4965 .{ .linkage_name, .strp },6008 .{ .linkage_name, .strx },
4966 .{ .type, .ref_addr },6009 .{ .type, .ref_addr },
4967 .{ .low_pc, .addr },6010 .{ .low_pc, .addr },
4968 .{ .external, .flag_present },6011 .{ .external, .flag_present },
...@@ -4973,9 +6016,10 @@ pub const AbbrevCode = enum {...@@ -4973,9 +6016,10 @@ pub const AbbrevCode = enum {
4973 .tag = .variable,6016 .tag = .variable,
4974 .attrs = &.{6017 .attrs = &.{
4975 .{ .ZIG_parent, .ref_addr },6018 .{ .ZIG_parent, .ref_addr },
4976 .{ .linkage_name, .strp },6019 .{ .linkage_name, .strx },
4977 .{ .type, .ref_addr },6020 .{ .type, .ref_addr },
4978 .{ .location, .exprloc },6021 .{ .location, .exprloc },
6022 .{ .alignment, .udata },
4979 .{ .external, .flag_present },6023 .{ .external, .flag_present },
4980 },6024 },
4981 },6025 },
...@@ -5018,7 +6062,7 @@ pub const AbbrevCode = enum {...@@ -5018,7 +6062,7 @@ pub const AbbrevCode = enum {
5018 .arg = .{6062 .arg = .{
5019 .tag = .formal_parameter,6063 .tag = .formal_parameter,
5020 .attrs = &.{6064 .attrs = &.{
5021 .{ .name, .strp },6065 .{ .name, .strx },
5022 .{ .type, .ref_addr },6066 .{ .type, .ref_addr },
5023 .{ .location, .exprloc },6067 .{ .location, .exprloc },
5024 },6068 },
...@@ -5034,7 +6078,7 @@ pub const AbbrevCode = enum {...@@ -5034,7 +6078,7 @@ pub const AbbrevCode = enum {
5034 .tag = .formal_parameter,6078 .tag = .formal_parameter,
5035 .attrs = &.{6079 .attrs = &.{
5036 .{ .const_expr, .flag_present },6080 .{ .const_expr, .flag_present },
5037 .{ .name, .strp },6081 .{ .name, .strx },
5038 .{ .type, .ref_addr },6082 .{ .type, .ref_addr },
5039 },6083 },
5040 },6084 },
...@@ -5042,7 +6086,7 @@ pub const AbbrevCode = enum {...@@ -5042,7 +6086,7 @@ pub const AbbrevCode = enum {
5042 .tag = .formal_parameter,6086 .tag = .formal_parameter,
5043 .attrs = &.{6087 .attrs = &.{
5044 .{ .const_expr, .flag_present },6088 .{ .const_expr, .flag_present },
5045 .{ .name, .strp },6089 .{ .name, .strx },
5046 .{ .type, .ref_addr },6090 .{ .type, .ref_addr },
5047 .{ .const_value, .block },6091 .{ .const_value, .block },
5048 },6092 },
...@@ -5051,7 +6095,7 @@ pub const AbbrevCode = enum {...@@ -5051,7 +6095,7 @@ pub const AbbrevCode = enum {
5051 .tag = .formal_parameter,6095 .tag = .formal_parameter,
5052 .attrs = &.{6096 .attrs = &.{
5053 .{ .const_expr, .flag_present },6097 .{ .const_expr, .flag_present },
5054 .{ .name, .strp },6098 .{ .name, .strx },
5055 .{ .type, .ref_addr },6099 .{ .type, .ref_addr },
5056 .{ .const_value, .block },6100 .{ .const_value, .block },
5057 .{ .ZIG_comptime_value, .ref_addr },6101 .{ .ZIG_comptime_value, .ref_addr },
...@@ -5061,7 +6105,7 @@ pub const AbbrevCode = enum {...@@ -5061,7 +6105,7 @@ pub const AbbrevCode = enum {
5061 .tag = .formal_parameter,6105 .tag = .formal_parameter,
5062 .attrs = &.{6106 .attrs = &.{
5063 .{ .const_expr, .flag_present },6107 .{ .const_expr, .flag_present },
5064 .{ .name, .strp },6108 .{ .name, .strx },
5065 .{ .type, .ref_addr },6109 .{ .type, .ref_addr },
5066 .{ .ZIG_comptime_value, .ref_addr },6110 .{ .ZIG_comptime_value, .ref_addr },
5067 },6111 },
...@@ -5107,7 +6151,7 @@ pub const AbbrevCode = enum {...@@ -5107,7 +6151,7 @@ pub const AbbrevCode = enum {
5107 .local_var = .{6151 .local_var = .{
5108 .tag = .variable,6152 .tag = .variable,
5109 .attrs = &.{6153 .attrs = &.{
5110 .{ .name, .strp },6154 .{ .name, .strx },
5111 .{ .type, .ref_addr },6155 .{ .type, .ref_addr },
5112 .{ .location, .exprloc },6156 .{ .location, .exprloc },
5113 },6157 },
...@@ -5115,14 +6159,14 @@ pub const AbbrevCode = enum {...@@ -5115,14 +6159,14 @@ pub const AbbrevCode = enum {
5115 .local_const = .{6159 .local_const = .{
5116 .tag = .constant,6160 .tag = .constant,
5117 .attrs = &.{6161 .attrs = &.{
5118 .{ .name, .strp },6162 .{ .name, .strx },
5119 .{ .type, .ref_addr },6163 .{ .type, .ref_addr },
5120 },6164 },
5121 },6165 },
5122 .local_const_fully_runtime = .{6166 .local_const_fully_runtime = .{
5123 .tag = .constant,6167 .tag = .constant,
5124 .attrs = &.{6168 .attrs = &.{
5125 .{ .name, .strp },6169 .{ .name, .strx },
5126 .{ .type, .ref_addr },6170 .{ .type, .ref_addr },
5127 .{ .const_value, .block },6171 .{ .const_value, .block },
5128 },6172 },
...@@ -5130,7 +6174,7 @@ pub const AbbrevCode = enum {...@@ -5130,7 +6174,7 @@ pub const AbbrevCode = enum {
5130 .local_const_partially_comptime = .{6174 .local_const_partially_comptime = .{
5131 .tag = .constant,6175 .tag = .constant,
5132 .attrs = &.{6176 .attrs = &.{
5133 .{ .name, .strp },6177 .{ .name, .strx },
5134 .{ .type, .ref_addr },6178 .{ .type, .ref_addr },
5135 .{ .const_value, .block },6179 .{ .const_value, .block },
5136 .{ .ZIG_comptime_value, .ref_addr },6180 .{ .ZIG_comptime_value, .ref_addr },
...@@ -5139,7 +6183,7 @@ pub const AbbrevCode = enum {...@@ -5139,7 +6183,7 @@ pub const AbbrevCode = enum {
5139 .local_const_fully_comptime = .{6183 .local_const_fully_comptime = .{
5140 .tag = .constant,6184 .tag = .constant,
5141 .attrs = &.{6185 .attrs = &.{
5142 .{ .name, .strp },6186 .{ .name, .strx },
5143 .{ .type, .ref_addr },6187 .{ .type, .ref_addr },
5144 .{ .ZIG_comptime_value, .ref_addr },6188 .{ .ZIG_comptime_value, .ref_addr },
5145 },6189 },
...@@ -5187,32 +6231,64 @@ pub const AbbrevCode = enum {...@@ -5187,32 +6231,64 @@ pub const AbbrevCode = enum {
5187 .{ .location, .exprloc },6231 .{ .location, .exprloc },
5188 },6232 },
5189 },6233 },
5190 .comptime_value_field_runtime_bits = .{6234 .comptime_value_field_runtime = .{
5191 .tag = .member,6235 .tag = .member,
5192 .attrs = &.{6236 .attrs = &.{
5193 .{ .name, .strp },6237 .{ .name, .strx },
5194 .{ .const_value, .block },6238 .{ .const_value, .block },
5195 },6239 },
5196 },6240 },
5197 .comptime_value_field_comptime_state = .{6241 .comptime_value_field_comptime = .{
5198 .tag = .member,6242 .tag = .member,
5199 .attrs = &.{6243 .attrs = &.{
5200 .{ .name, .strp },6244 .{ .name, .strx },
5201 .{ .ZIG_comptime_value, .ref_addr },6245 .{ .ZIG_comptime_value, .ref_addr },
5202 },6246 },
5203 },6247 },
5204 .comptime_value_elem_runtime_bits = .{6248 .comptime_value_elem_runtime = .{
5205 .tag = .member,6249 .tag = .member,
5206 .attrs = &.{6250 .attrs = &.{
5207 .{ .const_value, .block },6251 .{ .const_value, .block },
5208 },6252 },
5209 },6253 },
5210 .comptime_value_elem_comptime_state = .{6254 .comptime_value_elem_comptime = .{
5211 .tag = .member,6255 .tag = .member,
5212 .attrs = &.{6256 .attrs = &.{
5213 .{ .ZIG_comptime_value, .ref_addr },6257 .{ .ZIG_comptime_value, .ref_addr },
5214 },6258 },
5215 },6259 },
6260 .compile_unit = .{
6261 .tag = .compile_unit,
6262 .children = true,
6263 .attrs = &.{
6264 .{ .language, .data1 },
6265 .{ .base_types, .ref_addr },
6266 .{ .stmt_list, .sec_offset },
6267 .{ .addr_base, .sec_offset },
6268 .{ .rnglists_base, .sec_offset },
6269 .{ .str_offsets_base, .sec_offset },
6270 .{ .producer, .strx1 },
6271 .{ .comp_dir, .line_strp },
6272 .{ .name, .line_strp },
6273 .{ .ranges, .rnglistx },
6274 .{ .use_UTF8, .flag_present },
6275 },
6276 },
6277 .module = .{
6278 .tag = .module,
6279 .children = true,
6280 .attrs = &.{
6281 .{ .name, .strx },
6282 .{ .ranges, .rnglistx },
6283 },
6284 },
6285 .module_dependency = .{
6286 .tag = .imported_module,
6287 .attrs = &.{
6288 .{ .name, .strx },
6289 .{ .import, .ref_addr },
6290 },
6291 },
5216 });6292 });
5217};6293};
52186294
src/link/Elf2.zig+405-179
...@@ -53,6 +53,7 @@ shndx: struct {...@@ -53,6 +53,7 @@ shndx: struct {
53 rela_dyn: Section.Index,53 rela_dyn: Section.Index,
54 rela_plt: Section.Index,54 rela_plt: Section.Index,
55 debug_abbrev: Section.Index,55 debug_abbrev: Section.Index,
56 debug_addr: Section.Index,
56 eh_frame_hdr: Section.Index,57 eh_frame_hdr: Section.Index,
57 eh_frame: Section.Index,58 eh_frame: Section.Index,
58 debug_frame: Section.Index,59 debug_frame: Section.Index,
...@@ -215,6 +216,8 @@ textrel_count: u32,...@@ -215,6 +216,8 @@ textrel_count: u32,
215216
216dwarf: Dwarf,217dwarf: Dwarf,
217dwarf_shared: std.enums.EnumArray(Dwarf.SharedSection, dwarf_relocs.Shared),218dwarf_shared: std.enums.EnumArray(Dwarf.SharedSection, dwarf_relocs.Shared),
219dwarf_addr: dwarf_relocs.Addr,
220dwarf_str_offsets: dwarf_relocs.StrOffsets,
218dwarf_units: []dwarf_relocs.Unit,221dwarf_units: []dwarf_relocs.Unit,
219dwarf_consts: std.array_hash_map.Auto(link.ConstPool.Index, dwarf_relocs.Const),222dwarf_consts: std.array_hash_map.Auto(link.ConstPool.Index, dwarf_relocs.Const),
220dwarf_globals: std.ArrayList(dwarf_relocs.Global),223dwarf_globals: std.ArrayList(dwarf_relocs.Global),
...@@ -286,7 +289,9 @@ const Node = union(enum) {...@@ -286,7 +289,9 @@ const Node = union(enum) {
286 lazy_const_data: LazyMapRef.Index(.const_data),289 lazy_const_data: LazyMapRef.Index(.const_data),
287290
288 debug_shared: Dwarf.SharedSection,291 debug_shared: Dwarf.SharedSection,
292 debug_addr,
289 eh_frame_footer,293 eh_frame_footer,
294 debug_str_offsets,
290 unit_padding,295 unit_padding,
291 unit_frame: Dwarf.Unit.Index,296 unit_frame: Dwarf.Unit.Index,
292 unit_frame_cie: Dwarf.Unit.Index,297 unit_frame_cie: Dwarf.Unit.Index,
...@@ -880,6 +885,14 @@ const dwarf_relocs = struct {...@@ -880,6 +885,14 @@ const dwarf_relocs = struct {
880 const Shared = struct {885 const Shared = struct {
881 first_target_reloc: NodeReloc.Index,886 first_target_reloc: NodeReloc.Index,
882 };887 };
888 const Addr = struct {
889 first_target_reloc: NodeReloc.Index,
890 symbol_relocs: std.ArrayList(SymbolReloc.Index),
891 };
892 const StrOffsets = struct {
893 first_target_reloc: NodeReloc.Index,
894 node_relocs: std.ArrayList(NodeReloc.Index),
895 };
883 const Unit = struct {896 const Unit = struct {
884 frame_cie_first_target_reloc: NodeReloc.Index,897 frame_cie_first_target_reloc: NodeReloc.Index,
885 debug_info_header_first_target_reloc: NodeReloc.Index,898 debug_info_header_first_target_reloc: NodeReloc.Index,
...@@ -887,7 +900,7 @@ const dwarf_relocs = struct {...@@ -887,7 +900,7 @@ const dwarf_relocs = struct {
887 debug_line_header_first_target_reloc: NodeReloc.Index,900 debug_line_header_first_target_reloc: NodeReloc.Index,
888 debug_line_header_first_node_reloc: NodeReloc.Index,901 debug_line_header_first_node_reloc: NodeReloc.Index,
889 debug_rnglists_first_target_reloc: NodeReloc.Index,902 debug_rnglists_first_target_reloc: NodeReloc.Index,
890 debug_rnglists_symbol_relocs: std.array_hash_map.Auto(SymbolReloc.Index, void),903 debug_rnglists_symbol_relocs: std.ArrayList(SymbolReloc.Index),
891 };904 };
892 const Const = struct {905 const Const = struct {
893 debug_info_first_target_reloc: NodeReloc.Index,906 debug_info_first_target_reloc: NodeReloc.Index,
...@@ -3346,7 +3359,9 @@ pub fn symbolForAtom(elf: *Elf, atom: link.File.AtomId) link.File.SymbolId {...@@ -3346,7 +3359,9 @@ pub fn symbolForAtom(elf: *Elf, atom: link.File.AtomId) link.File.SymbolId {
3346 .input_section,3359 .input_section,
3347 .copied_global,3360 .copied_global,
3348 .debug_shared,3361 .debug_shared,
3362 .debug_addr,
3349 .eh_frame_footer,3363 .eh_frame_footer,
3364 .debug_str_offsets,
3350 .unit_padding,3365 .unit_padding,
3351 .unit_frame,3366 .unit_frame,
3352 .unit_frame_cie,3367 .unit_frame_cie,
...@@ -3800,6 +3815,7 @@ fn create(...@@ -3800,6 +3815,7 @@ fn create(
3800 .rela_dyn = .UNDEF,3815 .rela_dyn = .UNDEF,
3801 .rela_plt = .UNDEF,3816 .rela_plt = .UNDEF,
3802 .debug_abbrev = .UNDEF,3817 .debug_abbrev = .UNDEF,
3818 .debug_addr = .UNDEF,
3803 .eh_frame_hdr = .UNDEF,3819 .eh_frame_hdr = .UNDEF,
3804 .eh_frame = .UNDEF,3820 .eh_frame = .UNDEF,
3805 .debug_frame = .UNDEF,3821 .debug_frame = .UNDEF,
...@@ -3866,6 +3882,14 @@ fn create(...@@ -3866,6 +3882,14 @@ fn create(
3866 .dwarf_shared = comptime .initFill(.{3882 .dwarf_shared = comptime .initFill(.{
3867 .first_target_reloc = .none,3883 .first_target_reloc = .none,
3868 }),3884 }),
3885 .dwarf_addr = .{
3886 .first_target_reloc = .none,
3887 .symbol_relocs = .empty,
3888 },
3889 .dwarf_str_offsets = .{
3890 .first_target_reloc = .none,
3891 .node_relocs = .empty,
3892 },
3869 .dwarf_units = &.{},3893 .dwarf_units = &.{},
3870 .dwarf_consts = .empty,3894 .dwarf_consts = .empty,
3871 .dwarf_globals = .empty,3895 .dwarf_globals = .empty,
...@@ -3921,6 +3945,8 @@ pub fn deinit(elf: *Elf) void {...@@ -3921,6 +3945,8 @@ pub fn deinit(elf: *Elf) void {
3921 elf.changed_symtab_index.deinit(gpa);3945 elf.changed_symtab_index.deinit(gpa);
39223946
3923 elf.dwarf.deinit();3947 elf.dwarf.deinit();
3948 elf.dwarf_addr.symbol_relocs.deinit(gpa);
3949 elf.dwarf_str_offsets.node_relocs.deinit(gpa);
3924 for (elf.dwarf_units) |*dwarf_unit| dwarf_unit.debug_rnglists_symbol_relocs.deinit(gpa);3950 for (elf.dwarf_units) |*dwarf_unit| dwarf_unit.debug_rnglists_symbol_relocs.deinit(gpa);
3925 gpa.free(elf.dwarf_units);3951 gpa.free(elf.dwarf_units);
3926 elf.dwarf_consts.deinit(gpa);3952 elf.dwarf_consts.deinit(gpa);
...@@ -4000,6 +4026,7 @@ fn initHeaders(...@@ -4000,6 +4026,7 @@ fn initHeaders(
4000 .strip => {},4026 .strip => {},
4001 .dwarf => {4027 .dwarf => {
4002 shnum += 1; // .debug_abbrev4028 shnum += 1; // .debug_abbrev
4029 shnum += 1; // .debug_addr
4003 shnum += @intFromBool(have_debug_frame); // .debug_frame4030 shnum += @intFromBool(have_debug_frame); // .debug_frame
4004 shnum += 1; // .debug_info4031 shnum += 1; // .debug_info
4005 shnum += 1; // .debug_line4032 shnum += 1; // .debug_line
...@@ -5104,6 +5131,11 @@ fn initHeaders(...@@ -5104,6 +5131,11 @@ fn initHeaders(
5104 .strip => {},5131 .strip => {},
5105 .dwarf => {5132 .dwarf => {
5106 elf.shndx.debug_abbrev = try elf.addSection(elf.ni.elf, .{ .name = ".debug_abbrev" });5133 elf.shndx.debug_abbrev = try elf.addSection(elf.ni.elf, .{ .name = ".debug_abbrev" });
5134 elf.shndx.debug_addr = try elf.addSection(elf.ni.elf, .{
5135 .name = ".debug_addr",
5136 .addralign = addr_align,
5137 .node_align = elf.mf.flags.block_size,
5138 });
5107 if (have_debug_frame) elf.shndx.debug_frame = try elf.addSection(elf.ni.elf, .{5139 if (have_debug_frame) elf.shndx.debug_frame = try elf.addSection(elf.ni.elf, .{
5108 .name = ".debug_frame",5140 .name = ".debug_frame",
5109 .addralign = addr_align,5141 .addralign = addr_align,
...@@ -5132,6 +5164,11 @@ fn initHeaders(...@@ -5132,6 +5164,11 @@ fn initHeaders(
5132 });5164 });
5133 elf.shndx.debug_str_offsets = try elf.addSection(elf.ni.elf, .{5165 elf.shndx.debug_str_offsets = try elf.addSection(elf.ni.elf, .{
5134 .name = ".debug_str_offsets",5166 .name = ".debug_str_offsets",
5167 .addralign = switch (elf.dwarf.format) {
5168 .@"32" => .@"4",
5169 .@"64" => .@"8",
5170 },
5171 .node_align = elf.mf.flags.block_size,
5135 });5172 });
5136 },5173 },
5137 .code_view => unreachable,5174 .code_view => unreachable,
...@@ -5226,7 +5263,9 @@ fn getNodeShndx(elf: *const Elf, ni: MappedFile.Node.Index) Section.Index {...@@ -5226,7 +5263,9 @@ fn getNodeShndx(elf: *const Elf, ni: MappedFile.Node.Index) Section.Index {
5226 .lazy_code,5263 .lazy_code,
5227 .lazy_const_data,5264 .lazy_const_data,
5228 .debug_shared,5265 .debug_shared,
5266 .debug_addr,
5229 .eh_frame_footer,5267 .eh_frame_footer,
5268 .debug_str_offsets,
5230 .unit_padding,5269 .unit_padding,
5231 .unit_frame,5270 .unit_frame,
5232 .unit_debug_info,5271 .unit_debug_info,
...@@ -5273,7 +5312,9 @@ fn getNodeVAddr(elf: *Elf, ni: MappedFile.Node.Index) u64 {...@@ -5273,7 +5312,9 @@ fn getNodeVAddr(elf: *Elf, ni: MappedFile.Node.Index) u64 {
5273 .lazy_const_data,5312 .lazy_const_data,
5274 => |i| Symbol.Id.local(i.symbol(elf)).value(elf),5313 => |i| Symbol.Id.local(i.symbol(elf)).value(elf),
5275 .debug_shared,5314 .debug_shared,
5315 .debug_addr,
5276 .eh_frame_footer,5316 .eh_frame_footer,
5317 .debug_str_offsets,
5277 .unit_padding,5318 .unit_padding,
5278 .unit_frame,5319 .unit_frame,
5279 .unit_frame_cie,5320 .unit_frame_cie,
...@@ -5313,7 +5354,7 @@ fn computeNodeVAddr(elf: *Elf, ni: MappedFile.Node.Index) u64 {...@@ -5313,7 +5354,7 @@ fn computeNodeVAddr(elf: *Elf, ni: MappedFile.Node.Index) u64 {
5313 .lazy_code,5354 .lazy_code,
5314 .lazy_const_data,5355 .lazy_const_data,
5315 => |i| Symbol.Id.local(i.symbol(elf)).value(elf),5356 => |i| Symbol.Id.local(i.symbol(elf)).value(elf),
5316 .debug_shared, .eh_frame_footer, .unit_padding => unreachable,5357 .debug_shared, .debug_addr, .eh_frame_footer, .debug_str_offsets, .unit_padding => unreachable,
5317 .unit_frame, .unit_debug_info, .unit_debug_line => {5358 .unit_frame, .unit_debug_info, .unit_debug_line => {
5318 const section_offset, _ = parent_ni.location(&elf.mf).resolve(&elf.mf);5359 const section_offset, _ = parent_ni.location(&elf.mf).resolve(&elf.mf);
5319 break :parent_vaddr elf.getNodeShndx(parent_ni).vaddr(elf) + section_offset;5360 break :parent_vaddr elf.getNodeShndx(parent_ni).vaddr(elf) + section_offset;
...@@ -5350,7 +5391,7 @@ fn computeNodeSectionOffset(elf: *Elf, ni: MappedFile.Node.Index) u64 {...@@ -5350,7 +5391,7 @@ fn computeNodeSectionOffset(elf: *Elf, ni: MappedFile.Node.Index) u64 {
5350 .section, .section_manual_size => 0,5391 .section, .section_manual_size => 0,
5351 .input_section, .copied_global => unreachable,5392 .input_section, .copied_global => unreachable,
5352 .nav, .uav, .lazy_code, .lazy_const_data => unreachable,5393 .nav, .uav, .lazy_code, .lazy_const_data => unreachable,
5353 .debug_shared, .eh_frame_footer, .unit_padding => unreachable,5394 .debug_shared, .debug_addr, .eh_frame_footer, .debug_str_offsets, .unit_padding => unreachable,
5354 .unit_frame, .unit_debug_info, .unit_debug_line => {5395 .unit_frame, .unit_debug_info, .unit_debug_line => {
5355 const parent_section_offset, _ = parent_ni.location(&elf.mf).resolve(&elf.mf);5396 const parent_section_offset, _ = parent_ni.location(&elf.mf).resolve(&elf.mf);
5356 break :parent_section_offset parent_section_offset;5397 break :parent_section_offset parent_section_offset;
...@@ -5399,7 +5440,9 @@ pub fn resetNodeRelocs(elf: *Elf, ni: MappedFile.Node.Index) void {...@@ -5399,7 +5440,9 @@ pub fn resetNodeRelocs(elf: *Elf, ni: MappedFile.Node.Index) void {
5399 .segment,5440 .segment,
5400 .copied_global,5441 .copied_global,
5401 .debug_shared,5442 .debug_shared,
5443 .debug_addr,
5402 .eh_frame_footer,5444 .eh_frame_footer,
5445 .debug_str_offsets,
5403 .unit_padding,5446 .unit_padding,
5404 .unit_frame,5447 .unit_frame,
5405 .unit_frame_cie,5448 .unit_frame_cie,
...@@ -5856,10 +5899,11 @@ fn dynsymPtr(elf: *Elf, index: u32) SymPtr {...@@ -5856,10 +5899,11 @@ fn dynsymPtr(elf: *Elf, index: u32) SymPtr {
5856}5899}
58575900
5858fn navType(elf: *const Elf, nav_resolved: InternPool.Nav.Resolved) std.elf.STT {5901fn navType(elf: *const Elf, nav_resolved: InternPool.Nav.Resolved) std.elf.STT {
5859 const any_non_single_threaded = elf.base.comp.config.any_non_single_threaded;5902 const comp = elf.base.comp;
5903 const any_non_single_threaded = comp.config.any_non_single_threaded;
5860 return if (any_non_single_threaded and nav_resolved.@"threadlocal")5904 return if (any_non_single_threaded and nav_resolved.@"threadlocal")
5861 .TLS5905 .TLS
5862 else if (elf.base.comp.zcu.?.intern_pool.isFunctionType(nav_resolved.type))5906 else if (comp.zcu.?.intern_pool.isFunctionType(nav_resolved.type))
5863 .FUNC5907 .FUNC
5864 else5908 else
5865 .OBJECT;5909 .OBJECT;
...@@ -7162,8 +7206,8 @@ fn updateInitFiniArraySectionSize(...@@ -7162,8 +7206,8 @@ fn updateInitFiniArraySectionSize(
7162}7206}
71637207
7164pub fn prelink(elf: *Elf, prog_node: std.Progress.Node) link.Error!void {7208pub fn prelink(elf: *Elf, prog_node: std.Progress.Node) link.Error!void {
7165 const sub_prog_node = prog_node.start("ELF Prelink", 0);7209 const prelink_prog_node = prog_node.start("ELF Prelink", 0);
7166 defer sub_prog_node.end();7210 defer prelink_prog_node.end();
71677211
7168 const diags = &elf.base.comp.link_diags;7212 const diags = &elf.base.comp.link_diags;
7169 elf.prelinkInner() catch |err| switch (err) {7213 elf.prelinkInner() catch |err| switch (err) {
...@@ -7197,45 +7241,20 @@ fn prelinkInner(elf: *Elf) Error!void {...@@ -7197,45 +7241,20 @@ fn prelinkInner(elf: *Elf) Error!void {
7197 };7241 };
7198 elf.input_pending_index += 1;7242 elf.input_pending_index += 1;
71997243
7200 try elf.nodes.ensureUnusedCapacity(gpa, 5 + 4);7244 const addr_align: Alignment = switch (elf.identClass()) {
72017245 .NONE, _ => unreachable,
7202 switch (elf.shndx.debug_abbrev) {7246 .@"32" => .@"4",
7203 .UNDEF => {},7247 .@"64" => .@"8",
7204 else => |debug_abbrev_shndx| elf.dwarf.debug_abbrev.ni = .wrap(elf.addNodeAssumeCapacity(7248 };
7205 try debug_abbrev_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{}),7249 try elf.nodes.ensureUnusedCapacity(gpa, 7 + 5);
7206 .{ .debug_shared = .debug_abbrev },7250 for ([7]Section.Index{
7207 )),7251 elf.shndx.debug_addr,
7208 }
7209 switch (elf.shndx.debug_line_str) {
7210 .UNDEF => {},
7211 else => |debug_line_str_shndx| elf.dwarf.debug_line_str.ni =
7212 .wrap(elf.addNodeAssumeCapacity(
7213 try debug_line_str_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{}),
7214 .{ .debug_shared = .debug_line_str },
7215 )),
7216 }
7217 switch (elf.shndx.debug_str) {
7218 .UNDEF => {},
7219 else => |debug_str_shndx| elf.dwarf.debug_str.ni = .wrap(elf.addNodeAssumeCapacity(
7220 try debug_str_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{}),
7221 .{ .debug_shared = .debug_str },
7222 )),
7223 }
7224 switch (elf.shndx.debug_str_offsets) {
7225 .UNDEF => {},
7226 else => |debug_str_offsets_shndx| elf.dwarf.debug_str_offsets.ni =
7227 .wrap(elf.addNodeAssumeCapacity(
7228 try debug_str_offsets_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{}),
7229 .{ .debug_shared = .debug_str_offsets },
7230 )),
7231 }
7232
7233 for ([5]Section.Index{
7234 elf.shndx.eh_frame,7252 elf.shndx.eh_frame,
7235 elf.shndx.debug_frame,7253 elf.shndx.debug_frame,
7236 elf.shndx.debug_info,7254 elf.shndx.debug_info,
7237 elf.shndx.debug_line,7255 elf.shndx.debug_line,
7238 elf.shndx.debug_rnglists,7256 elf.shndx.debug_rnglists,
7257 elf.shndx.debug_str_offsets,
7239 }) |debug_shndx| {7258 }) |debug_shndx| {
7240 if (debug_shndx == .UNDEF) continue;7259 if (debug_shndx == .UNDEF) continue;
7241 const debug_ni = debug_shndx.get(elf).ni;7260 const debug_ni = debug_shndx.get(elf).ni;
...@@ -7251,11 +7270,7 @@ fn prelinkInner(elf: *Elf) Error!void {...@@ -7251,11 +7270,7 @@ fn prelinkInner(elf: *Elf) Error!void {
7251 };7270 };
7252 break :last_header_oni last_header_oni;7271 break :last_header_oni last_header_oni;
7253 }, .{7272 }, .{
7254 .alignment = if (frame_format) |_| switch (elf.identClass()) {7273 .alignment = if (frame_format) |_| addr_align else .@"1",
7255 .NONE, _ => unreachable,
7256 .@"32" => .@"4",
7257 .@"64" => .@"8",
7258 } else .@"1",
7259 .next_moved = true,7274 .next_moved = true,
7260 .enable_next_moved = true,7275 .enable_next_moved = true,
7261 }),7276 }),
...@@ -7271,6 +7286,75 @@ fn prelinkInner(elf: *Elf) Error!void {...@@ -7271,6 +7286,75 @@ fn prelinkInner(elf: *Elf) Error!void {
7271 error.WriteFailed => return debug_nw.err.?,7286 error.WriteFailed => return debug_nw.err.?,
7272 };7287 };
7273 }7288 }
7289 switch (elf.shndx.debug_addr) {
7290 .UNDEF => {},
7291 else => |debug_addr_shndx| {
7292 const debug_addr_ni = elf.addNodeAssumeCapacity(
7293 try debug_addr_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{
7294 .alignment = addr_align,
7295 .next_moved = true,
7296 .enable_next_moved = true,
7297 }),
7298 .debug_addr,
7299 );
7300 elf.dwarf.debug_addr.ni = .wrap(debug_addr_ni);
7301
7302 var dah_nw: link.MappedFile.Node.Writer = undefined;
7303 debug_addr_ni.writer(gpa, &elf.mf, &dah_nw);
7304 defer dah_nw.deinit();
7305 elf.dwarf.genDebugAddrHeader(&dah_nw.interface) catch |err| switch (err) {
7306 else => |e| return e,
7307 error.WriteFailed => return dah_nw.err.?,
7308 };
7309 },
7310 }
7311 switch (elf.shndx.debug_abbrev) {
7312 .UNDEF => {},
7313 else => |debug_abbrev_shndx| elf.dwarf.debug_abbrev.ni = .wrap(elf.addNodeAssumeCapacity(
7314 try debug_abbrev_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{}),
7315 .{ .debug_shared = .debug_abbrev },
7316 )),
7317 }
7318 switch (elf.shndx.debug_line_str) {
7319 .UNDEF => {},
7320 else => |debug_line_str_shndx| elf.dwarf.debug_line_str.ni =
7321 .wrap(elf.addNodeAssumeCapacity(
7322 try debug_line_str_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{}),
7323 .{ .debug_shared = .debug_line_str },
7324 )),
7325 }
7326 switch (elf.shndx.debug_str) {
7327 .UNDEF => {},
7328 else => |debug_str_shndx| elf.dwarf.debug_str.ni = .wrap(elf.addNodeAssumeCapacity(
7329 try debug_str_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{}),
7330 .{ .debug_shared = .debug_str },
7331 )),
7332 }
7333 switch (elf.shndx.debug_str_offsets) {
7334 .UNDEF => {},
7335 else => |debug_str_offsets_shndx| {
7336 const debug_str_offsets_ni = elf.addNodeAssumeCapacity(
7337 try debug_str_offsets_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{
7338 .alignment = switch (elf.dwarf.format) {
7339 .@"32" => .@"4",
7340 .@"64" => .@"8",
7341 },
7342 .next_moved = true,
7343 .enable_next_moved = true,
7344 }),
7345 .debug_str_offsets,
7346 );
7347 elf.dwarf.debug_str_offsets.ni = .wrap(debug_str_offsets_ni);
7348
7349 var dsoh_nw: link.MappedFile.Node.Writer = undefined;
7350 debug_str_offsets_ni.writer(gpa, &elf.mf, &dsoh_nw);
7351 defer dsoh_nw.deinit();
7352 elf.dwarf.genDebugStrOffsetsHeader(&dsoh_nw.interface) catch |err| switch (err) {
7353 else => |e| return e,
7354 error.WriteFailed => return dsoh_nw.err.?,
7355 };
7356 },
7357 }
7274 }7358 }
7275}7359}
72767360
...@@ -7301,7 +7385,7 @@ fn zcuFilesReadyInner(elf: *Elf, zcu: *Zcu) Error!void {...@@ -7301,7 +7385,7 @@ fn zcuFilesReadyInner(elf: *Elf, zcu: *Zcu) Error!void {
7301 });7385 });
7302 }7386 }
7303 if (!try elf.dwarf.updateUnits(zcu)) return;7387 if (!try elf.dwarf.updateUnits(zcu)) return;
7304 try elf.nodes.ensureUnusedCapacity(gpa, 5 * units_len);7388 try elf.nodes.ensureUnusedCapacity(gpa, 6 * units_len);
7305 for (0..units_len) |unit_index| {7389 for (0..units_len) |unit_index| {
7306 const ui: Dwarf.Unit.Index = @fromBackingInt(@intCast(unit_index));7390 const ui: Dwarf.Unit.Index = @fromBackingInt(@intCast(unit_index));
7307 const unit = ui.get(&elf.dwarf);7391 const unit = ui.get(&elf.dwarf);
...@@ -7396,6 +7480,7 @@ fn zcuFilesReadyInner(elf: *Elf, zcu: *Zcu) Error!void {...@@ -7396,6 +7480,7 @@ fn zcuFilesReadyInner(elf: *Elf, zcu: *Zcu) Error!void {
7396 error.WriteFailed => return dih_nw.err.?,7480 error.WriteFailed => return dih_nw.err.?,
7397 };7481 };
7398 }7482 }
7483 try elf.genPendingDebug(gpa);
7399}7484}
74007485
7401fn flushFiles(elf: *Elf) Error!void {7486fn flushFiles(elf: *Elf) Error!void {
...@@ -7406,7 +7491,6 @@ fn flushFiles(elf: *Elf) Error!void {...@@ -7406,7 +7491,6 @@ fn flushFiles(elf: *Elf) Error!void {
7406 const debug_line_header_ni = unit.debug_line_header_ni.unwrap().?;7491 const debug_line_header_ni = unit.debug_line_header_ni.unwrap().?;
7407 try debug_line_header_ni.parent(&elf.mf).unwrap().?.nextMoved(gpa, &elf.mf);7492 try debug_line_header_ni.parent(&elf.mf).unwrap().?.nextMoved(gpa, &elf.mf);
7408 try debug_line_header_ni.moved(gpa, &elf.mf);7493 try debug_line_header_ni.moved(gpa, &elf.mf);
7409 try debug_line_header_ni.nextMoved(gpa, &elf.mf);
7410 var dlh_nw: MappedFile.Node.Writer = undefined;7494 var dlh_nw: MappedFile.Node.Writer = undefined;
7411 debug_line_header_ni.writer(gpa, &elf.mf, &dlh_nw);7495 debug_line_header_ni.writer(gpa, &elf.mf, &dlh_nw);
7412 defer dlh_nw.deinit();7496 defer dlh_nw.deinit();
...@@ -8221,6 +8305,8 @@ fn addNodeRelocAssumeCapacity(...@@ -8221,6 +8305,8 @@ fn addNodeRelocAssumeCapacity(
8221 const first_target_reloc = switch (elf.getNode(target)) {8305 const first_target_reloc = switch (elf.getNode(target)) {
8222 else => unreachable,8306 else => unreachable,
8223 .debug_shared => |ss| &elf.dwarf_shared.getPtr(ss).first_target_reloc,8307 .debug_shared => |ss| &elf.dwarf_shared.getPtr(ss).first_target_reloc,
8308 .debug_addr => &elf.dwarf_addr.first_target_reloc,
8309 .debug_str_offsets => &elf.dwarf_str_offsets.first_target_reloc,
8224 .unit_frame_cie => |ui| &elf.dwarf_units[@backingInt(ui)].frame_cie_first_target_reloc,8310 .unit_frame_cie => |ui| &elf.dwarf_units[@backingInt(ui)].frame_cie_first_target_reloc,
8225 .unit_debug_info_header => |ui| &elf.dwarf_units[@backingInt(ui)].debug_info_header_first_target_reloc,8311 .unit_debug_info_header => |ui| &elf.dwarf_units[@backingInt(ui)].debug_info_header_first_target_reloc,
8226 .unit_debug_line_header => |ui| &elf.dwarf_units[@backingInt(ui)].debug_line_header_first_target_reloc,8312 .unit_debug_line_header => |ui| &elf.dwarf_units[@backingInt(ui)].debug_line_header_first_target_reloc,
...@@ -8326,7 +8412,9 @@ fn addGotRelocAssumeCapacity(...@@ -8326,7 +8412,9 @@ fn addGotRelocAssumeCapacity(
8326 .segment,8412 .segment,
8327 .copied_global,8413 .copied_global,
8328 .debug_shared,8414 .debug_shared,
8415 .debug_addr,
8329 .eh_frame_footer,8416 .eh_frame_footer,
8417 .debug_str_offsets,
8330 .unit_padding,8418 .unit_padding,
8331 .unit_frame,8419 .unit_frame,
8332 .unit_frame_cie,8420 .unit_frame_cie,
...@@ -8632,38 +8720,77 @@ fn updateNavInner(elf: *Elf, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index)...@@ -8632,38 +8720,77 @@ fn updateNavInner(elf: *Elf, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index)
8632 const ip = &zcu.intern_pool;8720 const ip = &zcu.intern_pool;
86338721
8634 const nav = ip.getNav(nav_index);8722 const nav = ip.getNav(nav_index);
8635 if (ip.indexToKey(nav.resolved.?.value) == .@"extern") return;8723 const mod = zcu.fileByIndex(nav.srcInst(ip).resolveFile(ip)).mod.?;
8636 if (!Type.fromInterned(nav.resolved.?.type).hasRuntimeBits(zcu)) {8724 switch (ip.indexToKey(nav.resolved.?.value)) {
8637 if (elf.ehdrMachine() != .X86_64) return;8725 .@"extern" => |@"extern"| {
8638 const mod = zcu.fileByIndex(nav.srcInst(ip).resolveFile(ip)).mod.?;8726 if (mod.strip or elf.ehdrMachine() != .X86_64) return;
8639 return if (!mod.strip) elf.dwarf.updateComptimeNav(pt, nav_index);8727 const si = try elf.externSymbol(.{
8640 }8728 .name = @"extern".name.toSlice(ip),
8729 .lib_name = @"extern".lib_name.toSlice(ip),
8730 .type = elf.navType(nav.resolved.?),
8731 .linkage = @"extern".linkage,
8732 .visibility = @"extern".visibility,
8733 });
8734 const dwarf_gi = try elf.dwarf.getGlobal(nav_index);
8735 const dwarf_global = dwarf_gi.get(&elf.dwarf);
8736 const debug_info_ni = dwarf_global.debug_info_ni.unwrap().?;
8737 try debug_info_ni.moved(gpa, &elf.mf);
8738 var di_nw: MappedFile.Node.Writer = undefined;
8739 debug_info_ni.writer(gpa, &elf.mf, &di_nw);
8740 defer di_nw.deinit();
8741 elf.resetNodeRelocs(debug_info_ni);
8742 try elf.dwarf.updateExtern(pt, &di_nw, switch (elf.ehdrMachine()) {
8743 else => unreachable,
8744 .X86_64 => .x86_64,
8745 }, si, nav_index);
8746 },
8747 else => if (Type.fromInterned(nav.resolved.?.type).hasRuntimeBits(zcu)) {
8748 const nmi = try elf.navMapIndex(zcu, nav_index);
8749 const lsi = nmi.symbol(elf);
8750 const ni = lsi.index().ptr(elf).node.unwrap().?;
86418751
8642 const nmi = try elf.navMapIndex(zcu, nav_index);8752 // Ensure the NAV is marked as moved so that once we're done, `flushMoved`
8643 const ni = nmi.symbol(elf).index().ptr(elf).node.unwrap().?;8753 // will eventually be called to apply the NAV's new relocations.
8754 try ni.moved(gpa, &elf.mf);
86448755
8645 // Ensure the NAV is marked as moved so that once we're done, `flushMoved` will eventually be8756 {
8646 // called to apply the NAV's new relocations.8757 var nw: MappedFile.Node.Writer = undefined;
8647 try ni.moved(gpa, &elf.mf);8758 ni.writer(gpa, &elf.mf, &nw);
8759 defer nw.deinit();
8760 elf.resetNodeRelocs(ni);
8761 codegen.generateSymbol(
8762 &elf.base,
8763 pt,
8764 .fromInterned(nav.resolved.?.value),
8765 &nw.interface,
8766 .{ .atom_index = Node.toAtom(ni) },
8767 ) catch |err| switch (err) {
8768 else => |e| return e,
8769 error.WriteFailed => return nw.err.?,
8770 };
8771 switch (elf.symPtr(nmi.symbol(elf).index())) {
8772 inline else => |sym| elf.targetStore(&sym.size, @intCast(nw.interface.end)),
8773 }
8774 }
86488775
8649 {8776 if (!mod.strip and elf.ehdrMachine() == .X86_64) {
8650 var nw: MappedFile.Node.Writer = undefined;8777 const dwarf_gi = try elf.dwarf.getGlobal(nav_index);
8651 ni.writer(gpa, &elf.mf, &nw);8778 const dwarf_global = dwarf_gi.get(&elf.dwarf);
8652 defer nw.deinit();8779 const debug_info_ni = dwarf_global.debug_info_ni.unwrap().?;
8653 elf.resetNodeRelocs(ni);8780 try debug_info_ni.moved(gpa, &elf.mf);
8654 codegen.generateSymbol(8781 var di_nw: MappedFile.Node.Writer = undefined;
8655 &elf.base,8782 debug_info_ni.writer(gpa, &elf.mf, &di_nw);
8656 pt,8783 defer di_nw.deinit();
8657 .fromInterned(nav.resolved.?.value),8784 elf.resetNodeRelocs(debug_info_ni);
8658 &nw.interface,8785 try elf.dwarf.updateGlobal(pt, &di_nw, switch (elf.ehdrMachine()) {
8659 .{ .atom_index = Node.toAtom(ni) },8786 else => unreachable,
8660 ) catch |err| switch (err) {8787 .X86_64 => .x86_64,
8661 else => |e| return e,8788 }, Symbol.Id.local(lsi).toTypeErased(), nav_index);
8662 error.WriteFailed => return nw.err.?,8789 }
8663 };8790 } else {
8664 switch (elf.symPtr(nmi.symbol(elf).index())) {8791 if (mod.strip or elf.ehdrMachine() != .X86_64) return;
8665 inline else => |sym| elf.targetStore(&sym.size, @intCast(nw.interface.end)),8792 try elf.dwarf.updateComptimeGlobal(pt, nav_index);
8666 }8793 },
8667 }8794 }
86688795
8669 // The NAV's node is done---now generate any UAVs or lazy code/data which the NAV needs.8796 // The NAV's node is done---now generate any UAVs or lazy code/data which the NAV needs.
...@@ -8726,7 +8853,11 @@ pub fn addConst(...@@ -8726,7 +8853,11 @@ pub fn addConst(
8726 .code_view => unreachable,8853 .code_view => unreachable,
8727 }8854 }
8728}8855}
8729fn addConstNode(lf: *link.File, ui: Dwarf.Unit.Index, cpi: link.ConstPool.Index) link.Error!MappedFile.Node.Index {8856fn addConstNode(
8857 lf: *link.File,
8858 ui: Dwarf.Unit.Index,
8859 cpi: link.ConstPool.Index,
8860) link.Error!MappedFile.Node.Index {
8730 const elf = lf.cast(.elf2).?;8861 const elf = lf.cast(.elf2).?;
8731 const unit = ui.get(&elf.dwarf);8862 const unit = ui.get(&elf.dwarf);
8732 const debug_info_ni = elf.addNodeAssumeCapacity(8863 const debug_info_ni = elf.addNodeAssumeCapacity(
...@@ -8769,17 +8900,18 @@ fn updateConstInner(...@@ -8769,17 +8900,18 @@ fn updateConstInner(
8769 switch (elf.base.comp.config.debug_format) {8900 switch (elf.base.comp.config.debug_format) {
8770 .strip => {},8901 .strip => {},
8771 .dwarf => {8902 .dwarf => {
8903 switch (pt.zcu.intern_pool.indexToKey(val)) {
8904 else => {},
8905 .@"extern" => return,
8906 .func => |func| {
8907 const fi = try elf.dwarf.getFunc(func.owner_nav);
8908 switch (fi.get(&elf.dwarf).state) {
8909 .unresolved => {},
8910 .resolved => return,
8911 }
8912 },
8913 }
8772 {8914 {
8773 switch (pt.zcu.intern_pool.indexToKey(val)) {
8774 else => {},
8775 .func => |func| {
8776 const fi = try elf.dwarf.getFunc(func.owner_nav);
8777 switch (fi.get(&elf.dwarf).state) {
8778 .unresolved => {},
8779 .resolved => return,
8780 }
8781 },
8782 }
8783 const gpa = elf.base.comp.gpa;8915 const gpa = elf.base.comp.gpa;
8784 const debug_info_ni = Dwarf.Const.get(cpi, &elf.dwarf).debug_info_ni.unwrap().?;8916 const debug_info_ni = Dwarf.Const.get(cpi, &elf.dwarf).debug_info_ni.unwrap().?;
8785 try debug_info_ni.moved(gpa, &elf.mf);8917 try debug_info_ni.moved(gpa, &elf.mf);
...@@ -8846,19 +8978,18 @@ fn updateFuncInner(...@@ -8846,19 +8978,18 @@ fn updateFuncInner(
8846 var nw: MappedFile.Node.Writer = undefined;8978 var nw: MappedFile.Node.Writer = undefined;
8847 ni.writer(gpa, &elf.mf, &nw);8979 ni.writer(gpa, &elf.mf, &nw);
8848 defer nw.deinit();8980 defer nw.deinit();
8849 var debug_output_buf: Dwarf.WipNav.Debug = undefined;8981 var debug_output_buf: Dwarf.WipFunc.Debug = undefined;
8850 const debug_output: link.File.DebugInfoOutput, const dwarf_func = debug_output: {8982 const debug_output: link.File.DebugInfoOutput, const dwarf_func = debug_output: {
8851 if (elf.ehdrMachine() != .X86_64) break :debug_output .{ .none, undefined };8983 if (elf.ehdrMachine() != .X86_64) break :debug_output .{ .none, undefined };
8852 const dwarf = &elf.dwarf;8984 const dwarf = &elf.dwarf;
8853 const src_inst = nav.srcInst(ip);8985 const mod = zcu.fileByIndex(nav.srcInst(ip).resolveFile(ip)).mod.?;
8854 const mod = zcu.fileByIndex(src_inst.resolveFile(ip)).mod.?;
8855 if (mod.strip and mod.unwind_tables == .none) break :debug_output .{ .none, undefined };8986 if (mod.strip and mod.unwind_tables == .none) break :debug_output .{ .none, undefined };
88568987
8857 try elf.nodes.ensureUnusedCapacity(gpa, 4);8988 try elf.nodes.ensureUnusedCapacity(gpa, 4);
8858 const dwarf_fi = try dwarf.getFunc(func.owner_nav);8989 const dwarf_fi = try dwarf.getFunc(func.owner_nav);
88598990
8860 const wip_nav = &debug_output_buf.wip_nav;8991 const wip_func = &debug_output_buf.wip_func;
8861 wip_nav.* = .{8992 wip_func.* = .{
8862 .dwarf = dwarf,8993 .dwarf = dwarf,
8863 .unit = dwarf.getUnit(mod),8994 .unit = dwarf.getUnit(mod),
8864 .func = func_index,8995 .func = func_index,
...@@ -8874,7 +9005,7 @@ fn updateFuncInner(...@@ -8874,7 +9005,7 @@ fn updateFuncInner(
8874 .fde_writer = undefined,9005 .fde_writer = undefined,
8875 .frame_func_length = undefined,9006 .frame_func_length = undefined,
8876 };9007 };
8877 const unit = wip_nav.unit.get(dwarf);9008 const unit = wip_func.unit.get(dwarf);
88789009
8879 const frame_align: Alignment = switch (elf.identClass()) {9010 const frame_align: Alignment = switch (elf.identClass()) {
8880 .NONE, _ => unreachable,9011 .NONE, _ => unreachable,
...@@ -8882,13 +9013,13 @@ fn updateFuncInner(...@@ -8882,13 +9013,13 @@ fn updateFuncInner(
8882 .@"64" => .@"8",9013 .@"64" => .@"8",
8883 };9014 };
8884 const frame_ni = unit.frame_ni.unwrap() orelse frame_ni: {9015 const frame_ni = unit.frame_ni.unwrap() orelse frame_ni: {
8885 const frame_ni = elf.addNodeAssumeCapacity(try switch (wip_nav.frame_format) {9016 const frame_ni = elf.addNodeAssumeCapacity(try switch (wip_func.frame_format) {
8886 .debug_frame => elf.shndx.debug_frame,9017 .debug_frame => elf.shndx.debug_frame,
8887 .eh_frame => elf.shndx.eh_frame,9018 .eh_frame => elf.shndx.eh_frame,
8888 }.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{9019 }.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{
8889 .alignment = frame_align.max(elf.mf.flags.block_size),9020 .alignment = frame_align.max(elf.mf.flags.block_size),
8890 .enable_next_moved = true,9021 .enable_next_moved = true,
8891 }), .{ .unit_frame = wip_nav.unit });9022 }), .{ .unit_frame = wip_func.unit });
8892 unit.frame_ni = .wrap(frame_ni);9023 unit.frame_ni = .wrap(frame_ni);
8893 break :frame_ni frame_ni;9024 break :frame_ni frame_ni;
8894 };9025 };
...@@ -8899,7 +9030,7 @@ fn updateFuncInner(...@@ -8899,7 +9030,7 @@ fn updateFuncInner(
8899 .next_moved = true,9030 .next_moved = true,
8900 .enable_next_moved = true,9031 .enable_next_moved = true,
8901 }),9032 }),
8902 .{ .unit_frame_cie = wip_nav.unit },9033 .{ .unit_frame_cie = wip_func.unit },
8903 );9034 );
8904 unit.cie_ni = .wrap(cie_ni);9035 unit.cie_ni = .wrap(cie_ni);
8905 var cie_nw: MappedFile.Node.Writer = undefined;9036 var cie_nw: MappedFile.Node.Writer = undefined;
...@@ -8908,14 +9039,13 @@ fn updateFuncInner(...@@ -8908,14 +9039,13 @@ fn updateFuncInner(
8908 dwarf.genDebugFrameCie(&cie_nw.interface, switch (elf.ehdrMachine()) {9039 dwarf.genDebugFrameCie(&cie_nw.interface, switch (elf.ehdrMachine()) {
8909 else => unreachable,9040 else => unreachable,
8910 .X86_64 => .x86_64,9041 .X86_64 => .x86_64,
8911 }, wip_nav.frame_format) catch |err| switch (err) {9042 }, wip_func.frame_format) catch |err| switch (err) {
8912 error.WriteFailed => return cie_nw.err.?,9043 error.WriteFailed => return cie_nw.err.?,
8913 };9044 };
8914 }9045 }
8915 const dwarf_func = dwarf_fi.get(dwarf);9046 const dwarf_func = dwarf_fi.get(dwarf);
8916 const fde_ni = if (dwarf_func.fde_ni.unwrap()) |fde_ni| fde_ni: {9047 const fde_ni = if (dwarf_func.fde_ni.unwrap()) |fde_ni| fde_ni: {
8917 try fde_ni.moved(gpa, &elf.mf);9048 try fde_ni.moved(gpa, &elf.mf);
8918 try fde_ni.nextMoved(gpa, &elf.mf);
8919 break :fde_ni fde_ni;9049 break :fde_ni fde_ni;
8920 } else fde_ni: {9050 } else fde_ni: {
8921 const fde_ni = elf.addNodeAssumeCapacity(try frame_ni.addFloatingChild(gpa, &elf.mf, .{9051 const fde_ni = elf.addNodeAssumeCapacity(try frame_ni.addFloatingChild(gpa, &elf.mf, .{
...@@ -8927,22 +9057,16 @@ fn updateFuncInner(...@@ -8927,22 +9057,16 @@ fn updateFuncInner(
8927 dwarf_func.fde_ni = .wrap(fde_ni);9057 dwarf_func.fde_ni = .wrap(fde_ni);
8928 break :fde_ni fde_ni;9058 break :fde_ni fde_ni;
8929 };9059 };
8930 fde_ni.writer(gpa, &elf.mf, &wip_nav.fde_writer);9060 fde_ni.writer(gpa, &elf.mf, &wip_func.fde_writer);
89319061
8932 if (mod.strip) break :debug_output .{ .{ .eh_frame = wip_nav }, dwarf_func };9062 if (mod.strip) break :debug_output .{ .{ .eh_frame = wip_func }, dwarf_func };
89339063
8934 const debug = &debug_output_buf;9064 const debug = &debug_output_buf;
8935 debug.pt = pt;9065 debug.init(pt);
8936 debug.any_children = false;
8937 debug.blocks = .empty;
8938 dwarf_func.state = .resolved;9066 dwarf_func.state = .resolved;
89399067
8940 const debug_info_ni = dwarf_func.debug_info_ni.unwrap().?;9068 const debug_info_ni = dwarf_func.debug_info_ni.unwrap().?;
8941 try dwarf.decls.put(zcu.comp.gpa, src_inst, .{
8942 .debug_info_ni = debug_info_ni.toOptional(),
8943 });
8944 try debug_info_ni.moved(gpa, &elf.mf);9069 try debug_info_ni.moved(gpa, &elf.mf);
8945 try debug_info_ni.nextMoved(gpa, &elf.mf);
8946 debug_info_ni.writer(gpa, &elf.mf, &debug.info_writer);9070 debug_info_ni.writer(gpa, &elf.mf, &debug.info_writer);
89479071
8948 const debug_line_ni = dwarf_func.debug_line_ni.unwrap() orelse debug_line_ni: {9072 const debug_line_ni = dwarf_func.debug_line_ni.unwrap() orelse debug_line_ni: {
...@@ -8968,17 +9092,17 @@ fn updateFuncInner(...@@ -8968,17 +9092,17 @@ fn updateFuncInner(
8968 };9092 };
8969 switch (debug_output) {9093 switch (debug_output) {
8970 .dwarf => unreachable,9094 .dwarf => unreachable,
8971 .eh_frame => |wip_nav| {9095 .eh_frame => |wip_func| {
8972 elf.resetNodeRelocs(dwarf_func.fde_ni.unwrap().?);9096 elf.resetNodeRelocs(dwarf_func.fde_ni.unwrap().?);
8973 try wip_nav.genDebugFrameHeader();9097 try wip_func.genDebugFrameHeader();
8974 },9098 },
8975 .dwarf2 => |debug| {9099 .dwarf2 => |debug| {
8976 elf.resetNodeRelocs(dwarf_func.fde_ni.unwrap().?);9100 elf.resetNodeRelocs(dwarf_func.fde_ni.unwrap().?);
8977 try debug.wip_nav.genDebugFrameHeader();9101 try debug.wip_func.genDebugFrameHeader();
8978 elf.resetNodeRelocs(dwarf_func.debug_line_ni.unwrap().?);9102 elf.resetNodeRelocs(dwarf_func.debug_line_ni.unwrap().?);
8979 try debug.startDebugLine();9103 try debug.startDebugLine();
8980 elf.resetNodeRelocs(dwarf_func.debug_info_ni.unwrap().?);9104 elf.resetNodeRelocs(dwarf_func.debug_info_ni.unwrap().?);
8981 try debug.startFuncDebugInfo();9105 try debug.startDebugInfo();
8982 },9106 },
8983 .none => {},9107 .none => {},
8984 }9108 }
...@@ -9001,35 +9125,34 @@ fn updateFuncInner(...@@ -9001,35 +9125,34 @@ fn updateFuncInner(
9001 }9125 }
9002 switch (debug_output) {9126 switch (debug_output) {
9003 .dwarf => unreachable,9127 .dwarf => unreachable,
9004 .eh_frame => |wip_nav| wip_nav.finishDebugFrameFde(func_length),9128 .eh_frame => |wip_func| wip_func.finishDebugFrameFde(func_length),
9005 .dwarf2 => |debug| {9129 .dwarf2 => |debug| {
9006 try debug.finishFunc(func_length);9130 try debug.finish(func_length);
9007 const unit = debug.wip_nav.unit.get(debug.wip_nav.dwarf);9131 const unit = debug.wip_func.unit.get(debug.wip_func.dwarf);
9008 {9132 {
9009 var dr_nw: MappedFile.Node.Writer = undefined;9133 var dr_nw: MappedFile.Node.Writer = undefined;
9010 unit.debug_rnglists_ni.unwrap().?.writer(gpa, &elf.mf, &dr_nw);9134 const debug_rnglists_ni = unit.debug_rnglists_ni.unwrap().?;
9135 try debug_rnglists_ni.moved(gpa, &elf.mf);
9136 debug_rnglists_ni.writer(gpa, &elf.mf, &dr_nw);
9011 defer dr_nw.deinit();9137 defer dr_nw.deinit();
9012 const first_symbol_reloc = elf.symbol_relocs.items.len;9138 const first_symbol_ri = elf.symbol_relocs.items.len;
9013 debug.wip_nav.dwarf.genDebugRnglists(9139 debug.wip_func.dwarf.genDebugRnglistsRange(
9014 unit,9140 unit,
9015 &dr_nw,9141 &dr_nw,
9016 debug.wip_nav.func_si,9142 debug.wip_func.func_si,
9017 func_length,9143 func_length,
9018 ) catch |err| switch (err) {9144 ) catch |err| switch (err) {
9019 else => |e| return e,9145 else => |e| return e,
9020 error.WriteFailed => return dr_nw.err.?,9146 error.WriteFailed => return dr_nw.err.?,
9021 };9147 };
9022 const symbol_relocs = &elf.dwarf_units[@backingInt(debug.wip_nav.unit)]9148 const symbol_relocs = &elf.dwarf_units[@backingInt(debug.wip_func.unit)]
9023 .debug_rnglists_symbol_relocs;9149 .debug_rnglists_symbol_relocs;
9024 try symbol_relocs.ensureUnusedCapacity(gpa, elf.symbol_relocs.items.len -9150 try symbol_relocs.ensureUnusedCapacity(gpa, elf.symbol_relocs.items.len -
9025 first_symbol_reloc);9151 first_symbol_ri);
9026 for (first_symbol_reloc..elf.symbol_relocs.items.len) |symbol_ri|9152 for (first_symbol_ri..elf.symbol_relocs.items.len) |symbol_ri|
9027 symbol_relocs.putAssumeCapacityNoClobber(9153 symbol_relocs.appendAssumeCapacity(@fromBackingInt(@intCast(symbol_ri)));
9028 @fromBackingInt(@intCast(symbol_ri)),
9029 {},
9030 );
9031 }9154 }
9032 debug.wip_nav.finishDebugFrameFde(func_length);9155 debug.wip_func.finishDebugFrameFde(func_length);
9033 if (func.analysisUnordered(ip).inferred_error_set) {9156 if (func.analysisUnordered(ip).inferred_error_set) {
9034 const ies = ip.getIfExists(.{ .inferred_error_set_type = func_index }).?;9157 const ies = ip.getIfExists(.{ .inferred_error_set_type = func_index }).?;
9035 if (elf.dwarf.const_pool.getIfExists(ies)) |cpi|9158 if (elf.dwarf.const_pool.getIfExists(ies)) |cpi|
...@@ -9111,8 +9234,8 @@ fn flushInner(...@@ -9111,8 +9234,8 @@ fn flushInner(
9111 const diags = &comp.link_diags;9234 const diags = &comp.link_diags;
9112 _ = arena;9235 _ = arena;
91139236
9114 const sub_prog_node = prog_node.start("ELF Flush", 0);9237 const flush_prog_node = prog_node.start("ELF Flush", 0);
9115 defer sub_prog_node.end();9238 defer flush_prog_node.end();
91169239
9117 try elf.flushFiles();9240 try elf.flushFiles();
91189241
...@@ -9130,8 +9253,12 @@ fn flushInner(...@@ -9130,8 +9253,12 @@ fn flushInner(
91309253
9131 while (try elf.idle(tid)) {}9254 while (try elf.idle(tid)) {}
91329255
9256 assert(elf.input_pending_index == elf.inputs.items.len);
9257 assert(elf.input_section_pending_index == elf.input_sections.items.len);
9133 assert(elf.pending_uavs.items.len == 0);9258 assert(elf.pending_uavs.items.len == 0);
9134 assert(elf.dwarf.const_pool.pending.items.len == 0);9259 assert(elf.dwarf.const_pool.pending.items.len == 0);
9260 assert(!elf.dwarf.debug_addr.anyPending());
9261 assert(!elf.dwarf.debug_str_offsets.anyPending());
91359262
9136 // We've done the final `idle` loop, so everything is at its final place in the file. We have a9263 // We've done the final `idle` loop, so everything is at its final place in the file. We have a
9137 // few more things to check and write now that addresses and offsets are finalized.9264 // few more things to check and write now that addresses and offsets are finalized.
...@@ -9195,22 +9322,24 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {...@@ -9195,22 +9322,24 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {
9195 assert(elf.dwarf.const_pool.pending.items.len == 0);9322 assert(elf.dwarf.const_pool.pending.items.len == 0);
91969323
9197 task: {9324 task: {
9198 if (elf.input_pending_index < elf.inputs.items.len) {9325 if (elf.inputs.items.len - elf.input_pending_index > 0) {
9199 const ii: Node.InputIndex = @fromBackingInt(elf.input_pending_index);9326 const ii: Node.InputIndex = @fromBackingInt(elf.input_pending_index);
9200 elf.input_pending_index += 1;9327 elf.input_pending_index += 1;
9201 const sub_prog_node = elf.idleProgNode(tid, elf.input_prog_node, elf.getNode(ii.node(elf)));9328 const idle_prog_node =
9202 defer sub_prog_node.end();9329 elf.startIdleProgress(tid, elf.input_prog_node, elf.getNode(ii.node(elf)));
9330 defer idle_prog_node.end();
9203 elf.flushInput(ii) catch |err| switch (err) {9331 elf.flushInput(ii) catch |err| switch (err) {
9204 else => |e| return e,9332 else => |e| return e,
9205 error.MappedFileIo => return diags.fail("failed to write output file: {t}", .{elf.mf.io_err.?}),9333 error.MappedFileIo => return diags.fail("failed to write output file: {t}", .{elf.mf.io_err.?}),
9206 };9334 };
9207 break :task;9335 break :task;
9208 }9336 }
9209 if (elf.input_section_pending_index < elf.input_sections.items.len) {9337 if (elf.input_sections.items.len - elf.input_section_pending_index > 0) {
9210 const isi: InputSection.Index = @fromBackingInt(elf.input_section_pending_index);9338 const isi: InputSection.Index = @fromBackingInt(elf.input_section_pending_index);
9211 elf.input_section_pending_index += 1;9339 elf.input_section_pending_index += 1;
9212 const sub_prog_node = elf.idleProgNode(tid, elf.input_prog_node, elf.getNode(isi.node(elf)));9340 const idle_prog_node =
9213 defer sub_prog_node.end();9341 elf.startIdleProgress(tid, elf.input_prog_node, elf.getNode(isi.node(elf)));
9342 defer idle_prog_node.end();
9214 elf.flushInputSection(isi) catch |err| switch (err) {9343 elf.flushInputSection(isi) catch |err| switch (err) {
9215 else => |e| return e,9344 else => |e| return e,
9216 error.MappedFileIo => return diags.fail("failed to write output file: {t}", .{elf.mf.io_err.?}),9345 error.MappedFileIo => return diags.fail("failed to write output file: {t}", .{elf.mf.io_err.?}),
...@@ -9237,8 +9366,8 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {...@@ -9237,8 +9366,8 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {
9237 break :task;9366 break :task;
9238 }9367 }
9239 if (elf.changed_symtab_index.pop()) |kv| {9368 if (elf.changed_symtab_index.pop()) |kv| {
9240 const sub_prog_node = elf.mf.update_prog_node.start(kv.key.slice(elf), 0);9369 const idle_prog_node = elf.mf.update_prog_node.start(kv.key.slice(elf), 0);
9241 defer sub_prog_node.end();9370 defer idle_prog_node.end();
92429371
9243 const global_name = kv.key;9372 const global_name = kv.key;
9244 const global = elf.globalByName(global_name).?;9373 const global = elf.globalByName(global_name).?;
...@@ -9317,22 +9446,23 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {...@@ -9317,22 +9446,23 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {
9317 const clean_resized = ni.cleanResized(&elf.mf);9446 const clean_resized = ni.cleanResized(&elf.mf);
9318 const clean_next_moved = ni.cleanNextMoved(&elf.mf);9447 const clean_next_moved = ni.cleanNextMoved(&elf.mf);
9319 if (!clean_moved and !clean_resized and !clean_next_moved) continue;9448 if (!clean_moved and !clean_resized and !clean_next_moved) continue;
9320 const sub_prog_node = elf.idleProgNode(tid, elf.mf.update_prog_node, elf.getNode(ni));9449 const idle_prog_node = elf.startIdleProgress(tid, elf.mf.update_prog_node, elf.getNode(ni));
9321 defer sub_prog_node.end();9450 defer idle_prog_node.end();
9322 if (clean_moved) try elf.flushMoved(ni);9451 if (clean_moved) try elf.flushMoved(ni);
9323 if (clean_resized) try elf.flushResized(ni);9452 if (clean_resized) try elf.flushResized(ni);
9324 if (clean_moved or clean_resized or clean_next_moved) try elf.flushPadding(ni);9453 if (clean_moved or clean_resized or clean_next_moved) try elf.flushPadding(ni);
9325 break :task;9454 break :task;
9326 }9455 }
9327 }9456 }
9328 if (elf.input_sections.items.len > elf.input_section_pending_index) return true;9457 if (elf.inputs.items.len - elf.input_pending_index > 0) return true;
9458 if (elf.input_sections.items.len - elf.input_section_pending_index > 0) return true;
9329 if (elf.one_shot_fixups.items.len > 0) return true;9459 if (elf.one_shot_fixups.items.len > 0) return true;
9330 if (elf.changed_symtab_index.count() > 0) return true;9460 if (elf.changed_symtab_index.count() > 0) return true;
9331 if (elf.mf.updates.items.len > 0) return true;9461 if (elf.mf.updates.items.len > 0) return true;
9332 return false;9462 return false;
9333}9463}
93349464
9335fn idleProgNode(9465fn startIdleProgress(
9336 elf: *Elf,9466 elf: *Elf,
9337 tid: Zcu.PerThread.Id,9467 tid: Zcu.PerThread.Id,
9338 prog_node: std.Progress.Node,9468 prog_node: std.Progress.Node,
...@@ -9363,7 +9493,7 @@ fn idleProgNode(...@@ -9363,7 +9493,7 @@ fn idleProgNode(
9363 }) catch &name,9493 }) catch &name,
9364 .debug_shared => |ss| switch (ss) {9494 .debug_shared => |ss| switch (ss) {
9365 .debug_abbrev => "debug info abbrevs",9495 .debug_abbrev => "debug info abbrevs",
9366 .debug_str, .debug_str_offsets => "debug info strings",9496 .debug_str => "debug info strings",
9367 .debug_line_str => "line info strings",9497 .debug_line_str => "line info strings",
9368 },9498 },
9369 .unit_frame,9499 .unit_frame,
...@@ -9432,29 +9562,56 @@ fn genPending(elf: *Elf, pt: Zcu.PerThread) link.Error!void {...@@ -9432,29 +9562,56 @@ fn genPending(elf: *Elf, pt: Zcu.PerThread) link.Error!void {
9432 try elf.genUav(pt, umi);9562 try elf.genUav(pt, umi);
9433 }9563 }
9434 var lazy_it = elf.lazy.iterator();9564 var lazy_it = elf.lazy.iterator();
9435 while (lazy_it.next()) |lazy| while (lazy.value.pending_index < lazy.value.map.count()) {9565 while (lazy_it.next()) |lazy| while (lazy.value.map.count() - lazy.value.pending_index > 0) {
9436 try elf.genLazy(pt, .{ .kind = lazy.key, .index = lazy.value.pending_index });9566 try elf.genLazy(pt, .{ .kind = lazy.key, .index = lazy.value.pending_index });
9437 lazy.value.pending_index += 1;9567 lazy.value.pending_index += 1;
9438 };9568 };
9569 const gpa = elf.base.comp.gpa;
9439 switch (elf.base.comp.config.debug_format) {9570 switch (elf.base.comp.config.debug_format) {
9440 .strip => {},9571 .strip => {},
9441 .dwarf => {9572 .dwarf => while (true) {
9442 const gpa = elf.base.comp.gpa;9573 const pending = elf.dwarf.pending_decl;
9443 while (true) {9574 if (pending.instance == .none) break;
9444 const pending = elf.dwarf.pending_decl;9575 elf.dwarf.pending_decl = .{ .di = undefined, .instance = .none };
9445 if (pending.instance_val == .none) break;9576 const debug_info_ni = pending.di.get(&elf.dwarf).debug_info_ni.unwrap().?;
9446 elf.dwarf.pending_decl = .{ .di = undefined, .instance_val = .none };9577 try debug_info_ni.moved(gpa, &elf.mf);
9447 const debug_info_ni = pending.di.get(&elf.dwarf).debug_info_ni.unwrap().?;9578 var di_nw: MappedFile.Node.Writer = undefined;
9448 try debug_info_ni.moved(gpa, &elf.mf);9579 debug_info_ni.writer(gpa, &elf.mf, &di_nw);
9449 var di_nw: MappedFile.Node.Writer = undefined;9580 defer di_nw.deinit();
9450 debug_info_ni.writer(gpa, &elf.mf, &di_nw);9581 elf.resetNodeRelocs(debug_info_ni);
9451 defer di_nw.deinit();9582 try elf.dwarf.genDecl(pt, &di_nw, pending.instance);
9452 elf.resetNodeRelocs(debug_info_ni);
9453 try elf.dwarf.genDecl(pt, &di_nw, pending.instance_val);
9454 }
9455 },9583 },
9456 .code_view => unreachable,9584 .code_view => unreachable,
9457 }9585 }
9586 try elf.genPendingDebug(gpa);
9587}
9588fn genPendingDebug(elf: *Elf, gpa: std.mem.Allocator) link.Error!void {
9589 while (elf.dwarf.debug_addr.map.count() - elf.dwarf.debug_addr.pending_index > 0) {
9590 const debug_addr_ni = elf.dwarf.debug_addr.ni.unwrap().?;
9591 try debug_addr_ni.moved(gpa, &elf.mf);
9592 var da_nw: link.MappedFile.Node.Writer = undefined;
9593 debug_addr_ni.writer(gpa, &elf.mf, &da_nw);
9594 defer da_nw.deinit();
9595 const first_symbol_ri = elf.symbol_relocs.items.len;
9596 try elf.dwarf.genPendingDebugAddr(&da_nw);
9597 const symbol_relocs = &elf.dwarf_addr.symbol_relocs;
9598 try symbol_relocs.ensureUnusedCapacity(gpa, elf.symbol_relocs.items.len - first_symbol_ri);
9599 for (first_symbol_ri..elf.symbol_relocs.items.len) |symbol_ri|
9600 symbol_relocs.appendAssumeCapacity(@fromBackingInt(@intCast(symbol_ri)));
9601 }
9602 while (elf.dwarf.debug_str_offsets.map.count() - elf.dwarf.debug_str_offsets.pending_index > 0) {
9603 const debug_str_offsets_ni = elf.dwarf.debug_str_offsets.ni.unwrap().?;
9604 try debug_str_offsets_ni.moved(gpa, &elf.mf);
9605 var dso_nw: link.MappedFile.Node.Writer = undefined;
9606 debug_str_offsets_ni.writer(gpa, &elf.mf, &dso_nw);
9607 defer dso_nw.deinit();
9608 const first_node_ri = elf.node_relocs.items.len;
9609 try elf.dwarf.genPendingDebugStrOffsets(&dso_nw);
9610 const node_relocs = &elf.dwarf_str_offsets.node_relocs;
9611 try node_relocs.ensureUnusedCapacity(gpa, elf.node_relocs.items.len - first_node_ri);
9612 for (first_node_ri..elf.node_relocs.items.len) |node_ri|
9613 node_relocs.appendAssumeCapacity(@fromBackingInt(@intCast(node_ri)));
9614 }
9458}9615}
94599616
9460fn genUav(9617fn genUav(
...@@ -9855,7 +10012,44 @@ fn flushMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!void...@@ -9855,7 +10012,44 @@ fn flushMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!void
9855 target_ri = target_reloc.next;10012 target_ri = target_reloc.next;
9856 }10013 }
9857 },10014 },
9858 .eh_frame_footer, .unit_padding, .unit_frame, .unit_debug_info, .unit_debug_line => {},10015 .eh_frame_footer,
10016 .unit_padding,
10017 .unit_frame,
10018 .unit_debug_info,
10019 .unit_debug_line,
10020 => {},
10021 .debug_addr => {
10022 const target_section_offset = elf.computeNodeSectionOffset(ni);
10023 var target_ri = elf.dwarf_addr.first_target_reloc;
10024 while (target_ri != .none) {
10025 const target_reloc = target_ri.get(elf);
10026 assert(target_reloc.target == ni);
10027 target_reloc.flushMovedTarget(elf, target_section_offset);
10028 target_ri = target_reloc.next;
10029 }
10030 const node_vaddr = elf.computeNodeVAddr(ni);
10031 for (elf.dwarf_addr.symbol_relocs.items) |symbol_ri| {
10032 const symbol_reloc = symbol_ri.get(elf);
10033 assert(symbol_reloc.node.unwrap().? == ni);
10034 symbol_reloc.flushMovedNode(elf, node_vaddr);
10035 }
10036 },
10037 .debug_str_offsets => {
10038 const target_section_offset = elf.computeNodeSectionOffset(ni);
10039 var target_ri = elf.dwarf_str_offsets.first_target_reloc;
10040 while (target_ri != .none) {
10041 const target_reloc = target_ri.get(elf);
10042 assert(target_reloc.target == ni);
10043 target_reloc.flushMovedTarget(elf, target_section_offset);
10044 target_ri = target_reloc.next;
10045 }
10046 const node_vaddr = elf.computeNodeVAddr(ni);
10047 for (elf.dwarf_str_offsets.node_relocs.items) |node_ri| {
10048 const node_reloc = node_ri.get(elf);
10049 assert(node_reloc.node.unwrap().? == ni);
10050 node_reloc.flushMovedNode(elf, node_vaddr);
10051 }
10052 },
9859 .unit_frame_cie => |ui| {10053 .unit_frame_cie => |ui| {
9860 const target_section_offset = elf.computeNodeSectionOffset(ni);10054 const target_section_offset = elf.computeNodeSectionOffset(ni);
9861 var target_ri = elf.dwarf_units[@backingInt(ui)].frame_cie_first_target_reloc;10055 var target_ri = elf.dwarf_units[@backingInt(ui)].frame_cie_first_target_reloc;
...@@ -9906,7 +10100,7 @@ fn flushMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!void...@@ -9906,7 +10100,7 @@ fn flushMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!void
9906 target_ri = target_reloc.next;10100 target_ri = target_reloc.next;
9907 }10101 }
9908 const node_vaddr = elf.computeNodeVAddr(ni);10102 const node_vaddr = elf.computeNodeVAddr(ni);
9909 for (dwarf_unit.debug_rnglists_symbol_relocs.keys()) |symbol_ri| {10103 for (dwarf_unit.debug_rnglists_symbol_relocs.items) |symbol_ri| {
9910 const symbol_reloc = symbol_ri.get(elf);10104 const symbol_reloc = symbol_ri.get(elf);
9911 assert(symbol_reloc.node.unwrap().? == ni);10105 assert(symbol_reloc.node.unwrap().? == ni);
9912 symbol_reloc.flushMovedNode(elf, node_vaddr);10106 symbol_reloc.flushMovedNode(elf, node_vaddr);
...@@ -10238,7 +10432,9 @@ fn flushResized(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo...@@ -10238,7 +10432,9 @@ fn flushResized(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
10238 .lazy_code,10432 .lazy_code,
10239 .lazy_const_data,10433 .lazy_const_data,
10240 .debug_shared,10434 .debug_shared,
10435 .debug_addr,
10241 .eh_frame_footer,10436 .eh_frame_footer,
10437 .debug_str_offsets,
10242 .unit_padding,10438 .unit_padding,
10243 .unit_frame,10439 .unit_frame,
10244 .unit_frame_cie,10440 .unit_frame_cie,
...@@ -10262,7 +10458,8 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo...@@ -10262,7 +10458,8 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
10262 const trace = tracy.trace(@src());10458 const trace = tracy.trace(@src());
10263 defer trace.end();10459 defer trace.end();
1026410460
10265 switch (elf.getNode(ni)) {10461 const node = elf.getNode(ni);
10462 switch (node) {
10266 .deleted => unreachable,10463 .deleted => unreachable,
10267 .archive,10464 .archive,
10268 .archive_input_member,10465 .archive_input_member,
...@@ -10310,6 +10507,8 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo...@@ -10310,6 +10507,8 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
10310 error.NoSpaceLeft => archive.strtab_member_too_big = true,10507 error.NoSpaceLeft => archive.strtab_member_too_big = true,
10311 }10508 }
10312 },10509 },
10510 .debug_addr,
10511 .debug_str_offsets,
10313 .unit_padding,10512 .unit_padding,
10314 .unit_frame_cie,10513 .unit_frame_cie,
10315 .unit_debug_info_header,10514 .unit_debug_info_header,
...@@ -10321,8 +10520,27 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo...@@ -10321,8 +10520,27 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
10321 .func_debug_info,10520 .func_debug_info,
10322 .func_debug_line,10521 .func_debug_line,
10323 .decl_debug_info,10522 .decl_debug_info,
10324 => |_, tag| {10523 => {
10325 const offset, const size = ni.location(&elf.mf).resolve(&elf.mf);10524 const offset, const size = location: {
10525 const offset, const size = ni.location(&elf.mf).resolve(&elf.mf);
10526 break :location .{ offset, switch (node) {
10527 else => unreachable,
10528 .debug_addr => elf.dwarf.debug_addr.size(&elf.dwarf),
10529 .debug_str_offsets => elf.dwarf.debug_str_offsets.size(&elf.dwarf),
10530 .unit_padding,
10531 .unit_frame_cie,
10532 .unit_debug_info_header,
10533 .unit_debug_line_header,
10534 .const_debug_info,
10535 .global_debug_info,
10536 .func_frame_fde,
10537 .func_debug_info,
10538 .func_debug_line,
10539 .decl_debug_info,
10540 => size,
10541 .unit_debug_rnglists => |ui| Dwarf.Rnglists.size(&elf.dwarf, ui),
10542 } };
10543 };
10326 const parent_ni = ni.parent(&elf.mf).unwrap().?;10544 const parent_ni = ni.parent(&elf.mf).unwrap().?;
10327 const slice = slice: {10545 const slice = slice: {
10328 if (ni.next(&elf.mf).unwrap()) |next_ni| switch (next_ni.position(&elf.mf)) {10546 if (ni.next(&elf.mf).unwrap()) |next_ni| switch (next_ni.position(&elf.mf)) {
...@@ -10334,9 +10552,9 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo...@@ -10334,9 +10552,9 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
10334 break :slice parent_slice[@intCast(offset)..@intCast(next_offset)];10552 break :slice parent_slice[@intCast(offset)..@intCast(next_offset)];
10335 },10553 },
10336 };10554 };
10337 switch (tag) {10555 switch (node) {
10338 else => unreachable,10556 else => unreachable,
10339 .unit_padding, .unit_debug_rnglists => {10557 .debug_addr, .debug_str_offsets, .unit_padding, .unit_debug_rnglists => {
10340 const parent_slice = parent_ni.slicePadding(&elf.mf);10558 const parent_slice = parent_ni.slicePadding(&elf.mf);
10341 const frame_shndx = elf.getNodeShndx(parent_ni);10559 const frame_shndx = elf.getNodeShndx(parent_ni);
10342 const frame_format = frame_shndx.debugFrameFormat(elf) orelse10560 const frame_format = frame_shndx.debugFrameFormat(elf) orelse
...@@ -10411,7 +10629,7 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo...@@ -10411,7 +10629,7 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
10411 break :buffer debug_slice[@intCast(parent_offset)..];10629 break :buffer debug_slice[@intCast(parent_offset)..];
10412 });10630 });
10413 fw.end = @intCast(offset + size);10631 fw.end = @intCast(offset + size);
10414 switch (tag) {10632 switch (node) {
10415 else => unreachable,10633 else => unreachable,
10416 .unit_debug_info_header,10634 .unit_debug_info_header,
10417 .const_debug_info,10635 .const_debug_info,
...@@ -10428,7 +10646,7 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo...@@ -10428,7 +10646,7 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
10428 error.WriteFailed => {10646 error.WriteFailed => {
10429 fw.end = unit_padding_offset;10647 fw.end = unit_padding_offset;
10430 elf.dwarf.updateUnitLength(fw.buffer, fw.buffer.len);10648 elf.dwarf.updateUnitLength(fw.buffer, fw.buffer.len);
10431 switch (tag) {10649 switch (node) {
10432 else => unreachable,10650 else => unreachable,
10433 .unit_debug_info_header,10651 .unit_debug_info_header,
10434 .const_debug_info,10652 .const_debug_info,
...@@ -10459,8 +10677,23 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo...@@ -10459,8 +10677,23 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
10459 }10677 }
10460 };10678 };
10461 var fw: Io.Writer = .fixed(slice[@intCast(size)..]);10679 var fw: Io.Writer = .fixed(slice[@intCast(size)..]);
10462 switch (tag) {10680 switch (node) {
10463 else => unreachable,10681 else => unreachable,
10682 .debug_addr, .debug_str_offsets, .unit_debug_rnglists => {
10683 elf.dwarf.genUnitPadding(&fw) catch |err| switch (err) {
10684 error.WriteFailed => {
10685 elf.dwarf.updateUnitLength(slice, slice.len);
10686 @memset(fw.buffer, switch (node) {
10687 else => unreachable,
10688 .debug_addr, .debug_str_offsets => std.math.maxInt(u8),
10689 .unit_debug_rnglists => std.dwarf.RLE.end_of_list,
10690 });
10691 return;
10692 },
10693 };
10694 elf.dwarf.updateUnitLength(slice, size);
10695 elf.dwarf.updateUnitLength(fw.buffer, fw.buffer.len);
10696 },
10464 .unit_padding => elf.dwarf.updateUnitLength(slice, slice.len),10697 .unit_padding => elf.dwarf.updateUnitLength(slice, slice.len),
10465 .unit_frame_cie, .func_frame_fde => {10698 .unit_frame_cie, .func_frame_fde => {
10466 elf.dwarf.updateUnitLength(slice, slice.len);10699 elf.dwarf.updateUnitLength(slice, slice.len);
...@@ -10475,17 +10708,6 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo...@@ -10475,17 +10708,6 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
10475 .unit_debug_line_header,10708 .unit_debug_line_header,
10476 .func_debug_line,10709 .func_debug_line,
10477 => Dwarf.genDebugLinePadding(&fw, fw.buffer.len) catch unreachable,10710 => Dwarf.genDebugLinePadding(&fw, fw.buffer.len) catch unreachable,
10478 .unit_debug_rnglists => {
10479 elf.dwarf.genUnitPadding(&fw) catch |err| switch (err) {
10480 error.WriteFailed => {
10481 elf.dwarf.updateUnitLength(slice, slice.len);
10482 @memset(fw.buffer, std.dwarf.RLE.end_of_list);
10483 return;
10484 },
10485 };
10486 elf.dwarf.updateUnitLength(slice, size);
10487 elf.dwarf.updateUnitLength(fw.buffer, fw.buffer.len);
10488 },
10489 }10711 }
10490 },10712 },
10491 .unit_frame, .unit_debug_info, .unit_debug_line => {10713 .unit_frame, .unit_debug_info, .unit_debug_line => {
...@@ -11037,7 +11259,11 @@ pub fn printNode(...@@ -11037,7 +11259,11 @@ pub fn printNode(
11037 if (nav.resolved) |resolved| try w.print("{f}, ", .{11259 if (nav.resolved) |resolved| try w.print("{f}, ", .{
11038 Type.fromInterned(resolved.type).fmt(.{ .zcu = zcu, .tid = tid }),11260 Type.fromInterned(resolved.type).fmt(.{ .zcu = zcu, .tid = tid }),
11039 });11261 });
11040 try w.print("{f})", .{nav.fqn.fmt(ip)});11262 try w.print("{f}", .{nav.fqn.fmt(ip)});
11263 if (nav.resolved) |resolved| try w.print(", {f}", .{
11264 Value.fromInterned(resolved.value).fmtValue(.{ .zcu = zcu, .tid = tid }),
11265 });
11266 try w.writeByte(')');
11041 },11267 },
11042 .func_frame_fde, .func_debug_info, .func_debug_line => |fi| {11268 .func_frame_fde, .func_debug_info, .func_debug_line => |fi| {
11043 const zcu = elf.base.comp.zcu.?;11269 const zcu = elf.base.comp.zcu.?;
src/main.zig+1-1
...@@ -5792,7 +5792,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8, environ_map...@@ -5792,7 +5792,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8, environ_map
5792 }5792 }
57935793
5794 var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .empty;5794 var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .empty;
5795 try Zcu.mapOldZirToNew(arena, old_zir, new_zir, &inst_map);5795 try Zcu.mapOldZirToNew(arena, &old_zir, &new_zir, &inst_map);
57965796
5797 var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer);5797 var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer);
5798 const stdout_bw = &stdout_writer.interface;5798 const stdout_bw = &stdout_writer.interface;
src/print_zir.zig+2-1
...@@ -2211,6 +2211,8 @@ const Writer = struct {...@@ -2211,6 +2211,8 @@ const Writer = struct {
2211 defer self.parent_decl_node = prev_parent_decl_node;2211 defer self.parent_decl_node = prev_parent_decl_node;
2212 self.parent_decl_node = decl.src_node;2212 self.parent_decl_node = decl.src_node;
22132213
2214 try stream.print(":{d}:{d} ", .{ decl.src_line + 1, decl.src_column + 1 });
2215
2214 if (decl.is_pub) try stream.writeAll("pub ");2216 if (decl.is_pub) try stream.writeAll("pub ");
2215 switch (decl.linkage) {2217 switch (decl.linkage) {
2216 .normal => {},2218 .normal => {},
...@@ -2224,7 +2226,6 @@ const Writer = struct {...@@ -2224,7 +2226,6 @@ const Writer = struct {
2224 try stream.print("{s} '{s}'", .{ @tagName(decl.kind), self.code.nullTerminatedString(decl.name) });2226 try stream.print("{s} '{s}'", .{ @tagName(decl.kind), self.code.nullTerminatedString(decl.name) });
2225 },2227 },
2226 }2228 }
2227 try stream.print(":{d}:{d}", .{ decl.src_line + 1, decl.src_column + 1 });
22282229
2229 const src_hash = self.code.getAssociatedSrcHash(inst).?;2230 const src_hash = self.code.getAssociatedSrcHash(inst).?;
2230 try stream.print(" hash({x})", .{&src_hash});2231 try stream.print(" hash({x})", .{&src_hash});
test/src/Debugger.zig+5-5
...@@ -629,7 +629,7 @@ pub fn addTests(db: *Debugger) void {...@@ -629,7 +629,7 @@ pub fn addTests(db: *Debugger) void {
629 \\(lldb) breakpoint delete --force 1629 \\(lldb) breakpoint delete --force 1
630 \\1 breakpoints deleted; 0 breakpoint locations disabled.630 \\1 breakpoints deleted; 0 breakpoint locations disabled.
631 },631 },
632 .{ .skip_new_linker = true },632 .{ .skip_new_linker = true }, // passes, but prints errors
633 );633 );
634 db.addLldbTest(634 db.addLldbTest(
635 "optionals",635 "optionals",
...@@ -868,7 +868,7 @@ pub fn addTests(db: *Debugger) void {...@@ -868,7 +868,7 @@ pub fn addTests(db: *Debugger) void {
868 \\(lldb) breakpoint delete --force 1868 \\(lldb) breakpoint delete --force 1
869 \\1 breakpoints deleted; 0 breakpoint locations disabled.869 \\1 breakpoints deleted; 0 breakpoint locations disabled.
870 },870 },
871 .{ .skip_new_linker = true },871 .{},
872 );872 );
873 db.addLldbTest(873 db.addLldbTest(
874 "if_blocks",874 "if_blocks",
...@@ -1946,7 +1946,7 @@ pub fn addTests(db: *Debugger) void {...@@ -1946,7 +1946,7 @@ pub fn addTests(db: *Debugger) void {
1946 \\ frame #1: inline_call`m1pfi(m1pai=89) at mod1.zig:23:151946 \\ frame #1: inline_call`m1pfi(m1pai=89) at mod1.zig:23:15
1947 \\ frame #2: inline_call`root0.main at root0.zig:41:151947 \\ frame #2: inline_call`root0.main at root0.zig:41:15
1948 },1948 },
1949 .{ .skip_new_linker = true },1949 .{},
1950 );1950 );
1951 db.addLldbTest(1951 db.addLldbTest(
1952 "link_object",1952 "link_object",
...@@ -2054,7 +2054,7 @@ pub fn addTests(db: *Debugger) void {...@@ -2054,7 +2054,7 @@ pub fn addTests(db: *Debugger) void {
2054 \\(lldb) breakpoint delete --force 12054 \\(lldb) breakpoint delete --force 1
2055 \\1 breakpoints deleted; 0 breakpoint locations disabled.2055 \\1 breakpoints deleted; 0 breakpoint locations disabled.
2056 },2056 },
2057 .{ .skip_new_linker = true },2057 .{},
2058 );2058 );
2059 db.addLldbTest(2059 db.addLldbTest(
2060 "multi_array_list",2060 "multi_array_list",
...@@ -2308,7 +2308,7 @@ pub fn addTests(db: *Debugger) void {...@@ -2308,7 +2308,7 @@ pub fn addTests(db: *Debugger) void {
2308 \\(lldb) breakpoint delete --force 12308 \\(lldb) breakpoint delete --force 1
2309 \\1 breakpoints deleted; 0 breakpoint locations disabled.2309 \\1 breakpoints deleted; 0 breakpoint locations disabled.
2310 },2310 },
2311 .{ .skip_new_linker = true },2311 .{},
2312 );2312 );
2313}2313}
23142314