Can not debug zig with helix (lldb lldb-dap)

I’m using helix as my main editor writing zig. Most of time experiences ars nice like highliting, lsp, code navigation …, except for debugging. When launching debug whith binary, I got a Failed to start debug client: server closed the stream message.

Here is my environment:

  • zig: 0.15.2
  • zls: 0.15.0
  • lldb(dap): 21.1.4
  • helix: 25.07.1 (a05c151b)

Files:

// src/main.zig

const std = @import("std");

pub fn main() !void {
    // Prints to stderr, ignoring potential errors.
    const str = "codebase";
    std.debug.print("All your {s} are belong to us.\n", .{str});
}

test "simple test" {
    const gpa = std.testing.allocator;
    var list: std.ArrayList(i32) = .empty;
    defer list.deinit(gpa); // Try commenting this out and see if zig detects the memory leak!
    try list.append(gpa, 42);
    try std.testing.expectEqual(@as(i32, 42), list.pop());
}

test "fuzz example" {
    const Context = struct {
        fn testOne(context: @This(), input: []const u8) anyerror!void {
            _ = context;
            // Try passing `--fuzz` to `zig build test` and see if it manages to fail this test case!
            try std.testing.expect(!std.mem.eql(u8, "canyoufindme", input));
        }
    };
    try std.testing.fuzz(Context{}, Context.testOne, .{});
}
// build.zig

const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});

    const optimize = b.standardOptimizeOption(.{});

    const exe = b.addExecutable(.{
        .name = "demo",
        .root_module = b.createModule(.{
            .root_source_file = b.path("src/main.zig"),

            .target = target,
            .optimize = optimize,
        }),
        .use_llvm = true,
    });

    b.installArtifact(exe);

    const run_step = b.step("run", "Run the app");

    const run_cmd = b.addRunArtifact(exe);
    run_step.dependOn(&run_cmd.step);

    run_cmd.step.dependOn(b.getInstallStep());

    if (b.args) |args| {
        run_cmd.addArgs(args);
    }

    const exe_tests = b.addTest(.{
        .root_module = exe.root_module,
        .use_llvm = true,
    });

    b.installArtifact(exe_tests);

    const run_exe_tests = b.addRunArtifact(exe_tests);

    const test_step = b.step("test", "Run tests");
    test_step.dependOn(&run_exe_tests.step);
}

But I can debug binary with only lldb successfully.

Screen shots:

Hello @dacec354
Welcome to ziggit :slight_smile:

Helix debugging support is experimental.
The problem seams resolved fix(helix-dap): seq number must start at 1 by likle · Pull Request #14706 · helix-editor/helix · GitHub but the fix is not released yet.

2 Likes

thanks very much. So I needs switching to master branch and the issue is supposed to be solved. I’ll try later.

I explained how I do it, but with nightly compilation, I don’t have any problems.

I prefer debugging with direct calls to llbd.