Getting Started with GDB141
Program exited with code 022.
(gdb) quit
[rr@conformix 5]$
Here are some observations about this session.
•The
list
command lists lines in the source code file and moves the pointer for listing.
So the first
list
command lists lines from 1 to 10. The next
list
command lists
lines from 11 to 14 where 14 is the last line.
•You can use a number with the
list
command. The
list
command displays the line
with the number in the middle. So the command
list 9
will list lines from 4 to 13
trying to keep line number 9 in the middle.
•To list a range of lines, you can specify that range as an argument to the
list
command using a comma. For example,
list 1,14
will list lines from line number 1
to line number 14.
•You can set a break point using the
break
command at a particular line number. When
you use the
run
command, the execution will stop at the break point. It is important
that you create at least one break point before using the
run
command. If you don’t do
so, the program will continue to run until it reaches the end and you may not be able to
debug it. More on
break
points will be discussed later.
•After setting a break point, you can use the
run
command to start execution of the
program. Note that simply loading a file into
gdb
does not start execution. When
gdb
comes across a break point, it will stop execution and you will get a
(gdb)
command
prompt. At this point you can start tracing the program line by line or using some other
method.
•The
next
command (or simply
n
) executes the current line and moves execution
pointer to the next line. Note that the line number and the contents of line are displayed
each time you use the
next
command.
•When the running program needs an input,
gdb
will stop and you can enter the
required value. For example, I have entered 45 and 56 as values for
num1
and
num2
.
•
gdb
will print any output when a command is executed that prints something on the
output device. You can see the result of addition printed.
•When
gdb
reaches the end of execution, it will print the exit code. After that you can
use the
quit
command to end
gdb
session.
This was a simple
gdb
session. In next sections, you will go through more examples of
how to use
gdb
.
5.2.3Passing Command Line Arguments to the Program Being Debugged
Many program need command line arguments to be passed to them at the time of execu-
tion. There are multiple ways to pass these command line arguments when you debug a pro-