| ... | @@ -8,6 +8,7 @@ mods: std.AutoArrayHashMapUnmanaged(*Module, ModInfo), | ... | @@ -8,6 +8,7 @@ mods: std.AutoArrayHashMapUnmanaged(*Module, ModInfo), |
| 8 | types: std.AutoArrayHashMapUnmanaged(InternPool.Index, Entry.Index), | 8 | types: std.AutoArrayHashMapUnmanaged(InternPool.Index, Entry.Index), |
| 9 | values: std.AutoArrayHashMapUnmanaged(InternPool.Index, Entry.Index), | 9 | values: std.AutoArrayHashMapUnmanaged(InternPool.Index, Entry.Index), |
| 10 | navs: std.AutoArrayHashMapUnmanaged(InternPool.Nav.Index, Entry.Index), | 10 | navs: std.AutoArrayHashMapUnmanaged(InternPool.Nav.Index, Entry.Index), |
| | 11 | decls: std.AutoArrayHashMapUnmanaged(InternPool.TrackedInst.Index, Entry.Index), |
| 11 | | 12 | |
| 12 | debug_abbrev: DebugAbbrev, | 13 | debug_abbrev: DebugAbbrev, |
| 13 | debug_aranges: DebugAranges, | 14 | debug_aranges: DebugAranges, |
| ... | @@ -51,9 +52,7 @@ pub const AddressSize = enum(u8) { | ... | @@ -51,9 +52,7 @@ pub const AddressSize = enum(u8) { |
| 51 | const ModInfo = struct { | 52 | const ModInfo = struct { |
| 52 | root_dir_path: Entry.Index, | 53 | root_dir_path: Entry.Index, |
| 53 | dirs: std.AutoArrayHashMapUnmanaged(Unit.Index, void), | 54 | dirs: std.AutoArrayHashMapUnmanaged(Unit.Index, void), |
| 54 | files: Files, | 55 | files: std.AutoArrayHashMapUnmanaged(Zcu.File.Index, void), |
| 55 | | | |
| 56 | const Files = std.AutoArrayHashMapUnmanaged(Zcu.File.Index, void); | | |
| 57 | | 56 | |
| 58 | fn deinit(mod_info: *ModInfo, gpa: std.mem.Allocator) void { | 57 | fn deinit(mod_info: *ModInfo, gpa: std.mem.Allocator) void { |
| 59 | mod_info.dirs.deinit(gpa); | 58 | mod_info.dirs.deinit(gpa); |
| ... | @@ -137,6 +136,20 @@ const DebugInfo = struct { | ... | @@ -137,6 +136,20 @@ const DebugInfo = struct { |
| 137 | return AbbrevCode.decl_bytes + dwarf.sectionOffsetBytes(); | 136 | return AbbrevCode.decl_bytes + dwarf.sectionOffsetBytes(); |
| 138 | } | 137 | } |
| 139 | | 138 | |
| | 139 | fn declAbbrevCode(debug_info: *DebugInfo, unit: Unit.Index, entry: Entry.Index) !AbbrevCode { |
| | 140 | const dwarf: *Dwarf = @fieldParentPtr("debug_info", debug_info); |
| | 141 | const unit_ptr = debug_info.section.getUnit(unit); |
| | 142 | const entry_ptr = unit_ptr.getEntry(entry); |
| | 143 | if (entry_ptr.len < AbbrevCode.decl_bytes) return .null; |
| | 144 | var abbrev_code_buf: [AbbrevCode.decl_bytes]u8 = undefined; |
| | 145 | if (try dwarf.getFile().?.preadAll( |
| | 146 | &abbrev_code_buf, |
| | 147 | debug_info.section.off(dwarf) + unit_ptr.off + unit_ptr.header_len + entry_ptr.off, |
| | 148 | ) != abbrev_code_buf.len) return error.InputOutput; |
| | 149 | var abbrev_code_fbs = std.io.fixedBufferStream(&abbrev_code_buf); |
| | 150 | return @enumFromInt(std.leb.readUleb128(@typeInfo(AbbrevCode).@"enum".tag_type, abbrev_code_fbs.reader()) catch unreachable); |
| | 151 | } |
| | 152 | |
| 140 | const trailer_bytes = 1 + 1; | 153 | const trailer_bytes = 1 + 1; |
| 141 | }; | 154 | }; |
| 142 | | 155 | |
| ... | @@ -206,8 +219,8 @@ const StringSection = struct { | ... | @@ -206,8 +219,8 @@ const StringSection = struct { |
| 206 | const unit: Unit.Index = @enumFromInt(0); | 219 | const unit: Unit.Index = @enumFromInt(0); |
| 207 | | 220 | |
| 208 | const init: StringSection = .{ | 221 | const init: StringSection = .{ |
| 209 | .contents = .{}, | 222 | .contents = .empty, |
| 210 | .map = .{}, | 223 | .map = .empty, |
| 211 | .section = Section.init, | 224 | .section = Section.init, |
| 212 | }; | 225 | }; |
| 213 | | 226 | |
| ... | @@ -219,9 +232,9 @@ const StringSection = struct { | ... | @@ -219,9 +232,9 @@ const StringSection = struct { |
| 219 | | 232 | |
| 220 | fn addString(str_sec: *StringSection, dwarf: *Dwarf, str: []const u8) UpdateError!Entry.Index { | 233 | fn addString(str_sec: *StringSection, dwarf: *Dwarf, str: []const u8) UpdateError!Entry.Index { |
| 221 | const gop = try str_sec.map.getOrPutAdapted(dwarf.gpa, str, Adapter{ .str_sec = str_sec }); | 234 | const gop = try str_sec.map.getOrPutAdapted(dwarf.gpa, str, Adapter{ .str_sec = str_sec }); |
| 222 | errdefer _ = str_sec.map.pop(); | | |
| 223 | const entry: Entry.Index = @enumFromInt(gop.index); | 235 | const entry: Entry.Index = @enumFromInt(gop.index); |
| 224 | if (!gop.found_existing) { | 236 | if (!gop.found_existing) { |
| | 237 | errdefer _ = str_sec.map.pop(); |
| 225 | const unit_ptr = str_sec.section.getUnit(unit); | 238 | const unit_ptr = str_sec.section.getUnit(unit); |
| 226 | assert(try str_sec.section.getUnit(unit).addEntry(dwarf.gpa) == entry); | 239 | assert(try str_sec.section.getUnit(unit).addEntry(dwarf.gpa) == entry); |
| 227 | errdefer _ = unit_ptr.entries.pop(); | 240 | errdefer _ = unit_ptr.entries.pop(); |
| ... | @@ -284,7 +297,7 @@ pub const Section = struct { | ... | @@ -284,7 +297,7 @@ pub const Section = struct { |
| 284 | .index = std.math.maxInt(u32), | 297 | .index = std.math.maxInt(u32), |
| 285 | .first = .none, | 298 | .first = .none, |
| 286 | .last = .none, | 299 | .last = .none, |
| 287 | .units = .{}, | 300 | .units = .empty, |
| 288 | .len = 0, | 301 | .len = 0, |
| 289 | }; | 302 | }; |
| 290 | | 303 | |
| ... | @@ -319,13 +332,14 @@ pub const Section = struct { | ... | @@ -319,13 +332,14 @@ pub const Section = struct { |
| 319 | .next = .none, | 332 | .next = .none, |
| 320 | .first = .none, | 333 | .first = .none, |
| 321 | .last = .none, | 334 | .last = .none, |
| | 335 | .free = .none, |
| 322 | .header_len = aligned_header_len, | 336 | .header_len = aligned_header_len, |
| 323 | .trailer_len = aligned_trailer_len, | 337 | .trailer_len = aligned_trailer_len, |
| 324 | .off = 0, | 338 | .off = 0, |
| 325 | .len = aligned_header_len + aligned_trailer_len, | 339 | .len = aligned_header_len + aligned_trailer_len, |
| 326 | .entries = .{}, | 340 | .entries = .empty, |
| 327 | .cross_unit_relocs = .{}, | 341 | .cross_unit_relocs = .empty, |
| 328 | .cross_section_relocs = .{}, | 342 | .cross_section_relocs = .empty, |
| 329 | }; | 343 | }; |
| 330 | if (sec.last.unwrap()) |last_unit| { | 344 | if (sec.last.unwrap()) |last_unit| { |
| 331 | const last_unit_ptr = sec.getUnit(last_unit); | 345 | const last_unit_ptr = sec.getUnit(last_unit); |
| ... | @@ -385,6 +399,28 @@ pub const Section = struct { | ... | @@ -385,6 +399,28 @@ pub const Section = struct { |
| 385 | try unit_ptr.getEntry(entry).replace(unit_ptr, sec, dwarf, contents); | 399 | try unit_ptr.getEntry(entry).replace(unit_ptr, sec, dwarf, contents); |
| 386 | } | 400 | } |
| 387 | | 401 | |
| | 402 | fn freeEntry(sec: *Section, unit: Unit.Index, entry: Entry.Index, dwarf: *Dwarf) UpdateError!void { |
| | 403 | const unit_ptr = sec.getUnit(unit); |
| | 404 | const entry_ptr = unit_ptr.getEntry(entry); |
| | 405 | if (entry_ptr.len > 0) { |
| | 406 | if (entry_ptr.next.unwrap()) |next_entry| unit_ptr.getEntry(next_entry).prev = entry_ptr.prev; |
| | 407 | if (entry_ptr.prev.unwrap()) |prev_entry| { |
| | 408 | const prev_entry_ptr = unit_ptr.getEntry(prev_entry); |
| | 409 | prev_entry_ptr.next = entry_ptr.next; |
| | 410 | try prev_entry_ptr.pad(unit_ptr, sec, dwarf); |
| | 411 | } else { |
| | 412 | unit_ptr.trim(); |
| | 413 | sec.trim(dwarf); |
| | 414 | } |
| | 415 | } else assert(entry_ptr.prev == .none and entry_ptr.next == .none); |
| | 416 | entry_ptr.prev = .none; |
| | 417 | entry_ptr.next = unit_ptr.free; |
| | 418 | entry_ptr.off = 0; |
| | 419 | entry_ptr.len = 0; |
| | 420 | entry_ptr.clear(); |
| | 421 | unit_ptr.free = entry.toOptional(); |
| | 422 | } |
| | 423 | |
| 388 | fn resize(sec: *Section, dwarf: *Dwarf, len: u64) UpdateError!void { | 424 | fn resize(sec: *Section, dwarf: *Dwarf, len: u64) UpdateError!void { |
| 389 | if (len <= sec.len) return; | 425 | if (len <= sec.len) return; |
| 390 | if (dwarf.bin_file.cast(.elf)) |elf_file| { | 426 | if (dwarf.bin_file.cast(.elf)) |elf_file| { |
| ... | @@ -449,6 +485,7 @@ const Unit = struct { | ... | @@ -449,6 +485,7 @@ const Unit = struct { |
| 449 | next: Index.Optional, | 485 | next: Index.Optional, |
| 450 | first: Entry.Index.Optional, | 486 | first: Entry.Index.Optional, |
| 451 | last: Entry.Index.Optional, | 487 | last: Entry.Index.Optional, |
| | 488 | free: Entry.Index.Optional, |
| 452 | /// offset within containing section | 489 | /// offset within containing section |
| 453 | off: u32, | 490 | off: u32, |
| 454 | header_len: u32, | 491 | header_len: u32, |
| ... | @@ -491,6 +528,12 @@ const Unit = struct { | ... | @@ -491,6 +528,12 @@ const Unit = struct { |
| 491 | } | 528 | } |
| 492 | | 529 | |
| 493 | fn addEntry(unit: *Unit, gpa: std.mem.Allocator) std.mem.Allocator.Error!Entry.Index { | 530 | fn addEntry(unit: *Unit, gpa: std.mem.Allocator) std.mem.Allocator.Error!Entry.Index { |
| | 531 | if (unit.free.unwrap()) |entry| { |
| | 532 | const entry_ptr = unit.getEntry(entry); |
| | 533 | unit.free = entry_ptr.next; |
| | 534 | entry_ptr.next = .none; |
| | 535 | return entry; |
| | 536 | } |
| 494 | const entry: Entry.Index = @enumFromInt(unit.entries.items.len); | 537 | const entry: Entry.Index = @enumFromInt(unit.entries.items.len); |
| 495 | const entry_ptr = try unit.entries.addOne(gpa); | 538 | const entry_ptr = try unit.entries.addOne(gpa); |
| 496 | entry_ptr.* = .{ | 539 | entry_ptr.* = .{ |
| ... | @@ -498,10 +541,10 @@ const Unit = struct { | ... | @@ -498,10 +541,10 @@ const Unit = struct { |
| 498 | .next = .none, | 541 | .next = .none, |
| 499 | .off = 0, | 542 | .off = 0, |
| 500 | .len = 0, | 543 | .len = 0, |
| 501 | .cross_entry_relocs = .{}, | 544 | .cross_entry_relocs = .empty, |
| 502 | .cross_unit_relocs = .{}, | 545 | .cross_unit_relocs = .empty, |
| 503 | .cross_section_relocs = .{}, | 546 | .cross_section_relocs = .empty, |
| 504 | .external_relocs = .{}, | 547 | .external_relocs = .empty, |
| 505 | }; | 548 | }; |
| 506 | return entry; | 549 | return entry; |
| 507 | } | 550 | } |
| ... | @@ -1583,7 +1626,7 @@ pub const WipNav = struct { | ... | @@ -1583,7 +1626,7 @@ pub const WipNav = struct { |
| 1583 | const dlw = wip_nav.debug_line.writer(dwarf.gpa); | 1626 | const dlw = wip_nav.debug_line.writer(dwarf.gpa); |
| 1584 | if (dwarf.incremental()) { | 1627 | if (dwarf.incremental()) { |
| 1585 | const new_nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, new_func_info.owner_nav); | 1628 | const new_nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, new_func_info.owner_nav); |
| 1586 | errdefer _ = dwarf.navs.pop(); | 1629 | errdefer _ = if (!new_nav_gop.found_existing) dwarf.navs.pop(); |
| 1587 | if (!new_nav_gop.found_existing) new_nav_gop.value_ptr.* = try dwarf.addCommonEntry(new_unit); | 1630 | if (!new_nav_gop.found_existing) new_nav_gop.value_ptr.* = try dwarf.addCommonEntry(new_unit); |
| 1588 | | 1631 | |
| 1589 | try dlw.writeByte(DW.LNS.extended_op); | 1632 | try dlw.writeByte(DW.LNS.extended_op); |
| ... | @@ -1603,10 +1646,8 @@ pub const WipNav = struct { | ... | @@ -1603,10 +1646,8 @@ pub const WipNav = struct { |
| 1603 | const old_file = zcu.navFileScopeIndex(old_func_info.owner_nav); | 1646 | const old_file = zcu.navFileScopeIndex(old_func_info.owner_nav); |
| 1604 | if (old_file != new_file) { | 1647 | if (old_file != new_file) { |
| 1605 | const mod_info = dwarf.getModInfo(wip_nav.unit); | 1648 | const mod_info = dwarf.getModInfo(wip_nav.unit); |
| 1606 | const mod_gop = try mod_info.dirs.getOrPut(dwarf.gpa, new_unit); | 1649 | try mod_info.dirs.put(dwarf.gpa, new_unit, {}); |
| 1607 | errdefer _ = if (!mod_gop.found_existing) mod_info.dirs.pop(); | | |
| 1608 | const file_gop = try mod_info.files.getOrPut(dwarf.gpa, new_file); | 1650 | const file_gop = try mod_info.files.getOrPut(dwarf.gpa, new_file); |
| 1609 | errdefer _ = if (!file_gop.found_existing) mod_info.files.pop(); | | |
| 1610 | | 1651 | |
| 1611 | try dlw.writeByte(DW.LNS.set_file); | 1652 | try dlw.writeByte(DW.LNS.set_file); |
| 1612 | try uleb128(dlw, file_gop.index); | 1653 | try uleb128(dlw, file_gop.index); |
| ... | @@ -1934,6 +1975,90 @@ pub const WipNav = struct { | ... | @@ -1934,6 +1975,90 @@ pub const WipNav = struct { |
| 1934 | std.math.big.int.Mutable.init(&big_int_space.limbs, field_index).toConst()); | 1975 | std.math.big.int.Mutable.init(&big_int_space.limbs, field_index).toConst()); |
| 1935 | } | 1976 | } |
| 1936 | | 1977 | |
| | 1978 | fn declCommon( |
| | 1979 | wip_nav: *WipNav, |
| | 1980 | abbrev_code: struct { |
| | 1981 | decl: AbbrevCode, |
| | 1982 | generic_decl: AbbrevCode, |
| | 1983 | instance: AbbrevCode, |
| | 1984 | }, |
| | 1985 | nav: *const InternPool.Nav, |
| | 1986 | file: Zcu.File.Index, |
| | 1987 | decl: *const std.zig.Zir.Inst.Declaration.Unwrapped, |
| | 1988 | ) UpdateError!void { |
| | 1989 | const zcu = wip_nav.pt.zcu; |
| | 1990 | const ip = &zcu.intern_pool; |
| | 1991 | const dwarf = wip_nav.dwarf; |
| | 1992 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| | 1993 | |
| | 1994 | const orig_entry = wip_nav.entry; |
| | 1995 | defer wip_nav.entry = orig_entry; |
| | 1996 | const parent_type, const is_generic_decl = if (nav.analysis) |analysis| parent_info: { |
| | 1997 | const parent_type: Type = .fromInterned(zcu.namespacePtr(analysis.namespace).owner_type); |
| | 1998 | const decl_gop = try dwarf.decls.getOrPut(dwarf.gpa, analysis.zir_index); |
| | 1999 | errdefer _ = if (!decl_gop.found_existing) dwarf.decls.pop(); |
| | 2000 | const was_generic_decl = decl_gop.found_existing and |
| | 2001 | switch (try dwarf.debug_info.declAbbrevCode(wip_nav.unit, decl_gop.value_ptr.*)) { |
| | 2002 | else => unreachable, |
| | 2003 | .decl_alias, |
| | 2004 | .decl_enum, |
| | 2005 | .decl_empty_enum, |
| | 2006 | .decl_namespace_struct, |
| | 2007 | .decl_struct, |
| | 2008 | .decl_packed_struct, |
| | 2009 | .decl_union, |
| | 2010 | .decl_var, |
| | 2011 | .decl_const, |
| | 2012 | .decl_const_runtime_bits, |
| | 2013 | .decl_const_comptime_state, |
| | 2014 | .decl_const_runtime_bits_comptime_state, |
| | 2015 | .decl_func, |
| | 2016 | .decl_empty_func, |
| | 2017 | .decl_func_generic, |
| | 2018 | .decl_empty_func_generic, |
| | 2019 | => false, |
| | 2020 | .generic_decl_alias, |
| | 2021 | .generic_decl_enum, |
| | 2022 | .generic_decl_struct, |
| | 2023 | .generic_decl_union, |
| | 2024 | .generic_decl_var, |
| | 2025 | .generic_decl_const, |
| | 2026 | .generic_decl_func, |
| | 2027 | => true, |
| | 2028 | }; |
| | 2029 | if (parent_type.getCaptures(zcu).len == 0) { |
| | 2030 | if (was_generic_decl) try dwarf.freeCommonEntry(wip_nav.unit, decl_gop.value_ptr.*); |
| | 2031 | decl_gop.value_ptr.* = orig_entry; |
| | 2032 | break :parent_info .{ parent_type, false }; |
| | 2033 | } else { |
| | 2034 | if (was_generic_decl) |
| | 2035 | dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(decl_gop.value_ptr.*).clear() |
| | 2036 | else |
| | 2037 | decl_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit); |
| | 2038 | wip_nav.entry = decl_gop.value_ptr.*; |
| | 2039 | break :parent_info .{ parent_type, true }; |
| | 2040 | } |
| | 2041 | } else .{ null, false }; |
| | 2042 | |
| | 2043 | try wip_nav.abbrevCode(if (is_generic_decl) abbrev_code.generic_decl else abbrev_code.decl); |
| | 2044 | try wip_nav.refType((if (is_generic_decl) null else parent_type) orelse |
| | 2045 | .fromInterned(zcu.fileRootType(file))); |
| | 2046 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); |
| | 2047 | try diw.writeInt(u32, decl.src_line + 1, dwarf.endian); |
| | 2048 | try uleb128(diw, decl.src_column + 1); |
| | 2049 | try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private); |
| | 2050 | try wip_nav.strp(nav.name.toSlice(ip)); |
| | 2051 | |
| | 2052 | if (!is_generic_decl) return; |
| | 2053 | const generic_decl_entry = wip_nav.entry; |
| | 2054 | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, generic_decl_entry, dwarf, wip_nav.debug_info.items); |
| | 2055 | wip_nav.debug_info.clearRetainingCapacity(); |
| | 2056 | wip_nav.entry = orig_entry; |
| | 2057 | try wip_nav.abbrevCode(abbrev_code.instance); |
| | 2058 | try wip_nav.refType(parent_type.?); |
| | 2059 | try wip_nav.infoSectionOffset(.debug_info, wip_nav.unit, generic_decl_entry, 0); |
| | 2060 | } |
| | 2061 | |
| 1937 | fn updateLazy(wip_nav: *WipNav, src_loc: Zcu.LazySrcLoc) UpdateError!void { | 2062 | fn updateLazy(wip_nav: *WipNav, src_loc: Zcu.LazySrcLoc) UpdateError!void { |
| 1938 | const ip = &wip_nav.pt.zcu.intern_pool; | 2063 | const ip = &wip_nav.pt.zcu.intern_pool; |
| 1939 | while (wip_nav.pending_lazy.popOrNull()) |val| switch (ip.typeOf(val)) { | 2064 | while (wip_nav.pending_lazy.popOrNull()) |val| switch (ip.typeOf(val)) { |
| ... | @@ -1966,10 +2091,11 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf { | ... | @@ -1966,10 +2091,11 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf { |
| 1966 | }, | 2091 | }, |
| 1967 | .endian = target.cpu.arch.endian(), | 2092 | .endian = target.cpu.arch.endian(), |
| 1968 | | 2093 | |
| 1969 | .mods = .{}, | 2094 | .mods = .empty, |
| 1970 | .types = .{}, | 2095 | .types = .empty, |
| 1971 | .values = .{}, | 2096 | .values = .empty, |
| 1972 | .navs = .{}, | 2097 | .navs = .empty, |
| | 2098 | .decls = .empty, |
| 1973 | | 2099 | |
| 1974 | .debug_abbrev = .{ .section = Section.init }, | 2100 | .debug_abbrev = .{ .section = Section.init }, |
| 1975 | .debug_aranges = .{ .section = Section.init }, | 2101 | .debug_aranges = .{ .section = Section.init }, |
| ... | @@ -2142,6 +2268,7 @@ pub fn deinit(dwarf: *Dwarf) void { | ... | @@ -2142,6 +2268,7 @@ pub fn deinit(dwarf: *Dwarf) void { |
| 2142 | dwarf.types.deinit(gpa); | 2268 | dwarf.types.deinit(gpa); |
| 2143 | dwarf.values.deinit(gpa); | 2269 | dwarf.values.deinit(gpa); |
| 2144 | dwarf.navs.deinit(gpa); | 2270 | dwarf.navs.deinit(gpa); |
| | 2271 | dwarf.decls.deinit(gpa); |
| 2145 | dwarf.debug_abbrev.section.deinit(gpa); | 2272 | dwarf.debug_abbrev.section.deinit(gpa); |
| 2146 | dwarf.debug_aranges.section.deinit(gpa); | 2273 | dwarf.debug_aranges.section.deinit(gpa); |
| 2147 | dwarf.debug_frame.section.deinit(gpa); | 2274 | dwarf.debug_frame.section.deinit(gpa); |
| ... | @@ -2161,8 +2288,8 @@ fn getUnit(dwarf: *Dwarf, mod: *Module) UpdateError!Unit.Index { | ... | @@ -2161,8 +2288,8 @@ fn getUnit(dwarf: *Dwarf, mod: *Module) UpdateError!Unit.Index { |
| 2161 | errdefer _ = dwarf.mods.pop(); | 2288 | errdefer _ = dwarf.mods.pop(); |
| 2162 | mod_gop.value_ptr.* = .{ | 2289 | mod_gop.value_ptr.* = .{ |
| 2163 | .root_dir_path = undefined, | 2290 | .root_dir_path = undefined, |
| 2164 | .dirs = .{}, | 2291 | .dirs = .empty, |
| 2165 | .files = .{}, | 2292 | .files = .empty, |
| 2166 | }; | 2293 | }; |
| 2167 | errdefer mod_gop.value_ptr.dirs.deinit(dwarf.gpa); | 2294 | errdefer mod_gop.value_ptr.dirs.deinit(dwarf.gpa); |
| 2168 | try mod_gop.value_ptr.dirs.putNoClobber(dwarf.gpa, unit, {}); | 2295 | try mod_gop.value_ptr.dirs.putNoClobber(dwarf.gpa, unit, {}); |
| ... | @@ -2219,14 +2346,28 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In | ... | @@ -2219,14 +2346,28 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 2219 | const ip = &zcu.intern_pool; | 2346 | const ip = &zcu.intern_pool; |
| 2220 | | 2347 | |
| 2221 | const nav = ip.getNav(nav_index); | 2348 | const nav = ip.getNav(nav_index); |
| 2222 | log.debug("initWipNav({})", .{nav.fqn.fmt(ip)}); | | |
| 2223 | | | |
| 2224 | const inst_info = nav.srcInst(ip).resolveFull(ip).?; | 2349 | const inst_info = nav.srcInst(ip).resolveFull(ip).?; |
| 2225 | const file = zcu.fileByIndex(inst_info.file); | 2350 | const file = zcu.fileByIndex(inst_info.file); |
| | 2351 | assert(file.zir_loaded); |
| | 2352 | const decl = file.zir.getDeclaration(inst_info.inst); |
| | 2353 | log.debug("initWipNav({s}:{d}:{d} %{d} = {})", .{ |
| | 2354 | file.sub_file_path, |
| | 2355 | decl.src_line + 1, |
| | 2356 | decl.src_column + 1, |
| | 2357 | @intFromEnum(inst_info.inst), |
| | 2358 | nav.fqn.fmt(ip), |
| | 2359 | }); |
| | 2360 | |
| | 2361 | const nav_val = zcu.navValue(nav_index); |
| | 2362 | const nav_key = ip.indexToKey(nav_val.toIntern()); |
| | 2363 | switch (nav_key) { |
| | 2364 | .@"extern" => return null, |
| | 2365 | else => {}, |
| | 2366 | } |
| 2226 | | 2367 | |
| 2227 | const unit = try dwarf.getUnit(file.mod); | 2368 | const unit = try dwarf.getUnit(file.mod); |
| 2228 | const nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, nav_index); | 2369 | const nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, nav_index); |
| 2229 | errdefer _ = dwarf.navs.pop(); | 2370 | errdefer _ = if (!nav_gop.found_existing) dwarf.navs.pop(); |
| 2230 | if (nav_gop.found_existing) { | 2371 | if (nav_gop.found_existing) { |
| 2231 | for ([_]*Section{ | 2372 | for ([_]*Section{ |
| 2232 | &dwarf.debug_aranges.section, | 2373 | &dwarf.debug_aranges.section, |
| ... | @@ -2236,7 +2377,6 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In | ... | @@ -2236,7 +2377,6 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 2236 | &dwarf.debug_rnglists.section, | 2377 | &dwarf.debug_rnglists.section, |
| 2237 | }) |sec| sec.getUnit(unit).getEntry(nav_gop.value_ptr.*).clear(); | 2378 | }) |sec| sec.getUnit(unit).getEntry(nav_gop.value_ptr.*).clear(); |
| 2238 | } else nav_gop.value_ptr.* = try dwarf.addCommonEntry(unit); | 2379 | } else nav_gop.value_ptr.* = try dwarf.addCommonEntry(unit); |
| 2239 | const nav_val = zcu.navValue(nav_index); | | |
| 2240 | var wip_nav: WipNav = .{ | 2380 | var wip_nav: WipNav = .{ |
| 2241 | .dwarf = dwarf, | 2381 | .dwarf = dwarf, |
| 2242 | .pt = pt, | 2382 | .pt = pt, |
| ... | @@ -2248,91 +2388,52 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In | ... | @@ -2248,91 +2388,52 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 2248 | .func_high_pc = undefined, | 2388 | .func_high_pc = undefined, |
| 2249 | .blocks = undefined, | 2389 | .blocks = undefined, |
| 2250 | .cfi = undefined, | 2390 | .cfi = undefined, |
| 2251 | .debug_frame = .{}, | 2391 | .debug_frame = .empty, |
| 2252 | .debug_info = .{}, | 2392 | .debug_info = .empty, |
| 2253 | .debug_line = .{}, | 2393 | .debug_line = .empty, |
| 2254 | .debug_loclists = .{}, | 2394 | .debug_loclists = .empty, |
| 2255 | .pending_lazy = .{}, | 2395 | .pending_lazy = .empty, |
| 2256 | }; | 2396 | }; |
| 2257 | errdefer wip_nav.deinit(); | 2397 | errdefer wip_nav.deinit(); |
| 2258 | | 2398 | |
| 2259 | switch (ip.indexToKey(nav_val.toIntern())) { | 2399 | switch (nav_key) { |
| 2260 | else => { | 2400 | else => { |
| 2261 | assert(file.zir_loaded); | | |
| 2262 | const decl = file.zir.getDeclaration(inst_info.inst); | | |
| 2263 | | | |
| 2264 | const parent_type, const accessibility: u8 = if (nav.analysis) |a| parent: { | | |
| 2265 | const parent_namespace_ptr = ip.namespacePtr(a.namespace); | | |
| 2266 | break :parent .{ | | |
| 2267 | parent_namespace_ptr.owner_type, | | |
| 2268 | if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private, | | |
| 2269 | }; | | |
| 2270 | } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private }; | | |
| 2271 | | | |
| 2272 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 2401 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2273 | try wip_nav.abbrevCode(.decl_var); | 2402 | try wip_nav.declCommon(.{ |
| 2274 | try wip_nav.refType(.fromInterned(parent_type)); | 2403 | .decl = .decl_var, |
| 2275 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); | 2404 | .generic_decl = .generic_decl_var, |
| 2276 | try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian); | 2405 | .instance = .instance_var, |
| 2277 | try uleb128(diw, decl.src_column + 1); | 2406 | }, &nav, inst_info.file, &decl); |
| 2278 | try diw.writeByte(accessibility); | | |
| 2279 | try wip_nav.strp(nav.name.toSlice(ip)); | | |
| 2280 | try wip_nav.strp(nav.fqn.toSlice(ip)); | 2407 | try wip_nav.strp(nav.fqn.toSlice(ip)); |
| 2281 | const nav_ty = nav_val.typeOf(zcu); | 2408 | const ty: Type = nav_val.typeOf(zcu); |
| 2282 | const nav_ty_reloc_index = try wip_nav.refForward(); | | |
| 2283 | try wip_nav.infoExprloc(.{ .addr = .{ .sym = sym_index } }); | | |
| 2284 | try uleb128(diw, nav.status.fully_resolved.alignment.toByteUnits() orelse | | |
| 2285 | nav_ty.abiAlignment(zcu).toByteUnits().?); | | |
| 2286 | try diw.writeByte(@intFromBool(false)); | | |
| 2287 | wip_nav.finishForward(nav_ty_reloc_index); | | |
| 2288 | try wip_nav.abbrevCode(.is_const); | | |
| 2289 | try wip_nav.refType(nav_ty); | | |
| 2290 | }, | | |
| 2291 | .variable => |variable| { | | |
| 2292 | assert(file.zir_loaded); | | |
| 2293 | const decl = file.zir.getDeclaration(inst_info.inst); | | |
| 2294 | | | |
| 2295 | const parent_type, const accessibility: u8 = if (nav.analysis) |a| parent: { | | |
| 2296 | const parent_namespace_ptr = ip.namespacePtr(a.namespace); | | |
| 2297 | break :parent .{ | | |
| 2298 | parent_namespace_ptr.owner_type, | | |
| 2299 | if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private, | | |
| 2300 | }; | | |
| 2301 | } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private }; | | |
| 2302 | | | |
| 2303 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | | |
| 2304 | try wip_nav.abbrevCode(.decl_var); | | |
| 2305 | try wip_nav.refType(.fromInterned(parent_type)); | | |
| 2306 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); | | |
| 2307 | try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian); | | |
| 2308 | try uleb128(diw, decl.src_column + 1); | | |
| 2309 | try diw.writeByte(accessibility); | | |
| 2310 | try wip_nav.strp(nav.name.toSlice(ip)); | | |
| 2311 | try wip_nav.strp(nav.fqn.toSlice(ip)); | | |
| 2312 | const ty: Type = .fromInterned(variable.ty); | | |
| 2313 | try wip_nav.refType(ty); | | |
| 2314 | const addr: Loc = .{ .addr = .{ .sym = sym_index } }; | 2409 | const addr: Loc = .{ .addr = .{ .sym = sym_index } }; |
| 2315 | try wip_nav.infoExprloc(if (variable.is_threadlocal) .{ .form_tls_address = &addr } else addr); | 2410 | const loc: Loc = if (decl.is_threadlocal) .{ .form_tls_address = &addr } else addr; |
| 2316 | try uleb128(diw, nav.status.fully_resolved.alignment.toByteUnits() orelse | 2411 | switch (decl.kind) { |
| 2317 | ty.abiAlignment(zcu).toByteUnits().?); | 2412 | .unnamed_test, .@"test", .decltest, .@"comptime", .@"usingnamespace" => unreachable, |
| 2318 | try diw.writeByte(@intFromBool(false)); | 2413 | .@"const" => { |
| | 2414 | const const_ty_reloc_index = try wip_nav.refForward(); |
| | 2415 | try wip_nav.infoExprloc(loc); |
| | 2416 | try uleb128(diw, nav.status.fully_resolved.alignment.toByteUnits() orelse |
| | 2417 | ty.abiAlignment(zcu).toByteUnits().?); |
| | 2418 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); |
| | 2419 | wip_nav.finishForward(const_ty_reloc_index); |
| | 2420 | try wip_nav.abbrevCode(.is_const); |
| | 2421 | try wip_nav.refType(ty); |
| | 2422 | }, |
| | 2423 | .@"var" => { |
| | 2424 | try wip_nav.refType(ty); |
| | 2425 | try wip_nav.infoExprloc(loc); |
| | 2426 | try uleb128(diw, nav.status.fully_resolved.alignment.toByteUnits() orelse |
| | 2427 | ty.abiAlignment(zcu).toByteUnits().?); |
| | 2428 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); |
| | 2429 | }, |
| | 2430 | } |
| 2319 | }, | 2431 | }, |
| 2320 | .func => |func| { | 2432 | .func => |func| { |
| 2321 | assert(file.zir_loaded); | | |
| 2322 | const decl = file.zir.getDeclaration(inst_info.inst); | | |
| 2323 | | | |
| 2324 | const parent_type, const accessibility: u8 = if (nav.analysis) |a| parent: { | | |
| 2325 | const parent_namespace_ptr = ip.namespacePtr(a.namespace); | | |
| 2326 | break :parent .{ | | |
| 2327 | parent_namespace_ptr.owner_type, | | |
| 2328 | if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private, | | |
| 2329 | }; | | |
| 2330 | } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private }; | | |
| 2331 | | | |
| 2332 | const func_type = ip.indexToKey(func.ty).func_type; | 2433 | const func_type = ip.indexToKey(func.ty).func_type; |
| 2333 | wip_nav.func = nav_val.toIntern(); | 2434 | wip_nav.func = nav_val.toIntern(); |
| 2334 | wip_nav.func_sym_index = sym_index; | 2435 | wip_nav.func_sym_index = sym_index; |
| 2335 | wip_nav.blocks = .{}; | 2436 | wip_nav.blocks = .empty; |
| 2336 | if (dwarf.debug_frame.header.format != .none) wip_nav.cfi = .{ | 2437 | if (dwarf.debug_frame.header.format != .none) wip_nav.cfi = .{ |
| 2337 | .loc = 0, | 2438 | .loc = 0, |
| 2338 | .cfa = dwarf.debug_frame.header.initial_instructions[0].def_cfa, | 2439 | .cfa = dwarf.debug_frame.header.initial_instructions[0].def_cfa, |
| ... | @@ -2375,13 +2476,11 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In | ... | @@ -2375,13 +2476,11 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 2375 | } | 2476 | } |
| 2376 | | 2477 | |
| 2377 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 2478 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2378 | try wip_nav.abbrevCode(.decl_func); | 2479 | try wip_nav.declCommon(.{ |
| 2379 | try wip_nav.refType(.fromInterned(parent_type)); | 2480 | .decl = .decl_func, |
| 2380 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); | 2481 | .generic_decl = .generic_decl_func, |
| 2381 | try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian); | 2482 | .instance = .instance_func, |
| 2382 | try uleb128(diw, decl.src_column + 1); | 2483 | }, &nav, inst_info.file, &decl); |
| 2383 | try diw.writeByte(accessibility); | | |
| 2384 | try wip_nav.strp(nav.name.toSlice(ip)); | | |
| 2385 | try wip_nav.strp(nav.fqn.toSlice(ip)); | 2484 | try wip_nav.strp(nav.fqn.toSlice(ip)); |
| 2386 | try wip_nav.refType(.fromInterned(func_type.return_type)); | 2485 | try wip_nav.refType(.fromInterned(func_type.return_type)); |
| 2387 | try wip_nav.infoAddrSym(sym_index, 0); | 2486 | try wip_nav.infoAddrSym(sym_index, 0); |
| ... | @@ -2392,7 +2491,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In | ... | @@ -2392,7 +2491,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 2392 | .none => target_info.defaultFunctionAlignment(target), | 2491 | .none => target_info.defaultFunctionAlignment(target), |
| 2393 | else => |a| a.maxStrict(target_info.minFunctionAlignment(target)), | 2492 | else => |a| a.maxStrict(target_info.minFunctionAlignment(target)), |
| 2394 | }.toByteUnits().?); | 2493 | }.toByteUnits().?); |
| 2395 | try diw.writeByte(@intFromBool(false)); | 2494 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); |
| 2396 | try diw.writeByte(@intFromBool(func_type.return_type == .noreturn_type)); | 2495 | try diw.writeByte(@intFromBool(func_type.return_type == .noreturn_type)); |
| 2397 | | 2496 | |
| 2398 | const dlw = wip_nav.debug_line.writer(dwarf.gpa); | 2497 | const dlw = wip_nav.debug_line.writer(dwarf.gpa); |
| ... | @@ -2435,97 +2534,110 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In | ... | @@ -2435,97 +2534,110 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 2435 | return wip_nav; | 2534 | return wip_nav; |
| 2436 | } | 2535 | } |
| 2437 | | 2536 | |
| 2438 | pub fn finishWipNav( | 2537 | pub fn finishWipNavFunc( |
| 2439 | dwarf: *Dwarf, | 2538 | dwarf: *Dwarf, |
| 2440 | pt: Zcu.PerThread, | 2539 | pt: Zcu.PerThread, |
| 2441 | nav_index: InternPool.Nav.Index, | 2540 | nav_index: InternPool.Nav.Index, |
| 2442 | sym: struct { index: u32, addr: u64, size: u64 }, | 2541 | code_size: u64, |
| 2443 | wip_nav: *WipNav, | 2542 | wip_nav: *WipNav, |
| 2444 | ) UpdateError!void { | 2543 | ) UpdateError!void { |
| 2445 | const zcu = pt.zcu; | 2544 | const zcu = pt.zcu; |
| 2446 | const ip = &zcu.intern_pool; | 2545 | const ip = &zcu.intern_pool; |
| 2447 | const nav = ip.getNav(nav_index); | 2546 | const nav = ip.getNav(nav_index); |
| 2448 | log.debug("finishWipNav({})", .{nav.fqn.fmt(ip)}); | 2547 | assert(wip_nav.func != .none); |
| | 2548 | log.debug("finishWipNavFunc({})", .{nav.fqn.fmt(ip)}); |
| 2449 | | 2549 | |
| 2450 | if (wip_nav.func != .none) { | 2550 | { |
| 2451 | { | 2551 | const external_relocs = &dwarf.debug_aranges.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs; |
| 2452 | const external_relocs = &dwarf.debug_aranges.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs; | 2552 | try external_relocs.append(dwarf.gpa, .{ .target_sym = wip_nav.func_sym_index }); |
| 2453 | try external_relocs.append(dwarf.gpa, .{ .target_sym = sym.index }); | 2553 | var entry: [8 + 8]u8 = undefined; |
| 2454 | var entry: [8 + 8]u8 = undefined; | 2554 | @memset(entry[0..@intFromEnum(dwarf.address_size)], 0); |
| 2455 | @memset(entry[0..@intFromEnum(dwarf.address_size)], 0); | 2555 | dwarf.writeInt(entry[@intFromEnum(dwarf.address_size)..][0..@intFromEnum(dwarf.address_size)], code_size); |
| 2456 | dwarf.writeInt(entry[@intFromEnum(dwarf.address_size)..][0..@intFromEnum(dwarf.address_size)], sym.size); | 2556 | try dwarf.debug_aranges.section.replaceEntry( |
| 2457 | try dwarf.debug_aranges.section.replaceEntry( | 2557 | wip_nav.unit, |
| 2458 | wip_nav.unit, | 2558 | wip_nav.entry, |
| 2459 | wip_nav.entry, | 2559 | dwarf, |
| 2460 | dwarf, | 2560 | entry[0 .. @intFromEnum(dwarf.address_size) * 2], |
| 2461 | entry[0 .. @intFromEnum(dwarf.address_size) * 2], | 2561 | ); |
| 2462 | ); | 2562 | } |
| 2463 | } | 2563 | switch (dwarf.debug_frame.header.format) { |
| 2464 | switch (dwarf.debug_frame.header.format) { | 2564 | .none => {}, |
| 2465 | .none => {}, | 2565 | .debug_frame, .eh_frame => |format| { |
| 2466 | .debug_frame, .eh_frame => |format| { | 2566 | try wip_nav.debug_frame.appendNTimes( |
| 2467 | try wip_nav.debug_frame.appendNTimes( | 2567 | dwarf.gpa, |
| 2468 | dwarf.gpa, | 2568 | DW.CFA.nop, |
| 2469 | DW.CFA.nop, | 2569 | @intCast(dwarf.debug_frame.section.alignment.forward(wip_nav.debug_frame.items.len) - wip_nav.debug_frame.items.len), |
| 2470 | @intCast(dwarf.debug_frame.section.alignment.forward(wip_nav.debug_frame.items.len) - wip_nav.debug_frame.items.len), | | |
| 2471 | ); | | |
| 2472 | const contents = wip_nav.debug_frame.items; | | |
| 2473 | try dwarf.debug_frame.section.resizeEntry(wip_nav.unit, wip_nav.entry, dwarf, @intCast(contents.len)); | | |
| 2474 | const unit = dwarf.debug_frame.section.getUnit(wip_nav.unit); | | |
| 2475 | const entry = unit.getEntry(wip_nav.entry); | | |
| 2476 | const unit_len = (if (entry.next.unwrap()) |next_entry| | | |
| 2477 | unit.getEntry(next_entry).off - entry.off | | |
| 2478 | else | | |
| 2479 | entry.len) - dwarf.unitLengthBytes(); | | |
| 2480 | dwarf.writeInt(contents[dwarf.unitLengthBytes() - dwarf.sectionOffsetBytes() ..][0..dwarf.sectionOffsetBytes()], unit_len); | | |
| 2481 | switch (format) { | | |
| 2482 | .none => unreachable, | | |
| 2483 | .debug_frame => dwarf.writeInt(contents[dwarf.unitLengthBytes() + dwarf.sectionOffsetBytes() + | | |
| 2484 | @intFromEnum(dwarf.address_size) ..][0..@intFromEnum(dwarf.address_size)], sym.size), | | |
| 2485 | .eh_frame => { | | |
| 2486 | std.mem.writeInt( | | |
| 2487 | u32, | | |
| 2488 | contents[dwarf.unitLengthBytes()..][0..4], | | |
| 2489 | unit.header_len + entry.off + dwarf.unitLengthBytes(), | | |
| 2490 | dwarf.endian, | | |
| 2491 | ); | | |
| 2492 | std.mem.writeInt(u32, contents[dwarf.unitLengthBytes() + 4 + 4 ..][0..4], @intCast(sym.size), dwarf.endian); | | |
| 2493 | }, | | |
| 2494 | } | | |
| 2495 | try entry.replace(unit, &dwarf.debug_frame.section, dwarf, contents); | | |
| 2496 | }, | | |
| 2497 | } | | |
| 2498 | { | | |
| 2499 | std.mem.writeInt(u32, wip_nav.debug_info.items[wip_nav.func_high_pc..][0..4], @intCast(sym.size), dwarf.endian); | | |
| 2500 | if (wip_nav.any_children) { | | |
| 2501 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | | |
| 2502 | try uleb128(diw, @intFromEnum(AbbrevCode.null)); | | |
| 2503 | } else std.leb.writeUnsignedFixed( | | |
| 2504 | AbbrevCode.decl_bytes, | | |
| 2505 | wip_nav.debug_info.items[0..AbbrevCode.decl_bytes], | | |
| 2506 | try dwarf.refAbbrevCode(.decl_empty_func), | | |
| 2507 | ); | 2570 | ); |
| 2508 | } | 2571 | const contents = wip_nav.debug_frame.items; |
| 2509 | { | 2572 | try dwarf.debug_frame.section.resizeEntry(wip_nav.unit, wip_nav.entry, dwarf, @intCast(contents.len)); |
| 2510 | try dwarf.debug_rnglists.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs.appendSlice(dwarf.gpa, &.{ | 2573 | const unit = dwarf.debug_frame.section.getUnit(wip_nav.unit); |
| 2511 | .{ | 2574 | const entry = unit.getEntry(wip_nav.entry); |
| 2512 | .source_off = 1, | 2575 | const unit_len = (if (entry.next.unwrap()) |next_entry| |
| 2513 | .target_sym = sym.index, | 2576 | unit.getEntry(next_entry).off - entry.off |
| 2514 | }, | 2577 | else |
| 2515 | .{ | 2578 | entry.len) - dwarf.unitLengthBytes(); |
| 2516 | .source_off = 1 + @intFromEnum(dwarf.address_size), | 2579 | dwarf.writeInt(contents[dwarf.unitLengthBytes() - dwarf.sectionOffsetBytes() ..][0..dwarf.sectionOffsetBytes()], unit_len); |
| 2517 | .target_sym = sym.index, | 2580 | switch (format) { |
| 2518 | .target_off = sym.size, | 2581 | .none => unreachable, |
| | 2582 | .debug_frame => dwarf.writeInt(contents[dwarf.unitLengthBytes() + dwarf.sectionOffsetBytes() + |
| | 2583 | @intFromEnum(dwarf.address_size) ..][0..@intFromEnum(dwarf.address_size)], code_size), |
| | 2584 | .eh_frame => { |
| | 2585 | std.mem.writeInt( |
| | 2586 | u32, |
| | 2587 | contents[dwarf.unitLengthBytes()..][0..4], |
| | 2588 | unit.header_len + entry.off + dwarf.unitLengthBytes(), |
| | 2589 | dwarf.endian, |
| | 2590 | ); |
| | 2591 | std.mem.writeInt(u32, contents[dwarf.unitLengthBytes() + 4 + 4 ..][0..4], @intCast(code_size), dwarf.endian); |
| 2519 | }, | 2592 | }, |
| 2520 | }); | 2593 | } |
| 2521 | try dwarf.debug_rnglists.section.replaceEntry( | 2594 | try entry.replace(unit, &dwarf.debug_frame.section, dwarf, contents); |
| 2522 | wip_nav.unit, | 2595 | }, |
| 2523 | wip_nav.entry, | 2596 | } |
| 2524 | dwarf, | 2597 | { |
| 2525 | ([1]u8{DW.RLE.start_end} ++ [1]u8{0} ** (8 + 8))[0 .. 1 + @intFromEnum(dwarf.address_size) + @intFromEnum(dwarf.address_size)], | 2598 | std.mem.writeInt(u32, wip_nav.debug_info.items[wip_nav.func_high_pc..][0..4], @intCast(code_size), dwarf.endian); |
| 2526 | ); | 2599 | if (wip_nav.any_children) { |
| 2527 | } | 2600 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| | 2601 | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| | 2602 | } else std.leb.writeUnsignedFixed( |
| | 2603 | AbbrevCode.decl_bytes, |
| | 2604 | wip_nav.debug_info.items[0..AbbrevCode.decl_bytes], |
| | 2605 | try dwarf.refAbbrevCode(.decl_empty_func), |
| | 2606 | ); |
| 2528 | } | 2607 | } |
| | 2608 | { |
| | 2609 | try dwarf.debug_rnglists.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs.appendSlice(dwarf.gpa, &.{ |
| | 2610 | .{ |
| | 2611 | .source_off = 1, |
| | 2612 | .target_sym = wip_nav.func_sym_index, |
| | 2613 | }, |
| | 2614 | .{ |
| | 2615 | .source_off = 1 + @intFromEnum(dwarf.address_size), |
| | 2616 | .target_sym = wip_nav.func_sym_index, |
| | 2617 | .target_off = code_size, |
| | 2618 | }, |
| | 2619 | }); |
| | 2620 | try dwarf.debug_rnglists.section.replaceEntry( |
| | 2621 | wip_nav.unit, |
| | 2622 | wip_nav.entry, |
| | 2623 | dwarf, |
| | 2624 | ([1]u8{DW.RLE.start_end} ++ [1]u8{0} ** (8 + 8))[0 .. 1 + @intFromEnum(dwarf.address_size) + @intFromEnum(dwarf.address_size)], |
| | 2625 | ); |
| | 2626 | } |
| | 2627 | |
| | 2628 | try dwarf.finishWipNav(pt, nav_index, wip_nav); |
| | 2629 | } |
| | 2630 | |
| | 2631 | pub fn finishWipNav( |
| | 2632 | dwarf: *Dwarf, |
| | 2633 | pt: Zcu.PerThread, |
| | 2634 | nav_index: InternPool.Nav.Index, |
| | 2635 | wip_nav: *WipNav, |
| | 2636 | ) UpdateError!void { |
| | 2637 | const zcu = pt.zcu; |
| | 2638 | const ip = &zcu.intern_pool; |
| | 2639 | const nav = ip.getNav(nav_index); |
| | 2640 | log.debug("finishWipNav({})", .{nav.fqn.fmt(ip)}); |
| 2529 | | 2641 | |
| 2530 | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items); | 2642 | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items); |
| 2531 | if (wip_nav.debug_line.items.len > 0) { | 2643 | if (wip_nav.debug_line.items.len > 0) { |
| ... | @@ -2547,12 +2659,17 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool | ... | @@ -2547,12 +2659,17 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2547 | const nav_val = zcu.navValue(nav_index); | 2659 | const nav_val = zcu.navValue(nav_index); |
| 2548 | | 2660 | |
| 2549 | const nav = ip.getNav(nav_index); | 2661 | const nav = ip.getNav(nav_index); |
| 2550 | log.debug("updateComptimeNav({})", .{nav.fqn.fmt(ip)}); | | |
| 2551 | | | |
| 2552 | const inst_info = nav.srcInst(ip).resolveFull(ip).?; | 2662 | const inst_info = nav.srcInst(ip).resolveFull(ip).?; |
| 2553 | const file = zcu.fileByIndex(inst_info.file); | 2663 | const file = zcu.fileByIndex(inst_info.file); |
| 2554 | assert(file.zir_loaded); | 2664 | assert(file.zir_loaded); |
| 2555 | const decl = file.zir.getDeclaration(inst_info.inst); | 2665 | const decl = file.zir.getDeclaration(inst_info.inst); |
| | 2666 | log.debug("updateComptimeNav({s}:{d}:{d} %{d} = {})", .{ |
| | 2667 | file.sub_file_path, |
| | 2668 | decl.src_line + 1, |
| | 2669 | decl.src_column + 1, |
| | 2670 | @intFromEnum(inst_info.inst), |
| | 2671 | nav.fqn.fmt(ip), |
| | 2672 | }); |
| 2556 | | 2673 | |
| 2557 | const is_test = switch (decl.kind) { | 2674 | const is_test = switch (decl.kind) { |
| 2558 | .unnamed_test, .@"test", .decltest => true, | 2675 | .unnamed_test, .@"test", .decltest => true, |
| ... | @@ -2563,14 +2680,6 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool | ... | @@ -2563,14 +2680,6 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2563 | return; | 2680 | return; |
| 2564 | } | 2681 | } |
| 2565 | | 2682 | |
| 2566 | const parent_type, const accessibility: u8 = if (nav.analysis) |a| parent: { | | |
| 2567 | const parent_namespace_ptr = ip.namespacePtr(a.namespace); | | |
| 2568 | break :parent .{ | | |
| 2569 | parent_namespace_ptr.owner_type, | | |
| 2570 | if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private, | | |
| 2571 | }; | | |
| 2572 | } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private }; | | |
| 2573 | | | |
| 2574 | var wip_nav: WipNav = .{ | 2683 | var wip_nav: WipNav = .{ |
| 2575 | .dwarf = dwarf, | 2684 | .dwarf = dwarf, |
| 2576 | .pt = pt, | 2685 | .pt = pt, |
| ... | @@ -2582,16 +2691,16 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool | ... | @@ -2582,16 +2691,16 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2582 | .func_high_pc = undefined, | 2691 | .func_high_pc = undefined, |
| 2583 | .blocks = undefined, | 2692 | .blocks = undefined, |
| 2584 | .cfi = undefined, | 2693 | .cfi = undefined, |
| 2585 | .debug_frame = .{}, | 2694 | .debug_frame = .empty, |
| 2586 | .debug_info = .{}, | 2695 | .debug_info = .empty, |
| 2587 | .debug_line = .{}, | 2696 | .debug_line = .empty, |
| 2588 | .debug_loclists = .{}, | 2697 | .debug_loclists = .empty, |
| 2589 | .pending_lazy = .{}, | 2698 | .pending_lazy = .empty, |
| 2590 | }; | 2699 | }; |
| 2591 | defer wip_nav.deinit(); | 2700 | defer wip_nav.deinit(); |
| 2592 | | 2701 | |
| 2593 | const nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, nav_index); | 2702 | const nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, nav_index); |
| 2594 | errdefer _ = dwarf.navs.pop(); | 2703 | errdefer _ = if (!nav_gop.found_existing) dwarf.navs.pop(); |
| 2595 | | 2704 | |
| 2596 | const tag: enum { done, decl_alias, decl_var, decl_const } = switch (ip.indexToKey(nav_val.toIntern())) { | 2705 | const tag: enum { done, decl_alias, decl_var, decl_const } = switch (ip.indexToKey(nav_val.toIntern())) { |
| 2597 | .int_type, | 2706 | .int_type, |
| ... | @@ -2609,9 +2718,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool | ... | @@ -2609,9 +2718,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2609 | => .decl_alias, | 2718 | => .decl_alias, |
| 2610 | .struct_type => tag: { | 2719 | .struct_type => tag: { |
| 2611 | const loaded_struct = ip.loadStructType(nav_val.toIntern()); | 2720 | const loaded_struct = ip.loadStructType(nav_val.toIntern()); |
| 2612 | | 2721 | if (loaded_struct.zir_index.resolveFile(ip) != inst_info.file) break :tag .decl_alias; |
| 2613 | const type_inst_info = loaded_struct.zir_index.resolveFull(ip).?; | | |
| 2614 | if (type_inst_info.file != inst_info.file) break :tag .decl_alias; | | |
| 2615 | | 2722 | |
| 2616 | const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern()); | 2723 | const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern()); |
| 2617 | if (type_gop.found_existing) { | 2724 | if (type_gop.found_existing) { |
| ... | @@ -2630,13 +2737,15 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool | ... | @@ -2630,13 +2737,15 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2630 | | 2737 | |
| 2631 | switch (loaded_struct.layout) { | 2738 | switch (loaded_struct.layout) { |
| 2632 | .auto, .@"extern" => { | 2739 | .auto, .@"extern" => { |
| 2633 | try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .decl_namespace_struct else .decl_struct); | 2740 | try wip_nav.declCommon(if (loaded_struct.field_types.len == 0) .{ |
| 2634 | try wip_nav.refType(.fromInterned(parent_type)); | 2741 | .decl = .decl_namespace_struct, |
| 2635 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); | 2742 | .generic_decl = .generic_decl_struct, |
| 2636 | try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian); | 2743 | .instance = .instance_namespace_struct, |
| 2637 | try uleb128(diw, decl.src_column + 1); | 2744 | } else .{ |
| 2638 | try diw.writeByte(accessibility); | 2745 | .decl = .decl_struct, |
| 2639 | try wip_nav.strp(nav.name.toSlice(ip)); | 2746 | .generic_decl = .generic_decl_struct, |
| | 2747 | .instance = .instance_struct, |
| | 2748 | }, &nav, inst_info.file, &decl); |
| 2640 | if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else { | 2749 | if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else { |
| 2641 | try uleb128(diw, nav_val.toType().abiSize(zcu)); | 2750 | try uleb128(diw, nav_val.toType().abiSize(zcu)); |
| 2642 | try uleb128(diw, nav_val.toType().abiAlignment(zcu).toByteUnits().?); | 2751 | try uleb128(diw, nav_val.toType().abiAlignment(zcu).toByteUnits().?); |
| ... | @@ -2688,13 +2797,11 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool | ... | @@ -2688,13 +2797,11 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2688 | } | 2797 | } |
| 2689 | }, | 2798 | }, |
| 2690 | .@"packed" => { | 2799 | .@"packed" => { |
| 2691 | try wip_nav.abbrevCode(.decl_packed_struct); | 2800 | try wip_nav.declCommon(.{ |
| 2692 | try wip_nav.refType(.fromInterned(parent_type)); | 2801 | .decl = .decl_packed_struct, |
| 2693 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); | 2802 | .generic_decl = .generic_decl_struct, |
| 2694 | try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian); | 2803 | .instance = .instance_packed_struct, |
| 2695 | try uleb128(diw, decl.src_column + 1); | 2804 | }, &nav, inst_info.file, &decl); |
| 2696 | try diw.writeByte(accessibility); | | |
| 2697 | try wip_nav.strp(nav.name.toSlice(ip)); | | |
| 2698 | try wip_nav.refType(.fromInterned(loaded_struct.backingIntTypeUnordered(ip))); | 2805 | try wip_nav.refType(.fromInterned(loaded_struct.backingIntTypeUnordered(ip))); |
| 2699 | var field_bit_offset: u16 = 0; | 2806 | var field_bit_offset: u16 = 0; |
| 2700 | for (0..loaded_struct.field_types.len) |field_index| { | 2807 | for (0..loaded_struct.field_types.len) |field_index| { |
| ... | @@ -2712,10 +2819,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool | ... | @@ -2712,10 +2819,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2712 | }, | 2819 | }, |
| 2713 | .enum_type => tag: { | 2820 | .enum_type => tag: { |
| 2714 | const loaded_enum = ip.loadEnumType(nav_val.toIntern()); | 2821 | const loaded_enum = ip.loadEnumType(nav_val.toIntern()); |
| 2715 | if (loaded_enum.zir_index == .none) break :tag .decl_alias; | 2822 | const type_zir_index = loaded_enum.zir_index.unwrap() orelse break :tag .decl_alias; |
| 2716 | | 2823 | if (type_zir_index.resolveFile(ip) != inst_info.file) break :tag .decl_alias; |
| 2717 | const type_inst_info = loaded_enum.zir_index.unwrap().?.resolveFull(ip).?; | | |
| 2718 | if (type_inst_info.file != inst_info.file) break :tag .decl_alias; | | |
| 2719 | | 2824 | |
| 2720 | const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern()); | 2825 | const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern()); |
| 2721 | if (type_gop.found_existing) { | 2826 | if (type_gop.found_existing) { |
| ... | @@ -2730,13 +2835,15 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool | ... | @@ -2730,13 +2835,15 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2730 | } | 2835 | } |
| 2731 | wip_nav.entry = nav_gop.value_ptr.*; | 2836 | wip_nav.entry = nav_gop.value_ptr.*; |
| 2732 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 2837 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2733 | try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .decl_enum else .decl_empty_enum); | 2838 | try wip_nav.declCommon(if (loaded_enum.names.len > 0) .{ |
| 2734 | try wip_nav.refType(.fromInterned(parent_type)); | 2839 | .decl = .decl_enum, |
| 2735 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); | 2840 | .generic_decl = .generic_decl_enum, |
| 2736 | try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian); | 2841 | .instance = .instance_enum, |
| 2737 | try uleb128(diw, decl.src_column + 1); | 2842 | } else .{ |
| 2738 | try diw.writeByte(accessibility); | 2843 | .decl = .decl_empty_enum, |
| 2739 | try wip_nav.strp(nav.name.toSlice(ip)); | 2844 | .generic_decl = .generic_decl_enum, |
| | 2845 | .instance = .instance_empty_enum, |
| | 2846 | }, &nav, inst_info.file, &decl); |
| 2740 | try wip_nav.refType(.fromInterned(loaded_enum.tag_ty)); | 2847 | try wip_nav.refType(.fromInterned(loaded_enum.tag_ty)); |
| 2741 | for (0..loaded_enum.names.len) |field_index| { | 2848 | for (0..loaded_enum.names.len) |field_index| { |
| 2742 | try wip_nav.enumConstValue(loaded_enum, .{ | 2849 | try wip_nav.enumConstValue(loaded_enum, .{ |
| ... | @@ -2751,9 +2858,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool | ... | @@ -2751,9 +2858,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2751 | }, | 2858 | }, |
| 2752 | .union_type => tag: { | 2859 | .union_type => tag: { |
| 2753 | const loaded_union = ip.loadUnionType(nav_val.toIntern()); | 2860 | const loaded_union = ip.loadUnionType(nav_val.toIntern()); |
| 2754 | | 2861 | if (loaded_union.zir_index.resolveFile(ip) != inst_info.file) break :tag .decl_alias; |
| 2755 | const type_inst_info = loaded_union.zir_index.resolveFull(ip).?; | | |
| 2756 | if (type_inst_info.file != inst_info.file) break :tag .decl_alias; | | |
| 2757 | | 2862 | |
| 2758 | const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern()); | 2863 | const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern()); |
| 2759 | if (type_gop.found_existing) { | 2864 | if (type_gop.found_existing) { |
| ... | @@ -2768,13 +2873,11 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool | ... | @@ -2768,13 +2873,11 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2768 | } | 2873 | } |
| 2769 | wip_nav.entry = nav_gop.value_ptr.*; | 2874 | wip_nav.entry = nav_gop.value_ptr.*; |
| 2770 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 2875 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2771 | try wip_nav.abbrevCode(.decl_union); | 2876 | try wip_nav.declCommon(.{ |
| 2772 | try wip_nav.refType(.fromInterned(parent_type)); | 2877 | .decl = .decl_union, |
| 2773 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); | 2878 | .generic_decl = .generic_decl_union, |
| 2774 | try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian); | 2879 | .instance = .instance_union, |
| 2775 | try uleb128(diw, decl.src_column + 1); | 2880 | }, &nav, inst_info.file, &decl); |
| 2776 | try diw.writeByte(accessibility); | | |
| 2777 | try wip_nav.strp(nav.name.toSlice(ip)); | | |
| 2778 | const union_layout = Type.getUnionLayout(loaded_union, zcu); | 2881 | const union_layout = Type.getUnionLayout(loaded_union, zcu); |
| 2779 | try uleb128(diw, union_layout.abi_size); | 2882 | try uleb128(diw, union_layout.abi_size); |
| 2780 | try uleb128(diw, union_layout.abi_align.toByteUnits().?); | 2883 | try uleb128(diw, union_layout.abi_align.toByteUnits().?); |
| ... | @@ -2825,9 +2928,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool | ... | @@ -2825,9 +2928,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2825 | }, | 2928 | }, |
| 2826 | .opaque_type => tag: { | 2929 | .opaque_type => tag: { |
| 2827 | const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern()); | 2930 | const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern()); |
| 2828 | | 2931 | if (loaded_opaque.zir_index.resolveFile(ip) != inst_info.file) break :tag .decl_alias; |
| 2829 | const type_inst_info = loaded_opaque.zir_index.resolveFull(ip).?; | | |
| 2830 | if (type_inst_info.file != inst_info.file) break :tag .decl_alias; | | |
| 2831 | | 2932 | |
| 2832 | const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern()); | 2933 | const type_gop = try dwarf.types.getOrPut(dwarf.gpa, nav_val.toIntern()); |
| 2833 | if (type_gop.found_existing) { | 2934 | if (type_gop.found_existing) { |
| ... | @@ -2842,19 +2943,16 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool | ... | @@ -2842,19 +2943,16 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2842 | } | 2943 | } |
| 2843 | wip_nav.entry = nav_gop.value_ptr.*; | 2944 | wip_nav.entry = nav_gop.value_ptr.*; |
| 2844 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 2945 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2845 | try wip_nav.abbrevCode(.decl_namespace_struct); | 2946 | try wip_nav.declCommon(.{ |
| 2846 | try wip_nav.refType(.fromInterned(parent_type)); | 2947 | .decl = .decl_namespace_struct, |
| 2847 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); | 2948 | .generic_decl = .generic_decl_struct, |
| 2848 | try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian); | 2949 | .instance = .instance_namespace_struct, |
| 2849 | try uleb128(diw, decl.src_column + 1); | 2950 | }, &nav, inst_info.file, &decl); |
| 2850 | try diw.writeByte(accessibility); | 2951 | try diw.writeByte(@intFromBool(true)); |
| 2851 | try wip_nav.strp(nav.name.toSlice(ip)); | | |
| 2852 | try diw.writeByte(@intFromBool(false)); | | |
| 2853 | break :tag .done; | 2952 | break :tag .done; |
| 2854 | }, | 2953 | }, |
| 2855 | .undef, | 2954 | .undef, |
| 2856 | .simple_value, | 2955 | .simple_value, |
| 2857 | .@"extern", | | |
| 2858 | .int, | 2956 | .int, |
| 2859 | .err, | 2957 | .err, |
| 2860 | .error_union, | 2958 | .error_union, |
| ... | @@ -2869,42 +2967,31 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool | ... | @@ -2869,42 +2967,31 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2869 | .un, | 2967 | .un, |
| 2870 | => .decl_const, | 2968 | => .decl_const, |
| 2871 | .variable => .decl_var, | 2969 | .variable => .decl_var, |
| | 2970 | .@"extern" => unreachable, |
| 2872 | .func => |func| tag: { | 2971 | .func => |func| tag: { |
| 2873 | if (nav_gop.found_existing) { | 2972 | if (nav_gop.found_existing) switch (try dwarf.debug_info.declAbbrevCode(wip_nav.unit, nav_gop.value_ptr.*)) { |
| 2874 | const unit_ptr = dwarf.debug_info.section.getUnit(wip_nav.unit); | 2973 | .null => {}, |
| 2875 | const entry_ptr = unit_ptr.getEntry(nav_gop.value_ptr.*); | 2974 | else => unreachable, |
| 2876 | if (entry_ptr.len >= AbbrevCode.decl_bytes) { | 2975 | .decl_func, .decl_empty_func, .instance_func, .instance_empty_func => return, |
| 2877 | var abbrev_code_buf: [AbbrevCode.decl_bytes]u8 = undefined; | 2976 | .decl_func_generic, |
| 2878 | if (try dwarf.getFile().?.preadAll( | 2977 | .decl_empty_func_generic, |
| 2879 | &abbrev_code_buf, | 2978 | .instance_func_generic, |
| 2880 | dwarf.debug_info.section.off(dwarf) + unit_ptr.off + unit_ptr.header_len + entry_ptr.off, | 2979 | .instance_empty_func_generic, |
| 2881 | ) != abbrev_code_buf.len) return error.InputOutput; | 2980 | => dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(nav_gop.value_ptr.*).clear(), |
| 2882 | var abbrev_code_fbs = std.io.fixedBufferStream(&abbrev_code_buf); | | |
| 2883 | const abbrev_code: AbbrevCode = @enumFromInt( | | |
| 2884 | std.leb.readUleb128(@typeInfo(AbbrevCode).@"enum".tag_type, abbrev_code_fbs.reader()) catch unreachable, | | |
| 2885 | ); | | |
| 2886 | switch (abbrev_code) { | | |
| 2887 | else => unreachable, | | |
| 2888 | .decl_func, .decl_empty_func => return, | | |
| 2889 | .decl_func_generic, .decl_empty_func_generic => {}, | | |
| 2890 | } | | |
| 2891 | } | | |
| 2892 | entry_ptr.clear(); | | |
| 2893 | } else nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit); | 2981 | } else nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit); |
| 2894 | wip_nav.entry = nav_gop.value_ptr.*; | 2982 | wip_nav.entry = nav_gop.value_ptr.*; |
| 2895 | | 2983 | |
| 2896 | const func_type = ip.indexToKey(func.ty).func_type; | 2984 | const func_type = ip.indexToKey(func.ty).func_type; |
| 2897 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 2985 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2898 | try wip_nav.abbrevCode(if (func_type.param_types.len > 0 or func_type.is_var_args) | 2986 | try wip_nav.declCommon(if (func_type.param_types.len > 0 or func_type.is_var_args) .{ |
| 2899 | .decl_func_generic | 2987 | .decl = .decl_func_generic, |
| 2900 | else | 2988 | .generic_decl = .generic_decl_func, |
| 2901 | .decl_empty_func_generic); | 2989 | .instance = .instance_func_generic, |
| 2902 | try wip_nav.refType(.fromInterned(parent_type)); | 2990 | } else .{ |
| 2903 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); | 2991 | .decl = .decl_empty_func_generic, |
| 2904 | try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian); | 2992 | .generic_decl = .generic_decl_func, |
| 2905 | try uleb128(diw, decl.src_column + 1); | 2993 | .instance = .instance_empty_func_generic, |
| 2906 | try diw.writeByte(accessibility); | 2994 | }, &nav, inst_info.file, &decl); |
| 2907 | try wip_nav.strp(nav.name.toSlice(ip)); | | |
| 2908 | try wip_nav.refType(.fromInterned(func_type.return_type)); | 2995 | try wip_nav.refType(.fromInterned(func_type.return_type)); |
| 2909 | if (func_type.param_types.len > 0 or func_type.is_var_args) { | 2996 | if (func_type.param_types.len > 0 or func_type.is_var_args) { |
| 2910 | for (0..func_type.param_types.len) |param_index| { | 2997 | for (0..func_type.param_types.len) |param_index| { |
| ... | @@ -2929,57 +3016,55 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool | ... | @@ -2929,57 +3016,55 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2929 | switch (tag) { | 3016 | switch (tag) { |
| 2930 | .done => {}, | 3017 | .done => {}, |
| 2931 | .decl_alias => { | 3018 | .decl_alias => { |
| 2932 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 3019 | try wip_nav.declCommon(.{ |
| 2933 | try wip_nav.abbrevCode(.decl_alias); | 3020 | .decl = .decl_alias, |
| 2934 | try wip_nav.refType(.fromInterned(parent_type)); | 3021 | .generic_decl = .generic_decl_alias, |
| 2935 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); | 3022 | .instance = .instance_alias, |
| 2936 | try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian); | 3023 | }, &nav, inst_info.file, &decl); |
| 2937 | try uleb128(diw, decl.src_column + 1); | | |
| 2938 | try diw.writeByte(accessibility); | | |
| 2939 | try wip_nav.strp(nav.name.toSlice(ip)); | | |
| 2940 | try wip_nav.refType(nav_val.toType()); | 3024 | try wip_nav.refType(nav_val.toType()); |
| 2941 | }, | 3025 | }, |
| 2942 | .decl_var => { | 3026 | .decl_var => { |
| 2943 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 3027 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2944 | try wip_nav.abbrevCode(.decl_var); | 3028 | try wip_nav.declCommon(.{ |
| 2945 | try wip_nav.refType(.fromInterned(parent_type)); | 3029 | .decl = .decl_var, |
| 2946 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); | 3030 | .generic_decl = .generic_decl_var, |
| 2947 | try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian); | 3031 | .instance = .instance_var, |
| 2948 | try uleb128(diw, decl.src_column + 1); | 3032 | }, &nav, inst_info.file, &decl); |
| 2949 | try diw.writeByte(accessibility); | | |
| 2950 | try wip_nav.strp(nav.name.toSlice(ip)); | | |
| 2951 | try wip_nav.strp(nav.fqn.toSlice(ip)); | 3033 | try wip_nav.strp(nav.fqn.toSlice(ip)); |
| 2952 | const nav_ty = nav_val.typeOf(zcu); | 3034 | const nav_ty = nav_val.typeOf(zcu); |
| 2953 | try wip_nav.refType(nav_ty); | 3035 | try wip_nav.refType(nav_ty); |
| 2954 | try wip_nav.blockValue(nav_src_loc, nav_val); | 3036 | try wip_nav.blockValue(nav_src_loc, nav_val); |
| 2955 | try uleb128(diw, nav.status.fully_resolved.alignment.toByteUnits() orelse | 3037 | try uleb128(diw, nav.status.fully_resolved.alignment.toByteUnits() orelse |
| 2956 | nav_ty.abiAlignment(zcu).toByteUnits().?); | 3038 | nav_ty.abiAlignment(zcu).toByteUnits().?); |
| 2957 | try diw.writeByte(@intFromBool(false)); | 3039 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); |
| 2958 | }, | 3040 | }, |
| 2959 | .decl_const => { | 3041 | .decl_const => { |
| 2960 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 3042 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2961 | const nav_ty = nav_val.typeOf(zcu); | 3043 | const nav_ty = nav_val.typeOf(zcu); |
| 2962 | const has_runtime_bits = nav_ty.hasRuntimeBits(zcu); | 3044 | const has_runtime_bits = nav_ty.hasRuntimeBits(zcu); |
| 2963 | const has_comptime_state = nav_ty.comptimeOnly(zcu) and try nav_ty.onePossibleValue(pt) == null; | 3045 | const has_comptime_state = nav_ty.comptimeOnly(zcu) and try nav_ty.onePossibleValue(pt) == null; |
| 2964 | try wip_nav.abbrevCode(if (has_runtime_bits and has_comptime_state) | 3046 | try wip_nav.declCommon(if (has_runtime_bits and has_comptime_state) .{ |
| 2965 | .decl_const_runtime_bits_comptime_state | 3047 | .decl = .decl_const_runtime_bits_comptime_state, |
| 2966 | else if (has_comptime_state) | 3048 | .generic_decl = .generic_decl_const, |
| 2967 | .decl_const_comptime_state | 3049 | .instance = .instance_const_runtime_bits_comptime_state, |
| 2968 | else if (has_runtime_bits) | 3050 | } else if (has_comptime_state) .{ |
| 2969 | .decl_const_runtime_bits | 3051 | .decl = .decl_const_comptime_state, |
| 2970 | else | 3052 | .generic_decl = .generic_decl_const, |
| 2971 | .decl_const); | 3053 | .instance = .instance_const_comptime_state, |
| 2972 | try wip_nav.refType(.fromInterned(parent_type)); | 3054 | } else if (has_runtime_bits) .{ |
| 2973 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); | 3055 | .decl = .decl_const_runtime_bits, |
| 2974 | try diw.writeInt(u32, @intCast(decl.src_line + 1), dwarf.endian); | 3056 | .generic_decl = .generic_decl_const, |
| 2975 | try uleb128(diw, decl.src_column + 1); | 3057 | .instance = .instance_const_runtime_bits, |
| 2976 | try diw.writeByte(accessibility); | 3058 | } else .{ |
| 2977 | try wip_nav.strp(nav.name.toSlice(ip)); | 3059 | .decl = .decl_const, |
| | 3060 | .generic_decl = .generic_decl_const, |
| | 3061 | .instance = .instance_const, |
| | 3062 | }, &nav, inst_info.file, &decl); |
| 2978 | try wip_nav.strp(nav.fqn.toSlice(ip)); | 3063 | try wip_nav.strp(nav.fqn.toSlice(ip)); |
| 2979 | const nav_ty_reloc_index = try wip_nav.refForward(); | 3064 | const nav_ty_reloc_index = try wip_nav.refForward(); |
| 2980 | try uleb128(diw, nav.status.fully_resolved.alignment.toByteUnits() orelse | 3065 | try uleb128(diw, nav.status.fully_resolved.alignment.toByteUnits() orelse |
| 2981 | nav_ty.abiAlignment(zcu).toByteUnits().?); | 3066 | nav_ty.abiAlignment(zcu).toByteUnits().?); |
| 2982 | try diw.writeByte(@intFromBool(false)); | 3067 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); |
| 2983 | if (has_runtime_bits) try wip_nav.blockValue(nav_src_loc, nav_val); | 3068 | if (has_runtime_bits) try wip_nav.blockValue(nav_src_loc, nav_val); |
| 2984 | if (has_comptime_state) try wip_nav.refValue(nav_val); | 3069 | if (has_comptime_state) try wip_nav.refValue(nav_val); |
| 2985 | wip_nav.finishForward(nav_ty_reloc_index); | 3070 | wip_nav.finishForward(nav_ty_reloc_index); |
| ... | @@ -3017,15 +3102,15 @@ fn updateLazyType( | ... | @@ -3017,15 +3102,15 @@ fn updateLazyType( |
| 3017 | .func_high_pc = undefined, | 3102 | .func_high_pc = undefined, |
| 3018 | .blocks = undefined, | 3103 | .blocks = undefined, |
| 3019 | .cfi = undefined, | 3104 | .cfi = undefined, |
| 3020 | .debug_frame = .{}, | 3105 | .debug_frame = .empty, |
| 3021 | .debug_info = .{}, | 3106 | .debug_info = .empty, |
| 3022 | .debug_line = .{}, | 3107 | .debug_line = .empty, |
| 3023 | .debug_loclists = .{}, | 3108 | .debug_loclists = .empty, |
| 3024 | .pending_lazy = pending_lazy.*, | 3109 | .pending_lazy = pending_lazy.*, |
| 3025 | }; | 3110 | }; |
| 3026 | defer { | 3111 | defer { |
| 3027 | pending_lazy.* = wip_nav.pending_lazy; | 3112 | pending_lazy.* = wip_nav.pending_lazy; |
| 3028 | wip_nav.pending_lazy = .{}; | 3113 | wip_nav.pending_lazy = .empty; |
| 3029 | wip_nav.deinit(); | 3114 | wip_nav.deinit(); |
| 3030 | } | 3115 | } |
| 3031 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 3116 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| ... | @@ -3076,7 +3161,7 @@ fn updateLazyType( | ... | @@ -3076,7 +3161,7 @@ fn updateLazyType( |
| 3076 | } | 3161 | } |
| 3077 | }, | 3162 | }, |
| 3078 | .Slice => { | 3163 | .Slice => { |
| 3079 | try wip_nav.abbrevCode(.struct_type); | 3164 | try wip_nav.abbrevCode(.generated_struct_type); |
| 3080 | try wip_nav.strp(name); | 3165 | try wip_nav.strp(name); |
| 3081 | try uleb128(diw, ty.abiSize(zcu)); | 3166 | try uleb128(diw, ty.abiSize(zcu)); |
| 3082 | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); | 3167 | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); |
| ... | @@ -3115,7 +3200,7 @@ fn updateLazyType( | ... | @@ -3115,7 +3200,7 @@ fn updateLazyType( |
| 3115 | }, | 3200 | }, |
| 3116 | .opt_type => |opt_child_type_index| { | 3201 | .opt_type => |opt_child_type_index| { |
| 3117 | const opt_child_type: Type = .fromInterned(opt_child_type_index); | 3202 | const opt_child_type: Type = .fromInterned(opt_child_type_index); |
| 3118 | try wip_nav.abbrevCode(.union_type); | 3203 | try wip_nav.abbrevCode(.generated_union_type); |
| 3119 | try wip_nav.strp(name); | 3204 | try wip_nav.strp(name); |
| 3120 | try uleb128(diw, ty.abiSize(zcu)); | 3205 | try uleb128(diw, ty.abiSize(zcu)); |
| 3121 | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); | 3206 | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); |
| ... | @@ -3199,7 +3284,7 @@ fn updateLazyType( | ... | @@ -3199,7 +3284,7 @@ fn updateLazyType( |
| 3199 | }, | 3284 | }, |
| 3200 | }; | 3285 | }; |
| 3201 | | 3286 | |
| 3202 | try wip_nav.abbrevCode(.union_type); | 3287 | try wip_nav.abbrevCode(.generated_union_type); |
| 3203 | try wip_nav.strp(name); | 3288 | try wip_nav.strp(name); |
| 3204 | if (error_union_type.error_set_type != .generic_poison_type and | 3289 | if (error_union_type.error_set_type != .generic_poison_type and |
| 3205 | error_union_type.payload_type != .generic_poison_type) | 3290 | error_union_type.payload_type != .generic_poison_type) |
| ... | @@ -3308,11 +3393,11 @@ fn updateLazyType( | ... | @@ -3308,11 +3393,11 @@ fn updateLazyType( |
| 3308 | .opaque_type, | 3393 | .opaque_type, |
| 3309 | => unreachable, | 3394 | => unreachable, |
| 3310 | .tuple_type => |tuple_type| if (tuple_type.types.len == 0) { | 3395 | .tuple_type => |tuple_type| if (tuple_type.types.len == 0) { |
| 3311 | try wip_nav.abbrevCode(.namespace_struct_type); | 3396 | try wip_nav.abbrevCode(.generated_empty_struct_type); |
| 3312 | try wip_nav.strp(name); | 3397 | try wip_nav.strp(name); |
| 3313 | try diw.writeByte(@intFromBool(false)); | 3398 | try diw.writeByte(@intFromBool(false)); |
| 3314 | } else { | 3399 | } else { |
| 3315 | try wip_nav.abbrevCode(.struct_type); | 3400 | try wip_nav.abbrevCode(.generated_struct_type); |
| 3316 | try wip_nav.strp(name); | 3401 | try wip_nav.strp(name); |
| 3317 | try uleb128(diw, ty.abiSize(zcu)); | 3402 | try uleb128(diw, ty.abiSize(zcu)); |
| 3318 | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); | 3403 | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); |
| ... | @@ -3357,7 +3442,7 @@ fn updateLazyType( | ... | @@ -3357,7 +3442,7 @@ fn updateLazyType( |
| 3357 | }, | 3442 | }, |
| 3358 | .enum_type => { | 3443 | .enum_type => { |
| 3359 | const loaded_enum = ip.loadEnumType(type_index); | 3444 | const loaded_enum = ip.loadEnumType(type_index); |
| 3360 | try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .enum_type else .empty_enum_type); | 3445 | try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .generated_enum_type else .generated_empty_enum_type); |
| 3361 | try wip_nav.strp(name); | 3446 | try wip_nav.strp(name); |
| 3362 | try wip_nav.refType(.fromInterned(loaded_enum.tag_ty)); | 3447 | try wip_nav.refType(.fromInterned(loaded_enum.tag_ty)); |
| 3363 | for (0..loaded_enum.names.len) |field_index| { | 3448 | for (0..loaded_enum.names.len) |field_index| { |
| ... | @@ -3449,7 +3534,7 @@ fn updateLazyType( | ... | @@ -3449,7 +3534,7 @@ fn updateLazyType( |
| 3449 | if (!is_nullary) try uleb128(diw, @intFromEnum(AbbrevCode.null)); | 3534 | if (!is_nullary) try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3450 | }, | 3535 | }, |
| 3451 | .error_set_type => |error_set_type| { | 3536 | .error_set_type => |error_set_type| { |
| 3452 | try wip_nav.abbrevCode(if (error_set_type.names.len > 0) .enum_type else .empty_enum_type); | 3537 | try wip_nav.abbrevCode(if (error_set_type.names.len > 0) .generated_enum_type else .generated_empty_enum_type); |
| 3453 | try wip_nav.strp(name); | 3538 | try wip_nav.strp(name); |
| 3454 | try wip_nav.refType(.fromInterned(try pt.intern(.{ .int_type = .{ | 3539 | try wip_nav.refType(.fromInterned(try pt.intern(.{ .int_type = .{ |
| 3455 | .signedness = .unsigned, | 3540 | .signedness = .unsigned, |
| ... | @@ -3518,15 +3603,15 @@ fn updateLazyValue( | ... | @@ -3518,15 +3603,15 @@ fn updateLazyValue( |
| 3518 | .func_high_pc = undefined, | 3603 | .func_high_pc = undefined, |
| 3519 | .blocks = undefined, | 3604 | .blocks = undefined, |
| 3520 | .cfi = undefined, | 3605 | .cfi = undefined, |
| 3521 | .debug_frame = .{}, | 3606 | .debug_frame = .empty, |
| 3522 | .debug_info = .{}, | 3607 | .debug_info = .empty, |
| 3523 | .debug_line = .{}, | 3608 | .debug_line = .empty, |
| 3524 | .debug_loclists = .{}, | 3609 | .debug_loclists = .empty, |
| 3525 | .pending_lazy = pending_lazy.*, | 3610 | .pending_lazy = pending_lazy.*, |
| 3526 | }; | 3611 | }; |
| 3527 | defer { | 3612 | defer { |
| 3528 | pending_lazy.* = wip_nav.pending_lazy; | 3613 | pending_lazy.* = wip_nav.pending_lazy; |
| 3529 | wip_nav.pending_lazy = .{}; | 3614 | wip_nav.pending_lazy = .empty; |
| 3530 | wip_nav.deinit(); | 3615 | wip_nav.deinit(); |
| 3531 | } | 3616 | } |
| 3532 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 3617 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| ... | @@ -3870,12 +3955,13 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP | ... | @@ -3870,12 +3955,13 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 3870 | const ip = &zcu.intern_pool; | 3955 | const ip = &zcu.intern_pool; |
| 3871 | const ty: Type = .fromInterned(type_index); | 3956 | const ty: Type = .fromInterned(type_index); |
| 3872 | const ty_src_loc = ty.srcLoc(zcu); | 3957 | const ty_src_loc = ty.srcLoc(zcu); |
| 3873 | log.debug("updateContainerType({}({d}))", .{ ty.fmt(pt), @intFromEnum(type_index) }); | 3958 | log.debug("updateContainerType({})", .{ty.fmt(pt)}); |
| 3874 | | 3959 | |
| 3875 | const inst_info = ty.typeDeclInst(zcu).?.resolveFull(ip).?; | 3960 | const inst_info = ty.typeDeclInst(zcu).?.resolveFull(ip).?; |
| 3876 | const file = zcu.fileByIndex(inst_info.file); | 3961 | const file = zcu.fileByIndex(inst_info.file); |
| | 3962 | const unit = try dwarf.getUnit(file.mod); |
| | 3963 | const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, inst_info.file); |
| 3877 | if (inst_info.inst == .main_struct_inst) { | 3964 | if (inst_info.inst == .main_struct_inst) { |
| 3878 | const unit = try dwarf.getUnit(file.mod); | | |
| 3879 | const type_gop = try dwarf.types.getOrPut(dwarf.gpa, type_index); | 3965 | const type_gop = try dwarf.types.getOrPut(dwarf.gpa, type_index); |
| 3880 | if (!type_gop.found_existing) type_gop.value_ptr.* = try dwarf.addCommonEntry(unit); | 3966 | if (!type_gop.found_existing) type_gop.value_ptr.* = try dwarf.addCommonEntry(unit); |
| 3881 | var wip_nav: WipNav = .{ | 3967 | var wip_nav: WipNav = .{ |
| ... | @@ -3889,19 +3975,18 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP | ... | @@ -3889,19 +3975,18 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 3889 | .func_high_pc = undefined, | 3975 | .func_high_pc = undefined, |
| 3890 | .blocks = undefined, | 3976 | .blocks = undefined, |
| 3891 | .cfi = undefined, | 3977 | .cfi = undefined, |
| 3892 | .debug_frame = .{}, | 3978 | .debug_frame = .empty, |
| 3893 | .debug_info = .{}, | 3979 | .debug_info = .empty, |
| 3894 | .debug_line = .{}, | 3980 | .debug_line = .empty, |
| 3895 | .debug_loclists = .{}, | 3981 | .debug_loclists = .empty, |
| 3896 | .pending_lazy = .{}, | 3982 | .pending_lazy = .empty, |
| 3897 | }; | 3983 | }; |
| 3898 | defer wip_nav.deinit(); | 3984 | defer wip_nav.deinit(); |
| 3899 | | 3985 | |
| 3900 | const loaded_struct = ip.loadStructType(type_index); | 3986 | const loaded_struct = ip.loadStructType(type_index); |
| 3901 | | 3987 | |
| 3902 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 3988 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 3903 | try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .namespace_file else .file); | 3989 | try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .empty_file else .file); |
| 3904 | const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, inst_info.file); | | |
| 3905 | try uleb128(diw, file_gop.index); | 3990 | try uleb128(diw, file_gop.index); |
| 3906 | try wip_nav.strp(loaded_struct.name.toSlice(ip)); | 3991 | try wip_nav.strp(loaded_struct.name.toSlice(ip)); |
| 3907 | if (loaded_struct.field_types.len > 0) { | 3992 | if (loaded_struct.field_types.len > 0) { |
| ... | @@ -3978,7 +4063,6 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP | ... | @@ -3978,7 +4063,6 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 3978 | if (name_strat == .parent) return; | 4063 | if (name_strat == .parent) return; |
| 3979 | } | 4064 | } |
| 3980 | | 4065 | |
| 3981 | const unit = try dwarf.getUnit(file.mod); | | |
| 3982 | const type_gop = try dwarf.types.getOrPut(dwarf.gpa, type_index); | 4066 | const type_gop = try dwarf.types.getOrPut(dwarf.gpa, type_index); |
| 3983 | if (!type_gop.found_existing) type_gop.value_ptr.* = try dwarf.addCommonEntry(unit); | 4067 | if (!type_gop.found_existing) type_gop.value_ptr.* = try dwarf.addCommonEntry(unit); |
| 3984 | var wip_nav: WipNav = .{ | 4068 | var wip_nav: WipNav = .{ |
| ... | @@ -3992,11 +4076,11 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP | ... | @@ -3992,11 +4076,11 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 3992 | .func_high_pc = undefined, | 4076 | .func_high_pc = undefined, |
| 3993 | .blocks = undefined, | 4077 | .blocks = undefined, |
| 3994 | .cfi = undefined, | 4078 | .cfi = undefined, |
| 3995 | .debug_frame = .{}, | 4079 | .debug_frame = .empty, |
| 3996 | .debug_info = .{}, | 4080 | .debug_info = .empty, |
| 3997 | .debug_line = .{}, | 4081 | .debug_line = .empty, |
| 3998 | .debug_loclists = .{}, | 4082 | .debug_loclists = .empty, |
| 3999 | .pending_lazy = .{}, | 4083 | .pending_lazy = .empty, |
| 4000 | }; | 4084 | }; |
| 4001 | defer wip_nav.deinit(); | 4085 | defer wip_nav.deinit(); |
| 4002 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 4086 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| ... | @@ -4008,7 +4092,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP | ... | @@ -4008,7 +4092,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4008 | const loaded_struct = ip.loadStructType(type_index); | 4092 | const loaded_struct = ip.loadStructType(type_index); |
| 4009 | switch (loaded_struct.layout) { | 4093 | switch (loaded_struct.layout) { |
| 4010 | .auto, .@"extern" => { | 4094 | .auto, .@"extern" => { |
| 4011 | try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .namespace_struct_type else .struct_type); | 4095 | try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .empty_struct_type else .struct_type); |
| | 4096 | try uleb128(diw, file_gop.index); |
| 4012 | try wip_nav.strp(name); | 4097 | try wip_nav.strp(name); |
| 4013 | if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else { | 4098 | if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else { |
| 4014 | try uleb128(diw, ty.abiSize(zcu)); | 4099 | try uleb128(diw, ty.abiSize(zcu)); |
| ... | @@ -4062,6 +4147,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP | ... | @@ -4062,6 +4147,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4062 | }, | 4147 | }, |
| 4063 | .@"packed" => { | 4148 | .@"packed" => { |
| 4064 | try wip_nav.abbrevCode(if (loaded_struct.field_types.len > 0) .packed_struct_type else .empty_packed_struct_type); | 4149 | try wip_nav.abbrevCode(if (loaded_struct.field_types.len > 0) .packed_struct_type else .empty_packed_struct_type); |
| | 4150 | try uleb128(diw, file_gop.index); |
| 4065 | try wip_nav.strp(name); | 4151 | try wip_nav.strp(name); |
| 4066 | try wip_nav.refType(.fromInterned(loaded_struct.backingIntTypeUnordered(ip))); | 4152 | try wip_nav.refType(.fromInterned(loaded_struct.backingIntTypeUnordered(ip))); |
| 4067 | var field_bit_offset: u16 = 0; | 4153 | var field_bit_offset: u16 = 0; |
| ... | @@ -4080,6 +4166,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP | ... | @@ -4080,6 +4166,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4080 | .enum_type => { | 4166 | .enum_type => { |
| 4081 | const loaded_enum = ip.loadEnumType(type_index); | 4167 | const loaded_enum = ip.loadEnumType(type_index); |
| 4082 | try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .enum_type else .empty_enum_type); | 4168 | try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .enum_type else .empty_enum_type); |
| | 4169 | try uleb128(diw, file_gop.index); |
| 4083 | try wip_nav.strp(name); | 4170 | try wip_nav.strp(name); |
| 4084 | try wip_nav.refType(.fromInterned(loaded_enum.tag_ty)); | 4171 | try wip_nav.refType(.fromInterned(loaded_enum.tag_ty)); |
| 4085 | for (0..loaded_enum.names.len) |field_index| { | 4172 | for (0..loaded_enum.names.len) |field_index| { |
| ... | @@ -4095,6 +4182,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP | ... | @@ -4095,6 +4182,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4095 | .union_type => { | 4182 | .union_type => { |
| 4096 | const loaded_union = ip.loadUnionType(type_index); | 4183 | const loaded_union = ip.loadUnionType(type_index); |
| 4097 | try wip_nav.abbrevCode(if (loaded_union.field_types.len > 0) .union_type else .empty_union_type); | 4184 | try wip_nav.abbrevCode(if (loaded_union.field_types.len > 0) .union_type else .empty_union_type); |
| | 4185 | try uleb128(diw, file_gop.index); |
| 4098 | try wip_nav.strp(name); | 4186 | try wip_nav.strp(name); |
| 4099 | const union_layout = Type.getUnionLayout(loaded_union, zcu); | 4187 | const union_layout = Type.getUnionLayout(loaded_union, zcu); |
| 4100 | try uleb128(diw, union_layout.abi_size); | 4188 | try uleb128(diw, union_layout.abi_size); |
| ... | @@ -4144,7 +4232,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP | ... | @@ -4144,7 +4232,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4144 | if (loaded_union.field_types.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null)); | 4232 | if (loaded_union.field_types.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 4145 | }, | 4233 | }, |
| 4146 | .opaque_type => { | 4234 | .opaque_type => { |
| 4147 | try wip_nav.abbrevCode(.namespace_struct_type); | 4235 | try wip_nav.abbrevCode(.empty_struct_type); |
| | 4236 | try uleb128(diw, file_gop.index); |
| 4148 | try wip_nav.strp(name); | 4237 | try wip_nav.strp(name); |
| 4149 | try diw.writeByte(@intFromBool(true)); | 4238 | try diw.writeByte(@intFromBool(true)); |
| 4150 | }, | 4239 | }, |
| ... | @@ -4156,21 +4245,28 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP | ... | @@ -4156,21 +4245,28 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4156 | } | 4245 | } |
| 4157 | } | 4246 | } |
| 4158 | | 4247 | |
| 4159 | pub fn updateNavLineNumber(dwarf: *Dwarf, zcu: *Zcu, nav_index: InternPool.Nav.Index) UpdateError!void { | 4248 | pub fn updateLineNumber(dwarf: *Dwarf, zcu: *Zcu, zir_index: InternPool.TrackedInst.Index) UpdateError!void { |
| 4160 | const ip = &zcu.intern_pool; | 4249 | const ip = &zcu.intern_pool; |
| 4161 | | 4250 | |
| 4162 | const zir_index = ip.getCau(ip.getNav(nav_index).analysis_owner.unwrap() orelse return).zir_index; | | |
| 4163 | const inst_info = zir_index.resolveFull(ip).?; | 4251 | const inst_info = zir_index.resolveFull(ip).?; |
| 4164 | assert(inst_info.inst != .main_struct_inst); | 4252 | assert(inst_info.inst != .main_struct_inst); |
| 4165 | const file = zcu.fileByIndex(inst_info.file); | 4253 | const file = zcu.fileByIndex(inst_info.file); |
| | 4254 | assert(file.zir_loaded); |
| | 4255 | const decl = file.zir.getDeclaration(inst_info.inst); |
| | 4256 | log.debug("updateLineNumber({s}:{d}:{d} %{d} = {s})", .{ |
| | 4257 | file.sub_file_path, |
| | 4258 | decl.src_line + 1, |
| | 4259 | decl.src_column + 1, |
| | 4260 | @intFromEnum(inst_info.inst), |
| | 4261 | file.zir.nullTerminatedString(decl.name), |
| | 4262 | }); |
| 4166 | | 4263 | |
| 4167 | const line = file.zir.getDeclaration(inst_info.inst).src_line; | | |
| 4168 | var line_buf: [4]u8 = undefined; | 4264 | var line_buf: [4]u8 = undefined; |
| 4169 | std.mem.writeInt(u32, &line_buf, line, dwarf.endian); | 4265 | std.mem.writeInt(u32, &line_buf, decl.src_line + 1, dwarf.endian); |
| 4170 | | 4266 | |
| 4171 | const unit = dwarf.debug_line.section.getUnit(dwarf.mods.get(file.mod).?); | 4267 | const unit = dwarf.debug_info.section.getUnit(dwarf.getUnitIfExists(file.mod) orelse return); |
| 4172 | const entry = unit.getEntry(dwarf.navs.get(nav_index).?); | 4268 | const entry = unit.getEntry(dwarf.decls.get(zir_index) orelse return); |
| 4173 | try dwarf.getFile().?.pwriteAll(&line, dwarf.debug_line.section.off + unit.off + unit.header_len + entry.off + DebugInfo.declEntryLineOff(dwarf)); | 4269 | try dwarf.getFile().?.pwriteAll(&line_buf, dwarf.debug_info.section.off(dwarf) + unit.off + unit.header_len + entry.off + DebugInfo.declEntryLineOff(dwarf)); |
| 4174 | } | 4270 | } |
| 4175 | | 4271 | |
| 4176 | pub fn freeNav(dwarf: *Dwarf, nav_index: InternPool.Nav.Index) void { | 4272 | pub fn freeNav(dwarf: *Dwarf, nav_index: InternPool.Nav.Index) void { |
| ... | @@ -4213,16 +4309,16 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { | ... | @@ -4213,16 +4309,16 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4213 | .func_high_pc = undefined, | 4309 | .func_high_pc = undefined, |
| 4214 | .blocks = undefined, | 4310 | .blocks = undefined, |
| 4215 | .cfi = undefined, | 4311 | .cfi = undefined, |
| 4216 | .debug_frame = .{}, | 4312 | .debug_frame = .empty, |
| 4217 | .debug_info = .{}, | 4313 | .debug_info = .empty, |
| 4218 | .debug_line = .{}, | 4314 | .debug_line = .empty, |
| 4219 | .debug_loclists = .{}, | 4315 | .debug_loclists = .empty, |
| 4220 | .pending_lazy = .{}, | 4316 | .pending_lazy = .empty, |
| 4221 | }; | 4317 | }; |
| 4222 | defer wip_nav.deinit(); | 4318 | defer wip_nav.deinit(); |
| 4223 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 4319 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 4224 | const global_error_set_names = ip.global_error_set.getNamesFromMainThread(); | 4320 | const global_error_set_names = ip.global_error_set.getNamesFromMainThread(); |
| 4225 | try wip_nav.abbrevCode(if (global_error_set_names.len > 0) .enum_type else .empty_enum_type); | 4321 | try wip_nav.abbrevCode(if (global_error_set_names.len > 0) .generated_enum_type else .generated_empty_enum_type); |
| 4226 | try wip_nav.strp("anyerror"); | 4322 | try wip_nav.strp("anyerror"); |
| 4227 | try wip_nav.refType(.fromInterned(try pt.intern(.{ .int_type = .{ | 4323 | try wip_nav.refType(.fromInterned(try pt.intern(.{ .int_type = .{ |
| 4228 | .signedness = .unsigned, | 4324 | .signedness = .unsigned, |
| ... | @@ -4611,7 +4707,7 @@ const AbbrevCode = enum { | ... | @@ -4611,7 +4707,7 @@ const AbbrevCode = enum { |
| 4611 | // padding codes must be one byte uleb128 values to function | 4707 | // padding codes must be one byte uleb128 values to function |
| 4612 | pad_1, | 4708 | pad_1, |
| 4613 | pad_n, | 4709 | pad_n, |
| 4614 | // decl codes are assumed to all have the same uleb128 length | 4710 | // (generic) decl codes are assumed to all have the same uleb128 length |
| 4615 | decl_alias, | 4711 | decl_alias, |
| 4616 | decl_enum, | 4712 | decl_enum, |
| 4617 | decl_empty_enum, | 4713 | decl_empty_enum, |
| ... | @@ -4628,11 +4724,34 @@ const AbbrevCode = enum { | ... | @@ -4628,11 +4724,34 @@ const AbbrevCode = enum { |
| 4628 | decl_empty_func, | 4724 | decl_empty_func, |
| 4629 | decl_func_generic, | 4725 | decl_func_generic, |
| 4630 | decl_empty_func_generic, | 4726 | decl_empty_func_generic, |
| | 4727 | generic_decl_alias, |
| | 4728 | generic_decl_enum, |
| | 4729 | generic_decl_struct, |
| | 4730 | generic_decl_union, |
| | 4731 | generic_decl_var, |
| | 4732 | generic_decl_const, |
| | 4733 | generic_decl_func, |
| 4631 | // the rest are unrestricted | 4734 | // the rest are unrestricted |
| | 4735 | instance_alias, |
| | 4736 | instance_enum, |
| | 4737 | instance_empty_enum, |
| | 4738 | instance_namespace_struct, |
| | 4739 | instance_struct, |
| | 4740 | instance_packed_struct, |
| | 4741 | instance_union, |
| | 4742 | instance_var, |
| | 4743 | instance_const, |
| | 4744 | instance_const_runtime_bits, |
| | 4745 | instance_const_comptime_state, |
| | 4746 | instance_const_runtime_bits_comptime_state, |
| | 4747 | instance_func, |
| | 4748 | instance_empty_func, |
| | 4749 | instance_func_generic, |
| | 4750 | instance_empty_func_generic, |
| 4632 | compile_unit, | 4751 | compile_unit, |
| 4633 | module, | 4752 | module, |
| 4634 | namespace_file, | | |
| 4635 | file, | 4753 | file, |
| | 4754 | empty_file, |
| 4636 | signed_enum_field, | 4755 | signed_enum_field, |
| 4637 | unsigned_enum_field, | 4756 | unsigned_enum_field, |
| 4638 | big_enum_field, | 4757 | big_enum_field, |
| ... | @@ -4665,10 +4784,15 @@ const AbbrevCode = enum { | ... | @@ -4665,10 +4784,15 @@ const AbbrevCode = enum { |
| 4665 | func_type, | 4784 | func_type, |
| 4666 | func_type_param, | 4785 | func_type_param, |
| 4667 | is_var_args, | 4786 | is_var_args, |
| | 4787 | generated_enum_type, |
| | 4788 | generated_empty_enum_type, |
| | 4789 | generated_struct_type, |
| | 4790 | generated_empty_struct_type, |
| | 4791 | generated_union_type, |
| 4668 | enum_type, | 4792 | enum_type, |
| 4669 | empty_enum_type, | 4793 | empty_enum_type, |
| 4670 | namespace_struct_type, | | |
| 4671 | struct_type, | 4794 | struct_type, |
| | 4795 | empty_struct_type, |
| 4672 | packed_struct_type, | 4796 | packed_struct_type, |
| 4673 | empty_packed_struct_type, | 4797 | empty_packed_struct_type, |
| 4674 | union_type, | 4798 | union_type, |
| ... | @@ -4694,7 +4818,7 @@ const AbbrevCode = enum { | ... | @@ -4694,7 +4818,7 @@ const AbbrevCode = enum { |
| 4694 | comptime_value_elem_runtime_bits, | 4818 | comptime_value_elem_runtime_bits, |
| 4695 | comptime_value_elem_comptime_state, | 4819 | comptime_value_elem_comptime_state, |
| 4696 | | 4820 | |
| 4697 | const decl_bytes = uleb128Bytes(@intFromEnum(AbbrevCode.decl_empty_func_generic)); | 4821 | const decl_bytes = uleb128Bytes(@intFromEnum(AbbrevCode.generic_decl_func)); |
| 4698 | | 4822 | |
| 4699 | const Attr = struct { | 4823 | const Attr = struct { |
| 4700 | DeclValEnum(DW.AT), | 4824 | DeclValEnum(DW.AT), |
| ... | @@ -4707,6 +4831,10 @@ const AbbrevCode = enum { | ... | @@ -4707,6 +4831,10 @@ const AbbrevCode = enum { |
| 4707 | .{ .accessibility, .data1 }, | 4831 | .{ .accessibility, .data1 }, |
| 4708 | .{ .name, .strp }, | 4832 | .{ .name, .strp }, |
| 4709 | }; | 4833 | }; |
| | 4834 | const instance_abbrev_common_attrs = &[_]Attr{ |
| | 4835 | .{ .ZIG_parent, .ref_addr }, |
| | 4836 | .{ .abstract_origin, .ref_addr }, |
| | 4837 | }; |
| 4710 | const abbrevs = std.EnumArray(AbbrevCode, struct { | 4838 | const abbrevs = std.EnumArray(AbbrevCode, struct { |
| 4711 | tag: DeclValEnum(DW.TAG), | 4839 | tag: DeclValEnum(DW.TAG), |
| 4712 | children: bool = false, | 4840 | children: bool = false, |
| ... | @@ -4857,6 +4985,184 @@ const AbbrevCode = enum { | ... | @@ -4857,6 +4985,184 @@ const AbbrevCode = enum { |
| 4857 | .{ .type, .ref_addr }, | 4985 | .{ .type, .ref_addr }, |
| 4858 | }, | 4986 | }, |
| 4859 | }, | 4987 | }, |
| | 4988 | .generic_decl_alias = .{ |
| | 4989 | .tag = .imported_declaration, |
| | 4990 | .attrs = decl_abbrev_common_attrs ++ .{ |
| | 4991 | .{ .declaration, .flag_present }, |
| | 4992 | }, |
| | 4993 | }, |
| | 4994 | .generic_decl_enum = .{ |
| | 4995 | .tag = .enumeration_type, |
| | 4996 | .attrs = decl_abbrev_common_attrs ++ .{ |
| | 4997 | .{ .declaration, .flag_present }, |
| | 4998 | }, |
| | 4999 | }, |
| | 5000 | .generic_decl_struct = .{ |
| | 5001 | .tag = .structure_type, |
| | 5002 | .attrs = decl_abbrev_common_attrs ++ .{ |
| | 5003 | .{ .declaration, .flag_present }, |
| | 5004 | }, |
| | 5005 | }, |
| | 5006 | .generic_decl_union = .{ |
| | 5007 | .tag = .union_type, |
| | 5008 | .attrs = decl_abbrev_common_attrs ++ .{ |
| | 5009 | .{ .declaration, .flag_present }, |
| | 5010 | }, |
| | 5011 | }, |
| | 5012 | .generic_decl_var = .{ |
| | 5013 | .tag = .variable, |
| | 5014 | .attrs = decl_abbrev_common_attrs ++ .{ |
| | 5015 | .{ .declaration, .flag_present }, |
| | 5016 | }, |
| | 5017 | }, |
| | 5018 | .generic_decl_const = .{ |
| | 5019 | .tag = .constant, |
| | 5020 | .attrs = decl_abbrev_common_attrs ++ .{ |
| | 5021 | .{ .declaration, .flag_present }, |
| | 5022 | }, |
| | 5023 | }, |
| | 5024 | .generic_decl_func = .{ |
| | 5025 | .tag = .subprogram, |
| | 5026 | .attrs = decl_abbrev_common_attrs ++ .{ |
| | 5027 | .{ .declaration, .flag_present }, |
| | 5028 | }, |
| | 5029 | }, |
| | 5030 | .instance_alias = .{ |
| | 5031 | .tag = .imported_declaration, |
| | 5032 | .attrs = instance_abbrev_common_attrs ++ .{ |
| | 5033 | .{ .import, .ref_addr }, |
| | 5034 | }, |
| | 5035 | }, |
| | 5036 | .instance_enum = .{ |
| | 5037 | .tag = .enumeration_type, |
| | 5038 | .children = true, |
| | 5039 | .attrs = instance_abbrev_common_attrs ++ .{ |
| | 5040 | .{ .type, .ref_addr }, |
| | 5041 | }, |
| | 5042 | }, |
| | 5043 | .instance_empty_enum = .{ |
| | 5044 | .tag = .enumeration_type, |
| | 5045 | .attrs = instance_abbrev_common_attrs ++ .{ |
| | 5046 | .{ .type, .ref_addr }, |
| | 5047 | }, |
| | 5048 | }, |
| | 5049 | .instance_namespace_struct = .{ |
| | 5050 | .tag = .structure_type, |
| | 5051 | .attrs = instance_abbrev_common_attrs ++ .{ |
| | 5052 | .{ .declaration, .flag }, |
| | 5053 | }, |
| | 5054 | }, |
| | 5055 | .instance_struct = .{ |
| | 5056 | .tag = .structure_type, |
| | 5057 | .children = true, |
| | 5058 | .attrs = instance_abbrev_common_attrs ++ .{ |
| | 5059 | .{ .byte_size, .udata }, |
| | 5060 | .{ .alignment, .udata }, |
| | 5061 | }, |
| | 5062 | }, |
| | 5063 | .instance_packed_struct = .{ |
| | 5064 | .tag = .structure_type, |
| | 5065 | .children = true, |
| | 5066 | .attrs = instance_abbrev_common_attrs ++ .{ |
| | 5067 | .{ .type, .ref_addr }, |
| | 5068 | }, |
| | 5069 | }, |
| | 5070 | .instance_union = .{ |
| | 5071 | .tag = .union_type, |
| | 5072 | .children = true, |
| | 5073 | .attrs = instance_abbrev_common_attrs ++ .{ |
| | 5074 | .{ .byte_size, .udata }, |
| | 5075 | .{ .alignment, .udata }, |
| | 5076 | }, |
| | 5077 | }, |
| | 5078 | .instance_var = .{ |
| | 5079 | .tag = .variable, |
| | 5080 | .attrs = instance_abbrev_common_attrs ++ .{ |
| | 5081 | .{ .linkage_name, .strp }, |
| | 5082 | .{ .type, .ref_addr }, |
| | 5083 | .{ .location, .exprloc }, |
| | 5084 | .{ .alignment, .udata }, |
| | 5085 | .{ .external, .flag }, |
| | 5086 | }, |
| | 5087 | }, |
| | 5088 | .instance_const = .{ |
| | 5089 | .tag = .constant, |
| | 5090 | .attrs = instance_abbrev_common_attrs ++ .{ |
| | 5091 | .{ .linkage_name, .strp }, |
| | 5092 | .{ .type, .ref_addr }, |
| | 5093 | .{ .alignment, .udata }, |
| | 5094 | .{ .external, .flag }, |
| | 5095 | }, |
| | 5096 | }, |
| | 5097 | .instance_const_runtime_bits = .{ |
| | 5098 | .tag = .constant, |
| | 5099 | .attrs = instance_abbrev_common_attrs ++ .{ |
| | 5100 | .{ .linkage_name, .strp }, |
| | 5101 | .{ .type, .ref_addr }, |
| | 5102 | .{ .alignment, .udata }, |
| | 5103 | .{ .external, .flag }, |
| | 5104 | .{ .const_value, .block }, |
| | 5105 | }, |
| | 5106 | }, |
| | 5107 | .instance_const_comptime_state = .{ |
| | 5108 | .tag = .constant, |
| | 5109 | .attrs = instance_abbrev_common_attrs ++ .{ |
| | 5110 | .{ .linkage_name, .strp }, |
| | 5111 | .{ .type, .ref_addr }, |
| | 5112 | .{ .alignment, .udata }, |
| | 5113 | .{ .external, .flag }, |
| | 5114 | .{ .ZIG_comptime_value, .ref_addr }, |
| | 5115 | }, |
| | 5116 | }, |
| | 5117 | .instance_const_runtime_bits_comptime_state = .{ |
| | 5118 | .tag = .constant, |
| | 5119 | .attrs = instance_abbrev_common_attrs ++ .{ |
| | 5120 | .{ .linkage_name, .strp }, |
| | 5121 | .{ .type, .ref_addr }, |
| | 5122 | .{ .alignment, .udata }, |
| | 5123 | .{ .external, .flag }, |
| | 5124 | .{ .const_value, .block }, |
| | 5125 | .{ .ZIG_comptime_value, .ref_addr }, |
| | 5126 | }, |
| | 5127 | }, |
| | 5128 | .instance_func = .{ |
| | 5129 | .tag = .subprogram, |
| | 5130 | .children = true, |
| | 5131 | .attrs = instance_abbrev_common_attrs ++ .{ |
| | 5132 | .{ .linkage_name, .strp }, |
| | 5133 | .{ .type, .ref_addr }, |
| | 5134 | .{ .low_pc, .addr }, |
| | 5135 | .{ .high_pc, .data4 }, |
| | 5136 | .{ .alignment, .udata }, |
| | 5137 | .{ .external, .flag }, |
| | 5138 | .{ .noreturn, .flag }, |
| | 5139 | }, |
| | 5140 | }, |
| | 5141 | .instance_empty_func = .{ |
| | 5142 | .tag = .subprogram, |
| | 5143 | .attrs = instance_abbrev_common_attrs ++ .{ |
| | 5144 | .{ .linkage_name, .strp }, |
| | 5145 | .{ .type, .ref_addr }, |
| | 5146 | .{ .low_pc, .addr }, |
| | 5147 | .{ .high_pc, .data4 }, |
| | 5148 | .{ .alignment, .udata }, |
| | 5149 | .{ .external, .flag }, |
| | 5150 | .{ .noreturn, .flag }, |
| | 5151 | }, |
| | 5152 | }, |
| | 5153 | .instance_func_generic = .{ |
| | 5154 | .tag = .subprogram, |
| | 5155 | .children = true, |
| | 5156 | .attrs = instance_abbrev_common_attrs ++ .{ |
| | 5157 | .{ .type, .ref_addr }, |
| | 5158 | }, |
| | 5159 | }, |
| | 5160 | .instance_empty_func_generic = .{ |
| | 5161 | .tag = .subprogram, |
| | 5162 | .attrs = instance_abbrev_common_attrs ++ .{ |
| | 5163 | .{ .type, .ref_addr }, |
| | 5164 | }, |
| | 5165 | }, |
| 4860 | .compile_unit = .{ | 5166 | .compile_unit = .{ |
| 4861 | .tag = .compile_unit, | 5167 | .tag = .compile_unit, |
| 4862 | .children = true, | 5168 | .children = true, |
| ... | @@ -4879,21 +5185,21 @@ const AbbrevCode = enum { | ... | @@ -4879,21 +5185,21 @@ const AbbrevCode = enum { |
| 4879 | .{ .ranges, .rnglistx }, | 5185 | .{ .ranges, .rnglistx }, |
| 4880 | }, | 5186 | }, |
| 4881 | }, | 5187 | }, |
| 4882 | .namespace_file = .{ | 5188 | .file = .{ |
| 4883 | .tag = .structure_type, | 5189 | .tag = .structure_type, |
| | 5190 | .children = true, |
| 4884 | .attrs = &.{ | 5191 | .attrs = &.{ |
| 4885 | .{ .decl_file, .udata }, | 5192 | .{ .decl_file, .udata }, |
| 4886 | .{ .name, .strp }, | 5193 | .{ .name, .strp }, |
| | 5194 | .{ .byte_size, .udata }, |
| | 5195 | .{ .alignment, .udata }, |
| 4887 | }, | 5196 | }, |
| 4888 | }, | 5197 | }, |
| 4889 | .file = .{ | 5198 | .empty_file = .{ |
| 4890 | .tag = .structure_type, | 5199 | .tag = .structure_type, |
| 4891 | .children = true, | | |
| 4892 | .attrs = &.{ | 5200 | .attrs = &.{ |
| 4893 | .{ .decl_file, .udata }, | 5201 | .{ .decl_file, .udata }, |
| 4894 | .{ .name, .strp }, | 5202 | .{ .name, .strp }, |
| 4895 | .{ .byte_size, .udata }, | | |
| 4896 | .{ .alignment, .udata }, | | |
| 4897 | }, | 5203 | }, |
| 4898 | }, | 5204 | }, |
| 4899 | .signed_enum_field = .{ | 5205 | .signed_enum_field = .{ |
| ... | @@ -5143,7 +5449,7 @@ const AbbrevCode = enum { | ... | @@ -5143,7 +5449,7 @@ const AbbrevCode = enum { |
| 5143 | .is_var_args = .{ | 5449 | .is_var_args = .{ |
| 5144 | .tag = .unspecified_parameters, | 5450 | .tag = .unspecified_parameters, |
| 5145 | }, | 5451 | }, |
| 5146 | .enum_type = .{ | 5452 | .generated_enum_type = .{ |
| 5147 | .tag = .enumeration_type, | 5453 | .tag = .enumeration_type, |
| 5148 | .children = true, | 5454 | .children = true, |
| 5149 | .attrs = &.{ | 5455 | .attrs = &.{ |
| ... | @@ -5151,33 +5457,78 @@ const AbbrevCode = enum { | ... | @@ -5151,33 +5457,78 @@ const AbbrevCode = enum { |
| 5151 | .{ .type, .ref_addr }, | 5457 | .{ .type, .ref_addr }, |
| 5152 | }, | 5458 | }, |
| 5153 | }, | 5459 | }, |
| 5154 | .empty_enum_type = .{ | 5460 | .generated_empty_enum_type = .{ |
| 5155 | .tag = .enumeration_type, | 5461 | .tag = .enumeration_type, |
| 5156 | .attrs = &.{ | 5462 | .attrs = &.{ |
| 5157 | .{ .name, .strp }, | 5463 | .{ .name, .strp }, |
| 5158 | .{ .type, .ref_addr }, | 5464 | .{ .type, .ref_addr }, |
| 5159 | }, | 5465 | }, |
| 5160 | }, | 5466 | }, |
| 5161 | .namespace_struct_type = .{ | 5467 | .generated_struct_type = .{ |
| | 5468 | .tag = .structure_type, |
| | 5469 | .children = true, |
| | 5470 | .attrs = &.{ |
| | 5471 | .{ .name, .strp }, |
| | 5472 | .{ .byte_size, .udata }, |
| | 5473 | .{ .alignment, .udata }, |
| | 5474 | }, |
| | 5475 | }, |
| | 5476 | .generated_empty_struct_type = .{ |
| 5162 | .tag = .structure_type, | 5477 | .tag = .structure_type, |
| 5163 | .attrs = &.{ | 5478 | .attrs = &.{ |
| 5164 | .{ .name, .strp }, | 5479 | .{ .name, .strp }, |
| 5165 | .{ .declaration, .flag }, | 5480 | .{ .declaration, .flag }, |
| 5166 | }, | 5481 | }, |
| 5167 | }, | 5482 | }, |
| | 5483 | .generated_union_type = .{ |
| | 5484 | .tag = .union_type, |
| | 5485 | .children = true, |
| | 5486 | .attrs = &.{ |
| | 5487 | .{ .name, .strp }, |
| | 5488 | .{ .byte_size, .udata }, |
| | 5489 | .{ .alignment, .udata }, |
| | 5490 | }, |
| | 5491 | }, |
| | 5492 | .enum_type = .{ |
| | 5493 | .tag = .enumeration_type, |
| | 5494 | .children = true, |
| | 5495 | .attrs = &.{ |
| | 5496 | .{ .decl_file, .udata }, |
| | 5497 | .{ .name, .strp }, |
| | 5498 | .{ .type, .ref_addr }, |
| | 5499 | }, |
| | 5500 | }, |
| | 5501 | .empty_enum_type = .{ |
| | 5502 | .tag = .enumeration_type, |
| | 5503 | .attrs = &.{ |
| | 5504 | .{ .decl_file, .udata }, |
| | 5505 | .{ .name, .strp }, |
| | 5506 | .{ .type, .ref_addr }, |
| | 5507 | }, |
| | 5508 | }, |
| 5168 | .struct_type = .{ | 5509 | .struct_type = .{ |
| 5169 | .tag = .structure_type, | 5510 | .tag = .structure_type, |
| 5170 | .children = true, | 5511 | .children = true, |
| 5171 | .attrs = &.{ | 5512 | .attrs = &.{ |
| | 5513 | .{ .decl_file, .udata }, |
| 5172 | .{ .name, .strp }, | 5514 | .{ .name, .strp }, |
| 5173 | .{ .byte_size, .udata }, | 5515 | .{ .byte_size, .udata }, |
| 5174 | .{ .alignment, .udata }, | 5516 | .{ .alignment, .udata }, |
| 5175 | }, | 5517 | }, |
| 5176 | }, | 5518 | }, |
| | 5519 | .empty_struct_type = .{ |
| | 5520 | .tag = .structure_type, |
| | 5521 | .attrs = &.{ |
| | 5522 | .{ .decl_file, .udata }, |
| | 5523 | .{ .name, .strp }, |
| | 5524 | .{ .declaration, .flag }, |
| | 5525 | }, |
| | 5526 | }, |
| 5177 | .packed_struct_type = .{ | 5527 | .packed_struct_type = .{ |
| 5178 | .tag = .structure_type, | 5528 | .tag = .structure_type, |
| 5179 | .children = true, | 5529 | .children = true, |
| 5180 | .attrs = &.{ | 5530 | .attrs = &.{ |
| | 5531 | .{ .decl_file, .udata }, |
| 5181 | .{ .name, .strp }, | 5532 | .{ .name, .strp }, |
| 5182 | .{ .type, .ref_addr }, | 5533 | .{ .type, .ref_addr }, |
| 5183 | }, | 5534 | }, |
| ... | @@ -5185,6 +5536,7 @@ const AbbrevCode = enum { | ... | @@ -5185,6 +5536,7 @@ const AbbrevCode = enum { |
| 5185 | .empty_packed_struct_type = .{ | 5536 | .empty_packed_struct_type = .{ |
| 5186 | .tag = .structure_type, | 5537 | .tag = .structure_type, |
| 5187 | .attrs = &.{ | 5538 | .attrs = &.{ |
| | 5539 | .{ .decl_file, .udata }, |
| 5188 | .{ .name, .strp }, | 5540 | .{ .name, .strp }, |
| 5189 | .{ .type, .ref_addr }, | 5541 | .{ .type, .ref_addr }, |
| 5190 | }, | 5542 | }, |
| ... | @@ -5193,6 +5545,7 @@ const AbbrevCode = enum { | ... | @@ -5193,6 +5545,7 @@ const AbbrevCode = enum { |
| 5193 | .tag = .union_type, | 5545 | .tag = .union_type, |
| 5194 | .children = true, | 5546 | .children = true, |
| 5195 | .attrs = &.{ | 5547 | .attrs = &.{ |
| | 5548 | .{ .decl_file, .udata }, |
| 5196 | .{ .name, .strp }, | 5549 | .{ .name, .strp }, |
| 5197 | .{ .byte_size, .udata }, | 5550 | .{ .byte_size, .udata }, |
| 5198 | .{ .alignment, .udata }, | 5551 | .{ .alignment, .udata }, |
| ... | @@ -5201,6 +5554,7 @@ const AbbrevCode = enum { | ... | @@ -5201,6 +5554,7 @@ const AbbrevCode = enum { |
| 5201 | .empty_union_type = .{ | 5554 | .empty_union_type = .{ |
| 5202 | .tag = .union_type, | 5555 | .tag = .union_type, |
| 5203 | .attrs = &.{ | 5556 | .attrs = &.{ |
| | 5557 | .{ .decl_file, .udata }, |
| 5204 | .{ .name, .strp }, | 5558 | .{ .name, .strp }, |
| 5205 | .{ .byte_size, .udata }, | 5559 | .{ .byte_size, .udata }, |
| 5206 | .{ .alignment, .udata }, | 5560 | .{ .alignment, .udata }, |
| ... | @@ -5373,6 +5727,15 @@ fn addCommonEntry(dwarf: *Dwarf, unit: Unit.Index) UpdateError!Entry.Index { | ... | @@ -5373,6 +5727,15 @@ fn addCommonEntry(dwarf: *Dwarf, unit: Unit.Index) UpdateError!Entry.Index { |
| 5373 | return entry; | 5727 | return entry; |
| 5374 | } | 5728 | } |
| 5375 | | 5729 | |
| | 5730 | fn freeCommonEntry(dwarf: *Dwarf, unit: Unit.Index, entry: Entry.Index) UpdateError!void { |
| | 5731 | try dwarf.debug_aranges.section.freeEntry(unit, entry, dwarf); |
| | 5732 | try dwarf.debug_frame.section.freeEntry(unit, entry, dwarf); |
| | 5733 | try dwarf.debug_info.section.freeEntry(unit, entry, dwarf); |
| | 5734 | try dwarf.debug_line.section.freeEntry(unit, entry, dwarf); |
| | 5735 | try dwarf.debug_loclists.section.freeEntry(unit, entry, dwarf); |
| | 5736 | try dwarf.debug_rnglists.section.freeEntry(unit, entry, dwarf); |
| | 5737 | } |
| | 5738 | |
| 5376 | fn writeInt(dwarf: *Dwarf, buf: []u8, int: u64) void { | 5739 | fn writeInt(dwarf: *Dwarf, buf: []u8, int: u64) void { |
| 5377 | switch (buf.len) { | 5740 | switch (buf.len) { |
| 5378 | inline 0...8 => |len| std.mem.writeInt(@Type(.{ .int = .{ | 5741 | inline 0...8 => |len| std.mem.writeInt(@Type(.{ .int = .{ |