How can I debug JIT-built zig tools like Aro translate-c?

I want to step through aro_translate_c.zig in a debugger to see how it works.

I have a debug build of zig and debugging the clang-based translate-c with lldb works fine, but it doesn’t work for Aro translate-c (i.e. zig translate-c -fno-clang), because this is one of the components that is not compiled into the zig binary, but lazily built when you use it, see ship even more of the compiler in source form · Issue #19063 · ziglang/zig · GitHub

ZIG_DEBUG_CMD=1 (you can discover these with zig env)

Or you can put a @breakpoint() in the code you want to debug.

Or you can run the program directly (it has a main function).

1 Like

Thank you, with ZIG_DEBUG_CMD=1 it works, and I had to tell lldb to follow the child process (settings set target.process.follow-fork-mode child).

Running it directly also works, you just need to add the aro module to build it (e.g. ../build/stage3/bin/zig build-exe --dep aro -Maro-translate-c=../lib/compiler/aro_translate_c.zig -Maro=../lib/compiler/aro/aro.zig).