How to attach debugger to iOS app after launch?
Asked Answered
U

5

116

I have an issue I am troubleshooting which occurs very infrequently and doesn't seem to happen when I have things running under Xcode.

Is it possible to run an app normally (i.e. from Springboard) until my issue occurs, and then attach a debugger at that point?

I would prefer to do this without jailbreaking if possible.

Ultrafilter answered 15/3, 2012 at 14:29 Comment(2)
See also How to debug an iOS extension (.appex)? (for a more complete answer)Carbuncle
And: Xcode's Profiler does not show Symbol names fix (which can be caused by Attach approach)Carbuncle
M
148
  • Attach your device connected your Mac
  • Debug > Attach to Process by PID or Name
  • In the dialog sheet, enter the name of your App as it appears in the Debug navigator when started via Xcode (e.g. Target's name not bundle-id).

If the app is already running, the debugger will attach to the running process. If it isn't running, it will wait for the app to launch and then attach.

Mosby answered 15/3, 2012 at 14:43 Comment(7)
Ole, thanks for the answer. I was looking for a way to do this. When I go to attach the debugger, it looks like it attaches but then I get this message: warning: Unable to read symbols for /var/mobile/Applications/ {GUID}/{APPNAME}.app/{APPNAME} (file not found). When I press the "stop" button in XCode, the app terminates. Looks like it's not finding the debug symbols, though it is being built in debug mode. Any ideas?Cleavland
I have a problem with the If it isn't running, it will wait for the app to launch and then attach. part. It doesn't work. I use the process name to wait for the app to call. I launch the app on the iPhone, but the debugger never realizes the app has started.Endoderm
@BrianV -- you need to make sure you're compiling with -ggdb if you want to be able to attach to the process.Lilith
I agree with Jonny; my experience is that the attach works on the simulator, but won't attach to the actual device.Briefless
@JamesMoore: Attach worked for me on device just now, no problem.Autoclave
NOTE: In Xcode 5.0.1+ it is Debug > Attach to Process > By Process Identifier (PID) or Name https://mcmap.net/q/187546/-how-to-attach-debugger-to-ios-app-after-launchGanja
Looks like they went back to "Debug > Attach to Process by PID or Name..." in Xcode 7.2Seaward
L
128

I'll leave this here since neither of the other 2 answers gave me quite enough detail without a little bit of a struggle.

  1. Run your app in the simulator and take note of the name in the Debug navigator enter image description here

  2. Plug in your device and don't forget to select your device as the target enter image description here

  3. Debug > Attach to Process > By Process Identifier (PID) or Name enter image description here
  4. Enter the name from step 1 and attach. That should be all you have to do. enter image description here
Lumbricoid answered 14/1, 2015 at 2:35 Comment(6)
You should have 1000 upvotes. Debugging things that start via a cutom url scheme can be a pain in the ass without this neat trick. Many thanks!Amorphism
I wish I saw this answer before I spent 20 minutes figuring this out on my own :(Gunboat
This works in that it attaches to the process, but I can't seen to get any log output which is what I really need. Any ideas?Schipperke
@Schipperke - If you're looking for log output, I highly recommend DeviceConsole: github.com/rpetrich/deviceconsoleStalinabad
I did exactly as you suggested. and I get error: Could not attach to PID I tried both the name and its ID. I tried while the app is running and while it's stopped..Geer
Same issue as @SchipperkeRaulrausch
E
49

In Xcode 5.0.1 and 6 it's the menu bar items:

Debug > Attach to Process > By Process Identifier (PID) or Name...
Emaciation answered 25/11, 2013 at 12:27 Comment(0)
P
8

In Xcode 7 it's just:

Debug > Attach to Process by PID or Name...
Playhouse answered 9/6, 2016 at 17:27 Comment(0)
S
-1

I was able to debug the app by adding a breakpoint on the AppCoordinator file init() method on the super.init() line.

I was able to turn off the wifi/internet and then by pass the developer verification.

Semicentennial answered 18/11, 2022 at 4:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.