authorgravatar for mason@gamesbymason.comMason Remaley <mason@gamesbymason.com> 2026-04-09 17:27:12-07:00
committergravatar for mason@gamesbymason.comMason Remaley <mason@gamesbymason.com> 2026-04-12 04:01:30-07:00
logdcdb562c154c950ed06a23a3a267fa8cdc172dda
tree68f7a6751e80a152ade5c054ec5b018333666178
parent492efd4c06541ca8add4147dfc2d766c1ba54693

Adds support for running the trace tests through darling, fixes compilation errors in MachO due to interface change


2 files changed, 33 insertions(+), 12 deletions(-)

lib/std/debug/SelfInfo/MachO.zig+27-12
......@@ -22,12 +22,26 @@ pub fn deinit(si: *SelfInfo, io: Io) void {
2222 si.modules.deinit(gpa);
2323}
2424
25pub fn getSymbol(si: *SelfInfo, io: Io, address: usize) Error!std.debug.Symbol {
25pub const SymbolIterator = struct {
26 curr: ?Error!std.debug.Symbol,
27
28 pub fn deinit(self: *SymbolIterator, _: Io) void {
29 self.* = undefined;
30 }
31
32 pub fn next(self: *SymbolIterator) ?Error!std.debug.Symbol {
33 const result = self.curr;
34 self.curr = null;
35 return result;
36 }
37};
38
39pub fn getSymbols(si: *SelfInfo, io: Io, address: usize) SymbolIterator {
2640 const gpa = std.debug.getDebugInfoAllocator();
27 const module = try si.findModule(gpa, io, address);
41 const module = si.findModule(gpa, io, address) catch |err| return .{ .curr = err };
2842 defer si.mutex.unlock(io);
2943
30 const file = try module.getFile(gpa, io);
44 const file = module.getFile(gpa, io) catch |err| return .{ .curr = err };
3145
3246 // This is not necessarily the same as the vmaddr_slide that dyld would report. This is
3347 // because the segments in the file on disk might differ from the ones in memory. Normally
......@@ -43,25 +57,26 @@ pub fn getSymbol(si: *SelfInfo, io: Io, address: usize) Error!std.debug.Symbol {
4357
4458 const ofile_dwarf, const ofile_vaddr = file.getDwarfForAddress(gpa, io, vaddr) catch {
4559 // Return at least the symbol name if available.
46 return .{
47 .name = try file.lookupSymbolName(vaddr),
60 return .{ .curr = .{
61 .name = file.lookupSymbolName(vaddr) catch |err| return .{ .curr = err },
4862 .compile_unit_name = null,
4963 .source_location = null,
50 };
64 } };
5165 };
5266
5367 const compile_unit = ofile_dwarf.findCompileUnit(native_endian, ofile_vaddr) catch {
5468 // Return at least the symbol name if available.
55 return .{
56 .name = try file.lookupSymbolName(vaddr),
69 return .{ .curr = .{
70 .name = file.lookupSymbolName(vaddr) catch |err| return .{ .curr = err },
5771 .compile_unit_name = null,
5872 .source_location = null,
59 };
73 } };
6074 };
6175
62 return .{
76 return .{ .curr = .{
6377 .name = ofile_dwarf.getSymbolName(ofile_vaddr) orelse
64 try file.lookupSymbolName(vaddr),
78 file.lookupSymbolName(vaddr) catch |err|
79 return .{ .curr = err },
6580 .compile_unit_name = compile_unit.die.getAttrString(
6681 ofile_dwarf,
6782 native_endian,
......@@ -77,7 +92,7 @@ pub fn getSymbol(si: *SelfInfo, io: Io, address: usize) Error!std.debug.Symbol {
7792 compile_unit,
7893 ofile_vaddr,
7994 ) catch null,
80 };
95 } };
8196}
8297pub fn getModuleName(si: *SelfInfo, io: Io, address: usize) Error![]const u8 {
8398 _ = si;
test/tests.zig+6
......@@ -2033,6 +2033,12 @@ fn nativeAndCompatible32bit(b: *std.Build, skip_non_native: bool) []const std.Bu
20332033 .os_tag = .windows,
20342034 })) catch @panic("OOM");
20352035 }
2036 if (b.enable_darling and b.graph.host.result.os.tag != .macos) {
2037 targets.append(b.graph.arena, b.resolveTargetQuery(.{
2038 .cpu_arch = host.cpu.arch,
2039 .os_tag = .macos,
2040 })) catch @panic("OOM");
2041 }
20362042 return targets.toOwnedSlice(b.graph.arena) catch @panic("OOM");
20372043}
20382044