Detailed Explanation of Strace Command for Linux Application Debugging

Time:2019-8-12

1. Introduction to strace

Strace is often used to track system calls and signals received during process execution. Through strace, you can know which files the application has opened and what it has read and written, including the time consumed and the return value. In the Linux world, processes cannot directly access hardware devices. When processes need to access hardware devices (such as reading disk files, receiving network data, etc.), they must switch from user mode to kernel mode and access hardware devices through system calls. Strace can track system calls generated by a process, including parameters, return values, and execution time.

2. Install strace command

First, you need the following two files:


strace-4.5.15.tar.bz2          
strace-fix-arm-bad-syscall.patch 

The steps are as follows:

#tar -xjf strace-4.5.15.tar.bz2
#cd strace-4.5.15/
#patch -p1 <../strace-fix-arm-bad-syscall.patch
// The "p1" value removes the first path of the patch "<" refers to the location of the patch file, and ". /" refers to returning to the previous directory.
#. / configure -- host = ARM-Linux CC = arm-linux-gcc // configure
# Make // Generate strace command file

Then put the strace command file in the root directory / bin of our development board, and you can use it.

# CP strace/nfs_root/bin///nfs_root: the NFS system root directory of development board

3. Strace command uses

Common parameters are as follows:

– o) Specify the output file for tracking information
– t) Time to record tracking information in S
– tt) Time to record tracking information in uS

4. Examples

Testing led_text application through strace

# insmod led.ko//load LED driver
# strace -o log.txt ./led_text led1 on      
     // Test the led_text application, open led1, and export trace information to log.txt

The contents of log.txt are as follows:

 

summary

The above is a detailed description of the strace command of Linux application debugging introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave a message for me and Xiaobian will reply to you in time. Thank you very much for your support to developpaer.

Recommended Today

Manjaro uses SS method (requires nodejs environment)

Just installed manjaro, need to installshadowsocks-qt5+Proxy SwitchyOmega, but the latest Chrome has long blocked the installation of non Google store CRX channels. Here is my solution, which is troublesome but usable. If you are familiar with NPM commands in nodejs, you won’t find it troublesome, because nodejs is used for compilation. Preparation environment: A VPS […]