GDB notes

Today I tried to debug with gdb ( good output )

It should be noted that for a gcc or g++ executable program compiled directly with gcc/g++ -o, it cannot be debugged directly with gdb. Only when the -g command is added, will the compilation containing debugging information be carried out.

Example:

gcc main.c -o main -g

Then you can use gdb to debug:

gdb main
或
gdb main --slient //去掉开始的提示信息

Then here are some simple and commonly used debugging instructions:
(gdb) break xxx
(gdb) b xxx Set a breakpoint on a line specified in the source code, where xxx is used to specify the location of the specific breakpoint.

(gdb) run
(gdb) r Execute the debugged program, which will automatically suspend execution at the first breakpoint.

(gdb) continue
(gdb) c When the program stops running at a certain breakpoint, use this instruction to continue execution until the next breakpoint is encountered or the program ends.

(gdb) next
(gdb) n makes the program execute one line of code and one line of code.

(gdb) print xxx
(gdb) p xxx Print the value of the specified variable, where xxx refers to a variable name.
(gdb) list
(gdb) l Display the content of the source code, including the line number where each line of code is located.
(Note: Only a few lines are displayed at a time, you can press enter to continue the display)

(gdb) quit
(gdb) q Stop debugging.

You can almost get rid of exporting Dafa by relying on the above instructions ( non-existent )

Want to know more about gdb can refer to the following website:
GDB debugging C/C++

Guess you like

Origin blog.csdn.net/weixin_45146520/article/details/109015192