| ... | ... | @@ -1374,10 +1374,11 @@ pub const WipNav = struct { |
| 1374 | 1374 | any_children: bool, |
| 1375 | 1375 | func: InternPool.Index, |
| 1376 | 1376 | func_sym_index: u32, |
| 1377 | | func_high_reloc: u32, |
| 1378 | | inlined_funcs: std.ArrayListUnmanaged(struct { |
| 1377 | func_high_pc: u32, |
| 1378 | blocks: std.ArrayListUnmanaged(struct { |
| 1379 | 1379 | abbrev_code: u32, |
| 1380 | | high_reloc: u32, |
| 1380 | low_pc_off: u64, |
| 1381 | high_pc: u32, |
| 1381 | 1382 | }), |
| 1382 | 1383 | cfi: struct { |
| 1383 | 1384 | loc: u32, |
| ... | ... | @@ -1391,7 +1392,7 @@ pub const WipNav = struct { |
| 1391 | 1392 | |
| 1392 | 1393 | pub fn deinit(wip_nav: *WipNav) void { |
| 1393 | 1394 | const gpa = wip_nav.dwarf.gpa; |
| 1394 | | if (wip_nav.func != .none) wip_nav.inlined_funcs.deinit(gpa); |
| 1395 | if (wip_nav.func != .none) wip_nav.blocks.deinit(gpa); |
| 1395 | 1396 | wip_nav.debug_frame.deinit(gpa); |
| 1396 | 1397 | wip_nav.debug_info.deinit(gpa); |
| 1397 | 1398 | wip_nav.debug_line.deinit(gpa); |
| ... | ... | @@ -1486,49 +1487,72 @@ pub const WipNav = struct { |
| 1486 | 1487 | try dlw.writeByte(DW.LNS.set_epilogue_begin); |
| 1487 | 1488 | } |
| 1488 | 1489 | |
| 1489 | | pub fn enterInlineFunc(wip_nav: *WipNav, func: InternPool.Index, code_off: u64, line: u32, column: u32) UpdateError!void { |
| 1490 | pub fn enterBlock(wip_nav: *WipNav, code_off: u64) UpdateError!void { |
| 1491 | const dwarf = wip_nav.dwarf; |
| 1492 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 1493 | const block = try wip_nav.blocks.addOne(dwarf.gpa); |
| 1494 | |
| 1495 | block.abbrev_code = @intCast(wip_nav.debug_info.items.len); |
| 1496 | try wip_nav.abbrevCode(.block); |
| 1497 | block.low_pc_off = code_off; |
| 1498 | try wip_nav.infoAddrSym(wip_nav.func_sym_index, code_off); |
| 1499 | block.high_pc = @intCast(wip_nav.debug_info.items.len); |
| 1500 | try diw.writeInt(u32, 0, dwarf.endian); |
| 1501 | wip_nav.any_children = false; |
| 1502 | } |
| 1503 | |
| 1504 | pub fn leaveBlock(wip_nav: *WipNav, code_off: u64) UpdateError!void { |
| 1505 | const block_bytes = comptime uleb128Bytes(@intFromEnum(AbbrevCode.block)); |
| 1506 | const block = wip_nav.blocks.pop(); |
| 1507 | if (wip_nav.any_children) |
| 1508 | try uleb128(wip_nav.debug_info.writer(wip_nav.dwarf.gpa), @intFromEnum(AbbrevCode.null)) |
| 1509 | else |
| 1510 | std.leb.writeUnsignedFixed( |
| 1511 | block_bytes, |
| 1512 | wip_nav.debug_info.items[block.abbrev_code..][0..block_bytes], |
| 1513 | try wip_nav.dwarf.refAbbrevCode(.empty_block), |
| 1514 | ); |
| 1515 | std.mem.writeInt(u32, wip_nav.debug_info.items[block.high_pc..][0..4], @intCast(code_off - block.low_pc_off), wip_nav.dwarf.endian); |
| 1516 | wip_nav.any_children = true; |
| 1517 | } |
| 1518 | |
| 1519 | pub fn enterInlineFunc( |
| 1520 | wip_nav: *WipNav, |
| 1521 | func: InternPool.Index, |
| 1522 | code_off: u64, |
| 1523 | line: u32, |
| 1524 | column: u32, |
| 1525 | ) UpdateError!void { |
| 1490 | 1526 | const dwarf = wip_nav.dwarf; |
| 1491 | 1527 | const zcu = wip_nav.pt.zcu; |
| 1492 | 1528 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 1493 | | const inlined_func = try wip_nav.inlined_funcs.addOne(dwarf.gpa); |
| 1529 | const block = try wip_nav.blocks.addOne(dwarf.gpa); |
| 1494 | 1530 | |
| 1495 | | inlined_func.abbrev_code = @intCast(wip_nav.debug_info.items.len); |
| 1531 | block.abbrev_code = @intCast(wip_nav.debug_info.items.len); |
| 1496 | 1532 | try wip_nav.abbrevCode(.inlined_func); |
| 1497 | 1533 | try wip_nav.refNav(zcu.funcInfo(func).owner_nav); |
| 1498 | 1534 | try uleb128(diw, zcu.navSrcLine(zcu.funcInfo(wip_nav.func).owner_nav) + line + 1); |
| 1499 | 1535 | try uleb128(diw, column + 1); |
| 1500 | | const external_relocs = &dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs; |
| 1501 | | try external_relocs.ensureUnusedCapacity(dwarf.gpa, 2); |
| 1502 | | external_relocs.appendAssumeCapacity(.{ |
| 1503 | | .source_off = @intCast(wip_nav.debug_info.items.len), |
| 1504 | | .target_sym = wip_nav.func_sym_index, |
| 1505 | | .target_off = code_off, |
| 1506 | | }); |
| 1507 | | try diw.writeByteNTimes(0, @intFromEnum(dwarf.address_size)); |
| 1508 | | inlined_func.high_reloc = @intCast(external_relocs.items.len); |
| 1509 | | external_relocs.appendAssumeCapacity(.{ |
| 1510 | | .source_off = @intCast(wip_nav.debug_info.items.len), |
| 1511 | | .target_sym = wip_nav.func_sym_index, |
| 1512 | | .target_off = undefined, |
| 1513 | | }); |
| 1514 | | try diw.writeByteNTimes(0, @intFromEnum(dwarf.address_size)); |
| 1536 | block.low_pc_off = code_off; |
| 1537 | try wip_nav.infoAddrSym(wip_nav.func_sym_index, code_off); |
| 1538 | block.high_pc = @intCast(wip_nav.debug_info.items.len); |
| 1539 | try diw.writeInt(u32, 0, dwarf.endian); |
| 1515 | 1540 | try wip_nav.setInlineFunc(func); |
| 1516 | 1541 | wip_nav.any_children = false; |
| 1517 | 1542 | } |
| 1518 | 1543 | |
| 1519 | 1544 | pub fn leaveInlineFunc(wip_nav: *WipNav, func: InternPool.Index, code_off: u64) UpdateError!void { |
| 1520 | 1545 | const inlined_func_bytes = comptime uleb128Bytes(@intFromEnum(AbbrevCode.inlined_func)); |
| 1521 | | const inlined_func = wip_nav.inlined_funcs.pop(); |
| 1522 | | const external_relocs = &wip_nav.dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs; |
| 1523 | | external_relocs.items[inlined_func.high_reloc].target_off = code_off; |
| 1546 | const block = wip_nav.blocks.pop(); |
| 1524 | 1547 | if (wip_nav.any_children) |
| 1525 | 1548 | try uleb128(wip_nav.debug_info.writer(wip_nav.dwarf.gpa), @intFromEnum(AbbrevCode.null)) |
| 1526 | 1549 | else |
| 1527 | 1550 | std.leb.writeUnsignedFixed( |
| 1528 | 1551 | inlined_func_bytes, |
| 1529 | | wip_nav.debug_info.items[inlined_func.abbrev_code..][0..inlined_func_bytes], |
| 1552 | wip_nav.debug_info.items[block.abbrev_code..][0..inlined_func_bytes], |
| 1530 | 1553 | try wip_nav.dwarf.refAbbrevCode(.empty_inlined_func), |
| 1531 | 1554 | ); |
| 1555 | std.mem.writeInt(u32, wip_nav.debug_info.items[block.high_pc..][0..4], @intCast(code_off - block.low_pc_off), wip_nav.dwarf.endian); |
| 1532 | 1556 | try wip_nav.setInlineFunc(func); |
| 1533 | 1557 | wip_nav.any_children = true; |
| 1534 | 1558 | } |
| ... | ... | @@ -1664,17 +1688,18 @@ pub const WipNav = struct { |
| 1664 | 1688 | return ctx.wip_nav.dwarf.endian; |
| 1665 | 1689 | } |
| 1666 | 1690 | fn addrSym(ctx: @This(), sym_index: u32) UpdateError!void { |
| 1667 | | try ctx.wip_nav.infoAddrSym(sym_index); |
| 1691 | try ctx.wip_nav.infoAddrSym(sym_index, 0); |
| 1668 | 1692 | } |
| 1669 | 1693 | } = .{ .wip_nav = wip_nav }; |
| 1670 | 1694 | try uleb128(adapter.writer(), counter.stream.bytes_written); |
| 1671 | 1695 | try loc.write(adapter); |
| 1672 | 1696 | } |
| 1673 | 1697 | |
| 1674 | | fn infoAddrSym(wip_nav: *WipNav, sym_index: u32) UpdateError!void { |
| 1698 | fn infoAddrSym(wip_nav: *WipNav, sym_index: u32, sym_off: u64) UpdateError!void { |
| 1675 | 1699 | try wip_nav.infoExternalReloc(.{ |
| 1676 | 1700 | .source_off = @intCast(wip_nav.debug_info.items.len), |
| 1677 | 1701 | .target_sym = sym_index, |
| 1702 | .target_off = sym_off, |
| 1678 | 1703 | }); |
| 1679 | 1704 | try wip_nav.debug_info.appendNTimes(wip_nav.dwarf.gpa, 0, @intFromEnum(wip_nav.dwarf.address_size)); |
| 1680 | 1705 | } |
| ... | ... | @@ -1695,17 +1720,18 @@ pub const WipNav = struct { |
| 1695 | 1720 | return ctx.wip_nav.dwarf.endian; |
| 1696 | 1721 | } |
| 1697 | 1722 | fn addrSym(ctx: @This(), sym_index: u32) UpdateError!void { |
| 1698 | | try ctx.wip_nav.frameAddrSym(sym_index); |
| 1723 | try ctx.wip_nav.frameAddrSym(sym_index, 0); |
| 1699 | 1724 | } |
| 1700 | 1725 | } = .{ .wip_nav = wip_nav }; |
| 1701 | 1726 | try uleb128(adapter.writer(), counter.stream.bytes_written); |
| 1702 | 1727 | try loc.write(adapter); |
| 1703 | 1728 | } |
| 1704 | 1729 | |
| 1705 | | fn frameAddrSym(wip_nav: *WipNav, sym_index: u32) UpdateError!void { |
| 1730 | fn frameAddrSym(wip_nav: *WipNav, sym_index: u32, sym_off: u64) UpdateError!void { |
| 1706 | 1731 | try wip_nav.frameExternalReloc(.{ |
| 1707 | 1732 | .source_off = @intCast(wip_nav.debug_frame.items.len), |
| 1708 | 1733 | .target_sym = sym_index, |
| 1734 | .target_off = sym_off, |
| 1709 | 1735 | }); |
| 1710 | 1736 | try wip_nav.debug_frame.appendNTimes(wip_nav.dwarf.gpa, 0, @intFromEnum(wip_nav.dwarf.address_size)); |
| 1711 | 1737 | } |
| ... | ... | @@ -2150,8 +2176,8 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 2150 | 2176 | .any_children = false, |
| 2151 | 2177 | .func = .none, |
| 2152 | 2178 | .func_sym_index = undefined, |
| 2153 | | .func_high_reloc = undefined, |
| 2154 | | .inlined_funcs = undefined, |
| 2179 | .func_high_pc = undefined, |
| 2180 | .blocks = undefined, |
| 2155 | 2181 | .cfi = undefined, |
| 2156 | 2182 | .debug_frame = .{}, |
| 2157 | 2183 | .debug_info = .{}, |
| ... | ... | @@ -2294,7 +2320,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 2294 | 2320 | const func_type = ip.indexToKey(func.ty).func_type; |
| 2295 | 2321 | wip_nav.func = nav_val.toIntern(); |
| 2296 | 2322 | wip_nav.func_sym_index = sym_index; |
| 2297 | | wip_nav.inlined_funcs = .{}; |
| 2323 | wip_nav.blocks = .{}; |
| 2298 | 2324 | if (dwarf.debug_frame.header.format != .none) wip_nav.cfi = .{ |
| 2299 | 2325 | .loc = 0, |
| 2300 | 2326 | .cfa = dwarf.debug_frame.header.initial_instructions[0].def_cfa, |
| ... | ... | @@ -2319,7 +2345,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 2319 | 2345 | .source_off = @intCast(wip_nav.debug_frame.items.len), |
| 2320 | 2346 | }); |
| 2321 | 2347 | try dfw.writeByteNTimes(0, dwarf.sectionOffsetBytes()); |
| 2322 | | try wip_nav.frameAddrSym(sym_index); |
| 2348 | try wip_nav.frameAddrSym(sym_index, 0); |
| 2323 | 2349 | try dfw.writeByteNTimes(undefined, @intFromEnum(dwarf.address_size)); |
| 2324 | 2350 | }, |
| 2325 | 2351 | .eh_frame => { |
| ... | ... | @@ -2346,20 +2372,9 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 2346 | 2372 | try wip_nav.strp(nav.name.toSlice(ip)); |
| 2347 | 2373 | try wip_nav.strp(nav.fqn.toSlice(ip)); |
| 2348 | 2374 | try wip_nav.refType(Type.fromInterned(func_type.return_type)); |
| 2349 | | const external_relocs = &dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs; |
| 2350 | | try external_relocs.ensureUnusedCapacity(dwarf.gpa, 2); |
| 2351 | | external_relocs.appendAssumeCapacity(.{ |
| 2352 | | .source_off = @intCast(wip_nav.debug_info.items.len), |
| 2353 | | .target_sym = sym_index, |
| 2354 | | }); |
| 2355 | | try diw.writeByteNTimes(0, @intFromEnum(dwarf.address_size)); |
| 2356 | | wip_nav.func_high_reloc = @intCast(external_relocs.items.len); |
| 2357 | | external_relocs.appendAssumeCapacity(.{ |
| 2358 | | .source_off = @intCast(wip_nav.debug_info.items.len), |
| 2359 | | .target_sym = sym_index, |
| 2360 | | .target_off = undefined, |
| 2361 | | }); |
| 2362 | | try diw.writeByteNTimes(0, @intFromEnum(dwarf.address_size)); |
| 2375 | try wip_nav.infoAddrSym(sym_index, 0); |
| 2376 | wip_nav.func_high_pc = @intCast(wip_nav.debug_info.items.len); |
| 2377 | try diw.writeInt(u32, 0, dwarf.endian); |
| 2363 | 2378 | try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse |
| 2364 | 2379 | target_info.defaultFunctionAlignment(file.mod.resolved_target.result).toByteUnits().?); |
| 2365 | 2380 | try diw.writeByte(@intFromBool(false)); |
| ... | ... | @@ -2466,8 +2481,7 @@ pub fn finishWipNav( |
| 2466 | 2481 | }, |
| 2467 | 2482 | } |
| 2468 | 2483 | { |
| 2469 | | const external_relocs = &dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs; |
| 2470 | | external_relocs.items[wip_nav.func_high_reloc].target_off = sym.size; |
| 2484 | std.mem.writeInt(u32, wip_nav.debug_info.items[wip_nav.func_high_pc..][0..4], @intCast(sym.size), dwarf.endian); |
| 2471 | 2485 | if (wip_nav.any_children) { |
| 2472 | 2486 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2473 | 2487 | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| ... | ... | @@ -2562,8 +2576,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2562 | 2576 | .any_children = false, |
| 2563 | 2577 | .func = .none, |
| 2564 | 2578 | .func_sym_index = undefined, |
| 2565 | | .func_high_reloc = undefined, |
| 2566 | | .inlined_funcs = undefined, |
| 2579 | .func_high_pc = undefined, |
| 2580 | .blocks = undefined, |
| 2567 | 2581 | .cfi = undefined, |
| 2568 | 2582 | .debug_frame = .{}, |
| 2569 | 2583 | .debug_info = .{}, |
| ... | ... | @@ -3036,8 +3050,8 @@ fn updateType( |
| 3036 | 3050 | .any_children = false, |
| 3037 | 3051 | .func = .none, |
| 3038 | 3052 | .func_sym_index = undefined, |
| 3039 | | .func_high_reloc = undefined, |
| 3040 | | .inlined_funcs = undefined, |
| 3053 | .func_high_pc = undefined, |
| 3054 | .blocks = undefined, |
| 3041 | 3055 | .cfi = undefined, |
| 3042 | 3056 | .debug_frame = .{}, |
| 3043 | 3057 | .debug_info = .{}, |
| ... | ... | @@ -3480,8 +3494,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 3480 | 3494 | .any_children = false, |
| 3481 | 3495 | .func = .none, |
| 3482 | 3496 | .func_sym_index = undefined, |
| 3483 | | .func_high_reloc = undefined, |
| 3484 | | .inlined_funcs = undefined, |
| 3497 | .func_high_pc = undefined, |
| 3498 | .blocks = undefined, |
| 3485 | 3499 | .cfi = undefined, |
| 3486 | 3500 | .debug_frame = .{}, |
| 3487 | 3501 | .debug_info = .{}, |
| ... | ... | @@ -3553,8 +3567,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 3553 | 3567 | .any_children = false, |
| 3554 | 3568 | .func = .none, |
| 3555 | 3569 | .func_sym_index = undefined, |
| 3556 | | .func_high_reloc = undefined, |
| 3557 | | .inlined_funcs = undefined, |
| 3570 | .func_high_pc = undefined, |
| 3571 | .blocks = undefined, |
| 3558 | 3572 | .cfi = undefined, |
| 3559 | 3573 | .debug_frame = .{}, |
| 3560 | 3574 | .debug_info = .{}, |
| ... | ... | @@ -3756,8 +3770,8 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 3756 | 3770 | .any_children = false, |
| 3757 | 3771 | .func = .none, |
| 3758 | 3772 | .func_sym_index = undefined, |
| 3759 | | .func_high_reloc = undefined, |
| 3760 | | .inlined_funcs = undefined, |
| 3773 | .func_high_pc = undefined, |
| 3774 | .blocks = undefined, |
| 3761 | 3775 | .cfi = undefined, |
| 3762 | 3776 | .debug_frame = .{}, |
| 3763 | 3777 | .debug_info = .{}, |
| ... | ... | @@ -4212,6 +4226,8 @@ const AbbrevCode = enum { |
| 4212 | 4226 | empty_packed_struct_type, |
| 4213 | 4227 | union_type, |
| 4214 | 4228 | empty_union_type, |
| 4229 | empty_block, |
| 4230 | block, |
| 4215 | 4231 | empty_inlined_func, |
| 4216 | 4232 | inlined_func, |
| 4217 | 4233 | local_arg, |
| ... | ... | @@ -4319,7 +4335,7 @@ const AbbrevCode = enum { |
| 4319 | 4335 | .{ .linkage_name, .strp }, |
| 4320 | 4336 | .{ .type, .ref_addr }, |
| 4321 | 4337 | .{ .low_pc, .addr }, |
| 4322 | | .{ .high_pc, .addr }, |
| 4338 | .{ .high_pc, .data4 }, |
| 4323 | 4339 | .{ .alignment, .udata }, |
| 4324 | 4340 | .{ .external, .flag }, |
| 4325 | 4341 | .{ .noreturn, .flag }, |
| ... | ... | @@ -4331,7 +4347,7 @@ const AbbrevCode = enum { |
| 4331 | 4347 | .{ .linkage_name, .strp }, |
| 4332 | 4348 | .{ .type, .ref_addr }, |
| 4333 | 4349 | .{ .low_pc, .addr }, |
| 4334 | | .{ .high_pc, .addr }, |
| 4350 | .{ .high_pc, .data4 }, |
| 4335 | 4351 | .{ .alignment, .udata }, |
| 4336 | 4352 | .{ .external, .flag }, |
| 4337 | 4353 | .{ .noreturn, .flag }, |
| ... | ... | @@ -4672,6 +4688,21 @@ const AbbrevCode = enum { |
| 4672 | 4688 | .{ .alignment, .udata }, |
| 4673 | 4689 | }, |
| 4674 | 4690 | }, |
| 4691 | .empty_block = .{ |
| 4692 | .tag = .lexical_block, |
| 4693 | .attrs = &.{ |
| 4694 | .{ .low_pc, .addr }, |
| 4695 | .{ .high_pc, .data4 }, |
| 4696 | }, |
| 4697 | }, |
| 4698 | .block = .{ |
| 4699 | .tag = .lexical_block, |
| 4700 | .children = true, |
| 4701 | .attrs = &.{ |
| 4702 | .{ .low_pc, .addr }, |
| 4703 | .{ .high_pc, .data4 }, |
| 4704 | }, |
| 4705 | }, |
| 4675 | 4706 | .empty_inlined_func = .{ |
| 4676 | 4707 | .tag = .inlined_subroutine, |
| 4677 | 4708 | .attrs = &.{ |
| ... | ... | @@ -4679,7 +4710,7 @@ const AbbrevCode = enum { |
| 4679 | 4710 | .{ .call_line, .udata }, |
| 4680 | 4711 | .{ .call_column, .udata }, |
| 4681 | 4712 | .{ .low_pc, .addr }, |
| 4682 | | .{ .high_pc, .addr }, |
| 4713 | .{ .high_pc, .data4 }, |
| 4683 | 4714 | }, |
| 4684 | 4715 | }, |
| 4685 | 4716 | .inlined_func = .{ |
| ... | ... | @@ -4690,7 +4721,7 @@ const AbbrevCode = enum { |
| 4690 | 4721 | .{ .call_line, .udata }, |
| 4691 | 4722 | .{ .call_column, .udata }, |
| 4692 | 4723 | .{ .low_pc, .addr }, |
| 4693 | | .{ .high_pc, .addr }, |
| 4724 | .{ .high_pc, .data4 }, |
| 4694 | 4725 | }, |
| 4695 | 4726 | }, |
| 4696 | 4727 | .local_arg = .{ |