authorgravatar for jonathan.haehne@hotmail.comTau <jonathan.haehne@hotmail.com> 2024-06-21 00:53:11+02:00
committergravatar for jonathan.haehne@hotmail.comTau <jonathan.haehne@hotmail.com> 2024-07-19 17:51:37+02:00
log359bbdd5748779a4e1b12706e0be704cfacb5078
treee68f19e9bec8e2771d6442aad19764848c0f80ee
parent876258abe46273aeac7c9791c7ec69bceb29f5ae

llvm: encode variables as DW_TAG_imported_declaration

Now we get working global variable lookup in GDB! LLDB still re-mangles, and it looks like we can't do much about that for now. Also: translate non-owning type declarations into typedefs.

3 files changed, 550 insertions(+), 412 deletions(-)

src/codegen/llvm.zig+412-389
...@@ -814,14 +814,17 @@ pub const Object = struct {...@@ -814,14 +814,17 @@ pub const Object = struct {
814814
815 debug_enums_fwd_ref: Builder.Metadata,815 debug_enums_fwd_ref: Builder.Metadata,
816 debug_globals_fwd_ref: Builder.Metadata,816 debug_globals_fwd_ref: Builder.Metadata,
817 debug_imports_fwd_ref: Builder.Metadata,
817818
818 debug_enums: std.ArrayListUnmanaged(Builder.Metadata),819 debug_enums: std.ArrayListUnmanaged(Builder.Metadata),
819 debug_globals: std.ArrayListUnmanaged(Builder.Metadata),820 debug_globals: std.ArrayListUnmanaged(Builder.Metadata),
821 debug_imports: std.ArrayListUnmanaged(Builder.Metadata),
820822
821 debug_file_map: std.AutoHashMapUnmanaged(*const Zcu.File, Builder.Metadata),823 debug_file_map: std.AutoHashMapUnmanaged(*const Zcu.File, Builder.Metadata),
822 debug_type_map: std.AutoHashMapUnmanaged(Type, Builder.Metadata),824 debug_type_map: std.AutoHashMapUnmanaged(Type, Builder.Metadata),
823825
824 debug_unresolved_namespace_scopes: std.AutoArrayHashMapUnmanaged(InternPool.NamespaceIndex, Builder.Metadata),826 // The value says whether this namespace's type is runtime-required.
827 debug_unresolved_namespace_scopes: std.AutoArrayHashMapUnmanaged(Type, bool),
825828
826 target: std.Target,829 target: std.Target,
827 /// Ideally we would use `llvm_module.getNamedFunction` to go from *Decl to LLVM function,830 /// Ideally we would use `llvm_module.getNamedFunction` to go from *Decl to LLVM function,
...@@ -884,7 +887,7 @@ pub const Object = struct {...@@ -884,7 +887,7 @@ pub const Object = struct {
884887
885 builder.data_layout = try builder.fmt("{}", .{DataLayoutBuilder{ .target = target }});888 builder.data_layout = try builder.fmt("{}", .{DataLayoutBuilder{ .target = target }});
886889
887 const debug_compile_unit, const debug_enums_fwd_ref, const debug_globals_fwd_ref =890 const debug_compile_unit, const debug_enums_fwd_ref, const debug_globals_fwd_ref, const debug_imports_fwd_ref =
888 if (!builder.strip)891 if (!builder.strip)
889 debug_info: {892 debug_info: {
890 // We fully resolve all paths at this point to avoid lack of893 // We fully resolve all paths at this point to avoid lack of
...@@ -916,6 +919,7 @@ pub const Object = struct {...@@ -916,6 +919,7 @@ pub const Object = struct {
916919
917 const debug_enums_fwd_ref = try builder.debugForwardReference();920 const debug_enums_fwd_ref = try builder.debugForwardReference();
918 const debug_globals_fwd_ref = try builder.debugForwardReference();921 const debug_globals_fwd_ref = try builder.debugForwardReference();
922 const debug_imports_fwd_ref = try builder.debugForwardReference();
919923
920 const debug_compile_unit = try builder.debugCompileUnit(924 const debug_compile_unit = try builder.debugCompileUnit(
921 debug_file,925 debug_file,
...@@ -928,6 +932,7 @@ pub const Object = struct {...@@ -928,6 +932,7 @@ pub const Object = struct {
928 }),932 }),
929 debug_enums_fwd_ref,933 debug_enums_fwd_ref,
930 debug_globals_fwd_ref,934 debug_globals_fwd_ref,
935 debug_imports_fwd_ref,
931 .{ .optimized = comp.root_mod.optimize_mode != .Debug },936 .{ .optimized = comp.root_mod.optimize_mode != .Debug },
932 );937 );
933938
...@@ -983,8 +988,8 @@ pub const Object = struct {...@@ -983,8 +988,8 @@ pub const Object = struct {
983 }988 }
984989
985 try builder.debugNamed(try builder.metadataString("llvm.dbg.cu"), &.{debug_compile_unit});990 try builder.debugNamed(try builder.metadataString("llvm.dbg.cu"), &.{debug_compile_unit});
986 break :debug_info .{ debug_compile_unit, debug_enums_fwd_ref, debug_globals_fwd_ref };991 break :debug_info .{ debug_compile_unit, debug_enums_fwd_ref, debug_globals_fwd_ref, debug_imports_fwd_ref };
987 } else .{.none} ** 3;992 } else .{.none} ** 4;
988993
989 const obj = try arena.create(Object);994 const obj = try arena.create(Object);
990 obj.* = .{995 obj.* = .{
...@@ -997,8 +1002,10 @@ pub const Object = struct {...@@ -997,8 +1002,10 @@ pub const Object = struct {
997 .debug_compile_unit = debug_compile_unit,1002 .debug_compile_unit = debug_compile_unit,
998 .debug_enums_fwd_ref = debug_enums_fwd_ref,1003 .debug_enums_fwd_ref = debug_enums_fwd_ref,
999 .debug_globals_fwd_ref = debug_globals_fwd_ref,1004 .debug_globals_fwd_ref = debug_globals_fwd_ref,
1005 .debug_imports_fwd_ref = debug_imports_fwd_ref,
1000 .debug_enums = .{},1006 .debug_enums = .{},
1001 .debug_globals = .{},1007 .debug_globals = .{},
1008 .debug_imports = .{},
1002 .debug_file_map = .{},1009 .debug_file_map = .{},
1003 .debug_type_map = .{},1010 .debug_type_map = .{},
1004 .debug_unresolved_namespace_scopes = .{},1011 .debug_unresolved_namespace_scopes = .{},
...@@ -1151,6 +1158,11 @@ pub const Object = struct {...@@ -1151,6 +1158,11 @@ pub const Object = struct {
1151 self.debug_globals_fwd_ref,1158 self.debug_globals_fwd_ref,
1152 try self.builder.debugTuple(self.debug_globals.items),1159 try self.builder.debugTuple(self.debug_globals.items),
1153 );1160 );
1161
1162 self.builder.debugForwardReferenceSetType(
1163 self.debug_imports_fwd_ref,
1164 try self.builder.debugTuple(self.debug_imports.items),
1165 );
1154 }1166 }
1155 }1167 }
11561168
...@@ -1634,7 +1646,7 @@ pub const Object = struct {...@@ -1634,7 +1646,7 @@ pub const Object = struct {
16341646
1635 const line_number = decl.navSrcLine(zcu) + 1;1647 const line_number = decl.navSrcLine(zcu) + 1;
1636 const is_internal_linkage = decl.val.getExternFunc(zcu) == null;1648 const is_internal_linkage = decl.val.getExternFunc(zcu) == null;
1637 const debug_decl_type = try o.lowerDebugType(decl.typeOf(zcu));1649 const debug_decl_type = try o.lowerDebugType(decl.typeOf(zcu), true);
16381650
1639 const subprogram = try o.builder.debugSubprogram(1651 const subprogram = try o.builder.debugSubprogram(
1640 file,1652 file,
...@@ -1904,6 +1916,7 @@ pub const Object = struct {...@@ -1904,6 +1916,7 @@ pub const Object = struct {
1904 pub fn lowerDebugType(1916 pub fn lowerDebugType(
1905 o: *Object,1917 o: *Object,
1906 ty: Type,1918 ty: Type,
1919 required_by_runtime: bool,
1907 ) Allocator.Error!Builder.Metadata {1920 ) Allocator.Error!Builder.Metadata {
1908 assert(!o.builder.strip);1921 assert(!o.builder.strip);
19091922
...@@ -1913,8 +1926,13 @@ pub const Object = struct {...@@ -1913,8 +1926,13 @@ pub const Object = struct {
1913 const zcu = pt.zcu;1926 const zcu = pt.zcu;
1914 const ip = &zcu.intern_pool;1927 const ip = &zcu.intern_pool;
19151928
1916 if (o.debug_type_map.get(ty)) |debug_type| return debug_type;1929 if (o.debug_type_map.get(ty)) |debug_type| {
19171930 if (required_by_runtime) {
1931 if (o.debug_unresolved_namespace_scopes.getEntry(ty)) |entry|
1932 entry.value_ptr.* = true;
1933 }
1934 return debug_type;
1935 }
19181936
1919 switch (ty.zigTypeTag(zcu)) {1937 switch (ty.zigTypeTag(zcu)) {
1920 .Void,1938 .Void,
...@@ -1988,7 +2006,7 @@ pub const Object = struct {...@@ -1988,7 +2006,7 @@ pub const Object = struct {
1988 },2006 },
1989 },2007 },
1990 });2008 });
1991 const debug_ptr_type = try o.lowerDebugType(bland_ptr_ty);2009 const debug_ptr_type = try o.lowerDebugType(bland_ptr_ty, required_by_runtime);
1992 try o.debug_type_map.put(gpa, ty, debug_ptr_type);2010 try o.debug_type_map.put(gpa, ty, debug_ptr_type);
1993 return debug_ptr_type;2011 return debug_ptr_type;
1994 }2012 }
...@@ -2019,7 +2037,7 @@ pub const Object = struct {...@@ -2019,7 +2037,7 @@ pub const Object = struct {
2019 .none, // File2037 .none, // File
2020 debug_fwd_ref,2038 debug_fwd_ref,
2021 0, // Line2039 0, // Line
2022 try o.lowerDebugType(ptr_ty),2040 try o.lowerDebugType(ptr_ty, required_by_runtime),
2023 ptr_size * 8,2041 ptr_size * 8,
2024 (ptr_align.toByteUnits() orelse 0) * 8,2042 (ptr_align.toByteUnits() orelse 0) * 8,
2025 0, // Offset2043 0, // Offset
...@@ -2030,7 +2048,7 @@ pub const Object = struct {...@@ -2030,7 +2048,7 @@ pub const Object = struct {
2030 .none, // File2048 .none, // File
2031 debug_fwd_ref,2049 debug_fwd_ref,
2032 0, // Line2050 0, // Line
2033 try o.lowerDebugType(len_ty),2051 try o.lowerDebugType(len_ty, required_by_runtime),
2034 len_size * 8,2052 len_size * 8,
2035 (len_align.toByteUnits() orelse 0) * 8,2053 (len_align.toByteUnits() orelse 0) * 8,
2036 len_offset * 8,2054 len_offset * 8,
...@@ -2059,7 +2077,7 @@ pub const Object = struct {...@@ -2059,7 +2077,7 @@ pub const Object = struct {
2059 return debug_slice_type;2077 return debug_slice_type;
2060 }2078 }
20612079
2062 const debug_elem_ty = try o.lowerDebugType(Type.fromInterned(ptr_info.child));2080 const debug_elem_ty = try o.lowerDebugType(Type.fromInterned(ptr_info.child), required_by_runtime);
20632081
2064 const name = try o.allocTypeName(ty);2082 const name = try o.allocTypeName(ty);
2065 defer gpa.free(name);2083 defer gpa.free(name);
...@@ -2089,7 +2107,7 @@ pub const Object = struct {...@@ -2089,7 +2107,7 @@ pub const Object = struct {
2089 .none, // File2107 .none, // File
2090 .none, // Scope2108 .none, // Scope
2091 0, // Line2109 0, // Line
2092 try o.lowerDebugType(ty.childType(zcu)),2110 try o.lowerDebugType(ty.childType(zcu), required_by_runtime),
2093 ty.abiSize(pt) * 8,2111 ty.abiSize(pt) * 8,
2094 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,2112 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2095 try o.builder.debugTuple(&.{2113 try o.builder.debugTuple(&.{
...@@ -2124,7 +2142,7 @@ pub const Object = struct {...@@ -2124,7 +2142,7 @@ pub const Object = struct {
2124 try o.builder.metadataString("bool"),2142 try o.builder.metadataString("bool"),
2125 1,2143 1,
2126 ),2144 ),
2127 else => try o.lowerDebugType(ty.childType(zcu)),2145 else => try o.lowerDebugType(ty.childType(zcu), required_by_runtime),
2128 };2146 };
21292147
2130 const debug_vector_type = try o.builder.debugVectorType(2148 const debug_vector_type = try o.builder.debugVectorType(
...@@ -2166,7 +2184,7 @@ pub const Object = struct {...@@ -2166,7 +2184,7 @@ pub const Object = struct {
2166 try o.debug_type_map.put(gpa, ty, debug_fwd_ref);2184 try o.debug_type_map.put(gpa, ty, debug_fwd_ref);
21672185
2168 if (ty.optionalReprIsPayload(zcu)) {2186 if (ty.optionalReprIsPayload(zcu)) {
2169 const debug_optional_type = try o.lowerDebugType(child_ty);2187 const debug_optional_type = try o.lowerDebugType(child_ty, required_by_runtime);
21702188
2171 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type);2189 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type);
21722190
...@@ -2189,7 +2207,7 @@ pub const Object = struct {...@@ -2189,7 +2207,7 @@ pub const Object = struct {
2189 .none, // File2207 .none, // File
2190 debug_fwd_ref,2208 debug_fwd_ref,
2191 0, // Line2209 0, // Line
2192 try o.lowerDebugType(child_ty),2210 try o.lowerDebugType(child_ty, required_by_runtime),
2193 payload_size * 8,2211 payload_size * 8,
2194 (payload_align.toByteUnits() orelse 0) * 8,2212 (payload_align.toByteUnits() orelse 0) * 8,
2195 0, // Offset2213 0, // Offset
...@@ -2200,7 +2218,7 @@ pub const Object = struct {...@@ -2200,7 +2218,7 @@ pub const Object = struct {
2200 .none,2218 .none,
2201 debug_fwd_ref,2219 debug_fwd_ref,
2202 0,2220 0,
2203 try o.lowerDebugType(non_null_ty),2221 try o.lowerDebugType(non_null_ty, required_by_runtime),
2204 non_null_size * 8,2222 non_null_size * 8,
2205 (non_null_align.toByteUnits() orelse 0) * 8,2223 (non_null_align.toByteUnits() orelse 0) * 8,
2206 non_null_offset * 8,2224 non_null_offset * 8,
...@@ -2232,7 +2250,7 @@ pub const Object = struct {...@@ -2232,7 +2250,7 @@ pub const Object = struct {
2232 const payload_ty = ty.errorUnionPayload(zcu);2250 const payload_ty = ty.errorUnionPayload(zcu);
2233 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {2251 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
2234 // TODO: Maybe remove?2252 // TODO: Maybe remove?
2235 const debug_error_union_type = try o.lowerDebugType(Type.anyerror);2253 const debug_error_union_type = try o.lowerDebugType(Type.anyerror, required_by_runtime);
2236 try o.debug_type_map.put(gpa, ty, debug_error_union_type);2254 try o.debug_type_map.put(gpa, ty, debug_error_union_type);
2237 return debug_error_union_type;2255 return debug_error_union_type;
2238 }2256 }
...@@ -2269,7 +2287,7 @@ pub const Object = struct {...@@ -2269,7 +2287,7 @@ pub const Object = struct {
2269 .none, // File2287 .none, // File
2270 debug_fwd_ref,2288 debug_fwd_ref,
2271 0, // Line2289 0, // Line
2272 try o.lowerDebugType(Type.anyerror),2290 try o.lowerDebugType(Type.anyerror, required_by_runtime),
2273 error_size * 8,2291 error_size * 8,
2274 (error_align.toByteUnits() orelse 0) * 8,2292 (error_align.toByteUnits() orelse 0) * 8,
2275 error_offset * 8,2293 error_offset * 8,
...@@ -2279,7 +2297,7 @@ pub const Object = struct {...@@ -2279,7 +2297,7 @@ pub const Object = struct {
2279 .none, // File2297 .none, // File
2280 debug_fwd_ref,2298 debug_fwd_ref,
2281 0, // Line2299 0, // Line
2282 try o.lowerDebugType(payload_ty),2300 try o.lowerDebugType(payload_ty, required_by_runtime),
2283 payload_size * 8,2301 payload_size * 8,
2284 (payload_align.toByteUnits() orelse 0) * 8,2302 (payload_align.toByteUnits() orelse 0) * 8,
2285 payload_offset * 8,2303 payload_offset * 8,
...@@ -2321,21 +2339,21 @@ pub const Object = struct {...@@ -2321,21 +2339,21 @@ pub const Object = struct {
2321 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(pt)) {2339 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(pt)) {
2322 const sret = firstParamSRet(fn_info, pt, target);2340 const sret = firstParamSRet(fn_info, pt, target);
2323 const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type);2341 const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type);
2324 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty));2342 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty, required_by_runtime));
23252343
2326 if (sret) {2344 if (sret) {
2327 const ptr_ty = try pt.singleMutPtrType(Type.fromInterned(fn_info.return_type));2345 const ptr_ty = try pt.singleMutPtrType(Type.fromInterned(fn_info.return_type));
2328 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));2346 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty, required_by_runtime));
2329 }2347 }
2330 } else {2348 } else {
2331 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(Type.void));2349 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(Type.void, required_by_runtime));
2332 }2350 }
23332351
2334 if (Type.fromInterned(fn_info.return_type).isError(zcu) and2352 if (Type.fromInterned(fn_info.return_type).isError(zcu) and
2335 zcu.comp.config.any_error_tracing)2353 zcu.comp.config.any_error_tracing)
2336 {2354 {
2337 const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType());2355 const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType());
2338 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));2356 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty, required_by_runtime));
2339 }2357 }
23402358
2341 for (0..fn_info.param_types.len) |i| {2359 for (0..fn_info.param_types.len) |i| {
...@@ -2344,9 +2362,9 @@ pub const Object = struct {...@@ -2344,9 +2362,9 @@ pub const Object = struct {
23442362
2345 if (isByRef(param_ty, pt)) {2363 if (isByRef(param_ty, pt)) {
2346 const ptr_ty = try pt.singleMutPtrType(param_ty);2364 const ptr_ty = try pt.singleMutPtrType(param_ty);
2347 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));2365 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty, required_by_runtime));
2348 } else {2366 } else {
2349 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(param_ty));2367 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(param_ty, required_by_runtime));
2350 }2368 }
2351 }2369 }
23522370
...@@ -2367,421 +2385,419 @@ pub const Object = struct {...@@ -2367,421 +2385,419 @@ pub const Object = struct {
2367 .Frame => @panic("TODO implement lowerDebugType for Frame types"),2385 .Frame => @panic("TODO implement lowerDebugType for Frame types"),
2368 .AnyFrame => @panic("TODO implement lowerDebugType for AnyFrame types"),2386 .AnyFrame => @panic("TODO implement lowerDebugType for AnyFrame types"),
2369 // These are the types that need a correct scope.2387 // These are the types that need a correct scope.
2370 .Enum,2388 .Enum, .Struct, .Union, .Opaque => {},
2371 .Struct,
2372 .Union,
2373 .Opaque => {}
2374 }2389 }
2390 const fwd_ref = try o.builder.debugForwardReference();
2391 try o.debug_type_map.put(gpa, ty, fwd_ref);
2392 try o.debug_unresolved_namespace_scopes.put(gpa, ty, required_by_runtime);
23752393
2394 return fwd_ref;
2395 }
23762396
2377 const owner_decl_index = ty.getOwnerDeclOrNull(zcu);2397 fn genNamespaces(o: *Object) !void {
2378 const owner_decl: ?*Zcu.Decl =2398 const gpa = o.gpa;
2379 if (owner_decl_index) |owner| zcu.declPtr(owner) else null;2399 const pt = o.pt;
2400 const zcu = pt.zcu;
2401 const ip = &zcu.intern_pool;
23802402
2381 const file = if (owner_decl) |owner|2403 var fields: std.ArrayListUnmanaged(Builder.Metadata) = .{};
2382 try o.getDebugFile(zcu.namespacePtr(owner.src_namespace).fileScope(zcu)) else .none;2404 defer fields.deinit(gpa);
2383 const scope = if (owner_decl) |owner|
2384 try o.namespaceToDebugScope(owner.src_namespace) else o.debug_compile_unit;
2385 const line = if (owner_decl) |owner| owner.typeSrcLine(zcu) + 1 else 0;
23862405
2406 const unresolved = &o.debug_unresolved_namespace_scopes;
2407 var unresolved_i: usize = 0;
2408 while (unresolved_i < unresolved.count()) : (unresolved_i += 1) {
2409 const ty = unresolved.keys()[unresolved_i];
2410 const required_by_runtime = unresolved.values()[unresolved_i];
23872411
2388 const name = if (owner_decl) |owner| owner.name.toSlice(ip) else try o.allocTypeName(ty);2412 const owner_decl_index = ty.getOwnerDeclOrNull(zcu);
2389 defer if (owner_decl == null) gpa.free(name);2413 const owner_decl: ?*Zcu.Decl =
2414 if (owner_decl_index) |owner| ip.declPtr(owner) else null;
23902415
2391 switch (ty.zigTypeTag(zcu)) {2416 const file = if (owner_decl) |owner|
2392 .Enum => {2417 try o.getDebugFile(zcu.namespacePtr(owner.src_namespace).fileScope(zcu))
2393 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {2418 else
2394 const debug_enum_type = try o.makeEmptyNamespaceDebugType(owner_decl_index.?);2419 .none;
2395 try o.debug_type_map.put(gpa, ty, debug_enum_type);2420 const scope = if (owner_decl) |owner|
2396 return debug_enum_type;2421 try o.namespaceToDebugScope(owner.src_namespace)
2397 }2422 else
2423 o.debug_compile_unit;
2424 const line = if (owner_decl) |owner| owner.typeSrcLine(zcu) + 1 else 0;
23982425
2399 const enum_type = ip.loadEnumType(ty.toIntern());2426 const name = if (owner_decl) |owner| owner.name.toSlice(ip) else try o.allocTypeName(ty);
2427 defer if (owner_decl == null) gpa.free(name);
24002428
2401 const enumerators = try gpa.alloc(Builder.Metadata, enum_type.names.len);2429 const fwd_ref = o.debug_type_map.get(ty).?;
2402 defer gpa.free(enumerators);
24032430
2404 const int_ty = Type.fromInterned(enum_type.tag_ty);2431 fields.clearRetainingCapacity();
2405 const int_info = ty.intInfo(zcu);
2406 assert(int_info.bits != 0);
24072432
2408 for (enum_type.names.get(ip), 0..) |field_name_ip, i| {2433 const ns = if (ty.getNamespace(zcu)) |n| n.unwrap() else null;
2409 var bigint_space: Value.BigIntSpace = undefined;2434 if (ns) |ns_id| {
2410 const bigint = if (enum_type.values.len != 0)2435 const namespace = ip.namespacePtr(ns_id);
2411 Value.fromInterned(enum_type.values.get(ip)[i]).toBigInt(&bigint_space, pt)2436 try fields.ensureUnusedCapacity(gpa, namespace.decls.keys().len);
2412 else
2413 std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst();
24142437
2415 enumerators[i] = try o.builder.debugEnumerator(2438 for (namespace.decls.keys()) |decl_id| {
2416 try o.builder.metadataString(field_name_ip.toSlice(ip)),2439 const decl = ip.declPtr(decl_id);
2417 int_info.signedness == .unsigned,2440 const decl_name = decl.name.toSlice(ip);
2418 int_info.bits,
2419 bigint,
2420 );
2421 }
24222441
2423 const debug_enum_type = try o.builder.debugEnumerationType(2442 if (!decl.has_tv) continue;
2424 try o.builder.metadataString(name),2443 if (decl.kind != .named) continue;
2425 file,2444 if (decl.analysis != .complete) continue;
2426 scope,
2427 line,
2428 try o.lowerDebugType(int_ty),
2429 ty.abiSize(pt) * 8,
2430 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2431 try o.builder.debugTuple(enumerators),
2432 );
24332445
2434 try o.debug_type_map.put(gpa, ty, debug_enum_type);2446 const decl_line = decl.typeSrcLine(zcu) + 1;
2435 try o.debug_enums.append(gpa, debug_enum_type);
2436 return debug_enum_type;
2437 },
2438 .Opaque => {
2439 if (ty.toIntern() == .anyopaque_type) {
2440 const debug_opaque_type = try o.builder.debugSignedType(
2441 try o.builder.metadataString("anyopaque"),
2442 0,
2443 );
2444 try o.debug_type_map.put(gpa, ty, debug_opaque_type);
2445 return debug_opaque_type;
2446 }
24472447
2448 const debug_opaque_type = try o.builder.debugStructType(2448 if (decl.val.typeOf(zcu).ip_index == .type_type) {
2449 try o.builder.metadataString(name),2449 const nested_type = decl.val.toType();
2450 file,2450 // If this decl is the owner of the type, it will
2451 scope,2451 // already have been declared as a direct child and
2452 line,2452 // will not need to be typedef'd.
2453 .none, // Underlying type2453 if (nested_type.getOwnerDeclOrNull(zcu)) |owner| {
2454 0, // Size2454 if (owner == decl_id) continue;
2455 0, // Align2455 }
2456 .none, // Fields2456
2457 );2457 fields.appendAssumeCapacity(try o.builder.debugTypedef(
2458 try o.debug_type_map.put(gpa, ty, debug_opaque_type);2458 try o.builder.metadataString(decl_name),
2459 return debug_opaque_type;2459 try o.getDebugFile(namespace.fileScope(zcu)),
2460 },2460 fwd_ref,
2461 .Struct => {2461 decl_line,
2462 if (zcu.typeToPackedStruct(ty)) |struct_type| {2462 try o.lowerDebugType(nested_type, false),
2463 const backing_int_ty = struct_type.backingIntTypeUnordered(ip);2463 0, // Align
2464 if (backing_int_ty != .none) {2464 ));
2465 const info = Type.fromInterned(backing_int_ty).intInfo(zcu);2465 } else if (decl.val.getVariable(zcu)) |v| {
2466 const builder_name = try o.builder.metadataString(name);2466 fields.appendAssumeCapacity(try o.builder.debugStaticMemberType(
2467 const debug_int_type = switch (info.signedness) {2467 try o.builder.metadataString(decl_name),
2468 .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(pt) * 8),2468 try o.getDebugFile(namespace.fileScope(zcu)),
2469 .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(pt) * 8),2469 fwd_ref,
2470 };2470 decl_line,
2471 try o.debug_type_map.put(gpa, ty, debug_int_type);2471 try o.lowerDebugType(Type.fromInterned(v.ty), false),
2472 return debug_int_type;2472 ));
2473 }2473 }
2474 }2474 }
2475 }
24752476
2476 switch (ip.indexToKey(ty.toIntern())) {2477 if (!required_by_runtime) {
2477 .anon_struct_type => |tuple| {2478 const res = try o.makeNamespaceDebugType(owner_decl_index.?, fields.items);
2478 var fields: std.ArrayListUnmanaged(Builder.Metadata) = .{};2479 o.builder.debugForwardReferenceSetType(fwd_ref, res);
2479 defer fields.deinit(gpa);2480 continue;
24802481 }
2481 try fields.ensureUnusedCapacity(gpa, tuple.types.len);
2482
2483 comptime assert(struct_layout_version == 2);
2484 var offset: u64 = 0;
2485
2486 const debug_fwd_ref = try o.builder.debugForwardReference();
2487
2488 for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, field_val, i| {
2489 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(pt)) continue;
2490
2491 const field_size = Type.fromInterned(field_ty).abiSize(pt);
2492 const field_align = Type.fromInterned(field_ty).abiAlignment(pt);
2493 const field_offset = field_align.forward(offset);
2494 offset = field_offset + field_size;
2495
2496 const field_name = if (tuple.names.len != 0)
2497 tuple.names.get(ip)[i].toSlice(ip)
2498 else
2499 try std.fmt.allocPrintZ(gpa, "{d}", .{i});
2500 defer if (tuple.names.len == 0) gpa.free(field_name);
2501
2502 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2503 try o.builder.metadataString(field_name),
2504 .none, // File
2505 debug_fwd_ref,
2506 0,
2507 try o.lowerDebugType(Type.fromInterned(field_ty)),
2508 field_size * 8,
2509 (field_align.toByteUnits() orelse 0) * 8,
2510 field_offset * 8,
2511 ));
2512 }
2513
2514 const debug_struct_type = try o.builder.debugStructType(
2515 try o.builder.metadataString(name),
2516 file,
2517 scope,
2518 0, // Line
2519 .none, // Underlying type
2520 ty.abiSize(pt) * 8,
2521 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2522 try o.builder.debugTuple(fields.items),
2523 );
25242482
2525 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_struct_type);2483 const res = switch (ty.zigTypeTag(zcu)) {
2484 .Enum => res: {
2485 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {
2486 break :res try o.makeNamespaceDebugType(owner_decl_index.?, fields.items);
2487 }
25262488
2527 try o.debug_type_map.put(gpa, ty, debug_struct_type);2489 const enum_type = ip.loadEnumType(ty.toIntern());
2528 return debug_struct_type;
2529 },
2530 .struct_type => {
2531 if (!ip.loadStructType(ty.toIntern()).haveFieldTypes(ip)) {
2532 // This can happen if a struct type makes it all the way to
2533 // flush() without ever being instantiated or referenced (even
2534 // via pointer). The only reason we are hearing about it now is
2535 // that it is being used as a namespace to put other debug types
2536 // into. Therefore we can satisfy this by making an empty namespace,
2537 // rather than changing the frontend to unnecessarily resolve the
2538 // struct field types.
2539 const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index.?);
2540 try o.debug_type_map.put(gpa, ty, debug_struct_type);
2541 return debug_struct_type;
2542 }
2543 },
2544 else => {},
2545 }
25462490
2547 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {2491 const enumerators = try gpa.alloc(Builder.Metadata, enum_type.names.len);
2548 const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index.?);2492 defer gpa.free(enumerators);
2549 try o.debug_type_map.put(gpa, ty, debug_struct_type);
2550 return debug_struct_type;
2551 }
25522493
2553 const struct_type = zcu.typeToStruct(ty).?;2494 const int_ty = Type.fromInterned(enum_type.tag_ty);
2495 const int_info = ty.intInfo(zcu);
2496 assert(int_info.bits != 0);
25542497
2555 var fields: std.ArrayListUnmanaged(Builder.Metadata) = .{};2498 for (enum_type.names.get(ip), 0..) |field_name_ip, i| {
2556 defer fields.deinit(gpa);2499 var bigint_space: Value.BigIntSpace = undefined;
2500 const bigint = if (enum_type.values.len != 0)
2501 Value.fromInterned(enum_type.values.get(ip)[i]).toBigInt(&bigint_space, pt)
2502 else
2503 std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst();
25572504
2558 try fields.ensureUnusedCapacity(gpa, struct_type.field_types.len);2505 enumerators[i] = try o.builder.debugEnumerator(
2506 try o.builder.metadataString(field_name_ip.toSlice(ip)),
2507 int_info.signedness == .unsigned,
2508 int_info.bits,
2509 bigint,
2510 );
2511 }
25592512
2560 const debug_fwd_ref = try o.builder.debugForwardReference();2513 const debug_enum_type = try o.builder.debugEnumerationType(
2514 try o.builder.metadataString(name),
2515 file,
2516 scope,
2517 line,
2518 try o.lowerDebugType(int_ty, required_by_runtime),
2519 ty.abiSize(pt) * 8,
2520 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2521 try o.builder.debugTuple(enumerators),
2522 );
25612523
2562 // Set as forward reference while the type is lowered in case it references itself2524 try o.debug_enums.append(gpa, debug_enum_type);
2563 try o.debug_type_map.put(gpa, ty, debug_fwd_ref);2525 break :res debug_enum_type;
2526 },
2527 .Opaque => res: {
2528 if (ty.toIntern() == .anyopaque_type) {
2529 break :res try o.builder.debugSignedType(
2530 try o.builder.metadataString("anyopaque"),
2531 0,
2532 );
2533 }
25642534
2565 comptime assert(struct_layout_version == 2);2535 const debug_opaque_type = try o.builder.debugStructType(
2566 var it = struct_type.iterateRuntimeOrder(ip);2536 try o.builder.metadataString(name),
2567 while (it.next()) |field_index| {2537 file,
2568 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);2538 scope,
2569 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;2539 line,
2570 const field_size = field_ty.abiSize(pt);2540 .none, // Underlying type
2571 const field_align = pt.structFieldAlignment(2541 0, // Size
2572 struct_type.fieldAlign(ip, field_index),2542 0, // Align
2573 field_ty,2543 .none, // Fields
2574 struct_type.layout,
2575 );2544 );
2576 const field_offset = ty.structFieldOffset(field_index, pt);2545 break :res debug_opaque_type;
2546 },
2547 .Struct => res: {
2548 if (zcu.typeToPackedStruct(ty)) |struct_type| {
2549 const backing_int_ty = struct_type.backingIntTypeUnordered(ip);
2550 if (backing_int_ty != .none) {
2551 const info = Type.fromInterned(backing_int_ty).intInfo(zcu);
2552 const builder_name = try o.builder.metadataString(name);
2553 const debug_int_type = switch (info.signedness) {
2554 .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(pt) * 8),
2555 .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(pt) * 8),
2556 };
2557 break :res debug_int_type;
2558 }
2559 }
25772560
2578 const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse2561 switch (ip.indexToKey(ty.toIntern())) {
2579 try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);2562 .anon_struct_type => |tuple| {
2563 try fields.ensureUnusedCapacity(gpa, tuple.types.len);
2564
2565 comptime assert(struct_layout_version == 2);
2566 var offset: u64 = 0;
2567
2568 for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, field_val, i| {
2569 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(pt)) continue;
2570
2571 const field_size = Type.fromInterned(field_ty).abiSize(pt);
2572 const field_align = Type.fromInterned(field_ty).abiAlignment(pt);
2573 const field_offset = field_align.forward(offset);
2574 offset = field_offset + field_size;
2575
2576 const field_name = if (tuple.names.len != 0)
2577 tuple.names.get(ip)[i].toSlice(ip)
2578 else
2579 try std.fmt.allocPrintZ(gpa, "{d}", .{i});
2580 defer if (tuple.names.len == 0) gpa.free(field_name);
2581
2582 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2583 try o.builder.metadataString(field_name),
2584 .none, // File
2585 fwd_ref,
2586 0,
2587 try o.lowerDebugType(Type.fromInterned(field_ty), required_by_runtime),
2588 field_size * 8,
2589 (field_align.toByteUnits() orelse 0) * 8,
2590 field_offset * 8,
2591 ));
2592 }
25802593
2581 fields.appendAssumeCapacity(try o.builder.debugMemberType(2594 const debug_struct_type = try o.builder.debugStructType(
2582 try o.builder.metadataString(field_name.toSlice(ip)),2595 try o.builder.metadataString(name),
2583 file,2596 file,
2584 debug_fwd_ref,2597 scope,
2585 0, // Line2598 0, // Line
2586 try o.lowerDebugType(field_ty),2599 .none, // Underlying type
2587 field_size * 8,2600 ty.abiSize(pt) * 8,
2588 (field_align.toByteUnits() orelse 0) * 8,2601 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2589 field_offset * 8,2602 try o.builder.debugTuple(fields.items),
2590 ));2603 );
2591 }
25922604
2593 const debug_struct_type = try o.builder.debugStructType(2605 break :res debug_struct_type;
2594 try o.builder.metadataString(name),2606 },
2595 file,2607 else => {},
2596 scope,2608 }
2597 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 );
26032609
2604 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_struct_type);2610 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {
2611 break :res try o.makeNamespaceDebugType(owner_decl_index.?, fields.items);
2612 }
2613 const struct_type = zcu.typeToStruct(ty).?;
26052614
2606 // Set to real type now that it has been lowered fully2615 if (!struct_type.haveLayout(ip) or !struct_type.haveFieldTypes(ip)) {
2607 const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable;2616 break :res try o.makeNamespaceDebugType(owner_decl_index.?, fields.items);
2608 map_ptr.* = debug_struct_type;2617 }
26092618
2610 return debug_struct_type;2619 try fields.ensureUnusedCapacity(gpa, struct_type.field_types.len);
2611 },
2612 .Union => {
2613 const union_type = ip.loadUnionType(ty.toIntern());
2614 if (!union_type.haveFieldTypes(ip) or
2615 !ty.hasRuntimeBitsIgnoreComptime(pt) or
2616 !union_type.haveLayout(ip))
2617 {
2618 const debug_union_type = try o.makeEmptyNamespaceDebugType(owner_decl_index.?);
2619 try o.debug_type_map.put(gpa, ty, debug_union_type);
2620 return debug_union_type;
2621 }
26222620
2623 const layout = pt.getUnionLayout(union_type);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);
26242633
2625 const debug_fwd_ref = try o.builder.debugForwardReference();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);
26262636
2627 // Set as forward reference while the type is lowered in case it references itself2637 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2628 try o.debug_type_map.put(gpa, ty, debug_fwd_ref);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 }
26292648
2630 if (layout.payload_size == 0) {2649 const debug_struct_type = try o.builder.debugStructType(
2631 const debug_union_type = try o.builder.debugStructType(
2632 try o.builder.metadataString(name),2650 try o.builder.metadataString(name),
2633 file,2651 file,
2634 scope,2652 scope,
2635 0, // Line2653 line,
2636 .none, // Underlying type2654 .none, // Underlying type
2637 ty.abiSize(pt) * 8,2655 ty.abiSize(pt) * 8,
2638 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,2656 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2639 try o.builder.debugTuple(2657 try o.builder.debugTuple(fields.items),
2640 &.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty))},
2641 ),
2642 );2658 );
26432659
2644 // Set to real type now that it has been lowered fully2660 break :res debug_struct_type;
2645 const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable;2661 },
2646 map_ptr.* = debug_union_type;2662 .Union => res: {
26472663 const union_type = ip.loadUnionType(ty.toIntern());
2648 return debug_union_type;2664 if (!union_type.haveFieldTypes(ip) or
2649 }2665 !ty.hasRuntimeBitsIgnoreComptime(pt) or
26502666 !union_type.haveLayout(ip))
2651 var fields: std.ArrayListUnmanaged(Builder.Metadata) = .{};2667 {
2652 defer fields.deinit(gpa);2668 break :res try o.makeNamespaceDebugType(owner_decl_index.?, fields.items);
26532669 }
2654 try fields.ensureUnusedCapacity(gpa, union_type.loadTagType(ip).names.len);
2655
2656 const debug_union_fwd_ref = if (layout.tag_size == 0)
2657 debug_fwd_ref
2658 else
2659 try o.builder.debugForwardReference();
26602670
2661 const tag_type = union_type.loadTagType(ip);2671 const layout = pt.getUnionLayout(union_type);
26622672
2663 for (0..tag_type.names.len) |field_index| {2673 if (layout.payload_size == 0) {
2664 const field_ty = union_type.field_types.get(ip)[field_index];2674 const debug_union_type = try o.builder.debugStructType(
2665 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue;2675 try o.builder.metadataString(name),
2676 file,
2677 scope,
2678 0, // Line
2679 .none, // Underlying type
2680 ty.abiSize(pt) * 8,
2681 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2682 try o.builder.debugTuple(
2683 &.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty), required_by_runtime)},
2684 ),
2685 );
26662686
2667 const field_size = Type.fromInterned(field_ty).abiSize(pt);2687 break :res debug_union_type;
2668 const field_align: InternPool.Alignment = switch (union_type.flagsUnordered(ip).layout) {2688 }
2669 .@"packed" => .none,
2670 .auto, .@"extern" => pt.unionFieldNormalAlignment(union_type, @intCast(field_index)),
2671 };
26722689
2673 const field_name = tag_type.names.get(ip)[field_index];2690 try fields.ensureUnusedCapacity(gpa, union_type.loadTagType(ip).names.len);
2674 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2675 try o.builder.metadataString(field_name.toSlice(ip)),
2676 file,
2677 debug_union_fwd_ref,
2678 0, // Line
2679 try o.lowerDebugType(Type.fromInterned(field_ty)),
2680 field_size * 8,
2681 (field_align.toByteUnits() orelse 0) * 8,
2682 0, // Offset
2683 ));
2684 }
26852691
2686 var union_name_buf: ?[:0]const u8 = null;2692 const debug_union_fwd_ref = if (layout.tag_size == 0)
2687 defer if (union_name_buf) |buf| gpa.free(buf);2693 fwd_ref
2688 const union_name = if (layout.tag_size == 0) name else name: {2694 else
2689 union_name_buf = try std.fmt.allocPrintZ(gpa, "{s}:Payload", .{name});2695 try o.builder.debugForwardReference();
2690 break :name union_name_buf.?;
2691 };
26922696
2693 const debug_union_type = try o.builder.debugUnionType(2697 const tag_type = union_type.loadTagType(ip);
2694 try o.builder.metadataString(union_name),
2695 file,
2696 scope,
2697 line,
2698 .none, // Underlying type
2699 ty.abiSize(pt) * 8,
2700 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2701 try o.builder.debugTuple(fields.items),
2702 );
27032698
2704 o.builder.debugForwardReferenceSetType(debug_union_fwd_ref, debug_union_type);2699 for (0..tag_type.names.len) |field_index| {
2700 const field_ty = union_type.field_types.get(ip)[field_index];
2701 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue;
27052702
2706 if (layout.tag_size == 0) {2703 const field_size = Type.fromInterned(field_ty).abiSize(pt);
2707 // Set to real type now that it has been lowered fully2704 const field_align: InternPool.Alignment = switch (union_type.flagsUnordered(ip).layout) {
2708 const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable;2705 .@"packed" => .none,
2709 map_ptr.* = debug_union_type;2706 .auto, .@"extern" => pt.unionFieldNormalAlignment(union_type, @intCast(field_index)),
2707 };
27102708
2711 return debug_union_type;2709 const field_name = tag_type.names.get(ip)[field_index];
2712 }2710 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2711 try o.builder.metadataString(field_name.toSlice(ip)),
2712 file,
2713 debug_union_fwd_ref,
2714 0, // Line
2715 try o.lowerDebugType(Type.fromInterned(field_ty), required_by_runtime),
2716 field_size * 8,
2717 (field_align.toByteUnits() orelse 0) * 8,
2718 0, // Offset
2719 ));
2720 }
27132721
2714 var tag_offset: u64 = undefined;2722 var union_name_buf: ?[:0]const u8 = null;
2715 var payload_offset: u64 = undefined;2723 defer if (union_name_buf) |buf| gpa.free(buf);
2716 if (layout.tag_align.compare(.gte, layout.payload_align)) {2724 const union_name = if (layout.tag_size == 0) name else name: {
2717 tag_offset = 0;2725 union_name_buf = try std.fmt.allocPrintZ(gpa, "{s}:Payload", .{name});
2718 payload_offset = layout.payload_align.forward(layout.tag_size);2726 break :name union_name_buf.?;
2719 } else {2727 };
2720 payload_offset = 0;
2721 tag_offset = layout.tag_align.forward(layout.payload_size);
2722 }
27232728
2724 const debug_tag_type = try o.builder.debugMemberType(2729 const debug_union_type = try o.builder.debugUnionType(
2725 try o.builder.metadataString("tag"),2730 try o.builder.metadataString(union_name),
2726 file, // File2731 file,
2727 debug_fwd_ref,2732 scope,
2728 0, // Line2733 line,
2729 try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty)),2734 .none, // Underlying type
2730 layout.tag_size * 8,2735 ty.abiSize(pt) * 8,
2731 (layout.tag_align.toByteUnits() orelse 0) * 8,2736 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2732 tag_offset * 8,2737 try o.builder.debugTuple(fields.items),
2733 );2738 );
27342739
2735 const debug_payload_type = try o.builder.debugMemberType(2740 if (layout.tag_size == 0) {
2736 try o.builder.metadataString("payload"),2741 break :res debug_union_type;
2737 file,2742 }
2738 debug_fwd_ref,
2739 0, // Line
2740 debug_union_type,
2741 layout.payload_size * 8,
2742 (layout.payload_align.toByteUnits() orelse 0) * 8,
2743 payload_offset * 8,
2744 );
27452743
2746 const full_fields: [2]Builder.Metadata =2744 o.builder.debugForwardReferenceSetType(debug_union_fwd_ref, debug_union_type);
2747 if (layout.tag_align.compare(.gte, layout.payload_align))
2748 .{ debug_tag_type, debug_payload_type }
2749 else
2750 .{ debug_payload_type, debug_tag_type };
27512745
2752 const debug_tagged_union_type = try o.builder.debugStructType(2746 var tag_offset: u64 = undefined;
2753 try o.builder.metadataString(name),2747 var payload_offset: u64 = undefined;
2754 file, // File2748 if (layout.tag_align.compare(.gte, layout.payload_align)) {
2755 scope,2749 tag_offset = 0;
2756 line,2750 payload_offset = layout.payload_align.forward(layout.tag_size);
2757 .none, // Underlying type2751 } else {
2758 ty.abiSize(pt) * 8,2752 payload_offset = 0;
2759 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,2753 tag_offset = layout.tag_align.forward(layout.payload_size);
2760 try o.builder.debugTuple(&full_fields),2754 }
2761 );
27622755
2763 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_tagged_union_type);2756 const debug_tag_type = try o.builder.debugMemberType(
2757 try o.builder.metadataString("tag"),
2758 file, // File
2759 fwd_ref,
2760 0, // Line
2761 try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty), required_by_runtime),
2762 layout.tag_size * 8,
2763 (layout.tag_align.toByteUnits() orelse 0) * 8,
2764 tag_offset * 8,
2765 );
27642766
2765 // Set to real type now that it has been lowered fully2767 const debug_payload_type = try o.builder.debugMemberType(
2766 const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable;2768 try o.builder.metadataString("payload"),
2767 map_ptr.* = debug_tagged_union_type;2769 file,
2770 fwd_ref,
2771 0, // Line
2772 debug_union_type,
2773 layout.payload_size * 8,
2774 (layout.payload_align.toByteUnits() orelse 0) * 8,
2775 payload_offset * 8,
2776 );
27682777
2769 return debug_tagged_union_type;2778 const full_fields: [2]Builder.Metadata =
2770 },2779 if (layout.tag_align.compare(.gte, layout.payload_align))
2771 else => unreachable, // Handled above.2780 .{ debug_tag_type, debug_payload_type }
2772 }2781 else
2773 }2782 .{ debug_payload_type, debug_tag_type };
27742783
2775 fn genNamespaces(o: *Object) !void {2784 const debug_tagged_union_type = try o.builder.debugStructType(
2776 var i: usize = 0;2785 try o.builder.metadataString(name),
2777 while (i < o.debug_unresolved_namespace_scopes.count()) : (i += 1) {2786 file, // File
2778 const namespace_index = o.debug_unresolved_namespace_scopes.keys()[i];2787 scope,
2779 const fwd_ref = o.debug_unresolved_namespace_scopes.values()[i];2788 line,
2789 .none, // Underlying type
2790 ty.abiSize(pt) * 8,
2791 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2792 try o.builder.debugTuple(&full_fields),
2793 );
27802794
2781 const namespace = o.pt.zcu.namespacePtr(namespace_index);2795 break :res debug_tagged_union_type;
2782 const debug_type = try o.lowerDebugType(namespace.getType(o.pt.zcu));2796 },
2797 else => unreachable, // Handled above.
2798 };
27832799
2784 o.builder.debugForwardReferenceSetType(fwd_ref, debug_type);2800 o.builder.debugForwardReferenceSetType(fwd_ref, res);
2785 }2801 }
2786 }2802 }
27872803
...@@ -2791,14 +2807,10 @@ pub const Object = struct {...@@ -2791,14 +2807,10 @@ pub const Object = struct {
2791 const file_scope = namespace.fileScope(zcu);2807 const file_scope = namespace.fileScope(zcu);
2792 if (namespace.parent == .none) return try o.getDebugFile(file_scope);2808 if (namespace.parent == .none) return try o.getDebugFile(file_scope);
27932809
2794 const gop = try o.debug_unresolved_namespace_scopes.getOrPut(o.gpa, namespace_index);2810 return o.lowerDebugType(zcu.declPtr(namespace.decl_index).val.toType(), false);
2795
2796 if (!gop.found_existing) gop.value_ptr.* = try o.builder.debugForwardReference();
2797
2798 return gop.value_ptr.*;
2799 }2811 }
28002812
2801 fn makeEmptyNamespaceDebugType(o: *Object, decl_index: InternPool.DeclIndex) !Builder.Metadata {2813 fn makeNamespaceDebugType(o: *Object, decl_index: InternPool.DeclIndex, fields: []const Builder.Metadata) !Builder.Metadata {
2802 const zcu = o.pt.zcu;2814 const zcu = o.pt.zcu;
2803 const decl = zcu.declPtr(decl_index);2815 const decl = zcu.declPtr(decl_index);
2804 const file_scope = zcu.namespacePtr(decl.src_namespace).fileScope(zcu);2816 const file_scope = zcu.namespacePtr(decl.src_namespace).fileScope(zcu);
...@@ -2810,7 +2822,7 @@ pub const Object = struct {...@@ -2810,7 +2822,7 @@ pub const Object = struct {
2810 .none,2822 .none,
2811 0,2823 0,
2812 0,2824 0,
2813 .none,2825 if (fields.len == 0) .none else try o.builder.debugTuple(fields),
2814 );2826 );
2815 }2827 }
28162828
...@@ -4723,6 +4735,7 @@ pub const DeclGen = struct {...@@ -4723,6 +4735,7 @@ pub const DeclGen = struct {
47234735
4724 if (!owner_mod.strip) {4736 if (!owner_mod.strip) {
4725 const debug_file = try o.getDebugFile(file_scope);4737 const debug_file = try o.getDebugFile(file_scope);
4738 const debug_scope = try o.namespaceToDebugScope(decl.src_namespace);
47264739
4727 const linkage_name = try o.builder.metadataStringFromStrtabString(variable_index.name(&o.builder));4740 const linkage_name = try o.builder.metadataStringFromStrtabString(variable_index.name(&o.builder));
47284741
...@@ -4730,10 +4743,10 @@ pub const DeclGen = struct {...@@ -4730,10 +4743,10 @@ pub const DeclGen = struct {
4730 // Imitate a C++ static member variable since neither4743 // Imitate a C++ static member variable since neither
4731 // GDB or LLDB can really cope with regular variables4744 // GDB or LLDB can really cope with regular variables
4732 // directly inside a struct type.4745 // directly inside a struct type.
4733 const ty = try o.lowerDebugType(decl.typeOf(zcu));4746 const ty = try o.lowerDebugType(decl.typeOf(zcu), true);
4734 const name = try o.builder.metadataString(decl.name.toSlice(ip));4747 const name = try o.builder.metadataString(decl.name.toSlice(ip));
47354748
4736 break :blk try o.builder.debugGlobalVar(4749 const variable = try o.builder.debugGlobalVar(
4737 name,4750 name,
4738 linkage_name,4751 linkage_name,
4739 debug_file,4752 debug_file,
...@@ -4742,15 +4755,25 @@ pub const DeclGen = struct {...@@ -4742,15 +4755,25 @@ pub const DeclGen = struct {
4742 ty,4755 ty,
4743 variable_index,4756 variable_index,
4744 .none,4757 .none,
4745 .internal,4758 .external,
4746 );4759 );
4760
4761 try o.debug_imports.append(o.gpa, try o.builder.debugImportDeclaration(
4762 name,
4763 debug_file,
4764 debug_scope,
4765 line_number,
4766 variable,
4767 ));
4768
4769 break :blk variable;
4747 } else try o.builder.debugGlobalVar(4770 } else try o.builder.debugGlobalVar(
4748 linkage_name,4771 linkage_name,
4749 linkage_name,4772 linkage_name,
4750 debug_file,4773 debug_file,
4751 debug_file,4774 debug_file,
4752 line_number,4775 line_number,
4753 try o.lowerDebugType(decl.typeOf(zcu)),4776 try o.lowerDebugType(decl.typeOf(zcu), true),
4754 variable_index,4777 variable_index,
4755 .none,4778 .none,
4756 .external,4779 .external,
...@@ -5209,7 +5232,7 @@ pub const FuncGen = struct {...@@ -5209,7 +5232,7 @@ pub const FuncGen = struct {
5209 try o.builder.metadataString(decl.fqn.toSlice(&zcu.intern_pool)),5232 try o.builder.metadataString(decl.fqn.toSlice(&zcu.intern_pool)),
5210 line_number,5233 line_number,
5211 line_number + func.lbrace_line,5234 line_number + func.lbrace_line,
5212 try o.lowerDebugType(fn_ty),5235 try o.lowerDebugType(fn_ty, true),
5213 .{5236 .{
5214 .di_flags = .{ .StaticMember = true },5237 .di_flags = .{ .StaticMember = true },
5215 .sp_flags = .{5238 .sp_flags = .{
...@@ -6759,7 +6782,7 @@ pub const FuncGen = struct {...@@ -6759,7 +6782,7 @@ pub const FuncGen = struct {
6759 self.file,6782 self.file,
6760 self.scope,6783 self.scope,
6761 self.prev_dbg_line,6784 self.prev_dbg_line,
6762 try o.lowerDebugType(ptr_ty.childType(mod)),6785 try o.lowerDebugType(ptr_ty.childType(mod), true),
6763 );6786 );
67646787
6765 _ = try self.wip.callIntrinsic(6788 _ = try self.wip.callIntrinsic(
...@@ -6792,7 +6815,7 @@ pub const FuncGen = struct {...@@ -6792,7 +6815,7 @@ pub const FuncGen = struct {
6792 self.file,6815 self.file,
6793 self.scope,6816 self.scope,
6794 self.prev_dbg_line,6817 self.prev_dbg_line,
6795 try o.lowerDebugType(operand_ty),6818 try o.lowerDebugType(operand_ty, true),
6796 );6819 );
67976820
6798 const pt = o.pt;6821 const pt = o.pt;
...@@ -8906,7 +8929,7 @@ pub const FuncGen = struct {...@@ -8906,7 +8929,7 @@ pub const FuncGen = struct {
8906 self.file,8929 self.file,
8907 self.scope,8930 self.scope,
8908 lbrace_line,8931 lbrace_line,
8909 try o.lowerDebugType(inst_ty),8932 try o.lowerDebugType(inst_ty, true),
8910 @intCast(self.arg_index),8933 @intCast(self.arg_index),
8911 );8934 );
89128935
src/codegen/llvm/Builder.zig+114-22
...@@ -7652,6 +7652,8 @@ pub const Metadata = enum(u32) {...@@ -7652,6 +7652,8 @@ pub const Metadata = enum(u32) {
7652 derived_pointer_type,7652 derived_pointer_type,
7653 derived_member_type,7653 derived_member_type,
7654 derived_static_member_type,7654 derived_static_member_type,
7655 derived_typedef,
7656 imported_declaration,
7655 subroutine_type,7657 subroutine_type,
7656 enumerator_unsigned,7658 enumerator_unsigned,
7657 enumerator_signed_positive,7659 enumerator_signed_positive,
...@@ -7699,6 +7701,8 @@ pub const Metadata = enum(u32) {...@@ -7699,6 +7701,8 @@ pub const Metadata = enum(u32) {
7699 .derived_pointer_type,7701 .derived_pointer_type,
7700 .derived_member_type,7702 .derived_member_type,
7701 .derived_static_member_type,7703 .derived_static_member_type,
7704 .derived_typedef,
7705 .imported_declaration,
7702 .subroutine_type,7706 .subroutine_type,
7703 .enumerator_unsigned,7707 .enumerator_unsigned,
7704 .enumerator_signed_positive,7708 .enumerator_signed_positive,
...@@ -7816,6 +7820,7 @@ pub const Metadata = enum(u32) {...@@ -7816,6 +7820,7 @@ pub const Metadata = enum(u32) {
7816 producer: MetadataString,7820 producer: MetadataString,
7817 enums: Metadata,7821 enums: Metadata,
7818 globals: Metadata,7822 globals: Metadata,
7823 imports: Metadata,
7819 };7824 };
78207825
7821 pub const Subprogram = struct {7826 pub const Subprogram = struct {
...@@ -7943,6 +7948,14 @@ pub const Metadata = enum(u32) {...@@ -7943,6 +7948,14 @@ pub const Metadata = enum(u32) {
7943 }7948 }
7944 };7949 };
79457950
7951 pub const ImportedEntity = struct {
7952 name: MetadataString,
7953 file: Metadata,
7954 scope: Metadata,
7955 line: u32,
7956 entity: Metadata,
7957 };
7958
7946 pub const SubroutineType = struct {7959 pub const SubroutineType = struct {
7947 types_tuple: Metadata,7960 types_tuple: Metadata,
7948 };7961 };
...@@ -8232,6 +8245,7 @@ pub const Metadata = enum(u32) {...@@ -8232,6 +8245,7 @@ pub const Metadata = enum(u32) {
8232 DIBasicType,8245 DIBasicType,
8233 DICompositeType,8246 DICompositeType,
8234 DIDerivedType,8247 DIDerivedType,
8248 DIImportedEntity,
8235 DISubroutineType,8249 DISubroutineType,
8236 DIEnumerator,8250 DIEnumerator,
8237 DISubrange,8251 DISubrange,
...@@ -9969,7 +9983,7 @@ pub fn printUnbuffered(...@@ -9969,7 +9983,7 @@ pub fn printUnbuffered(
9969 .enums = extra.enums,9983 .enums = extra.enums,
9970 .retainedTypes = null,9984 .retainedTypes = null,
9971 .globals = extra.globals,9985 .globals = extra.globals,
9972 .imports = null,9986 .imports = extra.imports,
9973 .macros = null,9987 .macros = null,
9974 .dwoId = null,9988 .dwoId = null,
9975 .splitDebugInlining = false,9989 .splitDebugInlining = false,
...@@ -10110,16 +10124,18 @@ pub fn printUnbuffered(...@@ -10110,16 +10124,18 @@ pub fn printUnbuffered(
10110 .derived_pointer_type,10124 .derived_pointer_type,
10111 .derived_member_type,10125 .derived_member_type,
10112 .derived_static_member_type,10126 .derived_static_member_type,
10127 .derived_typedef,
10113 => |kind| {10128 => |kind| {
10114 const extra = self.metadataExtraData(Metadata.DerivedType, metadata_item.data);10129 const extra = self.metadataExtraData(Metadata.DerivedType, metadata_item.data);
10115 try metadata_formatter.specialized(.@"!", .DIDerivedType, .{10130 try metadata_formatter.specialized(.@"!", .DIDerivedType, .{
10116 .tag = @as(enum {10131 .tag = @as(enum {
10117 DW_TAG_pointer_type,10132 DW_TAG_pointer_type,
10118 DW_TAG_member,10133 DW_TAG_member,
10134 DW_TAG_typedef,
10119 }, switch (kind) {10135 }, switch (kind) {
10120 .derived_pointer_type => .DW_TAG_pointer_type,10136 .derived_pointer_type => .DW_TAG_pointer_type,
10121 .derived_member_type,10137 .derived_member_type, .derived_static_member_type => .DW_TAG_member,
10122 .derived_static_member_type => .DW_TAG_member,10138 .derived_typedef => .DW_TAG_typedef,
10123 else => unreachable,10139 else => unreachable,
10124 }),10140 }),
10125 .name = switch (extra.name) {10141 .name = switch (extra.name) {
...@@ -10142,6 +10158,22 @@ pub fn printUnbuffered(...@@ -10142,6 +10158,22 @@ pub fn printUnbuffered(
10142 .annotations = null,10158 .annotations = null,
10143 }, writer);10159 }, writer);
10144 },10160 },
10161 .imported_declaration => {
10162 const extra = self.metadataExtraData(Metadata.ImportedEntity, metadata_item.data);
10163
10164 try metadata_formatter.specialized(.@"!", .DIImportedEntity, .{
10165 .tag = .DW_TAG_imported_declaration,
10166 .scope = extra.scope,
10167 .entity = extra.entity,
10168 .file = extra.file,
10169 .line = extra.line,
10170 .name = switch (extra.name) {
10171 .none => null,
10172 else => extra.name,
10173 },
10174 .elements = null,
10175 }, writer);
10176 },
10145 .subroutine_type => {10177 .subroutine_type => {
10146 const extra = self.metadataExtraData(Metadata.SubroutineType, metadata_item.data);10178 const extra = self.metadataExtraData(Metadata.SubroutineType, metadata_item.data);
10147 try metadata_formatter.specialized(.@"!", .DISubroutineType, .{10179 try metadata_formatter.specialized(.@"!", .DISubroutineType, .{
...@@ -11747,10 +11779,11 @@ pub fn debugCompileUnit(...@@ -11747,10 +11779,11 @@ pub fn debugCompileUnit(
11747 producer: MetadataString,11779 producer: MetadataString,
11748 enums: Metadata,11780 enums: Metadata,
11749 globals: Metadata,11781 globals: Metadata,
11782 imports: Metadata,
11750 options: Metadata.CompileUnit.Options,11783 options: Metadata.CompileUnit.Options,
11751) Allocator.Error!Metadata {11784) Allocator.Error!Metadata {
11752 try self.ensureUnusedMetadataCapacity(1, Metadata.CompileUnit, 0);11785 try self.ensureUnusedMetadataCapacity(1, Metadata.CompileUnit, 0);
11753 return self.debugCompileUnitAssumeCapacity(file, producer, enums, globals, options);11786 return self.debugCompileUnitAssumeCapacity(file, producer, enums, globals, imports, options);
11754}11787}
1175511788
11756pub fn debugSubprogram(11789pub fn debugSubprogram(
...@@ -12005,6 +12038,53 @@ pub fn debugMemberType(...@@ -12005,6 +12038,53 @@ pub fn debugMemberType(
12005 );12038 );
12006}12039}
1200712040
12041pub fn debugTypedef(
12042 self: *Builder,
12043 name: MetadataString,
12044 file: Metadata,
12045 scope: Metadata,
12046 line: u32,
12047 underlying_type: Metadata,
12048 align_in_bits: u64,
12049) Allocator.Error!Metadata {
12050 try self.ensureUnusedMetadataCapacity(1, Metadata.DerivedType, 0);
12051
12052 assert(!self.strip);
12053 return self.metadataSimpleAssumeCapacity(.derived_typedef, Metadata.DerivedType{
12054 .name = name,
12055 .file = file,
12056 .scope = scope,
12057 .line = line,
12058 .underlying_type = underlying_type,
12059 .size_in_bits_lo = 0,
12060 .size_in_bits_hi = 0,
12061 .align_in_bits_lo = @truncate(align_in_bits),
12062 .align_in_bits_hi = @truncate(align_in_bits >> 32),
12063 .offset_in_bits_lo = 0,
12064 .offset_in_bits_hi = 0,
12065 });
12066}
12067
12068pub fn debugImportDeclaration(
12069 self: *Builder,
12070 name: MetadataString,
12071 file: Metadata,
12072 scope: Metadata,
12073 line: u32,
12074 entity: Metadata,
12075) Allocator.Error!Metadata {
12076 try self.ensureUnusedMetadataCapacity(1, Metadata.ImportedEntity, 0);
12077
12078 assert(!self.strip);
12079 return self.metadataSimpleAssumeCapacity(.imported_declaration, Metadata.ImportedEntity{
12080 .name = name,
12081 .file = file,
12082 .scope = scope,
12083 .line = line,
12084 .entity = entity,
12085 });
12086}
12087
12008pub fn debugSubroutineType(12088pub fn debugSubroutineType(
12009 self: *Builder,12089 self: *Builder,
12010 types_tuple: Metadata,12090 types_tuple: Metadata,
...@@ -12241,6 +12321,7 @@ pub fn debugCompileUnitAssumeCapacity(...@@ -12241,6 +12321,7 @@ pub fn debugCompileUnitAssumeCapacity(
12241 producer: MetadataString,12321 producer: MetadataString,
12242 enums: Metadata,12322 enums: Metadata,
12243 globals: Metadata,12323 globals: Metadata,
12324 imports: Metadata,
12244 options: Metadata.CompileUnit.Options,12325 options: Metadata.CompileUnit.Options,
12245) Metadata {12326) Metadata {
12246 assert(!self.strip);12327 assert(!self.strip);
...@@ -12251,6 +12332,7 @@ pub fn debugCompileUnitAssumeCapacity(...@@ -12251,6 +12332,7 @@ pub fn debugCompileUnitAssumeCapacity(
12251 .producer = producer,12332 .producer = producer,
12252 .enums = enums,12333 .enums = enums,
12253 .globals = globals,12334 .globals = globals,
12335 .imports = imports,
12254 },12336 },
12255 );12337 );
12256}12338}
...@@ -12538,22 +12620,19 @@ fn debugMemberTypeAssumeCapacity(...@@ -12538,22 +12620,19 @@ fn debugMemberTypeAssumeCapacity(
12538 static: bool,12620 static: bool,
12539) Metadata {12621) Metadata {
12540 assert(!self.strip);12622 assert(!self.strip);
12541 return self.metadataSimpleAssumeCapacity(12623 return self.metadataSimpleAssumeCapacity(if (static) .derived_static_member_type else .derived_member_type, Metadata.DerivedType{
12542 if (static) .derived_static_member_type else .derived_member_type,12624 .name = name,
12543 Metadata.DerivedType{12625 .file = file,
12544 .name = name,12626 .scope = scope,
12545 .file = file,12627 .line = line,
12546 .scope = scope,12628 .underlying_type = underlying_type,
12547 .line = line,12629 .size_in_bits_lo = @truncate(size_in_bits),
12548 .underlying_type = underlying_type,12630 .size_in_bits_hi = @truncate(size_in_bits >> 32),
12549 .size_in_bits_lo = @truncate(size_in_bits),12631 .align_in_bits_lo = @truncate(align_in_bits),
12550 .size_in_bits_hi = @truncate(size_in_bits >> 32),12632 .align_in_bits_hi = @truncate(align_in_bits >> 32),
12551 .align_in_bits_lo = @truncate(align_in_bits),12633 .offset_in_bits_lo = @truncate(offset_in_bits),
12552 .align_in_bits_hi = @truncate(align_in_bits >> 32),12634 .offset_in_bits_hi = @truncate(offset_in_bits >> 32),
12553 .offset_in_bits_lo = @truncate(offset_in_bits),12635 });
12554 .offset_in_bits_hi = @truncate(offset_in_bits >> 32),
12555 }
12556 );
12557}12636}
1255812637
12559fn debugSubroutineTypeAssumeCapacity(12638fn debugSubroutineTypeAssumeCapacity(
...@@ -13850,6 +13929,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13850,6 +13929,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13850 },13929 },
13851 .enums = extra.enums,13930 .enums = extra.enums,
13852 .globals = extra.globals,13931 .globals = extra.globals,
13932 .imports = extra.imports,
13853 }, metadata_adapter);13933 }, metadata_adapter);
13854 },13934 },
13855 .subprogram,13935 .subprogram,
...@@ -13945,13 +14025,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13945,13 +14025,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13945 .derived_pointer_type,14025 .derived_pointer_type,
13946 .derived_member_type,14026 .derived_member_type,
13947 .derived_static_member_type,14027 .derived_static_member_type,
14028 .derived_typedef,
13948 => |kind| {14029 => |kind| {
13949 const extra = self.metadataExtraData(Metadata.DerivedType, data);14030 const extra = self.metadataExtraData(Metadata.DerivedType, data);
13950 try metadata_block.writeAbbrevAdapted(MetadataBlock.DerivedType{14031 try metadata_block.writeAbbrevAdapted(MetadataBlock.DerivedType{
13951 .tag = switch (kind) {14032 .tag = switch (kind) {
13952 .derived_pointer_type => DW.TAG.pointer_type,14033 .derived_pointer_type => DW.TAG.pointer_type,
13953 .derived_member_type,14034 .derived_member_type, .derived_static_member_type => DW.TAG.member,
13954 .derived_static_member_type => DW.TAG.member,14035 .derived_typedef => DW.TAG.typedef,
13955 else => unreachable,14036 else => unreachable,
13956 },14037 },
13957 .name = extra.name,14038 .name = extra.name,
...@@ -13967,6 +14048,17 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13967,6 +14048,17 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13967 },14048 },
13968 }, metadata_adapter);14049 }, metadata_adapter);
13969 },14050 },
14051 .imported_declaration => {
14052 const extra = self.metadataExtraData(Metadata.ImportedEntity, data);
14053 try metadata_block.writeAbbrevAdapted(MetadataBlock.ImportedEntity{
14054 .tag = DW.TAG.imported_declaration,
14055 .scope = extra.scope,
14056 .entity = extra.entity,
14057 .line = extra.line,
14058 .name = extra.name,
14059 .file = extra.file,
14060 }, metadata_adapter);
14061 },
13970 .subroutine_type => {14062 .subroutine_type => {
13971 const extra = self.metadataExtraData(Metadata.SubroutineType, data);14063 const extra = self.metadataExtraData(Metadata.SubroutineType, data);
1397214064
src/codegen/llvm/ir.zig+24-1
...@@ -649,6 +649,7 @@ pub const MetadataBlock = struct {...@@ -649,6 +649,7 @@ pub const MetadataBlock = struct {
649 BasicType,649 BasicType,
650 CompositeType,650 CompositeType,
651 DerivedType,651 DerivedType,
652 ImportedEntity,
652 SubroutineType,653 SubroutineType,
653 Enumerator,654 Enumerator,
654 Subrange,655 Subrange,
...@@ -706,7 +707,7 @@ pub const MetadataBlock = struct {...@@ -706,7 +707,7 @@ pub const MetadataBlock = struct {
706 .{ .literal = 0 }, // retained types707 .{ .literal = 0 }, // retained types
707 .{ .literal = 0 }, // subprograms708 .{ .literal = 0 }, // subprograms
708 MetadataAbbrev, // globals709 MetadataAbbrev, // globals
709 .{ .literal = 0 }, // imported entities710 MetadataAbbrev, // imported entities
710 .{ .literal = 0 }, // DWO ID711 .{ .literal = 0 }, // DWO ID
711 .{ .literal = 0 }, // macros712 .{ .literal = 0 }, // macros
712 .{ .literal = 0 }, // split debug inlining713 .{ .literal = 0 }, // split debug inlining
...@@ -722,6 +723,7 @@ pub const MetadataBlock = struct {...@@ -722,6 +723,7 @@ pub const MetadataBlock = struct {
722 is_optimized: bool,723 is_optimized: bool,
723 enums: Builder.Metadata,724 enums: Builder.Metadata,
724 globals: Builder.Metadata,725 globals: Builder.Metadata,
726 imports: Builder.Metadata,
725 };727 };
726728
727 pub const Subprogram = struct {729 pub const Subprogram = struct {
...@@ -879,6 +881,27 @@ pub const MetadataBlock = struct {...@@ -879,6 +881,27 @@ pub const MetadataBlock = struct {
879 flags: Builder.Metadata.DIFlags,881 flags: Builder.Metadata.DIFlags,
880 };882 };
881883
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,
903 };
904
882 pub const SubroutineType = struct {905 pub const SubroutineType = struct {
883 pub const ops = [_]AbbrevOp{906 pub const ops = [_]AbbrevOp{
884 .{ .literal = 19 },907 .{ .literal = 19 },