当前位置:网站首页>Use of GDB
Use of GDB
2022-07-27 01:50:00 【Half piece of instant noodles】
List of articles
Preface
GDB By GNU Debugging tools provided by the software system community , Same as GCC It forms a complete development environment ,GDB yes Linux And many classes Unix Standard development environment in the system .
Generally speaking ,GDB It mainly helps you complete the following four functions :
- Start the program , You can run the program at will according to custom requirements
( Start the program ) - Allows the debugged program to stop at the specified set breakpoint
( Use breakpoints to stop programs , Breakpoints can be conditional expressions ) - When the program is stopped , You can check what happens in the program at this time
( Check the variables in the program at this time ) - You can change the program , Will a BUG The impact is corrected to test other BUG
( Change the program )
One 、GDB Commissioning preparations
- When compiling for debugging , We'll turn off the compiler's optimization options
-O - Turn on debug options
-g - in addition ,
-WallThe option turns on all... Without affecting the behavior of the program as much as possible warning, Many problems can also be found , Avoid unnecessary BUG( Or you can skip it ).
gcc -g -Wall program.c -o program
Be careful :-g Option is used to add source code information to the executable , For example, the number of machine instructions in the executable file corresponds to the number of lines of the source code , But it's not embedding the entire source file into the executable , So when debugging Must ensure gdb Can find source file .
Two 、GDB The order of
install GDB Debugging tools ,apt-get -y install gdb
- Start and exit
gdb Executable program // start-up
quit perhaps q // sign out
- Set parameters for the program / Get and set parameters (main Parameters in function )
set args 10 20 // Set parameters
show args // Get and set parameters
GDB Use the help
helpView the current file code
list/l ( Show... From default location )
list/l Line number ( Displays... From the specified line )
list/l Function name ( Displays... From the specified function )
- View non current file code
list/l file name : Line number
list/l file name : Function name
- Set the number of rows displayed
show list/listsize
set list/listsize Row number
Two 、GDB The breakpoint of
- To set breakpoints
b/break Line number
b/break Function name
b/break file name : Line number
b/break file name : function
- View breakpoints
i/info b/break
- Delete breakpoints , This place is not a line number , Is the breakpoint in the breakpoint information (
i b) Number in , After deleting the breakpoint , The breakpoint number will not be updated , If it was 4, The number of the new next breakpoint will be 5.
d/del/delete Breakpoint number
- Setting breakpoint is invalid
dis/disable Breakpoint number
- Setting breakpoints takes effect
ena/enable Breakpoint number
- Set conditional breakpoints ( It is generally used in the position of circulation )
b/break 10 if i=5
Two 、GDB Debugging of
- function GDB Program
start( Stop on the first line )
run( After program running , Stop when you encounter the first breakpoint )
- Continue operation , Stop at the next breakpoint
c/continue
- One line down ( Will not enter function body )
n/next
- Variable operating
p/print Variable name ( Print variable values )
ptype Variable name ( Print variable types )
- Step down debugging ( Encountered a function entering the function body ), When you jump out of a function , There is no breakpoint in the function , Otherwise, the next execution will stop at the breakpoint .
s/step
finish( Jump out of the body of functions )
Automatic variable operation
display Variable name ( Automatically print the value of the specified variable , Otherwise, perform the next step every time , Both print Primary variable )
i/info display
undisplay Number (i display Number in )
- Other operating , When jumping out of the loop, first jump to the beginning of the loop (while()、for()), And there are no breakpoints in the loop , Otherwise, the next execution will stop at the breakpoint .
set var Variable name = A variable's value ( More used in the loop )
until ( Out of the loop )
- Multi process and multi thread debugging
// Switch multithreading thread id
// Switch multithreading inferior id
summary
Follow Niuke online C++ Course learning
边栏推荐
猜你喜欢
随机推荐
识别神器Mx-yolov3
Text three swordsman two
Understanding and learning of internal classes
Shell编程规范与变量
FTP服务
构造函数,拷贝函数和析构函数的区别
[cloud native | learn kubernetes from scratch] VI. kubernetes core technology pod
Proxmox VE安装与初始化
负载均衡的运用
Web services (02) - Web server middleware
深度学习过程中笔记(待完善)
Ubuntu12.10 installing mysql5.5 (II)
mysql视图
Summary of key points of system dynamics specialized examination
33三剑客awk
DNS
LAMP.
Web服务(02)——Web服务器中间件
Typescript 14 starting from 0: built in tool type
39 installing LNMP

![[polymorphism] the detailed introduction of polymorphism is simple and easy to understand](/img/85/7d00a0d9bd35d50635a0e41f49c691.png)







