.attach (Attach to Process)

The .attach command attaches to a new target application.

.attach [-premote RemoteOptions] AttachOptions PID

Parameters

RemoteOptions
Specifies a process server to attach to. The options are the same as those for the command line -premote option. See Activating a Smart Client for syntax details.

AttachOptions
Specifies how the attach is to be done. This can include any of the following options:

-b
Prevents the debugger from requesting an initial break-in when attaching to a target process. This can be useful if the application is already suspended, or if you want to avoid creating a break-in thread in the target.

-e
Allows the debugger to attach to a process that is already being debugged. See Re-attaching to the Target Application for details.

-k
Begins a local kernel debugging session. See Performing Local Kernel Debugging for details.

-f
Freezes all threads in all target applications, except in the new target being attached to. These threads will remain frozen until an exception occurs in the newly-attached process. Note that an initial breakpoint qualifies as an exception. Individual threads can be unfrozen by using the ~u (Unfreeze Thread) command.

-r

Causes the debugger to start the target process running when it attaches to it. This can be useful if the application is already suspended and you want it to resume execution.

-v
Causes the specified process to be debugged noninvasively.

PID
Specifies the process ID of the new target application.

Environment

Item Description
Modes user mode only
Targets live debugging only
Platforms all

Remarks

This command can be used when CDB is dormant, or if it is already debugging one or more processes. It cannot be used when WinDbg is dormant.

If this command is successful, the debugger will attach to the specified process the next time the debugger issues an execution command. If this command is used several times in a row, execution will have to be requested as many times as this command was used.

Because execution is not permitted during noninvasive debugging, the debugger is not able to noninvasively debug more than one process at a time. This also means that using the .attach -v command may render an already-existing invasive debugging session less useful.

Multiple target processes will always be executed together, unless some of their threads are frozen or suspended.

If you wish to attach to a new process and freeze all your existing targets, use the -f option. For example, you might be debugging a crash in a client application and want to attach to the server process without letting the client application continue running.

If the -premote option is used, the new process will be part of a new system. For details, see Debugging Multiple Targets.