No symbol in LLDB debugger

I’m trying to debug a small zig program while learning the language. From other posts I tried to use lldb, but it seems to find no main function nor other symbols.

This is the simple program I’m using as a test (copied from one of the tutorials).

const std = @import("std");

pub fn rot(txt: []u8, key: u8) void {
    for (txt, 0..txt.len) |c, i| {
        if (std.ascii.isLower(c)) {
            txt[i] = (c - 'a' + key) % 26 + 'a';
        } else if (std.ascii.isUpper(c)) {
            txt[i] = (c - 'A' + key) % 26 + 'A';
        }
    }
}

pub fn main() !void {
    const key = 3;
    var txt = "The five boxing wizards jump quickly".*;

    std.debug.print("Original:  {s}\n", .{txt});
    rot(&txt, key);
    std.debug.print("Encrypted: {s}\n", .{txt});
    rot(&txt, 26 - key);
    std.debug.print("Decrypted: {s}\n", .{txt});
}

Then in the terminal I’m running

# compile
zig build-exe src/main.zig

# run lldb
lldb main

Inside lldb

(lldb) target create "main"
Current executable set to '/tmp/my_test/main' (x86_64).
(lldb) b main
Breakpoint 1: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.

I’m obtaining a really similar output from gdb.

Some info on the system:

  • Zig compiler 0.15.2
  • LLDB 20.1.8
  • OS: Linux / Fedora workstation 42
  • Kernel 6.16.10-200.fc42

Am I missing something? Is there any other way to debug a zig program? I tried also VsCode with CodeLLDB extension, but the editor shows an error saying that the extension is invalid…

1 Like

The self-hosted backend doesn’t work with the lldb/gdb. Using -fllvm flag will compile your code using the llvm backend and that should work. I think there was a fork for lldb that would work with zig’s self-hosted backend, but it hasn’t been updated in a while.

4 Likes

The fork is here: GitHub - jacobly0/llvm-project at lldb-zig

You will have to build it yourself if you want to used the zig selfhosted backend and debug it with lldb. Otherwise add the flag like @Calder-Ty said, or you can add .use_llvm = true in build.zig to your executables.

4 Likes

Thanks to both of you! It worked as you told.

The problem is that Zig no longer uses LLVM as its backend in debug mode. Therefore, the necessary debug symbols are missing. If you want to use lldb as before, you’ll have to compile Zig with -fllvm, so in your case zig build-exe -fllvm main.zig.

1 Like