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…