6

One of my projects is a System Preference Pane. With 10.11, Xcode's debugger can't debug it as I get a "can't attach to System Preferences because of System Integrity Protection".

How can I debug my prefpane under 10.11, as I have done in every OS back to 10.3?

Trygve
  • 1,317
  • 10
  • 27
  • I don't work with OS X at the moment, but [this thread on the Apple Developer Forums](https://forums.developer.apple.com/thread/8254) suggests watching [WWDC 2015 Session 706 -- "Security and Your Apps"](https://developer.apple.com/videos/wwdc/2015/?id=706). –  Sep 29 '15 at 21:54
  • There was no real mention of the issue - other than you can't attach to some processes, but without being able to attach to System Preferences, it is impossible to debug pref panes. – Trygve Sep 30 '15 at 00:57
  • And you're using Xcode 7, right? "OS X El Capitan requires Xcode 7, which includes Swift 2, native support for System Integrity Protection (SIP), app thinning, as well as the latest SDKs," and also, "If you must stay on Xcode 6 for a little while, you will need to continue to use OS X Yosemite as your development OS. ... Also note that Xcode 7 is supported on both OS X El Capitan and Yosemite." -- from [this blog entry](https://developer.apple.com/swift/blog/?id=32&utm_medium=web&utm_source=This_Week_in_Swift_55). If that doesn't help, hopefully someone else runs across this question. –  Sep 30 '15 at 01:04
  • Yes, OS X 10.11 and Xcode 7. – Trygve Sep 30 '15 at 01:29
  • My suggestion now is to try the [Apple Developer Forums](https://forums.developer.apple.com/) if you haven't already. While this community can be extremely helpful, I feel you can receive more focused attention for this particular question there. –  Sep 30 '15 at 01:39
  • 1
    Yup - I have asked there and on the Apple Mailing List. It seems someone at Apple just forgot about this situation while they were locking all the doors in the system. – Trygve Sep 30 '15 at 02:01
  • Actually, I'm using Xcode 6.4 for development on OS X.11, without special problems, for months now. We can't move to Xcode 7 because it drops SDK 10.9 that we depend on for compatibility. I don't know who wrote that blog, but this is incorrect. – Motti Shneor Jan 12 '16 at 16:14

2 Answers2

8

I ended up making a copy of System Preferences, called it "System Preferences (Signed)" and then signed it with my DeveloperID which replaces the old code signature and allows it to run normally without SIP getting in the way.

Trygve
  • 1,317
  • 10
  • 27
  • 1
    That works. For future reference: `codesign -s "My Codesign" -f /Applications/System\ Preferences\ \(signed\).app/` – Maurizio Dec 08 '16 at 13:50
  • 1
    Note that you may not even need a code signing identity. Ad-hoc signing was sufficient for me to debug Console.app. Use `codesign -s - -f /path/to/Whatever.app` to sign ad-hoc. – rob mayoff Oct 23 '18 at 22:26
  • This no longer works in 10.15. See: https://stackoverflow.com/questions/58704469/debug-system-pref-pane-w-10-15-and-system-integrity-protection – Trygve Nov 05 '19 at 04:25
0

After creating your PreferencePane project edit the build scheme, select the Run scheme on the left list and on the argument tab add an environment variable using + button (variable OBJC_DISABLE_GC and value YES).

Then choose Pre-Actions on the left list and add

cp -Rf ${CONFIGURATION_BUILD_DIR}/BuildOutputPrefPane.prefPane ~/Library/PreferencePanes

Then choose Run on the left list and choose the System Preference.app as Executable from the info tab.

Build your solution and go to build output and install your Preference Pane by clicking on it and replace existing one.

Run you project with the right scheme now if you put a breakpoint in you app and use the installed Preference Pane it works, logging work too.

This work for Swift too.

Tested with Xcode 7.1.1, EL Capitan and Swift 2 language. Enjoy

Hugo Pereira
  • 396
  • 3
  • 10
  • 1
    Nope. Doing this I still get "Message from debugger: cannot attach to process due to System Integrity Protection" Apple's DTS said the only solution is to turn SIP off. – Trygve Dec 14 '15 at 21:52
  • Maybe you compromised, or lowered SIP before doing this? – Motti Shneor Jan 12 '16 at 16:20
  • Same issue for me (macOS 10.12.2, Swift 3), and I have definitely not modified SIP in any way. – mgadda Dec 23 '16 at 18:25