xcode 我可以调试从 IPA 存档安装的 iOS 应用程序吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26861275/
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
Can I debug iOS app installed from IPA archive?
提问by Yevgeniy P
I m having some problem with my app which reproduces only when i install it ad hoc, but doesn't reproduce if i just run the app from Xcode. I would like to debug this problem, but so far i m not having any luck. I m using Xcode 5.1.1. Here is what i did:
我的应用程序有一些问题,只有在我临时安装时才会重现,但如果我只是从 Xcode 运行应用程序,则不会重现。我想调试这个问题,但到目前为止我没有任何运气。我正在使用 Xcode 5.1.1。这是我所做的:
1) Go to Product->Scheme->Edit Scheme->Archive and set build configuration to Debug.
2) Code signing identity is set to iPhone Developer.
3) Generate Debug Symbols is set to Yes.
4) Go to Product->Archive and after it is archived, click "Distribute", then choose "Save for Enterprise or Ad Hoc Deployment".
5) My development provisioning profile is selected.
6) Click "Export" and export the .ipa file.
7) Use iPhone configuration Utility to install the app onto the device.
8) Run the app on the device.
9) In Xcode, go to Debug->Attach To Process->By PID or Name, enter the app name. Xcode attaches successfully and says running the app on iPad.
10) However, i cannot hit any breakpoints which should be hit when i do certain actions in my app (if i install and run the app from Xcode instead, all breakpoints are hit).
1) 转到 Product->Scheme->Edit Scheme->Archive 并将构建配置设置为 Debug。
2) 代码签名身份设置为 iPhone Developer。
3) 生成调试符号设置为是。
4) 进入产品->存档,存档后,点击“分发”,然后选择“保存为企业或临时部署”。
5) 选择了我的开发配置文件。
6) 单击“导出”并导出 .ipa 文件。
7) 使用 iPhone 配置实用程序将应用程序安装到设备上。
8) 在设备上运行应用程序。
9) 在 Xcode 中,转到 Debug->Attach To Process->By PID or Name,输入应用程序名称。Xcode 连接成功并说在 iPad 上运行该应用程序。
10) 但是,当我在我的应用程序中执行某些操作时,我无法命中任何应该命中的断点(如果我从 Xcode 安装并运行应用程序,则会命中所有断点)。
Am i missing something?
我错过了什么吗?
采纳答案by Yevgeniy P
Jim Ingham, thanks for your answers.
吉姆·英厄姆,感谢您的回答。
I found the reason why i was unable to debug into static libraries. In each Xcode project, there is a setting called "Strip Linked Product" under "Deployment" section. In all my projects this setting was set to "Yes".
我找到了无法调试到静态库的原因。在每个 Xcode 项目中,“部署”部分下都有一个名为“剥离链接产品”的设置。在我的所有项目中,此设置都设置为“是”。
In order to debug into static libraries for an app built by archiving, i set this setting to "No" in each dependent library project (as well as the main project). This can also be set differently for Debug/Release modes. After this, i see the library symbols built during archiving and i m able to debug into library code. I hope this helps someone.
为了调试通过归档构建的应用程序的静态库,我在每个依赖库项目(以及主项目)中将此设置设置为“否”。这也可以针对调试/发布模式进行不同的设置。在此之后,我看到在归档期间构建的库符号,并且我能够调试到库代码中。我希望这可以帮助别人。
Unfortunately (or maybe fortunately) the bug i was trying to debug no longer reproduces when the library symbols are not stripped. Maybe something happens when the symbols are stripped, i will need to investigate further.
不幸的是(或者幸运的是)当库符号没有被剥离时,我试图调试的错误不再重现。也许当符号被剥离时会发生什么,我需要进一步调查。
回答by Jim Ingham
You don't have any debug information for the app at this point, and since most apps are pretty thoroughly stripped, there won't even be symbols for lldb to hook on to. So we're not going to be able to successfully set breakpoints.
此时您没有应用程序的任何调试信息,而且由于大多数应用程序都被彻底剥离了,因此甚至不会有 lldb 挂钩的符号。所以我们将无法成功设置断点。
When you built the app, Xcode produced a dSYM file (MyApp.app.dSYM) which has the debug info in it, so all is not lost. Problem is when you attach to some - to Xcode - random app on the device, Xcode has no way to know where to find its debug info.
当您构建应用程序时,Xcode 会生成一个 dSYM 文件 (MyApp.app.dSYM),其中包含调试信息,因此不会丢失所有内容。问题是当你附加到设备上的一些 - 到 Xcode - 随机应用程序时,Xcode 无法知道在哪里可以找到它的调试信息。
You can add the debug info into your debug session in lldb by using the command:
您可以使用以下命令将调试信息添加到 lldb 中的调试会话中:
(lldb) add-dsym <PathTo.dSYM>
You have to do this after you have attached.
您必须在附加后执行此操作。
lldb also uses SpotLight to find dSYM's so if you put the dSYM somewhere that SpotLight knows to search (like your Desktop or a folder under your User directory) then lldb should pick it up automatically.
lldb 还使用 SpotLight 来查找 dSYM,因此如果您将 dSYM 放在 SpotLight 知道要搜索的地方(例如您的桌面或用户目录下的文件夹),那么 lldb 应该会自动选取它。
You can tell whether lldb has successfully read in the dSYM by doing:
您可以通过执行以下操作来判断 lldb 是否已成功读取 dSYM:
(lldb) image list <AppName>
If lldb found the dSYM, it will list the path to it on a separate line after listing the path to the AppName binary.
如果 lldb 找到了 dSYM,它会在列出 AppName 二进制文件的路径后,在单独的行中列出它的路径。
回答by user5905914
I was struggling with the same problem, and just launching my app from Xcode was not an option - I had to build the IPA, sideload it on an iOS device, and then debug. Eventually I was able to make that work with the following steps:
我正在为同样的问题苦苦挣扎,从 Xcode 启动我的应用程序不是一种选择 - 我必须构建 IPA,将其侧载到 iOS 设备上,然后进行调试。最终,我能够通过以下步骤完成这项工作:
1) Set the scheme archive target to Debug
1) 将方案归档目标设置为 Debug
2) Change the following settings for the Debug builds
2)更改调试版本的以下设置
- Keep Private External Symbols (KEEP_PRIVATE_EXTERNS) : YES
- Enable Bitcode (ENABLE_BITCODE) : NO
- Strip Linked Product (STRIP_INSTALLED_PRODUCT) : NO
- 保留私有外部符号 (KEEP_PRIVATE_EXTENS) : 是
- 启用位码 (ENABLE_BITCODE) : NO
- 剥离链接产品 (STRIP_INSTALLED_PRODUCT) :否
3) Rebuild, archive, and deploy the resulting IPA file to your iOS device.
3) 重建、存档并将生成的 IPA 文件部署到您的 iOS 设备。
4) Launch the app, and in Xcode, select Debug/Attach to Process/YourAppName(id)
4) 启动应用程序,在 Xcode 中,选择 Debug/Attach to Process/YourAppName(id)
5) Break into the debugger - you should be able to see the code, put and use breakpoints, etc.
5) 进入调试器——您应该能够看到代码、放置和使用断点等。
If you want to debug your code from the very beginning, just put a loop that sleeps for a second or two and then checks a flag at the top of your main function - when you break into the debugger, just change the flag to let it escape the loop.
如果您想从一开始就调试代码,只需放置一个休眠一两秒钟的循环,然后检查主函数顶部的标志 - 当您闯入调试器时,只需更改标志即可逃离循环。