如何在OS X中调试屏保

时间:2022-12-20 02:45:35

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?

我想知道是否有什么像样的方法,除了NSLog-ing几乎所有的东西——在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

“屏幕保护程序”是Xcode中的一个项目类型,但是显然没有构建和调试。此外,我发现实际上我的包被加载到。

/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.

那么是否有一种合适的方法来调试代码呢?查看崩溃报告和对控制台的无口号是有帮助的,但它远不是完美的。

8 个解决方案

#1


10  

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.

有一篇老的MacTech文章描述了屏幕保护程序的开发周期。这篇文章还有第二部分。请看“调试提示”部分。

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.

我发现这种方法很痛苦,所以我编写了一个应用程序,基本的应用程序是一个窗口和一个控制器,它用我的新屏幕保护程序包初始化了一个ScreenSaverView。一旦它开始工作,我所要做的就是在Xcode中点击Command-R。

#2


6  

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,并使用远程调试,这样您的用户界面操作就不会干扰屏幕保护程序。

#3


4  

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.

由于OS X 10.11 El Capitan的系统完整性保护特性,调试器不能连接到任何从/System/运行的东西。另外,这里的其他信息也适用于旧版本的Xcode。

Here's how I got it working on El Capitan with Xcode 7.2:

下面是我如何在El Capitan上使用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. 复制/系统/图书馆/框架/ ScreenSaver.framework /版本/ /资源/ ScreenSaverEngine.app / / tmp /。(因为.xcscheme引用了完全限定的路径,所以将它复制到某个公共的路径是最适合协作的,而不是复制到某个特定用户的主目录中的某个地方。)
  3. 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).
    • 将其运行操作的可执行文件设置为复制的应用程序,并添加参数:-debug -background -module“ ”(其中 是没有.saver扩展名的bundle名称)。
    • 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/
    • 添加一个预动作脚本(下面的源代码),它的shell设置为/bin/bash,它的构建设置来自scheme。它创建一个符号链接到~/Library/Screen saver中的build .saver绑定包
  4. 编辑项目的.xcscheme:将其运行操作的可执行文件设置为复制的应用程序,并添加参数:-debug -background -module“ ”(其中 是没有.saver扩展名的bundle名称)。添加一个预动作脚本(下面的源代码),它的shell设置为/bin/bash,它的构建设置来自scheme。它创建一个符号链接到~/Library/Screen saver中的build .saver绑定包

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.

现在,当您点击Xcode的运行按钮时,屏幕保护程序将在您的桌面的墙纸模式下运行,您可以使用调试器。

#4


3  

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).

您还可以将屏幕保护引擎('/System/Library/ framework/ screensaver .framework/Resources/ screensaverengineering .app')作为目标可执行文件,并将其传递为-background标志(因此它运行在所有内容后面,而不是在所有内容前面)。

#5


2  

As Peter says, you can debug the plugin by executing an application that will load the plugin.

正如Peter所说,可以通过执行加载插件的应用程序来调试插件。

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.

它并不完美,因为您的视图不会是完整的,但是它比设置远程调试要容易。

#6


2  

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).

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

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):

为了避免在每次构建之后将构建产品复制到“~/Library/Screen saver /”,您可以添加一个自定义构建脚本(注意:我对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

Then set its input file to "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}" and its output file to "${HOME}/Library/Screen Savers/${FULL_PRODUCT_NAME}".

然后将其输入文件设置为“${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}”,其输出文件设置为“${HOME}/Library/Screen saver /${FULL_PRODUCT_NAME}”。

Now when you build / run your project it will auto-magicly link to your debug build or copy your release build.

现在,当您构建/运行项目时,它将自动链接到您的调试构建或复制您的发布构建。

#7


1  

not necessarily the best way, but you could ssh in from another machine and launch ScreenSaverEngine from gdb (untested)

不一定是最好的方法,但是您可以从另一台机器上ssh并从gdb上启动ScreenSaverEngine(未经测试)

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

此外,您还可以尝试添加一个新的应用程序目标,并将您的ScreenSaverView添加到IB中的一个窗口中,您可能需要手动配置设置之类的内容,但这可能会有所帮助,因为ScreenSaverView是NSView的一个子类

#8


0  

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.

如果您复制了ScreenSaverEngine应用程序,并使用开发人员ID签名,它将修复系统完整性保护阻止附加调试器的情况。只需确保将可执行文件设置为自签名的副本。

#1


10  

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.

有一篇老的MacTech文章描述了屏幕保护程序的开发周期。这篇文章还有第二部分。请看“调试提示”部分。

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.

我发现这种方法很痛苦,所以我编写了一个应用程序,基本的应用程序是一个窗口和一个控制器,它用我的新屏幕保护程序包初始化了一个ScreenSaverView。一旦它开始工作,我所要做的就是在Xcode中点击Command-R。

#2


6  

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,并使用远程调试,这样您的用户界面操作就不会干扰屏幕保护程序。

#3


4  

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.

由于OS X 10.11 El Capitan的系统完整性保护特性,调试器不能连接到任何从/System/运行的东西。另外,这里的其他信息也适用于旧版本的Xcode。

Here's how I got it working on El Capitan with Xcode 7.2:

下面是我如何在El Capitan上使用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. 复制/系统/图书馆/框架/ ScreenSaver.framework /版本/ /资源/ ScreenSaverEngine.app / / tmp /。(因为.xcscheme引用了完全限定的路径,所以将它复制到某个公共的路径是最适合协作的,而不是复制到某个特定用户的主目录中的某个地方。)
  3. 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).
    • 将其运行操作的可执行文件设置为复制的应用程序,并添加参数:-debug -background -module“ ”(其中 是没有.saver扩展名的bundle名称)。
    • 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/
    • 添加一个预动作脚本(下面的源代码),它的shell设置为/bin/bash,它的构建设置来自scheme。它创建一个符号链接到~/Library/Screen saver中的build .saver绑定包
  4. 编辑项目的.xcscheme:将其运行操作的可执行文件设置为复制的应用程序,并添加参数:-debug -background -module“ ”(其中 是没有.saver扩展名的bundle名称)。添加一个预动作脚本(下面的源代码),它的shell设置为/bin/bash,它的构建设置来自scheme。它创建一个符号链接到~/Library/Screen saver中的build .saver绑定包

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.

现在,当您点击Xcode的运行按钮时,屏幕保护程序将在您的桌面的墙纸模式下运行,您可以使用调试器。

#4


3  

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).

您还可以将屏幕保护引擎('/System/Library/ framework/ screensaver .framework/Resources/ screensaverengineering .app')作为目标可执行文件,并将其传递为-background标志(因此它运行在所有内容后面,而不是在所有内容前面)。

#5


2  

As Peter says, you can debug the plugin by executing an application that will load the plugin.

正如Peter所说,可以通过执行加载插件的应用程序来调试插件。

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.

它并不完美,因为您的视图不会是完整的,但是它比设置远程调试要容易。

#6


2  

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).

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

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):

为了避免在每次构建之后将构建产品复制到“~/Library/Screen saver /”,您可以添加一个自定义构建脚本(注意:我对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

Then set its input file to "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}" and its output file to "${HOME}/Library/Screen Savers/${FULL_PRODUCT_NAME}".

然后将其输入文件设置为“${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}”,其输出文件设置为“${HOME}/Library/Screen saver /${FULL_PRODUCT_NAME}”。

Now when you build / run your project it will auto-magicly link to your debug build or copy your release build.

现在,当您构建/运行项目时,它将自动链接到您的调试构建或复制您的发布构建。

#7


1  

not necessarily the best way, but you could ssh in from another machine and launch ScreenSaverEngine from gdb (untested)

不一定是最好的方法,但是您可以从另一台机器上ssh并从gdb上启动ScreenSaverEngine(未经测试)

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

此外,您还可以尝试添加一个新的应用程序目标,并将您的ScreenSaverView添加到IB中的一个窗口中,您可能需要手动配置设置之类的内容,但这可能会有所帮助,因为ScreenSaverView是NSView的一个子类

#8


0  

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.

如果您复制了ScreenSaverEngine应用程序,并使用开发人员ID签名,它将修复系统完整性保护阻止附加调试器的情况。只需确保将可执行文件设置为自签名的副本。