| author | |
| committer | |
| log | 8796da028320b97a4b67a401109dce1137ee2bbf |
| tree | eac0ec8d74fe773619bec1e67b87fa620a78849c |
| parent | 3575048c0ae8b5bae2cd5c6fd3dbc9cb569c4b1f |
We need to access it outside of `DeclState` too so why not reuse
the helper anyway.4 files changed, 28 insertions(+), 37 deletions(-)
src/link/Dwarf.zig+18-27| ... | ... | @@ -586,7 +586,7 @@ pub const DeclState = struct { |
| 586 | 586 | loc: DbgInfoLoc, |
| 587 | 587 | ) error{OutOfMemory}!void { |
| 588 | 588 | const dbg_info = &self.dbg_info; |
| 589 | const atom = self.getDbgInfoAtom(tag, owner_decl); | |
| 589 | const atom = getDbgInfoAtom(tag, self.mod, owner_decl); | |
| 590 | 590 | const name_with_null = name.ptr[0 .. name.len + 1]; |
| 591 | 591 | |
| 592 | 592 | switch (loc) { |
| ... | ... | @@ -645,7 +645,7 @@ pub const DeclState = struct { |
| 645 | 645 | loc: DbgInfoLoc, |
| 646 | 646 | ) error{OutOfMemory}!void { |
| 647 | 647 | const dbg_info = &self.dbg_info; |
| 648 | const atom = self.getDbgInfoAtom(tag, owner_decl); | |
| 648 | const atom = getDbgInfoAtom(tag, self.mod, owner_decl); | |
| 649 | 649 | const name_with_null = name.ptr[0 .. name.len + 1]; |
| 650 | 650 | try dbg_info.append(@enumToInt(AbbrevKind.variable)); |
| 651 | 651 | const target = self.mod.getTarget(); |
| ... | ... | @@ -778,16 +778,6 @@ pub const DeclState = struct { |
| 778 | 778 | try self.addTypeRelocGlobal(atom, child_ty, @intCast(u32, index)); |
| 779 | 779 | dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string |
| 780 | 780 | } |
| 781 | ||
| 782 | fn getDbgInfoAtom(self: *DeclState, tag: File.Tag, decl_index: Module.Decl.Index) *Atom { | |
| 783 | const decl = self.mod.declPtr(decl_index); | |
| 784 | return switch (tag) { | |
| 785 | .elf => &decl.link.elf.dbg_info_atom, | |
| 786 | .macho => &decl.link.macho.dbg_info_atom, | |
| 787 | .wasm => &decl.link.wasm.dbg_info_atom, | |
| 788 | else => unreachable, | |
| 789 | }; | |
| 790 | } | |
| 791 | 781 | }; |
| 792 | 782 | |
| 793 | 783 | pub const AbbrevEntry = struct { |
| ... | ... | @@ -899,10 +889,11 @@ pub fn deinit(self: *Dwarf) void { |
| 899 | 889 | |
| 900 | 890 | /// Initializes Decl's state and its matching output buffers. |
| 901 | 891 | /// Call this before `commitDeclState`. |
| 902 | pub fn initDeclState(self: *Dwarf, mod: *Module, decl: *Module.Decl) !DeclState { | |
| 892 | pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index) !DeclState { | |
| 903 | 893 | const tracy = trace(@src()); |
| 904 | 894 | defer tracy.end(); |
| 905 | 895 | |
| 896 | const decl = mod.declPtr(decl_index); | |
| 906 | 897 | const decl_name = try decl.getFullyQualifiedName(mod); |
| 907 | 898 | defer self.allocator.free(decl_name); |
| 908 | 899 | |
| ... | ... | @@ -977,12 +968,7 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl: *Module.Decl) !DeclState |
| 977 | 968 | dbg_info_buffer.items.len += 4; // DW.AT.high_pc, DW.FORM.data4 |
| 978 | 969 | // |
| 979 | 970 | if (fn_ret_has_bits) { |
| 980 | const atom = switch (self.tag) { | |
| 981 | .elf => &decl.link.elf.dbg_info_atom, | |
| 982 | .macho => &decl.link.macho.dbg_info_atom, | |
| 983 | .wasm => &decl.link.wasm.dbg_info_atom, | |
| 984 | else => unreachable, | |
| 985 | }; | |
| 971 | const atom = getDbgInfoAtom(self.tag, mod, decl_index); | |
| 986 | 972 | try decl_state.addTypeRelocGlobal(atom, fn_ret_type, @intCast(u32, dbg_info_buffer.items.len)); |
| 987 | 973 | dbg_info_buffer.items.len += 4; // DW.AT.type, DW.FORM.ref4 |
| 988 | 974 | } |
| ... | ... | @@ -1002,7 +988,7 @@ pub fn commitDeclState( |
| 1002 | 988 | self: *Dwarf, |
| 1003 | 989 | file: *File, |
| 1004 | 990 | module: *Module, |
| 1005 | decl: *Module.Decl, | |
| 991 | decl_index: Module.Decl.Index, | |
| 1006 | 992 | sym_addr: u64, |
| 1007 | 993 | sym_size: u64, |
| 1008 | 994 | decl_state: *DeclState, |
| ... | ... | @@ -1013,6 +999,7 @@ pub fn commitDeclState( |
| 1013 | 999 | const gpa = self.allocator; |
| 1014 | 1000 | var dbg_line_buffer = &decl_state.dbg_line; |
| 1015 | 1001 | var dbg_info_buffer = &decl_state.dbg_info; |
| 1002 | const decl = module.declPtr(decl_index); | |
| 1016 | 1003 | |
| 1017 | 1004 | const target_endian = self.target.cpu.arch.endian(); |
| 1018 | 1005 | |
| ... | ... | @@ -1233,13 +1220,7 @@ pub fn commitDeclState( |
| 1233 | 1220 | if (dbg_info_buffer.items.len == 0) |
| 1234 | 1221 | return; |
| 1235 | 1222 | |
| 1236 | const atom = switch (self.tag) { | |
| 1237 | .elf => &decl.link.elf.dbg_info_atom, | |
| 1238 | .macho => &decl.link.macho.dbg_info_atom, | |
| 1239 | .wasm => &decl.link.wasm.dbg_info_atom, | |
| 1240 | else => unreachable, | |
| 1241 | }; | |
| 1242 | ||
| 1223 | const atom = getDbgInfoAtom(self.tag, module, decl_index); | |
| 1243 | 1224 | if (decl_state.abbrev_table.items.len > 0) { |
| 1244 | 1225 | // Now we emit the .debug_info types of the Decl. These will count towards the size of |
| 1245 | 1226 | // the buffer, so we have to do it before computing the offset, and we can't perform the actual |
| ... | ... | @@ -2563,3 +2544,13 @@ fn addDbgInfoErrorSet( |
| 2563 | 2544 | // DW.AT.enumeration_type delimit children |
| 2564 | 2545 | try dbg_info_buffer.append(0); |
| 2565 | 2546 | } |
| 2547 | ||
| 2548 | fn getDbgInfoAtom(tag: File.Tag, mod: *Module, decl_index: Module.Decl.Index) *Atom { | |
| 2549 | const decl = mod.declPtr(decl_index); | |
| 2550 | return switch (tag) { | |
| 2551 | .elf => &decl.link.elf.dbg_info_atom, | |
| 2552 | .macho => &decl.link.macho.dbg_info_atom, | |
| 2553 | .wasm => &decl.link.wasm.dbg_info_atom, | |
| 2554 | else => unreachable, | |
| 2555 | }; | |
| 2556 | } |
src/link/Elf.zig+4-4| ... | ... | @@ -2420,7 +2420,7 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven |
| 2420 | 2420 | const decl = module.declPtr(decl_index); |
| 2421 | 2421 | self.freeUnnamedConsts(decl_index); |
| 2422 | 2422 | |
| 2423 | var decl_state: ?Dwarf.DeclState = if (self.dwarf) |*dw| try dw.initDeclState(module, decl) else null; | |
| 2423 | var decl_state: ?Dwarf.DeclState = if (self.dwarf) |*dw| try dw.initDeclState(module, decl_index) else null; | |
| 2424 | 2424 | defer if (decl_state) |*ds| ds.deinit(); |
| 2425 | 2425 | |
| 2426 | 2426 | const res = if (decl_state) |*ds| |
| ... | ... | @@ -2443,7 +2443,7 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven |
| 2443 | 2443 | try self.dwarf.?.commitDeclState( |
| 2444 | 2444 | &self.base, |
| 2445 | 2445 | module, |
| 2446 | decl, | |
| 2446 | decl_index, | |
| 2447 | 2447 | local_sym.st_value, |
| 2448 | 2448 | local_sym.st_size, |
| 2449 | 2449 | ds, |
| ... | ... | @@ -2483,7 +2483,7 @@ pub fn updateDecl(self: *Elf, module: *Module, decl_index: Module.Decl.Index) !v |
| 2483 | 2483 | var code_buffer = std.ArrayList(u8).init(self.base.allocator); |
| 2484 | 2484 | defer code_buffer.deinit(); |
| 2485 | 2485 | |
| 2486 | var decl_state: ?Dwarf.DeclState = if (self.dwarf) |*dw| try dw.initDeclState(module, decl) else null; | |
| 2486 | var decl_state: ?Dwarf.DeclState = if (self.dwarf) |*dw| try dw.initDeclState(module, decl_index) else null; | |
| 2487 | 2487 | defer if (decl_state) |*ds| ds.deinit(); |
| 2488 | 2488 | |
| 2489 | 2489 | // TODO implement .debug_info for global variables |
| ... | ... | @@ -2520,7 +2520,7 @@ pub fn updateDecl(self: *Elf, module: *Module, decl_index: Module.Decl.Index) !v |
| 2520 | 2520 | try self.dwarf.?.commitDeclState( |
| 2521 | 2521 | &self.base, |
| 2522 | 2522 | module, |
| 2523 | decl, | |
| 2523 | decl_index, | |
| 2524 | 2524 | local_sym.st_value, |
| 2525 | 2525 | local_sym.st_size, |
| 2526 | 2526 | ds, |
src/link/MachO.zig+4-4| ... | ... | @@ -2190,7 +2190,7 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv |
| 2190 | 2190 | defer code_buffer.deinit(); |
| 2191 | 2191 | |
| 2192 | 2192 | var decl_state = if (self.d_sym) |*d_sym| |
| 2193 | try d_sym.dwarf.initDeclState(module, decl) | |
| 2193 | try d_sym.dwarf.initDeclState(module, decl_index) | |
| 2194 | 2194 | else |
| 2195 | 2195 | null; |
| 2196 | 2196 | defer if (decl_state) |*ds| ds.deinit(); |
| ... | ... | @@ -2217,7 +2217,7 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv |
| 2217 | 2217 | try self.d_sym.?.dwarf.commitDeclState( |
| 2218 | 2218 | &self.base, |
| 2219 | 2219 | module, |
| 2220 | decl, | |
| 2220 | decl_index, | |
| 2221 | 2221 | addr, |
| 2222 | 2222 | decl.link.macho.size, |
| 2223 | 2223 | ds, |
| ... | ... | @@ -2330,7 +2330,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index) |
| 2330 | 2330 | defer code_buffer.deinit(); |
| 2331 | 2331 | |
| 2332 | 2332 | var decl_state: ?Dwarf.DeclState = if (self.d_sym) |*d_sym| |
| 2333 | try d_sym.dwarf.initDeclState(module, decl) | |
| 2333 | try d_sym.dwarf.initDeclState(module, decl_index) | |
| 2334 | 2334 | else |
| 2335 | 2335 | null; |
| 2336 | 2336 | defer if (decl_state) |*ds| ds.deinit(); |
| ... | ... | @@ -2368,7 +2368,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index) |
| 2368 | 2368 | try self.d_sym.?.dwarf.commitDeclState( |
| 2369 | 2369 | &self.base, |
| 2370 | 2370 | module, |
| 2371 | decl, | |
| 2371 | decl_index, | |
| 2372 | 2372 | addr, |
| 2373 | 2373 | decl.link.macho.size, |
| 2374 | 2374 | ds, |
src/link/Wasm.zig+2-2| ... | ... | @@ -885,7 +885,7 @@ pub fn updateFunc(wasm: *Wasm, mod: *Module, func: *Module.Fn, air: Air, livenes |
| 885 | 885 | |
| 886 | 886 | decl.link.wasm.clear(); |
| 887 | 887 | |
| 888 | var decl_state: ?Dwarf.DeclState = if (wasm.dwarf) |*dwarf| try dwarf.initDeclState(mod, decl) else null; | |
| 888 | var decl_state: ?Dwarf.DeclState = if (wasm.dwarf) |*dwarf| try dwarf.initDeclState(mod, decl_index) else null; | |
| 889 | 889 | defer if (decl_state) |*ds| ds.deinit(); |
| 890 | 890 | |
| 891 | 891 | var code_writer = std.ArrayList(u8).init(wasm.base.allocator); |
| ... | ... | @@ -913,7 +913,7 @@ pub fn updateFunc(wasm: *Wasm, mod: *Module, func: *Module.Fn, air: Air, livenes |
| 913 | 913 | try dwarf.commitDeclState( |
| 914 | 914 | &wasm.base, |
| 915 | 915 | mod, |
| 916 | decl, | |
| 916 | decl_index, | |
| 917 | 917 | // Actual value will be written after relocation. |
| 918 | 918 | // For Wasm, this is the offset relative to the code section |
| 919 | 919 | // which isn't known until flush(). |