| ... | ... | @@ -10,7 +10,7 @@ consts: std.ArrayList(Const), |
| 10 | 10 | globals: std.array_hash_map.Auto(InternPool.Nav.Index, Global), |
| 11 | 11 | funcs: std.array_hash_map.Auto(InternPool.Nav.Index, Func), |
| 12 | 12 | decls: std.array_hash_map.Auto(InternPool.TrackedInst.Index, Decl), |
| 13 | | pending_decl: struct { di: Decl.Index, instance_val: InternPool.Index }, |
| 13 | pending_decl: struct { di: Decl.Index, instance: Decl.Instance }, |
| 14 | 14 | |
| 15 | 15 | debug_abbrev: Abbrev, |
| 16 | 16 | frame: Frame, |
| ... | ... | @@ -155,6 +155,12 @@ pub const Decl = struct { |
| 155 | 155 | return &dwarf.decls.values()[@backingInt(di)]; |
| 156 | 156 | } |
| 157 | 157 | }; |
| 158 | |
| 159 | const Instance = union(enum) { |
| 160 | none, |
| 161 | @"const": InternPool.Index, |
| 162 | global: InternPool.Nav.Index, |
| 163 | }; |
| 158 | 164 | }; |
| 159 | 165 | |
| 160 | 166 | pub const Frame = struct { |
| ... | ... | @@ -1258,7 +1264,7 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf { |
| 1258 | 1264 | .globals = .empty, |
| 1259 | 1265 | .funcs = .empty, |
| 1260 | 1266 | .decls = .empty, |
| 1261 | | .pending_decl = .{ .di = undefined, .instance_val = .none }, |
| 1267 | .pending_decl = .{ .di = undefined, .instance = .none }, |
| 1262 | 1268 | |
| 1263 | 1269 | .debug_abbrev = .{ |
| 1264 | 1270 | .ni = .none, |
| ... | ... | @@ -1468,7 +1474,7 @@ pub fn getFuncIfExists(dwarf: *Dwarf, nav: InternPool.Nav.Index) ?Func.Index { |
| 1468 | 1474 | return @fromBackingInt(@intCast(dwarf.funcs.getIndex(nav) orelse return null)); |
| 1469 | 1475 | } |
| 1470 | 1476 | |
| 1471 | | fn getDeclInst(dwarf: *Dwarf, val: InternPool.Index) ?InternPool.TrackedInst.Index { |
| 1477 | fn getConstDeclInst(dwarf: *Dwarf, val: InternPool.Index) ?InternPool.TrackedInst.Index { |
| 1472 | 1478 | const ip = &dwarf.lf.comp.zcu.?.intern_pool; |
| 1473 | 1479 | switch (ip.indexToKey(val)) { |
| 1474 | 1480 | else => unreachable, |
| ... | ... | @@ -1511,26 +1517,41 @@ fn getDeclInst(dwarf: *Dwarf, val: InternPool.Index) ?InternPool.TrackedInst.Ind |
| 1511 | 1517 | }).srcInst(ip), |
| 1512 | 1518 | } |
| 1513 | 1519 | } |
| 1514 | | pub fn getDecl( |
| 1520 | fn getConstDecl( |
| 1521 | dwarf: *Dwarf, |
| 1522 | pt: Zcu.PerThread, |
| 1523 | instance_const: InternPool.Index, |
| 1524 | ) link.Error!link.MappedFile.Node.Index { |
| 1525 | return dwarf.getDecl(pt, dwarf.getConstDeclInst(instance_const) orelse { |
| 1526 | const cpi = try dwarf.getConst(pt, .fromInterned(instance_const)); |
| 1527 | return Const.get(cpi, dwarf).debug_info_ni.unwrap().?; |
| 1528 | }, .{ .@"const" = instance_const }); |
| 1529 | } |
| 1530 | fn getGlobalDecl( |
| 1515 | 1531 | dwarf: *Dwarf, |
| 1516 | 1532 | pt: Zcu.PerThread, |
| 1517 | | instance_val: InternPool.Index, |
| 1533 | instance_global: InternPool.Nav.Index, |
| 1534 | ) link.Error!link.MappedFile.Node.Index { |
| 1535 | const ip = &pt.zcu.intern_pool; |
| 1536 | return dwarf.getDecl(pt, ip.getNav(instance_global).srcInst(ip), .{ .global = instance_global }); |
| 1537 | } |
| 1538 | fn getDecl( |
| 1539 | dwarf: *Dwarf, |
| 1540 | pt: Zcu.PerThread, |
| 1541 | inst: InternPool.TrackedInst.Index, |
| 1542 | instance: Decl.Instance, |
| 1518 | 1543 | ) link.Error!link.MappedFile.Node.Index { |
| 1519 | 1544 | const comp = dwarf.lf.comp; |
| 1520 | 1545 | const gpa = comp.gpa; |
| 1521 | 1546 | const zcu = pt.zcu; |
| 1522 | 1547 | const ip = &zcu.intern_pool; |
| 1523 | | const inst = dwarf.getDeclInst(instance_val) orelse { |
| 1524 | | const cpi = try dwarf.getConst(pt, .fromInterned(instance_val)); |
| 1525 | | return Const.get(cpi, dwarf).debug_info_ni.unwrap().?; |
| 1526 | | }; |
| 1527 | 1548 | const decl_gop = try dwarf.decls.getOrPut(gpa, inst); |
| 1528 | 1549 | if (!decl_gop.found_existing) decl_gop.value_ptr.* = .{ |
| 1529 | 1550 | .debug_info_ni = .none, |
| 1530 | 1551 | }; |
| 1531 | 1552 | const di: Decl.Index = @fromBackingInt(@intCast(decl_gop.index)); |
| 1532 | 1553 | if (decl_gop.value_ptr.debug_info_ni.unwrap()) |debug_info_ni| return debug_info_ni; |
| 1533 | | dwarf.pending_decl = .{ .di = di, .instance_val = instance_val }; |
| 1554 | dwarf.pending_decl = .{ .di = di, .instance = instance }; |
| 1534 | 1555 | const debug_info_ni = if (dwarf.lf.cast(.elf2)) |elf| debug_info_ni: { |
| 1535 | 1556 | try elf.nodes.ensureUnusedCapacity(gpa, 1); |
| 1536 | 1557 | try elf.dwarf_decls.putNoClobber(gpa, di, .{ |
| ... | ... | @@ -1946,19 +1967,18 @@ pub fn genDebugRnglists( |
| 1946 | 1967 | try dr_w.writeByte(DW.RLE.end_of_list); |
| 1947 | 1968 | } |
| 1948 | 1969 | |
| 1949 | | pub fn updateComptimeNav( |
| 1970 | pub fn updateComptimeGlobal( |
| 1950 | 1971 | dwarf: *Dwarf, |
| 1951 | 1972 | pt: Zcu.PerThread, |
| 1952 | | ni: InternPool.Nav.Index, |
| 1973 | global: InternPool.Nav.Index, |
| 1953 | 1974 | ) link.Error!void { |
| 1954 | 1975 | const zcu = pt.zcu; |
| 1955 | 1976 | const ip = &zcu.intern_pool; |
| 1956 | | const nav = ip.getNav(ni); |
| 1977 | const nav = ip.getNav(global); |
| 1957 | 1978 | log.debug("updateComptimeNav({f})", .{nav.fqn.fmt(ip)}); |
| 1958 | 1979 | const inst_info = nav.srcInst(ip).resolveFull(ip).?; |
| 1959 | 1980 | const nav_val: Value = .fromInterned(nav.resolved.?.value); |
| 1960 | | const zf = zcu.fileByIndex(inst_info.file); |
| 1961 | | const decl = zf.zir.?.getDeclaration(inst_info.inst); |
| 1981 | const decl = zcu.fileByIndex(inst_info.file).zir.?.getDeclaration(inst_info.inst); |
| 1962 | 1982 | switch (decl.kind) { |
| 1963 | 1983 | .unnamed_test, .@"test", .decltest => return, |
| 1964 | 1984 | .@"comptime", .@"const", .@"var" => {}, |
| ... | ... | @@ -1977,34 +1997,34 @@ pub fn updateComptimeNav( |
| 1977 | 1997 | .error_set_type, |
| 1978 | 1998 | .inferred_error_set_type, |
| 1979 | 1999 | .spirv_type, |
| 1980 | | => try dwarf.genDeclType(pt, ni, &decl), |
| 2000 | => try dwarf.genDeclType(pt, global, &decl), |
| 1981 | 2001 | .struct_type => { |
| 1982 | 2002 | const loaded_struct = ip.loadStructType(nav_val.toIntern()); |
| 1983 | | if (ni.toOptional() == loaded_struct.name_nav) |
| 2003 | if (global.toOptional() == loaded_struct.name_nav) |
| 1984 | 2004 | _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern()) |
| 1985 | 2005 | else |
| 1986 | | try dwarf.genDeclType(pt, ni, &decl); |
| 2006 | try dwarf.genDeclType(pt, global, &decl); |
| 1987 | 2007 | }, |
| 1988 | 2008 | .enum_type => { |
| 1989 | 2009 | const loaded_enum = ip.loadEnumType(nav_val.toIntern()); |
| 1990 | | if (ni.toOptional() == loaded_enum.name_nav) |
| 2010 | if (global.toOptional() == loaded_enum.name_nav) |
| 1991 | 2011 | _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern()) |
| 1992 | 2012 | else |
| 1993 | | try dwarf.genDeclType(pt, ni, &decl); |
| 2013 | try dwarf.genDeclType(pt, global, &decl); |
| 1994 | 2014 | }, |
| 1995 | 2015 | .union_type => { |
| 1996 | 2016 | const loaded_union = ip.loadUnionType(nav_val.toIntern()); |
| 1997 | | if (ni.toOptional() == loaded_union.name_nav) |
| 2017 | if (global.toOptional() == loaded_union.name_nav) |
| 1998 | 2018 | _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern()) |
| 1999 | 2019 | else |
| 2000 | | try dwarf.genDeclType(pt, ni, &decl); |
| 2020 | try dwarf.genDeclType(pt, global, &decl); |
| 2001 | 2021 | }, |
| 2002 | 2022 | .opaque_type => { |
| 2003 | 2023 | const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern()); |
| 2004 | | if (ni.toOptional() == loaded_opaque.name_nav) |
| 2024 | if (global.toOptional() == loaded_opaque.name_nav) |
| 2005 | 2025 | _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern()) |
| 2006 | 2026 | else |
| 2007 | | try dwarf.genDeclType(pt, ni, &decl); |
| 2027 | try dwarf.genDeclType(pt, global, &decl); |
| 2008 | 2028 | }, |
| 2009 | 2029 | .undef, |
| 2010 | 2030 | .simple_value, |
| ... | ... | @@ -2020,9 +2040,9 @@ pub fn updateComptimeNav( |
| 2020 | 2040 | .aggregate, |
| 2021 | 2041 | .un, |
| 2022 | 2042 | .bitpack, |
| 2023 | | => try dwarf.genDeclValue(pt, ni, &decl), |
| 2043 | => try dwarf.genDeclGlobal(pt, global, &decl), |
| 2024 | 2044 | .@"extern" => unreachable, |
| 2025 | | .func => |func| if (func.owner_nav == ni and func.generic_owner == .none) { |
| 2045 | .func => |func| if (func.owner_nav == global and func.generic_owner == .none) { |
| 2026 | 2046 | _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern()); |
| 2027 | 2047 | break :done; |
| 2028 | 2048 | } else return, |
| ... | ... | @@ -2034,10 +2054,10 @@ pub fn updateComptimeNav( |
| 2034 | 2054 | fn genDeclType( |
| 2035 | 2055 | dwarf: *Dwarf, |
| 2036 | 2056 | pt: Zcu.PerThread, |
| 2037 | | ni: InternPool.Nav.Index, |
| 2057 | global: InternPool.Nav.Index, |
| 2038 | 2058 | decl: *const std.zig.Zir.Inst.Declaration.Unwrapped, |
| 2039 | 2059 | ) link.Error!void { |
| 2040 | | const gi = try dwarf.getGlobal(ni); |
| 2060 | const gi = try dwarf.getGlobal(global); |
| 2041 | 2061 | const debug_info_ni = gi.get(dwarf).debug_info_ni.unwrap().?; |
| 2042 | 2062 | var di_nw: link.MappedFile.Node.Writer = undefined; |
| 2043 | 2063 | if (dwarf.lf.cast(.elf2)) |elf| { |
| ... | ... | @@ -2045,7 +2065,7 @@ fn genDeclType( |
| 2045 | 2065 | elf.resetNodeRelocs(debug_info_ni); |
| 2046 | 2066 | } else unreachable; |
| 2047 | 2067 | defer di_nw.deinit(); |
| 2048 | | dwarf.genDeclTypeInner(pt, &di_nw, ni, decl) catch |err| switch (err) { |
| 2068 | dwarf.genDeclTypeInner(pt, &di_nw, global, decl) catch |err| switch (err) { |
| 2049 | 2069 | error.WriteFailed => return dwarf.reportWriteError(&di_nw), |
| 2050 | 2070 | else => |e| return e, |
| 2051 | 2071 | }; |
| ... | ... | @@ -2054,30 +2074,38 @@ fn genDeclTypeInner( |
| 2054 | 2074 | dwarf: *Dwarf, |
| 2055 | 2075 | pt: Zcu.PerThread, |
| 2056 | 2076 | di_nw: *link.MappedFile.Node.Writer, |
| 2057 | | ni: InternPool.Nav.Index, |
| 2077 | global: InternPool.Nav.Index, |
| 2058 | 2078 | decl: *const std.zig.Zir.Inst.Declaration.Unwrapped, |
| 2059 | 2079 | ) link.EmitError!void { |
| 2060 | | const ip = &pt.zcu.intern_pool; |
| 2061 | | const nav = ip.getNav(ni); |
| 2062 | | const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(nav.analysis.?.namespace).owner_type); |
| 2080 | const zcu = pt.zcu; |
| 2081 | const ip = &zcu.intern_pool; |
| 2082 | const nav = ip.getNav(global); |
| 2083 | const parent_ty = ip.namespacePtr(nav.analysis.?.namespace).owner_type; |
| 2063 | 2084 | const di_w = &di_nw.interface; |
| 2064 | | try dwarf.abbrevCode(di_nw, .decl_type); |
| 2065 | | try dwarf.secOffset(di_nw, parent_ni, 0); |
| 2066 | | try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian); |
| 2067 | | try di_w.writeUleb128(decl.src_column + 1); |
| 2068 | | try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private); |
| 2069 | | try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip)); |
| 2085 | if (Type.fromInterned(parent_ty).getCaptures(zcu).len > 0) { |
| 2086 | try dwarf.abbrevCode(di_nw, .decl_instance_type); |
| 2087 | try dwarf.refType(pt, di_nw, .fromInterned(parent_ty)); |
| 2088 | try dwarf.secOffset(di_nw, try dwarf.getGlobalDecl(pt, global), 0); |
| 2089 | } else { |
| 2090 | const parent_ni = try dwarf.getConstDecl(pt, parent_ty); |
| 2091 | try dwarf.abbrevCode(di_nw, .decl_type); |
| 2092 | try dwarf.secOffset(di_nw, parent_ni, 0); |
| 2093 | try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian); |
| 2094 | try di_w.writeUleb128(decl.src_column + 1); |
| 2095 | 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)); |
| 2097 | } |
| 2070 | 2098 | try dwarf.refConst(pt, di_nw, .fromInterned(nav.resolved.?.value)); |
| 2071 | 2099 | try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen()); |
| 2072 | 2100 | } |
| 2073 | 2101 | |
| 2074 | | fn genDeclValue( |
| 2102 | fn genDeclGlobal( |
| 2075 | 2103 | dwarf: *Dwarf, |
| 2076 | 2104 | pt: Zcu.PerThread, |
| 2077 | | ni: InternPool.Nav.Index, |
| 2105 | global: InternPool.Nav.Index, |
| 2078 | 2106 | decl: *const std.zig.Zir.Inst.Declaration.Unwrapped, |
| 2079 | 2107 | ) link.Error!void { |
| 2080 | | const gi = try dwarf.getGlobal(ni); |
| 2108 | const gi = try dwarf.getGlobal(global); |
| 2081 | 2109 | const debug_info_ni = gi.get(dwarf).debug_info_ni.unwrap().?; |
| 2082 | 2110 | var di_nw: link.MappedFile.Node.Writer = undefined; |
| 2083 | 2111 | if (dwarf.lf.cast(.elf2)) |elf| { |
| ... | ... | @@ -2085,21 +2113,21 @@ fn genDeclValue( |
| 2085 | 2113 | elf.resetNodeRelocs(debug_info_ni); |
| 2086 | 2114 | } else unreachable; |
| 2087 | 2115 | defer di_nw.deinit(); |
| 2088 | | dwarf.genDeclValueInner(pt, &di_nw, ni, decl) catch |err| switch (err) { |
| 2116 | dwarf.genDeclGlobalInner(pt, &di_nw, global, decl) catch |err| switch (err) { |
| 2089 | 2117 | error.WriteFailed => return dwarf.reportWriteError(&di_nw), |
| 2090 | 2118 | else => |e| return e, |
| 2091 | 2119 | }; |
| 2092 | 2120 | } |
| 2093 | | fn genDeclValueInner( |
| 2121 | fn genDeclGlobalInner( |
| 2094 | 2122 | dwarf: *Dwarf, |
| 2095 | 2123 | pt: Zcu.PerThread, |
| 2096 | 2124 | di_nw: *link.MappedFile.Node.Writer, |
| 2097 | | ni: InternPool.Nav.Index, |
| 2125 | global: InternPool.Nav.Index, |
| 2098 | 2126 | decl: *const std.zig.Zir.Inst.Declaration.Unwrapped, |
| 2099 | 2127 | ) link.EmitError!void { |
| 2100 | 2128 | const zcu = pt.zcu; |
| 2101 | 2129 | const ip = &zcu.intern_pool; |
| 2102 | | const nav = ip.getNav(ni); |
| 2130 | const nav = ip.getNav(global); |
| 2103 | 2131 | const nav_const, const nav_ty: Type, const nav_align, const nav_val: Value = resolved: { |
| 2104 | 2132 | const resolved = nav.resolved.?; |
| 2105 | 2133 | break :resolved .{ |
| ... | ... | @@ -2110,7 +2138,7 @@ fn genDeclValueInner( |
| 2110 | 2138 | }; |
| 2111 | 2139 | }; |
| 2112 | 2140 | const nav_class = nav_ty.classify(zcu); |
| 2113 | | const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr(nav.analysis.?.namespace).owner_type); |
| 2141 | const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(nav.analysis.?.namespace).owner_type); |
| 2114 | 2142 | const di_w = &di_nw.interface; |
| 2115 | 2143 | try dwarf.abbrevCode(di_nw, if (nav_const) switch (nav_class) { |
| 2116 | 2144 | .no_possible_value, .one_possible_value => .decl_const, |
| ... | ... | @@ -2589,12 +2617,13 @@ fn updateConstInner( |
| 2589 | 2617 | .auto, .@"extern" => .decl_instance_empty_struct, |
| 2590 | 2618 | .@"packed" => .decl_instance_empty_packed_struct, |
| 2591 | 2619 | }); |
| 2592 | | try dwarf.secOffset(di_nw, try dwarf.getDecl(pt, val), 0); |
| 2620 | try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, val), 0); |
| 2593 | 2621 | } else if (loaded_struct.name_nav.unwrap()) |name_ni| { |
| 2594 | 2622 | const name_nav = ip.getNav(name_ni); |
| 2595 | 2623 | const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?); |
| 2596 | | const parent_ni = |
| 2597 | | try dwarf.getDecl(pt, ip.namespacePtr(name_nav.analysis.?.namespace).owner_type); |
| 2624 | const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr( |
| 2625 | name_nav.analysis.?.namespace, |
| 2626 | ).owner_type); |
| 2598 | 2627 | try dwarf.abbrevCode(di_nw, if (loaded_struct.field_types.len > 0) |
| 2599 | 2628 | switch (loaded_struct.layout) { |
| 2600 | 2629 | .auto, .@"extern" => .decl_struct, |
| ... | ... | @@ -2611,7 +2640,7 @@ fn updateConstInner( |
| 2611 | 2640 | try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip)); |
| 2612 | 2641 | } else { |
| 2613 | 2642 | const decl = zf.zir.?.getStructDecl(src_inst.inst); |
| 2614 | | const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr( |
| 2643 | const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr( |
| 2615 | 2644 | ip.namespacePtr(loaded_struct.namespace).parent.unwrap().?, |
| 2616 | 2645 | ).owner_type); |
| 2617 | 2646 | try dwarf.abbrevCode(di_nw, if (loaded_struct.field_types.len > 0) |
| ... | ... | @@ -2721,12 +2750,13 @@ fn updateConstInner( |
| 2721 | 2750 | .auto, .@"extern" => .decl_instance_empty_union, |
| 2722 | 2751 | .@"packed" => .decl_instance_empty_packed_union, |
| 2723 | 2752 | }); |
| 2724 | | try dwarf.secOffset(di_nw, try dwarf.getDecl(pt, val), 0); |
| 2753 | try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, val), 0); |
| 2725 | 2754 | } else if (loaded_union.name_nav.unwrap()) |name_ni| { |
| 2726 | 2755 | const name_nav = ip.getNav(name_ni); |
| 2727 | 2756 | const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?); |
| 2728 | | const parent_ni = |
| 2729 | | try dwarf.getDecl(pt, ip.namespacePtr(name_nav.analysis.?.namespace).owner_type); |
| 2757 | const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr( |
| 2758 | name_nav.analysis.?.namespace, |
| 2759 | ).owner_type); |
| 2730 | 2760 | try dwarf.abbrevCode(di_nw, if (loaded_union.field_types.len > 0) |
| 2731 | 2761 | switch (loaded_union.layout) { |
| 2732 | 2762 | .auto, .@"extern" => .decl_union, |
| ... | ... | @@ -2743,7 +2773,7 @@ fn updateConstInner( |
| 2743 | 2773 | try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip)); |
| 2744 | 2774 | } else { |
| 2745 | 2775 | const decl = zf.zir.?.getUnionDecl(loaded_union.zir_index.resolve(ip).?); |
| 2746 | | const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr( |
| 2776 | const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr( |
| 2747 | 2777 | ip.namespacePtr(loaded_union.namespace).parent.unwrap().?, |
| 2748 | 2778 | ).owner_type); |
| 2749 | 2779 | try dwarf.abbrevCode(di_nw, if (loaded_union.field_types.len > 0) |
| ... | ... | @@ -2853,11 +2883,11 @@ fn updateConstInner( |
| 2853 | 2883 | .decl_instance_enum |
| 2854 | 2884 | else |
| 2855 | 2885 | .decl_instance_empty_enum); |
| 2856 | | try dwarf.secOffset(di_nw, try dwarf.getDecl(pt, val), 0); |
| 2886 | try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, val), 0); |
| 2857 | 2887 | } else if (loaded_enum.name_nav.unwrap()) |name_ni| { |
| 2858 | 2888 | const name_nav = ip.getNav(name_ni); |
| 2859 | 2889 | const decl = zir.getDeclaration(name_nav.srcInst(ip).resolve(ip).?); |
| 2860 | | const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr( |
| 2890 | const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr( |
| 2861 | 2891 | name_nav.analysis.?.namespace, |
| 2862 | 2892 | ).owner_type); |
| 2863 | 2893 | try dwarf.abbrevCode( |
| ... | ... | @@ -2871,7 +2901,7 @@ fn updateConstInner( |
| 2871 | 2901 | try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip)); |
| 2872 | 2902 | } else { |
| 2873 | 2903 | const decl = zir.getEnumDecl(loaded_enum.zir_index.unwrap().?.resolve(ip).?); |
| 2874 | | const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr( |
| 2904 | const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr( |
| 2875 | 2905 | ip.namespacePtr(loaded_enum.namespace).parent.unwrap().?, |
| 2876 | 2906 | ).owner_type); |
| 2877 | 2907 | try dwarf.abbrevCode(di_nw, if (loaded_enum.field_names.len > 0) |
| ... | ... | @@ -3036,8 +3066,7 @@ fn updateConstInner( |
| 3036 | 3066 | const func_type = ip.indexToKey(func.ty).func_type; |
| 3037 | 3067 | const nav = ip.getNav(func.owner_nav); |
| 3038 | 3068 | const inst_info = nav.srcInst(ip).resolveFull(ip).?; |
| 3039 | | const zf = zcu.fileByIndex(inst_info.file); |
| 3040 | | const zir = &zf.zir.?; |
| 3069 | const zir = &zcu.fileByIndex(inst_info.file).zir.?; |
| 3041 | 3070 | const decl = zir.getDeclaration(inst_info.inst); |
| 3042 | 3071 | const empty = func_type.param_types.len == 0 and !func_type.is_var_args; |
| 3043 | 3072 | const parent_ty: Type = .fromInterned(ip.namespacePtr(nav.analysis.?.namespace).owner_type); |
| ... | ... | @@ -3268,12 +3297,12 @@ fn updateConstIncompleteInner( |
| 3268 | 3297 | .@"union" => .decl_instance_empty_incomplete_union, |
| 3269 | 3298 | .@"enum" => .decl_instance_empty_incomplete_enum, |
| 3270 | 3299 | }); |
| 3271 | | try dwarf.secOffset(di_nw, try dwarf.getDecl(pt, val), 0); |
| 3300 | try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, val), 0); |
| 3272 | 3301 | } else if (maybe_name_nav.unwrap()) |name_ni| { |
| 3273 | 3302 | const name_nav = ip.getNav(name_ni); |
| 3274 | 3303 | const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?); |
| 3275 | 3304 | const parent_ni = |
| 3276 | | try dwarf.getDecl(pt, ip.namespacePtr(name_nav.analysis.?.namespace).owner_type); |
| 3305 | try dwarf.getConstDecl(pt, ip.namespacePtr(name_nav.analysis.?.namespace).owner_type); |
| 3277 | 3306 | try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) { |
| 3278 | 3307 | .@"struct" => .decl_incomplete_struct, |
| 3279 | 3308 | .@"union" => .decl_incomplete_union, |
| ... | ... | @@ -3289,7 +3318,7 @@ fn updateConstIncompleteInner( |
| 3289 | 3318 | try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private); |
| 3290 | 3319 | try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip)); |
| 3291 | 3320 | } else { |
| 3292 | | const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr( |
| 3321 | const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr( |
| 3293 | 3322 | ip.namespacePtr(namespace).parent.unwrap().?, |
| 3294 | 3323 | ).owner_type); |
| 3295 | 3324 | try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) { |
| ... | ... | @@ -3360,10 +3389,16 @@ pub fn genDecl( |
| 3360 | 3389 | dwarf: *Dwarf, |
| 3361 | 3390 | pt: Zcu.PerThread, |
| 3362 | 3391 | di_nw: *link.MappedFile.Node.Writer, |
| 3363 | | instance_val: InternPool.Index, |
| 3392 | instance: Decl.Instance, |
| 3364 | 3393 | ) link.Error!void { |
| 3365 | | log.debug("genDecl({f})", .{Value.fromInterned(instance_val).fmtValue(pt)}); |
| 3366 | | dwarf.genDeclInner(pt, di_nw, instance_val) catch |err| switch (err) { |
| 3394 | switch (instance) { |
| 3395 | .none => unreachable, |
| 3396 | .@"const" => |@"const"| log.debug("genDecl({f})", .{Value.fromInterned(@"const").fmtValue(pt)}), |
| 3397 | .global => |global| log.debug("genDecl({f})", .{ |
| 3398 | pt.zcu.intern_pool.getNav(global).fqn.fmt(&pt.zcu.intern_pool), |
| 3399 | }), |
| 3400 | } |
| 3401 | dwarf.genDeclInner(pt, di_nw, instance) catch |err| switch (err) { |
| 3367 | 3402 | else => |e| return e, |
| 3368 | 3403 | error.WriteFailed => return dwarf.reportWriteError(di_nw), |
| 3369 | 3404 | }; |
| ... | ... | @@ -3372,218 +3407,239 @@ fn genDeclInner( |
| 3372 | 3407 | dwarf: *Dwarf, |
| 3373 | 3408 | pt: Zcu.PerThread, |
| 3374 | 3409 | di_nw: *link.MappedFile.Node.Writer, |
| 3375 | | instance_val: InternPool.Index, |
| 3410 | instance: Decl.Instance, |
| 3376 | 3411 | ) link.EmitError!void { |
| 3377 | 3412 | const zcu = pt.zcu; |
| 3378 | 3413 | const ip = &zcu.intern_pool; |
| 3379 | 3414 | const di_w = &di_nw.interface; |
| 3380 | | done: { |
| 3381 | | const kind: enum { @"struct", @"union", @"enum" }, const zf, const src_line, const src_column, const capture_names, const captures, const name, const maybe_name_nav, const namespace = container: switch (ip.indexToKey(instance_val)) { |
| 3382 | | else => unreachable, |
| 3383 | | .struct_type => { |
| 3384 | | const loaded_struct = ip.loadStructType(instance_val); |
| 3385 | | const src_inst = loaded_struct.zir_index.resolveFull(ip) orelse { |
| 3386 | | try dwarf.lostTracking(di_nw); |
| 3387 | | break :done; |
| 3388 | | }; |
| 3389 | | const zf = zcu.fileByIndex(src_inst.file); |
| 3390 | | const zir = &zf.zir.?; |
| 3391 | | const inst = zir.instructions.get(@backingInt(src_inst.inst)); |
| 3392 | | const src_line, const src_column, const capture_names = decl: switch (inst.tag) { |
| 3393 | | else => unreachable, |
| 3394 | | .struct_init, .struct_init_ref => { |
| 3395 | | const decl = zir.extraData( |
| 3396 | | std.zig.Zir.Inst.StructInit, |
| 3397 | | inst.data.pl_node.payload_index, |
| 3398 | | ).data; |
| 3399 | | break :decl .{ decl.src_line, decl.src_column, &.{} }; |
| 3400 | | }, |
| 3401 | | .struct_init_anon => { |
| 3402 | | const decl = zir.extraData( |
| 3403 | | std.zig.Zir.Inst.StructInitAnon, |
| 3404 | | inst.data.pl_node.payload_index, |
| 3405 | | ).data; |
| 3406 | | break :decl .{ decl.src_line, decl.src_column, &.{} }; |
| 3407 | | }, |
| 3408 | | .extended => switch (inst.data.extended.opcode) { |
| 3415 | done: switch (instance) { |
| 3416 | .none => unreachable, |
| 3417 | .@"const" => |@"const"| { |
| 3418 | const kind: enum { @"struct", @"union", @"enum" }, const zf, const src_line, const src_column, const capture_names, const captures, const name, const maybe_name_nav, const namespace = container: switch (ip.indexToKey(instance.@"const")) { |
| 3419 | else => unreachable, |
| 3420 | .struct_type => { |
| 3421 | const loaded_struct = ip.loadStructType(@"const"); |
| 3422 | const src_inst = loaded_struct.zir_index.resolveFull(ip) orelse { |
| 3423 | try dwarf.lostTracking(di_nw); |
| 3424 | break :done; |
| 3425 | }; |
| 3426 | const zf = zcu.fileByIndex(src_inst.file); |
| 3427 | const zir = &zf.zir.?; |
| 3428 | const inst = zir.instructions.get(@backingInt(src_inst.inst)); |
| 3429 | const src_line, const src_column, const capture_names = decl: switch (inst.tag) { |
| 3409 | 3430 | else => unreachable, |
| 3410 | | .struct_decl => { |
| 3411 | | const decl = zir.getStructDecl(src_inst.inst); |
| 3412 | | break :decl .{ decl.src_line, decl.src_column, decl.capture_names }; |
| 3413 | | }, |
| 3414 | | .reify_struct => { |
| 3431 | .struct_init, .struct_init_ref => { |
| 3415 | 3432 | const decl = zir.extraData( |
| 3416 | | std.zig.Zir.Inst.ReifyStruct, |
| 3417 | | inst.data.extended.operand, |
| 3433 | std.zig.Zir.Inst.StructInit, |
| 3434 | inst.data.pl_node.payload_index, |
| 3418 | 3435 | ).data; |
| 3419 | 3436 | break :decl .{ decl.src_line, decl.src_column, &.{} }; |
| 3420 | 3437 | }, |
| 3421 | | }, |
| 3422 | | }; |
| 3423 | | break :container .{ |
| 3424 | | .@"struct", |
| 3425 | | zf, |
| 3426 | | src_line, |
| 3427 | | src_column, |
| 3428 | | capture_names, |
| 3429 | | loaded_struct.captures, |
| 3430 | | loaded_struct.name, |
| 3431 | | loaded_struct.name_nav, |
| 3432 | | loaded_struct.namespace, |
| 3433 | | }; |
| 3434 | | }, |
| 3435 | | .union_type => { |
| 3436 | | const loaded_union = ip.loadUnionType(instance_val); |
| 3437 | | const src_inst = loaded_union.zir_index.resolveFull(ip) orelse { |
| 3438 | | try dwarf.lostTracking(di_nw); |
| 3439 | | break :done; |
| 3440 | | }; |
| 3441 | | const zf = zcu.fileByIndex(src_inst.file); |
| 3442 | | const zir = &zf.zir.?; |
| 3443 | | const inst = zir.instructions.get(@backingInt(src_inst.inst)); |
| 3444 | | const src_line, const src_column, const capture_names = decl: switch (inst.tag) { |
| 3445 | | else => unreachable, |
| 3446 | | .extended => switch (inst.data.extended.opcode) { |
| 3447 | | else => unreachable, |
| 3448 | | .union_decl => { |
| 3449 | | const decl = zir.getUnionDecl(src_inst.inst); |
| 3450 | | break :decl .{ decl.src_line, decl.src_column, decl.capture_names }; |
| 3451 | | }, |
| 3452 | | .reify_union => { |
| 3438 | .struct_init_anon => { |
| 3453 | 3439 | const decl = zir.extraData( |
| 3454 | | std.zig.Zir.Inst.ReifyUnion, |
| 3455 | | inst.data.extended.operand, |
| 3440 | std.zig.Zir.Inst.StructInitAnon, |
| 3441 | inst.data.pl_node.payload_index, |
| 3456 | 3442 | ).data; |
| 3457 | 3443 | break :decl .{ decl.src_line, decl.src_column, &.{} }; |
| 3458 | 3444 | }, |
| 3459 | | }, |
| 3460 | | }; |
| 3461 | | break :container .{ |
| 3462 | | .@"union", |
| 3463 | | zf, |
| 3464 | | src_line, |
| 3465 | | src_column, |
| 3466 | | capture_names, |
| 3467 | | loaded_union.captures, |
| 3468 | | loaded_union.name, |
| 3469 | | loaded_union.name_nav, |
| 3470 | | loaded_union.namespace, |
| 3471 | | }; |
| 3472 | | }, |
| 3473 | | .enum_type => { |
| 3474 | | const loaded_enum = ip.loadEnumType(instance_val); |
| 3475 | | const src_inst = loaded_enum.zir_index.unwrap().?.resolveFull(ip) orelse { |
| 3476 | | try dwarf.lostTracking(di_nw); |
| 3477 | | break :done; |
| 3478 | | }; |
| 3479 | | const zf = zcu.fileByIndex(src_inst.file); |
| 3480 | | const zir = &zf.zir.?; |
| 3481 | | const inst = zir.instructions.get(@backingInt(src_inst.inst)); |
| 3482 | | const src_line, const src_column, const capture_names = decl: switch (inst.tag) { |
| 3483 | | else => unreachable, |
| 3484 | | .extended => switch (inst.data.extended.opcode) { |
| 3445 | .extended => switch (inst.data.extended.opcode) { |
| 3446 | else => unreachable, |
| 3447 | .struct_decl => { |
| 3448 | const decl = zir.getStructDecl(src_inst.inst); |
| 3449 | break :decl .{ decl.src_line, decl.src_column, decl.capture_names }; |
| 3450 | }, |
| 3451 | .reify_struct => { |
| 3452 | const decl = zir.extraData( |
| 3453 | std.zig.Zir.Inst.ReifyStruct, |
| 3454 | inst.data.extended.operand, |
| 3455 | ).data; |
| 3456 | break :decl .{ decl.src_line, decl.src_column, &.{} }; |
| 3457 | }, |
| 3458 | }, |
| 3459 | }; |
| 3460 | break :container .{ |
| 3461 | .@"struct", |
| 3462 | zf, |
| 3463 | src_line, |
| 3464 | src_column, |
| 3465 | capture_names, |
| 3466 | loaded_struct.captures, |
| 3467 | loaded_struct.name, |
| 3468 | loaded_struct.name_nav, |
| 3469 | loaded_struct.namespace, |
| 3470 | }; |
| 3471 | }, |
| 3472 | .union_type => { |
| 3473 | const loaded_union = ip.loadUnionType(@"const"); |
| 3474 | const src_inst = loaded_union.zir_index.resolveFull(ip) orelse { |
| 3475 | try dwarf.lostTracking(di_nw); |
| 3476 | break :done; |
| 3477 | }; |
| 3478 | const zf = zcu.fileByIndex(src_inst.file); |
| 3479 | const zir = &zf.zir.?; |
| 3480 | const inst = zir.instructions.get(@backingInt(src_inst.inst)); |
| 3481 | const src_line, const src_column, const capture_names = decl: switch (inst.tag) { |
| 3485 | 3482 | else => unreachable, |
| 3486 | | .enum_decl => { |
| 3487 | | const decl = zir.getEnumDecl(src_inst.inst); |
| 3488 | | break :decl .{ decl.src_line, decl.src_column, decl.capture_names }; |
| 3483 | .extended => switch (inst.data.extended.opcode) { |
| 3484 | else => unreachable, |
| 3485 | .union_decl => { |
| 3486 | const decl = zir.getUnionDecl(src_inst.inst); |
| 3487 | break :decl .{ decl.src_line, decl.src_column, decl.capture_names }; |
| 3488 | }, |
| 3489 | .reify_union => { |
| 3490 | const decl = zir.extraData( |
| 3491 | std.zig.Zir.Inst.ReifyUnion, |
| 3492 | inst.data.extended.operand, |
| 3493 | ).data; |
| 3494 | break :decl .{ decl.src_line, decl.src_column, &.{} }; |
| 3495 | }, |
| 3489 | 3496 | }, |
| 3490 | | .reify_enum => { |
| 3491 | | const decl = zir.extraData( |
| 3492 | | std.zig.Zir.Inst.ReifyEnum, |
| 3493 | | inst.data.extended.operand, |
| 3494 | | ).data; |
| 3495 | | break :decl .{ decl.src_line, decl.src_column, &.{} }; |
| 3497 | }; |
| 3498 | break :container .{ |
| 3499 | .@"union", |
| 3500 | zf, |
| 3501 | src_line, |
| 3502 | src_column, |
| 3503 | capture_names, |
| 3504 | loaded_union.captures, |
| 3505 | loaded_union.name, |
| 3506 | loaded_union.name_nav, |
| 3507 | loaded_union.namespace, |
| 3508 | }; |
| 3509 | }, |
| 3510 | .enum_type => { |
| 3511 | const loaded_enum = ip.loadEnumType(@"const"); |
| 3512 | const src_inst = loaded_enum.zir_index.unwrap().?.resolveFull(ip) orelse { |
| 3513 | try dwarf.lostTracking(di_nw); |
| 3514 | break :done; |
| 3515 | }; |
| 3516 | const zf = zcu.fileByIndex(src_inst.file); |
| 3517 | const zir = &zf.zir.?; |
| 3518 | const inst = zir.instructions.get(@backingInt(src_inst.inst)); |
| 3519 | const src_line, const src_column, const capture_names = decl: switch (inst.tag) { |
| 3520 | else => unreachable, |
| 3521 | .extended => switch (inst.data.extended.opcode) { |
| 3522 | else => unreachable, |
| 3523 | .enum_decl => { |
| 3524 | const decl = zir.getEnumDecl(src_inst.inst); |
| 3525 | break :decl .{ decl.src_line, decl.src_column, decl.capture_names }; |
| 3526 | }, |
| 3527 | .reify_enum => { |
| 3528 | const decl = zir.extraData( |
| 3529 | std.zig.Zir.Inst.ReifyEnum, |
| 3530 | inst.data.extended.operand, |
| 3531 | ).data; |
| 3532 | break :decl .{ decl.src_line, decl.src_column, &.{} }; |
| 3533 | }, |
| 3496 | 3534 | }, |
| 3535 | }; |
| 3536 | break :container .{ |
| 3537 | .@"enum", |
| 3538 | zf, |
| 3539 | src_line, |
| 3540 | src_column, |
| 3541 | capture_names, |
| 3542 | loaded_enum.captures, |
| 3543 | loaded_enum.name, |
| 3544 | loaded_enum.name_nav, |
| 3545 | loaded_enum.namespace, |
| 3546 | }; |
| 3547 | }, |
| 3548 | .opaque_type => { |
| 3549 | const loaded_opaque = ip.loadOpaqueType(@"const"); |
| 3550 | const src_inst = loaded_opaque.zir_index.resolveFull(ip) orelse { |
| 3551 | try dwarf.lostTracking(di_nw); |
| 3552 | break :done; |
| 3553 | }; |
| 3554 | const zf = zcu.fileByIndex(src_inst.file); |
| 3555 | const decl = zf.zir.?.getOpaqueDecl(src_inst.inst); |
| 3556 | break :container .{ |
| 3557 | .@"struct", |
| 3558 | zf, |
| 3559 | decl.src_line, |
| 3560 | decl.src_column, |
| 3561 | decl.capture_names, |
| 3562 | loaded_opaque.captures, |
| 3563 | loaded_opaque.name, |
| 3564 | loaded_opaque.name_nav, |
| 3565 | loaded_opaque.namespace, |
| 3566 | }; |
| 3567 | }, |
| 3568 | }; |
| 3569 | const zir = &zf.zir.?; |
| 3570 | if (maybe_name_nav.unwrap()) |name_ni| { |
| 3571 | const name_nav = ip.getNav(name_ni); |
| 3572 | const decl = zir.getDeclaration(name_nav.srcInst(ip).resolve(ip).?); |
| 3573 | const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr( |
| 3574 | name_nav.analysis.?.namespace, |
| 3575 | ).owner_type); |
| 3576 | try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) { |
| 3577 | .@"struct" => .decl_specification_struct, |
| 3578 | .@"union" => .decl_specification_union, |
| 3579 | .@"enum" => .decl_specification_enum, |
| 3580 | } else switch (kind) { |
| 3581 | .@"struct" => .decl_specification_empty_struct, |
| 3582 | .@"union" => .decl_specification_empty_union, |
| 3583 | .@"enum" => .decl_specification_empty_enum, |
| 3584 | }); |
| 3585 | try dwarf.secOffset(di_nw, parent_ni, 0); |
| 3586 | try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian); |
| 3587 | try di_w.writeUleb128(decl.src_column + 1); |
| 3588 | try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private); |
| 3589 | try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip)); |
| 3590 | } else { |
| 3591 | const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr( |
| 3592 | ip.namespacePtr(namespace).parent.unwrap().?, |
| 3593 | ).owner_type); |
| 3594 | try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) { |
| 3595 | .@"struct" => .type_decl_specification_struct, |
| 3596 | .@"union" => .type_decl_specification_union, |
| 3597 | .@"enum" => .type_decl_specification_enum, |
| 3598 | } else switch (kind) { |
| 3599 | .@"struct" => .type_decl_specification_empty_struct, |
| 3600 | .@"union" => .type_decl_specification_empty_union, |
| 3601 | .@"enum" => .type_decl_specification_empty_enum, |
| 3602 | }); |
| 3603 | try dwarf.secOffset(di_nw, parent_ni, 0); |
| 3604 | try di_w.writeInt(u32, src_line + 1, dwarf.endian); |
| 3605 | try di_w.writeUleb128(src_column + 1); |
| 3606 | try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip)); |
| 3607 | } |
| 3608 | for (capture_names, captures.get(ip)) |capture_name, capture| { |
| 3609 | try dwarf.abbrevCode(di_nw, .capture_specification); |
| 3610 | switch (capture.unwrap()) { |
| 3611 | .@"comptime", .runtime, .nav_val => try dwarf.strp( |
| 3612 | &dwarf.debug_str, |
| 3613 | di_nw, |
| 3614 | zir.nullTerminatedString(capture_name), |
| 3615 | ), |
| 3616 | .nav_ref => { |
| 3617 | const capture_name_slice = |
| 3618 | try zcu.gpa.print("&{s}", .{zir.nullTerminatedString(capture_name)}); |
| 3619 | defer zcu.gpa.free(capture_name_slice); |
| 3620 | try dwarf.strp(&dwarf.debug_str, di_nw, capture_name_slice); |
| 3497 | 3621 | }, |
| 3498 | | }; |
| 3499 | | break :container .{ |
| 3500 | | .@"enum", |
| 3501 | | zf, |
| 3502 | | src_line, |
| 3503 | | src_column, |
| 3504 | | capture_names, |
| 3505 | | loaded_enum.captures, |
| 3506 | | loaded_enum.name, |
| 3507 | | loaded_enum.name_nav, |
| 3508 | | loaded_enum.namespace, |
| 3509 | | }; |
| 3510 | | }, |
| 3511 | | .opaque_type => { |
| 3512 | | const loaded_opaque = ip.loadOpaqueType(instance_val); |
| 3513 | | const src_inst = loaded_opaque.zir_index.resolveFull(ip) orelse { |
| 3514 | | try dwarf.lostTracking(di_nw); |
| 3515 | | break :done; |
| 3516 | | }; |
| 3517 | | const zf = zcu.fileByIndex(src_inst.file); |
| 3518 | | const decl = zf.zir.?.getOpaqueDecl(src_inst.inst); |
| 3519 | | break :container .{ |
| 3520 | | .@"struct", |
| 3521 | | zf, |
| 3522 | | decl.src_line, |
| 3523 | | decl.src_column, |
| 3524 | | decl.capture_names, |
| 3525 | | loaded_opaque.captures, |
| 3526 | | loaded_opaque.name, |
| 3527 | | loaded_opaque.name_nav, |
| 3528 | | loaded_opaque.namespace, |
| 3529 | | }; |
| 3530 | | }, |
| 3531 | | }; |
| 3532 | | const zir = &zf.zir.?; |
| 3533 | | if (maybe_name_nav.unwrap()) |name_ni| { |
| 3534 | | const name_nav = ip.getNav(name_ni); |
| 3535 | | const decl = zir.getDeclaration(name_nav.srcInst(ip).resolve(ip).?); |
| 3536 | | const parent_ni = |
| 3537 | | try dwarf.getDecl(pt, ip.namespacePtr(name_nav.analysis.?.namespace).owner_type); |
| 3538 | | try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) { |
| 3539 | | .@"struct" => .decl_specification_struct, |
| 3540 | | .@"union" => .decl_specification_union, |
| 3541 | | .@"enum" => .decl_specification_enum, |
| 3542 | | } else switch (kind) { |
| 3543 | | .@"struct" => .decl_specification_empty_struct, |
| 3544 | | .@"union" => .decl_specification_empty_union, |
| 3545 | | .@"enum" => .decl_specification_empty_enum, |
| 3546 | | }); |
| 3622 | } |
| 3623 | } |
| 3624 | if (captures.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null)); |
| 3625 | }, |
| 3626 | .global => |global| { |
| 3627 | const nav = ip.getNav(global); |
| 3628 | const src_inst = nav.srcInst(ip).resolveFull(ip).?; |
| 3629 | const decl = zcu.fileByIndex(src_inst.file).zir.?.getDeclaration(src_inst.inst); |
| 3630 | const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr( |
| 3631 | nav.analysis.?.namespace, |
| 3632 | ).owner_type); |
| 3633 | try dwarf.abbrevCode(di_nw, if (nav.resolved.?.@"const") switch (nav.resolved.?.type) { |
| 3634 | .type_type => .decl_specification_type, |
| 3635 | else => .decl_specification_const, |
| 3636 | } else .decl_specification_var); |
| 3547 | 3637 | try dwarf.secOffset(di_nw, parent_ni, 0); |
| 3548 | 3638 | try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian); |
| 3549 | 3639 | try di_w.writeUleb128(decl.src_column + 1); |
| 3550 | 3640 | try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private); |
| 3551 | | try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip)); |
| 3552 | | } else { |
| 3553 | | const parent_ni = try dwarf.getDecl(pt, ip.namespacePtr( |
| 3554 | | ip.namespacePtr(namespace).parent.unwrap().?, |
| 3555 | | ).owner_type); |
| 3556 | | try dwarf.abbrevCode(di_nw, if (captures.len > 0) switch (kind) { |
| 3557 | | .@"struct" => .type_decl_specification_struct, |
| 3558 | | .@"union" => .type_decl_specification_union, |
| 3559 | | .@"enum" => .type_decl_specification_enum, |
| 3560 | | } else switch (kind) { |
| 3561 | | .@"struct" => .type_decl_specification_empty_struct, |
| 3562 | | .@"union" => .type_decl_specification_empty_union, |
| 3563 | | .@"enum" => .type_decl_specification_empty_enum, |
| 3564 | | }); |
| 3565 | | try dwarf.secOffset(di_nw, parent_ni, 0); |
| 3566 | | try di_w.writeInt(u32, src_line + 1, dwarf.endian); |
| 3567 | | try di_w.writeUleb128(src_column + 1); |
| 3568 | | try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip)); |
| 3569 | | } |
| 3570 | | for (capture_names, captures.get(ip)) |capture_name, capture| { |
| 3571 | | try dwarf.abbrevCode(di_nw, .capture_specification); |
| 3572 | | switch (capture.unwrap()) { |
| 3573 | | .@"comptime", .runtime, .nav_val => try dwarf.strp( |
| 3574 | | &dwarf.debug_str, |
| 3575 | | di_nw, |
| 3576 | | zir.nullTerminatedString(capture_name), |
| 3577 | | ), |
| 3578 | | .nav_ref => { |
| 3579 | | const capture_name_slice = |
| 3580 | | try zcu.gpa.print("&{s}", .{zir.nullTerminatedString(capture_name)}); |
| 3581 | | defer zcu.gpa.free(capture_name_slice); |
| 3582 | | try dwarf.strp(&dwarf.debug_str, di_nw, capture_name_slice); |
| 3583 | | }, |
| 3584 | | } |
| 3585 | | } |
| 3586 | | if (captures.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null)); |
| 3641 | try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip)); |
| 3642 | }, |
| 3587 | 3643 | } |
| 3588 | 3644 | try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen()); |
| 3589 | 3645 | } |
| ... | ... | @@ -3887,7 +3943,6 @@ pub const AbbrevCode = enum { |
| 3887 | 3943 | pad_n, |
| 3888 | 3944 | // decl, specification, and instance codes are assumed to all have the same uleb128 size |
| 3889 | 3945 | decl_lost, |
| 3890 | | decl_type, |
| 3891 | 3946 | decl_empty_incomplete_enum, |
| 3892 | 3947 | decl_incomplete_enum, |
| 3893 | 3948 | decl_empty_enum, |
| ... | ... | @@ -3920,11 +3975,12 @@ pub const AbbrevCode = enum { |
| 3920 | 3975 | decl_packed_union, |
| 3921 | 3976 | type_decl_empty_packed_union, |
| 3922 | 3977 | type_decl_packed_union, |
| 3923 | | decl_var, |
| 3978 | decl_type, |
| 3924 | 3979 | decl_const, |
| 3925 | 3980 | decl_const_fully_runtime, |
| 3926 | 3981 | decl_const_partially_comptime, |
| 3927 | 3982 | decl_const_fully_comptime, |
| 3983 | decl_var, |
| 3928 | 3984 | decl_empty_func, |
| 3929 | 3985 | decl_func, |
| 3930 | 3986 | decl_empty_func_generic, |
| ... | ... | @@ -3943,6 +3999,9 @@ pub const AbbrevCode = enum { |
| 3943 | 3999 | decl_specification_union, |
| 3944 | 4000 | type_decl_specification_empty_union, |
| 3945 | 4001 | type_decl_specification_union, |
| 4002 | decl_specification_type, |
| 4003 | decl_specification_const, |
| 4004 | decl_specification_var, |
| 3946 | 4005 | decl_specification_func, |
| 3947 | 4006 | decl_instance_type, |
| 3948 | 4007 | decl_instance_empty_incomplete_enum, |
| ... | ... | @@ -4063,7 +4122,7 @@ pub const AbbrevCode = enum { |
| 4063 | 4122 | comptime { |
| 4064 | 4123 | assert(uleb128Size(@backingInt(AbbrevCode.pad_1)) == 1); |
| 4065 | 4124 | assert(uleb128Size(@backingInt(AbbrevCode.pad_n)) == 1); |
| 4066 | | assert(uleb128Size(@backingInt(AbbrevCode.decl_type)) == decl_size); |
| 4125 | assert(uleb128Size(@backingInt(AbbrevCode.decl_lost)) == decl_size); |
| 4067 | 4126 | } |
| 4068 | 4127 | |
| 4069 | 4128 | const Attr = struct { |
| ... | ... | @@ -4111,12 +4170,6 @@ pub const AbbrevCode = enum { |
| 4111 | 4170 | .decl_lost = .{ |
| 4112 | 4171 | .tag = .ZIG_lost_declaration, |
| 4113 | 4172 | }, |
| 4114 | | .decl_type = .{ |
| 4115 | | .tag = .imported_declaration, |
| 4116 | | .attrs = decl_attrs ++ .{ |
| 4117 | | .{ .import, .ref_addr }, |
| 4118 | | }, |
| 4119 | | }, |
| 4120 | 4173 | .decl_empty_incomplete_enum = .{ |
| 4121 | 4174 | .tag = .enumeration_type, |
| 4122 | 4175 | .attrs = decl_attrs, |
| ... | ... | @@ -4309,6 +4362,12 @@ pub const AbbrevCode = enum { |
| 4309 | 4362 | .{ .type, .ref_addr }, |
| 4310 | 4363 | }, |
| 4311 | 4364 | }, |
| 4365 | .decl_type = .{ |
| 4366 | .tag = .imported_declaration, |
| 4367 | .attrs = decl_attrs ++ .{ |
| 4368 | .{ .import, .ref_addr }, |
| 4369 | }, |
| 4370 | }, |
| 4312 | 4371 | .decl_var = .{ |
| 4313 | 4372 | .tag = .variable, |
| 4314 | 4373 | .attrs = decl_attrs ++ .{ |
| ... | ... | @@ -4472,13 +4531,27 @@ pub const AbbrevCode = enum { |
| 4472 | 4531 | .children = true, |
| 4473 | 4532 | .attrs = type_decl_specification_attrs, |
| 4474 | 4533 | }, |
| 4534 | .decl_specification_type = .{ |
| 4535 | .tag = .imported_declaration, |
| 4536 | .attrs = decl_specification_attrs, |
| 4537 | }, |
| 4538 | .decl_specification_const = .{ |
| 4539 | .tag = .constant, |
| 4540 | .attrs = decl_specification_attrs, |
| 4541 | }, |
| 4542 | .decl_specification_var = .{ |
| 4543 | .tag = .variable, |
| 4544 | .attrs = decl_specification_attrs, |
| 4545 | }, |
| 4475 | 4546 | .decl_specification_func = .{ |
| 4476 | 4547 | .tag = .subprogram, |
| 4477 | 4548 | .attrs = decl_specification_attrs, |
| 4478 | 4549 | }, |
| 4479 | 4550 | .decl_instance_type = .{ |
| 4480 | 4551 | .tag = .imported_declaration, |
| 4481 | | .attrs = decl_instance_attrs ++ .{ |
| 4552 | .attrs = .{ |
| 4553 | .{ .ZIG_parent, .ref_addr }, |
| 4554 | } ++ decl_instance_attrs ++ .{ |
| 4482 | 4555 | .{ .import, .ref_addr }, |
| 4483 | 4556 | }, |
| 4484 | 4557 | }, |