authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-09-06 16:05:38-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-09-07 16:11:00-04:00
logefa11ce196bc1c60b34b41ab8b14be23825b45dc
tree4f9ef6288c9d3d9750d2f9f9cb12a5bbae799f22
parent4582acf585911b4391b909e5bbe7dd635801477b

Dwarf2: implement generic decls


3 files changed, 142 insertions(+), 156 deletions(-)

src/link/Dwarf2.zig+136-154
...@@ -1395,8 +1395,7 @@ pub fn getConst(dwarf: *Dwarf, pt: Zcu.PerThread, val: Value) link.Error!link.Co...@@ -1395,8 +1395,7 @@ pub fn getConst(dwarf: *Dwarf, pt: Zcu.PerThread, val: Value) link.Error!link.Co
13951395
1396pub fn getGlobal(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Global.Index {1396pub fn getGlobal(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Global.Index {
1397 const comp = dwarf.lf.comp;1397 const comp = dwarf.lf.comp;
1398 const gpa = comp.gpa;1398 const global_gop = try dwarf.globals.getOrPut(comp.gpa, nav);
1399 const global_gop = try dwarf.globals.getOrPut(gpa, nav);
1400 if (!global_gop.found_existing) global_gop.value_ptr.* = .{1399 if (!global_gop.found_existing) global_gop.value_ptr.* = .{
1401 .debug_info_ni = .none,1400 .debug_info_ni = .none,
1402 };1401 };
...@@ -1405,15 +1404,15 @@ pub fn getGlobal(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Global.Ind...@@ -1405,15 +1404,15 @@ pub fn getGlobal(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Global.Ind
1405 const mod = comp.zcu.?.navFileScope(nav).mod.?;1404 const mod = comp.zcu.?.navFileScope(nav).mod.?;
1406 assert(!mod.strip);1405 assert(!mod.strip);
1407 if (dwarf.lf.cast(.elf2)) |elf| {1406 if (dwarf.lf.cast(.elf2)) |elf| {
1408 try elf.nodes.ensureUnusedCapacity(gpa, 1);1407 try elf.nodes.ensureUnusedCapacity(comp.gpa, 1);
1409 try elf.dwarf_globals.append(gpa, .{1408 try elf.dwarf_globals.append(comp.gpa, .{
1410 .debug_info_first_target_reloc = .none,1409 .debug_info_first_target_reloc = .none,
1411 .debug_info_first_node_reloc = .none,1410 .debug_info_first_node_reloc = .none,
1412 .debug_info_first_symbol_reloc = .none,1411 .debug_info_first_symbol_reloc = .none,
1413 });1412 });
1414 const unit = dwarf.getUnit(mod).get(dwarf);1413 const unit = dwarf.getUnit(mod).get(dwarf);
1415 global_gop.value_ptr.debug_info_ni = .wrap(elf.addNodeAssumeCapacity(1414 global_gop.value_ptr.debug_info_ni = .wrap(elf.addNodeAssumeCapacity(
1416 unit.debug_info_ni.unwrap().?.addFloatingChild(gpa, &elf.mf, .{1415 unit.debug_info_ni.unwrap().?.addFloatingChild(comp.gpa, &elf.mf, .{
1417 .enable_next_moved = true,1416 .enable_next_moved = true,
1418 }) catch |err| switch (err) {1417 }) catch |err| switch (err) {
1419 else => |e| return e,1418 else => |e| return e,
...@@ -1983,7 +1982,7 @@ pub fn updateComptimeGlobal(...@@ -1983,7 +1982,7 @@ pub fn updateComptimeGlobal(
1983 .unnamed_test, .@"test", .decltest => return,1982 .unnamed_test, .@"test", .decltest => return,
1984 .@"comptime", .@"const", .@"var" => {},1983 .@"comptime", .@"const", .@"var" => {},
1985 }1984 }
1986 done: switch (ip.indexToKey(nav_val.toIntern())) {1985 switch (ip.indexToKey(nav_val.toIntern())) {
1987 .int_type,1986 .int_type,
1988 .ptr_type,1987 .ptr_type,
1989 .array_type,1988 .array_type,
...@@ -1997,35 +1996,6 @@ pub fn updateComptimeGlobal(...@@ -1997,35 +1996,6 @@ pub fn updateComptimeGlobal(
1997 .error_set_type,1996 .error_set_type,
1998 .inferred_error_set_type,1997 .inferred_error_set_type,
1999 .spirv_type,1998 .spirv_type,
2000 => try dwarf.genDeclType(pt, global, &decl),
2001 .struct_type => {
2002 const loaded_struct = ip.loadStructType(nav_val.toIntern());
2003 if (global.toOptional() == loaded_struct.name_nav)
2004 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern())
2005 else
2006 try dwarf.genDeclType(pt, global, &decl);
2007 },
2008 .enum_type => {
2009 const loaded_enum = ip.loadEnumType(nav_val.toIntern());
2010 if (global.toOptional() == loaded_enum.name_nav)
2011 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern())
2012 else
2013 try dwarf.genDeclType(pt, global, &decl);
2014 },
2015 .union_type => {
2016 const loaded_union = ip.loadUnionType(nav_val.toIntern());
2017 if (global.toOptional() == loaded_union.name_nav)
2018 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern())
2019 else
2020 try dwarf.genDeclType(pt, global, &decl);
2021 },
2022 .opaque_type => {
2023 const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern());
2024 if (global.toOptional() == loaded_opaque.name_nav)
2025 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern())
2026 else
2027 try dwarf.genDeclType(pt, global, &decl);
2028 },
2029 .undef,1999 .undef,
2030 .simple_value,2000 .simple_value,
2031 .int,2001 .int,
...@@ -2040,18 +2010,39 @@ pub fn updateComptimeGlobal(...@@ -2040,18 +2010,39 @@ pub fn updateComptimeGlobal(
2040 .aggregate,2010 .aggregate,
2041 .un,2011 .un,
2042 .bitpack,2012 .bitpack,
2043 => try dwarf.genDeclGlobal(pt, global, &decl),2013 => try dwarf.genGlobal(pt, global, &decl),
2014 .struct_type => {
2015 const loaded_struct = ip.loadStructType(nav_val.toIntern());
2016 if (global.toOptional() == loaded_struct.name_nav) {
2017 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
2018 } else try dwarf.genGlobal(pt, global, &decl);
2019 },
2020 .enum_type => {
2021 const loaded_enum = ip.loadEnumType(nav_val.toIntern());
2022 if (global.toOptional() == loaded_enum.name_nav) {
2023 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
2024 } else try dwarf.genGlobal(pt, global, &decl);
2025 },
2026 .union_type => {
2027 const loaded_union = ip.loadUnionType(nav_val.toIntern());
2028 if (global.toOptional() == loaded_union.name_nav) {
2029 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
2030 } else try dwarf.genGlobal(pt, global, &decl);
2031 },
2032 .opaque_type => {
2033 const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern());
2034 if (global.toOptional() == loaded_opaque.name_nav) {
2035 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
2036 } else try dwarf.genGlobal(pt, global, &decl);
2037 },
2044 .@"extern" => unreachable,2038 .@"extern" => unreachable,
2045 .func => |func| if (func.owner_nav == global and func.generic_owner == .none) {2039 .func => |func| if (func.owner_nav == global and func.generic_owner == .none) {
2046 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());2040 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
2047 break :done;
2048 } else return,2041 } else return,
2049 // memoization, not values2042 .memoized_call => unreachable, // not a value
2050 .memoized_call => unreachable,
2051 }2043 }
2052}2044}
20532045fn genGlobal(
2054fn genDeclType(
2055 dwarf: *Dwarf,2046 dwarf: *Dwarf,
2056 pt: Zcu.PerThread,2047 pt: Zcu.PerThread,
2057 global: InternPool.Nav.Index,2048 global: InternPool.Nav.Index,
...@@ -2065,12 +2056,12 @@ fn genDeclType(...@@ -2065,12 +2056,12 @@ fn genDeclType(
2065 elf.resetNodeRelocs(debug_info_ni);2056 elf.resetNodeRelocs(debug_info_ni);
2066 } else unreachable;2057 } else unreachable;
2067 defer di_nw.deinit();2058 defer di_nw.deinit();
2068 dwarf.genDeclTypeInner(pt, &di_nw, global, decl) catch |err| switch (err) {2059 dwarf.genGlobalInner(pt, &di_nw, global, decl) catch |err| switch (err) {
2069 error.WriteFailed => return dwarf.reportWriteError(&di_nw),2060 error.WriteFailed => return dwarf.reportWriteError(&di_nw),
2070 else => |e| return e,2061 else => |e| return e,
2071 };2062 };
2072}2063}
2073fn genDeclTypeInner(2064fn genGlobalInner(
2074 dwarf: *Dwarf,2065 dwarf: *Dwarf,
2075 pt: Zcu.PerThread,2066 pt: Zcu.PerThread,
2076 di_nw: *link.MappedFile.Node.Writer,2067 di_nw: *link.MappedFile.Node.Writer,
...@@ -2080,94 +2071,70 @@ fn genDeclTypeInner(...@@ -2080,94 +2071,70 @@ fn genDeclTypeInner(
2080 const zcu = pt.zcu;2071 const zcu = pt.zcu;
2081 const ip = &zcu.intern_pool;2072 const ip = &zcu.intern_pool;
2082 const nav = ip.getNav(global);2073 const nav = ip.getNav(global);
2074 const nav_const, const nav_ty: Type, const nav_align, const nav_val: Value = nav_resolved: {
2075 const nav_resolved = nav.resolved.?;
2076 break :nav_resolved .{
2077 nav_resolved.@"const",
2078 .fromInterned(nav_resolved.type),
2079 nav_resolved.@"align",
2080 .fromInterned(nav_resolved.value),
2081 };
2082 };
2083 const nav_class = nav_ty.classify(zcu);
2083 const parent_ty = ip.namespacePtr(nav.analysis.?.namespace).owner_type;2084 const parent_ty = ip.namespacePtr(nav.analysis.?.namespace).owner_type;
2084 const di_w = &di_nw.interface;2085 const di_w = &di_nw.interface;
2085 if (Type.fromInterned(parent_ty).getCaptures(zcu).len > 0) {2086 if (Type.fromInterned(parent_ty).getCaptures(zcu).len > 0) {
2086 try dwarf.abbrevCode(di_nw, .decl_instance_type);2087 try dwarf.abbrevCode(di_nw, switch (nav_ty.toIntern()) {
2088 .type_type => .decl_instance_type,
2089 else => if (nav_const) switch (nav_class) {
2090 .no_possible_value, .one_possible_value => .decl_instance_const,
2091 .runtime => .decl_instance_const_fully_runtime,
2092 .partially_comptime => .decl_instance_const_partially_comptime,
2093 .fully_comptime => .decl_instance_const_fully_comptime,
2094 } else .decl_instance_var,
2095 });
2087 try dwarf.refType(pt, di_nw, .fromInterned(parent_ty));2096 try dwarf.refType(pt, di_nw, .fromInterned(parent_ty));
2088 try dwarf.secOffset(di_nw, try dwarf.getGlobalDecl(pt, global), 0);2097 try dwarf.secOffset(di_nw, try dwarf.getGlobalDecl(pt, global), 0);
2089 } else {2098 } else {
2090 const parent_ni = try dwarf.getConstDecl(pt, parent_ty);2099 const parent_ni = try dwarf.getConstDecl(pt, parent_ty);
2091 try dwarf.abbrevCode(di_nw, .decl_type);2100 try dwarf.abbrevCode(di_nw, switch (nav_ty.toIntern()) {
2101 .type_type => .decl_type,
2102 else => if (nav_const) switch (nav_class) {
2103 .no_possible_value, .one_possible_value => .decl_const,
2104 .runtime => .decl_const_fully_runtime,
2105 .partially_comptime => .decl_const_partially_comptime,
2106 .fully_comptime => .decl_const_fully_comptime,
2107 } else .decl_var,
2108 });
2092 try dwarf.secOffset(di_nw, parent_ni, 0);2109 try dwarf.secOffset(di_nw, parent_ni, 0);
2093 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);2110 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
2094 try di_w.writeUleb128(decl.src_column + 1);2111 try di_w.writeUleb128(decl.src_column + 1);
2095 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);2112 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2096 try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip));2113 try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip));
2097 }2114 }
2098 try dwarf.refConst(pt, di_nw, .fromInterned(nav.resolved.?.value));2115 switch (nav_ty.toIntern()) {
2099 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());2116 .type_type => try dwarf.refConst(pt, di_nw, nav_val),
2100}2117 else => {
21012118 try dwarf.strp(&dwarf.debug_str, di_nw, switch (decl.linkage) {
2102fn genDeclGlobal(2119 .normal => nav.fqn,
2103 dwarf: *Dwarf,2120 .@"extern", .@"export" => nav.name,
2104 pt: Zcu.PerThread,2121 }.toSlice(ip));
2105 global: InternPool.Nav.Index,2122 const type_offset = di_w.end;
2106 decl: *const std.zig.Zir.Inst.Declaration.Unwrapped,2123 if (nav_const) try dwarf.secOffsetPlaceholder(di_w) else {
2107) link.Error!void {2124 try dwarf.refType(pt, di_nw, nav_ty);
2108 const gi = try dwarf.getGlobal(global);2125 try dwarf.blockConst(pt, di_nw, nav_val);
2109 const debug_info_ni = gi.get(dwarf).debug_info_ni.unwrap().?;2126 }
2110 var di_nw: link.MappedFile.Node.Writer = undefined;2127 try di_w.writeUleb128(nav_align.toByteUnits() orelse
2111 if (dwarf.lf.cast(.elf2)) |elf| {2128 nav_ty.abiAlignment(zcu).toByteUnits().?);
2112 debug_info_ni.writer(pt.zcu.gpa, &elf.mf, &di_nw);2129 try di_w.writeByte(@intFromBool(decl.linkage != .normal));
2113 elf.resetNodeRelocs(debug_info_ni);2130 if (nav_const) {
2114 } else unreachable;2131 if (nav_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, nav_val);
2115 defer di_nw.deinit();2132 if (nav_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, nav_val);
2116 dwarf.genDeclGlobalInner(pt, &di_nw, global, decl) catch |err| switch (err) {2133 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
2117 error.WriteFailed => return dwarf.reportWriteError(&di_nw),2134 try dwarf.abbrevCode(di_nw, .is_const);
2118 else => |e| return e,2135 try dwarf.refType(pt, di_nw, nav_ty);
2119 };2136 }
2120}2137 },
2121fn genDeclGlobalInner(
2122 dwarf: *Dwarf,
2123 pt: Zcu.PerThread,
2124 di_nw: *link.MappedFile.Node.Writer,
2125 global: InternPool.Nav.Index,
2126 decl: *const std.zig.Zir.Inst.Declaration.Unwrapped,
2127) link.EmitError!void {
2128 const zcu = pt.zcu;
2129 const ip = &zcu.intern_pool;
2130 const nav = ip.getNav(global);
2131 const nav_const, const nav_ty: Type, const nav_align, const nav_val: Value = resolved: {
2132 const resolved = nav.resolved.?;
2133 break :resolved .{
2134 resolved.@"const",
2135 .fromInterned(resolved.type),
2136 resolved.@"align",
2137 .fromInterned(resolved.value),
2138 };
2139 };
2140 const nav_class = nav_ty.classify(zcu);
2141 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(nav.analysis.?.namespace).owner_type);
2142 const di_w = &di_nw.interface;
2143 try dwarf.abbrevCode(di_nw, if (nav_const) switch (nav_class) {
2144 .no_possible_value, .one_possible_value => .decl_const,
2145 .runtime => .decl_const_fully_runtime,
2146 .partially_comptime => .decl_const_partially_comptime,
2147 .fully_comptime => .decl_const_fully_comptime,
2148 } else .decl_var);
2149 try dwarf.secOffset(di_nw, parent_ni, 0);
2150 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
2151 try di_w.writeUleb128(decl.src_column + 1);
2152 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2153 try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip));
2154 try dwarf.strp(&dwarf.debug_str, di_nw, switch (decl.linkage) {
2155 .normal => nav.fqn,
2156 .@"extern", .@"export" => nav.name,
2157 }.toSlice(ip));
2158 const type_offset = di_w.end;
2159 if (nav_const) try dwarf.secOffsetPlaceholder(di_w) else {
2160 try dwarf.refType(pt, di_nw, nav_ty);
2161 try dwarf.blockConst(pt, di_nw, nav_val);
2162 }
2163 try di_w.writeUleb128(nav_align.toByteUnits() orelse nav_ty.abiAlignment(zcu).toByteUnits().?);
2164 try di_w.writeByte(@intFromBool(decl.linkage != .normal));
2165 if (nav_const) {
2166 if (nav_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, nav_val);
2167 if (nav_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, nav_val);
2168 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
2169 try dwarf.abbrevCode(di_nw, .is_const);
2170 try dwarf.refType(pt, di_nw, nav_ty);
2171 }2138 }
2172 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());2139 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());
2173}2140}
...@@ -2617,6 +2584,9 @@ fn updateConstInner(...@@ -2617,6 +2584,9 @@ fn updateConstInner(
2617 .auto, .@"extern" => .decl_instance_empty_struct,2584 .auto, .@"extern" => .decl_instance_empty_struct,
2618 .@"packed" => .decl_instance_empty_packed_struct,2585 .@"packed" => .decl_instance_empty_packed_struct,
2619 });2586 });
2587 try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr(
2588 ip.namespacePtr(loaded_struct.namespace).parent.unwrap().?,
2589 ).owner_type));
2620 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, val), 0);2590 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, val), 0);
2621 } else if (loaded_struct.name_nav.unwrap()) |name_ni| {2591 } else if (loaded_struct.name_nav.unwrap()) |name_ni| {
2622 const name_nav = ip.getNav(name_ni);2592 const name_nav = ip.getNav(name_ni);
...@@ -2750,6 +2720,9 @@ fn updateConstInner(...@@ -2750,6 +2720,9 @@ fn updateConstInner(
2750 .auto, .@"extern" => .decl_instance_empty_union,2720 .auto, .@"extern" => .decl_instance_empty_union,
2751 .@"packed" => .decl_instance_empty_packed_union,2721 .@"packed" => .decl_instance_empty_packed_union,
2752 });2722 });
2723 try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr(
2724 ip.namespacePtr(loaded_union.namespace).parent.unwrap().?,
2725 ).owner_type));
2753 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, val), 0);2726 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, val), 0);
2754 } else if (loaded_union.name_nav.unwrap()) |name_ni| {2727 } else if (loaded_union.name_nav.unwrap()) |name_ni| {
2755 const name_nav = ip.getNav(name_ni);2728 const name_nav = ip.getNav(name_ni);
...@@ -2883,6 +2856,9 @@ fn updateConstInner(...@@ -2883,6 +2856,9 @@ fn updateConstInner(
2883 .decl_instance_enum2856 .decl_instance_enum
2884 else2857 else
2885 .decl_instance_empty_enum);2858 .decl_instance_empty_enum);
2859 try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr(
2860 ip.namespacePtr(loaded_enum.namespace).parent.unwrap().?,
2861 ).owner_type));
2886 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, val), 0);2862 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, val), 0);
2887 } else if (loaded_enum.name_nav.unwrap()) |name_ni| {2863 } else if (loaded_enum.name_nav.unwrap()) |name_ni| {
2888 const name_nav = ip.getNav(name_ni);2864 const name_nav = ip.getNav(name_ni);
...@@ -3297,6 +3273,9 @@ fn updateConstIncompleteInner(...@@ -3297,6 +3273,9 @@ fn updateConstIncompleteInner(
3297 .@"union" => .decl_instance_empty_incomplete_union,3273 .@"union" => .decl_instance_empty_incomplete_union,
3298 .@"enum" => .decl_instance_empty_incomplete_enum,3274 .@"enum" => .decl_instance_empty_incomplete_enum,
3299 });3275 });
3276 try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr(
3277 ip.namespacePtr(namespace).parent.unwrap().?,
3278 ).owner_type));
3300 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, val), 0);3279 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, val), 0);
3301 } else if (maybe_name_nav.unwrap()) |name_ni| {3280 } else if (maybe_name_nav.unwrap()) |name_ni| {
3302 const name_nav = ip.getNav(name_ni);3281 const name_nav = ip.getNav(name_ni);
...@@ -3625,15 +3604,19 @@ fn genDeclInner(...@@ -3625,15 +3604,19 @@ fn genDeclInner(
3625 },3604 },
3626 .global => |global| {3605 .global => |global| {
3627 const nav = ip.getNav(global);3606 const nav = ip.getNav(global);
3607 const nav_const, const nav_ty = nav_resolved: {
3608 const nav_resolved = nav.resolved.?;
3609 break :nav_resolved .{ nav_resolved.@"const", nav_resolved.type };
3610 };
3628 const src_inst = nav.srcInst(ip).resolveFull(ip).?;3611 const src_inst = nav.srcInst(ip).resolveFull(ip).?;
3629 const decl = zcu.fileByIndex(src_inst.file).zir.?.getDeclaration(src_inst.inst);3612 const decl = zcu.fileByIndex(src_inst.file).zir.?.getDeclaration(src_inst.inst);
3630 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(3613 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
3631 nav.analysis.?.namespace,3614 nav.analysis.?.namespace,
3632 ).owner_type);3615 ).owner_type);
3633 try dwarf.abbrevCode(di_nw, if (nav.resolved.?.@"const") switch (nav.resolved.?.type) {3616 try dwarf.abbrevCode(di_nw, switch (nav_ty) {
3634 .type_type => .decl_specification_type,3617 .type_type => .decl_specification_type,
3635 else => .decl_specification_const,3618 else => if (nav_const) .decl_specification_const else .decl_specification_var,
3636 } else .decl_specification_var);3619 });
3637 try dwarf.secOffset(di_nw, parent_ni, 0);3620 try dwarf.secOffset(di_nw, parent_ni, 0);
3638 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);3621 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
3639 try di_w.writeUleb128(decl.src_column + 1);3622 try di_w.writeUleb128(decl.src_column + 1);
...@@ -4003,7 +3986,6 @@ pub const AbbrevCode = enum {...@@ -4003,7 +3986,6 @@ pub const AbbrevCode = enum {
4003 decl_specification_const,3986 decl_specification_const,
4004 decl_specification_var,3987 decl_specification_var,
4005 decl_specification_func,3988 decl_specification_func,
4006 decl_instance_type,
4007 decl_instance_empty_incomplete_enum,3989 decl_instance_empty_incomplete_enum,
4008 decl_instance_incomplete_enum,3990 decl_instance_incomplete_enum,
4009 decl_instance_empty_enum,3991 decl_instance_empty_enum,
...@@ -4020,11 +4002,12 @@ pub const AbbrevCode = enum {...@@ -4020,11 +4002,12 @@ pub const AbbrevCode = enum {
4020 decl_instance_union,4002 decl_instance_union,
4021 decl_instance_empty_packed_union,4003 decl_instance_empty_packed_union,
4022 decl_instance_packed_union,4004 decl_instance_packed_union,
4023 decl_instance_var,4005 decl_instance_type,
4024 decl_instance_const,4006 decl_instance_const,
4025 decl_instance_const_runtime_bits,4007 decl_instance_const_fully_runtime,
4026 decl_instance_const_comptime_state,4008 decl_instance_const_partially_comptime,
4027 decl_instance_const_runtime_bits_comptime_state,4009 decl_instance_const_fully_comptime,
4010 decl_instance_var,
4028 decl_instance_empty_func,4011 decl_instance_empty_func,
4029 decl_instance_func,4012 decl_instance_func,
4030 decl_instance_empty_func_generic,4013 decl_instance_empty_func_generic,
...@@ -4149,6 +4132,7 @@ pub const AbbrevCode = enum {...@@ -4149,6 +4132,7 @@ pub const AbbrevCode = enum {
4149 .{ .declaration, .flag_present },4132 .{ .declaration, .flag_present },
4150 };4133 };
4151 const decl_instance_attrs = &[_]Attr{4134 const decl_instance_attrs = &[_]Attr{
4135 .{ .ZIG_parent, .ref_addr },
4152 .{ .specification, .ref_addr },4136 .{ .specification, .ref_addr },
4153 };4137 };
41544138
...@@ -4368,16 +4352,6 @@ pub const AbbrevCode = enum {...@@ -4368,16 +4352,6 @@ pub const AbbrevCode = enum {
4368 .{ .import, .ref_addr },4352 .{ .import, .ref_addr },
4369 },4353 },
4370 },4354 },
4371 .decl_var = .{
4372 .tag = .variable,
4373 .attrs = decl_attrs ++ .{
4374 .{ .linkage_name, .strp },
4375 .{ .type, .ref_addr },
4376 .{ .location, .exprloc },
4377 .{ .alignment, .udata },
4378 .{ .external, .flag },
4379 },
4380 },
4381 .decl_const = .{4355 .decl_const = .{
4382 .tag = .constant,4356 .tag = .constant,
4383 .attrs = decl_attrs ++ .{4357 .attrs = decl_attrs ++ .{
...@@ -4418,6 +4392,16 @@ pub const AbbrevCode = enum {...@@ -4418,6 +4392,16 @@ pub const AbbrevCode = enum {
4418 .{ .ZIG_comptime_value, .ref_addr },4392 .{ .ZIG_comptime_value, .ref_addr },
4419 },4393 },
4420 },4394 },
4395 .decl_var = .{
4396 .tag = .variable,
4397 .attrs = decl_attrs ++ .{
4398 .{ .linkage_name, .strp },
4399 .{ .type, .ref_addr },
4400 .{ .location, .exprloc },
4401 .{ .alignment, .udata },
4402 .{ .external, .flag },
4403 },
4404 },
4421 .decl_empty_func = .{4405 .decl_empty_func = .{
4422 .tag = .subprogram,4406 .tag = .subprogram,
4423 .attrs = decl_attrs ++ .{4407 .attrs = decl_attrs ++ .{
...@@ -4547,14 +4531,6 @@ pub const AbbrevCode = enum {...@@ -4547,14 +4531,6 @@ pub const AbbrevCode = enum {
4547 .tag = .subprogram,4531 .tag = .subprogram,
4548 .attrs = decl_specification_attrs,4532 .attrs = decl_specification_attrs,
4549 },4533 },
4550 .decl_instance_type = .{
4551 .tag = .imported_declaration,
4552 .attrs = .{
4553 .{ .ZIG_parent, .ref_addr },
4554 } ++ decl_instance_attrs ++ .{
4555 .{ .import, .ref_addr },
4556 },
4557 },
4558 .decl_instance_empty_incomplete_enum = .{4534 .decl_instance_empty_incomplete_enum = .{
4559 .tag = .enumeration_type,4535 .tag = .enumeration_type,
4560 .attrs = decl_instance_attrs,4536 .attrs = decl_instance_attrs,
...@@ -4651,26 +4627,32 @@ pub const AbbrevCode = enum {...@@ -4651,26 +4627,32 @@ pub const AbbrevCode = enum {
4651 .{ .type, .ref_addr },4627 .{ .type, .ref_addr },
4652 },4628 },
4653 },4629 },
4654 .decl_instance_var = .{4630 .decl_instance_type = .{
4655 .tag = .variable,4631 .tag = .imported_declaration,
4632 .attrs = decl_instance_attrs ++ .{
4633 .{ .import, .ref_addr },
4634 },
4635 },
4636 .decl_instance_const = .{
4637 .tag = .constant,
4656 .attrs = decl_instance_attrs ++ .{4638 .attrs = decl_instance_attrs ++ .{
4657 .{ .linkage_name, .strp },4639 .{ .linkage_name, .strp },
4658 .{ .type, .ref_addr },4640 .{ .type, .ref_addr },
4659 .{ .location, .exprloc },
4660 .{ .alignment, .udata },4641 .{ .alignment, .udata },
4661 .{ .external, .flag },4642 .{ .external, .flag },
4662 },4643 },
4663 },4644 },
4664 .decl_instance_const = .{4645 .decl_instance_const_fully_runtime = .{
4665 .tag = .constant,4646 .tag = .constant,
4666 .attrs = decl_instance_attrs ++ .{4647 .attrs = decl_instance_attrs ++ .{
4667 .{ .linkage_name, .strp },4648 .{ .linkage_name, .strp },
4668 .{ .type, .ref_addr },4649 .{ .type, .ref_addr },
4669 .{ .alignment, .udata },4650 .{ .alignment, .udata },
4670 .{ .external, .flag },4651 .{ .external, .flag },
4652 .{ .const_value, .block },
4671 },4653 },
4672 },4654 },
4673 .decl_instance_const_runtime_bits = .{4655 .decl_instance_const_partially_comptime = .{
4674 .tag = .constant,4656 .tag = .constant,
4675 .attrs = decl_instance_attrs ++ .{4657 .attrs = decl_instance_attrs ++ .{
4676 .{ .linkage_name, .strp },4658 .{ .linkage_name, .strp },
...@@ -4678,9 +4660,10 @@ pub const AbbrevCode = enum {...@@ -4678,9 +4660,10 @@ pub const AbbrevCode = enum {
4678 .{ .alignment, .udata },4660 .{ .alignment, .udata },
4679 .{ .external, .flag },4661 .{ .external, .flag },
4680 .{ .const_value, .block },4662 .{ .const_value, .block },
4663 .{ .ZIG_comptime_value, .ref_addr },
4681 },4664 },
4682 },4665 },
4683 .decl_instance_const_comptime_state = .{4666 .decl_instance_const_fully_comptime = .{
4684 .tag = .constant,4667 .tag = .constant,
4685 .attrs = decl_instance_attrs ++ .{4668 .attrs = decl_instance_attrs ++ .{
4686 .{ .linkage_name, .strp },4669 .{ .linkage_name, .strp },
...@@ -4690,15 +4673,14 @@ pub const AbbrevCode = enum {...@@ -4690,15 +4673,14 @@ pub const AbbrevCode = enum {
4690 .{ .ZIG_comptime_value, .ref_addr },4673 .{ .ZIG_comptime_value, .ref_addr },
4691 },4674 },
4692 },4675 },
4693 .decl_instance_const_runtime_bits_comptime_state = .{4676 .decl_instance_var = .{
4694 .tag = .constant,4677 .tag = .variable,
4695 .attrs = decl_instance_attrs ++ .{4678 .attrs = decl_instance_attrs ++ .{
4696 .{ .linkage_name, .strp },4679 .{ .linkage_name, .strp },
4697 .{ .type, .ref_addr },4680 .{ .type, .ref_addr },
4681 .{ .location, .exprloc },
4698 .{ .alignment, .udata },4682 .{ .alignment, .udata },
4699 .{ .external, .flag },4683 .{ .external, .flag },
4700 .{ .const_value, .block },
4701 .{ .ZIG_comptime_value, .ref_addr },
4702 },4684 },
4703 },4685 },
4704 .decl_instance_empty_func = .{4686 .decl_instance_empty_func = .{
src/link/Elf2.zig+5-1
...@@ -11041,7 +11041,11 @@ pub fn printNode(...@@ -11041,7 +11041,11 @@ pub fn printNode(
11041 if (nav.resolved) |resolved| try w.print("{f}, ", .{11041 if (nav.resolved) |resolved| try w.print("{f}, ", .{
11042 Type.fromInterned(resolved.type).fmt(.{ .zcu = zcu, .tid = tid }),11042 Type.fromInterned(resolved.type).fmt(.{ .zcu = zcu, .tid = tid }),
11043 });11043 });
11044 try w.print("{f})", .{nav.fqn.fmt(ip)});11044 try w.print("{f}", .{nav.fqn.fmt(ip)});
11045 if (nav.resolved) |resolved| try w.print(", {f}", .{
11046 Value.fromInterned(resolved.value).fmtValue(.{ .zcu = zcu, .tid = tid }),
11047 });
11048 try w.writeByte(')');
11045 },11049 },
11046 .func_frame_fde, .func_debug_info, .func_debug_line => |fi| {11050 .func_frame_fde, .func_debug_info, .func_debug_line => |fi| {
11047 const zcu = elf.base.comp.zcu.?;11051 const zcu = elf.base.comp.zcu.?;
test/src/Debugger.zig+1-1
...@@ -2054,7 +2054,7 @@ pub fn addTests(db: *Debugger) void {...@@ -2054,7 +2054,7 @@ pub fn addTests(db: *Debugger) void {
2054 \\(lldb) breakpoint delete --force 12054 \\(lldb) breakpoint delete --force 1
2055 \\1 breakpoints deleted; 0 breakpoint locations disabled.2055 \\1 breakpoints deleted; 0 breakpoint locations disabled.
2056 },2056 },
2057 .{ .skip_new_linker = true },2057 .{},
2058 );2058 );
2059 db.addLldbTest(2059 db.addLldbTest(
2060 "multi_array_list",2060 "multi_array_list",