| ... | @@ -785,6 +785,7 @@ const Entry = struct { | ... | @@ -785,6 +785,7 @@ const Entry = struct { |
| 785 | } | 785 | } |
| 786 | | 786 | |
| 787 | const Index = enum(u32) { | 787 | const Index = enum(u32) { |
| | 788 | //got_proc, |
| 788 | _, | 789 | _, |
| 789 | | 790 | |
| 790 | const Optional = enum(u32) { | 791 | const Optional = enum(u32) { |
| ... | @@ -1040,7 +1041,7 @@ const Entry = struct { | ... | @@ -1040,7 +1041,7 @@ const Entry = struct { |
| 1040 | const symbol = zo.symbol(reloc.target_sym); | 1041 | const symbol = zo.symbol(reloc.target_sym); |
| 1041 | try dwarf.resolveReloc( | 1042 | try dwarf.resolveReloc( |
| 1042 | entry_off + reloc.source_off, | 1043 | entry_off + reloc.source_off, |
| 1043 | @bitCast(symbol.address(.{}, elf_file) + @as(i64, @intCast(reloc.target_off)) - | 1044 | @bitCast(symbol.address(.{}, elf_file) + @as(i64, @intCast(@intFromEnum(reloc.target_off))) - |
| 1044 | if (symbol.flags.is_tls) elf_file.dtpAddress() else 0), | 1045 | if (symbol.flags.is_tls) elf_file.dtpAddress() else 0), |
| 1045 | @intFromEnum(dwarf.address_size), | 1046 | @intFromEnum(dwarf.address_size), |
| 1046 | ); | 1047 | ); |
| ... | @@ -1051,7 +1052,7 @@ const Entry = struct { | ... | @@ -1051,7 +1052,7 @@ const Entry = struct { |
| 1051 | const ref = zo.getSymbolRef(reloc.target_sym, macho_file); | 1052 | const ref = zo.getSymbolRef(reloc.target_sym, macho_file); |
| 1052 | try dwarf.resolveReloc( | 1053 | try dwarf.resolveReloc( |
| 1053 | entry_off + reloc.source_off, | 1054 | entry_off + reloc.source_off, |
| 1054 | ref.getSymbol(macho_file).?.getAddress(.{}, macho_file), | 1055 | ref.getSymbol(macho_file).?.getAddress(.{}, macho_file) + @as(i64, @intCast(@intFromEnum(reloc.target_off))), |
| 1055 | @intFromEnum(dwarf.address_size), | 1056 | @intFromEnum(dwarf.address_size), |
| 1056 | ); | 1057 | ); |
| 1057 | } | 1058 | } |
| ... | @@ -1080,18 +1081,39 @@ const CrossSectionReloc = struct { | ... | @@ -1080,18 +1081,39 @@ const CrossSectionReloc = struct { |
| 1080 | const ExternalReloc = struct { | 1081 | const ExternalReloc = struct { |
| 1081 | source_off: u32 = 0, | 1082 | source_off: u32 = 0, |
| 1082 | target_sym: u32, | 1083 | target_sym: u32, |
| 1083 | target_off: u64 = 0, | 1084 | target_off: enum(u64) { |
| | 1085 | none = 0, |
| | 1086 | got = std.math.maxInt(i64) + 1, |
| | 1087 | _, |
| | 1088 | |
| | 1089 | pub fn rel(off: u64) @This() { |
| | 1090 | const res: @This() = @enumFromInt(off); |
| | 1091 | switch (res) { |
| | 1092 | .none => {}, |
| | 1093 | _ => {}, |
| | 1094 | .got => unreachable, // assertion failure |
| | 1095 | } |
| | 1096 | return res; |
| | 1097 | } |
| | 1098 | } = .none, |
| 1084 | }; | 1099 | }; |
| 1085 | | 1100 | |
| 1086 | pub const Loc = union(enum) { | 1101 | pub const Loc = union(enum) { |
| 1087 | empty, | 1102 | empty, |
| 1088 | addr: union(enum) { sym: u32 }, | 1103 | addr_reloc: u32, |
| | 1104 | got_reloc: u32, |
| | 1105 | deref: *const Loc, |
| 1089 | constu: u64, | 1106 | constu: u64, |
| 1090 | consts: i64, | 1107 | consts: i64, |
| 1091 | plus: Bin, | 1108 | plus: Bin, |
| 1092 | reg: u32, | 1109 | reg: u32, |
| 1093 | breg: u32, | 1110 | breg: u32, |
| 1094 | push_object_address, | 1111 | push_object_address, |
| | 1112 | call: struct { |
| | 1113 | args: []const Loc = &.{}, |
| | 1114 | unit: Unit.Index, |
| | 1115 | entry: Entry.Index, |
| | 1116 | }, |
| 1095 | form_tls_address: *const Loc, | 1117 | form_tls_address: *const Loc, |
| 1096 | implicit_value: []const u8, | 1118 | implicit_value: []const u8, |
| 1097 | stack_value: *const Loc, | 1119 | stack_value: *const Loc, |
| ... | @@ -1136,11 +1158,17 @@ pub const Loc = union(enum) { | ... | @@ -1136,11 +1158,17 @@ pub const Loc = union(enum) { |
| 1136 | const writer = adapter.writer(); | 1158 | const writer = adapter.writer(); |
| 1137 | switch (loc) { | 1159 | switch (loc) { |
| 1138 | .empty => {}, | 1160 | .empty => {}, |
| 1139 | .addr => |addr| { | 1161 | .addr_reloc => |sym_index| { |
| 1140 | try writer.writeByte(DW.OP.addr); | 1162 | try writer.writeByte(DW.OP.addr); |
| 1141 | switch (addr) { | 1163 | try adapter.addrSym(sym_index); |
| 1142 | .sym => |sym_index| try adapter.addrSym(sym_index), | 1164 | }, |
| 1143 | } | 1165 | .deref => |addr| { |
| | 1166 | try addr.write(adapter); |
| | 1167 | try writer.writeByte(DW.OP.deref); |
| | 1168 | }, |
| | 1169 | .got_reloc => |sym_index| { |
| | 1170 | try writer.writeByte(DW.OP.const4s); |
| | 1171 | try adapter.gotSym(sym_index); |
| 1144 | }, | 1172 | }, |
| 1145 | .constu => |constu| if (std.math.cast(u5, constu)) |lit| { | 1173 | .constu => |constu| if (std.math.cast(u5, constu)) |lit| { |
| 1146 | try writer.writeByte(@as(u8, DW.OP.lit0) + lit); | 1174 | try writer.writeByte(@as(u8, DW.OP.lit0) + lit); |
| ... | @@ -1225,6 +1253,11 @@ pub const Loc = union(enum) { | ... | @@ -1225,6 +1253,11 @@ pub const Loc = union(enum) { |
| 1225 | try sleb128(writer, 0); | 1253 | try sleb128(writer, 0); |
| 1226 | }, | 1254 | }, |
| 1227 | .push_object_address => try writer.writeByte(DW.OP.push_object_address), | 1255 | .push_object_address => try writer.writeByte(DW.OP.push_object_address), |
| | 1256 | .call => |call| { |
| | 1257 | for (call.args) |arg| try arg.write(adapter); |
| | 1258 | try writer.writeByte(DW.OP.call_ref); |
| | 1259 | try adapter.infoEntry(call.unit, call.entry); |
| | 1260 | }, |
| 1228 | .form_tls_address => |addr| { | 1261 | .form_tls_address => |addr| { |
| 1229 | try addr.write(adapter); | 1262 | try addr.write(adapter); |
| 1230 | try writer.writeByte(DW.OP.form_tls_address); | 1263 | try writer.writeByte(DW.OP.form_tls_address); |
| ... | @@ -1385,12 +1418,12 @@ pub const Cfa = union(enum) { | ... | @@ -1385,12 +1418,12 @@ pub const Cfa = union(enum) { |
| 1385 | }, | 1418 | }, |
| 1386 | .def_cfa_expression => |expr| { | 1419 | .def_cfa_expression => |expr| { |
| 1387 | try writer.writeByte(DW.CFA.def_cfa_expression); | 1420 | try writer.writeByte(DW.CFA.def_cfa_expression); |
| 1388 | try wip_nav.frameExprloc(expr); | 1421 | try wip_nav.frameExprLoc(expr); |
| 1389 | }, | 1422 | }, |
| 1390 | .expression => |reg_expr| { | 1423 | .expression => |reg_expr| { |
| 1391 | try writer.writeByte(DW.CFA.expression); | 1424 | try writer.writeByte(DW.CFA.expression); |
| 1392 | try uleb128(writer, reg_expr.reg); | 1425 | try uleb128(writer, reg_expr.reg); |
| 1393 | try wip_nav.frameExprloc(reg_expr.expr); | 1426 | try wip_nav.frameExprLoc(reg_expr.expr); |
| 1394 | }, | 1427 | }, |
| 1395 | .val_offset => |reg_off| { | 1428 | .val_offset => |reg_off| { |
| 1396 | const factored_off = @divExact(reg_off.off, wip_nav.dwarf.debug_frame.header.data_alignment_factor); | 1429 | const factored_off = @divExact(reg_off.off, wip_nav.dwarf.debug_frame.header.data_alignment_factor); |
| ... | @@ -1407,7 +1440,7 @@ pub const Cfa = union(enum) { | ... | @@ -1407,7 +1440,7 @@ pub const Cfa = union(enum) { |
| 1407 | .val_expression => |reg_expr| { | 1440 | .val_expression => |reg_expr| { |
| 1408 | try writer.writeByte(DW.CFA.val_expression); | 1441 | try writer.writeByte(DW.CFA.val_expression); |
| 1409 | try uleb128(writer, reg_expr.reg); | 1442 | try uleb128(writer, reg_expr.reg); |
| 1410 | try wip_nav.frameExprloc(reg_expr.expr); | 1443 | try wip_nav.frameExprLoc(reg_expr.expr); |
| 1411 | }, | 1444 | }, |
| 1412 | .escape => |bytes| try writer.writeAll(bytes), | 1445 | .escape => |bytes| try writer.writeAll(bytes), |
| 1413 | } | 1446 | } |
| ... | @@ -1471,7 +1504,7 @@ pub const WipNav = struct { | ... | @@ -1471,7 +1504,7 @@ pub const WipNav = struct { |
| 1471 | }); | 1504 | }); |
| 1472 | try wip_nav.strp(name); | 1505 | try wip_nav.strp(name); |
| 1473 | try wip_nav.refType(ty); | 1506 | try wip_nav.refType(ty); |
| 1474 | try wip_nav.infoExprloc(loc); | 1507 | try wip_nav.infoExprLoc(loc); |
| 1475 | wip_nav.any_children = true; | 1508 | wip_nav.any_children = true; |
| 1476 | } | 1509 | } |
| 1477 | | 1510 | |
| ... | @@ -1733,6 +1766,9 @@ pub const WipNav = struct { | ... | @@ -1733,6 +1766,9 @@ pub const WipNav = struct { |
| 1733 | fn endian(_: ExprLocCounter) std.builtin.Endian { | 1766 | fn endian(_: ExprLocCounter) std.builtin.Endian { |
| 1734 | return @import("builtin").cpu.arch.endian(); | 1767 | return @import("builtin").cpu.arch.endian(); |
| 1735 | } | 1768 | } |
| | 1769 | fn gotSym(counter: *ExprLocCounter, _: u32) error{}!void { |
| | 1770 | counter.stream.bytes_written += 4; |
| | 1771 | } |
| 1736 | fn addrSym(counter: *ExprLocCounter, _: u32) error{}!void { | 1772 | fn addrSym(counter: *ExprLocCounter, _: u32) error{}!void { |
| 1737 | counter.stream.bytes_written += @intFromEnum(counter.address_size); | 1773 | counter.stream.bytes_written += @intFromEnum(counter.address_size); |
| 1738 | } | 1774 | } |
| ... | @@ -1741,7 +1777,7 @@ pub const WipNav = struct { | ... | @@ -1741,7 +1777,7 @@ pub const WipNav = struct { |
| 1741 | } | 1777 | } |
| 1742 | }; | 1778 | }; |
| 1743 | | 1779 | |
| 1744 | fn infoExprloc(wip_nav: *WipNav, loc: Loc) UpdateError!void { | 1780 | fn infoExprLoc(wip_nav: *WipNav, loc: Loc) UpdateError!void { |
| 1745 | var counter: ExprLocCounter = .init(wip_nav.dwarf); | 1781 | var counter: ExprLocCounter = .init(wip_nav.dwarf); |
| 1746 | try loc.write(&counter); | 1782 | try loc.write(&counter); |
| 1747 | | 1783 | |
| ... | @@ -1753,6 +1789,14 @@ pub const WipNav = struct { | ... | @@ -1753,6 +1789,14 @@ pub const WipNav = struct { |
| 1753 | fn endian(ctx: @This()) std.builtin.Endian { | 1789 | fn endian(ctx: @This()) std.builtin.Endian { |
| 1754 | return ctx.wip_nav.dwarf.endian; | 1790 | return ctx.wip_nav.dwarf.endian; |
| 1755 | } | 1791 | } |
| | 1792 | fn gotSym(ctx: @This(), sym_index: u32) UpdateError!void { |
| | 1793 | try ctx.wip_nav.infoExternalReloc(.{ |
| | 1794 | .source_off = @intCast(ctx.wip_nav.debug_info.items.len), |
| | 1795 | .target_sym = sym_index, |
| | 1796 | .target_off = .got, |
| | 1797 | }); |
| | 1798 | try ctx.wip_nav.debug_info.appendNTimes(ctx.wip_nav.dwarf.gpa, 0, 4); |
| | 1799 | } |
| 1756 | fn addrSym(ctx: @This(), sym_index: u32) UpdateError!void { | 1800 | fn addrSym(ctx: @This(), sym_index: u32) UpdateError!void { |
| 1757 | try ctx.wip_nav.infoAddrSym(sym_index, 0); | 1801 | try ctx.wip_nav.infoAddrSym(sym_index, 0); |
| 1758 | } | 1802 | } |
| ... | @@ -1768,12 +1812,12 @@ pub const WipNav = struct { | ... | @@ -1768,12 +1812,12 @@ pub const WipNav = struct { |
| 1768 | try wip_nav.infoExternalReloc(.{ | 1812 | try wip_nav.infoExternalReloc(.{ |
| 1769 | .source_off = @intCast(wip_nav.debug_info.items.len), | 1813 | .source_off = @intCast(wip_nav.debug_info.items.len), |
| 1770 | .target_sym = sym_index, | 1814 | .target_sym = sym_index, |
| 1771 | .target_off = sym_off, | 1815 | .target_off = .rel(sym_off), |
| 1772 | }); | 1816 | }); |
| 1773 | try wip_nav.debug_info.appendNTimes(wip_nav.dwarf.gpa, 0, @intFromEnum(wip_nav.dwarf.address_size)); | 1817 | try wip_nav.debug_info.appendNTimes(wip_nav.dwarf.gpa, 0, @intFromEnum(wip_nav.dwarf.address_size)); |
| 1774 | } | 1818 | } |
| 1775 | | 1819 | |
| 1776 | fn frameExprloc(wip_nav: *WipNav, loc: Loc) UpdateError!void { | 1820 | fn frameExprLoc(wip_nav: *WipNav, loc: Loc) UpdateError!void { |
| 1777 | var counter: ExprLocCounter = .init(wip_nav.dwarf); | 1821 | var counter: ExprLocCounter = .init(wip_nav.dwarf); |
| 1778 | try loc.write(&counter); | 1822 | try loc.write(&counter); |
| 1779 | | 1823 | |
| ... | @@ -1785,6 +1829,14 @@ pub const WipNav = struct { | ... | @@ -1785,6 +1829,14 @@ pub const WipNav = struct { |
| 1785 | fn endian(ctx: @This()) std.builtin.Endian { | 1829 | fn endian(ctx: @This()) std.builtin.Endian { |
| 1786 | return ctx.wip_nav.dwarf.endian; | 1830 | return ctx.wip_nav.dwarf.endian; |
| 1787 | } | 1831 | } |
| | 1832 | fn gotSym(ctx: @This(), sym_index: u32) UpdateError!void { |
| | 1833 | try ctx.wip_nav.frameExternalReloc(.{ |
| | 1834 | .source_off = @intCast(ctx.wip_nav.debug_frame.items.len), |
| | 1835 | .target_sym = sym_index, |
| | 1836 | .target_off = .got, |
| | 1837 | }); |
| | 1838 | try ctx.wip_nav.debug_frame.appendNTimes(ctx.wip_nav.dwarf.gpa, 0, 4); |
| | 1839 | } |
| 1788 | fn addrSym(ctx: @This(), sym_index: u32) UpdateError!void { | 1840 | fn addrSym(ctx: @This(), sym_index: u32) UpdateError!void { |
| 1789 | try ctx.wip_nav.frameAddrSym(sym_index, 0); | 1841 | try ctx.wip_nav.frameAddrSym(sym_index, 0); |
| 1790 | } | 1842 | } |
| ... | @@ -1800,7 +1852,7 @@ pub const WipNav = struct { | ... | @@ -1800,7 +1852,7 @@ pub const WipNav = struct { |
| 1800 | try wip_nav.frameExternalReloc(.{ | 1852 | try wip_nav.frameExternalReloc(.{ |
| 1801 | .source_off = @intCast(wip_nav.debug_frame.items.len), | 1853 | .source_off = @intCast(wip_nav.debug_frame.items.len), |
| 1802 | .target_sym = sym_index, | 1854 | .target_sym = sym_index, |
| 1803 | .target_off = sym_off, | 1855 | .target_off = .rel(sym_off), |
| 1804 | }); | 1856 | }); |
| 1805 | try wip_nav.debug_frame.appendNTimes(wip_nav.dwarf.gpa, 0, @intFromEnum(wip_nav.dwarf.address_size)); | 1857 | try wip_nav.debug_frame.appendNTimes(wip_nav.dwarf.gpa, 0, @intFromEnum(wip_nav.dwarf.address_size)); |
| 1806 | } | 1858 | } |
| ... | @@ -2286,50 +2338,81 @@ fn getUnit(dwarf: *Dwarf, mod: *Module) !Unit.Index { | ... | @@ -2286,50 +2338,81 @@ fn getUnit(dwarf: *Dwarf, mod: *Module) !Unit.Index { |
| 2286 | const mod_gop = try dwarf.mods.getOrPut(dwarf.gpa, mod); | 2338 | const mod_gop = try dwarf.mods.getOrPut(dwarf.gpa, mod); |
| 2287 | const unit: Unit.Index = @enumFromInt(mod_gop.index); | 2339 | const unit: Unit.Index = @enumFromInt(mod_gop.index); |
| 2288 | if (!mod_gop.found_existing) { | 2340 | if (!mod_gop.found_existing) { |
| 2289 | errdefer _ = dwarf.mods.pop(); | 2341 | { |
| 2290 | mod_gop.value_ptr.* = .{ | 2342 | errdefer _ = dwarf.mods.pop(); |
| 2291 | .root_dir_path = undefined, | 2343 | mod_gop.value_ptr.* = .{ |
| 2292 | .dirs = .empty, | 2344 | .root_dir_path = undefined, |
| 2293 | .files = .empty, | 2345 | .dirs = .empty, |
| 2294 | }; | 2346 | .files = .empty, |
| 2295 | errdefer mod_gop.value_ptr.dirs.deinit(dwarf.gpa); | 2347 | }; |
| 2296 | try mod_gop.value_ptr.dirs.putNoClobber(dwarf.gpa, unit, {}); | 2348 | errdefer mod_gop.value_ptr.dirs.deinit(dwarf.gpa); |
| 2297 | assert(try dwarf.debug_aranges.section.addUnit( | 2349 | try mod_gop.value_ptr.dirs.putNoClobber(dwarf.gpa, unit, {}); |
| 2298 | DebugAranges.headerBytes(dwarf), | 2350 | assert(try dwarf.debug_aranges.section.addUnit( |
| 2299 | DebugAranges.trailerBytes(dwarf), | 2351 | DebugAranges.headerBytes(dwarf), |
| 2300 | dwarf, | 2352 | DebugAranges.trailerBytes(dwarf), |
| 2301 | ) == unit); | 2353 | dwarf, |
| 2302 | errdefer dwarf.debug_aranges.section.popUnit(dwarf.gpa); | 2354 | ) == unit); |
| 2303 | assert(try dwarf.debug_frame.section.addUnit( | 2355 | errdefer dwarf.debug_aranges.section.popUnit(dwarf.gpa); |
| 2304 | DebugFrame.headerBytes(dwarf), | 2356 | assert(try dwarf.debug_frame.section.addUnit( |
| 2305 | DebugFrame.trailerBytes(dwarf), | 2357 | DebugFrame.headerBytes(dwarf), |
| 2306 | dwarf, | 2358 | DebugFrame.trailerBytes(dwarf), |
| 2307 | ) == unit); | 2359 | dwarf, |
| 2308 | errdefer dwarf.debug_frame.section.popUnit(dwarf.gpa); | 2360 | ) == unit); |
| 2309 | assert(try dwarf.debug_info.section.addUnit( | 2361 | errdefer dwarf.debug_frame.section.popUnit(dwarf.gpa); |
| 2310 | DebugInfo.headerBytes(dwarf), | 2362 | assert(try dwarf.debug_info.section.addUnit( |
| 2311 | DebugInfo.trailer_bytes, | 2363 | DebugInfo.headerBytes(dwarf), |
| 2312 | dwarf, | 2364 | DebugInfo.trailer_bytes, |
| 2313 | ) == unit); | 2365 | dwarf, |
| 2314 | errdefer dwarf.debug_info.section.popUnit(dwarf.gpa); | 2366 | ) == unit); |
| 2315 | assert(try dwarf.debug_line.section.addUnit( | 2367 | errdefer dwarf.debug_info.section.popUnit(dwarf.gpa); |
| 2316 | DebugLine.headerBytes(dwarf, 5, 25), | 2368 | assert(try dwarf.debug_line.section.addUnit( |
| 2317 | DebugLine.trailer_bytes, | 2369 | DebugLine.headerBytes(dwarf, 5, 25), |
| 2318 | dwarf, | 2370 | DebugLine.trailer_bytes, |
| 2319 | ) == unit); | 2371 | dwarf, |
| 2320 | errdefer dwarf.debug_line.section.popUnit(dwarf.gpa); | 2372 | ) == unit); |
| 2321 | assert(try dwarf.debug_loclists.section.addUnit( | 2373 | errdefer dwarf.debug_line.section.popUnit(dwarf.gpa); |
| 2322 | DebugLocLists.headerBytes(dwarf), | 2374 | assert(try dwarf.debug_loclists.section.addUnit( |
| 2323 | DebugLocLists.trailer_bytes, | 2375 | DebugLocLists.headerBytes(dwarf), |
| 2324 | dwarf, | 2376 | DebugLocLists.trailer_bytes, |
| 2325 | ) == unit); | 2377 | dwarf, |
| 2326 | errdefer dwarf.debug_loclists.section.popUnit(dwarf.gpa); | 2378 | ) == unit); |
| 2327 | assert(try dwarf.debug_rnglists.section.addUnit( | 2379 | errdefer dwarf.debug_loclists.section.popUnit(dwarf.gpa); |
| 2328 | DebugRngLists.headerBytes(dwarf), | 2380 | assert(try dwarf.debug_rnglists.section.addUnit( |
| 2329 | DebugRngLists.trailer_bytes, | 2381 | DebugRngLists.headerBytes(dwarf), |
| 2330 | dwarf, | 2382 | DebugRngLists.trailer_bytes, |
| 2331 | ) == unit); | 2383 | dwarf, |
| 2332 | errdefer dwarf.debug_rnglists.section.popUnit(dwarf.gpa); | 2384 | ) == unit); |
| | 2385 | errdefer dwarf.debug_rnglists.section.popUnit(dwarf.gpa); |
| | 2386 | } |
| | 2387 | //if (dwarf.bin_file.cast(.elf)) |elf_file| { |
| | 2388 | // if (unit == .main) assert(try dwarf.addCommonEntry(unit) == .got_proc); |
| | 2389 | // if (mod.pic and dwarf.debug_info.section.getUnit(.main).getEntry(.got_proc).len == 0) { |
| | 2390 | // var wip_nav: WipNav = .{ |
| | 2391 | // .dwarf = dwarf, |
| | 2392 | // .pt = undefined, |
| | 2393 | // .unit = .main, |
| | 2394 | // .entry = .got_proc, |
| | 2395 | // .any_children = false, |
| | 2396 | // .func = .none, |
| | 2397 | // .func_sym_index = undefined, |
| | 2398 | // .func_high_pc = undefined, |
| | 2399 | // .blocks = undefined, |
| | 2400 | // .cfi = undefined, |
| | 2401 | // .debug_frame = .empty, |
| | 2402 | // .debug_info = .empty, |
| | 2403 | // .debug_line = .empty, |
| | 2404 | // .debug_loclists = .empty, |
| | 2405 | // .pending_lazy = .empty, |
| | 2406 | // }; |
| | 2407 | // defer wip_nav.deinit(); |
| | 2408 | // try wip_nav.abbrevCode(.proc); |
| | 2409 | // try wip_nav.infoExprLoc(.{ .deref = &.{ .plus = .{ |
| | 2410 | // &.empty, |
| | 2411 | // &.{ .addr_reloc = try elf_file.zigObjectPtr().?.getGlobalSymbol(elf_file, "_GLOBAL_OFFSET_TABLE_", null) }, |
| | 2412 | // } } }); |
| | 2413 | // try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items); |
| | 2414 | // } |
| | 2415 | //} |
| 2333 | } | 2416 | } |
| 2334 | return unit; | 2417 | return unit; |
| 2335 | } | 2418 | } |
| ... | @@ -2384,7 +2467,8 @@ fn initWipNavInner( | ... | @@ -2384,7 +2467,8 @@ fn initWipNavInner( |
| 2384 | else => {}, | 2467 | else => {}, |
| 2385 | } | 2468 | } |
| 2386 | | 2469 | |
| 2387 | const unit = try dwarf.getUnit(file.mod.?); | 2470 | const mod = file.mod.?; |
| | 2471 | const unit = try dwarf.getUnit(mod); |
| 2388 | const nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, nav_index); | 2472 | const nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, nav_index); |
| 2389 | errdefer _ = if (!nav_gop.found_existing) dwarf.navs.pop(); | 2473 | errdefer _ = if (!nav_gop.found_existing) dwarf.navs.pop(); |
| 2390 | if (nav_gop.found_existing) { | 2474 | if (nav_gop.found_existing) { |
| ... | @@ -2425,13 +2509,22 @@ fn initWipNavInner( | ... | @@ -2425,13 +2509,22 @@ fn initWipNavInner( |
| 2425 | }, &nav, inst_info.file, &decl); | 2509 | }, &nav, inst_info.file, &decl); |
| 2426 | try wip_nav.strp(nav.fqn.toSlice(ip)); | 2510 | try wip_nav.strp(nav.fqn.toSlice(ip)); |
| 2427 | const ty: Type = nav_val.typeOf(zcu); | 2511 | const ty: Type = nav_val.typeOf(zcu); |
| 2428 | const addr: Loc = .{ .addr = .{ .sym = sym_index } }; | 2512 | const addr: Loc = .{ .addr_reloc = sym_index }; |
| 2429 | const loc: Loc = if (decl.is_threadlocal) .{ .form_tls_address = &addr } else addr; | 2513 | const loc: Loc = loc: { |
| | 2514 | if (dwarf.bin_file.cast(.elf)) |elf_file| if (decl.linkage == .@"extern" and mod.pic) |
| | 2515 | // TODO: lldb doesn't support call :( |
| | 2516 | //.{ .call = .{ .args = &.{.{ .got_reloc = sym_index }}, .unit = .main, .entry = .got_proc } } |
| | 2517 | break :loc .{ .deref = &.{ .plus = .{ |
| | 2518 | &.{ .addr_reloc = try elf_file.zigObjectPtr().?.getGlobalSymbol(elf_file, "_GLOBAL_OFFSET_TABLE_", null) }, |
| | 2519 | &.{ .got_reloc = sym_index }, |
| | 2520 | } } }; |
| | 2521 | break :loc if (decl.is_threadlocal) .{ .form_tls_address = &addr } else addr; |
| | 2522 | }; |
| 2430 | switch (decl.kind) { | 2523 | switch (decl.kind) { |
| 2431 | .unnamed_test, .@"test", .decltest, .@"comptime", .@"usingnamespace" => unreachable, | 2524 | .unnamed_test, .@"test", .decltest, .@"comptime", .@"usingnamespace" => unreachable, |
| 2432 | .@"const" => { | 2525 | .@"const" => { |
| 2433 | const const_ty_reloc_index = try wip_nav.refForward(); | 2526 | const const_ty_reloc_index = try wip_nav.refForward(); |
| 2434 | try wip_nav.infoExprloc(loc); | 2527 | try wip_nav.infoExprLoc(loc); |
| 2435 | try uleb128(diw, nav.status.fully_resolved.alignment.toByteUnits() orelse | 2528 | try uleb128(diw, nav.status.fully_resolved.alignment.toByteUnits() orelse |
| 2436 | ty.abiAlignment(zcu).toByteUnits().?); | 2529 | ty.abiAlignment(zcu).toByteUnits().?); |
| 2437 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); | 2530 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); |
| ... | @@ -2441,7 +2534,7 @@ fn initWipNavInner( | ... | @@ -2441,7 +2534,7 @@ fn initWipNavInner( |
| 2441 | }, | 2534 | }, |
| 2442 | .@"var" => { | 2535 | .@"var" => { |
| 2443 | try wip_nav.refType(ty); | 2536 | try wip_nav.refType(ty); |
| 2444 | try wip_nav.infoExprloc(loc); | 2537 | try wip_nav.infoExprLoc(loc); |
| 2445 | try uleb128(diw, nav.status.fully_resolved.alignment.toByteUnits() orelse | 2538 | try uleb128(diw, nav.status.fully_resolved.alignment.toByteUnits() orelse |
| 2446 | ty.abiAlignment(zcu).toByteUnits().?); | 2539 | ty.abiAlignment(zcu).toByteUnits().?); |
| 2447 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); | 2540 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); |
| ... | @@ -2649,7 +2742,7 @@ pub fn finishWipNavFunc( | ... | @@ -2649,7 +2742,7 @@ pub fn finishWipNavFunc( |
| 2649 | .{ | 2742 | .{ |
| 2650 | .source_off = 1 + @intFromEnum(dwarf.address_size), | 2743 | .source_off = 1 + @intFromEnum(dwarf.address_size), |
| 2651 | .target_sym = wip_nav.func_sym_index, | 2744 | .target_sym = wip_nav.func_sym_index, |
| 2652 | .target_off = code_size, | 2745 | .target_off = .rel(code_size), |
| 2653 | }, | 2746 | }, |
| 2654 | }); | 2747 | }); |
| 2655 | try dwarf.debug_rnglists.section.replaceEntry( | 2748 | try dwarf.debug_rnglists.section.replaceEntry( |
| ... | @@ -3838,7 +3931,7 @@ fn updateLazyValue( | ... | @@ -3838,7 +3931,7 @@ fn updateLazyValue( |
| 3838 | byte_offset += base_ptr.byte_offset; | 3931 | byte_offset += base_ptr.byte_offset; |
| 3839 | }; | 3932 | }; |
| 3840 | try wip_nav.abbrevCode(.location_comptime_value); | 3933 | try wip_nav.abbrevCode(.location_comptime_value); |
| 3841 | try wip_nav.infoExprloc(.{ .implicit_pointer = .{ | 3934 | try wip_nav.infoExprLoc(.{ .implicit_pointer = .{ |
| 3842 | .unit = base_unit, | 3935 | .unit = base_unit, |
| 3843 | .entry = base_entry, | 3936 | .entry = base_entry, |
| 3844 | .offset = byte_offset, | 3937 | .offset = byte_offset, |
| ... | @@ -4360,7 +4453,7 @@ fn refAbbrevCode(dwarf: *Dwarf, abbrev_code: AbbrevCode) UpdateError!@typeInfo(A | ... | @@ -4360,7 +4453,7 @@ fn refAbbrevCode(dwarf: *Dwarf, abbrev_code: AbbrevCode) UpdateError!@typeInfo(A |
| 4360 | assert(abbrev_code != .null); | 4453 | assert(abbrev_code != .null); |
| 4361 | const entry: Entry.Index = @enumFromInt(@intFromEnum(abbrev_code)); | 4454 | const entry: Entry.Index = @enumFromInt(@intFromEnum(abbrev_code)); |
| 4362 | if (dwarf.debug_abbrev.section.getUnit(DebugAbbrev.unit).getEntry(entry).len > 0) return @intFromEnum(abbrev_code); | 4455 | if (dwarf.debug_abbrev.section.getUnit(DebugAbbrev.unit).getEntry(entry).len > 0) return @intFromEnum(abbrev_code); |
| 4363 | var debug_abbrev = std.ArrayList(u8).init(dwarf.gpa); | 4456 | var debug_abbrev: std.ArrayList(u8) = .init(dwarf.gpa); |
| 4364 | defer debug_abbrev.deinit(); | 4457 | defer debug_abbrev.deinit(); |
| 4365 | const daw = debug_abbrev.writer(); | 4458 | const daw = debug_abbrev.writer(); |
| 4366 | const abbrev = AbbrevCode.abbrevs.get(abbrev_code); | 4459 | const abbrev = AbbrevCode.abbrevs.get(abbrev_code); |
| ... | @@ -4422,7 +4515,7 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { | ... | @@ -4422,7 +4515,7 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4422 | mod_info.root_dir_path = try dwarf.debug_line_str.addString(dwarf, root_dir_path); | 4515 | mod_info.root_dir_path = try dwarf.debug_line_str.addString(dwarf, root_dir_path); |
| 4423 | } | 4516 | } |
| 4424 | | 4517 | |
| 4425 | var header = std.ArrayList(u8).init(dwarf.gpa); | 4518 | var header: std.ArrayList(u8) = .init(dwarf.gpa); |
| 4426 | defer header.deinit(); | 4519 | defer header.deinit(); |
| 4427 | if (dwarf.debug_aranges.section.dirty) { | 4520 | if (dwarf.debug_aranges.section.dirty) { |
| 4428 | for (dwarf.debug_aranges.section.units.items, 0..) |*unit_ptr, unit_index| { | 4521 | for (dwarf.debug_aranges.section.units.items, 0..) |*unit_ptr, unit_index| { |
| ... | @@ -4888,6 +4981,7 @@ const AbbrevCode = enum { | ... | @@ -4888,6 +4981,7 @@ const AbbrevCode = enum { |
| 4888 | comptime_value_field_comptime_state, | 4981 | comptime_value_field_comptime_state, |
| 4889 | comptime_value_elem_runtime_bits, | 4982 | comptime_value_elem_runtime_bits, |
| 4890 | comptime_value_elem_comptime_state, | 4983 | comptime_value_elem_comptime_state, |
| | 4984 | //proc, |
| 4891 | | 4985 | |
| 4892 | const decl_bytes = uleb128Bytes(@intFromEnum(AbbrevCode.decl_instance_func_generic)); | 4986 | const decl_bytes = uleb128Bytes(@intFromEnum(AbbrevCode.decl_instance_func_generic)); |
| 4893 | comptime { | 4987 | comptime { |
| ... | @@ -5757,6 +5851,12 @@ const AbbrevCode = enum { | ... | @@ -5757,6 +5851,12 @@ const AbbrevCode = enum { |
| 5757 | .{ .ZIG_comptime_value, .ref_addr }, | 5851 | .{ .ZIG_comptime_value, .ref_addr }, |
| 5758 | }, | 5852 | }, |
| 5759 | }, | 5853 | }, |
| | 5854 | //.proc = .{ |
| | 5855 | // .tag = .dwarf_procedure, |
| | 5856 | // .attrs = &.{ |
| | 5857 | // .{ .location, .exprloc }, |
| | 5858 | // }, |
| | 5859 | //}, |
| 5760 | .null = undefined, | 5860 | .null = undefined, |
| 5761 | }); | 5861 | }); |
| 5762 | }; | 5862 | }; |