在Ubuntu上安裝使用Systemtap,ubuntusystemtap

來源:互聯網
上載者:User

在Ubuntu上安裝使用Systemtap,ubuntusystemtap

  因為最近開始學習Nginx,在網上看到別人介紹了一款強大的核心探測工具Systemtap,於是便準備學習下這款探測工具為以後程式碼分析做準備。

  第一步便是安裝。在自己電腦上安裝的時候,也是費了一番勁兒。因此,為防止以後需要重新安裝,也希望可以協助後來學習的人,在這裡準備寫一篇部落格做一個記錄。

  以下便是安裝步驟:

  (0)、安裝elfutils,提供分析調試資訊的庫函數,及libcap-dev。

  藉助於Ubuntu方便強大的包管理器,可以很方便進行安裝,如下:

sudo apt-get install elfutils
sudo apt-get install  libcap-dev

  (1)、安裝systemtap。

  藉助於Ubuntu方便強大的包管理器,可以很方便進行安裝,如下:    

sudo apt-get install systemtap

  後續如果需要卸載,可執行如下命令:

sudo apt-get remove systemtap

  也可以通過源碼進行安裝,:https://sourceware.org/systemtap/ftp/releases/ 。解壓然後進入根目錄,執行如下命令:

./configuremakesudo make instal

  如果後續需要卸載,可進入根目錄,執行如下命令:

sudo make uninstall

  (2)、安裝debug symbols。

   1)、配置ddeb repository。

sudo cat > /etc/apt/sources.list.d/ddebs.list << EOFdeb http://ddebs.ubuntu.com/ precise main restricted universe multiverseEOFsudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ECDCAD72428D7C01sudo apt-get update

  上面添加倉庫地址也可以直接在ddebs.list檔案後面添加相應地址。

    2)、添加完repository之後,便是下載和你當前核心版本相對應的debug symbols。在這裡推薦一位外國朋友寫的指令碼,寫的非常好,博文連結(http://www.domaigne.com/blog/random/getting-debug-kernel-on-ubuntu/),感興趣的可以去學習學習。因此為了減少錯誤發生,這裡採用這裡的指令碼進行下載和安裝:

wget http://www.domaigne.com/download/tools/get-dbgsymchmod +x get-dbgsym

sudo ./get-dbgsy

  執行指令碼後,可以去做些其他事情,因為這裡可能需要等待較長的時間。

  3)、產生systemtap/libelf所需的模組資訊。將如下命令放入debug_ko.sh:

for file in `find /usr/lib/debug -name '*.ko' -print`do        buildid=`eu-readelf -n $file| grep Build.ID: | awk '{print $3}'`        dir=`echo $buildid | cut -c1-2`        fn=`echo $buildid | cut -c3-`        mkdir -p /usr/lib/debug/.build-id/$dir        ln -s $file /usr/lib/debug/.build-id/$dir/$fn        ln -s $file /usr/lib/debug/.build-id/$dir/${fn}.debugdone

    然後執行該檔案:

sudo ./debug_ko.sh

  (4)、測試安裝是否成功。執行如下命令:

stap -e 'probe kernel.function("sys_open") {log("hello world") exit()}'

  如果在終端列印出“hello world”說明安裝成功。如果沒有,繼續往下看。

  (5)、如果按照上述步驟安裝完之後,仍然不能使用,那麼請參考下面的情境分別進行補充。

  1)、如果執行(4)中的命令後,終端列印如下資訊:

stap: Symbol `SSL_ImplementedCiphers' has different size in shared object, consider re-linkingIn file included from include/linux/mutex.h:15:0,                 from /tmp/staphH2yQD/stap_6e022ad97cbe9c6f46b582f7a0eac81d_1242_src.c:25:include/linux/spinlock_types.h:55:14: error: ‘__ARCH_SPIN_LOCK_UNLOCKED’ undeclared here (not in a function)  .raw_lock = __ARCH_SPIN_LOCK_UNLOCKED, \              ^include/linux/spinlock_types.h:79:15: note: in expansion of macro ‘__RAW_SPIN_LOCK_INITIALIZER’  { { .rlock = __RAW_SPIN_LOCK_INITIALIZER(lockname) } }               ^include/linux/spinlock_types.h:82:16: note: in expansion of macro ‘__SPIN_LOCK_INITIALIZER’  (spinlock_t ) __SPIN_LOCK_INITIALIZER(lockname)                ^include/linux/mutex.h:111:18: note: in expansion of macro ‘__SPIN_LOCK_UNLOCKED’   , .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) \                  ^include/linux/mutex.h:117:27: note: in expansion of macro ‘__MUTEX_INITIALIZER’  struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)                           ^/tmp/staphH2yQD/stap_6e022ad97cbe9c6f46b582f7a0eac81d_1242_src.c:26:8: note: in expansion of macro ‘DEFINE_MUTEX’ static DEFINE_MUTEX(module_refresh_mutex);        ^scripts/Makefile.build:258: recipe for target '/tmp/staphH2yQD/stap_6e022ad97cbe9c6f46b582f7a0eac81d_1242_src.o' failedmake[1]: *** [/tmp/staphH2yQD/stap_6e022ad97cbe9c6f46b582f7a0eac81d_1242_src.o] Error 1Makefile:1398: recipe for target '_module_/tmp/staphH2yQD' failedmake: *** [_module_/tmp/staphH2yQD] Error 2WARNING: kbuild exited with status: 2Pass 4: compilation failed.  [man error::pass4]

  說明有些共用庫需要重新readlink,執行如下命令:

readlink /lib/modules/`uname -r`/build/

 

參考文章如下:

  1、http://www.domaigne.com/blog/random/running-systemtap-on-ubuntu/

  2、https://sourceware.org/systemtap/wiki/SystemtapOnUbuntu

  3、https://wiki.ubuntu.com/Kernel/Systemtap

【注】轉載需經本人同意並註明出處:http://www.cnblogs.com/wtb2012/p/5218889.html

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.