Debugging with GDB Manual The GNU Source-Level Debugger (769148-001, March 2014)
directs that processes started with subsequent run commands default to do
input and output on the terminal '/dev/ttyb' and have that as their
controlling terminal.
NOTE:
• You can redirect your program input and output using shell redirection with the run command.
For example,
run > outfile
starts your program, diverting its output to the file 'outfile'.
• An explicit redirection in run overrides the tty command's effect on the input/output device,
but not its effect on the controlling terminal.
• When you use the tty command or redirect input in the run command, only the input for
your program is affected. The input for GDB still comes from your terminal.
Debugging a Running Process
You can use GDB to debug a running process by specifying the process ID. Following commands
are used to debug a running process:
attach process-id dev-file This command attaches to a running process―one that was
started outside GDB. (info files shows your active
targets.) The command takes as argument a process ID or
a device file. The usual way to find out the process-id of a
Unix process is with the ps utility, or with the 'jobs -l'
shell command.
attach does not repeat if you press RET a second time
after executing the command.
NOTE:
• To use attach, your program must be running in an environment which supports processes;
for example, attach does not work for programs on bare-board targets that lack an operating
system.
• You must also have permission to send the process a signal.
• When you use attach, the debugger finds the program running in the process first by looking
in the current working directory, then (if the program is not found) by using the source file
search path (see “Specifying source directories” (page 55)). You can also use the file
command to load the program. See “Commands to specify files” (page 88).
• GDB stops the process being attached for debugging. You can examine and modify an
attached process with the GDB commands that are available when you start processes with
run. You can insert breakpoints; you can step and continue; you can modify storage. See
“Breakpoints” (page 36). If you want the process to continue running, you can use the
continue command after attaching GDB to the process.
detach When you have finished debugging the attached process, you can use the detach
command to release it from GDB control. The process continues its execution after being
detached. After the detach command, that process and GDB become completely
independent once more, and you are ready to attach another process or start one
with run. detach does not repeat if you press RET again after executing the command.
If you exit GDB or use the run command while you have an attached process, you kill that process.
By default, GDB asks for confirmation if you try to do either of these things; you can control whether
or not you need to confirm by using the set confirm command (see “Optional warnings and
messages” (page 218)).
Debugging a Running Process 31