简体   繁体   English

我可以调试从IPA存档安装的iOS应用吗?

[英]Can I debug iOS app installed from IPA archive?

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. 我的应用程序有一些问题,只有当我安装它时才会重现,但如果我只是从Xcode运行应用程序,则不会重现。 I would like to debug this problem, but so far im not having any luck. 我想调试这个问题,但到目前为止我没有任何运气。 I m using Xcode 5.1.1. 我正在使用Xcode 5.1.1。 Here is what i did: 这是我做的:

1) Go to Product->Scheme->Edit Scheme->Archive and set build configuration to Debug. 1)转到Product-> Scheme-> Edit Scheme-> Archive并将构建配置设置为Debug。

2) Code signing identity is set to iPhone Developer. 2)代码签名身份设置为iPhone Developer。

3) Generate Debug Symbols is set to Yes. 3)生成调试符号设置为是。

4) Go to Product->Archive and after it is archived, click "Distribute", then choose "Save for Enterprise or Ad Hoc Deployment". 4)转到Product-> Archive,归档后,单击“Distribute”,然后选择“Save for Enterprise或Ad Hoc Deployment”。

5) My development provisioning profile is selected. 5)选择了我的开发配置文件。

6) Click "Export" and export the .ipa file. 6)单击“导出”并导出.ipa文件。

7) Use iPhone configuration Utility to install the app onto the device. 7)使用iPhone配置实用程序将应用程序安装到设备上。

8) Run the app on the device. 8)在设备上运行应用程序。

9) In Xcode, go to Debug->Attach To Process->By PID or Name, enter the app name. 9)在Xcode中,转到Debug-> Attach To Process->通过PID或Name,输入应用程序名称。 Xcode attaches successfully and says running the app on iPad. Xcode成功附加并表示在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). 10)然而,当我在我的应用程序中执行某些操作时,我无法点击应该被击中的任何断点(如果我从Xcode安装并运行应用程序,则所有断点都被命中)。

Am i missing something? 我错过了什么吗?

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. 此时您还没有针对该应用程序的任何调试信息,并且由于大多数应用程序都被彻底剥离,因此lldb甚至不会挂起符号。 So we're not going to be able to successfully set breakpoints. 所以我们无法成功设置断点。

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. 当您构建应用程序时,Xcode生成了一个dSYM文件(MyApp.app.dSYM),其中包含调试信息,因此所有文件都不会丢失。 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 - 随机应用程序时,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二进制文件的路径后在单独的行中列出它的路径。

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. 在每个Xcode项目中,“部署”部分下都有一个名为“剥离链接产品”的设置。 In all my projects this setting was set to "Yes". 在我的所有项目中,此设置都设置为“是”。

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 im 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. 当符号被剥离时可能会发生某些事情,我需要进一步调查。

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. 我正在努力解决同样的问题,只是从Xcode启动我的应用程序不是一个选项 - 我必须构建IPA,在iOS设备上加载它,然后调试。 Eventually I was able to make that work with the following steps: 最终我能够通过以下步骤完成这项工作:

1) Set the scheme archive target to Debug 1)将方案归档目标设置为Debug

2) Change the following settings for the Debug builds 2)更改Debug版本的以下设置

  • Keep Private External Symbols (KEEP_PRIVATE_EXTERNS) : YES 保留私有外部符号(KEEP_PRIVATE_EXTERNS):是
  • Enable Bitcode (ENABLE_BITCODE) : NO 启用Bitcode(ENABLE_BITCODE):否
  • Strip Linked Product (STRIP_INSTALLED_PRODUCT) : 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. 如果你想从一开始就调试你的代码,只需要放一个休眠一两秒的循环,然后检查主函数顶部的标志 - 当你进入调试器时,只需更改标志就可以了逃离循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM