Strace, a tool for Linux program debugging

Source: Internet
Author: User
Tags add time
Call strace [-dffhiqrtttTvxx] [-acolumn] [-eexpr] [call

Strace [-dffhiqrtttTvxx] [-acolumn] [-eexpr]... [-ofile] [-ppid]... [-sstrsize] [-uusername] [-Evar = val]... [-Evar]... [command [arg...]
Strace-c [-eexpr]... [-Ooverhead] [-Ssortby] [command [arg...]

Function

Tracks system calls and received signals during program execution. the general usage is to execute strace until commande ends, and output the name, parameters, and return values of the called system call to the standard output or to the file specified by-o.
Strace is a powerful debugging and analysis and diagnosis tool. you will find that it is an excellent helper when you want to debug a program that cannot see the source code or the source code cannot be compiled.
You can easily learn how a software can implement its functions through system calls. as a programmer, you can understand how the user and kernel states implement program functions through system calls and signals.
Each line of strace output includes the system call name, followed by parameters and return values.
Strace is an essential debugging tool used to monitor system calls. You can debug a new program or a running program (bind strace to an existing PID ).
Strace can be used not only by programmers, but also by common system administrators and users to debug system errors. It must be admitted that the output of strace is not always easy to understand, but many outputs are not important to most people. You will gradually learn to find the information you may need from a large number of outputs, such as permission errors and files not found, then strace will become a powerful tool.

Parameter description

-C: calculate the execution time, number of times, and number of errors of each system call.
-D: output strace debugging information about standard errors.
-F tracks the sub-processes generated by the fork call.
-Ff if-o filename is provided, the trace results of all processes are output to the corresponding filename. pid, which is the process number of each process.
-F attempts to trace vfork calls. in-f, vfork is not tracked.
-H outputs brief help information.
-I output the entry pointer of the system call.
-Q: Do not output the message about the disconnection.
-R prints the relative time, which is called by every system.
-T add time information before each row in the output.
-Tt adds time information before each row in the output, in microseconds.
-Ttt microsecond-level output, expressed in seconds.
-T shows the time consumed by each call.
-V outputs all system calls. some calls about environment variables, status, input and output are not output by default due to frequent calls.
-V outputs the version information of strace.
-X outputs non-standard strings in hexadecimal format
-Xx all strings are output in hexadecimal format.
-A column
Set the output position of the returned value. The default value is 40.
-E expr
Specify an expression to control how to trace. the format is as follows:
[Qualifier =] [!] Value1 [, value2]...
Qualifier can only be trace, abbrev, verbose, raw, signal, read, or write. value is a symbol or number used to limit. the default qualifier is trace. the exclamation point is a negative sign. for example:
-Eopen is equivalent to-e trace = open, indicating that only open calls are tracked.-etrace! = Open indicates all calls except open. There are two special symbols: all and none.
Note that some shells are used! To execute the commands in the history, so use \\\\.
-E trace = set
Only trace the specified system call. for example,-e trace = open, close, rean, and write indicates that only the four system calls are tracked. the default value is set = all.
-E trace = file
Only system calls related to file operations are tracked.
-E trace = process
Only system calls related to process control are tracked.
-E trace = network
Tracks all network-related system calls.
-E strace = signal
Tracks all system calls related to system signals
-E trace = ipc
Trace all system calls related to process communication
-E abbrev = set
Set the result set of the system call output by strace, such as-v and abbrev = none. the default value is abbrev = all.
-E raw = set
Displays the specified system call parameters in hexadecimal format.
-E signal = set
System signal of the trail. the default value is all. for example, signal =! SIGIO (or signal =! Io), indicating that the SIGIO signal is not tracked.
-E read = set
Output the data read from the specified file. for example:
-E read = 3, 5
-E write = set
Output data written to the specified file.
-O filename
Write strace output to file filename
-P pid
Trace the specified process pid.
-S strsize
Specify the maximum length of the output string. the default value is 32. the file name is always output.
-U username
Run the following command with the UID and GID of username.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.