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...@@ -88,7 +88,7 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable
88 try file.seekTo(0);88 try file.seekTo(0);
8989
90 var hdr: MachHeader64 = undefined;90 var hdr: MachHeader64 = undefined;
91 try readNoEof(in, &hdr);91 try readOneNoEof(in, MachHeader64, &hdr);
92 if (hdr.magic != MH_MAGIC_64) return error.MissingDebugInfo;92 if (hdr.magic != MH_MAGIC_64) return error.MissingDebugInfo;
93 const is_pie = MH_PIE == (hdr.flags & MH_PIE);93 const is_pie = MH_PIE == (hdr.flags & MH_PIE);
9494
...@@ -97,7 +97,7 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable...@@ -97,7 +97,7 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable
97 while (ncmd != 0) : (ncmd -= 1) {97 while (ncmd != 0) : (ncmd -= 1) {
98 try file.seekTo(pos);98 try file.seekTo(pos);
99 var lc: LoadCommand = undefined;99 var lc: LoadCommand = undefined;
100 try readNoEof(in, &lc);100 try readOneNoEof(in, LoadCommand, &lc);
101 if (lc.cmd == LC_SYMTAB) break;101 if (lc.cmd == LC_SYMTAB) break;
102 pos += lc.cmdsize;102 pos += lc.cmdsize;
103 } else {103 } else {
...@@ -105,12 +105,12 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable...@@ -105,12 +105,12 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable
105 }105 }
106106
107 var cmd: SymtabCommand = undefined;107 var cmd: SymtabCommand = undefined;
108 try readNoEof(in, &cmd);108 try readOneNoEof(in, SymtabCommand, &cmd);
109109
110 try file.seekTo(cmd.symoff);110 try file.seekTo(cmd.symoff);
111 var syms = try allocator.alloc(Nlist64, cmd.nsyms);111 var syms = try allocator.alloc(Nlist64, cmd.nsyms);
112 defer allocator.free(syms);112 defer allocator.free(syms);
113 try readNoEof(in, syms);113 try readNoEof(in, Nlist64, syms);
114114
115 try file.seekTo(cmd.stroff);115 try file.seekTo(cmd.stroff);
116 var strings = try allocator.alloc(u8, cmd.strsize);116 var strings = try allocator.alloc(u8, cmd.strsize);
...@@ -158,18 +158,11 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable...@@ -158,18 +158,11 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable
158 };158 };
159}159}
160160
161fn readNoEof(in: &io.FileInStream, sink: var) !void {161fn readNoEof(in: &io.FileInStream, comptime T: type, result: []T) !void {
162 if (@typeOf(sink) == []Nlist64) {162 return in.stream.readNoEof(([]u8)(result));
163 const T = @typeOf(sink[0]);163}
164 const len = @sizeOf(T) * sink.len;164fn readOneNoEof(in: &io.FileInStream, comptime T: type, result: &T) !void {
165 const bytes = @ptrCast(&u8, &sink[0]);165 return readNoEof(in, T, result[0..1]);
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 }
173}166}
174167
175fn isSymbol(sym: &const Nlist64) bool {168fn isSymbol(sym: &const Nlist64) bool {