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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
[root@SqaServer gdb]# gcc gdb-sample.c -o gdb-sample -g [root@SqaServer gdb]# ll 总用量 37716 -rwxrwxrwx 1 root root 38604458 5月 2 2022 gdb-12.1.tar.gz -rwxr-xr-x 1 root root 11064 11月 17 10:42 gdb-sample -rwxrwxrwx 1 root root 435 11月 17 10:43 gdb-sample.c
[root@SqaServer gdb]# gdb GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.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/>.
(gdb) file gdb-sample Reading symbols from /tmp/soft/gdb/gdb-sample...done.
(gdb) r Starting program: /tmp/soft/gdb/gdb-sample n = 1, nGlobalVar = 88 tempFunction is called, a = 1, b = 2 n = 3[Inferior 1 (process 11509) exited normally] Missing separate debuginfos, use: debuginfo-install glibc-2.17-326.el7_9.x86_64
(gdb) b main Breakpoint 1 at 0x400549: file gdb-sample.c, line 13.
(gdb) r Starting program: /tmp/soft/gdb/gdb-sample
Breakpoint 1, main () at gdb-sample.c:13 13 n = 1;
(gdb) s 14 n++;
(gdb) p n $1 = 1
(gdb) b 20 Breakpoint 2 at 0x400576: file gdb-sample.c, line 20. (gdb) b tempFunction Breakpoint 3 at 0x400520: file gdb-sample.c, line 6. (gdb) Note: breakpoint 3 also set at pc 0x400520. Breakpoint 4 at 0x400520: file gdb-sample.c, line 6.
(gdb) c Continuing.
Breakpoint 2, main () at gdb-sample.c:20 20 printf("n = %d, nGlobalVar = %d \n", n, nGlobalVar); (gdb) c Continuing. n = 1, nGlobalVar = 88
Breakpoint 3, tempFunction (a=1, b=2) at gdb-sample.c:6 6 printf("tempFunction is called, a = %d, b = %d \n", a, b); (gdb) p a $2 = 1 (gdb) p b $3 = 2
(gdb) c Continuing. tempFunction is called, a = 1, b = 2 n = 3[Inferior 1 (process 12101) exited normally]
(gdb) display /i $pc
(gdb) r Starting program: /tmp/soft/gdb/gdb-sample
Breakpoint 1, main () at gdb-sample.c:13 13 n = 1; 1: x/i $pc => 0x400549 <main+8>: movl $0x1,-0x4(%rbp)
(gdb) si 14 n++; 1: x/i $pc => 0x400550 <main+15>: addl $0x1,-0x4(%rbp) (gdb) si 15 n--; 1: x/i $pc => 0x400554 <main+19>: subl $0x1,-0x4(%rbp) (gdb) si 17 nGlobalVar += 100; 1: x/i $pc => 0x400558 <main+23>: mov 0x200ada(%rip),%eax
(gdb) d Delete all breakpoints? (y or n) y
(gdb) b *main Breakpoint 5 at 0x400541: file gdb-sample.c, line 11. (gdb) r The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /tmp/soft/gdb/gdb-sample
Breakpoint 5, main () at gdb-sample.c:11 11 { 1: x/i $pc => 0x400541 <main>: push %rbp (gdb) si 0x0000000000400542 11 { 1: x/i $pc => 0x400542 <main+1>: mov %rsp,%rbp (gdb) si 0x0000000000400545 11 { 1: x/i $pc => 0x400545 <main+4>: sub $0x10,%rsp (gdb) si 13 n = 1; 1: x/i $pc => 0x400549 <main+8>: movl $0x1,-0x4(%rbp) (gdb) si 14 n++; 1: x/i $pc => 0x400550 <main+15>: addl $0x1,-0x4(%rbp) (gdb) si 15 n--; 1: x/i $pc => 0x400554 <main+19>: subl $0x1,-0x4(%rbp) (gdb) si 17 nGlobalVar += 100; 1: x/i $pc => 0x400558 <main+23>: mov 0x200ada(%rip),%eax
(gdb) i r rax 0x400541 4195649 rbx 0x0 0 rcx 0x4005c0 4195776 rdx 0x7fffffffe228 140737488347688 rsi 0x7fffffffe218 140737488347672 rdi 0x1 1 rbp 0x7fffffffe130 0x7fffffffe130 rsp 0x7fffffffe120 0x7fffffffe120 r8 0x7ffff7dd5e80 140737351868032 r9 0x0 0 r10 0x7fffffffdc60 140737488346208 r11 0x7ffff7a2f460 140737348039776 r12 0x400440 4195392 r13 0x7fffffffe210 140737488347664 r14 0x0 0 r15 0x0 0 rip 0x400558 0x400558 <main+23> eflags 0x202 [ IF ] cs 0x33 51 ss 0x2b 43 ds 0x0 0 es 0x0 0 fs 0x0 0 gs 0x0 0 (gdb) i r eax eax 0x400541 4195649 (gdb) q A debugging session is active.
Inferior 1 [process 12970] will be killed.
Quit anyway? (y or n) y [root@SqaServer gdb]#
|