| author | |
| committer | |
| log | aa7e65d5ba865132e7080b9d1c8a2fb0eb38cc28 |
| tree | 6b61d1cd513c57c4914db048162bd76802a037d2 |
| parent | c2ad78922a4df1087fb720f79ff800bd85894a8d |
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, |
| ... | @@ -2674,6 +2675,10 @@ pub const LibExeObjStep = struct { | ... | @@ -2674,6 +2675,10 @@ pub const LibExeObjStep = struct { |
| 2674 | try zig_args.append(log_scope); | 2675 | try zig_args.append(log_scope); |
| 2675 | } | 2676 | } |
| 2676 | 2677 | ||
| 2678 | if (builder.debug_compile_errors) { | ||
| 2679 | try zig_args.append("--debug-compile-errors"); | ||
| 2680 | } | ||
| 2681 | |||
| 2677 | if (builder.verbose_cimport) zig_args.append("--verbose-cimport") catch unreachable; | 2682 | if (builder.verbose_cimport) zig_args.append("--verbose-cimport") catch unreachable; |
| 2678 | if (builder.verbose_air) zig_args.append("--verbose-air") catch unreachable; | 2683 | if (builder.verbose_air) zig_args.append("--verbose-air") catch unreachable; |
| 2679 | if (builder.verbose_llvm_ir) zig_args.append("--verbose-llvm-ir") catch unreachable; | 2684 | if (builder.verbose_llvm_ir) zig_args.append("--verbose-llvm-ir") catch unreachable; |
src/Sema.zig+9-3| ... | @@ -2091,10 +2091,16 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { | ... | @@ -2091,10 +2091,16 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { |
| 2091 | @setCold(true); | 2091 | @setCold(true); |
| 2092 | 2092 | ||
| 2093 | if (crash_report.is_enabled and sema.mod.comp.debug_compile_errors) { | 2093 | if (crash_report.is_enabled and sema.mod.comp.debug_compile_errors) { |
| 2094 | std.debug.print("compile error during Sema: {s}, src: {s}:{}\n", .{ | 2094 | const err_path = err_msg.src_loc.file_scope.fullPath(sema.mod.gpa) catch unreachable; |
| 2095 | const err_source = err_msg.src_loc.file_scope.getSource(sema.mod.gpa) catch unreachable; | ||
| 2096 | const err_span = err_msg.src_loc.span(sema.mod.gpa) catch unreachable; | ||
| 2097 | const err_loc = std.zig.findLineColumn(err_source.bytes, err_span.main); | ||
| 2098 | std.debug.print("compile error during Sema:\n{s}:{d}:{d}: error: {s}\n{s}\n\n", .{ | ||
| 2099 | err_path, | ||
| 2100 | err_loc.line + 1, | ||
| 2101 | err_loc.column + 1, | ||
| 2095 | err_msg.msg, | 2102 | err_msg.msg, |
| 2096 | err_msg.src_loc.file_scope.sub_file_path, | 2103 | err_loc.source_line, |
| 2097 | err_msg.src_loc.lazy, | ||
| 2098 | }); | 2104 | }); |
| 2099 | crash_report.compilerPanic("unexpected compile error occurred", null, null); | 2105 | crash_report.compilerPanic("unexpected compile error occurred", null, null); |
| 2100 | } | 2106 | } |
src/codegen/llvm.zig+12| ... | @@ -6090,6 +6090,12 @@ pub const FuncGen = struct { | ... | @@ -6090,6 +6090,12 @@ pub const FuncGen = struct { |
| 6090 | const insert_block = self.builder.getInsertBlock(); | 6090 | const insert_block = self.builder.getInsertBlock(); |
| 6091 | if (isByRef(operand_ty)) { | 6091 | if (isByRef(operand_ty)) { |
| 6092 | _ = dib.insertDeclareAtEnd(operand, di_local_var, debug_loc, insert_block); | 6092 | _ = dib.insertDeclareAtEnd(operand, di_local_var, debug_loc, insert_block); |
| 6093 | } else if (self.dg.module.comp.bin_file.options.optimize_mode == .Debug) { | ||
| 6094 | const alignment = operand_ty.abiAlignment(self.dg.module.getTarget()); | ||
| 6095 | const alloca = self.buildAlloca(operand.typeOf(), alignment); | ||
| 6096 | const store_inst = self.builder.buildStore(operand, alloca); | ||
| 6097 | store_inst.setAlignment(alignment); | ||
| 6098 | _ = dib.insertDeclareAtEnd(alloca, di_local_var, debug_loc, insert_block); | ||
| 6093 | } else { | 6099 | } else { |
| 6094 | _ = dib.insertDbgValueIntrinsicAtEnd(operand, di_local_var, debug_loc, insert_block); | 6100 | _ = dib.insertDbgValueIntrinsicAtEnd(operand, di_local_var, debug_loc, insert_block); |
| 6095 | } | 6101 | } |
| ... | @@ -8028,6 +8034,12 @@ pub const FuncGen = struct { | ... | @@ -8028,6 +8034,12 @@ pub const FuncGen = struct { |
| 8028 | const insert_block = self.builder.getInsertBlock(); | 8034 | const insert_block = self.builder.getInsertBlock(); |
| 8029 | if (isByRef(inst_ty)) { | 8035 | if (isByRef(inst_ty)) { |
| 8030 | _ = dib.insertDeclareAtEnd(arg_val, di_local_var, debug_loc, insert_block); | 8036 | _ = dib.insertDeclareAtEnd(arg_val, di_local_var, debug_loc, insert_block); |
| 8037 | } else if (self.dg.module.comp.bin_file.options.optimize_mode == .Debug) { | ||
| 8038 | const alignment = inst_ty.abiAlignment(self.dg.module.getTarget()); | ||
| 8039 | const alloca = self.buildAlloca(arg_val.typeOf(), alignment); | ||
| 8040 | const store_inst = self.builder.buildStore(arg_val, alloca); | ||
| 8041 | store_inst.setAlignment(alignment); | ||
| 8042 | _ = dib.insertDeclareAtEnd(alloca, di_local_var, debug_loc, insert_block); | ||
| 8031 | } else { | 8043 | } else { |
| 8032 | _ = dib.insertDbgValueIntrinsicAtEnd(arg_val, di_local_var, debug_loc, insert_block); | 8044 | _ = dib.insertDbgValueIntrinsicAtEnd(arg_val, di_local_var, debug_loc, insert_block); |
| 8033 | } | 8045 | } |
src/main.zig+5| ... | @@ -3752,6 +3752,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi | ... | @@ -3752,6 +3752,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi |
| 3752 | var override_global_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_GLOBAL_CACHE_DIR"); | 3752 | var override_global_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_GLOBAL_CACHE_DIR"); |
| 3753 | var override_local_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LOCAL_CACHE_DIR"); | 3753 | var override_local_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LOCAL_CACHE_DIR"); |
| 3754 | var child_argv = std.ArrayList([]const u8).init(arena); | 3754 | var child_argv = std.ArrayList([]const u8).init(arena); |
| 3755 | var debug_compile_errors = false; | ||
| 3755 | 3756 | ||
| 3756 | const argv_index_exe = child_argv.items.len; | 3757 | const argv_index_exe = child_argv.items.len; |
| 3757 | _ = try child_argv.addOne(); | 3758 | _ = try child_argv.addOne(); |
| ... | @@ -3807,6 +3808,9 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi | ... | @@ -3807,6 +3808,9 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi |
| 3807 | try child_argv.append(arg); | 3808 | try child_argv.append(arg); |
| 3808 | } else if (mem.eql(u8, arg, "-fno-reference-trace")) { | 3809 | } else if (mem.eql(u8, arg, "-fno-reference-trace")) { |
| 3809 | try child_argv.append(arg); | 3810 | try child_argv.append(arg); |
| 3811 | } else if (mem.eql(u8, arg, "--debug-compile-errors")) { | ||
| 3812 | try child_argv.append(arg); | ||
| 3813 | debug_compile_errors = true; | ||
| 3810 | } | 3814 | } |
| 3811 | } | 3815 | } |
| 3812 | try child_argv.append(arg); | 3816 | try child_argv.append(arg); |
| ... | @@ -3940,6 +3944,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi | ... | @@ -3940,6 +3944,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi |
| 3940 | .thread_pool = &thread_pool, | 3944 | .thread_pool = &thread_pool, |
| 3941 | .use_stage1 = use_stage1, | 3945 | .use_stage1 = use_stage1, |
| 3942 | .cache_mode = .whole, | 3946 | .cache_mode = .whole, |
| 3947 | .debug_compile_errors = debug_compile_errors, | ||
| 3943 | }) catch |err| { | 3948 | }) catch |err| { |
| 3944 | fatal("unable to create compilation: {s}", .{@errorName(err)}); | 3949 | fatal("unable to create compilation: {s}", .{@errorName(err)}); |
| 3945 | }; | 3950 | }; |