| author | |
| committer | |
| log | 34f96c5fd068aeadfdbd1630fdea44fda2af1fdf |
| tree | 903f8785c8a87a62e1541edaabb16c1249439eab |
| parent | 44ee1c885f056eb8d7163a6b455af5c268a83a76 |
| parent | fb4a5ccdeeddf56a0849b4168fe7a9525f36b107 |
| signature |
Improve debuggability of programs built by the self hosted compiler5 files changed, 33 insertions(+), 3 deletions(-)
lib/build_runner.zig+2| ... | @@ -142,6 +142,8 @@ pub fn main() !void { | ... | @@ -142,6 +142,8 @@ pub fn main() !void { |
| 142 | return usageAndErr(builder, false, stderr_stream); | 142 | return usageAndErr(builder, false, stderr_stream); |
| 143 | }; | 143 | }; |
| 144 | try debug_log_scopes.append(next_arg); | 144 | try debug_log_scopes.append(next_arg); |
| 145 | } else if (mem.eql(u8, arg, "--debug-compile-errors")) { | ||
| 146 | builder.debug_compile_errors = true; | ||
| 145 | } else if (mem.eql(u8, arg, "--glibc-runtimes")) { | 147 | } else if (mem.eql(u8, arg, "--glibc-runtimes")) { |
| 146 | builder.glibc_runtimes_dir = nextArg(args, &arg_idx) orelse { | 148 | builder.glibc_runtimes_dir = nextArg(args, &arg_idx) orelse { |
| 147 | std.debug.print("Expected argument after --glibc-runtimes\n\n", .{}); | 149 | std.debug.print("Expected argument after --glibc-runtimes\n\n", .{}); |
lib/std/build.zig+5| ... | @@ -72,6 +72,7 @@ pub const Builder = struct { | ... | @@ -72,6 +72,7 @@ pub const Builder = struct { |
| 72 | pkg_config_pkg_list: ?(PkgConfigError![]const PkgConfigPkg) = null, | 72 | pkg_config_pkg_list: ?(PkgConfigError![]const PkgConfigPkg) = null, |
| 73 | args: ?[][]const u8 = null, | 73 | args: ?[][]const u8 = null, |
| 74 | debug_log_scopes: []const []const u8 = &.{}, | 74 | debug_log_scopes: []const []const u8 = &.{}, |
| 75 | debug_compile_errors: bool = false, | ||
| 75 | 76 | ||
| 76 | /// Experimental. Use system Darling installation to run cross compiled macOS build artifacts. | 77 | /// Experimental. Use system Darling installation to run cross compiled macOS build artifacts. |
| 77 | enable_darling: bool = false, | 78 | enable_darling: bool = false, |
| ... | @@ -2686,6 +2687,10 @@ pub const LibExeObjStep = struct { | ... | @@ -2686,6 +2687,10 @@ pub const LibExeObjStep = struct { |
| 2686 | try zig_args.append(log_scope); | 2687 | try zig_args.append(log_scope); |
| 2687 | } | 2688 | } |
| 2688 | 2689 | ||
| 2690 | if (builder.debug_compile_errors) { | ||
| 2691 | try zig_args.append("--debug-compile-errors"); | ||
| 2692 | } | ||
| 2693 | |||
| 2689 | if (builder.verbose_cimport) zig_args.append("--verbose-cimport") catch unreachable; | 2694 | if (builder.verbose_cimport) zig_args.append("--verbose-cimport") catch unreachable; |
| 2690 | if (builder.verbose_air) zig_args.append("--verbose-air") catch unreachable; | 2695 | if (builder.verbose_air) zig_args.append("--verbose-air") catch unreachable; |
| 2691 | if (builder.verbose_llvm_ir) zig_args.append("--verbose-llvm-ir") catch unreachable; | 2696 | if (builder.verbose_llvm_ir) zig_args.append("--verbose-llvm-ir") catch unreachable; |
src/Sema.zig+9-3| ... | @@ -2189,10 +2189,16 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { | ... | @@ -2189,10 +2189,16 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { |
| 2189 | @setCold(true); | 2189 | @setCold(true); |
| 2190 | 2190 | ||
| 2191 | if (crash_report.is_enabled and sema.mod.comp.debug_compile_errors) { | 2191 | if (crash_report.is_enabled and sema.mod.comp.debug_compile_errors) { |
| 2192 | std.debug.print("compile error during Sema: {s}, src: {s}:{}\n", .{ | 2192 | const err_path = err_msg.src_loc.file_scope.fullPath(sema.mod.gpa) catch unreachable; |
| 2193 | const err_source = err_msg.src_loc.file_scope.getSource(sema.mod.gpa) catch unreachable; | ||
| 2194 | const err_span = err_msg.src_loc.span(sema.mod.gpa) catch unreachable; | ||
| 2195 | const err_loc = std.zig.findLineColumn(err_source.bytes, err_span.main); | ||
| 2196 | std.debug.print("compile error during Sema:\n{s}:{d}:{d}: error: {s}\n{s}\n\n", .{ | ||
| 2197 | err_path, | ||
| 2198 | err_loc.line + 1, | ||
| 2199 | err_loc.column + 1, | ||
| 2193 | err_msg.msg, | 2200 | err_msg.msg, |
| 2194 | err_msg.src_loc.file_scope.sub_file_path, | 2201 | err_loc.source_line, |
| 2195 | err_msg.src_loc.lazy, | ||
| 2196 | }); | 2202 | }); |
| 2197 | crash_report.compilerPanic("unexpected compile error occurred", null, null); | 2203 | crash_report.compilerPanic("unexpected compile error occurred", null, null); |
| 2198 | } | 2204 | } |
src/codegen/llvm.zig+12| ... | @@ -6088,6 +6088,12 @@ pub const FuncGen = struct { | ... | @@ -6088,6 +6088,12 @@ pub const FuncGen = struct { |
| 6088 | const insert_block = self.builder.getInsertBlock(); | 6088 | const insert_block = self.builder.getInsertBlock(); |
| 6089 | if (isByRef(operand_ty)) { | 6089 | if (isByRef(operand_ty)) { |
| 6090 | _ = dib.insertDeclareAtEnd(operand, di_local_var, debug_loc, insert_block); | 6090 | _ = dib.insertDeclareAtEnd(operand, di_local_var, debug_loc, insert_block); |
| 6091 | } else if (self.dg.module.comp.bin_file.options.optimize_mode == .Debug) { | ||
| 6092 | const alignment = operand_ty.abiAlignment(self.dg.module.getTarget()); | ||
| 6093 | const alloca = self.buildAlloca(operand.typeOf(), alignment); | ||
| 6094 | const store_inst = self.builder.buildStore(operand, alloca); | ||
| 6095 | store_inst.setAlignment(alignment); | ||
| 6096 | _ = dib.insertDeclareAtEnd(alloca, di_local_var, debug_loc, insert_block); | ||
| 6091 | } else { | 6097 | } else { |
| 6092 | _ = dib.insertDbgValueIntrinsicAtEnd(operand, di_local_var, debug_loc, insert_block); | 6098 | _ = dib.insertDbgValueIntrinsicAtEnd(operand, di_local_var, debug_loc, insert_block); |
| 6093 | } | 6099 | } |
| ... | @@ -8026,6 +8032,12 @@ pub const FuncGen = struct { | ... | @@ -8026,6 +8032,12 @@ pub const FuncGen = struct { |
| 8026 | const insert_block = self.builder.getInsertBlock(); | 8032 | const insert_block = self.builder.getInsertBlock(); |
| 8027 | if (isByRef(inst_ty)) { | 8033 | if (isByRef(inst_ty)) { |
| 8028 | _ = dib.insertDeclareAtEnd(arg_val, di_local_var, debug_loc, insert_block); | 8034 | _ = dib.insertDeclareAtEnd(arg_val, di_local_var, debug_loc, insert_block); |
| 8035 | } else if (self.dg.module.comp.bin_file.options.optimize_mode == .Debug) { | ||
| 8036 | const alignment = inst_ty.abiAlignment(self.dg.module.getTarget()); | ||
| 8037 | const alloca = self.buildAlloca(arg_val.typeOf(), alignment); | ||
| 8038 | const store_inst = self.builder.buildStore(arg_val, alloca); | ||
| 8039 | store_inst.setAlignment(alignment); | ||
| 8040 | _ = dib.insertDeclareAtEnd(alloca, di_local_var, debug_loc, insert_block); | ||
| 8029 | } else { | 8041 | } else { |
| 8030 | _ = dib.insertDbgValueIntrinsicAtEnd(arg_val, di_local_var, debug_loc, insert_block); | 8042 | _ = dib.insertDbgValueIntrinsicAtEnd(arg_val, di_local_var, debug_loc, insert_block); |
| 8031 | } | 8043 | } |
src/main.zig+5| ... | @@ -3778,6 +3778,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi | ... | @@ -3778,6 +3778,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi |
| 3778 | var override_local_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LOCAL_CACHE_DIR"); | 3778 | var override_local_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LOCAL_CACHE_DIR"); |
| 3779 | var child_argv = std.ArrayList([]const u8).init(arena); | 3779 | var child_argv = std.ArrayList([]const u8).init(arena); |
| 3780 | var reference_trace: ?u32 = null; | 3780 | var reference_trace: ?u32 = null; |
| 3781 | var debug_compile_errors = false; | ||
| 3781 | 3782 | ||
| 3782 | const argv_index_exe = child_argv.items.len; | 3783 | const argv_index_exe = child_argv.items.len; |
| 3783 | _ = try child_argv.addOne(); | 3784 | _ = try child_argv.addOne(); |
| ... | @@ -3839,6 +3840,9 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi | ... | @@ -3839,6 +3840,9 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi |
| 3839 | } else if (mem.eql(u8, arg, "-fno-reference-trace")) { | 3840 | } else if (mem.eql(u8, arg, "-fno-reference-trace")) { |
| 3840 | try child_argv.append(arg); | 3841 | try child_argv.append(arg); |
| 3841 | reference_trace = null; | 3842 | reference_trace = null; |
| 3843 | } else if (mem.eql(u8, arg, "--debug-compile-errors")) { | ||
| 3844 | try child_argv.append(arg); | ||
| 3845 | debug_compile_errors = true; | ||
| 3842 | } | 3846 | } |
| 3843 | } | 3847 | } |
| 3844 | try child_argv.append(arg); | 3848 | try child_argv.append(arg); |
| ... | @@ -3973,6 +3977,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi | ... | @@ -3973,6 +3977,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi |
| 3973 | .use_stage1 = use_stage1, | 3977 | .use_stage1 = use_stage1, |
| 3974 | .cache_mode = .whole, | 3978 | .cache_mode = .whole, |
| 3975 | .reference_trace = reference_trace, | 3979 | .reference_trace = reference_trace, |
| 3980 | .debug_compile_errors = debug_compile_errors, | ||
| 3976 | }) catch |err| { | 3981 | }) catch |err| { |
| 3977 | fatal("unable to create compilation: {s}", .{@errorName(err)}); | 3982 | fatal("unable to create compilation: {s}", .{@errorName(err)}); |
| 3978 | }; | 3983 | }; |