| ... | ... | @@ -635,8 +635,12 @@ pub const WipNav = struct { |
| 635 | 635 | const zcu = debug.pt.zcu; |
| 636 | 636 | const ip = &zcu.intern_pool; |
| 637 | 637 | const func = zcu.funcInfo(debug.wip_nav.func); |
| 638 | const func_type = ip.indexToKey(func.ty).func_type; |
| 638 | 639 | const inst_info = ip.getNav(func.owner_nav).srcInst(ip).resolveFull(ip).?; |
| 639 | | const decl = zcu.fileByIndex(inst_info.file).zir.?.getDeclaration(inst_info.inst); |
| 640 | const zf = zcu.fileByIndex(inst_info.file); |
| 641 | const mod = zf.mod.?; |
| 642 | const target = &mod.resolved_target.result; |
| 643 | const decl = zf.zir.?.getDeclaration(inst_info.inst); |
| 640 | 644 | const nav = ip.getNav(func.owner_nav); |
| 641 | 645 | const diw = &debug.info_writer.interface; |
| 642 | 646 | try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_func)); |
| ... | ... | @@ -645,10 +649,19 @@ pub const WipNav = struct { |
| 645 | 649 | try diw.writeUleb128(decl.src_column + 1); |
| 646 | 650 | try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private); |
| 647 | 651 | try debug.strp(nav.name.toSlice(ip)); |
| 648 | | try debug.strp(nav.fqn.toSlice(ip)); |
| 652 | try debug.strp(switch (decl.linkage) { |
| 653 | .normal => nav.fqn, |
| 654 | .@"extern", .@"export" => nav.name, |
| 655 | }.toSlice(ip)); |
| 656 | try debug.refType(.fromInterned(func_type.return_type)); |
| 649 | 657 | try dwarf.symbolAddress(&debug.info_writer, debug.wip_nav.func_si, 0); |
| 650 | 658 | debug.info_func_length_offset = diw.end; |
| 651 | 659 | try diw.writeInt(u32, undefined, dwarf.endian); |
| 660 | try diw.writeUleb128( |
| 661 | target_info.minFunctionAlignment(target).max(nav.resolved.?.@"align").toByteUnits().?, |
| 662 | ); |
| 663 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); |
| 664 | try diw.writeByte(@intFromBool(Type.fromInterned(func_type.return_type).isNoReturn(zcu))); |
| 652 | 665 | } |
| 653 | 666 | |
| 654 | 667 | pub fn startDebugLine(debug: *Debug) link.Error!void { |
| ... | ... | @@ -1712,7 +1725,7 @@ pub fn genDebugInfoHeader( |
| 1712 | 1725 | try dwarf.strp(&dwarf.debug_line_str, dih_nw, mod.root_src_path); |
| 1713 | 1726 | try dwarf.sectionOffset( |
| 1714 | 1727 | dih_nw, |
| 1715 | | dwarf.getUnit(comp.root_mod).get(dwarf).debug_info_header_ni.unwrap().?, |
| 1728 | dwarf.getUnit(zcu.root_mod).get(dwarf).debug_info_header_ni.unwrap().?, |
| 1716 | 1729 | compile_unit_offset, |
| 1717 | 1730 | ); |
| 1718 | 1731 | try dwarf.sectionOffset(dih_nw, unit.debug_line_header_ni.unwrap().?, 0); |
| ... | ... | @@ -1726,11 +1739,14 @@ pub fn genDebugInfoHeader( |
| 1726 | 1739 | try dihw.writeUleb128(try dwarf.refAbbrevCode(.module)); |
| 1727 | 1740 | try dwarf.strp(&dwarf.debug_str, dih_nw, mod.fully_qualified_name); |
| 1728 | 1741 | try dihw.writeUleb128(0); |
| 1729 | | for ([_][]const u8{ "builtin", "root", "std" }, [_]*Module{ |
| 1742 | try dwarf.genModuleDependency( |
| 1743 | dih_nw, |
| 1744 | "builtin", |
| 1730 | 1745 | zcu.builtin_modules.get(mod.getBuiltinOptions(comp.config).hash()).?, |
| 1731 | | zcu.root_mod, |
| 1732 | | zcu.std_mod, |
| 1733 | | }) |name, dep| try dwarf.genModuleDependency(dih_nw, name, dep, module_offset); |
| 1746 | module_offset, |
| 1747 | ); |
| 1748 | try dwarf.genModuleDependency(dih_nw, "root", zcu.root_mod, module_offset); |
| 1749 | try dwarf.genModuleDependency(dih_nw, "std", zcu.std_mod, module_offset); |
| 1734 | 1750 | for (mod.deps.keys(), mod.deps.values()) |name, dep| |
| 1735 | 1751 | try dwarf.genModuleDependency(dih_nw, name, dep, module_offset); |
| 1736 | 1752 | for ([2]AbbrevCode{ .pad_1, .pad_n }) |pad| _ = try dwarf.refAbbrevCode(pad); |
| ... | ... | @@ -1739,18 +1755,17 @@ pub fn genDebugInfoHeader( |
| 1739 | 1755 | |
| 1740 | 1756 | fn genModuleDependency( |
| 1741 | 1757 | dwarf: *Dwarf, |
| 1742 | | nw: *MappedFile.Node.Writer, |
| 1758 | di_nw: *MappedFile.Node.Writer, |
| 1743 | 1759 | name: []const u8, |
| 1744 | 1760 | dep: *Module, |
| 1745 | 1761 | module_offset: usize, |
| 1746 | 1762 | ) link.EmitError!void { |
| 1747 | 1763 | const dep_unit = dwarf.getUnit(dep).get(dwarf); |
| 1748 | 1764 | if (!dep_unit.alive) return; |
| 1749 | | const diw = &nw.interface; |
| 1765 | const diw = &di_nw.interface; |
| 1750 | 1766 | try diw.writeUleb128(try dwarf.refAbbrevCode(.module_dependency)); |
| 1751 | | try diw.writeAll(name); |
| 1752 | | try diw.writeByte(0); |
| 1753 | | try dwarf.sectionOffset(nw, dep_unit.debug_info_header_ni.unwrap().?, module_offset); |
| 1767 | try dwarf.strp(&dwarf.debug_str, di_nw, name); |
| 1768 | try dwarf.sectionOffset(di_nw, dep_unit.debug_info_header_ni.unwrap().?, module_offset); |
| 1754 | 1769 | } |
| 1755 | 1770 | |
| 1756 | 1771 | pub fn genDebugInfoPadding(dwarf: *Dwarf, diw: *Writer, size: u64) Writer.Error!void { |
| ... | ... | @@ -1948,9 +1963,10 @@ pub fn updateComptimeNav( |
| 1948 | 1963 | pt: Zcu.PerThread, |
| 1949 | 1964 | nav_index: InternPool.Nav.Index, |
| 1950 | 1965 | ) link.Error!void { |
| 1951 | | const zcu = dwarf.lf.comp.zcu.?; |
| 1966 | const zcu = pt.zcu; |
| 1952 | 1967 | const ip = &zcu.intern_pool; |
| 1953 | 1968 | const nav = ip.getNav(nav_index); |
| 1969 | log.debug("updateComptimeNav({f})", .{nav.fqn.fmt(ip)}); |
| 1954 | 1970 | const inst_info = nav.srcInst(ip).resolveFull(ip).?; |
| 1955 | 1971 | const nav_val: Value = .fromInterned(nav.resolved.?.value); |
| 1956 | 1972 | const file = zcu.fileByIndex(inst_info.file); |
| ... | ... | @@ -1998,6 +2014,7 @@ pub fn updateComptimeNav( |
| 1998 | 2014 | defer di_nw.deinit(); |
| 1999 | 2015 | const parent_cpi = try dwarf.getConst(pt, .fromInterned(zcu.fileRootType(inst_info.file))); |
| 2000 | 2016 | dwarf.genDeclFuncGeneric( |
| 2017 | pt, |
| 2001 | 2018 | &di_nw, |
| 2002 | 2019 | zir, |
| 2003 | 2020 | parent_cpi, |
| ... | ... | @@ -2020,6 +2037,7 @@ pub fn updateComptimeNav( |
| 2020 | 2037 | } |
| 2021 | 2038 | fn genDeclFuncGeneric( |
| 2022 | 2039 | dwarf: *Dwarf, |
| 2040 | pt: Zcu.PerThread, |
| 2023 | 2041 | di_nw: *MappedFile.Node.Writer, |
| 2024 | 2042 | zir: *const std.zig.Zir, |
| 2025 | 2043 | parent_cpi: link.ConstPool.Index, |
| ... | ... | @@ -2035,75 +2053,268 @@ fn genDeclFuncGeneric( |
| 2035 | 2053 | try diw.writeUleb128(decl.src_column + 1); |
| 2036 | 2054 | try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private); |
| 2037 | 2055 | try dwarf.strp(&dwarf.debug_str, di_nw, name); |
| 2038 | | for (param_body) |param_inst| switch (zir.getParamName(param_inst) orelse continue) { |
| 2039 | | .empty => { |
| 2040 | | try diw.writeUleb128(try dwarf.refAbbrevCode(.unnamed_arg)); |
| 2041 | | try diw.writeUleb128(0); |
| 2042 | | }, |
| 2043 | | else => |param_name| { |
| 2044 | | try diw.writeUleb128(try dwarf.refAbbrevCode(.arg)); |
| 2045 | | try dwarf.strp(&dwarf.debug_str, di_nw, zir.nullTerminatedString(param_name)); |
| 2046 | | try diw.writeUleb128(0); |
| 2047 | | }, |
| 2048 | | }; |
| 2056 | var param_index: u32 = 0; |
| 2057 | for (param_body) |param_inst| { |
| 2058 | switch (zir.getParamName(param_inst) orelse break) { |
| 2059 | .empty => try diw.writeUleb128(try dwarf.refAbbrevCode(.unnamed_param)), |
| 2060 | else => |param_name| { |
| 2061 | try diw.writeUleb128(try dwarf.refAbbrevCode(.param)); |
| 2062 | try dwarf.strp(&dwarf.debug_str, di_nw, zir.nullTerminatedString(param_name)); |
| 2063 | }, |
| 2064 | } |
| 2065 | try dwarf.sectionOffset(di_nw, Const.get(try dwarf.getConst( |
| 2066 | pt, |
| 2067 | .fromInterned(fn_ty.param_types.get(&pt.zcu.intern_pool)[param_index]), |
| 2068 | ), dwarf).debug_info_ni.unwrap().?, 0); |
| 2069 | param_index += 1; |
| 2070 | } |
| 2049 | 2071 | if (fn_ty.is_var_args) try diw.writeUleb128(try dwarf.refAbbrevCode(.is_var_args)); |
| 2050 | 2072 | try diw.writeUleb128(@backingInt(AbbrevCode.null)); |
| 2051 | 2073 | try dwarf.genDebugInfoPadding(diw, diw.unusedCapacityLen()); |
| 2052 | 2074 | } |
| 2053 | 2075 | |
| 2054 | | pub fn addConst(dwarf: *Dwarf, cpi: link.ConstPool.Index, val: InternPool.Index) link.Error!void { |
| 2076 | pub fn addConst( |
| 2077 | dwarf: *Dwarf, |
| 2078 | cpi: link.ConstPool.Index, |
| 2079 | val: InternPool.Index, |
| 2080 | addConstNode: *const fn ( |
| 2081 | lf: *link.File, |
| 2082 | ui: Dwarf.Unit.Index, |
| 2083 | cpi: link.ConstPool.Index, |
| 2084 | ) link.Error!MappedFile.Node.Index, |
| 2085 | ) link.Error!void { |
| 2055 | 2086 | const comp = dwarf.lf.comp; |
| 2056 | 2087 | const zcu = comp.zcu.?; |
| 2057 | 2088 | const ip = &zcu.intern_pool; |
| 2058 | | try dwarf.consts.ensureUnusedCapacity(comp.gpa, 1); |
| 2059 | 2089 | |
| 2060 | 2090 | assert(@backingInt(cpi) == dwarf.consts.items.len); |
| 2061 | | dwarf.consts.appendAssumeCapacity(.{ |
| 2062 | | .debug_info_ni = switch (ip.indexToKey(val)) { |
| 2063 | | else => .none, |
| 2064 | | .struct_type, .union_type, .enum_type, .opaque_type => |_, tag| debug_info_ni: { |
| 2091 | try dwarf.consts.append(comp.gpa, .{ |
| 2092 | .debug_info_ni = debug_info_ni: switch (ip.indexToKey(val)) { |
| 2093 | else => try addConstNode(dwarf.lf, dwarf.getUnit(zcu.root_mod), cpi), |
| 2094 | .func => |func| { |
| 2095 | const fi = try dwarf.getFunc(func.owner_nav); |
| 2096 | break :debug_info_ni fi.get(dwarf).debug_info_ni.unwrap().?; |
| 2097 | }, |
| 2098 | .@"extern" => |@"extern"| { |
| 2099 | const gi = try dwarf.getGlobal(@"extern".owner_nav); |
| 2100 | break :debug_info_ni gi.get(dwarf).debug_info_ni.unwrap().?; |
| 2101 | }, |
| 2102 | .struct_type, .union_type, .enum_type, .opaque_type => |_, tag| { |
| 2065 | 2103 | if (switch (tag) { |
| 2104 | else => unreachable, |
| 2066 | 2105 | .struct_type => ip.loadStructType(val).name_nav, |
| 2067 | 2106 | .union_type => ip.loadUnionType(val).name_nav, |
| 2068 | 2107 | .enum_type => ip.loadEnumType(val).name_nav, |
| 2069 | 2108 | .opaque_type => ip.loadOpaqueType(val).name_nav, |
| 2070 | | else => unreachable, |
| 2071 | 2109 | }.unwrap()) |name_nav| { |
| 2072 | 2110 | const name_gi = try dwarf.getGlobal(name_nav); |
| 2073 | 2111 | break :debug_info_ni name_gi.get(dwarf).debug_info_ni.unwrap().?; |
| 2074 | 2112 | } |
| 2075 | | const elf = dwarf.lf.cast(.elf2).?; |
| 2076 | | try elf.nodes.ensureUnusedCapacity(comp.gpa, 1); |
| 2077 | | try elf.dwarf_consts.ensureUnusedCapacity(comp.gpa, 1); |
| 2078 | | const src_inst = Type.fromInterned(val).typeDeclInstAllowGeneratedTag(zcu).?; |
| 2079 | | const unit = dwarf.getUnit(zcu.fileByIndex(src_inst.resolveFile(ip)).mod.?).get(dwarf); |
| 2080 | | const debug_info_ni = elf.addNodeAssumeCapacity( |
| 2081 | | unit.debug_info_ni.unwrap().?.addFloatingChild(comp.gpa, &elf.mf, .{ |
| 2082 | | .enable_next_moved = true, |
| 2083 | | }) catch |err| switch (err) { |
| 2084 | | else => |e| return e, |
| 2085 | | error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{ |
| 2086 | | elf.mf.io_err.?, |
| 2087 | | }), |
| 2088 | | }, |
| 2089 | | .{ .const_debug_info = cpi }, |
| 2090 | | ); |
| 2091 | | elf.dwarf_consts.putAssumeCapacity(cpi, .{ |
| 2092 | | .debug_info_first_target_reloc = .none, |
| 2093 | | .debug_info_first_symbol_reloc = .none, |
| 2094 | | .debug_info_first_node_reloc = .none, |
| 2095 | | }); |
| 2096 | | |
| 2097 | | break :debug_info_ni debug_info_ni; |
| 2098 | | }.toOptional(), |
| 2099 | | }, |
| 2113 | break :debug_info_ni try addConstNode(dwarf.lf, dwarf.getUnit(zcu.fileByIndex( |
| 2114 | Type.fromInterned(val).typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip), |
| 2115 | ).mod.?), cpi); |
| 2116 | }, |
| 2117 | }.toOptional(), |
| 2100 | 2118 | }); |
| 2101 | 2119 | } |
| 2102 | 2120 | |
| 2103 | | pub fn updateConst(dwarf: *Dwarf, cpi: link.ConstPool.Index, val: InternPool.Index) void { |
| 2104 | | _ = dwarf; |
| 2105 | | _ = cpi; |
| 2106 | | _ = val; |
| 2121 | pub fn updateConst( |
| 2122 | dwarf: *Dwarf, |
| 2123 | pt: Zcu.PerThread, |
| 2124 | di_nw: *MappedFile.Node.Writer, |
| 2125 | val: InternPool.Index, |
| 2126 | ) link.Error!void { |
| 2127 | switch (val) { |
| 2128 | .generic_poison_type => log.debug("updateConst(anytype)", .{}), |
| 2129 | else => log.debug("updateConst({f})", .{Value.fromInterned(val).fmtValue(pt)}), |
| 2130 | } |
| 2131 | dwarf.updateConstInner(pt, di_nw, val) catch |err| switch (err) { |
| 2132 | else => |e| return e, |
| 2133 | error.WriteFailed => return dwarf.reportWriteError(di_nw), |
| 2134 | }; |
| 2135 | } |
| 2136 | fn updateConstInner( |
| 2137 | dwarf: *Dwarf, |
| 2138 | pt: Zcu.PerThread, |
| 2139 | di_nw: *MappedFile.Node.Writer, |
| 2140 | val: InternPool.Index, |
| 2141 | ) link.EmitError!void { |
| 2142 | const zcu = pt.zcu; |
| 2143 | const ip = &zcu.intern_pool; |
| 2144 | const diw = &di_nw.interface; |
| 2145 | switch (ip.indexToKey(val)) { |
| 2146 | else => return, |
| 2147 | .struct_type => { |
| 2148 | const loaded_struct = ip.loadStructType(val); |
| 2149 | const ty: Type = .fromInterned(val); |
| 2150 | const file = loaded_struct.zir_index.resolveFile(ip); |
| 2151 | switch (loaded_struct.layout) { |
| 2152 | .auto, .@"extern" => { |
| 2153 | const struct_is_file: bool = if (loaded_struct.zir_index.resolve(ip)) |inst| |
| 2154 | inst == .main_struct_inst |
| 2155 | else |
| 2156 | false; |
| 2157 | if (loaded_struct.name_nav.unwrap()) |nav_index| { |
| 2158 | assert(!struct_is_file); |
| 2159 | const nav = ip.getNav(nav_index); |
| 2160 | const decl_inst = nav.srcInst(ip).resolve(ip).?; |
| 2161 | const decl = zcu.fileByIndex(file).zir.?.getDeclaration(decl_inst); |
| 2162 | try diw.writeUleb128(try dwarf.refAbbrevCode( |
| 2163 | if (loaded_struct.field_types.len == 0) .decl_namespace_struct else .decl_struct, |
| 2164 | )); |
| 2165 | try dwarf.sectionOffset(di_nw, Const.get( |
| 2166 | try dwarf.getConst(pt, .fromInterned(zcu.fileRootType(file))), |
| 2167 | dwarf, |
| 2168 | ).debug_info_ni.unwrap().?, 0); |
| 2169 | try diw.writeInt(u32, decl.src_line + 1, dwarf.endian); |
| 2170 | try diw.writeUleb128(decl.src_column + 1); |
| 2171 | try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private); |
| 2172 | try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip)); |
| 2173 | } else { |
| 2174 | const zfi = loaded_struct.zir_index.resolveFile(ip); |
| 2175 | const ui = dwarf.getUnit(zcu.fileByIndex(zfi).mod.?); |
| 2176 | _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, zfi); |
| 2177 | try diw.writeUleb128(try dwarf.refAbbrevCode(switch (loaded_struct.field_types.len) { |
| 2178 | 0 => if (struct_is_file) .empty_file else .empty_struct_type, |
| 2179 | else => if (struct_is_file) .file else .struct_type, |
| 2180 | })); |
| 2181 | try diw.writeUleb128(@backingInt(fi)); |
| 2182 | try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.name.toSlice(ip)); |
| 2183 | } |
| 2184 | if (loaded_struct.field_types.len == 0) { |
| 2185 | if (!struct_is_file) try diw.writeByte(@intFromBool(false)); |
| 2186 | } else { |
| 2187 | try diw.writeUleb128(ty.abiSize(zcu)); |
| 2188 | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 2189 | for (0..loaded_struct.field_types.len) |field_index| { |
| 2190 | const is_comptime = loaded_struct.field_is_comptime_bits.get(ip, field_index); |
| 2191 | // TODO: we currently don't emit information about default values for |
| 2192 | // non-`comptime` fields, because these default values are resolved at a |
| 2193 | // separate time in the compiler frontend. To emit this information, the |
| 2194 | // frontend needs to tell us when the default values are available: like |
| 2195 | // how `Zcu.PerThread.ensureTypeLayoutUpToDate` enqueues a link task to |
| 2196 | // indicate completion of the type's layout, a task should be enqueued |
| 2197 | // by `Zcu.PerThread.ensureStructDefaultsUpToDate`, and upon receiving |
| 2198 | // it we should patch the correct default field values in. |
| 2199 | const field_init: InternPool.Index = if (is_comptime) loaded_struct.field_defaults.getOrNone(ip, field_index) else .none; |
| 2200 | assert(!(is_comptime and field_init == .none)); |
| 2201 | const field_type: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]); |
| 2202 | const has_runtime_bits, const has_comptime_state = switch (field_init) { |
| 2203 | .none => .{ false, false }, |
| 2204 | else => .{ |
| 2205 | field_type.hasRuntimeBits(zcu), |
| 2206 | field_type.comptimeOnly(zcu), |
| 2207 | }, |
| 2208 | }; |
| 2209 | try diw.writeUleb128(try dwarf.refAbbrevCode(if (is_comptime) |
| 2210 | if (has_comptime_state) |
| 2211 | .field_comptime_comptime_state |
| 2212 | else if (has_runtime_bits) |
| 2213 | .field_comptime_runtime_bits |
| 2214 | else |
| 2215 | .field_comptime |
| 2216 | else if (field_init != .none) |
| 2217 | if (has_comptime_state) |
| 2218 | .field_default_comptime_state |
| 2219 | else if (has_runtime_bits) |
| 2220 | .field_default_runtime_bits |
| 2221 | else |
| 2222 | .field |
| 2223 | else |
| 2224 | .field)); |
| 2225 | try dwarf.strp( |
| 2226 | &dwarf.debug_str, |
| 2227 | di_nw, |
| 2228 | loaded_struct.field_names.get(ip)[field_index].toSlice(ip), |
| 2229 | ); |
| 2230 | try dwarf.sectionOffset(di_nw, Const.get( |
| 2231 | try dwarf.getConst(pt, field_type.toValue()), |
| 2232 | dwarf, |
| 2233 | ).debug_info_ni.unwrap().?, 0); |
| 2234 | if (!is_comptime) { |
| 2235 | try diw.writeUleb128(loaded_struct.field_offsets.get(ip)[field_index]); |
| 2236 | try diw.writeUleb128(loaded_struct.field_aligns.getOrNone(ip, field_index).toByteUnits() orelse |
| 2237 | field_type.abiAlignment(zcu).toByteUnits().?); |
| 2238 | } |
| 2239 | if (has_comptime_state) |
| 2240 | try dwarf.sectionOffset(di_nw, Const.get( |
| 2241 | try dwarf.getConst(pt, .fromInterned(field_init)), |
| 2242 | dwarf, |
| 2243 | ).debug_info_ni.unwrap().?, 0) |
| 2244 | else if (has_runtime_bits) |
| 2245 | //try wip_nav.blockValue(.fromInterned(field_init)); |
| 2246 | try diw.writeUleb128(0); |
| 2247 | } |
| 2248 | try diw.writeUleb128(@backingInt(AbbrevCode.null)); |
| 2249 | } |
| 2250 | }, |
| 2251 | .@"packed" => return, |
| 2252 | } |
| 2253 | }, |
| 2254 | .simple_type => |simple_type| switch (simple_type) { |
| 2255 | .f16, |
| 2256 | .f32, |
| 2257 | .f64, |
| 2258 | .f80, |
| 2259 | .f128, |
| 2260 | .usize, |
| 2261 | .isize, |
| 2262 | .c_char, |
| 2263 | .c_short, |
| 2264 | .c_ushort, |
| 2265 | .c_int, |
| 2266 | .c_uint, |
| 2267 | .c_long, |
| 2268 | .c_ulong, |
| 2269 | .c_longlong, |
| 2270 | .c_ulonglong, |
| 2271 | .c_longdouble, |
| 2272 | .bool, |
| 2273 | => { |
| 2274 | const ty: Type = .fromInterned(val); |
| 2275 | try diw.writeUleb128(try dwarf.refAbbrevCode(.numeric_type)); |
| 2276 | try dwarf.strp(&dwarf.debug_str, di_nw, @tagName(simple_type)); |
| 2277 | try diw.writeByte(if (val == .bool_type) |
| 2278 | DW.ATE.boolean |
| 2279 | else if (ty.isRuntimeFloat()) |
| 2280 | DW.ATE.float |
| 2281 | else if (ty.isSignedInt(zcu)) |
| 2282 | DW.ATE.signed |
| 2283 | else if (ty.isUnsignedInt(zcu)) |
| 2284 | DW.ATE.unsigned |
| 2285 | else |
| 2286 | unreachable); |
| 2287 | try diw.writeUleb128(ty.bitSize(zcu)); |
| 2288 | try diw.writeUleb128(ty.abiSize(zcu)); |
| 2289 | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 2290 | }, |
| 2291 | .generic_poison => { |
| 2292 | try diw.writeUleb128(try dwarf.refAbbrevCode(.void_type)); |
| 2293 | try dwarf.strp(&dwarf.debug_str, di_nw, "anytype"); |
| 2294 | }, |
| 2295 | .anyopaque, |
| 2296 | .void, |
| 2297 | .type, |
| 2298 | .comptime_int, |
| 2299 | .comptime_float, |
| 2300 | .noreturn, |
| 2301 | => { |
| 2302 | try diw.writeUleb128(try dwarf.refAbbrevCode(.void_type)); |
| 2303 | try dwarf.strp(&dwarf.debug_str, di_nw, @tagName(simple_type)); |
| 2304 | }, |
| 2305 | inline .null, .undefined => |tag| { |
| 2306 | try diw.writeUleb128(try dwarf.refAbbrevCode(.void_type)); |
| 2307 | try dwarf.strp(&dwarf.debug_str, di_nw, "@TypeOf(" ++ @tagName(tag) ++ ")"); |
| 2308 | }, |
| 2309 | .enum_literal => { |
| 2310 | try diw.writeUleb128(try dwarf.refAbbrevCode(.void_type)); |
| 2311 | try dwarf.strp(&dwarf.debug_str, di_nw, "@EnumLiteral()"); |
| 2312 | }, |
| 2313 | .anyerror => return, |
| 2314 | .adhoc_inferred_error_set => unreachable, |
| 2315 | }, |
| 2316 | } |
| 2317 | try dwarf.genDebugInfoPadding(diw, diw.unusedCapacityLen()); |
| 2107 | 2318 | } |
| 2108 | 2319 | |
| 2109 | 2320 | pub fn updateConstIncomplete( |
| ... | ... | @@ -2112,6 +2323,7 @@ pub fn updateConstIncomplete( |
| 2112 | 2323 | di_nw: *MappedFile.Node.Writer, |
| 2113 | 2324 | val: InternPool.Index, |
| 2114 | 2325 | ) link.Error!void { |
| 2326 | log.debug("updateConstIncomplete({f})", .{Value.fromInterned(val).fmtValue(pt)}); |
| 2115 | 2327 | dwarf.updateConstIncompleteInner(pt, di_nw, val) catch |err| switch (err) { |
| 2116 | 2328 | else => |e| return e, |
| 2117 | 2329 | error.WriteFailed => return dwarf.reportWriteError(di_nw), |
| ... | ... | @@ -2123,8 +2335,7 @@ fn updateConstIncompleteInner( |
| 2123 | 2335 | di_nw: *MappedFile.Node.Writer, |
| 2124 | 2336 | val: InternPool.Index, |
| 2125 | 2337 | ) link.EmitError!void { |
| 2126 | | const comp = dwarf.lf.comp; |
| 2127 | | const zcu = comp.zcu.?; |
| 2338 | const zcu = pt.zcu; |
| 2128 | 2339 | const ip = &zcu.intern_pool; |
| 2129 | 2340 | const diw = &di_nw.interface; |
| 2130 | 2341 | done: { |
| ... | ... | @@ -2133,8 +2344,8 @@ fn updateConstIncompleteInner( |
| 2133 | 2344 | const loaded_struct = ip.loadStructType(val); |
| 2134 | 2345 | if (loaded_struct.zir_index.resolveFull(ip)) |src_inst| switch (src_inst.inst) { |
| 2135 | 2346 | .main_struct_inst => { |
| 2136 | | const ui = dwarf.getUnit(comp.zcu.?.fileByIndex(src_inst.file).mod.?); |
| 2137 | | _, const fi = try ui.get(dwarf).getFile(comp.gpa, ui, src_inst.file); |
| 2347 | const ui = dwarf.getUnit(zcu.fileByIndex(src_inst.file).mod.?); |
| 2348 | _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, src_inst.file); |
| 2138 | 2349 | try diw.writeUleb128(try dwarf.refAbbrevCode(.empty_file)); |
| 2139 | 2350 | try diw.writeUleb128(@backingInt(fi)); |
| 2140 | 2351 | try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.name.toSlice(ip)); |
| ... | ... | @@ -2171,8 +2382,8 @@ fn updateConstIncompleteInner( |
| 2171 | 2382 | }, |
| 2172 | 2383 | else => |val_key| break :done switch (val_key.typeOf()) { |
| 2173 | 2384 | .type_type => { |
| 2174 | | const name = try comp.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)}); |
| 2175 | | defer comp.gpa.free(name); |
| 2385 | const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)}); |
| 2386 | defer zcu.gpa.free(name); |
| 2176 | 2387 | try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_empty_struct_type)); |
| 2177 | 2388 | try dwarf.strp(&dwarf.debug_str, di_nw, name); |
| 2178 | 2389 | try diw.writeByte(@intFromBool(true)); |
| ... | ... | @@ -2203,7 +2414,7 @@ fn updateConstIncompleteInner( |
| 2203 | 2414 | try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private); |
| 2204 | 2415 | } else { |
| 2205 | 2416 | const ui = dwarf.getUnit(zcu.fileByIndex(src_inst.file).mod.?); |
| 2206 | | _, const fi = try ui.get(dwarf).getFile(comp.gpa, ui, src_inst.file); |
| 2417 | _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, src_inst.file); |
| 2207 | 2418 | try diw.writeUleb128(try dwarf.refAbbrevCode(.empty_struct_type)); |
| 2208 | 2419 | try diw.writeUleb128(@backingInt(fi)); |
| 2209 | 2420 | } |
| ... | ... | @@ -2433,7 +2644,8 @@ pub const AbbrevCode = enum { |
| 2433 | 2644 | array_len, |
| 2434 | 2645 | nullary_func_type, |
| 2435 | 2646 | func_type, |
| 2436 | | func_type_param, |
| 2647 | param, |
| 2648 | unnamed_param, |
| 2437 | 2649 | is_var_args, |
| 2438 | 2650 | generated_empty_enum_type, |
| 2439 | 2651 | generated_enum_type, |
| ... | ... | @@ -2651,12 +2863,12 @@ pub const AbbrevCode = enum { |
| 2651 | 2863 | .children = true, |
| 2652 | 2864 | .attrs = decl_attrs ++ .{ |
| 2653 | 2865 | .{ .linkage_name, .strp }, |
| 2654 | | //.{ .type, .ref_addr }, |
| 2866 | .{ .type, .ref_addr }, |
| 2655 | 2867 | .{ .low_pc, .addr }, |
| 2656 | 2868 | .{ .high_pc, .data4 }, |
| 2657 | | //.{ .alignment, .udata }, |
| 2658 | | //.{ .external, .flag }, |
| 2659 | | //.{ .noreturn, .flag }, |
| 2869 | .{ .alignment, .udata }, |
| 2870 | .{ .external, .flag }, |
| 2871 | .{ .noreturn, .flag }, |
| 2660 | 2872 | }, |
| 2661 | 2873 | }, |
| 2662 | 2874 | .decl_nullary_func_generic = .{ |
| ... | ... | @@ -2897,7 +3109,7 @@ pub const AbbrevCode = enum { |
| 2897 | 3109 | .module_dependency = .{ |
| 2898 | 3110 | .tag = .imported_module, |
| 2899 | 3111 | .attrs = &.{ |
| 2900 | | .{ .name, .string }, |
| 3112 | .{ .name, .strp }, |
| 2901 | 3113 | .{ .import, .ref_addr }, |
| 2902 | 3114 | }, |
| 2903 | 3115 | }, |
| ... | ... | @@ -3148,7 +3360,14 @@ pub const AbbrevCode = enum { |
| 3148 | 3360 | .{ .type, .ref_addr }, |
| 3149 | 3361 | }, |
| 3150 | 3362 | }, |
| 3151 | | .func_type_param = .{ |
| 3363 | .param = .{ |
| 3364 | .tag = .formal_parameter, |
| 3365 | .attrs = &.{ |
| 3366 | .{ .name, .strp }, |
| 3367 | .{ .type, .ref_addr }, |
| 3368 | }, |
| 3369 | }, |
| 3370 | .unnamed_param = .{ |
| 3152 | 3371 | .tag = .formal_parameter, |
| 3153 | 3372 | .attrs = &.{ |
| 3154 | 3373 | .{ .type, .ref_addr }, |
| ... | ... | @@ -3578,9 +3797,11 @@ const DW = std.dwarf; |
| 3578 | 3797 | const Dwarf = @This(); |
| 3579 | 3798 | const InternPool = @import("../InternPool.zig"); |
| 3580 | 3799 | const link = @import("../link.zig"); |
| 3800 | const log = std.log.scoped(.dwarf); |
| 3581 | 3801 | const MappedFile = @import("MappedFile.zig"); |
| 3582 | 3802 | const Module = @import("../Module.zig"); |
| 3583 | 3803 | const std = @import("std"); |
| 3804 | const target_info = @import("../target.zig"); |
| 3584 | 3805 | const Type = @import("../Type.zig"); |
| 3585 | 3806 | const Value = @import("../Value.zig"); |
| 3586 | 3807 | const Writer = std.Io.Writer; |