I've written a launchd .plist which should attach a debugger to the WindowServer when it launches. The main part of the script looks like
screen -D -m -S "WindowServer Debugger" \
gdb \
-x $GDBSCRIPT \
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreGraphics.framework/Versions/A/Resources/WindowServer \
$WSPID
This starts a detached screen session in which gdb is attached to WindowServer.
However, this seems to trigger an error condition in launchd under Snow Leopard, causing it to spout out error messages to the log:
com.apple.launchd[1] (0x10011c070.anonymous.screen[961]) Bug: launchd_core_logic.c:8250 (23932):0
com.apple.launchd[1] (0x10011c070.anonymous.screen[961]) Switching sessions is not allowed in the system Mach bootstrap.
com.apple.launchd[1] (0x10011c070.anonymous.screen[961]) _vprocmgr_switch_to_session(): kr = 0x44c
I should note that the "... not allowed in the system Mach bootstrap" messages occur regardless of how long it has been since system boot.
Is there a workaround to this so that I can spawn my screen session?
According to the manpage for launchd,
Daemons should not attempt to display UI or interact directly with a user's login session.
This might suggest that launchd is seeing this behavior as interacting with another session and denying it. The code is here but I'm not familiar with it: http://launchd.macosforge.org/trac/browser/trunk/launchd/src/launchd_core_logic.c#L8250