In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to use gdb program debugging tools in Linux system", the content is simple and easy to understand, clear organization, I hope to help you solve doubts, let Xiaobian lead you to study and learn "how to use gdb program debugging tools in Linux system" this article bar.
I. Regular debugging
gdb is a commonly used program debugging tool under Linux, of course, provided that gcc/g++ is compiled with the-g parameter, so that the compiled executable program will be added with gdb debugging information.
There are many gdb commands, but the commonly used ones mainly include the following commands:
(1)list [file:]functuon
Command abbreviation is l, view the source code, without parameters, down the source code, plus parameters-l, up the source code, the default display 10 lines.
You can also set the source code to list in a function. Note that if it is a non-member function, use file:function. If it is a class member function, use class::functuon.
(2)edit [file:]function
Command abbreviation is e, edit the current line, you can also edit the source code of a function (rules with list).
(3)break [file:]function
Command abbreviation is b, set breakpoint, can be set in a line or a function (rule with list), in addition to can also be directly used to set breakpoint file name: line number.
(4)info
Command abbreviation is i, list gdb subcommand information, such as: info break, info variables, info stack, etc.
(5)run [arglist]
Command abbreviation is r, run the program to the breakpoint stop, run command can be added after the debugging program needs parameters.
(6)next
Command abbreviation is n, single step debugging statement, if encountered when a function is also a single step statement without entering the function, similar to VC F10.
(7)step
Command abbreviation is s, step debug statement, if you encounter a function will directly enter the function inside, similar to VC F11.
(8)continue
The abbreviation for fame is c. Continue running the program to the next breakpoint.
(9)what
View variable types.
(10)print
The command abbreviation is p and prints the value of the variable.
(11)backtrace
The command abbreviation is bt, view stack information.
(12)enter
Enter to repeat the previous debug command.
(13)help [name]
Displays help information for the specified gdb command.
(14)quit
The command abbreviation is q, exit gdb.
gdb debugging running program, with gdb.exe loader, gdb debugging core dump, with gdb .exe .core loader, execution of r command can start running the program. After editing the code in gdb, you don't need to exit gdb, but make it directly in gdb, otherwise the breakpoint and other information set before will be burned.
Second, multithreaded debugging
(1)info threads
The command abbreviation is info thr, which displays all threads currently debuggable. Each thread will have an ID assigned to it by gdb. This ID will be used later when operating threads. The thread with * in front is the thread currently debugged.
(2)thread ID
The command acronym is thr and switches the thread currently debugged to the thread with the specified ID.
(3)thread apply ID1 ID2 command
Command abbreviation rules as above, let one or more threads execute gdb command.
(4)thread apply all command
Command abbreviation rules are the same as above, so that all debugged threads execute gdb command.
(5)set scheduler-locking off|on|step
When debugging a multithreaded program, use the step or continue command to debug the current thread, and other threads are also executing concurrently. This command can be passed by off.| on| Step to control thread execution, i.e.:
off: No threads are locked, i.e. all threads execute, which is the default.
on: Only the currently debugged program will be executed.
Step: During a single step, only the current thread will execute, except in the case of the next function.
The above is "Linux system gdb program debugging tool how to use" all the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to 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.