[sunbin@localhost ~]$ gcc -Wall -g simple.c -o simple
[sunbin@localhost ~]$ ./simple
Entering main ...
result[1-100] = 5050
result[1-10] = 55
Exiting main ...
[sunbin@localhost ~]$ gdb simple 启动gdb
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-110.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/sunbin/simple...done.
(gdb) list 查看代码
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 long func(int n);
5
6 int main(int argc, char *argv[])
7 {
8 printf("Entering main ...\n");
9 int i;
10 long result = 0;
(gdb) l 查看代码
11 for (i = 1; i <= 100; ++i)
12 {
13 result += i;
14 }
15 printf("result[1-100] = %ld\n", result);
16 printf("result[1-10] = %ld\n", func(10));
17
18 printf("Exiting main ...\n");
19 return 0;
20 }
(gdb)
21
22 long func(int n)
23 {
24 long sum = 0;
25 int i;
26 for (i = 1; i <= n; ++i)
27 {
28 sum += i;
29 }
30 return sum;
(gdb)
31 }
(gdb)
Line number 32 out of range; simple.c has 31 lines.
(gdb)
Line number 32 out of range; simple.c has 31 lines.
(gdb)
Line number 32 out of range; simple.c has 31 lines.
(gdb)