authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-08-19 23:43:02-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-09-03 12:59:38-04:00
logc41b7d1b850ba998bd253461536d25b06bcb41cb
tree6f2f495542a469c15f32faf6a656b938e487c856
parent84c2fd3d781b8843dfd3565139282fddf60e4e97

Dwarf2: start implementing decl debug info


7 files changed, 992 insertions(+), 460 deletions(-)

lib/std/dwarf/TAG.zig+2-2
...@@ -40,8 +40,8 @@ pub const namelist = 0x2b;...@@ -40,8 +40,8 @@ pub const namelist = 0x2b;
40pub const namelist_item = 0x2c;40pub const namelist_item = 0x2c;
41pub const packed_type = 0x2d;41pub const packed_type = 0x2d;
42pub const subprogram = 0x2e;42pub const subprogram = 0x2e;
43pub const template_type_param = 0x2f;43pub const template_type_parameter = 0x2f;
44pub const template_value_param = 0x30;44pub const template_value_parameter = 0x30;
45pub const thrown_type = 0x31;45pub const thrown_type = 0x31;
46pub const try_block = 0x32;46pub const try_block = 0x32;
47pub const variant_part = 0x33;47pub const variant_part = 0x33;
src/Type.zig+16-8
...@@ -109,6 +109,20 @@ pub const Class = enum(u3) {...@@ -109,6 +109,20 @@ pub const Class = enum(u3) {
109 /// Then, aggregates containing fully-comptime types may themselves be either fully-comptime or109 /// Then, aggregates containing fully-comptime types may themselves be either fully-comptime or
110 /// partially-comptime; see the doc comment on `.partially_comptime` for details.110 /// partially-comptime; see the doc comment on `.partially_comptime` for details.
111 fully_comptime,111 fully_comptime,
112
113 pub fn hasRuntimeBits(class: Class) bool {
114 return switch (class) {
115 .no_possible_value, .one_possible_value, .fully_comptime => false,
116 .runtime, .partially_comptime => true,
117 };
118 }
119
120 pub fn comptimeOnly(class: Class) bool {
121 return switch (class) {
122 .no_possible_value, .one_possible_value, .runtime => false,
123 .partially_comptime, .fully_comptime => true,
124 };
125 }
112};126};
113127
114/// Returns the `Class` for the type `ty`. Asserts that the layout of `ty` is resolved.128/// Returns the `Class` for the type `ty`. Asserts that the layout of `ty` is resolved.
...@@ -761,10 +775,7 @@ pub fn toValue(self: Type) Value {...@@ -761,10 +775,7 @@ pub fn toValue(self: Type) Value {
761///775///
762/// * All other types contain some runtime state, so have runtime bits and a non-zero ABI size.776/// * All other types contain some runtime state, so have runtime bits and a non-zero ABI size.
763pub fn hasRuntimeBits(ty: Type, zcu: *const Zcu) bool {777pub fn hasRuntimeBits(ty: Type, zcu: *const Zcu) bool {
764 return switch (ty.classify(zcu)) {778 return ty.classify(zcu).hasRuntimeBits();
765 .no_possible_value, .one_possible_value, .fully_comptime => false,
766 .runtime, .partially_comptime => true,
767 };
768}779}
769780
770/// Returns `true` iff the memory layout of `ty` is defined by the Zig language specification.781/// Returns `true` iff the memory layout of `ty` is defined by the Zig language specification.
...@@ -2195,10 +2206,7 @@ pub fn onePossibleValue(ty: Type, pt: Zcu.PerThread) !?Value {...@@ -2195,10 +2206,7 @@ pub fn onePossibleValue(ty: Type, pt: Zcu.PerThread) !?Value {
2195pub fn comptimeOnly(ty: Type, zcu: *const Zcu) bool {2206pub fn comptimeOnly(ty: Type, zcu: *const Zcu) bool {
2196 if (ty.toIntern() == .generic_poison_type) return false;2207 if (ty.toIntern() == .generic_poison_type) return false;
2197 if (ty.zigTypeTag(zcu) == .error_union and ty.errorUnionPayload(zcu).toIntern() == .generic_poison_type) return false;2208 if (ty.zigTypeTag(zcu) == .error_union and ty.errorUnionPayload(zcu).toIntern() == .generic_poison_type) return false;
2198 return switch (ty.classify(zcu)) {2209 return ty.classify(zcu).comptimeOnly();
2199 .no_possible_value, .one_possible_value, .runtime => false,
2200 .partially_comptime, .fully_comptime => true,
2201 };
2202}2210}
22032211
2204pub fn isVector(ty: Type, zcu: *const Zcu) bool {2212pub fn isVector(ty: Type, zcu: *const Zcu) bool {
src/link.zig+2-1
...@@ -26,9 +26,10 @@ const target_util = @import("target.zig");...@@ -26,9 +26,10 @@ const target_util = @import("target.zig");
26const codegen = @import("codegen.zig");26const codegen = @import("codegen.zig");
27const crash_report = @import("crash_report.zig");27const crash_report = @import("crash_report.zig");
2828
29pub const ConstPool = @import("link/ConstPool.zig");
29pub const LdScript = @import("link/LdScript.zig");30pub const LdScript = @import("link/LdScript.zig");
31pub const MappedFile = @import("link/MappedFile.zig");
30pub const Queue = @import("link/Queue.zig");32pub const Queue = @import("link/Queue.zig");
31pub const ConstPool = @import("link/ConstPool.zig");
3233
33pub const aarch64 = @import("link/aarch64.zig");34pub const aarch64 = @import("link/aarch64.zig");
34pub const loongarch = @import("link/loongarch.zig");35pub const loongarch = @import("link/loongarch.zig");
src/link/ConstPool.zig+1-1
...@@ -134,7 +134,7 @@ pub fn updateContainerType(...@@ -134,7 +134,7 @@ pub fn updateContainerType(
134 const gpa = pt.zcu.comp.gpa;134 const gpa = pt.zcu.comp.gpa;
135 try pool.complete_containers.put(gpa, container_ty, {});135 try pool.complete_containers.put(gpa, container_ty, {});
136 } else {136 } else {
137 _ = pool.complete_containers.fetchSwapRemove(container_ty);137 _ = pool.complete_containers.swapRemove(container_ty);
138 }138 }
139 var opt_dep = pool.container_deps.get(container_ty);139 var opt_dep = pool.container_deps.get(container_ty);
140 while (opt_dep) |dep| : (opt_dep = dep.ptr(pool).next.unwrap()) {140 while (opt_dep) |dep| : (opt_dep = dep.ptr(pool).next.unwrap()) {
src/link/Dwarf.zig+49-49
...@@ -2202,7 +2202,7 @@ pub const WipNav = struct {...@@ -2202,7 +2202,7 @@ pub const WipNav = struct {
2202 wip_nav: *WipNav,2202 wip_nav: *WipNav,
2203 abbrev_code: struct {2203 abbrev_code: struct {
2204 decl: AbbrevCode,2204 decl: AbbrevCode,
2205 decl_abstract: AbbrevCode,2205 decl_specification: AbbrevCode,
2206 decl_instance: AbbrevCode,2206 decl_instance: AbbrevCode,
2207 },2207 },
2208 nav: *const InternPool.Nav,2208 nav: *const InternPool.Nav,
...@@ -2216,11 +2216,11 @@ pub const WipNav = struct {...@@ -2216,11 +2216,11 @@ pub const WipNav = struct {
22162216
2217 const orig_entry = wip_nav.entry;2217 const orig_entry = wip_nav.entry;
2218 defer wip_nav.entry = orig_entry;2218 defer wip_nav.entry = orig_entry;
2219 const parent_type, const is_abstract = if (nav.analysis) |analysis| parent_info: {2219 const parent_type, const is_specification = if (nav.analysis) |analysis| parent_info: {
2220 const parent_type: Type = .fromInterned(zcu.namespacePtr(analysis.namespace).owner_type);2220 const parent_type: Type = .fromInterned(zcu.namespacePtr(analysis.namespace).owner_type);
2221 const decl_gop = try dwarf.decls.getOrPut(dwarf.gpa, analysis.zir_index);2221 const decl_gop = try dwarf.decls.getOrPut(dwarf.gpa, analysis.zir_index);
2222 errdefer _ = if (!decl_gop.found_existing) dwarf.decls.pop();2222 errdefer _ = if (!decl_gop.found_existing) dwarf.decls.pop();
2223 const was_abstract = decl_gop.found_existing and2223 const was_specification = decl_gop.found_existing and
2224 switch (try dwarf.debug_info.declAbbrevCode(wip_nav.unit, decl_gop.value_ptr.*)) {2224 switch (try dwarf.debug_info.declAbbrevCode(wip_nav.unit, decl_gop.value_ptr.*)) {
2225 .null,2225 .null,
2226 .decl_alias,2226 .decl_alias,
...@@ -2242,9 +2242,9 @@ pub const WipNav = struct {...@@ -2242,9 +2242,9 @@ pub const WipNav = struct {
2242 .decl_extern_nullary_func,2242 .decl_extern_nullary_func,
2243 .decl_extern_func,2243 .decl_extern_func,
2244 => false,2244 => false,
2245 .decl_abstract_var,2245 .decl_specification_var,
2246 .decl_abstract_const,2246 .decl_specification_const,
2247 .decl_abstract_func,2247 .decl_specification_func,
2248 => true,2248 => true,
22492249
2250 // This comes from a decl which was previously generated as an incomplete value2250 // This comes from a decl which was previously generated as an incomplete value
...@@ -2255,11 +2255,11 @@ pub const WipNav = struct {...@@ -2255,11 +2255,11 @@ pub const WipNav = struct {
2255 else => |t| std.debug.panic("bad decl abbrev code: {t}", .{t}),2255 else => |t| std.debug.panic("bad decl abbrev code: {t}", .{t}),
2256 };2256 };
2257 if (parent_type.getCaptures(zcu).len == 0) {2257 if (parent_type.getCaptures(zcu).len == 0) {
2258 if (was_abstract) try dwarf.freeCommonEntry(wip_nav.unit, decl_gop.value_ptr.*);2258 if (was_specification) try dwarf.freeCommonEntry(wip_nav.unit, decl_gop.value_ptr.*);
2259 decl_gop.value_ptr.* = orig_entry;2259 decl_gop.value_ptr.* = orig_entry;
2260 break :parent_info .{ parent_type, false };2260 break :parent_info .{ parent_type, false };
2261 } else {2261 } else {
2262 if (was_abstract)2262 if (was_specification)
2263 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(decl_gop.value_ptr.*).clear()2263 dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(decl_gop.value_ptr.*).clear()
2264 else2264 else
2265 decl_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit);2265 decl_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit);
...@@ -2268,8 +2268,8 @@ pub const WipNav = struct {...@@ -2268,8 +2268,8 @@ pub const WipNav = struct {
2268 }2268 }
2269 } else .{ null, false };2269 } else .{ null, false };
22702270
2271 try wip_nav.abbrevCode(if (is_abstract) abbrev_code.decl_abstract else abbrev_code.decl);2271 try wip_nav.abbrevCode(if (is_specification) abbrev_code.decl_specification else abbrev_code.decl);
2272 try wip_nav.refType((if (is_abstract) null else parent_type) orelse2272 try wip_nav.refType((if (is_specification) null else parent_type) orelse
2273 .fromInterned(zcu.fileRootType(file)));2273 .fromInterned(zcu.fileRootType(file)));
2274 assert(diw.end == DebugInfo.declEntryLineOff(dwarf));2274 assert(diw.end == DebugInfo.declEntryLineOff(dwarf));
2275 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);2275 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);
...@@ -2277,14 +2277,14 @@ pub const WipNav = struct {...@@ -2277,14 +2277,14 @@ pub const WipNav = struct {
2277 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);2277 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2278 try wip_nav.strp(nav.name.toSlice(ip));2278 try wip_nav.strp(nav.name.toSlice(ip));
22792279
2280 if (!is_abstract) return;2280 if (!is_specification) return;
2281 const abstract_entry = wip_nav.entry;2281 const specification_entry = wip_nav.entry;
2282 try dwarf.debug_info.section.replaceEntry(wip_nav.unit, abstract_entry, dwarf, wip_nav.debug_info.written());2282 try dwarf.debug_info.section.replaceEntry(wip_nav.unit, specification_entry, dwarf, wip_nav.debug_info.written());
2283 wip_nav.debug_info.clearRetainingCapacity();2283 wip_nav.debug_info.clearRetainingCapacity();
2284 wip_nav.entry = orig_entry;2284 wip_nav.entry = orig_entry;
2285 try wip_nav.abbrevCode(abbrev_code.decl_instance);2285 try wip_nav.abbrevCode(abbrev_code.decl_instance);
2286 try wip_nav.refType(parent_type.?);2286 try wip_nav.refType(parent_type.?);
2287 try wip_nav.infoSectionOffset(.debug_info, wip_nav.unit, abstract_entry, 0);2287 try wip_nav.infoSectionOffset(.debug_info, wip_nav.unit, specification_entry, 0);
2288 }2288 }
2289};2289};
22902290
...@@ -2680,11 +2680,11 @@ fn initWipNavInner(...@@ -2680,11 +2680,11 @@ fn initWipNavInner(
2680 const diw = &wip_nav.debug_info.writer;2680 const diw = &wip_nav.debug_info.writer;
2681 try wip_nav.declCommon(if (func_type.param_types.len > 0 or func_type.is_var_args) .{2681 try wip_nav.declCommon(if (func_type.param_types.len > 0 or func_type.is_var_args) .{
2682 .decl = .decl_extern_func,2682 .decl = .decl_extern_func,
2683 .decl_abstract = .decl_abstract_func,2683 .decl_specification = .decl_specification_func,
2684 .decl_instance = .decl_instance_extern_func,2684 .decl_instance = .decl_instance_extern_func,
2685 } else .{2685 } else .{
2686 .decl = .decl_extern_nullary_func,2686 .decl = .decl_extern_nullary_func,
2687 .decl_abstract = .decl_abstract_func,2687 .decl_specification = .decl_specification_func,
2688 .decl_instance = .decl_instance_extern_nullary_func,2688 .decl_instance = .decl_instance_extern_nullary_func,
2689 }, &nav, inst_info.file, &decl);2689 }, &nav, inst_info.file, &decl);
2690 try wip_nav.strp(@"extern".name.toSlice(ip));2690 try wip_nav.strp(@"extern".name.toSlice(ip));
...@@ -2705,7 +2705,7 @@ fn initWipNavInner(...@@ -2705,7 +2705,7 @@ fn initWipNavInner(
2705 .func => |func| if (func.owner_nav != nav_index) {2705 .func => |func| if (func.owner_nav != nav_index) {
2706 try wip_nav.declCommon(.{2706 try wip_nav.declCommon(.{
2707 .decl = .decl_alias,2707 .decl = .decl_alias,
2708 .decl_abstract = .decl_abstract_const,2708 .decl_specification = .decl_specification_const,
2709 .decl_instance = .decl_instance_alias,2709 .decl_instance = .decl_instance_alias,
2710 }, &nav, inst_info.file, &decl);2710 }, &nav, inst_info.file, &decl);
2711 try wip_nav.refNav(func.owner_nav);2711 try wip_nav.refNav(func.owner_nav);
...@@ -2758,7 +2758,7 @@ fn initWipNavInner(...@@ -2758,7 +2758,7 @@ fn initWipNavInner(
2758 const diw = &wip_nav.debug_info.writer;2758 const diw = &wip_nav.debug_info.writer;
2759 try wip_nav.declCommon(.{2759 try wip_nav.declCommon(.{
2760 .decl = .decl_func,2760 .decl = .decl_func,
2761 .decl_abstract = .decl_abstract_func,2761 .decl_specification = .decl_specification_func,
2762 .decl_instance = .decl_instance_func,2762 .decl_instance = .decl_instance_func,
2763 }, &nav, inst_info.file, &decl);2763 }, &nav, inst_info.file, &decl);
2764 try wip_nav.strp(switch (decl.linkage) {2764 try wip_nav.strp(switch (decl.linkage) {
...@@ -2817,10 +2817,10 @@ fn initWipNavInner(...@@ -2817,10 +2817,10 @@ fn initWipNavInner(
2817 const diw = &wip_nav.debug_info.writer;2817 const diw = &wip_nav.debug_info.writer;
2818 try wip_nav.declCommon(.{2818 try wip_nav.declCommon(.{
2819 .decl = .decl_var,2819 .decl = .decl_var,
2820 .decl_abstract = switch (decl.kind) {2820 .decl_specification = switch (decl.kind) {
2821 .unnamed_test, .@"test", .decltest, .@"comptime" => unreachable,2821 .unnamed_test, .@"test", .decltest, .@"comptime" => unreachable,
2822 .@"const" => .decl_abstract_const,2822 .@"const" => .decl_specification_const,
2823 .@"var" => .decl_abstract_var,2823 .@"var" => .decl_specification_var,
2824 },2824 },
2825 .decl_instance = .decl_instance_var,2825 .decl_instance = .decl_instance_var,
2826 }, &nav, inst_info.file, &decl);2826 }, &nav, inst_info.file, &decl);
...@@ -3181,7 +3181,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo...@@ -3181,7 +3181,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo
3181 .alias => {3181 .alias => {
3182 try wip_nav.declCommon(.{3182 try wip_nav.declCommon(.{
3183 .decl = .decl_alias,3183 .decl = .decl_alias,
3184 .decl_abstract = .decl_abstract_const,3184 .decl_specification = .decl_specification_const,
3185 .decl_instance = .decl_instance_alias,3185 .decl_instance = .decl_instance_alias,
3186 }, &nav, inst_info.file, &decl);3186 }, &nav, inst_info.file, &decl);
3187 try wip_nav.refType(nav_val.toType());3187 try wip_nav.refType(nav_val.toType());
...@@ -3189,7 +3189,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo...@@ -3189,7 +3189,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo
3189 .@"var" => {3189 .@"var" => {
3190 try wip_nav.declCommon(.{3190 try wip_nav.declCommon(.{
3191 .decl = .decl_var,3191 .decl = .decl_var,
3192 .decl_abstract = .decl_abstract_var,3192 .decl_specification = .decl_specification_var,
3193 .decl_instance = .decl_instance_var,3193 .decl_instance = .decl_instance_var,
3194 }, &nav, inst_info.file, &decl);3194 }, &nav, inst_info.file, &decl);
3195 try wip_nav.strp(switch (decl.linkage) {3195 try wip_nav.strp(switch (decl.linkage) {
...@@ -3209,19 +3209,19 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo...@@ -3209,19 +3209,19 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo
3209 const has_comptime_state = nav_ty.comptimeOnly(zcu);3209 const has_comptime_state = nav_ty.comptimeOnly(zcu);
3210 try wip_nav.declCommon(if (has_runtime_bits and has_comptime_state) .{3210 try wip_nav.declCommon(if (has_runtime_bits and has_comptime_state) .{
3211 .decl = .decl_const_runtime_bits_comptime_state,3211 .decl = .decl_const_runtime_bits_comptime_state,
3212 .decl_abstract = .decl_abstract_const,3212 .decl_specification = .decl_specification_const,
3213 .decl_instance = .decl_instance_const_runtime_bits_comptime_state,3213 .decl_instance = .decl_instance_const_runtime_bits_comptime_state,
3214 } else if (has_comptime_state) .{3214 } else if (has_comptime_state) .{
3215 .decl = .decl_const_comptime_state,3215 .decl = .decl_const_comptime_state,
3216 .decl_abstract = .decl_abstract_const,3216 .decl_specification = .decl_specification_const,
3217 .decl_instance = .decl_instance_const_comptime_state,3217 .decl_instance = .decl_instance_const_comptime_state,
3218 } else if (has_runtime_bits) .{3218 } else if (has_runtime_bits) .{
3219 .decl = .decl_const_runtime_bits,3219 .decl = .decl_const_runtime_bits,
3220 .decl_abstract = .decl_abstract_const,3220 .decl_specification = .decl_specification_const,
3221 .decl_instance = .decl_instance_const_runtime_bits,3221 .decl_instance = .decl_instance_const_runtime_bits,
3222 } else .{3222 } else .{
3223 .decl = .decl_const,3223 .decl = .decl_const,
3224 .decl_abstract = .decl_abstract_const,3224 .decl_specification = .decl_specification_const,
3225 .decl_instance = .decl_instance_const,3225 .decl_instance = .decl_instance_const,
3226 }, &nav, inst_info.file, &decl);3226 }, &nav, inst_info.file, &decl);
3227 try wip_nav.strp(switch (decl.linkage) {3227 try wip_nav.strp(switch (decl.linkage) {
...@@ -3245,11 +3245,11 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo...@@ -3245,11 +3245,11 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo
3245 } else true;3245 } else true;
3246 try wip_nav.declCommon(if (is_nullary) .{3246 try wip_nav.declCommon(if (is_nullary) .{
3247 .decl = .decl_nullary_func_generic,3247 .decl = .decl_nullary_func_generic,
3248 .decl_abstract = .decl_abstract_func,3248 .decl_specification = .decl_specification_func,
3249 .decl_instance = .decl_instance_nullary_func_generic,3249 .decl_instance = .decl_instance_nullary_func_generic,
3250 } else .{3250 } else .{
3251 .decl = .decl_func_generic,3251 .decl = .decl_func_generic,
3252 .decl_abstract = .decl_abstract_func,3252 .decl_specification = .decl_specification_func,
3253 .decl_instance = .decl_instance_func_generic,3253 .decl_instance = .decl_instance_func_generic,
3254 }, &nav, inst_info.file, &decl);3254 }, &nav, inst_info.file, &decl);
3255 try wip_nav.refType(.fromInterned(func_type.return_type));3255 try wip_nav.refType(.fromInterned(func_type.return_type));
...@@ -3267,7 +3267,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo...@@ -3267,7 +3267,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo
3267 .func_alias => |owner_nav| {3267 .func_alias => |owner_nav| {
3268 try wip_nav.declCommon(.{3268 try wip_nav.declCommon(.{
3269 .decl = .decl_alias,3269 .decl = .decl_alias,
3270 .decl_abstract = .decl_abstract_const,3270 .decl_specification = .decl_specification_const,
3271 .decl_instance = .decl_instance_alias,3271 .decl_instance = .decl_instance_alias,
3272 }, &nav, inst_info.file, &decl);3272 }, &nav, inst_info.file, &decl);
3273 try wip_nav.refNav(owner_nav);3273 try wip_nav.refNav(owner_nav);
...@@ -3463,7 +3463,7 @@ fn emitIncompleteContainerType(...@@ -3463,7 +3463,7 @@ fn emitIncompleteContainerType(
3463 const decl = zcu.fileByIndex(file).zir.?.getDeclaration(decl_inst);3463 const decl = zcu.fileByIndex(file).zir.?.getDeclaration(decl_inst);
3464 try wip_nav.declCommon(.{3464 try wip_nav.declCommon(.{
3465 .decl = .decl_namespace_struct,3465 .decl = .decl_namespace_struct,
3466 .decl_abstract = .decl_abstract_const,3466 .decl_specification = .decl_specification_const,
3467 .decl_instance = .decl_instance_namespace_struct,3467 .decl_instance = .decl_instance_namespace_struct,
3468 }, &nav, file, &decl);3468 }, &nav, file, &decl);
3469 try wip_nav.debug_info.writer.writeByte(@intFromBool(true));3469 try wip_nav.debug_info.writer.writeByte(@intFromBool(true));
...@@ -3881,11 +3881,11 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co...@@ -3881,11 +3881,11 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
3881 const decl = zcu.fileByIndex(file).zir.?.getDeclaration(decl_inst);3881 const decl = zcu.fileByIndex(file).zir.?.getDeclaration(decl_inst);
3882 try wip_nav.declCommon(if (loaded_struct.field_types.len == 0) .{3882 try wip_nav.declCommon(if (loaded_struct.field_types.len == 0) .{
3883 .decl = .decl_namespace_struct,3883 .decl = .decl_namespace_struct,
3884 .decl_abstract = .decl_abstract_const,3884 .decl_specification = .decl_specification_const,
3885 .decl_instance = .decl_instance_namespace_struct,3885 .decl_instance = .decl_instance_namespace_struct,
3886 } else .{3886 } else .{
3887 .decl = .decl_struct,3887 .decl = .decl_struct,
3888 .decl_abstract = .decl_abstract_const,3888 .decl_specification = .decl_specification_const,
3889 .decl_instance = .decl_instance_struct,3889 .decl_instance = .decl_instance_struct,
3890 }, &nav, file, &decl);3890 }, &nav, file, &decl);
3891 } else {3891 } else {
...@@ -3960,7 +3960,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co...@@ -3960,7 +3960,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
3960 const decl = zcu.fileByIndex(file).zir.?.getDeclaration(decl_inst);3960 const decl = zcu.fileByIndex(file).zir.?.getDeclaration(decl_inst);
3961 try wip_nav.declCommon(.{3961 try wip_nav.declCommon(.{
3962 .decl = .decl_packed_struct,3962 .decl = .decl_packed_struct,
3963 .decl_abstract = .decl_abstract_const,3963 .decl_specification = .decl_specification_const,
3964 .decl_instance = .decl_instance_packed_struct,3964 .decl_instance = .decl_instance_packed_struct,
3965 }, &nav, file, &decl);3965 }, &nav, file, &decl);
3966 break :t true;3966 break :t true;
...@@ -3997,7 +3997,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co...@@ -3997,7 +3997,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
3997 const decl = zcu.fileByIndex(file).zir.?.getDeclaration(decl_inst);3997 const decl = zcu.fileByIndex(file).zir.?.getDeclaration(decl_inst);
3998 try wip_nav.declCommon(.{3998 try wip_nav.declCommon(.{
3999 .decl = .decl_union,3999 .decl = .decl_union,
4000 .decl_abstract = .decl_abstract_const,4000 .decl_specification = .decl_specification_const,
4001 .decl_instance = .decl_instance_union,4001 .decl_instance = .decl_instance_union,
4002 }, &nav, file, &decl);4002 }, &nav, file, &decl);
4003 break :t true;4003 break :t true;
...@@ -4059,7 +4059,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co...@@ -4059,7 +4059,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
4059 const decl = zcu.fileByIndex(file).zir.?.getDeclaration(decl_inst);4059 const decl = zcu.fileByIndex(file).zir.?.getDeclaration(decl_inst);
4060 try wip_nav.declCommon(.{4060 try wip_nav.declCommon(.{
4061 .decl = .decl_packed_union,4061 .decl = .decl_packed_union,
4062 .decl_abstract = .decl_abstract_const,4062 .decl_specification = .decl_specification_const,
4063 .decl_instance = .decl_instance_packed_union,4063 .decl_instance = .decl_instance_packed_union,
4064 }, &nav, file, &decl);4064 }, &nav, file, &decl);
4065 break :t true;4065 break :t true;
...@@ -4092,11 +4092,11 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co...@@ -4092,11 +4092,11 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
4092 const decl = zcu.fileByIndex(file).zir.?.getDeclaration(decl_inst);4092 const decl = zcu.fileByIndex(file).zir.?.getDeclaration(decl_inst);
4093 try wip_nav.declCommon(if (loaded_enum.field_names.len > 0) .{4093 try wip_nav.declCommon(if (loaded_enum.field_names.len > 0) .{
4094 .decl = .decl_enum,4094 .decl = .decl_enum,
4095 .decl_abstract = .decl_abstract_const,4095 .decl_specification = .decl_specification_const,
4096 .decl_instance = .decl_instance_enum,4096 .decl_instance = .decl_instance_enum,
4097 } else .{4097 } else .{
4098 .decl = .decl_empty_enum,4098 .decl = .decl_empty_enum,
4099 .decl_abstract = .decl_abstract_const,4099 .decl_specification = .decl_specification_const,
4100 .decl_instance = .decl_instance_empty_enum,4100 .decl_instance = .decl_instance_empty_enum,
4101 }, &nav, file, &decl);4101 }, &nav, file, &decl);
4102 } else {4102 } else {
...@@ -4134,7 +4134,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co...@@ -4134,7 +4134,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
4134 const decl = zcu.fileByIndex(file).zir.?.getDeclaration(decl_inst);4134 const decl = zcu.fileByIndex(file).zir.?.getDeclaration(decl_inst);
4135 try wip_nav.declCommon(.{4135 try wip_nav.declCommon(.{
4136 .decl = .decl_namespace_struct,4136 .decl = .decl_namespace_struct,
4137 .decl_abstract = .decl_abstract_const,4137 .decl_specification = .decl_specification_const,
4138 .decl_instance = .decl_instance_namespace_struct,4138 .decl_instance = .decl_instance_namespace_struct,
4139 }, &nav, file, &decl);4139 }, &nav, file, &decl);
4140 } else {4140 } else {
...@@ -5136,9 +5136,9 @@ const AbbrevCode = enum {...@@ -5136,9 +5136,9 @@ const AbbrevCode = enum {
5136 decl_func_generic,5136 decl_func_generic,
5137 decl_extern_nullary_func,5137 decl_extern_nullary_func,
5138 decl_extern_func,5138 decl_extern_func,
5139 decl_abstract_var,5139 decl_specification_var,
5140 decl_abstract_const,5140 decl_specification_const,
5141 decl_abstract_func,5141 decl_specification_func,
5142 decl_instance_alias,5142 decl_instance_alias,
5143 decl_instance_empty_enum,5143 decl_instance_empty_enum,
5144 decl_instance_enum,5144 decl_instance_enum,
...@@ -5262,7 +5262,7 @@ const AbbrevCode = enum {...@@ -5262,7 +5262,7 @@ const AbbrevCode = enum {
5262 .{ .accessibility, .data1 },5262 .{ .accessibility, .data1 },
5263 .{ .name, .strp },5263 .{ .name, .strp },
5264 };5264 };
5265 const decl_abstract_abbrev_common_attrs = decl_abbrev_common_attrs ++ &[_]Attr{5265 const decl_specification_abbrev_common_attrs = decl_abbrev_common_attrs ++ &[_]Attr{
5266 .{ .declaration, .flag_present },5266 .{ .declaration, .flag_present },
5267 };5267 };
5268 const decl_instance_abbrev_common_attrs = &[_]Attr{5268 const decl_instance_abbrev_common_attrs = &[_]Attr{
...@@ -5447,17 +5447,17 @@ const AbbrevCode = enum {...@@ -5447,17 +5447,17 @@ const AbbrevCode = enum {
5447 .{ .noreturn, .flag },5447 .{ .noreturn, .flag },
5448 },5448 },
5449 },5449 },
5450 .decl_abstract_var = .{5450 .decl_specification_var = .{
5451 .tag = .variable,5451 .tag = .variable,
5452 .attrs = decl_abstract_abbrev_common_attrs,5452 .attrs = decl_specification_abbrev_common_attrs,
5453 },5453 },
5454 .decl_abstract_const = .{5454 .decl_specification_const = .{
5455 .tag = .constant,5455 .tag = .constant,
5456 .attrs = decl_abstract_abbrev_common_attrs,5456 .attrs = decl_specification_abbrev_common_attrs,
5457 },5457 },
5458 .decl_abstract_func = .{5458 .decl_specification_func = .{
5459 .tag = .subprogram,5459 .tag = .subprogram,
5460 .attrs = decl_abstract_abbrev_common_attrs,5460 .attrs = decl_specification_abbrev_common_attrs,
5461 },5461 },
5462 .decl_instance_alias = .{5462 .decl_instance_alias = .{
5463 .tag = .imported_declaration,5463 .tag = .imported_declaration,
src/link/Dwarf2.zig+784-351
...@@ -9,7 +9,11 @@ units: []Unit,...@@ -9,7 +9,11 @@ units: []Unit,
9consts: std.ArrayList(Const),9consts: std.ArrayList(Const),
10globals: std.array_hash_map.Auto(InternPool.Nav.Index, Global),10globals: std.array_hash_map.Auto(InternPool.Nav.Index, Global),
11funcs: std.array_hash_map.Auto(InternPool.Nav.Index, Func),11funcs: std.array_hash_map.Auto(InternPool.Nav.Index, Func),
12decls: std.array_hash_map.Auto(InternPool.TrackedInst.Index, MappedFile.Node.Index),12decls: std.array_hash_map.Auto(InternPool.TrackedInst.Index, Decl),
13pending_decl: ?struct {
14 di: Decl.Index,
15 instance_val: InternPool.Index,
16},
1317
14debug_abbrev: Abbrev,18debug_abbrev: Abbrev,
15frame: Frame,19frame: Frame,
...@@ -135,6 +139,22 @@ pub const Func = struct {...@@ -135,6 +139,22 @@ pub const Func = struct {
135 };139 };
136};140};
137141
142pub const Decl = struct {
143 debug_info_ni: MappedFile.Node.Index.Optional,
144
145 pub const Index = enum(u32) {
146 _,
147
148 pub fn srcInst(di: Decl.Index, dwarf: *Dwarf) InternPool.TrackedInst.Index {
149 return dwarf.decls.keys()[@backingInt(di)];
150 }
151
152 pub fn get(di: Decl.Index, dwarf: *Dwarf) *Decl {
153 return &dwarf.decls.values()[@backingInt(di)];
154 }
155 };
156};
157
138pub const Frame = struct {158pub const Frame = struct {
139 header: Header,159 header: Header,
140160
...@@ -632,29 +652,33 @@ pub const WipNav = struct {...@@ -632,29 +652,33 @@ pub const WipNav = struct {
632 }652 }
633 fn startFuncDebugInfoInner(debug: *Debug) link.EmitError!void {653 fn startFuncDebugInfoInner(debug: *Debug) link.EmitError!void {
634 const dwarf = debug.wip_nav.dwarf;654 const dwarf = debug.wip_nav.dwarf;
635 const zcu = debug.pt.zcu;655 const pt = debug.pt;
656 const zcu = pt.zcu;
636 const ip = &zcu.intern_pool;657 const ip = &zcu.intern_pool;
637 const func = zcu.funcInfo(debug.wip_nav.func);658 const func = zcu.funcInfo(debug.wip_nav.func);
659 const nav = ip.getNav(func.owner_nav);
638 const func_type = ip.indexToKey(func.ty).func_type;660 const func_type = ip.indexToKey(func.ty).func_type;
639 const inst_info = ip.getNav(func.owner_nav).srcInst(ip).resolveFull(ip).?;661 const inst_info = nav.srcInst(ip).resolveFull(ip).?;
640 const zf = zcu.fileByIndex(inst_info.file);662 const zf = zcu.fileByIndex(inst_info.file);
641 const mod = zf.mod.?;663 const target = &zf.mod.?.resolved_target.result;
642 const target = &mod.resolved_target.result;
643 const decl = zf.zir.?.getDeclaration(inst_info.inst);664 const decl = zf.zir.?.getDeclaration(inst_info.inst);
644 const nav = ip.getNav(func.owner_nav);665 const di_nw = &debug.info_writer;
645 const diw = &debug.info_writer.interface;666 const diw = &di_nw.interface;
646 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_func));667 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_func));
647 try debug.refType(.fromInterned(zcu.fileRootType(inst_info.file)));668 try dwarf.refConst(pt, di_nw, .fromInterned(ip.namespacePtr(switch (func.generic_owner) {
669 .none => nav,
670 else => |generic_owner| ip.getNav(zcu.funcInfo(generic_owner).owner_nav),
671 }.analysis.?.namespace).owner_type));
648 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);672 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);
649 try diw.writeUleb128(decl.src_column + 1);673 try diw.writeUleb128(decl.src_column + 1);
650 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);674 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
651 try debug.strp(nav.name.toSlice(ip));675 try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip));
652 try debug.strp(switch (decl.linkage) {676 try dwarf.strp(&dwarf.debug_str, di_nw, switch (decl.linkage) {
653 .normal => nav.fqn,677 .normal => nav.fqn,
654 .@"extern", .@"export" => nav.name,678 .@"extern", .@"export" => nav.name,
655 }.toSlice(ip));679 }.toSlice(ip));
656 try debug.refType(.fromInterned(func_type.return_type));680 try dwarf.refConst(pt, di_nw, .fromInterned(func_type.return_type));
657 try dwarf.symbolAddress(&debug.info_writer, debug.wip_nav.func_si, 0);681 try dwarf.symbolAddress(di_nw, debug.wip_nav.func_si, 0);
658 debug.info_func_length_offset = diw.end;682 debug.info_func_length_offset = diw.end;
659 try diw.writeInt(u32, undefined, dwarf.endian);683 try diw.writeInt(u32, undefined, dwarf.endian);
660 try diw.writeUleb128(684 try diw.writeUleb128(
...@@ -756,12 +780,14 @@ pub const WipNav = struct {...@@ -756,12 +780,14 @@ pub const WipNav = struct {
756 loc: Loc,780 loc: Loc,
757 ) link.EmitError!void {781 ) link.EmitError!void {
758 assert(debug.wip_nav.func != .none);782 assert(debug.wip_nav.func != .none);
759 try debug.abbrevCode(switch (tag) {783 const dwarf = debug.wip_nav.dwarf;
784 const di_nw = &debug.info_writer;
785 try di_nw.interface.writeUleb128(try dwarf.refAbbrevCode(switch (tag) {
760 .arg => if (opt_name) |_| .arg else .unnamed_arg,786 .arg => if (opt_name) |_| .arg else .unnamed_arg,
761 .local_var => if (opt_name) |_| .local_var else unreachable,787 .local_var => if (opt_name) |_| .local_var else unreachable,
762 });788 }));
763 if (opt_name) |name| try debug.strp(name);789 if (opt_name) |name| try dwarf.strp(&dwarf.debug_str, di_nw, name);
764 if (false) try debug.refType(ty);790 try dwarf.refConst(debug.pt, di_nw, ty.toValue());
765 try debug.infoExprLoc(loc);791 try debug.infoExprLoc(loc);
766 debug.any_children = true;792 debug.any_children = true;
767 }793 }
...@@ -785,27 +811,38 @@ pub const WipNav = struct {...@@ -785,27 +811,38 @@ pub const WipNav = struct {
785 val: Value,811 val: Value,
786 ) link.EmitError!void {812 ) link.EmitError!void {
787 assert(debug.wip_nav.func != .none);813 assert(debug.wip_nav.func != .none);
814 const dwarf = debug.wip_nav.dwarf;
815 const pt = debug.pt;
788 const zcu = debug.pt.zcu;816 const zcu = debug.pt.zcu;
789 const ty = val.typeOf(zcu);817 const ty = val.typeOf(zcu);
790 const has_runtime_bits = ty.hasRuntimeBits(zcu);818 const ty_class = ty.classify(zcu);
791 const has_comptime_state = ty.comptimeOnly(zcu);819 const di_nw = &debug.info_writer;
792 try debug.abbrevCode(if (has_runtime_bits and has_comptime_state) switch (tag) {820 try di_nw.interface.writeUleb128(try dwarf.refAbbrevCode(switch (tag) {
793 .comptime_arg => if (opt_name) |_| .comptime_arg_runtime_bits_comptime_state else .unnamed_comptime_arg_runtime_bits_comptime_state,821 .comptime_arg => if (opt_name) |_| switch (ty_class) {
794 .local_const => if (opt_name) |_| .local_const_runtime_bits_comptime_state else unreachable,822 .no_possible_value => unreachable,
795 } else if (has_comptime_state) switch (tag) {823 .one_possible_value => .comptime_arg,
796 .comptime_arg => if (opt_name) |_| .comptime_arg_comptime_state else .unnamed_comptime_arg_comptime_state,824 .runtime => .comptime_arg_fully_runtime,
797 .local_const => if (opt_name) |_| .local_const_comptime_state else unreachable,825 .partially_comptime => .comptime_arg_partially_comptime,
798 } else if (has_runtime_bits) switch (tag) {826 .fully_comptime => .comptime_arg_fully_comptime,
799 .comptime_arg => if (opt_name) |_| .comptime_arg_runtime_bits else .unnamed_comptime_arg_runtime_bits,827 } else switch (ty_class) {
800 .local_const => if (opt_name) |_| .local_const_runtime_bits else unreachable,828 .no_possible_value => unreachable,
801 } else switch (tag) {829 .one_possible_value => .unnamed_comptime_arg,
802 .comptime_arg => if (opt_name) |_| .comptime_arg else .unnamed_comptime_arg,830 .runtime => .unnamed_comptime_arg_fully_runtime,
803 .local_const => if (opt_name) |_| .local_const else unreachable,831 .partially_comptime => .unnamed_comptime_arg_partially_comptime,
804 });832 .fully_comptime => .unnamed_comptime_arg_fully_comptime,
805 if (opt_name) |name| try debug.strp(name);833 },
806 if (false) try debug.refType(ty);834 .local_const => if (opt_name) |_| switch (ty_class) {
807 if (has_runtime_bits) try debug.blockValue(val);835 .no_possible_value => unreachable,
808 if (false and has_comptime_state) try debug.refValue(val);836 .one_possible_value => .local_const,
837 .runtime => .local_const_fully_runtime,
838 .partially_comptime => .local_const_partially_comptime,
839 .fully_comptime => .local_const_fully_comptime,
840 } else unreachable,
841 }));
842 if (opt_name) |name| try dwarf.strp(&dwarf.debug_str, di_nw, name);
843 try dwarf.refConst(pt, di_nw, ty.toValue());
844 if (ty_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, val);
845 if (ty_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, val);
809 debug.any_children = true;846 debug.any_children = true;
810 }847 }
811848
...@@ -817,7 +854,7 @@ pub const WipNav = struct {...@@ -817,7 +854,7 @@ pub const WipNav = struct {
817 }854 }
818 fn genVarArgsDebugInfoInner(debug: *Debug) link.EmitError!void {855 fn genVarArgsDebugInfoInner(debug: *Debug) link.EmitError!void {
819 assert(debug.wip_nav.func != .none);856 assert(debug.wip_nav.func != .none);
820 try debug.abbrevCode(.is_var_args);857 try debug.info_writer.interface.writeUleb128(try debug.wip_nav.dwarf.refAbbrevCode(.is_var_args));
821 debug.any_children = true;858 debug.any_children = true;
822 }859 }
823860
...@@ -927,11 +964,11 @@ pub const WipNav = struct {...@@ -927,11 +964,11 @@ pub const WipNav = struct {
927 }964 }
928 fn enterBlockInner(debug: *Debug, code_off: usize) link.EmitError!void {965 fn enterBlockInner(debug: *Debug, code_off: usize) link.EmitError!void {
929 const dwarf = debug.wip_nav.dwarf;966 const dwarf = debug.wip_nav.dwarf;
930 const diw = &debug.info_writer.interface;
931 const block = try debug.blocks.addOne(dwarf.lf.comp.gpa);967 const block = try debug.blocks.addOne(dwarf.lf.comp.gpa);
932968
969 const diw = &debug.info_writer.interface;
933 block.abbrev_code = @intCast(diw.end);970 block.abbrev_code = @intCast(diw.end);
934 try debug.abbrevCode(.block);971 try diw.writeUleb128(try dwarf.refAbbrevCode(.block));
935 block.low_pc_off = code_off;972 block.low_pc_off = code_off;
936 try debug.infoAddrSym(debug.wip_nav.func_si, code_off);973 try debug.infoAddrSym(debug.wip_nav.func_si, code_off);
937 block.high_pc = @intCast(diw.end);974 block.high_pc = @intCast(diw.end);
...@@ -947,14 +984,14 @@ pub const WipNav = struct {...@@ -947,14 +984,14 @@ pub const WipNav = struct {
947 }984 }
948 fn leaveBlockInner(debug: *Debug, code_off: usize) link.EmitError!void {985 fn leaveBlockInner(debug: *Debug, code_off: usize) link.EmitError!void {
949 const dwarf = debug.wip_nav.dwarf;986 const dwarf = debug.wip_nav.dwarf;
950 const block_bytes = comptime uleb128Size(@backingInt(AbbrevCode.block));987 const block_size = comptime uleb128Size(@backingInt(AbbrevCode.block));
951 const block = debug.blocks.pop().?;988 const block = debug.blocks.pop().?;
952 if (debug.any_children)989 if (debug.any_children)
953 try debug.info_writer.interface.writeUleb128(@backingInt(AbbrevCode.null))990 try debug.info_writer.interface.writeUleb128(@backingInt(AbbrevCode.null))
954 else991 else
955 std.leb.writeUnsignedFixed(992 std.leb.writeUnsignedFixed(
956 block_bytes,993 block_size,
957 debug.info_writer.interface.buffered()[block.abbrev_code..][0..block_bytes],994 debug.info_writer.interface.buffered()[block.abbrev_code..][0..block_size],
958 @intCast(try dwarf.refAbbrevCode(.empty_block)),995 @intCast(try dwarf.refAbbrevCode(.empty_block)),
959 );996 );
960 std.mem.writeInt(997 std.mem.writeInt(
...@@ -987,11 +1024,11 @@ pub const WipNav = struct {...@@ -987,11 +1024,11 @@ pub const WipNav = struct {
987 ) link.EmitError!void {1024 ) link.EmitError!void {
988 const dwarf = debug.wip_nav.dwarf;1025 const dwarf = debug.wip_nav.dwarf;
989 const zcu = debug.pt.zcu;1026 const zcu = debug.pt.zcu;
990 const diw = &debug.info_writer.interface;
991 const block = try debug.blocks.addOne(zcu.gpa);1027 const block = try debug.blocks.addOne(zcu.gpa);
9921028
1029 const diw = &debug.info_writer.interface;
993 block.abbrev_code = @intCast(diw.end);1030 block.abbrev_code = @intCast(diw.end);
994 try debug.abbrevCode(.inlined_func);1031 try diw.writeUleb128(try dwarf.refAbbrevCode(.inlined_func));
995 try debug.refFunc(func);1032 try debug.refFunc(func);
996 try diw.writeUleb128((if (zcu.comp.config.incremental)1033 try diw.writeUleb128((if (zcu.comp.config.incremental)
997 01034 0
...@@ -1019,15 +1056,15 @@ pub const WipNav = struct {...@@ -1019,15 +1056,15 @@ pub const WipNav = struct {
1019 code_off: usize,1056 code_off: usize,
1020 ) link.EmitError!void {1057 ) link.EmitError!void {
1021 const dwarf = debug.wip_nav.dwarf;1058 const dwarf = debug.wip_nav.dwarf;
1022 const inlined_func_bytes = comptime uleb128Size(@backingInt(AbbrevCode.inlined_func));1059 const inlined_func_size = comptime uleb128Size(@backingInt(AbbrevCode.inlined_func));
1023 const block = debug.blocks.pop().?;1060 const block = debug.blocks.pop().?;
1024 const diw = &debug.info_writer.interface;1061 const diw = &debug.info_writer.interface;
1025 if (debug.any_children)1062 if (debug.any_children)
1026 try diw.writeUleb128(@backingInt(AbbrevCode.null))1063 try diw.writeUleb128(@backingInt(AbbrevCode.null))
1027 else1064 else
1028 std.leb.writeUnsignedFixed(1065 std.leb.writeUnsignedFixed(
1029 inlined_func_bytes,1066 inlined_func_size,
1030 diw.buffered()[block.abbrev_code..][0..inlined_func_bytes],1067 diw.buffered()[block.abbrev_code..][0..inlined_func_size],
1031 @intCast(try dwarf.refAbbrevCode(.empty_inlined_func)),1068 @intCast(try dwarf.refAbbrevCode(.empty_inlined_func)),
1032 );1069 );
1033 std.mem.writeInt(1070 std.mem.writeInt(
...@@ -1091,24 +1128,6 @@ pub const WipNav = struct {...@@ -1091,24 +1128,6 @@ pub const WipNav = struct {
1091 debug.wip_nav.func = func;1128 debug.wip_nav.func = func;
1092 }1129 }
10931130
1094 fn abbrevCode(debug: *Debug, abbrev_code: AbbrevCode) link.EmitError!void {
1095 try debug.info_writer.interface.writeUleb128(
1096 try debug.wip_nav.dwarf.refAbbrevCode(abbrev_code),
1097 );
1098 }
1099
1100 fn strp(debug: *Debug, str: []const u8) link.EmitError!void {
1101 const dwarf = debug.wip_nav.dwarf;
1102 try dwarf.strp(&dwarf.debug_str, &debug.info_writer, str);
1103 }
1104
1105 fn strpFmt(debug: *Debug, comptime fmt: []const u8, args: anytype) link.EmitError!void {
1106 const gpa = debug.pt.zcu.gpa;
1107 const str = try gpa.print(fmt, args);
1108 defer gpa.free(str);
1109 try debug.strp(str);
1110 }
1111
1112 fn infoExprLoc(debug: *Debug, loc: Loc) link.EmitError!void {1131 fn infoExprLoc(debug: *Debug, loc: Loc) link.EmitError!void {
1113 var buf: [64]u8 = undefined;1132 var buf: [64]u8 = undefined;
1114 var counter: ExprLocCounter = .init(debug.wip_nav.dwarf, &buf);1133 var counter: ExprLocCounter = .init(debug.wip_nav.dwarf, &buf);
...@@ -1146,45 +1165,6 @@ pub const WipNav = struct {...@@ -1146,45 +1165,6 @@ pub const WipNav = struct {
1146 0,1165 0,
1147 );1166 );
1148 }1167 }
1149
1150 fn refType(debug: *Debug, ty: Type) link.EmitError!void {
1151 return debug.refValue(ty.toValue());
1152 }
1153
1154 fn refValue(debug: *Debug, val: Value) link.EmitError!void {
1155 const dwarf = debug.wip_nav.dwarf;
1156 const cpi = try dwarf.getConst(debug.pt, val);
1157 try dwarf.sectionOffset(
1158 &debug.info_writer,
1159 Const.get(cpi, dwarf).debug_info_ni.unwrap().?,
1160 0,
1161 );
1162 }
1163
1164 fn blockValue(debug: *Debug, val: Value) link.EmitError!void {
1165 const ty = val.typeOf(debug.pt.zcu);
1166 const diw = &debug.info_writer.interface;
1167 const size = ty.abiSize(debug.pt.zcu);
1168 try diw.writeUleb128(size);
1169 if (size == 0) return;
1170 const offset = diw.end;
1171 try codegen.generateSymbol(
1172 debug.wip_nav.dwarf.lf,
1173 debug.pt,
1174 val,
1175 diw,
1176 .{ .debug_output = .{ .dwarf2 = debug } },
1177 );
1178 if (offset + size != diw.end) {
1179 std.debug.print("{f} [{}]: {} != {}\n", .{
1180 ty.fmt(debug.pt),
1181 ty.toIntern(),
1182 size,
1183 diw.end - offset,
1184 });
1185 unreachable;
1186 }
1187 }
1188 };1168 };
11891169
1190 pub fn deinit(wip_nav: *WipNav) void {1170 pub fn deinit(wip_nav: *WipNav) void {
...@@ -1271,15 +1251,12 @@ pub const WipNav = struct {...@@ -1271,15 +1251,12 @@ pub const WipNav = struct {
12711251
1272 const ExprLocCounter = struct {1252 const ExprLocCounter = struct {
1273 dw: Writer.Discarding,1253 dw: Writer.Discarding,
1274 section_offset_bytes: u32,1254 section_offset_size: usize,
1275 address_size: AddressSize,1255 address_size: AddressSize,
1276 fn init(dwarf: *Dwarf, buf: []u8) ExprLocCounter {1256 fn init(dwarf: *Dwarf, buf: []u8) ExprLocCounter {
1277 return .{1257 return .{
1278 .dw = .init(buf),1258 .dw = .init(buf),
1279 .section_offset_bytes = switch (dwarf.format) {1259 .section_offset_size = dwarf.sectionOffsetSize(),
1280 .@"32" => 4,
1281 .@"64" => 8,
1282 },
1283 .address_size = dwarf.address_size,1260 .address_size = dwarf.address_size,
1284 };1261 };
1285 }1262 }
...@@ -1293,7 +1270,7 @@ pub const WipNav = struct {...@@ -1293,7 +1270,7 @@ pub const WipNav = struct {
1293 try counter.dw.writer.splatByteAll(undefined, @backingInt(counter.address_size));1270 try counter.dw.writer.splatByteAll(undefined, @backingInt(counter.address_size));
1294 }1271 }
1295 fn infoEntry(counter: *ExprLocCounter, _: MappedFile.Node.Index) Writer.Error!void {1272 fn infoEntry(counter: *ExprLocCounter, _: MappedFile.Node.Index) Writer.Error!void {
1296 try counter.dw.writer.splatByteAll(undefined, counter.section_offset_bytes);1273 try counter.dw.writer.splatByteAll(undefined, counter.section_offset_size);
1297 }1274 }
1298 };1275 };
12991276
...@@ -1363,6 +1340,7 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf {...@@ -1363,6 +1340,7 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf {
1363 .globals = .empty,1340 .globals = .empty,
1364 .funcs = .empty,1341 .funcs = .empty,
1365 .decls = .empty,1342 .decls = .empty,
1343 .pending_decl = null,
13661344
1367 .debug_abbrev = .{1345 .debug_abbrev = .{
1368 .ni = .none,1346 .ni = .none,
...@@ -1486,9 +1464,7 @@ pub fn getUnit(dwarf: *Dwarf, mod: *Module) Unit.Index {...@@ -1486,9 +1464,7 @@ pub fn getUnit(dwarf: *Dwarf, mod: *Module) Unit.Index {
1486}1464}
14871465
1488pub fn getConst(dwarf: *Dwarf, pt: Zcu.PerThread, val: Value) link.Error!link.ConstPool.Index {1466pub fn getConst(dwarf: *Dwarf, pt: Zcu.PerThread, val: Value) link.Error!link.ConstPool.Index {
1489 const zcu = pt.zcu;1467 assert(val.typeOf(pt.zcu).comptimeOnly(pt.zcu));
1490 const ty = val.typeOf(zcu);
1491 if (ty.toIntern() != .type_type) assert(ty.comptimeOnly(zcu));
1492 return dwarf.const_pool.get(pt, .{ .elf2 = dwarf.lf.cast(.elf2).? }, val.toIntern());1468 return dwarf.const_pool.get(pt, .{ .elf2 = dwarf.lf.cast(.elf2).? }, val.toIntern());
1493}1469}
14941470
...@@ -1505,7 +1481,11 @@ pub fn getGlobal(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Global.Ind...@@ -1505,7 +1481,11 @@ pub fn getGlobal(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Global.Ind
1505 assert(!mod.strip);1481 assert(!mod.strip);
1506 const elf = dwarf.lf.cast(.elf2).?;1482 const elf = dwarf.lf.cast(.elf2).?;
1507 try elf.nodes.ensureUnusedCapacity(gpa, 1);1483 try elf.nodes.ensureUnusedCapacity(gpa, 1);
1508 try elf.dwarf_globals.ensureUnusedCapacity(gpa, 1);1484 try elf.dwarf_globals.append(gpa, .{
1485 .debug_info_first_target_reloc = .none,
1486 .debug_info_first_node_reloc = .none,
1487 .debug_info_first_symbol_reloc = .none,
1488 });
1509 const unit = dwarf.getUnit(mod).get(dwarf);1489 const unit = dwarf.getUnit(mod).get(dwarf);
1510 global_gop.value_ptr.debug_info_ni = .wrap(elf.addNodeAssumeCapacity(1490 global_gop.value_ptr.debug_info_ni = .wrap(elf.addNodeAssumeCapacity(
1511 unit.debug_info_ni.unwrap().?.addFloatingChild(gpa, &elf.mf, .{1491 unit.debug_info_ni.unwrap().?.addFloatingChild(gpa, &elf.mf, .{
...@@ -1518,11 +1498,6 @@ pub fn getGlobal(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Global.Ind...@@ -1518,11 +1498,6 @@ pub fn getGlobal(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Global.Ind
1518 },1498 },
1519 .{ .global_debug_info = gi },1499 .{ .global_debug_info = gi },
1520 ));1500 ));
1521 elf.dwarf_globals.addOneAssumeCapacity().* = .{
1522 .debug_info_first_target_reloc = .none,
1523 .debug_info_first_node_reloc = .none,
1524 .debug_info_first_symbol_reloc = .none,
1525 };
1526 return gi;1501 return gi;
1527}1502}
1528pub fn getGlobalIfExists(dwarf: *Dwarf, nav: InternPool.Nav.Index) ?Global.Index {1503pub fn getGlobalIfExists(dwarf: *Dwarf, nav: InternPool.Nav.Index) ?Global.Index {
...@@ -1542,9 +1517,8 @@ pub fn getFunc(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Func.Index {...@@ -1542,9 +1517,8 @@ pub fn getFunc(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Func.Index {
1542 if (func_gop.value_ptr.debug_info_ni != .none) return fi;1517 if (func_gop.value_ptr.debug_info_ni != .none) return fi;
1543 const mod = comp.zcu.?.navFileScope(nav).mod.?;1518 const mod = comp.zcu.?.navFileScope(nav).mod.?;
1544 const elf = dwarf.lf.cast(.elf2).?;1519 const elf = dwarf.lf.cast(.elf2).?;
1545 try elf.dwarf_funcs.ensureUnusedCapacity(gpa, 1);
1546 try elf.nodes.ensureUnusedCapacity(gpa, 1);1520 try elf.nodes.ensureUnusedCapacity(gpa, 1);
1547 elf.dwarf_funcs.addOneAssumeCapacity().* = .{1521 try elf.dwarf_funcs.append(gpa, .{
1548 .frame_fde_first_symbol_reloc = .none,1522 .frame_fde_first_symbol_reloc = .none,
1549 .frame_fde_first_node_reloc = .none,1523 .frame_fde_first_node_reloc = .none,
1550 .debug_info_first_target_reloc = .none,1524 .debug_info_first_target_reloc = .none,
...@@ -1552,7 +1526,7 @@ pub fn getFunc(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Func.Index {...@@ -1552,7 +1526,7 @@ pub fn getFunc(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Func.Index {
1552 .debug_info_first_node_reloc = .none,1526 .debug_info_first_node_reloc = .none,
1553 .debug_line_first_symbol_reloc = .none,1527 .debug_line_first_symbol_reloc = .none,
1554 .debug_line_first_node_reloc = .none,1528 .debug_line_first_node_reloc = .none,
1555 };1529 });
1556 if (mod.strip) return fi;1530 if (mod.strip) return fi;
1557 const unit = dwarf.getUnit(mod).get(dwarf);1531 const unit = dwarf.getUnit(mod).get(dwarf);
1558 func_gop.value_ptr.debug_info_ni = .wrap(elf.addNodeAssumeCapacity(1532 func_gop.value_ptr.debug_info_ni = .wrap(elf.addNodeAssumeCapacity(
...@@ -1572,6 +1546,86 @@ pub fn getFuncIfExists(dwarf: *Dwarf, nav: InternPool.Nav.Index) ?Func.Index {...@@ -1572,6 +1546,86 @@ pub fn getFuncIfExists(dwarf: *Dwarf, nav: InternPool.Nav.Index) ?Func.Index {
1572 return @fromBackingInt(@intCast(dwarf.funcs.getIndex(nav) orelse return null));1546 return @fromBackingInt(@intCast(dwarf.funcs.getIndex(nav) orelse return null));
1573}1547}
15741548
1549pub fn getDeclInst(dwarf: *Dwarf, val: InternPool.Index) ?InternPool.TrackedInst.Index {
1550 const ip = &dwarf.lf.comp.zcu.?.intern_pool;
1551 switch (ip.indexToKey(val)) {
1552 else => unreachable,
1553 .struct_type => {
1554 const loaded_struct = ip.loadStructType(val);
1555 if (loaded_struct.captures.len == 0) return null;
1556 return ip.getNav(loaded_struct.name_nav.unwrap() orelse
1557 return loaded_struct.zir_index).srcInst(ip);
1558 },
1559 .enum_type => {
1560 const loaded_enum = ip.loadEnumType(val);
1561 if (loaded_enum.captures.len == 0) return null;
1562 return ip.getNav(loaded_enum.name_nav.unwrap() orelse
1563 return loaded_enum.zir_index.unwrap().?).srcInst(ip);
1564 },
1565 .union_type => {
1566 const loaded_union = ip.loadUnionType(val);
1567 if (loaded_union.captures.len == 0) return null;
1568 return ip.getNav(loaded_union.name_nav.unwrap() orelse
1569 return loaded_union.zir_index).srcInst(ip);
1570 },
1571 .opaque_type => {
1572 const loaded_opaque = ip.loadOpaqueType(val);
1573 if (loaded_opaque.captures.len == 0) return null;
1574 return ip.getNav(loaded_opaque.name_nav.unwrap() orelse
1575 return loaded_opaque.zir_index).srcInst(ip);
1576 },
1577 .func => |func| return ip.getNav(switch (func.generic_owner) {
1578 .none => func.owner_nav,
1579 else => |generic_owner| ip.indexToKey(generic_owner).func.owner_nav,
1580 }).srcInst(ip),
1581 }
1582}
1583pub fn getDecl(
1584 dwarf: *Dwarf,
1585 pt: Zcu.PerThread,
1586 instance_val: InternPool.Index,
1587) link.Error!MappedFile.Node.Index {
1588 assert(dwarf.pending_decl == null);
1589 const comp = dwarf.lf.comp;
1590 const gpa = comp.gpa;
1591 const zcu = pt.zcu;
1592 const ip = &zcu.intern_pool;
1593 const inst = dwarf.getDeclInst(instance_val) orelse {
1594 const cpi = try dwarf.getConst(pt, .fromInterned(instance_val));
1595 return Const.get(cpi, dwarf).debug_info_ni.unwrap().?;
1596 };
1597 const decl_gop = try dwarf.decls.getOrPut(gpa, inst);
1598 if (!decl_gop.found_existing) decl_gop.value_ptr.* = .{
1599 .debug_info_ni = .none,
1600 };
1601 const di: Decl.Index = @fromBackingInt(@intCast(decl_gop.index));
1602 if (decl_gop.value_ptr.debug_info_ni.unwrap()) |debug_info_ni| return debug_info_ni;
1603 dwarf.pending_decl = .{ .di = di, .instance_val = instance_val };
1604 const elf = dwarf.lf.cast(.elf2).?;
1605 try elf.nodes.ensureUnusedCapacity(gpa, 1);
1606 try elf.dwarf_decls.putNoClobber(gpa, di, .{
1607 .debug_info_first_target_reloc = .none,
1608 .debug_info_first_node_reloc = .none,
1609 });
1610 const unit = dwarf.getUnit(zcu.fileByIndex(di.srcInst(dwarf).resolveFile(ip)).mod.?).get(dwarf);
1611 const debug_info_ni = elf.addNodeAssumeCapacity(
1612 unit.debug_info_ni.unwrap().?.addFloatingChild(gpa, &elf.mf, .{
1613 .enable_next_moved = true,
1614 }) catch |err| switch (err) {
1615 else => |e| return e,
1616 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{
1617 elf.mf.io_err.?,
1618 }),
1619 },
1620 .{ .decl_debug_info = di },
1621 );
1622 decl_gop.value_ptr.debug_info_ni = .wrap(debug_info_ni);
1623 return debug_info_ni;
1624}
1625pub fn getDeclIfExists(dwarf: *Dwarf, inst: InternPool.TrackedInst.Index) ?Decl.Index {
1626 return @fromBackingInt(@intCast(dwarf.decls.getIndex(inst) orelse return null));
1627}
1628
1575pub fn unitLengthSize(dwarf: *Dwarf) usize {1629pub fn unitLengthSize(dwarf: *Dwarf) usize {
1576 return switch (dwarf.format) {1630 return switch (dwarf.format) {
1577 .@"32" => 4,1631 .@"32" => 4,
...@@ -1976,33 +2030,33 @@ pub fn updateComptimeNav(...@@ -1976,33 +2030,33 @@ pub fn updateComptimeNav(
1976 .unnamed_test, .@"test", .decltest => return,2030 .unnamed_test, .@"test", .decltest => return,
1977 .@"comptime", .@"const", .@"var" => {},2031 .@"comptime", .@"const", .@"var" => {},
1978 }2032 }
1979 emit: switch (ip.indexToKey(nav_val.toIntern())) {2033 done: switch (ip.indexToKey(nav_val.toIntern())) {
1980 .struct_type => {2034 .struct_type => {
1981 const loaded_struct = ip.loadStructType(nav_val.toIntern());2035 const loaded_struct = ip.loadStructType(nav_val.toIntern());
1982 if (nav_index.toOptional() == loaded_struct.name_nav) {2036 if (nav_index.toOptional() == loaded_struct.name_nav) {
1983 _ = try dwarf.const_pool.get(pt, .{ .elf2 = dwarf.lf.cast(.elf2).? }, nav_val.toIntern());2037 _ = try dwarf.const_pool.get(pt, .{ .elf2 = dwarf.lf.cast(.elf2).? }, nav_val.toIntern());
1984 break :emit;2038 break :done;
1985 }2039 }
1986 },2040 },
1987 .enum_type => {2041 .enum_type => {
1988 const loaded_enum = ip.loadEnumType(nav_val.toIntern());2042 const loaded_enum = ip.loadEnumType(nav_val.toIntern());
1989 if (nav_index.toOptional() == loaded_enum.name_nav) {2043 if (nav_index.toOptional() == loaded_enum.name_nav) {
1990 _ = try dwarf.const_pool.get(pt, .{ .elf2 = dwarf.lf.cast(.elf2).? }, nav_val.toIntern());2044 _ = try dwarf.const_pool.get(pt, .{ .elf2 = dwarf.lf.cast(.elf2).? }, nav_val.toIntern());
1991 break :emit;2045 break :done;
1992 }2046 }
1993 },2047 },
1994 .union_type => {2048 .union_type => {
1995 const loaded_union = ip.loadUnionType(nav_val.toIntern());2049 const loaded_union = ip.loadUnionType(nav_val.toIntern());
1996 if (nav_index.toOptional() == loaded_union.name_nav) {2050 if (nav_index.toOptional() == loaded_union.name_nav) {
1997 _ = try dwarf.const_pool.get(pt, .{ .elf2 = dwarf.lf.cast(.elf2).? }, nav_val.toIntern());2051 _ = try dwarf.const_pool.get(pt, .{ .elf2 = dwarf.lf.cast(.elf2).? }, nav_val.toIntern());
1998 break :emit;2052 break :done;
1999 }2053 }
2000 },2054 },
2001 .opaque_type => {2055 .opaque_type => {
2002 const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern());2056 const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern());
2003 if (nav_index.toOptional() == loaded_opaque.name_nav) {2057 if (nav_index.toOptional() == loaded_opaque.name_nav) {
2004 _ = try dwarf.const_pool.get(pt, .{ .elf2 = dwarf.lf.cast(.elf2).? }, nav_val.toIntern());2058 _ = try dwarf.const_pool.get(pt, .{ .elf2 = dwarf.lf.cast(.elf2).? }, nav_val.toIntern());
2005 break :emit;2059 break :done;
2006 }2060 }
2007 },2061 },
2008 .func => |func| if (func.owner_nav == nav_index and func.generic_owner == .none) {2062 .func => |func| if (func.owner_nav == nav_index and func.generic_owner == .none) {
...@@ -2012,12 +2066,11 @@ pub fn updateComptimeNav(...@@ -2012,12 +2066,11 @@ pub fn updateComptimeNav(
2012 var di_nw: MappedFile.Node.Writer = undefined;2066 var di_nw: MappedFile.Node.Writer = undefined;
2013 f.debug_info_ni.unwrap().?.writer(zcu.gpa, &dwarf.lf.cast(.elf2).?.mf, &di_nw);2067 f.debug_info_ni.unwrap().?.writer(zcu.gpa, &dwarf.lf.cast(.elf2).?.mf, &di_nw);
2014 defer di_nw.deinit();2068 defer di_nw.deinit();
2015 const parent_cpi = try dwarf.getConst(pt, .fromInterned(zcu.fileRootType(inst_info.file)));
2016 dwarf.genDeclFuncGeneric(2069 dwarf.genDeclFuncGeneric(
2017 pt,2070 pt,
2018 &di_nw,2071 &di_nw,
2019 zir,2072 zir,
2020 parent_cpi,2073 .fromInterned(ip.namespacePtr(nav.analysis.?.namespace).owner_type),
2021 &decl,2074 &decl,
2022 &ip.indexToKey(func.ty).func_type,2075 &ip.indexToKey(func.ty).func_type,
2023 nav.name.toSlice(ip),2076 nav.name.toSlice(ip),
...@@ -2040,7 +2093,7 @@ fn genDeclFuncGeneric(...@@ -2040,7 +2093,7 @@ fn genDeclFuncGeneric(
2040 pt: Zcu.PerThread,2093 pt: Zcu.PerThread,
2041 di_nw: *MappedFile.Node.Writer,2094 di_nw: *MappedFile.Node.Writer,
2042 zir: *const std.zig.Zir,2095 zir: *const std.zig.Zir,
2043 parent_cpi: link.ConstPool.Index,2096 parent_ty: Type,
2044 decl: *const std.zig.Zir.Inst.Declaration.Unwrapped,2097 decl: *const std.zig.Zir.Inst.Declaration.Unwrapped,
2045 fn_ty: *const InternPool.Key.FuncType,2098 fn_ty: *const InternPool.Key.FuncType,
2046 name: []const u8,2099 name: []const u8,
...@@ -2048,7 +2101,7 @@ fn genDeclFuncGeneric(...@@ -2048,7 +2101,7 @@ fn genDeclFuncGeneric(
2048) link.EmitError!void {2101) link.EmitError!void {
2049 const diw = &di_nw.interface;2102 const diw = &di_nw.interface;
2050 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_func_generic));2103 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_func_generic));
2051 try dwarf.sectionOffset(di_nw, Const.get(parent_cpi, dwarf).debug_info_ni.unwrap().?, 0);2104 try dwarf.refConst(pt, di_nw, parent_ty.toValue());
2052 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);2105 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);
2053 try diw.writeUleb128(decl.src_column + 1);2106 try diw.writeUleb128(decl.src_column + 1);
2054 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);2107 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
...@@ -2062,10 +2115,7 @@ fn genDeclFuncGeneric(...@@ -2062,10 +2115,7 @@ fn genDeclFuncGeneric(
2062 try dwarf.strp(&dwarf.debug_str, di_nw, zir.nullTerminatedString(param_name));2115 try dwarf.strp(&dwarf.debug_str, di_nw, zir.nullTerminatedString(param_name));
2063 },2116 },
2064 }2117 }
2065 try dwarf.sectionOffset(di_nw, Const.get(try dwarf.getConst(2118 try dwarf.refConst(pt, di_nw, .fromInterned(fn_ty.param_types.get(&pt.zcu.intern_pool)[param_index]));
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;2119 param_index += 1;
2070 }2120 }
2071 if (fn_ty.is_var_args) try diw.writeUleb128(try dwarf.refAbbrevCode(.is_var_args));2121 if (fn_ty.is_var_args) try diw.writeUleb128(try dwarf.refAbbrevCode(.is_var_args));
...@@ -2079,16 +2129,14 @@ pub fn addConst(...@@ -2079,16 +2129,14 @@ pub fn addConst(
2079 val: InternPool.Index,2129 val: InternPool.Index,
2080 addConstNode: *const fn (2130 addConstNode: *const fn (
2081 lf: *link.File,2131 lf: *link.File,
2082 ui: Dwarf.Unit.Index,2132 ui: Unit.Index,
2083 cpi: link.ConstPool.Index,2133 cpi: link.ConstPool.Index,
2084 ) link.Error!MappedFile.Node.Index,2134 ) link.Error!MappedFile.Node.Index,
2085) link.Error!void {2135) link.Error!void {
2086 const comp = dwarf.lf.comp;2136 const zcu = dwarf.lf.comp.zcu.?;
2087 const zcu = comp.zcu.?;
2088 const ip = &zcu.intern_pool;2137 const ip = &zcu.intern_pool;
2089
2090 assert(@backingInt(cpi) == dwarf.consts.items.len);2138 assert(@backingInt(cpi) == dwarf.consts.items.len);
2091 try dwarf.consts.append(comp.gpa, .{2139 dwarf.consts.appendAssumeCapacity(.{
2092 .debug_info_ni = debug_info_ni: switch (ip.indexToKey(val)) {2140 .debug_info_ni = debug_info_ni: switch (ip.indexToKey(val)) {
2093 else => try addConstNode(dwarf.lf, dwarf.getUnit(zcu.root_mod), cpi),2141 else => try addConstNode(dwarf.lf, dwarf.getUnit(zcu.root_mod), cpi),
2094 .func => |func| {2142 .func => |func| {
...@@ -2144,112 +2192,73 @@ fn updateConstInner(...@@ -2144,112 +2192,73 @@ fn updateConstInner(
2144 const diw = &di_nw.interface;2192 const diw = &di_nw.interface;
2145 switch (ip.indexToKey(val)) {2193 switch (ip.indexToKey(val)) {
2146 else => return,2194 else => return,
2147 .struct_type => {2195 .int_type => |int_type| {
2148 const loaded_struct = ip.loadStructType(val);
2149 const ty: Type = .fromInterned(val);2196 const ty: Type = .fromInterned(val);
2150 const file = loaded_struct.zir_index.resolveFile(ip);2197 try diw.writeUleb128(try dwarf.refAbbrevCode(.numeric_type));
2151 switch (loaded_struct.layout) {2198 var name_buf: [std.fmt.count("i{d}", .{std.math.maxInt(u16)})]u8 = undefined;
2152 .auto, .@"extern" => {2199 try dwarf.strp(&dwarf.debug_str, di_nw, std.mem.print(&name_buf, "{f}", .{ty.fmt(pt)}) catch unreachable);
2153 const struct_is_file: bool = if (loaded_struct.zir_index.resolve(ip)) |inst|2200 try diw.writeByte(switch (int_type.signedness) {
2154 inst == .main_struct_inst2201 .signed => DW.ATE.signed,
2155 else2202 .unsigned => DW.ATE.unsigned,
2156 false;2203 });
2157 if (loaded_struct.name_nav.unwrap()) |nav_index| {2204 try diw.writeUleb128(int_type.bits);
2158 assert(!struct_is_file);2205 try diw.writeUleb128(ty.abiSize(zcu));
2159 const nav = ip.getNav(nav_index);2206 try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);
2160 const decl_inst = nav.srcInst(ip).resolve(ip).?;2207 },
2161 const decl = zcu.fileByIndex(file).zir.?.getDeclaration(decl_inst);2208 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
2162 try diw.writeUleb128(try dwarf.refAbbrevCode(2209 .one, .many, .c => {
2163 if (loaded_struct.field_types.len == 0) .decl_namespace_struct else .decl_struct,2210 const ty: Type = .fromInterned(val);
2164 ));2211 const ptr_child_ty: Type = .fromInterned(ptr_type.child);
2165 try dwarf.sectionOffset(di_nw, Const.get(2212 try diw.writeUleb128(try dwarf.refAbbrevCode(switch (ptr_type.flags.alignment) {
2166 try dwarf.getConst(pt, .fromInterned(zcu.fileRootType(file))),2213 .none => if (ptr_type.sentinel == .none) .ptr_type else .ptr_sentinel_type,
2167 dwarf,2214 else => if (ptr_type.sentinel == .none) .ptr_aligned_type else .ptr_aligned_sentinel_type,
2168 ).debug_info_ni.unwrap().?, 0);2215 }));
2169 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);2216 {
2170 try diw.writeUleb128(decl.src_column + 1);2217 const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)});
2171 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);2218 defer zcu.gpa.free(name);
2172 try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip));2219 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2173 } else {2220 }
2174 const zfi = loaded_struct.zir_index.resolveFile(ip);2221 if (ptr_type.sentinel != .none) try dwarf.blockConst(pt, di_nw, .fromInterned(ptr_type.sentinel));
2175 const ui = dwarf.getUnit(zcu.fileByIndex(zfi).mod.?);2222 if (ptr_type.flags.alignment.toByteUnits()) |a| try diw.writeUleb128(a);
2176 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, zfi);2223 try diw.writeByte(@backingInt(ptr_type.flags.address_space));
2177 try diw.writeUleb128(try dwarf.refAbbrevCode(switch (loaded_struct.field_types.len) {2224 if (ptr_type.flags.is_const or ptr_type.flags.is_volatile) try dwarf.sectionOffset(
2178 0 => if (struct_is_file) .empty_file else .empty_struct_type,2225 di_nw,
2179 else => if (struct_is_file) .file else .struct_type,2226 di_nw.ni,
2180 }));2227 diw.end + dwarf.sectionOffsetSize(),
2181 try diw.writeUleb128(@backingInt(fi));2228 );
2182 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.name.toSlice(ip));2229 if (ptr_type.flags.is_const) {
2183 }2230 try diw.writeUleb128(try dwarf.refAbbrevCode(.is_const));
2184 if (loaded_struct.field_types.len == 0) {2231 if (ptr_type.flags.is_volatile) try dwarf.sectionOffset(
2185 if (!struct_is_file) try diw.writeByte(@intFromBool(false));2232 di_nw,
2186 } else {2233 di_nw.ni,
2187 try diw.writeUleb128(ty.abiSize(zcu));2234 diw.end + dwarf.sectionOffsetSize(),
2188 try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);2235 );
2189 for (0..loaded_struct.field_types.len) |field_index| {2236 }
2190 const is_comptime = loaded_struct.field_is_comptime_bits.get(ip, field_index);2237 if (ptr_type.flags.is_volatile) try diw.writeUleb128(try dwarf.refAbbrevCode(.is_volatile));
2191 // TODO: we currently don't emit information about default values for2238 try dwarf.refConst(pt, di_nw, ptr_child_ty.toValue());
2192 // non-`comptime` fields, because these default values are resolved at a2239 },
2193 // separate time in the compiler frontend. To emit this information, the2240 .slice => {
2194 // frontend needs to tell us when the default values are available: like2241 const ty: Type = .fromInterned(val);
2195 // how `Zcu.PerThread.ensureTypeLayoutUpToDate` enqueues a link task to2242 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_struct_type));
2196 // indicate completion of the type's layout, a task should be enqueued2243 {
2197 // by `Zcu.PerThread.ensureStructDefaultsUpToDate`, and upon receiving2244 const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)});
2198 // it we should patch the correct default field values in.2245 defer zcu.gpa.free(name);
2199 const field_init: InternPool.Index = if (is_comptime) loaded_struct.field_defaults.getOrNone(ip, field_index) else .none;2246 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2200 assert(!(is_comptime and field_init == .none));2247 }
2201 const field_type: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);2248 try diw.writeUleb128(ty.abiSize(zcu));
2202 const has_runtime_bits, const has_comptime_state = switch (field_init) {2249 try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);
2203 .none => .{ false, false },2250 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_field));
2204 else => .{2251 try dwarf.strp(&dwarf.debug_str, di_nw, "ptr");
2205 field_type.hasRuntimeBits(zcu),2252 const ptr_field_ty = ty.slicePtrFieldType(zcu);
2206 field_type.comptimeOnly(zcu),2253 try dwarf.refConst(pt, di_nw, ptr_field_ty.toValue());
2207 },2254 try diw.writeUleb128(0);
2208 };2255 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_field));
2209 try diw.writeUleb128(try dwarf.refAbbrevCode(if (is_comptime)2256 try dwarf.strp(&dwarf.debug_str, di_nw, "len");
2210 if (has_comptime_state)2257 const len_field_ty: Type = .usize;
2211 .field_comptime_comptime_state2258 try dwarf.refConst(pt, di_nw, len_field_ty.toValue());
2212 else if (has_runtime_bits)2259 try diw.writeUleb128(len_field_ty.abiAlignment(zcu).forward(ptr_field_ty.abiSize(zcu)));
2213 .field_comptime_runtime_bits2260 try diw.writeUleb128(@backingInt(AbbrevCode.null));
2214 else2261 },
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 },2262 },
2254 .simple_type => |simple_type| switch (simple_type) {2263 .simple_type => |simple_type| switch (simple_type) {
2255 .f16,2264 .f16,
...@@ -2298,21 +2307,138 @@ fn updateConstInner(...@@ -2298,21 +2307,138 @@ fn updateConstInner(
2298 .comptime_int,2307 .comptime_int,
2299 .comptime_float,2308 .comptime_float,
2300 .noreturn,2309 .noreturn,
2310 .null,
2311 .undefined,
2312 .enum_literal,
2301 => {2313 => {
2314 const ty: Type = .fromInterned(val);
2302 try diw.writeUleb128(try dwarf.refAbbrevCode(.void_type));2315 try diw.writeUleb128(try dwarf.refAbbrevCode(.void_type));
2303 try dwarf.strp(&dwarf.debug_str, di_nw, @tagName(simple_type));2316 var name_buf: ["@TypeOf(undefined)".len]u8 = undefined;
2304 },2317 try dwarf.strp(&dwarf.debug_str, di_nw, std.mem.print(&name_buf, "{f}", .{ty.fmt(pt)}) catch unreachable);
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 },2318 },
2313 .anyerror => return,2319 .anyerror => return,
2314 .adhoc_inferred_error_set => unreachable,2320 .adhoc_inferred_error_set => unreachable,
2315 },2321 },
2322 .struct_type => {
2323 const loaded_struct = ip.loadStructType(val);
2324 const zfi = loaded_struct.zir_index.resolveFile(ip);
2325 const zf = zcu.fileByIndex(zfi);
2326 switch (loaded_struct.layout) {
2327 .auto, .@"extern" => {
2328 const struct_is_file = loaded_struct.zir_index.resolve(ip) == .main_struct_inst;
2329 if (loaded_struct.name_nav.unwrap()) |name_ni| {
2330 assert(!struct_is_file);
2331 const name_nav = ip.getNav(name_ni);
2332 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
2333 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2334 name_nav.analysis.?.namespace,
2335 ).owner_type);
2336 try diw.writeUleb128(try dwarf.refAbbrevCode(
2337 if (loaded_struct.field_types.len > 0) .decl_struct else .decl_namespace_struct,
2338 ));
2339 try dwarf.sectionOffset(di_nw, parent_ni, 0);
2340 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);
2341 try diw.writeUleb128(decl.src_column + 1);
2342 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2343 try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip));
2344 } else {
2345 const ui = dwarf.getUnit(zf.mod.?);
2346 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, zfi);
2347 try diw.writeUleb128(try dwarf.refAbbrevCode(switch (loaded_struct.field_types.len) {
2348 0 => if (struct_is_file) .empty_file else .empty_struct_type,
2349 else => if (struct_is_file) .file else .struct_type,
2350 }));
2351 try diw.writeUleb128(@backingInt(fi));
2352 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.name.toSlice(ip));
2353 }
2354 if (loaded_struct.field_types.len > 0) {
2355 const ty: Type = .fromInterned(val);
2356 try diw.writeUleb128(ty.abiSize(zcu));
2357 try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);
2358 for (0..loaded_struct.field_types.len) |field_index| {
2359 const is_comptime = loaded_struct.field_is_comptime_bits.get(ip, field_index);
2360 // TODO: we currently don't emit information about default values for
2361 // non-`comptime` fields, because these default values are resolved at a
2362 // separate time in the compiler frontend. To emit this information, the
2363 // frontend needs to tell us when the default values are available: like
2364 // how `Zcu.PerThread.ensureTypeLayoutUpToDate` enqueues a link task to
2365 // indicate completion of the type's layout, a task should be enqueued
2366 // by `Zcu.PerThread.ensureStructDefaultsUpToDate`, and upon receiving
2367 // it we should patch the correct default field values in.
2368 const field_default: InternPool.Index =
2369 if (is_comptime) loaded_struct.field_defaults.getOrNone(ip, field_index) else .none;
2370 assert(!(is_comptime and field_default == .none));
2371 const field_ty: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
2372 const field_default_class = switch (field_default) {
2373 .none => .no_possible_value,
2374 else => field_ty.classify(zcu),
2375 };
2376 try diw.writeUleb128(try dwarf.refAbbrevCode(switch (field_default_class) {
2377 .no_possible_value, .one_possible_value => if (is_comptime) .field_comptime else .field,
2378 .runtime => if (is_comptime) .field_comptime_fully_runtime else .field_default_fully_runtime,
2379 .partially_comptime => if (is_comptime) .field_comptime_partially_comptime else .field_default_partially_comptime,
2380 .fully_comptime => if (is_comptime) .field_comptime_fully_comptime else .field_default_fully_comptime,
2381 }));
2382 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.field_names.get(ip)[field_index].toSlice(ip));
2383 try dwarf.refConst(pt, di_nw, field_ty.toValue());
2384 if (!is_comptime) {
2385 try diw.writeUleb128(loaded_struct.field_offsets.get(ip)[field_index]);
2386 try diw.writeUleb128(loaded_struct.field_aligns.getOrNone(ip, field_index).toByteUnits() orelse
2387 field_ty.abiAlignment(zcu).toByteUnits().?);
2388 }
2389 if (field_default_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, .fromInterned(field_default));
2390 if (field_default_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, .fromInterned(field_default));
2391 }
2392 try diw.writeUleb128(@backingInt(AbbrevCode.null));
2393 } else try diw.writeByte(@intFromBool(false));
2394 },
2395 .@"packed" => return,
2396 }
2397 },
2398 .enum_type => {
2399 const loaded_enum = ip.loadEnumType(val);
2400 if (loaded_enum.zir_index.unwrap()) |zir_index| {
2401 assert(loaded_enum.owner_union == .none);
2402 const zfi = zir_index.resolveFile(ip);
2403 const zf = zcu.fileByIndex(zfi);
2404 if (loaded_enum.name_nav.unwrap()) |name_ni| {
2405 const name_nav = ip.getNav(name_ni);
2406 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
2407 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2408 name_nav.analysis.?.namespace,
2409 ).owner_type);
2410 try diw.writeUleb128(try dwarf.refAbbrevCode(
2411 if (loaded_enum.field_names.len > 0) .decl_enum else .decl_empty_enum,
2412 ));
2413 try dwarf.sectionOffset(di_nw, parent_ni, 0);
2414 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);
2415 try diw.writeUleb128(decl.src_column + 1);
2416 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2417 try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip));
2418 } else {
2419 const ui = dwarf.getUnit(zf.mod.?);
2420 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, zfi);
2421 try diw.writeUleb128(try dwarf.refAbbrevCode(
2422 if (loaded_enum.field_names.len > 0) .enum_type else .empty_enum_type,
2423 ));
2424 try diw.writeUleb128(@backingInt(fi));
2425 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.name.toSlice(ip));
2426 }
2427 } else {
2428 assert(loaded_enum.owner_union != .none);
2429 try diw.writeUleb128(try dwarf.refAbbrevCode(
2430 if (loaded_enum.field_names.len == 0) .generated_empty_enum_type else .generated_enum_type,
2431 ));
2432 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.name.toSlice(ip));
2433 }
2434 try dwarf.refConst(pt, di_nw, .fromInterned(loaded_enum.int_tag_type));
2435 for (0..loaded_enum.field_names.len) |field_index| {
2436 try diw.writeUleb128(try dwarf.refAbbrevCode(.enum_field));
2437 try dwarf.enumConstValue(diw, loaded_enum, field_index);
2438 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.field_names.get(ip)[field_index].toSlice(ip));
2439 }
2440 if (loaded_enum.field_names.len > 0) try diw.writeUleb128(@backingInt(AbbrevCode.null));
2441 },
2316 }2442 }
2317 try dwarf.genDebugInfoPadding(diw, diw.unusedCapacityLen());2443 try dwarf.genDebugInfoPadding(diw, diw.unusedCapacityLen());
2318}2444}
...@@ -2339,45 +2465,90 @@ fn updateConstIncompleteInner(...@@ -2339,45 +2465,90 @@ fn updateConstIncompleteInner(
2339 const ip = &zcu.intern_pool;2465 const ip = &zcu.intern_pool;
2340 const diw = &di_nw.interface;2466 const diw = &di_nw.interface;
2341 done: {2467 done: {
2342 const zir_index, const name, const maybe_name_nav = container: switch (ip.indexToKey(val)) {2468 const src_inst, const zf, const capture_names, const captures, const name, const maybe_name_nav, const namespace = container: switch (ip.indexToKey(val)) {
2343 .struct_type => {2469 .struct_type => {
2344 const loaded_struct = ip.loadStructType(val);2470 const loaded_struct = ip.loadStructType(val);
2345 if (loaded_struct.zir_index.resolveFull(ip)) |src_inst| switch (src_inst.inst) {2471 const src_inst = loaded_struct.zir_index.resolveFull(ip) orelse {
2472 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_lost));
2473 break :done;
2474 };
2475 const zf = zcu.fileByIndex(src_inst.file);
2476 switch (src_inst.inst) {
2346 .main_struct_inst => {2477 .main_struct_inst => {
2347 const ui = dwarf.getUnit(zcu.fileByIndex(src_inst.file).mod.?);2478 const ui = dwarf.getUnit(zf.mod.?);
2348 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, src_inst.file);2479 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, src_inst.file);
2349 try diw.writeUleb128(try dwarf.refAbbrevCode(.empty_file));2480 try diw.writeUleb128(try dwarf.refAbbrevCode(.empty_file));
2350 try diw.writeUleb128(@backingInt(fi));2481 try diw.writeUleb128(@backingInt(fi));
2351 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.name.toSlice(ip));2482 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.name.toSlice(ip));
2483 try diw.writeByte(@intFromBool(true));
2352 break :done;2484 break :done;
2353 },2485 },
2354 else => {},2486 else => break :container .{
2355 };2487 src_inst,
2356 break :container .{2488 zf,
2357 loaded_struct.zir_index,2489 zf.zir.?.getStructDecl(src_inst.inst).capture_names,
2358 loaded_struct.name,2490 loaded_struct.captures,
2359 loaded_struct.name_nav,2491 loaded_struct.name,
2360 };2492 loaded_struct.name_nav,
2493 loaded_struct.namespace,
2494 },
2495 }
2361 },2496 },
2362 .union_type => {2497 .union_type => {
2363 const loaded_union = ip.loadUnionType(val);2498 const loaded_union = ip.loadUnionType(val);
2364 break :container .{ loaded_union.zir_index, loaded_union.name, loaded_union.name_nav };2499 const src_inst = loaded_union.zir_index.resolveFull(ip) orelse {
2500 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_lost));
2501 break :done;
2502 };
2503 const zf = zcu.fileByIndex(src_inst.file);
2504 break :container .{
2505 src_inst,
2506 zf,
2507 zf.zir.?.getUnionDecl(src_inst.inst).capture_names,
2508 loaded_union.captures,
2509 loaded_union.name,
2510 loaded_union.name_nav,
2511 loaded_union.namespace,
2512 };
2365 },2513 },
2366 .enum_type => {2514 .enum_type => {
2367 const loaded_enum = ip.loadEnumType(val);2515 const loaded_enum = ip.loadEnumType(val);
2368 if (loaded_enum.zir_index.unwrap()) |zir_index|2516 const zir_index = loaded_enum.zir_index.unwrap() orelse {
2369 break :container .{ zir_index, loaded_enum.name, loaded_enum.name_nav };2517 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_empty_struct_type));
2370 try diw.writeUleb128(try dwarf.refAbbrevCode(.generated_empty_struct_type));2518 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.name.toSlice(ip));
2371 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.name.toSlice(ip));2519 try diw.writeByte(@intFromBool(true));
2372 try diw.writeByte(@intFromBool(true));2520 break :done;
2373 break :done;2521 };
2522 const src_inst = zir_index.resolveFull(ip) orelse {
2523 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_lost));
2524 break :done;
2525 };
2526 const zf = zcu.fileByIndex(src_inst.file);
2527 break :container .{
2528 src_inst,
2529 zf,
2530 zf.zir.?.getEnumDecl(src_inst.inst).capture_names,
2531 loaded_enum.captures,
2532 loaded_enum.name,
2533 loaded_enum.name_nav,
2534 loaded_enum.namespace,
2535 };
2374 },2536 },
2375 .opaque_type => {2537 .opaque_type => {
2376 const loaded_opaque = ip.loadOpaqueType(val);2538 const loaded_opaque = ip.loadOpaqueType(val);
2539 const src_inst = loaded_opaque.zir_index.resolveFull(ip) orelse {
2540 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_lost));
2541 break :done;
2542 };
2543 const zf = zcu.fileByIndex(src_inst.file);
2377 break :container .{2544 break :container .{
2378 loaded_opaque.zir_index,2545 src_inst,
2546 zf,
2547 zf.zir.?.getOpaqueDecl(src_inst.inst).capture_names,
2548 loaded_opaque.captures,
2379 loaded_opaque.name,2549 loaded_opaque.name,
2380 loaded_opaque.name_nav,2550 loaded_opaque.name_nav,
2551 loaded_opaque.namespace,
2381 };2552 };
2382 },2553 },
2383 else => |val_key| break :done switch (val_key.typeOf()) {2554 else => |val_key| break :done switch (val_key.typeOf()) {
...@@ -2389,37 +2560,133 @@ fn updateConstIncompleteInner(...@@ -2389,37 +2560,133 @@ fn updateConstIncompleteInner(
2389 try diw.writeByte(@intFromBool(true));2560 try diw.writeByte(@intFromBool(true));
2390 },2561 },
2391 else => |ty| {2562 else => |ty| {
2392 const ty_cpi = try dwarf.getConst(pt, Value.fromInterned(ty));
2393 try diw.writeUleb128(try dwarf.refAbbrevCode(.undefined_comptime_value));2563 try diw.writeUleb128(try dwarf.refAbbrevCode(.undefined_comptime_value));
2394 try dwarf.sectionOffset(2564 try dwarf.refConst(pt, di_nw, .fromInterned(ty));
2395 di_nw,
2396 Const.get(ty_cpi, dwarf).debug_info_ni.unwrap().?,
2397 0,
2398 );
2399 },2565 },
2400 },2566 },
2401 };2567 };
2402 const src_inst = zir_index.resolveFull(ip) orelse {2568 const capturing = for (captures.get(ip)) |capture| switch (capture.tag) {
2403 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_lost));2569 .@"comptime", .runtime => break true,
2404 break :done;2570 .nav_val, .nav_ref => {},
2405 };2571 } else false;
2406 if (maybe_name_nav.unwrap()) |name_nav| {2572 const spec_di = if (false and capturing) try dwarf.getDecl(pt, val) else undefined;
2407 const name_src_inst = ip.getNav(name_nav).srcInst(ip).resolve(ip).?;2573 _ = spec_di;
2408 const decl = zcu.fileByIndex(src_inst.file).zir.?.getDeclaration(name_src_inst);2574 if (maybe_name_nav.unwrap()) |name_ni| {
2409 const parent_cpi = try dwarf.getConst(pt, .fromInterned(zcu.fileRootType(src_inst.file)));2575 const name_nav = ip.getNav(name_ni);
2410 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_namespace_struct));2576 const name_src_inst = name_nav.srcInst(ip).resolve(ip).?;
2411 try dwarf.sectionOffset(di_nw, Const.get(parent_cpi, dwarf).debug_info_ni.unwrap().?, 0);2577 const decl = zf.zir.?.getDeclaration(name_src_inst);
2578 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2579 name_nav.analysis.?.namespace,
2580 ).owner_type);
2581 try diw.writeUleb128(try dwarf.refAbbrevCode(
2582 if (capturing) .decl_capturing_namespace_struct else .decl_namespace_struct,
2583 ));
2584 try dwarf.sectionOffset(di_nw, parent_ni, 0);
2412 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);2585 try diw.writeInt(u32, decl.src_line + 1, dwarf.endian);
2413 try diw.writeUleb128(decl.src_column + 1);2586 try diw.writeUleb128(decl.src_column + 1);
2414 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);2587 try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2588 try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip));
2415 } else {2589 } else {
2416 const ui = dwarf.getUnit(zcu.fileByIndex(src_inst.file).mod.?);2590 const ui = dwarf.getUnit(zf.mod.?);
2417 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, src_inst.file);2591 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, src_inst.file);
2418 try diw.writeUleb128(try dwarf.refAbbrevCode(.empty_struct_type));2592 const parent_ni = if (false) try dwarf.getDecl(pt, ip.namespacePtr(
2593 ip.namespacePtr(namespace).parent.unwrap().?,
2594 ).owner_type);
2595 _ = parent_ni;
2596 try diw.writeUleb128(try dwarf.refAbbrevCode(
2597 if (capturing) .capturing_empty_struct_type else .empty_struct_type,
2598 ));
2419 try diw.writeUleb128(@backingInt(fi));2599 try diw.writeUleb128(@backingInt(fi));
2600 try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip));
2420 }2601 }
2421 try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip));
2422 try diw.writeByte(@intFromBool(true));2602 try diw.writeByte(@intFromBool(true));
2603 if (capturing) {
2604 for (capture_names, captures.get(ip)) |capture_name, capture| switch (capture.unwrap()) {
2605 .@"comptime" => |capture_val| {
2606 const ty: Type = .fromInterned(ip.typeOf(capture_val));
2607 const ty_class = ty.classify(zcu);
2608 try diw.writeUleb128(try dwarf.refAbbrevCode(switch (ty_class) {
2609 .no_possible_value => unreachable,
2610 .one_possible_value => .comptime_capture,
2611 .runtime => .comptime_capture_runtime,
2612 .partially_comptime => .comptime_capture_partially_comptime,
2613 .fully_comptime => .comptime_capture_fully_comptime,
2614 }));
2615 try dwarf.strp(&dwarf.debug_str, di_nw, zf.zir.?.nullTerminatedString(capture_name));
2616 try dwarf.refConst(pt, di_nw, ty.toValue());
2617 if (ty_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, .fromInterned(capture_val));
2618 if (ty_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, .fromInterned(capture_val));
2619 },
2620 .runtime => |capture_ty| {
2621 try diw.writeUleb128(try dwarf.refAbbrevCode(.runtime_capture));
2622 try dwarf.strp(&dwarf.debug_str, di_nw, zf.zir.?.nullTerminatedString(capture_name));
2623 try dwarf.refConst(pt, di_nw, .fromInterned(capture_ty));
2624 },
2625 .nav_val, .nav_ref => {},
2626 };
2627 try diw.writeByte(@backingInt(AbbrevCode.null));
2628 }
2629 }
2630 try dwarf.genDebugInfoPadding(diw, diw.unusedCapacityLen());
2631}
2632
2633pub fn genDecl(
2634 dwarf: *Dwarf,
2635 pt: Zcu.PerThread,
2636 di_nw: *MappedFile.Node.Writer,
2637 instance_val: InternPool.Index,
2638) link.Error!void {
2639 dwarf.genDeclInner(pt, di_nw, instance_val) catch |err| switch (err) {
2640 else => |e| return e,
2641 error.WriteFailed => return dwarf.reportWriteError(di_nw),
2642 };
2643}
2644fn genDeclInner(
2645 dwarf: *Dwarf,
2646 pt: Zcu.PerThread,
2647 di_nw: *MappedFile.Node.Writer,
2648 instance_val: InternPool.Index,
2649) link.EmitError!void {
2650 const ip = &dwarf.lf.comp.zcu.?.intern_pool;
2651 const diw = &di_nw.interface;
2652 switch (ip.indexToKey(instance_val)) {
2653 else => unreachable,
2654 .struct_type => {
2655 const loaded_struct = ip.loadStructType(instance_val);
2656 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2657 ip.namespacePtr(loaded_struct.namespace).parent.unwrap().?,
2658 ).owner_type);
2659 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_specification_struct));
2660 try dwarf.sectionOffset(di_nw, parent_ni, 0);
2661 try diw.writeInt(u32, 0, dwarf.endian);
2662 try diw.writeUleb128(0);
2663 try diw.writeByte(DW.ACCESS.public);
2664 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.name.toSlice(ip));
2665 },
2666 .enum_type => {
2667 const loaded_enum = ip.loadEnumType(instance_val);
2668 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2669 ip.namespacePtr(loaded_enum.namespace).parent.unwrap().?,
2670 ).owner_type);
2671 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_specification_enum));
2672 try dwarf.sectionOffset(di_nw, parent_ni, 0);
2673 try diw.writeInt(u32, 0, dwarf.endian);
2674 try diw.writeUleb128(0);
2675 try diw.writeByte(DW.ACCESS.public);
2676 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.name.toSlice(ip));
2677 },
2678 .union_type => {
2679 const loaded_union = ip.loadUnionType(instance_val);
2680 const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(
2681 ip.namespacePtr(loaded_union.namespace).parent.unwrap().?,
2682 ).owner_type);
2683 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_specification_union));
2684 try dwarf.sectionOffset(di_nw, parent_ni, 0);
2685 try diw.writeInt(u32, 0, dwarf.endian);
2686 try diw.writeUleb128(0);
2687 try diw.writeByte(DW.ACCESS.public);
2688 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_union.name.toSlice(ip));
2689 },
2423 }2690 }
2424 try dwarf.genDebugInfoPadding(diw, diw.unusedCapacityLen());2691 try dwarf.genDebugInfoPadding(diw, diw.unusedCapacityLen());
2425}2692}
...@@ -2430,8 +2697,13 @@ pub fn updateLineNumber(...@@ -2430,8 +2697,13 @@ pub fn updateLineNumber(
2430 inst: InternPool.TrackedInst.Index,2697 inst: InternPool.TrackedInst.Index,
2431 line: u32,2698 line: u32,
2432) void {2699) void {
2433 const decl_ni = dwarf.decls.get(inst) orelse return;2700 const di = dwarf.getDeclIfExists(inst) orelse return;
2434 std.mem.writeInt(u32, decl_ni.slice(mf)[AbbrevCode.decl_bytes..][0..4], line + 1, dwarf.endian);2701 const decl_ni = di.get(dwarf).debug_info_ni.unwrap() orelse return;
2702 std.mem.writeInt(u32, decl_ni.slice(mf)[AbbrevCode.decl_size..][0..4], line + 1, dwarf.endian);
2703}
2704
2705pub fn lostTracking(dwarf: *Dwarf, diw: *Writer) link.EmitError!void {
2706 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_lost));
2435}2707}
24362708
2437fn refAbbrevCodeIfExists(2709fn refAbbrevCodeIfExists(
...@@ -2442,7 +2714,7 @@ fn refAbbrevCodeIfExists(...@@ -2442,7 +2714,7 @@ fn refAbbrevCodeIfExists(
2442 return if (dwarf.debug_abbrev.set.contains(abbrev_code)) @backingInt(abbrev_code) else null;2714 return if (dwarf.debug_abbrev.set.contains(abbrev_code)) @backingInt(abbrev_code) else null;
2443}2715}
24442716
2445pub fn refAbbrevCode(2717fn refAbbrevCode(
2446 dwarf: *Dwarf,2718 dwarf: *Dwarf,
2447 abbrev_code: AbbrevCode,2719 abbrev_code: AbbrevCode,
2448) link.Error!@typeInfo(AbbrevCode).@"enum".tag_type {2720) link.Error!@typeInfo(AbbrevCode).@"enum".tag_type {
...@@ -2517,6 +2789,75 @@ fn symbolAddress(...@@ -2517,6 +2789,75 @@ fn symbolAddress(
2517 try elf.addReloc(@bitCast(nw.ni), offset, target_si, @bitCast(@as(u64, addend)), .absAddr(elf));2789 try elf.addReloc(@bitCast(nw.ni), offset, target_si, @bitCast(@as(u64, addend)), .absAddr(elf));
2518}2790}
25192791
2792fn blockConst(dwarf: *Dwarf, pt: Zcu.PerThread, nw: *MappedFile.Node.Writer, val: Value) link.EmitError!void {
2793 const ty = val.typeOf(pt.zcu);
2794 const size = ty.abiSize(pt.zcu);
2795 try nw.interface.writeUleb128(size);
2796 const start = nw.interface.end;
2797 if (size > 0) try codegen.generateSymbol(
2798 dwarf.lf,
2799 pt,
2800 val,
2801 &nw.interface,
2802 .{ .atom_index = @bitCast(nw.ni) },
2803 );
2804 assert(start + size == nw.interface.end);
2805}
2806
2807fn refConst(dwarf: *Dwarf, pt: Zcu.PerThread, nw: *MappedFile.Node.Writer, val: Value) link.EmitError!void {
2808 try dwarf.sectionOffset(nw, Const.get(try dwarf.getConst(pt, val), dwarf).debug_info_ni.unwrap().?, 0);
2809}
2810
2811fn bigIntConstValue(dwarf: *Dwarf, diw: *Writer, ty: Type, big_int: std.math.big.int.Const) link.EmitError!void {
2812 const zcu = dwarf.lf.comp.zcu.?;
2813 const signedness = switch (ty.toIntern()) {
2814 .comptime_int_type => .signed,
2815 else => ty.intInfo(zcu).signedness,
2816 };
2817 const bits = @max(1, big_int.bitCountTwosCompForSignedness(signedness));
2818 if (bits <= 64) {
2819 try diw.writeUleb128(@as(u13, switch (signedness) {
2820 .signed => DW.FORM.sdata,
2821 .unsigned => DW.FORM.udata,
2822 }));
2823 var bit: usize = 0;
2824 var carry: u1 = 1;
2825 for (try diw.writableSlice(@divCeil(bits, 7))) |*byte| {
2826 const limb_bits = @typeInfo(std.math.big.Limb).int.bits;
2827 const limb_index = bit / limb_bits;
2828 const limb_shift: std.math.Log2Int(std.math.big.Limb) = @intCast(bit % limb_bits);
2829 const low_abs_part: u7 = @truncate(big_int.limbs[limb_index] >> limb_shift);
2830 const abs_part = if (limb_shift > limb_bits - 7 and limb_index + 1 < big_int.limbs.len) abs_part: {
2831 const high_abs_part: u7 = @truncate(big_int.limbs[limb_index + 1] << -%limb_shift);
2832 break :abs_part high_abs_part | low_abs_part;
2833 } else low_abs_part;
2834 const twos_comp_part = if (big_int.positive) abs_part else twos_comp_part: {
2835 const twos_comp_part, carry = @addWithOverflow(~abs_part, carry);
2836 break :twos_comp_part twos_comp_part;
2837 };
2838 bit += 7;
2839 byte.* = @as(u8, if (bit < bits) 0x80 else 0x00) | twos_comp_part;
2840 }
2841 } else {
2842 try diw.writeUleb128(DW.FORM.block);
2843 const size = switch (ty.toIntern()) {
2844 .comptime_int_type => @divCeil(bits, 8),
2845 else => ty.abiSize(zcu),
2846 };
2847 try diw.writeUleb128(size);
2848 big_int.writeTwosComplement(try diw.writableSlice(@intCast(size)), dwarf.endian);
2849 }
2850}
2851
2852fn enumConstValue(dwarf: *Dwarf, diw: *Writer, loaded_enum: InternPool.LoadedEnumType, field_index: usize) link.EmitError!void {
2853 const zcu = dwarf.lf.comp.zcu.?;
2854 var big_int_space: Value.BigIntSpace = undefined;
2855 try dwarf.bigIntConstValue(diw, .fromInterned(loaded_enum.int_tag_type), if (loaded_enum.field_values.len > 0)
2856 Value.fromInterned(loaded_enum.field_values.get(&zcu.intern_pool)[field_index]).toBigInt(&big_int_space, zcu)
2857 else
2858 std.math.big.int.Mutable.init(&big_int_space.limbs, field_index).toConst());
2859}
2860
2520fn strp(dwarf: *Dwarf, s: *Str, nw: *MappedFile.Node.Writer, str: []const u8) link.EmitError!void {2861fn strp(dwarf: *Dwarf, s: *Str, nw: *MappedFile.Node.Writer, str: []const u8) link.EmitError!void {
2521 const comp = dwarf.lf.comp;2862 const comp = dwarf.lf.comp;
2522 const mf = &dwarf.lf.cast(.elf2).?.mf;2863 const mf = &dwarf.lf.cast(.elf2).?.mf;
...@@ -2571,6 +2912,7 @@ pub const AbbrevCode = enum {...@@ -2571,6 +2912,7 @@ pub const AbbrevCode = enum {
2571 decl_empty_enum,2912 decl_empty_enum,
2572 decl_enum,2913 decl_enum,
2573 decl_namespace_struct,2914 decl_namespace_struct,
2915 decl_capturing_namespace_struct,
2574 decl_struct,2916 decl_struct,
2575 decl_packed_struct,2917 decl_packed_struct,
2576 decl_union,2918 decl_union,
...@@ -2587,6 +2929,7 @@ pub const AbbrevCode = enum {...@@ -2587,6 +2929,7 @@ pub const AbbrevCode = enum {
2587 decl_extern_nullary_func,2929 decl_extern_nullary_func,
2588 decl_extern_func,2930 decl_extern_func,
2589 decl_specification_struct,2931 decl_specification_struct,
2932 decl_specification_enum,
2590 decl_specification_union,2933 decl_specification_union,
2591 decl_specification_func,2934 decl_specification_func,
2592 decl_instance_alias,2935 decl_instance_alias,
...@@ -2619,11 +2962,13 @@ pub const AbbrevCode = enum {...@@ -2619,11 +2962,13 @@ pub const AbbrevCode = enum {
2619 enum_field,2962 enum_field,
2620 generated_field,2963 generated_field,
2621 field,2964 field,
2622 field_default_runtime_bits,2965 field_default_fully_runtime,
2623 field_default_comptime_state,2966 field_default_partially_comptime,
2967 field_default_fully_comptime,
2624 field_comptime,2968 field_comptime,
2625 field_comptime_runtime_bits,2969 field_comptime_fully_runtime,
2626 field_comptime_comptime_state,2970 field_comptime_partially_comptime,
2971 field_comptime_fully_comptime,
2627 packed_field,2972 packed_field,
2628 tagged_union,2973 tagged_union,
2629 tagged_union_field,2974 tagged_union_field,
...@@ -2655,6 +3000,7 @@ pub const AbbrevCode = enum {...@@ -2655,6 +3000,7 @@ pub const AbbrevCode = enum {
2655 empty_enum_type,3000 empty_enum_type,
2656 enum_type,3001 enum_type,
2657 empty_struct_type,3002 empty_struct_type,
3003 capturing_empty_struct_type,
2658 struct_type,3004 struct_type,
2659 empty_packed_struct_type,3005 empty_packed_struct_type,
2660 packed_struct_type,3006 packed_struct_type,
...@@ -2662,6 +3008,11 @@ pub const AbbrevCode = enum {...@@ -2662,6 +3008,11 @@ pub const AbbrevCode = enum {
2662 union_type,3008 union_type,
2663 empty_packed_union_type,3009 empty_packed_union_type,
2664 packed_union_type,3010 packed_union_type,
3011 comptime_capture,
3012 comptime_capture_runtime,
3013 comptime_capture_partially_comptime,
3014 comptime_capture_fully_comptime,
3015 runtime_capture,
2665 builtin_extern_nullary_func,3016 builtin_extern_nullary_func,
2666 builtin_extern_func,3017 builtin_extern_func,
2667 builtin_extern_var,3018 builtin_extern_var,
...@@ -2672,19 +3023,19 @@ pub const AbbrevCode = enum {...@@ -2672,19 +3023,19 @@ pub const AbbrevCode = enum {
2672 arg,3023 arg,
2673 unnamed_arg,3024 unnamed_arg,
2674 comptime_arg,3025 comptime_arg,
3026 comptime_arg_fully_runtime,
3027 comptime_arg_partially_comptime,
3028 comptime_arg_fully_comptime,
2675 unnamed_comptime_arg,3029 unnamed_comptime_arg,
2676 comptime_arg_runtime_bits,3030 unnamed_comptime_arg_fully_runtime,
2677 unnamed_comptime_arg_runtime_bits,3031 unnamed_comptime_arg_partially_comptime,
2678 comptime_arg_comptime_state,3032 unnamed_comptime_arg_fully_comptime,
2679 unnamed_comptime_arg_comptime_state,
2680 comptime_arg_runtime_bits_comptime_state,
2681 unnamed_comptime_arg_runtime_bits_comptime_state,
2682 extern_param,3033 extern_param,
2683 local_var,3034 local_var,
2684 local_const,3035 local_const,
2685 local_const_runtime_bits,3036 local_const_fully_runtime,
2686 local_const_comptime_state,3037 local_const_partially_comptime,
2687 local_const_runtime_bits_comptime_state,3038 local_const_fully_comptime,
2688 undefined_comptime_value,3039 undefined_comptime_value,
2689 comptime_value,3040 comptime_value,
2690 location_comptime_value,3041 location_comptime_value,
...@@ -2696,11 +3047,11 @@ pub const AbbrevCode = enum {...@@ -2696,11 +3047,11 @@ pub const AbbrevCode = enum {
2696 comptime_value_elem_runtime_bits,3047 comptime_value_elem_runtime_bits,
2697 comptime_value_elem_comptime_state,3048 comptime_value_elem_comptime_state,
26983049
2699 const decl_bytes = uleb128Size(@backingInt(AbbrevCode.decl_instance_extern_func));3050 const decl_size = uleb128Size(@backingInt(AbbrevCode.decl_instance_extern_func));
2700 comptime {3051 comptime {
2701 assert(uleb128Size(@backingInt(AbbrevCode.pad_1)) == 1);3052 assert(uleb128Size(@backingInt(AbbrevCode.pad_1)) == 1);
2702 assert(uleb128Size(@backingInt(AbbrevCode.pad_n)) == 1);3053 assert(uleb128Size(@backingInt(AbbrevCode.pad_n)) == 1);
2703 assert(uleb128Size(@backingInt(AbbrevCode.decl_alias)) == decl_bytes);3054 assert(uleb128Size(@backingInt(AbbrevCode.decl_alias)) == decl_size);
2704 }3055 }
27053056
2706 const Attr = struct {3057 const Attr = struct {
...@@ -2766,6 +3117,13 @@ pub const AbbrevCode = enum {...@@ -2766,6 +3117,13 @@ pub const AbbrevCode = enum {
2766 .{ .declaration, .flag },3117 .{ .declaration, .flag },
2767 },3118 },
2768 },3119 },
3120 .decl_capturing_namespace_struct = .{
3121 .tag = .structure_type,
3122 .children = true,
3123 .attrs = decl_attrs ++ .{
3124 .{ .declaration, .flag },
3125 },
3126 },
2769 .decl_struct = .{3127 .decl_struct = .{
2770 .tag = .structure_type,3128 .tag = .structure_type,
2771 .children = true,3129 .children = true,
...@@ -2908,11 +3266,15 @@ pub const AbbrevCode = enum {...@@ -2908,11 +3266,15 @@ pub const AbbrevCode = enum {
2908 },3266 },
2909 },3267 },
2910 .decl_specification_struct = .{3268 .decl_specification_struct = .{
2911 .tag = .variable,3269 .tag = .structure_type,
3270 .attrs = decl_specification_attrs,
3271 },
3272 .decl_specification_enum = .{
3273 .tag = .enumeration_type,
2912 .attrs = decl_specification_attrs,3274 .attrs = decl_specification_attrs,
2913 },3275 },
2914 .decl_specification_union = .{3276 .decl_specification_union = .{
2915 .tag = .constant,3277 .tag = .union_type,
2916 .attrs = decl_specification_attrs,3278 .attrs = decl_specification_attrs,
2917 },3279 },
2918 .decl_specification_func = .{3280 .decl_specification_func = .{
...@@ -2940,6 +3302,7 @@ pub const AbbrevCode = enum {...@@ -2940,6 +3302,7 @@ pub const AbbrevCode = enum {
2940 },3302 },
2941 .decl_instance_namespace_struct = .{3303 .decl_instance_namespace_struct = .{
2942 .tag = .structure_type,3304 .tag = .structure_type,
3305 .children = true,
2943 .attrs = decl_instance_attrs ++ .{3306 .attrs = decl_instance_attrs ++ .{
2944 .{ .declaration, .flag },3307 .{ .declaration, .flag },
2945 },3308 },
...@@ -3118,6 +3481,7 @@ pub const AbbrevCode = enum {...@@ -3118,6 +3481,7 @@ pub const AbbrevCode = enum {
3118 .attrs = &.{3481 .attrs = &.{
3119 .{ .decl_file, .udata },3482 .{ .decl_file, .udata },
3120 .{ .name, .strp },3483 .{ .name, .strp },
3484 .{ .declaration, .flag },
3121 },3485 },
3122 },3486 },
3123 .file = .{3487 .file = .{
...@@ -3161,7 +3525,17 @@ pub const AbbrevCode = enum {...@@ -3161,7 +3525,17 @@ pub const AbbrevCode = enum {
3161 .{ .alignment, .udata },3525 .{ .alignment, .udata },
3162 },3526 },
3163 },3527 },
3164 .field_default_runtime_bits = .{3528 .field_default_fully_runtime = .{
3529 .tag = .member,
3530 .attrs = &.{
3531 .{ .name, .strp },
3532 .{ .type, .ref_addr },
3533 .{ .data_member_location, .udata },
3534 .{ .alignment, .udata },
3535 .{ .default_value, .block },
3536 },
3537 },
3538 .field_default_partially_comptime = .{
3165 .tag = .member,3539 .tag = .member,
3166 .attrs = &.{3540 .attrs = &.{
3167 .{ .name, .strp },3541 .{ .name, .strp },
...@@ -3169,9 +3543,10 @@ pub const AbbrevCode = enum {...@@ -3169,9 +3543,10 @@ pub const AbbrevCode = enum {
3169 .{ .data_member_location, .udata },3543 .{ .data_member_location, .udata },
3170 .{ .alignment, .udata },3544 .{ .alignment, .udata },
3171 .{ .default_value, .block },3545 .{ .default_value, .block },
3546 .{ .ZIG_comptime_value, .ref_addr },
3172 },3547 },
3173 },3548 },
3174 .field_default_comptime_state = .{3549 .field_default_fully_comptime = .{
3175 .tag = .member,3550 .tag = .member,
3176 .attrs = &.{3551 .attrs = &.{
3177 .{ .name, .strp },3552 .{ .name, .strp },
...@@ -3189,7 +3564,7 @@ pub const AbbrevCode = enum {...@@ -3189,7 +3564,7 @@ pub const AbbrevCode = enum {
3189 .{ .type, .ref_addr },3564 .{ .type, .ref_addr },
3190 },3565 },
3191 },3566 },
3192 .field_comptime_runtime_bits = .{3567 .field_comptime_fully_runtime = .{
3193 .tag = .member,3568 .tag = .member,
3194 .attrs = &.{3569 .attrs = &.{
3195 .{ .const_expr, .flag_present },3570 .{ .const_expr, .flag_present },
...@@ -3198,7 +3573,17 @@ pub const AbbrevCode = enum {...@@ -3198,7 +3573,17 @@ pub const AbbrevCode = enum {
3198 .{ .const_value, .block },3573 .{ .const_value, .block },
3199 },3574 },
3200 },3575 },
3201 .field_comptime_comptime_state = .{3576 .field_comptime_partially_comptime = .{
3577 .tag = .member,
3578 .attrs = &.{
3579 .{ .const_expr, .flag_present },
3580 .{ .name, .strp },
3581 .{ .type, .ref_addr },
3582 .{ .const_value, .block },
3583 .{ .ZIG_comptime_value, .ref_addr },
3584 },
3585 },
3586 .field_comptime_fully_comptime = .{
3202 .tag = .member,3587 .tag = .member,
3203 .attrs = &.{3588 .attrs = &.{
3204 .{ .const_expr, .flag_present },3589 .{ .const_expr, .flag_present },
...@@ -3441,6 +3826,15 @@ pub const AbbrevCode = enum {...@@ -3441,6 +3826,15 @@ pub const AbbrevCode = enum {
3441 .{ .declaration, .flag },3826 .{ .declaration, .flag },
3442 },3827 },
3443 },3828 },
3829 .capturing_empty_struct_type = .{
3830 .tag = .structure_type,
3831 .children = true,
3832 .attrs = &.{
3833 .{ .decl_file, .udata },
3834 .{ .name, .strp },
3835 .{ .declaration, .flag },
3836 },
3837 },
3444 .struct_type = .{3838 .struct_type = .{
3445 .tag = .structure_type,3839 .tag = .structure_type,
3446 .children = true,3840 .children = true,
...@@ -3504,6 +3898,45 @@ pub const AbbrevCode = enum {...@@ -3504,6 +3898,45 @@ pub const AbbrevCode = enum {
3504 .{ .type, .ref_addr },3898 .{ .type, .ref_addr },
3505 },3899 },
3506 },3900 },
3901 .comptime_capture = .{
3902 .tag = .template_value_parameter,
3903 .attrs = &.{
3904 .{ .name, .strp },
3905 .{ .type, .ref_addr },
3906 },
3907 },
3908 .comptime_capture_runtime = .{
3909 .tag = .template_value_parameter,
3910 .attrs = &.{
3911 .{ .name, .strp },
3912 .{ .type, .ref_addr },
3913 .{ .const_value, .block },
3914 },
3915 },
3916 .comptime_capture_partially_comptime = .{
3917 .tag = .template_value_parameter,
3918 .attrs = &.{
3919 .{ .name, .strp },
3920 .{ .type, .ref_addr },
3921 .{ .const_value, .block },
3922 .{ .ZIG_comptime_value, .ref_addr },
3923 },
3924 },
3925 .comptime_capture_fully_comptime = .{
3926 .tag = .template_value_parameter,
3927 .attrs = &.{
3928 .{ .name, .strp },
3929 .{ .type, .ref_addr },
3930 .{ .ZIG_comptime_value, .ref_addr },
3931 },
3932 },
3933 .runtime_capture = .{
3934 .tag = .template_type_parameter,
3935 .attrs = &.{
3936 .{ .name, .strp },
3937 .{ .type, .ref_addr },
3938 },
3939 },
3507 .builtin_extern_nullary_func = .{3940 .builtin_extern_nullary_func = .{
3508 .tag = .subprogram,3941 .tag = .subprogram,
3509 .attrs = &.{3942 .attrs = &.{
...@@ -3577,14 +4010,14 @@ pub const AbbrevCode = enum {...@@ -3577,14 +4010,14 @@ pub const AbbrevCode = enum {
3577 .tag = .formal_parameter,4010 .tag = .formal_parameter,
3578 .attrs = &.{4011 .attrs = &.{
3579 .{ .name, .strp },4012 .{ .name, .strp },
3580 //.{ .type, .ref_addr },4013 .{ .type, .ref_addr },
3581 .{ .location, .exprloc },4014 .{ .location, .exprloc },
3582 },4015 },
3583 },4016 },
3584 .unnamed_arg = .{4017 .unnamed_arg = .{
3585 .tag = .formal_parameter,4018 .tag = .formal_parameter,
3586 .attrs = &.{4019 .attrs = &.{
3587 //.{ .type, .ref_addr },4020 .{ .type, .ref_addr },
3588 .{ .location, .exprloc },4021 .{ .location, .exprloc },
3589 },4022 },
3590 },4023 },
...@@ -3593,80 +4026,80 @@ pub const AbbrevCode = enum {...@@ -3593,80 +4026,80 @@ pub const AbbrevCode = enum {
3593 .attrs = &.{4026 .attrs = &.{
3594 .{ .const_expr, .flag_present },4027 .{ .const_expr, .flag_present },
3595 .{ .name, .strp },4028 .{ .name, .strp },
3596 //.{ .type, .ref_addr },4029 .{ .type, .ref_addr },
3597 },4030 },
3598 },4031 },
3599 .unnamed_comptime_arg = .{4032 .comptime_arg_fully_runtime = .{
3600 .tag = .formal_parameter,4033 .tag = .formal_parameter,
3601 .attrs = &.{4034 .attrs = &.{
3602 .{ .const_expr, .flag_present },4035 .{ .const_expr, .flag_present },
3603 //.{ .type, .ref_addr },4036 .{ .name, .strp },
4037 .{ .type, .ref_addr },
4038 .{ .const_value, .block },
3604 },4039 },
3605 },4040 },
3606 .comptime_arg_runtime_bits = .{4041 .comptime_arg_partially_comptime = .{
3607 .tag = .formal_parameter,4042 .tag = .formal_parameter,
3608 .attrs = &.{4043 .attrs = &.{
3609 .{ .const_expr, .flag_present },4044 .{ .const_expr, .flag_present },
3610 .{ .name, .strp },4045 .{ .name, .strp },
3611 //.{ .type, .ref_addr },4046 .{ .type, .ref_addr },
3612 .{ .const_value, .block },4047 .{ .const_value, .block },
4048 .{ .ZIG_comptime_value, .ref_addr },
3613 },4049 },
3614 },4050 },
3615 .unnamed_comptime_arg_runtime_bits = .{4051 .comptime_arg_fully_comptime = .{
3616 .tag = .formal_parameter,4052 .tag = .formal_parameter,
3617 .attrs = &.{4053 .attrs = &.{
3618 .{ .const_expr, .flag_present },4054 .{ .const_expr, .flag_present },
3619 //.{ .type, .ref_addr },4055 .{ .name, .strp },
3620 .{ .const_value, .block },4056 .{ .type, .ref_addr },
4057 .{ .ZIG_comptime_value, .ref_addr },
3621 },4058 },
3622 },4059 },
3623 .comptime_arg_comptime_state = .{4060 .unnamed_comptime_arg = .{
3624 .tag = .formal_parameter,4061 .tag = .formal_parameter,
3625 .attrs = &.{4062 .attrs = &.{
3626 .{ .const_expr, .flag_present },4063 .{ .const_expr, .flag_present },
3627 .{ .name, .strp },4064 .{ .type, .ref_addr },
3628 //.{ .type, .ref_addr },
3629 //.{ .ZIG_comptime_value, .ref_addr },
3630 },4065 },
3631 },4066 },
3632 .unnamed_comptime_arg_comptime_state = .{4067 .unnamed_comptime_arg_fully_runtime = .{
3633 .tag = .formal_parameter,4068 .tag = .formal_parameter,
3634 .attrs = &.{4069 .attrs = &.{
3635 .{ .const_expr, .flag_present },4070 .{ .const_expr, .flag_present },
3636 //.{ .type, .ref_addr },4071 .{ .type, .ref_addr },
3637 //.{ .ZIG_comptime_value, .ref_addr },4072 .{ .const_value, .block },
3638 },4073 },
3639 },4074 },
3640 .comptime_arg_runtime_bits_comptime_state = .{4075 .unnamed_comptime_arg_partially_comptime = .{
3641 .tag = .formal_parameter,4076 .tag = .formal_parameter,
3642 .attrs = &.{4077 .attrs = &.{
3643 .{ .const_expr, .flag_present },4078 .{ .const_expr, .flag_present },
3644 .{ .name, .strp },4079 .{ .type, .ref_addr },
3645 //.{ .type, .ref_addr },
3646 .{ .const_value, .block },4080 .{ .const_value, .block },
3647 //.{ .ZIG_comptime_value, .ref_addr },4081 .{ .ZIG_comptime_value, .ref_addr },
3648 },4082 },
3649 },4083 },
3650 .unnamed_comptime_arg_runtime_bits_comptime_state = .{4084 .unnamed_comptime_arg_fully_comptime = .{
3651 .tag = .formal_parameter,4085 .tag = .formal_parameter,
3652 .attrs = &.{4086 .attrs = &.{
3653 .{ .const_expr, .flag_present },4087 .{ .const_expr, .flag_present },
3654 //.{ .type, .ref_addr },4088 .{ .type, .ref_addr },
3655 .{ .const_value, .block },4089 .{ .ZIG_comptime_value, .ref_addr },
3656 //.{ .ZIG_comptime_value, .ref_addr },
3657 },4090 },
3658 },4091 },
3659 .extern_param = .{4092 .extern_param = .{
3660 .tag = .formal_parameter,4093 .tag = .formal_parameter,
3661 .attrs = &.{4094 .attrs = &.{
3662 //.{ .type, .ref_addr },4095 .{ .type, .ref_addr },
3663 },4096 },
3664 },4097 },
3665 .local_var = .{4098 .local_var = .{
3666 .tag = .variable,4099 .tag = .variable,
3667 .attrs = &.{4100 .attrs = &.{
3668 .{ .name, .strp },4101 .{ .name, .strp },
3669 //.{ .type, .ref_addr },4102 .{ .type, .ref_addr },
3670 .{ .location, .exprloc },4103 .{ .location, .exprloc },
3671 },4104 },
3672 },4105 },
...@@ -3674,32 +4107,32 @@ pub const AbbrevCode = enum {...@@ -3674,32 +4107,32 @@ pub const AbbrevCode = enum {
3674 .tag = .constant,4107 .tag = .constant,
3675 .attrs = &.{4108 .attrs = &.{
3676 .{ .name, .strp },4109 .{ .name, .strp },
3677 //.{ .type, .ref_addr },4110 .{ .type, .ref_addr },
3678 },4111 },
3679 },4112 },
3680 .local_const_runtime_bits = .{4113 .local_const_fully_runtime = .{
3681 .tag = .constant,4114 .tag = .constant,
3682 .attrs = &.{4115 .attrs = &.{
3683 .{ .name, .strp },4116 .{ .name, .strp },
3684 //.{ .type, .ref_addr },4117 .{ .type, .ref_addr },
3685 .{ .const_value, .block },4118 .{ .const_value, .block },
3686 },4119 },
3687 },4120 },
3688 .local_const_comptime_state = .{4121 .local_const_partially_comptime = .{
3689 .tag = .constant,4122 .tag = .constant,
3690 .attrs = &.{4123 .attrs = &.{
3691 .{ .name, .strp },4124 .{ .name, .strp },
3692 //.{ .type, .ref_addr },4125 .{ .type, .ref_addr },
3693 //.{ .ZIG_comptime_value, .ref_addr },4126 .{ .const_value, .block },
4127 .{ .ZIG_comptime_value, .ref_addr },
3694 },4128 },
3695 },4129 },
3696 .local_const_runtime_bits_comptime_state = .{4130 .local_const_fully_comptime = .{
3697 .tag = .constant,4131 .tag = .constant,
3698 .attrs = &.{4132 .attrs = &.{
3699 .{ .name, .strp },4133 .{ .name, .strp },
3700 //.{ .type, .ref_addr },4134 .{ .type, .ref_addr },
3701 .{ .const_value, .block },4135 .{ .ZIG_comptime_value, .ref_addr },
3702 //.{ .ZIG_comptime_value, .ref_addr },
3703 },4136 },
3704 },4137 },
3705 .undefined_comptime_value = .{4138 .undefined_comptime_value = .{
src/link/Elf2.zig+138-48
...@@ -220,6 +220,7 @@ dwarf_units: []dwarf_relocs.Unit,...@@ -220,6 +220,7 @@ dwarf_units: []dwarf_relocs.Unit,
220dwarf_consts: std.array_hash_map.Auto(link.ConstPool.Index, dwarf_relocs.Const),220dwarf_consts: std.array_hash_map.Auto(link.ConstPool.Index, dwarf_relocs.Const),
221dwarf_globals: std.ArrayList(dwarf_relocs.Global),221dwarf_globals: std.ArrayList(dwarf_relocs.Global),
222dwarf_funcs: std.ArrayList(dwarf_relocs.Func),222dwarf_funcs: std.ArrayList(dwarf_relocs.Func),
223dwarf_decls: std.array_hash_map.Auto(Dwarf.Decl.Index, dwarf_relocs.Decl),
223224
224overflowed_reloc_count: u32,225overflowed_reloc_count: u32,
225misaligned_reloc_count: u32,226misaligned_reloc_count: u32,
...@@ -300,6 +301,7 @@ const Node = union(enum) {...@@ -300,6 +301,7 @@ const Node = union(enum) {
300 func_frame_fde: Dwarf.Func.Index,301 func_frame_fde: Dwarf.Func.Index,
301 func_debug_info: Dwarf.Func.Index,302 func_debug_info: Dwarf.Func.Index,
302 func_debug_line: Dwarf.Func.Index,303 func_debug_line: Dwarf.Func.Index,
304 decl_debug_info: Dwarf.Decl.Index,
303305
304 pub const InputIndex = enum(u32) {306 pub const InputIndex = enum(u32) {
305 _,307 _,
...@@ -884,6 +886,10 @@ const dwarf_relocs = struct {...@@ -884,6 +886,10 @@ const dwarf_relocs = struct {
884 debug_line_first_symbol_reloc: SymbolReloc.Index,886 debug_line_first_symbol_reloc: SymbolReloc.Index,
885 debug_line_first_node_reloc: NodeReloc.Index,887 debug_line_first_node_reloc: NodeReloc.Index,
886 };888 };
889 const Decl = struct {
890 debug_info_first_target_reloc: NodeReloc.Index,
891 debug_info_first_node_reloc: NodeReloc.Index,
892 };
887};893};
888894
889pub const MachineRelocType = union {895pub const MachineRelocType = union {
...@@ -1874,6 +1880,7 @@ const NodeReloc = struct {...@@ -1874,6 +1880,7 @@ const NodeReloc = struct {
1874 .const_debug_info => |cpi| &elf.dwarf_consts.getPtr(cpi).?.debug_info_first_target_reloc,1880 .const_debug_info => |cpi| &elf.dwarf_consts.getPtr(cpi).?.debug_info_first_target_reloc,
1875 .global_debug_info => |gi| &elf.dwarf_globals.items[@backingInt(gi)].debug_info_first_target_reloc,1881 .global_debug_info => |gi| &elf.dwarf_globals.items[@backingInt(gi)].debug_info_first_target_reloc,
1876 .func_debug_info => |fi| &elf.dwarf_funcs.items[@backingInt(fi)].debug_info_first_target_reloc,1882 .func_debug_info => |fi| &elf.dwarf_funcs.items[@backingInt(fi)].debug_info_first_target_reloc,
1883 .decl_debug_info => |di| &elf.dwarf_decls.getPtr(di).?.debug_info_first_target_reloc,
1877 };1884 };
1878 first_target_reloc.* = reloc.next;1885 first_target_reloc.* = reloc.next;
1879 },1886 },
...@@ -3330,6 +3337,7 @@ pub fn symbolForAtom(elf: *Elf, atom: link.File.AtomId) link.File.SymbolId {...@@ -3330,6 +3337,7 @@ pub fn symbolForAtom(elf: *Elf, atom: link.File.AtomId) link.File.SymbolId {
3330 .func_frame_fde,3337 .func_frame_fde,
3331 .func_debug_info,3338 .func_debug_info,
3332 .func_debug_line,3339 .func_debug_line,
3340 .decl_debug_info,
3333 => unreachable,3341 => unreachable,
3334 inline .nav,3342 inline .nav,
3335 .uav,3343 .uav,
...@@ -3838,6 +3846,7 @@ fn create(...@@ -3838,6 +3846,7 @@ fn create(
3838 .dwarf_consts = .empty,3846 .dwarf_consts = .empty,
3839 .dwarf_globals = .empty,3847 .dwarf_globals = .empty,
3840 .dwarf_funcs = .empty,3848 .dwarf_funcs = .empty,
3849 .dwarf_decls = .empty,
38413850
3842 .overflowed_reloc_count = 0,3851 .overflowed_reloc_count = 0,
3843 .misaligned_reloc_count = 0,3852 .misaligned_reloc_count = 0,
...@@ -3893,6 +3902,7 @@ pub fn deinit(elf: *Elf) void {...@@ -3893,6 +3902,7 @@ pub fn deinit(elf: *Elf) void {
3893 elf.dwarf_consts.deinit(gpa);3902 elf.dwarf_consts.deinit(gpa);
3894 elf.dwarf_globals.deinit(gpa);3903 elf.dwarf_globals.deinit(gpa);
3895 elf.dwarf_funcs.deinit(gpa);3904 elf.dwarf_funcs.deinit(gpa);
3905 elf.dwarf_decls.deinit(gpa);
38963906
3897 elf.* = undefined;3907 elf.* = undefined;
3898}3908}
...@@ -5193,6 +5203,7 @@ fn getNodeShndx(elf: *const Elf, ni: MappedFile.Node.Index) Section.Index {...@@ -5193,6 +5203,7 @@ fn getNodeShndx(elf: *const Elf, ni: MappedFile.Node.Index) Section.Index {
5193 .func_frame_fde,5203 .func_frame_fde,
5194 .func_debug_info,5204 .func_debug_info,
5195 .func_debug_line,5205 .func_debug_line,
5206 .decl_debug_info,
5196 => elf.getNode(ni.parent(&elf.mf).unwrap().?.parent(&elf.mf).unwrap().?).section,5207 => elf.getNode(ni.parent(&elf.mf).unwrap().?.parent(&elf.mf).unwrap().?).section,
5197 };5208 };
5198}5209}
...@@ -5230,6 +5241,7 @@ fn getNodeVAddr(elf: *Elf, ni: MappedFile.Node.Index) u64 {...@@ -5230,6 +5241,7 @@ fn getNodeVAddr(elf: *Elf, ni: MappedFile.Node.Index) u64 {
5230 .func_frame_fde,5241 .func_frame_fde,
5231 .func_debug_info,5242 .func_debug_info,
5232 .func_debug_line,5243 .func_debug_line,
5244 .decl_debug_info,
5233 => elf.computeNodeVAddr(ni),5245 => elf.computeNodeVAddr(ni),
5234 };5246 };
5235}5247}
...@@ -5269,6 +5281,7 @@ fn computeNodeVAddr(elf: *Elf, ni: MappedFile.Node.Index) u64 {...@@ -5269,6 +5281,7 @@ fn computeNodeVAddr(elf: *Elf, ni: MappedFile.Node.Index) u64 {
5269 .func_frame_fde,5281 .func_frame_fde,
5270 .func_debug_info,5282 .func_debug_info,
5271 .func_debug_line,5283 .func_debug_line,
5284 .decl_debug_info,
5272 => unreachable,5285 => unreachable,
5273 };5286 };
5274 const offset, _ = ni.location(&elf.mf).resolve(&elf.mf);5287 const offset, _ = ni.location(&elf.mf).resolve(&elf.mf);
...@@ -5304,6 +5317,7 @@ fn computeNodeSectionOffset(elf: *Elf, ni: MappedFile.Node.Index) u64 {...@@ -5304,6 +5317,7 @@ fn computeNodeSectionOffset(elf: *Elf, ni: MappedFile.Node.Index) u64 {
5304 .func_frame_fde,5317 .func_frame_fde,
5305 .func_debug_info,5318 .func_debug_info,
5306 .func_debug_line,5319 .func_debug_line,
5320 .decl_debug_info,
5307 => unreachable,5321 => unreachable,
5308 };5322 };
5309 const offset, _ = ni.location(&elf.mf).resolve(&elf.mf);5323 const offset, _ = ni.location(&elf.mf).resolve(&elf.mf);
...@@ -5394,6 +5408,9 @@ fn resetNodeRelocs(elf: *Elf, ni: MappedFile.Node.Index) void {...@@ -5394,6 +5408,9 @@ fn resetNodeRelocs(elf: *Elf, ni: MappedFile.Node.Index) void {
5394 .first_node_reloc = &elf.dwarf_funcs.items[@backingInt(fi)].debug_line_first_node_reloc,5408 .first_node_reloc = &elf.dwarf_funcs.items[@backingInt(fi)].debug_line_first_node_reloc,
5395 .skip_node_relocs = fi.get(&elf.dwarf).debug_info_ni,5409 .skip_node_relocs = fi.get(&elf.dwarf).debug_info_ni,
5396 },5410 },
5411 .decl_debug_info => |di| .{
5412 .first_node_reloc = &elf.dwarf_decls.getPtr(di).?.debug_info_first_node_reloc,
5413 },
5397 };5414 };
53985415
5399 if (opts.first_symbol_reloc) |ptr| {5416 if (opts.first_symbol_reloc) |ptr| {
...@@ -8150,6 +8167,7 @@ fn addNodeRelocAssumeCapacity(...@@ -8150,6 +8167,7 @@ fn addNodeRelocAssumeCapacity(
8150 .const_debug_info => |cpi| &elf.dwarf_consts.getPtr(cpi).?.debug_info_first_target_reloc,8167 .const_debug_info => |cpi| &elf.dwarf_consts.getPtr(cpi).?.debug_info_first_target_reloc,
8151 .global_debug_info => |gi| &elf.dwarf_globals.items[@backingInt(gi)].debug_info_first_target_reloc,8168 .global_debug_info => |gi| &elf.dwarf_globals.items[@backingInt(gi)].debug_info_first_target_reloc,
8152 .func_debug_info => |fi| &elf.dwarf_funcs.items[@backingInt(fi)].debug_info_first_target_reloc,8169 .func_debug_info => |fi| &elf.dwarf_funcs.items[@backingInt(fi)].debug_info_first_target_reloc,
8170 .decl_debug_info => |di| &elf.dwarf_decls.getPtr(di).?.debug_info_first_target_reloc,
8153 };8171 };
8154 const next = first_target_reloc.*;8172 const next = first_target_reloc.*;
8155 const ri: NodeReloc.Index = @fromBackingInt(@intCast(elf.node_relocs.items.len));8173 const ri: NodeReloc.Index = @fromBackingInt(@intCast(elf.node_relocs.items.len));
...@@ -8260,6 +8278,7 @@ fn addGotRelocAssumeCapacity(...@@ -8260,6 +8278,7 @@ fn addGotRelocAssumeCapacity(
8260 .func_frame_fde,8278 .func_frame_fde,
8261 .func_debug_info,8279 .func_debug_info,
8262 .func_debug_line,8280 .func_debug_line,
8281 .decl_debug_info,
8263 => unreachable, // cannot contain relocs,8282 => unreachable, // cannot contain relocs,
8264 .section,8283 .section,
8265 .section_manual_size,8284 .section_manual_size,
...@@ -8607,7 +8626,10 @@ pub fn updateContainerTypeInner(...@@ -8607,7 +8626,10 @@ pub fn updateContainerTypeInner(
8607) Error!void {8626) Error!void {
8608 switch (elf.base.comp.config.debug_format) {8627 switch (elf.base.comp.config.debug_format) {
8609 .strip => {},8628 .strip => {},
8610 .dwarf => try elf.dwarf.const_pool.updateContainerType(pt, .{ .elf2 = elf }, ty, success),8629 .dwarf => {
8630 try elf.dwarf.const_pool.updateContainerType(pt, .{ .elf2 = elf }, ty, success);
8631 try elf.dwarf.const_pool.flushPending(pt, .{ .elf2 = elf });
8632 },
8611 .code_view => unreachable,8633 .code_view => unreachable,
8612 }8634 }
8613 if (!success) return;8635 if (!success) return;
...@@ -8630,13 +8652,9 @@ pub fn addConst(...@@ -8630,13 +8652,9 @@ pub fn addConst(
8630 .dwarf => {8652 .dwarf => {
8631 const gpa = elf.base.comp.gpa;8653 const gpa = elf.base.comp.gpa;
8632 try elf.nodes.ensureUnusedCapacity(gpa, 1);8654 try elf.nodes.ensureUnusedCapacity(gpa, 1);
8655 try elf.dwarf.consts.ensureUnusedCapacity(gpa, 1);
8633 try elf.dwarf_consts.ensureUnusedCapacity(gpa, 1);8656 try elf.dwarf_consts.ensureUnusedCapacity(gpa, 1);
8634 try elf.dwarf.addConst(cpi, val, &addConstNode);8657 try elf.dwarf.addConst(cpi, val, &addConstNode);
8635 elf.dwarf_consts.putAssumeCapacity(cpi, .{
8636 .debug_info_first_target_reloc = .none,
8637 .debug_info_first_symbol_reloc = .none,
8638 .debug_info_first_node_reloc = .none,
8639 });
8640 },8658 },
8641 .code_view => unreachable,8659 .code_view => unreachable,
8642 }8660 }
...@@ -8644,7 +8662,7 @@ pub fn addConst(...@@ -8644,7 +8662,7 @@ pub fn addConst(
8644fn addConstNode(lf: *link.File, ui: Dwarf.Unit.Index, cpi: link.ConstPool.Index) link.Error!MappedFile.Node.Index {8662fn addConstNode(lf: *link.File, ui: Dwarf.Unit.Index, cpi: link.ConstPool.Index) link.Error!MappedFile.Node.Index {
8645 const elf = lf.cast(.elf2).?;8663 const elf = lf.cast(.elf2).?;
8646 const unit = ui.get(&elf.dwarf);8664 const unit = ui.get(&elf.dwarf);
8647 return elf.addNodeAssumeCapacity(8665 const debug_info_ni = elf.addNodeAssumeCapacity(
8648 unit.debug_info_ni.unwrap().?.addFloatingChild(lf.comp.gpa, &elf.mf, .{8666 unit.debug_info_ni.unwrap().?.addFloatingChild(lf.comp.gpa, &elf.mf, .{
8649 .enable_next_moved = true,8667 .enable_next_moved = true,
8650 }) catch |err| switch (err) {8668 }) catch |err| switch (err) {
...@@ -8655,6 +8673,12 @@ fn addConstNode(lf: *link.File, ui: Dwarf.Unit.Index, cpi: link.ConstPool.Index)...@@ -8655,6 +8673,12 @@ fn addConstNode(lf: *link.File, ui: Dwarf.Unit.Index, cpi: link.ConstPool.Index)
8655 },8673 },
8656 .{ .const_debug_info = cpi },8674 .{ .const_debug_info = cpi },
8657 );8675 );
8676 elf.dwarf_consts.putAssumeCapacityNoClobber(cpi, .{
8677 .debug_info_first_target_reloc = .none,
8678 .debug_info_first_symbol_reloc = .none,
8679 .debug_info_first_node_reloc = .none,
8680 });
8681 return debug_info_ni;
8658}8682}
86598683
8660pub fn updateConst(8684pub fn updateConst(
...@@ -8674,18 +8698,20 @@ fn updateConstInner(...@@ -8674,18 +8698,20 @@ fn updateConstInner(
8674 cpi: link.ConstPool.Index,8698 cpi: link.ConstPool.Index,
8675 val: InternPool.Index,8699 val: InternPool.Index,
8676) link.Error!void {8700) link.Error!void {
8677 if (val == .anyerror_type) return; // handled in `updateErrorData` instead
8678 switch (elf.base.comp.config.debug_format) {8701 switch (elf.base.comp.config.debug_format) {
8679 .strip => {},8702 .strip => {},
8680 .dwarf => {8703 .dwarf => {
8681 const gpa = elf.base.comp.gpa;8704 {
8682 const debug_info_ni = Dwarf.Const.get(cpi, &elf.dwarf).debug_info_ni.unwrap().?;8705 const gpa = elf.base.comp.gpa;
8683 try debug_info_ni.moved(gpa, &elf.mf);8706 const debug_info_ni = Dwarf.Const.get(cpi, &elf.dwarf).debug_info_ni.unwrap().?;
8684 var di_nw: MappedFile.Node.Writer = undefined;8707 try debug_info_ni.moved(gpa, &elf.mf);
8685 debug_info_ni.writer(gpa, &elf.mf, &di_nw);8708 var di_nw: MappedFile.Node.Writer = undefined;
8686 defer di_nw.deinit();8709 debug_info_ni.writer(gpa, &elf.mf, &di_nw);
8687 elf.resetNodeRelocs(debug_info_ni);8710 defer di_nw.deinit();
8688 try elf.dwarf.updateConst(pt, &di_nw, val);8711 elf.resetNodeRelocs(debug_info_ni);
8712 try elf.dwarf.updateConst(pt, &di_nw, val);
8713 }
8714 try elf.genPending(pt);
8689 },8715 },
8690 .code_view => unreachable,8716 .code_view => unreachable,
8691 }8717 }
...@@ -8700,14 +8726,17 @@ pub fn updateConstIncomplete(...@@ -8700,14 +8726,17 @@ pub fn updateConstIncomplete(
8700 switch (elf.base.comp.config.debug_format) {8726 switch (elf.base.comp.config.debug_format) {
8701 .strip => {},8727 .strip => {},
8702 .dwarf => {8728 .dwarf => {
8703 const gpa = elf.base.comp.gpa;8729 {
8704 const debug_info_ni = Dwarf.Const.get(cpi, &elf.dwarf).debug_info_ni.unwrap().?;8730 const gpa = elf.base.comp.gpa;
8705 try debug_info_ni.moved(gpa, &elf.mf);8731 const debug_info_ni = Dwarf.Const.get(cpi, &elf.dwarf).debug_info_ni.unwrap().?;
8706 var di_nw: MappedFile.Node.Writer = undefined;8732 try debug_info_ni.moved(gpa, &elf.mf);
8707 debug_info_ni.writer(gpa, &elf.mf, &di_nw);8733 var di_nw: MappedFile.Node.Writer = undefined;
8708 defer di_nw.deinit();8734 debug_info_ni.writer(gpa, &elf.mf, &di_nw);
8709 elf.resetNodeRelocs(debug_info_ni);8735 defer di_nw.deinit();
8710 try elf.dwarf.updateConstIncomplete(pt, &di_nw, val);8736 elf.resetNodeRelocs(debug_info_ni);
8737 try elf.dwarf.updateConstIncomplete(pt, &di_nw, val);
8738 }
8739 try elf.genPending(pt);
8711 },8740 },
8712 .code_view => unreachable,8741 .code_view => unreachable,
8713 }8742 }
...@@ -8843,7 +8872,9 @@ fn updateFuncInner(...@@ -8843,7 +8872,9 @@ fn updateFuncInner(
8843 debug.blocks = .empty;8872 debug.blocks = .empty;
88448873
8845 const debug_info_ni = dwarf_func.debug_info_ni.unwrap().?;8874 const debug_info_ni = dwarf_func.debug_info_ni.unwrap().?;
8846 try dwarf.decls.put(zcu.comp.gpa, src_inst, debug_info_ni);8875 try dwarf.decls.put(zcu.comp.gpa, src_inst, .{
8876 .debug_info_ni = debug_info_ni.toOptional(),
8877 });
8847 try debug_info_ni.moved(gpa, &elf.mf);8878 try debug_info_ni.moved(gpa, &elf.mf);
8848 try debug_info_ni.nextMoved(gpa, &elf.mf);8879 try debug_info_ni.nextMoved(gpa, &elf.mf);
8849 debug_info_ni.writer(gpa, &elf.mf, &debug.info_writer);8880 debug_info_ni.writer(gpa, &elf.mf, &debug.info_writer);
...@@ -8983,31 +9014,28 @@ pub fn lostTracking(...@@ -8983,31 +9014,28 @@ pub fn lostTracking(
8983 _: Zcu.PerThread,9014 _: Zcu.PerThread,
8984 inst: InternPool.TrackedInst.Index,9015 inst: InternPool.TrackedInst.Index,
8985) link.Error!void {9016) link.Error!void {
8986 const decl_ni = elf.dwarf.decls.get(inst) orelse return;9017 const di = elf.dwarf.getDeclIfExists(inst) orelse return;
9018 const decl_ni = di.get(&elf.dwarf).debug_info_ni.unwrap() orelse return;
8987 const comp = elf.base.comp;9019 const comp = elf.base.comp;
8988 var diw: std.Io.Writer = .fixed(decl_ni.slice(&elf.mf));9020 var diw: std.Io.Writer = .fixed(decl_ni.slice(&elf.mf));
8989 elf.resetNodeRelocs(decl_ni);9021 elf.resetNodeRelocs(decl_ni);
8990 diw.writeUleb128(try elf.dwarf.refAbbrevCode(.decl_lost)) catch unreachable;9022 elf.dwarf.lostTracking(&diw) catch |err| switch (err) {
9023 else => |e| return e,
9024 error.WriteFailed => unreachable,
9025 };
8991 decl_ni.resizeLeaf(comp.gpa, &elf.mf, diw.end) catch |err| switch (err) {9026 decl_ni.resizeLeaf(comp.gpa, &elf.mf, diw.end) catch |err| switch (err) {
9027 else => |e| return e,
8992 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{9028 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{
8993 elf.mf.io_err.?,9029 elf.mf.io_err.?,
8994 }),9030 }),
8995 else => |e| return e,
8996 };9031 };
8997}9032}
89989033
8999pub fn updateErrorData(elf: *Elf, pt: Zcu.PerThread) link.Error!void {9034pub fn updateErrorData(elf: *Elf, pt: Zcu.PerThread) link.Error!void {
9000 const comp = elf.base.comp;9035 if (elf.lazy.getPtr(.const_data).map.getIndex(.anyerror_type)) |lmi| try elf.genLazyInner(pt, .{
9001 if (elf.lazy.getPtr(.const_data).map.getIndex(.anyerror_type)) |lmi| elf.genLazyInner(pt, .{
9002 .kind = .const_data,9036 .kind = .const_data,
9003 .index = @intCast(lmi),9037 .index = @intCast(lmi),
9004 }) catch |err| switch (err) {9038 });
9005 else => |e| return e,
9006 error.MappedFileIo => return comp.link_diags.fail(
9007 "failed to write output file: {t}",
9008 .{elf.mf.io_err.?},
9009 ),
9010 };
9011 if (elf.dwarf.const_pool.getIfExists(.anyerror_type)) |cpi|9039 if (elf.dwarf.const_pool.getIfExists(.anyerror_type)) |cpi|
9012 try elf.updateConstInner(pt, cpi, .anyerror_type);9040 try elf.updateConstInner(pt, cpi, .anyerror_type);
9013}9041}
...@@ -9287,8 +9315,9 @@ fn idleProgNode(...@@ -9287,8 +9315,9 @@ fn idleProgNode(
9287 Value.fromInterned(umi.uavValue(elf)).fmtValue(.{ .zcu = elf.base.comp.zcu.?, .tid = tid }),9315 Value.fromInterned(umi.uavValue(elf)).fmtValue(.{ .zcu = elf.base.comp.zcu.?, .tid = tid }),
9288 }) catch &name,9316 }) catch &name,
9289 .debug_shared => |ss| switch (ss) {9317 .debug_shared => |ss| switch (ss) {
9290 .debug_abbrev, .debug_str, .debug_str_offsets => "debug info",9318 .debug_abbrev => "debug info abbrevs",
9291 .debug_line_str => "line info",9319 .debug_str, .debug_str_offsets => "debug info strings",
9320 .debug_line_str => "line info strings",
9292 },9321 },
9293 .unit_frame,9322 .unit_frame,
9294 .unit_frame_cie,9323 .unit_frame_cie,
...@@ -9330,10 +9359,17 @@ fn idleProgNode(...@@ -9330,10 +9359,17 @@ fn idleProgNode(
9330 ip.getNav(fi.nav(&elf.dwarf)).fqn.fmt(ip),9359 ip.getNav(fi.nav(&elf.dwarf)).fqn.fmt(ip),
9331 }) catch &name;9360 }) catch &name;
9332 },9361 },
9362 .decl_debug_info => |di| {
9363 const comp = elf.base.comp;
9364 const zcu = comp.zcu.?;
9365 break :name std.mem.print(&name, "debug info for {f}", .{
9366 zcu.fileByIndex(di.srcInst(&elf.dwarf).resolveFile(&zcu.intern_pool)).path.fmt(comp),
9367 }) catch &name;
9368 },
9333 }, 0);9369 }, 0);
9334}9370}
93359371
9336fn genPending(elf: *Elf, pt: Zcu.PerThread) Error!void {9372fn genPending(elf: *Elf, pt: Zcu.PerThread) link.Error!void {
9337 while (elf.pending_uavs.pop()) |umi| {9373 while (elf.pending_uavs.pop()) |umi| {
9338 var prog_name_buf: [std.Progress.Node.max_name_len]u8 = undefined;9374 var prog_name_buf: [std.Progress.Node.max_name_len]u8 = undefined;
9339 const prog_name = std.mem.print(&prog_name_buf, "{f}", .{9375 const prog_name = std.mem.print(&prog_name_buf, "{f}", .{
...@@ -9350,7 +9386,20 @@ fn genPending(elf: *Elf, pt: Zcu.PerThread) Error!void {...@@ -9350,7 +9386,20 @@ fn genPending(elf: *Elf, pt: Zcu.PerThread) Error!void {
9350 };9386 };
9351 switch (elf.base.comp.config.debug_format) {9387 switch (elf.base.comp.config.debug_format) {
9352 .strip => {},9388 .strip => {},
9353 .dwarf => try elf.dwarf.const_pool.flushPending(pt, .{ .elf2 = elf }),9389 .dwarf => {
9390 const gpa = elf.base.comp.gpa;
9391 while (elf.dwarf.pending_decl) |pending| {
9392 elf.dwarf.pending_decl = null;
9393 const debug_info_ni = pending.di.get(&elf.dwarf).debug_info_ni.unwrap().?;
9394 try debug_info_ni.moved(gpa, &elf.mf);
9395 var di_nw: MappedFile.Node.Writer = undefined;
9396 debug_info_ni.writer(gpa, &elf.mf, &di_nw);
9397 defer di_nw.deinit();
9398 elf.resetNodeRelocs(debug_info_ni);
9399 try elf.dwarf.genDecl(pt, &di_nw, pending.instance_val);
9400 }
9401 try elf.dwarf.const_pool.flushPending(pt, .{ .elf2 = elf });
9402 },
9354 .code_view => unreachable,9403 .code_view => unreachable,
9355 }9404 }
9356}9405}
...@@ -9359,8 +9408,9 @@ fn genUav(...@@ -9359,8 +9408,9 @@ fn genUav(
9359 elf: *Elf,9408 elf: *Elf,
9360 pt: Zcu.PerThread,9409 pt: Zcu.PerThread,
9361 umi: Node.UavMapIndex,9410 umi: Node.UavMapIndex,
9362) Error!void {9411) link.Error!void {
9363 const gpa = elf.base.comp.gpa;9412 const comp = elf.base.comp;
9413 const gpa = comp.gpa;
93649414
9365 const uav_val = umi.uavValue(elf);9415 const uav_val = umi.uavValue(elf);
9366 const ni = umi.symbol(elf).index().ptr(elf).node.unwrap().?;9416 const ni = umi.symbol(elf).index().ptr(elf).node.unwrap().?;
...@@ -9377,7 +9427,10 @@ fn genUav(...@@ -9377,7 +9427,10 @@ fn genUav(
9377 .{ .atom_index = Node.toAtom(ni) },9427 .{ .atom_index = Node.toAtom(ni) },
9378 ) catch |err| switch (err) {9428 ) catch |err| switch (err) {
9379 else => |e| return e,9429 else => |e| return e,
9380 error.WriteFailed => return nw.err.?,9430 error.WriteFailed => switch (nw.err.?) {
9431 else => |e| return e,
9432 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{elf.mf.io_err.?}),
9433 },
9381 };9434 };
9382 switch (elf.symPtr(umi.symbol(elf).index())) {9435 switch (elf.symPtr(umi.symbol(elf).index())) {
9383 inline else => |sym| elf.targetStore(&sym.size, @intCast(nw.interface.end)),9436 inline else => |sym| elf.targetStore(&sym.size, @intCast(nw.interface.end)),
...@@ -9387,7 +9440,7 @@ fn genUav(...@@ -9387,7 +9440,7 @@ fn genUav(
9387 assert(ni.hasMoved(&elf.mf));9440 assert(ni.hasMoved(&elf.mf));
9388}9441}
93899442
9390fn genLazy(elf: *Elf, pt: Zcu.PerThread, lmr: Node.LazyMapRef) Error!void {9443fn genLazy(elf: *Elf, pt: Zcu.PerThread, lmr: Node.LazyMapRef) link.Error!void {
9391 const lazy = lmr.lazySymbol(elf);9444 const lazy = lmr.lazySymbol(elf);
9392 if (lazy.ty == .anyerror_type) return;9445 if (lazy.ty == .anyerror_type) return;
9393 const lazy_ty: Type = .fromInterned(lazy.ty);9446 const lazy_ty: Type = .fromInterned(lazy.ty);
...@@ -9404,7 +9457,7 @@ fn genLazy(elf: *Elf, pt: Zcu.PerThread, lmr: Node.LazyMapRef) Error!void {...@@ -9404,7 +9457,7 @@ fn genLazy(elf: *Elf, pt: Zcu.PerThread, lmr: Node.LazyMapRef) Error!void {
9404 defer prog_node.end();9457 defer prog_node.end();
9405 try elf.genLazyInner(pt, lmr);9458 try elf.genLazyInner(pt, lmr);
9406}9459}
9407fn genLazyInner(elf: *Elf, pt: Zcu.PerThread, lmr: Node.LazyMapRef) Error!void {9460fn genLazyInner(elf: *Elf, pt: Zcu.PerThread, lmr: Node.LazyMapRef) link.Error!void {
9408 const zcu = pt.zcu;9461 const zcu = pt.zcu;
9409 const gpa = zcu.gpa;9462 const gpa = zcu.gpa;
94109463
...@@ -9430,7 +9483,13 @@ fn genLazyInner(elf: *Elf, pt: Zcu.PerThread, lmr: Node.LazyMapRef) Error!void {...@@ -9430,7 +9483,13 @@ fn genLazyInner(elf: *Elf, pt: Zcu.PerThread, lmr: Node.LazyMapRef) Error!void {
9430 .{ .atom_index = Node.toAtom(ni) },9483 .{ .atom_index = Node.toAtom(ni) },
9431 ) catch |err| switch (err) {9484 ) catch |err| switch (err) {
9432 else => |e| return e,9485 else => |e| return e,
9433 error.WriteFailed => return nw.err.?,9486 error.WriteFailed => return switch (nw.err.?) {
9487 else => |e| return e,
9488 error.MappedFileIo => return elf.base.comp.link_diags.fail(
9489 "failed to write output file: {t}",
9490 .{elf.mf.io_err.?},
9491 ),
9492 },
9434 };9493 };
9435 switch (elf.symPtr(lmr.symbol(elf).index())) {9494 switch (elf.symPtr(lmr.symbol(elf).index())) {
9436 inline else => |sym| elf.targetStore(&sym.size, @intCast(nw.interface.end)),9495 inline else => |sym| elf.targetStore(&sym.size, @intCast(nw.interface.end)),
...@@ -9873,6 +9932,20 @@ fn flushMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!void...@@ -9873,6 +9932,20 @@ fn flushMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!void
9873 .skip_node_relocs = fi.get(&elf.dwarf).debug_info_ni,9932 .skip_node_relocs = fi.get(&elf.dwarf).debug_info_ni,
9874 });9933 });
9875 },9934 },
9935 .decl_debug_info => |di| {
9936 const dwarf_decl = &elf.dwarf_decls.get(di).?;
9937 const target_section_offset = elf.computeNodeSectionOffset(ni);
9938 var target_ri = dwarf_decl.debug_info_first_target_reloc;
9939 while (target_ri != .none) {
9940 const target_reloc = target_ri.get(elf);
9941 assert(target_reloc.target == ni);
9942 target_reloc.flushMovedTarget(elf, target_section_offset);
9943 target_ri = target_reloc.next;
9944 }
9945 elf.flushMovedNodeRelocs(ni, elf.computeNodeVAddr(ni), .{
9946 .first_node_reloc = dwarf_decl.debug_info_first_node_reloc,
9947 });
9948 },
9876 }9949 }
9877 try ni.childrenMoved(elf.base.comp.gpa, &elf.mf);9950 try ni.childrenMoved(elf.base.comp.gpa, &elf.mf);
9878}9951}
...@@ -10124,6 +10197,7 @@ fn flushResized(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo...@@ -10124,6 +10197,7 @@ fn flushResized(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
10124 .func_frame_fde,10197 .func_frame_fde,
10125 .func_debug_info,10198 .func_debug_info,
10126 .func_debug_line,10199 .func_debug_line,
10200 .decl_debug_info,
10127 => {},10201 => {},
10128 }10202 }
10129}10203}
...@@ -10188,6 +10262,7 @@ fn flushNextMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!...@@ -10188,6 +10262,7 @@ fn flushNextMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!
10188 .func_frame_fde,10262 .func_frame_fde,
10189 .func_debug_info,10263 .func_debug_info,
10190 .func_debug_line,10264 .func_debug_line,
10265 .decl_debug_info,
10191 => |_, tag| {10266 => |_, tag| {
10192 const offset, const size = ni.location(&elf.mf).resolve(&elf.mf);10267 const offset, const size = ni.location(&elf.mf).resolve(&elf.mf);
10193 const parent_ni = ni.parent(&elf.mf).unwrap().?;10268 const parent_ni = ni.parent(&elf.mf).unwrap().?;
...@@ -10240,6 +10315,7 @@ fn flushNextMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!...@@ -10240,6 +10315,7 @@ fn flushNextMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!
10240 .global_debug_info,10315 .global_debug_info,
10241 .func_debug_info,10316 .func_debug_info,
10242 .func_debug_line,10317 .func_debug_line,
10318 .decl_debug_info,
10243 => {10319 => {
10244 const parent_offset, _ = parent_ni.location(&elf.mf).resolve(&elf.mf);10320 const parent_offset, _ = parent_ni.location(&elf.mf).resolve(&elf.mf);
10245 const debug_ni = parent_ni.parent(&elf.mf).unwrap().?;10321 const debug_ni = parent_ni.parent(&elf.mf).unwrap().?;
...@@ -10255,6 +10331,7 @@ fn flushNextMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!...@@ -10255,6 +10331,7 @@ fn flushNextMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!
10255 .const_debug_info,10331 .const_debug_info,
10256 .global_debug_info,10332 .global_debug_info,
10257 .func_debug_info,10333 .func_debug_info,
10334 .decl_debug_info,
10258 => for (0..2) |_| fw.writeUleb128(@backingInt(Dwarf.AbbrevCode.null)) catch unreachable,10335 => for (0..2) |_| fw.writeUleb128(@backingInt(Dwarf.AbbrevCode.null)) catch unreachable,
10259 .unit_debug_line_header, .func_debug_line => {},10336 .unit_debug_line_header, .func_debug_line => {},
10260 }10337 }
...@@ -10266,7 +10343,7 @@ fn flushNextMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!...@@ -10266,7 +10343,7 @@ fn flushNextMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!
10266 elf.dwarf.updateUnitLength(fw.buffer, fw.buffer.len);10343 elf.dwarf.updateUnitLength(fw.buffer, fw.buffer.len);
10267 switch (tag) {10344 switch (tag) {
10268 else => unreachable,10345 else => unreachable,
10269 .unit_debug_info_header, .const_debug_info, .global_debug_info, .func_debug_info => {10346 .unit_debug_info_header, .const_debug_info, .global_debug_info, .func_debug_info, .decl_debug_info => {
10270 comptime assert(Dwarf.uleb128Size(@backingInt(Dwarf.AbbrevCode.null)) == 1);10347 comptime assert(Dwarf.uleb128Size(@backingInt(Dwarf.AbbrevCode.null)) == 1);
10271 @memset(fw.unusedCapacitySlice(), @backingInt(Dwarf.AbbrevCode.null));10348 @memset(fw.unusedCapacitySlice(), @backingInt(Dwarf.AbbrevCode.null));
10272 },10349 },
...@@ -10293,6 +10370,7 @@ fn flushNextMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!...@@ -10293,6 +10370,7 @@ fn flushNextMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!
10293 .const_debug_info,10370 .const_debug_info,
10294 .global_debug_info,10371 .global_debug_info,
10295 .func_debug_info,10372 .func_debug_info,
10373 .decl_debug_info,
10296 => elf.dwarf.genDebugInfoPadding(&fw, fw.buffer.len) catch unreachable,10374 => elf.dwarf.genDebugInfoPadding(&fw, fw.buffer.len) catch unreachable,
10297 .unit_debug_line_header,10375 .unit_debug_line_header,
10298 .func_debug_line,10376 .func_debug_line,
...@@ -10864,6 +10942,18 @@ pub fn printNode(...@@ -10864,6 +10942,18 @@ pub fn printNode(
10864 nav.fqn.fmt(ip),10942 nav.fqn.fmt(ip),
10865 });10943 });
10866 },10944 },
10945 .decl_debug_info => |di| {
10946 const comp = elf.base.comp;
10947 const zcu = comp.zcu.?;
10948 const ip = &zcu.intern_pool;
10949 const src_inst = di.srcInst(&elf.dwarf);
10950 try w.print("({f}, ", .{zcu.fileByIndex(src_inst.resolveFile(ip)).path.fmt(comp)});
10951 if (src_inst.resolve(ip)) |inst|
10952 try w.print("%{d}", .{inst})
10953 else
10954 try w.writeAll("lost");
10955 try w.writeByte(')');
10956 },
10867 }10957 }
10868 {10958 {
10869 const mf_node = &elf.mf.nodes.items[@backingInt(ni)];10959 const mf_node = &elf.mf.nodes.items[@backingInt(ni)];