如何在 OS X 中调试屏幕保护程序

发布于 2024-07-26 17:26:12 字数 358 浏览 4 评论 0原文

我想知道除了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

心奴独伤 2024-08-02 17:26:13

您还可以使屏幕保护程序引擎('/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).

一个人练习一个人 2024-08-02 17:26:13

正如 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.

夏有森光若流苏 2024-08-02 17:26:13

不一定是最好的方法,但您可以从另一台计算机 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

不必你懂 2024-08-02 17:26:13

如果您制作 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.

娇妻 2024-08-02 17:26:13

我想指出@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)

土豪我们做朋友吧 2024-08-02 17:26:12

有一篇旧的 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.

葬花如无物 2024-08-02 17:26:12

由于 OS X 10.11 El Capitan 的系统完整性保护功能,调试器无法附加到从 /System/ 运行的任何内容。 此外,此处的其他信息适用于旧版本的 Xcode。

以下是我如何使用 Xcode 7.2 在 El Capitan 上工作:

  1. /System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app/ 复制到 /tmp/< /代码>。 (由于 .xcscheme 引用完全限定路径,因此将其复制到某个公共位置最适合协作,而不是复制到特定用户主目录中的某个位置。)
  2. 编辑项目的 .xcscheme
    • 将其运行操作的可执行文件设置为复制的应用程序,并添加参数:-debug -background -module "; "(其中 是不带 .saver 扩展名的捆绑包名称)。
    • 添加一个预操作脚本(来源如下),其 shell 设置为 /bin/bash ,其构建设置来自该方案。 它会创建一个指向 ~/Library/Screen Savers/
    • 中构建的 .saver 包的符号链接

来源:

SCREEN_SAVER_PATH="${HOME}/Library/Screen Savers/${FULL_PRODUCT_NAME}"
if [[ -d "${SCREEN_SAVER_PATH}" || -f "${SCREEN_SAVER_PATH}" || -L "${SCREEN_SAVER_PATH}" ]]; then
    rm -Rf "${SCREEN_SAVER_PATH}"
fi
ln -s "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}" "${SCREEN_SAVER_PATH}"

现在,当您点击 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:

  1. Copy /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.)
  2. Edit the project's .xcscheme:
    • Set the Executable for its Run action to the copied app, and add the arguments: -debug -background -module "<product-name>" (where <product-name> is the bundle name without the .saver extension).
    • Add a Pre-action script (source below), with its shell set to /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:

SCREEN_SAVER_PATH="${HOME}/Library/Screen Savers/${FULL_PRODUCT_NAME}"
if [[ -d "${SCREEN_SAVER_PATH}" || -f "${SCREEN_SAVER_PATH}" || -L "${SCREEN_SAVER_PATH}" ]]; then
    rm -Rf "${SCREEN_SAVER_PATH}"
fi
ln -s "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}" "${SCREEN_SAVER_PATH}"

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.

淑女气质 2024-08-02 17:26:12

您可以通过执行将加载插件的应用程序来调试插件。

因此,要调试屏幕保护程序,请打开插件项目,从“项目”菜单中选择“新建自定义可执行文件”,然后将应用程序设置为屏幕保护程序引擎。

为了调试屏幕保护程序,您可能还想使用第二台 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.

半枫 2024-08-02 17:26:12

有一些 Mac OS X 应用程序可以运行屏幕保护程序:SaverLab、Screenalicious 等。
只需在网上找到其中一个并下载它,然后将其设置为目标可执行文件(正如 Peter N Lewis 所说)。

为了避免在每次构建后将构建产品复制到“~/Library/Screen Savers/”,您可以添加自定义构建脚本(注意:我在 shell 中使用“/bin/tcsh -x”):

#remove the old screen saver or link
rm -Rf "${SCRIPT_OUTPUT_FILE_0}"

#if this is a debug build…
if ("${CONFIGURATION}" == "Debug" ) then

# create a symbolic link from our screen saver to this users screen saver directory
ln -sfv "${SCRIPT_INPUT_FILE_0}" "${SCRIPT_OUTPUT_FILE_0}"

#if this is a release build…
else if ("${CONFIGURATION}" == "Release" ) then

# copy our screen saver to this users CMM directory
cp -Rfv "${SCRIPT_INPUT_FILE_0}" "${SCRIPT_OUTPUT_FILE_0}"

endif

然后设置其输入文件保存到“${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):

#remove the old screen saver or link
rm -Rf "${SCRIPT_OUTPUT_FILE_0}"

#if this is a debug build…
if ("${CONFIGURATION}" == "Debug" ) then

# create a symbolic link from our screen saver to this users screen saver directory
ln -sfv "${SCRIPT_INPUT_FILE_0}" "${SCRIPT_OUTPUT_FILE_0}"

#if this is a release build…
else if ("${CONFIGURATION}" == "Release" ) then

# copy our screen saver to this users CMM directory
cp -Rfv "${SCRIPT_INPUT_FILE_0}" "${SCRIPT_OUTPUT_FILE_0}"

endif

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文