authorgravatar for jonathan.haehne@hotmail.comTau <jonathan.haehne@hotmail.com> 2024-06-20 19:10:26+02:00
committergravatar for jonathan.haehne@hotmail.comTau <jonathan.haehne@hotmail.com> 2024-07-19 17:46:34+02:00
log876258abe46273aeac7c9791c7ec69bceb29f5ae
treec21713bd3200a847d65aea06c64a9a5b408c6f62
parentebd9efa85052fc19d8296e8e0f4da079da9cab45

llvm: set precise scopes on namespace types and variables

This will allow accessing non-local declarations from debuggers, which, AFAICT, was impossible before. Getting scopes right already works for type declarations and functions, but will need some fiddling for variables: For those, I tried imitating what Clang does for static member variables, but LLDB tries to re-mangle those and then fails at lookup, while GDB outright crashes. Hopefully I can find some other dwarven incantation to do the right thing.

3 files changed, 313 insertions(+), 229 deletions(-)

src/codegen/llvm.zig+223-196
...@@ -1140,18 +1140,7 @@ pub const Object = struct {...@@ -1140,18 +1140,7 @@ pub const Object = struct {
1140 try self.genModuleLevelAssembly();1140 try self.genModuleLevelAssembly();
11411141
1142 if (!self.builder.strip) {1142 if (!self.builder.strip) {
1143 {1143 try self.genNamespaces();
1144 var i: usize = 0;
1145 while (i < self.debug_unresolved_namespace_scopes.count()) : (i += 1) {
1146 const namespace_index = self.debug_unresolved_namespace_scopes.keys()[i];
1147 const fwd_ref = self.debug_unresolved_namespace_scopes.values()[i];
1148
1149 const namespace = zcu.namespacePtr(namespace_index);
1150 const debug_type = try self.lowerDebugType(namespace.getType(zcu));
1151
1152 self.builder.debugForwardReferenceSetType(fwd_ref, debug_type);
1153 }
1154 }
11551144
1156 self.builder.debugForwardReferenceSetType(1145 self.builder.debugForwardReferenceSetType(
1157 self.debug_enums_fwd_ref,1146 self.debug_enums_fwd_ref,
...@@ -1641,6 +1630,7 @@ pub const Object = struct {...@@ -1641,6 +1630,7 @@ pub const Object = struct {
16411630
1642 const file, const subprogram = if (!wip.strip) debug_info: {1631 const file, const subprogram = if (!wip.strip) debug_info: {
1643 const file = try o.getDebugFile(file_scope);1632 const file = try o.getDebugFile(file_scope);
1633 const scope = try o.namespaceToDebugScope(decl.src_namespace);
16441634
1645 const line_number = decl.navSrcLine(zcu) + 1;1635 const line_number = decl.navSrcLine(zcu) + 1;
1646 const is_internal_linkage = decl.val.getExternFunc(zcu) == null;1636 const is_internal_linkage = decl.val.getExternFunc(zcu) == null;
...@@ -1648,6 +1638,7 @@ pub const Object = struct {...@@ -1648,6 +1638,7 @@ pub const Object = struct {
16481638
1649 const subprogram = try o.builder.debugSubprogram(1639 const subprogram = try o.builder.debugSubprogram(
1650 file,1640 file,
1641 scope,
1651 try o.builder.metadataString(decl.name.toSlice(ip)),1642 try o.builder.metadataString(decl.name.toSlice(ip)),
1652 try o.builder.metadataStringFromStrtabString(function_index.name(&o.builder)),1643 try o.builder.metadataStringFromStrtabString(function_index.name(&o.builder)),
1653 line_number,1644 line_number,
...@@ -1924,6 +1915,7 @@ pub const Object = struct {...@@ -1924,6 +1915,7 @@ pub const Object = struct {
19241915
1925 if (o.debug_type_map.get(ty)) |debug_type| return debug_type;1916 if (o.debug_type_map.get(ty)) |debug_type| return debug_type;
19261917
1918
1927 switch (ty.zigTypeTag(zcu)) {1919 switch (ty.zigTypeTag(zcu)) {
1928 .Void,1920 .Void,
1929 .NoReturn,1921 .NoReturn,
...@@ -1938,9 +1930,9 @@ pub const Object = struct {...@@ -1938,9 +1930,9 @@ pub const Object = struct {
1938 .Int => {1930 .Int => {
1939 const info = ty.intInfo(zcu);1931 const info = ty.intInfo(zcu);
1940 assert(info.bits != 0);1932 assert(info.bits != 0);
1941 const name = try o.allocTypeName(ty);1933 const int_name = try o.allocTypeName(ty);
1942 defer gpa.free(name);1934 defer gpa.free(int_name);
1943 const builder_name = try o.builder.metadataString(name);1935 const builder_name = try o.builder.metadataString(int_name);
1944 const debug_bits = ty.abiSize(pt) * 8; // lldb cannot handle non-byte sized types1936 const debug_bits = ty.abiSize(pt) * 8; // lldb cannot handle non-byte sized types
1945 const debug_int_type = switch (info.signedness) {1937 const debug_int_type = switch (info.signedness) {
1946 .signed => try o.builder.debugSignedType(builder_name, debug_bits),1938 .signed => try o.builder.debugSignedType(builder_name, debug_bits),
...@@ -1949,68 +1941,12 @@ pub const Object = struct {...@@ -1949,68 +1941,12 @@ pub const Object = struct {
1949 try o.debug_type_map.put(gpa, ty, debug_int_type);1941 try o.debug_type_map.put(gpa, ty, debug_int_type);
1950 return debug_int_type;1942 return debug_int_type;
1951 },1943 },
1952 .Enum => {
1953 const owner_decl_index = ty.getOwnerDecl(zcu);
1954 const owner_decl = zcu.declPtr(owner_decl_index);
1955
1956 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {
1957 const debug_enum_type = try o.makeEmptyNamespaceDebugType(owner_decl_index);
1958 try o.debug_type_map.put(gpa, ty, debug_enum_type);
1959 return debug_enum_type;
1960 }
1961
1962 const enum_type = ip.loadEnumType(ty.toIntern());
1963
1964 const enumerators = try gpa.alloc(Builder.Metadata, enum_type.names.len);
1965 defer gpa.free(enumerators);
1966
1967 const int_ty = Type.fromInterned(enum_type.tag_ty);
1968 const int_info = ty.intInfo(zcu);
1969 assert(int_info.bits != 0);
1970
1971 for (enum_type.names.get(ip), 0..) |field_name_ip, i| {
1972 var bigint_space: Value.BigIntSpace = undefined;
1973 const bigint = if (enum_type.values.len != 0)
1974 Value.fromInterned(enum_type.values.get(ip)[i]).toBigInt(&bigint_space, pt)
1975 else
1976 std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst();
1977
1978 enumerators[i] = try o.builder.debugEnumerator(
1979 try o.builder.metadataString(field_name_ip.toSlice(ip)),
1980 int_info.signedness == .unsigned,
1981 int_info.bits,
1982 bigint,
1983 );
1984 }
1985
1986 const file_scope = zcu.namespacePtr(owner_decl.src_namespace).fileScope(zcu);
1987 const file = try o.getDebugFile(file_scope);
1988 const scope = try o.namespaceToDebugScope(owner_decl.src_namespace);
1989
1990 const name = try o.allocTypeName(ty);
1991 defer gpa.free(name);
1992
1993 const debug_enum_type = try o.builder.debugEnumerationType(
1994 try o.builder.metadataString(name),
1995 file,
1996 scope,
1997 owner_decl.typeSrcLine(zcu) + 1, // Line
1998 try o.lowerDebugType(int_ty),
1999 ty.abiSize(pt) * 8,
2000 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2001 try o.builder.debugTuple(enumerators),
2002 );
2003
2004 try o.debug_type_map.put(gpa, ty, debug_enum_type);
2005 try o.debug_enums.append(gpa, debug_enum_type);
2006 return debug_enum_type;
2007 },
2008 .Float => {1944 .Float => {
2009 const bits = ty.floatBits(target);1945 const bits = ty.floatBits(target);
2010 const name = try o.allocTypeName(ty);1946 const float_name = try o.allocTypeName(ty);
2011 defer gpa.free(name);1947 defer gpa.free(float_name);
2012 const debug_float_type = try o.builder.debugFloatType(1948 const debug_float_type = try o.builder.debugFloatType(
2013 try o.builder.metadataString(name),1949 try o.builder.metadataString(float_name),
2014 bits,1950 bits,
2015 );1951 );
2016 try o.debug_type_map.put(gpa, ty, debug_float_type);1952 try o.debug_type_map.put(gpa, ty, debug_float_type);
...@@ -2068,6 +2004,7 @@ pub const Object = struct {...@@ -2068,6 +2004,7 @@ pub const Object = struct {
20682004
2069 const name = try o.allocTypeName(ty);2005 const name = try o.allocTypeName(ty);
2070 defer gpa.free(name);2006 defer gpa.free(name);
2007
2071 const line = 0;2008 const line = 0;
20722009
2073 const ptr_size = ptr_ty.abiSize(pt);2010 const ptr_size = ptr_ty.abiSize(pt);
...@@ -2146,34 +2083,6 @@ pub const Object = struct {...@@ -2146,34 +2083,6 @@ pub const Object = struct {
21462083
2147 return debug_ptr_type;2084 return debug_ptr_type;
2148 },2085 },
2149 .Opaque => {
2150 if (ty.toIntern() == .anyopaque_type) {
2151 const debug_opaque_type = try o.builder.debugSignedType(
2152 try o.builder.metadataString("anyopaque"),
2153 0,
2154 );
2155 try o.debug_type_map.put(gpa, ty, debug_opaque_type);
2156 return debug_opaque_type;
2157 }
2158
2159 const name = try o.allocTypeName(ty);
2160 defer gpa.free(name);
2161 const owner_decl_index = ty.getOwnerDecl(zcu);
2162 const owner_decl = zcu.declPtr(owner_decl_index);
2163 const file_scope = zcu.namespacePtr(owner_decl.src_namespace).fileScope(zcu);
2164 const debug_opaque_type = try o.builder.debugStructType(
2165 try o.builder.metadataString(name),
2166 try o.getDebugFile(file_scope),
2167 try o.namespaceToDebugScope(owner_decl.src_namespace),
2168 owner_decl.typeSrcLine(zcu) + 1, // Line
2169 .none, // Underlying type
2170 0, // Size
2171 0, // Align
2172 .none, // Fields
2173 );
2174 try o.debug_type_map.put(gpa, ty, debug_opaque_type);
2175 return debug_opaque_type;
2176 },
2177 .Array => {2086 .Array => {
2178 const debug_array_type = try o.builder.debugArrayType(2087 const debug_array_type = try o.builder.debugArrayType(
2179 .none, // Name2088 .none, // Name
...@@ -2203,9 +2112,9 @@ pub const Object = struct {...@@ -2203,9 +2112,9 @@ pub const Object = struct {
2203 .Int => blk: {2112 .Int => blk: {
2204 const info = elem_ty.intInfo(zcu);2113 const info = elem_ty.intInfo(zcu);
2205 assert(info.bits != 0);2114 assert(info.bits != 0);
2206 const name = try o.allocTypeName(ty);2115 const vec_name = try o.allocTypeName(ty);
2207 defer gpa.free(name);2116 defer gpa.free(vec_name);
2208 const builder_name = try o.builder.metadataString(name);2117 const builder_name = try o.builder.metadataString(vec_name);
2209 break :blk switch (info.signedness) {2118 break :blk switch (info.signedness) {
2210 .signed => try o.builder.debugSignedType(builder_name, info.bits),2119 .signed => try o.builder.debugSignedType(builder_name, info.bits),
2211 .unsigned => try o.builder.debugUnsignedType(builder_name, info.bits),2120 .unsigned => try o.builder.debugUnsignedType(builder_name, info.bits),
...@@ -2240,6 +2149,7 @@ pub const Object = struct {...@@ -2240,6 +2149,7 @@ pub const Object = struct {
2240 .Optional => {2149 .Optional => {
2241 const name = try o.allocTypeName(ty);2150 const name = try o.allocTypeName(ty);
2242 defer gpa.free(name);2151 defer gpa.free(name);
2152
2243 const child_ty = ty.optionalChild(zcu);2153 const child_ty = ty.optionalChild(zcu);
2244 if (!child_ty.hasRuntimeBitsIgnoreComptime(pt)) {2154 if (!child_ty.hasRuntimeBitsIgnoreComptime(pt)) {
2245 const debug_bool_type = try o.builder.debugBoolType(2155 const debug_bool_type = try o.builder.debugBoolType(
...@@ -2399,10 +2309,156 @@ pub const Object = struct {...@@ -2399,10 +2309,156 @@ pub const Object = struct {
2399 try o.debug_type_map.put(gpa, ty, debug_error_set);2309 try o.debug_type_map.put(gpa, ty, debug_error_set);
2400 return debug_error_set;2310 return debug_error_set;
2401 },2311 },
2402 .Struct => {2312 .Fn => {
2403 const name = try o.allocTypeName(ty);2313 const fn_info = zcu.typeToFunc(ty).?;
2404 defer gpa.free(name);2314
2315 var debug_param_types = std.ArrayList(Builder.Metadata).init(gpa);
2316 defer debug_param_types.deinit();
2317
2318 try debug_param_types.ensureUnusedCapacity(3 + fn_info.param_types.len);
2319
2320 // Return type goes first.
2321 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(pt)) {
2322 const sret = firstParamSRet(fn_info, pt, target);
2323 const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type);
2324 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty));
2325
2326 if (sret) {
2327 const ptr_ty = try pt.singleMutPtrType(Type.fromInterned(fn_info.return_type));
2328 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
2329 }
2330 } else {
2331 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(Type.void));
2332 }
2333
2334 if (Type.fromInterned(fn_info.return_type).isError(zcu) and
2335 zcu.comp.config.any_error_tracing)
2336 {
2337 const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType());
2338 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
2339 }
2340
2341 for (0..fn_info.param_types.len) |i| {
2342 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[i]);
2343 if (!param_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
2344
2345 if (isByRef(param_ty, pt)) {
2346 const ptr_ty = try pt.singleMutPtrType(param_ty);
2347 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
2348 } else {
2349 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(param_ty));
2350 }
2351 }
2352
2353 const debug_function_type = try o.builder.debugSubroutineType(
2354 try o.builder.debugTuple(debug_param_types.items),
2355 );
2356
2357 try o.debug_type_map.put(gpa, ty, debug_function_type);
2358 return debug_function_type;
2359 },
2360 .ComptimeInt => unreachable,
2361 .ComptimeFloat => unreachable,
2362 .Type => unreachable,
2363 .Undefined => unreachable,
2364 .Null => unreachable,
2365 .EnumLiteral => unreachable,
24052366
2367 .Frame => @panic("TODO implement lowerDebugType for Frame types"),
2368 .AnyFrame => @panic("TODO implement lowerDebugType for AnyFrame types"),
2369 // These are the types that need a correct scope.
2370 .Enum,
2371 .Struct,
2372 .Union,
2373 .Opaque => {}
2374 }
2375
2376
2377 const owner_decl_index = ty.getOwnerDeclOrNull(zcu);
2378 const owner_decl: ?*Zcu.Decl =
2379 if (owner_decl_index) |owner| zcu.declPtr(owner) else null;
2380
2381 const file = if (owner_decl) |owner|
2382 try o.getDebugFile(zcu.namespacePtr(owner.src_namespace).fileScope(zcu)) else .none;
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;
2386
2387
2388 const name = if (owner_decl) |owner| owner.name.toSlice(ip) else try o.allocTypeName(ty);
2389 defer if (owner_decl == null) gpa.free(name);
2390
2391 switch (ty.zigTypeTag(zcu)) {
2392 .Enum => {
2393 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {
2394 const debug_enum_type = try o.makeEmptyNamespaceDebugType(owner_decl_index.?);
2395 try o.debug_type_map.put(gpa, ty, debug_enum_type);
2396 return debug_enum_type;
2397 }
2398
2399 const enum_type = ip.loadEnumType(ty.toIntern());
2400
2401 const enumerators = try gpa.alloc(Builder.Metadata, enum_type.names.len);
2402 defer gpa.free(enumerators);
2403
2404 const int_ty = Type.fromInterned(enum_type.tag_ty);
2405 const int_info = ty.intInfo(zcu);
2406 assert(int_info.bits != 0);
2407
2408 for (enum_type.names.get(ip), 0..) |field_name_ip, i| {
2409 var bigint_space: Value.BigIntSpace = undefined;
2410 const bigint = if (enum_type.values.len != 0)
2411 Value.fromInterned(enum_type.values.get(ip)[i]).toBigInt(&bigint_space, pt)
2412 else
2413 std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst();
2414
2415 enumerators[i] = try o.builder.debugEnumerator(
2416 try o.builder.metadataString(field_name_ip.toSlice(ip)),
2417 int_info.signedness == .unsigned,
2418 int_info.bits,
2419 bigint,
2420 );
2421 }
2422
2423 const debug_enum_type = try o.builder.debugEnumerationType(
2424 try o.builder.metadataString(name),
2425 file,
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 );
2433
2434 try o.debug_type_map.put(gpa, ty, debug_enum_type);
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 }
2447
2448 const debug_opaque_type = try o.builder.debugStructType(
2449 try o.builder.metadataString(name),
2450 file,
2451 scope,
2452 line,
2453 .none, // Underlying type
2454 0, // Size
2455 0, // Align
2456 .none, // Fields
2457 );
2458 try o.debug_type_map.put(gpa, ty, debug_opaque_type);
2459 return debug_opaque_type;
2460 },
2461 .Struct => {
2406 if (zcu.typeToPackedStruct(ty)) |struct_type| {2462 if (zcu.typeToPackedStruct(ty)) |struct_type| {
2407 const backing_int_ty = struct_type.backingIntTypeUnordered(ip);2463 const backing_int_ty = struct_type.backingIntTypeUnordered(ip);
2408 if (backing_int_ty != .none) {2464 if (backing_int_ty != .none) {
...@@ -2457,8 +2513,8 @@ pub const Object = struct {...@@ -2457,8 +2513,8 @@ pub const Object = struct {
24572513
2458 const debug_struct_type = try o.builder.debugStructType(2514 const debug_struct_type = try o.builder.debugStructType(
2459 try o.builder.metadataString(name),2515 try o.builder.metadataString(name),
2460 .none, // File2516 file,
2461 o.debug_compile_unit, // Scope2517 scope,
2462 0, // Line2518 0, // Line
2463 .none, // Underlying type2519 .none, // Underlying type
2464 ty.abiSize(pt) * 8,2520 ty.abiSize(pt) * 8,
...@@ -2480,8 +2536,7 @@ pub const Object = struct {...@@ -2480,8 +2536,7 @@ pub const Object = struct {
2480 // into. Therefore we can satisfy this by making an empty namespace,2536 // into. Therefore we can satisfy this by making an empty namespace,
2481 // rather than changing the frontend to unnecessarily resolve the2537 // rather than changing the frontend to unnecessarily resolve the
2482 // struct field types.2538 // struct field types.
2483 const owner_decl_index = ty.getOwnerDecl(zcu);2539 const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index.?);
2484 const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index);
2485 try o.debug_type_map.put(gpa, ty, debug_struct_type);2540 try o.debug_type_map.put(gpa, ty, debug_struct_type);
2486 return debug_struct_type;2541 return debug_struct_type;
2487 }2542 }
...@@ -2490,8 +2545,7 @@ pub const Object = struct {...@@ -2490,8 +2545,7 @@ pub const Object = struct {
2490 }2545 }
24912546
2492 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {2547 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {
2493 const owner_decl_index = ty.getOwnerDecl(zcu);2548 const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index.?);
2494 const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index);
2495 try o.debug_type_map.put(gpa, ty, debug_struct_type);2549 try o.debug_type_map.put(gpa, ty, debug_struct_type);
2496 return debug_struct_type;2550 return debug_struct_type;
2497 }2551 }
...@@ -2526,7 +2580,7 @@ pub const Object = struct {...@@ -2526,7 +2580,7 @@ pub const Object = struct {
25262580
2527 fields.appendAssumeCapacity(try o.builder.debugMemberType(2581 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2528 try o.builder.metadataString(field_name.toSlice(ip)),2582 try o.builder.metadataString(field_name.toSlice(ip)),
2529 .none, // File2583 file,
2530 debug_fwd_ref,2584 debug_fwd_ref,
2531 0, // Line2585 0, // Line
2532 try o.lowerDebugType(field_ty),2586 try o.lowerDebugType(field_ty),
...@@ -2538,9 +2592,9 @@ pub const Object = struct {...@@ -2538,9 +2592,9 @@ pub const Object = struct {
25382592
2539 const debug_struct_type = try o.builder.debugStructType(2593 const debug_struct_type = try o.builder.debugStructType(
2540 try o.builder.metadataString(name),2594 try o.builder.metadataString(name),
2541 .none, // File2595 file,
2542 o.debug_compile_unit, // Scope2596 scope,
2543 0, // Line2597 line,
2544 .none, // Underlying type2598 .none, // Underlying type
2545 ty.abiSize(pt) * 8,2599 ty.abiSize(pt) * 8,
2546 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,2600 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
...@@ -2556,17 +2610,12 @@ pub const Object = struct {...@@ -2556,17 +2610,12 @@ pub const Object = struct {
2556 return debug_struct_type;2610 return debug_struct_type;
2557 },2611 },
2558 .Union => {2612 .Union => {
2559 const owner_decl_index = ty.getOwnerDecl(zcu);
2560
2561 const name = try o.allocTypeName(ty);
2562 defer gpa.free(name);
2563
2564 const union_type = ip.loadUnionType(ty.toIntern());2613 const union_type = ip.loadUnionType(ty.toIntern());
2565 if (!union_type.haveFieldTypes(ip) or2614 if (!union_type.haveFieldTypes(ip) or
2566 !ty.hasRuntimeBitsIgnoreComptime(pt) or2615 !ty.hasRuntimeBitsIgnoreComptime(pt) or
2567 !union_type.haveLayout(ip))2616 !union_type.haveLayout(ip))
2568 {2617 {
2569 const debug_union_type = try o.makeEmptyNamespaceDebugType(owner_decl_index);2618 const debug_union_type = try o.makeEmptyNamespaceDebugType(owner_decl_index.?);
2570 try o.debug_type_map.put(gpa, ty, debug_union_type);2619 try o.debug_type_map.put(gpa, ty, debug_union_type);
2571 return debug_union_type;2620 return debug_union_type;
2572 }2621 }
...@@ -2581,8 +2630,8 @@ pub const Object = struct {...@@ -2581,8 +2630,8 @@ pub const Object = struct {
2581 if (layout.payload_size == 0) {2630 if (layout.payload_size == 0) {
2582 const debug_union_type = try o.builder.debugStructType(2631 const debug_union_type = try o.builder.debugStructType(
2583 try o.builder.metadataString(name),2632 try o.builder.metadataString(name),
2584 .none, // File2633 file,
2585 o.debug_compile_unit, // Scope2634 scope,
2586 0, // Line2635 0, // Line
2587 .none, // Underlying type2636 .none, // Underlying type
2588 ty.abiSize(pt) * 8,2637 ty.abiSize(pt) * 8,
...@@ -2624,7 +2673,7 @@ pub const Object = struct {...@@ -2624,7 +2673,7 @@ pub const Object = struct {
2624 const field_name = tag_type.names.get(ip)[field_index];2673 const field_name = tag_type.names.get(ip)[field_index];
2625 fields.appendAssumeCapacity(try o.builder.debugMemberType(2674 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2626 try o.builder.metadataString(field_name.toSlice(ip)),2675 try o.builder.metadataString(field_name.toSlice(ip)),
2627 .none, // File2676 file,
2628 debug_union_fwd_ref,2677 debug_union_fwd_ref,
2629 0, // Line2678 0, // Line
2630 try o.lowerDebugType(Type.fromInterned(field_ty)),2679 try o.lowerDebugType(Type.fromInterned(field_ty)),
...@@ -2643,9 +2692,9 @@ pub const Object = struct {...@@ -2643,9 +2692,9 @@ pub const Object = struct {
26432692
2644 const debug_union_type = try o.builder.debugUnionType(2693 const debug_union_type = try o.builder.debugUnionType(
2645 try o.builder.metadataString(union_name),2694 try o.builder.metadataString(union_name),
2646 .none, // File2695 file,
2647 o.debug_compile_unit, // Scope2696 scope,
2648 0, // Line2697 line,
2649 .none, // Underlying type2698 .none, // Underlying type
2650 ty.abiSize(pt) * 8,2699 ty.abiSize(pt) * 8,
2651 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,2700 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
...@@ -2674,7 +2723,7 @@ pub const Object = struct {...@@ -2674,7 +2723,7 @@ pub const Object = struct {
26742723
2675 const debug_tag_type = try o.builder.debugMemberType(2724 const debug_tag_type = try o.builder.debugMemberType(
2676 try o.builder.metadataString("tag"),2725 try o.builder.metadataString("tag"),
2677 .none, // File2726 file, // File
2678 debug_fwd_ref,2727 debug_fwd_ref,
2679 0, // Line2728 0, // Line
2680 try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty)),2729 try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty)),
...@@ -2685,7 +2734,7 @@ pub const Object = struct {...@@ -2685,7 +2734,7 @@ pub const Object = struct {
26852734
2686 const debug_payload_type = try o.builder.debugMemberType(2735 const debug_payload_type = try o.builder.debugMemberType(
2687 try o.builder.metadataString("payload"),2736 try o.builder.metadataString("payload"),
2688 .none, // File2737 file,
2689 debug_fwd_ref,2738 debug_fwd_ref,
2690 0, // Line2739 0, // Line
2691 debug_union_type,2740 debug_union_type,
...@@ -2702,9 +2751,9 @@ pub const Object = struct {...@@ -2702,9 +2751,9 @@ pub const Object = struct {
27022751
2703 const debug_tagged_union_type = try o.builder.debugStructType(2752 const debug_tagged_union_type = try o.builder.debugStructType(
2704 try o.builder.metadataString(name),2753 try o.builder.metadataString(name),
2705 .none, // File2754 file, // File
2706 o.debug_compile_unit, // Scope2755 scope,
2707 0, // Line2756 line,
2708 .none, // Underlying type2757 .none, // Underlying type
2709 ty.abiSize(pt) * 8,2758 ty.abiSize(pt) * 8,
2710 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,2759 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
...@@ -2719,63 +2768,20 @@ pub const Object = struct {...@@ -2719,63 +2768,20 @@ pub const Object = struct {
27192768
2720 return debug_tagged_union_type;2769 return debug_tagged_union_type;
2721 },2770 },
2722 .Fn => {2771 else => unreachable, // Handled above.
2723 const fn_info = zcu.typeToFunc(ty).?;2772 }
27242773 }
2725 var debug_param_types = std.ArrayList(Builder.Metadata).init(gpa);
2726 defer debug_param_types.deinit();
2727
2728 try debug_param_types.ensureUnusedCapacity(3 + fn_info.param_types.len);
2729
2730 // Return type goes first.
2731 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(pt)) {
2732 const sret = firstParamSRet(fn_info, pt, target);
2733 const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type);
2734 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty));
2735
2736 if (sret) {
2737 const ptr_ty = try pt.singleMutPtrType(Type.fromInterned(fn_info.return_type));
2738 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
2739 }
2740 } else {
2741 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(Type.void));
2742 }
2743
2744 if (Type.fromInterned(fn_info.return_type).isError(zcu) and
2745 zcu.comp.config.any_error_tracing)
2746 {
2747 const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType());
2748 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
2749 }
2750
2751 for (0..fn_info.param_types.len) |i| {
2752 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[i]);
2753 if (!param_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
2754
2755 if (isByRef(param_ty, pt)) {
2756 const ptr_ty = try pt.singleMutPtrType(param_ty);
2757 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
2758 } else {
2759 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(param_ty));
2760 }
2761 }
27622774
2763 const debug_function_type = try o.builder.debugSubroutineType(2775 fn genNamespaces(o: *Object) !void {
2764 try o.builder.debugTuple(debug_param_types.items),2776 var i: usize = 0;
2765 );2777 while (i < o.debug_unresolved_namespace_scopes.count()) : (i += 1) {
2778 const namespace_index = o.debug_unresolved_namespace_scopes.keys()[i];
2779 const fwd_ref = o.debug_unresolved_namespace_scopes.values()[i];
27662780
2767 try o.debug_type_map.put(gpa, ty, debug_function_type);2781 const namespace = o.pt.zcu.namespacePtr(namespace_index);
2768 return debug_function_type;2782 const debug_type = try o.lowerDebugType(namespace.getType(o.pt.zcu));
2769 },
2770 .ComptimeInt => unreachable,
2771 .ComptimeFloat => unreachable,
2772 .Type => unreachable,
2773 .Undefined => unreachable,
2774 .Null => unreachable,
2775 .EnumLiteral => unreachable,
27762783
2777 .Frame => @panic("TODO implement lowerDebugType for Frame types"),2784 o.builder.debugForwardReferenceSetType(fwd_ref, debug_type);
2778 .AnyFrame => @panic("TODO implement lowerDebugType for AnyFrame types"),
2779 }2785 }
2780 }2786 }
27812787
...@@ -4718,17 +4724,37 @@ pub const DeclGen = struct {...@@ -4718,17 +4724,37 @@ pub const DeclGen = struct {
4718 if (!owner_mod.strip) {4724 if (!owner_mod.strip) {
4719 const debug_file = try o.getDebugFile(file_scope);4725 const debug_file = try o.getDebugFile(file_scope);
47204726
4721 const debug_global_var = try o.builder.debugGlobalVar(4727 const linkage_name = try o.builder.metadataStringFromStrtabString(variable_index.name(&o.builder));
4722 try o.builder.metadataString(decl.name.toSlice(ip)), // Name4728
4723 try o.builder.metadataStringFromStrtabString(variable_index.name(&o.builder)), // Linkage name4729 const debug_global_var = if (!decl.isExtern(zcu)) blk: {
4724 debug_file, // File4730 // Imitate a C++ static member variable since neither
4725 debug_file, // Scope4731 // GDB or LLDB can really cope with regular variables
4732 // directly inside a struct type.
4733 const ty = try o.lowerDebugType(decl.typeOf(zcu));
4734 const name = try o.builder.metadataString(decl.name.toSlice(ip));
4735
4736 break :blk try o.builder.debugGlobalVar(
4737 name,
4738 linkage_name,
4739 debug_file,
4740 debug_file,
4741 line_number,
4742 ty,
4743 variable_index,
4744 .none,
4745 .internal,
4746 );
4747 } else try o.builder.debugGlobalVar(
4748 linkage_name,
4749 linkage_name,
4750 debug_file,
4751 debug_file,
4726 line_number,4752 line_number,
4727 try o.lowerDebugType(decl.typeOf(zcu)),4753 try o.lowerDebugType(decl.typeOf(zcu)),
4728 variable_index,4754 variable_index,
4729 .{ .local = !decl.isExtern(zcu) },4755 .none,
4756 .external,
4730 );4757 );
4731
4732 const debug_expression = try o.builder.debugExpression(&.{});4758 const debug_expression = try o.builder.debugExpression(&.{});
47334759
4734 const debug_global_var_expression = try o.builder.debugGlobalVarExpression(4760 const debug_global_var_expression = try o.builder.debugGlobalVarExpression(
...@@ -5178,6 +5204,7 @@ pub const FuncGen = struct {...@@ -5178,6 +5204,7 @@ pub const FuncGen = struct {
51785204
5179 self.scope = try o.builder.debugSubprogram(5205 self.scope = try o.builder.debugSubprogram(
5180 self.file,5206 self.file,
5207 self.file, // TODO Get the correct scope into here—self.scope is the function's *inner* scope.
5181 try o.builder.metadataString(decl.name.toSlice(&zcu.intern_pool)),5208 try o.builder.metadataString(decl.name.toSlice(&zcu.intern_pool)),
5182 try o.builder.metadataString(decl.fqn.toSlice(&zcu.intern_pool)),5209 try o.builder.metadataString(decl.fqn.toSlice(&zcu.intern_pool)),
5183 line_number,5210 line_number,
src/codegen/llvm/Builder.zig+83-29
...@@ -7651,6 +7651,7 @@ pub const Metadata = enum(u32) {...@@ -7651,6 +7651,7 @@ pub const Metadata = enum(u32) {
7651 composite_vector_type,7651 composite_vector_type,
7652 derived_pointer_type,7652 derived_pointer_type,
7653 derived_member_type,7653 derived_member_type,
7654 derived_static_member_type,
7654 subroutine_type,7655 subroutine_type,
7655 enumerator_unsigned,7656 enumerator_unsigned,
7656 enumerator_signed_positive,7657 enumerator_signed_positive,
...@@ -7663,6 +7664,7 @@ pub const Metadata = enum(u32) {...@@ -7663,6 +7664,7 @@ pub const Metadata = enum(u32) {
7663 parameter,7664 parameter,
7664 global_var,7665 global_var,
7665 @"global_var local",7666 @"global_var local",
7667 @"global_var decl",
7666 global_var_expression,7668 global_var_expression,
7667 constant,7669 constant,
76687670
...@@ -7696,6 +7698,7 @@ pub const Metadata = enum(u32) {...@@ -7696,6 +7698,7 @@ pub const Metadata = enum(u32) {
7696 .composite_vector_type,7698 .composite_vector_type,
7697 .derived_pointer_type,7699 .derived_pointer_type,
7698 .derived_member_type,7700 .derived_member_type,
7701 .derived_static_member_type,
7699 .subroutine_type,7702 .subroutine_type,
7700 .enumerator_unsigned,7703 .enumerator_unsigned,
7701 .enumerator_signed_positive,7704 .enumerator_signed_positive,
...@@ -7707,6 +7710,7 @@ pub const Metadata = enum(u32) {...@@ -7707,6 +7710,7 @@ pub const Metadata = enum(u32) {
7707 .parameter,7710 .parameter,
7708 .global_var,7711 .global_var,
7709 .@"global_var local",7712 .@"global_var local",
7713 .@"global_var decl",
7710 .global_var_expression,7714 .global_var_expression,
7711 => false,7715 => false,
7712 };7716 };
...@@ -7860,6 +7864,7 @@ pub const Metadata = enum(u32) {...@@ -7860,6 +7864,7 @@ pub const Metadata = enum(u32) {
7860 }7864 }
7861 };7865 };
78627866
7867 scope: Metadata,
7863 file: Metadata,7868 file: Metadata,
7864 name: MetadataString,7869 name: MetadataString,
7865 linkage_name: MetadataString,7870 linkage_name: MetadataString,
...@@ -7990,8 +7995,10 @@ pub const Metadata = enum(u32) {...@@ -7990,8 +7995,10 @@ pub const Metadata = enum(u32) {
7990 };7995 };
79917996
7992 pub const GlobalVar = struct {7997 pub const GlobalVar = struct {
7993 pub const Options = struct {7998 pub const Options = enum {
7994 local: bool,7999 internal,
8000 internal_decl,
8001 external,
7995 };8002 };
79968003
7997 name: MetadataString,8004 name: MetadataString,
...@@ -8001,6 +8008,7 @@ pub const Metadata = enum(u32) {...@@ -8001,6 +8008,7 @@ pub const Metadata = enum(u32) {
8001 line: u32,8008 line: u32,
8002 ty: Metadata,8009 ty: Metadata,
8003 variable: Variable.Index,8010 variable: Variable.Index,
8011 declaration: Metadata,
8004 };8012 };
80058013
8006 pub const GlobalVarExpression = struct {8014 pub const GlobalVarExpression = struct {
...@@ -9985,7 +9993,7 @@ pub fn printUnbuffered(...@@ -9985,7 +9993,7 @@ pub fn printUnbuffered(
9985 try metadata_formatter.specialized(.@"distinct !", .DISubprogram, .{9993 try metadata_formatter.specialized(.@"distinct !", .DISubprogram, .{
9986 .name = extra.name,9994 .name = extra.name,
9987 .linkageName = extra.linkage_name,9995 .linkageName = extra.linkage_name,
9988 .scope = extra.file,9996 .scope = extra.scope,
9989 .file = extra.file,9997 .file = extra.file,
9990 .line = extra.line,9998 .line = extra.line,
9991 .type = extra.ty,9999 .type = extra.ty,
...@@ -10079,8 +10087,8 @@ pub fn printUnbuffered(...@@ -10079,8 +10087,8 @@ pub fn printUnbuffered(
10079 else => extra.name,10087 else => extra.name,
10080 },10088 },
10081 .scope = extra.scope,10089 .scope = extra.scope,
10082 .file = null,10090 .file = extra.file,
10083 .line = null,10091 .line = extra.line,
10084 .baseType = extra.underlying_type,10092 .baseType = extra.underlying_type,
10085 .size = extra.bitSize(),10093 .size = extra.bitSize(),
10086 .@"align" = extra.bitAlign(),10094 .@"align" = extra.bitAlign(),
...@@ -10101,6 +10109,7 @@ pub fn printUnbuffered(...@@ -10101,6 +10109,7 @@ pub fn printUnbuffered(
10101 },10109 },
10102 .derived_pointer_type,10110 .derived_pointer_type,
10103 .derived_member_type,10111 .derived_member_type,
10112 .derived_static_member_type,
10104 => |kind| {10113 => |kind| {
10105 const extra = self.metadataExtraData(Metadata.DerivedType, metadata_item.data);10114 const extra = self.metadataExtraData(Metadata.DerivedType, metadata_item.data);
10106 try metadata_formatter.specialized(.@"!", .DIDerivedType, .{10115 try metadata_formatter.specialized(.@"!", .DIDerivedType, .{
...@@ -10109,7 +10118,8 @@ pub fn printUnbuffered(...@@ -10109,7 +10118,8 @@ pub fn printUnbuffered(
10109 DW_TAG_member,10118 DW_TAG_member,
10110 }, switch (kind) {10119 }, switch (kind) {
10111 .derived_pointer_type => .DW_TAG_pointer_type,10120 .derived_pointer_type => .DW_TAG_pointer_type,
10112 .derived_member_type => .DW_TAG_member,10121 .derived_member_type,
10122 .derived_static_member_type => .DW_TAG_member,
10113 else => unreachable,10123 else => unreachable,
10114 }),10124 }),
10115 .name = switch (extra.name) {10125 .name = switch (extra.name) {
...@@ -10126,7 +10136,7 @@ pub fn printUnbuffered(...@@ -10126,7 +10136,7 @@ pub fn printUnbuffered(
10126 0 => null,10136 0 => null,
10127 else => |bit_offset| bit_offset,10137 else => |bit_offset| bit_offset,
10128 },10138 },
10129 .flags = null,10139 .flags = null, // TODO staticness
10130 .extraData = null,10140 .extraData = null,
10131 .dwarfAddressSpace = null,10141 .dwarfAddressSpace = null,
10132 .annotations = null,10142 .annotations = null,
...@@ -10246,6 +10256,7 @@ pub fn printUnbuffered(...@@ -10246,6 +10256,7 @@ pub fn printUnbuffered(
10246 },10256 },
10247 .global_var,10257 .global_var,
10248 .@"global_var local",10258 .@"global_var local",
10259 .@"global_var decl",
10249 => |kind| {10260 => |kind| {
10250 const extra = self.metadataExtraData(Metadata.GlobalVar, metadata_item.data);10261 const extra = self.metadataExtraData(Metadata.GlobalVar, metadata_item.data);
10251 try metadata_formatter.specialized(.@"distinct !", .DIGlobalVariable, .{10262 try metadata_formatter.specialized(.@"distinct !", .DIGlobalVariable, .{
...@@ -10255,12 +10266,8 @@ pub fn printUnbuffered(...@@ -10255,12 +10266,8 @@ pub fn printUnbuffered(
10255 .file = extra.file,10266 .file = extra.file,
10256 .line = extra.line,10267 .line = extra.line,
10257 .type = extra.ty,10268 .type = extra.ty,
10258 .isLocal = switch (kind) {10269 .isLocal = kind != .global_var,
10259 .global_var => false,10270 .isDefinition = kind != .@"global_var decl",
10260 .@"global_var local" => true,
10261 else => unreachable,
10262 },
10263 .isDefinition = true,
10264 .declaration = null,10271 .declaration = null,
10265 .templateParams = null,10272 .templateParams = null,
10266 .@"align" = null,10273 .@"align" = null,
...@@ -11749,6 +11756,7 @@ pub fn debugCompileUnit(...@@ -11749,6 +11756,7 @@ pub fn debugCompileUnit(
11749pub fn debugSubprogram(11756pub fn debugSubprogram(
11750 self: *Builder,11757 self: *Builder,
11751 file: Metadata,11758 file: Metadata,
11759 scope: Metadata,
11752 name: MetadataString,11760 name: MetadataString,
11753 linkage_name: MetadataString,11761 linkage_name: MetadataString,
11754 line: u32,11762 line: u32,
...@@ -11760,6 +11768,7 @@ pub fn debugSubprogram(...@@ -11760,6 +11768,7 @@ pub fn debugSubprogram(
11760 try self.ensureUnusedMetadataCapacity(1, Metadata.Subprogram, 0);11768 try self.ensureUnusedMetadataCapacity(1, Metadata.Subprogram, 0);
11761 return self.debugSubprogramAssumeCapacity(11769 return self.debugSubprogramAssumeCapacity(
11762 file,11770 file,
11771 scope,
11763 name,11772 name,
11764 linkage_name,11773 linkage_name,
11765 line,11774 line,
...@@ -11949,6 +11958,28 @@ pub fn debugPointerType(...@@ -11949,6 +11958,28 @@ pub fn debugPointerType(
11949 );11958 );
11950}11959}
1195111960
11961pub fn debugStaticMemberType(
11962 self: *Builder,
11963 name: MetadataString,
11964 file: Metadata,
11965 scope: Metadata,
11966 line: u32,
11967 underlying_type: Metadata,
11968) Allocator.Error!Metadata {
11969 try self.ensureUnusedMetadataCapacity(1, Metadata.DerivedType, 0);
11970 return self.debugMemberTypeAssumeCapacity(
11971 name,
11972 file,
11973 scope,
11974 line,
11975 underlying_type,
11976 0,
11977 0,
11978 0,
11979 true,
11980 );
11981}
11982
11952pub fn debugMemberType(11983pub fn debugMemberType(
11953 self: *Builder,11984 self: *Builder,
11954 name: MetadataString,11985 name: MetadataString,
...@@ -11970,6 +12001,7 @@ pub fn debugMemberType(...@@ -11970,6 +12001,7 @@ pub fn debugMemberType(
11970 size_in_bits,12001 size_in_bits,
11971 align_in_bits,12002 align_in_bits,
11972 offset_in_bits,12003 offset_in_bits,
12004 false,
11973 );12005 );
11974}12006}
1197512007
...@@ -12063,6 +12095,7 @@ pub fn debugGlobalVar(...@@ -12063,6 +12095,7 @@ pub fn debugGlobalVar(
12063 line: u32,12095 line: u32,
12064 ty: Metadata,12096 ty: Metadata,
12065 variable: Variable.Index,12097 variable: Variable.Index,
12098 declaration: Metadata,
12066 options: Metadata.GlobalVar.Options,12099 options: Metadata.GlobalVar.Options,
12067) Allocator.Error!Metadata {12100) Allocator.Error!Metadata {
12068 try self.ensureUnusedMetadataCapacity(1, Metadata.GlobalVar, 0);12101 try self.ensureUnusedMetadataCapacity(1, Metadata.GlobalVar, 0);
...@@ -12074,6 +12107,7 @@ pub fn debugGlobalVar(...@@ -12074,6 +12107,7 @@ pub fn debugGlobalVar(
12074 line,12107 line,
12075 ty,12108 ty,
12076 variable,12109 variable,
12110 declaration,
12077 options,12111 options,
12078 );12112 );
12079}12113}
...@@ -12224,6 +12258,7 @@ pub fn debugCompileUnitAssumeCapacity(...@@ -12224,6 +12258,7 @@ pub fn debugCompileUnitAssumeCapacity(
12224fn debugSubprogramAssumeCapacity(12258fn debugSubprogramAssumeCapacity(
12225 self: *Builder,12259 self: *Builder,
12226 file: Metadata,12260 file: Metadata,
12261 scope: Metadata,
12227 name: MetadataString,12262 name: MetadataString,
12228 linkage_name: MetadataString,12263 linkage_name: MetadataString,
12229 line: u32,12264 line: u32,
...@@ -12237,6 +12272,7 @@ fn debugSubprogramAssumeCapacity(...@@ -12237,6 +12272,7 @@ fn debugSubprogramAssumeCapacity(
12237 @as(u3, @truncate(@as(u32, @bitCast(options.sp_flags)) >> 2)));12272 @as(u3, @truncate(@as(u32, @bitCast(options.sp_flags)) >> 2)));
12238 return self.metadataDistinctAssumeCapacity(tag, Metadata.Subprogram{12273 return self.metadataDistinctAssumeCapacity(tag, Metadata.Subprogram{
12239 .file = file,12274 .file = file,
12275 .scope = scope,
12240 .name = name,12276 .name = name,
12241 .linkage_name = linkage_name,12277 .linkage_name = linkage_name,
12242 .line = line,12278 .line = line,
...@@ -12499,21 +12535,25 @@ fn debugMemberTypeAssumeCapacity(...@@ -12499,21 +12535,25 @@ fn debugMemberTypeAssumeCapacity(
12499 size_in_bits: u64,12535 size_in_bits: u64,
12500 align_in_bits: u64,12536 align_in_bits: u64,
12501 offset_in_bits: u64,12537 offset_in_bits: u64,
12538 static: bool,
12502) Metadata {12539) Metadata {
12503 assert(!self.strip);12540 assert(!self.strip);
12504 return self.metadataSimpleAssumeCapacity(.derived_member_type, Metadata.DerivedType{12541 return self.metadataSimpleAssumeCapacity(
12505 .name = name,12542 if (static) .derived_static_member_type else .derived_member_type,
12506 .file = file,12543 Metadata.DerivedType{
12507 .scope = scope,12544 .name = name,
12508 .line = line,12545 .file = file,
12509 .underlying_type = underlying_type,12546 .scope = scope,
12510 .size_in_bits_lo = @truncate(size_in_bits),12547 .line = line,
12511 .size_in_bits_hi = @truncate(size_in_bits >> 32),12548 .underlying_type = underlying_type,
12512 .align_in_bits_lo = @truncate(align_in_bits),12549 .size_in_bits_lo = @truncate(size_in_bits),
12513 .align_in_bits_hi = @truncate(align_in_bits >> 32),12550 .size_in_bits_hi = @truncate(size_in_bits >> 32),
12514 .offset_in_bits_lo = @truncate(offset_in_bits),12551 .align_in_bits_lo = @truncate(align_in_bits),
12515 .offset_in_bits_hi = @truncate(offset_in_bits >> 32),12552 .align_in_bits_hi = @truncate(align_in_bits >> 32),
12516 });12553 .offset_in_bits_lo = @truncate(offset_in_bits),
12554 .offset_in_bits_hi = @truncate(offset_in_bits >> 32),
12555 }
12556 );
12517}12557}
1251812558
12519fn debugSubroutineTypeAssumeCapacity(12559fn debugSubroutineTypeAssumeCapacity(
...@@ -12769,11 +12809,16 @@ fn debugGlobalVarAssumeCapacity(...@@ -12769,11 +12809,16 @@ fn debugGlobalVarAssumeCapacity(
12769 line: u32,12809 line: u32,
12770 ty: Metadata,12810 ty: Metadata,
12771 variable: Variable.Index,12811 variable: Variable.Index,
12812 declaration: Metadata,
12772 options: Metadata.GlobalVar.Options,12813 options: Metadata.GlobalVar.Options,
12773) Metadata {12814) Metadata {
12774 assert(!self.strip);12815 assert(!self.strip);
12775 return self.metadataDistinctAssumeCapacity(12816 return self.metadataDistinctAssumeCapacity(
12776 if (options.local) .@"global_var local" else .global_var,12817 switch (options) {
12818 .internal => .@"global_var local",
12819 .internal_decl => .@"global_var decl",
12820 .external => .global_var,
12821 },
12777 Metadata.GlobalVar{12822 Metadata.GlobalVar{
12778 .name = name,12823 .name = name,
12779 .linkage_name = linkage_name,12824 .linkage_name = linkage_name,
...@@ -12782,6 +12827,7 @@ fn debugGlobalVarAssumeCapacity(...@@ -12782,6 +12827,7 @@ fn debugGlobalVarAssumeCapacity(
12782 .line = line,12827 .line = line,
12783 .ty = ty,12828 .ty = ty,
12784 .variable = variable,12829 .variable = variable,
12830 .declaration = declaration,
12785 },12831 },
12786 );12832 );
12787}12833}
...@@ -13818,7 +13864,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13818,7 +13864,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13818 const extra = self.metadataExtraData(Metadata.Subprogram, data);13864 const extra = self.metadataExtraData(Metadata.Subprogram, data);
1381913865
13820 try metadata_block.writeAbbrevAdapted(MetadataBlock.Subprogram{13866 try metadata_block.writeAbbrevAdapted(MetadataBlock.Subprogram{
13821 .scope = extra.file,13867 .scope = extra.scope,
13822 .name = extra.name,13868 .name = extra.name,
13823 .linkage_name = extra.linkage_name,13869 .linkage_name = extra.linkage_name,
13824 .file = extra.file,13870 .file = extra.file,
...@@ -13898,12 +13944,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13898,12 +13944,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13898 },13944 },
13899 .derived_pointer_type,13945 .derived_pointer_type,
13900 .derived_member_type,13946 .derived_member_type,
13947 .derived_static_member_type,
13901 => |kind| {13948 => |kind| {
13902 const extra = self.metadataExtraData(Metadata.DerivedType, data);13949 const extra = self.metadataExtraData(Metadata.DerivedType, data);
13903 try metadata_block.writeAbbrevAdapted(MetadataBlock.DerivedType{13950 try metadata_block.writeAbbrevAdapted(MetadataBlock.DerivedType{
13904 .tag = switch (kind) {13951 .tag = switch (kind) {
13905 .derived_pointer_type => DW.TAG.pointer_type,13952 .derived_pointer_type => DW.TAG.pointer_type,
13906 .derived_member_type => DW.TAG.member,13953 .derived_member_type,
13954 .derived_static_member_type => DW.TAG.member,
13907 else => unreachable,13955 else => unreachable,
13908 },13956 },
13909 .name = extra.name,13957 .name = extra.name,
...@@ -13914,6 +13962,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13914,6 +13962,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13914 .size_in_bits = extra.bitSize(),13962 .size_in_bits = extra.bitSize(),
13915 .align_in_bits = extra.bitAlign(),13963 .align_in_bits = extra.bitAlign(),
13916 .offset_in_bits = extra.bitOffset(),13964 .offset_in_bits = extra.bitOffset(),
13965 .flags = .{
13966 .StaticMember = kind == .derived_static_member_type,
13967 },
13917 }, metadata_adapter);13968 }, metadata_adapter);
13918 },13969 },
13919 .subroutine_type => {13970 .subroutine_type => {
...@@ -14041,6 +14092,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14041,6 +14092,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14041 },14092 },
14042 .global_var,14093 .global_var,
14043 .@"global_var local",14094 .@"global_var local",
14095 .@"global_var decl",
14044 => |kind| {14096 => |kind| {
14045 const extra = self.metadataExtraData(Metadata.GlobalVar, data);14097 const extra = self.metadataExtraData(Metadata.GlobalVar, data);
14046 try metadata_block.writeAbbrevAdapted(MetadataBlock.GlobalVar{14098 try metadata_block.writeAbbrevAdapted(MetadataBlock.GlobalVar{
...@@ -14051,6 +14103,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14051,6 +14103,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14051 .line = extra.line,14103 .line = extra.line,
14052 .ty = extra.ty,14104 .ty = extra.ty,
14053 .local = kind == .@"global_var local",14105 .local = kind == .@"global_var local",
14106 .defined = kind != .@"global_var decl",
14107 .declaration = extra.declaration,
14054 }, metadata_adapter);14108 }, metadata_adapter);
14055 },14109 },
14056 .global_var_expression => {14110 .global_var_expression => {
src/codegen/llvm/ir.zig+7-4
...@@ -694,7 +694,7 @@ pub const MetadataBlock = struct {...@@ -694,7 +694,7 @@ pub const MetadataBlock = struct {
694 pub const ops = [_]AbbrevOp{694 pub const ops = [_]AbbrevOp{
695 .{ .literal = 20 },695 .{ .literal = 20 },
696 .{ .literal = 1 }, // is distinct696 .{ .literal = 1 }, // is distinct
697 .{ .literal = std.dwarf.LANG.C99 }, // source language697 .{ .literal = std.dwarf.LANG.C_plus_plus_11 }, // source language
698 MetadataAbbrev, // file698 MetadataAbbrev, // file
699 MetadataAbbrev, // producer699 MetadataAbbrev, // producer
700 .{ .fixed = 1 }, // isOptimized700 .{ .fixed = 1 }, // isOptimized
...@@ -863,7 +863,7 @@ pub const MetadataBlock = struct {...@@ -863,7 +863,7 @@ pub const MetadataBlock = struct {
863 .{ .vbr = 6 }, // size in bits863 .{ .vbr = 6 }, // size in bits
864 .{ .vbr = 6 }, // align in bits864 .{ .vbr = 6 }, // align in bits
865 .{ .vbr = 6 }, // offset in bits865 .{ .vbr = 6 }, // offset in bits
866 .{ .literal = 0 }, // flags866 .{ .fixed = 32 }, // flags
867 .{ .literal = 0 }, // extra data867 .{ .literal = 0 }, // extra data
868 };868 };
869869
...@@ -876,6 +876,7 @@ pub const MetadataBlock = struct {...@@ -876,6 +876,7 @@ pub const MetadataBlock = struct {
876 size_in_bits: u64,876 size_in_bits: u64,
877 align_in_bits: u64,877 align_in_bits: u64,
878 offset_in_bits: u64,878 offset_in_bits: u64,
879 flags: Builder.Metadata.DIFlags,
879 };880 };
880881
881 pub const SubroutineType = struct {882 pub const SubroutineType = struct {
...@@ -1002,8 +1003,8 @@ pub const MetadataBlock = struct {...@@ -1002,8 +1003,8 @@ pub const MetadataBlock = struct {
1002 LineAbbrev, // line1003 LineAbbrev, // line
1003 MetadataAbbrev, // type1004 MetadataAbbrev, // type
1004 .{ .fixed = 1 }, // local1005 .{ .fixed = 1 }, // local
1005 .{ .literal = 1 }, // defined1006 .{ .fixed = 1 }, // defined
1006 .{ .literal = 0 }, // static data members declaration1007 MetadataAbbrev, // static data members declaration
1007 .{ .literal = 0 }, // template params1008 .{ .literal = 0 }, // template params
1008 .{ .literal = 0 }, // align in bits1009 .{ .literal = 0 }, // align in bits
1009 .{ .literal = 0 }, // annotations1010 .{ .literal = 0 }, // annotations
...@@ -1016,6 +1017,8 @@ pub const MetadataBlock = struct {...@@ -1016,6 +1017,8 @@ pub const MetadataBlock = struct {
1016 line: u32,1017 line: u32,
1017 ty: Builder.Metadata,1018 ty: Builder.Metadata,
1018 local: bool,1019 local: bool,
1020 defined: bool,
1021 declaration: Builder.Metadata,
1019 };1022 };
10201023
1021 pub const GlobalVarExpression = struct {1024 pub const GlobalVarExpression = struct {