In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to debug C++ code under Linux", the content is simple and clear, and I hope it can help you solve your doubts. Let me lead you to study and learn how to debug C++ code under Linux.
Specific methods for debugging C++ code under Linux 1. After writing the code, we need to generate an executable file to run the program.
Gmail +-g test.cpp-o test
As instructed above, we compile test.cpp and generate the executable file test through Gmail +
two。 Run the executable file test
. / test
3. Then debug the code, type gdb on the command line, and then enter the environment of gdb.
Gdb
4. Then type file main, so we tell gdb we want to debug the main project
File main
5. Then we type l to list the information about the current code
L
6. Enter b plus function name or b plus line number to set the breakpoint at the corresponding location
B main (set a breakpoint at the main function)
B 5 (set breakpoint on line 5)
7. By typing r, we start running the code, and then the code stops at the set breakpoint
R
8. Then enter s to step into the function body
S
9. You can enter n for single-step debugging
N
10. We see the value of a variable num, and then we enter print num and see the value of the variable
Print num
11. Enter c, and the program continues execution
C
Description of the corresponding parameters
1 、 file
Load the executable program file being debugged. Because GDB is usually executed in the directory where the program is being debugged, the text name does not need to have a path.
Example: (gdb) file gdb-sample
2 、 r
Abbreviation for Run to run the program being debugged. If there is no breakpoint before, the entire program is executed; if there is a breakpoint, the program is paused at the first available breakpoint.
Example: (gdb) r
3 、 c
Shorthand for Continue to continue executing the debugged program until the next breakpoint or the end of the program.
Example: (gdb) c
4 、 b
B
B *
B *
B: shorthand for Breakpoint to set breakpoints. The breakpoint location can be specified by using "line number", "function name", "execution address" and so on.
The "*" symbol before the function name indicates that the breakpoint is set "at the prolog code generated by the compiler". If you don't know the assembly, you can ignore this usage.
5 、 set args [parameter]
When gdb is debugging, set the command line parameters.
6 、 bt
Bt can check the stack information. Down and up and a print stack information. Bt prints all stack information directly.
7 、 n
Single-step debugging
8 、 s
Step into
These are all the contents of this article entitled "how to debug C++ code under Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.