新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 使用 SystemTap 調(diào)試內(nèi)核

使用 SystemTap 調(diào)試內(nèi)核

作者: 時(shí)間:2016-09-12 來(lái)源:網(wǎng)絡(luò) 收藏

#!/usr/bin/env stap## display the top 10 syscalls called in last 5 seconds#global syscallsfunction print_top () {cnt=0log (SYSCALLttttCOUNT)foreach ([name] in syscalls-) {printf(%-20stt%5dn,name, syscalls[name])if (cnt++ == 10)break}printf(--------------------------------------n)delete syscalls}probe syscall.* {syscalls[probefunc()]++}probe timer.ms(5000) {print_top ()}

它的輸出結(jié)果一目了然:

圖

看看是誰(shuí)在偷偷動(dòng)我的文件

有時(shí)候,我們?nèi)绻辛藧阂獾牟《拒浖?,?huì)發(fā)現(xiàn)某些文件莫名其妙的被修改,下面這個(gè)例子可以幫你監(jiān)視誰(shuí)在修改你的文件。

#!/usr/bin/env stap## monitor who is messing my file of secrets#probe generic.fop.open {if(filename == secrets)printf(%s is opening my file: %sn, execname(), filename)}

我們運(yùn)行這個(gè)腳本,在另外一個(gè)窗口做一些操作,來(lái)看看它的輸出結(jié)果:

圖

打印ANSI字符串

SystemTap不僅僅是一個(gè)簡(jiǎn)單的調(diào)試工具,強(qiáng)大的腳本語(yǔ)言能力讓它同樣能做一些有趣的事情,

下面這個(gè)例子就可以對(duì)輸出的字符進(jìn)行美化:

#!/usr/bin/env stap## print colorful ANSI strings#probe begin {printf(a \ b |);for (c = 40; c 48; c++)printf( %d , c);printf(12);for (l = 0; l 71; l++)printf(-);printf(12);for (r = 30; r 38; r++)for (t = 0; t 2; t++) {printf(%d |, r);for (c = 40; c 48; c++)printf(