Debugging with GDB Manual HP WDB v6.3 (5900-2180, August 2012)
tty Another way to specify where your program should do input and output is
with the tty command. This command accepts a file name as argument,
and causes this file to be the default for future run commands. It also resets
the controlling terminal for the child process, for future run commands. For
example,
tty /dev/ttyb
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.
4.7 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 60)). You can also use the file
command to load the program. See “Commands to specify files” (page 95).
• 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 39). 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
34 Running Programs Under GDB