Attaching a source of framework in xcode - ios

I am trying to debug some code of framework. Right now it always brings me to assembly code. Is there a way I can attach my source to framework so I can debug in framework? Any other alternatives?

If you want to debug the code of a framework that your app uses, create a workspace and put the sources of the framework as well as your app source as 2 projects inside the workspace. make sure the framework is a dependency of the app, and compile and run the app.
The framework will first compile, then the app, and you can put breakpoints in the framework and do all standard debugging.

Related

Framework folder getting generated inside dynamic framework

I am creating a dynamic framework using Swift. When I build the framework, the resulting artifact has a Framework folder that has a bunch of system dylibs that I don't expect.
I am using this documentation for reference - https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/FrameworkAnatomy.html#//apple_ref/doc/uid/20002253-99920-BAJFEJFI
Because of this folder and libswiftRemoteMirror.dylib, the app's release archive is getting rejected by iTunes upload.
I found out the solution to this. In my framework build settings, I had Always Embed Swift Standard Libraries enabled which should have been disabled. Not sure why it was enabled in the first place, since I didn't write the framework, someone else did. But I think it might have been because they started the project using an iOS app template instead of the framework template.

Proper way to debug your own framework project from main app project in Xcode 8?

I have read about two possibilities for that:
To build the framework as debug, to add it to main app project, and run the main project also as debug. Breakpoints should allow you to inspect the frameworks code stepping into it.
To add somehow the framework project itself to the main app project
I tried first one and it is not working for me. I get an Couldn't Generate Swift Representation when trying to step into framework's code. If this option should still work in Xcode 8 and Xcode 8.1, what settings should I check?
If the best/only option now is the second one, how should I properly set that?

Debugging (owned) Framework when using Carthage

I am in the process of developing my own Swift framework to be used privately between two of my applications. I am using Carthage to manage that and other dependencies.
I finally got through developing the framework and hooking it up to one of my apps and, not surprisingly, the app crashes in the new framework code.
I would like to debug the framework code. I've looked at some articles that talk about:
Copying the dsym files and
Compiling with debugging information.
Unfortunately, the articles leave out a lot of details (and I'm not a seasoned enough iOS developer or Carthage user to implicitly know them).
Can someone provide a recipe on how to configure the app such that the private framework code is not optimized and I can step into the framework code from the hosting application?
Thanks
Peter...
Here are two options.
1. Debug framework within main project
Follow step 4 of the Carthage guide and then you should be able to step through and debug your private framework.
With the debug information copied into the built products directory, Xcode will be able to symbolicate the stack trace whenever you stop at a breakpoint. This will also enable you to step through third-party code in the debugger.
2. Modify framework within main project
Clone the private framework source locally.
Drag the framework's .xcodeproj into your main project. (Do not have both projects open in Xcode).
remove crthage entry form carthageInput.xcfilelist & carthageOutput.xcfilelist
remove the framework from project -> target -> general -> frameworks libraries and embedded content then add it using the + sign from the dragged project. then you will see beside the framework name Embed & sign
Now you can develop on your private framework and test them all within your main project. Once done
Remove reference to framework .xcodeproj from main project.
Create a new release of your framework.
Update main project to use newer version using standard carthage update

How to build iOS framework with XCode 6

I know of familiar tutorials on this, but introduction of framework XCode 6 template has changed the game.
I already watched WWDC 2014 video about building modern frameworks but it talks more about building extensions, framework & app all inside single project. It does not specify if the framework I make with it is truly reusable across any project.
I am building framework the XCode 6 way (File->New Project->Framework and Library->Cocoa Touch Framework), but when I import it inside my test app project (separate from framework project) - I keep getting various errors.
Example: Include of non-modular header inside framework, and so on.
I know this is not what it says, and there are quite some missing steps in whatever I am doing. The older tricks may have worked for everyone, but I simply don't find which way to follow after XCode 6.
For example, there is some folder structure that a framework needs, but XCode 6 doesn't comply to it while building it. Is it right? If not, how can I change the way the XCode builds framework folder hierarchy?
Do I go back to old school or am I screwing some tiny thing in XCode 6 that I am unable to create a reusable framework?
I am not sure if you are trying to build a framework with Objective-C or Swift as your question doesn't state it. I've encountered errors you are mentioning with Swift so I'll give you my method to build Swift frameworks.
I found the process for Objective-C to be very straightforward and well documented, so I'll skip this.
As for Swift, there are a few things to consider. First, Swift static libraries are not supported, so you must exclusively use a framework (aka dynamic library) when linking an app to a library.
Here are the steps:
Create the Framework using New > Project under IOS > Framework & Library, select Cocoa Touch Framework
To avoid the "ld: warning: directory not found for option..." goto Library Search Paths in Build Settings for your target and delete the paths.
You can't mix Objective-C with Swift so don't even consider adding the Swift-Header bridge file in your code.
There are some cases in swift where you need to import code from unexposed Frameworks. I've successfully used the module-map inside the framework to deal with these case.
I also select CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES in the Build Settings to solve 'include of non-modular header inside framework module'. That seems to work
I make sure that the header file that gets generated is marked as Public (not Project). Click on the file and you'll see the selection in the inspector under 'Target Membership'
You may run into some bizarre error messages when building. Xcode has a tendency to report linker errors when your code can't compile correctly resulting in missing files the linker needs to output its binaries. Sometimes XCode won't show the errors in the files you are compiling and you need to go manually on the build output and go back to the files. Some other time, you'll get a problem where you need to delete the cache. Those issues I call XCode blues and deal with it constantly. I found this type of problems happens more often when building libraries. The rest should work as expected.

Xcode - debugging library built outside project

I have a C library whose code resides in say /repos1/clib. I build that from the command line using the latest iOS sdk to create clib.a (including a debug build for the simulator) which I copy to an iOS project say in /repos2/proj.
I have been using this setup for several years. The old C library very occasionally might require some debugging and I was pleased by the fact that Xcode simply stepped into the library code that was outside the project (inside repos1) without having to do any setup - it just worked.
But this was up until a few Xcode versions ago. I am not sure exactly when it changed - perhaps when they moved from gcc to llvm? - since I very seldom needed to debug the C code, but for a while now I only get dissasembly when I try to debug the C library from the iOS project (including at least references to the C file name & line number). For the few times I need to debug it is very inconvenient (I create a temp project that includes the C code).
So, any idea why it worked before and doesn't now? Where should I look? Could it be the way I build the C library, maybe there was a flag in gcc I was using that does not have an equivalent in llvm (I can find and post the old build command I was using if it is relevant)? Is the issue in Xcode and there is a way to tell it where to look for the sources?
Thanks!
Edit: To make it clear, I can add the C library either as the source or as a subproject in Xcode, however for reasons that are out of scope this is not helpful for this specific project. So, can it work like it used to with older Xcode versions? If not, it would still be interesting to know why not.
The recommended approach is to create a library project in Xcode, one for iOS (there is a template for it), then when you get that to build add that project to your app, make sure the lib is a dependency and gets linked. There are many tutorials on the web how to do this.
Then as iOS evolves and new architectures (armv7s) arrive you simply update both projects.
I was struggling with the same issue.
I tried resetting in library/application project all options related to symbol stripping and copy application project to same truecrypt drive as library project but it didn't help.
In my case it appeared it was an app project issue. Same library could be debugged in another app project with source code so that was a clue.
I had more than one version of the same library in app project and set only target membership to choose which should be used. Not sure if that could affect my app project somehow.
Nevertheless after deleting all libraries and copying them to app project again I was able to debug libraries with access to source code.

Resources