authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-21 02:44:58-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-21 02:44:58-07:00
logf303c3943f188b76c6d2566bd65429a8b60e8a59
tree72bc31b2923544e0308abe815be89356de65bcc3
parentd484269543c571454818599cce0460f9b363631f

Revert "Merge pull request #20380 from tau-dev/master"

This reverts commit 397be0c9cc8156d38d1487a4c80210007033cbd0, reversing changes made to 18d412ab2fb7bda92f7bfbdf732849bbcd066c33. Caused test failures in master branch.

5 files changed, 483 insertions(+), 716 deletions(-)

lib/std/debug.zig+1-12
......@@ -2459,24 +2459,13 @@ pub const ModuleDebugInfo = switch (native_os) {
24592459 module,
24602460 relocated_address - coff_section.virtual_address,
24612461 ) orelse "???";
2462 // While DWARF gets us just the function's own name, the PDB
2463 // stores it qualified with its namespace by the C++ `::`
2464 // operator. We can strip that for consistency; the
2465 // SymbolInfo will contain the line number, which is a more
2466 // language-neutral way of distinguishing same-named symbols
2467 // anyway.
2468 const symbol_simple_name = if (mem.indexOf(u8, symbol_name, "::")) |cpp_namespace|
2469 symbol_name[cpp_namespace + 2 ..]
2470 else
2471 symbol_name;
2472
24732462 const opt_line_info = try self.pdb.?.getLineNumberInfo(
24742463 module,
24752464 relocated_address - coff_section.virtual_address,
24762465 );
24772466
24782467 return SymbolInfo{
2479 .symbol_name = symbol_simple_name,
2468 .symbol_name = symbol_name,
24802469 .compile_unit_name = obj_basename,
24812470 .line_info = opt_line_info,
24822471 };
src/codegen/llvm.zig+457-504
......@@ -806,17 +806,14 @@ pub const Object = struct {
806806
807807 debug_enums_fwd_ref: Builder.Metadata,
808808 debug_globals_fwd_ref: Builder.Metadata,
809 debug_imports_fwd_ref: Builder.Metadata,
810809
811810 debug_enums: std.ArrayListUnmanaged(Builder.Metadata),
812811 debug_globals: std.ArrayListUnmanaged(Builder.Metadata),
813 debug_imports: std.ArrayListUnmanaged(Builder.Metadata),
814812
815813 debug_file_map: std.AutoHashMapUnmanaged(*const Zcu.File, Builder.Metadata),
816814 debug_type_map: std.AutoHashMapUnmanaged(Type, Builder.Metadata),
817815
818 // The value says whether this namespace's type is runtime-required.
819 debug_unresolved_namespace_scopes: std.AutoArrayHashMapUnmanaged(Type, bool),
816 debug_unresolved_namespace_scopes: std.AutoArrayHashMapUnmanaged(InternPool.NamespaceIndex, Builder.Metadata),
820817
821818 target: std.Target,
822819 /// Ideally we would use `llvm_module.getNamedFunction` to go from *Decl to LLVM function,
......@@ -881,7 +878,7 @@ pub const Object = struct {
881878
882879 builder.data_layout = try builder.fmt("{}", .{DataLayoutBuilder{ .target = target }});
883880
884 const debug_compile_unit, const debug_enums_fwd_ref, const debug_globals_fwd_ref, const debug_imports_fwd_ref =
881 const debug_compile_unit, const debug_enums_fwd_ref, const debug_globals_fwd_ref =
885882 if (!builder.strip)
886883 debug_info: {
887884 // We fully resolve all paths at this point to avoid lack of
......@@ -913,7 +910,6 @@ pub const Object = struct {
913910
914911 const debug_enums_fwd_ref = try builder.debugForwardReference();
915912 const debug_globals_fwd_ref = try builder.debugForwardReference();
916 const debug_imports_fwd_ref = try builder.debugForwardReference();
917913
918914 const debug_compile_unit = try builder.debugCompileUnit(
919915 debug_file,
......@@ -926,7 +922,6 @@ pub const Object = struct {
926922 }),
927923 debug_enums_fwd_ref,
928924 debug_globals_fwd_ref,
929 debug_imports_fwd_ref,
930925 .{ .optimized = comp.root_mod.optimize_mode != .Debug },
931926 );
932927
......@@ -982,8 +977,8 @@ pub const Object = struct {
982977 }
983978
984979 try builder.debugNamed(try builder.metadataString("llvm.dbg.cu"), &.{debug_compile_unit});
985 break :debug_info .{ debug_compile_unit, debug_enums_fwd_ref, debug_globals_fwd_ref, debug_imports_fwd_ref };
986 } else .{.none} ** 4;
980 break :debug_info .{ debug_compile_unit, debug_enums_fwd_ref, debug_globals_fwd_ref };
981 } else .{.none} ** 3;
987982
988983 const obj = try arena.create(Object);
989984 obj.* = .{
......@@ -996,10 +991,8 @@ pub const Object = struct {
996991 .debug_compile_unit = debug_compile_unit,
997992 .debug_enums_fwd_ref = debug_enums_fwd_ref,
998993 .debug_globals_fwd_ref = debug_globals_fwd_ref,
999 .debug_imports_fwd_ref = debug_imports_fwd_ref,
1000994 .debug_enums = .{},
1001995 .debug_globals = .{},
1002 .debug_imports = .{},
1003996 .debug_file_map = .{},
1004997 .debug_type_map = .{},
1005998 .debug_unresolved_namespace_scopes = .{},
......@@ -1141,7 +1134,18 @@ pub const Object = struct {
11411134 try self.genModuleLevelAssembly();
11421135
11431136 if (!self.builder.strip) {
1144 try self.genNamespaces();
1137 {
1138 var i: usize = 0;
1139 while (i < self.debug_unresolved_namespace_scopes.count()) : (i += 1) {
1140 const namespace_index = self.debug_unresolved_namespace_scopes.keys()[i];
1141 const fwd_ref = self.debug_unresolved_namespace_scopes.values()[i];
1142
1143 const namespace = zcu.namespacePtr(namespace_index);
1144 const debug_type = try self.lowerDebugType(namespace.getType(zcu));
1145
1146 self.builder.debugForwardReferenceSetType(fwd_ref, debug_type);
1147 }
1148 }
11451149
11461150 self.builder.debugForwardReferenceSetType(
11471151 self.debug_enums_fwd_ref,
......@@ -1152,11 +1156,6 @@ pub const Object = struct {
11521156 self.debug_globals_fwd_ref,
11531157 try self.builder.debugTuple(self.debug_globals.items),
11541158 );
1155
1156 self.builder.debugForwardReferenceSetType(
1157 self.debug_imports_fwd_ref,
1158 try self.builder.debugTuple(self.debug_imports.items),
1159 );
11601159 }
11611160 }
11621161
......@@ -1636,19 +1635,15 @@ pub const Object = struct {
16361635
16371636 const file, const subprogram = if (!wip.strip) debug_info: {
16381637 const file = try o.getDebugFile(file_scope);
1639 const scope = try o.lowerDebugType(zcu.declPtr(namespace.decl_index).val.toType(), false);
16401638
16411639 const line_number = decl.navSrcLine(zcu) + 1;
16421640 const is_internal_linkage = decl.val.getExternFunc(zcu) == null;
1643 const debug_decl_type = try o.lowerDebugType(decl.typeOf(zcu), true);
1644 const decl_name = try o.builder.metadataString(decl.name.toSlice(ip));
1645 const link_name = try o.builder.metadataStringFromStrtabString(function_index.name(&o.builder));
1641 const debug_decl_type = try o.lowerDebugType(decl.typeOf(zcu));
16461642
16471643 const subprogram = try o.builder.debugSubprogram(
16481644 file,
1649 scope,
1650 decl_name,
1651 link_name,
1645 try o.builder.metadataString(decl.name.toSlice(ip)),
1646 try o.builder.metadataStringFromStrtabString(function_index.name(&o.builder)),
16521647 line_number,
16531648 line_number + func.lbrace_line,
16541649 debug_decl_type,
......@@ -1665,7 +1660,6 @@ pub const Object = struct {
16651660 },
16661661 o.debug_compile_unit,
16671662 );
1668
16691663 function_index.setSubprogram(subprogram, &o.builder);
16701664 break :debug_info .{ file, subprogram };
16711665 } else .{.none} ** 2;
......@@ -1913,7 +1907,6 @@ pub const Object = struct {
19131907 pub fn lowerDebugType(
19141908 o: *Object,
19151909 ty: Type,
1916 required_by_runtime: bool,
19171910 ) Allocator.Error!Builder.Metadata {
19181911 assert(!o.builder.strip);
19191912
......@@ -1923,13 +1916,7 @@ pub const Object = struct {
19231916 const zcu = pt.zcu;
19241917 const ip = &zcu.intern_pool;
19251918
1926 if (o.debug_type_map.get(ty)) |debug_type| {
1927 if (required_by_runtime) {
1928 if (o.debug_unresolved_namespace_scopes.getEntry(ty)) |entry|
1929 entry.value_ptr.* = true;
1930 }
1931 return debug_type;
1932 }
1919 if (o.debug_type_map.get(ty)) |debug_type| return debug_type;
19331920
19341921 switch (ty.zigTypeTag(zcu)) {
19351922 .Void,
......@@ -1944,9 +1931,10 @@ pub const Object = struct {
19441931 },
19451932 .Int => {
19461933 const info = ty.intInfo(zcu);
1947 const int_name = try o.allocTypeName(ty);
1948 defer gpa.free(int_name);
1949 const builder_name = try o.builder.metadataString(int_name);
1934 assert(info.bits != 0);
1935 const name = try o.allocTypeName(ty);
1936 defer gpa.free(name);
1937 const builder_name = try o.builder.metadataString(name);
19501938 const debug_bits = ty.abiSize(pt) * 8; // lldb cannot handle non-byte sized types
19511939 const debug_int_type = switch (info.signedness) {
19521940 .signed => try o.builder.debugSignedType(builder_name, debug_bits),
......@@ -1955,12 +1943,68 @@ pub const Object = struct {
19551943 try o.debug_type_map.put(gpa, ty, debug_int_type);
19561944 return debug_int_type;
19571945 },
1946 .Enum => {
1947 const owner_decl_index = ty.getOwnerDecl(zcu);
1948 const owner_decl = zcu.declPtr(owner_decl_index);
1949
1950 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {
1951 const debug_enum_type = try o.makeEmptyNamespaceDebugType(owner_decl_index);
1952 try o.debug_type_map.put(gpa, ty, debug_enum_type);
1953 return debug_enum_type;
1954 }
1955
1956 const enum_type = ip.loadEnumType(ty.toIntern());
1957
1958 const enumerators = try gpa.alloc(Builder.Metadata, enum_type.names.len);
1959 defer gpa.free(enumerators);
1960
1961 const int_ty = Type.fromInterned(enum_type.tag_ty);
1962 const int_info = ty.intInfo(zcu);
1963 assert(int_info.bits != 0);
1964
1965 for (enum_type.names.get(ip), 0..) |field_name_ip, i| {
1966 var bigint_space: Value.BigIntSpace = undefined;
1967 const bigint = if (enum_type.values.len != 0)
1968 Value.fromInterned(enum_type.values.get(ip)[i]).toBigInt(&bigint_space, pt)
1969 else
1970 std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst();
1971
1972 enumerators[i] = try o.builder.debugEnumerator(
1973 try o.builder.metadataString(field_name_ip.toSlice(ip)),
1974 int_info.signedness == .unsigned,
1975 int_info.bits,
1976 bigint,
1977 );
1978 }
1979
1980 const file_scope = zcu.namespacePtr(owner_decl.src_namespace).fileScope(zcu);
1981 const file = try o.getDebugFile(file_scope);
1982 const scope = try o.namespaceToDebugScope(owner_decl.src_namespace);
1983
1984 const name = try o.allocTypeName(ty);
1985 defer gpa.free(name);
1986
1987 const debug_enum_type = try o.builder.debugEnumerationType(
1988 try o.builder.metadataString(name),
1989 file,
1990 scope,
1991 owner_decl.typeSrcLine(zcu) + 1, // Line
1992 try o.lowerDebugType(int_ty),
1993 ty.abiSize(pt) * 8,
1994 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
1995 try o.builder.debugTuple(enumerators),
1996 );
1997
1998 try o.debug_type_map.put(gpa, ty, debug_enum_type);
1999 try o.debug_enums.append(gpa, debug_enum_type);
2000 return debug_enum_type;
2001 },
19582002 .Float => {
19592003 const bits = ty.floatBits(target);
1960 const float_name = try o.allocTypeName(ty);
1961 defer gpa.free(float_name);
2004 const name = try o.allocTypeName(ty);
2005 defer gpa.free(name);
19622006 const debug_float_type = try o.builder.debugFloatType(
1963 try o.builder.metadataString(float_name),
2007 try o.builder.metadataString(name),
19642008 bits,
19652009 );
19662010 try o.debug_type_map.put(gpa, ty, debug_float_type);
......@@ -2002,7 +2046,7 @@ pub const Object = struct {
20022046 },
20032047 },
20042048 });
2005 const debug_ptr_type = try o.lowerDebugType(bland_ptr_ty, required_by_runtime);
2049 const debug_ptr_type = try o.lowerDebugType(bland_ptr_ty);
20062050 try o.debug_type_map.put(gpa, ty, debug_ptr_type);
20072051 return debug_ptr_type;
20082052 }
......@@ -2018,7 +2062,6 @@ pub const Object = struct {
20182062
20192063 const name = try o.allocTypeName(ty);
20202064 defer gpa.free(name);
2021
20222065 const line = 0;
20232066
20242067 const ptr_size = ptr_ty.abiSize(pt);
......@@ -2033,7 +2076,7 @@ pub const Object = struct {
20332076 .none, // File
20342077 debug_fwd_ref,
20352078 0, // Line
2036 try o.lowerDebugType(ptr_ty, required_by_runtime),
2079 try o.lowerDebugType(ptr_ty),
20372080 ptr_size * 8,
20382081 (ptr_align.toByteUnits() orelse 0) * 8,
20392082 0, // Offset
......@@ -2044,7 +2087,7 @@ pub const Object = struct {
20442087 .none, // File
20452088 debug_fwd_ref,
20462089 0, // Line
2047 try o.lowerDebugType(len_ty, required_by_runtime),
2090 try o.lowerDebugType(len_ty),
20482091 len_size * 8,
20492092 (len_align.toByteUnits() orelse 0) * 8,
20502093 len_offset * 8,
......@@ -2062,7 +2105,6 @@ pub const Object = struct {
20622105 debug_ptr_type,
20632106 debug_len_type,
20642107 }),
2065 isByRef(ty, pt),
20662108 );
20672109
20682110 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_slice_type);
......@@ -2074,7 +2116,7 @@ pub const Object = struct {
20742116 return debug_slice_type;
20752117 }
20762118
2077 const debug_elem_ty = try o.lowerDebugType(Type.fromInterned(ptr_info.child), required_by_runtime);
2119 const debug_elem_ty = try o.lowerDebugType(Type.fromInterned(ptr_info.child));
20782120
20792121 const name = try o.allocTypeName(ty);
20802122 defer gpa.free(name);
......@@ -2098,13 +2140,41 @@ pub const Object = struct {
20982140
20992141 return debug_ptr_type;
21002142 },
2143 .Opaque => {
2144 if (ty.toIntern() == .anyopaque_type) {
2145 const debug_opaque_type = try o.builder.debugSignedType(
2146 try o.builder.metadataString("anyopaque"),
2147 0,
2148 );
2149 try o.debug_type_map.put(gpa, ty, debug_opaque_type);
2150 return debug_opaque_type;
2151 }
2152
2153 const name = try o.allocTypeName(ty);
2154 defer gpa.free(name);
2155 const owner_decl_index = ty.getOwnerDecl(zcu);
2156 const owner_decl = zcu.declPtr(owner_decl_index);
2157 const file_scope = zcu.namespacePtr(owner_decl.src_namespace).fileScope(zcu);
2158 const debug_opaque_type = try o.builder.debugStructType(
2159 try o.builder.metadataString(name),
2160 try o.getDebugFile(file_scope),
2161 try o.namespaceToDebugScope(owner_decl.src_namespace),
2162 owner_decl.typeSrcLine(zcu) + 1, // Line
2163 .none, // Underlying type
2164 0, // Size
2165 0, // Align
2166 .none, // Fields
2167 );
2168 try o.debug_type_map.put(gpa, ty, debug_opaque_type);
2169 return debug_opaque_type;
2170 },
21012171 .Array => {
21022172 const debug_array_type = try o.builder.debugArrayType(
21032173 .none, // Name
21042174 .none, // File
21052175 .none, // Scope
21062176 0, // Line
2107 try o.lowerDebugType(ty.childType(zcu), required_by_runtime),
2177 try o.lowerDebugType(ty.childType(zcu)),
21082178 ty.abiSize(pt) * 8,
21092179 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
21102180 try o.builder.debugTuple(&.{
......@@ -2126,9 +2196,10 @@ pub const Object = struct {
21262196 const debug_elem_type = switch (elem_ty.zigTypeTag(zcu)) {
21272197 .Int => blk: {
21282198 const info = elem_ty.intInfo(zcu);
2129 const vec_name = try o.allocTypeName(ty);
2130 defer gpa.free(vec_name);
2131 const builder_name = try o.builder.metadataString(vec_name);
2199 assert(info.bits != 0);
2200 const name = try o.allocTypeName(ty);
2201 defer gpa.free(name);
2202 const builder_name = try o.builder.metadataString(name);
21322203 break :blk switch (info.signedness) {
21332204 .signed => try o.builder.debugSignedType(builder_name, info.bits),
21342205 .unsigned => try o.builder.debugUnsignedType(builder_name, info.bits),
......@@ -2138,7 +2209,7 @@ pub const Object = struct {
21382209 try o.builder.metadataString("bool"),
21392210 1,
21402211 ),
2141 else => try o.lowerDebugType(ty.childType(zcu), required_by_runtime),
2212 else => try o.lowerDebugType(ty.childType(zcu)),
21422213 };
21432214
21442215 const debug_vector_type = try o.builder.debugVectorType(
......@@ -2163,7 +2234,6 @@ pub const Object = struct {
21632234 .Optional => {
21642235 const name = try o.allocTypeName(ty);
21652236 defer gpa.free(name);
2166
21672237 const child_ty = ty.optionalChild(zcu);
21682238 if (!child_ty.hasRuntimeBitsIgnoreComptime(pt)) {
21692239 const debug_bool_type = try o.builder.debugBoolType(
......@@ -2180,7 +2250,7 @@ pub const Object = struct {
21802250 try o.debug_type_map.put(gpa, ty, debug_fwd_ref);
21812251
21822252 if (ty.optionalReprIsPayload(zcu)) {
2183 const debug_optional_type = try o.lowerDebugType(child_ty, required_by_runtime);
2253 const debug_optional_type = try o.lowerDebugType(child_ty);
21842254
21852255 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type);
21862256
......@@ -2203,7 +2273,7 @@ pub const Object = struct {
22032273 .none, // File
22042274 debug_fwd_ref,
22052275 0, // Line
2206 try o.lowerDebugType(child_ty, required_by_runtime),
2276 try o.lowerDebugType(child_ty),
22072277 payload_size * 8,
22082278 (payload_align.toByteUnits() orelse 0) * 8,
22092279 0, // Offset
......@@ -2214,7 +2284,7 @@ pub const Object = struct {
22142284 .none,
22152285 debug_fwd_ref,
22162286 0,
2217 try o.lowerDebugType(non_null_ty, required_by_runtime),
2287 try o.lowerDebugType(non_null_ty),
22182288 non_null_size * 8,
22192289 (non_null_align.toByteUnits() orelse 0) * 8,
22202290 non_null_offset * 8,
......@@ -2232,7 +2302,6 @@ pub const Object = struct {
22322302 debug_data_type,
22332303 debug_some_type,
22342304 }),
2235 isByRef(ty, pt),
22362305 );
22372306
22382307 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type);
......@@ -2247,7 +2316,7 @@ pub const Object = struct {
22472316 const payload_ty = ty.errorUnionPayload(zcu);
22482317 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
22492318 // TODO: Maybe remove?
2250 const debug_error_union_type = try o.lowerDebugType(Type.anyerror, required_by_runtime);
2319 const debug_error_union_type = try o.lowerDebugType(Type.anyerror);
22512320 try o.debug_type_map.put(gpa, ty, debug_error_union_type);
22522321 return debug_error_union_type;
22532322 }
......@@ -2284,7 +2353,7 @@ pub const Object = struct {
22842353 .none, // File
22852354 debug_fwd_ref,
22862355 0, // Line
2287 try o.lowerDebugType(Type.anyerror, required_by_runtime),
2356 try o.lowerDebugType(Type.anyerror),
22882357 error_size * 8,
22892358 (error_align.toByteUnits() orelse 0) * 8,
22902359 error_offset * 8,
......@@ -2294,7 +2363,7 @@ pub const Object = struct {
22942363 .none, // File
22952364 debug_fwd_ref,
22962365 0, // Line
2297 try o.lowerDebugType(payload_ty, required_by_runtime),
2366 try o.lowerDebugType(payload_ty),
22982367 payload_size * 8,
22992368 (payload_align.toByteUnits() orelse 0) * 8,
23002369 payload_offset * 8,
......@@ -2309,7 +2378,6 @@ pub const Object = struct {
23092378 ty.abiSize(pt) * 8,
23102379 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
23112380 try o.builder.debugTuple(&fields),
2312 isByRef(ty, pt),
23132381 );
23142382
23152383 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_error_union_type);
......@@ -2325,483 +2393,383 @@ pub const Object = struct {
23252393 try o.debug_type_map.put(gpa, ty, debug_error_set);
23262394 return debug_error_set;
23272395 },
2328 .Fn => {
2329 const fn_info = zcu.typeToFunc(ty).?;
2330
2331 var debug_param_types = std.ArrayList(Builder.Metadata).init(gpa);
2332 defer debug_param_types.deinit();
2333
2334 try debug_param_types.ensureUnusedCapacity(3 + fn_info.param_types.len);
2335
2336 // Return type goes first.
2337 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(pt)) {
2338 const sret = firstParamSRet(fn_info, pt, target);
2339 const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type);
2340 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty, required_by_runtime));
2341
2342 if (sret) {
2343 const ptr_ty = try pt.singleMutPtrType(Type.fromInterned(fn_info.return_type));
2344 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty, required_by_runtime));
2345 }
2346 } else {
2347 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(Type.void, required_by_runtime));
2348 }
2349
2350 if (Type.fromInterned(fn_info.return_type).isError(zcu) and
2351 zcu.comp.config.any_error_tracing)
2352 {
2353 const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType());
2354 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty, required_by_runtime));
2355 }
2356
2357 for (0..fn_info.param_types.len) |i| {
2358 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[i]);
2359 if (!param_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
2396 .Struct => {
2397 const name = try o.allocTypeName(ty);
2398 defer gpa.free(name);
23602399
2361 if (isByRef(param_ty, pt)) {
2362 const ptr_ty = try pt.singleMutPtrType(param_ty);
2363 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty, required_by_runtime));
2364 } else {
2365 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(param_ty, required_by_runtime));
2400 if (zcu.typeToPackedStruct(ty)) |struct_type| {
2401 const backing_int_ty = struct_type.backingIntTypeUnordered(ip);
2402 if (backing_int_ty != .none) {
2403 const info = Type.fromInterned(backing_int_ty).intInfo(zcu);
2404 const builder_name = try o.builder.metadataString(name);
2405 const debug_int_type = switch (info.signedness) {
2406 .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(pt) * 8),
2407 .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(pt) * 8),
2408 };
2409 try o.debug_type_map.put(gpa, ty, debug_int_type);
2410 return debug_int_type;
23662411 }
23672412 }
23682413
2369 const debug_function_type = try o.builder.debugSubroutineType(
2370 try o.builder.debugTuple(debug_param_types.items),
2371 );
2414 switch (ip.indexToKey(ty.toIntern())) {
2415 .anon_struct_type => |tuple| {
2416 var fields: std.ArrayListUnmanaged(Builder.Metadata) = .{};
2417 defer fields.deinit(gpa);
2418
2419 try fields.ensureUnusedCapacity(gpa, tuple.types.len);
2420
2421 comptime assert(struct_layout_version == 2);
2422 var offset: u64 = 0;
2423
2424 const debug_fwd_ref = try o.builder.debugForwardReference();
2425
2426 for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, field_val, i| {
2427 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(pt)) continue;
2428
2429 const field_size = Type.fromInterned(field_ty).abiSize(pt);
2430 const field_align = Type.fromInterned(field_ty).abiAlignment(pt);
2431 const field_offset = field_align.forward(offset);
2432 offset = field_offset + field_size;
2433
2434 const field_name = if (tuple.names.len != 0)
2435 tuple.names.get(ip)[i].toSlice(ip)
2436 else
2437 try std.fmt.allocPrintZ(gpa, "{d}", .{i});
2438 defer if (tuple.names.len == 0) gpa.free(field_name);
2439
2440 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2441 try o.builder.metadataString(field_name),
2442 .none, // File
2443 debug_fwd_ref,
2444 0,
2445 try o.lowerDebugType(Type.fromInterned(field_ty)),
2446 field_size * 8,
2447 (field_align.toByteUnits() orelse 0) * 8,
2448 field_offset * 8,
2449 ));
2450 }
23722451
2373 try o.debug_type_map.put(gpa, ty, debug_function_type);
2374 return debug_function_type;
2375 },
2376 .ComptimeInt => unreachable,
2377 .ComptimeFloat => unreachable,
2378 .Type => unreachable,
2379 .Undefined => unreachable,
2380 .Null => unreachable,
2381 .EnumLiteral => unreachable,
2452 const debug_struct_type = try o.builder.debugStructType(
2453 try o.builder.metadataString(name),
2454 .none, // File
2455 o.debug_compile_unit, // Scope
2456 0, // Line
2457 .none, // Underlying type
2458 ty.abiSize(pt) * 8,
2459 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2460 try o.builder.debugTuple(fields.items),
2461 );
23822462
2383 .Frame => @panic("TODO implement lowerDebugType for Frame types"),
2384 .AnyFrame => @panic("TODO implement lowerDebugType for AnyFrame types"),
2385 // These are the types that need a correct scope.
2386 .Enum, .Struct, .Union, .Opaque => {},
2387 }
2388 const fwd_ref = try o.builder.debugForwardReference();
2389 try o.debug_type_map.put(gpa, ty, fwd_ref);
2390 try o.debug_unresolved_namespace_scopes.put(gpa, ty, required_by_runtime);
2463 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_struct_type);
23912464
2392 return fwd_ref;
2393 }
2465 try o.debug_type_map.put(gpa, ty, debug_struct_type);
2466 return debug_struct_type;
2467 },
2468 .struct_type => {
2469 if (!ip.loadStructType(ty.toIntern()).haveFieldTypes(ip)) {
2470 // This can happen if a struct type makes it all the way to
2471 // flush() without ever being instantiated or referenced (even
2472 // via pointer). The only reason we are hearing about it now is
2473 // that it is being used as a namespace to put other debug types
2474 // into. Therefore we can satisfy this by making an empty namespace,
2475 // rather than changing the frontend to unnecessarily resolve the
2476 // struct field types.
2477 const owner_decl_index = ty.getOwnerDecl(zcu);
2478 const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index);
2479 try o.debug_type_map.put(gpa, ty, debug_struct_type);
2480 return debug_struct_type;
2481 }
2482 },
2483 else => {},
2484 }
23942485
2395 fn genNamespaces(o: *Object) !void {
2396 const gpa = o.gpa;
2397 const pt = o.pt;
2398 const zcu = pt.zcu;
2399 const ip = &zcu.intern_pool;
2486 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {
2487 const owner_decl_index = ty.getOwnerDecl(zcu);
2488 const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index);
2489 try o.debug_type_map.put(gpa, ty, debug_struct_type);
2490 return debug_struct_type;
2491 }
24002492
2401 var fields: std.ArrayListUnmanaged(Builder.Metadata) = .{};
2402 defer fields.deinit(gpa);
2493 const struct_type = zcu.typeToStruct(ty).?;
24032494
2404 const unresolved = &o.debug_unresolved_namespace_scopes;
2405 var unresolved_i: usize = 0;
2406 while (unresolved_i < unresolved.count()) : (unresolved_i += 1) {
2407 const ty = unresolved.keys()[unresolved_i];
2408 const required_by_runtime = unresolved.values()[unresolved_i];
2495 var fields: std.ArrayListUnmanaged(Builder.Metadata) = .{};
2496 defer fields.deinit(gpa);
24092497
2410 const owner_decl_index = ty.getOwnerDeclOrNull(zcu);
2411 const owner_decl: ?*Zcu.Decl =
2412 if (owner_decl_index) |owner| ip.declPtr(owner) else null;
2498 try fields.ensureUnusedCapacity(gpa, struct_type.field_types.len);
24132499
2414 const file = if (owner_decl) |owner|
2415 try o.getDebugFile(zcu.namespacePtr(owner.src_namespace).fileScope(zcu))
2416 else
2417 .none;
2418 const scope = if (owner_decl) |owner|
2419 try o.namespaceToDebugScope(owner.src_namespace)
2420 else
2421 o.debug_compile_unit;
2422 const line = if (owner_decl) |owner| owner.typeSrcLine(zcu) + 1 else 0;
2500 const debug_fwd_ref = try o.builder.debugForwardReference();
24232501
2424 const name = if (owner_decl) |owner| owner.name.toSlice(ip) else try o.allocTypeName(ty);
2425 defer if (owner_decl == null) gpa.free(name);
2502 // Set as forward reference while the type is lowered in case it references itself
2503 try o.debug_type_map.put(gpa, ty, debug_fwd_ref);
24262504
2427 const fwd_ref = o.debug_type_map.get(ty).?;
2505 comptime assert(struct_layout_version == 2);
2506 var it = struct_type.iterateRuntimeOrder(ip);
2507 while (it.next()) |field_index| {
2508 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
2509 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
2510 const field_size = field_ty.abiSize(pt);
2511 const field_align = pt.structFieldAlignment(
2512 struct_type.fieldAlign(ip, field_index),
2513 field_ty,
2514 struct_type.layout,
2515 );
2516 const field_offset = ty.structFieldOffset(field_index, pt);
24282517
2429 fields.clearRetainingCapacity();
2518 const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse
2519 try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);
24302520
2431 const ns = if (ty.getNamespace(zcu)) |n| n.unwrap() else null;
2432 if (ns) |ns_id| {
2433 const namespace = ip.namespacePtr(ns_id);
2434 try fields.ensureUnusedCapacity(gpa, namespace.decls.keys().len);
2521 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2522 try o.builder.metadataString(field_name.toSlice(ip)),
2523 .none, // File
2524 debug_fwd_ref,
2525 0, // Line
2526 try o.lowerDebugType(field_ty),
2527 field_size * 8,
2528 (field_align.toByteUnits() orelse 0) * 8,
2529 field_offset * 8,
2530 ));
2531 }
24352532
2436 for (namespace.decls.keys()) |decl_id| {
2437 const decl = ip.declPtr(decl_id);
2438 const decl_name = decl.name.toSlice(ip);
2533 const debug_struct_type = try o.builder.debugStructType(
2534 try o.builder.metadataString(name),
2535 .none, // File
2536 o.debug_compile_unit, // Scope
2537 0, // Line
2538 .none, // Underlying type
2539 ty.abiSize(pt) * 8,
2540 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2541 try o.builder.debugTuple(fields.items),
2542 );
24392543
2440 if (!decl.has_tv) continue;
2441 if (decl.kind != .named) continue;
2442 if (decl.analysis != .complete) continue;
2544 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_struct_type);
24432545
2444 const decl_line = 0;
2546 // Set to real type now that it has been lowered fully
2547 const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable;
2548 map_ptr.* = debug_struct_type;
24452549
2446 if (decl.val.typeOf(zcu).ip_index == .type_type) {
2447 const nested_type = decl.val.toType();
2448 // If this decl is the owner of the type, it will
2449 // already have been declared as a direct child and
2450 // will not need to be typedef'd.
2451 if (nested_type.getOwnerDeclOrNull(zcu)) |owner| {
2452 if (owner == decl_id) continue;
2453 }
2550 return debug_struct_type;
2551 },
2552 .Union => {
2553 const owner_decl_index = ty.getOwnerDecl(zcu);
24542554
2455 switch (nested_type.zigTypeTag(zcu)) {
2456 // We still may want these for a Zig expression
2457 // evaluator in debuggers, but for now they are
2458 // completely useless.
2459 .ComptimeInt, .ComptimeFloat, .Type, .Undefined, .Null, .EnumLiteral => continue,
2460 else => {},
2461 }
2555 const name = try o.allocTypeName(ty);
2556 defer gpa.free(name);
24622557
2463 fields.appendAssumeCapacity(try o.builder.debugTypedef(
2464 try o.builder.metadataString(decl_name),
2465 try o.getDebugFile(namespace.fileScope(zcu)),
2466 fwd_ref,
2467 decl_line,
2468 try o.lowerDebugType(nested_type, false),
2469 0, // Align
2470 ));
2471 }
2558 const union_type = ip.loadUnionType(ty.toIntern());
2559 if (!union_type.haveFieldTypes(ip) or
2560 !ty.hasRuntimeBitsIgnoreComptime(pt) or
2561 !union_type.haveLayout(ip))
2562 {
2563 const debug_union_type = try o.makeEmptyNamespaceDebugType(owner_decl_index);
2564 try o.debug_type_map.put(gpa, ty, debug_union_type);
2565 return debug_union_type;
24722566 }
2473 }
24742567
2475 if (!required_by_runtime) {
2476 const res = try o.makeNamespaceDebugType(owner_decl_index.?, fields.items);
2477 o.builder.debugForwardReferenceSetType(fwd_ref, res);
2478 continue;
2479 }
2480
2481 const res = switch (ty.zigTypeTag(zcu)) {
2482 .Enum => res: {
2483 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {
2484 break :res try o.makeNamespaceDebugType(owner_decl_index.?, fields.items);
2485 }
2486
2487 const enum_type = ip.loadEnumType(ty.toIntern());
2488
2489 const enumerators = try gpa.alloc(Builder.Metadata, enum_type.names.len);
2490 defer gpa.free(enumerators);
2568 const layout = pt.getUnionLayout(union_type);
24912569
2492 const int_ty = Type.fromInterned(enum_type.tag_ty);
2493 const int_info = ty.intInfo(zcu);
2494 assert(int_info.bits != 0);
2495
2496 for (enum_type.names.get(ip), 0..) |field_name_ip, i| {
2497 var bigint_space: Value.BigIntSpace = undefined;
2498 const bigint = if (enum_type.values.len != 0)
2499 Value.fromInterned(enum_type.values.get(ip)[i]).toBigInt(&bigint_space, pt)
2500 else
2501 std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst();
2570 const debug_fwd_ref = try o.builder.debugForwardReference();
25022571
2503 enumerators[i] = try o.builder.debugEnumerator(
2504 try o.builder.metadataString(field_name_ip.toSlice(ip)),
2505 int_info.signedness == .unsigned,
2506 int_info.bits,
2507 bigint,
2508 );
2509 }
2572 // Set as forward reference while the type is lowered in case it references itself
2573 try o.debug_type_map.put(gpa, ty, debug_fwd_ref);
25102574
2511 const debug_enum_type = try o.builder.debugEnumerationType(
2575 if (layout.payload_size == 0) {
2576 const debug_union_type = try o.builder.debugStructType(
25122577 try o.builder.metadataString(name),
2513 file,
2514 scope,
2515 line,
2516 try o.lowerDebugType(int_ty, required_by_runtime),
2578 .none, // File
2579 o.debug_compile_unit, // Scope
2580 0, // Line
2581 .none, // Underlying type
25172582 ty.abiSize(pt) * 8,
25182583 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2519 try o.builder.debugTuple(enumerators),
2584 try o.builder.debugTuple(
2585 &.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty))},
2586 ),
25202587 );
25212588
2522 try o.debug_enums.append(gpa, debug_enum_type);
2523 break :res debug_enum_type;
2524 },
2525 .Opaque => res: {
2526 if (ty.toIntern() == .anyopaque_type) {
2527 break :res try o.builder.debugSignedType(
2528 try o.builder.metadataString("anyopaque"),
2529 0,
2530 );
2531 }
2532
2533 const debug_opaque_type = try o.builder.debugStructType(
2534 try o.builder.metadataString(name),
2535 file,
2536 scope,
2537 line,
2538 .none, // Underlying type
2539 0, // Size
2540 0, // Align
2541 .none, // Fields
2542 false, // ByRef
2543 );
2544 break :res debug_opaque_type;
2545 },
2546 .Struct => res: {
2547 if (zcu.typeToPackedStruct(ty)) |struct_type| {
2548 const backing_int_ty = struct_type.backingIntTypeUnordered(ip);
2549 if (backing_int_ty != .none) {
2550 const info = Type.fromInterned(backing_int_ty).intInfo(zcu);
2551 const builder_name = try o.builder.metadataString(name);
2552 const debug_int_type = switch (info.signedness) {
2553 .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(pt) * 8),
2554 .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(pt) * 8),
2555 };
2556 break :res debug_int_type;
2557 }
2558 }
2589 // Set to real type now that it has been lowered fully
2590 const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable;
2591 map_ptr.* = debug_union_type;
25592592
2560 switch (ip.indexToKey(ty.toIntern())) {
2561 .anon_struct_type => |tuple| {
2562 try fields.ensureUnusedCapacity(gpa, tuple.types.len);
2563
2564 comptime assert(struct_layout_version == 2);
2565 var offset: u64 = 0;
2566
2567 for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, field_val, i| {
2568 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(pt)) continue;
2569
2570 const field_size = Type.fromInterned(field_ty).abiSize(pt);
2571 const field_align = Type.fromInterned(field_ty).abiAlignment(pt);
2572 const field_offset = field_align.forward(offset);
2573 offset = field_offset + field_size;
2574
2575 const field_name = if (tuple.names.len != 0)
2576 tuple.names.get(ip)[i].toSlice(ip)
2577 else
2578 try std.fmt.allocPrintZ(gpa, "{d}", .{i});
2579 defer if (tuple.names.len == 0) gpa.free(field_name);
2580
2581 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2582 try o.builder.metadataString(field_name),
2583 .none, // File
2584 fwd_ref,
2585 0,
2586 try o.lowerDebugType(Type.fromInterned(field_ty), required_by_runtime),
2587 field_size * 8,
2588 (field_align.toByteUnits() orelse 0) * 8,
2589 field_offset * 8,
2590 ));
2591 }
2593 return debug_union_type;
2594 }
25922595
2593 const debug_struct_type = try o.builder.debugStructType(
2594 try o.builder.metadataString(name),
2595 file,
2596 scope,
2597 0, // Line
2598 .none, // Underlying type
2599 ty.abiSize(pt) * 8,
2600 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2601 try o.builder.debugTuple(fields.items),
2602 isByRef(ty, pt),
2603 );
2596 var fields: std.ArrayListUnmanaged(Builder.Metadata) = .{};
2597 defer fields.deinit(gpa);
26042598
2605 break :res debug_struct_type;
2606 },
2607 else => {},
2608 }
2599 try fields.ensureUnusedCapacity(gpa, union_type.loadTagType(ip).names.len);
26092600
2610 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {
2611 break :res try o.makeNamespaceDebugType(owner_decl_index.?, fields.items);
2612 }
2613 const struct_type = zcu.typeToStruct(ty).?;
2601 const debug_union_fwd_ref = if (layout.tag_size == 0)
2602 debug_fwd_ref
2603 else
2604 try o.builder.debugForwardReference();
26142605
2615 if (!struct_type.haveLayout(ip) or !struct_type.haveFieldTypes(ip)) {
2616 break :res try o.makeNamespaceDebugType(owner_decl_index.?, fields.items);
2617 }
2606 const tag_type = union_type.loadTagType(ip);
26182607
2619 try fields.ensureUnusedCapacity(gpa, struct_type.field_types.len);
2608 for (0..tag_type.names.len) |field_index| {
2609 const field_ty = union_type.field_types.get(ip)[field_index];
2610 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue;
26202611
2621 comptime assert(struct_layout_version == 2);
2622 var it = struct_type.iterateRuntimeOrder(ip);
2623 while (it.next()) |field_index| {
2624 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
2625 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
2626 const field_size = field_ty.abiSize(pt);
2627 const field_align = pt.structFieldAlignment(
2628 struct_type.fieldAlign(ip, field_index),
2629 field_ty,
2630 struct_type.layout,
2631 );
2632 const field_offset = ty.structFieldOffset(field_index, pt);
2612 const field_size = Type.fromInterned(field_ty).abiSize(pt);
2613 const field_align: InternPool.Alignment = switch (union_type.flagsUnordered(ip).layout) {
2614 .@"packed" => .none,
2615 .auto, .@"extern" => pt.unionFieldNormalAlignment(union_type, @intCast(field_index)),
2616 };
26332617
2634 const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse
2635 try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);
2618 const field_name = tag_type.names.get(ip)[field_index];
2619 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2620 try o.builder.metadataString(field_name.toSlice(ip)),
2621 .none, // File
2622 debug_union_fwd_ref,
2623 0, // Line
2624 try o.lowerDebugType(Type.fromInterned(field_ty)),
2625 field_size * 8,
2626 (field_align.toByteUnits() orelse 0) * 8,
2627 0, // Offset
2628 ));
2629 }
26362630
2637 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2638 try o.builder.metadataString(field_name.toSlice(ip)),
2639 file,
2640 fwd_ref,
2641 0, // Line
2642 try o.lowerDebugType(field_ty, required_by_runtime),
2643 field_size * 8,
2644 (field_align.toByteUnits() orelse 0) * 8,
2645 field_offset * 8,
2646 ));
2647 }
2631 var union_name_buf: ?[:0]const u8 = null;
2632 defer if (union_name_buf) |buf| gpa.free(buf);
2633 const union_name = if (layout.tag_size == 0) name else name: {
2634 union_name_buf = try std.fmt.allocPrintZ(gpa, "{s}:Payload", .{name});
2635 break :name union_name_buf.?;
2636 };
26482637
2649 const debug_struct_type = try o.builder.debugStructType(
2650 try o.builder.metadataString(name),
2651 file,
2652 scope,
2653 line,
2654 .none, // Underlying type
2655 ty.abiSize(pt) * 8,
2656 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2657 try o.builder.debugTuple(fields.items),
2658 isByRef(ty, pt),
2659 );
2638 const debug_union_type = try o.builder.debugUnionType(
2639 try o.builder.metadataString(union_name),
2640 .none, // File
2641 o.debug_compile_unit, // Scope
2642 0, // Line
2643 .none, // Underlying type
2644 ty.abiSize(pt) * 8,
2645 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2646 try o.builder.debugTuple(fields.items),
2647 );
26602648
2661 break :res debug_struct_type;
2662 },
2663 .Union => res: {
2664 const union_type = ip.loadUnionType(ty.toIntern());
2665 if (!union_type.haveFieldTypes(ip) or
2666 !ty.hasRuntimeBitsIgnoreComptime(pt) or
2667 !union_type.haveLayout(ip))
2668 {
2669 break :res try o.makeNamespaceDebugType(owner_decl_index.?, fields.items);
2670 }
2649 o.builder.debugForwardReferenceSetType(debug_union_fwd_ref, debug_union_type);
26712650
2672 const layout = pt.getUnionLayout(union_type);
2651 if (layout.tag_size == 0) {
2652 // Set to real type now that it has been lowered fully
2653 const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable;
2654 map_ptr.* = debug_union_type;
26732655
2674 if (layout.payload_size == 0) {
2675 const debug_union_type = try o.builder.debugStructType(
2676 try o.builder.metadataString(name),
2677 file,
2678 scope,
2679 0, // Line
2680 .none, // Underlying type
2681 ty.abiSize(pt) * 8,
2682 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2683 try o.builder.debugTuple(
2684 &.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty), required_by_runtime)},
2685 ),
2686 isByRef(ty, pt),
2687 );
2656 return debug_union_type;
2657 }
26882658
2689 break :res debug_union_type;
2690 }
2659 var tag_offset: u64 = undefined;
2660 var payload_offset: u64 = undefined;
2661 if (layout.tag_align.compare(.gte, layout.payload_align)) {
2662 tag_offset = 0;
2663 payload_offset = layout.payload_align.forward(layout.tag_size);
2664 } else {
2665 payload_offset = 0;
2666 tag_offset = layout.tag_align.forward(layout.payload_size);
2667 }
26912668
2692 try fields.ensureUnusedCapacity(gpa, union_type.loadTagType(ip).names.len);
2669 const debug_tag_type = try o.builder.debugMemberType(
2670 try o.builder.metadataString("tag"),
2671 .none, // File
2672 debug_fwd_ref,
2673 0, // Line
2674 try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty)),
2675 layout.tag_size * 8,
2676 (layout.tag_align.toByteUnits() orelse 0) * 8,
2677 tag_offset * 8,
2678 );
26932679
2694 const debug_union_fwd_ref = if (layout.tag_size == 0)
2695 fwd_ref
2696 else
2697 try o.builder.debugForwardReference();
2680 const debug_payload_type = try o.builder.debugMemberType(
2681 try o.builder.metadataString("payload"),
2682 .none, // File
2683 debug_fwd_ref,
2684 0, // Line
2685 debug_union_type,
2686 layout.payload_size * 8,
2687 (layout.payload_align.toByteUnits() orelse 0) * 8,
2688 payload_offset * 8,
2689 );
26982690
2699 const tag_type = union_type.loadTagType(ip);
2691 const full_fields: [2]Builder.Metadata =
2692 if (layout.tag_align.compare(.gte, layout.payload_align))
2693 .{ debug_tag_type, debug_payload_type }
2694 else
2695 .{ debug_payload_type, debug_tag_type };
27002696
2701 for (0..tag_type.names.len) |field_index| {
2702 const field_ty = union_type.field_types.get(ip)[field_index];
2703 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue;
2697 const debug_tagged_union_type = try o.builder.debugStructType(
2698 try o.builder.metadataString(name),
2699 .none, // File
2700 o.debug_compile_unit, // Scope
2701 0, // Line
2702 .none, // Underlying type
2703 ty.abiSize(pt) * 8,
2704 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2705 try o.builder.debugTuple(&full_fields),
2706 );
27042707
2705 const field_size = Type.fromInterned(field_ty).abiSize(pt);
2706 const field_align: InternPool.Alignment = switch (union_type.flagsUnordered(ip).layout) {
2707 .@"packed" => .none,
2708 .auto, .@"extern" => pt.unionFieldNormalAlignment(union_type, @intCast(field_index)),
2709 };
2708 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_tagged_union_type);
27102709
2711 const field_name = tag_type.names.get(ip)[field_index];
2712 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2713 try o.builder.metadataString(field_name.toSlice(ip)),
2714 file,
2715 debug_union_fwd_ref,
2716 0, // Line
2717 try o.lowerDebugType(Type.fromInterned(field_ty), required_by_runtime),
2718 field_size * 8,
2719 (field_align.toByteUnits() orelse 0) * 8,
2720 0, // Offset
2721 ));
2722 }
2710 // Set to real type now that it has been lowered fully
2711 const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable;
2712 map_ptr.* = debug_tagged_union_type;
27232713
2724 var union_name_buf: ?[:0]const u8 = null;
2725 defer if (union_name_buf) |buf| gpa.free(buf);
2726 const union_name = if (layout.tag_size == 0) name else name: {
2727 union_name_buf = try std.fmt.allocPrintZ(gpa, "{s}:Payload", .{name});
2728 break :name union_name_buf.?;
2729 };
2714 return debug_tagged_union_type;
2715 },
2716 .Fn => {
2717 const fn_info = zcu.typeToFunc(ty).?;
27302718
2731 const debug_union_type = try o.builder.debugUnionType(
2732 try o.builder.metadataString(union_name),
2733 file,
2734 scope,
2735 line,
2736 .none, // Underlying type
2737 ty.abiSize(pt) * 8,
2738 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2739 try o.builder.debugTuple(fields.items),
2740 isByRef(ty, pt),
2741 );
2719 var debug_param_types = std.ArrayList(Builder.Metadata).init(gpa);
2720 defer debug_param_types.deinit();
27422721
2743 if (layout.tag_size == 0) {
2744 break :res debug_union_type;
2745 }
2722 try debug_param_types.ensureUnusedCapacity(3 + fn_info.param_types.len);
27462723
2747 o.builder.debugForwardReferenceSetType(debug_union_fwd_ref, debug_union_type);
2724 // Return type goes first.
2725 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(pt)) {
2726 const sret = firstParamSRet(fn_info, pt, target);
2727 const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type);
2728 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty));
27482729
2749 var tag_offset: u64 = undefined;
2750 var payload_offset: u64 = undefined;
2751 if (layout.tag_align.compare(.gte, layout.payload_align)) {
2752 tag_offset = 0;
2753 payload_offset = layout.payload_align.forward(layout.tag_size);
2754 } else {
2755 payload_offset = 0;
2756 tag_offset = layout.tag_align.forward(layout.payload_size);
2730 if (sret) {
2731 const ptr_ty = try pt.singleMutPtrType(Type.fromInterned(fn_info.return_type));
2732 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
27572733 }
2734 } else {
2735 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(Type.void));
2736 }
27582737
2759 const debug_tag_type = try o.builder.debugMemberType(
2760 try o.builder.metadataString("tag"),
2761 file, // File
2762 fwd_ref,
2763 0, // Line
2764 try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty), required_by_runtime),
2765 layout.tag_size * 8,
2766 (layout.tag_align.toByteUnits() orelse 0) * 8,
2767 tag_offset * 8,
2768 );
2738 if (Type.fromInterned(fn_info.return_type).isError(zcu) and
2739 zcu.comp.config.any_error_tracing)
2740 {
2741 const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType());
2742 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
2743 }
27692744
2770 const debug_payload_type = try o.builder.debugMemberType(
2771 try o.builder.metadataString("payload"),
2772 file,
2773 fwd_ref,
2774 0, // Line
2775 debug_union_type,
2776 layout.payload_size * 8,
2777 (layout.payload_align.toByteUnits() orelse 0) * 8,
2778 payload_offset * 8,
2779 );
2745 for (0..fn_info.param_types.len) |i| {
2746 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[i]);
2747 if (!param_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
27802748
2781 const full_fields: [2]Builder.Metadata =
2782 if (layout.tag_align.compare(.gte, layout.payload_align))
2783 .{ debug_tag_type, debug_payload_type }
2784 else
2785 .{ debug_payload_type, debug_tag_type };
2749 if (isByRef(param_ty, pt)) {
2750 const ptr_ty = try pt.singleMutPtrType(param_ty);
2751 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
2752 } else {
2753 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(param_ty));
2754 }
2755 }
27862756
2787 const debug_tagged_union_type = try o.builder.debugStructType(
2788 try o.builder.metadataString(name),
2789 file, // File
2790 scope,
2791 line,
2792 .none, // Underlying type
2793 ty.abiSize(pt) * 8,
2794 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2795 try o.builder.debugTuple(&full_fields),
2796 isByRef(ty, pt),
2797 );
2757 const debug_function_type = try o.builder.debugSubroutineType(
2758 try o.builder.debugTuple(debug_param_types.items),
2759 );
27982760
2799 break :res debug_tagged_union_type;
2800 },
2801 else => unreachable, // Handled above.
2802 };
2761 try o.debug_type_map.put(gpa, ty, debug_function_type);
2762 return debug_function_type;
2763 },
2764 .ComptimeInt => unreachable,
2765 .ComptimeFloat => unreachable,
2766 .Type => unreachable,
2767 .Undefined => unreachable,
2768 .Null => unreachable,
2769 .EnumLiteral => unreachable,
28032770
2804 o.builder.debugForwardReferenceSetType(fwd_ref, res);
2771 .Frame => @panic("TODO implement lowerDebugType for Frame types"),
2772 .AnyFrame => @panic("TODO implement lowerDebugType for AnyFrame types"),
28052773 }
28062774 }
28072775
......@@ -2811,10 +2779,14 @@ pub const Object = struct {
28112779 const file_scope = namespace.fileScope(zcu);
28122780 if (namespace.parent == .none) return try o.getDebugFile(file_scope);
28132781
2814 return o.lowerDebugType(zcu.declPtr(namespace.decl_index).val.toType(), false);
2782 const gop = try o.debug_unresolved_namespace_scopes.getOrPut(o.gpa, namespace_index);
2783
2784 if (!gop.found_existing) gop.value_ptr.* = try o.builder.debugForwardReference();
2785
2786 return gop.value_ptr.*;
28152787 }
28162788
2817 fn makeNamespaceDebugType(o: *Object, decl_index: InternPool.DeclIndex, fields: []const Builder.Metadata) !Builder.Metadata {
2789 fn makeEmptyNamespaceDebugType(o: *Object, decl_index: InternPool.DeclIndex) !Builder.Metadata {
28182790 const zcu = o.pt.zcu;
28192791 const decl = zcu.declPtr(decl_index);
28202792 const file_scope = zcu.namespacePtr(decl.src_namespace).fileScope(zcu);
......@@ -2826,8 +2798,7 @@ pub const Object = struct {
28262798 .none,
28272799 0,
28282800 0,
2829 if (fields.len == 0) .none else try o.builder.debugTuple(fields),
2830 false, // is_byref
2801 .none,
28312802 );
28322803 }
28332804
......@@ -4741,33 +4712,16 @@ pub const DeclGen = struct {
47414712 if (!owner_mod.strip) {
47424713 const debug_file = try o.getDebugFile(file_scope);
47434714
4744 const linkage_name = try o.builder.metadataStringFromStrtabString(variable_index.name(&o.builder));
4745 const is_internal_linkage = !decl.isExtern(zcu);
4746
4747 const ty = try o.lowerDebugType(decl.typeOf(zcu), true);
47484715 const debug_global_var = try o.builder.debugGlobalVar(
4749 linkage_name,
4750 linkage_name,
4751 debug_file,
4752 debug_file,
4716 try o.builder.metadataString(decl.name.toSlice(ip)), // Name
4717 try o.builder.metadataStringFromStrtabString(variable_index.name(&o.builder)), // Linkage name
4718 debug_file, // File
4719 debug_file, // Scope
47534720 line_number,
4754 ty,
4721 try o.lowerDebugType(decl.typeOf(zcu)),
47554722 variable_index,
4756 is_internal_linkage,
4723 .{ .local = !decl.isExtern(zcu) },
47574724 );
4758 if (is_internal_linkage) {
4759 const name = try o.builder.metadataString(decl.name.toSlice(ip));
4760 const debug_scope = try o.namespaceToDebugScope(decl.src_namespace);
4761
4762 const import = try o.builder.debugImportDeclaration(
4763 name,
4764 debug_file,
4765 debug_scope,
4766 line_number,
4767 debug_global_var,
4768 );
4769 try o.debug_imports.append(o.gpa, import);
4770 }
47714725
47724726 const debug_expression = try o.builder.debugExpression(&.{});
47734727
......@@ -5218,12 +5172,11 @@ pub const FuncGen = struct {
52185172
52195173 self.scope = try o.builder.debugSubprogram(
52205174 self.file,
5221 self.file, // TODO Get the correct scope into here—self.scope is the function's *inner* scope.
52225175 try o.builder.metadataString(decl.name.toSlice(&zcu.intern_pool)),
52235176 try o.builder.metadataString(decl.fqn.toSlice(&zcu.intern_pool)),
52245177 line_number,
52255178 line_number + func.lbrace_line,
5226 try o.lowerDebugType(fn_ty, true),
5179 try o.lowerDebugType(fn_ty),
52275180 .{
52285181 .di_flags = .{ .StaticMember = true },
52295182 .sp_flags = .{
......@@ -6773,7 +6726,7 @@ pub const FuncGen = struct {
67736726 self.file,
67746727 self.scope,
67756728 self.prev_dbg_line,
6776 try o.lowerDebugType(ptr_ty.childType(mod), true),
6729 try o.lowerDebugType(ptr_ty.childType(mod)),
67776730 );
67786731
67796732 _ = try self.wip.callIntrinsic(
......@@ -6806,7 +6759,7 @@ pub const FuncGen = struct {
68066759 self.file,
68076760 self.scope,
68086761 self.prev_dbg_line,
6809 try o.lowerDebugType(operand_ty, true),
6762 try o.lowerDebugType(operand_ty),
68106763 );
68116764
68126765 const pt = o.pt;
......@@ -8920,7 +8873,7 @@ pub const FuncGen = struct {
89208873 self.file,
89218874 self.scope,
89228875 lbrace_line,
8923 try o.lowerDebugType(inst_ty, true),
8876 try o.lowerDebugType(inst_ty),
89248877 @intCast(self.arg_index),
89258878 );
89268879
src/codegen/llvm/Builder.zig+22-150
......@@ -7651,8 +7651,6 @@ pub const Metadata = enum(u32) {
76517651 composite_vector_type,
76527652 derived_pointer_type,
76537653 derived_member_type,
7654 derived_typedef,
7655 imported_declaration,
76567654 subroutine_type,
76577655 enumerator_unsigned,
76587656 enumerator_signed_positive,
......@@ -7698,8 +7696,6 @@ pub const Metadata = enum(u32) {
76987696 .composite_vector_type,
76997697 .derived_pointer_type,
77007698 .derived_member_type,
7701 .derived_typedef,
7702 .imported_declaration,
77037699 .subroutine_type,
77047700 .enumerator_unsigned,
77057701 .enumerator_signed_positive,
......@@ -7816,7 +7812,6 @@ pub const Metadata = enum(u32) {
78167812 producer: MetadataString,
78177813 enums: Metadata,
78187814 globals: Metadata,
7819 imports: Metadata,
78207815 };
78217816
78227817 pub const Subprogram = struct {
......@@ -7865,7 +7860,6 @@ pub const Metadata = enum(u32) {
78657860 }
78667861 };
78677862
7868 scope: Metadata,
78697863 file: Metadata,
78707864 name: MetadataString,
78717865 linkage_name: MetadataString,
......@@ -7911,10 +7905,6 @@ pub const Metadata = enum(u32) {
79117905 align_in_bits_lo: u32,
79127906 align_in_bits_hi: u32,
79137907 fields_tuple: Metadata,
7914 flags: packed struct(u32) {
7915 is_byref: bool,
7916 pad: u31 = 0,
7917 },
79187908
79197909 pub fn bitSize(self: CompositeType) u64 {
79207910 return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;
......@@ -7948,14 +7938,6 @@ pub const Metadata = enum(u32) {
79487938 }
79497939 };
79507940
7951 pub const ImportedEntity = struct {
7952 name: MetadataString,
7953 file: Metadata,
7954 scope: Metadata,
7955 line: u32,
7956 entity: Metadata,
7957 };
7958
79597941 pub const SubroutineType = struct {
79607942 types_tuple: Metadata,
79617943 };
......@@ -8008,6 +7990,10 @@ pub const Metadata = enum(u32) {
80087990 };
80097991
80107992 pub const GlobalVar = struct {
7993 pub const Options = struct {
7994 local: bool,
7995 };
7996
80117997 name: MetadataString,
80127998 linkage_name: MetadataString,
80137999 file: Metadata,
......@@ -8238,7 +8224,6 @@ pub const Metadata = enum(u32) {
82388224 DIBasicType,
82398225 DICompositeType,
82408226 DIDerivedType,
8241 DIImportedEntity,
82428227 DISubroutineType,
82438228 DIEnumerator,
82448229 DISubrange,
......@@ -9976,7 +9961,7 @@ pub fn printUnbuffered(
99769961 .enums = extra.enums,
99779962 .retainedTypes = null,
99789963 .globals = extra.globals,
9979 .imports = extra.imports,
9964 .imports = null,
99809965 .macros = null,
99819966 .dwoId = null,
99829967 .splitDebugInlining = false,
......@@ -10000,7 +9985,7 @@ pub fn printUnbuffered(
100009985 try metadata_formatter.specialized(.@"distinct !", .DISubprogram, .{
100019986 .name = extra.name,
100029987 .linkageName = extra.linkage_name,
10003 .scope = extra.scope,
9988 .scope = extra.file,
100049989 .file = extra.file,
100059990 .line = extra.line,
100069991 .type = extra.ty,
......@@ -10094,8 +10079,8 @@ pub fn printUnbuffered(
1009410079 else => extra.name,
1009510080 },
1009610081 .scope = extra.scope,
10097 .file = extra.file,
10098 .line = extra.line,
10082 .file = null,
10083 .line = null,
1009910084 .baseType = extra.underlying_type,
1010010085 .size = extra.bitSize(),
1010110086 .@"align" = extra.bitAlign(),
......@@ -10116,18 +10101,15 @@ pub fn printUnbuffered(
1011610101 },
1011710102 .derived_pointer_type,
1011810103 .derived_member_type,
10119 .derived_typedef,
1012010104 => |kind| {
1012110105 const extra = self.metadataExtraData(Metadata.DerivedType, metadata_item.data);
1012210106 try metadata_formatter.specialized(.@"!", .DIDerivedType, .{
1012310107 .tag = @as(enum {
1012410108 DW_TAG_pointer_type,
1012510109 DW_TAG_member,
10126 DW_TAG_typedef,
1012710110 }, switch (kind) {
1012810111 .derived_pointer_type => .DW_TAG_pointer_type,
1012910112 .derived_member_type => .DW_TAG_member,
10130 .derived_typedef => .DW_TAG_typedef,
1013110113 else => unreachable,
1013210114 }),
1013310115 .name = switch (extra.name) {
......@@ -10150,22 +10132,6 @@ pub fn printUnbuffered(
1015010132 .annotations = null,
1015110133 }, writer);
1015210134 },
10153 .imported_declaration => {
10154 const extra = self.metadataExtraData(Metadata.ImportedEntity, metadata_item.data);
10155
10156 try metadata_formatter.specialized(.@"!", .DIImportedEntity, .{
10157 .tag = .DW_TAG_imported_declaration,
10158 .scope = extra.scope,
10159 .entity = extra.entity,
10160 .file = extra.file,
10161 .line = extra.line,
10162 .name = switch (extra.name) {
10163 .none => null,
10164 else => extra.name,
10165 },
10166 .elements = null,
10167 }, writer);
10168 },
1016910135 .subroutine_type => {
1017010136 const extra = self.metadataExtraData(Metadata.SubroutineType, metadata_item.data);
1017110137 try metadata_formatter.specialized(.@"!", .DISubroutineType, .{
......@@ -10289,7 +10255,11 @@ pub fn printUnbuffered(
1028910255 .file = extra.file,
1029010256 .line = extra.line,
1029110257 .type = extra.ty,
10292 .isLocal = kind != .global_var,
10258 .isLocal = switch (kind) {
10259 .global_var => false,
10260 .@"global_var local" => true,
10261 else => unreachable,
10262 },
1029310263 .isDefinition = true,
1029410264 .declaration = null,
1029510265 .templateParams = null,
......@@ -11642,17 +11612,7 @@ fn addMetadataExtraAssumeCapacity(self: *Builder, extra: anytype) Metadata.Item.
1164211612 u32 => value,
1164311613 MetadataString, Metadata, Variable.Index, Value => @intFromEnum(value),
1164411614 Metadata.DIFlags => @bitCast(value),
11645 else => blk: {
11646 switch (@typeInfo(field.type)) {
11647 .Struct => |s| {
11648 if (s.backing_integer == u32)
11649 break :blk @bitCast(value);
11650 @compileLog(s.layout, s.backing_integer);
11651 },
11652 else => {},
11653 }
11654 @compileError("bad field type: " ++ @typeName(field.type));
11655 },
11615 else => @compileError("bad field type: " ++ @typeName(field.type)),
1165611616 });
1165711617 }
1165811618 return result;
......@@ -11691,7 +11651,7 @@ fn metadataExtraDataTrail(
1169111651 u32 => value,
1169211652 MetadataString, Metadata, Variable.Index, Value => @enumFromInt(value),
1169311653 Metadata.DIFlags => @bitCast(value),
11694 else => @bitCast(value),
11654 else => @compileError("bad field type: " ++ @typeName(field.type)),
1169511655 };
1169611656 return .{
1169711657 .data = result,
......@@ -11780,17 +11740,15 @@ pub fn debugCompileUnit(
1178011740 producer: MetadataString,
1178111741 enums: Metadata,
1178211742 globals: Metadata,
11783 imports: Metadata,
1178411743 options: Metadata.CompileUnit.Options,
1178511744) Allocator.Error!Metadata {
1178611745 try self.ensureUnusedMetadataCapacity(1, Metadata.CompileUnit, 0);
11787 return self.debugCompileUnitAssumeCapacity(file, producer, enums, globals, imports, options);
11746 return self.debugCompileUnitAssumeCapacity(file, producer, enums, globals, options);
1178811747}
1178911748
1179011749pub fn debugSubprogram(
1179111750 self: *Builder,
1179211751 file: Metadata,
11793 scope: Metadata,
1179411752 name: MetadataString,
1179511753 linkage_name: MetadataString,
1179611754 line: u32,
......@@ -11802,7 +11760,6 @@ pub fn debugSubprogram(
1180211760 try self.ensureUnusedMetadataCapacity(1, Metadata.Subprogram, 0);
1180311761 return self.debugSubprogramAssumeCapacity(
1180411762 file,
11805 scope,
1180611763 name,
1180711764 linkage_name,
1180811765 line,
......@@ -11858,7 +11815,6 @@ pub fn debugStructType(
1185811815 size_in_bits: u64,
1185911816 align_in_bits: u64,
1186011817 fields_tuple: Metadata,
11861 is_byref: bool,
1186211818) Allocator.Error!Metadata {
1186311819 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);
1186411820 return self.debugStructTypeAssumeCapacity(
......@@ -11870,7 +11826,6 @@ pub fn debugStructType(
1187011826 size_in_bits,
1187111827 align_in_bits,
1187211828 fields_tuple,
11873 is_byref,
1187411829 );
1187511830}
1187611831
......@@ -11884,7 +11839,6 @@ pub fn debugUnionType(
1188411839 size_in_bits: u64,
1188511840 align_in_bits: u64,
1188611841 fields_tuple: Metadata,
11887 is_byref: bool,
1188811842) Allocator.Error!Metadata {
1188911843 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);
1189011844 return self.debugUnionTypeAssumeCapacity(
......@@ -11896,7 +11850,6 @@ pub fn debugUnionType(
1189611850 size_in_bits,
1189711851 align_in_bits,
1189811852 fields_tuple,
11899 is_byref,
1190011853 );
1190111854}
1190211855
......@@ -12020,53 +11973,6 @@ pub fn debugMemberType(
1202011973 );
1202111974}
1202211975
12023pub fn debugTypedef(
12024 self: *Builder,
12025 name: MetadataString,
12026 file: Metadata,
12027 scope: Metadata,
12028 line: u32,
12029 underlying_type: Metadata,
12030 align_in_bits: u64,
12031) Allocator.Error!Metadata {
12032 try self.ensureUnusedMetadataCapacity(1, Metadata.DerivedType, 0);
12033
12034 assert(!self.strip);
12035 return self.metadataSimpleAssumeCapacity(.derived_typedef, Metadata.DerivedType{
12036 .name = name,
12037 .file = file,
12038 .scope = scope,
12039 .line = line,
12040 .underlying_type = underlying_type,
12041 .size_in_bits_lo = 0,
12042 .size_in_bits_hi = 0,
12043 .align_in_bits_lo = @truncate(align_in_bits),
12044 .align_in_bits_hi = @truncate(align_in_bits >> 32),
12045 .offset_in_bits_lo = 0,
12046 .offset_in_bits_hi = 0,
12047 });
12048}
12049
12050pub fn debugImportDeclaration(
12051 self: *Builder,
12052 name: MetadataString,
12053 file: Metadata,
12054 scope: Metadata,
12055 line: u32,
12056 entity: Metadata,
12057) Allocator.Error!Metadata {
12058 try self.ensureUnusedMetadataCapacity(1, Metadata.ImportedEntity, 0);
12059
12060 assert(!self.strip);
12061 return self.metadataSimpleAssumeCapacity(.imported_declaration, Metadata.ImportedEntity{
12062 .name = name,
12063 .file = file,
12064 .scope = scope,
12065 .line = line,
12066 .entity = entity,
12067 });
12068}
12069
1207011976pub fn debugSubroutineType(
1207111977 self: *Builder,
1207211978 types_tuple: Metadata,
......@@ -12157,7 +12063,7 @@ pub fn debugGlobalVar(
1215712063 line: u32,
1215812064 ty: Metadata,
1215912065 variable: Variable.Index,
12160 internal: bool,
12066 options: Metadata.GlobalVar.Options,
1216112067) Allocator.Error!Metadata {
1216212068 try self.ensureUnusedMetadataCapacity(1, Metadata.GlobalVar, 0);
1216312069 return self.debugGlobalVarAssumeCapacity(
......@@ -12168,7 +12074,7 @@ pub fn debugGlobalVar(
1216812074 line,
1216912075 ty,
1217012076 variable,
12171 internal,
12077 options,
1217212078 );
1217312079}
1217412080
......@@ -12301,7 +12207,6 @@ pub fn debugCompileUnitAssumeCapacity(
1230112207 producer: MetadataString,
1230212208 enums: Metadata,
1230312209 globals: Metadata,
12304 imports: Metadata,
1230512210 options: Metadata.CompileUnit.Options,
1230612211) Metadata {
1230712212 assert(!self.strip);
......@@ -12312,7 +12217,6 @@ pub fn debugCompileUnitAssumeCapacity(
1231212217 .producer = producer,
1231312218 .enums = enums,
1231412219 .globals = globals,
12315 .imports = imports,
1231612220 },
1231712221 );
1231812222}
......@@ -12320,7 +12224,6 @@ pub fn debugCompileUnitAssumeCapacity(
1232012224fn debugSubprogramAssumeCapacity(
1232112225 self: *Builder,
1232212226 file: Metadata,
12323 scope: Metadata,
1232412227 name: MetadataString,
1232512228 linkage_name: MetadataString,
1232612229 line: u32,
......@@ -12334,7 +12237,6 @@ fn debugSubprogramAssumeCapacity(
1233412237 @as(u3, @truncate(@as(u32, @bitCast(options.sp_flags)) >> 2)));
1233512238 return self.metadataDistinctAssumeCapacity(tag, Metadata.Subprogram{
1233612239 .file = file,
12337 .scope = scope,
1233812240 .name = name,
1233912241 .linkage_name = linkage_name,
1234012242 .line = line,
......@@ -12418,7 +12320,6 @@ fn debugStructTypeAssumeCapacity(
1241812320 size_in_bits: u64,
1241912321 align_in_bits: u64,
1242012322 fields_tuple: Metadata,
12421 is_byref: bool,
1242212323) Metadata {
1242312324 assert(!self.strip);
1242412325 return self.debugCompositeTypeAssumeCapacity(
......@@ -12431,7 +12332,6 @@ fn debugStructTypeAssumeCapacity(
1243112332 size_in_bits,
1243212333 align_in_bits,
1243312334 fields_tuple,
12434 is_byref,
1243512335 );
1243612336}
1243712337
......@@ -12445,7 +12345,6 @@ fn debugUnionTypeAssumeCapacity(
1244512345 size_in_bits: u64,
1244612346 align_in_bits: u64,
1244712347 fields_tuple: Metadata,
12448 is_byref: bool,
1244912348) Metadata {
1245012349 assert(!self.strip);
1245112350 return self.debugCompositeTypeAssumeCapacity(
......@@ -12458,7 +12357,6 @@ fn debugUnionTypeAssumeCapacity(
1245812357 size_in_bits,
1245912358 align_in_bits,
1246012359 fields_tuple,
12461 is_byref,
1246212360 );
1246312361}
1246412362
......@@ -12484,7 +12382,6 @@ fn debugEnumerationTypeAssumeCapacity(
1248412382 size_in_bits,
1248512383 align_in_bits,
1248612384 fields_tuple,
12487 false, // is_byref
1248812385 );
1248912386}
1249012387
......@@ -12510,7 +12407,6 @@ fn debugArrayTypeAssumeCapacity(
1251012407 size_in_bits,
1251112408 align_in_bits,
1251212409 fields_tuple,
12513 size_in_bits > 0, // is_byref
1251412410 );
1251512411}
1251612412
......@@ -12536,7 +12432,6 @@ fn debugVectorTypeAssumeCapacity(
1253612432 size_in_bits,
1253712433 align_in_bits,
1253812434 fields_tuple,
12539 false,
1254012435 );
1254112436}
1254212437
......@@ -12551,7 +12446,6 @@ fn debugCompositeTypeAssumeCapacity(
1255112446 size_in_bits: u64,
1255212447 align_in_bits: u64,
1255312448 fields_tuple: Metadata,
12554 is_byref: bool,
1255512449) Metadata {
1255612450 assert(!self.strip);
1255712451 return self.metadataSimpleAssumeCapacity(tag, Metadata.CompositeType{
......@@ -12565,7 +12459,6 @@ fn debugCompositeTypeAssumeCapacity(
1256512459 .align_in_bits_lo = @truncate(align_in_bits),
1256612460 .align_in_bits_hi = @truncate(align_in_bits >> 32),
1256712461 .fields_tuple = fields_tuple,
12568 .flags = .{ .is_byref = is_byref },
1256912462 });
1257012463}
1257112464
......@@ -12876,11 +12769,11 @@ fn debugGlobalVarAssumeCapacity(
1287612769 line: u32,
1287712770 ty: Metadata,
1287812771 variable: Variable.Index,
12879 internal: bool,
12772 options: Metadata.GlobalVar.Options,
1288012773) Metadata {
1288112774 assert(!self.strip);
1288212775 return self.metadataDistinctAssumeCapacity(
12883 if (internal) .@"global_var local" else .global_var,
12776 if (options.local) .@"global_var local" else .global_var,
1288412777 Metadata.GlobalVar{
1288512778 .name = name,
1288612779 .linkage_name = linkage_name,
......@@ -13911,7 +13804,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1391113804 },
1391213805 .enums = extra.enums,
1391313806 .globals = extra.globals,
13914 .imports = extra.imports,
1391513807 }, metadata_adapter);
1391613808 },
1391713809 .subprogram,
......@@ -13926,7 +13818,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1392613818 const extra = self.metadataExtraData(Metadata.Subprogram, data);
1392713819
1392813820 try metadata_block.writeAbbrevAdapted(MetadataBlock.Subprogram{
13929 .scope = extra.scope,
13821 .scope = extra.file,
1393013822 .name = extra.name,
1393113823 .linkage_name = extra.linkage_name,
1393213824 .file = extra.file,
......@@ -14000,24 +13892,18 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1400013892 .underlying_type = extra.underlying_type,
1400113893 .size_in_bits = extra.bitSize(),
1400213894 .align_in_bits = extra.bitAlign(),
14003 .flags = .{
14004 .Vector = kind == .composite_vector_type,
14005 .EnumClass = kind == .composite_enumeration_type,
14006 .TypePassbyReference = extra.flags.is_byref,
14007 },
13895 .flags = if (kind == .composite_vector_type) .{ .Vector = true } else .{},
1400813896 .elements = extra.fields_tuple,
1400913897 }, metadata_adapter);
1401013898 },
1401113899 .derived_pointer_type,
1401213900 .derived_member_type,
14013 .derived_typedef,
1401413901 => |kind| {
1401513902 const extra = self.metadataExtraData(Metadata.DerivedType, data);
1401613903 try metadata_block.writeAbbrevAdapted(MetadataBlock.DerivedType{
1401713904 .tag = switch (kind) {
1401813905 .derived_pointer_type => DW.TAG.pointer_type,
1401913906 .derived_member_type => DW.TAG.member,
14020 .derived_typedef => DW.TAG.typedef,
1402113907 else => unreachable,
1402213908 },
1402313909 .name = extra.name,
......@@ -14028,20 +13914,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1402813914 .size_in_bits = extra.bitSize(),
1402913915 .align_in_bits = extra.bitAlign(),
1403013916 .offset_in_bits = extra.bitOffset(),
14031 .flags = .{
14032 .StaticMember = false,
14033 },
14034 }, metadata_adapter);
14035 },
14036 .imported_declaration => {
14037 const extra = self.metadataExtraData(Metadata.ImportedEntity, data);
14038 try metadata_block.writeAbbrevAdapted(MetadataBlock.ImportedEntity{
14039 .tag = DW.TAG.imported_declaration,
14040 .scope = extra.scope,
14041 .entity = extra.entity,
14042 .line = extra.line,
14043 .name = extra.name,
14044 .file = extra.file,
1404513917 }, metadata_adapter);
1404613918 },
1404713919 .subroutine_type => {
src/codegen/llvm/ir.zig+3-27
......@@ -649,7 +649,6 @@ pub const MetadataBlock = struct {
649649 BasicType,
650650 CompositeType,
651651 DerivedType,
652 ImportedEntity,
653652 SubroutineType,
654653 Enumerator,
655654 Subrange,
......@@ -695,7 +694,7 @@ pub const MetadataBlock = struct {
695694 pub const ops = [_]AbbrevOp{
696695 .{ .literal = 20 },
697696 .{ .literal = 1 }, // is distinct
698 .{ .literal = std.dwarf.LANG.C_plus_plus_11 }, // source language
697 .{ .literal = std.dwarf.LANG.C99 }, // source language
699698 MetadataAbbrev, // file
700699 MetadataAbbrev, // producer
701700 .{ .fixed = 1 }, // isOptimized
......@@ -707,7 +706,7 @@ pub const MetadataBlock = struct {
707706 .{ .literal = 0 }, // retained types
708707 .{ .literal = 0 }, // subprograms
709708 MetadataAbbrev, // globals
710 MetadataAbbrev, // imported entities
709 .{ .literal = 0 }, // imported entities
711710 .{ .literal = 0 }, // DWO ID
712711 .{ .literal = 0 }, // macros
713712 .{ .literal = 0 }, // split debug inlining
......@@ -723,7 +722,6 @@ pub const MetadataBlock = struct {
723722 is_optimized: bool,
724723 enums: Builder.Metadata,
725724 globals: Builder.Metadata,
726 imports: Builder.Metadata,
727725 };
728726
729727 pub const Subprogram = struct {
......@@ -865,7 +863,7 @@ pub const MetadataBlock = struct {
865863 .{ .vbr = 6 }, // size in bits
866864 .{ .vbr = 6 }, // align in bits
867865 .{ .vbr = 6 }, // offset in bits
868 .{ .fixed = 32 }, // flags
866 .{ .literal = 0 }, // flags
869867 .{ .literal = 0 }, // extra data
870868 };
871869
......@@ -878,28 +876,6 @@ pub const MetadataBlock = struct {
878876 size_in_bits: u64,
879877 align_in_bits: u64,
880878 offset_in_bits: u64,
881 flags: Builder.Metadata.DIFlags,
882 };
883
884 pub const ImportedEntity = struct {
885 pub const ops = [_]AbbrevOp{
886 .{ .literal = 31 },
887 .{ .literal = 0 }, // is distinct
888 .{ .fixed = 32 }, // tag
889 MetadataAbbrev, // scope
890 MetadataAbbrev, // entity
891 LineAbbrev, // line
892 MetadataAbbrev, // name
893 MetadataAbbrev, // file
894 .{ .literal = 0 }, // elements
895 };
896
897 tag: u32,
898 scope: Builder.Metadata,
899 entity: Builder.Metadata,
900 line: u32,
901 name: Builder.MetadataString,
902 file: Builder.Metadata,
903879 };
904880
905881 pub const SubroutineType = struct {
test/cases/llvm/debug_types.zig deleted-23
......@@ -1,23 +0,0 @@
1const Ty = struct {
2 pub const A = void;
3 pub const B = @Vector(2, u0);
4 pub const C = u0;
5 pub const D = enum (u0) {};
6 pub const E = type;
7 pub const F = 1;
8 pub const G = 1.0;
9 pub const H = undefined;
10 pub const I = null;
11 pub const J = .foo;
12};
13pub fn main() void {
14 inline for (@typeInfo(Ty).Struct.decls) |d|{
15 _ = @field(Ty, d.name);
16 }
17}
18
19// compile
20// output_mode=Exe
21// backend=llvm
22// target=x86_64-linux,x86_64-macos
23//
\ No newline at end of file