In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
This article is to share with you the introduction of strace and gdb debugging tools in Linux. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.
Strace debugging tool
The strace tool is used to track system calls and received signals during process execution, including parameters, return values, and execution time. In Linux, if the user program wants to access the system device, it must switch from the user mode to the kernel state, which is initiated and completed by the system call.
Common parameters of strace:
-c count the execution time, number of calls and errors of each system call, and give a report when the program exits
-p pid tracks specified processes, and you can use multiple-p to track multiple processes at the same time
-o filename strace default output to stdout,-o can write the output to the specified file
-f tracks the system calls of child processes generated by fork
-ff is often used with the-o option, and system calls generated by different processes (child processes) are output to various filename.pid files
-F attempts to trace vFork child process system calls. Note: when used with-f, vfork is not tracked.
-e expr output filter expression, which can filter out unwanted strace results
-e trace=set specifies to trace system calls in set
-e trace=network tracks all system calls related to the network
-e strace=signal tracks all system calls related to system signals
-e trace=ipc tracks all system calls related to process communication
-e signal=set specifies to track the signal in the set
-e read=set outputs data read from the specified file, such as-e read=3,5
-e write=set outputs data written to the specified file, such as-e write=1
-r print the relative time of each system call
-t add time information before each line in the output
-tt adds time information before each line in the output, which is accurate to microseconds
-ttt adds time information before each line in the output, and the output is relative time.
-s specifies the length of each line of output string (default is 32)
Examples of strace usage:
Strace-t whoami # tracks the whoami executable program and prints the execution time before each line outputs the result
Strace-p 17151-p 17152-p 17153 # simultaneously tracks processes 17151, 17152, 17153
Strace-f-e trace=read,write-p 17151-o log # tracks process 17151 and read and write system calls in child processes, output to log file
Gdb debugging tool
GDB is a powerful program debugging tool under UNIX released by GNU open source organization. Gcc compiles with the-g parameter to enable executable programs to add gdb debugging information.
(1) info
Abbreviation: I, list the information of the GDB subcommand, such as info break,info variables,info stack, etc.
(2) list [file:] function
Abbreviation: l, look at the context of the current line, the default is 10 lines, or you can set the source code to be listed at a function.
(3) edit [file:] function
Abbreviation: e, edit the current line, or you can edit the source code of a function.
(4) break [file:] function
Abbreviation: B, set breakpoints, which can be set on a line or at a function.
(5) run [arglist]
Abbreviation: r, run the program to stop at the breakpoint, and add the parameters needed by the debugger after the run command.
(6) next
Abbreviation: n, single statement execution.
(7) continue
Abbreviation: C, continue to run the program to the next breakpoint.
(8) print
Abbreviation: P, print the value of the variable.
(9) bt
View function stack information.
(10) enter
Enter key to repeat the last debug command.
(11) help [name]
Displays help information for the specified gdb command.
(12) quit
Abbreviation: Q, quit gdb.
After reading the above, do you have any further understanding of the use of strace and gdb debugging tools? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel. Thank you for reading.
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.