Debugging a launch daemon at system start

Is it possible to debug a launchd daemon during system start except by writing log messages to the console or to a file? My gut says no but I am curious if there might exist some exotic setup, like attaching LLDB remotely to a launch daemon in the VM while it is starting up or similar.

For the curious, the question came up while struggling with running MDQueries in that scenario. It seems Metadata might not be quite ready at that particular point in the system lifecycle but being able to actually peek in there at runtime would be priceless, of course.

Replies

You can have the daemon wait for you to attach by setting WaitForDebugger in your launchd property list. See the launchd.plist man page for details.

You can then SSH into the machine and attach to the daemon using LLDb from the command line.

However, this may not be sufficient to debug your issue. If this really is a race condition with mds starting up, by the time you attach mds may be up far enough for your daemon to work.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Thanks, Quinn, I'll give it a try. I guess you're right about the race condition, though.