GDB commands a lot, this article will not be all introduced, will only introduce some of the most commonly used. Before introducing, let's introduce a very useful feature in GDB: the completion function. It's just like the commands in the shell of Linux are padded. When you enter the first few characters of a command and then enter the TAB key, the shell will fill this command if the first few characters of the other commands are the same. If the first few characters of the other commands are the same, you will hear a warning and then enter the TAB key, which lists all the first few characters in the same command. The completion function of GDB not only can complement the GDB command, but also can make up the parameters.
This article will first introduce the commonly used commands, and then combine a concrete example to demonstrate how to actually use these commands. All of the following commands, except the first to start GDB command, are entered under the shell, and the rest are commands in GDB. Most GDB commands can enter only the first few characters, as long as they do not conflict with other directives. If quit can be abbreviated to Q, because the command with the beginning of Q is only quit. List can be abbreviated to L, and so on.
1. Start GDB
You can enter GDB to start the GDB program. GDB program has many parameters, there is no need to detail, but one of the most commonly used or to introduce: if you have compiled a program, we assume the file name Hello, you want to debug it with GDB, you can enter gdb hello to start gdb and load your program. If you only start GDB, you must reload your program in GDB after it is started.
2. Loading program = = File
Within GDB, the loading program is simple, using the file command. such as file hello. Of course, the path name of the program should be correct.
Exit GDB = = quit
In GDB's command mode, enter quit, you can exit gdb. You can also enter ' c-d ' to exit gdb.
3. Running the program = = = Run
When you load a program that you have already debugged in GDB, you can use the Run command to execute it. If your program requires parameters, you can then enter the parameters after the Run command, just as you would execute a command that requires arguments under the shell.
4. View program Info = = Info
The info instruction is used to view the information of the program, and when you use Help info to see it, the parameters of the info command take up two screens, which have many parameters, but most of them are not used. The most I use info command is to use it to view breakpoint information.
4. 1 View breakpoint Information
Info BR
BR is the abbreviation of breakpoint break, remember the completion function of GDB. With this instruction, you can get the details of all the breakpoints you have set. This includes the breakpoint number, type, state, memory address, location of the breakpoint in the source program, and so on.
4. 2 View Current source program
Info source
4. 3 Viewing stack information
Info stack
With this instruction you can see clearly the call hierarchy of the program.
4. 4 View the current parameters
Info args
5. List Source section source program = = List
5. 1 List A function
List FUNCTION