| ... | ... | @@ -1140,18 +1140,7 @@ pub const Object = struct { |
| 1140 | 1140 | try self.genModuleLevelAssembly(); |
| 1141 | 1141 | |
| 1142 | 1142 | if (!self.builder.strip) { |
| 1143 | | { |
| 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 | | } |
| 1143 | try self.genNamespaces(); |
| 1155 | 1144 | |
| 1156 | 1145 | self.builder.debugForwardReferenceSetType( |
| 1157 | 1146 | self.debug_enums_fwd_ref, |
| ... | ... | @@ -1641,6 +1630,7 @@ pub const Object = struct { |
| 1641 | 1630 | |
| 1642 | 1631 | const file, const subprogram = if (!wip.strip) debug_info: { |
| 1643 | 1632 | const file = try o.getDebugFile(file_scope); |
| 1633 | const scope = try o.namespaceToDebugScope(decl.src_namespace); |
| 1644 | 1634 | |
| 1645 | 1635 | const line_number = decl.navSrcLine(zcu) + 1; |
| 1646 | 1636 | const is_internal_linkage = decl.val.getExternFunc(zcu) == null; |
| ... | ... | @@ -1648,6 +1638,7 @@ pub const Object = struct { |
| 1648 | 1638 | |
| 1649 | 1639 | const subprogram = try o.builder.debugSubprogram( |
| 1650 | 1640 | file, |
| 1641 | scope, |
| 1651 | 1642 | try o.builder.metadataString(decl.name.toSlice(ip)), |
| 1652 | 1643 | try o.builder.metadataStringFromStrtabString(function_index.name(&o.builder)), |
| 1653 | 1644 | line_number, |
| ... | ... | @@ -1924,6 +1915,7 @@ pub const Object = struct { |
| 1924 | 1915 | |
| 1925 | 1916 | if (o.debug_type_map.get(ty)) |debug_type| return debug_type; |
| 1926 | 1917 | |
| 1918 | |
| 1927 | 1919 | switch (ty.zigTypeTag(zcu)) { |
| 1928 | 1920 | .Void, |
| 1929 | 1921 | .NoReturn, |
| ... | ... | @@ -1938,9 +1930,9 @@ pub const Object = struct { |
| 1938 | 1930 | .Int => { |
| 1939 | 1931 | const info = ty.intInfo(zcu); |
| 1940 | 1932 | assert(info.bits != 0); |
| 1941 | | const name = try o.allocTypeName(ty); |
| 1942 | | defer gpa.free(name); |
| 1943 | | const builder_name = try o.builder.metadataString(name); |
| 1933 | const int_name = try o.allocTypeName(ty); |
| 1934 | defer gpa.free(int_name); |
| 1935 | const builder_name = try o.builder.metadataString(int_name); |
| 1944 | 1936 | const debug_bits = ty.abiSize(pt) * 8; // lldb cannot handle non-byte sized types |
| 1945 | 1937 | const debug_int_type = switch (info.signedness) { |
| 1946 | 1938 | .signed => try o.builder.debugSignedType(builder_name, debug_bits), |
| ... | ... | @@ -1949,68 +1941,12 @@ pub const Object = struct { |
| 1949 | 1941 | try o.debug_type_map.put(gpa, ty, debug_int_type); |
| 1950 | 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 | 1944 | .Float => { |
| 2009 | 1945 | const bits = ty.floatBits(target); |
| 2010 | | const name = try o.allocTypeName(ty); |
| 2011 | | defer gpa.free(name); |
| 1946 | const float_name = try o.allocTypeName(ty); |
| 1947 | defer gpa.free(float_name); |
| 2012 | 1948 | const debug_float_type = try o.builder.debugFloatType( |
| 2013 | | try o.builder.metadataString(name), |
| 1949 | try o.builder.metadataString(float_name), |
| 2014 | 1950 | bits, |
| 2015 | 1951 | ); |
| 2016 | 1952 | try o.debug_type_map.put(gpa, ty, debug_float_type); |
| ... | ... | @@ -2068,6 +2004,7 @@ pub const Object = struct { |
| 2068 | 2004 | |
| 2069 | 2005 | const name = try o.allocTypeName(ty); |
| 2070 | 2006 | defer gpa.free(name); |
| 2007 | |
| 2071 | 2008 | const line = 0; |
| 2072 | 2009 | |
| 2073 | 2010 | const ptr_size = ptr_ty.abiSize(pt); |
| ... | ... | @@ -2146,34 +2083,6 @@ pub const Object = struct { |
| 2146 | 2083 | |
| 2147 | 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 | 2086 | .Array => { |
| 2178 | 2087 | const debug_array_type = try o.builder.debugArrayType( |
| 2179 | 2088 | .none, // Name |
| ... | ... | @@ -2203,9 +2112,9 @@ pub const Object = struct { |
| 2203 | 2112 | .Int => blk: { |
| 2204 | 2113 | const info = elem_ty.intInfo(zcu); |
| 2205 | 2114 | assert(info.bits != 0); |
| 2206 | | const name = try o.allocTypeName(ty); |
| 2207 | | defer gpa.free(name); |
| 2208 | | const builder_name = try o.builder.metadataString(name); |
| 2115 | const vec_name = try o.allocTypeName(ty); |
| 2116 | defer gpa.free(vec_name); |
| 2117 | const builder_name = try o.builder.metadataString(vec_name); |
| 2209 | 2118 | break :blk switch (info.signedness) { |
| 2210 | 2119 | .signed => try o.builder.debugSignedType(builder_name, info.bits), |
| 2211 | 2120 | .unsigned => try o.builder.debugUnsignedType(builder_name, info.bits), |
| ... | ... | @@ -2240,6 +2149,7 @@ pub const Object = struct { |
| 2240 | 2149 | .Optional => { |
| 2241 | 2150 | const name = try o.allocTypeName(ty); |
| 2242 | 2151 | defer gpa.free(name); |
| 2152 | |
| 2243 | 2153 | const child_ty = ty.optionalChild(zcu); |
| 2244 | 2154 | if (!child_ty.hasRuntimeBitsIgnoreComptime(pt)) { |
| 2245 | 2155 | const debug_bool_type = try o.builder.debugBoolType( |
| ... | ... | @@ -2399,10 +2309,156 @@ pub const Object = struct { |
| 2399 | 2309 | try o.debug_type_map.put(gpa, ty, debug_error_set); |
| 2400 | 2310 | return debug_error_set; |
| 2401 | 2311 | }, |
| 2402 | | .Struct => { |
| 2403 | | const name = try o.allocTypeName(ty); |
| 2404 | | defer gpa.free(name); |
| 2312 | .Fn => { |
| 2313 | const fn_info = zcu.typeToFunc(ty).?; |
| 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, |
| 2405 | 2366 | |
| 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 | 2462 | if (zcu.typeToPackedStruct(ty)) |struct_type| { |
| 2407 | 2463 | const backing_int_ty = struct_type.backingIntTypeUnordered(ip); |
| 2408 | 2464 | if (backing_int_ty != .none) { |
| ... | ... | @@ -2457,8 +2513,8 @@ pub const Object = struct { |
| 2457 | 2513 | |
| 2458 | 2514 | const debug_struct_type = try o.builder.debugStructType( |
| 2459 | 2515 | try o.builder.metadataString(name), |
| 2460 | | .none, // File |
| 2461 | | o.debug_compile_unit, // Scope |
| 2516 | file, |
| 2517 | scope, |
| 2462 | 2518 | 0, // Line |
| 2463 | 2519 | .none, // Underlying type |
| 2464 | 2520 | ty.abiSize(pt) * 8, |
| ... | ... | @@ -2480,8 +2536,7 @@ pub const Object = struct { |
| 2480 | 2536 | // into. Therefore we can satisfy this by making an empty namespace, |
| 2481 | 2537 | // rather than changing the frontend to unnecessarily resolve the |
| 2482 | 2538 | // struct field types. |
| 2483 | | const owner_decl_index = ty.getOwnerDecl(zcu); |
| 2484 | | const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index); |
| 2539 | const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index.?); |
| 2485 | 2540 | try o.debug_type_map.put(gpa, ty, debug_struct_type); |
| 2486 | 2541 | return debug_struct_type; |
| 2487 | 2542 | } |
| ... | ... | @@ -2490,8 +2545,7 @@ pub const Object = struct { |
| 2490 | 2545 | } |
| 2491 | 2546 | |
| 2492 | 2547 | if (!ty.hasRuntimeBitsIgnoreComptime(pt)) { |
| 2493 | | const owner_decl_index = ty.getOwnerDecl(zcu); |
| 2494 | | const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index); |
| 2548 | const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index.?); |
| 2495 | 2549 | try o.debug_type_map.put(gpa, ty, debug_struct_type); |
| 2496 | 2550 | return debug_struct_type; |
| 2497 | 2551 | } |
| ... | ... | @@ -2526,7 +2580,7 @@ pub const Object = struct { |
| 2526 | 2580 | |
| 2527 | 2581 | fields.appendAssumeCapacity(try o.builder.debugMemberType( |
| 2528 | 2582 | try o.builder.metadataString(field_name.toSlice(ip)), |
| 2529 | | .none, // File |
| 2583 | file, |
| 2530 | 2584 | debug_fwd_ref, |
| 2531 | 2585 | 0, // Line |
| 2532 | 2586 | try o.lowerDebugType(field_ty), |
| ... | ... | @@ -2538,9 +2592,9 @@ pub const Object = struct { |
| 2538 | 2592 | |
| 2539 | 2593 | const debug_struct_type = try o.builder.debugStructType( |
| 2540 | 2594 | try o.builder.metadataString(name), |
| 2541 | | .none, // File |
| 2542 | | o.debug_compile_unit, // Scope |
| 2543 | | 0, // Line |
| 2595 | file, |
| 2596 | scope, |
| 2597 | line, |
| 2544 | 2598 | .none, // Underlying type |
| 2545 | 2599 | ty.abiSize(pt) * 8, |
| 2546 | 2600 | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, |
| ... | ... | @@ -2556,17 +2610,12 @@ pub const Object = struct { |
| 2556 | 2610 | return debug_struct_type; |
| 2557 | 2611 | }, |
| 2558 | 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 | 2613 | const union_type = ip.loadUnionType(ty.toIntern()); |
| 2565 | 2614 | if (!union_type.haveFieldTypes(ip) or |
| 2566 | 2615 | !ty.hasRuntimeBitsIgnoreComptime(pt) or |
| 2567 | 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 | 2619 | try o.debug_type_map.put(gpa, ty, debug_union_type); |
| 2571 | 2620 | return debug_union_type; |
| 2572 | 2621 | } |
| ... | ... | @@ -2581,8 +2630,8 @@ pub const Object = struct { |
| 2581 | 2630 | if (layout.payload_size == 0) { |
| 2582 | 2631 | const debug_union_type = try o.builder.debugStructType( |
| 2583 | 2632 | try o.builder.metadataString(name), |
| 2584 | | .none, // File |
| 2585 | | o.debug_compile_unit, // Scope |
| 2633 | file, |
| 2634 | scope, |
| 2586 | 2635 | 0, // Line |
| 2587 | 2636 | .none, // Underlying type |
| 2588 | 2637 | ty.abiSize(pt) * 8, |
| ... | ... | @@ -2624,7 +2673,7 @@ pub const Object = struct { |
| 2624 | 2673 | const field_name = tag_type.names.get(ip)[field_index]; |
| 2625 | 2674 | fields.appendAssumeCapacity(try o.builder.debugMemberType( |
| 2626 | 2675 | try o.builder.metadataString(field_name.toSlice(ip)), |
| 2627 | | .none, // File |
| 2676 | file, |
| 2628 | 2677 | debug_union_fwd_ref, |
| 2629 | 2678 | 0, // Line |
| 2630 | 2679 | try o.lowerDebugType(Type.fromInterned(field_ty)), |
| ... | ... | @@ -2643,9 +2692,9 @@ pub const Object = struct { |
| 2643 | 2692 | |
| 2644 | 2693 | const debug_union_type = try o.builder.debugUnionType( |
| 2645 | 2694 | try o.builder.metadataString(union_name), |
| 2646 | | .none, // File |
| 2647 | | o.debug_compile_unit, // Scope |
| 2648 | | 0, // Line |
| 2695 | file, |
| 2696 | scope, |
| 2697 | line, |
| 2649 | 2698 | .none, // Underlying type |
| 2650 | 2699 | ty.abiSize(pt) * 8, |
| 2651 | 2700 | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, |
| ... | ... | @@ -2674,7 +2723,7 @@ pub const Object = struct { |
| 2674 | 2723 | |
| 2675 | 2724 | const debug_tag_type = try o.builder.debugMemberType( |
| 2676 | 2725 | try o.builder.metadataString("tag"), |
| 2677 | | .none, // File |
| 2726 | file, // File |
| 2678 | 2727 | debug_fwd_ref, |
| 2679 | 2728 | 0, // Line |
| 2680 | 2729 | try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty)), |
| ... | ... | @@ -2685,7 +2734,7 @@ pub const Object = struct { |
| 2685 | 2734 | |
| 2686 | 2735 | const debug_payload_type = try o.builder.debugMemberType( |
| 2687 | 2736 | try o.builder.metadataString("payload"), |
| 2688 | | .none, // File |
| 2737 | file, |
| 2689 | 2738 | debug_fwd_ref, |
| 2690 | 2739 | 0, // Line |
| 2691 | 2740 | debug_union_type, |
| ... | ... | @@ -2702,9 +2751,9 @@ pub const Object = struct { |
| 2702 | 2751 | |
| 2703 | 2752 | const debug_tagged_union_type = try o.builder.debugStructType( |
| 2704 | 2753 | try o.builder.metadataString(name), |
| 2705 | | .none, // File |
| 2706 | | o.debug_compile_unit, // Scope |
| 2707 | | 0, // Line |
| 2754 | file, // File |
| 2755 | scope, |
| 2756 | line, |
| 2708 | 2757 | .none, // Underlying type |
| 2709 | 2758 | ty.abiSize(pt) * 8, |
| 2710 | 2759 | (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8, |
| ... | ... | @@ -2719,63 +2768,20 @@ pub const Object = struct { |
| 2719 | 2768 | |
| 2720 | 2769 | return debug_tagged_union_type; |
| 2721 | 2770 | }, |
| 2722 | | .Fn => { |
| 2723 | | const fn_info = zcu.typeToFunc(ty).?; |
| 2724 | | |
| 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 | | } |
| 2771 | else => unreachable, // Handled above. |
| 2772 | } |
| 2773 | } |
| 2762 | 2774 | |
| 2763 | | const debug_function_type = try o.builder.debugSubroutineType( |
| 2764 | | try o.builder.debugTuple(debug_param_types.items), |
| 2765 | | ); |
| 2775 | fn genNamespaces(o: *Object) !void { |
| 2776 | var i: usize = 0; |
| 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]; |
| 2766 | 2780 | |
| 2767 | | try o.debug_type_map.put(gpa, ty, debug_function_type); |
| 2768 | | return debug_function_type; |
| 2769 | | }, |
| 2770 | | .ComptimeInt => unreachable, |
| 2771 | | .ComptimeFloat => unreachable, |
| 2772 | | .Type => unreachable, |
| 2773 | | .Undefined => unreachable, |
| 2774 | | .Null => unreachable, |
| 2775 | | .EnumLiteral => unreachable, |
| 2781 | const namespace = o.pt.zcu.namespacePtr(namespace_index); |
| 2782 | const debug_type = try o.lowerDebugType(namespace.getType(o.pt.zcu)); |
| 2776 | 2783 | |
| 2777 | | .Frame => @panic("TODO implement lowerDebugType for Frame types"), |
| 2778 | | .AnyFrame => @panic("TODO implement lowerDebugType for AnyFrame types"), |
| 2784 | o.builder.debugForwardReferenceSetType(fwd_ref, debug_type); |
| 2779 | 2785 | } |
| 2780 | 2786 | } |
| 2781 | 2787 | |
| ... | ... | @@ -4718,17 +4724,37 @@ pub const DeclGen = struct { |
| 4718 | 4724 | if (!owner_mod.strip) { |
| 4719 | 4725 | const debug_file = try o.getDebugFile(file_scope); |
| 4720 | 4726 | |
| 4721 | | const debug_global_var = try o.builder.debugGlobalVar( |
| 4722 | | try o.builder.metadataString(decl.name.toSlice(ip)), // Name |
| 4723 | | try o.builder.metadataStringFromStrtabString(variable_index.name(&o.builder)), // Linkage name |
| 4724 | | debug_file, // File |
| 4725 | | debug_file, // Scope |
| 4727 | const linkage_name = try o.builder.metadataStringFromStrtabString(variable_index.name(&o.builder)); |
| 4728 | |
| 4729 | const debug_global_var = if (!decl.isExtern(zcu)) blk: { |
| 4730 | // Imitate a C++ static member variable since neither |
| 4731 | // 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 | 4752 | line_number, |
| 4727 | 4753 | try o.lowerDebugType(decl.typeOf(zcu)), |
| 4728 | 4754 | variable_index, |
| 4729 | | .{ .local = !decl.isExtern(zcu) }, |
| 4755 | .none, |
| 4756 | .external, |
| 4730 | 4757 | ); |
| 4731 | | |
| 4732 | 4758 | const debug_expression = try o.builder.debugExpression(&.{}); |
| 4733 | 4759 | |
| 4734 | 4760 | const debug_global_var_expression = try o.builder.debugGlobalVarExpression( |
| ... | ... | @@ -5178,6 +5204,7 @@ pub const FuncGen = struct { |
| 5178 | 5204 | |
| 5179 | 5205 | self.scope = try o.builder.debugSubprogram( |
| 5180 | 5206 | self.file, |
| 5207 | self.file, // TODO Get the correct scope into here—self.scope is the function's *inner* scope. |
| 5181 | 5208 | try o.builder.metadataString(decl.name.toSlice(&zcu.intern_pool)), |
| 5182 | 5209 | try o.builder.metadataString(decl.fqn.toSlice(&zcu.intern_pool)), |
| 5183 | 5210 | line_number, |