Remember a gdb debugging process for later use (pure personal use)

gdb is a powerful tool for debugging in the linux environment. It has powerful functions and many instructions. If it is not used frequently, many instructions cannot be remembered.
Today, there is a problem with a historical project that needs to be tracked. Since the colleague handed over before has left, and this project has not been maintained for a long time, the code is also relatively complicated; temporarily need to locate the problem, and there is no way to start, so we have to add a break at the entrance. Click to step through the process step by step.

Since it appears in a specific environment, and the machine that compiles the code is automatically compiled, the source code path is different, and the following method is used

1. Copy the source code to the target machine  
2. Attach to the specified process through gdb debugme pid 
3. Replace the source code search path through set substitute-path
   set substitute-path compile_src_path current_src_path
4. Through break file:func and break file:line Add a breakpoint at the determined entrance
5. Perform single-step debugging through the step or next command, and sort out the function call path in the whole process
6. Display the value of the variable through the display at a specific place, and combine the analysis of the specific function to make a judgment
7. Other commands such as bt, info, etc. are used together when necessary 


Finally, after 2 hours of debugging, the problem was found and the cause was located.

おすすめ

転載: blog.csdn.net/TragicGuy/article/details/81948074