'Debugging Quicklook Plugin in Xcode

I am trying to debug a quicklook plugin in Xcode 4.6. I have created the executable in Edit Scheme.

Now, when I build the project the plugin is not installed to the "/Library/Quicklook" path. Rather I didn't find it anywhere.

I want to run the plugin in debug mode and want to hit the breakpoints so that I can figure out where the plugin crashes on different files.



Solution 1:[1]

You can use brake points and NSLog function for debugging QL plugin. But first you need to configure environment.

  • Select your project on Project Navigator
  • Then select QL plugin target
  • Go to 'Build Phases' tab and add new phase 'Copy files'
  • Select 'Absolute Path' on destination drop down menu and set ~/Library/QuickLook as subpath
  • Open terminal and copy qlmanage to your project's root directory with command cp /usr/bin/qlmanage PROJECT_ROOT_DIR
  • Then select menu Product -> Scheme -> Edit Scheme...
  • Select 'Run' on schemes list
  • On info tab select executable drop down menu, then 'Other...' and select qlmanage binary you have copied to project's root directory
  • On arguments tab add row for 'Arguments Passed On Launch' and set value to -p FULL_PATH_TO_FILE_FOR_PREVIEW

After all steps you can run your project and debug your code.

Solution 2:[2]

Xcode 6 must be different somehow, because the instructions above didn't work for me. But here's a solution that I puzzled out today and that works. Hopefuly it will help someone else.

(Assume the name of your plugin is myplugin.qlgenerator)

First of all, if you tried the earlier solutions above, undo them.

  1. Delete the Copy Phase that copies your binary to ~/Library/Quicklook and delete the copy of qlmanage you may have copied to your project's root.

Set the Executable to /usr/bin/qlmanage. "qlmanage" is the program that will load and run your plugin.

  1. Edit your scheme.

  2. Choose 'Run' from the list on the left, then the Info tab of the display on the right.

  3. Choose 'Other...' from the Executable popup. A standard file sheet will appear.

  4. Type cmd-shift-g. A 'Go to folder' sheet appears with a text field.

  5. Enter /usr/bin/ and hit the Go button. The standard file sheet should now be showing the contents of /usr/bin.

  6. Select the 'qlmanage' binary

  7. Turn on the 'Debug executable' checkbox and click the Choose button.

Configure the Arguments Xcode passes to qlmanage

  1. Select the Arguments tab in the Run section of the Edit Schemes sheet.

  2. Remove any arguments that may be left over from previous attempts.

  3. Add -c public.data as the first argument to be passed on launch. You may need to change this depending on the kind of UTIs your plugin supports.

  4. Add -g $(BUILD_DIR)/Debug/myplugin.qlgenerator as the second argument. This resolves to a path to the debug version of your plugin.

  5. Add -p '/fullpath/to/file/to/be/quicklooked as the third argument. This is a path to a file that should already exist. Your plugin will be asked to render previews of this file.

  6. Close the Schemes sheet.

That's it. You should now be able to debug your pluging including setting (and hitting) breakpoints!

Solution 3:[3]

I've written this blog post describing how to debug Quick Look plugins which should work as of Xcode 8.2 / macOS 10.12.

Giving due credit, this is basically the steps given here by mlist0987 but with an extra step to get around the System Integrity Protection introduced in 10.11.

TLDR: you have to take a copy of the version of qlmanage, referenced by the link in /usr/bin (i.e. don't just copy the alias) and set that as the debugging executable.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Besi
Solution 2
Solution 3 Community