7

I'm writing an app which has its own (cross-platform) custom XML-based file type.

I want to write a quick look plugin so that things look good in the finder, and have found the tutorial on how this is supposed to work, but apparently I must be doing something wrong since I see in /var/log/system.log that I get a segfault when my Quick Look plugin is ran. How do I see where it's crashing?

Where does macOS store core dumps (if it even does that)? Do I need to set some system option or something to enable that?

How do I get Xcode to look at these core dumps?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Wouter Verhelst
  • 1,269
  • 1
  • 12
  • 27
  • Here's an answer with [details about how to enable core dumps](http://stackoverflow.com/a/21308843/4151918). –  Jul 01 '15 at 19:14

2 Answers2

13

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.
  4. absolutely ensure the "Provide build settings from" is set to your QuickLook extension target.
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.

Slipp D. Thompson
  • 33,165
  • 3
  • 43
  • 43
zneak
  • 134,922
  • 42
  • 253
  • 328
  • I get the message: "cannot attach to process due to System Integrity Protection" when I run this configuration. Is there something I'm missing? – Damiaan Dufaux Sep 06 '17 at 07:21
  • 2
    @DamiaanDufaux, let me see if I can find another better way to do this with SIP enabled. Until then, you can copy `qlmanage` to anywhere else on your file system and [strip the signature](https://reverseengineering.stackexchange.com/questions/13622/remove-code-signature-from-a-mac-binary/13623#13623) from that copy, which will enable you to debug it. – zneak Sep 06 '17 at 16:23
  • OK qlmanage is opening now, but I still get the following errors: `Month 13 is out of bounds` and `CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0x9c03, name = 'com.apple.coredrag'` and `CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0xc53b, name = 'com.apple.tsm.portname'` – Damiaan Dufaux Sep 06 '17 at 19:14
  • @DamiaanDufaux, you might have reached that conclusion already, but I now have it on pretty good authority that the only way to debug a qlgenerator, right now, is to either disable SIP or load the qlgenerator yourself and handle the data feed and display. – zneak Dec 27 '17 at 23:52
  • I was surprised to read your edit mentioning Thumbnail extensions. I can’t find any more information on that. Do you have any information? – Manngo Oct 15 '19 at 21:32
  • @Manngo, I swear I heard that at WWDC, but now that we’re further ahead and Catalina is out, I also can’t find anything to back it up. – zneak Oct 15 '19 at 21:39
  • @Manngo: https://developer.apple.com/documentation/quicklookthumbnailing/providing_thumbnails_of_your_custom_file_types?language=objc shows how to do that – Wouter Verhelst Oct 24 '19 at 10:43
  • @WouterVerhelst Are you sure that comment was for me? – Manngo Oct 24 '19 at 10:52
  • @Manngo you asked about Thumbnail Extensions, did you not? That's what the given link is about. – Wouter Verhelst Oct 24 '19 at 10:56
  • @WouterVerhelst I see. Thanks. I was actually asking about @zneak’s deleted comment that the classic QuickLook plugin is deprecated. Useful link, though. – Manngo Oct 24 '19 at 11:04
  • It's crucial that for the Build Post-Action script, you ensure *Provide build settings from:* is set to your QuickLook extension target. If you forget to do this, Xcode will try to run `cp -R "/" ~/Library/QuickLook`, which is really bad. I've taken the liberty of updating your answer to prevent anyone from making the same mistake I did. – Slipp D. Thompson May 19 '21 at 06:04
1

I haven't tried this personally, but this page:

Debugging Quicklook Plugin in Xcode 4.6

has a description of how to debug your plugin in Xcode 4 - 6. That will probably be much more useful than trying to grub through the core file after the fact.

Community
  • 1
  • 1
Jim Ingham
  • 25,260
  • 2
  • 55
  • 63