In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 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 language under Linux". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "how to debug c language under Linux".
Debugging is a problem that every programmer will face. How to improve the debugging efficiency of programmers and locate the problems in the program better and faster so as to speed up the progress of program development.
Debug instruction instruction:
1. Compile: gcc-o xxx xxx.c
two。 Generate a debuggable file: gcc-o xxx-g xxx.c
3. Debugger: gdb xxx
4. Execute the program:
Start starts from the first step of the program.
Run runs the program directly to the end or breakpoint
5. Set breakpoint: break line (number of lines) or function name or conditional expression
Break 6 sets a breakpoint on line 6
Break Swap sets a breakpoint at the entrance of the Swap function
Break 6 if I = = 10 set a breakpoint on line 6, requiring I = = 10
6. Delete breakpoints:
Clear deletes all breakpoints
Clear line number: delete the breakpoint of this line
Clear function name: delete the breakpoint of this function
7.info View breakpoint
8.c continue execution to the next breakpoint
9.print + variable print variable value
10.n next step
11.Q exit debugging
Example: first, we take "swapping the values of two numbers" as an example to debug. The code is as follows:
/ / We exchange the third value here to facilitate viewing the value of the variable void Swap (int* number1,int* number2) {int tmp= (* number1); (* number1) = (* number2); (* number2) = tmp;} int main () {int xdye 2; int yellow3; Swap (& x Magnetity); retrun 0;} 123456789101112131415 2. Follow the steps below to prepare for debugging:
Third, debug content (please enter instructions according to the following sequence number): ① runs the program: (gdb) run
According to the figure above, the program runs normally and exits.
② sets breakpoint: (gdb) break 12 (number of lines or function name)
③ starts debugging: (gdb) run
According to the figure above, the program starts at the breakpoint, that is, line 12.
④ print variable value: (gdb) print x (variable name)
According to the figure above, the variable x in line 11 is printed with a value of 2.
⑤ continues with the next step: (gdb) n
⑥ jumps to the next breakpoint: (gdb) c
According to the figure above, a second breakpoint is set on line 6 (the first breakpoint is on line 12), type "c" and jump directly to line 6, the second breakpoint.
⑦ continues execution until the exit function: (gdb) n
⑧ prints the value of the variable after the execution of the Swap function: (gdb) print x (gdb) print y
⑨ exit debugging: (gdb) Q
The above is all the contents of the article "how to debug c language 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.