1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| $ gdb tst GNU gdb (GDB) 10.1 Copyright (C) 2020 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-pc-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>.
For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from tst... (gdb) l 1 2 3 int func(int n) { 4 int sum = 0, i; 5 for(i = 0; i < n; i++) { 6 sum += i; 7 } 8 return sum; 9 } 10 (gdb) 11 int main(int argc, char *argv[]) 12 { 13 int i; 14 long result = 0; 15 for (i = 0; i <= 100; i ++) { 16 result += i; 17 } 18 printf("result[1-100] = %ld \n", result); 19 printf("result[1-250] = %d \n", func(250)); 20 return 0; (gdb) break 13 Breakpoint 1 at 0x1176: file tst.c, line 14. (gdb) break func Breakpoint 2 at 0x1140: file tst.c, line 4. (gdb) info break Num Type Disp Enb Address What 1 breakpoint keep y 0x0000000000001176 in main at tst.c:14 2 breakpoint keep y 0x0000000000001140 in func at tst.c:4 (gdb) r Starting program: /home/ansore/study/gdb/tst
Breakpoint 1, main (argc=1, argv=0x7fffffffdcd8) at tst.c:14 14 long result = 0; (gdb) n 15 for (i = 0; i <= 100; i ++) { (gdb) n 16 result += i; (gdb) n 15 for (i = 0; i <= 100; i ++) { (gdb) n 16 result += i; (gdb) c Continuing. result[1-100] = 5050
Breakpoint 2, func (n=250) at tst.c:4 4 int sum = 0, i; (gdb) n 5 for(i = 0; i < n; i++) { (gdb) p i $1 = 32767 (gdb) n 6 sum += i; (gdb) n 5 for(i = 0; i < n; i++) { (gdb) p sum $2 = 0 (gdb) n 6 sum += i; (gdb) p i $3 = 1 (gdb) n 5 for(i = 0; i < n; i++) { (gdb) p sum $4 = 1 (gdb) bt
(gdb) finish Run till exit from 0x00005555555551bc in main (argc=1, argv=0x7fffffffdcd8) at tst.c:19 19 printf("result[1-250] = %d \n", func(250)); Value returned is $5 = 31125 (gdb) c Continuing. result[1-250] = 31125 [Inferior 1 (process 12432) exited normally] (gdb) q
|