| ... | @@ -4,9 +4,7 @@ format: DW.Format, | ... | @@ -4,9 +4,7 @@ format: DW.Format, |
| 4 | endian: std.builtin.Endian, | 4 | endian: std.builtin.Endian, |
| 5 | address_size: AddressSize, | 5 | address_size: AddressSize, |
| 6 | | 6 | |
| 7 | mods: std.AutoArrayHashMapUnmanaged(*Module, struct { | 7 | mods: std.AutoArrayHashMapUnmanaged(*Module, ModInfo), |
| 8 | files: Files, | | |
| 9 | }), | | |
| 10 | types: std.AutoArrayHashMapUnmanaged(InternPool.Index, Entry.Index), | 8 | types: std.AutoArrayHashMapUnmanaged(InternPool.Index, Entry.Index), |
| 11 | navs: std.AutoArrayHashMapUnmanaged(InternPool.Nav.Index, Entry.Index), | 9 | navs: std.AutoArrayHashMapUnmanaged(InternPool.Nav.Index, Entry.Index), |
| 12 | | 10 | |
| ... | @@ -39,7 +37,19 @@ pub const AddressSize = enum(u8) { | ... | @@ -39,7 +37,19 @@ pub const AddressSize = enum(u8) { |
| 39 | _, | 37 | _, |
| 40 | }; | 38 | }; |
| 41 | | 39 | |
| 42 | const Files = std.AutoArrayHashMapUnmanaged(Zcu.File.Index, void); | 40 | const ModInfo = struct { |
| | 41 | root_dir_path: Entry.Index, |
| | 42 | dirs: std.AutoArrayHashMapUnmanaged(Unit.Index, void), |
| | 43 | files: Files, |
| | 44 | |
| | 45 | const Files = std.AutoArrayHashMapUnmanaged(Zcu.File.Index, void); |
| | 46 | |
| | 47 | fn deinit(mod_info: *ModInfo, gpa: std.mem.Allocator) void { |
| | 48 | mod_info.dirs.deinit(gpa); |
| | 49 | mod_info.files.deinit(gpa); |
| | 50 | mod_info.* = undefined; |
| | 51 | } |
| | 52 | }; |
| 43 | | 53 | |
| 44 | const DebugAbbrev = struct { | 54 | const DebugAbbrev = struct { |
| 45 | section: Section, | 55 | section: Section, |
| ... | @@ -92,10 +102,20 @@ const DebugLine = struct { | ... | @@ -92,10 +102,20 @@ const DebugLine = struct { |
| 92 | opcode_base: u8, | 102 | opcode_base: u8, |
| 93 | }; | 103 | }; |
| 94 | | 104 | |
| 95 | fn headerBytes(dwarf: *Dwarf, file_count: u32) u32 { | 105 | fn dirIndexInfo(dir_count: u32) struct { bytes: u8, form: DeclValEnum(DW.FORM) } { |
| | 106 | return if (dir_count <= 1 << 8) |
| | 107 | .{ .bytes = 1, .form = .data1 } |
| | 108 | else if (dir_count <= 1 << 16) |
| | 109 | .{ .bytes = 2, .form = .data2 } |
| | 110 | else |
| | 111 | unreachable; |
| | 112 | } |
| | 113 | |
| | 114 | fn headerBytes(dwarf: *Dwarf, dir_count: u32, file_count: u32) u32 { |
| | 115 | const dir_index_info = dirIndexInfo(dir_count); |
| 96 | return dwarf.unitLengthBytes() + 2 + 1 + 1 + dwarf.sectionOffsetBytes() + 1 + 1 + 1 + 1 + 1 + 1 + 1 * (dwarf.debug_line.header.opcode_base - 1) + | 116 | return dwarf.unitLengthBytes() + 2 + 1 + 1 + dwarf.sectionOffsetBytes() + 1 + 1 + 1 + 1 + 1 + 1 + 1 * (dwarf.debug_line.header.opcode_base - 1) + |
| 97 | 1 + uleb128Bytes(DW.LNCT.path) + uleb128Bytes(DW.FORM.line_strp) + uleb128Bytes(1) + (dwarf.sectionOffsetBytes()) * 1 + | 117 | 1 + uleb128Bytes(DW.LNCT.path) + uleb128Bytes(DW.FORM.line_strp) + uleb128Bytes(dir_count) + (dwarf.sectionOffsetBytes()) * dir_count + |
| 98 | 1 + uleb128Bytes(DW.LNCT.path) + uleb128Bytes(DW.FORM.line_strp) + uleb128Bytes(DW.LNCT.LLVM_source) + uleb128Bytes(DW.FORM.line_strp) + uleb128Bytes(file_count) + (dwarf.sectionOffsetBytes() + dwarf.sectionOffsetBytes()) * file_count; | 118 | 1 + uleb128Bytes(DW.LNCT.path) + uleb128Bytes(DW.FORM.line_strp) + uleb128Bytes(DW.LNCT.directory_index) + uleb128Bytes(@intFromEnum(dir_index_info.form)) + uleb128Bytes(DW.LNCT.LLVM_source) + uleb128Bytes(DW.FORM.line_strp) + uleb128Bytes(file_count) + (dwarf.sectionOffsetBytes() + dir_index_info.bytes + dwarf.sectionOffsetBytes()) * file_count; |
| 99 | } | 119 | } |
| 100 | | 120 | |
| 101 | const trailer_bytes = 1 + uleb128Bytes(0) + | 121 | const trailer_bytes = 1 + uleb128Bytes(0) + |
| ... | @@ -1066,6 +1086,7 @@ pub const WipNav = struct { | ... | @@ -1066,6 +1086,7 @@ pub const WipNav = struct { |
| 1066 | const new_func_info = zcu.funcInfo(func); | 1086 | const new_func_info = zcu.funcInfo(func); |
| 1067 | const new_file = zcu.navFileScopeIndex(new_func_info.owner_nav); | 1087 | const new_file = zcu.navFileScopeIndex(new_func_info.owner_nav); |
| 1068 | const new_unit = try dwarf.getUnit(zcu.fileByIndex(new_file).mod); | 1088 | const new_unit = try dwarf.getUnit(zcu.fileByIndex(new_file).mod); |
| | 1089 | |
| 1069 | const dlw = wip_nav.debug_line.writer(dwarf.gpa); | 1090 | const dlw = wip_nav.debug_line.writer(dwarf.gpa); |
| 1070 | if (dwarf.incremental()) { | 1091 | if (dwarf.incremental()) { |
| 1071 | const new_nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, new_func_info.owner_nav); | 1092 | const new_nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, new_func_info.owner_nav); |
| ... | @@ -1089,9 +1110,14 @@ pub const WipNav = struct { | ... | @@ -1089,9 +1110,14 @@ pub const WipNav = struct { |
| 1089 | const old_func_info = zcu.funcInfo(wip_nav.func); | 1110 | const old_func_info = zcu.funcInfo(wip_nav.func); |
| 1090 | const old_file = zcu.navFileScopeIndex(old_func_info.owner_nav); | 1111 | const old_file = zcu.navFileScopeIndex(old_func_info.owner_nav); |
| 1091 | if (old_file != new_file) { | 1112 | if (old_file != new_file) { |
| 1092 | const new_file_gop = try dwarf.getUnitFiles(new_unit).getOrPut(dwarf.gpa, new_file); | 1113 | const mod_info = dwarf.getModInfo(wip_nav.unit); |
| | 1114 | const mod_gop = try mod_info.dirs.getOrPut(dwarf.gpa, new_unit); |
| | 1115 | errdefer _ = if (!mod_gop.found_existing) mod_info.dirs.pop(); |
| | 1116 | const file_gop = try mod_info.files.getOrPut(dwarf.gpa, new_file); |
| | 1117 | errdefer _ = if (!file_gop.found_existing) mod_info.files.pop(); |
| | 1118 | |
| 1093 | try dlw.writeByte(DW.LNS.set_file); | 1119 | try dlw.writeByte(DW.LNS.set_file); |
| 1094 | try uleb128(dlw, new_file_gop.index); | 1120 | try uleb128(dlw, file_gop.index); |
| 1095 | } | 1121 | } |
| 1096 | | 1122 | |
| 1097 | const old_src_line: i33 = zcu.navSrcLine(old_func_info.owner_nav); | 1123 | const old_src_line: i33 = zcu.navSrcLine(old_func_info.owner_nav); |
| ... | @@ -1437,7 +1463,7 @@ pub fn initMetadata(dwarf: *Dwarf) UpdateError!void { | ... | @@ -1437,7 +1463,7 @@ pub fn initMetadata(dwarf: *Dwarf) UpdateError!void { |
| 1437 | | 1463 | |
| 1438 | pub fn deinit(dwarf: *Dwarf) void { | 1464 | pub fn deinit(dwarf: *Dwarf) void { |
| 1439 | const gpa = dwarf.gpa; | 1465 | const gpa = dwarf.gpa; |
| 1440 | for (dwarf.mods.values()) |*mod_info| mod_info.files.deinit(gpa); | 1466 | for (dwarf.mods.values()) |*mod_info| mod_info.deinit(gpa); |
| 1441 | dwarf.mods.deinit(gpa); | 1467 | dwarf.mods.deinit(gpa); |
| 1442 | dwarf.types.deinit(gpa); | 1468 | dwarf.types.deinit(gpa); |
| 1443 | dwarf.navs.deinit(gpa); | 1469 | dwarf.navs.deinit(gpa); |
| ... | @@ -1458,8 +1484,12 @@ fn getUnit(dwarf: *Dwarf, mod: *Module) UpdateError!Unit.Index { | ... | @@ -1458,8 +1484,12 @@ fn getUnit(dwarf: *Dwarf, mod: *Module) UpdateError!Unit.Index { |
| 1458 | if (!mod_gop.found_existing) { | 1484 | if (!mod_gop.found_existing) { |
| 1459 | errdefer _ = dwarf.mods.pop(); | 1485 | errdefer _ = dwarf.mods.pop(); |
| 1460 | mod_gop.value_ptr.* = .{ | 1486 | mod_gop.value_ptr.* = .{ |
| | 1487 | .root_dir_path = undefined, |
| | 1488 | .dirs = .{}, |
| 1461 | .files = .{}, | 1489 | .files = .{}, |
| 1462 | }; | 1490 | }; |
| | 1491 | errdefer mod_gop.value_ptr.dirs.deinit(dwarf.gpa); |
| | 1492 | try mod_gop.value_ptr.dirs.putNoClobber(dwarf.gpa, unit, {}); |
| 1463 | assert(try dwarf.debug_aranges.section.addUnit( | 1493 | assert(try dwarf.debug_aranges.section.addUnit( |
| 1464 | DebugAranges.headerBytes(dwarf), | 1494 | DebugAranges.headerBytes(dwarf), |
| 1465 | DebugAranges.trailerBytes(dwarf), | 1495 | DebugAranges.trailerBytes(dwarf), |
| ... | @@ -1473,7 +1503,7 @@ fn getUnit(dwarf: *Dwarf, mod: *Module) UpdateError!Unit.Index { | ... | @@ -1473,7 +1503,7 @@ fn getUnit(dwarf: *Dwarf, mod: *Module) UpdateError!Unit.Index { |
| 1473 | ) == unit); | 1503 | ) == unit); |
| 1474 | errdefer dwarf.debug_info.section.popUnit(); | 1504 | errdefer dwarf.debug_info.section.popUnit(); |
| 1475 | assert(try dwarf.debug_line.section.addUnit( | 1505 | assert(try dwarf.debug_line.section.addUnit( |
| 1476 | DebugLine.headerBytes(dwarf, 25), | 1506 | DebugLine.headerBytes(dwarf, 5, 25), |
| 1477 | DebugLine.trailer_bytes, | 1507 | DebugLine.trailer_bytes, |
| 1478 | dwarf, | 1508 | dwarf, |
| 1479 | ) == unit); | 1509 | ) == unit); |
| ... | @@ -1494,8 +1524,12 @@ fn getUnit(dwarf: *Dwarf, mod: *Module) UpdateError!Unit.Index { | ... | @@ -1494,8 +1524,12 @@ fn getUnit(dwarf: *Dwarf, mod: *Module) UpdateError!Unit.Index { |
| 1494 | return unit; | 1524 | return unit; |
| 1495 | } | 1525 | } |
| 1496 | | 1526 | |
| 1497 | fn getUnitFiles(dwarf: *Dwarf, unit: Unit.Index) *Files { | 1527 | fn getUnitIfExists(dwarf: *const Dwarf, mod: *Module) ?Unit.Index { |
| 1498 | return &dwarf.mods.values()[@intFromEnum(unit)].files; | 1528 | return @enumFromInt(dwarf.mods.getIndex(mod) orelse return null); |
| | 1529 | } |
| | 1530 | |
| | 1531 | fn getModInfo(dwarf: *Dwarf, unit: Unit.Index) *ModInfo { |
| | 1532 | return &dwarf.mods.values()[@intFromEnum(unit)]; |
| 1499 | } | 1533 | } |
| 1500 | | 1534 | |
| 1501 | pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index, sym_index: u32) UpdateError!?WipNav { | 1535 | pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index, sym_index: u32) UpdateError!?WipNav { |
| ... | @@ -1745,7 +1779,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In | ... | @@ -1745,7 +1779,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 1745 | }); | 1779 | }); |
| 1746 | try dlw.writeByteNTimes(0, @intFromEnum(dwarf.address_size)); | 1780 | try dlw.writeByteNTimes(0, @intFromEnum(dwarf.address_size)); |
| 1747 | | 1781 | |
| 1748 | const file_gop = try dwarf.getUnitFiles(unit).getOrPut(dwarf.gpa, inst_info.file); | 1782 | const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, inst_info.file); |
| 1749 | try dlw.writeByte(DW.LNS.set_file); | 1783 | try dlw.writeByte(DW.LNS.set_file); |
| 1750 | try uleb128(dlw, file_gop.index); | 1784 | try uleb128(dlw, file_gop.index); |
| 1751 | | 1785 | |
| ... | @@ -2698,7 +2732,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP | ... | @@ -2698,7 +2732,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 2698 | | 2732 | |
| 2699 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 2733 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2700 | try uleb128(diw, @intFromEnum(@as(AbbrevCode, if (loaded_struct.field_types.len == 0) .namespace_file else .file))); | 2734 | try uleb128(diw, @intFromEnum(@as(AbbrevCode, if (loaded_struct.field_types.len == 0) .namespace_file else .file))); |
| 2701 | const file_gop = try dwarf.getUnitFiles(unit).getOrPut(dwarf.gpa, inst_info.file); | 2735 | const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, inst_info.file); |
| 2702 | try uleb128(diw, file_gop.index); | 2736 | try uleb128(diw, file_gop.index); |
| 2703 | try wip_nav.strp(loaded_struct.name.toSlice(ip)); | 2737 | try wip_nav.strp(loaded_struct.name.toSlice(ip)); |
| 2704 | if (loaded_struct.field_types.len > 0) { | 2738 | if (loaded_struct.field_types.len > 0) { |
| ... | @@ -2945,8 +2979,19 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { | ... | @@ -2945,8 +2979,19 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 2945 | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items); | 2979 | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items); |
| 2946 | } | 2980 | } |
| 2947 | | 2981 | |
| 2948 | const cwd = try std.process.getCwdAlloc(dwarf.gpa); | 2982 | { |
| 2949 | defer dwarf.gpa.free(cwd); | 2983 | const cwd = try std.process.getCwdAlloc(dwarf.gpa); |
| | 2984 | defer dwarf.gpa.free(cwd); |
| | 2985 | for (dwarf.mods.keys(), dwarf.mods.values()) |mod, *mod_info| { |
| | 2986 | const root_dir_path = try std.fs.path.resolve(dwarf.gpa, &.{ |
| | 2987 | cwd, |
| | 2988 | mod.root.root_dir.path orelse "", |
| | 2989 | mod.root.sub_path, |
| | 2990 | }); |
| | 2991 | defer dwarf.gpa.free(root_dir_path); |
| | 2992 | mod_info.root_dir_path = try dwarf.debug_line_str.addString(dwarf, root_dir_path); |
| | 2993 | } |
| | 2994 | } |
| 2950 | | 2995 | |
| 2951 | var header = std.ArrayList(u8).init(dwarf.gpa); | 2996 | var header = std.ArrayList(u8).init(dwarf.gpa); |
| 2952 | defer header.deinit(); | 2997 | defer header.deinit(); |
| ... | @@ -2997,7 +3042,7 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { | ... | @@ -2997,7 +3042,7 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 2997 | dwarf.debug_aranges.section.dirty = false; | 3042 | dwarf.debug_aranges.section.dirty = false; |
| 2998 | } | 3043 | } |
| 2999 | if (dwarf.debug_info.section.dirty) { | 3044 | if (dwarf.debug_info.section.dirty) { |
| 3000 | for (dwarf.mods.keys(), dwarf.debug_info.section.units.items, 0..) |mod, *unit_ptr, unit_index| { | 3045 | for (dwarf.mods.keys(), dwarf.mods.values(), dwarf.debug_info.section.units.items, 0..) |mod, mod_info, *unit_ptr, unit_index| { |
| 3001 | const unit: Unit.Index = @enumFromInt(unit_index); | 3046 | const unit: Unit.Index = @enumFromInt(unit_index); |
| 3002 | try unit_ptr.cross_unit_relocs.ensureUnusedCapacity(dwarf.gpa, 1); | 3047 | try unit_ptr.cross_unit_relocs.ensureUnusedCapacity(dwarf.gpa, 1); |
| 3003 | try unit_ptr.cross_section_relocs.ensureUnusedCapacity(dwarf.gpa, 7); | 3048 | try unit_ptr.cross_section_relocs.ensureUnusedCapacity(dwarf.gpa, 7); |
| ... | @@ -3032,22 +3077,14 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { | ... | @@ -3032,22 +3077,14 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 3032 | .target_unit = StringSection.unit, | 3077 | .target_unit = StringSection.unit, |
| 3033 | .target_entry = (try dwarf.debug_line_str.addString(dwarf, "zig " ++ @import("build_options").version)).toOptional(), | 3078 | .target_entry = (try dwarf.debug_line_str.addString(dwarf, "zig " ++ @import("build_options").version)).toOptional(), |
| 3034 | }); | 3079 | }); |
| 3035 | { | 3080 | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); |
| 3036 | const mod_root_path = try std.fs.path.resolve(dwarf.gpa, &.{ | 3081 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ |
| 3037 | cwd, | 3082 | .source_off = @intCast(header.items.len), |
| 3038 | mod.root.root_dir.path orelse "", | 3083 | .target_sec = .debug_line_str, |
| 3039 | mod.root.sub_path, | 3084 | .target_unit = StringSection.unit, |
| 3040 | }); | 3085 | .target_entry = mod_info.root_dir_path.toOptional(), |
| 3041 | defer dwarf.gpa.free(mod_root_path); | 3086 | }); |
| 3042 | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); | 3087 | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); |
| 3043 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ | | |
| 3044 | .source_off = @intCast(header.items.len), | | |
| 3045 | .target_sec = .debug_line_str, | | |
| 3046 | .target_unit = StringSection.unit, | | |
| 3047 | .target_entry = (try dwarf.debug_line_str.addString(dwarf, mod_root_path)).toOptional(), | | |
| 3048 | }); | | |
| 3049 | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); | | |
| 3050 | } | | |
| 3051 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ | 3088 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ |
| 3052 | .source_off = @intCast(header.items.len), | 3089 | .source_off = @intCast(header.items.len), |
| 3053 | .target_sec = .debug_line_str, | 3090 | .target_sec = .debug_line_str, |
| ... | @@ -3097,8 +3134,8 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { | ... | @@ -3097,8 +3134,8 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 3097 | } | 3134 | } |
| 3098 | if (dwarf.debug_line.section.dirty) { | 3135 | if (dwarf.debug_line.section.dirty) { |
| 3099 | for (dwarf.mods.values(), dwarf.debug_line.section.units.items) |mod_info, *unit| | 3136 | for (dwarf.mods.values(), dwarf.debug_line.section.units.items) |mod_info, *unit| |
| 3100 | try unit.resizeHeader(&dwarf.debug_line.section, dwarf, DebugLine.headerBytes(dwarf, @intCast(mod_info.files.count()))); | 3137 | try unit.resizeHeader(&dwarf.debug_line.section, dwarf, DebugLine.headerBytes(dwarf, @intCast(mod_info.dirs.count()), @intCast(mod_info.files.count()))); |
| 3101 | for (dwarf.mods.keys(), dwarf.mods.values(), dwarf.debug_line.section.units.items) |mod, mod_info, *unit| { | 3138 | for (dwarf.mods.values(), dwarf.debug_line.section.units.items) |mod_info, *unit| { |
| 3102 | try unit.cross_section_relocs.ensureUnusedCapacity(dwarf.gpa, 2 * (1 + mod_info.files.count())); | 3139 | try unit.cross_section_relocs.ensureUnusedCapacity(dwarf.gpa, 2 * (1 + mod_info.files.count())); |
| 3103 | header.clearRetainingCapacity(); | 3140 | header.clearRetainingCapacity(); |
| 3104 | try header.ensureTotalCapacity(unit.header_len); | 3141 | try header.ensureTotalCapacity(unit.header_len); |
| ... | @@ -3150,25 +3187,22 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { | ... | @@ -3150,25 +3187,22 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 3150 | header.appendAssumeCapacity(1); | 3187 | header.appendAssumeCapacity(1); |
| 3151 | uleb128(header.fixedWriter(), DW.LNCT.path) catch unreachable; | 3188 | uleb128(header.fixedWriter(), DW.LNCT.path) catch unreachable; |
| 3152 | uleb128(header.fixedWriter(), DW.FORM.line_strp) catch unreachable; | 3189 | uleb128(header.fixedWriter(), DW.FORM.line_strp) catch unreachable; |
| 3153 | uleb128(header.fixedWriter(), 1) catch unreachable; | 3190 | uleb128(header.fixedWriter(), mod_info.dirs.count()) catch unreachable; |
| 3154 | { | 3191 | for (mod_info.dirs.keys()) |dir_unit| { |
| 3155 | const mod_root_path = try std.fs.path.resolve(dwarf.gpa, &.{ | | |
| 3156 | cwd, | | |
| 3157 | mod.root.root_dir.path orelse "", | | |
| 3158 | mod.root.sub_path, | | |
| 3159 | }); | | |
| 3160 | defer dwarf.gpa.free(mod_root_path); | | |
| 3161 | unit.cross_section_relocs.appendAssumeCapacity(.{ | 3192 | unit.cross_section_relocs.appendAssumeCapacity(.{ |
| 3162 | .source_off = @intCast(header.items.len), | 3193 | .source_off = @intCast(header.items.len), |
| 3163 | .target_sec = .debug_line_str, | 3194 | .target_sec = .debug_line_str, |
| 3164 | .target_unit = StringSection.unit, | 3195 | .target_unit = StringSection.unit, |
| 3165 | .target_entry = (try dwarf.debug_line_str.addString(dwarf, mod_root_path)).toOptional(), | 3196 | .target_entry = dwarf.getModInfo(dir_unit).root_dir_path.toOptional(), |
| 3166 | }); | 3197 | }); |
| 3167 | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); | 3198 | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); |
| 3168 | } | 3199 | } |
| 3169 | header.appendAssumeCapacity(2); | 3200 | const dir_index_info = DebugLine.dirIndexInfo(@intCast(mod_info.dirs.count())); |
| | 3201 | header.appendAssumeCapacity(3); |
| 3170 | uleb128(header.fixedWriter(), DW.LNCT.path) catch unreachable; | 3202 | uleb128(header.fixedWriter(), DW.LNCT.path) catch unreachable; |
| 3171 | uleb128(header.fixedWriter(), DW.FORM.line_strp) catch unreachable; | 3203 | uleb128(header.fixedWriter(), DW.FORM.line_strp) catch unreachable; |
| | 3204 | uleb128(header.fixedWriter(), DW.LNCT.directory_index) catch unreachable; |
| | 3205 | uleb128(header.fixedWriter(), @intFromEnum(dir_index_info.form)) catch unreachable; |
| 3172 | uleb128(header.fixedWriter(), DW.LNCT.LLVM_source) catch unreachable; | 3206 | uleb128(header.fixedWriter(), DW.LNCT.LLVM_source) catch unreachable; |
| 3173 | uleb128(header.fixedWriter(), DW.FORM.line_strp) catch unreachable; | 3207 | uleb128(header.fixedWriter(), DW.FORM.line_strp) catch unreachable; |
| 3174 | uleb128(header.fixedWriter(), mod_info.files.count()) catch unreachable; | 3208 | uleb128(header.fixedWriter(), mod_info.files.count()) catch unreachable; |
| ... | @@ -3181,6 +3215,10 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { | ... | @@ -3181,6 +3215,10 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 3181 | .target_entry = (try dwarf.debug_line_str.addString(dwarf, file.sub_file_path)).toOptional(), | 3215 | .target_entry = (try dwarf.debug_line_str.addString(dwarf, file.sub_file_path)).toOptional(), |
| 3182 | }); | 3216 | }); |
| 3183 | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); | 3217 | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); |
| | 3218 | dwarf.writeInt( |
| | 3219 | header.addManyAsSliceAssumeCapacity(dir_index_info.bytes), |
| | 3220 | mod_info.dirs.getIndex(dwarf.getUnitIfExists(file.mod).?).?, |
| | 3221 | ); |
| 3184 | unit.cross_section_relocs.appendAssumeCapacity(.{ | 3222 | unit.cross_section_relocs.appendAssumeCapacity(.{ |
| 3185 | .source_off = @intCast(header.items.len), | 3223 | .source_off = @intCast(header.items.len), |
| 3186 | .target_sec = .debug_line_str, | 3224 | .target_sec = .debug_line_str, |