| ... | ... | @@ -805,14 +805,17 @@ pub const Object = struct { |
| 805 | 805 | |
| 806 | 806 | debug_enums_fwd_ref: Builder.Metadata, |
| 807 | 807 | debug_globals_fwd_ref: Builder.Metadata, |
| 808 | debug_imports_fwd_ref: Builder.Metadata, |
| 808 | 809 | |
| 809 | 810 | debug_enums: std.ArrayListUnmanaged(Builder.Metadata), |
| 810 | 811 | debug_globals: std.ArrayListUnmanaged(Builder.Metadata), |
| 812 | debug_imports: std.ArrayListUnmanaged(Builder.Metadata), |
| 811 | 813 | |
| 812 | 814 | debug_file_map: std.AutoHashMapUnmanaged(*const Zcu.File, Builder.Metadata), |
| 813 | 815 | debug_type_map: std.AutoHashMapUnmanaged(Type, Builder.Metadata), |
| 814 | 816 | |
| 815 | | debug_unresolved_namespace_scopes: std.AutoArrayHashMapUnmanaged(InternPool.NamespaceIndex, Builder.Metadata), |
| 817 | // The value says whether this namespace's type is runtime-required. |
| 818 | debug_unresolved_namespace_scopes: std.AutoArrayHashMapUnmanaged(Type, bool), |
| 816 | 819 | |
| 817 | 820 | target: std.Target, |
| 818 | 821 | /// Ideally we would use `llvm_module.getNamedFunction` to go from *Decl to LLVM function, |
| ... | ... | @@ -877,7 +880,7 @@ pub const Object = struct { |
| 877 | 880 | |
| 878 | 881 | builder.data_layout = try builder.fmt("{}", .{DataLayoutBuilder{ .target = target }}); |
| 879 | 882 | |
| 880 | | const debug_compile_unit, const debug_enums_fwd_ref, const debug_globals_fwd_ref = |
| 883 | const debug_compile_unit, const debug_enums_fwd_ref, const debug_globals_fwd_ref, const debug_imports_fwd_ref = |
| 881 | 884 | if (!builder.strip) |
| 882 | 885 | debug_info: { |
| 883 | 886 | // We fully resolve all paths at this point to avoid lack of |
| ... | ... | @@ -909,6 +912,7 @@ pub const Object = struct { |
| 909 | 912 | |
| 910 | 913 | const debug_enums_fwd_ref = try builder.debugForwardReference(); |
| 911 | 914 | const debug_globals_fwd_ref = try builder.debugForwardReference(); |
| 915 | const debug_imports_fwd_ref = try builder.debugForwardReference(); |
| 912 | 916 | |
| 913 | 917 | const debug_compile_unit = try builder.debugCompileUnit( |
| 914 | 918 | debug_file, |
| ... | ... | @@ -921,6 +925,7 @@ pub const Object = struct { |
| 921 | 925 | }), |
| 922 | 926 | debug_enums_fwd_ref, |
| 923 | 927 | debug_globals_fwd_ref, |
| 928 | debug_imports_fwd_ref, |
| 924 | 929 | .{ .optimized = comp.root_mod.optimize_mode != .Debug }, |
| 925 | 930 | ); |
| 926 | 931 | |
| ... | ... | @@ -976,8 +981,8 @@ pub const Object = struct { |
| 976 | 981 | } |
| 977 | 982 | |
| 978 | 983 | try builder.debugNamed(try builder.metadataString("llvm.dbg.cu"), &.{debug_compile_unit}); |
| 979 | | break :debug_info .{ debug_compile_unit, debug_enums_fwd_ref, debug_globals_fwd_ref }; |
| 980 | | } else .{.none} ** 3; |
| 984 | break :debug_info .{ debug_compile_unit, debug_enums_fwd_ref, debug_globals_fwd_ref, debug_imports_fwd_ref }; |
| 985 | } else .{.none} ** 4; |
| 981 | 986 | |
| 982 | 987 | const obj = try arena.create(Object); |
| 983 | 988 | obj.* = .{ |
| ... | ... | @@ -990,8 +995,10 @@ pub const Object = struct { |
| 990 | 995 | .debug_compile_unit = debug_compile_unit, |
| 991 | 996 | .debug_enums_fwd_ref = debug_enums_fwd_ref, |
| 992 | 997 | .debug_globals_fwd_ref = debug_globals_fwd_ref, |
| 998 | .debug_imports_fwd_ref = debug_imports_fwd_ref, |
| 993 | 999 | .debug_enums = .{}, |
| 994 | 1000 | .debug_globals = .{}, |
| 1001 | .debug_imports = .{}, |
| 995 | 1002 | .debug_file_map = .{}, |
| 996 | 1003 | .debug_type_map = .{}, |
| 997 | 1004 | .debug_unresolved_namespace_scopes = .{}, |
| ... | ... | @@ -1133,18 +1140,7 @@ pub const Object = struct { |
| 1133 | 1140 | try self.genModuleLevelAssembly(); |
| 1134 | 1141 | |
| 1135 | 1142 | if (!self.builder.strip) { |
| 1136 | | { |
| 1137 | | var i: usize = 0; |
| 1138 | | while (i < self.debug_unresolved_namespace_scopes.count()) : (i += 1) { |
| 1139 | | const namespace_index = self.debug_unresolved_namespace_scopes.keys()[i]; |
| 1140 | | const fwd_ref = self.debug_unresolved_namespace_scopes.values()[i]; |
| 1141 | | |
| 1142 | | const namespace = zcu.namespacePtr(namespace_index); |
| 1143 | | const debug_type = try self.lowerDebugType(namespace.getType(zcu)); |
| 1144 | | |
| 1145 | | self.builder.debugForwardReferenceSetType(fwd_ref, debug_type); |
| 1146 | | } |
| 1147 | | } |
| 1143 | try self.genNamespaces(); |
| 1148 | 1144 | |
| 1149 | 1145 | self.builder.debugForwardReferenceSetType( |
| 1150 | 1146 | self.debug_enums_fwd_ref, |
| ... | ... | @@ -1155,6 +1151,11 @@ pub const Object = struct { |
| 1155 | 1151 | self.debug_globals_fwd_ref, |
| 1156 | 1152 | try self.builder.debugTuple(self.debug_globals.items), |
| 1157 | 1153 | ); |
| 1154 | |
| 1155 | self.builder.debugForwardReferenceSetType( |
| 1156 | self.debug_imports_fwd_ref, |
| 1157 | try self.builder.debugTuple(self.debug_imports.items), |
| 1158 | ); |
| 1158 | 1159 | } |
| 1159 | 1160 | } |
| 1160 | 1161 | |
| ... | ... | @@ -1634,15 +1635,19 @@ pub const Object = struct { |
| 1634 | 1635 | |
| 1635 | 1636 | const file, const subprogram = if (!wip.strip) debug_info: { |
| 1636 | 1637 | const file = try o.getDebugFile(file_scope); |
| 1638 | const scope = try o.lowerDebugType(zcu.declPtr(namespace.decl_index).val.toType(), false); |
| 1637 | 1639 | |
| 1638 | 1640 | const line_number = decl.navSrcLine(zcu) + 1; |
| 1639 | 1641 | const is_internal_linkage = decl.val.getExternFunc(zcu) == null; |
| 1640 | | const debug_decl_type = try o.lowerDebugType(decl.typeOf(zcu)); |
| 1642 | const debug_decl_type = try o.lowerDebugType(decl.typeOf(zcu), true); |
| 1643 | const decl_name = try o.builder.metadataString(decl.name.toSlice(ip)); |
| 1644 | const link_name = try o.builder.metadataStringFromStrtabString(function_index.name(&o.builder)); |
| 1641 | 1645 | |
| 1642 | 1646 | const subprogram = try o.builder.debugSubprogram( |
| 1643 | 1647 | file, |
| 1644 | | try o.builder.metadataString(decl.name.toSlice(ip)), |
| 1645 | | try o.builder.metadataStringFromStrtabString(function_index.name(&o.builder)), |
| 1648 | scope, |
| 1649 | decl_name, |
| 1650 | link_name, |
| 1646 | 1651 | line_number, |
| 1647 | 1652 | line_number + func.lbrace_line, |
| 1648 | 1653 | debug_decl_type, |
| ... | ... | @@ -1659,6 +1664,7 @@ pub const Object = struct { |
| 1659 | 1664 | }, |
| 1660 | 1665 | o.debug_compile_unit, |
| 1661 | 1666 | ); |
| 1667 | |
| 1662 | 1668 | function_index.setSubprogram(subprogram, &o.builder); |
| 1663 | 1669 | break :debug_info .{ file, subprogram }; |
| 1664 | 1670 | } else .{.none} ** 2; |
| ... | ... | @@ -1906,6 +1912,7 @@ pub const Object = struct { |
| 1906 | 1912 | pub fn lowerDebugType( |
| 1907 | 1913 | o: *Object, |
| 1908 | 1914 | ty: Type, |
| 1915 | required_by_runtime: bool, |
| 1909 | 1916 | ) Allocator.Error!Builder.Metadata { |
| 1910 | 1917 | assert(!o.builder.strip); |
| 1911 | 1918 | |
| ... | ... | @@ -1915,7 +1922,13 @@ pub const Object = struct { |
| 1915 | 1922 | const zcu = pt.zcu; |
| 1916 | 1923 | const ip = &zcu.intern_pool; |
| 1917 | 1924 | |
| 1918 | | if (o.debug_type_map.get(ty)) |debug_type| return debug_type; |
| 1925 | if (o.debug_type_map.get(ty)) |debug_type| { |
| 1926 | if (required_by_runtime) { |
| 1927 | if (o.debug_unresolved_namespace_scopes.getEntry(ty)) |entry| |
| 1928 | entry.value_ptr.* = true; |
| 1929 | } |
| 1930 | return debug_type; |
| 1931 | } |
| 1919 | 1932 | |
| 1920 | 1933 | switch (ty.zigTypeTag(zcu)) { |
| 1921 | 1934 | .Void, |
| ... | ... | @@ -1930,10 +1943,9 @@ pub const Object = struct { |
| 1930 | 1943 | }, |
| 1931 | 1944 | .Int => { |
| 1932 | 1945 | const info = ty.intInfo(zcu); |
| 1933 | | assert(info.bits != 0); |
| 1934 | | const name = try o.allocTypeName(ty); |
| 1935 | | defer gpa.free(name); |
| 1936 | | const builder_name = try o.builder.metadataString(name); |
| 1946 | const int_name = try o.allocTypeName(ty); |
| 1947 | defer gpa.free(int_name); |
| 1948 | const builder_name = try o.builder.metadataString(int_name); |
| 1937 | 1949 | const debug_bits = ty.abiSize(pt) * 8; // lldb cannot handle non-byte sized types |
| 1938 | 1950 | const debug_int_type = switch (info.signedness) { |
| 1939 | 1951 | .signed => try o.builder.debugSignedType(builder_name, debug_bits), |
| ... | ... | @@ -1942,68 +1954,12 @@ pub const Object = struct { |
| 1942 | 1954 | try o.debug_type_map.put(gpa, ty, debug_int_type); |
| 1943 | 1955 | return debug_int_type; |
| 1944 | 1956 | }, |
| 1945 | | .Enum => { |
| 1946 | | const owner_decl_index = ty.getOwnerDecl(zcu); |
| 1947 | | const owner_decl = zcu.declPtr(owner_decl_index); |
| 1948 | | |
| 1949 | | if (!ty.hasRuntimeBitsIgnoreComptime(pt)) { |
| 1950 | | const debug_enum_type = try o.makeEmptyNamespaceDebugType(owner_decl_index); |
| 1951 | | try o.debug_type_map.put(gpa, ty, debug_enum_type); |
| 1952 | | return debug_enum_type; |
| 1953 | | } |
| 1954 | | |
| 1955 | | const enum_type = ip.loadEnumType(ty.toIntern()); |
| 1956 | | |
| 1957 | | const enumerators = try gpa.alloc(Builder.Metadata, enum_type.names.len); |
| 1958 | | defer gpa.free(enumerators); |
| 1959 | | |
| 1960 | | const int_ty = Type.fromInterned(enum_type.tag_ty); |
| 1961 | | const int_info = ty.intInfo(zcu); |
| 1962 | | assert(int_info.bits != 0); |
| 1963 | | |
| 1964 | | for (enum_type.names.get(ip), 0..) |field_name_ip, i| { |
| 1965 | | var bigint_space: Value.BigIntSpace = undefined; |
| 1966 | | const bigint = if (enum_type.values.len != 0) |
| 1967 | | Value.fromInterned(enum_type.values.get(ip)[i]).toBigInt(&bigint_space, pt) |
| 1968 | | else |
| 1969 | | std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst(); |
| 1970 | | |
| 1971 | | enumerators[i] = try o.builder.debugEnumerator( |
| 1972 | | try o.builder.metadataString(field_name_ip.toSlice(ip)), |
| 1973 | | int_info.signedness == .unsigned, |
| 1974 | | int_info.bits, |
| 1975 | | bigint, |
| 1976 | | ); |
| 1977 | | } |
| 1978 | | |
| 1979 | | const file_scope = zcu.namespacePtr(owner_decl.src_namespace).fileScope(zcu); |
| 1980 | | const file = try o.getDebugFile(file_scope); |
| 1981 | | const scope = try o.namespaceToDebugScope(owner_decl.src_namespace); |
| 1982 | | |
| 1983 | | const name = try o.allocTypeName(ty); |
| 1984 | | defer gpa.free(name); |
| 1985 | | |
| 1986 | | const debug_enum_type = try o.builder.debugEnumerationType( |
| 1987 | | try o.builder.metadataString(name), |
| 1988 | | file, |
| 1989 | | scope, |
| 1990 | | owner_decl.typeSrcLine(zcu) + 1, // Line |
| 1991 | | try o.lowerDebugType(int_ty), |
| 1992 | | ty.abiSize(pt) * 8, |
| 1993 | | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, |
| 1994 | | try o.builder.debugTuple(enumerators), |
| 1995 | | ); |
| 1996 | | |
| 1997 | | try o.debug_type_map.put(gpa, ty, debug_enum_type); |
| 1998 | | try o.debug_enums.append(gpa, debug_enum_type); |
| 1999 | | return debug_enum_type; |
| 2000 | | }, |
| 2001 | 1957 | .Float => { |
| 2002 | 1958 | const bits = ty.floatBits(target); |
| 2003 | | const name = try o.allocTypeName(ty); |
| 2004 | | defer gpa.free(name); |
| 1959 | const float_name = try o.allocTypeName(ty); |
| 1960 | defer gpa.free(float_name); |
| 2005 | 1961 | const debug_float_type = try o.builder.debugFloatType( |
| 2006 | | try o.builder.metadataString(name), |
| 1962 | try o.builder.metadataString(float_name), |
| 2007 | 1963 | bits, |
| 2008 | 1964 | ); |
| 2009 | 1965 | try o.debug_type_map.put(gpa, ty, debug_float_type); |
| ... | ... | @@ -2045,7 +2001,7 @@ pub const Object = struct { |
| 2045 | 2001 | }, |
| 2046 | 2002 | }, |
| 2047 | 2003 | }); |
| 2048 | | const debug_ptr_type = try o.lowerDebugType(bland_ptr_ty); |
| 2004 | const debug_ptr_type = try o.lowerDebugType(bland_ptr_ty, required_by_runtime); |
| 2049 | 2005 | try o.debug_type_map.put(gpa, ty, debug_ptr_type); |
| 2050 | 2006 | return debug_ptr_type; |
| 2051 | 2007 | } |
| ... | ... | @@ -2061,6 +2017,7 @@ pub const Object = struct { |
| 2061 | 2017 | |
| 2062 | 2018 | const name = try o.allocTypeName(ty); |
| 2063 | 2019 | defer gpa.free(name); |
| 2020 | |
| 2064 | 2021 | const line = 0; |
| 2065 | 2022 | |
| 2066 | 2023 | const ptr_size = ptr_ty.abiSize(pt); |
| ... | ... | @@ -2075,7 +2032,7 @@ pub const Object = struct { |
| 2075 | 2032 | .none, // File |
| 2076 | 2033 | debug_fwd_ref, |
| 2077 | 2034 | 0, // Line |
| 2078 | | try o.lowerDebugType(ptr_ty), |
| 2035 | try o.lowerDebugType(ptr_ty, required_by_runtime), |
| 2079 | 2036 | ptr_size * 8, |
| 2080 | 2037 | (ptr_align.toByteUnits() orelse 0) * 8, |
| 2081 | 2038 | 0, // Offset |
| ... | ... | @@ -2086,7 +2043,7 @@ pub const Object = struct { |
| 2086 | 2043 | .none, // File |
| 2087 | 2044 | debug_fwd_ref, |
| 2088 | 2045 | 0, // Line |
| 2089 | | try o.lowerDebugType(len_ty), |
| 2046 | try o.lowerDebugType(len_ty, required_by_runtime), |
| 2090 | 2047 | len_size * 8, |
| 2091 | 2048 | (len_align.toByteUnits() orelse 0) * 8, |
| 2092 | 2049 | len_offset * 8, |
| ... | ... | @@ -2104,6 +2061,7 @@ pub const Object = struct { |
| 2104 | 2061 | debug_ptr_type, |
| 2105 | 2062 | debug_len_type, |
| 2106 | 2063 | }), |
| 2064 | isByRef(ty, pt), |
| 2107 | 2065 | ); |
| 2108 | 2066 | |
| 2109 | 2067 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_slice_type); |
| ... | ... | @@ -2115,7 +2073,7 @@ pub const Object = struct { |
| 2115 | 2073 | return debug_slice_type; |
| 2116 | 2074 | } |
| 2117 | 2075 | |
| 2118 | | const debug_elem_ty = try o.lowerDebugType(Type.fromInterned(ptr_info.child)); |
| 2076 | const debug_elem_ty = try o.lowerDebugType(Type.fromInterned(ptr_info.child), required_by_runtime); |
| 2119 | 2077 | |
| 2120 | 2078 | const name = try o.allocTypeName(ty); |
| 2121 | 2079 | defer gpa.free(name); |
| ... | ... | @@ -2139,41 +2097,13 @@ pub const Object = struct { |
| 2139 | 2097 | |
| 2140 | 2098 | return debug_ptr_type; |
| 2141 | 2099 | }, |
| 2142 | | .Opaque => { |
| 2143 | | if (ty.toIntern() == .anyopaque_type) { |
| 2144 | | const debug_opaque_type = try o.builder.debugSignedType( |
| 2145 | | try o.builder.metadataString("anyopaque"), |
| 2146 | | 0, |
| 2147 | | ); |
| 2148 | | try o.debug_type_map.put(gpa, ty, debug_opaque_type); |
| 2149 | | return debug_opaque_type; |
| 2150 | | } |
| 2151 | | |
| 2152 | | const name = try o.allocTypeName(ty); |
| 2153 | | defer gpa.free(name); |
| 2154 | | const owner_decl_index = ty.getOwnerDecl(zcu); |
| 2155 | | const owner_decl = zcu.declPtr(owner_decl_index); |
| 2156 | | const file_scope = zcu.namespacePtr(owner_decl.src_namespace).fileScope(zcu); |
| 2157 | | const debug_opaque_type = try o.builder.debugStructType( |
| 2158 | | try o.builder.metadataString(name), |
| 2159 | | try o.getDebugFile(file_scope), |
| 2160 | | try o.namespaceToDebugScope(owner_decl.src_namespace), |
| 2161 | | owner_decl.typeSrcLine(zcu) + 1, // Line |
| 2162 | | .none, // Underlying type |
| 2163 | | 0, // Size |
| 2164 | | 0, // Align |
| 2165 | | .none, // Fields |
| 2166 | | ); |
| 2167 | | try o.debug_type_map.put(gpa, ty, debug_opaque_type); |
| 2168 | | return debug_opaque_type; |
| 2169 | | }, |
| 2170 | 2100 | .Array => { |
| 2171 | 2101 | const debug_array_type = try o.builder.debugArrayType( |
| 2172 | 2102 | .none, // Name |
| 2173 | 2103 | .none, // File |
| 2174 | 2104 | .none, // Scope |
| 2175 | 2105 | 0, // Line |
| 2176 | | try o.lowerDebugType(ty.childType(zcu)), |
| 2106 | try o.lowerDebugType(ty.childType(zcu), required_by_runtime), |
| 2177 | 2107 | ty.abiSize(pt) * 8, |
| 2178 | 2108 | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, |
| 2179 | 2109 | try o.builder.debugTuple(&.{ |
| ... | ... | @@ -2195,10 +2125,9 @@ pub const Object = struct { |
| 2195 | 2125 | const debug_elem_type = switch (elem_ty.zigTypeTag(zcu)) { |
| 2196 | 2126 | .Int => blk: { |
| 2197 | 2127 | const info = elem_ty.intInfo(zcu); |
| 2198 | | assert(info.bits != 0); |
| 2199 | | const name = try o.allocTypeName(ty); |
| 2200 | | defer gpa.free(name); |
| 2201 | | const builder_name = try o.builder.metadataString(name); |
| 2128 | const vec_name = try o.allocTypeName(ty); |
| 2129 | defer gpa.free(vec_name); |
| 2130 | const builder_name = try o.builder.metadataString(vec_name); |
| 2202 | 2131 | break :blk switch (info.signedness) { |
| 2203 | 2132 | .signed => try o.builder.debugSignedType(builder_name, info.bits), |
| 2204 | 2133 | .unsigned => try o.builder.debugUnsignedType(builder_name, info.bits), |
| ... | ... | @@ -2208,7 +2137,7 @@ pub const Object = struct { |
| 2208 | 2137 | try o.builder.metadataString("bool"), |
| 2209 | 2138 | 1, |
| 2210 | 2139 | ), |
| 2211 | | else => try o.lowerDebugType(ty.childType(zcu)), |
| 2140 | else => try o.lowerDebugType(ty.childType(zcu), required_by_runtime), |
| 2212 | 2141 | }; |
| 2213 | 2142 | |
| 2214 | 2143 | const debug_vector_type = try o.builder.debugVectorType( |
| ... | ... | @@ -2233,6 +2162,7 @@ pub const Object = struct { |
| 2233 | 2162 | .Optional => { |
| 2234 | 2163 | const name = try o.allocTypeName(ty); |
| 2235 | 2164 | defer gpa.free(name); |
| 2165 | |
| 2236 | 2166 | const child_ty = ty.optionalChild(zcu); |
| 2237 | 2167 | if (!child_ty.hasRuntimeBitsIgnoreComptime(pt)) { |
| 2238 | 2168 | const debug_bool_type = try o.builder.debugBoolType( |
| ... | ... | @@ -2249,7 +2179,7 @@ pub const Object = struct { |
| 2249 | 2179 | try o.debug_type_map.put(gpa, ty, debug_fwd_ref); |
| 2250 | 2180 | |
| 2251 | 2181 | if (ty.optionalReprIsPayload(zcu)) { |
| 2252 | | const debug_optional_type = try o.lowerDebugType(child_ty); |
| 2182 | const debug_optional_type = try o.lowerDebugType(child_ty, required_by_runtime); |
| 2253 | 2183 | |
| 2254 | 2184 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type); |
| 2255 | 2185 | |
| ... | ... | @@ -2272,7 +2202,7 @@ pub const Object = struct { |
| 2272 | 2202 | .none, // File |
| 2273 | 2203 | debug_fwd_ref, |
| 2274 | 2204 | 0, // Line |
| 2275 | | try o.lowerDebugType(child_ty), |
| 2205 | try o.lowerDebugType(child_ty, required_by_runtime), |
| 2276 | 2206 | payload_size * 8, |
| 2277 | 2207 | (payload_align.toByteUnits() orelse 0) * 8, |
| 2278 | 2208 | 0, // Offset |
| ... | ... | @@ -2283,7 +2213,7 @@ pub const Object = struct { |
| 2283 | 2213 | .none, |
| 2284 | 2214 | debug_fwd_ref, |
| 2285 | 2215 | 0, |
| 2286 | | try o.lowerDebugType(non_null_ty), |
| 2216 | try o.lowerDebugType(non_null_ty, required_by_runtime), |
| 2287 | 2217 | non_null_size * 8, |
| 2288 | 2218 | (non_null_align.toByteUnits() orelse 0) * 8, |
| 2289 | 2219 | non_null_offset * 8, |
| ... | ... | @@ -2301,6 +2231,7 @@ pub const Object = struct { |
| 2301 | 2231 | debug_data_type, |
| 2302 | 2232 | debug_some_type, |
| 2303 | 2233 | }), |
| 2234 | isByRef(ty, pt), |
| 2304 | 2235 | ); |
| 2305 | 2236 | |
| 2306 | 2237 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type); |
| ... | ... | @@ -2315,7 +2246,7 @@ pub const Object = struct { |
| 2315 | 2246 | const payload_ty = ty.errorUnionPayload(zcu); |
| 2316 | 2247 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) { |
| 2317 | 2248 | // TODO: Maybe remove? |
| 2318 | | const debug_error_union_type = try o.lowerDebugType(Type.anyerror); |
| 2249 | const debug_error_union_type = try o.lowerDebugType(Type.anyerror, required_by_runtime); |
| 2319 | 2250 | try o.debug_type_map.put(gpa, ty, debug_error_union_type); |
| 2320 | 2251 | return debug_error_union_type; |
| 2321 | 2252 | } |
| ... | ... | @@ -2352,7 +2283,7 @@ pub const Object = struct { |
| 2352 | 2283 | .none, // File |
| 2353 | 2284 | debug_fwd_ref, |
| 2354 | 2285 | 0, // Line |
| 2355 | | try o.lowerDebugType(Type.anyerror), |
| 2286 | try o.lowerDebugType(Type.anyerror, required_by_runtime), |
| 2356 | 2287 | error_size * 8, |
| 2357 | 2288 | (error_align.toByteUnits() orelse 0) * 8, |
| 2358 | 2289 | error_offset * 8, |
| ... | ... | @@ -2362,7 +2293,7 @@ pub const Object = struct { |
| 2362 | 2293 | .none, // File |
| 2363 | 2294 | debug_fwd_ref, |
| 2364 | 2295 | 0, // Line |
| 2365 | | try o.lowerDebugType(payload_ty), |
| 2296 | try o.lowerDebugType(payload_ty, required_by_runtime), |
| 2366 | 2297 | payload_size * 8, |
| 2367 | 2298 | (payload_align.toByteUnits() orelse 0) * 8, |
| 2368 | 2299 | payload_offset * 8, |
| ... | ... | @@ -2377,6 +2308,7 @@ pub const Object = struct { |
| 2377 | 2308 | ty.abiSize(pt) * 8, |
| 2378 | 2309 | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, |
| 2379 | 2310 | try o.builder.debugTuple(&fields), |
| 2311 | isByRef(ty, pt), |
| 2380 | 2312 | ); |
| 2381 | 2313 | |
| 2382 | 2314 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_error_union_type); |
| ... | ... | @@ -2392,383 +2324,483 @@ pub const Object = struct { |
| 2392 | 2324 | try o.debug_type_map.put(gpa, ty, debug_error_set); |
| 2393 | 2325 | return debug_error_set; |
| 2394 | 2326 | }, |
| 2395 | | .Struct => { |
| 2396 | | const name = try o.allocTypeName(ty); |
| 2397 | | defer gpa.free(name); |
| 2327 | .Fn => { |
| 2328 | const fn_info = zcu.typeToFunc(ty).?; |
| 2398 | 2329 | |
| 2399 | | if (zcu.typeToPackedStruct(ty)) |struct_type| { |
| 2400 | | const backing_int_ty = struct_type.backingIntTypeUnordered(ip); |
| 2401 | | if (backing_int_ty != .none) { |
| 2402 | | const info = Type.fromInterned(backing_int_ty).intInfo(zcu); |
| 2403 | | const builder_name = try o.builder.metadataString(name); |
| 2404 | | const debug_int_type = switch (info.signedness) { |
| 2405 | | .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(pt) * 8), |
| 2406 | | .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(pt) * 8), |
| 2407 | | }; |
| 2408 | | try o.debug_type_map.put(gpa, ty, debug_int_type); |
| 2409 | | return debug_int_type; |
| 2410 | | } |
| 2411 | | } |
| 2330 | var debug_param_types = std.ArrayList(Builder.Metadata).init(gpa); |
| 2331 | defer debug_param_types.deinit(); |
| 2412 | 2332 | |
| 2413 | | switch (ip.indexToKey(ty.toIntern())) { |
| 2414 | | .anon_struct_type => |tuple| { |
| 2415 | | var fields: std.ArrayListUnmanaged(Builder.Metadata) = .{}; |
| 2416 | | defer fields.deinit(gpa); |
| 2417 | | |
| 2418 | | try fields.ensureUnusedCapacity(gpa, tuple.types.len); |
| 2419 | | |
| 2420 | | comptime assert(struct_layout_version == 2); |
| 2421 | | var offset: u64 = 0; |
| 2422 | | |
| 2423 | | const debug_fwd_ref = try o.builder.debugForwardReference(); |
| 2424 | | |
| 2425 | | for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, field_val, i| { |
| 2426 | | if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(pt)) continue; |
| 2427 | | |
| 2428 | | const field_size = Type.fromInterned(field_ty).abiSize(pt); |
| 2429 | | const field_align = Type.fromInterned(field_ty).abiAlignment(pt); |
| 2430 | | const field_offset = field_align.forward(offset); |
| 2431 | | offset = field_offset + field_size; |
| 2432 | | |
| 2433 | | const field_name = if (tuple.names.len != 0) |
| 2434 | | tuple.names.get(ip)[i].toSlice(ip) |
| 2435 | | else |
| 2436 | | try std.fmt.allocPrintZ(gpa, "{d}", .{i}); |
| 2437 | | defer if (tuple.names.len == 0) gpa.free(field_name); |
| 2438 | | |
| 2439 | | fields.appendAssumeCapacity(try o.builder.debugMemberType( |
| 2440 | | try o.builder.metadataString(field_name), |
| 2441 | | .none, // File |
| 2442 | | debug_fwd_ref, |
| 2443 | | 0, |
| 2444 | | try o.lowerDebugType(Type.fromInterned(field_ty)), |
| 2445 | | field_size * 8, |
| 2446 | | (field_align.toByteUnits() orelse 0) * 8, |
| 2447 | | field_offset * 8, |
| 2448 | | )); |
| 2449 | | } |
| 2333 | try debug_param_types.ensureUnusedCapacity(3 + fn_info.param_types.len); |
| 2450 | 2334 | |
| 2451 | | const debug_struct_type = try o.builder.debugStructType( |
| 2452 | | try o.builder.metadataString(name), |
| 2453 | | .none, // File |
| 2454 | | o.debug_compile_unit, // Scope |
| 2455 | | 0, // Line |
| 2456 | | .none, // Underlying type |
| 2457 | | ty.abiSize(pt) * 8, |
| 2458 | | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, |
| 2459 | | try o.builder.debugTuple(fields.items), |
| 2460 | | ); |
| 2335 | // Return type goes first. |
| 2336 | if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(pt)) { |
| 2337 | const sret = firstParamSRet(fn_info, pt, target); |
| 2338 | const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type); |
| 2339 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty, required_by_runtime)); |
| 2461 | 2340 | |
| 2462 | | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_struct_type); |
| 2341 | if (sret) { |
| 2342 | const ptr_ty = try pt.singleMutPtrType(Type.fromInterned(fn_info.return_type)); |
| 2343 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty, required_by_runtime)); |
| 2344 | } |
| 2345 | } else { |
| 2346 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(Type.void, required_by_runtime)); |
| 2347 | } |
| 2463 | 2348 | |
| 2464 | | try o.debug_type_map.put(gpa, ty, debug_struct_type); |
| 2465 | | return debug_struct_type; |
| 2466 | | }, |
| 2467 | | .struct_type => { |
| 2468 | | if (!ip.loadStructType(ty.toIntern()).haveFieldTypes(ip)) { |
| 2469 | | // This can happen if a struct type makes it all the way to |
| 2470 | | // flush() without ever being instantiated or referenced (even |
| 2471 | | // via pointer). The only reason we are hearing about it now is |
| 2472 | | // that it is being used as a namespace to put other debug types |
| 2473 | | // into. Therefore we can satisfy this by making an empty namespace, |
| 2474 | | // rather than changing the frontend to unnecessarily resolve the |
| 2475 | | // struct field types. |
| 2476 | | const owner_decl_index = ty.getOwnerDecl(zcu); |
| 2477 | | const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index); |
| 2478 | | try o.debug_type_map.put(gpa, ty, debug_struct_type); |
| 2479 | | return debug_struct_type; |
| 2480 | | } |
| 2481 | | }, |
| 2482 | | else => {}, |
| 2349 | if (Type.fromInterned(fn_info.return_type).isError(zcu) and |
| 2350 | zcu.comp.config.any_error_tracing) |
| 2351 | { |
| 2352 | const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType()); |
| 2353 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty, required_by_runtime)); |
| 2483 | 2354 | } |
| 2484 | 2355 | |
| 2485 | | if (!ty.hasRuntimeBitsIgnoreComptime(pt)) { |
| 2486 | | const owner_decl_index = ty.getOwnerDecl(zcu); |
| 2487 | | const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index); |
| 2488 | | try o.debug_type_map.put(gpa, ty, debug_struct_type); |
| 2489 | | return debug_struct_type; |
| 2356 | for (0..fn_info.param_types.len) |i| { |
| 2357 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[i]); |
| 2358 | if (!param_ty.hasRuntimeBitsIgnoreComptime(pt)) continue; |
| 2359 | |
| 2360 | if (isByRef(param_ty, pt)) { |
| 2361 | const ptr_ty = try pt.singleMutPtrType(param_ty); |
| 2362 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty, required_by_runtime)); |
| 2363 | } else { |
| 2364 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(param_ty, required_by_runtime)); |
| 2365 | } |
| 2490 | 2366 | } |
| 2491 | 2367 | |
| 2492 | | const struct_type = zcu.typeToStruct(ty).?; |
| 2368 | const debug_function_type = try o.builder.debugSubroutineType( |
| 2369 | try o.builder.debugTuple(debug_param_types.items), |
| 2370 | ); |
| 2493 | 2371 | |
| 2494 | | var fields: std.ArrayListUnmanaged(Builder.Metadata) = .{}; |
| 2495 | | defer fields.deinit(gpa); |
| 2372 | try o.debug_type_map.put(gpa, ty, debug_function_type); |
| 2373 | return debug_function_type; |
| 2374 | }, |
| 2375 | .ComptimeInt => unreachable, |
| 2376 | .ComptimeFloat => unreachable, |
| 2377 | .Type => unreachable, |
| 2378 | .Undefined => unreachable, |
| 2379 | .Null => unreachable, |
| 2380 | .EnumLiteral => unreachable, |
| 2496 | 2381 | |
| 2497 | | try fields.ensureUnusedCapacity(gpa, struct_type.field_types.len); |
| 2382 | .Frame => @panic("TODO implement lowerDebugType for Frame types"), |
| 2383 | .AnyFrame => @panic("TODO implement lowerDebugType for AnyFrame types"), |
| 2384 | // These are the types that need a correct scope. |
| 2385 | .Enum, .Struct, .Union, .Opaque => {}, |
| 2386 | } |
| 2387 | const fwd_ref = try o.builder.debugForwardReference(); |
| 2388 | try o.debug_type_map.put(gpa, ty, fwd_ref); |
| 2389 | try o.debug_unresolved_namespace_scopes.put(gpa, ty, required_by_runtime); |
| 2498 | 2390 | |
| 2499 | | const debug_fwd_ref = try o.builder.debugForwardReference(); |
| 2391 | return fwd_ref; |
| 2392 | } |
| 2500 | 2393 | |
| 2501 | | // Set as forward reference while the type is lowered in case it references itself |
| 2502 | | try o.debug_type_map.put(gpa, ty, debug_fwd_ref); |
| 2394 | fn genNamespaces(o: *Object) !void { |
| 2395 | const gpa = o.gpa; |
| 2396 | const pt = o.pt; |
| 2397 | const zcu = pt.zcu; |
| 2398 | const ip = &zcu.intern_pool; |
| 2503 | 2399 | |
| 2504 | | comptime assert(struct_layout_version == 2); |
| 2505 | | var it = struct_type.iterateRuntimeOrder(ip); |
| 2506 | | while (it.next()) |field_index| { |
| 2507 | | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]); |
| 2508 | | if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue; |
| 2509 | | const field_size = field_ty.abiSize(pt); |
| 2510 | | const field_align = pt.structFieldAlignment( |
| 2511 | | struct_type.fieldAlign(ip, field_index), |
| 2512 | | field_ty, |
| 2513 | | struct_type.layout, |
| 2514 | | ); |
| 2515 | | const field_offset = ty.structFieldOffset(field_index, pt); |
| 2400 | var fields: std.ArrayListUnmanaged(Builder.Metadata) = .{}; |
| 2401 | defer fields.deinit(gpa); |
| 2516 | 2402 | |
| 2517 | | const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse |
| 2518 | | try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls); |
| 2403 | const unresolved = &o.debug_unresolved_namespace_scopes; |
| 2404 | var unresolved_i: usize = 0; |
| 2405 | while (unresolved_i < unresolved.count()) : (unresolved_i += 1) { |
| 2406 | const ty = unresolved.keys()[unresolved_i]; |
| 2407 | const required_by_runtime = unresolved.values()[unresolved_i]; |
| 2519 | 2408 | |
| 2520 | | fields.appendAssumeCapacity(try o.builder.debugMemberType( |
| 2521 | | try o.builder.metadataString(field_name.toSlice(ip)), |
| 2522 | | .none, // File |
| 2523 | | debug_fwd_ref, |
| 2524 | | 0, // Line |
| 2525 | | try o.lowerDebugType(field_ty), |
| 2526 | | field_size * 8, |
| 2527 | | (field_align.toByteUnits() orelse 0) * 8, |
| 2528 | | field_offset * 8, |
| 2529 | | )); |
| 2530 | | } |
| 2409 | const owner_decl_index = ty.getOwnerDeclOrNull(zcu); |
| 2410 | const owner_decl: ?*Zcu.Decl = |
| 2411 | if (owner_decl_index) |owner| ip.declPtr(owner) else null; |
| 2531 | 2412 | |
| 2532 | | const debug_struct_type = try o.builder.debugStructType( |
| 2533 | | try o.builder.metadataString(name), |
| 2534 | | .none, // File |
| 2535 | | o.debug_compile_unit, // Scope |
| 2536 | | 0, // Line |
| 2537 | | .none, // Underlying type |
| 2538 | | ty.abiSize(pt) * 8, |
| 2539 | | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, |
| 2540 | | try o.builder.debugTuple(fields.items), |
| 2541 | | ); |
| 2413 | const file = if (owner_decl) |owner| |
| 2414 | try o.getDebugFile(zcu.namespacePtr(owner.src_namespace).fileScope(zcu)) |
| 2415 | else |
| 2416 | .none; |
| 2417 | const scope = if (owner_decl) |owner| |
| 2418 | try o.namespaceToDebugScope(owner.src_namespace) |
| 2419 | else |
| 2420 | o.debug_compile_unit; |
| 2421 | const line = if (owner_decl) |owner| owner.typeSrcLine(zcu) + 1 else 0; |
| 2542 | 2422 | |
| 2543 | | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_struct_type); |
| 2423 | const name = if (owner_decl) |owner| owner.name.toSlice(ip) else try o.allocTypeName(ty); |
| 2424 | defer if (owner_decl == null) gpa.free(name); |
| 2544 | 2425 | |
| 2545 | | // Set to real type now that it has been lowered fully |
| 2546 | | const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable; |
| 2547 | | map_ptr.* = debug_struct_type; |
| 2426 | const fwd_ref = o.debug_type_map.get(ty).?; |
| 2548 | 2427 | |
| 2549 | | return debug_struct_type; |
| 2550 | | }, |
| 2551 | | .Union => { |
| 2552 | | const owner_decl_index = ty.getOwnerDecl(zcu); |
| 2428 | fields.clearRetainingCapacity(); |
| 2553 | 2429 | |
| 2554 | | const name = try o.allocTypeName(ty); |
| 2555 | | defer gpa.free(name); |
| 2430 | const ns = if (ty.getNamespace(zcu)) |n| n.unwrap() else null; |
| 2431 | if (ns) |ns_id| { |
| 2432 | const namespace = ip.namespacePtr(ns_id); |
| 2433 | try fields.ensureUnusedCapacity(gpa, namespace.decls.keys().len); |
| 2556 | 2434 | |
| 2557 | | const union_type = ip.loadUnionType(ty.toIntern()); |
| 2558 | | if (!union_type.haveFieldTypes(ip) or |
| 2559 | | !ty.hasRuntimeBitsIgnoreComptime(pt) or |
| 2560 | | !union_type.haveLayout(ip)) |
| 2561 | | { |
| 2562 | | const debug_union_type = try o.makeEmptyNamespaceDebugType(owner_decl_index); |
| 2563 | | try o.debug_type_map.put(gpa, ty, debug_union_type); |
| 2564 | | return debug_union_type; |
| 2435 | for (namespace.decls.keys()) |decl_id| { |
| 2436 | const decl = ip.declPtr(decl_id); |
| 2437 | const decl_name = decl.name.toSlice(ip); |
| 2438 | |
| 2439 | if (!decl.has_tv) continue; |
| 2440 | if (decl.kind != .named) continue; |
| 2441 | if (decl.analysis != .complete) continue; |
| 2442 | |
| 2443 | const decl_line = 0; |
| 2444 | |
| 2445 | if (decl.val.typeOf(zcu).ip_index == .type_type) { |
| 2446 | const nested_type = decl.val.toType(); |
| 2447 | // If this decl is the owner of the type, it will |
| 2448 | // already have been declared as a direct child and |
| 2449 | // will not need to be typedef'd. |
| 2450 | if (nested_type.getOwnerDeclOrNull(zcu)) |owner| { |
| 2451 | if (owner == decl_id) continue; |
| 2452 | } |
| 2453 | |
| 2454 | switch (nested_type.zigTypeTag(zcu)) { |
| 2455 | // We still may want these for a Zig expression |
| 2456 | // evaluator in debuggers, but for now they are |
| 2457 | // completely useless. |
| 2458 | .ComptimeInt, .ComptimeFloat, .Type, .Undefined, .Null, .EnumLiteral => continue, |
| 2459 | else => {}, |
| 2460 | } |
| 2461 | |
| 2462 | fields.appendAssumeCapacity(try o.builder.debugTypedef( |
| 2463 | try o.builder.metadataString(decl_name), |
| 2464 | try o.getDebugFile(namespace.fileScope(zcu)), |
| 2465 | fwd_ref, |
| 2466 | decl_line, |
| 2467 | try o.lowerDebugType(nested_type, false), |
| 2468 | 0, // Align |
| 2469 | )); |
| 2470 | } |
| 2565 | 2471 | } |
| 2472 | } |
| 2566 | 2473 | |
| 2567 | | const layout = pt.getUnionLayout(union_type); |
| 2474 | if (!required_by_runtime) { |
| 2475 | const res = try o.makeNamespaceDebugType(owner_decl_index.?, fields.items); |
| 2476 | o.builder.debugForwardReferenceSetType(fwd_ref, res); |
| 2477 | continue; |
| 2478 | } |
| 2568 | 2479 | |
| 2569 | | const debug_fwd_ref = try o.builder.debugForwardReference(); |
| 2480 | const res = switch (ty.zigTypeTag(zcu)) { |
| 2481 | .Enum => res: { |
| 2482 | if (!ty.hasRuntimeBitsIgnoreComptime(pt)) { |
| 2483 | break :res try o.makeNamespaceDebugType(owner_decl_index.?, fields.items); |
| 2484 | } |
| 2570 | 2485 | |
| 2571 | | // Set as forward reference while the type is lowered in case it references itself |
| 2572 | | try o.debug_type_map.put(gpa, ty, debug_fwd_ref); |
| 2486 | const enum_type = ip.loadEnumType(ty.toIntern()); |
| 2487 | |
| 2488 | const enumerators = try gpa.alloc(Builder.Metadata, enum_type.names.len); |
| 2489 | defer gpa.free(enumerators); |
| 2490 | |
| 2491 | const int_ty = Type.fromInterned(enum_type.tag_ty); |
| 2492 | const int_info = ty.intInfo(zcu); |
| 2493 | assert(int_info.bits != 0); |
| 2494 | |
| 2495 | for (enum_type.names.get(ip), 0..) |field_name_ip, i| { |
| 2496 | var bigint_space: Value.BigIntSpace = undefined; |
| 2497 | const bigint = if (enum_type.values.len != 0) |
| 2498 | Value.fromInterned(enum_type.values.get(ip)[i]).toBigInt(&bigint_space, pt) |
| 2499 | else |
| 2500 | std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst(); |
| 2501 | |
| 2502 | enumerators[i] = try o.builder.debugEnumerator( |
| 2503 | try o.builder.metadataString(field_name_ip.toSlice(ip)), |
| 2504 | int_info.signedness == .unsigned, |
| 2505 | int_info.bits, |
| 2506 | bigint, |
| 2507 | ); |
| 2508 | } |
| 2573 | 2509 | |
| 2574 | | if (layout.payload_size == 0) { |
| 2575 | | const debug_union_type = try o.builder.debugStructType( |
| 2510 | const debug_enum_type = try o.builder.debugEnumerationType( |
| 2576 | 2511 | try o.builder.metadataString(name), |
| 2577 | | .none, // File |
| 2578 | | o.debug_compile_unit, // Scope |
| 2579 | | 0, // Line |
| 2580 | | .none, // Underlying type |
| 2512 | file, |
| 2513 | scope, |
| 2514 | line, |
| 2515 | try o.lowerDebugType(int_ty, required_by_runtime), |
| 2581 | 2516 | ty.abiSize(pt) * 8, |
| 2582 | 2517 | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, |
| 2583 | | try o.builder.debugTuple( |
| 2584 | | &.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty))}, |
| 2585 | | ), |
| 2518 | try o.builder.debugTuple(enumerators), |
| 2586 | 2519 | ); |
| 2587 | 2520 | |
| 2588 | | // Set to real type now that it has been lowered fully |
| 2589 | | const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable; |
| 2590 | | map_ptr.* = debug_union_type; |
| 2591 | | |
| 2592 | | return debug_union_type; |
| 2593 | | } |
| 2521 | try o.debug_enums.append(gpa, debug_enum_type); |
| 2522 | break :res debug_enum_type; |
| 2523 | }, |
| 2524 | .Opaque => res: { |
| 2525 | if (ty.toIntern() == .anyopaque_type) { |
| 2526 | break :res try o.builder.debugSignedType( |
| 2527 | try o.builder.metadataString("anyopaque"), |
| 2528 | 0, |
| 2529 | ); |
| 2530 | } |
| 2594 | 2531 | |
| 2595 | | var fields: std.ArrayListUnmanaged(Builder.Metadata) = .{}; |
| 2596 | | defer fields.deinit(gpa); |
| 2532 | const debug_opaque_type = try o.builder.debugStructType( |
| 2533 | try o.builder.metadataString(name), |
| 2534 | file, |
| 2535 | scope, |
| 2536 | line, |
| 2537 | .none, // Underlying type |
| 2538 | 0, // Size |
| 2539 | 0, // Align |
| 2540 | .none, // Fields |
| 2541 | false, // ByRef |
| 2542 | ); |
| 2543 | break :res debug_opaque_type; |
| 2544 | }, |
| 2545 | .Struct => res: { |
| 2546 | if (zcu.typeToPackedStruct(ty)) |struct_type| { |
| 2547 | const backing_int_ty = struct_type.backingIntTypeUnordered(ip); |
| 2548 | if (backing_int_ty != .none) { |
| 2549 | const info = Type.fromInterned(backing_int_ty).intInfo(zcu); |
| 2550 | const builder_name = try o.builder.metadataString(name); |
| 2551 | const debug_int_type = switch (info.signedness) { |
| 2552 | .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(pt) * 8), |
| 2553 | .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(pt) * 8), |
| 2554 | }; |
| 2555 | break :res debug_int_type; |
| 2556 | } |
| 2557 | } |
| 2597 | 2558 | |
| 2598 | | try fields.ensureUnusedCapacity(gpa, union_type.loadTagType(ip).names.len); |
| 2559 | switch (ip.indexToKey(ty.toIntern())) { |
| 2560 | .anon_struct_type => |tuple| { |
| 2561 | try fields.ensureUnusedCapacity(gpa, tuple.types.len); |
| 2562 | |
| 2563 | comptime assert(struct_layout_version == 2); |
| 2564 | var offset: u64 = 0; |
| 2565 | |
| 2566 | for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, field_val, i| { |
| 2567 | if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(pt)) continue; |
| 2568 | |
| 2569 | const field_size = Type.fromInterned(field_ty).abiSize(pt); |
| 2570 | const field_align = Type.fromInterned(field_ty).abiAlignment(pt); |
| 2571 | const field_offset = field_align.forward(offset); |
| 2572 | offset = field_offset + field_size; |
| 2573 | |
| 2574 | const field_name = if (tuple.names.len != 0) |
| 2575 | tuple.names.get(ip)[i].toSlice(ip) |
| 2576 | else |
| 2577 | try std.fmt.allocPrintZ(gpa, "{d}", .{i}); |
| 2578 | defer if (tuple.names.len == 0) gpa.free(field_name); |
| 2579 | |
| 2580 | fields.appendAssumeCapacity(try o.builder.debugMemberType( |
| 2581 | try o.builder.metadataString(field_name), |
| 2582 | .none, // File |
| 2583 | fwd_ref, |
| 2584 | 0, |
| 2585 | try o.lowerDebugType(Type.fromInterned(field_ty), required_by_runtime), |
| 2586 | field_size * 8, |
| 2587 | (field_align.toByteUnits() orelse 0) * 8, |
| 2588 | field_offset * 8, |
| 2589 | )); |
| 2590 | } |
| 2599 | 2591 | |
| 2600 | | const debug_union_fwd_ref = if (layout.tag_size == 0) |
| 2601 | | debug_fwd_ref |
| 2602 | | else |
| 2603 | | try o.builder.debugForwardReference(); |
| 2592 | const debug_struct_type = try o.builder.debugStructType( |
| 2593 | try o.builder.metadataString(name), |
| 2594 | file, |
| 2595 | scope, |
| 2596 | 0, // Line |
| 2597 | .none, // Underlying type |
| 2598 | ty.abiSize(pt) * 8, |
| 2599 | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, |
| 2600 | try o.builder.debugTuple(fields.items), |
| 2601 | isByRef(ty, pt), |
| 2602 | ); |
| 2604 | 2603 | |
| 2605 | | const tag_type = union_type.loadTagType(ip); |
| 2604 | break :res debug_struct_type; |
| 2605 | }, |
| 2606 | else => {}, |
| 2607 | } |
| 2606 | 2608 | |
| 2607 | | for (0..tag_type.names.len) |field_index| { |
| 2608 | | const field_ty = union_type.field_types.get(ip)[field_index]; |
| 2609 | | if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue; |
| 2609 | if (!ty.hasRuntimeBitsIgnoreComptime(pt)) { |
| 2610 | break :res try o.makeNamespaceDebugType(owner_decl_index.?, fields.items); |
| 2611 | } |
| 2612 | const struct_type = zcu.typeToStruct(ty).?; |
| 2610 | 2613 | |
| 2611 | | const field_size = Type.fromInterned(field_ty).abiSize(pt); |
| 2612 | | const field_align: InternPool.Alignment = switch (union_type.flagsUnordered(ip).layout) { |
| 2613 | | .@"packed" => .none, |
| 2614 | | .auto, .@"extern" => pt.unionFieldNormalAlignment(union_type, @intCast(field_index)), |
| 2615 | | }; |
| 2614 | if (!struct_type.haveLayout(ip) or !struct_type.haveFieldTypes(ip)) { |
| 2615 | break :res try o.makeNamespaceDebugType(owner_decl_index.?, fields.items); |
| 2616 | } |
| 2616 | 2617 | |
| 2617 | | const field_name = tag_type.names.get(ip)[field_index]; |
| 2618 | | fields.appendAssumeCapacity(try o.builder.debugMemberType( |
| 2619 | | try o.builder.metadataString(field_name.toSlice(ip)), |
| 2620 | | .none, // File |
| 2621 | | debug_union_fwd_ref, |
| 2622 | | 0, // Line |
| 2623 | | try o.lowerDebugType(Type.fromInterned(field_ty)), |
| 2624 | | field_size * 8, |
| 2625 | | (field_align.toByteUnits() orelse 0) * 8, |
| 2626 | | 0, // Offset |
| 2627 | | )); |
| 2628 | | } |
| 2618 | try fields.ensureUnusedCapacity(gpa, struct_type.field_types.len); |
| 2629 | 2619 | |
| 2630 | | var union_name_buf: ?[:0]const u8 = null; |
| 2631 | | defer if (union_name_buf) |buf| gpa.free(buf); |
| 2632 | | const union_name = if (layout.tag_size == 0) name else name: { |
| 2633 | | union_name_buf = try std.fmt.allocPrintZ(gpa, "{s}:Payload", .{name}); |
| 2634 | | break :name union_name_buf.?; |
| 2635 | | }; |
| 2620 | comptime assert(struct_layout_version == 2); |
| 2621 | var it = struct_type.iterateRuntimeOrder(ip); |
| 2622 | while (it.next()) |field_index| { |
| 2623 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]); |
| 2624 | if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue; |
| 2625 | const field_size = field_ty.abiSize(pt); |
| 2626 | const field_align = pt.structFieldAlignment( |
| 2627 | struct_type.fieldAlign(ip, field_index), |
| 2628 | field_ty, |
| 2629 | struct_type.layout, |
| 2630 | ); |
| 2631 | const field_offset = ty.structFieldOffset(field_index, pt); |
| 2636 | 2632 | |
| 2637 | | const debug_union_type = try o.builder.debugUnionType( |
| 2638 | | try o.builder.metadataString(union_name), |
| 2639 | | .none, // File |
| 2640 | | o.debug_compile_unit, // Scope |
| 2641 | | 0, // Line |
| 2642 | | .none, // Underlying type |
| 2643 | | ty.abiSize(pt) * 8, |
| 2644 | | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, |
| 2645 | | try o.builder.debugTuple(fields.items), |
| 2646 | | ); |
| 2633 | const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse |
| 2634 | try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls); |
| 2647 | 2635 | |
| 2648 | | o.builder.debugForwardReferenceSetType(debug_union_fwd_ref, debug_union_type); |
| 2636 | fields.appendAssumeCapacity(try o.builder.debugMemberType( |
| 2637 | try o.builder.metadataString(field_name.toSlice(ip)), |
| 2638 | file, |
| 2639 | fwd_ref, |
| 2640 | 0, // Line |
| 2641 | try o.lowerDebugType(field_ty, required_by_runtime), |
| 2642 | field_size * 8, |
| 2643 | (field_align.toByteUnits() orelse 0) * 8, |
| 2644 | field_offset * 8, |
| 2645 | )); |
| 2646 | } |
| 2649 | 2647 | |
| 2650 | | if (layout.tag_size == 0) { |
| 2651 | | // Set to real type now that it has been lowered fully |
| 2652 | | const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable; |
| 2653 | | map_ptr.* = debug_union_type; |
| 2648 | const debug_struct_type = try o.builder.debugStructType( |
| 2649 | try o.builder.metadataString(name), |
| 2650 | file, |
| 2651 | scope, |
| 2652 | line, |
| 2653 | .none, // Underlying type |
| 2654 | ty.abiSize(pt) * 8, |
| 2655 | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, |
| 2656 | try o.builder.debugTuple(fields.items), |
| 2657 | isByRef(ty, pt), |
| 2658 | ); |
| 2654 | 2659 | |
| 2655 | | return debug_union_type; |
| 2656 | | } |
| 2660 | break :res debug_struct_type; |
| 2661 | }, |
| 2662 | .Union => res: { |
| 2663 | const union_type = ip.loadUnionType(ty.toIntern()); |
| 2664 | if (!union_type.haveFieldTypes(ip) or |
| 2665 | !ty.hasRuntimeBitsIgnoreComptime(pt) or |
| 2666 | !union_type.haveLayout(ip)) |
| 2667 | { |
| 2668 | break :res try o.makeNamespaceDebugType(owner_decl_index.?, fields.items); |
| 2669 | } |
| 2657 | 2670 | |
| 2658 | | var tag_offset: u64 = undefined; |
| 2659 | | var payload_offset: u64 = undefined; |
| 2660 | | if (layout.tag_align.compare(.gte, layout.payload_align)) { |
| 2661 | | tag_offset = 0; |
| 2662 | | payload_offset = layout.payload_align.forward(layout.tag_size); |
| 2663 | | } else { |
| 2664 | | payload_offset = 0; |
| 2665 | | tag_offset = layout.tag_align.forward(layout.payload_size); |
| 2666 | | } |
| 2671 | const layout = pt.getUnionLayout(union_type); |
| 2667 | 2672 | |
| 2668 | | const debug_tag_type = try o.builder.debugMemberType( |
| 2669 | | try o.builder.metadataString("tag"), |
| 2670 | | .none, // File |
| 2671 | | debug_fwd_ref, |
| 2672 | | 0, // Line |
| 2673 | | try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty)), |
| 2674 | | layout.tag_size * 8, |
| 2675 | | (layout.tag_align.toByteUnits() orelse 0) * 8, |
| 2676 | | tag_offset * 8, |
| 2677 | | ); |
| 2673 | if (layout.payload_size == 0) { |
| 2674 | const debug_union_type = try o.builder.debugStructType( |
| 2675 | try o.builder.metadataString(name), |
| 2676 | file, |
| 2677 | scope, |
| 2678 | 0, // Line |
| 2679 | .none, // Underlying type |
| 2680 | ty.abiSize(pt) * 8, |
| 2681 | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, |
| 2682 | try o.builder.debugTuple( |
| 2683 | &.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty), required_by_runtime)}, |
| 2684 | ), |
| 2685 | isByRef(ty, pt), |
| 2686 | ); |
| 2678 | 2687 | |
| 2679 | | const debug_payload_type = try o.builder.debugMemberType( |
| 2680 | | try o.builder.metadataString("payload"), |
| 2681 | | .none, // File |
| 2682 | | debug_fwd_ref, |
| 2683 | | 0, // Line |
| 2684 | | debug_union_type, |
| 2685 | | layout.payload_size * 8, |
| 2686 | | (layout.payload_align.toByteUnits() orelse 0) * 8, |
| 2687 | | payload_offset * 8, |
| 2688 | | ); |
| 2688 | break :res debug_union_type; |
| 2689 | } |
| 2689 | 2690 | |
| 2690 | | const full_fields: [2]Builder.Metadata = |
| 2691 | | if (layout.tag_align.compare(.gte, layout.payload_align)) |
| 2692 | | .{ debug_tag_type, debug_payload_type } |
| 2693 | | else |
| 2694 | | .{ debug_payload_type, debug_tag_type }; |
| 2691 | try fields.ensureUnusedCapacity(gpa, union_type.loadTagType(ip).names.len); |
| 2695 | 2692 | |
| 2696 | | const debug_tagged_union_type = try o.builder.debugStructType( |
| 2697 | | try o.builder.metadataString(name), |
| 2698 | | .none, // File |
| 2699 | | o.debug_compile_unit, // Scope |
| 2700 | | 0, // Line |
| 2701 | | .none, // Underlying type |
| 2702 | | ty.abiSize(pt) * 8, |
| 2703 | | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, |
| 2704 | | try o.builder.debugTuple(&full_fields), |
| 2705 | | ); |
| 2693 | const debug_union_fwd_ref = if (layout.tag_size == 0) |
| 2694 | fwd_ref |
| 2695 | else |
| 2696 | try o.builder.debugForwardReference(); |
| 2706 | 2697 | |
| 2707 | | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_tagged_union_type); |
| 2698 | const tag_type = union_type.loadTagType(ip); |
| 2708 | 2699 | |
| 2709 | | // Set to real type now that it has been lowered fully |
| 2710 | | const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable; |
| 2711 | | map_ptr.* = debug_tagged_union_type; |
| 2700 | for (0..tag_type.names.len) |field_index| { |
| 2701 | const field_ty = union_type.field_types.get(ip)[field_index]; |
| 2702 | if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue; |
| 2712 | 2703 | |
| 2713 | | return debug_tagged_union_type; |
| 2714 | | }, |
| 2715 | | .Fn => { |
| 2716 | | const fn_info = zcu.typeToFunc(ty).?; |
| 2704 | const field_size = Type.fromInterned(field_ty).abiSize(pt); |
| 2705 | const field_align: InternPool.Alignment = switch (union_type.flagsUnordered(ip).layout) { |
| 2706 | .@"packed" => .none, |
| 2707 | .auto, .@"extern" => pt.unionFieldNormalAlignment(union_type, @intCast(field_index)), |
| 2708 | }; |
| 2717 | 2709 | |
| 2718 | | var debug_param_types = std.ArrayList(Builder.Metadata).init(gpa); |
| 2719 | | defer debug_param_types.deinit(); |
| 2710 | const field_name = tag_type.names.get(ip)[field_index]; |
| 2711 | fields.appendAssumeCapacity(try o.builder.debugMemberType( |
| 2712 | try o.builder.metadataString(field_name.toSlice(ip)), |
| 2713 | file, |
| 2714 | debug_union_fwd_ref, |
| 2715 | 0, // Line |
| 2716 | try o.lowerDebugType(Type.fromInterned(field_ty), required_by_runtime), |
| 2717 | field_size * 8, |
| 2718 | (field_align.toByteUnits() orelse 0) * 8, |
| 2719 | 0, // Offset |
| 2720 | )); |
| 2721 | } |
| 2720 | 2722 | |
| 2721 | | try debug_param_types.ensureUnusedCapacity(3 + fn_info.param_types.len); |
| 2723 | var union_name_buf: ?[:0]const u8 = null; |
| 2724 | defer if (union_name_buf) |buf| gpa.free(buf); |
| 2725 | const union_name = if (layout.tag_size == 0) name else name: { |
| 2726 | union_name_buf = try std.fmt.allocPrintZ(gpa, "{s}:Payload", .{name}); |
| 2727 | break :name union_name_buf.?; |
| 2728 | }; |
| 2722 | 2729 | |
| 2723 | | // Return type goes first. |
| 2724 | | if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(pt)) { |
| 2725 | | const sret = firstParamSRet(fn_info, pt, target); |
| 2726 | | const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type); |
| 2727 | | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty)); |
| 2730 | const debug_union_type = try o.builder.debugUnionType( |
| 2731 | try o.builder.metadataString(union_name), |
| 2732 | file, |
| 2733 | scope, |
| 2734 | line, |
| 2735 | .none, // Underlying type |
| 2736 | ty.abiSize(pt) * 8, |
| 2737 | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, |
| 2738 | try o.builder.debugTuple(fields.items), |
| 2739 | isByRef(ty, pt), |
| 2740 | ); |
| 2728 | 2741 | |
| 2729 | | if (sret) { |
| 2730 | | const ptr_ty = try pt.singleMutPtrType(Type.fromInterned(fn_info.return_type)); |
| 2731 | | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty)); |
| 2742 | if (layout.tag_size == 0) { |
| 2743 | break :res debug_union_type; |
| 2732 | 2744 | } |
| 2733 | | } else { |
| 2734 | | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(Type.void)); |
| 2735 | | } |
| 2736 | | |
| 2737 | | if (Type.fromInterned(fn_info.return_type).isError(zcu) and |
| 2738 | | zcu.comp.config.any_error_tracing) |
| 2739 | | { |
| 2740 | | const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType()); |
| 2741 | | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty)); |
| 2742 | | } |
| 2743 | 2745 | |
| 2744 | | for (0..fn_info.param_types.len) |i| { |
| 2745 | | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[i]); |
| 2746 | | if (!param_ty.hasRuntimeBitsIgnoreComptime(pt)) continue; |
| 2746 | o.builder.debugForwardReferenceSetType(debug_union_fwd_ref, debug_union_type); |
| 2747 | 2747 | |
| 2748 | | if (isByRef(param_ty, pt)) { |
| 2749 | | const ptr_ty = try pt.singleMutPtrType(param_ty); |
| 2750 | | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty)); |
| 2748 | var tag_offset: u64 = undefined; |
| 2749 | var payload_offset: u64 = undefined; |
| 2750 | if (layout.tag_align.compare(.gte, layout.payload_align)) { |
| 2751 | tag_offset = 0; |
| 2752 | payload_offset = layout.payload_align.forward(layout.tag_size); |
| 2751 | 2753 | } else { |
| 2752 | | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(param_ty)); |
| 2754 | payload_offset = 0; |
| 2755 | tag_offset = layout.tag_align.forward(layout.payload_size); |
| 2753 | 2756 | } |
| 2754 | | } |
| 2755 | 2757 | |
| 2756 | | const debug_function_type = try o.builder.debugSubroutineType( |
| 2757 | | try o.builder.debugTuple(debug_param_types.items), |
| 2758 | | ); |
| 2758 | const debug_tag_type = try o.builder.debugMemberType( |
| 2759 | try o.builder.metadataString("tag"), |
| 2760 | file, // File |
| 2761 | fwd_ref, |
| 2762 | 0, // Line |
| 2763 | try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty), required_by_runtime), |
| 2764 | layout.tag_size * 8, |
| 2765 | (layout.tag_align.toByteUnits() orelse 0) * 8, |
| 2766 | tag_offset * 8, |
| 2767 | ); |
| 2759 | 2768 | |
| 2760 | | try o.debug_type_map.put(gpa, ty, debug_function_type); |
| 2761 | | return debug_function_type; |
| 2762 | | }, |
| 2763 | | .ComptimeInt => unreachable, |
| 2764 | | .ComptimeFloat => unreachable, |
| 2765 | | .Type => unreachable, |
| 2766 | | .Undefined => unreachable, |
| 2767 | | .Null => unreachable, |
| 2768 | | .EnumLiteral => unreachable, |
| 2769 | const debug_payload_type = try o.builder.debugMemberType( |
| 2770 | try o.builder.metadataString("payload"), |
| 2771 | file, |
| 2772 | fwd_ref, |
| 2773 | 0, // Line |
| 2774 | debug_union_type, |
| 2775 | layout.payload_size * 8, |
| 2776 | (layout.payload_align.toByteUnits() orelse 0) * 8, |
| 2777 | payload_offset * 8, |
| 2778 | ); |
| 2769 | 2779 | |
| 2770 | | .Frame => @panic("TODO implement lowerDebugType for Frame types"), |
| 2771 | | .AnyFrame => @panic("TODO implement lowerDebugType for AnyFrame types"), |
| 2780 | const full_fields: [2]Builder.Metadata = |
| 2781 | if (layout.tag_align.compare(.gte, layout.payload_align)) |
| 2782 | .{ debug_tag_type, debug_payload_type } |
| 2783 | else |
| 2784 | .{ debug_payload_type, debug_tag_type }; |
| 2785 | |
| 2786 | const debug_tagged_union_type = try o.builder.debugStructType( |
| 2787 | try o.builder.metadataString(name), |
| 2788 | file, // File |
| 2789 | scope, |
| 2790 | line, |
| 2791 | .none, // Underlying type |
| 2792 | ty.abiSize(pt) * 8, |
| 2793 | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, |
| 2794 | try o.builder.debugTuple(&full_fields), |
| 2795 | isByRef(ty, pt), |
| 2796 | ); |
| 2797 | |
| 2798 | break :res debug_tagged_union_type; |
| 2799 | }, |
| 2800 | else => unreachable, // Handled above. |
| 2801 | }; |
| 2802 | |
| 2803 | o.builder.debugForwardReferenceSetType(fwd_ref, res); |
| 2772 | 2804 | } |
| 2773 | 2805 | } |
| 2774 | 2806 | |
| ... | ... | @@ -2778,14 +2810,10 @@ pub const Object = struct { |
| 2778 | 2810 | const file_scope = namespace.fileScope(zcu); |
| 2779 | 2811 | if (namespace.parent == .none) return try o.getDebugFile(file_scope); |
| 2780 | 2812 | |
| 2781 | | const gop = try o.debug_unresolved_namespace_scopes.getOrPut(o.gpa, namespace_index); |
| 2782 | | |
| 2783 | | if (!gop.found_existing) gop.value_ptr.* = try o.builder.debugForwardReference(); |
| 2784 | | |
| 2785 | | return gop.value_ptr.*; |
| 2813 | return o.lowerDebugType(zcu.declPtr(namespace.decl_index).val.toType(), false); |
| 2786 | 2814 | } |
| 2787 | 2815 | |
| 2788 | | fn makeEmptyNamespaceDebugType(o: *Object, decl_index: InternPool.DeclIndex) !Builder.Metadata { |
| 2816 | fn makeNamespaceDebugType(o: *Object, decl_index: InternPool.DeclIndex, fields: []const Builder.Metadata) !Builder.Metadata { |
| 2789 | 2817 | const zcu = o.pt.zcu; |
| 2790 | 2818 | const decl = zcu.declPtr(decl_index); |
| 2791 | 2819 | const file_scope = zcu.namespacePtr(decl.src_namespace).fileScope(zcu); |
| ... | ... | @@ -2797,7 +2825,8 @@ pub const Object = struct { |
| 2797 | 2825 | .none, |
| 2798 | 2826 | 0, |
| 2799 | 2827 | 0, |
| 2800 | | .none, |
| 2828 | if (fields.len == 0) .none else try o.builder.debugTuple(fields), |
| 2829 | false, // is_byref |
| 2801 | 2830 | ); |
| 2802 | 2831 | } |
| 2803 | 2832 | |
| ... | ... | @@ -4711,16 +4740,33 @@ pub const DeclGen = struct { |
| 4711 | 4740 | if (!owner_mod.strip) { |
| 4712 | 4741 | const debug_file = try o.getDebugFile(file_scope); |
| 4713 | 4742 | |
| 4743 | const linkage_name = try o.builder.metadataStringFromStrtabString(variable_index.name(&o.builder)); |
| 4744 | const is_internal_linkage = !decl.isExtern(zcu); |
| 4745 | |
| 4746 | const ty = try o.lowerDebugType(decl.typeOf(zcu), true); |
| 4714 | 4747 | const debug_global_var = try o.builder.debugGlobalVar( |
| 4715 | | try o.builder.metadataString(decl.name.toSlice(ip)), // Name |
| 4716 | | try o.builder.metadataStringFromStrtabString(variable_index.name(&o.builder)), // Linkage name |
| 4717 | | debug_file, // File |
| 4718 | | debug_file, // Scope |
| 4748 | linkage_name, |
| 4749 | linkage_name, |
| 4750 | debug_file, |
| 4751 | debug_file, |
| 4719 | 4752 | line_number, |
| 4720 | | try o.lowerDebugType(decl.typeOf(zcu)), |
| 4753 | ty, |
| 4721 | 4754 | variable_index, |
| 4722 | | .{ .local = !decl.isExtern(zcu) }, |
| 4755 | is_internal_linkage, |
| 4723 | 4756 | ); |
| 4757 | if (is_internal_linkage) { |
| 4758 | const name = try o.builder.metadataString(decl.name.toSlice(ip)); |
| 4759 | const debug_scope = try o.namespaceToDebugScope(decl.src_namespace); |
| 4760 | |
| 4761 | const import = try o.builder.debugImportDeclaration( |
| 4762 | name, |
| 4763 | debug_file, |
| 4764 | debug_scope, |
| 4765 | line_number, |
| 4766 | debug_global_var, |
| 4767 | ); |
| 4768 | try o.debug_imports.append(o.gpa, import); |
| 4769 | } |
| 4724 | 4770 | |
| 4725 | 4771 | const debug_expression = try o.builder.debugExpression(&.{}); |
| 4726 | 4772 | |
| ... | ... | @@ -5171,11 +5217,12 @@ pub const FuncGen = struct { |
| 5171 | 5217 | |
| 5172 | 5218 | self.scope = try o.builder.debugSubprogram( |
| 5173 | 5219 | self.file, |
| 5220 | self.file, // TODO Get the correct scope into here—self.scope is the function's *inner* scope. |
| 5174 | 5221 | try o.builder.metadataString(decl.name.toSlice(&zcu.intern_pool)), |
| 5175 | 5222 | try o.builder.metadataString(decl.fqn.toSlice(&zcu.intern_pool)), |
| 5176 | 5223 | line_number, |
| 5177 | 5224 | line_number + func.lbrace_line, |
| 5178 | | try o.lowerDebugType(fn_ty), |
| 5225 | try o.lowerDebugType(fn_ty, true), |
| 5179 | 5226 | .{ |
| 5180 | 5227 | .di_flags = .{ .StaticMember = true }, |
| 5181 | 5228 | .sp_flags = .{ |
| ... | ... | @@ -6725,7 +6772,7 @@ pub const FuncGen = struct { |
| 6725 | 6772 | self.file, |
| 6726 | 6773 | self.scope, |
| 6727 | 6774 | self.prev_dbg_line, |
| 6728 | | try o.lowerDebugType(ptr_ty.childType(mod)), |
| 6775 | try o.lowerDebugType(ptr_ty.childType(mod), true), |
| 6729 | 6776 | ); |
| 6730 | 6777 | |
| 6731 | 6778 | _ = try self.wip.callIntrinsic( |
| ... | ... | @@ -6758,7 +6805,7 @@ pub const FuncGen = struct { |
| 6758 | 6805 | self.file, |
| 6759 | 6806 | self.scope, |
| 6760 | 6807 | self.prev_dbg_line, |
| 6761 | | try o.lowerDebugType(operand_ty), |
| 6808 | try o.lowerDebugType(operand_ty, true), |
| 6762 | 6809 | ); |
| 6763 | 6810 | |
| 6764 | 6811 | const pt = o.pt; |
| ... | ... | @@ -8872,7 +8919,7 @@ pub const FuncGen = struct { |
| 8872 | 8919 | self.file, |
| 8873 | 8920 | self.scope, |
| 8874 | 8921 | lbrace_line, |
| 8875 | | try o.lowerDebugType(inst_ty), |
| 8922 | try o.lowerDebugType(inst_ty, true), |
| 8876 | 8923 | @intCast(self.arg_index), |
| 8877 | 8924 | ); |
| 8878 | 8925 | |