如何在 Xcode 的框架中进行调试?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15654493/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I debug in a framework in Xcode?
提问by Jason Lee
I have two projects, one is the networkLib
for login and some other network function, the other is the usingLibDemo
. So I have all the source code of both projects.
我有两个项目,一个是networkLib
登录和一些其他网络功能,另一个是usingLibDemo
. 所以我拥有两个项目的所有源代码。
The networkLib
project outputs a framework, called myNetKit.framework
, which is used by usingLibDemo
.
该networkLib
项目输出一个名为 的框架,myNetKit.framework
由usingLibDemo
.
Now I successfully use myNetKit.framework
to login, but sometimes it crashes, maybe in main() without stack information, but sometimes Xcode gives me the stack info like below:
现在我成功使用myNetKit.framework
登录,但有时它会崩溃,可能在没有堆栈信息的 main() 中,但有时 Xcode 会给我如下堆栈信息:
So I know where it crashes:
所以我知道它在哪里崩溃:
But the Utils.m
is not exposed, how Xcode gets the stack info and the crash line, and eventually open the source file for me?Because that I have the source code in my disk?
但是Utils.m
没有暴露,Xcode是如何获取堆栈信息和崩溃行,并最终为我打开源文件的?因为我的磁盘中有源代码?
If so, how can I debug the myNetKit.framework
step by step, when it is not crashed?
如果是这样,我如何myNetKit.framework
在没有崩溃的情况下逐步调试?
Thanks a lot for any tips.
非常感谢您的任何提示。
采纳答案by Mathew Varghese
You can also add the entire library (networkLib
) project into your project and link the library dynamically by adding dependency in project settings. So you can have all the source code within your project. So you can debug it in run time.
您还可以将整个库 ( networkLib
) 项目添加到您的项目中,并通过在项目设置中添加依赖项来动态链接库。因此,您可以拥有项目中的所有源代码。所以你可以在运行时调试它。
回答by merry_ejik
If someone would have the same question in future (now I am using Xcode 8):
如果将来有人会有同样的问题(现在我使用的是 Xcode 8):
You can:
你可以:
- build your framework project (in this example "networkLib")
- copy project output ("myNetKit.framework") to destination project ("usingLibDemo")
- run destination project ("usingLibDemo") on your device
- stop process
- launch app from your device manually ("usingLibDemo")
- open framework project and Attach to Process of your app (launched in step 5). In Xcode 8: Debug->Attach to Process-> Select name of your app.
- 构建您的框架项目(在本例中为“networkLib”)
- 将项目输出(“myNetKit.framework”)复制到目标项目(“usingLibDemo”)
- 在您的设备上运行目标项目(“usingLibDemo”)
- 停止进程
- 手动从您的设备启动应用程序(“usingLibDemo”)
- 打开框架项目并附加到应用程序的进程(在步骤 5 中启动)。在 Xcode 8 中:Debug->Attach to Process-> Select name of your app。
Don't forget set some breakpoints in your framework project.
不要忘记在您的框架项目中设置一些断点。
回答by Moonwalker
When the library is built with all symbols, it contains full paths to the each source file embedded in itself. You can actually see this if you open the .a with a hex viewer. With this in place, the XCode will know how to get to the source file.
当使用所有符号构建库时,它包含嵌入到自身中的每个源文件的完整路径。如果您使用十六进制查看器打开 .a,您实际上可以看到这一点。有了这个,XCode 将知道如何获取源文件。
Setting breakpoints is somewhat more challenging. You basically have to make XCode slowly discover source files from your library by stepping into methods in those file. Once XCode has opened the file, you can set the breakpoint anywhere in it.
设置断点更具挑战性。您基本上必须通过单步执行那些文件中的方法,让 XCode 从您的库中慢慢发现源文件。XCode 打开文件后,您可以在其中的任何位置设置断点。
It is a bit painful but it works and you do not have to make the library project a subproject if you do not want to.
这有点痛苦,但它有效,如果您不想,您不必将库项目设为子项目。
回答by Shivansh Jagga
The following works considering the scenariothat you have the framework project separately and added a.frameworkto some project B.
考虑到您单独拥有框架项目并将a.framework添加到某个项目 B的情况,以下工作。
- Go to your project B, add a breakpoint anywhere.
- Go to the breakpoint view(where all breakpoints can be seen as a list), right click your breakpoint and click move breakpoint to user.
- Go to a.frameworkand repeat step 1 and 2 but for your framework project.
- Now switch back to project B and run the project on simulator/device.
- 转到您的项目 B,在任意位置添加断点。
- 转到断点视图(所有断点都可以看作一个列表),右键单击您的断点,然后单击将断点移动到用户。
- 转到a.framework并重复第 1 步和第 2 步,但要针对您的框架项目。
- 现在切换回项目 B 并在模拟器/设备上运行该项目。
You'll now see program stopping at the breakpoints set in the framework as well.
您现在将看到程序也在框架中设置的断点处停止。
回答by Vinoth Kumar
Use XCode Workspace when you deal with multiple framework projects. When you use a workspace, breakpoints will work and you can find your crash without loads of back and forth debugging. It will be much easier to manage your frameworks in the long run.
在处理多个框架项目时使用 XCode Workspace。当您使用工作区时,断点将起作用,您无需大量来回调试即可找到崩溃。从长远来看,管理您的框架会容易得多。
回答by Yogi
You should debug the project networkLib which outputs the framework separately. The framework do not have app like structure so a framework file within other project can't be debugged.
您应该调试单独输出框架的项目networkLib。该框架没有类似应用程序的结构,因此无法调试其他项目中的框架文件。