[Linux] gdb debugger--

gdb: debugger

Functions of the debugger:

Debug and observe program operation errors, usually for the purpose of troubleshooting program operation errors

Classification of program errors:

Compile errors, link errors, runtime errors (run-time logic errors and runtime program crashes)

Prerequisites for debugging

The program must be a debug version of the program; gcc/g++ generates the releas version of the program by default, if you want to generate the debug version, use the -g option, for example: gcc -g test.c -o test.exe

Classification of executable programs:

debug-debug version: do not optimize the code, and add debugging program information;

release-release version: does not contain debugging information, and the code is optimized

gdb commonly used commands

gdb ./test.exe means to debug the test.exe file

Process control

RUN : run the program directly

Start : start stepping

List : view the code example near the debug line: list test.c: 12

the Next : Step Over - finished running encounter function directly

the STEP : Step Into - into the internal functions that encounter is to continue debugging function

an until : Example run directly to the specified location: until test.c: 16 run directly to the line 16

the Continue : continue to run from its current location

BREAK : e.g. break point: break test.c: 14 to add a breakpoint at line 14 of file test.c

BREAK info : View breakpoint information

the Delete : Delete the breakpoint example: delete id (heel breakpoint id, the available info break View)

Watch : variable monitoring break - when the change occurs stop debugging variable, followed by the variable name

quit : Quit gdb debugging

Memory control

 print:查看嚯设置变量内容; 例:print var_name   print var=val

 backtrac:查看函数调用栈--通常用于检测程序运行时的崩溃位置

Note: Most of the above operations can also be implemented with initials abbreviated, but there are some ambiguities in the initials of individual commands and cannot be abbreviated. Pay attention to the actual operation.

Guess you like

Origin blog.csdn.net/weixin_43962381/article/details/113518180