博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
systemtap函数调用栈信息不齐的原因和解决方法 :print_backtrace
阅读量:4029 次
发布时间:2019-05-24

本文共 2916 字,大约阅读时间需要 9 分钟。

http://blog.yufeng.info/archives/1229 

本文链接地址: 

有时候在看系统代码的时候,我们很难从源码中看出我们感兴趣的函数是如何被调用的,因为调用路径有可能太多。用户空间的程序gdb设断点是个好的方法,内核的就麻烦了。这时候systemtap可以帮忙, 比如:

$uname -r
2.6.18-164.el5
 
$stap -V
SystemTap translator/driver (version 1.5/0.137 non-git sources)
Copyright (C) 2005-2011 Red Hat, Inc. and others
This is free software; see the source for copying conditions.
enabled features: LIBRPM LIBSQLITE3 NSS BOOST_SHARED_PTR TR1_UNORDERED_MAP NLS
 
$sudo stap -e 'probe vfs.add_to_page_cache {print_backtrace();println("")}'
 0xffffffff8000c633 : add_to_page_cache+0x0/0xc1 [kernel]
 0xffffffff800c4565 : add_to_page_cache_lru+0xe/0x22 [kernel]
 0xffffffff80025a10 : find_or_create_page+0x4b/0x72 [kernel]
 0xffffffff80019b72 : __getblk+0x105/0x236 [kernel]
 0xffffffff8803826a
 0xffff811838293600 (inexact)
...

但是有时候我们并没能得到全部的符号信息, 比如# 0xffffffff8803826a 这行是谁没打印出来吧。 原因是我们的模块可能被未知的模块所调用,这些模块的符号信息没有自动加载,所以systemtap当然就不知道谁是谁了!

解决方法 man stap 文档写的很清楚:

-d MODULE

Add symbol/unwind information for the given module into the kernel object module. This may enable symbolic tracebacks from those mod-
ules/programs, even if they do not have an explicit probe placed into them.

–ldd Add symbol/unwind information for all shared libraries suspected by ldd to be necessary for user-space binaries being probe or listed

with the -d option. Caution: this can make the probe modules considerably larger.

–all-modules

Equivalent to specifying “-dkernel” and a “-d” for each kernel module that is currently loaded. Caution: this can make the probe modules
considerably larger.

$sudo stap --all-modules -e 'probe vfs.add_to_page_cache {print_backtrace();println("")}'
 0xffffffff8000c633 : add_to_page_cache+0x0/0xc1 [kernel]
 0xffffffff800c4565 : add_to_page_cache_lru+0xe/0x22 [kernel]
 0xffffffff80025a10 : find_or_create_page+0x4b/0x72 [kernel]
 0xffffffff80019b72 : __getblk+0x105/0x236 [kernel]
 0xffffffff8803826a : journal_get_descriptor_buffer+0x30/0x0 [jbd]
 0xffff81183f50c000 (inexact)

0xffffffff8803826a 这行我们知道是谁了把, jbd. 知道了这个模块我们就可以这样:

$sudo stap -d jbd -e 'probe vfs.add_to_page_cache {print_backtrace();println("")}'           
 0xffffffff8000c633 : add_to_page_cache+0x0/0xc1 [kernel]
 0xffffffff800c4565 : add_to_page_cache_lru+0xe/0x22 [kernel]
 0xffffffff80025a10 : find_or_create_page+0x4b/0x72 [kernel]
 0xffffffff80019b72 : __getblk+0x105/0x236 [kernel]
 0xffffffff8803826a : journal_get_descriptor_buffer+0x30/0x0 [jbd]
 0xffff81183f50c000 (inexact)
...

二个一样的的运行效果,只是生成的模块大小不一样,我们来看下:

$sudo stap -d jbd -m demo -p4 -e 'probe vfs.add_to_page_cache {print_backtrace();println("")}'
demo.ko
$ll demo.ko
-rw-r--r-- 1 root root 2943293 Mar 26 22:14 demo.ko
 
$sudo stap --all-modules -m demo -p4 -e 'probe vfs.add_to_page_cache {print_backtrace();println("")}'
demo.ko
$ll demo.ko
-rw-r--r-- 1 root root 3890409 Mar 26 22:15 demo.ko

–all-modules的生成要大不少,不过很适合我们这样的懒人!

用户空间的程序用–ldd来搞定!

玩得开心!

Post Footer automatically generated by  for wordpress.

转载地址:http://trobi.baihongyu.com/

你可能感兴趣的文章
通过C++反射实现C++与任意脚本(lua、js等)的交互(二)
查看>>
利用清华镜像站解决pip超时问题
查看>>
[leetcode BY python]1两数之和
查看>>
微信小程序开发全线记录
查看>>
Centos import torchvision 出现 No module named ‘_lzma‘
查看>>
网页设计里的浮动 属性
查看>>
Maximum Subsequence Sum
查看>>
PTA:一元多项式的加乘运算
查看>>
CCF 分蛋糕
查看>>
解决python2.7中UnicodeEncodeError
查看>>
小谈python 输出
查看>>
Django objects.all()、objects.get()与objects.filter()之间的区别介绍
查看>>
python:如何将excel文件转化成CSV格式
查看>>
Django 的Error: [Errno 10013]错误
查看>>
机器学习实战之决策树(一)
查看>>
[LeetCode By Python] 2 Add Two Number
查看>>
python 中的 if __name__=='__main__' 作用
查看>>
机器学习实战之决策树二
查看>>
[LeetCode By Python]7 Reverse Integer
查看>>
[LeetCode By Python]9. Palindrome Number
查看>>