/*test.c*/
#include
int sum(int m);
int main()
{
int i, n = 0;
sum(50);
for(i = 1; i<= 50; i++)
{
n += i;
}
printf("The sum of 1-50 is %d \n", n );
}
int sum(int m)
{
int i, n = 0;
for (i = 1; i <= m; i++)
{
n += i;
printf("The sum of 1-m is %d\n", n);
}
}
[root@localhost gdb]# gdb test
GNU gdb Red Hat Linux (6.3.0.0-1.21rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library
"/lib/libthread_db.so.1".
(gdb)
(gdb) l
1 #include
2 int sum(int m);
3 int main()
4 {
5 int i,n = 0;
6 sum(50);
7 for(i = 1; i <= 50; i++)
8 {
9 n += i;
10 }
(gdb) l
11 printf("The sum of 1~50 is %d \n", n );
12
13 }
14 int sum(int m)
15 {
16 int i, n = 0;
17 for(i = 1; i <= m; i++)
18 {
19 n += i;
20 }
21 printf("The sum of 1~m is = %d\n", n);
20 }
(gdb) b 19
(gdb) c
Breakpoin 2, sum(m=50) at test.c:19
19 printf("The sum of 1-m is %d\n", n);
(gdb) bt
#0 sum(m=50) at test.c:19 /* 停在test.c 的sum()函数,第19 行*/
#1 0x080483e8 in main() at test.c:6 /* test.c 的第6 行调用sum 函数*/
(gdb) r
Starting program: /root/workplace/gdb/test
Reading symbols from shared object read from target memory...done.
Loaded system supplied DSO at 0x5fb000
Breakpoint 1, main () at test.c:6
6 sum(50);