当前位置:网站首页>Basic usage of GDB debugging
Basic usage of GDB debugging
2020-11-06 01:35:40 【itread01】
> Despite the current use of VS code You can use the plug-in to build and run programs , but GDB As a tool for debugging , It's worth the time to learn . ** summary ** **GDB(GNU Debugger)** It's a matter of GNU Open source organizations release 、UNIX/LINUX Under the operating system 、 Based on the command line 、 Powerful debugging tool . Refer to : [gdb A good tool for debugging ](https://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/gdb.html) ## Enter GDB Environment debugging ### Load compilation options ” –g” In order to be in GDB Debugging environment can show the specific error location . example : ``` g++ filename.cpp –g –o filename ``` stay cmake Compiling , It can be done through optional `-DCMAKE_VERBOSE_MAKEFILE=1` , Show the compilation process , Guarantee -g Option is used during compilation . ### Load the executable file to GDB in In the folder where the execution file is located , Use `gdb` Order to enter GDB In the debugging environment . Later use `file filename` Or use `gdb filename` (filename Executable file name ). ### Set the input arguments for the execution file Use command `set args parameter` (parameter Is the input argument ), Load arguments required for execution . Through `show args` View loaded arguments . example : ``` set args /home/hello.png 2016 12 ``` Use ’show args’ After : ``` /home/hello.png 2016 12 ``` ### GDB Internal use make If the external file is modified , Directly in GDB Use... In the environment “make” Compile . ### File execution Use `r` The file can be executed . ### sign out GDB Debugging environment Use `q` Exit debugging environment . ## Breakpoint setting ### How to set breakpoints - Use line number :`b linenumber` example :“b 2017” - Use the function name `b function` example :“b hello” - Use the address `b *address` example :“b *0x404” > If you break points on different files , Prefix a line number or function name with a file name and colon “filename:”. example : ``` b hello.cpp:hello b hello.cpp:2017 ``` ### Conditional breakpoint stay 1 Add the condition after the small point method , Breakpoints stop when conditions hold . example : ``` b 12 if x > y // stay x > y Under the circumstances , Breakpoints work . ``` ### Breakpoint conditions change Modify the condition of the specified breakpoint number : ``` condition breakpointnumber expression ``` example : ``` condition 12 if x = y ``` > `condition breakpointnumber` Stop using conditions , Breakpoints are used unconditionally . example : ``` condition 12 ``` ### Breakpoint information view - View all breakpoint information : `info b` - View the breakpoint information of the specified breakpoint number : `info b number` ### The enabling of breakpoints - Stop that breakpoint . But not deleted : `dis breakpointnumber` - Enable to change the number of breakpoints : `enable breakpointnumber` ## The way to get rid of mistakes ### Print variables `p` - Print variable values :`p variable` example : “p x” - Print variable address :`p &variable` example : “p &x” - Print index content :`p *point` example : “p *pData” ### Single step debugging `s` Similar to **step in** - Step by step , Encountered function , Go inside the function to execute . `s number` Perform multi-step execution ### Step by step `n` Similar **step over** Execute , Encountered function , Don't go inside a function , Execute the function directly . `n number` Perform multi-step execution ### Continue execution `c` After the program runs into a breakpoint , Use `c` Continue execution ### Run the current function and print out the information `finish` Use... Inside a function `finish` , After the current function is printed, information is returned ### Set variable value to debug `set var variable = x` Set the variable to x After debugging example : ``` set var tmp = 5 ``` Change the variables tmp Set to 5,var Keywords make sure there is no conflict ## Segment error query ### Section backtracking `bt` - In the presence of segment fault When , Use the command to view segment errors . - You can get a function that's sitting in the wrong place . Like getting someone's home address . - You can also use `where` ### Enter error section - After looking at the wrong location , Use `frame number` Go inside the paragraph . - After entering the internal, you can print and debug regional variables . example : ``` frame 5 ``` Just go into the section 5. - Switch to the previous layer segment : `up` - Switch to the next layer segment : `down` ### Code shows - Displays the current code : `l` - Show current previous code : `l -` - Show the code around the line : `l number` - Show the code around the function : `l function` (C++ Code needs to precede the function name with the class name , Overload functions need to add argument types to the function ) - Displays the code around the specified line in the specified file : `l filename:linenumber` example : ``` l hello.cpp:1 // From hello.cpp The first line begins to show ``` - Displays the code around the specified function in the specified file : `l filename:function` example : ``` l hello.cpp:Util::hello // Display hello.cpp Under the file ,Util Class function hello ``` - Show start and end inline code : `l fisrt,last` example : ``` l 1,30 // From the 0 The line shows up to 30 The content of the line ``` --- About GDB Debugging related articles :https://www.cnblogs.com/acceptedzhs/p/13161
版权声明
本文为[itread01]所创,转载请带上原文链接,感谢
边栏推荐
- C++ 数字、string和char*的转换
- C++学习——centos7上部署C++开发环境
- C++学习——一步步学会写Makefile
- C++学习——临时对象的产生与优化
- C++学习——对象的引用的用法
- C++编程经验(6):使用C++风格的类型转换
- Won the CKA + CKS certificate with the highest gold content in kubernetes in 31 days!
- C + + number, string and char * conversion
- C + + Learning -- capacity() and resize() in C + +
- C + + Learning -- about code performance optimization
猜你喜欢
-
C + + programming experience (6): using C + + style type conversion
-
Latest party and government work report ppt - Park ppt
-
在线身份证号码提取生日工具
-
Online ID number extraction birthday tool
-
️野指针?悬空指针?️ 一文带你搞懂!
-
Field pointer? Dangling pointer? This article will help you understand!
-
HCNA Routing&Switching之GVRP
-
GVRP of hcna Routing & Switching
-
Seq2Seq实现闲聊机器人
-
【闲聊机器人】seq2seq模型的原理
随机推荐
- LeetCode 91. 解码方法
- Seq2seq implements chat robot
- [chat robot] principle of seq2seq model
- Leetcode 91. Decoding method
- HCNA Routing&Switching之GVRP
- GVRP of hcna Routing & Switching
- HDU7016 Random Walk 2
- [Code+#1]Yazid 的新生舞会
- CF1548C The Three Little Pigs
- HDU7033 Typing Contest
- HDU7016 Random Walk 2
- [code + 1] Yazid's freshman ball
- CF1548C The Three Little Pigs
- HDU7033 Typing Contest
- Qt Creator 自动补齐变慢的解决
- HALCON 20.11:如何处理标定助手品质问题
- HALCON 20.11:标定助手使用注意事项
- Solution of QT creator's automatic replenishment slowing down
- Halcon 20.11: how to deal with the quality problem of calibration assistant
- Halcon 20.11: precautions for use of calibration assistant
- “十大科学技术问题”揭晓!|青年科学家50²论坛
- "Top ten scientific and technological issues" announced| Young scientists 50 ² forum
- 求反转链表
- Reverse linked list
- js的数据类型
- JS data type
- 记一次文件读写遇到的bug
- Remember the bug encountered in reading and writing a file
- 单例模式
- Singleton mode
- 在这个 N 多编程语言争霸的世界,C++ 究竟还有没有未来?
- In this world of N programming languages, is there a future for C + +?
- es6模板字符
- js Promise
- js 数组方法 回顾
- ES6 template characters
- js Promise
- JS array method review
- 【Golang】️走进 Go 语言️ 第一课 Hello World
- [golang] go into go language lesson 1 Hello World