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 {
27542754 if (zir_inst == .main_struct_inst) return .{ file, .root };
27552755
27562756 // Otherwise, make sure ZIR is loaded.
2757 const zir = file.zir.?;
2757 const zir = &file.zir.?;
27582758
27592759 const inst = zir.instructions.get(@backingInt(zir_inst));
27602760 const base_node: Ast.Node.Index = switch (inst.tag) {
......@@ -3045,7 +3045,7 @@ pub fn saveZirCache(
30453045 gpa: Allocator,
30463046 cache_file_writer: *Io.File.Writer,
30473047 stat: Io.File.Stat,
3048 zir: Zir,
3048 zir: *const Zir,
30493049) (Io.File.Writer.Error || Allocator.Error)!void {
30503050 const safety_buffer = if (data_has_safety_tag)
30513051 try gpa.alloc([8]u8, zir.instructions.len)
......@@ -3085,7 +3085,7 @@ pub fn saveZirCache(
30853085 };
30863086}
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 {
30893089 const header: Zoir.Header = .{
30903090 .nodes_len = @intCast(zoir.nodes.len),
30913091 .extra_len = @intCast(zoir.extra.len),
......@@ -3399,8 +3399,8 @@ pub fn flushRetryableFailures(zcu: *Zcu) !void {
33993399
34003400pub fn mapOldZirToNew(
34013401 gpa: Allocator,
3402 old_zir: Zir,
3403 new_zir: Zir,
3402 old_zir: *const Zir,
3403 new_zir: *const Zir,
34043404 inst_map: *std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index),
34053405) Allocator.Error!void {
34063406 // 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(
389389 // Discover all imports in the file. Imports of modules we ignore for now since we don't
390390 // know which module we're in, but imports of file paths might need us to queue up other
391391 // 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)];
393394 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);
395396 var import_i: u32 = 0;
396397 var extra_index = extra.end;
397398
398399 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);
400401 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
404405 if (active.pt.discoverImport(file.path, import_path)) |res| switch (res) {
405406 .module, .existing_file => {},
......@@ -652,7 +653,7 @@ pub fn updateFile(
652653 switch (file.getMode()) {
653654 .zig => {
654655 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) {
656657 error.OutOfMemory => |e| return e,
657658 else => log.warn("unable to write cached ZIR code for {f} to {f}{s}: {t}", .{
658659 file.path.fmt(comp), cache_directory, &hex_digest, err,
......@@ -661,7 +662,7 @@ pub fn updateFile(
661662 },
662663 .zon => {
663664 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| {
665666 log.warn("unable to write cached ZOIR code for {f} to {f}{s}: {t}", .{
666667 file.path.fmt(comp), cache_directory, &hex_digest, err,
667668 });
......@@ -694,12 +695,13 @@ pub fn updateFile(
694695
695696 switch (file.getMode()) {
696697 .zig => {
697 if (file.zir.?.hasCompileErrors()) {
698 const zir = &file.zir.?;
699 if (zir.hasCompileErrors()) {
698700 comp.mutex.lockUncancelable(io);
699701 defer comp.mutex.unlock(io);
700702 try zcu.failed_files.putNoClobber(gpa, file_index, null);
701703 }
702 if (file.zir.?.loweringFailed()) {
704 if (zir.loweringFailed()) {
703705 file.status = .astgen_failure;
704706 } else {
705707 file.status = .success;
......@@ -829,14 +831,14 @@ fn updateZirRefs(pt: Zcu.PerThread) (Io.Cancelable || Allocator.Error)!void {
829831 },
830832 }
831833 const old_zir = file.prev_zir orelse continue;
832 const new_zir = file.zir.?;
834 const new_zir = &file.zir.?;
833835 const gop = try updated_files.getOrPut(gpa, file_index);
834836 assert(!gop.found_existing);
835837 gop.value_ptr.* = .{
836838 .file = file,
837839 .inst_map = .{},
838840 };
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);
840842 }
841843
842844 if (updated_files.count() == 0)
......@@ -870,7 +872,7 @@ fn updateZirRefs(pt: Zcu.PerThread) (Io.Cancelable || Allocator.Error)!void {
870872 const old_tag = old_zir.instructions.items(.tag)[@backingInt(old_inst)];
871873 const old_data = old_zir.instructions.items(.data)[@backingInt(old_inst)];
872874
873 const new_zir = file.zir.?;
875 const new_zir = &file.zir.?;
874876 const new_data = new_zir.instructions.items(.data)[@backingInt(new_inst)];
875877
876878 debug_update_line_number: {
......@@ -2640,7 +2642,7 @@ fn computeAliveFiles(pt: Zcu.PerThread) Allocator.Error!bool {
26402642
26412643 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.?;
26442646 const imports_index = zir.extra[@backingInt(Zir.ExtraIndex.imports)];
26452647 if (imports_index == 0) continue; // this Zig file has no imports
26462648 const extra = zir.extraData(Zir.Inst.Imports, imports_index);
......@@ -2655,7 +2657,13 @@ fn computeAliveFiles(pt: Zcu.PerThread) Allocator.Error!bool {
26552657 // We've not necessarily generated builtin modules yet, so `doImport` could fail. Instead,
26562658 // create the module here. Then, since we know that `builtin.zig` doesn't have an error and
26572659 // 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 } };
26592667 continue;
26602668 }
26612669
......@@ -2754,14 +2762,20 @@ fn computeAliveFiles(pt: Zcu.PerThread) Allocator.Error!bool {
27542762/// up-to-date, setting a misc failure if updating it fails.
27552763/// Asserts that the imported `builtin.zig` has no ZIR errors, and that it has only one
27562764/// 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} {
27582769 const zcu = pt.zcu;
27592770 const comp = zcu.comp;
27602771 const gpa = comp.gpa;
27612772 const io = comp.io;
27622773
27632774 const gop = try zcu.builtin_modules.getOrPut(gpa, opts.hash());
2764 if (gop.found_existing) return; // the `File` is up-to-date
2775 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 };
27652779 errdefer _ = zcu.builtin_modules.pop();
27662780
27672781 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
28092823 try opts.populateFile(gpa, file);
28102824
28112825 assert(file.status == .success);
2812 assert(!file.zir.?.hasCompileErrors());
2826 const zir = &file.zir.?;
2827 assert(!zir.hasCompileErrors());
28132828 {
28142829 // 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)];
28162831 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);
28182833 assert(extra.data.imports_len == 1); // there is exactly one import
2819 const item = file.zir.?.extraData(Zir.Inst.Imports.Item, extra.end);
2820 const import_path = file.zir.?.nullTerminatedString(item.data.name);
2834 const item = zir.extraData(Zir.Inst.Imports.Item, extra.end);
2835 const import_path = zir.nullTerminatedString(item.data.name);
28212836 assert(mem.eql(u8, import_path, "std")); // the single import is of 'std'
28222837 }
28232838
......@@ -2826,6 +2841,10 @@ pub fn updateBuiltinModule(pt: Zcu.PerThread, opts: Builtin) Allocator.Error!voi
28262841 "unable to write '{f}': {s}",
28272842 .{ file.path.fmt(comp), @errorName(err) },
28282843 );
2844 return .{
2845 .file = file_index,
2846 .module_root = mod,
2847 };
28292848}
28302849
28312850pub fn embedFile(
......@@ -3137,7 +3156,7 @@ const ScanDeclIter = struct {
31373156 const gpa = comp.gpa;
31383157 const io = comp.io;
31393158 const file = namespace.fileScope(zcu);
3140 const zir = file.zir.?;
3159 const zir = &file.zir.?;
31413160 const ip = &zcu.intern_pool;
31423161
31433162 const decl = zir.getDeclaration(decl_inst);
......@@ -3572,11 +3591,11 @@ fn lockAndClearFileCompileError(pt: Zcu.PerThread, file_index: Zcu.File.Index, f
35723591 .astgen_failure => true,
35733592 .success => switch (file.getMode()) {
35743593 .zig => has_error: {
3575 const zir = file.zir orelse break :has_error false;
3594 const zir = &(file.zir orelse break :has_error false);
35763595 break :has_error zir.hasCompileErrors();
35773596 },
35783597 .zon => has_error: {
3579 const zoir = file.zoir orelse break :has_error false;
3598 const zoir = &(file.zoir orelse break :has_error false);
35803599 break :has_error zoir.hasCompileErrors();
35813600 },
35823601 },
src/codegen/x86_64/Emit.zig+18-13
......@@ -552,9 +552,9 @@ pub fn emitMir(emit: *Emit) Error!void {
552552 .pseudo_dbg_var_m,
553553 => switch (emit.debug_output) {
554554 inline .dwarf, .dwarf2 => |dwarf, tag| {
555 const DwarfLoc = switch (tag) {
556 .dwarf => link.File.Dwarf.Loc,
557 .dwarf2 => link.File.Dwarf2.Loc,
555 const DwarfLoc, const addr_loc = switch (tag) {
556 .dwarf => .{ link.File.Dwarf.Loc, "addr_reloc" },
557 .dwarf2 => .{ link.File.Dwarf2.Loc, "addrx_sym" },
558558 .eh_frame, .none => comptime unreachable,
559559 };
560560 var loc_buf: [2]DwarfLoc = undefined;
......@@ -597,16 +597,21 @@ pub fn emitMir(emit: *Emit) Error!void {
597597 .none => .{ .constu = 0 },
598598 .reg => |reg| .{ .breg = reg.dwarfNum() },
599599 .frame, .table, .rip_inst => unreachable,
600 .nav => |nav| .{ .addr_reloc = try codegen.genNavRef(
601 emit.bin_file,
602 emit.pt,
603 nav,
604 ) },
605 .uav => |uav| .{ .addr_reloc = try emit.bin_file.lowerUav(
606 emit.pt,
607 uav.val,
608 Type.fromInterned(uav.orig_ty).ptrAlignment(emit.pt.zcu),
609 ) },
600 .nav => |nav| @unionInit(
601 DwarfLoc,
602 addr_loc,
603 try codegen.genNavRef(emit.bin_file, emit.pt, nav),
604 ),
605 .uav => |uav| @unionInit(
606 DwarfLoc,
607 addr_loc,
608 try emit.bin_file.lowerUav(
609 emit.pt,
610 uav.val,
611 Type.fromInterned(uav.orig_ty)
612 .ptrAlignment(emit.pt.zcu),
613 ),
614 ),
610615 .lazy_sym, .extern_func => unreachable,
611616 };
612617 break :base &loc_buf[0];
src/codegen/x86_64/Mir.zig+1-1
......@@ -2009,7 +2009,7 @@ pub fn emit(
20092009 .column = func.lbrace_column,
20102010 .is_stmt = switch (debug_output) {
20112011 .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,
20132013 .eh_frame, .none => undefined,
20142014 },
20152015 },
src/link.zig+2-2
......@@ -755,8 +755,8 @@ pub const File = struct {
755755
756756 pub const DebugInfoOutput = union(enum) {
757757 dwarf: *Dwarf.WipNav,
758 eh_frame: *Dwarf2.WipNav,
759 dwarf2: *Dwarf2.WipNav.Debug,
758 eh_frame: *Dwarf2.WipFunc,
759 dwarf2: *Dwarf2.WipFunc.Debug,
760760 none,
761761 };
762762 pub const UpdateDebugInfoError = Dwarf.UpdateError;
src/link/Dwarf2.zig+2096-1020
......@@ -10,9 +10,10 @@ consts: std.ArrayList(Const),
1010globals: std.array_hash_map.Auto(InternPool.Nav.Index, Global),
1111funcs: std.array_hash_map.Auto(InternPool.Nav.Index, Func),
1212decls: 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
1515debug_abbrev: Abbrev,
16debug_addr: Addr,
1617frame: Frame,
1718debug_info: Info,
1819debug_line: Line,
......@@ -81,6 +82,7 @@ pub const Unit = struct {
8182 ui: Unit.Index,
8283 zfi: Zcu.File.Index,
8384 ) std.mem.Allocator.Error!struct { DirIndex, FileIndex } {
85 assert(unit.alive);
8486 try unit.dirs.ensureUnusedCapacity(gpa, 1);
8587 try unit.files.ensureUnusedCapacity(gpa, 1);
8688 const dir_gop = unit.dirs.getOrPutAssumeCapacity(ui);
......@@ -154,6 +156,12 @@ pub const Decl = struct {
154156 return &dwarf.decls.values()[@backingInt(di)];
155157 }
156158 };
159
160 const Instance = union(enum) {
161 none,
162 @"const": InternPool.Index,
163 global: InternPool.Nav.Index,
164 };
157165};
158166
159167pub const Frame = struct {
......@@ -175,6 +183,29 @@ pub const Abbrev = struct {
175183 set: std.enums.EnumSet(AbbrevCode),
176184};
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
178209pub const Info = struct {};
179210
180211pub const Line = struct {
......@@ -192,8 +223,8 @@ pub const Line = struct {
192223
193224pub const Str = struct {
194225 ni: link.MappedFile.Node.Index.Optional,
195 offset: usize,
196 map: std.HashMapUnmanaged(usize, void, Context, std.hash_map.default_max_load_percentage),
226 end: usize,
227 map: std.array_hash_map.Custom(usize, void, Context, true),
197228
198229 fn get(
199230 s: *Str,
......@@ -210,21 +241,21 @@ pub const Str = struct {
210241 .{ .slice = slice },
211242 );
212243 if (!gop.found_existing) {
213 gop.key_ptr.* = s.offset;
214 try ni.ensureMinimumSize(gpa, mf, s.offset + str.len + 1);
244 gop.key_ptr.* = s.end;
245 try ni.ensureMinimumSize(gpa, mf, s.end + str.len + 1);
215246 const slice_mut = ni.slice(mf);
216 @memcpy(slice_mut[s.offset..][0..str.len], str);
217 s.offset += str.len;
218 slice_mut[s.offset] = 0;
219 s.offset += 1;
247 @memcpy(slice_mut[s.end..][0..str.len], str);
248 s.end += str.len;
249 slice_mut[s.end] = 0;
250 s.end += 1;
220251 }
221252 return gop.key_ptr.*;
222253 }
223254
224255 const Context = struct {
225256 slice: []const u8,
226 pub fn hash(context: Context, offset: usize) u64 {
227 return std.hash.Wyhash.hash(0, std.mem.sliceTo(context.slice[offset..], 0));
257 pub fn hash(context: Context, offset: usize) u32 {
258 return @truncate(std.hash.Wyhash.hash(0, std.mem.sliceTo(context.slice[offset..], 0)));
228259 }
229260 pub fn eql(_: Context, lhs_offset: usize, rhs_offset: usize) bool {
230261 return lhs_offset == rhs_offset;
......@@ -233,10 +264,10 @@ pub const Str = struct {
233264
234265 const Adapter = struct {
235266 slice: []const u8,
236 pub fn hash(_: Adapter, key: []const u8) u64 {
237 return std.hash.Wyhash.hash(0, key);
267 pub fn hash(_: Adapter, key: []const u8) u32 {
268 return @truncate(std.hash.Wyhash.hash(0, key));
238269 }
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 {
240271 return std.mem.startsWith(u8, adapter.slice[rhs_offset..], key) and
241272 adapter.slice[rhs_offset + key.len] == 0;
242273 }
......@@ -244,21 +275,60 @@ pub const Str = struct {
244275};
245276
246277pub const Rnglists = struct {
247 fn offsetsTableOffset(dwarf: *Dwarf) usize {
278 fn tableOffset(dwarf: *Dwarf) usize {
248279 return dwarf.unitLengthSize() + 2 + 1 + 1 + 4;
249280 }
281
282 pub fn size(dwarf: *Dwarf, ui: Unit.Index) usize {
283 return ui.get(dwarf).debug_rnglists_end + 1;
284 }
250285};
251286
252287pub const StrOffsets = struct {
253288 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 }
255322};
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
259326pub const Loc = union(enum) {
260327 empty,
261 addr_reloc: link.File.SymbolId,
328 addr_sym: struct {
329 si: link.File.SymbolId,
330 offset: usize = 0,
331 },
262332 deref: *const Loc,
263333 constu: u64,
264334 consts: i64,
......@@ -277,6 +347,8 @@ pub const Loc = union(enum) {
277347 node: link.MappedFile.Node.Index,
278348 offset: i65 = 0,
279349 },
350 addrx_sym: link.File.SymbolId,
351 constx_sym: link.File.SymbolId,
280352 wasm_ext: union(enum) {
281353 local: u32,
282354 global: u32,
......@@ -319,11 +391,11 @@ pub const Loc = union(enum) {
319391 };
320392 switch (loc) {
321393 .empty => {},
322 .addr_reloc => |si| {
394 .addr_sym => |sym| {
323395 try w.writeByte(DW.OP.addr);
324396 switch (writer) {
325397 .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),
327399 }
328400 },
329401 .deref => |addr| {
......@@ -442,6 +514,14 @@ pub const Loc = union(enum) {
442514 }
443515 try w.writeSleb128(implicit_pointer.offset);
444516 },
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 },
445525 .wasm_ext => |wasm_ext| {
446526 try w.writeByte(DW.OP.WASM_location);
447527 switch (wasm_ext) {
......@@ -490,33 +570,33 @@ pub const Cfa = union(enum) {
490570 const RegOff = struct { reg: u32, off: i64 };
491571 const RegExpr = struct { reg: u32, expr: Loc };
492572
493 fn write(cfa: Cfa, wip_nav: *WipNav) link.EmitError!void {
494 const df_nw = &wip_nav.fde_writer;
573 fn write(cfa: Cfa, wip_func: *WipFunc) link.EmitError!void {
574 const df_nw = &wip_func.fde_writer;
495575 const df_w = &df_nw.interface;
496576 switch (cfa) {
497577 .nop => try df_w.writeByte(DW.CFA.nop),
498578 .advance_loc => |loc| {
499579 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);
501581 if (delta == 0) {} else if (std.math.cast(u6, delta)) |small_delta|
502582 try df_w.writeByte(@as(u8, DW.CFA.advance_loc) + small_delta)
503583 else if (std.math.cast(u8, delta)) |ubyte_delta|
504584 try df_w.writeAll(&.{ DW.CFA.advance_loc1, ubyte_delta })
505585 else if (std.math.cast(u16, delta)) |uhalf_delta| {
506586 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);
508588 } else if (std.math.cast(u32, delta)) |uword_delta| {
509589 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);
511591 }
512 wip_nav.cfi.loc = loc;
592 wip_func.cfi.loc = loc;
513593 },
514594 .offset, .rel_offset => |reg_off| {
515595 const factored_off = @divExact(reg_off.off - switch (cfa) {
516596 else => unreachable,
517597 .offset => 0,
518 .rel_offset => wip_nav.cfi.cfa.off,
519 }, wip_nav.dwarf.frame.header.data_alignment_factor);
598 .rel_offset => wip_func.cfi.cfa.off,
599 }, wip_func.dwarf.frame.header.data_alignment_factor);
520600 if (std.math.cast(u63, factored_off)) |unsigned_off| {
521601 if (std.math.cast(u6, reg_off.reg)) |small_reg| {
522602 try df_w.writeByte(@as(u8, DW.CFA.offset) + small_reg);
......@@ -558,21 +638,21 @@ pub const Cfa = union(enum) {
558638 const reg_off: RegOff = switch (cfa) {
559639 else => unreachable,
560640 .def_cfa => |reg_off| reg_off,
561 .def_cfa_register => |reg| .{ .reg = reg, .off = wip_nav.cfi.cfa.off },
562 .def_cfa_offset => |off| .{ .reg = wip_nav.cfi.cfa.reg, .off = off },
641 .def_cfa_register => |reg| .{ .reg = reg, .off = wip_func.cfi.cfa.off },
642 .def_cfa_offset => |off| .{ .reg = wip_func.cfi.cfa.reg, .off = off },
563643 .adjust_cfa_offset => |off| .{
564 .reg = wip_nav.cfi.cfa.reg,
565 .off = wip_nav.cfi.cfa.off + off,
644 .reg = wip_func.cfi.cfa.reg,
645 .off = wip_func.cfi.cfa.off + off,
566646 },
567647 };
568 const changed_reg = reg_off.reg != wip_nav.cfi.cfa.reg;
648 const changed_reg = reg_off.reg != wip_func.cfi.cfa.reg;
569649 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) {
571651 if (changed_reg) {
572652 try df_w.writeByte(DW.CFA.def_cfa_register);
573653 try df_w.writeUleb128(reg_off.reg);
574654 }
575 } else if (switch (wip_nav.dwarf.frame.header.data_alignment_factor) {
655 } else if (switch (wip_func.dwarf.frame.header.data_alignment_factor) {
576656 0 => unreachable,
577657 1 => unsigned_off != null,
578658 else => |data_alignment_factor| @rem(reg_off.off, data_alignment_factor) != 0,
......@@ -584,23 +664,23 @@ pub const Cfa = union(enum) {
584664 try df_w.writeByte(if (changed_reg) DW.CFA.def_cfa_sf else DW.CFA.def_cfa_offset_sf);
585665 if (changed_reg) try df_w.writeUleb128(reg_off.reg);
586666 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),
588668 );
589669 }
590 wip_nav.cfi.cfa = reg_off;
670 wip_func.cfi.cfa = reg_off;
591671 },
592672 .def_cfa_expression => |expr| {
593673 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);
595675 },
596676 .expression => |reg_expr| {
597677 try df_w.writeByte(DW.CFA.expression);
598678 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);
600680 },
601681 .val_offset => |reg_off| {
602682 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);
604684 if (std.math.cast(u63, factored_off)) |unsigned_off| {
605685 try df_w.writeByte(DW.CFA.val_offset);
606686 try df_w.writeUleb128(reg_off.reg);
......@@ -614,14 +694,14 @@ pub const Cfa = union(enum) {
614694 .val_expression => |reg_expr| {
615695 try df_w.writeByte(DW.CFA.val_expression);
616696 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);
618698 },
619699 .escape => |bytes| try df_w.writeAll(bytes),
620700 }
621701 }
622702};
623703
624pub const WipNav = struct {
704pub const WipFunc = struct {
625705 dwarf: *Dwarf,
626706 unit: Unit.Index,
627707 func: InternPool.Index,
......@@ -635,44 +715,50 @@ pub const WipNav = struct {
635715 frame_func_length: struct { offset: usize, size: AddressSize },
636716
637717 pub const Debug = struct {
638 wip_nav: WipNav,
718 wip_func: WipFunc,
639719 pt: Zcu.PerThread,
640 any_children: bool,
720 is_empty: bool,
721 empty_abbrev_code: AbbrevCode,
641722 blocks: std.ArrayList(struct {
642 abbrev_code: u32,
643 low_pc_off: usize,
644 high_pc: u32,
723 abbrev_code_offset: usize,
724 low_pc: usize,
725 high_pc_offset: usize,
645726 }),
646727 info_writer: link.MappedFile.Node.Writer,
647728 info_func_length_offset: usize,
648729 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
650737 pub fn deinit(debug: *Debug) void {
651738 const gpa = debug.pt.zcu.gpa;
652739 debug.line_writer.deinit();
653740 debug.info_writer.deinit();
654741 debug.blocks.deinit(gpa);
655 debug.wip_nav.deinit();
742 debug.wip_func.deinit();
656743 debug.* = undefined;
657744 }
658745
659746 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);
661748 }
662749
663 pub fn startFuncDebugInfo(debug: *Debug) link.Error!void {
664 assert(debug.wip_nav.func != .none);
665 debug.startFuncDebugInfoInner() catch |err| switch (err) {
666 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
750 pub fn startDebugInfo(debug: *Debug) link.Error!void {
751 debug.startDebugInfoInner() catch |err| switch (err) {
667752 else => |e| return e,
753 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
668754 };
669755 }
670 fn startFuncDebugInfoInner(debug: *Debug) link.EmitError!void {
671 const dwarf = debug.wip_nav.dwarf;
756 fn startDebugInfoInner(debug: *Debug) link.EmitError!void {
757 const dwarf = debug.wip_func.dwarf;
672758 const pt = debug.pt;
673759 const zcu = pt.zcu;
674760 const ip = &zcu.intern_pool;
675 const func = zcu.funcInfo(debug.wip_nav.func);
761 const func = zcu.funcInfo(debug.wip_func.func);
676762 const nav = ip.getNav(func.owner_nav);
677763 const func_type = ip.indexToKey(func.ty).func_type;
678764 const inst_info = nav.srcInst(ip).resolveFull(ip).?;
......@@ -681,42 +767,52 @@ pub const WipNav = struct {
681767 const decl = zf.zir.?.getDeclaration(inst_info.inst);
682768 const di_nw = &debug.info_writer;
683769 const di_w = &di_nw.interface;
684 try dwarf.abbrevCode(di_nw, .decl_func);
685 try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr(switch (func.generic_owner) {
686 .none => nav,
770 const parent_ty: Type = .fromInterned(ip.namespacePtr(switch (func.generic_owner) {
687771 else => |generic_owner| ip.getNav(zcu.funcInfo(generic_owner).owner_nav),
688 }.analysis.?.namespace).owner_type));
689 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
690 try di_w.writeUleb128(decl.src_column + 1);
691 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
692 try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip));
693 try dwarf.strp(&dwarf.debug_str, di_nw, switch (decl.linkage) {
772 .none => nav,
773 }.analysis.?.namespace).owner_type);
774 if (func.generic_owner != .none or parent_ty.getCaptures(zcu).len > 0) {
775 debug.empty_abbrev_code = .decl_instance_empty_func;
776 try dwarf.abbrevCode(di_nw, .decl_instance_func);
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) {
694789 .normal => nav.fqn,
695790 .@"extern", .@"export" => nav.name,
696791 }.toSlice(ip));
697792 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);
699794 debug.info_func_length_offset = di_w.end;
700795 try di_w.writeInt(u32, undefined, dwarf.endian);
701796 try di_w.writeUleb128(
702797 target_info.minFunctionAlignment(target).max(nav.resolved.?.@"align").toByteUnits().?,
703798 );
704 try di_w.writeByte(@intFromBool(decl.linkage != .normal));
705 try di_w.writeByte(@intFromBool(Type.fromInterned(func_type.return_type).isNoReturn(zcu)));
799 try di_w.writeAll(&.{
800 @intFromBool(decl.linkage != .normal),
801 @intFromBool(Type.fromInterned(func_type.return_type).isNoReturn(zcu)),
802 });
706803 }
707804
708805 pub fn startDebugLine(debug: *Debug) link.Error!void {
709 assert(debug.wip_nav.func != .none);
710806 debug.startDebugLineInner() catch |err| switch (err) {
711 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),
712807 else => |e| return e,
808 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
713809 };
714810 }
715811 fn startDebugLineInner(debug: *Debug) link.EmitError!void {
716 const dwarf = debug.wip_nav.dwarf;
812 const dwarf = debug.wip_func.dwarf;
717813 const zcu = debug.pt.zcu;
718814 const ip = &zcu.intern_pool;
719 const func = zcu.funcInfo(debug.wip_nav.func);
815 const func = zcu.funcInfo(debug.wip_func.func);
720816 const inst_info = ip.getNav(func.owner_nav).srcInst(ip).resolveFull(ip).?;
721817 const zf = zcu.fileByIndex(inst_info.file);
722818 const decl = zf.zir.?.getDeclaration(inst_info.inst);
......@@ -735,10 +831,10 @@ pub const WipNav = struct {
735831 } else {
736832 try dl_w.writeUleb128(1 + @backingInt(dwarf.address_size));
737833 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.?);
741 _, const fi = try unit.get(dwarf).getFile(zcu.gpa, unit, inst_info.file);
836 const ui = dwarf.getUnit(zf.mod.?);
837 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, inst_info.file);
742838 try dl_w.writeByte(DW.LNS.set_file);
743839 try dl_w.writeUleb128(@backingInt(fi));
744840
......@@ -749,28 +845,32 @@ pub const WipNav = struct {
749845 }
750846 }
751847
752 pub fn finishFunc(debug: *Debug, func_length: u64) link.Error!void {
753 assert(debug.wip_nav.func != .none);
848 pub fn finish(debug: *Debug, func_length: u64) link.Error!void {
754849 const di_nw = &debug.info_writer;
755850 debug.finishDebugInfo(func_length) catch |err| switch (err) {
756 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(di_nw),
757851 else => |e| return e,
852 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(di_nw),
758853 };
759854 debug.finishDebugLine() catch |err| switch (err) {
760 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(di_nw),
761855 else => |e| return e,
856 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(di_nw),
762857 };
763858 }
764859 fn finishDebugInfo(debug: *Debug, func_length: u64) link.EmitError!void {
765 const dwarf = debug.wip_nav.dwarf;
766 const di_w = &debug.info_writer.interface;
860 const dwarf = debug.wip_func.dwarf;
861 const di_nw = &debug.info_writer;
862 const di_w = &di_nw.interface;
767863 std.mem.writeInt(
768864 u32,
769865 di_w.buffered()[debug.info_func_length_offset..][0..4],
770866 @intCast(func_length),
771867 dwarf.endian,
772868 );
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));
774874 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());
775875 }
776876 fn finishDebugLine(debug: *Debug) link.EmitError!void {
......@@ -787,8 +887,8 @@ pub const WipNav = struct {
787887 loc: Loc,
788888 ) link.Error!void {
789889 return debug.genLocalVarDebugInfoInner(tag, opt_name, ty, loc) catch |err| switch (err) {
790 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
791890 else => |e| e,
891 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
792892 };
793893 }
794894 fn genLocalVarDebugInfoInner(
......@@ -798,17 +898,16 @@ pub const WipNav = struct {
798898 ty: Type,
799899 loc: Loc,
800900 ) link.EmitError!void {
801 assert(debug.wip_nav.func != .none);
802 const dwarf = debug.wip_nav.dwarf;
901 const dwarf = debug.wip_func.dwarf;
803902 const di_nw = &debug.info_writer;
804903 try dwarf.abbrevCode(di_nw, switch (tag) {
805904 .arg => if (opt_name) |_| .arg else .unnamed_arg,
806905 .local_var => if (opt_name) |_| .local_var else unreachable,
807906 });
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);
809908 try dwarf.refType(debug.pt, di_nw, ty);
810909 try dwarf.exprLoc(di_nw, loc);
811 debug.any_children = true;
910 debug.is_empty = false;
812911 }
813912
814913 pub const LocalConstTag = enum { comptime_arg, local_const };
......@@ -819,8 +918,8 @@ pub const WipNav = struct {
819918 val: Value,
820919 ) link.Error!void {
821920 return debug.genLocalConstDebugInfoInner(tag, opt_name, val) catch |err| switch (err) {
822 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
823921 else => |e| e,
922 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
824923 };
825924 }
826925 fn genLocalConstDebugInfoInner(
......@@ -829,8 +928,7 @@ pub const WipNav = struct {
829928 opt_name: ?[]const u8,
830929 val: Value,
831930 ) link.EmitError!void {
832 assert(debug.wip_nav.func != .none);
833 const dwarf = debug.wip_nav.dwarf;
931 const dwarf = debug.wip_func.dwarf;
834932 const pt = debug.pt;
835933 const zcu = debug.pt.zcu;
836934 const ty = val.typeOf(zcu);
......@@ -858,23 +956,22 @@ pub const WipNav = struct {
858956 .fully_comptime => .local_const_fully_comptime,
859957 } else unreachable,
860958 });
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);
862960 try dwarf.refType(pt, di_nw, ty);
863961 if (ty_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, val);
864962 if (ty_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, val);
865 debug.any_children = true;
963 debug.is_empty = false;
866964 }
867965
868966 pub fn genVarArgsDebugInfo(debug: *Debug) link.Error!void {
869967 return debug.genVarArgsDebugInfoInner() catch |err| switch (err) {
870 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
871968 else => |e| e,
969 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
872970 };
873971 }
874972 fn genVarArgsDebugInfoInner(debug: *Debug) link.EmitError!void {
875 assert(debug.wip_nav.func != .none);
876 try debug.wip_nav.dwarf.abbrevCode(&debug.info_writer, .is_var_args);
877 debug.any_children = true;
973 try debug.wip_func.dwarf.abbrevCode(&debug.info_writer, .is_var_args);
974 debug.is_empty = false;
878975 }
879976
880977 pub fn advanceLineAndPc(
......@@ -884,7 +981,7 @@ pub const WipNav = struct {
884981 end: bool,
885982 ) link.Error!void {
886983 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),
888985 };
889986 }
890987 fn advanceLineAndPcInner(
......@@ -895,7 +992,7 @@ pub const WipNav = struct {
895992 ) std.Io.Writer.Error!void {
896993 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;
899996 assert(header.maximum_operations_per_instruction == 1);
900997 const delta_op: u64 = 0;
901998
......@@ -939,7 +1036,7 @@ pub const WipNav = struct {
9391036
9401037 pub fn setColumn(debug: *Debug, column: u32) link.Error!void {
9411038 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),
9431040 };
9441041 }
9451042 fn setColumnInner(debug: *Debug, column: u32) std.Io.Writer.Error!void {
......@@ -950,7 +1047,7 @@ pub const WipNav = struct {
9501047
9511048 pub fn negateStmt(debug: *Debug) link.Error!void {
9521049 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),
9541051 };
9551052 }
9561053 fn negateStmtInner(debug: *Debug) std.Io.Writer.Error!void {
......@@ -959,7 +1056,7 @@ pub const WipNav = struct {
9591056
9601057 pub fn setPrologueEnd(debug: *Debug) link.Error!void {
9611058 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),
9631060 };
9641061 }
9651062 fn setPrologueEndInner(debug: *Debug) std.Io.Writer.Error!void {
......@@ -968,151 +1065,155 @@ pub const WipNav = struct {
9681065
9691066 pub fn setEpilogueBegin(debug: *Debug) link.Error!void {
9701067 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),
9721069 };
9731070 }
9741071 fn setEpilogueBeginInner(debug: *Debug) std.Io.Writer.Error!void {
9751072 try debug.line_writer.interface.writeByte(DW.LNS.set_epilogue_begin);
9761073 }
9771074
978 pub fn enterBlock(debug: *Debug, code_off: usize) link.Error!void {
979 return debug.enterBlockInner(code_off) catch |err| switch (err) {
980 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
1075 pub fn enterBlock(debug: *Debug, code_offset: usize) link.Error!void {
1076 return debug.enterBlockInner(code_offset) catch |err| switch (err) {
9811077 else => |e| e,
1078 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
9821079 };
9831080 }
984 fn enterBlockInner(debug: *Debug, code_off: usize) link.EmitError!void {
985 const dwarf = debug.wip_nav.dwarf;
1081 fn enterBlockInner(debug: *Debug, code_offset: usize) link.EmitError!void {
1082 const dwarf = debug.wip_func.dwarf;
9861083 const block = try debug.blocks.addOne(dwarf.lf.comp.gpa);
9871084
9881085 const di_nw = &debug.info_writer;
9891086 const di_w = &di_nw.interface;
990 block.abbrev_code = @intCast(di_w.end);
1087 block.abbrev_code_offset = di_w.end;
9911088 try dwarf.abbrevCode(di_nw, .block);
992 block.low_pc_off = code_off;
993 try dwarf.addrSym(di_nw, debug.wip_nav.func_si, code_off);
994 block.high_pc = @intCast(di_w.end);
1089 block.low_pc = code_offset;
1090 try dwarf.addrSym(di_nw, debug.wip_func.func_si, code_offset);
1091 block.high_pc_offset = di_w.end;
9951092 try di_w.writeInt(u32, 0, dwarf.endian);
996 debug.any_children = false;
1093 debug.is_empty = true;
9971094 }
9981095
999 pub fn leaveBlock(debug: *Debug, code_off: usize) link.Error!void {
1000 return debug.leaveBlockInner(code_off) catch |err| switch (err) {
1001 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
1096 pub fn leaveBlock(debug: *Debug, code_offset: usize) link.Error!void {
1097 return debug.leaveBlockInner(code_offset) catch |err| switch (err) {
10021098 else => |e| e,
1099 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
10031100 };
10041101 }
1005 fn leaveBlockInner(debug: *Debug, code_off: usize) link.EmitError!void {
1006 const dwarf = debug.wip_nav.dwarf;
1007 const block_size = comptime uleb128Size(@backingInt(AbbrevCode.block));
1102 fn leaveBlockInner(debug: *Debug, code_offset: usize) link.EmitError!void {
1103 const dwarf = debug.wip_func.dwarf;
10081104 const block = debug.blocks.pop().?;
10091105
10101106 const di_nw = &debug.info_writer;
10111107 const di_w = &di_nw.interface;
1012 if (debug.any_children)
1013 try di_w.writeUleb128(@backingInt(AbbrevCode.null))
1014 else
1015 std.leb.writeUnsignedFixed(
1016 block_size,
1017 di_w.buffered()[block.abbrev_code..][0..block_size],
1018 @intCast(try dwarf.refAbbrevCode(di_nw.mf, .empty_block)),
1019 );
1108 const block_size = comptime uleb128Size(@backingInt(AbbrevCode.block));
1109 if (debug.is_empty) std.leb.writeUnsignedFixed(
1110 block_size,
1111 di_w.buffered()[block.abbrev_code_offset..][0..block_size],
1112 @intCast(try dwarf.refAbbrevCode(di_nw.mf, .empty_block)),
1113 ) else try di_w.writeUleb128(@backingInt(AbbrevCode.null));
10201114 std.mem.writeInt(
10211115 u32,
1022 di_nw.interface.buffered()[block.high_pc..][0..4],
1023 @intCast(code_off - block.low_pc_off),
1116 di_nw.interface.buffered()[block.high_pc_offset..][0..4],
1117 @intCast(code_offset - block.low_pc),
10241118 dwarf.endian,
10251119 );
1026 debug.any_children = true;
1120 debug.is_empty = false;
10271121 }
10281122
10291123 pub fn enterInlineFunc(
10301124 debug: *Debug,
10311125 func: InternPool.Index,
1032 code_off: usize,
1126 code_offset: usize,
10331127 line: u32,
10341128 column: u32,
10351129 ) link.Error!void {
1036 return debug.enterInlineFuncInner(func, code_off, line, column) catch |err| switch (err) {
1037 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
1130 return debug.enterInlineFuncInner(
1131 func,
1132 code_offset,
1133 line,
1134 column,
1135 ) catch |err| switch (err) {
10381136 else => |e| e,
1137 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
10391138 };
10401139 }
10411140 fn enterInlineFuncInner(
10421141 debug: *Debug,
10431142 func: InternPool.Index,
1044 code_off: usize,
1143 code_offset: usize,
10451144 line: u32,
10461145 column: u32,
10471146 ) link.EmitError!void {
1048 const dwarf = debug.wip_nav.dwarf;
1049 const zcu = debug.pt.zcu;
1147 const dwarf = debug.wip_func.dwarf;
1148 const pt = debug.pt;
1149 const zcu = pt.zcu;
10501150 const block = try debug.blocks.addOne(zcu.gpa);
10511151
10521152 const di_nw = &debug.info_writer;
10531153 const di_w = &di_nw.interface;
1054 block.abbrev_code = @intCast(di_w.end);
1154 block.abbrev_code_offset = di_w.end;
10551155 try dwarf.abbrevCode(di_nw, .inlined_func);
1056 try debug.refFunc(func);
1156 try dwarf.refConst(pt, di_nw, .fromInterned(func));
10571157 try di_w.writeUleb128((if (zcu.comp.config.incremental)
10581158 0
10591159 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);
10611161 try di_w.writeUleb128(column + 1);
1062 block.low_pc_off = code_off;
1063 try dwarf.addrSym(di_nw, debug.wip_nav.func_si, code_off);
1064 block.high_pc = @intCast(di_w.end);
1162 block.low_pc = code_offset;
1163 try dwarf.addrSym(di_nw, debug.wip_func.func_si, code_offset);
1164 block.high_pc_offset = di_w.end;
10651165 try di_w.writeInt(u32, 0, dwarf.endian);
10661166 try debug.setInlineFunc(func);
1067 debug.any_children = false;
1167 debug.is_empty = true;
10681168 }
10691169
1070 pub fn leaveInlineFunc(debug: *Debug, func: InternPool.Index, code_off: usize) link.Error!void {
1071 return debug.leaveInlineFuncInner(func, code_off) catch |err| switch (err) {
1072 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
1170 pub fn leaveInlineFunc(
1171 debug: *Debug,
1172 func: InternPool.Index,
1173 code_offset: usize,
1174 ) link.Error!void {
1175 return debug.leaveInlineFuncInner(func, code_offset) catch |err| switch (err) {
10731176 else => |e| e,
1177 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
10741178 };
10751179 }
10761180 fn leaveInlineFuncInner(
10771181 debug: *Debug,
10781182 func: InternPool.Index,
1079 code_off: usize,
1183 code_offset: usize,
10801184 ) link.EmitError!void {
1081 const dwarf = debug.wip_nav.dwarf;
1082 const inlined_func_size = comptime uleb128Size(@backingInt(AbbrevCode.inlined_func));
1185 const dwarf = debug.wip_func.dwarf;
10831186 const block = debug.blocks.pop().?;
10841187
10851188 const di_nw = &debug.info_writer;
10861189 const di_w = &di_nw.interface;
1087 if (debug.any_children)
1088 try di_w.writeUleb128(@backingInt(AbbrevCode.null))
1089 else
1090 std.leb.writeUnsignedFixed(
1091 inlined_func_size,
1092 di_w.buffered()[block.abbrev_code..][0..inlined_func_size],
1093 @intCast(try dwarf.refAbbrevCode(di_nw.mf, .empty_inlined_func)),
1094 );
1190 const inlined_func_size = comptime uleb128Size(@backingInt(AbbrevCode.inlined_func));
1191 if (debug.is_empty) std.leb.writeUnsignedFixed(
1192 inlined_func_size,
1193 di_w.buffered()[block.abbrev_code_offset..][0..inlined_func_size],
1194 @intCast(try dwarf.refAbbrevCode(di_nw.mf, .empty_inlined_func)),
1195 ) else try di_w.writeUleb128(@backingInt(AbbrevCode.null));
10951196 std.mem.writeInt(
10961197 u32,
1097 di_w.buffered()[block.high_pc..][0..4],
1098 @intCast(code_off - block.low_pc_off),
1198 di_w.buffered()[block.high_pc_offset..][0..4],
1199 @intCast(code_offset - block.low_pc),
10991200 dwarf.endian,
11001201 );
11011202 try debug.setInlineFunc(func);
1102 debug.any_children = true;
1203 debug.is_empty = false;
11031204 }
11041205
11051206 pub fn setInlineFunc(debug: *Debug, func: InternPool.Index) link.Error!void {
11061207 return debug.setInlineFuncInner(func) catch |err| switch (err) {
1107 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),
11081208 else => |e| e,
1209 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
11091210 };
11101211 }
11111212 fn setInlineFuncInner(debug: *Debug, func: InternPool.Index) link.EmitError!void {
11121213 const zcu = debug.pt.zcu;
11131214 const ip = &zcu.intern_pool;
1114 const dwarf = debug.wip_nav.dwarf;
1115 if (debug.wip_nav.func == func) return;
1215 const dwarf = debug.wip_func.dwarf;
1216 if (debug.wip_func.func == func) return;
11161217
11171218 const dl_nw = &debug.line_writer;
11181219 const dl_w = &dl_nw.interface;
......@@ -1126,7 +1227,7 @@ pub const WipNav = struct {
11261227 return;
11271228 }
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;
11301231 const old_inst_info = ip.getNav(old_owner_nav).srcInst(ip).resolveFull(ip).?;
11311232 const old_zf = zcu.fileByIndex(old_inst_info.file);
11321233 const new_inst_info = ip.getNav(new_owner_nav).srcInst(ip).resolveFull(ip).?;
......@@ -1134,7 +1235,7 @@ pub const WipNav = struct {
11341235 if (old_inst_info.file != new_inst_info.file) {
11351236 const new_ui = dwarf.getUnit(new_zf.mod.?);
11361237 _, 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
11391240 try dl_w.writeByte(DW.LNS.set_file);
11401241 try dl_w.writeUleb128(@backingInt(new_fi));
......@@ -1147,38 +1248,27 @@ pub const WipNav = struct {
11471248 try dl_w.writeSleb128(new_src_line - old_src_line);
11481249 }
11491250
1150 debug.wip_nav.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 );
1251 debug.wip_func.func = func;
11611252 }
11621253 };
11631254
1164 pub fn deinit(wip_nav: *WipNav) void {
1165 wip_nav.fde_writer.deinit();
1166 wip_nav.* = undefined;
1255 pub fn deinit(wip_func: *WipFunc) void {
1256 wip_func.fde_writer.deinit();
1257 wip_func.* = undefined;
11671258 }
11681259
1169 pub fn genDebugFrameHeader(wip_nav: *WipNav) link.Error!void {
1170 wip_nav.genDebugFrameHeaderInner() catch |err| switch (err) {
1171 error.WriteFailed => return wip_nav.dwarf.reportWriteError(&wip_nav.fde_writer),
1260 pub fn genDebugFrameHeader(wip_func: *WipFunc) link.Error!void {
1261 wip_func.genDebugFrameHeaderInner() catch |err| switch (err) {
11721262 else => |e| return e,
1263 error.WriteFailed => return wip_func.dwarf.reportWriteError(&wip_func.fde_writer),
11731264 };
11741265 }
1175 fn genDebugFrameHeaderInner(wip_nav: *WipNav) link.EmitError!void {
1176 assert(wip_nav.func != .none);
1177 const dwarf = wip_nav.dwarf;
1178 const df_nw = &wip_nav.fde_writer;
1266 fn genDebugFrameHeaderInner(wip_func: *WipFunc) link.EmitError!void {
1267 const dwarf = wip_func.dwarf;
1268 const df_nw = &wip_func.fde_writer;
11791269 const df_w = &df_nw.interface;
11801270 try dwarf.genUnitLength(df_w);
1181 switch (wip_nav.frame_format) {
1271 switch (wip_func.frame_format) {
11821272 .eh_frame => {
11831273 try df_w.writeInt(u32, undefined, dwarf.endian);
11841274 {
......@@ -1187,51 +1277,50 @@ pub const WipNav = struct {
11871277 if (dwarf.lf.cast(.elf2)) |elf| try elf.addReloc(
11881278 @bitCast(df_nw.ni),
11891279 offset,
1190 wip_nav.func_si,
1280 wip_func.func_si,
11911281 0,
11921282 .rel32(elf),
11931283 ) else unreachable;
11941284 }
1195 wip_nav.frame_func_length = .{ .offset = df_w.end, .size = .@"32" };
1285 wip_func.frame_func_length = .{ .offset = df_w.end, .size = .@"32" };
11961286 try df_w.writeInt(u32, undefined, dwarf.endian);
11971287 try df_w.writeUleb128(0);
11981288 },
11991289 .debug_frame => {
1200 try dwarf.secOffset(df_nw, wip_nav.unit.get(dwarf).cie_ni.unwrap().?, 0);
1201 try dwarf.addrSym(df_nw, wip_nav.func_si, 0);
1202 wip_nav.frame_func_length = .{ .offset = df_w.end, .size = dwarf.address_size };
1290 try dwarf.secOffset(df_nw, wip_func.unit.get(dwarf).cie_ni.unwrap().?, 0);
1291 try dwarf.addrSym(df_nw, wip_func.func_si, 0);
1292 wip_func.frame_func_length = .{ .offset = df_w.end, .size = dwarf.address_size };
12031293 try dwarf.addrPlaceholder(df_w);
12041294 },
12051295 }
12061296 }
12071297
1208 pub fn genDebugFrame(wip_nav: *WipNav, loc: u32, cfa: Cfa) link.Error!void {
1209 return wip_nav.genDebugFrameInner(loc, cfa) catch |err| switch (err) {
1210 error.WriteFailed => return wip_nav.dwarf.reportWriteError(&wip_nav.fde_writer),
1298 pub fn genDebugFrame(wip_func: *WipFunc, loc: u32, cfa: Cfa) link.Error!void {
1299 return wip_func.genDebugFrameInner(loc, cfa) catch |err| switch (err) {
12111300 else => |e| return e,
1301 error.WriteFailed => return wip_func.dwarf.reportWriteError(&wip_func.fde_writer),
12121302 };
12131303 }
1214 fn genDebugFrameInner(wip_nav: *WipNav, loc: u32, cfa: Cfa) link.EmitError!void {
1215 assert(wip_nav.func != .none);
1304 fn genDebugFrameInner(wip_func: *WipFunc, loc: u32, cfa: Cfa) link.EmitError!void {
12161305 const loc_cfa: Cfa = .{ .advance_loc = loc };
1217 try loc_cfa.write(wip_nav);
1218 try cfa.write(wip_nav);
1306 try loc_cfa.write(wip_func);
1307 try cfa.write(wip_func);
12191308 }
12201309
1221 pub fn finishDebugFrameFde(wip_nav: *WipNav, func_length: u64) void {
1222 const dwarf = wip_nav.dwarf;
1223 const df_w = &wip_nav.fde_writer.interface;
1224 switch (wip_nav.frame_func_length.size) {
1310 pub fn finishDebugFrameFde(wip_func: *WipFunc, func_length: u64) void {
1311 const dwarf = wip_func.dwarf;
1312 const df_w = &wip_func.fde_writer.interface;
1313 switch (wip_func.frame_func_length.size) {
12251314 _ => unreachable,
12261315 .@"32" => std.mem.writeInt(
12271316 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],
12291318 @intCast(func_length),
12301319 dwarf.endian,
12311320 ),
12321321 .@"64" => std.mem.writeInt(
12331322 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],
12351324 func_length,
12361325 dwarf.endian,
12371326 ),
......@@ -1258,13 +1347,18 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf {
12581347 .globals = .empty,
12591348 .funcs = .empty,
12601349 .decls = .empty,
1261 .pending_decl = .{ .di = undefined, .instance_val = .none },
1350 .pending_decl = .{ .di = undefined, .instance = .none },
12621351
12631352 .debug_abbrev = .{
12641353 .ni = .none,
12651354 .end = 0,
12661355 .set = .empty,
12671356 },
1357 .debug_addr = .{
1358 .ni = .none,
1359 .pending_index = 0,
1360 .map = .empty,
1361 },
12681362 .frame = .{
12691363 .header = if (target.cpu.arch == .x86_64 and target.ofmt == .elf) header: {
12701364 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
......@@ -1308,18 +1402,19 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf {
13081402 },
13091403 .debug_line_str = .{
13101404 .ni = .none,
1311 .offset = 0,
1405 .end = 0,
13121406 .map = .empty,
13131407 },
13141408 .debug_rnglists = .{},
13151409 .debug_str = .{
13161410 .ni = .none,
1317 .offset = 0,
1411 .end = 0,
13181412 .map = .empty,
13191413 },
13201414 .debug_str_offsets = .{
13211415 .ni = .none,
1322 .offset = 0,
1416 .pending_index = 0,
1417 .map = .empty,
13231418 },
13241419 };
13251420}
......@@ -1333,8 +1428,10 @@ pub fn deinit(dwarf: *Dwarf) void {
13331428 dwarf.globals.deinit(gpa);
13341429 dwarf.funcs.deinit(gpa);
13351430 dwarf.decls.deinit(gpa);
1431 dwarf.debug_addr.map.deinit(gpa);
13361432 dwarf.debug_line_str.map.deinit(gpa);
13371433 dwarf.debug_str.map.deinit(gpa);
1434 dwarf.debug_str_offsets.map.deinit(gpa);
13381435 dwarf.* = undefined;
13391436}
13401437
......@@ -1389,8 +1486,7 @@ pub fn getConst(dwarf: *Dwarf, pt: Zcu.PerThread, val: Value) link.Error!link.Co
13891486
13901487pub fn getGlobal(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Global.Index {
13911488 const comp = dwarf.lf.comp;
1392 const gpa = comp.gpa;
1393 const global_gop = try dwarf.globals.getOrPut(gpa, nav);
1489 const global_gop = try dwarf.globals.getOrPut(comp.gpa, nav);
13941490 if (!global_gop.found_existing) global_gop.value_ptr.* = .{
13951491 .debug_info_ni = .none,
13961492 };
......@@ -1398,25 +1494,26 @@ pub fn getGlobal(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Global.Ind
13981494 if (global_gop.value_ptr.debug_info_ni != .none) return gi;
13991495 const mod = comp.zcu.?.navFileScope(nav).mod.?;
14001496 assert(!mod.strip);
1401 const elf = dwarf.lf.cast(.elf2).?;
1402 try elf.nodes.ensureUnusedCapacity(gpa, 1);
1403 try elf.dwarf_globals.append(gpa, .{
1404 .debug_info_first_target_reloc = .none,
1405 .debug_info_first_node_reloc = .none,
1406 .debug_info_first_symbol_reloc = .none,
1407 });
1408 const unit = dwarf.getUnit(mod).get(dwarf);
1409 global_gop.value_ptr.debug_info_ni = .wrap(elf.addNodeAssumeCapacity(
1410 unit.debug_info_ni.unwrap().?.addFloatingChild(gpa, &elf.mf, .{
1411 .enable_next_moved = true,
1412 }) catch |err| switch (err) {
1413 else => |e| return e,
1414 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{
1415 elf.mf.io_err.?,
1416 }),
1417 },
1418 .{ .global_debug_info = gi },
1419 ));
1497 if (dwarf.lf.cast(.elf2)) |elf| {
1498 try elf.nodes.ensureUnusedCapacity(comp.gpa, 1);
1499 try elf.dwarf_globals.append(comp.gpa, .{
1500 .debug_info_first_target_reloc = .none,
1501 .debug_info_first_node_reloc = .none,
1502 .debug_info_first_symbol_reloc = .none,
1503 });
1504 const unit = dwarf.getUnit(mod).get(dwarf);
1505 global_gop.value_ptr.debug_info_ni = .wrap(elf.addNodeAssumeCapacity(
1506 unit.debug_info_ni.unwrap().?.addFloatingChild(comp.gpa, &elf.mf, .{
1507 .enable_next_moved = true,
1508 }) catch |err| switch (err) {
1509 else => |e| return e,
1510 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{
1511 elf.mf.io_err.?,
1512 }),
1513 },
1514 .{ .global_debug_info = gi },
1515 ));
1516 } else unreachable;
14201517 return gi;
14211518}
14221519pub 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 {
14361533 const fi: Func.Index = @fromBackingInt(@intCast(func_gop.index));
14371534 if (func_gop.value_ptr.debug_info_ni != .none) return fi;
14381535 const mod = comp.zcu.?.navFileScope(nav).mod.?;
1439 const elf = dwarf.lf.cast(.elf2).?;
1440 try elf.nodes.ensureUnusedCapacity(gpa, 1);
1441 try elf.dwarf_funcs.append(gpa, .{
1442 .frame_fde_first_symbol_reloc = .none,
1443 .frame_fde_first_node_reloc = .none,
1444 .debug_info_first_target_reloc = .none,
1445 .debug_info_first_symbol_reloc = .none,
1446 .debug_info_first_node_reloc = .none,
1447 .debug_line_first_symbol_reloc = .none,
1448 .debug_line_first_node_reloc = .none,
1449 });
1450 if (mod.strip) return fi;
1451 const unit = dwarf.getUnit(mod).get(dwarf);
1452 func_gop.value_ptr.debug_info_ni = .wrap(elf.addNodeAssumeCapacity(
1453 unit.debug_info_ni.unwrap().?.addFloatingChild(gpa, &elf.mf, .{
1454 .enable_next_moved = true,
1455 }) catch |err| switch (err) {
1456 else => |e| return e,
1457 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{
1458 elf.mf.io_err.?,
1459 }),
1460 },
1461 .{ .func_debug_info = fi },
1462 ));
1536 if (dwarf.lf.cast(.elf2)) |elf| {
1537 try elf.nodes.ensureUnusedCapacity(gpa, 1);
1538 try elf.dwarf_funcs.append(gpa, .{
1539 .frame_fde_first_symbol_reloc = .none,
1540 .frame_fde_first_node_reloc = .none,
1541 .debug_info_first_target_reloc = .none,
1542 .debug_info_first_symbol_reloc = .none,
1543 .debug_info_first_node_reloc = .none,
1544 .debug_line_first_symbol_reloc = .none,
1545 .debug_line_first_node_reloc = .none,
1546 });
1547 if (mod.strip) return fi;
1548 const unit = dwarf.getUnit(mod).get(dwarf);
1549 func_gop.value_ptr.debug_info_ni = .wrap(elf.addNodeAssumeCapacity(
1550 unit.debug_info_ni.unwrap().?.addFloatingChild(gpa, &elf.mf, .{
1551 .enable_next_moved = true,
1552 }) catch |err| switch (err) {
1553 else => |e| return e,
1554 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{
1555 elf.mf.io_err.?,
1556 }),
1557 },
1558 .{ .func_debug_info = fi },
1559 ));
1560 } else unreachable;
14631561 return fi;
14641562}
14651563pub fn getFuncIfExists(dwarf: *Dwarf, nav: InternPool.Nav.Index) ?Func.Index {
14661564 return @fromBackingInt(@intCast(dwarf.funcs.getIndex(nav) orelse return null));
14671565}
14681566
1469fn getDeclInst(dwarf: *Dwarf, val: InternPool.Index) ?InternPool.TrackedInst.Index {
1470 const ip = &dwarf.lf.comp.zcu.?.intern_pool;
1471 switch (ip.indexToKey(val)) {
1567fn getConstDeclInst(dwarf: *Dwarf, @"const": InternPool.Index) union(enum) {
1568 @"const": InternPool.Index,
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")) {
14721574 else => unreachable,
14731575 .struct_type, .union_type, .enum_type, .opaque_type => |container, tag| switch (container) {
14741576 .declared => |declared| switch (declared.captures.owned.len) {
1475 0 => return null,
1476 else => switch (tag) {
1577 0 => return .{ .@"const" = @"const" },
1578 else => return .{ .src_inst = src_inst: switch (tag) {
14771579 else => unreachable,
14781580 .struct_type => {
1479 const loaded_struct = ip.loadStructType(val);
1480 return ip.getNav(loaded_struct.name_nav.unwrap() orelse
1481 return loaded_struct.zir_index).srcInst(ip);
1581 const loaded_struct = ip.loadStructType(@"const");
1582 break :src_inst ip.getNav(loaded_struct.name_nav.unwrap() orelse
1583 break :src_inst loaded_struct.zir_index).srcInst(ip);
14821584 },
14831585 .union_type => {
1484 const loaded_union = ip.loadUnionType(val);
1485 return ip.getNav(loaded_union.name_nav.unwrap() orelse
1486 return loaded_union.zir_index).srcInst(ip);
1586 const loaded_union = ip.loadUnionType(@"const");
1587 break :src_inst ip.getNav(loaded_union.name_nav.unwrap() orelse
1588 break :src_inst loaded_union.zir_index).srcInst(ip);
14871589 },
14881590 .enum_type => {
1489 const loaded_enum = ip.loadEnumType(val);
1490 return ip.getNav(loaded_enum.name_nav.unwrap() orelse
1491 return loaded_enum.zir_index.unwrap().?).srcInst(ip);
1591 const loaded_enum = ip.loadEnumType(@"const");
1592 break :src_inst ip.getNav(loaded_enum.name_nav.unwrap() orelse
1593 break :src_inst loaded_enum.zir_index.unwrap().?).srcInst(ip);
14921594 },
14931595 .opaque_type => {
1494 const loaded_opaque = ip.loadOpaqueType(val);
1495 return ip.getNav(loaded_opaque.name_nav.unwrap() orelse
1496 return loaded_opaque.zir_index).srcInst(ip);
1596 const loaded_opaque = ip.loadOpaqueType(@"const");
1597 break :src_inst ip.getNav(loaded_opaque.name_nav.unwrap() orelse
1598 break :src_inst loaded_opaque.zir_index).srcInst(ip);
14971599 },
1498 },
1600 } },
14991601 },
15001602 .reified => |reified| {
15011603 assert(reified.zir_index.resolve(ip).? != .main_struct_inst);
1502 return reified.zir_index;
1604 return .{ .src_inst = reified.zir_index };
15031605 },
15041606 .generated_union_tag => unreachable,
15051607 },
1506 .func => |func| return ip.getNav(switch (func.generic_owner) {
1507 .none => func.owner_nav,
1508 else => |generic_owner| ip.indexToKey(generic_owner).func.owner_nav,
1509 }).srcInst(ip),
1608 .func => |func| switch (func.generic_owner) {
1609 else => |generic_owner| return .{ .@"const" = generic_owner },
1610 .none => {
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 }),
15101633 }
15111634}
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(
15131644 dwarf: *Dwarf,
15141645 pt: Zcu.PerThread,
1515 instance_val: InternPool.Index,
1646 inst: InternPool.TrackedInst.Index,
1647 instance: Decl.Instance,
15161648) link.Error!link.MappedFile.Node.Index {
1517 assert(dwarf.pending_decl.instance_val == .none);
15181649 const comp = dwarf.lf.comp;
15191650 const gpa = comp.gpa;
15201651 const zcu = pt.zcu;
15211652 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 };
15261653 const decl_gop = try dwarf.decls.getOrPut(gpa, inst);
15271654 if (!decl_gop.found_existing) decl_gop.value_ptr.* = .{
15281655 .debug_info_ni = .none,
15291656 };
15301657 const di: Decl.Index = @fromBackingInt(@intCast(decl_gop.index));
15311658 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 };
1533 const elf = dwarf.lf.cast(.elf2).?;
1534 try elf.nodes.ensureUnusedCapacity(gpa, 1);
1535 try elf.dwarf_decls.putNoClobber(gpa, di, .{
1536 .debug_info_first_target_reloc = .none,
1537 .debug_info_first_node_reloc = .none,
1538 });
1539 const unit = dwarf.getUnit(zcu.fileByIndex(di.srcInst(dwarf).resolveFile(ip)).mod.?).get(dwarf);
1540 const debug_info_ni = elf.addNodeAssumeCapacity(
1541 unit.debug_info_ni.unwrap().?.addFloatingChild(gpa, &elf.mf, .{
1542 .enable_next_moved = true,
1543 }) catch |err| switch (err) {
1544 else => |e| return e,
1545 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{
1546 elf.mf.io_err.?,
1547 }),
1548 },
1549 .{ .decl_debug_info = di },
1550 );
1659 dwarf.pending_decl = .{ .di = di, .instance = instance };
1660 const debug_info_ni = if (dwarf.lf.cast(.elf2)) |elf| debug_info_ni: {
1661 try elf.nodes.ensureUnusedCapacity(gpa, 1);
1662 try elf.dwarf_decls.putNoClobber(gpa, di, .{
1663 .debug_info_first_target_reloc = .none,
1664 .debug_info_first_node_reloc = .none,
1665 });
1666 const unit = dwarf.getUnit(zcu.fileByIndex(di.srcInst(dwarf).resolveFile(ip)).mod.?).get(dwarf);
1667 const debug_info_ni = elf.addNodeAssumeCapacity(
1668 unit.debug_info_ni.unwrap().?.addFloatingChild(gpa, &elf.mf, .{
1669 .enable_next_moved = true,
1670 }) catch |err| switch (err) {
1671 else => |e| return e,
1672 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{
1673 elf.mf.io_err.?,
1674 }),
1675 },
1676 .{ .decl_debug_info = di },
1677 );
1678 break :debug_info_ni debug_info_ni;
1679 } else unreachable;
15511680 decl_gop.value_ptr.debug_info_ni = .wrap(debug_info_ni);
15521681 return debug_info_ni;
15531682}
......@@ -1561,7 +1690,7 @@ pub fn unitLengthSize(dwarf: *Dwarf) usize {
15611690 .@"64" => 4 + 8,
15621691 };
15631692}
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 {
15651694 switch (dwarf.format) {
15661695 .@"32" => try w.writeInt(u32, undefined, dwarf.endian),
15671696 .@"64" => {
......@@ -1582,6 +1711,24 @@ pub fn genUnitPadding(dwarf: *Dwarf, w: *std.Io.Writer) std.Io.Writer.Error!void
15821711 try w.writeInt(u16, 0, dwarf.endian);
15831712}
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
15851732pub const EhFrameHdr = extern struct {
15861733 version: u8,
15871734 eh_frame_ptr_enc: std.dwarf.EH.PE,
......@@ -1637,11 +1784,7 @@ pub fn genDebugFrameCie(
16371784 const Register = @import("../codegen/x86_64/bits.zig").Register;
16381785 switch (format) {
16391786 .eh_frame => try df_w.writeAll("zR\x00"),
1640 .debug_frame => {
1641 try df_w.writeAll("\x00");
1642 try df_w.writeByte(@backingInt(dwarf.address_size));
1643 try df_w.writeByte(0);
1644 },
1787 .debug_frame => try df_w.writeAll("\x00" ++ .{ @backingInt(dwarf.address_size), 0 }),
16451788 }
16461789 try df_w.writeUleb128(dwarf.frame.header.code_alignment_factor);
16471790 try df_w.writeSleb128(dwarf.frame.header.data_alignment_factor);
......@@ -1688,28 +1831,29 @@ pub fn genDebugInfoHeader(
16881831 if (!unit.alive) return dwarf.genUnitPadding(dih_w);
16891832 try dwarf.genUnitLength(dih_w);
16901833 try dih_w.writeInt(u16, 5, dwarf.endian);
1691 try dih_w.writeByte(DW.UT.compile);
1692 try dih_w.writeByte(@backingInt(dwarf.address_size));
1834 try dih_w.writeAll(&.{ DW.UT.compile, @backingInt(dwarf.address_size) });
16931835 try dwarf.secOffset(dih_nw, dwarf.debug_abbrev.ni.unwrap().?, 0);
16941836 const compile_unit_offset = dih_w.end;
16951837 try dwarf.abbrevCode(dih_nw, .compile_unit);
16961838 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);
17021839 try dwarf.secOffset(
17031840 dih_nw,
17041841 dwarf.getUnit(zcu.root_mod).get(dwarf).debug_info_header_ni.unwrap().?,
17051842 compile_unit_offset,
17061843 );
17071844 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);
17091853 try dih_w.writeUleb128(0);
17101854 const module_offset = dih_w.end;
17111855 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);
17131857 try dih_w.writeUleb128(0);
17141858 try dwarf.genModuleDependency(
17151859 dih_nw,
......@@ -1735,7 +1879,7 @@ fn genModuleDependency(
17351879 const dep_unit = dwarf.getUnit(dep).get(dwarf);
17361880 if (!dep_unit.alive) return;
17371881 try dwarf.abbrevCode(di_nw, .module_dependency);
1738 try dwarf.strp(&dwarf.debug_str, di_nw, name);
1882 try dwarf.strx(di_nw, name);
17391883 try dwarf.secOffset(di_nw, dep_unit.debug_info_header_ni.unwrap().?, module_offset);
17401884}
17411885
......@@ -1779,8 +1923,7 @@ pub fn genDebugLineHeader(
17791923 const dlh_w = &dlh_nw.interface;
17801924 try dwarf.genUnitLength(dlh_w);
17811925 try dlh_w.writeInt(u16, 5, dwarf.endian);
1782 try dlh_w.writeByte(@backingInt(dwarf.address_size));
1783 try dlh_w.writeByte(0);
1926 try dlh_w.writeAll(&.{ @backingInt(dwarf.address_size), 0 });
17841927 const header_length_offset = dlh_w.end;
17851928 switch (dwarf.format) {
17861929 .@"32" => try dlh_w.writeInt(u32, undefined, dwarf.endian),
......@@ -1852,11 +1995,7 @@ pub fn genDebugLineHeader(
18521995 }
18531996 try dlh_w.writeInt(i64, @truncate(zf.stat.mtime.nanoseconds), dwarf.endian);
18541997 try dlh_w.writeInt(u64, zf.stat.size, dwarf.endian);
1855 try dwarf.strp(
1856 &dwarf.debug_line_str,
1857 dlh_nw,
1858 if (zf.is_builtin) zf.source.? else "",
1859 );
1998 try dwarf.strp(&dwarf.debug_line_str, dlh_nw, if (zf.is_builtin) zf.source.? else "");
18601999 }
18612000 switch (dwarf.format) {
18622001 .@"32" => std.mem.writeInt(
......@@ -1915,10 +2054,9 @@ pub fn genDebugRnglistsHeader(
19152054 const drh_w = &drh_nw.interface;
19162055 try dwarf.genUnitLength(drh_w);
19172056 try drh_w.writeInt(u16, 5, dwarf.endian);
1918 try drh_w.writeByte(@backingInt(dwarf.address_size));
1919 try drh_w.writeByte(0);
2057 try drh_w.writeAll(&.{ @backingInt(dwarf.address_size), 0 });
19202058 try drh_w.writeInt(u32, 1, dwarf.endian);
1921 assert(drh_w.end == Rnglists.offsetsTableOffset(dwarf));
2059 assert(drh_w.end == Rnglists.tableOffset(dwarf));
19222060 switch (dwarf.format) {
19232061 .@"32" => try drh_w.writeInt(u32, 4, dwarf.endian),
19242062 .@"64" => try drh_w.writeInt(u64, 8, dwarf.endian),
......@@ -1927,7 +2065,7 @@ pub fn genDebugRnglistsHeader(
19272065 try drh_w.writeByte(DW.RLE.end_of_list);
19282066}
19292067
1930pub fn genDebugRnglists(
2068pub fn genDebugRnglistsRange(
19312069 dwarf: *Dwarf,
19322070 unit: *Unit,
19332071 dr_nw: *link.MappedFile.Node.Writer,
......@@ -1936,74 +2074,396 @@ pub fn genDebugRnglists(
19362074) link.EmitError!void {
19372075 const dr_w = &dr_nw.interface;
19382076 dr_w.end = unit.debug_rnglists_end;
1939 try dr_w.writeByte(DW.RLE.start_length);
1940 try dwarf.addrSym(dr_nw, func_si, 0);
2077 try dr_w.writeByte(DW.RLE.startx_length);
2078 try dwarf.addrxSym(dr_w, func_si);
19412079 try dr_w.writeUleb128(func_length);
19422080 unit.debug_rnglists_end = dr_w.end;
19432081 try dr_w.writeByte(DW.RLE.end_of_list);
19442082}
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(
19472295 dwarf: *Dwarf,
19482296 pt: Zcu.PerThread,
1949 nav_index: InternPool.Nav.Index,
2297 global: InternPool.Nav.Index,
19502298) link.Error!void {
19512299 const zcu = pt.zcu;
19522300 const ip = &zcu.intern_pool;
1953 const nav = ip.getNav(nav_index);
1954 log.debug("updateComptimeNav({f})", .{nav.fqn.fmt(ip)});
2301 const nav = ip.getNav(global);
2302 log.debug("updateComptimeGlobal({f})", .{nav.fqn.fmt(ip)});
19552303 const inst_info = nav.srcInst(ip).resolveFull(ip).?;
19562304 const nav_val: Value = .fromInterned(nav.resolved.?.value);
1957 const zf = zcu.fileByIndex(inst_info.file);
1958 const decl = zf.zir.?.getDeclaration(inst_info.inst);
2305 const decl = zcu.fileByIndex(inst_info.file).zir.?.getDeclaration(inst_info.inst);
19592306 switch (decl.kind) {
19602307 .unnamed_test, .@"test", .decltest => return,
19612308 .@"comptime", .@"const", .@"var" => {},
19622309 }
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),
19642339 .struct_type => {
19652340 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()) {
19672342 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
1968 break :done;
1969 }
1970 return;
2343 } else try dwarf.genComptimeGlobal(pt, global, &decl);
19712344 },
19722345 .enum_type => {
19732346 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()) {
19752348 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
1976 break :done;
1977 }
1978 return;
2349 } else try dwarf.genComptimeGlobal(pt, global, &decl);
19792350 },
19802351 .union_type => {
19812352 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()) {
19832354 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
1984 break :done;
1985 }
1986 return;
2355 } else try dwarf.genComptimeGlobal(pt, global, &decl);
19872356 },
19882357 .opaque_type => {
19892358 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()) {
19912360 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
1992 break :done;
1993 }
1994 return;
2361 } else try dwarf.genComptimeGlobal(pt, global, &decl);
19952362 },
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) {
19972365 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
1998 break :done;
1999 } else return,
2000
2001 else => return,
2002
2003 // memoization, not values
2004 .memoized_call => unreachable,
2366 } else try dwarf.genComptimeGlobal(pt, global, &decl),
2367 .memoized_call => unreachable, // not a value
2368 }
2369}
2370fn genComptimeGlobal(
2371 dwarf: *Dwarf,
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 },
20052465 }
2006 try dwarf.const_pool.flushPending(pt, dwarf.constPoolUser());
2466 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());
20072467}
20082468
20092469pub fn addConst(
......@@ -2041,9 +2501,11 @@ pub fn addConst(
20412501 const name_gi = try dwarf.getGlobal(name_nav);
20422502 break :debug_info_ni name_gi.get(dwarf).debug_info_ni.unwrap().?;
20432503 }
2044 break :debug_info_ni try addConstNode(dwarf.lf, dwarf.getUnit(zcu.fileByIndex(
2504 const mod = zcu.fileByIndex(
20452505 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);
20472509 },
20482510 }.toOptional(),
20492511 });
......@@ -2068,17 +2530,17 @@ fn updateConstInner(
20682530 dwarf: *Dwarf,
20692531 pt: Zcu.PerThread,
20702532 di_nw: *link.MappedFile.Node.Writer,
2071 val: InternPool.Index,
2533 @"const": InternPool.Index,
20722534) link.EmitError!void {
20732535 const zcu = pt.zcu;
20742536 const ip = &zcu.intern_pool;
20752537 const di_w = &di_nw.interface;
2076 switch (ip.indexToKey(val)) {
2538 switch (ip.indexToKey(@"const")) {
20772539 .int_type => |int_type| {
2078 const ty: Type = .fromInterned(val);
2540 const ty: Type = .fromInterned(@"const");
20792541 try dwarf.abbrevCode(di_nw, .numeric_type);
20802542 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}", .{
20822544 ty.fmt(pt),
20832545 }) catch unreachable);
20842546 try di_w.writeByte(switch (int_type.signedness) {
......@@ -2091,56 +2553,54 @@ fn updateConstInner(
20912553 },
20922554 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
20932555 .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)});
20952557 defer zcu.gpa.free(name);
20962558 try dwarf.abbrevCode(di_nw, switch (ptr_type.sentinel) {
2097 .none => switch (ptr_type.flags.alignment) {
2098 .none => .ptr_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 },
2559 .none => .ptr_type,
2560 else => .ptr_sentinel_type,
21052561 });
2106 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2562 try dwarf.strx(di_nw, name);
21072563 switch (ptr_type.sentinel) {
21082564 .none => {},
21092565 else => |sentinel| try dwarf.blockConst(pt, di_nw, .fromInterned(sentinel)),
21102566 }
2111 if (ptr_type.flags.alignment.toByteUnits()) |a| try di_w.writeUleb128(a);
21122567 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(
2114 di_nw,
2115 di_nw.ni,
2116 di_w.end + dwarf.secOffsetSize(),
2117 );
2568 if (ptr_type.flags.alignment.toByteUnits()) |a| {
2569 const type_offset = di_w.end;
2570 try dwarf.secOffsetPlaceholder(di_w);
2571 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
2572 try dwarf.abbrevCode(di_nw, .is_aligned);
2573 try di_w.writeUleb128(a);
2574 }
21182575 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);
21192579 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 );
21252580 }
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 }
21272587 try dwarf.refType(pt, di_nw, .fromInterned(ptr_type.child));
21282588 },
21292589 .slice => {
2130 const ty: Type = .fromInterned(val);
2590 const ty: Type = .fromInterned(@"const");
21312591 const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)});
21322592 defer zcu.gpa.free(name);
21332593 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);
21352595 try di_w.writeUleb128(ty.abiSize(zcu));
21362596 try di_w.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);
21372597 try dwarf.abbrevCode(di_nw, .generated_field);
2138 try dwarf.strp(&dwarf.debug_str, di_nw, "ptr");
2598 try dwarf.strx(di_nw, "ptr");
21392599 const ptr_field_ty = ty.slicePtrFieldType(zcu);
21402600 try dwarf.refType(pt, di_nw, ptr_field_ty);
21412601 try di_w.writeUleb128(0);
21422602 try dwarf.abbrevCode(di_nw, .generated_field);
2143 try dwarf.strp(&dwarf.debug_str, di_nw, "len");
2603 try dwarf.strx(di_nw, "len");
21442604 const len_field_ty: Type = .usize;
21452605 try dwarf.refType(pt, di_nw, len_field_ty);
21462606 try di_w.writeUleb128(len_field_ty.abiAlignment(zcu).forward(ptr_field_ty.abiSize(zcu)));
......@@ -2148,13 +2608,13 @@ fn updateConstInner(
21482608 },
21492609 },
21502610 .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)});
21522612 defer zcu.gpa.free(name);
21532613 try dwarf.abbrevCode(
21542614 di_nw,
21552615 if (array_type.sentinel == .none) .array_type else .array_sentinel_type,
21562616 );
2157 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2617 try dwarf.strx(di_nw, name);
21582618 if (array_type.sentinel != .none)
21592619 try dwarf.blockConst(pt, di_nw, .fromInterned(array_type.sentinel));
21602620 try dwarf.refType(pt, di_nw, .fromInterned(array_type.child));
......@@ -2164,10 +2624,10 @@ fn updateConstInner(
21642624 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
21652625 },
21662626 .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)});
21682628 defer zcu.gpa.free(name);
21692629 try dwarf.abbrevCode(di_nw, .vector_type);
2170 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2630 try dwarf.strx(di_nw, name);
21712631 try dwarf.refType(pt, di_nw, .fromInterned(vector_type.child));
21722632 try dwarf.abbrevCode(di_nw, .array_len);
21732633 try dwarf.refType(pt, di_nw, .usize);
......@@ -2175,28 +2635,30 @@ fn updateConstInner(
21752635 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
21762636 },
21772637 .opt_type => |opt_child_type_index| {
2178 const opt_ty: Type = .fromInterned(val);
2638 const opt_ty: Type = .fromInterned(@"const");
21792639 const opt_child_ty: Type = .fromInterned(opt_child_type_index);
21802640 const opt_repr = optRepr(opt_child_ty, zcu);
21812641 const name = try zcu.gpa.print("{f}", .{opt_ty.fmt(pt)});
21822642 defer zcu.gpa.free(name);
21832643 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);
21852645 try di_w.writeUleb128(opt_ty.abiSize(zcu));
21862646 try di_w.writeUleb128(opt_ty.abiAlignment(zcu).toByteUnits().?);
21872647 switch (opt_repr) {
21882648 .opv_null => {
21892649 try dwarf.abbrevCode(di_nw, .generated_field);
2190 try dwarf.strp(&dwarf.debug_str, di_nw, "null");
2650 try dwarf.strx(di_nw, "null");
21912651 try dwarf.refType(pt, di_nw, .null);
21922652 try di_w.writeUleb128(0);
21932653 },
21942654 .unpacked, .error_set, .pointer => {
21952655 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);
21972658 {
2659 try dwarf.secOffsetFinish(di_nw, discr_offset, di_nw.ni, di_w.end);
21982660 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");
22002662 switch (opt_repr) {
22012663 .opv_null => unreachable,
22022664 .unpacked => {
......@@ -2207,7 +2669,10 @@ fn updateConstInner(
22072669 0);
22082670 },
22092671 .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 ));
22112676 try di_w.writeUleb128(0);
22122677 },
22132678 .pointer => {
......@@ -2221,7 +2686,7 @@ fn updateConstInner(
22212686 try di_w.writeByte(0);
22222687 {
22232688 try dwarf.abbrevCode(di_nw, .generated_field);
2224 try dwarf.strp(&dwarf.debug_str, di_nw, "null");
2689 try dwarf.strx(di_nw, "null");
22252690 try dwarf.refType(pt, di_nw, .null);
22262691 try di_w.writeUleb128(0);
22272692 }
......@@ -2230,7 +2695,7 @@ fn updateConstInner(
22302695 try dwarf.abbrevCode(di_nw, .tagged_union_default_field);
22312696 {
22322697 try dwarf.abbrevCode(di_nw, .generated_field);
2233 try dwarf.strp(&dwarf.debug_str, di_nw, "?");
2698 try dwarf.strx(di_nw, "?");
22342699 try dwarf.refType(pt, di_nw, opt_child_ty);
22352700 try di_w.writeUleb128(0);
22362701 }
......@@ -2243,7 +2708,7 @@ fn updateConstInner(
22432708 },
22442709 .anyframe_type => unreachable,
22452710 .error_union_type => |error_union_type| {
2246 const eu_ty: Type = .fromInterned(val);
2711 const eu_ty: Type = .fromInterned(@"const");
22472712 const eu_error_set_ty: Type = .fromInterned(error_union_type.error_set_type);
22482713 const eu_payload_ty: Type = .fromInterned(error_union_type.payload_type);
22492714 const eu_error_set_offset, const eu_payload_offset = switch (error_union_type.payload_type) {
......@@ -2257,7 +2722,7 @@ fn updateConstInner(
22572722 defer zcu.gpa.free(name);
22582723
22592724 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);
22612726 if (error_union_type.error_set_type != .generic_poison_type and
22622727 error_union_type.payload_type != .generic_poison_type)
22632728 {
......@@ -2269,10 +2734,12 @@ fn updateConstInner(
22692734 }
22702735 {
22712736 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);
22732739 {
2740 try dwarf.secOffsetFinish(di_nw, discr_offset, di_nw.ni, di_w.end);
22742741 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");
22762743 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));
22772744 try di_w.writeUleb128(eu_error_set_offset);
22782745
......@@ -2281,7 +2748,7 @@ fn updateConstInner(
22812748 try di_w.writeUleb128(0);
22822749 {
22832750 try dwarf.abbrevCode(di_nw, .generated_field);
2284 try dwarf.strp(&dwarf.debug_str, di_nw, "value");
2751 try dwarf.strx(di_nw, "value");
22852752 try dwarf.refType(pt, di_nw, eu_payload_ty);
22862753 try di_w.writeUleb128(eu_payload_offset);
22872754 }
......@@ -2290,7 +2757,7 @@ fn updateConstInner(
22902757 try dwarf.abbrevCode(di_nw, .tagged_union_default_field);
22912758 {
22922759 try dwarf.abbrevCode(di_nw, .generated_field);
2293 try dwarf.strp(&dwarf.debug_str, di_nw, "error");
2760 try dwarf.strx(di_nw, "error");
22942761 try dwarf.refType(pt, di_nw, eu_error_set_ty);
22952762 try di_w.writeUleb128(eu_error_set_offset);
22962763 }
......@@ -2320,10 +2787,10 @@ fn updateConstInner(
23202787 .c_longdouble,
23212788 .bool,
23222789 => {
2323 const ty: Type = .fromInterned(val);
2790 const ty: Type = .fromInterned(@"const");
23242791 try dwarf.abbrevCode(di_nw, .numeric_type);
2325 try dwarf.strp(&dwarf.debug_str, di_nw, @tagName(simple_type));
2326 try di_w.writeByte(if (val == .bool_type)
2792 try dwarf.strx(di_nw, @tagName(simple_type));
2793 try di_w.writeByte(if (@"const" == .bool_type)
23272794 DW.ATE.boolean
23282795 else if (ty.isRuntimeFloat())
23292796 DW.ATE.float
......@@ -2339,7 +2806,7 @@ fn updateConstInner(
23392806 },
23402807 .generic_poison => {
23412808 try dwarf.abbrevCode(di_nw, .void_type);
2342 try dwarf.strp(&dwarf.debug_str, di_nw, "anytype");
2809 try dwarf.strx(di_nw, "anytype");
23432810 },
23442811 .anyopaque,
23452812 .void,
......@@ -2351,10 +2818,10 @@ fn updateConstInner(
23512818 .undefined,
23522819 .enum_literal,
23532820 => {
2354 const ty: Type = .fromInterned(val);
2821 const ty: Type = .fromInterned(@"const");
23552822 try dwarf.abbrevCode(di_nw, .void_type);
23562823 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}", .{
23582825 ty.fmt(pt),
23592826 }) catch unreachable);
23602827 },
......@@ -2364,29 +2831,29 @@ fn updateConstInner(
23642831 .generated_enum_type
23652832 else
23662833 .generated_empty_enum_type);
2367 try dwarf.strp(&dwarf.debug_str, di_nw, "anyerror");
2834 try dwarf.strx(di_nw, "anyerror");
23682835 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| {
23702837 try dwarf.abbrevCode(di_nw, .enum_field);
23712838 try di_w.writeUleb128(DW.FORM.udata);
2372 try di_w.writeUleb128(value);
2373 try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip));
2839 try di_w.writeUleb128(err_value);
2840 try dwarf.strx(di_nw, err_name.toSlice(ip));
23742841 }
23752842 if (global_error_set_names.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
23762843 },
23772844 .adhoc_inferred_error_set => unreachable,
23782845 },
23792846 .tuple_type => |tuple_type| {
2380 const ty: Type = .fromInterned(val);
2847 const ty: Type = .fromInterned(@"const");
23812848 const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)});
23822849 defer zcu.gpa.free(name);
23832850 if (tuple_type.types.len == 0) {
23842851 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);
23862853 try di_w.writeByte(@intFromBool(false));
23872854 } else {
23882855 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);
23902857 try di_w.writeUleb128(ty.abiSize(zcu));
23912858 try di_w.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);
23922859 var field_byte_offset: u64 = 0;
......@@ -2407,7 +2874,7 @@ fn updateConstInner(
24072874 },
24082875 });
24092876 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}", .{
24112878 field_index,
24122879 }) catch unreachable);
24132880 try dwarf.refType(pt, di_nw, field_ty);
......@@ -2427,72 +2894,81 @@ fn updateConstInner(
24272894 }
24282895 },
24292896 .struct_type => {
2430 const loaded_struct = ip.loadStructType(val);
2431 const zfi = loaded_struct.zir_index.resolveFile(ip);
2432 const zf = zcu.fileByIndex(zfi);
2433 const src_inst = loaded_struct.zir_index.resolve(ip);
2434 if (src_inst == .main_struct_inst) {
2897 const loaded_struct = ip.loadStructType(@"const");
2898 const src_inst = loaded_struct.zir_index.resolveFull(ip).?;
2899 const zf = zcu.fileByIndex(src_inst.file);
2900 const is_empty = loaded_struct.captures.len == 0 and loaded_struct.field_types.len == 0;
2901 if (src_inst.inst == .main_struct_inst) {
24352902 assert(loaded_struct.captures.len == 0);
24362903 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);
24382905 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,
24402907 .@"extern", .@"packed" => unreachable,
24412908 });
24422909 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));
24442911 } else if (loaded_struct.captures.len > 0 or loaded_struct.is_reified) {
2445 try dwarf.abbrevCode(di_nw, if (loaded_struct.captures.len > 0 or
2446 loaded_struct.field_types.len > 0) switch (loaded_struct.layout) {
2447 .auto, .@"extern" => .decl_instance_struct,
2448 .@"packed" => .decl_instance_packed_struct,
2449 } else switch (loaded_struct.layout) {
2450 .auto, .@"extern" => .decl_instance_empty_struct,
2451 .@"packed" => .decl_instance_empty_packed_struct,
2912 try dwarf.abbrevCode(di_nw, switch (loaded_struct.name_nav) {
2913 else => if (is_empty) switch (loaded_struct.layout) {
2914 .auto, .@"extern" => .decl_instance_empty_struct,
2915 .@"packed" => .decl_instance_empty_packed_struct,
2916 } else switch (loaded_struct.layout) {
2917 .auto, .@"extern" => .decl_instance_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 },
24522927 });
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));
24542934 } else if (loaded_struct.name_nav.unwrap()) |name_ni| {
24552935 const name_nav = ip.getNav(name_ni);
24562936 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(
24582938 name_nav.analysis.?.namespace,
24592939 ).owner_type);
2460 try dwarf.abbrevCode(di_nw, if (loaded_struct.field_types.len > 0)
2461 switch (loaded_struct.layout) {
2462 .auto, .@"extern" => .decl_struct,
2463 .@"packed" => .decl_packed_struct,
2464 }
2465 else switch (loaded_struct.layout) {
2940 try dwarf.abbrevCode(di_nw, if (is_empty) switch (loaded_struct.layout) {
24662941 .auto, .@"extern" => .decl_empty_struct,
24672942 .@"packed" => .decl_empty_packed_struct,
2943 } else switch (loaded_struct.layout) {
2944 .auto, .@"extern" => .decl_struct,
2945 .@"packed" => .decl_packed_struct,
24682946 });
24692947 try dwarf.secOffset(di_nw, parent_ni, 0);
24702948 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
24712949 try di_w.writeUleb128(decl.src_column + 1);
24722950 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));
24742952 } else {
2475 const decl = zf.zir.?.getStructDecl(src_inst.?);
2476 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2953 const decl = zf.zir.?.getStructDecl(src_inst.inst);
2954 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
24772955 ip.namespacePtr(loaded_struct.namespace).parent.unwrap().?,
24782956 ).owner_type);
2479 try dwarf.abbrevCode(di_nw, if (loaded_struct.field_types.len > 0)
2480 switch (loaded_struct.layout) {
2481 .auto, .@"extern" => .type_decl_struct,
2482 .@"packed" => .type_decl_packed_struct,
2483 }
2484 else switch (loaded_struct.layout) {
2957 try dwarf.abbrevCode(di_nw, if (is_empty) switch (loaded_struct.layout) {
24852958 .auto, .@"extern" => .type_decl_empty_struct,
24862959 .@"packed" => .type_decl_empty_packed_struct,
2960 } else switch (loaded_struct.layout) {
2961 .auto, .@"extern" => .type_decl_struct,
2962 .@"packed" => .type_decl_packed_struct,
24872963 });
24882964 try dwarf.secOffset(di_nw, parent_ni, 0);
24892965 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
24902966 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));
24922968 }
24932969 switch (loaded_struct.layout) {
24942970 .auto, .@"extern" => {
2495 const ty: Type = .fromInterned(val);
2971 const ty: Type = .fromInterned(@"const");
24962972 try di_w.writeUleb128(ty.abiSize(zcu));
24972973 try di_w.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);
24982974 try dwarf.genCaptures(pt, di_nw, loaded_struct.captures);
......@@ -2528,8 +3004,7 @@ fn updateConstInner(
25283004 .partially_comptime => .field_default_partially_comptime,
25293005 .fully_comptime => .field_default_fully_comptime,
25303006 });
2531 try dwarf.strp(
2532 &dwarf.debug_str,
3007 try dwarf.strx(
25333008 di_nw,
25343009 loaded_struct.field_names.get(ip)[field_index].toSlice(ip),
25353010 );
......@@ -2553,8 +3028,7 @@ fn updateConstInner(
25533028 var field_bit_offset: u16 = 0;
25543029 for (0..loaded_struct.field_types.len) |field_index| {
25553030 try dwarf.abbrevCode(di_nw, .packed_field);
2556 try dwarf.strp(
2557 &dwarf.debug_str,
3031 try dwarf.strx(
25583032 di_nw,
25593033 loaded_struct.field_names.get(ip)[field_index].toSlice(ip),
25603034 );
......@@ -2566,62 +3040,71 @@ fn updateConstInner(
25663040 }
25673041 },
25683042 }
2569 if (loaded_struct.captures.len > 0 or loaded_struct.field_types.len > 0)
2570 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
3043 if (!is_empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
25713044 },
25723045 .union_type => {
2573 const loaded_union = ip.loadUnionType(val);
3046 const loaded_union = ip.loadUnionType(@"const");
25743047 const loaded_tag = ip.loadEnumType(loaded_union.enum_tag_type);
25753048 const zfi = loaded_union.zir_index.resolveFile(ip);
25763049 const zf = zcu.fileByIndex(zfi);
3050 const is_empty = loaded_union.captures.len == 0 and loaded_union.field_types.len == 0;
25773051 if (loaded_union.captures.len > 0 or loaded_union.is_reified) {
2578 try dwarf.abbrevCode(di_nw, if (loaded_union.captures.len > 0 or
2579 loaded_union.field_types.len > 0) switch (loaded_union.layout) {
2580 .auto, .@"extern" => .decl_instance_union,
2581 .@"packed" => .decl_instance_packed_union,
2582 } else switch (loaded_union.layout) {
2583 .auto, .@"extern" => .decl_instance_empty_union,
2584 .@"packed" => .decl_instance_empty_packed_union,
3052 try dwarf.abbrevCode(di_nw, switch (loaded_union.name_nav) {
3053 else => if (is_empty) switch (loaded_union.layout) {
3054 .auto, .@"extern" => .decl_instance_empty_union,
3055 .@"packed" => .decl_instance_empty_packed_union,
3056 } else switch (loaded_union.layout) {
3057 .auto, .@"extern" => .decl_instance_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 },
25853067 });
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));
25873074 } else if (loaded_union.name_nav.unwrap()) |name_ni| {
25883075 const name_nav = ip.getNav(name_ni);
25893076 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(
25913078 name_nav.analysis.?.namespace,
25923079 ).owner_type);
2593 try dwarf.abbrevCode(di_nw, if (loaded_union.field_types.len > 0)
2594 switch (loaded_union.layout) {
2595 .auto, .@"extern" => .decl_union,
2596 .@"packed" => .decl_packed_union,
2597 }
2598 else switch (loaded_union.layout) {
3080 try dwarf.abbrevCode(di_nw, if (is_empty) switch (loaded_union.layout) {
25993081 .auto, .@"extern" => .decl_empty_union,
26003082 .@"packed" => .decl_empty_packed_union,
3083 } else switch (loaded_union.layout) {
3084 .auto, .@"extern" => .decl_union,
3085 .@"packed" => .decl_packed_union,
26013086 });
26023087 try dwarf.secOffset(di_nw, parent_ni, 0);
26033088 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
26043089 try di_w.writeUleb128(decl.src_column + 1);
26053090 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));
26073092 } else {
26083093 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(
26103095 ip.namespacePtr(loaded_union.namespace).parent.unwrap().?,
26113096 ).owner_type);
2612 try dwarf.abbrevCode(di_nw, if (loaded_union.field_types.len > 0)
2613 switch (loaded_union.layout) {
2614 .auto, .@"extern" => .type_decl_union,
2615 .@"packed" => .type_decl_packed_union,
2616 }
2617 else switch (loaded_union.layout) {
3097 try dwarf.abbrevCode(di_nw, if (is_empty) switch (loaded_union.layout) {
26183098 .auto, .@"extern" => .type_decl_empty_union,
26193099 .@"packed" => .type_decl_empty_packed_union,
3100 } else switch (loaded_union.layout) {
3101 .auto, .@"extern" => .type_decl_union,
3102 .@"packed" => .type_decl_packed_union,
26203103 });
26213104 try dwarf.secOffset(di_nw, parent_ni, 0);
26223105 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
26233106 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));
26253108 }
26263109 switch (loaded_union.layout) {
26273110 .auto, .@"extern" => {
......@@ -2631,10 +3114,12 @@ fn updateConstInner(
26313114 try dwarf.genCaptures(pt, di_nw, loaded_union.captures);
26323115 if (loaded_union.has_runtime_tag) {
26333116 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);
26353119 {
3120 try dwarf.secOffsetFinish(di_nw, discr_offset, di_nw.ni, di_w.end);
26363121 try dwarf.abbrevCode(di_nw, .generated_field);
2637 try dwarf.strp(&dwarf.debug_str, di_nw, "tag");
3122 try dwarf.strx(di_nw, "tag");
26383123 try dwarf.refType(pt, di_nw, .fromInterned(loaded_union.enum_tag_type));
26393124 try di_w.writeUleb128(union_layout.tagOffset());
26403125
......@@ -2643,8 +3128,7 @@ fn updateConstInner(
26433128 try dwarf.enumConstValue(di_w, loaded_tag, field_index);
26443129 {
26453130 try dwarf.abbrevCode(di_nw, .field);
2646 try dwarf.strp(
2647 &dwarf.debug_str,
3131 try dwarf.strx(
26483132 di_nw,
26493133 loaded_tag.field_names.get(ip)[field_index].toSlice(ip),
26503134 );
......@@ -2666,8 +3150,7 @@ fn updateConstInner(
26663150 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
26673151 } else for (0..loaded_union.field_types.len) |field_index| {
26683152 try dwarf.abbrevCode(di_nw, .field);
2669 try dwarf.strp(
2670 &dwarf.debug_str,
3153 try dwarf.strx(
26713154 di_nw,
26723155 loaded_tag.field_names.get(ip)[field_index].toSlice(ip),
26733156 );
......@@ -2688,8 +3171,7 @@ fn updateConstInner(
26883171 try dwarf.refType(pt, di_nw, .fromInterned(loaded_union.packed_backing_int_type));
26893172 for (0..loaded_union.field_types.len) |field_index| {
26903173 try dwarf.abbrevCode(di_nw, .packed_field);
2691 try dwarf.strp(
2692 &dwarf.debug_str,
3174 try dwarf.strx(
26933175 di_nw,
26943176 loaded_tag.field_names.get(ip)[field_index].toSlice(ip),
26953177 );
......@@ -2700,83 +3182,86 @@ fn updateConstInner(
27003182 }
27013183 },
27023184 }
2703 if (loaded_union.captures.len > 0 or loaded_union.field_types.len > 0)
2704 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
3185 if (!is_empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
27053186 },
27063187 .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;
27083190 switch (loaded_enum.owner_union) {
27093191 .none => {
27103192 const zfi = loaded_enum.zir_index.unwrap().?.resolveFile(ip);
27113193 const zf = zcu.fileByIndex(zfi);
3194 const zir = &zf.zir.?;
27123195 if (loaded_enum.captures.len > 0 or loaded_enum.is_reified) {
2713 try dwarf.abbrevCode(di_nw, if (loaded_enum.captures.len > 0 or
2714 loaded_enum.field_names.len > 0)
2715 .decl_instance_enum
2716 else
2717 .decl_instance_empty_enum);
2718 try dwarf.secOffset(di_nw, try dwarf.getDecl(pt, val), 0);
3196 try dwarf.abbrevCode(di_nw, switch (loaded_enum.name_nav) {
3197 else => if (is_empty) .decl_instance_empty_enum else .decl_instance_enum,
3198 .none => if (is_empty)
3199 .type_decl_instance_empty_enum
3200 else
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));
27193209 } else if (loaded_enum.name_nav.unwrap()) |name_ni| {
27203210 const name_nav = ip.getNav(name_ni);
2721 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
2722 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
3211 const decl = zir.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
3212 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
27233213 name_nav.analysis.?.namespace,
27243214 ).owner_type);
27253215 try dwarf.abbrevCode(
27263216 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,
27283218 );
27293219 try dwarf.secOffset(di_nw, parent_ni, 0);
27303220 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
27313221 try di_w.writeUleb128(decl.src_column + 1);
27323222 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));
27343224 } else {
2735 const decl =
2736 zf.zir.?.getEnumDecl(loaded_enum.zir_index.unwrap().?.resolve(ip).?);
2737 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
3225 const decl = zir.getEnumDecl(loaded_enum.zir_index.unwrap().?.resolve(ip).?);
3226 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
27383227 ip.namespacePtr(loaded_enum.namespace).parent.unwrap().?,
27393228 ).owner_type);
2740 try dwarf.abbrevCode(di_nw, if (loaded_enum.field_names.len > 0)
2741 .type_decl_enum
2742 else
2743 .type_decl_empty_enum);
3229 try dwarf.abbrevCode(
3230 di_nw,
3231 if (is_empty) .type_decl_empty_enum else .type_decl_enum,
3232 );
27443233 try dwarf.secOffset(di_nw, parent_ni, 0);
27453234 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
27463235 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));
27483237 }
27493238 },
27503239 else => {
2751 try dwarf.abbrevCode(di_nw, if (loaded_enum.field_names.len > 0)
2752 .generated_enum_type
2753 else
2754 .generated_empty_enum_type);
2755 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.fqn.toSlice(ip));
3240 try dwarf.abbrevCode(
3241 di_nw,
3242 if (is_empty) .generated_empty_enum_type else .generated_enum_type,
3243 );
3244 try dwarf.strx(di_nw, loaded_enum.fqn.toSlice(ip));
27563245 },
27573246 }
27583247 try dwarf.refType(pt, di_nw, .fromInterned(loaded_enum.int_tag_type));
3248 try dwarf.genCaptures(pt, di_nw, loaded_enum.captures);
27593249 for (0..loaded_enum.field_names.len) |field_index| {
27603250 try dwarf.abbrevCode(di_nw, .enum_field);
27613251 try dwarf.enumConstValue(di_w, loaded_enum, field_index);
2762 try dwarf.strp(
2763 &dwarf.debug_str,
2764 di_nw,
2765 loaded_enum.field_names.get(ip)[field_index].toSlice(ip),
2766 );
3252 try dwarf.strx(di_nw, loaded_enum.field_names.get(ip)[field_index].toSlice(ip));
27673253 }
2768 if (loaded_enum.captures.len > 0 or loaded_enum.field_names.len > 0)
2769 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
3254 if (!is_empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
27703255 },
27713256 // 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"),
27733258 .spirv_type => unreachable,
27743259 .func_type => |func_type| {
2775 const is_nullary = 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)});
3260 const is_empty = func_type.param_types.len == 0 and !func_type.is_var_args;
3261 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)});
27773262 defer zcu.gpa.free(name);
2778 try dwarf.abbrevCode(di_nw, if (is_nullary) .nullary_func_type else .func_type);
2779 try dwarf.strp(&dwarf.debug_str, di_nw, name);
3263 try dwarf.abbrevCode(di_nw, if (is_empty) .empty_func_type else .func_type);
3264 try dwarf.strx(di_nw, name);
27803265 const cc: DW.CC = cc: {
27813266 if (zcu.getTarget().cCallingConvention()) |cc| {
27823267 if (@as(std.lang.CallingConvention.Tag, cc) == func_type.cc) {
......@@ -2848,40 +3333,38 @@ fn updateConstInner(
28483333 };
28493334 try di_w.writeByte(@backingInt(cc));
28503335 try dwarf.refType(pt, di_nw, .fromInterned(func_type.return_type));
2851 if (!is_nullary) {
2852 for (0..func_type.param_types.len) |param_index| {
2853 try dwarf.abbrevCode(di_nw, .unnamed_param);
2854 try dwarf.refType(pt, di_nw, .fromInterned(
2855 func_type.param_types.get(ip)[param_index],
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));
3336 for (0..func_type.param_types.len) |param_index| {
3337 try dwarf.abbrevCode(di_nw, .unnamed_param);
3338 try dwarf.refType(pt, di_nw, .fromInterned(
3339 func_type.param_types.get(ip)[param_index],
3340 ));
28603341 }
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));
28613344 },
28623345 .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)});
28643347 defer zcu.gpa.free(name);
28653348 try dwarf.abbrevCode(
28663349 di_nw,
28673350 if (error_set_type.names.len > 0) .generated_enum_type else .generated_empty_enum_type,
28683351 );
2869 try dwarf.strp(&dwarf.debug_str, di_nw, name);
3352 try dwarf.strx(di_nw, name);
28703353 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));
28713354 for (0..error_set_type.names.len) |field_index| {
28723355 const field_name = error_set_type.names.get(ip)[field_index];
28733356 try dwarf.abbrevCode(di_nw, .enum_field);
28743357 try di_w.writeUleb128(DW.FORM.udata);
28753358 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));
28773360 }
28783361 if (error_set_type.names.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
28793362 },
28803363 .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)});
28823365 defer zcu.gpa.free(name);
28833366 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);
28853368 try dwarf.refType(pt, di_nw, switch (ies: {
28863369 const fi = dwarf.getFuncIfExists(ip.indexToKey(func).func.owner_nav) orelse
28873370 break :ies .none;
......@@ -2895,38 +3378,468 @@ fn updateConstInner(
28953378 });
28963379 },
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,
28993396 .func => |func| {
2900 const fn_ty = ip.indexToKey(func.ty).func_type;
3397 const func_type = ip.indexToKey(func.ty).func_type;
29013398 const nav = ip.getNav(func.owner_nav);
29023399 const inst_info = nav.srcInst(ip).resolveFull(ip).?;
2903 const zf = zcu.fileByIndex(inst_info.file);
2904 const decl = zf.zir.?.getDeclaration(inst_info.inst);
3400 const zir = &zcu.fileByIndex(inst_info.file).zir.?;
3401 const decl = zir.getDeclaration(inst_info.inst);
3402 const is_empty = func_type.param_types.len == 0 and !func_type.is_var_args;
29053403 const parent_ty: Type = .fromInterned(ip.namespacePtr(nav.analysis.?.namespace).owner_type);
2906 try dwarf.abbrevCode(di_nw, .decl_func_generic);
2907 try dwarf.refType(pt, di_nw, parent_ty);
2908 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
2909 try di_w.writeUleb128(decl.src_column + 1);
2910 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2911 try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip));
2912 try dwarf.refType(pt, di_nw, .fromInterned(fn_ty.return_type));
2913 var param_index: u32 = 0;
2914 for (zf.zir.?.getParamBody(func.zir_body_inst.resolve(ip).?)) |param_inst| {
2915 switch (zf.zir.?.getParamName(param_inst) orelse break) {
3404 if (func.generic_owner != .none or parent_ty.getCaptures(zcu).len > 0) {
3405 try dwarf.abbrevCode(
3406 di_nw,
3407 if (is_empty) .decl_instance_empty_func_generic else .decl_instance_func_generic,
3408 );
3409 try dwarf.refType(pt, di_nw, parent_ty);
3410 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, @"const"), 0);
3411 } else {
3412 try dwarf.abbrevCode(
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).?) {
29163428 .empty => try dwarf.abbrevCode(di_nw, .unnamed_param),
29173429 else => |param_name| {
29183430 try dwarf.abbrevCode(di_nw, .param);
2919 try dwarf.strp(&dwarf.debug_str, di_nw, zf.zir.?.nullTerminatedString(
2920 param_name,
2921 ));
3431 try dwarf.strx(di_nw, zir.nullTerminatedString(param_name));
29223432 },
29233433 }
2924 try dwarf.refType(pt, di_nw, .fromInterned(
2925 fn_ty.param_types.get(&zcu.intern_pool)[param_index],
2926 ));
2927 param_index += 1;
3434 try dwarf.refType(pt, di_nw, .fromInterned(param_ty));
3435 }
3436 if (func_type.is_var_args) try dwarf.abbrevCode(di_nw, .is_var_args);
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));
29283842 }
2929 if (fn_ty.is_var_args) try dwarf.abbrevCode(di_nw, .is_var_args);
29303843 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
29313844 },
29323845
......@@ -2935,11 +3848,11 @@ fn updateConstInner(
29353848 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());
29363849}
29373850
2938fn optRepr(opt_child_type: Type, zcu: *const Zcu) enum { unpacked, opv_null, error_set, pointer } {
2939 if (opt_child_type.isNoReturn(zcu)) return .opv_null;
2940 return switch (opt_child_type.toIntern()) {
3851fn optRepr(opt_child_ty: Type, zcu: *const Zcu) enum { unpacked, opv_null, error_set, pointer } {
3852 if (opt_child_ty.isNoReturn(zcu)) return .opv_null;
3853 return switch (opt_child_ty.toIntern()) {
29413854 .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())) {
29433856 else => .unpacked,
29443857 .error_set_type, .inferred_error_set_type => .error_set,
29453858 .ptr_type => |ptr_type| if (ptr_type.flags.is_allowzero) .unpacked else .pointer,
......@@ -2983,21 +3896,21 @@ fn updateConstIncompleteInner(
29833896 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, src_inst.file);
29843897 try dwarf.abbrevCode(di_nw, .empty_file);
29853898 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));
29873900 try di_w.writeByte(@intFromBool(true));
29883901 break :done;
29893902 },
29903903 else => {
2991 const data =
2992 zf.zir.?.instructions.items(.data)[@backingInt(src_inst.inst)].extended;
3904 const zir = &zf.zir.?;
3905 const data = zir.instructions.items(.data)[@backingInt(src_inst.inst)].extended;
29933906 const src_line, const src_column = src_loc: switch (data.opcode) {
29943907 else => unreachable,
29953908 .struct_decl => {
2996 const decl = zf.zir.?.getStructDecl(src_inst.inst);
3909 const decl = zir.getStructDecl(src_inst.inst);
29973910 break :src_loc .{ decl.src_line, decl.src_column };
29983911 },
29993912 .reify_struct => {
3000 const decl = zf.zir.?.extraData(
3913 const decl = zir.extraData(
30013914 std.zig.Zir.Inst.ReifyStruct,
30023915 data.operand,
30033916 ).data;
......@@ -3025,15 +3938,16 @@ fn updateConstIncompleteInner(
30253938 break :done;
30263939 };
30273940 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;
30293943 const src_line, const src_column = src_loc: switch (data.opcode) {
30303944 else => unreachable,
30313945 .union_decl => {
3032 const decl = zf.zir.?.getUnionDecl(src_inst.inst);
3946 const decl = zir.getUnionDecl(src_inst.inst);
30333947 break :src_loc .{ decl.src_line, decl.src_column };
30343948 },
30353949 .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;
30373951 break :src_loc .{ decl.src_line, decl.src_column };
30383952 },
30393953 };
......@@ -3053,7 +3967,7 @@ fn updateConstIncompleteInner(
30533967 const loaded_enum = ip.loadEnumType(val);
30543968 const zir_index = loaded_enum.zir_index.unwrap() orelse {
30553969 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));
30573971 try di_w.writeByte(@intFromBool(true));
30583972 break :done;
30593973 };
......@@ -3062,15 +3976,16 @@ fn updateConstIncompleteInner(
30623976 break :done;
30633977 };
30643978 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;
30663981 const src_line, const src_column = src_loc: switch (data.opcode) {
30673982 else => unreachable,
30683983 .enum_decl => {
3069 const decl = zf.zir.?.getEnumDecl(src_inst.inst);
3984 const decl = zir.getEnumDecl(src_inst.inst);
30703985 break :src_loc .{ decl.src_line, decl.src_column };
30713986 },
30723987 .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;
30743989 break :src_loc .{ decl.src_line, decl.src_column };
30753990 },
30763991 };
......@@ -3112,7 +4027,7 @@ fn updateConstIncompleteInner(
31124027 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
31134028 defer zcu.gpa.free(name);
31144029 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);
31164031 try di_w.writeByte(@intFromBool(true));
31174032 },
31184033 else => |ty| {
......@@ -3131,13 +4046,15 @@ fn updateConstIncompleteInner(
31314046 .@"union" => .decl_instance_empty_incomplete_union,
31324047 .@"enum" => .decl_instance_empty_incomplete_enum,
31334048 });
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);
31354053 } else if (maybe_name_nav.unwrap()) |name_ni| {
31364054 const name_nav = ip.getNav(name_ni);
31374055 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
3138 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
3139 name_nav.analysis.?.namespace,
3140 ).owner_type);
4056 const parent_ni =
4057 try dwarf.getConstDecl(pt, ip.namespacePtr(name_nav.analysis.?.namespace).owner_type);
31414058 try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) {
31424059 .@"struct" => .decl_incomplete_struct,
31434060 .@"union" => .decl_incomplete_union,
......@@ -3151,9 +4068,9 @@ fn updateConstIncompleteInner(
31514068 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
31524069 try di_w.writeUleb128(decl.src_column + 1);
31534070 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));
31554072 } else {
3156 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
4073 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
31574074 ip.namespacePtr(namespace).parent.unwrap().?,
31584075 ).owner_type);
31594076 try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) {
......@@ -3168,7 +4085,7 @@ fn updateConstIncompleteInner(
31684085 try dwarf.secOffset(di_nw, parent_ni, 0);
31694086 try di_w.writeInt(u32, src_line + 1, dwarf.endian);
31704087 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));
31724089 }
31734090 try dwarf.genCaptures(pt, di_nw, captures);
31744091 if (captures.len > 0) try di_w.writeByte(@backingInt(AbbrevCode.null));
......@@ -3224,10 +4141,16 @@ pub fn genDecl(
32244141 dwarf: *Dwarf,
32254142 pt: Zcu.PerThread,
32264143 di_nw: *link.MappedFile.Node.Writer,
3227 instance_val: InternPool.Index,
4144 instance: Decl.Instance,
32284145) link.Error!void {
3229 log.debug("genDecl({f})", .{Value.fromInterned(instance_val).fmtValue(pt)});
3230 dwarf.genDeclInner(pt, di_nw, instance_val) catch |err| switch (err) {
4146 switch (instance) {
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) {
32314154 else => |e| return e,
32324155 error.WriteFailed => return dwarf.reportWriteError(di_nw),
32334156 };
......@@ -3236,216 +4159,255 @@ fn genDeclInner(
32364159 dwarf: *Dwarf,
32374160 pt: Zcu.PerThread,
32384161 di_nw: *link.MappedFile.Node.Writer,
3239 instance_val: InternPool.Index,
4162 instance: Decl.Instance,
32404163) link.EmitError!void {
32414164 const zcu = pt.zcu;
32424165 const ip = &zcu.intern_pool;
32434166 const di_w = &di_nw.interface;
3244 done: {
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)) {
3246 else => unreachable,
3247 .struct_type => {
3248 const loaded_struct = ip.loadStructType(instance_val);
3249 const src_inst = loaded_struct.zir_index.resolveFull(ip) orelse {
3250 try dwarf.lostTracking(di_nw);
3251 break :done;
3252 };
3253 const zf = zcu.fileByIndex(src_inst.file);
3254 const inst = zf.zir.?.instructions.get(@backingInt(src_inst.inst));
3255 const src_line, const src_column, const capture_names = decl: switch (inst.tag) {
3256 else => unreachable,
3257 .struct_init, .struct_init_ref => {
3258 const decl = zf.zir.?.extraData(
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) {
4167 done: switch (instance) {
4168 .none => unreachable,
4169 .@"const" => |@"const"| {
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")) {
4171 else => unreachable,
4172 .struct_type => {
4173 const loaded_struct = ip.loadStructType(@"const");
4174 const src_inst = loaded_struct.zir_index.resolveFull(ip) orelse {
4175 try dwarf.lostTracking(di_nw);
4176 break :done;
4177 };
4178 const zf = zcu.fileByIndex(src_inst.file);
4179 const zir = &zf.zir.?;
4180 const inst = zir.instructions.get(@backingInt(src_inst.inst));
4181 const src_line, const src_column, const capture_names = decl: switch (inst.tag) {
32724182 else => unreachable,
3273 .struct_decl => {
3274 const decl = zf.zir.?.getStructDecl(src_inst.inst);
3275 break :decl .{ decl.src_line, decl.src_column, decl.capture_names };
3276 },
3277 .reify_struct => {
3278 const decl = zf.zir.?.extraData(
3279 std.zig.Zir.Inst.ReifyStruct,
3280 inst.data.extended.operand,
4183 .struct_init, .struct_init_ref => {
4184 const decl = zir.extraData(
4185 std.zig.Zir.Inst.StructInit,
4186 inst.data.pl_node.payload_index,
32814187 ).data;
32824188 break :decl .{ decl.src_line, decl.src_column, &.{} };
32834189 },
3284 },
3285 };
3286 break :container .{
3287 .@"struct",
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,
4190 .struct_init_anon => {
4191 const decl = zir.extraData(
4192 std.zig.Zir.Inst.StructInitAnon,
4193 inst.data.pl_node.payload_index,
33184194 ).data;
33194195 break :decl .{ decl.src_line, decl.src_column, &.{} };
33204196 },
3321 },
3322 };
3323 break :container .{
3324 .@"union",
3325 zf,
3326 src_line,
3327 src_column,
3328 capture_names,
3329 loaded_union.captures,
3330 loaded_union.name,
3331 loaded_union.name_nav,
3332 loaded_union.namespace,
3333 };
3334 },
3335 .enum_type => {
3336 const loaded_enum = ip.loadEnumType(instance_val);
3337 const src_inst = loaded_enum.zir_index.unwrap().?.resolveFull(ip) orelse {
3338 try dwarf.lostTracking(di_nw);
3339 break :done;
3340 };
3341 const zf = zcu.fileByIndex(src_inst.file);
3342 const inst = zf.zir.?.instructions.get(@backingInt(src_inst.inst));
3343 const src_line, const src_column, const capture_names = decl: switch (inst.tag) {
3344 else => unreachable,
3345 .extended => switch (inst.data.extended.opcode) {
4197 .extended => switch (inst.data.extended.opcode) {
4198 else => unreachable,
4199 .struct_decl => {
4200 const decl = zir.getStructDecl(src_inst.inst);
4201 break :decl .{ decl.src_line, decl.src_column, decl.capture_names };
4202 },
4203 .reify_struct => {
4204 const decl = zir.extraData(
4205 std.zig.Zir.Inst.ReifyStruct,
4206 inst.data.extended.operand,
4207 ).data;
4208 break :decl .{ decl.src_line, decl.src_column, &.{} };
4209 },
4210 },
4211 };
4212 break :container .{
4213 .@"struct",
4214 zf,
4215 src_line,
4216 src_column,
4217 capture_names,
4218 loaded_struct.captures,
4219 loaded_struct.name_nav,
4220 loaded_struct.namespace,
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) {
33464233 else => unreachable,
3347 .enum_decl => {
3348 const decl = zf.zir.?.getEnumDecl(src_inst.inst);
3349 break :decl .{ decl.src_line, decl.src_column, decl.capture_names };
4234 .extended => switch (inst.data.extended.opcode) {
4235 else => unreachable,
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 },
33504247 },
3351 .reify_enum => {
3352 const decl = zf.zir.?.extraData(
3353 std.zig.Zir.Inst.ReifyEnum,
3354 inst.data.extended.operand,
3355 ).data;
3356 break :decl .{ decl.src_line, decl.src_column, &.{} };
4248 };
4249 break :container .{
4250 .@"union",
4251 zf,
4252 src_line,
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 },
33574284 },
3358 },
3359 };
3360 break :container .{
3361 .@"enum",
3362 zf,
3363 src_line,
3364 src_column,
3365 capture_names,
3366 loaded_enum.captures,
3367 loaded_enum.name,
3368 loaded_enum.name_nav,
3369 loaded_enum.namespace,
3370 };
3371 },
3372 .opaque_type => {
3373 const loaded_opaque = ip.loadOpaqueType(instance_val);
3374 const src_inst = loaded_opaque.zir_index.resolveFull(ip) orelse {
3375 try dwarf.lostTracking(di_nw);
4285 };
4286 break :container .{
4287 .@"enum",
4288 zf,
4289 src_line,
4290 src_column,
4291 capture_names,
4292 loaded_enum.captures,
4293 loaded_enum.name_nav,
4294 loaded_enum.namespace,
4295 };
4296 },
4297 .opaque_type => {
4298 const loaded_opaque = ip.loadOpaqueType(@"const");
4299 const src_inst = loaded_opaque.zir_index.resolveFull(ip) orelse {
4300 try dwarf.lostTracking(di_nw);
4301 break :done;
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));
33764332 break :done;
3377 };
3378 const zf = zcu.fileByIndex(src_inst.file);
3379 const decl = zf.zir.?.getOpaqueDecl(src_inst.inst);
3380 break :container .{
3381 .@"struct",
3382 zf,
3383 decl.src_line,
3384 decl.src_column,
3385 decl.capture_names,
3386 loaded_opaque.captures,
3387 loaded_opaque.name,
3388 loaded_opaque.name_nav,
3389 loaded_opaque.namespace,
3390 };
3391 },
3392 };
3393 if (maybe_name_nav.unwrap()) |name_ni| {
3394 const name_nav = ip.getNav(name_ni);
3395 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
3396 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
3397 name_nav.analysis.?.namespace,
3398 ).owner_type);
3399 try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) {
3400 .@"struct" => .decl_specification_struct,
3401 .@"union" => .decl_specification_union,
3402 .@"enum" => .decl_specification_enum,
3403 } else switch (kind) {
3404 .@"struct" => .decl_specification_empty_struct,
3405 .@"union" => .decl_specification_empty_union,
3406 .@"enum" => .decl_specification_empty_enum,
3407 });
3408 try dwarf.secOffset(di_nw, parent_ni, 0);
3409 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
3410 try di_w.writeUleb128(decl.src_column + 1);
3411 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
3412 try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip));
3413 } else {
3414 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
3415 ip.namespacePtr(namespace).parent.unwrap().?,
4333 },
4334 };
4335 const zir = &zf.zir.?;
4336 if (maybe_name_nav.unwrap()) |name_ni| {
4337 const name_nav = ip.getNav(name_ni);
4338 const decl = zir.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
4339 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
4340 name_nav.analysis.?.namespace,
4341 ).owner_type);
4342 try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) {
4343 .@"struct" => .decl_specification_struct,
4344 .@"union" => .decl_specification_union,
4345 .@"enum" => .decl_specification_enum,
4346 } else switch (kind) {
4347 .@"struct" => .decl_specification_empty_struct,
4348 .@"union" => .decl_specification_empty_union,
4349 .@"enum" => .decl_specification_empty_enum,
4350 });
4351 try dwarf.secOffset(di_nw, parent_ni, 0);
4352 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
4353 try di_w.writeUleb128(decl.src_column + 1);
4354 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
4355 try dwarf.strx(di_nw, name_nav.name.toSlice(ip));
4356 } else {
4357 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
4358 ip.namespacePtr(namespace).parent.unwrap().?,
4359 ).owner_type);
4360 try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) {
4361 .@"struct" => .type_decl_specification_struct,
4362 .@"union" => .type_decl_specification_union,
4363 .@"enum" => .type_decl_specification_enum,
4364 } else switch (kind) {
4365 .@"struct" => .type_decl_specification_empty_struct,
4366 .@"union" => .type_decl_specification_empty_union,
4367 .@"enum" => .type_decl_specification_empty_enum,
4368 });
4369 try dwarf.secOffset(di_nw, parent_ni, 0);
4370 try di_w.writeInt(u32, src_line + 1, dwarf.endian);
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,
34164400 ).owner_type);
3417 try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) {
3418 .@"struct" => .type_decl_specification_struct,
3419 .@"union" => .type_decl_specification_union,
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,
4401 try dwarf.abbrevCode(di_nw, switch (nav_ty) {
4402 .type_type => .decl_specification_type,
4403 else => if (nav_const) .decl_specification_const else .decl_specification_var,
34254404 });
34264405 try dwarf.secOffset(di_nw, parent_ni, 0);
3427 try di_w.writeInt(u32, src_line + 1, dwarf.endian);
3428 try di_w.writeUleb128(src_column + 1);
3429 try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip));
3430 }
3431 for (capture_names, captures.get(ip)) |capture_name, capture| {
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));
4406 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
4407 try di_w.writeUleb128(decl.src_column + 1);
4408 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
4409 try dwarf.strx(di_nw, nav.name.toSlice(ip));
4410 },
34494411 }
34504412 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());
34514413}
......@@ -3458,9 +4420,12 @@ pub fn updateLineNumber(
34584420) void {
34594421 const di = dwarf.getDeclIfExists(inst) orelse return;
34604422 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);
34614426 std.mem.writeInt(
34624427 u32,
3463 decl_ni.slice(mf)[AbbrevCode.decl_size..][0..4],
4428 decl_ni.slice(mf)[AbbrevCode.decl_size + dwarf.secOffsetSize() ..][0..4],
34644429 line + 1,
34654430 dwarf.endian,
34664431 );
......@@ -3486,8 +4451,11 @@ fn refAbbrevCode(
34864451 @branchHint(.likely);
34874452 return backing_int;
34884453 }
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);
34894457 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);
34914459 defer da_nw.deinit();
34924460 dwarf.genDebugAbbrev(&da_nw, abbrev_code) catch |err| switch (err) {
34934461 else => |e| return e,
......@@ -3526,15 +4494,12 @@ fn genDebugAbbrev(
35264494 dwarf.debug_abbrev.end = da_w.end;
35274495}
35284496
3529pub fn secOffsetSize(dwarf: *Dwarf) usize {
4497fn secOffsetSize(dwarf: *Dwarf) usize {
35304498 return switch (dwarf.format) {
35314499 .@"32" => 4,
35324500 .@"64" => 8,
35334501 };
35344502}
3535fn secOffsetPlaceholder(dwarf: *Dwarf, w: *std.Io.Writer) std.Io.Writer.Error!void {
3536 @memset(try w.writableSlice(dwarf.secOffsetSize()), undefined);
3537}
35384503fn secOffset(
35394504 dwarf: *Dwarf,
35404505 nw: *link.MappedFile.Node.Writer,
......@@ -3543,6 +4508,18 @@ fn secOffset(
35434508) link.EmitError!void {
35444509 const offset = nw.interface.end;
35454510 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 {
35464523 if (dwarf.lf.cast(.elf2)) |elf| try elf.addNodeReloc(
35474524 nw.ni,
35484525 offset,
......@@ -3574,6 +4551,21 @@ fn addrSym(
35744551 .absAddr(elf),
35754552 ) else unreachable;
35764553}
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
35784570fn blockConst(
35794571 dwarf: *Dwarf,
......@@ -3585,13 +4577,9 @@ fn blockConst(
35854577 const size = ty.abiSize(pt.zcu);
35864578 try nw.interface.writeUleb128(size);
35874579 const start = nw.interface.end;
3588 if (size > 0) try codegen.generateSymbol(
3589 dwarf.lf,
3590 pt,
3591 val,
3592 &nw.interface,
3593 .{ .atom_index = @bitCast(nw.ni) },
3594 );
4580 if (size > 0) try codegen.generateSymbol(dwarf.lf, pt, val, &nw.interface, .{
4581 .atom_index = @bitCast(nw.ni),
4582 });
35954583 assert(start + size == nw.interface.end);
35964584}
35974585
......@@ -3691,13 +4679,37 @@ fn exprLoc(dwarf: *Dwarf, nw: *link.MappedFile.Node.Writer, loc: Loc) link.EmitE
36914679fn strp(dwarf: *Dwarf, s: *Str, nw: *link.MappedFile.Node.Writer, str: []const u8) link.EmitError!void {
36924680 const comp = dwarf.lf.comp;
36934681 try dwarf.secOffset(nw, s.ni.unwrap().?, s.get(comp.gpa, nw.mf, str) catch |err| switch (err) {
4682 else => |e| return e,
36944683 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{
36954684 nw.mf.io_err.?,
36964685 }),
3697 else => |e| return e,
36984686 });
36994687}
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
37014713fn reportWriteError(dwarf: *Dwarf, nw: *const link.MappedFile.Node.Writer) link.Error {
37024714 switch (nw.err.?) {
37034715 else => |e| return e,
......@@ -3744,7 +4756,6 @@ pub const AbbrevCode = enum {
37444756 pad_n,
37454757 // decl, specification, and instance codes are assumed to all have the same uleb128 size
37464758 decl_lost,
3747 decl_alias,
37484759 decl_empty_incomplete_enum,
37494760 decl_incomplete_enum,
37504761 decl_empty_enum,
......@@ -3777,16 +4788,17 @@ pub const AbbrevCode = enum {
37774788 decl_packed_union,
37784789 type_decl_empty_packed_union,
37794790 type_decl_packed_union,
3780 decl_var,
4791 decl_type,
37814792 decl_const,
3782 decl_const_runtime_bits,
3783 decl_const_comptime_state,
3784 decl_const_runtime_bits_comptime_state,
3785 decl_nullary_func,
4793 decl_const_fully_runtime,
4794 decl_const_partially_comptime,
4795 decl_const_fully_comptime,
4796 decl_var,
4797 decl_empty_func,
37864798 decl_func,
3787 decl_nullary_func_generic,
4799 decl_empty_func_generic,
37884800 decl_func_generic,
3789 decl_extern_nullary_func,
4801 decl_extern_empty_func,
37904802 decl_extern_func,
37914803 decl_specification_empty_struct,
37924804 decl_specification_struct,
......@@ -3800,40 +4812,48 @@ pub const AbbrevCode = enum {
38004812 decl_specification_union,
38014813 type_decl_specification_empty_union,
38024814 type_decl_specification_union,
4815 decl_specification_type,
4816 decl_specification_const,
4817 decl_specification_var,
38034818 decl_specification_func,
3804 decl_instance_alias,
38054819 decl_instance_empty_incomplete_enum,
38064820 decl_instance_incomplete_enum,
38074821 decl_instance_empty_enum,
38084822 decl_instance_enum,
4823 type_decl_instance_empty_enum,
4824 type_decl_instance_enum,
38094825 decl_instance_empty_incomplete_struct,
38104826 decl_instance_incomplete_struct,
38114827 decl_instance_empty_struct,
38124828 decl_instance_struct,
4829 type_decl_instance_empty_struct,
4830 type_decl_instance_struct,
38134831 decl_instance_empty_packed_struct,
38144832 decl_instance_packed_struct,
4833 type_decl_instance_empty_packed_struct,
4834 type_decl_instance_packed_struct,
38154835 decl_instance_empty_incomplete_union,
38164836 decl_instance_incomplete_union,
38174837 decl_instance_empty_union,
38184838 decl_instance_union,
4839 type_decl_instance_empty_union,
4840 type_decl_instance_union,
38194841 decl_instance_empty_packed_union,
38204842 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,
38224846 decl_instance_const,
3823 decl_instance_const_runtime_bits,
3824 decl_instance_const_comptime_state,
3825 decl_instance_const_runtime_bits_comptime_state,
3826 decl_instance_nullary_func,
4847 decl_instance_const_fully_runtime,
4848 decl_instance_const_partially_comptime,
4849 decl_instance_const_fully_comptime,
4850 decl_instance_var,
4851 decl_instance_empty_func,
38274852 decl_instance_func,
3828 decl_instance_nullary_func_generic,
4853 decl_instance_empty_func_generic,
38294854 decl_instance_func_generic,
3830 decl_instance_extern_nullary_func,
3831 decl_instance_extern_func,
38324855 // the rest are unrestricted other than empty variants must not be longer
38334856 // than the non-empty variant, and so should appear first
3834 compile_unit,
3835 module,
3836 module_dependency,
38374857 empty_file,
38384858 file,
38394859 access,
......@@ -3856,8 +4876,7 @@ pub const AbbrevCode = enum {
38564876 inferred_error_set_type,
38574877 ptr_type,
38584878 ptr_sentinel_type,
3859 ptr_aligned_type,
3860 ptr_aligned_sentinel_type,
4879 is_aligned,
38614880 is_const,
38624881 is_volatile,
38634882 array_type,
......@@ -3865,7 +4884,7 @@ pub const AbbrevCode = enum {
38654884 vector_type,
38664885 array_index,
38674886 array_len,
3868 nullary_func_type,
4887 empty_func_type,
38694888 func_type,
38704889 param,
38714890 unnamed_param,
......@@ -3882,7 +4901,7 @@ pub const AbbrevCode = enum {
38824901 comptime_capture_fully_comptime,
38834902 runtime_capture,
38844903 nav_capture,
3885 builtin_extern_nullary_func,
4904 builtin_extern_empty_func,
38864905 builtin_extern_func,
38874906 builtin_extern_var,
38884907 empty_block,
......@@ -3911,44 +4930,51 @@ pub const AbbrevCode = enum {
39114930 aggregate_undefined_comptime_value,
39124931 aggregate_comptime_value,
39134932 aggregate_location_comptime_value,
3914 comptime_value_field_runtime_bits,
3915 comptime_value_field_comptime_state,
3916 comptime_value_elem_runtime_bits,
3917 comptime_value_elem_comptime_state,
4933 comptime_value_field_runtime,
4934 comptime_value_field_comptime,
4935 comptime_value_elem_runtime,
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));
39204943 comptime {
39214944 assert(uleb128Size(@backingInt(AbbrevCode.pad_1)) == 1);
39224945 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);
39244947 }
39254948
39264949 const Attr = struct {
39274950 DeclValEnum(DW.AT),
39284951 DeclValEnum(DW.FORM),
39294952 };
3930 const decl_attrs = &[_]Attr{
4953 const common_decl_attrs = &[_]Attr{
39314954 .{ .ZIG_parent, .ref_addr },
39324955 .{ .decl_line, .data4 },
39334956 .{ .decl_column, .udata },
4957 };
4958 const decl_attrs = common_decl_attrs ++ .{
39344959 .{ .accessibility, .data1 },
3935 .{ .name, .strp },
4960 .{ .name, .strx },
39364961 };
3937 const type_decl_attrs = &[_]Attr{
3938 .{ .ZIG_parent, .ref_addr },
3939 .{ .decl_line, .data4 },
3940 .{ .decl_column, .udata },
3941 .{ .name, .strp },
4962 const type_decl_attrs = common_decl_attrs ++ .{
4963 .{ .name, .strx },
39424964 };
39434965 const decl_specification_attrs = decl_attrs ++ &[_]Attr{
39444966 .{ .declaration, .flag_present },
39454967 };
3946 const type_decl_specification_attrs = type_decl_attrs ++ &[_]Attr{
4968 const type_decl_specification_attrs = common_decl_attrs ++ &[_]Attr{
39474969 .{ .declaration, .flag_present },
39484970 };
39494971 const decl_instance_attrs = &[_]Attr{
4972 .{ .ZIG_parent, .ref_addr },
39504973 .{ .specification, .ref_addr },
39514974 };
4975 const type_decl_instance_attrs = decl_instance_attrs ++ .{
4976 .{ .name, .strx },
4977 };
39524978
39534979 const abbrevs = std.EnumArray(AbbrevCode, struct {
39544980 tag: DeclValEnum(DW.TAG),
......@@ -3968,12 +4994,6 @@ pub const AbbrevCode = enum {
39684994 .decl_lost = .{
39694995 .tag = .ZIG_lost_declaration,
39704996 },
3971 .decl_alias = .{
3972 .tag = .imported_declaration,
3973 .attrs = decl_attrs ++ .{
3974 .{ .import, .ref_addr },
3975 },
3976 },
39774997 .decl_empty_incomplete_enum = .{
39784998 .tag = .enumeration_type,
39794999 .attrs = decl_attrs,
......@@ -4166,62 +5186,68 @@ pub const AbbrevCode = enum {
41665186 .{ .type, .ref_addr },
41675187 },
41685188 },
4169 .decl_var = .{
4170 .tag = .variable,
5189 .decl_type = .{
5190 .tag = .imported_declaration,
41715191 .attrs = decl_attrs ++ .{
4172 .{ .linkage_name, .strp },
4173 .{ .type, .ref_addr },
4174 .{ .location, .exprloc },
4175 .{ .alignment, .udata },
4176 .{ .external, .flag },
5192 .{ .import, .ref_addr },
41775193 },
41785194 },
41795195 .decl_const = .{
41805196 .tag = .constant,
41815197 .attrs = decl_attrs ++ .{
4182 .{ .linkage_name, .strp },
5198 .{ .linkage_name, .strx },
41835199 .{ .type, .ref_addr },
41845200 .{ .alignment, .udata },
41855201 .{ .external, .flag },
41865202 },
41875203 },
4188 .decl_const_runtime_bits = .{
5204 .decl_const_fully_runtime = .{
41895205 .tag = .constant,
41905206 .attrs = decl_attrs ++ .{
4191 .{ .linkage_name, .strp },
5207 .{ .linkage_name, .strx },
41925208 .{ .type, .ref_addr },
41935209 .{ .alignment, .udata },
41945210 .{ .external, .flag },
41955211 .{ .const_value, .block },
41965212 },
41975213 },
4198 .decl_const_comptime_state = .{
5214 .decl_const_partially_comptime = .{
41995215 .tag = .constant,
42005216 .attrs = decl_attrs ++ .{
4201 .{ .linkage_name, .strp },
5217 .{ .linkage_name, .strx },
42025218 .{ .type, .ref_addr },
42035219 .{ .alignment, .udata },
42045220 .{ .external, .flag },
5221 .{ .const_value, .block },
42055222 .{ .ZIG_comptime_value, .ref_addr },
42065223 },
42075224 },
4208 .decl_const_runtime_bits_comptime_state = .{
5225 .decl_const_fully_comptime = .{
42095226 .tag = .constant,
42105227 .attrs = decl_attrs ++ .{
4211 .{ .linkage_name, .strp },
5228 .{ .linkage_name, .strx },
42125229 .{ .type, .ref_addr },
42135230 .{ .alignment, .udata },
42145231 .{ .external, .flag },
4215 .{ .const_value, .block },
42165232 .{ .ZIG_comptime_value, .ref_addr },
42175233 },
42185234 },
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 = .{
42205246 .tag = .subprogram,
42215247 .attrs = decl_attrs ++ .{
4222 .{ .linkage_name, .strp },
5248 .{ .linkage_name, .strx },
42235249 .{ .type, .ref_addr },
4224 .{ .low_pc, .addr },
5250 .{ .low_pc, .addrx },
42255251 .{ .high_pc, .data4 },
42265252 .{ .alignment, .udata },
42275253 .{ .external, .flag },
......@@ -4232,20 +5258,19 @@ pub const AbbrevCode = enum {
42325258 .tag = .subprogram,
42335259 .children = true,
42345260 .attrs = decl_attrs ++ .{
4235 .{ .linkage_name, .strp },
5261 .{ .linkage_name, .strx },
42365262 .{ .type, .ref_addr },
4237 .{ .low_pc, .addr },
5263 .{ .low_pc, .addrx },
42385264 .{ .high_pc, .data4 },
42395265 .{ .alignment, .udata },
42405266 .{ .external, .flag },
42415267 .{ .noreturn, .flag },
42425268 },
42435269 },
4244 .decl_nullary_func_generic = .{
5270 .decl_empty_func_generic = .{
42455271 .tag = .subprogram,
42465272 .attrs = decl_attrs ++ .{
42475273 .{ .type, .ref_addr },
4248 .{ .noreturn, .flag },
42495274 },
42505275 },
42515276 .decl_func_generic = .{
......@@ -4255,10 +5280,10 @@ pub const AbbrevCode = enum {
42555280 .{ .type, .ref_addr },
42565281 },
42575282 },
4258 .decl_extern_nullary_func = .{
5283 .decl_extern_empty_func = .{
42595284 .tag = .subprogram,
42605285 .attrs = decl_attrs ++ .{
4261 .{ .linkage_name, .strp },
5286 .{ .linkage_name, .strx },
42625287 .{ .type, .ref_addr },
42635288 .{ .low_pc, .addr },
42645289 .{ .external, .flag_present },
......@@ -4269,7 +5294,7 @@ pub const AbbrevCode = enum {
42695294 .tag = .subprogram,
42705295 .children = true,
42715296 .attrs = decl_attrs ++ .{
4272 .{ .linkage_name, .strp },
5297 .{ .linkage_name, .strx },
42735298 .{ .type, .ref_addr },
42745299 .{ .low_pc, .addr },
42755300 .{ .external, .flag_present },
......@@ -4330,16 +5355,22 @@ pub const AbbrevCode = enum {
43305355 .children = true,
43315356 .attrs = type_decl_specification_attrs,
43325357 },
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 },
43335370 .decl_specification_func = .{
43345371 .tag = .subprogram,
43355372 .attrs = decl_specification_attrs,
43365373 },
4337 .decl_instance_alias = .{
4338 .tag = .imported_declaration,
4339 .attrs = decl_instance_attrs ++ .{
4340 .{ .import, .ref_addr },
4341 },
4342 },
43435374 .decl_instance_empty_incomplete_enum = .{
43445375 .tag = .enumeration_type,
43455376 .attrs = decl_instance_attrs,
......@@ -4362,6 +5393,19 @@ pub const AbbrevCode = enum {
43625393 .{ .type, .ref_addr },
43635394 },
43645395 },
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 },
43655409 .decl_instance_empty_incomplete_struct = .{
43665410 .tag = .structure_type,
43675411 .attrs = decl_instance_attrs,
......@@ -4386,6 +5430,21 @@ pub const AbbrevCode = enum {
43865430 .{ .alignment, .udata },
43875431 },
43885432 },
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 },
43895448 .decl_instance_empty_packed_struct = .{
43905449 .tag = .structure_type,
43915450 .attrs = decl_instance_attrs ++ .{
......@@ -4399,6 +5458,19 @@ pub const AbbrevCode = enum {
43995458 .{ .type, .ref_addr },
44005459 },
44015460 },
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 },
44025474 .decl_instance_empty_incomplete_union = .{
44035475 .tag = .union_type,
44045476 .attrs = decl_instance_attrs,
......@@ -4423,6 +5495,21 @@ pub const AbbrevCode = enum {
44235495 .{ .alignment, .udata },
44245496 },
44255497 },
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 },
44265513 .decl_instance_empty_packed_union = .{
44275514 .tag = .union_type,
44285515 .attrs = decl_instance_attrs ++ .{
......@@ -4436,150 +5523,118 @@ pub const AbbrevCode = enum {
44365523 .{ .type, .ref_addr },
44375524 },
44385525 },
4439 .decl_instance_var = .{
4440 .tag = .variable,
4441 .attrs = decl_instance_attrs ++ .{
4442 .{ .linkage_name, .strp },
5526 .type_decl_instance_empty_packed_union = .{
5527 .tag = .union_type,
5528 .attrs = type_decl_instance_attrs ++ .{
44435529 .{ .type, .ref_addr },
4444 .{ .location, .exprloc },
4445 .{ .alignment, .udata },
4446 .{ .external, .flag },
5530 },
5531 },
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 },
44475543 },
44485544 },
44495545 .decl_instance_const = .{
44505546 .tag = .constant,
44515547 .attrs = decl_instance_attrs ++ .{
4452 .{ .linkage_name, .strp },
5548 .{ .linkage_name, .strx },
44535549 .{ .type, .ref_addr },
44545550 .{ .alignment, .udata },
44555551 .{ .external, .flag },
44565552 },
44575553 },
4458 .decl_instance_const_runtime_bits = .{
5554 .decl_instance_const_fully_runtime = .{
44595555 .tag = .constant,
44605556 .attrs = decl_instance_attrs ++ .{
4461 .{ .linkage_name, .strp },
5557 .{ .linkage_name, .strx },
44625558 .{ .type, .ref_addr },
44635559 .{ .alignment, .udata },
44645560 .{ .external, .flag },
44655561 .{ .const_value, .block },
44665562 },
44675563 },
4468 .decl_instance_const_comptime_state = .{
5564 .decl_instance_const_partially_comptime = .{
44695565 .tag = .constant,
44705566 .attrs = decl_instance_attrs ++ .{
4471 .{ .linkage_name, .strp },
5567 .{ .linkage_name, .strx },
44725568 .{ .type, .ref_addr },
44735569 .{ .alignment, .udata },
44745570 .{ .external, .flag },
5571 .{ .const_value, .block },
44755572 .{ .ZIG_comptime_value, .ref_addr },
44765573 },
44775574 },
4478 .decl_instance_const_runtime_bits_comptime_state = .{
5575 .decl_instance_const_fully_comptime = .{
44795576 .tag = .constant,
44805577 .attrs = decl_instance_attrs ++ .{
4481 .{ .linkage_name, .strp },
5578 .{ .linkage_name, .strx },
44825579 .{ .type, .ref_addr },
44835580 .{ .alignment, .udata },
44845581 .{ .external, .flag },
4485 .{ .const_value, .block },
44865582 .{ .ZIG_comptime_value, .ref_addr },
44875583 },
44885584 },
4489 .decl_instance_nullary_func = .{
4490 .tag = .subprogram,
5585 .decl_instance_var = .{
5586 .tag = .variable,
44915587 .attrs = decl_instance_attrs ++ .{
4492 .{ .linkage_name, .strp },
5588 .{ .linkage_name, .strx },
44935589 .{ .type, .ref_addr },
4494 .{ .low_pc, .addr },
4495 .{ .high_pc, .data4 },
5590 .{ .location, .exprloc },
44965591 .{ .alignment, .udata },
44975592 .{ .external, .flag },
4498 .{ .noreturn, .flag },
44995593 },
45005594 },
4501 .decl_instance_func = .{
5595 .decl_instance_empty_func = .{
45025596 .tag = .subprogram,
4503 .children = true,
45045597 .attrs = decl_instance_attrs ++ .{
4505 .{ .linkage_name, .strp },
5598 .{ .linkage_name, .strx },
45065599 .{ .type, .ref_addr },
4507 .{ .low_pc, .addr },
5600 .{ .low_pc, .addrx },
45085601 .{ .high_pc, .data4 },
45095602 .{ .alignment, .udata },
45105603 .{ .external, .flag },
45115604 .{ .noreturn, .flag },
45125605 },
45135606 },
4514 .decl_instance_nullary_func_generic = .{
4515 .tag = .subprogram,
4516 .attrs = decl_instance_attrs ++ .{
4517 .{ .type, .ref_addr },
4518 },
4519 },
4520 .decl_instance_func_generic = .{
5607 .decl_instance_func = .{
45215608 .tag = .subprogram,
45225609 .children = true,
45235610 .attrs = decl_instance_attrs ++ .{
5611 .{ .linkage_name, .strx },
45245612 .{ .type, .ref_addr },
5613 .{ .low_pc, .addrx },
5614 .{ .high_pc, .data4 },
5615 .{ .alignment, .udata },
5616 .{ .external, .flag },
5617 .{ .noreturn, .flag },
45255618 },
45265619 },
4527 .decl_instance_extern_nullary_func = .{
5620 .decl_instance_empty_func_generic = .{
45285621 .tag = .subprogram,
45295622 .attrs = decl_instance_attrs ++ .{
4530 .{ .linkage_name, .strp },
45315623 .{ .type, .ref_addr },
4532 .{ .low_pc, .addr },
4533 .{ .external, .flag_present },
4534 .{ .noreturn, .flag },
45355624 },
45365625 },
4537 .decl_instance_extern_func = .{
5626 .decl_instance_func_generic = .{
45385627 .tag = .subprogram,
45395628 .children = true,
45405629 .attrs = decl_instance_attrs ++ .{
4541 .{ .linkage_name, .strp },
45425630 .{ .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 },
45765631 },
45775632 },
45785633 .empty_file = .{
45795634 .tag = .structure_type,
45805635 .attrs = &.{
45815636 .{ .decl_file, .udata },
4582 .{ .name, .strp },
5637 .{ .name, .strx },
45835638 .{ .declaration, .flag },
45845639 },
45855640 },
......@@ -4588,7 +5643,7 @@ pub const AbbrevCode = enum {
45885643 .children = true,
45895644 .attrs = &.{
45905645 .{ .decl_file, .udata },
4591 .{ .name, .strp },
5646 .{ .name, .strx },
45925647 .{ .byte_size, .udata },
45935648 .{ .alignment, .udata },
45945649 },
......@@ -4596,20 +5651,20 @@ pub const AbbrevCode = enum {
45965651 .access = .{
45975652 .tag = .member,
45985653 .attrs = &.{
4599 .{ .name, .strp },
5654 .{ .name, .strx },
46005655 },
46015656 },
46025657 .enum_field = .{
46035658 .tag = .enumerator,
46045659 .attrs = &.{
46055660 .{ .const_value, .indirect },
4606 .{ .name, .strp },
5661 .{ .name, .strx },
46075662 },
46085663 },
46095664 .generated_field = .{
46105665 .tag = .member,
46115666 .attrs = &.{
4612 .{ .name, .strp },
5667 .{ .name, .strx },
46135668 .{ .type, .ref_addr },
46145669 .{ .data_member_location, .udata },
46155670 .{ .artificial, .flag_present },
......@@ -4618,7 +5673,7 @@ pub const AbbrevCode = enum {
46185673 .field = .{
46195674 .tag = .member,
46205675 .attrs = &.{
4621 .{ .name, .strp },
5676 .{ .name, .strx },
46225677 .{ .type, .ref_addr },
46235678 .{ .data_member_location, .udata },
46245679 .{ .alignment, .udata },
......@@ -4627,7 +5682,7 @@ pub const AbbrevCode = enum {
46275682 .field_default_fully_runtime = .{
46285683 .tag = .member,
46295684 .attrs = &.{
4630 .{ .name, .strp },
5685 .{ .name, .strx },
46315686 .{ .type, .ref_addr },
46325687 .{ .data_member_location, .udata },
46335688 .{ .alignment, .udata },
......@@ -4637,7 +5692,7 @@ pub const AbbrevCode = enum {
46375692 .field_default_partially_comptime = .{
46385693 .tag = .member,
46395694 .attrs = &.{
4640 .{ .name, .strp },
5695 .{ .name, .strx },
46415696 .{ .type, .ref_addr },
46425697 .{ .data_member_location, .udata },
46435698 .{ .alignment, .udata },
......@@ -4648,7 +5703,7 @@ pub const AbbrevCode = enum {
46485703 .field_default_fully_comptime = .{
46495704 .tag = .member,
46505705 .attrs = &.{
4651 .{ .name, .strp },
5706 .{ .name, .strx },
46525707 .{ .type, .ref_addr },
46535708 .{ .data_member_location, .udata },
46545709 .{ .alignment, .udata },
......@@ -4659,7 +5714,7 @@ pub const AbbrevCode = enum {
46595714 .tag = .member,
46605715 .attrs = &.{
46615716 .{ .const_expr, .flag_present },
4662 .{ .name, .strp },
5717 .{ .name, .strx },
46635718 .{ .type, .ref_addr },
46645719 },
46655720 },
......@@ -4667,7 +5722,7 @@ pub const AbbrevCode = enum {
46675722 .tag = .member,
46685723 .attrs = &.{
46695724 .{ .const_expr, .flag_present },
4670 .{ .name, .strp },
5725 .{ .name, .strx },
46715726 .{ .type, .ref_addr },
46725727 .{ .const_value, .block },
46735728 },
......@@ -4676,7 +5731,7 @@ pub const AbbrevCode = enum {
46765731 .tag = .member,
46775732 .attrs = &.{
46785733 .{ .const_expr, .flag_present },
4679 .{ .name, .strp },
5734 .{ .name, .strx },
46805735 .{ .type, .ref_addr },
46815736 .{ .const_value, .block },
46825737 .{ .ZIG_comptime_value, .ref_addr },
......@@ -4686,7 +5741,7 @@ pub const AbbrevCode = enum {
46865741 .tag = .member,
46875742 .attrs = &.{
46885743 .{ .const_expr, .flag_present },
4689 .{ .name, .strp },
5744 .{ .name, .strx },
46905745 .{ .type, .ref_addr },
46915746 .{ .ZIG_comptime_value, .ref_addr },
46925747 },
......@@ -4694,7 +5749,7 @@ pub const AbbrevCode = enum {
46945749 .packed_field = .{
46955750 .tag = .member,
46965751 .attrs = &.{
4697 .{ .name, .strp },
5752 .{ .name, .strx },
46985753 .{ .type, .ref_addr },
46995754 .{ .data_bit_offset, .udata },
47005755 },
......@@ -4720,13 +5775,13 @@ pub const AbbrevCode = enum {
47205775 .void_type = .{
47215776 .tag = .unspecified_type,
47225777 .attrs = &.{
4723 .{ .name, .strp },
5778 .{ .name, .strx },
47245779 },
47255780 },
47265781 .numeric_type = .{
47275782 .tag = .base_type,
47285783 .attrs = &.{
4729 .{ .name, .strp },
5784 .{ .name, .strx },
47305785 .{ .encoding, .data1 },
47315786 .{ .bit_size, .udata },
47325787 .{ .byte_size, .udata },
......@@ -4736,14 +5791,14 @@ pub const AbbrevCode = enum {
47365791 .inferred_error_set_type = .{
47375792 .tag = .typedef,
47385793 .attrs = &.{
4739 .{ .name, .strp },
5794 .{ .name, .strx },
47405795 .{ .type, .ref_addr },
47415796 },
47425797 },
47435798 .ptr_type = .{
47445799 .tag = .pointer_type,
47455800 .attrs = &.{
4746 .{ .name, .strp },
5801 .{ .name, .strx },
47475802 .{ .address_class, .data1 },
47485803 .{ .type, .ref_addr },
47495804 },
......@@ -4751,28 +5806,16 @@ pub const AbbrevCode = enum {
47515806 .ptr_sentinel_type = .{
47525807 .tag = .pointer_type,
47535808 .attrs = &.{
4754 .{ .name, .strp },
5809 .{ .name, .strx },
47555810 .{ .ZIG_sentinel, .block },
47565811 .{ .address_class, .data1 },
47575812 .{ .type, .ref_addr },
47585813 },
47595814 },
4760 .ptr_aligned_type = .{
4761 .tag = .pointer_type,
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,
5815 .is_aligned = .{
5816 .tag = .typedef,
47715817 .attrs = &.{
4772 .{ .name, .strp },
4773 .{ .ZIG_sentinel, .block },
47745818 .{ .alignment, .udata },
4775 .{ .address_class, .data1 },
47765819 .{ .type, .ref_addr },
47775820 },
47785821 },
......@@ -4792,7 +5835,7 @@ pub const AbbrevCode = enum {
47925835 .tag = .array_type,
47935836 .children = true,
47945837 .attrs = &.{
4795 .{ .name, .strp },
5838 .{ .name, .strx },
47965839 .{ .type, .ref_addr },
47975840 },
47985841 },
......@@ -4800,7 +5843,7 @@ pub const AbbrevCode = enum {
48005843 .tag = .array_type,
48015844 .children = true,
48025845 .attrs = &.{
4803 .{ .name, .strp },
5846 .{ .name, .strx },
48045847 .{ .ZIG_sentinel, .block },
48055848 .{ .type, .ref_addr },
48065849 },
......@@ -4809,7 +5852,7 @@ pub const AbbrevCode = enum {
48095852 .tag = .array_type,
48105853 .children = true,
48115854 .attrs = &.{
4812 .{ .name, .strp },
5855 .{ .name, .strx },
48135856 .{ .type, .ref_addr },
48145857 .{ .GNU_vector, .flag_present },
48155858 },
......@@ -4827,10 +5870,10 @@ pub const AbbrevCode = enum {
48275870 .{ .count, .udata },
48285871 },
48295872 },
4830 .nullary_func_type = .{
5873 .empty_func_type = .{
48315874 .tag = .subroutine_type,
48325875 .attrs = &.{
4833 .{ .name, .strp },
5876 .{ .name, .strx },
48345877 .{ .calling_convention, .data1 },
48355878 .{ .type, .ref_addr },
48365879 },
......@@ -4839,7 +5882,7 @@ pub const AbbrevCode = enum {
48395882 .tag = .subroutine_type,
48405883 .children = true,
48415884 .attrs = &.{
4842 .{ .name, .strp },
5885 .{ .name, .strx },
48435886 .{ .calling_convention, .data1 },
48445887 .{ .type, .ref_addr },
48455888 },
......@@ -4847,7 +5890,7 @@ pub const AbbrevCode = enum {
48475890 .param = .{
48485891 .tag = .formal_parameter,
48495892 .attrs = &.{
4850 .{ .name, .strp },
5893 .{ .name, .strx },
48515894 .{ .type, .ref_addr },
48525895 },
48535896 },
......@@ -4863,7 +5906,7 @@ pub const AbbrevCode = enum {
48635906 .generated_empty_enum_type = .{
48645907 .tag = .enumeration_type,
48655908 .attrs = &.{
4866 .{ .name, .strp },
5909 .{ .name, .strx },
48675910 .{ .type, .ref_addr },
48685911 },
48695912 },
......@@ -4871,14 +5914,14 @@ pub const AbbrevCode = enum {
48715914 .tag = .enumeration_type,
48725915 .children = true,
48735916 .attrs = &.{
4874 .{ .name, .strp },
5917 .{ .name, .strx },
48755918 .{ .type, .ref_addr },
48765919 },
48775920 },
48785921 .generated_empty_struct_type = .{
48795922 .tag = .structure_type,
48805923 .attrs = &.{
4881 .{ .name, .strp },
5924 .{ .name, .strx },
48825925 .{ .declaration, .flag },
48835926 },
48845927 },
......@@ -4886,7 +5929,7 @@ pub const AbbrevCode = enum {
48865929 .tag = .structure_type,
48875930 .children = true,
48885931 .attrs = &.{
4889 .{ .name, .strp },
5932 .{ .name, .strx },
48905933 .{ .byte_size, .udata },
48915934 .{ .alignment, .udata },
48925935 },
......@@ -4895,7 +5938,7 @@ pub const AbbrevCode = enum {
48955938 .tag = .union_type,
48965939 .children = true,
48975940 .attrs = &.{
4898 .{ .name, .strp },
5941 .{ .name, .strx },
48995942 .{ .byte_size, .udata },
49005943 .{ .alignment, .udata },
49015944 },
......@@ -4903,7 +5946,7 @@ pub const AbbrevCode = enum {
49035946 .capture_specification = .{
49045947 .tag = .template_value_parameter,
49055948 .attrs = &.{
4906 .{ .name, .strp },
5949 .{ .name, .strx },
49075950 },
49085951 },
49095952 .comptime_capture = .{
......@@ -4946,11 +5989,11 @@ pub const AbbrevCode = enum {
49465989 .{ .location, .exprloc },
49475990 },
49485991 },
4949 .builtin_extern_nullary_func = .{
5992 .builtin_extern_empty_func = .{
49505993 .tag = .subprogram,
49515994 .attrs = &.{
49525995 .{ .ZIG_parent, .ref_addr },
4953 .{ .linkage_name, .strp },
5996 .{ .linkage_name, .strx },
49545997 .{ .type, .ref_addr },
49555998 .{ .low_pc, .addr },
49565999 .{ .external, .flag_present },
......@@ -4962,7 +6005,7 @@ pub const AbbrevCode = enum {
49626005 .children = true,
49636006 .attrs = &.{
49646007 .{ .ZIG_parent, .ref_addr },
4965 .{ .linkage_name, .strp },
6008 .{ .linkage_name, .strx },
49666009 .{ .type, .ref_addr },
49676010 .{ .low_pc, .addr },
49686011 .{ .external, .flag_present },
......@@ -4973,9 +6016,10 @@ pub const AbbrevCode = enum {
49736016 .tag = .variable,
49746017 .attrs = &.{
49756018 .{ .ZIG_parent, .ref_addr },
4976 .{ .linkage_name, .strp },
6019 .{ .linkage_name, .strx },
49776020 .{ .type, .ref_addr },
49786021 .{ .location, .exprloc },
6022 .{ .alignment, .udata },
49796023 .{ .external, .flag_present },
49806024 },
49816025 },
......@@ -5018,7 +6062,7 @@ pub const AbbrevCode = enum {
50186062 .arg = .{
50196063 .tag = .formal_parameter,
50206064 .attrs = &.{
5021 .{ .name, .strp },
6065 .{ .name, .strx },
50226066 .{ .type, .ref_addr },
50236067 .{ .location, .exprloc },
50246068 },
......@@ -5034,7 +6078,7 @@ pub const AbbrevCode = enum {
50346078 .tag = .formal_parameter,
50356079 .attrs = &.{
50366080 .{ .const_expr, .flag_present },
5037 .{ .name, .strp },
6081 .{ .name, .strx },
50386082 .{ .type, .ref_addr },
50396083 },
50406084 },
......@@ -5042,7 +6086,7 @@ pub const AbbrevCode = enum {
50426086 .tag = .formal_parameter,
50436087 .attrs = &.{
50446088 .{ .const_expr, .flag_present },
5045 .{ .name, .strp },
6089 .{ .name, .strx },
50466090 .{ .type, .ref_addr },
50476091 .{ .const_value, .block },
50486092 },
......@@ -5051,7 +6095,7 @@ pub const AbbrevCode = enum {
50516095 .tag = .formal_parameter,
50526096 .attrs = &.{
50536097 .{ .const_expr, .flag_present },
5054 .{ .name, .strp },
6098 .{ .name, .strx },
50556099 .{ .type, .ref_addr },
50566100 .{ .const_value, .block },
50576101 .{ .ZIG_comptime_value, .ref_addr },
......@@ -5061,7 +6105,7 @@ pub const AbbrevCode = enum {
50616105 .tag = .formal_parameter,
50626106 .attrs = &.{
50636107 .{ .const_expr, .flag_present },
5064 .{ .name, .strp },
6108 .{ .name, .strx },
50656109 .{ .type, .ref_addr },
50666110 .{ .ZIG_comptime_value, .ref_addr },
50676111 },
......@@ -5107,7 +6151,7 @@ pub const AbbrevCode = enum {
51076151 .local_var = .{
51086152 .tag = .variable,
51096153 .attrs = &.{
5110 .{ .name, .strp },
6154 .{ .name, .strx },
51116155 .{ .type, .ref_addr },
51126156 .{ .location, .exprloc },
51136157 },
......@@ -5115,14 +6159,14 @@ pub const AbbrevCode = enum {
51156159 .local_const = .{
51166160 .tag = .constant,
51176161 .attrs = &.{
5118 .{ .name, .strp },
6162 .{ .name, .strx },
51196163 .{ .type, .ref_addr },
51206164 },
51216165 },
51226166 .local_const_fully_runtime = .{
51236167 .tag = .constant,
51246168 .attrs = &.{
5125 .{ .name, .strp },
6169 .{ .name, .strx },
51266170 .{ .type, .ref_addr },
51276171 .{ .const_value, .block },
51286172 },
......@@ -5130,7 +6174,7 @@ pub const AbbrevCode = enum {
51306174 .local_const_partially_comptime = .{
51316175 .tag = .constant,
51326176 .attrs = &.{
5133 .{ .name, .strp },
6177 .{ .name, .strx },
51346178 .{ .type, .ref_addr },
51356179 .{ .const_value, .block },
51366180 .{ .ZIG_comptime_value, .ref_addr },
......@@ -5139,7 +6183,7 @@ pub const AbbrevCode = enum {
51396183 .local_const_fully_comptime = .{
51406184 .tag = .constant,
51416185 .attrs = &.{
5142 .{ .name, .strp },
6186 .{ .name, .strx },
51436187 .{ .type, .ref_addr },
51446188 .{ .ZIG_comptime_value, .ref_addr },
51456189 },
......@@ -5187,32 +6231,64 @@ pub const AbbrevCode = enum {
51876231 .{ .location, .exprloc },
51886232 },
51896233 },
5190 .comptime_value_field_runtime_bits = .{
6234 .comptime_value_field_runtime = .{
51916235 .tag = .member,
51926236 .attrs = &.{
5193 .{ .name, .strp },
6237 .{ .name, .strx },
51946238 .{ .const_value, .block },
51956239 },
51966240 },
5197 .comptime_value_field_comptime_state = .{
6241 .comptime_value_field_comptime = .{
51986242 .tag = .member,
51996243 .attrs = &.{
5200 .{ .name, .strp },
6244 .{ .name, .strx },
52016245 .{ .ZIG_comptime_value, .ref_addr },
52026246 },
52036247 },
5204 .comptime_value_elem_runtime_bits = .{
6248 .comptime_value_elem_runtime = .{
52056249 .tag = .member,
52066250 .attrs = &.{
52076251 .{ .const_value, .block },
52086252 },
52096253 },
5210 .comptime_value_elem_comptime_state = .{
6254 .comptime_value_elem_comptime = .{
52116255 .tag = .member,
52126256 .attrs = &.{
52136257 .{ .ZIG_comptime_value, .ref_addr },
52146258 },
52156259 },
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 },
52166292 });
52176293};
52186294
src/link/Elf2.zig+405-179
......@@ -53,6 +53,7 @@ shndx: struct {
5353 rela_dyn: Section.Index,
5454 rela_plt: Section.Index,
5555 debug_abbrev: Section.Index,
56 debug_addr: Section.Index,
5657 eh_frame_hdr: Section.Index,
5758 eh_frame: Section.Index,
5859 debug_frame: Section.Index,
......@@ -215,6 +216,8 @@ textrel_count: u32,
215216
216217dwarf: Dwarf,
217218dwarf_shared: std.enums.EnumArray(Dwarf.SharedSection, dwarf_relocs.Shared),
219dwarf_addr: dwarf_relocs.Addr,
220dwarf_str_offsets: dwarf_relocs.StrOffsets,
218221dwarf_units: []dwarf_relocs.Unit,
219222dwarf_consts: std.array_hash_map.Auto(link.ConstPool.Index, dwarf_relocs.Const),
220223dwarf_globals: std.ArrayList(dwarf_relocs.Global),
......@@ -286,7 +289,9 @@ const Node = union(enum) {
286289 lazy_const_data: LazyMapRef.Index(.const_data),
287290
288291 debug_shared: Dwarf.SharedSection,
292 debug_addr,
289293 eh_frame_footer,
294 debug_str_offsets,
290295 unit_padding,
291296 unit_frame: Dwarf.Unit.Index,
292297 unit_frame_cie: Dwarf.Unit.Index,
......@@ -880,6 +885,14 @@ const dwarf_relocs = struct {
880885 const Shared = struct {
881886 first_target_reloc: NodeReloc.Index,
882887 };
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 };
883896 const Unit = struct {
884897 frame_cie_first_target_reloc: NodeReloc.Index,
885898 debug_info_header_first_target_reloc: NodeReloc.Index,
......@@ -887,7 +900,7 @@ const dwarf_relocs = struct {
887900 debug_line_header_first_target_reloc: NodeReloc.Index,
888901 debug_line_header_first_node_reloc: NodeReloc.Index,
889902 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),
891904 };
892905 const Const = struct {
893906 debug_info_first_target_reloc: NodeReloc.Index,
......@@ -3346,7 +3359,9 @@ pub fn symbolForAtom(elf: *Elf, atom: link.File.AtomId) link.File.SymbolId {
33463359 .input_section,
33473360 .copied_global,
33483361 .debug_shared,
3362 .debug_addr,
33493363 .eh_frame_footer,
3364 .debug_str_offsets,
33503365 .unit_padding,
33513366 .unit_frame,
33523367 .unit_frame_cie,
......@@ -3800,6 +3815,7 @@ fn create(
38003815 .rela_dyn = .UNDEF,
38013816 .rela_plt = .UNDEF,
38023817 .debug_abbrev = .UNDEF,
3818 .debug_addr = .UNDEF,
38033819 .eh_frame_hdr = .UNDEF,
38043820 .eh_frame = .UNDEF,
38053821 .debug_frame = .UNDEF,
......@@ -3866,6 +3882,14 @@ fn create(
38663882 .dwarf_shared = comptime .initFill(.{
38673883 .first_target_reloc = .none,
38683884 }),
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 },
38693893 .dwarf_units = &.{},
38703894 .dwarf_consts = .empty,
38713895 .dwarf_globals = .empty,
......@@ -3921,6 +3945,8 @@ pub fn deinit(elf: *Elf) void {
39213945 elf.changed_symtab_index.deinit(gpa);
39223946
39233947 elf.dwarf.deinit();
3948 elf.dwarf_addr.symbol_relocs.deinit(gpa);
3949 elf.dwarf_str_offsets.node_relocs.deinit(gpa);
39243950 for (elf.dwarf_units) |*dwarf_unit| dwarf_unit.debug_rnglists_symbol_relocs.deinit(gpa);
39253951 gpa.free(elf.dwarf_units);
39263952 elf.dwarf_consts.deinit(gpa);
......@@ -4000,6 +4026,7 @@ fn initHeaders(
40004026 .strip => {},
40014027 .dwarf => {
40024028 shnum += 1; // .debug_abbrev
4029 shnum += 1; // .debug_addr
40034030 shnum += @intFromBool(have_debug_frame); // .debug_frame
40044031 shnum += 1; // .debug_info
40054032 shnum += 1; // .debug_line
......@@ -5104,6 +5131,11 @@ fn initHeaders(
51045131 .strip => {},
51055132 .dwarf => {
51065133 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 });
51075139 if (have_debug_frame) elf.shndx.debug_frame = try elf.addSection(elf.ni.elf, .{
51085140 .name = ".debug_frame",
51095141 .addralign = addr_align,
......@@ -5132,6 +5164,11 @@ fn initHeaders(
51325164 });
51335165 elf.shndx.debug_str_offsets = try elf.addSection(elf.ni.elf, .{
51345166 .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,
51355172 });
51365173 },
51375174 .code_view => unreachable,
......@@ -5226,7 +5263,9 @@ fn getNodeShndx(elf: *const Elf, ni: MappedFile.Node.Index) Section.Index {
52265263 .lazy_code,
52275264 .lazy_const_data,
52285265 .debug_shared,
5266 .debug_addr,
52295267 .eh_frame_footer,
5268 .debug_str_offsets,
52305269 .unit_padding,
52315270 .unit_frame,
52325271 .unit_debug_info,
......@@ -5273,7 +5312,9 @@ fn getNodeVAddr(elf: *Elf, ni: MappedFile.Node.Index) u64 {
52735312 .lazy_const_data,
52745313 => |i| Symbol.Id.local(i.symbol(elf)).value(elf),
52755314 .debug_shared,
5315 .debug_addr,
52765316 .eh_frame_footer,
5317 .debug_str_offsets,
52775318 .unit_padding,
52785319 .unit_frame,
52795320 .unit_frame_cie,
......@@ -5313,7 +5354,7 @@ fn computeNodeVAddr(elf: *Elf, ni: MappedFile.Node.Index) u64 {
53135354 .lazy_code,
53145355 .lazy_const_data,
53155356 => |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,
53175358 .unit_frame, .unit_debug_info, .unit_debug_line => {
53185359 const section_offset, _ = parent_ni.location(&elf.mf).resolve(&elf.mf);
53195360 break :parent_vaddr elf.getNodeShndx(parent_ni).vaddr(elf) + section_offset;
......@@ -5350,7 +5391,7 @@ fn computeNodeSectionOffset(elf: *Elf, ni: MappedFile.Node.Index) u64 {
53505391 .section, .section_manual_size => 0,
53515392 .input_section, .copied_global => unreachable,
53525393 .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,
53545395 .unit_frame, .unit_debug_info, .unit_debug_line => {
53555396 const parent_section_offset, _ = parent_ni.location(&elf.mf).resolve(&elf.mf);
53565397 break :parent_section_offset parent_section_offset;
......@@ -5399,7 +5440,9 @@ pub fn resetNodeRelocs(elf: *Elf, ni: MappedFile.Node.Index) void {
53995440 .segment,
54005441 .copied_global,
54015442 .debug_shared,
5443 .debug_addr,
54025444 .eh_frame_footer,
5445 .debug_str_offsets,
54035446 .unit_padding,
54045447 .unit_frame,
54055448 .unit_frame_cie,
......@@ -5856,10 +5899,11 @@ fn dynsymPtr(elf: *Elf, index: u32) SymPtr {
58565899}
58575900
58585901fn 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;
58605904 return if (any_non_single_threaded and nav_resolved.@"threadlocal")
58615905 .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))
58635907 .FUNC
58645908 else
58655909 .OBJECT;
......@@ -7162,8 +7206,8 @@ fn updateInitFiniArraySectionSize(
71627206}
71637207
71647208pub fn prelink(elf: *Elf, prog_node: std.Progress.Node) link.Error!void {
7165 const sub_prog_node = prog_node.start("ELF Prelink", 0);
7166 defer sub_prog_node.end();
7209 const prelink_prog_node = prog_node.start("ELF Prelink", 0);
7210 defer prelink_prog_node.end();
71677211
71687212 const diags = &elf.base.comp.link_diags;
71697213 elf.prelinkInner() catch |err| switch (err) {
......@@ -7197,45 +7241,20 @@ fn prelinkInner(elf: *Elf) Error!void {
71977241 };
71987242 elf.input_pending_index += 1;
71997243
7200 try elf.nodes.ensureUnusedCapacity(gpa, 5 + 4);
7201
7202 switch (elf.shndx.debug_abbrev) {
7203 .UNDEF => {},
7204 else => |debug_abbrev_shndx| elf.dwarf.debug_abbrev.ni = .wrap(elf.addNodeAssumeCapacity(
7205 try debug_abbrev_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{}),
7206 .{ .debug_shared = .debug_abbrev },
7207 )),
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{
7244 const addr_align: Alignment = switch (elf.identClass()) {
7245 .NONE, _ => unreachable,
7246 .@"32" => .@"4",
7247 .@"64" => .@"8",
7248 };
7249 try elf.nodes.ensureUnusedCapacity(gpa, 7 + 5);
7250 for ([7]Section.Index{
7251 elf.shndx.debug_addr,
72347252 elf.shndx.eh_frame,
72357253 elf.shndx.debug_frame,
72367254 elf.shndx.debug_info,
72377255 elf.shndx.debug_line,
72387256 elf.shndx.debug_rnglists,
7257 elf.shndx.debug_str_offsets,
72397258 }) |debug_shndx| {
72407259 if (debug_shndx == .UNDEF) continue;
72417260 const debug_ni = debug_shndx.get(elf).ni;
......@@ -7251,11 +7270,7 @@ fn prelinkInner(elf: *Elf) Error!void {
72517270 };
72527271 break :last_header_oni last_header_oni;
72537272 }, .{
7254 .alignment = if (frame_format) |_| switch (elf.identClass()) {
7255 .NONE, _ => unreachable,
7256 .@"32" => .@"4",
7257 .@"64" => .@"8",
7258 } else .@"1",
7273 .alignment = if (frame_format) |_| addr_align else .@"1",
72597274 .next_moved = true,
72607275 .enable_next_moved = true,
72617276 }),
......@@ -7271,6 +7286,75 @@ fn prelinkInner(elf: *Elf) Error!void {
72717286 error.WriteFailed => return debug_nw.err.?,
72727287 };
72737288 }
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 }
72747358 }
72757359}
72767360
......@@ -7301,7 +7385,7 @@ fn zcuFilesReadyInner(elf: *Elf, zcu: *Zcu) Error!void {
73017385 });
73027386 }
73037387 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);
73057389 for (0..units_len) |unit_index| {
73067390 const ui: Dwarf.Unit.Index = @fromBackingInt(@intCast(unit_index));
73077391 const unit = ui.get(&elf.dwarf);
......@@ -7396,6 +7480,7 @@ fn zcuFilesReadyInner(elf: *Elf, zcu: *Zcu) Error!void {
73967480 error.WriteFailed => return dih_nw.err.?,
73977481 };
73987482 }
7483 try elf.genPendingDebug(gpa);
73997484}
74007485
74017486fn flushFiles(elf: *Elf) Error!void {
......@@ -7406,7 +7491,6 @@ fn flushFiles(elf: *Elf) Error!void {
74067491 const debug_line_header_ni = unit.debug_line_header_ni.unwrap().?;
74077492 try debug_line_header_ni.parent(&elf.mf).unwrap().?.nextMoved(gpa, &elf.mf);
74087493 try debug_line_header_ni.moved(gpa, &elf.mf);
7409 try debug_line_header_ni.nextMoved(gpa, &elf.mf);
74107494 var dlh_nw: MappedFile.Node.Writer = undefined;
74117495 debug_line_header_ni.writer(gpa, &elf.mf, &dlh_nw);
74127496 defer dlh_nw.deinit();
......@@ -8221,6 +8305,8 @@ fn addNodeRelocAssumeCapacity(
82218305 const first_target_reloc = switch (elf.getNode(target)) {
82228306 else => unreachable,
82238307 .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,
82248310 .unit_frame_cie => |ui| &elf.dwarf_units[@backingInt(ui)].frame_cie_first_target_reloc,
82258311 .unit_debug_info_header => |ui| &elf.dwarf_units[@backingInt(ui)].debug_info_header_first_target_reloc,
82268312 .unit_debug_line_header => |ui| &elf.dwarf_units[@backingInt(ui)].debug_line_header_first_target_reloc,
......@@ -8326,7 +8412,9 @@ fn addGotRelocAssumeCapacity(
83268412 .segment,
83278413 .copied_global,
83288414 .debug_shared,
8415 .debug_addr,
83298416 .eh_frame_footer,
8417 .debug_str_offsets,
83308418 .unit_padding,
83318419 .unit_frame,
83328420 .unit_frame_cie,
......@@ -8632,38 +8720,77 @@ fn updateNavInner(elf: *Elf, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index)
86328720 const ip = &zcu.intern_pool;
86338721
86348722 const nav = ip.getNav(nav_index);
8635 if (ip.indexToKey(nav.resolved.?.value) == .@"extern") return;
8636 if (!Type.fromInterned(nav.resolved.?.type).hasRuntimeBits(zcu)) {
8637 if (elf.ehdrMachine() != .X86_64) return;
8638 const mod = zcu.fileByIndex(nav.srcInst(ip).resolveFile(ip)).mod.?;
8639 return if (!mod.strip) elf.dwarf.updateComptimeNav(pt, nav_index);
8640 }
8723 const mod = zcu.fileByIndex(nav.srcInst(ip).resolveFile(ip)).mod.?;
8724 switch (ip.indexToKey(nav.resolved.?.value)) {
8725 .@"extern" => |@"extern"| {
8726 if (mod.strip or elf.ehdrMachine() != .X86_64) return;
8727 const si = try elf.externSymbol(.{
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);
8643 const ni = nmi.symbol(elf).index().ptr(elf).node.unwrap().?;
8752 // Ensure the NAV is marked as moved so that once we're done, `flushMoved`
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 be
8646 // called to apply the NAV's new relocations.
8647 try ni.moved(gpa, &elf.mf);
8756 {
8757 var nw: MappedFile.Node.Writer = undefined;
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 {
8650 var nw: MappedFile.Node.Writer = undefined;
8651 ni.writer(gpa, &elf.mf, &nw);
8652 defer nw.deinit();
8653 elf.resetNodeRelocs(ni);
8654 codegen.generateSymbol(
8655 &elf.base,
8656 pt,
8657 .fromInterned(nav.resolved.?.value),
8658 &nw.interface,
8659 .{ .atom_index = Node.toAtom(ni) },
8660 ) catch |err| switch (err) {
8661 else => |e| return e,
8662 error.WriteFailed => return nw.err.?,
8663 };
8664 switch (elf.symPtr(nmi.symbol(elf).index())) {
8665 inline else => |sym| elf.targetStore(&sym.size, @intCast(nw.interface.end)),
8666 }
8776 if (!mod.strip and elf.ehdrMachine() == .X86_64) {
8777 const dwarf_gi = try elf.dwarf.getGlobal(nav_index);
8778 const dwarf_global = dwarf_gi.get(&elf.dwarf);
8779 const debug_info_ni = dwarf_global.debug_info_ni.unwrap().?;
8780 try debug_info_ni.moved(gpa, &elf.mf);
8781 var di_nw: MappedFile.Node.Writer = undefined;
8782 debug_info_ni.writer(gpa, &elf.mf, &di_nw);
8783 defer di_nw.deinit();
8784 elf.resetNodeRelocs(debug_info_ni);
8785 try elf.dwarf.updateGlobal(pt, &di_nw, switch (elf.ehdrMachine()) {
8786 else => unreachable,
8787 .X86_64 => .x86_64,
8788 }, Symbol.Id.local(lsi).toTypeErased(), nav_index);
8789 }
8790 } else {
8791 if (mod.strip or elf.ehdrMachine() != .X86_64) return;
8792 try elf.dwarf.updateComptimeGlobal(pt, nav_index);
8793 },
86678794 }
86688795
86698796 // 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(
87268853 .code_view => unreachable,
87278854 }
87288855}
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 {
87308861 const elf = lf.cast(.elf2).?;
87318862 const unit = ui.get(&elf.dwarf);
87328863 const debug_info_ni = elf.addNodeAssumeCapacity(
......@@ -8769,17 +8900,18 @@ fn updateConstInner(
87698900 switch (elf.base.comp.config.debug_format) {
87708901 .strip => {},
87718902 .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 }
87728914 {
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 }
87838915 const gpa = elf.base.comp.gpa;
87848916 const debug_info_ni = Dwarf.Const.get(cpi, &elf.dwarf).debug_info_ni.unwrap().?;
87858917 try debug_info_ni.moved(gpa, &elf.mf);
......@@ -8846,19 +8978,18 @@ fn updateFuncInner(
88468978 var nw: MappedFile.Node.Writer = undefined;
88478979 ni.writer(gpa, &elf.mf, &nw);
88488980 defer nw.deinit();
8849 var debug_output_buf: Dwarf.WipNav.Debug = undefined;
8981 var debug_output_buf: Dwarf.WipFunc.Debug = undefined;
88508982 const debug_output: link.File.DebugInfoOutput, const dwarf_func = debug_output: {
88518983 if (elf.ehdrMachine() != .X86_64) break :debug_output .{ .none, undefined };
88528984 const dwarf = &elf.dwarf;
8853 const src_inst = nav.srcInst(ip);
8854 const mod = zcu.fileByIndex(src_inst.resolveFile(ip)).mod.?;
8985 const mod = zcu.fileByIndex(nav.srcInst(ip).resolveFile(ip)).mod.?;
88558986 if (mod.strip and mod.unwind_tables == .none) break :debug_output .{ .none, undefined };
88568987
88578988 try elf.nodes.ensureUnusedCapacity(gpa, 4);
88588989 const dwarf_fi = try dwarf.getFunc(func.owner_nav);
88598990
8860 const wip_nav = &debug_output_buf.wip_nav;
8861 wip_nav.* = .{
8991 const wip_func = &debug_output_buf.wip_func;
8992 wip_func.* = .{
88628993 .dwarf = dwarf,
88638994 .unit = dwarf.getUnit(mod),
88648995 .func = func_index,
......@@ -8874,7 +9005,7 @@ fn updateFuncInner(
88749005 .fde_writer = undefined,
88759006 .frame_func_length = undefined,
88769007 };
8877 const unit = wip_nav.unit.get(dwarf);
9008 const unit = wip_func.unit.get(dwarf);
88789009
88799010 const frame_align: Alignment = switch (elf.identClass()) {
88809011 .NONE, _ => unreachable,
......@@ -8882,13 +9013,13 @@ fn updateFuncInner(
88829013 .@"64" => .@"8",
88839014 };
88849015 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) {
88869017 .debug_frame => elf.shndx.debug_frame,
88879018 .eh_frame => elf.shndx.eh_frame,
88889019 }.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{
88899020 .alignment = frame_align.max(elf.mf.flags.block_size),
88909021 .enable_next_moved = true,
8891 }), .{ .unit_frame = wip_nav.unit });
9022 }), .{ .unit_frame = wip_func.unit });
88929023 unit.frame_ni = .wrap(frame_ni);
88939024 break :frame_ni frame_ni;
88949025 };
......@@ -8899,7 +9030,7 @@ fn updateFuncInner(
88999030 .next_moved = true,
89009031 .enable_next_moved = true,
89019032 }),
8902 .{ .unit_frame_cie = wip_nav.unit },
9033 .{ .unit_frame_cie = wip_func.unit },
89039034 );
89049035 unit.cie_ni = .wrap(cie_ni);
89059036 var cie_nw: MappedFile.Node.Writer = undefined;
......@@ -8908,14 +9039,13 @@ fn updateFuncInner(
89089039 dwarf.genDebugFrameCie(&cie_nw.interface, switch (elf.ehdrMachine()) {
89099040 else => unreachable,
89109041 .X86_64 => .x86_64,
8911 }, wip_nav.frame_format) catch |err| switch (err) {
9042 }, wip_func.frame_format) catch |err| switch (err) {
89129043 error.WriteFailed => return cie_nw.err.?,
89139044 };
89149045 }
89159046 const dwarf_func = dwarf_fi.get(dwarf);
89169047 const fde_ni = if (dwarf_func.fde_ni.unwrap()) |fde_ni| fde_ni: {
89179048 try fde_ni.moved(gpa, &elf.mf);
8918 try fde_ni.nextMoved(gpa, &elf.mf);
89199049 break :fde_ni fde_ni;
89209050 } else fde_ni: {
89219051 const fde_ni = elf.addNodeAssumeCapacity(try frame_ni.addFloatingChild(gpa, &elf.mf, .{
......@@ -8927,22 +9057,16 @@ fn updateFuncInner(
89279057 dwarf_func.fde_ni = .wrap(fde_ni);
89289058 break :fde_ni fde_ni;
89299059 };
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
89349064 const debug = &debug_output_buf;
8935 debug.pt = pt;
8936 debug.any_children = false;
8937 debug.blocks = .empty;
9065 debug.init(pt);
89389066 dwarf_func.state = .resolved;
89399067
89409068 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 });
89449069 try debug_info_ni.moved(gpa, &elf.mf);
8945 try debug_info_ni.nextMoved(gpa, &elf.mf);
89469070 debug_info_ni.writer(gpa, &elf.mf, &debug.info_writer);
89479071
89489072 const debug_line_ni = dwarf_func.debug_line_ni.unwrap() orelse debug_line_ni: {
......@@ -8968,17 +9092,17 @@ fn updateFuncInner(
89689092 };
89699093 switch (debug_output) {
89709094 .dwarf => unreachable,
8971 .eh_frame => |wip_nav| {
9095 .eh_frame => |wip_func| {
89729096 elf.resetNodeRelocs(dwarf_func.fde_ni.unwrap().?);
8973 try wip_nav.genDebugFrameHeader();
9097 try wip_func.genDebugFrameHeader();
89749098 },
89759099 .dwarf2 => |debug| {
89769100 elf.resetNodeRelocs(dwarf_func.fde_ni.unwrap().?);
8977 try debug.wip_nav.genDebugFrameHeader();
9101 try debug.wip_func.genDebugFrameHeader();
89789102 elf.resetNodeRelocs(dwarf_func.debug_line_ni.unwrap().?);
89799103 try debug.startDebugLine();
89809104 elf.resetNodeRelocs(dwarf_func.debug_info_ni.unwrap().?);
8981 try debug.startFuncDebugInfo();
9105 try debug.startDebugInfo();
89829106 },
89839107 .none => {},
89849108 }
......@@ -9001,35 +9125,34 @@ fn updateFuncInner(
90019125 }
90029126 switch (debug_output) {
90039127 .dwarf => unreachable,
9004 .eh_frame => |wip_nav| wip_nav.finishDebugFrameFde(func_length),
9128 .eh_frame => |wip_func| wip_func.finishDebugFrameFde(func_length),
90059129 .dwarf2 => |debug| {
9006 try debug.finishFunc(func_length);
9007 const unit = debug.wip_nav.unit.get(debug.wip_nav.dwarf);
9130 try debug.finish(func_length);
9131 const unit = debug.wip_func.unit.get(debug.wip_func.dwarf);
90089132 {
90099133 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);
90119137 defer dr_nw.deinit();
9012 const first_symbol_reloc = elf.symbol_relocs.items.len;
9013 debug.wip_nav.dwarf.genDebugRnglists(
9138 const first_symbol_ri = elf.symbol_relocs.items.len;
9139 debug.wip_func.dwarf.genDebugRnglistsRange(
90149140 unit,
90159141 &dr_nw,
9016 debug.wip_nav.func_si,
9142 debug.wip_func.func_si,
90179143 func_length,
90189144 ) catch |err| switch (err) {
90199145 else => |e| return e,
90209146 error.WriteFailed => return dr_nw.err.?,
90219147 };
9022 const symbol_relocs = &elf.dwarf_units[@backingInt(debug.wip_nav.unit)]
9148 const symbol_relocs = &elf.dwarf_units[@backingInt(debug.wip_func.unit)]
90239149 .debug_rnglists_symbol_relocs;
90249150 try symbol_relocs.ensureUnusedCapacity(gpa, elf.symbol_relocs.items.len -
9025 first_symbol_reloc);
9026 for (first_symbol_reloc..elf.symbol_relocs.items.len) |symbol_ri|
9027 symbol_relocs.putAssumeCapacityNoClobber(
9028 @fromBackingInt(@intCast(symbol_ri)),
9029 {},
9030 );
9151 first_symbol_ri);
9152 for (first_symbol_ri..elf.symbol_relocs.items.len) |symbol_ri|
9153 symbol_relocs.appendAssumeCapacity(@fromBackingInt(@intCast(symbol_ri)));
90319154 }
9032 debug.wip_nav.finishDebugFrameFde(func_length);
9155 debug.wip_func.finishDebugFrameFde(func_length);
90339156 if (func.analysisUnordered(ip).inferred_error_set) {
90349157 const ies = ip.getIfExists(.{ .inferred_error_set_type = func_index }).?;
90359158 if (elf.dwarf.const_pool.getIfExists(ies)) |cpi|
......@@ -9111,8 +9234,8 @@ fn flushInner(
91119234 const diags = &comp.link_diags;
91129235 _ = arena;
91139236
9114 const sub_prog_node = prog_node.start("ELF Flush", 0);
9115 defer sub_prog_node.end();
9237 const flush_prog_node = prog_node.start("ELF Flush", 0);
9238 defer flush_prog_node.end();
91169239
91179240 try elf.flushFiles();
91189241
......@@ -9130,8 +9253,12 @@ fn flushInner(
91309253
91319254 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);
91339258 assert(elf.pending_uavs.items.len == 0);
91349259 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
91369263 // We've done the final `idle` loop, so everything is at its final place in the file. We have a
91379264 // 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 {
91959322 assert(elf.dwarf.const_pool.pending.items.len == 0);
91969323
91979324 task: {
9198 if (elf.input_pending_index < elf.inputs.items.len) {
9325 if (elf.inputs.items.len - elf.input_pending_index > 0) {
91999326 const ii: Node.InputIndex = @fromBackingInt(elf.input_pending_index);
92009327 elf.input_pending_index += 1;
9201 const sub_prog_node = elf.idleProgNode(tid, elf.input_prog_node, elf.getNode(ii.node(elf)));
9202 defer sub_prog_node.end();
9328 const idle_prog_node =
9329 elf.startIdleProgress(tid, elf.input_prog_node, elf.getNode(ii.node(elf)));
9330 defer idle_prog_node.end();
92039331 elf.flushInput(ii) catch |err| switch (err) {
92049332 else => |e| return e,
92059333 error.MappedFileIo => return diags.fail("failed to write output file: {t}", .{elf.mf.io_err.?}),
92069334 };
92079335 break :task;
92089336 }
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) {
92109338 const isi: InputSection.Index = @fromBackingInt(elf.input_section_pending_index);
92119339 elf.input_section_pending_index += 1;
9212 const sub_prog_node = elf.idleProgNode(tid, elf.input_prog_node, elf.getNode(isi.node(elf)));
9213 defer sub_prog_node.end();
9340 const idle_prog_node =
9341 elf.startIdleProgress(tid, elf.input_prog_node, elf.getNode(isi.node(elf)));
9342 defer idle_prog_node.end();
92149343 elf.flushInputSection(isi) catch |err| switch (err) {
92159344 else => |e| return e,
92169345 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 {
92379366 break :task;
92389367 }
92399368 if (elf.changed_symtab_index.pop()) |kv| {
9240 const sub_prog_node = elf.mf.update_prog_node.start(kv.key.slice(elf), 0);
9241 defer sub_prog_node.end();
9369 const idle_prog_node = elf.mf.update_prog_node.start(kv.key.slice(elf), 0);
9370 defer idle_prog_node.end();
92429371
92439372 const global_name = kv.key;
92449373 const global = elf.globalByName(global_name).?;
......@@ -9317,22 +9446,23 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {
93179446 const clean_resized = ni.cleanResized(&elf.mf);
93189447 const clean_next_moved = ni.cleanNextMoved(&elf.mf);
93199448 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));
9321 defer sub_prog_node.end();
9449 const idle_prog_node = elf.startIdleProgress(tid, elf.mf.update_prog_node, elf.getNode(ni));
9450 defer idle_prog_node.end();
93229451 if (clean_moved) try elf.flushMoved(ni);
93239452 if (clean_resized) try elf.flushResized(ni);
93249453 if (clean_moved or clean_resized or clean_next_moved) try elf.flushPadding(ni);
93259454 break :task;
93269455 }
93279456 }
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;
93299459 if (elf.one_shot_fixups.items.len > 0) return true;
93309460 if (elf.changed_symtab_index.count() > 0) return true;
93319461 if (elf.mf.updates.items.len > 0) return true;
93329462 return false;
93339463}
93349464
9335fn idleProgNode(
9465fn startIdleProgress(
93369466 elf: *Elf,
93379467 tid: Zcu.PerThread.Id,
93389468 prog_node: std.Progress.Node,
......@@ -9363,7 +9493,7 @@ fn idleProgNode(
93639493 }) catch &name,
93649494 .debug_shared => |ss| switch (ss) {
93659495 .debug_abbrev => "debug info abbrevs",
9366 .debug_str, .debug_str_offsets => "debug info strings",
9496 .debug_str => "debug info strings",
93679497 .debug_line_str => "line info strings",
93689498 },
93699499 .unit_frame,
......@@ -9432,29 +9562,56 @@ fn genPending(elf: *Elf, pt: Zcu.PerThread) link.Error!void {
94329562 try elf.genUav(pt, umi);
94339563 }
94349564 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) {
94369566 try elf.genLazy(pt, .{ .kind = lazy.key, .index = lazy.value.pending_index });
94379567 lazy.value.pending_index += 1;
94389568 };
9569 const gpa = elf.base.comp.gpa;
94399570 switch (elf.base.comp.config.debug_format) {
94409571 .strip => {},
9441 .dwarf => {
9442 const gpa = elf.base.comp.gpa;
9443 while (true) {
9444 const pending = elf.dwarf.pending_decl;
9445 if (pending.instance_val == .none) break;
9446 elf.dwarf.pending_decl = .{ .di = undefined, .instance_val = .none };
9447 const debug_info_ni = pending.di.get(&elf.dwarf).debug_info_ni.unwrap().?;
9448 try debug_info_ni.moved(gpa, &elf.mf);
9449 var di_nw: MappedFile.Node.Writer = undefined;
9450 debug_info_ni.writer(gpa, &elf.mf, &di_nw);
9451 defer di_nw.deinit();
9452 elf.resetNodeRelocs(debug_info_ni);
9453 try elf.dwarf.genDecl(pt, &di_nw, pending.instance_val);
9454 }
9572 .dwarf => while (true) {
9573 const pending = elf.dwarf.pending_decl;
9574 if (pending.instance == .none) break;
9575 elf.dwarf.pending_decl = .{ .di = undefined, .instance = .none };
9576 const debug_info_ni = pending.di.get(&elf.dwarf).debug_info_ni.unwrap().?;
9577 try debug_info_ni.moved(gpa, &elf.mf);
9578 var di_nw: MappedFile.Node.Writer = undefined;
9579 debug_info_ni.writer(gpa, &elf.mf, &di_nw);
9580 defer di_nw.deinit();
9581 elf.resetNodeRelocs(debug_info_ni);
9582 try elf.dwarf.genDecl(pt, &di_nw, pending.instance);
94559583 },
94569584 .code_view => unreachable,
94579585 }
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 }
94589615}
94599616
94609617fn genUav(
......@@ -9855,7 +10012,44 @@ fn flushMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!void
985510012 target_ri = target_reloc.next;
985610013 }
985710014 },
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 },
985910053 .unit_frame_cie => |ui| {
986010054 const target_section_offset = elf.computeNodeSectionOffset(ni);
986110055 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
990610100 target_ri = target_reloc.next;
990710101 }
990810102 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| {
991010104 const symbol_reloc = symbol_ri.get(elf);
991110105 assert(symbol_reloc.node.unwrap().? == ni);
991210106 symbol_reloc.flushMovedNode(elf, node_vaddr);
......@@ -10238,7 +10432,9 @@ fn flushResized(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
1023810432 .lazy_code,
1023910433 .lazy_const_data,
1024010434 .debug_shared,
10435 .debug_addr,
1024110436 .eh_frame_footer,
10437 .debug_str_offsets,
1024210438 .unit_padding,
1024310439 .unit_frame,
1024410440 .unit_frame_cie,
......@@ -10262,7 +10458,8 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
1026210458 const trace = tracy.trace(@src());
1026310459 defer trace.end();
1026410460
10265 switch (elf.getNode(ni)) {
10461 const node = elf.getNode(ni);
10462 switch (node) {
1026610463 .deleted => unreachable,
1026710464 .archive,
1026810465 .archive_input_member,
......@@ -10310,6 +10507,8 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
1031010507 error.NoSpaceLeft => archive.strtab_member_too_big = true,
1031110508 }
1031210509 },
10510 .debug_addr,
10511 .debug_str_offsets,
1031310512 .unit_padding,
1031410513 .unit_frame_cie,
1031510514 .unit_debug_info_header,
......@@ -10321,8 +10520,27 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
1032110520 .func_debug_info,
1032210521 .func_debug_line,
1032310522 .decl_debug_info,
10324 => |_, tag| {
10325 const offset, const size = ni.location(&elf.mf).resolve(&elf.mf);
10523 => {
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 };
1032610544 const parent_ni = ni.parent(&elf.mf).unwrap().?;
1032710545 const slice = slice: {
1032810546 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
1033410552 break :slice parent_slice[@intCast(offset)..@intCast(next_offset)];
1033510553 },
1033610554 };
10337 switch (tag) {
10555 switch (node) {
1033810556 else => unreachable,
10339 .unit_padding, .unit_debug_rnglists => {
10557 .debug_addr, .debug_str_offsets, .unit_padding, .unit_debug_rnglists => {
1034010558 const parent_slice = parent_ni.slicePadding(&elf.mf);
1034110559 const frame_shndx = elf.getNodeShndx(parent_ni);
1034210560 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
1041110629 break :buffer debug_slice[@intCast(parent_offset)..];
1041210630 });
1041310631 fw.end = @intCast(offset + size);
10414 switch (tag) {
10632 switch (node) {
1041510633 else => unreachable,
1041610634 .unit_debug_info_header,
1041710635 .const_debug_info,
......@@ -10428,7 +10646,7 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
1042810646 error.WriteFailed => {
1042910647 fw.end = unit_padding_offset;
1043010648 elf.dwarf.updateUnitLength(fw.buffer, fw.buffer.len);
10431 switch (tag) {
10649 switch (node) {
1043210650 else => unreachable,
1043310651 .unit_debug_info_header,
1043410652 .const_debug_info,
......@@ -10459,8 +10677,23 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
1045910677 }
1046010678 };
1046110679 var fw: Io.Writer = .fixed(slice[@intCast(size)..]);
10462 switch (tag) {
10680 switch (node) {
1046310681 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 },
1046410697 .unit_padding => elf.dwarf.updateUnitLength(slice, slice.len),
1046510698 .unit_frame_cie, .func_frame_fde => {
1046610699 elf.dwarf.updateUnitLength(slice, slice.len);
......@@ -10475,17 +10708,6 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
1047510708 .unit_debug_line_header,
1047610709 .func_debug_line,
1047710710 => 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 },
1048910711 }
1049010712 },
1049110713 .unit_frame, .unit_debug_info, .unit_debug_line => {
......@@ -11037,7 +11259,11 @@ pub fn printNode(
1103711259 if (nav.resolved) |resolved| try w.print("{f}, ", .{
1103811260 Type.fromInterned(resolved.type).fmt(.{ .zcu = zcu, .tid = tid }),
1103911261 });
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(')');
1104111267 },
1104211268 .func_frame_fde, .func_debug_info, .func_debug_line => |fi| {
1104311269 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
57925792 }
57935793
57945794 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
57975797 var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer);
57985798 const stdout_bw = &stdout_writer.interface;
src/print_zir.zig+2-1
......@@ -2211,6 +2211,8 @@ const Writer = struct {
22112211 defer self.parent_decl_node = prev_parent_decl_node;
22122212 self.parent_decl_node = decl.src_node;
22132213
2214 try stream.print(":{d}:{d} ", .{ decl.src_line + 1, decl.src_column + 1 });
2215
22142216 if (decl.is_pub) try stream.writeAll("pub ");
22152217 switch (decl.linkage) {
22162218 .normal => {},
......@@ -2224,7 +2226,6 @@ const Writer = struct {
22242226 try stream.print("{s} '{s}'", .{ @tagName(decl.kind), self.code.nullTerminatedString(decl.name) });
22252227 },
22262228 }
2227 try stream.print(":{d}:{d}", .{ decl.src_line + 1, decl.src_column + 1 });
22282229
22292230 const src_hash = self.code.getAssociatedSrcHash(inst).?;
22302231 try stream.print(" hash({x})", .{&src_hash});
test/src/Debugger.zig+5-5
......@@ -629,7 +629,7 @@ pub fn addTests(db: *Debugger) void {
629629 \\(lldb) breakpoint delete --force 1
630630 \\1 breakpoints deleted; 0 breakpoint locations disabled.
631631 },
632 .{ .skip_new_linker = true },
632 .{ .skip_new_linker = true }, // passes, but prints errors
633633 );
634634 db.addLldbTest(
635635 "optionals",
......@@ -868,7 +868,7 @@ pub fn addTests(db: *Debugger) void {
868868 \\(lldb) breakpoint delete --force 1
869869 \\1 breakpoints deleted; 0 breakpoint locations disabled.
870870 },
871 .{ .skip_new_linker = true },
871 .{},
872872 );
873873 db.addLldbTest(
874874 "if_blocks",
......@@ -1946,7 +1946,7 @@ pub fn addTests(db: *Debugger) void {
19461946 \\ frame #1: inline_call`m1pfi(m1pai=89) at mod1.zig:23:15
19471947 \\ frame #2: inline_call`root0.main at root0.zig:41:15
19481948 },
1949 .{ .skip_new_linker = true },
1949 .{},
19501950 );
19511951 db.addLldbTest(
19521952 "link_object",
......@@ -2054,7 +2054,7 @@ pub fn addTests(db: *Debugger) void {
20542054 \\(lldb) breakpoint delete --force 1
20552055 \\1 breakpoints deleted; 0 breakpoint locations disabled.
20562056 },
2057 .{ .skip_new_linker = true },
2057 .{},
20582058 );
20592059 db.addLldbTest(
20602060 "multi_array_list",
......@@ -2308,7 +2308,7 @@ pub fn addTests(db: *Debugger) void {
23082308 \\(lldb) breakpoint delete --force 1
23092309 \\1 breakpoints deleted; 0 breakpoint locations disabled.
23102310 },
2311 .{ .skip_new_linker = true },
2311 .{},
23122312 );
23132313}
23142314