View
243
Download
3
Category
Preview:
Citation preview
Linux Strace tool user guide
1 / 9
Reversion Record
Date Rev Change Description Author
2017-10-13 V0.1 Initial Zhang Yongchang
Linux Strace tool user guide
2 / 9
catalog 1 PURPOSE ...............................................................................................................................................................4
2 TERMINOLOGY ......................................................................................................................................................4
3 ENVIRONMENT ......................................................................................................................................................4
3.1 HARDWARE PLATFORM .......................................................................................................................................4 3.2 SOFTWARE PLATFORM ........................................................................................................................................4
4 INSTALL GUIDE .....................................................................................................................................................4
4.1 DOWNLOAD THE STRACE .....................................................................................................................................4 4.2 ENVIRONMENT PREPARED ...................................................................................................................................5 4.3 COMPILE STRACE ...............................................................................................................................................5
5 USE GUIDE .............................................................................................................................................................5
5.1 SIMPLE EXAMPLE ................................................................................................................................................5 5.1.1 Trace system call ......................................................................................................................................6 5.1.2 Trace signal ..............................................................................................................................................7
5.2 STATISTICAL SYSTEM CALL ..................................................................................................................................8 5.3 OTHER OPTIONS DESCRIPTION ............................................................................................................................8 5.4 TRACE A EXIST PROCESS .....................................................................................................................................8
Linux Strace tool user guide
3 / 9
Figure index Figure 1 trace system call ...................................................................................................................................6
Figure 2 trace signal (1) ......................................................................................................................................7
Figure 3 trace signal (2) ......................................................................................................................................8
Figure 4 statistical system call .............................................................................................................................8
Linux Strace tool user guide
4 / 9
1 Purpose
This guide help user install the strace on ARM, and show how to use Strace to intercept and record the system calls.
2 Terminology
strace: strace is a diagnostic, debugging and instructional user space utility for Linux. It
is used to monitor and tamper with interactions between processes and the Linux
kernel, which include system calls, signal deliveries, and changes of process state. The
operation of strace is made possible by the kernel feature known as ptrace.
3 Environment
3.1 Hardware Platform
SOC: Rockchip RK3399
GPU: Mali T864 (800MHz)
CPU: Dual-core Cortex-A72 up to 2.0GHz (real frequency is 1.8GHz) Quad-core Cortex-A53 up to 1.5GHz (real frequency is 1.4GHz)
3.2 Software Platform
OS: Ubuntu 16.04 (32bit)
4 Install Guide
4.1 Download the strace
wget https://nchc.dl.sourceforge.net/project/strace/strace/4.19/strace-4.19.tar.xz
tar -xvf strace-4.19.tar.xz
cd ~/
mkdir -p build-starce
To assume the code directory:
strace source code:~/strace-4.19
strace build:~/build-strace
Linux Strace tool user guide
5 / 9
4.2 Environment Prepared
sudo apt-get install flex bison libelf-dev libaudit-dev libdw-dev libunwind-dev python-dev
sudo apt-get install libnuma-dev libunwind8 libunwind8-dev
sudo apt-get install libslang2 libslang2-dev
sudo apt-get install binutils-multiarch-dev elfutils libiberty-dev
sudo apt-get install gcc-arm-linux-gnueabihf
4.3 Compile Strace
cd ~/build-strace
CC=arm-linux-gnueabihf-gcc LD=arm-linux-gnueabifh-ld RANLIB=arm-linux-gnueabihf-ranlib ../strace-
4.19/configure --host=arm-linux --target=arm-linux --prefix=/usr/
make –j4
sudo make install
• If your system is 64bit, you should specific --target=aarch64-linux, --host=aarch64-linux.
5 Use Guide
5.1 Simple example
Create a test file test.c:
#include <stdio.h>
int main()
{
int num = 0;
printf(“Please input number: ”);
scanf(“%d”, &num);
printf(“%09d\n”, num);
return 0;
}
Compile test:
Linux Strace tool user guide
6 / 9
gcc –o test test.c
5.1.1 Trace system call
Figure 1 trace system call
From the output we can know:
1. The system calls the exec to start a new process, then to prepare the environment. 2. Pause at "read (0,", and wait for input the number.
Linux Strace tool user guide
7 / 9
3. Input the number “99”, the writer function output “000000099\n” to the screen. 4. Call exit_group() to complete the entire process
5.1.2 Trace signal
Figure 2 trace signal (1)
Now, we don’t input anything, it block at the read function. Start a new terminal:
killall test
And you can see the strace output:
Linux Strace tool user guide
8 / 9
Figure 3 trace signal (2)
The test process receives the “SIFTERM” signal, it will be terminated.
5.2 Statistical system call
Strace can count times, calls and errors for the system call, and report a summary.
Figure 4 statistical system call
5.3 Other Options description
Please read Strace command manual
man strace
5.4 Trace a exist process
Attach to the process with the process ID “pid” and begin tracing. The trace may be terminated at any time by a keyboard interrupt signal (CTRL-C). Strace will respond by detaching itself from the traced process(es) leaving it (them) to continue running. Multiple -p options can be used to attach to many processes in addition to command (which is optional if at least one -p option is given). -p "`pidof PROG`" syntax is supported.
Recommended