用strace监视串口读写(转)

本文转自  zhiwei.li 的blog

 

用strace监视串口读写
2009-09-26

strace用来监视 操作串口的函数ioctl,从而达到监视串口数据的目的

监视ioctl, 还将相应的结构解码出来

-e read=set
执行一个 文件描述符的读取的数据的 十六进制和ASCII的完全的转储
比如,为了监视文件描述符3和5,   -e read=3,5

-e write=set
执行对 文件描述写数据的转储

首先,必须把相应设备的文件描述符用fuse这个命令找出来 

$ fuser /dev/ttyS0
/dev/ttyS0:          12476

$ ls -l /proc/12476/fd | grep /dev/ttyS0
lrwx—— 1 zhiwei zhiwei 64 09-26 16:10 9 -> /dev/ttyS0

需要 track fd为 9的的描述符

strace -e read=9 -p 12476 就能跟踪了

select, ioctl,  read, write 监视串口

-e expr

A qualifying expression which modifies which events to trace or how to trace them. The format of the expression is:

[qualifier=][!]value1[,value2]…

    where qualifier is one of trace, abbrev, verbose, raw, signal, read, or write and value is a qualifier-dependent symbol or number. The default qualifier is trace. Using an exclamation mark negates the set of values. For example, -eopen means literally -e trace=open which in turn means trace only the open system call. By contrast, -etrace=!open means to trace every system call except open. In addition, the special values all and none have the obvious meanings.

    Note that some shells use the exclamation point for history expansion even inside quoted arguments. If so, you must escape the exclamation point with a backslash.

-e trace=set
    Trace only the specified set of system calls. The -c option is useful for determining which system calls might be useful to trace. For example, trace=open,close,read,write means to only trace those four system calls. Be careful when making inferences about the user/kernel boundary if only a subset of system calls are being monitored. The default is trace=all.
-e trace=file
    Trace all system calls which take a file name as an argument. You can think of this as an abbreviation for -e trace=open,stat,chmod,unlink,… which is useful to seeing what files the process is referencing. Furthermore, using the abbreviation will ensure that you don’t accidentally forget to include a call like lstat in the list. Betchya woulda forgot that one.
-e trace=process
    Trace all system calls which involve process management. This is useful for watching the fork, wait, and exec steps of a process.
-e trace=network
    Trace all the network related system calls.
-e trace=signal
    Trace all signal related system calls.
-e trace=ipc
    Trace all IPC related system calls.
-e trace=desc
    Trace all file descriptor related system calls.
-e abbrev=set
    Abbreviate the output from printing each member of large structures. The default is abbrev=all. The -v option has the effect of abbrev=none.
-e verbose=set
    Dereference structures for the specified set of system calls. The default is verbose=all.
-e raw=set

Print raw, undecoded arguments for the specified set of system calls. This option has the effect of causing all arguments to be printed in hexadecimal. This is mostly useful if you don’t trust the decoding or you need to know the actual numeric value of an argument.
-e signal=set
    Trace only the specified subset of signals. The default is signal=all. For example, signal=!SIGIO (or signal=!io) causes SIGIO signals not to be traced.

-e read=set

Perform a full hexadecimal and ASCII dump of all the data read from file descriptors listed in the specified set. For example, to see all input activity on file descriptors 3 and 5 use -e read=3,5. Note that this is independent from the normal tracing of the read(2) system call which is controlled by the option -e trace=read.

-e write=set
    Perform a full hexadecimal and ASCII dump of all the data written to file descriptors listed in the specified set. For example, to see all output activity on file descriptors 3 and 5 use -e write=3,5. Note that this is independent from the normal tracing of the write(2) system call which is controlled by the option -e trace=write.

所以,这样
strace -e read=7 -e write=7 -p 4920
也是合法的命令

select() 和 poll()
poll    wait for some event on a file descriptor 等待在某个文件描述符上出现事件

你可能感兴趣的:(system,signal,descriptor,file,printing,network)