如何在 OS X 中调试屏幕保护程序
我想知道除了 NSLog-ing 之外,是否还有其他好的方法可以在 OS X 中正确调试屏幕保护程序应用程序包?
“Screensaver”是Xcode中的一个项目类型,但显然没有Build and Go调试。 此外,我发现实际上我的包正在
/System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app
作为某种插件加载到应用程序中。
那么有没有一种好的方法来调试你的代码呢? 查看崩溃报告和 NSLog-ing 到控制台有帮助,但它远非完美。
I was wondering if there was any decent way, other than NSLog-ing just about everything - to properly debug a Screensaver app bundle in OS X?
The "Screensaver" is a project type in Xcode, but there's obviously no Build and Go debugging. Further, I've found that in fact my bundle is getting loaded in to the
/System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app
application as some sort of plugin.
So is there a decent way to debug your code? Looking at crash reports and NSLog-ing to the console helps, but it's far from perfect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
您还可以使屏幕保护程序引擎('/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app')成为目标可执行文件并传递 -background 标志(因此它在所有内容后面运行,而不是在所有内容前面运行) 。
You could also make the screensaver engine ('/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app') the target executable and pass it the -background flag (so it runs behind everything instead of in front of everything).
正如 Peter 所说,您可以通过执行加载插件的应用程序来调试插件。
但是,您还可以使用系统首选项,而不是使用屏幕保护程序引擎。 当出现首选项时,导航到“桌面和屏幕保护程序”下的屏幕保护程序以加载插件。
它并不完美,因为您的视图不会是全尺寸的,但它比设置远程调试更容易。
As Peter says, you can debug the plugin by executing an application that will load the plugin.
However, rather than using the screensaver engine you could also use system preferences. When the preferences appear navigate to your screensaver under "Desktop & Screen Saver" to load your plugin.
It's not perfect as your view won't be full size, but it can be easier than setting up remote debugging.
不一定是最好的方法,但您可以从另一台计算机 ssh 并从 gdb 启动 ScreenSaverEngine(未经测试)
编辑:
另外,您可以尝试添加新的应用程序目标并将 ScreenSaverView 添加到 IB 中的窗口,您可能需要手动配置诸如设置之类的东西,但它可以帮助一些人,并且应该可以正常工作,因为 ScreenSaverView 是 NSView 的子类
not necessarily the best way, but you could ssh in from another machine and launch ScreenSaverEngine from gdb (untested)
edit:
also, you could try adding a new application target and add your ScreenSaverView to a window in IB, you may have to manually configure stuff like settings, but it could help some and should probably work OK as ScreenSaverView is a subclass of NSView
如果您制作 ScreenSaverEngine 应用程序的副本,并使用您的开发人员 ID 对其进行签名,它将修复系统完整性保护阻止附加调试器的情况。 只需确保将可执行文件设置为您自己签名的副本即可。
If you make a copy of the ScreenSaverEngine app, and sign it with your Developer ID, it will fix the situation where System Integrity Protection prevents attaching the debugger. Just make sure to set the executable to your own-signed copy.
我想指出@Karl 的解决方案最适合我。
但是,如果您像我一样每天晚上重新启动计算机,您可能需要考虑
添加: cp -Rn /System/Library/CoreServices/ScreenSaverEngine.app /tmp
在 pre 的开头 -在他的回答中提到构建shell脚本。 这将自动为您执行复制步骤。
(虽然我相信这确实属于评论,但我的经验还不够高)
I would like to note that @Karl's solution worked the best for me.
However, if you are like me and you reboot your computer every night you may want to think about putting:
cp -Rn /System/Library/CoreServices/ScreenSaverEngine.app /tmp
at the beginning of the pre-Build shell script mentioned in his answer. This will automatically do the copying step for you.
(though I believe this really belongs in a comment, my xp is not yet high enough)
有一篇旧的 MacTech 文章描述了屏幕保护程序的开发循环。 该文章还有第 2 部分。 查看“调试提示”部分。
我发现这种方法很痛苦,所以我编写了一个应用程序,基本应用程序是一个窗口和一个控制器,它用我的新屏幕保护程序包初始化了 ScreenSaverView。 一旦它开始工作,我所要做的就是在 Xcode 中按下 Command-R 来测试更改。
There is an old MacTech article that describes the Screen Saver development cycle. There is also a Part 2 to the article. Look in the "Debugging Tips" section.
I find this method a pain so I wrote an application, the basic application was one window and a controller that initialized a ScreenSaverView with my new screensaver bundle. Once that was working all I had to do to test a change was hit Command-R in Xcode.
由于 OS X 10.11 El Capitan 的系统完整性保护功能,调试器无法附加到从
/System/
运行的任何内容。 此外,此处的其他信息适用于旧版本的 Xcode。以下是我如何使用 Xcode 7.2 在 El Capitan 上工作:
/System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app/
复制到/tmp/< /代码>。 (由于 .xcscheme 引用完全限定路径,因此将其复制到某个公共位置最适合协作,而不是复制到特定用户主目录中的某个位置。)
.xcscheme
:-debug
-background
-module "; "
(其中
是不带.saver
扩展名的捆绑包名称)。/bin/bash
,其构建设置来自该方案。 它会创建一个指向~/Library/Screen Savers/
中构建的
.saver
包的符号链接来源:
现在,当您点击 Xcode 的“运行”按钮时,屏幕保护程序将在桌面上的壁纸模式,并且可以使用调试器。
Because of OS X 10.11 El Capitan's System Integrity Protection feature, the debugger can't attach to anything running from
/System/
. Also, the other info here applies to old versions of Xcode.Here's how I got it working on El Capitan with Xcode 7.2:
/System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app/
to/tmp/
. (Since the .xcscheme references the fully-qualified path, copying it to someplace common is best for collaboration, instead of to somewhere in a particular user's home directory.).xcscheme
:-debug
-background
-module "<product-name>"
(where<product-name>
is the bundle name without the.saver
extension)./bin/bash
and its build settings to come from the scheme. It creates a symbolic link to the built.saver
bundle in~/Library/Screen Savers/
Source:
Now, when you hit Xcode's Run button, the screen saver will run in wallpaper mode on your Desktop, and you can use the debugger.
您可以通过执行将加载插件的应用程序来调试插件。
因此,要调试屏幕保护程序,请打开插件项目,从“项目”菜单中选择“新建自定义可执行文件”,然后将应用程序设置为屏幕保护程序引擎。
为了调试屏幕保护程序,您可能还想使用第二台 Mac 并使用 远程调试,以便您的用户界面操作不会干扰屏幕保护程序。
You can debug plugins by executing the application that will load the plugin.
So to debug a screensaver, open your plugin project, choose New Custom Executable from the Project menu and set the application to be the screensaver engine.
For debugging a screensaver, you might also want to use a second Mac and use remote debugging so your user interface actions don't interfere with the screensaver.
有一些 Mac OS X 应用程序可以运行屏幕保护程序:SaverLab、Screenalicious 等。
只需在网上找到其中一个并下载它,然后将其设置为目标可执行文件(正如 Peter N Lewis 所说)。
为了避免在每次构建后将构建产品复制到“~/Library/Screen Savers/”,您可以添加自定义构建脚本(注意:我在 shell 中使用“/bin/tcsh -x”):
然后设置其输入文件保存到“${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}”,其输出文件保存到“${HOME}/Library/Screen Savers/${FULL_PRODUCT_NAME}”。
现在,当您构建/运行项目时,它将自动神奇地链接到您的调试版本或复制您的发布版本。
There's a few Mac OS X apps that will run screen savers: SaverLab, Screenalicious, etc.
Just find one of them on the web and download it and then set it as the target executable (as Peter N Lewis said).
To avoid copying the build product to '~/Library/Screen Savers/' after each build you can add a custom build script (note: I'm using '/bin/tcsh -x' for the shell):
Then set its input file to "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}" and its output file to "${HOME}/Library/Screen Savers/${FULL_PRODUCT_NAME}".
Now when you build / run your project it will auto-magicly link to your debug build or copy your release build.