Debugging Zig code in Xcode for Apple iOS

I integrated a small Zig library in the build of our iOS app. Unfortunately, I get now a crash where the test works fine. Usually, this is no big thing – just start the debugger and find out what’s going on. But in this case the iOS app is inside Xcode, and while this IDE uses lldb the version it uses does not support debugging Zig code.

How do others here solve the problem using Zig for iOS?

it might be tougher if the app is running in a simulator (just because i don’t know to what extent the process name is or isn’t available to you, for example), but the command line lldb works for debugging Zig on macOS and can attach to a running process with one of a couple command line arguments.

I debug Zig code on macOS, too. But the problem is on iOS, and yes, the app runs in the simulator (or on a real iOS device, respectively). On macOS I use vim, so I don’t have Xcode running.

it sounds like either you didn’t read my proposed solution correctly or i didn’t understand that there’s something wrong with it. we’re outside my experience, so i don’t know which it is!

If I’m following: Your post gave advice for macOS but they are asking about iOS (macOS works for them).

2 Likes

oh, it sounds like the crash only occurs on-device and not in the simulator? my mistake

I test in the simulator. So what I take from what you’re saying is that debugging in Xcode does not work. Somehow, I have to disconnect the debugger from Xcode and manually connect a debugger from command line, which I most likely have to compile myself and get it to work. Is that what you’re saying?

interestingly, still no! what i had in mind was: run your code in the simulator (just “run”, i guess?) and then simultaneously in a terminal window, open stock lldb, don’t compile it oommggg, and then attach to your app in the simulator. that last bit i haven’t done, so i don’t know what hurdles you’ll run into. for non-simulated apps, i’ve had great success attaching lldb by using one of its command-line arguments to target a running process.

3 Likes

Thank you for clarifying this! I’m used to attach processes with gdb and lldb from command line. The additional problem of the iOS simulator is that it has its own platform, which must be supported by a debugger – and I am not sure if standard lldb on macOS does that. I’m developing on an M1 machine, and the simulator is aarch64-apple-ios-sim. If no-one knows a trick how to get Xcode to work I’ll try that if it is the only option, but it is a lot of work for a few lines of Zig code in a library.

That seems to be supported. Thank you, @alanza

1 Like