authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-07 20:31:50-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-07 20:31:50-04:00
logced3aae3b2371479c01b4abba42c751697185d7b
tree63445ec62935209ab2c551bf258277b6c0440cd3
parentd8295c188946b0f07d62420c2f08c940f70b03ac

cleaner output from zig build when there are compile errors


2 files changed, 47 insertions(+), 24 deletions(-)

std/debug/index.zig+41-21
......@@ -156,7 +156,7 @@ pub fn writeStackTrace(stack_trace: *const builtin.StackTrace, out_stream: var,
156156 frame_index = (frame_index + 1) % stack_trace.instruction_addresses.len;
157157 }) {
158158 const return_address = stack_trace.instruction_addresses[frame_index];
159 try printSourceAtAddress(debug_info, out_stream, return_address);
159 try printSourceAtAddress(debug_info, out_stream, return_address, tty_color);
160160 }
161161}
162162
......@@ -189,13 +189,11 @@ pub fn writeCurrentStackTrace(out_stream: var, allocator: *mem.Allocator, debug_
189189 }
190190 },
191191 }
192 try printSourceAtAddress(debug_info, out_stream, return_address);
192 try printSourceAtAddress(debug_info, out_stream, return_address, tty_color);
193193 }
194194}
195195
196fn printSourceAtAddress(debug_info: *ElfStackTrace, out_stream: var, address: usize) !void {
197 const ptr_hex = "0x{x}";
198
196fn printSourceAtAddress(debug_info: *ElfStackTrace, out_stream: var, address: usize, tty_color: bool) !void {
199197 switch (builtin.os) {
200198 builtin.Os.windows => return error.UnsupportedDebugInfo,
201199 builtin.Os.macosx => {
......@@ -209,36 +207,58 @@ fn printSourceAtAddress(debug_info: *ElfStackTrace, out_stream: var, address: us
209207 .address = address,
210208 };
211209 const symbol = debug_info.symbol_table.search(address) orelse &unknown;
212 try out_stream.print(WHITE ++ "{}" ++ RESET ++ ": " ++ DIM ++ ptr_hex ++ " in ??? (???)" ++ RESET ++ "\n", symbol.name, address);
210 try out_stream.print(WHITE ++ "{}" ++ RESET ++ ": " ++ DIM ++ "0x{x}" ++ " in ??? (???)" ++ RESET ++ "\n", symbol.name, address);
213211 },
214212 else => {
215213 const compile_unit = findCompileUnit(debug_info, address) catch {
216 try out_stream.print("???:?:?: " ++ DIM ++ ptr_hex ++ " in ??? (???)" ++ RESET ++ "\n ???\n\n", address);
214 if (tty_color) {
215 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n ???\n\n", address);
216 } else {
217 try out_stream.print("???:?:?: 0x{x} in ??? (???)\n ???\n\n", address);
218 }
217219 return;
218220 };
219221 const compile_unit_name = try compile_unit.die.getAttrString(debug_info, DW.AT_name);
220222 if (getLineNumberInfo(debug_info, compile_unit, address - 1)) |line_info| {
221223 defer line_info.deinit();
222 try out_stream.print(WHITE ++ "{}:{}:{}" ++ RESET ++ ": " ++ DIM ++ ptr_hex ++ " in ??? ({})" ++ RESET ++ "\n", line_info.file_name, line_info.line, line_info.column, address, compile_unit_name);
223 if (printLineFromFile(debug_info.allocator(), out_stream, line_info)) {
224 if (line_info.column == 0) {
225 try out_stream.write("\n");
226 } else {
227 {
228 var col_i: usize = 1;
229 while (col_i < line_info.column) : (col_i += 1) {
230 try out_stream.writeByte(' ');
224 if (tty_color) {
225 try out_stream.print(
226 WHITE ++ "{}:{}:{}" ++ RESET ++ ": " ++ DIM ++ "0x{x} in ??? ({})" ++ RESET ++ "\n",
227 line_info.file_name,
228 line_info.line,
229 line_info.column,
230 address,
231 compile_unit_name,
232 );
233 if (printLineFromFile(debug_info.allocator(), out_stream, line_info)) {
234 if (line_info.column == 0) {
235 try out_stream.write("\n");
236 } else {
237 {
238 var col_i: usize = 1;
239 while (col_i < line_info.column) : (col_i += 1) {
240 try out_stream.writeByte(' ');
241 }
231242 }
243 try out_stream.write(GREEN ++ "^" ++ RESET ++ "\n");
232244 }
233 try out_stream.write(GREEN ++ "^" ++ RESET ++ "\n");
245 } else |err| switch (err) {
246 error.EndOfFile => {},
247 else => return err,
234248 }
235 } else |err| switch (err) {
236 error.EndOfFile => {},
237 else => return err,
249 } else {
250 try out_stream.print(
251 "{}:{}:{}: 0x{x} in ??? ({})\n",
252 line_info.file_name,
253 line_info.line,
254 line_info.column,
255 address,
256 compile_unit_name,
257 );
238258 }
239259 } else |err| switch (err) {
240260 error.MissingDebugInfo, error.InvalidDebugInfo => {
241 try out_stream.print(ptr_hex ++ " in ??? ({})\n", address, compile_unit_name);
261 try out_stream.print("0x{x} in ??? ({})\n", address, compile_unit_name);
242262 },
243263 else => return err,
244264 }
std/special/build_runner.zig+6-3
......@@ -122,10 +122,13 @@ pub fn main() !void {
122122 return usageAndErr(&builder, true, try stderr_stream);
123123
124124 builder.make(targets.toSliceConst()) catch |err| {
125 if (err == error.InvalidStepName) {
126 return usageAndErr(&builder, true, try stderr_stream);
125 switch (err) {
126 error.InvalidStepName => {
127 return usageAndErr(&builder, true, try stderr_stream);
128 },
129 error.UncleanExit => os.exit(1),
130 else => return err,
127131 }
128 return err;
129132 };
130133}
131134