156Chapter5 • Working with GNU Debugger
(gdb) n
Enter second number : 12
14 total = sum(num1, num2);
(gdb) print num1
$1 = 34
(gdb) set num1=11
(gdb) print num1
$2 = 11
(gdb) print num2
$3 = 12
(gdb) n
Calculation complete. Returning ...
15 printf("\nThe sum is : %d\n", total);
(gdb) n
The sum is : 23
16 }
(gdb)
5.6Adding Break Points
When you start debugging a program, you use the
run
command. This command executes the
program until the end of the program or a break point is met. A break point is a place in your
source code file where you temporarily want to stop execution of the program being debugged.
Break points in GNU debugger can be placed using the
break
command. Look at the fol-
lowing list of the source code file
sum.c
which you already have used:
(gdb) list
1 #include
2 main ()
3 {
4 int num1, num2, total ;
5
6 printf("Enter first number : ");
7 scanf("%d", &num1);
8 printf("Enter second number : ");
9 scanf("%d", &num2);
10
(gdb)
To place a break point at line number 6 in file
sum.c
(displayed above), you can use the
following command:
(gdb) break sum.c:6
Breakpoint 1 at 0x8048496: file sum.c, line 6.
(gdb)
Next Page >>
<< Previous Page
Back to the Table of Contents