免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 3780 | 回复: 16
打印 上一主题 下一主题

[求助]如何查看内核代码每条指令的地址? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-03-28 18:29 |只看该作者 |倒序浏览
最近在做虚拟机安全方面的研究,想要找出内核中某些函数调用点的地址,请问有什么好方法么?

论坛徽章:
0
2 [报告]
发表于 2011-03-28 20:22 |只看该作者
就高手,帮顶!!!

论坛徽章:
0
3 [报告]
发表于 2011-03-28 22:13 |只看该作者
本帖最后由 灌水菜鸟 于 2011-03-28 22:14 编辑

不是很清楚你的需求,你说的调用点是什么?是要函数的地址么?如果是的话:
-)内核的vmlinux可以直接用objdump看;
-)运行时可以看 /proc/kallsyms, 或者/proc/kcore

论坛徽章:
0
4 [报告]
发表于 2011-03-28 22:41 |只看该作者
回复 3# 灌水菜鸟


    不是函数定义的地址~~ 比如说下面这个例子,调用了printf函数,我可以通过反汇编看到调用点的地址。假如说内核中有些地方会调用HYPERVISOR_mm_update()这个函数,我想找出内核中所有调用这个函数的点……不知道这样说您可以明白么?
80483b5:        89 e5                        mov    %esp,%ebp
80483b7:        83 e4 f0                     and    $0xfffffff0,%esp
80483ba:        83 ec 10                     sub    $0x10,%esp
        printf ( "Hello World\n" );
80483bd:        c7 04 24 a4 84 04 08         movl   $0x80484a4,(%esp)
80483c4:        e8 27 ff ff ff               call   80482f0 <puts@plt>
        printf ( "Hello World\n" );
80483c9:        c7 04 24 a4 84 04 08         movl   $0x80484a4,(%esp)
80483d0:        e8 1b ff ff ff               call   80482f0 <puts@plt>
        return EXIT_SUCCESS;

论坛徽章:
0
5 [报告]
发表于 2011-03-28 22:47 |只看该作者
没想过这个问题,不好意思,帮不上你了。

论坛徽章:
0
6 [报告]
发表于 2011-03-28 22:52 |只看该作者
回复 5# 灌水菜鸟


       还是谢谢了~~~!

论坛徽章:
0
7 [报告]
发表于 2011-03-28 23:39 |只看该作者
动态或静态?

静态的话普通调用用cscope/ctags就可以分析出来啊
动态的话神码ftrace, systemtap上马吧

论坛徽章:
0
8 [报告]
发表于 2011-03-28 23:42 |只看该作者
oh, sorry,看错了,要指令地址。

论坛徽章:
0
9 [报告]
发表于 2011-03-29 00:05 |只看该作者
Function caller in linux kernel
http://stackoverflow.com/questio ... ler-in-linux-kernel

You can get the caller with __builtin_return_address(0).

The caller's caller is __builtin_return_address(1) and so on.

It's a GCC extension, documented in the gcc manual: http://gcc.gnu.org/onlinedocs/gcc/Return-Address.html

Edit: I should probably point out, that gets you the address of the caller. If you want the function name you can print it with %pS, eg:

printk("Caller is %pS\n", __builtin_return_address(0));

If you don't want to print it, you can use kallsyms_lookup() etc.



Note, printk with %pS is only supported on later version of Linux. Ref:
http://lwn.net/Articles/289064/

Another article about kallsyms_lookup:
http://daydreamer.idv.tw/rewrite.php/read-55.html

论坛徽章:
0
10 [报告]
发表于 2011-03-29 00:36 |只看该作者
回复 9# accessory


    版主~~感谢您提供的方法~~!
    可是这个方法对我来说有点不现实,我是要找出内核中所有调用某个函数的指令的地址,首先我不知道有几个,其次我也不知道具体是在哪里,用您提供的方法有点困难啊
    请问有没有什么别的好方法?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP