authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-21 02:00:33-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-21 02:00:33-05:00
log623466762eba820f263a40622d70dc46ba0cb8ab
tree39d7e4f1b945d562c68702233877f62279e9bf89
parent2b35615ffbe238c8ec421654a7e1ae0890477fe0

clean up mach-o stack trace code


1 files changed, 9 insertions(+), 16 deletions(-)

std/macho.zig+9-16
......@@ -88,7 +88,7 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable
8888 try file.seekTo(0);
8989
9090 var hdr: MachHeader64 = undefined;
91 try readNoEof(in, &hdr);
91 try readOneNoEof(in, MachHeader64, &hdr);
9292 if (hdr.magic != MH_MAGIC_64) return error.MissingDebugInfo;
9393 const is_pie = MH_PIE == (hdr.flags & MH_PIE);
9494
......@@ -97,7 +97,7 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable
9797 while (ncmd != 0) : (ncmd -= 1) {
9898 try file.seekTo(pos);
9999 var lc: LoadCommand = undefined;
100 try readNoEof(in, &lc);
100 try readOneNoEof(in, LoadCommand, &lc);
101101 if (lc.cmd == LC_SYMTAB) break;
102102 pos += lc.cmdsize;
103103 } else {
......@@ -105,12 +105,12 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable
105105 }
106106
107107 var cmd: SymtabCommand = undefined;
108 try readNoEof(in, &cmd);
108 try readOneNoEof(in, SymtabCommand, &cmd);
109109
110110 try file.seekTo(cmd.symoff);
111111 var syms = try allocator.alloc(Nlist64, cmd.nsyms);
112112 defer allocator.free(syms);
113 try readNoEof(in, syms);
113 try readNoEof(in, Nlist64, syms);
114114
115115 try file.seekTo(cmd.stroff);
116116 var strings = try allocator.alloc(u8, cmd.strsize);
......@@ -158,18 +158,11 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable
158158 };
159159}
160160
161fn readNoEof(in: &io.FileInStream, sink: var) !void {
162 if (@typeOf(sink) == []Nlist64) {
163 const T = @typeOf(sink[0]);
164 const len = @sizeOf(T) * sink.len;
165 const bytes = @ptrCast(&u8, &sink[0]);
166 return in.stream.readNoEof(bytes[0..len]);
167 } else {
168 const T = @typeOf(*sink);
169 const len = @sizeOf(T);
170 const bytes = @ptrCast(&u8, sink);
171 return in.stream.readNoEof(bytes[0..len]);
172 }
161fn readNoEof(in: &io.FileInStream, comptime T: type, result: []T) !void {
162 return in.stream.readNoEof(([]u8)(result));
163}
164fn readOneNoEof(in: &io.FileInStream, comptime T: type, result: &T) !void {
165 return readNoEof(in, T, result[0..1]);
173166}
174167
175168fn isSymbol(sym: &const Nlist64) bool {