strace 4.6版本用法输出
某嵌入式设备的strace版本及用法输出
strace -- version 4.6
usage: strace [-CdDffhiqrtttTvVxx] [-a column] [-e expr] ... [-o file]
[-p pid] ... [-s strsize] [-u username] [-E var=val] ...
[command [arg ...]]
or: strace -c [-D] [-e expr] ... [-O overhead] [-S sortby] [-E var=val] ...
[command [arg ...]]
-c -- count time, calls, and errors for each syscall and report summary
-C -- like -c but also print regular output while processes are running
-f -- follow forks, -ff -- with output into separate files
-F -- attempt to follow vforks, -h -- print help message
-i -- print instruction pointer at time of syscall
-q -- suppress messages about attaching, detaching, etc.
-r -- print relative timestamp, -t -- absolute timestamp, -tt -- with usecs
-T -- print time spent in each syscall, -V -- print version
-v -- verbose mode: print unabbreviated argv, stat, termio[s], etc. args
-x -- print non-ascii strings in hex, -xx -- print all strings in hex
-a column -- alignment COLUMN for printing syscall results (default 40)
-e expr -- a qualifying expression: option=[!]all or option=[!]val1[,val2]...
options: trace, abbrev, verbose, raw, signal, read, or write
-o file -- send trace output to FILE instead of stderr
-O overhead -- set overhead for tracing syscalls to OVERHEAD usecs
-p pid -- trace process with process id PID, may be repeated
-D -- run tracer process as a detached grandchild, not as parent
-s strsize -- limit length of print strings to STRSIZE chars (default 32)
-S sortby -- sort syscall counts by: time, calls, name, nothing (default time)
-u username -- run command as username handling setuid and/or setgid
-E var=val -- put var=val in the environment for command
-E var -- remove var from the environment for command
零碎的strace文档记录
strace尝试把参数以原结构显示,如果系统调用失败,可能显示不出来。解释了为什么参数有的是一个地址。结构是用大括号注释的,但是简单的指针和数组是用方括号和逗号分隔元素来打印的,bit-sets也使用方括号
unfinished,strace的一个系统调用未完成,另一个系统调用开始了,上一个完成以后会显示resumed
中断一个可以重启的系统调用,内核指定
字符指针被取消引用并打印为C字符串。字符串中的非打印字符通常由普通的C转义码表示。只打印字符串的第一个strsize(默认为32)字节;较长的字符串在右引号后附加一个省略号。
strace参数详解
args | desc |
---|---|
-c | 统计每个系统调用的的时间,调用次数和错误次数,并报告总结 |
-C | 和-c类似,在进程运行时定时输出 |
-f | 跟踪fork |
-ff | 输出到不同的文件 |
-F | 尝试跟踪vforks,-f是vforks不跟踪 |
-h | 输出帮助信息 |
-i | 输出系统调用时的指令指针 |
-q | 禁止输出attach和detach的信息 |
-r | 输出相对时间戳 |
-t | 输出绝对时间戳 |
-tt | 输出微秒 |
-T | 输出每个系统调用的时间开销 |
-V | 输出版本信息 |
-v | 输出未缩写的argv,stat,termio等,默认不输出,取消缩写 |
-x | 非ascii字符串hex输出 |
-xx | 所有字符串hex输出 |
-a | 设置返回值输出位置,默认40 |
-e | 指定表达式 |
-o | 输出到文件 |
-O | set overhead for tracing syscalls to OVERHEAD usecs |
-p | 指定跟踪的进程id |
-D | 将跟踪的进程作为分离的子进程,而不是父进程 |
-s | 设置打印的字符串长度,默认32 |
-S | 排序系统调用计数,通过时间,调用名,名字等,默认时间 |
-u | 以指定用户名的UID和GID运行命令 |
-E | 设置运行命令时的系统变量 |
---- | ---- |
后面是5.5版本命令 | 后面是5.5版本命令 |
-b | execve |
-D | run tracer process as a grandchild, not as a parent |
-DD | run tracer process in a separate process group |
-DDD | run tracer process in a separate session |
-k | 获取栈信息在每个系统调用之间 |
屏蔽进程退出状态 | |
-y | print paths associated with file descriptor arguments |
-yy | print protocol specific information associated with socket file descriptors |
-e选项详解
后面会有一个简单的输出例子
选项:trace, abbrev, verbose, raw, signal, read, write
5.5版本新添选项:fault, inject, status, kvm
过滤选项
signal, status
-e signal=SET
只跟踪指定的信号
-e status=SET
只跟踪指定返回值的调用
statuses: successful, failed, unfinished, unavailable, detached
trace
-e trace=[syscall name]
只跟踪指定的系统调用
输出选项
abbrev, verbose, raw
-e abbrev=SET verbose=SET raw=SET
输出展示格式:
abbrev
:缩写输出
verbose
:取消引用输出
raw
:直接打印未编码的参数
read, write
-e read=SET write=SET
read,write,dump数据从文件描述符中读写的
kvm
-e kvm=vcpu, --kvm=vcpu
print exit reason of kvm vcpu
篡改选项
inject, fault
-e inject=SET[:error=ERRNO|:retval=VALUE][:signal=SIG][:syscall=SYSCALL]
[:delay_enter=DELAY][:delay_exit=DELAY][:when=WHEN],
--inject=SET[:error=ERRNO|:retval=VALUE][:signal=SIG][:syscall=SYSCALL]
[:delay_enter=DELAY][:delay_exit=DELAY][:when=WHEN]
perform syscall tampering for the syscalls in SET
delay: milliseconds or NUMBER{s|ms|us|ns}
when: FIRST, FIRST+, or FIRST+STEP
-e fault=SET[:error=ERRNO][:when=WHEN], --fault=SET[:error=ERRNO][:when=WHEN]
synonym for -e inject with default ERRNO set to ENOSYS.
常用参数
跟踪网络调用
strace -v -f -r -xx -s 202800 -e trace=recv -e verbose=recv -p [pid]
-v取消缩写;
-f跟踪fork;
-r输出相对时间戳;
-T输出每个调用的时间开销;
-xx输出hex编码;
-s指定字符串大小限制;
-e指定只看recv系统调用,并且取消引用输出
效果
recv(5, "A", 102400, 0) = 1
如果想看地址,不取消引用,可以用:
strace -v -f -r -xx -s 202800 -e trace=recv -e raw=recv -p [pid]
效果:
recv(0x5, 0xbe8d64fc, 0x19000, 0) = 0x27d8
问题和思考
- 遇到输出选项是verbose,但是recv系统调用参数显示成地址,没有取消引用?
- 可能是返回值位置的原因??
- 在树莓派测试,也是arm,strace5.5,recv可以正常取消引用超过10000长度的数据。
- 编译一个用recv的程序传上去试一试。
- 全部保持引用,看看那个地址有没有被别的调用用到:
strace -f -r -xx -s 202800 -e raw=all -p [pid]