Zig Version
0.16.0-dev.11+01b502386
Steps to Reproduce and Observed Behavior
Make this simple zig project on x86_64 Linux:
//build.zig
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const mod = b.addModule("zig_repro", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
});
const mod_tests = b.addTest(.{
.root_module = mod,
});
const run_mod_tests = b.addRunArtifact(mod_tests);
const test_step = b.step("test", "Run tests");
test_step.dependOn(&run_mod_tests.step);
}
//src/root.zig
//! By convention, root.zig is the root source file when making a library.
const std = @import("std");
pub fn bufferedPrint() !void {
// Stdout is for the actual output of your application, for example if you
// are implementing gzip, then only the compressed bytes should be sent to
// stdout, not any debugging messages.
var stdout_buffer: [1024]u8 = undefined;
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
const stdout = &stdout_writer.interface;
try stdout.print("Run `zig build test` to run the tests.\n", .{});
try stdout.flush(); // Don't forget to flush!
}
pub fn add(a: i32, b: i32) i32 {
return a + b;
}
test "basic add functionality" {
try std.testing.expect(add(3, 7) == 10);
}
Run a zig build test to generate a test executable in ./zig-cache. Find that executable in something like ./.zig-cache/o/4b05f9f63a9dee57fa29fdff781ea789/test.
Try to debug the tests with gdb or lldb. Something like:
$ lldb .zig-cache/o/4b05f9f63a9dee57fa29fdff781ea789/test
(lldb) target create ".zig-cache/o/4b05f9f63a9dee57fa29fdff781ea789/test"
Current executable set to '/home/chris/Code/tapestry-research/zig-repro/.zig-cache/o/4b05f9f63a9dee57fa29fdff781ea789/test' (x86_64).
(lldb) b add
Breakpoint 1: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
(lldb)
Now add .use_llvm=true to the mod_tests declaration in build.zig like this:
const mod_tests = b.addTest(.{
.root_module = mod,
.use_llvm = true,
});
Rerun zig build test to regenerate a test executable and try to debug the new executable (at its new path):
$ lldb .zig-cache/o/8f960bbd12346026c6882d2732508bad/test
(lldb) target create ".zig-cache/o/8f960bbd12346026c6882d2732508bad/test"
Current executable set to '/home/chris/Code/tapestry-research/zig-repro/.zig-cache/o/8f960bbd12346026c6882d2732508bad/test' (x86_64).
(lldb) b add
Breakpoint 1: where = test`root.add + 12 at root.zig:17:32, address = 0x0000000001035d4c
(lldb)
Expected Behavior
I expected the debugger to be able to set breakpoints in code generated by the new x86_64 backend. I couldn't find any existing issues that seemed to cover this. I apologize if I missed one. The closest related thing seems like #21719, but that's specific to macOS, whereas I'm on Linux.
Zig Version
0.16.0-dev.11+01b502386
Steps to Reproduce and Observed Behavior
Make this simple zig project on x86_64 Linux:
Run a
zig build testto generate a test executable in./zig-cache. Find that executable in something like./.zig-cache/o/4b05f9f63a9dee57fa29fdff781ea789/test.Try to debug the tests with
gdborlldb. Something like:Now add
.use_llvm=trueto themod_testsdeclaration inbuild.ziglike this:Rerun
zig build testto regenerate a test executable and try to debug the new executable (at its new path):Expected Behavior
I expected the debugger to be able to set breakpoints in code generated by the new x86_64 backend. I couldn't find any existing issues that seemed to cover this. I apologize if I missed one. The closest related thing seems like #21719, but that's specific to macOS, whereas I'm on Linux.