Can I debug iOS app installed from IPA archive?

六月ゝ 毕业季﹏ 提交于 2019-12-30 03:13:29

问题


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:

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).

Am i missing something?


回答1:


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.

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.

You can add the debug info into your debug session in lldb by using the command:

(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.

You can tell whether lldb has successfully read in the dSYM by doing:

(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.




回答2:


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".

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.




回答3:


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:

1) Set the scheme archive target to Debug

2) Change the following settings for the Debug builds

  • Keep Private External Symbols (KEEP_PRIVATE_EXTERNS) : YES
  • Enable Bitcode (ENABLE_BITCODE) : NO
  • Strip Linked Product (STRIP_INSTALLED_PRODUCT) : NO

3) Rebuild, archive, and deploy the resulting IPA file to your iOS device.

4) Launch the app, and in Xcode, select Debug/Attach to Process/YourAppName(id)

5) Break into the debugger - you should be able to see the code, put and use breakpoints, etc.

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.



来源:https://stackoverflow.com/questions/26861275/can-i-debug-ios-app-installed-from-ipa-archive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!