root@iZ2zeeailqvwws5dcuivdbZ:~/2/02# gcc -o a a.c -g
root@iZ2zeeailqvwws5dcuivdbZ:~/2/02# gdb a
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 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-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://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 a...done.
(gdb)
(gdb) start
Temporary breakpoint 1 at 0x40052e: file a.c, line 5.
Starting program: /root/2/02/a
Temporary breakpoint 1, main () at a.c:5
5 int a = 1;
(gdb)
gdb提示准备执行a.c程序的第六行代码。然后继续用(gdb)提示需要输入的命令。
[2] 单步执行(n)
(gdb) start
Temporary breakpoint 1 at 0x40052e: file a.c, line 5.
Starting program: /root/2/02/a
Temporary breakpoint 1, main () at a.c:5
5 int a = 1;
(gdb) n
6 int b = a;
(gdb) n
8 printf("a = %d, b = %d\n", a, b);
(gdb) n
a = 1, b = 1
9 return 0;
(gdb) quit
A debugging session is active.
Inferior 1 [process 22935] will be killed.
Quit anyway? (y or n) y
root@iZ2zeeailqvwws5dcuivdbZ:~/2/02#
(gdb) start
Temporary breakpoint 1 at 0x40052e: file a.c, line 5.
Starting program: /root/2/02/a
Temporary breakpoint 1, main () at a.c:5
5 int a = 1;
(gdb) b 8
Breakpoint 2 at 0x40053b: file a.c, line 8.
(gdb) c
Continuing.
Breakpoint 2, main () at a.c:8
8 printf("a = %d, b = %d\n", a, b);
(gdb) display b
1: b = 1
(gdb) n
a = 1, b = 1
9 return 0;
1: b = 1
(gdb)
10 }
1: b = 1
(gdb) quit
root@iZ2zeeailqvwws5dcuivdbZ:~/2/02#
root@iZ2zeeailqvwws5dcuivdbZ:~/2/02# gdb a
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 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-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://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 a...done.
(gdb) start
Temporary breakpoint 1 at 0x40052e: file a.c, line 5.
Starting program: /root/2/02/a
Temporary breakpoint 1, main () at a.c:5
5 int a = 1;
(gdb) b 7
Breakpoint 2 at 0x40053b: file a.c, line 7.
(gdb) b 8
Note: breakpoint 2 also set at pc 0x40053b.
Breakpoint 3 at 0x40053b: file a.c, line 8.
(gdb) i breakpoints
Num Type Disp Enb Address What
2 breakpoint keep y 0x000000000040053b in main at a.c:7
3 breakpoint keep y 0x000000000040053b in main at a.c:8
(gdb)
......(gdb) b 7
Breakpoint 2 at 0x40053b: file a.c, line 7.
(gdb) b 8
Note: breakpoint 2 also set at pc 0x40053b.
Breakpoint 3 at 0x40053b: file a.c, line 8.
(gdb) i breakpoints
Num Type Disp Enb Address What
2 breakpoint keep y 0x000000000040053b in main at a.c:7
3 breakpoint keep y 0x000000000040053b in main at a.c:8
(gdb) delete 3
(gdb) i breakpoints
Num Type Disp Enb Address What
2 breakpoint keep y 0x000000000040053b in main at a.c:7
(gdb)
......//先把其余的断点删掉。(gdb) b 9 if a == 2
Breakpoint 5 at 0x400552: file a.c, line 9.
(gdb) i breakpoints
Num Type Disp Enb Address What
5 breakpoint keep y 0x0000000000400552 in main at a.c:9
stop only if a == 2
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /root/2/02/a
a = 1, b = 1
[Inferior 1 (process 22968) exited normally]
(gdb)
root@iZ2zeeailqvwws5dcuivdbZ:~/2/02# gdb a
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 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-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://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 a...done.
(gdb) start
Temporary breakpoint 1 at 0x40052e: file a.c, line 5.
Starting program: /root/2/02/a
Temporary breakpoint 1, main () at a.c:5
5 int a = 1;
(gdb) watch b
Hardware watchpoint 2: b
(gdb) c
Continuing.
Hardware watchpoint 2: b
Old value = 0
New value = 1
main () at a.c:8
8 printf("a = %d, b = %d\n", a, b);
(gdb)
yuyi@yuyi-machine:~/workspace/zqingyangLib/examples/2024年6月21日_文件传输$ arm-linux-gnueabi-gdb ./client.out
GNU gdb (Linaro_GDB-2017.01) 7.12.1.20170127-git
Copyright (C) 2017 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 "--host=x86_64-unknown-linux-gnu --target=arm-linux-gnueabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://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"...
[root@GEC6818 /yuyiworkspace/tmp]#gdbserver 192.168.64.202:2001 ./client.out
Process ./client.out created; pid = 1516
Listening on port 2001
Remote debugging from host 192.168.64.202
./client.out: No such file or directory.
(gdb) target remote 192.168.64.203:2001
Remote debugging using 192.168.64.203:2001
Reading /yuyiworkspace/tmp/client.out from remote target...
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
Reading /yuyiworkspace/tmp/client.out from remote target...
Reading symbols from target:/yuyiworkspace/tmp/client.out...done.
Reading /lib/ld-linux.so.3 from remote target...
Reading /lib/ld-linux.so.3 from remote target...
Reading symbols from target:/lib/ld-linux.so.3...done.
0xb6fcea80 in _start () from target:/lib/ld-linux.so.3
(gdb)