mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-07 22:34:28 +00:00
Merge pull request #13719 from Vexu/debug
Improve debuggability of programs built by the self hosted compiler
This commit is contained in:
parent
c2ad78922a
commit
aa7e65d5ba
5 changed files with 33 additions and 3 deletions
|
|
@ -142,6 +142,8 @@ pub fn main() !void {
|
||||||
return usageAndErr(builder, false, stderr_stream);
|
return usageAndErr(builder, false, stderr_stream);
|
||||||
};
|
};
|
||||||
try debug_log_scopes.append(next_arg);
|
try debug_log_scopes.append(next_arg);
|
||||||
|
} else if (mem.eql(u8, arg, "--debug-compile-errors")) {
|
||||||
|
builder.debug_compile_errors = true;
|
||||||
} else if (mem.eql(u8, arg, "--glibc-runtimes")) {
|
} else if (mem.eql(u8, arg, "--glibc-runtimes")) {
|
||||||
builder.glibc_runtimes_dir = nextArg(args, &arg_idx) orelse {
|
builder.glibc_runtimes_dir = nextArg(args, &arg_idx) orelse {
|
||||||
std.debug.print("Expected argument after --glibc-runtimes\n\n", .{});
|
std.debug.print("Expected argument after --glibc-runtimes\n\n", .{});
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ pub const Builder = struct {
|
||||||
pkg_config_pkg_list: ?(PkgConfigError![]const PkgConfigPkg) = null,
|
pkg_config_pkg_list: ?(PkgConfigError![]const PkgConfigPkg) = null,
|
||||||
args: ?[][]const u8 = null,
|
args: ?[][]const u8 = null,
|
||||||
debug_log_scopes: []const []const u8 = &.{},
|
debug_log_scopes: []const []const u8 = &.{},
|
||||||
|
debug_compile_errors: bool = false,
|
||||||
|
|
||||||
/// Experimental. Use system Darling installation to run cross compiled macOS build artifacts.
|
/// Experimental. Use system Darling installation to run cross compiled macOS build artifacts.
|
||||||
enable_darling: bool = false,
|
enable_darling: bool = false,
|
||||||
|
|
@ -2674,6 +2675,10 @@ pub const LibExeObjStep = struct {
|
||||||
try zig_args.append(log_scope);
|
try zig_args.append(log_scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (builder.debug_compile_errors) {
|
||||||
|
try zig_args.append("--debug-compile-errors");
|
||||||
|
}
|
||||||
|
|
||||||
if (builder.verbose_cimport) zig_args.append("--verbose-cimport") catch unreachable;
|
if (builder.verbose_cimport) zig_args.append("--verbose-cimport") catch unreachable;
|
||||||
if (builder.verbose_air) zig_args.append("--verbose-air") catch unreachable;
|
if (builder.verbose_air) zig_args.append("--verbose-air") catch unreachable;
|
||||||
if (builder.verbose_llvm_ir) zig_args.append("--verbose-llvm-ir") catch unreachable;
|
if (builder.verbose_llvm_ir) zig_args.append("--verbose-llvm-ir") catch unreachable;
|
||||||
|
|
|
||||||
12
src/Sema.zig
12
src/Sema.zig
|
|
@ -2091,10 +2091,16 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError {
|
||||||
@setCold(true);
|
@setCold(true);
|
||||||
|
|
||||||
if (crash_report.is_enabled and sema.mod.comp.debug_compile_errors) {
|
if (crash_report.is_enabled and sema.mod.comp.debug_compile_errors) {
|
||||||
std.debug.print("compile error during Sema: {s}, src: {s}:{}\n", .{
|
const err_path = err_msg.src_loc.file_scope.fullPath(sema.mod.gpa) catch unreachable;
|
||||||
|
const err_source = err_msg.src_loc.file_scope.getSource(sema.mod.gpa) catch unreachable;
|
||||||
|
const err_span = err_msg.src_loc.span(sema.mod.gpa) catch unreachable;
|
||||||
|
const err_loc = std.zig.findLineColumn(err_source.bytes, err_span.main);
|
||||||
|
std.debug.print("compile error during Sema:\n{s}:{d}:{d}: error: {s}\n{s}\n\n", .{
|
||||||
|
err_path,
|
||||||
|
err_loc.line + 1,
|
||||||
|
err_loc.column + 1,
|
||||||
err_msg.msg,
|
err_msg.msg,
|
||||||
err_msg.src_loc.file_scope.sub_file_path,
|
err_loc.source_line,
|
||||||
err_msg.src_loc.lazy,
|
|
||||||
});
|
});
|
||||||
crash_report.compilerPanic("unexpected compile error occurred", null, null);
|
crash_report.compilerPanic("unexpected compile error occurred", null, null);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6090,6 +6090,12 @@ pub const FuncGen = struct {
|
||||||
const insert_block = self.builder.getInsertBlock();
|
const insert_block = self.builder.getInsertBlock();
|
||||||
if (isByRef(operand_ty)) {
|
if (isByRef(operand_ty)) {
|
||||||
_ = dib.insertDeclareAtEnd(operand, di_local_var, debug_loc, insert_block);
|
_ = dib.insertDeclareAtEnd(operand, di_local_var, debug_loc, insert_block);
|
||||||
|
} else if (self.dg.module.comp.bin_file.options.optimize_mode == .Debug) {
|
||||||
|
const alignment = operand_ty.abiAlignment(self.dg.module.getTarget());
|
||||||
|
const alloca = self.buildAlloca(operand.typeOf(), alignment);
|
||||||
|
const store_inst = self.builder.buildStore(operand, alloca);
|
||||||
|
store_inst.setAlignment(alignment);
|
||||||
|
_ = dib.insertDeclareAtEnd(alloca, di_local_var, debug_loc, insert_block);
|
||||||
} else {
|
} else {
|
||||||
_ = dib.insertDbgValueIntrinsicAtEnd(operand, di_local_var, debug_loc, insert_block);
|
_ = dib.insertDbgValueIntrinsicAtEnd(operand, di_local_var, debug_loc, insert_block);
|
||||||
}
|
}
|
||||||
|
|
@ -8028,6 +8034,12 @@ pub const FuncGen = struct {
|
||||||
const insert_block = self.builder.getInsertBlock();
|
const insert_block = self.builder.getInsertBlock();
|
||||||
if (isByRef(inst_ty)) {
|
if (isByRef(inst_ty)) {
|
||||||
_ = dib.insertDeclareAtEnd(arg_val, di_local_var, debug_loc, insert_block);
|
_ = dib.insertDeclareAtEnd(arg_val, di_local_var, debug_loc, insert_block);
|
||||||
|
} else if (self.dg.module.comp.bin_file.options.optimize_mode == .Debug) {
|
||||||
|
const alignment = inst_ty.abiAlignment(self.dg.module.getTarget());
|
||||||
|
const alloca = self.buildAlloca(arg_val.typeOf(), alignment);
|
||||||
|
const store_inst = self.builder.buildStore(arg_val, alloca);
|
||||||
|
store_inst.setAlignment(alignment);
|
||||||
|
_ = dib.insertDeclareAtEnd(alloca, di_local_var, debug_loc, insert_block);
|
||||||
} else {
|
} else {
|
||||||
_ = dib.insertDbgValueIntrinsicAtEnd(arg_val, di_local_var, debug_loc, insert_block);
|
_ = dib.insertDbgValueIntrinsicAtEnd(arg_val, di_local_var, debug_loc, insert_block);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3752,6 +3752,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
|
||||||
var override_global_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_GLOBAL_CACHE_DIR");
|
var override_global_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_GLOBAL_CACHE_DIR");
|
||||||
var override_local_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LOCAL_CACHE_DIR");
|
var override_local_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LOCAL_CACHE_DIR");
|
||||||
var child_argv = std.ArrayList([]const u8).init(arena);
|
var child_argv = std.ArrayList([]const u8).init(arena);
|
||||||
|
var debug_compile_errors = false;
|
||||||
|
|
||||||
const argv_index_exe = child_argv.items.len;
|
const argv_index_exe = child_argv.items.len;
|
||||||
_ = try child_argv.addOne();
|
_ = try child_argv.addOne();
|
||||||
|
|
@ -3807,6 +3808,9 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
|
||||||
try child_argv.append(arg);
|
try child_argv.append(arg);
|
||||||
} else if (mem.eql(u8, arg, "-fno-reference-trace")) {
|
} else if (mem.eql(u8, arg, "-fno-reference-trace")) {
|
||||||
try child_argv.append(arg);
|
try child_argv.append(arg);
|
||||||
|
} else if (mem.eql(u8, arg, "--debug-compile-errors")) {
|
||||||
|
try child_argv.append(arg);
|
||||||
|
debug_compile_errors = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try child_argv.append(arg);
|
try child_argv.append(arg);
|
||||||
|
|
@ -3940,6 +3944,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
|
||||||
.thread_pool = &thread_pool,
|
.thread_pool = &thread_pool,
|
||||||
.use_stage1 = use_stage1,
|
.use_stage1 = use_stage1,
|
||||||
.cache_mode = .whole,
|
.cache_mode = .whole,
|
||||||
|
.debug_compile_errors = debug_compile_errors,
|
||||||
}) catch |err| {
|
}) catch |err| {
|
||||||
fatal("unable to create compilation: {s}", .{@errorName(err)});
|
fatal("unable to create compilation: {s}", .{@errorName(err)});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue