authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-08 11:13:52+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-08 11:13:52+01:00
log37033a96ac2e33a56eb2e153462d1a730b426029
tree1d599e8f86942a7daed800ad0c8010855a1c0780
parent3122fd0ba0eb4cdb17616658b462a255a37f1ad7

macho: move Dwarf handle to ZigObject from DebugSymbols


4 files changed, 157 insertions(+), 167 deletions(-)

src/link/Dwarf.zig+18-12
......@@ -1351,9 +1351,10 @@ pub fn commitDeclState(
13511351 },
13521352
13531353 .macho => {
1354 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
1354 const macho_file = self.bin_file.cast(File.MachO).?;
1355 const d_sym = macho_file.getDebugSymbols().?;
13551356 const sect_index = d_sym.debug_line_section_index.?;
1356 try d_sym.growSection(sect_index, needed_size, true);
1357 try d_sym.growSection(sect_index, needed_size, true, macho_file);
13571358 const sect = d_sym.getSection(sect_index);
13581359 const file_pos = sect.offset + src_fn.off;
13591360 try pwriteDbgLineNops(
......@@ -1597,9 +1598,10 @@ fn writeDeclDebugInfo(self: *Dwarf, atom_index: Atom.Index, dbg_info_buf: []cons
15971598 },
15981599
15991600 .macho => {
1600 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
1601 const macho_file = self.bin_file.cast(File.MachO).?;
1602 const d_sym = macho_file.getDebugSymbols().?;
16011603 const sect_index = d_sym.debug_info_section_index.?;
1602 try d_sym.growSection(sect_index, needed_size, true);
1604 try d_sym.growSection(sect_index, needed_size, true, macho_file);
16031605 const sect = d_sym.getSection(sect_index);
16041606 const file_pos = sect.offset + atom.off;
16051607 try pwriteDbgInfoNops(
......@@ -1877,9 +1879,10 @@ pub fn writeDbgAbbrev(self: *Dwarf) !void {
18771879 try elf_file.base.file.?.pwriteAll(&abbrev_buf, file_pos);
18781880 },
18791881 .macho => {
1880 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
1882 const macho_file = self.bin_file.cast(File.MachO).?;
1883 const d_sym = macho_file.getDebugSymbols().?;
18811884 const sect_index = d_sym.debug_abbrev_section_index.?;
1882 try d_sym.growSection(sect_index, needed_size, false);
1885 try d_sym.growSection(sect_index, needed_size, false, macho_file);
18831886 const sect = d_sym.getSection(sect_index);
18841887 const file_pos = sect.offset + abbrev_offset;
18851888 try d_sym.file.pwriteAll(&abbrev_buf, file_pos);
......@@ -2292,9 +2295,10 @@ pub fn writeDbgAranges(self: *Dwarf, addr: u64, size: u64) !void {
22922295 try elf_file.base.file.?.pwriteAll(di_buf.items, file_pos);
22932296 },
22942297 .macho => {
2295 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
2298 const macho_file = self.bin_file.cast(File.MachO).?;
2299 const d_sym = macho_file.getDebugSymbols().?;
22962300 const sect_index = d_sym.debug_aranges_section_index.?;
2297 try d_sym.growSection(sect_index, needed_size, false);
2301 try d_sym.growSection(sect_index, needed_size, false, macho_file);
22982302 const sect = d_sym.getSection(sect_index);
22992303 const file_pos = sect.offset;
23002304 try d_sym.file.pwriteAll(di_buf.items, file_pos);
......@@ -2432,10 +2436,11 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {
24322436 try elf_file.base.file.?.pwriteAll(buffer, file_pos + delta);
24332437 },
24342438 .macho => {
2435 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
2439 const macho_file = self.bin_file.cast(File.MachO).?;
2440 const d_sym = macho_file.getDebugSymbols().?;
24362441 const sect_index = d_sym.debug_line_section_index.?;
24372442 const needed_size: u32 = @intCast(d_sym.getSection(sect_index).size + delta);
2438 try d_sym.growSection(sect_index, needed_size, true);
2443 try d_sym.growSection(sect_index, needed_size, true, macho_file);
24392444 const file_pos = d_sym.getSection(sect_index).offset + first_fn.off;
24402445
24412446 const amt = try d_sym.file.preadAll(buffer, file_pos);
......@@ -2653,8 +2658,9 @@ fn addDIFile(self: *Dwarf, mod: *Module, decl_index: InternPool.DeclIndex) !u28
26532658 elf_file.markDirty(elf_file.debug_line_section_index.?);
26542659 },
26552660 .macho => {
2656 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
2657 d_sym.markDirty(d_sym.debug_line_section_index.?);
2661 const macho_file = self.bin_file.cast(File.MachO).?;
2662 const d_sym = macho_file.getDebugSymbols().?;
2663 d_sym.markDirty(d_sym.debug_line_section_index.?, macho_file);
26582664 },
26592665 .wasm => {},
26602666 else => unreachable,
src/link/MachO.zig+22-30
......@@ -255,43 +255,35 @@ pub fn createEmpty(
255255 )}),
256256 } });
257257 self.zig_object = index;
258 try self.getZigObject().?.init(self);
258 const zo = self.getZigObject().?;
259 try zo.init(self);
260
259261 try self.initMetadata(.{
260262 .symbol_count_hint = options.symbol_count_hint,
261263 .program_code_size_hint = options.program_code_size_hint,
262264 });
263265
264 switch (comp.config.debug_format) {
265 .strip => {},
266 .dwarf => if (!self.base.isRelocatable()) {
267 // Create dSYM bundle.
268 log.debug("creating {s}.dSYM bundle", .{emit.sub_path});
269
270 const sep = fs.path.sep_str;
271 const d_sym_path = try std.fmt.allocPrint(
272 arena,
273 "{s}.dSYM" ++ sep ++ "Contents" ++ sep ++ "Resources" ++ sep ++ "DWARF",
274 .{emit.sub_path},
275 );
266 if (zo.dwarf != null and !self.base.isRelocatable()) {
267 // Create dSYM bundle.
268 log.debug("creating {s}.dSYM bundle", .{emit.sub_path});
276269
277 var d_sym_bundle = try emit.directory.handle.makeOpenPath(d_sym_path, .{});
278 defer d_sym_bundle.close();
270 const sep = fs.path.sep_str;
271 const d_sym_path = try std.fmt.allocPrint(
272 arena,
273 "{s}.dSYM" ++ sep ++ "Contents" ++ sep ++ "Resources" ++ sep ++ "DWARF",
274 .{emit.sub_path},
275 );
279276
280 const d_sym_file = try d_sym_bundle.createFile(emit.sub_path, .{
281 .truncate = false,
282 .read = true,
283 });
277 var d_sym_bundle = try emit.directory.handle.makeOpenPath(d_sym_path, .{});
278 defer d_sym_bundle.close();
284279
285 self.d_sym = .{
286 .allocator = gpa,
287 .dwarf = link.File.Dwarf.init(&self.base, .dwarf32),
288 .file = d_sym_file,
289 };
290 try self.d_sym.?.initMetadata(self);
291 } else {
292 @panic("TODO: implement generating and emitting __DWARF in .o file");
293 },
294 .code_view => unreachable,
280 const d_sym_file = try d_sym_bundle.createFile(emit.sub_path, .{
281 .truncate = false,
282 .read = true,
283 });
284
285 self.d_sym = .{ .allocator = gpa, .file = d_sym_file };
286 try self.d_sym.?.initMetadata(self);
295287 }
296288 }
297289 }
......@@ -3152,7 +3144,7 @@ pub fn updateDecl(self: *MachO, mod: *Module, decl_index: InternPool.DeclIndex)
31523144
31533145pub fn updateDeclLineNumber(self: *MachO, module: *Module, decl_index: InternPool.DeclIndex) !void {
31543146 if (self.llvm_object) |_| return;
3155 return self.getZigObject().?.updateDeclLineNumber(self, module, decl_index);
3147 return self.getZigObject().?.updateDeclLineNumber(module, decl_index);
31563148}
31573149
31583150pub fn updateExports(
src/link/MachO/DebugSymbols.zig+35-112
......@@ -1,5 +1,4 @@
11allocator: Allocator,
2dwarf: Dwarf,
32file: fs.File,
43
54symtab_cmd: macho.symtab_command = .{},
......@@ -17,12 +16,6 @@ debug_str_section_index: ?u8 = null,
1716debug_aranges_section_index: ?u8 = null,
1817debug_line_section_index: ?u8 = null,
1918
20debug_string_table_dirty: bool = false,
21debug_abbrev_section_dirty: bool = false,
22debug_aranges_section_dirty: bool = false,
23debug_info_header_dirty: bool = false,
24debug_line_header_dirty: bool = false,
25
2619relocs: std.ArrayListUnmanaged(Reloc) = .{},
2720
2821/// Output synthetic sections
......@@ -44,7 +37,7 @@ pub const Reloc = struct {
4437pub fn initMetadata(self: *DebugSymbols, macho_file: *MachO) !void {
4538 try self.strtab.append(self.allocator, 0);
4639
47 if (self.dwarf_segment_cmd_index == null) {
40 {
4841 self.dwarf_segment_cmd_index = @as(u8, @intCast(self.segments.items.len));
4942
5043 const page_size = macho_file.getPageSize();
......@@ -63,46 +56,19 @@ pub fn initMetadata(self: *DebugSymbols, macho_file: *MachO) !void {
6356 });
6457 }
6558
66 if (self.debug_str_section_index == null) {
67 assert(self.dwarf.strtab.buffer.items.len == 0);
68 try self.dwarf.strtab.buffer.append(self.allocator, 0);
69 self.debug_str_section_index = try self.allocateSection(
70 "__debug_str",
71 @as(u32, @intCast(self.dwarf.strtab.buffer.items.len)),
72 0,
73 );
74 self.debug_string_table_dirty = true;
75 }
76
77 if (self.debug_info_section_index == null) {
78 self.debug_info_section_index = try self.allocateSection("__debug_info", 200, 0);
79 self.debug_info_header_dirty = true;
80 }
81
82 if (self.debug_abbrev_section_index == null) {
83 self.debug_abbrev_section_index = try self.allocateSection("__debug_abbrev", 128, 0);
84 self.debug_abbrev_section_dirty = true;
85 }
86
87 if (self.debug_aranges_section_index == null) {
88 self.debug_aranges_section_index = try self.allocateSection("__debug_aranges", 160, 4);
89 self.debug_aranges_section_dirty = true;
90 }
91
92 if (self.debug_line_section_index == null) {
93 self.debug_line_section_index = try self.allocateSection("__debug_line", 250, 0);
94 self.debug_line_header_dirty = true;
95 }
96
97 if (self.linkedit_segment_cmd_index == null) {
98 self.linkedit_segment_cmd_index = @as(u8, @intCast(self.segments.items.len));
99 try self.segments.append(self.allocator, .{
100 .segname = makeStaticString("__LINKEDIT"),
101 .maxprot = macho.PROT.READ,
102 .initprot = macho.PROT.READ,
103 .cmdsize = @sizeOf(macho.segment_command_64),
104 });
105 }
59 self.debug_str_section_index = try self.allocateSection("__debug_str", 200, 0);
60 self.debug_info_section_index = try self.allocateSection("__debug_info", 200, 0);
61 self.debug_abbrev_section_index = try self.allocateSection("__debug_abbrev", 128, 0);
62 self.debug_aranges_section_index = try self.allocateSection("__debug_aranges", 160, 4);
63 self.debug_line_section_index = try self.allocateSection("__debug_line", 250, 0);
64
65 self.linkedit_segment_cmd_index = @as(u8, @intCast(self.segments.items.len));
66 try self.segments.append(self.allocator, .{
67 .segname = makeStaticString("__LINKEDIT"),
68 .maxprot = macho.PROT.READ,
69 .initprot = macho.PROT.READ,
70 .cmdsize = @sizeOf(macho.segment_command_64),
71 });
10672}
10773
10874fn allocateSection(self: *DebugSymbols, sectname: []const u8, size: u64, alignment: u16) !u8 {
......@@ -133,7 +99,13 @@ fn allocateSection(self: *DebugSymbols, sectname: []const u8, size: u64, alignme
13399 return index;
134100}
135101
136pub fn growSection(self: *DebugSymbols, sect_index: u8, needed_size: u32, requires_file_copy: bool) !void {
102pub fn growSection(
103 self: *DebugSymbols,
104 sect_index: u8,
105 needed_size: u32,
106 requires_file_copy: bool,
107 macho_file: *MachO,
108) !void {
137109 const sect = self.getSectionPtr(sect_index);
138110
139111 if (needed_size > self.allocatedSize(sect.offset)) {
......@@ -162,20 +134,22 @@ pub fn growSection(self: *DebugSymbols, sect_index: u8, needed_size: u32, requir
162134 }
163135
164136 sect.size = needed_size;
165 self.markDirty(sect_index);
137 self.markDirty(sect_index, macho_file);
166138}
167139
168pub fn markDirty(self: *DebugSymbols, sect_index: u8) void {
169 if (self.debug_info_section_index.? == sect_index) {
170 self.debug_info_header_dirty = true;
171 } else if (self.debug_line_section_index.? == sect_index) {
172 self.debug_line_header_dirty = true;
173 } else if (self.debug_abbrev_section_index.? == sect_index) {
174 self.debug_abbrev_section_dirty = true;
175 } else if (self.debug_str_section_index.? == sect_index) {
176 self.debug_string_table_dirty = true;
177 } else if (self.debug_aranges_section_index.? == sect_index) {
178 self.debug_aranges_section_dirty = true;
140pub fn markDirty(self: *DebugSymbols, sect_index: u8, macho_file: *MachO) void {
141 if (macho_file.getZigObject()) |zo| {
142 if (self.debug_info_section_index.? == sect_index) {
143 zo.debug_info_header_dirty = true;
144 } else if (self.debug_line_section_index.? == sect_index) {
145 zo.debug_line_header_dirty = true;
146 } else if (self.debug_abbrev_section_index.? == sect_index) {
147 zo.debug_abbrev_dirty = true;
148 } else if (self.debug_str_section_index.? == sect_index) {
149 zo.debug_strtab_dirty = true;
150 } else if (self.debug_aranges_section_index.? == sect_index) {
151 zo.debug_aranges_dirty = true;
152 }
179153 }
180154}
181155
......@@ -201,13 +175,6 @@ fn findFreeSpace(self: *DebugSymbols, object_size: u64, min_alignment: u64) u64
201175}
202176
203177pub fn flushModule(self: *DebugSymbols, macho_file: *MachO) !void {
204 const comp = macho_file.base.comp;
205 // TODO This linker code currently assumes there is only 1 compilation unit
206 // and it corresponds to the Zig source code.
207 const zcu = comp.module orelse return error.LinkingWithoutZigSourceUnimplemented;
208
209 try self.dwarf.flushModule(zcu);
210
211178 for (self.relocs.items) |*reloc| {
212179 const sym = macho_file.getSymbol(reloc.target);
213180 const sym_name = sym.getName(macho_file);
......@@ -226,54 +193,12 @@ pub fn flushModule(self: *DebugSymbols, macho_file: *MachO) !void {
226193 try self.file.pwriteAll(mem.asBytes(&addr), file_offset);
227194 }
228195
229 if (self.debug_abbrev_section_dirty) {
230 try self.dwarf.writeDbgAbbrev();
231 self.debug_abbrev_section_dirty = false;
232 }
233
234 if (self.debug_info_header_dirty) {
235 // Currently only one compilation unit is supported, so the address range is simply
236 // identical to the main program header virtual address and memory size.
237 const text_section = macho_file.sections.items(.header)[macho_file.zig_text_sect_index.?];
238 const low_pc = text_section.addr;
239 const high_pc = text_section.addr + text_section.size;
240 try self.dwarf.writeDbgInfoHeader(zcu, low_pc, high_pc);
241 self.debug_info_header_dirty = false;
242 }
243
244 if (self.debug_aranges_section_dirty) {
245 // Currently only one compilation unit is supported, so the address range is simply
246 // identical to the main program header virtual address and memory size.
247 const text_section = macho_file.sections.items(.header)[macho_file.zig_text_sect_index.?];
248 try self.dwarf.writeDbgAranges(text_section.addr, text_section.size);
249 self.debug_aranges_section_dirty = false;
250 }
251
252 if (self.debug_line_header_dirty) {
253 try self.dwarf.writeDbgLineHeader();
254 self.debug_line_header_dirty = false;
255 }
256
257 {
258 const sect_index = self.debug_str_section_index.?;
259 if (self.debug_string_table_dirty or self.dwarf.strtab.buffer.items.len != self.getSection(sect_index).size) {
260 const needed_size = @as(u32, @intCast(self.dwarf.strtab.buffer.items.len));
261 try self.growSection(sect_index, needed_size, false);
262 try self.file.pwriteAll(self.dwarf.strtab.buffer.items, self.getSection(sect_index).offset);
263 self.debug_string_table_dirty = false;
264 }
265 }
266
267196 self.finalizeDwarfSegment(macho_file);
268197 try self.writeLinkeditSegmentData(macho_file);
269198
270199 // Write load commands
271200 const ncmds, const sizeofcmds = try self.writeLoadCommands(macho_file);
272201 try self.writeHeader(macho_file, ncmds, sizeofcmds);
273
274 assert(!self.debug_abbrev_section_dirty);
275 assert(!self.debug_aranges_section_dirty);
276 assert(!self.debug_string_table_dirty);
277202}
278203
279204pub fn deinit(self: *DebugSymbols) void {
......@@ -281,7 +206,6 @@ pub fn deinit(self: *DebugSymbols) void {
281206 self.file.close();
282207 self.segments.deinit(gpa);
283208 self.sections.deinit(gpa);
284 self.dwarf.deinit();
285209 self.relocs.deinit(gpa);
286210 self.symtab.deinit(gpa);
287211 self.strtab.deinit(gpa);
......@@ -534,7 +458,6 @@ const padToIdeal = MachO.padToIdeal;
534458const trace = @import("../../tracy.zig").trace;
535459
536460const Allocator = mem.Allocator;
537const Dwarf = @import("../Dwarf.zig");
538461const MachO = @import("../MachO.zig");
539462const StringTable = @import("../StringTable.zig");
540463const Type = @import("../../type.zig").Type;
src/link/MachO/ZigObject.zig+82-13
......@@ -46,16 +46,33 @@ tlv_initializers: TlvInitializerTable = .{},
4646/// A table of relocations.
4747relocs: RelocationTable = .{},
4848
49dwarf: ?Dwarf = null,
50
4951dynamic_relocs: MachO.DynamicRelocs = .{},
5052output_symtab_ctx: MachO.SymtabCtx = .{},
5153output_ar_state: Archive.ArState = .{},
5254
55debug_strtab_dirty: bool = true,
56debug_abbrev_dirty: bool = true,
57debug_aranges_dirty: bool = true,
58debug_info_header_dirty: bool = true,
59debug_line_header_dirty: bool = true,
60
5361pub fn init(self: *ZigObject, macho_file: *MachO) !void {
5462 const comp = macho_file.base.comp;
5563 const gpa = comp.gpa;
5664
5765 try self.atoms.append(gpa, 0); // null input section
5866 try self.strtab.buffer.append(gpa, 0);
67
68 switch (comp.config.debug_format) {
69 .strip => {},
70 .dwarf => |v| {
71 assert(v == .@"32");
72 self.dwarf = Dwarf.init(&macho_file.base, .dwarf32);
73 },
74 .code_view => unreachable,
75 }
5976}
6077
6178pub fn deinit(self: *ZigObject, allocator: Allocator) void {
......@@ -101,6 +118,10 @@ pub fn deinit(self: *ZigObject, allocator: Allocator) void {
101118 tlv_init.deinit(allocator);
102119 }
103120 self.tlv_initializers.deinit(allocator);
121
122 if (self.dwarf) |*dw| {
123 dw.deinit();
124 }
104125}
105126
106127fn addNlist(self: *ZigObject, allocator: Allocator) !Symbol.Index {
......@@ -407,6 +428,60 @@ pub fn flushModule(self: *ZigObject, macho_file: *MachO) !void {
407428 if (metadata.text_state != .unused) metadata.text_state = .flushed;
408429 if (metadata.const_state != .unused) metadata.const_state = .flushed;
409430 }
431
432 if (self.dwarf) |*dw| {
433 const zcu = macho_file.base.comp.module.?;
434 try dw.flushModule(zcu);
435
436 if (self.debug_abbrev_dirty) {
437 try dw.writeDbgAbbrev();
438 self.debug_abbrev_dirty = false;
439 }
440
441 if (self.debug_info_header_dirty) {
442 // Currently only one compilation unit is supported, so the address range is simply
443 // identical to the main program header virtual address and memory size.
444 const text_section = macho_file.sections.items(.header)[macho_file.zig_text_sect_index.?];
445 const low_pc = text_section.addr;
446 const high_pc = text_section.addr + text_section.size;
447 try dw.writeDbgInfoHeader(zcu, low_pc, high_pc);
448 self.debug_info_header_dirty = false;
449 }
450
451 if (self.debug_aranges_dirty) {
452 // Currently only one compilation unit is supported, so the address range is simply
453 // identical to the main program header virtual address and memory size.
454 const text_section = macho_file.sections.items(.header)[macho_file.zig_text_sect_index.?];
455 try dw.writeDbgAranges(text_section.addr, text_section.size);
456 self.debug_aranges_dirty = false;
457 }
458
459 if (self.debug_line_header_dirty) {
460 try dw.writeDbgLineHeader();
461 self.debug_line_header_dirty = false;
462 }
463
464 if (!macho_file.base.isRelocatable()) {
465 const d_sym = macho_file.getDebugSymbols().?;
466 const sect_index = d_sym.debug_str_section_index.?;
467 if (self.debug_strtab_dirty or dw.strtab.buffer.items.len != d_sym.getSection(sect_index).size) {
468 const needed_size = @as(u32, @intCast(dw.strtab.buffer.items.len));
469 try d_sym.growSection(sect_index, needed_size, false, macho_file);
470 try d_sym.file.pwriteAll(dw.strtab.buffer.items, d_sym.getSection(sect_index).offset);
471 self.debug_strtab_dirty = false;
472 }
473 } else {
474 // TODO: relocatable
475 }
476 }
477
478 // The point of flushModule() is to commit changes, so in theory, nothing should
479 // be dirty after this. However, it is possible for some things to remain
480 // dirty because they fail to be written in the event of compile errors,
481 // such as debug_line_header_dirty and debug_info_header_dirty.
482 assert(!self.debug_abbrev_dirty);
483 assert(!self.debug_aranges_dirty);
484 assert(!self.debug_strtab_dirty);
410485}
411486
412487pub fn getDeclVAddr(
......@@ -572,7 +647,7 @@ pub fn updateFunc(
572647 var code_buffer = std.ArrayList(u8).init(gpa);
573648 defer code_buffer.deinit();
574649
575 var decl_state: ?Dwarf.DeclState = if (macho_file.getDebugSymbols()) |d_sym| try d_sym.dwarf.initDeclState(mod, decl_index) else null;
650 var decl_state: ?Dwarf.DeclState = if (self.dwarf) |*dw| try dw.initDeclState(mod, decl_index) else null;
576651 defer if (decl_state) |*ds| ds.deinit();
577652
578653 const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none;
......@@ -600,7 +675,7 @@ pub fn updateFunc(
600675
601676 if (decl_state) |*ds| {
602677 const sym = macho_file.getSymbol(sym_index);
603 try macho_file.getDebugSymbols().?.dwarf.commitDeclState(
678 try self.dwarf.?.commitDeclState(
604679 mod,
605680 decl_index,
606681 sym.getAddress(.{}, macho_file),
......@@ -647,7 +722,7 @@ pub fn updateDecl(
647722 var code_buffer = std.ArrayList(u8).init(gpa);
648723 defer code_buffer.deinit();
649724
650 var decl_state: ?Dwarf.DeclState = if (macho_file.getDebugSymbols()) |d_sym| try d_sym.dwarf.initDeclState(mod, decl_index) else null;
725 var decl_state: ?Dwarf.DeclState = if (self.dwarf) |*dw| try dw.initDeclState(mod, decl_index) else null;
651726 defer if (decl_state) |*ds| ds.deinit();
652727
653728 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
......@@ -681,7 +756,7 @@ pub fn updateDecl(
681756
682757 if (decl_state) |*ds| {
683758 const sym = macho_file.getSymbol(sym_index);
684 try macho_file.getDebugSymbols().?.dwarf.commitDeclState(
759 try self.dwarf.?.commitDeclState(
685760 mod,
686761 decl_index,
687762 sym.getAddress(.{}, macho_file),
......@@ -1257,15 +1332,9 @@ fn updateLazySymbol(
12571332}
12581333
12591334/// Must be called only after a successful call to `updateDecl`.
1260pub fn updateDeclLineNumber(
1261 self: *ZigObject,
1262 macho_file: *MachO,
1263 mod: *Module,
1264 decl_index: InternPool.DeclIndex,
1265) !void {
1266 _ = self;
1267 if (macho_file.getDebugSymbols()) |d_sym| {
1268 try d_sym.dwarf.updateDeclLineNumber(mod, decl_index);
1335pub fn updateDeclLineNumber(self: *ZigObject, mod: *Module, decl_index: InternPool.DeclIndex) !void {
1336 if (self.dwarf) |*dw| {
1337 try dw.updateDeclLineNumber(mod, decl_index);
12691338 }
12701339}
12711340