authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-24 19:14:54-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-26 20:56:21-07:00
log396bd51c4818752f6309ff10f2d316f41598d5cd
tree452bc2f332c7a3ee6ab9d0274582b4b9da6800d6
parentafbcad9939169f0b9b9b8ecb287718023c58b428

enable debugging infrastructure when using C backend

Thanks to @jacobly0's recent enhancements to the C backend, this stuff works now.

4 files changed, 9 insertions(+), 17 deletions(-)

lib/std/builtin.zig+1-2
...@@ -868,8 +868,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr...@@ -868,8 +868,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr
868868
869 // For backends that cannot handle the language features depended on by the869 // For backends that cannot handle the language features depended on by the
870 // default panic handler, we have a simpler panic handler:870 // default panic handler, we have a simpler panic handler:
871 if (builtin.zig_backend == .stage2_c or871 if (builtin.zig_backend == .stage2_wasm or
872 builtin.zig_backend == .stage2_wasm or
873 builtin.zig_backend == .stage2_arm or872 builtin.zig_backend == .stage2_arm or
874 builtin.zig_backend == .stage2_aarch64 or873 builtin.zig_backend == .stage2_aarch64 or
875 builtin.zig_backend == .stage2_x86_64 or874 builtin.zig_backend == .stage2_x86_64 or
lib/std/debug.zig+2-12
...@@ -1360,13 +1360,7 @@ pub const DebugInfo = struct {...@@ -1360,13 +1360,7 @@ pub const DebugInfo = struct {
1360 }1360 }
13611361
1362 pub fn getModuleForAddress(self: *DebugInfo, address: usize) !*ModuleDebugInfo {1362 pub fn getModuleForAddress(self: *DebugInfo, address: usize) !*ModuleDebugInfo {
1363 if (builtin.zig_backend == .stage2_c) {1363 if (comptime builtin.target.isDarwin()) {
1364 return @as(error{
1365 InvalidDebugInfo,
1366 MissingDebugInfo,
1367 UnsupportedBackend,
1368 }, error.UnsupportedBackend);
1369 } else if (comptime builtin.target.isDarwin()) {
1370 return self.lookupModuleDyld(address);1364 return self.lookupModuleDyld(address);
1371 } else if (native_os == .windows) {1365 } else if (native_os == .windows) {
1372 return self.lookupModuleWin32(address);1366 return self.lookupModuleWin32(address);
...@@ -1380,9 +1374,7 @@ pub const DebugInfo = struct {...@@ -1380,9 +1374,7 @@ pub const DebugInfo = struct {
1380 }1374 }
13811375
1382 pub fn getModuleNameForAddress(self: *DebugInfo, address: usize) ?[]const u8 {1376 pub fn getModuleNameForAddress(self: *DebugInfo, address: usize) ?[]const u8 {
1383 if (builtin.zig_backend == .stage2_c) {1377 if (comptime builtin.target.isDarwin()) {
1384 return null;
1385 } else if (comptime builtin.target.isDarwin()) {
1386 return null;1378 return null;
1387 } else if (native_os == .windows) {1379 } else if (native_os == .windows) {
1388 return self.lookupModuleNameWin32(address);1380 return self.lookupModuleNameWin32(address);
...@@ -2191,8 +2183,6 @@ pub fn dumpStackPointerAddr(prefix: []const u8) void {...@@ -2191,8 +2183,6 @@ pub fn dumpStackPointerAddr(prefix: []const u8) void {
2191}2183}
21922184
2193test "manage resources correctly" {2185test "manage resources correctly" {
2194 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // error.UnsupportedBackend
2195
2196 if (builtin.os.tag == .wasi) return error.SkipZigTest;2186 if (builtin.os.tag == .wasi) return error.SkipZigTest;
21972187
2198 if (builtin.os.tag == .windows and builtin.cpu.arch == .x86_64) {2188 if (builtin.os.tag == .windows and builtin.cpu.arch == .x86_64) {
lib/std/os.zig+4-2
...@@ -5371,8 +5371,10 @@ pub fn dl_iterate_phdr(...@@ -5371,8 +5371,10 @@ pub fn dl_iterate_phdr(
5371) Error!void {5371) Error!void {
5372 const Context = @TypeOf(context);5372 const Context = @TypeOf(context);
53735373
5374 if (builtin.object_format != .elf)5374 switch (builtin.object_format) {
5375 @compileError("dl_iterate_phdr is not available for this target");5375 .elf, .c => {},
5376 else => @compileError("dl_iterate_phdr is not available for this target"),
5377 }
53765378
5377 if (builtin.link_libc) {5379 if (builtin.link_libc) {
5378 switch (system.dl_iterate_phdr(struct {5380 switch (system.dl_iterate_phdr(struct {
src/Module.zig+2-1
...@@ -6629,7 +6629,8 @@ pub fn backendSupportsFeature(mod: Module, feature: Feature) bool {...@@ -6629,7 +6629,8 @@ pub fn backendSupportsFeature(mod: Module, feature: Feature) bool {
6629 mod.comp.bin_file.options.use_llvm,6629 mod.comp.bin_file.options.use_llvm,
6630 .panic_unwrap_error => mod.comp.bin_file.options.target.ofmt == .c or6630 .panic_unwrap_error => mod.comp.bin_file.options.target.ofmt == .c or
6631 mod.comp.bin_file.options.use_llvm,6631 mod.comp.bin_file.options.use_llvm,
6632 .safety_check_formatted => mod.comp.bin_file.options.use_llvm,6632 .safety_check_formatted => mod.comp.bin_file.options.target.ofmt == .c or
6633 mod.comp.bin_file.options.use_llvm,
6633 .error_return_trace => mod.comp.bin_file.options.use_llvm,6634 .error_return_trace => mod.comp.bin_file.options.use_llvm,
6634 .is_named_enum_value => mod.comp.bin_file.options.use_llvm,6635 .is_named_enum_value => mod.comp.bin_file.options.use_llvm,
6635 .error_set_has_value => mod.comp.bin_file.options.use_llvm or mod.comp.bin_file.options.target.isWasm(),6636 .error_set_has_value => mod.comp.bin_file.options.use_llvm or mod.comp.bin_file.options.target.isWasm(),