When I attempt to compile my program after trimming down all the stuff zig.build needs to do, I finally get a much mroe constrained, but unhelpful, fault after running commands manually:
$ zig build-exe src/main.zig -I/usr/include
zsh: segmentation fault (core dumped) zig build-exe src/main.zig -I/usr/include
What’s my next step to try to debug this?
Presumably I have to go build a debug version of Zig somehow so that I can at least run gdb/lldb and get a backtrace as to where it’s blowing up?
This video is a bit older, but hopefully it should help you get started:
Did you explain how to build a debug “zig” executable and I missed it? My issue is that zig is segfaulting and gdb doesn’t seem to even give me a useful backtrace without a debug build.
I’m currently following the instructions from “zig-bootstrap” to build from source, but I do not see any references to what to tweak to make a debug build.
Okay, looking at this: Goodbye to the C++ Implementation of Zig ⚡ Zig Programming Language
I apparently need to inject “-DCMAKE_BUILD_TYPE=Debug” everywhere in the build.sh file where there currently is “-DCMAKE_BUILD_TYPE=Release”.
I’ll see if I can bootstrap this …
Ah, sorry, I misunderstood your initial question. I thought you were looking for information regarding how to use gdb with Zig and were looking for an example.
And yes, if the cmake build flags are set to release, they’ll alter the behaviour of the C ecosystem. Unfortunately the cmake flags are very poorly documented but it’s generally excepted that you’ll need to be building with debug flags to do get you’re looking for.
I’m going to edit the title of your post to include this because I think it will help direct people to this post.
Right now, there seems to be some issue bootstrapping Zig. Given that 0.11 is imminent, I’ll come back and revisit this after the release.
There is no point in annoying people when the issue may very well just disappear in a few days.
So to get a debug build of Zig you need to:
beware that building LLVM will take a bit, but thankfully it’s not something that has to be done too often.
That was … quite painful. But I produced a backtrace finally. I’ll try to cut down to a smaller test case.
Issue filed: Compiler crash in llvm.zig:6310 · Issue #16698 · ziglang/zig · GitHub