Debugging Quicklook Plugin in Xcode
Asked Answered
Z

3

7

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.

Zahn answered 29/5, 2013 at 10:30 Comment(1)
Official documentation: Quick Look Programming Guide - Debugging and Testing a GeneratorFatidic
B
11

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.

Bangle answered 23/7, 2013 at 10:4 Comment(2)
You don't need to copy qlmanage to your project directory, just use SHIFT + CMD + G in the file browser then point it at \usr\bin and you can choose the executable there.Felting
This really should replace the painfully outdated documentation Apple provides. Able to build/debug in <5 mins following this whereas I could never get theirs to work. Thanks.Felicio
S
12

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!

Schweiker answered 22/12, 2014 at 23:45 Comment(4)
Thanks for this. I was pulling my hair out trying to get this to work until I found it!Hardnosed
Sadly this doesn't seem to work on El Capitan. Xcode terminates with this message: Message from debugger: cannot attach to process due to System Integrity ProtectionParty
To avoid the cannot attach to process due to System Integrity Protection message, you should uncheck the "Debug executable" button in the plugin Scheme (where you put qlmanage).Berkow
what is the public.data exactly?Expeller
B
11

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.

Bangle answered 23/7, 2013 at 10:4 Comment(2)
You don't need to copy qlmanage to your project directory, just use SHIFT + CMD + G in the file browser then point it at \usr\bin and you can choose the executable there.Felting
This really should replace the painfully outdated documentation Apple provides. Able to build/debug in <5 mins following this whereas I could never get theirs to work. Thanks.Felicio
A
1

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.

Authenticity answered 13/3, 2017 at 10:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.