Debugging a Quick Look plugin

EDIT SIP prevents you from debugging protected processes. Because of that, it is currently (at least since SIP was introduced, through Mojave) impossible to debug QuickLook plugins without turning off SIP, at least partially.


As you've probably discovered, since your QuickLook plugin is a plug-in instead of a standalone executable, you need to debug the process that hosts the plugin. To do that, you can hook yourself to the qlmanage executable.

The first step is to make your .qlgenerator plugin available to the Quick Look server. To do that, you need to copy it to ~/Library/QuickLook and run qlmanage -r. The first can be implemented as a post-build action, the second has to be specified in the debug options.

For the post-build action, you should follow these steps:

  1. hit Alt+Cmd+R to open the run configuration window;
  2. unfold the "Build" tab on the left and go to post-actions;
  3. click the plus at the bottom of the window and select "New Run Script Action", and use the following code.
rm -Rf "~/Library/QuickLook/$FULL_PRODUCT_NAME"
cp -R "$BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME" ~/Library/QuickLook
qlmanage -r

Then, you need to configure Xcode to launch qlmanage:

  1. in the same window, go to the "Run" tab, and select "Info";
  2. in the executable drop-down menu, pick "Other...";
  3. hit Shift+Cmd+G to enter a path, put in "/usr/bin/qlmanage", and select that file;
  4. check "Debug executable" if it isn't already;
  5. move to the "Arguments" tab, add a "-p" argument, and then add arguments as you see fit for the files that you need to preview.

Now, when you use the Run action, you'll be able to debug your plugin through qlmanage.