Http://blog.csdn.net/absurd/
GDB is more powerful than a debugger with a GUI, so it is more complicated to use. On the one hand, it has a poor affinity. After all, it is intended for programmers and does not need to be fooled. On the other hand, there are too many commands for it. We often get started with it by remembering just a few common commands and failing to make full use of its potential. Today, I want to debug a piece of arm assembly code. It is very troublesome to debug the assembly code by using conventional methods. It took me some time to look at the help of GDB and I found several useful techniques. Here I will take a note.
1. Use custom commands. There are many built-in commands in GDB, which follow the Unix principle and each command has only one basic function. The command is fine-grained and reusable. Organize these basic commands to form more powerful commands. This can be implemented using define, for example:
(GDB) define Nid
Type commands for definition of "NID ".
End with a line saying just "end ".
> Ni
> Disassemble $ PC + 16
> End
2. Multiple windows. The GUI debugger can open multiple small windows to display registers, assemblies, and source code. It can also be done in GDB, but only two windows can be displayed at the same time. It is convenient to try it. The basic commands are as follows:
A) 'layout src' only displays the source code window.
B) 'layout ASM 'Only displays the assembly code window.
C) 'layout split': displays the source code and assembly code windows.
D) 'layout regs 'displays the register and source code windows, or registers and assembly code windows.
E) switch between 'layout next' and 'layout prev.
F) Ctrl + L refresh the screen.
G) 'C-x 1' Single Window mode.
H) 'C-x 2' dual-window mode.
I) 'C-x a' returns to the traditional mode.