In the "Mach Services" section of the xpc_connection_create(3) man page, we have the following:
Important: New service names may NOT be dynamically registered using xpc_connection_create_mach_service(). Only launchd jobs may listen on certain service names, and any service name that the job wishes to listen on must be declared in its launchd.plist(5). XPC may make allowances for dynamic name registration in debug scenarios, but these allowances abso- lutely will NOT be made in the production scenario.
In a debugging scenario, how can I allow a dynamic name resolution for listeners? While the man page references this, it doesn't detail how to, and I can't find any information online about this. I can't tell if this text implies that it's currently possible, or may be allowed sometime in the future.
running
xpc_connection_create_mach_service
does not work in a debug environment since the provided name is not found within the bootstrap namespace.
That’s interesting, but there are definitely circumstances where folks get mislead by Xcode’s behaviour.
However, I'm attempting to debug it by writing up a small "demo" program where I can easily debug and run the XPC listener code.
Are you trying to debug the XPC aspects of your code? If so, I recommend that you do this in a single process using an anonymous listener. See TN3113 Testing and debugging XPC code with an anonymous listener.
If you’re trying to debug other aspects of your launchd
job, my advice is:
-
If the code does not need to run in the
launchd
context, factor it out into a unit test and debug it there. -
If it does, start the code using
launchd
and attach to it. That’s the only way to ensure that the code is running in exactly the right context.In this case, check out
WaitForDebugger
in thelaunchd.plist
man page.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"