
Running Your Program Under GDB
Motorola
GNU Debugger (GDB)
For More Information On This Product,
Go to: www.freescale.com
D-15
You can redirect the program’s input and/or output using ‘sh’-style redirection commands
in the ‘run’ command. For example,
run > outfile
starts the program, diverting its output to the file ‘outfile’.
Another way to specify where the 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.
An explicit redirection in ‘run’ overrides the ‘tty’ command’s effect on input/output
redirection, 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.
D.5.5 Debugging an Already-Running Process
Some operating systems allow GDB to debug an already running process that was started
outside of GDB. To do this, you use the ‘a(chǎn)ttach’ command instead of the ‘run’ command.
The ‘a(chǎn)ttach’ command requires one argument, which is the process-id of the process you
want to debug. (The usual way to find out the process-id of the process is with the ps
utility.)
The first thing GDB does after arranging to debug the process is to stop it. You can
examine and modify an attached process with all the GDB commands that ordinarily
available when you start processes with ‘run’. You can insert breakpoints; you can step
and continue; you can modify storage. If you would rather the process continue running,
you may use the ‘continue’ command after attaching GDB to the process.
When you have finished debugging the attached process, you can use the ‘detach’
command to release it from GDB’s control. Detaching the process continues its execution.
After the ‘detach’ command, that process and GDB become completely independent once
more, and you are ready to ‘a(chǎn)ttach’ another process or start one with ‘run’.
If you exit GDB or use the ‘run’ command while you have an attached process, you kill
that process. You will be asked for confirmation if you try to do either of these things.
F
Freescale Semiconductor, Inc.
n
.