Summary of common commands based on Linux debugging tool strace and gdb _ PHP Tutorial

Source: Internet
Author: User
Tags add time
Summary of common commands based on Linux debugging tool strace and gdb. Strace and gdb are two common debugging tools in Linux. here is a summary of the common parameters of these two tools during use, which will be used for future reference. Strace debugging tools strace and gdb are two common debugging tools in Linux. here is a summary of the common parameters of these two tools during use, which will be used for future reference.
Strace debugging tool
The strace tool is used to track system calls during process execution and received signals, including parameters, return values, and execution time. In Linux, to access system devices, user programs must switch from user mode to kernel mode, which is initiated and completed through system calls.
Common strace parameters:
-C: calculates the invocation time, number of calls, and number of errors of each system call. a report is provided when the program exits.
-P pid tracks the specified process. Multiple-p can be used to track multiple processes at the same time.
-O filename strace is output to stdout by default, and-o can write the output to the specified file.
-F tracks system calls of sub-processes generated by fork
-Ff is often used with the-o option. system calls generated by different processes (sub-processes) are output to each filename. pid file.
-F tries to trace the system calls of the vfork sub-process. Note: When used together with-f, vfork is not tracked.
-E expr output filter expression, which can filter strace results that do not want to be output
-E trace = set indicates the system call in the trace set.
-E trace = network tracks all network-related system calls
-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 indicates the signal in the trace set.
-E read = set outputs the data read from the specified file, for example,-e read =
-E write = set output data written to the specified file, for example,-e write = 1
-R: print the relative time of each system call.
-T add time information before each row in the output
-Tt adds time information before each row in the output, and the time 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 the output string for each row (default value: 32)
Example of strace:
Strace-t whoami # trace the executable program of whoami and print the execution time before the output result of each row
Strace-p 17151-p 17152-p 17153 # simultaneously tracking processes 17151, 17152, and 17153
Strace-f-e trace = read, write-p 17151-o log # trace process 17151 and read and write system calls in sub-processes, and output to log files
Gdb debugging tool
GDB is a powerful UNIX program debugging tool released by the GNU open-source organization. The-g parameter is added during gcc Compilation to add gdb debugging information to the executable program.
(1) info
Abbreviation: I. It lists information about gdb sub-commands, such as info break, info variables, and info stack.
(2) list [file:] function
Abbreviation: l. check the context of the current row. the default value is 10. you can also set the source code to be listed in a function.
(3) edit [file:] function
Abbreviation: e. edit the current row or the source code of a function.
(4) break [file:] function
Abbreviation: B. You can set breakpoints in a row or function.
(5) run [arglist]
Abbreviation: r. run the program to stop at the breakpoint. after the run command, you can add the parameters required for debugging the program.
(6) next
Abbreviation: n. execute a single statement.
(7) continue
Abbreviation: c. continue to run the program to the next breakpoint.
(8) print
Abbreviation: p. print the variable value.
(9) bt
View function stack information.
(10) enter
Enter the enter key and repeat the previous debugging command.
(11) help [name]
Displays the help information of the specified gdb command.
(12) quit
Abbreviation: q. exit gdb.

Bytes. Strace debugging tool...

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.