What can GDB do for us:
Previous articles introduced the working principle of debug tool-GDB. We may have some knowledge about how GDB works. When we can ask what GDB can do for us, most people may not have a specific answer except to debug the program, this article also serves as a summary of power. In addition to knowing how the mixer works, we also know what problems can be solved with the mixer.
Many of the content in this article comes from Jim Huang's happygdb. Thank you.
1. In general, GDB can let us know where the program exits and why it ends or exits.
2. Learning to use GDB during the development process allows us to better understand the specific behavior of our program and identify problems in advance.
3. GDB can help us get information about the software and hardware environment when the program is running, and use commands such as GDB's cute info.
4. With GDB, You can dynamically change the execution process and perform multiple conditional tests without recompilation.
5. You can monitor or modify the data during program execution, such as disp and watch.
6. You can view the Assembly: dissamble main (or address)
7. You can debug a third-party library (no source code released, no debugging information) to locate the problem and cause. Si, Ni
8. You can directly modify the compilation code in GDB. The debugging process is like a flow of water... Shell.
Why use GDB:
Many of my friends (including me, :() previously thought that printf could solve many problems, and it was straightforward enough. GDB was difficult to use and had a large number of commands, which was complicated.
It is true that printf can solve the problem in most cases. However, we know that different tools have different application scenarios. You cannot use a cow or a cow...
1. We all know the efficiency of using GDB, but this is not enough for our friends to abandon printf, because when there is a problem, printf is often used more directly than the method of recalling or searching for GDB.
2. If printf is used for debugging, we need to add the debug code. In some non-real-time applications, it may not bring any bad applications, but in embedded development, in real-time application development, increasing the debug code will increase the differences between the actual situation and the debugging mode.
3. Using GDB will help us quickly track code behavior and reproduce the problem. Of course, this speed is based on the fact that we can play with GDB. When we know the charm of GDB, we will have great motivation to turn it around quickly, just like chasing girls...
4. Using GDB allows us to accurately master various information during runtime, which may be of great inspiration to us when debugging has a deep potential problem. Printf needs some profound skills to achieve this goal.