Supported on windows
Supported on linux
Not supported on embedded
Supported on android

detach command

Detaches GDB from a process

Syntax

detach

Remarks

After GDB detaches from a process, the process will keep on running with no debugger attached to it. You can then attach back to it using the attach command.

Note that you can detach command is valid in all of those cases:

  • When you have attached to a process with the attach command
  • When you have started a process using the run command
  • When you have connected to a gdbserver using the target command

If you want to terminate the debugged process instead of detaching from it, use the kill command.

Examples

In the following example we attach GDB to a running Linux process, detach from it and attach again:

(gdb) attach 14199
Attaching to process 14199
Reading symbols from /home/testuser/0.elf...done.
Reading symbols from /lib/i386-linux-gnu/libc.so.6...
Reading symbols from /usr/lib/debug/lib/i386-linux-gnu/libc-2.15.so...done.
done.
Loaded symbols for /lib/i386-linux-gnu/libc.so.6
Reading symbols from /lib/ld-linux.so.2...
Reading symbols from /usr/lib/debug/lib/i386-linux-gnu/ld-2.15.so...done.
done.
Loaded symbols for /lib/ld-linux.so.2
0xb771f424 in __kernel_vsyscall ()
(gdb) detach
Detaching from program: /home/testuser/0.elf, process 14199
(gdb) attach 14199
Attaching to program: /home/testuser/0.elf, process 14199
Reading symbols from /lib/i386-linux-gnu/libc.so.6...
Reading symbols from /usr/lib/debug/lib/i386-linux-gnu/libc-2.15.so...done.
done.
Loaded symbols for /lib/i386-linux-gnu/libc.so.6
Reading symbols from /lib/ld-linux.so.2...
Reading symbols from /usr/lib/debug/lib/i386-linux-gnu/ld-2.15.so...done.
done.
Loaded symbols for /lib/ld-linux.so.2
0xb771f424 in __kernel_vsyscall ()
(gdb)

Compatibility with VisualGDB

Do not execute the detach command manually under Visual Studio. Use the VisualGDB Project Properties dialog to configure VisualGDB to execute the detach command when you exit debugging with Shift-F5.

See also