authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-05-14 13:09:40+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-05-14 13:09:40+02:00
logaf9c6f2c696201e16d95f79a7275aae19b34cd59
treeebc0836bd9d1c185249b48e23ed581c38f93ffa5
parent00ebbe6df2249ba8201c0e5472d95022bf73e782

macho: put dSYM bundle in zig-cache

Originally, I thought that the dSYM bundle has to reside side-by-side with the binary it carries the debugging information for. However, it turns out macOS is clever enough that it auto-searches for matching dSYM bundle based on the embedded UUID of the binary. To verify this, run this on your macOS: ``` mdfind "com_apple_xcode_dsym_uuids == <UUID from LC_UUID>" ``` See [here] for more info. [here]: https://developer.apple.com/documentation/xcode/adding-identifiable-symbol-names-to-a-crash-report

1 files changed, 25 insertions(+), 13 deletions(-)

src/link/MachO.zig+25-13
...@@ -363,18 +363,30 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio...@@ -363,18 +363,30 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio
363 self.base.file = file;363 self.base.file = file;
364364
365 // Create dSYM bundle.365 // Create dSYM bundle.
366 const d_sym_path = try fmt.allocPrint(allocator, "{s}.dSYM/Contents/Resources/DWARF/", .{sub_path});366 if (options.module) |mod| {
367 defer allocator.free(d_sym_path);367 const dir = mod.zig_cache_artifact_directory;
368 var d_sym_bundle = try options.emit.?.directory.handle.makeOpenPath(d_sym_path, .{});368 log.debug("creating {s}.dSYM bundle in {s}", .{ sub_path, dir.path });
369 defer d_sym_bundle.close();369
370 const d_sym_file = try d_sym_bundle.createFile(sub_path, .{370 const d_sym_path = try fmt.allocPrint(
371 .truncate = false,371 allocator,
372 .read = true,372 "{s}.dSYM" ++ fs.path.sep_str ++ "Contents" ++ fs.path.sep_str ++ "Resources" ++ fs.path.sep_str ++ "DWARF",
373 });373 .{sub_path},
374 self.d_sym = .{374 );
375 .base = self,375 defer allocator.free(d_sym_path);
376 .file = d_sym_file,376
377 };377 var d_sym_bundle = try dir.handle.makeOpenPath(d_sym_path, .{});
378 defer d_sym_bundle.close();
379
380 const d_sym_file = try d_sym_bundle.createFile(sub_path, .{
381 .truncate = false,
382 .read = true,
383 });
384
385 self.d_sym = .{
386 .base = self,
387 .file = d_sym_file,
388 };
389 }
378390
379 // Index 0 is always a null symbol.391 // Index 0 is always a null symbol.
380 try self.locals.append(allocator, .{392 try self.locals.append(allocator, .{
...@@ -387,7 +399,7 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio...@@ -387,7 +399,7 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio
387399
388 switch (options.output_mode) {400 switch (options.output_mode) {
389 .Exe => {},401 .Exe => {},
390 .Obj => {},402 .Obj => return error.TODOImplementWritingObjFiles,
391 .Lib => return error.TODOImplementWritingLibFiles,403 .Lib => return error.TODOImplementWritingLibFiles,
392 }404 }
393405