日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

strace调试(Linux Device Driver)

發布時間:2023/12/20 linux 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 strace调试(Linux Device Driver) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

strace常用來跟蹤進程執行時的系統調用和所接收的信號。 在Linux世界,進程不能直接訪問硬件設備,當進程需要訪問硬件設備(比如讀取磁盤文件,接收網絡數據等等)時,必須由用戶態模式切換至內核態模式,通 過系統調用訪問硬件設備。strace可以跟蹤到一個進程產生的系統調用,包括參數,返回值,執行消耗的時間。
輸出參數含義
復制代碼

root@ubuntu:/usr# strace cat /dev/null
execve(“/bin/cat”, [“cat”, “/dev/null”], [/* 22 vars */]) = 0
brk(0) = 0xab1000
access(“/etc/ld.so.nohwcap”, F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f29379a7000
access(“/etc/ld.so.preload”, R_OK) = -1 ENOENT (No such file or directory)

brk(0) = 0xab1000
brk(0xad2000) = 0xad2000
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), …}) = 0
open(“/dev/null”, O_RDONLY) = 3
fstat(3, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), …}) = 0
read(3, “”, 32768) = 0
close(3) = 0
close(1) = 0
close(2) = 0
exit_group(0) = ?

復制代碼

每一行都是一條系統調用,等號左邊是系統調用的函數名及其參數,右邊是該調用的返回值。
strace 顯示這些調用的參數并返回符號形式的值。strace 從內核接收信息,而且不需要以任何特殊的方式來構建內核。
https://linux.cn/article-3935-1.html  
http://www.cnblogs.com/bangerlee/archive/2012/02/20/2356818.html

strace 命令是一個有力工具, 顯示所有的用戶空間程序發出的系統調用. 它不僅顯示調用, 還以符號形式顯示調用的參數和返回值. 當一個系統調用失敗, 錯誤的符號值(例如,
ENOMEM)和對應的字串(Out of memory) 都顯示. strace 有很多命令行選項; 其中最有用的是 -t 來顯示每個調用執行的時間, -T 來顯示調用中花費的時間, -e 來限制被跟蹤調用的類型, 以及-o 來重定向輸出到一個文件. 缺省地, strace 打印調用信息到 stderr.strace 從內核自身獲取信息.
這意味著可以跟蹤一個程序, 不管它是否帶有調試支持編譯(對 gcc 是 -g 選項)以及不管它是否 strip 過. 你也可以連接追蹤到一個運行中的進程, 類似于一個調試器的方式連接到一個運行中的進程并控制它.跟蹤信息常用來支持發給應用程序開發者的故障報告, 但是對內核程序員也是很有價值的.我們已經看到驅動代碼運行如何響應系統調用; strace 允許我們檢查每個調用的輸入和輸出數據的一致性.

weiqifa@weiqifa-Inspiron-3847:~/weiqifa/new_tm100/tm100$ strace --help strace: invalid option -- '-' usage: strace [-CdffhiqrtttTvVxxy] [-I n] [-e expr]...[-a column] [-o file] [-s strsize] [-P path]...-p pid... / [-D] [-E var=val]... [-u username] PROG [ARGS]or: strace -c[df] [-I n] [-e expr]... [-O overhead] [-S sortby]-p pid... / [-D] [-E var=val]... [-u username] PROG [ARGS] -c -- count time, calls, and errors for each syscall and report summary -C -- like -c but also print regular output -d -- enable debug output to stderr -D -- run tracer process as a detached grandchild, not as parent -f -- follow forks, -ff -- with output into separate files -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 -- verbose mode: print unabbreviated argv, stat, termios, etc. args -x -- print non-ascii strings in hex, -xx -- print all strings in hex -y -- print paths associated with file descriptor arguments -h -- print help message, -V -- print version -a column -- alignment COLUMN for printing syscall results (default 40) -b execve -- detach on this syscall -e expr -- a qualifying expression: option=[!]all or option=[!]val1[,val2]...options: trace, abbrev, verbose, raw, signal, read, write -I interruptible --1: no signals are blocked2: fatal signals are blocked while decoding syscall (default)3: fatal signals are always blocked (default if '-o FILE PROG')4: fatal signals and SIGTSTP (^Z) are always blocked(useful to make 'strace -o FILE PROG' not stop on ^Z) -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 -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 -P path -- trace accesses to path

如下是實例:

1|root@mid713l_lp_lvds:/ # strace -T /dev/input/event4 execve("/dev/input/event4", ["/dev/input/event4"], [/* 25 vars */]) = -1 EACCES (Permission denied) <0.000954> write(2, "strace: exec", 12strace: exec) = 12 <0.005100> write(2, ": ", 2: ) = 2 <0.001029> write(2, "Permission denied", 17Permission denied) = 17 <0.000269> write(2, "\n", 1 ) = 1 <0.002202> exit_group(1) = ? 1|root@mid713l_lp_lvds:/ # strace -T /dev/input/event4

strace -ttt system/xbi/busybox 查看busybox的使用調用情況 列表如下

strace -ttt system/xbi/busybox < 1357029942.164145 execve("system/xbin/busybox", ["system/xbin/busybox"], [/* 25 vars */]) = 0 1357029942.178440 brk(0) = 0x93c000 1357029942.182622 brk(0x93c4b8) = 0x93c4b8 1357029942.185678 set_tls(0x93c490, 0x11e464, 0, 0x1212d4, 0x121a50) = 0 1357029942.191336 ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 1357029942.195093 ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 1357029942.202561 getuid32() = 0 1357029942.208745 ioctl(0, TIOCGWINSZ, {ws_row=0, ws_col=0, ws_xpixel=0, ws_ypixel=0}) = 0 1357029942.213450 dup2(1, 2) = 2 1357029942.218086 write(2, "BusyBox v1.21.1 (2013-07-08 10:2"..., 41BusyBox v1.21.1 (2013-07-08 10:26:30 CDT)) = 41 1357029942.223062 write(2, " multi-call binary.\n", 20 multi-call binary. ) = 20 1357029942.227870 write(2, "BusyBox is copyrighted by many a"..., 539BusyBox is copyrighted by many authors between 1998-2012. Licensed under GPLv2. See source distribution for detailed copyright notices.Usage: busybox [function [arguments]...]or: busybox --list[-full]or: busybox --install [-s] [DIR]or: function [arguments]...BusyBox is a multi-call binary that combines many common Unixutilities into a single executable. Most people will create alink to busybox for each function they wish to use and BusyBoxwill act like whatever it was invoked as.Currently defined functions: ) = 539 1357029942.236050 write(2, "\t", 1 ) = 1 1357029942.240429 write(2, "[", 1[) = 1 1357029942.241966 write(2, ", ", 2, ) = 2 1357029942.244555 write(2, "[[", 2[[) = 2 1357029942.245292 write(2, ", ", 2, ) = 2 1357029942.246183 write(2, "acpid", 5acpid) = 5 1357029942.247706 write(2, ", ", 2, ) = 2 1357029942.248437 write(2, "add-shell", 9add-shell) = 9 1357029942.252078 write(2, ", ", 2, ) = 2 1357029942.252936 write(2, "addgroup", 8addgroup) = 8 1357029942.253986 write(2, ", ", 2, ) = 2 1357029942.255638 write(2, "adduser", 7adduser) = 7 1357029942.256660 write(2, ", ", 2, ) = 2 1357029942.258274 write(2, "adjtimex", 8adjtimex) = 8 1357029942.259147 write(2, ", ", 2, ) = 2 1357029942.262591 write(2, "arp", 3arp) = 3 1357029942.264350 write(2, ", ", 2, ) = 2 1357029942.266202 write(2, "arping", 6arping) = 6 1357029942.268030 write(2, ", ", 2, ) = 2 1357029942.271160 write(2, "ash", 3ash) = 3 1357029942.273002 write(2, ",\n", 2, ) = 2 1357029942.274807 write(2, "\t", 1 ) = 1 1357029942.275769 write(2, "awk", 3awk) = 3 1357029942.277461 write(2, ", ", 2, ) = 2 1357029942.279009 write(2, "base64", 6base64) = 6 1357029942.282269 write(2, ", ", 2, ) = 2 1357029942.283981 write(2, "basename", 8basename) = 8 1357029942.285709 write(2, ", ", 2, ) = 2 1357029942.287381 write(2, "beep", 4beep) = 4 1357029942.289075 write(2, ", ", 2, ) = 2 1357029942.292113 write(2, "blkid", 5blkid) = 5 1357029942.293823 write(2, ", ", 2, ) = 2 1357029942.295509 write(2, "blockdev", 8blockdev) = 8 1357029942.297266 write(2, ", ", 2, ) = 2 1357029942.298931 write(2, "bootchartd", 10bootchartd) = 10 1357029942.302217 write(2, ", ", 2, ) = 2 1357029942.303743 write(2, "brctl", 5brctl) = 5 1357029942.305639 write(2, ",\n", 2, ) = 2 1357029942.307332 write(2, "\t", 1 ) = 1 1357029942.309011 write(2, "bunzip2", 7bunzip2) = 7 1357029942.312026 write(2, ", ", 2, ) = 2 1357029942.313707 write(2, "bzcat", 5bzcat) = 5 1357029942.315428 write(2, ", ", 2, ) = 2 1357029942.317106 write(2, "bzip2", 5bzip2) = 5 1357029942.318821 write(2, ", ", 2, ) = 2 1357029942.323463 write(2, "cal", 3cal) = 3 1357029942.325169 write(2, ", ", 2, ) = 2 1357029942.326848 write(2, "cat", 3cat) = 3 1357029942.328519 write(2, ", ", 2, ) = 2 1357029942.331470 write(2, "catv", 4catv) = 4 1357029942.333238 write(2, ", ", 2, ) = 2 1357029942.334950 write(2, "chat", 4chat) = 4 1357029942.336668 write(2, ", ", 2, ) = 2 1357029942.337607 write(2, "chattr", 6chattr) = 6 1357029942.340726 write(2, ", ", 2, ) = 2 1357029942.342281 write(2, "chgrp", 5chgrp) = 5 1357029942.343967 write(2, ", ", 2, ) = 2 1357029942.345622 write(2, "chmod", 5chmod) = 5 1357029942.347408 write(2, ",\n", 2, ) = 2 1357029942.349119 write(2, "\t", 1 ) = 1 1357029942.352351 write(2, "chown", 5chown) = 5 1357029942.354056 write(2, ", ", 2, ) = 2 1357029942.355118 write(2, "chpasswd", 8chpasswd) = 8 1357029942.356883 write(2, ", ", 2, ) = 2 1357029942.362810 write(2, "chpst", 5chpst) = 5 1357029942.364715 write(2, ", ", 2, ) = 2 1357029942.366292 write(2, "chroot", 6chroot) = 6 1357029942.368063 write(2, ", ", 2, ) = 2 1357029942.370988 write(2, "chrt", 4chrt) = 4 1357029942.372698 write(2, ", ", 2, ) = 2 1357029942.374392 write(2, "chvt", 4chvt) = 4 1357029942.376113 write(2, ", ", 2, ) = 2 1357029942.377788 write(2, "cksum", 5cksum) = 5 1357029942.381052 write(2, ", ", 2, ) = 2 1357029942.382598 write(2, "clear", 5clear) = 5 1357029942.384305 write(2, ", ", 2, ) = 2 1357029942.385996 write(2, "cmp", 3cmp) = 3 1357029942.387659 write(2, ", ", 2, ) = 2 1357029942.390869 write(2, "comm", 4comm) = 4 1357029942.392656 write(2, ",\n", 2, ) = 2 1357029942.394381 write(2, "\t", 1 ) = 1 1357029942.396071 write(2, "conspy", 6conspy) = 6 1357029942.397044 write(2, ", ", 2, ) = 2 1357029942.398727 write(2, "cp", 2cp) = 2 1357029942.401569 write(2, ", ", 2, ) = 2 1357029942.403275 write(2, "cpio", 4cpio) = 4 1357029942.404976 write(2, ", ", 2, ) = 2 1357029942.406659 write(2, "crond", 5crond) = 5 1357029942.408353 write(2, ", ", 2, ) = 2 1357029942.411464 write(2, "crontab", 7crontab) = 7 1357029942.413264 write(2, ", ", 2, ) = 2 1357029942.414967 write(2, "cryptpw", 7cryptpw) = 7 1357029942.416708 write(2, ", ", 2, ) = 2 1357029942.418405 write(2, "cttyhack", 8cttyhack) = 8 1357029942.421579 write(2, ", ", 2, ) = 2 1357029942.423337 write(2, "cut", 3cut) = 3 1357029942.425098 write(2, ", ", 2, ) = 2

總結

以上是生活随笔為你收集整理的strace调试(Linux Device Driver)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。