Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell Xcode to attach debugger to a process as soon as the process will start?

I'm working on something that happens just when my app restarts, and I'm trying to get logs for that. So I build my app, kill it, and restart it.

Killing the app makes Xcode disconnect from the running process.

After I restart the app, I can select Debug > Attach to Process to attach Xcode to the new process, but I'll miss everything that happens between the app start and when I manually attach to the process.

Is there a way to tell Xcode there no process running currently, but as soon as process X starts, attach the debugger to it?

like image 344
Guig Avatar asked Sep 03 '16 17:09

Guig


People also ask

How do debuggers attach to processes?

You can attach the Visual Studio debugger to a running process on a local or remote computer. After the process is running, select Debug > Attach to Process or press Ctrl+Alt+p in Visual Studio, and use the Attach to Process dialog to attach the debugger to the process.

How do I enable Debug mode in Xcode?

When you run an application in Xcode, the debugger is automatically started and attached to the process of the application. Click the Run button in the top left or press Command + R. From the moment the application is up and running, we can start inspecting the process and, if necessary, debug it.

What is debugging executable in Xcode?

The “Debug executable” checkbox specifies whether or not you want to run with the debugger enabled. Once running, you can use Debug > Attach to Process on a process that has been launched with debugging disabled if needed. It seems like all this does is start your app with the debugger attached.


1 Answers

Use the Attach to process by PID or Name feature.

It's under the Debug -> Attach to process by PID or Name menu in Xcode, then simply type in the process name that you normally attach to, and select Attach.

Once your app with said PID or name starts up, the debugger will attach to it immediately.

Make sure to set breakpoints for as early as late as you want to catch the launch.

like image 109
Wilmar Avatar answered Sep 19 '22 13:09

Wilmar