In linux, there are usually few debugging tools for programming, among which gdb is a famous one. Because the program runs on the ARM board, it is often unable to run gdb due to insufficient resources. Therefore, the problem of debugging and tracking was often solved only by using a simple printf, and gdb was never used. But today I encountered a problem that printf could not be tracked, and I remembered gdb. Through the application of gdb, we found that the gdb function is really powerful. The following is a record of the commands I used.
. /Gdb testprogram: indicates that gdb is used to run the testprogram program. Because my gdb program is in the current directory, it is added before. /If gdb is in the directory of system environment variables (such as/bin), run gdb testprogram directly. Ps: when developing in an embedded environment, gdb is often used to observe the core file. The running command should be followed by the core file name, for example:./gdb testprogram core.
R: indicates the execution program. It is short for run. You can also enter run. If r is input after the program is interrupted, it indicates re-execution from the beginning.
Ctrl + c: this is not a command input, but an instant interrupt program is implemented through this key combination during the program running.
Bt n: displays the program pressure on the stack when the program is interrupted. In fact, it is to look at the several functions in turn. N indicates the number of call layers to be observed.
F n: used in combination with bt n, so that the program State is returned to the function scope of the corresponding layers. It is mainly used to facilitate observation of local variables. If the corresponding function call layer is not available, the variables in the corresponding scope cannot be printed.
P x: the abbreviation of print, which prints the value of the x variable. x can be an expression. * And & among others can be used, very powerful.
Break linenum: sets a breakpoint. Linenum indicates the row number. If a file is used, write the row number directly. If there are multiple files, you can use the format of the file name: row number. For example, break test. c: 8 indicates that the breakpoint is set on line 8th of test. c.
Cont: the abbreviation of continue. After the program is interrupted, enter this command to continue the program.
Next: run the program in one step. When a function is called, next executes the function call as a statement.
Step: run the program in one step. However, unlike next, when a function call is triggered, step tracks the code in the execution function that enters the function once.
Q: quit stands for exit gdb.