| ... | @@ -805,14 +805,17 @@ pub const Object = struct { | ... | @@ -805,14 +805,17 @@ pub const Object = struct { |
| 805 | | 805 | |
| 806 | debug_enums_fwd_ref: Builder.Metadata, | 806 | debug_enums_fwd_ref: Builder.Metadata, |
| 807 | debug_globals_fwd_ref: Builder.Metadata, | 807 | debug_globals_fwd_ref: Builder.Metadata, |
| | 808 | debug_imports_fwd_ref: Builder.Metadata, |
| 808 | | 809 | |
| 809 | debug_enums: std.ArrayListUnmanaged(Builder.Metadata), | 810 | debug_enums: std.ArrayListUnmanaged(Builder.Metadata), |
| 810 | debug_globals: std.ArrayListUnmanaged(Builder.Metadata), | 811 | debug_globals: std.ArrayListUnmanaged(Builder.Metadata), |
| | 812 | debug_imports: std.ArrayListUnmanaged(Builder.Metadata), |
| 811 | | 813 | |
| 812 | debug_file_map: std.AutoHashMapUnmanaged(*const Zcu.File, Builder.Metadata), | 814 | debug_file_map: std.AutoHashMapUnmanaged(*const Zcu.File, Builder.Metadata), |
| 813 | debug_type_map: std.AutoHashMapUnmanaged(Type, Builder.Metadata), | 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 | target: std.Target, | 820 | target: std.Target, |
| 818 | /// Ideally we would use `llvm_module.getNamedFunction` to go from *Decl to LLVM function, | 821 | /// Ideally we would use `llvm_module.getNamedFunction` to go from *Decl to LLVM function, |
| ... | @@ -877,7 +880,7 @@ pub const Object = struct { | ... | @@ -877,7 +880,7 @@ pub const Object = struct { |
| 877 | | 880 | |
| 878 | builder.data_layout = try builder.fmt("{}", .{DataLayoutBuilder{ .target = target }}); | 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 | if (!builder.strip) | 884 | if (!builder.strip) |
| 882 | debug_info: { | 885 | debug_info: { |
| 883 | // We fully resolve all paths at this point to avoid lack of | 886 | // We fully resolve all paths at this point to avoid lack of |
| ... | @@ -909,6 +912,7 @@ pub const Object = struct { | ... | @@ -909,6 +912,7 @@ pub const Object = struct { |
| 909 | | 912 | |
| 910 | const debug_enums_fwd_ref = try builder.debugForwardReference(); | 913 | const debug_enums_fwd_ref = try builder.debugForwardReference(); |
| 911 | const debug_globals_fwd_ref = try builder.debugForwardReference(); | 914 | const debug_globals_fwd_ref = try builder.debugForwardReference(); |
| | 915 | const debug_imports_fwd_ref = try builder.debugForwardReference(); |
| 912 | | 916 | |
| 913 | const debug_compile_unit = try builder.debugCompileUnit( | 917 | const debug_compile_unit = try builder.debugCompileUnit( |
| 914 | debug_file, | 918 | debug_file, |
| ... | @@ -921,6 +925,7 @@ pub const Object = struct { | ... | @@ -921,6 +925,7 @@ pub const Object = struct { |
| 921 | }), | 925 | }), |
| 922 | debug_enums_fwd_ref, | 926 | debug_enums_fwd_ref, |
| 923 | debug_globals_fwd_ref, | 927 | debug_globals_fwd_ref, |
| | 928 | debug_imports_fwd_ref, |
| 924 | .{ .optimized = comp.root_mod.optimize_mode != .Debug }, | 929 | .{ .optimized = comp.root_mod.optimize_mode != .Debug }, |
| 925 | ); | 930 | ); |
| 926 | | 931 | |
| ... | @@ -976,8 +981,8 @@ pub const Object = struct { | ... | @@ -976,8 +981,8 @@ pub const Object = struct { |
| 976 | } | 981 | } |
| 977 | | 982 | |
| 978 | try builder.debugNamed(try builder.metadataString("llvm.dbg.cu"), &.{debug_compile_unit}); | 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 }; | 984 | break :debug_info .{ debug_compile_unit, debug_enums_fwd_ref, debug_globals_fwd_ref, debug_imports_fwd_ref }; |
| 980 | } else .{.none} ** 3; | 985 | } else .{.none} ** 4; |
| 981 | | 986 | |
| 982 | const obj = try arena.create(Object); | 987 | const obj = try arena.create(Object); |
| 983 | obj.* = .{ | 988 | obj.* = .{ |
| ... | @@ -990,8 +995,10 @@ pub const Object = struct { | ... | @@ -990,8 +995,10 @@ pub const Object = struct { |
| 990 | .debug_compile_unit = debug_compile_unit, | 995 | .debug_compile_unit = debug_compile_unit, |
| 991 | .debug_enums_fwd_ref = debug_enums_fwd_ref, | 996 | .debug_enums_fwd_ref = debug_enums_fwd_ref, |
| 992 | .debug_globals_fwd_ref = debug_globals_fwd_ref, | 997 | .debug_globals_fwd_ref = debug_globals_fwd_ref, |
| | 998 | .debug_imports_fwd_ref = debug_imports_fwd_ref, |
| 993 | .debug_enums = .{}, | 999 | .debug_enums = .{}, |
| 994 | .debug_globals = .{}, | 1000 | .debug_globals = .{}, |
| | 1001 | .debug_imports = .{}, |
| 995 | .debug_file_map = .{}, | 1002 | .debug_file_map = .{}, |
| 996 | .debug_type_map = .{}, | 1003 | .debug_type_map = .{}, |
| 997 | .debug_unresolved_namespace_scopes = .{}, | 1004 | .debug_unresolved_namespace_scopes = .{}, |
| ... | @@ -1133,18 +1140,7 @@ pub const Object = struct { | ... | @@ -1133,18 +1140,7 @@ pub const Object = struct { |
| 1133 | try self.genModuleLevelAssembly(); | 1140 | try self.genModuleLevelAssembly(); |
| 1134 | | 1141 | |
| 1135 | if (!self.builder.strip) { | 1142 | if (!self.builder.strip) { |
| 1136 | { | 1143 | try self.genNamespaces(); |
| 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 | } | | |
| 1148 | | 1144 | |
| 1149 | self.builder.debugForwardReferenceSetType( | 1145 | self.builder.debugForwardReferenceSetType( |
| 1150 | self.debug_enums_fwd_ref, | 1146 | self.debug_enums_fwd_ref, |
| ... | @@ -1155,6 +1151,11 @@ pub const Object = struct { | ... | @@ -1155,6 +1151,11 @@ pub const Object = struct { |
| 1155 | self.debug_globals_fwd_ref, | 1151 | self.debug_globals_fwd_ref, |
| 1156 | try self.builder.debugTuple(self.debug_globals.items), | 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,15 +1635,19 @@ pub const Object = struct { |
| 1634 | | 1635 | |
| 1635 | const file, const subprogram = if (!wip.strip) debug_info: { | 1636 | const file, const subprogram = if (!wip.strip) debug_info: { |
| 1636 | const file = try o.getDebugFile(file_scope); | 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 | const line_number = decl.navSrcLine(zcu) + 1; | 1640 | const line_number = decl.navSrcLine(zcu) + 1; |
| 1639 | const is_internal_linkage = decl.val.getExternFunc(zcu) == null; | 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 | const subprogram = try o.builder.debugSubprogram( | 1646 | const subprogram = try o.builder.debugSubprogram( |
| 1643 | file, | 1647 | file, |
| 1644 | try o.builder.metadataString(decl.name.toSlice(ip)), | 1648 | scope, |
| 1645 | try o.builder.metadataStringFromStrtabString(function_index.name(&o.builder)), | 1649 | decl_name, |
| | 1650 | link_name, |
| 1646 | line_number, | 1651 | line_number, |
| 1647 | line_number + func.lbrace_line, | 1652 | line_number + func.lbrace_line, |
| 1648 | debug_decl_type, | 1653 | debug_decl_type, |
| ... | @@ -1659,6 +1664,7 @@ pub const Object = struct { | ... | @@ -1659,6 +1664,7 @@ pub const Object = struct { |
| 1659 | }, | 1664 | }, |
| 1660 | o.debug_compile_unit, | 1665 | o.debug_compile_unit, |
| 1661 | ); | 1666 | ); |
| | 1667 | |
| 1662 | function_index.setSubprogram(subprogram, &o.builder); | 1668 | function_index.setSubprogram(subprogram, &o.builder); |
| 1663 | break :debug_info .{ file, subprogram }; | 1669 | break :debug_info .{ file, subprogram }; |
| 1664 | } else .{.none} ** 2; | 1670 | } else .{.none} ** 2; |
| ... | @@ -1906,6 +1912,7 @@ pub const Object = struct { | ... | @@ -1906,6 +1912,7 @@ pub const Object = struct { |
| 1906 | pub fn lowerDebugType( | 1912 | pub fn lowerDebugType( |
| 1907 | o: *Object, | 1913 | o: *Object, |
| 1908 | ty: Type, | 1914 | ty: Type, |
| | 1915 | required_by_runtime: bool, |
| 1909 | ) Allocator.Error!Builder.Metadata { | 1916 | ) Allocator.Error!Builder.Metadata { |
| 1910 | assert(!o.builder.strip); | 1917 | assert(!o.builder.strip); |
| 1911 | | 1918 | |
| ... | @@ -1915,7 +1922,13 @@ pub const Object = struct { | ... | @@ -1915,7 +1922,13 @@ pub const Object = struct { |
| 1915 | const zcu = pt.zcu; | 1922 | const zcu = pt.zcu; |
| 1916 | const ip = &zcu.intern_pool; | 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 | switch (ty.zigTypeTag(zcu)) { | 1933 | switch (ty.zigTypeTag(zcu)) { |
| 1921 | .Void, | 1934 | .Void, |
| ... | @@ -1930,10 +1943,9 @@ pub const Object = struct { | ... | @@ -1930,10 +1943,9 @@ pub const Object = struct { |
| 1930 | }, | 1943 | }, |
| 1931 | .Int => { | 1944 | .Int => { |
| 1932 | const info = ty.intInfo(zcu); | 1945 | const info = ty.intInfo(zcu); |
| 1933 | assert(info.bits != 0); | 1946 | const int_name = try o.allocTypeName(ty); |
| 1934 | const name = try o.allocTypeName(ty); | 1947 | defer gpa.free(int_name); |
| 1935 | defer gpa.free(name); | 1948 | const builder_name = try o.builder.metadataString(int_name); |
| 1936 | const builder_name = try o.builder.metadataString(name); | | |
| 1937 | const debug_bits = ty.abiSize(pt) * 8; // lldb cannot handle non-byte sized types | 1949 | const debug_bits = ty.abiSize(pt) * 8; // lldb cannot handle non-byte sized types |
| 1938 | const debug_int_type = switch (info.signedness) { | 1950 | const debug_int_type = switch (info.signedness) { |
| 1939 | .signed => try o.builder.debugSignedType(builder_name, debug_bits), | 1951 | .signed => try o.builder.debugSignedType(builder_name, debug_bits), |
| ... | @@ -1942,68 +1954,12 @@ pub const Object = struct { | ... | @@ -1942,68 +1954,12 @@ pub const Object = struct { |
| 1942 | try o.debug_type_map.put(gpa, ty, debug_int_type); | 1954 | try o.debug_type_map.put(gpa, ty, debug_int_type); |
| 1943 | return debug_int_type; | 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 | .Float => { | 1957 | .Float => { |
| 2002 | const bits = ty.floatBits(target); | 1958 | const bits = ty.floatBits(target); |
| 2003 | const name = try o.allocTypeName(ty); | 1959 | const float_name = try o.allocTypeName(ty); |
| 2004 | defer gpa.free(name); | 1960 | defer gpa.free(float_name); |
| 2005 | const debug_float_type = try o.builder.debugFloatType( | 1961 | const debug_float_type = try o.builder.debugFloatType( |
| 2006 | try o.builder.metadataString(name), | 1962 | try o.builder.metadataString(float_name), |
| 2007 | bits, | 1963 | bits, |
| 2008 | ); | 1964 | ); |
| 2009 | try o.debug_type_map.put(gpa, ty, debug_float_type); | 1965 | try o.debug_type_map.put(gpa, ty, debug_float_type); |
| ... | @@ -2045,7 +2001,7 @@ pub const Object = struct { | ... | @@ -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 | try o.debug_type_map.put(gpa, ty, debug_ptr_type); | 2005 | try o.debug_type_map.put(gpa, ty, debug_ptr_type); |
| 2050 | return debug_ptr_type; | 2006 | return debug_ptr_type; |
| 2051 | } | 2007 | } |
| ... | @@ -2061,6 +2017,7 @@ pub const Object = struct { | ... | @@ -2061,6 +2017,7 @@ pub const Object = struct { |
| 2061 | | 2017 | |
| 2062 | const name = try o.allocTypeName(ty); | 2018 | const name = try o.allocTypeName(ty); |
| 2063 | defer gpa.free(name); | 2019 | defer gpa.free(name); |
| | 2020 | |
| 2064 | const line = 0; | 2021 | const line = 0; |
| 2065 | | 2022 | |
| 2066 | const ptr_size = ptr_ty.abiSize(pt); | 2023 | const ptr_size = ptr_ty.abiSize(pt); |
| ... | @@ -2075,7 +2032,7 @@ pub const Object = struct { | ... | @@ -2075,7 +2032,7 @@ pub const Object = struct { |
| 2075 | .none, // File | 2032 | .none, // File |
| 2076 | debug_fwd_ref, | 2033 | debug_fwd_ref, |
| 2077 | 0, // Line | 2034 | 0, // Line |
| 2078 | try o.lowerDebugType(ptr_ty), | 2035 | try o.lowerDebugType(ptr_ty, required_by_runtime), |
| 2079 | ptr_size * 8, | 2036 | ptr_size * 8, |
| 2080 | (ptr_align.toByteUnits() orelse 0) * 8, | 2037 | (ptr_align.toByteUnits() orelse 0) * 8, |
| 2081 | 0, // Offset | 2038 | 0, // Offset |
| ... | @@ -2086,7 +2043,7 @@ pub const Object = struct { | ... | @@ -2086,7 +2043,7 @@ pub const Object = struct { |
| 2086 | .none, // File | 2043 | .none, // File |
| 2087 | debug_fwd_ref, | 2044 | debug_fwd_ref, |
| 2088 | 0, // Line | 2045 | 0, // Line |
| 2089 | try o.lowerDebugType(len_ty), | 2046 | try o.lowerDebugType(len_ty, required_by_runtime), |
| 2090 | len_size * 8, | 2047 | len_size * 8, |
| 2091 | (len_align.toByteUnits() orelse 0) * 8, | 2048 | (len_align.toByteUnits() orelse 0) * 8, |
| 2092 | len_offset * 8, | 2049 | len_offset * 8, |
| ... | @@ -2104,6 +2061,7 @@ pub const Object = struct { | ... | @@ -2104,6 +2061,7 @@ pub const Object = struct { |
| 2104 | debug_ptr_type, | 2061 | debug_ptr_type, |
| 2105 | debug_len_type, | 2062 | debug_len_type, |
| 2106 | }), | 2063 | }), |
| | 2064 | isByRef(ty, pt), |
| 2107 | ); | 2065 | ); |
| 2108 | | 2066 | |
| 2109 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_slice_type); | 2067 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_slice_type); |
| ... | @@ -2115,7 +2073,7 @@ pub const Object = struct { | ... | @@ -2115,7 +2073,7 @@ pub const Object = struct { |
| 2115 | return debug_slice_type; | 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 | const name = try o.allocTypeName(ty); | 2078 | const name = try o.allocTypeName(ty); |
| 2121 | defer gpa.free(name); | 2079 | defer gpa.free(name); |
| ... | @@ -2139,41 +2097,13 @@ pub const Object = struct { | ... | @@ -2139,41 +2097,13 @@ pub const Object = struct { |
| 2139 | | 2097 | |
| 2140 | return debug_ptr_type; | 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 | .Array => { | 2100 | .Array => { |
| 2171 | const debug_array_type = try o.builder.debugArrayType( | 2101 | const debug_array_type = try o.builder.debugArrayType( |
| 2172 | .none, // Name | 2102 | .none, // Name |
| 2173 | .none, // File | 2103 | .none, // File |
| 2174 | .none, // Scope | 2104 | .none, // Scope |
| 2175 | 0, // Line | 2105 | 0, // Line |
| 2176 | try o.lowerDebugType(ty.childType(zcu)), | 2106 | try o.lowerDebugType(ty.childType(zcu), required_by_runtime), |
| 2177 | ty.abiSize(pt) * 8, | 2107 | ty.abiSize(pt) * 8, |
| 2178 | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, | 2108 | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, |
| 2179 | try o.builder.debugTuple(&.{ | 2109 | try o.builder.debugTuple(&.{ |
| ... | @@ -2195,10 +2125,9 @@ pub const Object = struct { | ... | @@ -2195,10 +2125,9 @@ pub const Object = struct { |
| 2195 | const debug_elem_type = switch (elem_ty.zigTypeTag(zcu)) { | 2125 | const debug_elem_type = switch (elem_ty.zigTypeTag(zcu)) { |
| 2196 | .Int => blk: { | 2126 | .Int => blk: { |
| 2197 | const info = elem_ty.intInfo(zcu); | 2127 | const info = elem_ty.intInfo(zcu); |
| 2198 | assert(info.bits != 0); | 2128 | const vec_name = try o.allocTypeName(ty); |
| 2199 | const name = try o.allocTypeName(ty); | 2129 | defer gpa.free(vec_name); |
| 2200 | defer gpa.free(name); | 2130 | const builder_name = try o.builder.metadataString(vec_name); |
| 2201 | const builder_name = try o.builder.metadataString(name); | | |
| 2202 | break :blk switch (info.signedness) { | 2131 | break :blk switch (info.signedness) { |
| 2203 | .signed => try o.builder.debugSignedType(builder_name, info.bits), | 2132 | .signed => try o.builder.debugSignedType(builder_name, info.bits), |
| 2204 | .unsigned => try o.builder.debugUnsignedType(builder_name, info.bits), | 2133 | .unsigned => try o.builder.debugUnsignedType(builder_name, info.bits), |
| ... | @@ -2208,7 +2137,7 @@ pub const Object = struct { | ... | @@ -2208,7 +2137,7 @@ pub const Object = struct { |
| 2208 | try o.builder.metadataString("bool"), | 2137 | try o.builder.metadataString("bool"), |
| 2209 | 1, | 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 | const debug_vector_type = try o.builder.debugVectorType( | 2143 | const debug_vector_type = try o.builder.debugVectorType( |
| ... | @@ -2233,6 +2162,7 @@ pub const Object = struct { | ... | @@ -2233,6 +2162,7 @@ pub const Object = struct { |
| 2233 | .Optional => { | 2162 | .Optional => { |
| 2234 | const name = try o.allocTypeName(ty); | 2163 | const name = try o.allocTypeName(ty); |
| 2235 | defer gpa.free(name); | 2164 | defer gpa.free(name); |
| | 2165 | |
| 2236 | const child_ty = ty.optionalChild(zcu); | 2166 | const child_ty = ty.optionalChild(zcu); |
| 2237 | if (!child_ty.hasRuntimeBitsIgnoreComptime(pt)) { | 2167 | if (!child_ty.hasRuntimeBitsIgnoreComptime(pt)) { |
| 2238 | const debug_bool_type = try o.builder.debugBoolType( | 2168 | const debug_bool_type = try o.builder.debugBoolType( |
| ... | @@ -2249,7 +2179,7 @@ pub const Object = struct { | ... | @@ -2249,7 +2179,7 @@ pub const Object = struct { |
| 2249 | try o.debug_type_map.put(gpa, ty, debug_fwd_ref); | 2179 | try o.debug_type_map.put(gpa, ty, debug_fwd_ref); |
| 2250 | | 2180 | |
| 2251 | if (ty.optionalReprIsPayload(zcu)) { | 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 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type); | 2184 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type); |
| 2255 | | 2185 | |
| ... | @@ -2272,7 +2202,7 @@ pub const Object = struct { | ... | @@ -2272,7 +2202,7 @@ pub const Object = struct { |
| 2272 | .none, // File | 2202 | .none, // File |
| 2273 | debug_fwd_ref, | 2203 | debug_fwd_ref, |
| 2274 | 0, // Line | 2204 | 0, // Line |
| 2275 | try o.lowerDebugType(child_ty), | 2205 | try o.lowerDebugType(child_ty, required_by_runtime), |
| 2276 | payload_size * 8, | 2206 | payload_size * 8, |
| 2277 | (payload_align.toByteUnits() orelse 0) * 8, | 2207 | (payload_align.toByteUnits() orelse 0) * 8, |
| 2278 | 0, // Offset | 2208 | 0, // Offset |
| ... | @@ -2283,7 +2213,7 @@ pub const Object = struct { | ... | @@ -2283,7 +2213,7 @@ pub const Object = struct { |
| 2283 | .none, | 2213 | .none, |
| 2284 | debug_fwd_ref, | 2214 | debug_fwd_ref, |
| 2285 | 0, | 2215 | 0, |
| 2286 | try o.lowerDebugType(non_null_ty), | 2216 | try o.lowerDebugType(non_null_ty, required_by_runtime), |
| 2287 | non_null_size * 8, | 2217 | non_null_size * 8, |
| 2288 | (non_null_align.toByteUnits() orelse 0) * 8, | 2218 | (non_null_align.toByteUnits() orelse 0) * 8, |
| 2289 | non_null_offset * 8, | 2219 | non_null_offset * 8, |
| ... | @@ -2301,6 +2231,7 @@ pub const Object = struct { | ... | @@ -2301,6 +2231,7 @@ pub const Object = struct { |
| 2301 | debug_data_type, | 2231 | debug_data_type, |
| 2302 | debug_some_type, | 2232 | debug_some_type, |
| 2303 | }), | 2233 | }), |
| | 2234 | isByRef(ty, pt), |
| 2304 | ); | 2235 | ); |
| 2305 | | 2236 | |
| 2306 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type); | 2237 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type); |
| ... | @@ -2315,7 +2246,7 @@ pub const Object = struct { | ... | @@ -2315,7 +2246,7 @@ pub const Object = struct { |
| 2315 | const payload_ty = ty.errorUnionPayload(zcu); | 2246 | const payload_ty = ty.errorUnionPayload(zcu); |
| 2316 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) { | 2247 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) { |
| 2317 | // TODO: Maybe remove? | 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 | try o.debug_type_map.put(gpa, ty, debug_error_union_type); | 2250 | try o.debug_type_map.put(gpa, ty, debug_error_union_type); |
| 2320 | return debug_error_union_type; | 2251 | return debug_error_union_type; |
| 2321 | } | 2252 | } |
| ... | @@ -2352,7 +2283,7 @@ pub const Object = struct { | ... | @@ -2352,7 +2283,7 @@ pub const Object = struct { |
| 2352 | .none, // File | 2283 | .none, // File |
| 2353 | debug_fwd_ref, | 2284 | debug_fwd_ref, |
| 2354 | 0, // Line | 2285 | 0, // Line |
| 2355 | try o.lowerDebugType(Type.anyerror), | 2286 | try o.lowerDebugType(Type.anyerror, required_by_runtime), |
| 2356 | error_size * 8, | 2287 | error_size * 8, |
| 2357 | (error_align.toByteUnits() orelse 0) * 8, | 2288 | (error_align.toByteUnits() orelse 0) * 8, |
| 2358 | error_offset * 8, | 2289 | error_offset * 8, |
| ... | @@ -2362,7 +2293,7 @@ pub const Object = struct { | ... | @@ -2362,7 +2293,7 @@ pub const Object = struct { |
| 2362 | .none, // File | 2293 | .none, // File |
| 2363 | debug_fwd_ref, | 2294 | debug_fwd_ref, |
| 2364 | 0, // Line | 2295 | 0, // Line |
| 2365 | try o.lowerDebugType(payload_ty), | 2296 | try o.lowerDebugType(payload_ty, required_by_runtime), |
| 2366 | payload_size * 8, | 2297 | payload_size * 8, |
| 2367 | (payload_align.toByteUnits() orelse 0) * 8, | 2298 | (payload_align.toByteUnits() orelse 0) * 8, |
| 2368 | payload_offset * 8, | 2299 | payload_offset * 8, |
| ... | @@ -2377,6 +2308,7 @@ pub const Object = struct { | ... | @@ -2377,6 +2308,7 @@ pub const Object = struct { |
| 2377 | ty.abiSize(pt) * 8, | 2308 | ty.abiSize(pt) * 8, |
| 2378 | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, | 2309 | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, |
| 2379 | try o.builder.debugTuple(&fields), | 2310 | try o.builder.debugTuple(&fields), |
| | 2311 | isByRef(ty, pt), |
| 2380 | ); | 2312 | ); |
| 2381 | | 2313 | |
| 2382 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_error_union_type); | 2314 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_error_union_type); |
| ... | @@ -2392,383 +2324,483 @@ pub const Object = struct { | ... | @@ -2392,383 +2324,483 @@ pub const Object = struct { |
| 2392 | try o.debug_type_map.put(gpa, ty, debug_error_set); | 2324 | try o.debug_type_map.put(gpa, ty, debug_error_set); |
| 2393 | return debug_error_set; | 2325 | return debug_error_set; |
| 2394 | }, | 2326 | }, |
| 2395 | .Struct => { | 2327 | .Fn => { |
| 2396 | const name = try o.allocTypeName(ty); | 2328 | const fn_info = zcu.typeToFunc(ty).?; |
| 2397 | defer gpa.free(name); | | |
| 2398 | | 2329 | |
| 2399 | if (zcu.typeToPackedStruct(ty)) |struct_type| { | 2330 | var debug_param_types = std.ArrayList(Builder.Metadata).init(gpa); |
| 2400 | const backing_int_ty = struct_type.backingIntTypeUnordered(ip); | 2331 | defer debug_param_types.deinit(); |
| 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 | } | | |
| 2412 | | 2332 | |
| 2413 | switch (ip.indexToKey(ty.toIntern())) { | 2333 | try debug_param_types.ensureUnusedCapacity(3 + fn_info.param_types.len); |
| 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 | } | | |
| 2450 | | 2334 | |
| 2451 | const debug_struct_type = try o.builder.debugStructType( | 2335 | // Return type goes first. |
| 2452 | try o.builder.metadataString(name), | 2336 | if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(pt)) { |
| 2453 | .none, // File | 2337 | const sret = firstParamSRet(fn_info, pt, target); |
| 2454 | o.debug_compile_unit, // Scope | 2338 | const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type); |
| 2455 | 0, // Line | 2339 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty, required_by_runtime)); |
| 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 | ); | | |
| 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); | 2349 | if (Type.fromInterned(fn_info.return_type).isError(zcu) and |
| 2465 | return debug_struct_type; | 2350 | zcu.comp.config.any_error_tracing) |
| 2466 | }, | 2351 | { |
| 2467 | .struct_type => { | 2352 | const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType()); |
| 2468 | if (!ip.loadStructType(ty.toIntern()).haveFieldTypes(ip)) { | 2353 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty, required_by_runtime)); |
| 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 => {}, | | |
| 2483 | } | 2354 | } |
| 2484 | | 2355 | |
| 2485 | if (!ty.hasRuntimeBitsIgnoreComptime(pt)) { | 2356 | for (0..fn_info.param_types.len) |i| { |
| 2486 | const owner_decl_index = ty.getOwnerDecl(zcu); | 2357 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[i]); |
| 2487 | const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index); | 2358 | if (!param_ty.hasRuntimeBitsIgnoreComptime(pt)) continue; |
| 2488 | try o.debug_type_map.put(gpa, ty, debug_struct_type); | 2359 | |
| 2489 | return debug_struct_type; | 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) = .{}; | 2372 | try o.debug_type_map.put(gpa, ty, debug_function_type); |
| 2495 | defer fields.deinit(gpa); | 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 | 2394 | fn genNamespaces(o: *Object) !void { |
| 2502 | try o.debug_type_map.put(gpa, ty, debug_fwd_ref); | 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); | 2400 | var fields: std.ArrayListUnmanaged(Builder.Metadata) = .{}; |
| 2505 | var it = struct_type.iterateRuntimeOrder(ip); | 2401 | defer fields.deinit(gpa); |
| 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); | | |
| 2516 | | 2402 | |
| 2517 | const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse | 2403 | const unresolved = &o.debug_unresolved_namespace_scopes; |
| 2518 | try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls); | 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( | 2409 | const owner_decl_index = ty.getOwnerDeclOrNull(zcu); |
| 2521 | try o.builder.metadataString(field_name.toSlice(ip)), | 2410 | const owner_decl: ?*Zcu.Decl = |
| 2522 | .none, // File | 2411 | if (owner_decl_index) |owner| ip.declPtr(owner) else null; |
| 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 | } | | |
| 2531 | | 2412 | |
| 2532 | const debug_struct_type = try o.builder.debugStructType( | 2413 | const file = if (owner_decl) |owner| |
| 2533 | try o.builder.metadataString(name), | 2414 | try o.getDebugFile(zcu.namespacePtr(owner.src_namespace).fileScope(zcu)) |
| 2534 | .none, // File | 2415 | else |
| 2535 | o.debug_compile_unit, // Scope | 2416 | .none; |
| 2536 | 0, // Line | 2417 | const scope = if (owner_decl) |owner| |
| 2537 | .none, // Underlying type | 2418 | try o.namespaceToDebugScope(owner.src_namespace) |
| 2538 | ty.abiSize(pt) * 8, | 2419 | else |
| 2539 | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, | 2420 | o.debug_compile_unit; |
| 2540 | try o.builder.debugTuple(fields.items), | 2421 | const line = if (owner_decl) |owner| owner.typeSrcLine(zcu) + 1 else 0; |
| 2541 | ); | | |
| 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 | 2426 | const fwd_ref = o.debug_type_map.get(ty).?; |
| 2546 | const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable; | | |
| 2547 | map_ptr.* = debug_struct_type; | | |
| 2548 | | 2427 | |
| 2549 | return debug_struct_type; | 2428 | fields.clearRetainingCapacity(); |
| 2550 | }, | | |
| 2551 | .Union => { | | |
| 2552 | const owner_decl_index = ty.getOwnerDecl(zcu); | | |
| 2553 | | 2429 | |
| 2554 | const name = try o.allocTypeName(ty); | 2430 | const ns = if (ty.getNamespace(zcu)) |n| n.unwrap() else null; |
| 2555 | defer gpa.free(name); | 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()); | 2435 | for (namespace.decls.keys()) |decl_id| { |
| 2558 | if (!union_type.haveFieldTypes(ip) or | 2436 | const decl = ip.declPtr(decl_id); |
| 2559 | !ty.hasRuntimeBitsIgnoreComptime(pt) or | 2437 | const decl_name = decl.name.toSlice(ip); |
| 2560 | !union_type.haveLayout(ip)) | 2438 | |
| 2561 | { | 2439 | if (!decl.has_tv) continue; |
| 2562 | const debug_union_type = try o.makeEmptyNamespaceDebugType(owner_decl_index); | 2440 | if (decl.kind != .named) continue; |
| 2563 | try o.debug_type_map.put(gpa, ty, debug_union_type); | 2441 | if (decl.analysis != .complete) continue; |
| 2564 | return debug_union_type; | 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 | 2486 | const enum_type = ip.loadEnumType(ty.toIntern()); |
| 2572 | try o.debug_type_map.put(gpa, ty, debug_fwd_ref); | 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) { | 2510 | const debug_enum_type = try o.builder.debugEnumerationType( |
| 2575 | const debug_union_type = try o.builder.debugStructType( | | |
| 2576 | try o.builder.metadataString(name), | 2511 | try o.builder.metadataString(name), |
| 2577 | .none, // File | 2512 | file, |
| 2578 | o.debug_compile_unit, // Scope | 2513 | scope, |
| 2579 | 0, // Line | 2514 | line, |
| 2580 | .none, // Underlying type | 2515 | try o.lowerDebugType(int_ty, required_by_runtime), |
| 2581 | ty.abiSize(pt) * 8, | 2516 | ty.abiSize(pt) * 8, |
| 2582 | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, | 2517 | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, |
| 2583 | try o.builder.debugTuple( | 2518 | try o.builder.debugTuple(enumerators), |
| 2584 | &.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty))}, | | |
| 2585 | ), | | |
| 2586 | ); | 2519 | ); |
| 2587 | | 2520 | |
| 2588 | // Set to real type now that it has been lowered fully | 2521 | try o.debug_enums.append(gpa, debug_enum_type); |
| 2589 | const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable; | 2522 | break :res debug_enum_type; |
| 2590 | map_ptr.* = debug_union_type; | 2523 | }, |
| 2591 | | 2524 | .Opaque => res: { |
| 2592 | return debug_union_type; | 2525 | if (ty.toIntern() == .anyopaque_type) { |
| 2593 | } | 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) = .{}; | 2532 | const debug_opaque_type = try o.builder.debugStructType( |
| 2596 | defer fields.deinit(gpa); | 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) | 2592 | const debug_struct_type = try o.builder.debugStructType( |
| 2601 | debug_fwd_ref | 2593 | try o.builder.metadataString(name), |
| 2602 | else | 2594 | file, |
| 2603 | try o.builder.debugForwardReference(); | 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| { | 2609 | if (!ty.hasRuntimeBitsIgnoreComptime(pt)) { |
| 2608 | const field_ty = union_type.field_types.get(ip)[field_index]; | 2610 | break :res try o.makeNamespaceDebugType(owner_decl_index.?, fields.items); |
| 2609 | if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue; | 2611 | } |
| | 2612 | const struct_type = zcu.typeToStruct(ty).?; |
| 2610 | | 2613 | |
| 2611 | const field_size = Type.fromInterned(field_ty).abiSize(pt); | 2614 | if (!struct_type.haveLayout(ip) or !struct_type.haveFieldTypes(ip)) { |
| 2612 | const field_align: InternPool.Alignment = switch (union_type.flagsUnordered(ip).layout) { | 2615 | break :res try o.makeNamespaceDebugType(owner_decl_index.?, fields.items); |
| 2613 | .@"packed" => .none, | 2616 | } |
| 2614 | .auto, .@"extern" => pt.unionFieldNormalAlignment(union_type, @intCast(field_index)), | | |
| 2615 | }; | | |
| 2616 | | 2617 | |
| 2617 | const field_name = tag_type.names.get(ip)[field_index]; | 2618 | try fields.ensureUnusedCapacity(gpa, struct_type.field_types.len); |
| 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 | } | | |
| 2629 | | 2619 | |
| 2630 | var union_name_buf: ?[:0]const u8 = null; | 2620 | comptime assert(struct_layout_version == 2); |
| 2631 | defer if (union_name_buf) |buf| gpa.free(buf); | 2621 | var it = struct_type.iterateRuntimeOrder(ip); |
| 2632 | const union_name = if (layout.tag_size == 0) name else name: { | 2622 | while (it.next()) |field_index| { |
| 2633 | union_name_buf = try std.fmt.allocPrintZ(gpa, "{s}:Payload", .{name}); | 2623 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]); |
| 2634 | break :name union_name_buf.?; | 2624 | if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue; |
| 2635 | }; | 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( | 2633 | const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse |
| 2638 | try o.builder.metadataString(union_name), | 2634 | try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls); |
| 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 | ); | | |
| 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) { | 2648 | const debug_struct_type = try o.builder.debugStructType( |
| 2651 | // Set to real type now that it has been lowered fully | 2649 | try o.builder.metadataString(name), |
| 2652 | const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable; | 2650 | file, |
| 2653 | map_ptr.* = debug_union_type; | 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; | 2660 | break :res debug_struct_type; |
| 2656 | } | 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; | 2671 | const layout = pt.getUnionLayout(union_type); |
| 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 | } | | |
| 2667 | | 2672 | |
| 2668 | const debug_tag_type = try o.builder.debugMemberType( | 2673 | if (layout.payload_size == 0) { |
| 2669 | try o.builder.metadataString("tag"), | 2674 | const debug_union_type = try o.builder.debugStructType( |
| 2670 | .none, // File | 2675 | try o.builder.metadataString(name), |
| 2671 | debug_fwd_ref, | 2676 | file, |
| 2672 | 0, // Line | 2677 | scope, |
| 2673 | try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty)), | 2678 | 0, // Line |
| 2674 | layout.tag_size * 8, | 2679 | .none, // Underlying type |
| 2675 | (layout.tag_align.toByteUnits() orelse 0) * 8, | 2680 | ty.abiSize(pt) * 8, |
| 2676 | tag_offset * 8, | 2681 | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, |
| 2677 | ); | 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( | 2688 | break :res debug_union_type; |
| 2680 | try o.builder.metadataString("payload"), | 2689 | } |
| 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 | ); | | |
| 2689 | | 2690 | |
| 2690 | const full_fields: [2]Builder.Metadata = | 2691 | try fields.ensureUnusedCapacity(gpa, union_type.loadTagType(ip).names.len); |
| 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 }; | | |
| 2695 | | 2692 | |
| 2696 | const debug_tagged_union_type = try o.builder.debugStructType( | 2693 | const debug_union_fwd_ref = if (layout.tag_size == 0) |
| 2697 | try o.builder.metadataString(name), | 2694 | fwd_ref |
| 2698 | .none, // File | 2695 | else |
| 2699 | o.debug_compile_unit, // Scope | 2696 | try o.builder.debugForwardReference(); |
| 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 | ); | | |
| 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 | 2700 | for (0..tag_type.names.len) |field_index| { |
| 2710 | const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable; | 2701 | const field_ty = union_type.field_types.get(ip)[field_index]; |
| 2711 | map_ptr.* = debug_tagged_union_type; | 2702 | if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue; |
| 2712 | | 2703 | |
| 2713 | return debug_tagged_union_type; | 2704 | const field_size = Type.fromInterned(field_ty).abiSize(pt); |
| 2714 | }, | 2705 | const field_align: InternPool.Alignment = switch (union_type.flagsUnordered(ip).layout) { |
| 2715 | .Fn => { | 2706 | .@"packed" => .none, |
| 2716 | const fn_info = zcu.typeToFunc(ty).?; | 2707 | .auto, .@"extern" => pt.unionFieldNormalAlignment(union_type, @intCast(field_index)), |
| | 2708 | }; |
| 2717 | | 2709 | |
| 2718 | var debug_param_types = std.ArrayList(Builder.Metadata).init(gpa); | 2710 | const field_name = tag_type.names.get(ip)[field_index]; |
| 2719 | defer debug_param_types.deinit(); | 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. | 2730 | const debug_union_type = try o.builder.debugUnionType( |
| 2724 | if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(pt)) { | 2731 | try o.builder.metadataString(union_name), |
| 2725 | const sret = firstParamSRet(fn_info, pt, target); | 2732 | file, |
| 2726 | const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type); | 2733 | scope, |
| 2727 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty)); | 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) { | 2742 | if (layout.tag_size == 0) { |
| 2730 | const ptr_ty = try pt.singleMutPtrType(Type.fromInterned(fn_info.return_type)); | 2743 | break :res debug_union_type; |
| 2731 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty)); | | |
| 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| { | 2746 | o.builder.debugForwardReferenceSetType(debug_union_fwd_ref, debug_union_type); |
| 2745 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[i]); | | |
| 2746 | if (!param_ty.hasRuntimeBitsIgnoreComptime(pt)) continue; | | |
| 2747 | | 2747 | |
| 2748 | if (isByRef(param_ty, pt)) { | 2748 | var tag_offset: u64 = undefined; |
| 2749 | const ptr_ty = try pt.singleMutPtrType(param_ty); | 2749 | var payload_offset: u64 = undefined; |
| 2750 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty)); | 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 | } else { | 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( | 2758 | const debug_tag_type = try o.builder.debugMemberType( |
| 2757 | try o.builder.debugTuple(debug_param_types.items), | 2759 | try o.builder.metadataString("tag"), |
| 2758 | ); | 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); | 2769 | const debug_payload_type = try o.builder.debugMemberType( |
| 2761 | return debug_function_type; | 2770 | try o.builder.metadataString("payload"), |
| 2762 | }, | 2771 | file, |
| 2763 | .ComptimeInt => unreachable, | 2772 | fwd_ref, |
| 2764 | .ComptimeFloat => unreachable, | 2773 | 0, // Line |
| 2765 | .Type => unreachable, | 2774 | debug_union_type, |
| 2766 | .Undefined => unreachable, | 2775 | layout.payload_size * 8, |
| 2767 | .Null => unreachable, | 2776 | (layout.payload_align.toByteUnits() orelse 0) * 8, |
| 2768 | .EnumLiteral => unreachable, | 2777 | payload_offset * 8, |
| | 2778 | ); |
| 2769 | | 2779 | |
| 2770 | .Frame => @panic("TODO implement lowerDebugType for Frame types"), | 2780 | const full_fields: [2]Builder.Metadata = |
| 2771 | .AnyFrame => @panic("TODO implement lowerDebugType for AnyFrame types"), | 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,14 +2810,10 @@ pub const Object = struct { |
| 2778 | const file_scope = namespace.fileScope(zcu); | 2810 | const file_scope = namespace.fileScope(zcu); |
| 2779 | if (namespace.parent == .none) return try o.getDebugFile(file_scope); | 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); | 2813 | return o.lowerDebugType(zcu.declPtr(namespace.decl_index).val.toType(), false); |
| 2782 | | | |
| 2783 | if (!gop.found_existing) gop.value_ptr.* = try o.builder.debugForwardReference(); | | |
| 2784 | | | |
| 2785 | return gop.value_ptr.*; | | |
| 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 | const zcu = o.pt.zcu; | 2817 | const zcu = o.pt.zcu; |
| 2790 | const decl = zcu.declPtr(decl_index); | 2818 | const decl = zcu.declPtr(decl_index); |
| 2791 | const file_scope = zcu.namespacePtr(decl.src_namespace).fileScope(zcu); | 2819 | const file_scope = zcu.namespacePtr(decl.src_namespace).fileScope(zcu); |
| ... | @@ -2797,7 +2825,8 @@ pub const Object = struct { | ... | @@ -2797,7 +2825,8 @@ pub const Object = struct { |
| 2797 | .none, | 2825 | .none, |
| 2798 | 0, | 2826 | 0, |
| 2799 | 0, | 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,16 +4740,33 @@ pub const DeclGen = struct { |
| 4711 | if (!owner_mod.strip) { | 4740 | if (!owner_mod.strip) { |
| 4712 | const debug_file = try o.getDebugFile(file_scope); | 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 | const debug_global_var = try o.builder.debugGlobalVar( | 4747 | const debug_global_var = try o.builder.debugGlobalVar( |
| 4715 | try o.builder.metadataString(decl.name.toSlice(ip)), // Name | 4748 | linkage_name, |
| 4716 | try o.builder.metadataStringFromStrtabString(variable_index.name(&o.builder)), // Linkage name | 4749 | linkage_name, |
| 4717 | debug_file, // File | 4750 | debug_file, |
| 4718 | debug_file, // Scope | 4751 | debug_file, |
| 4719 | line_number, | 4752 | line_number, |
| 4720 | try o.lowerDebugType(decl.typeOf(zcu)), | 4753 | ty, |
| 4721 | variable_index, | 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 | const debug_expression = try o.builder.debugExpression(&.{}); | 4771 | const debug_expression = try o.builder.debugExpression(&.{}); |
| 4726 | | 4772 | |
| ... | @@ -5171,11 +5217,12 @@ pub const FuncGen = struct { | ... | @@ -5171,11 +5217,12 @@ pub const FuncGen = struct { |
| 5171 | | 5217 | |
| 5172 | self.scope = try o.builder.debugSubprogram( | 5218 | self.scope = try o.builder.debugSubprogram( |
| 5173 | self.file, | 5219 | self.file, |
| | 5220 | self.file, // TODO Get the correct scope into here—self.scope is the function's *inner* scope. |
| 5174 | try o.builder.metadataString(decl.name.toSlice(&zcu.intern_pool)), | 5221 | try o.builder.metadataString(decl.name.toSlice(&zcu.intern_pool)), |
| 5175 | try o.builder.metadataString(decl.fqn.toSlice(&zcu.intern_pool)), | 5222 | try o.builder.metadataString(decl.fqn.toSlice(&zcu.intern_pool)), |
| 5176 | line_number, | 5223 | line_number, |
| 5177 | line_number + func.lbrace_line, | 5224 | line_number + func.lbrace_line, |
| 5178 | try o.lowerDebugType(fn_ty), | 5225 | try o.lowerDebugType(fn_ty, true), |
| 5179 | .{ | 5226 | .{ |
| 5180 | .di_flags = .{ .StaticMember = true }, | 5227 | .di_flags = .{ .StaticMember = true }, |
| 5181 | .sp_flags = .{ | 5228 | .sp_flags = .{ |
| ... | @@ -6725,7 +6772,7 @@ pub const FuncGen = struct { | ... | @@ -6725,7 +6772,7 @@ pub const FuncGen = struct { |
| 6725 | self.file, | 6772 | self.file, |
| 6726 | self.scope, | 6773 | self.scope, |
| 6727 | self.prev_dbg_line, | 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 | _ = try self.wip.callIntrinsic( | 6778 | _ = try self.wip.callIntrinsic( |
| ... | @@ -6758,7 +6805,7 @@ pub const FuncGen = struct { | ... | @@ -6758,7 +6805,7 @@ pub const FuncGen = struct { |
| 6758 | self.file, | 6805 | self.file, |
| 6759 | self.scope, | 6806 | self.scope, |
| 6760 | self.prev_dbg_line, | 6807 | self.prev_dbg_line, |
| 6761 | try o.lowerDebugType(operand_ty), | 6808 | try o.lowerDebugType(operand_ty, true), |
| 6762 | ); | 6809 | ); |
| 6763 | | 6810 | |
| 6764 | const pt = o.pt; | 6811 | const pt = o.pt; |
| ... | @@ -8872,7 +8919,7 @@ pub const FuncGen = struct { | ... | @@ -8872,7 +8919,7 @@ pub const FuncGen = struct { |
| 8872 | self.file, | 8919 | self.file, |
| 8873 | self.scope, | 8920 | self.scope, |
| 8874 | lbrace_line, | 8921 | lbrace_line, |
| 8875 | try o.lowerDebugType(inst_ty), | 8922 | try o.lowerDebugType(inst_ty, true), |
| 8876 | @intCast(self.arg_index), | 8923 | @intCast(self.arg_index), |
| 8877 | ); | 8924 | ); |
| 8878 | | 8925 | |