johnno1962 / Xtrace

Trace Objective-C method calls by class or instance
MIT License
1.83k stars 132 forks source link

Adding Xtrace.mm to Xcode plugin stops plugin loading #1

Closed edwardaux closed 10 years ago

edwardaux commented 10 years ago

Not really sure if this is an issue, but thought I'd bounce it off you to see if you have seen it before.

I have a working Xcode plugin but when I drag Xtrace.mm and Xtrace.h into the plugin project, for some reason, after an Xcode restart the plugin doesn't get loaded.

Note that the problem occurs even if I don't actually have any calls to Xtrace code in my plugin code. If, however, I uncheck the Target Membership for Xtrace.mm (ie. stop it being compiled) the plugin will load successfully again.

There is zero errors emitted in /var/log/system.log, so I'm a bit stumped. Just curious if you have seen anything like this before?

johnno1962 commented 10 years ago

Ha, using Xtrace inside Xcode, now we’re talking! It shouldn’t be a problem as I have already included Xtrace in the “Injection Plugin” for plugin developers and it loads fine. Have you tried running up Xcode inside lldb to see any message:

$ lldb /Applications/Xcode.app/Contents/MacOS/Xcode then type “r"

edwardaux commented 10 years ago

Unfortunately, lldb outputs the same into that I see in /var/log/system.log (ie. nothing helpful).

I've downloaded your Injection Plugin and it definitely loads OK. I've modified all of my plugin's build settings so that the compiler and linker settings for Xtrace.mm are exactly the same as your Injection Plugin, but still no luck. Likewise for the Info.plist settings - the one difference being that you use a Principal class, whereas I don't (not that I would have thought it would matter).

I added a few debug statements into both Xtrace.mm and my plugin class (XCEPlugin.m). I can see that:

I'll do some digging in lldb to see if I can get it to give me some info on the class loading process.

While my plugin is pretty simple, I'm also going to try and create a brand new plugin today and see if I can reproduce it in a different project. It is all very strange.

johnno1962 commented 10 years ago

Strange indeed. Is this some sort of [NSBundle principalClass] issue? Have you tried changing the order of classes in the project?

edwardaux commented 10 years ago

Well, well, well... it turns out that the plugin won't load if the Principal Class isn't set. As soon as I set that, the plugin loads and Xtrace works like a champ.

So bizarre, though, the plugin loads just fine without the Principal Class set - as long as I don't compile in Xtrace.mm.

Anyway, apologies for dragging you into it... I'm up and running now. Thanks for a great library.