gpt4 book ai didi

linux - 跟踪 : How to ascertain if a system call has called another system call?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:25:24 24 4
gpt4 key购买 nike

“strace 是一个系统调用跟踪器,即一个调试工具,它打印出另一个进程/程序进行的所有系统调用的跟踪。”如果系统调用递归工作或一个系统调用调用另一个系统调用怎么办。我怎样才能得到这些信息?

可能的解决方案 - 我们可以创建一个简单的变量缩进,当我们进入系统调用时递增,退出时递减。现在只需在每次调用前打印“缩进”空格数。所以我们可以得到这样的东西 -

05:31:09.449402 getpriority(PRIO_PROCESS, 0) = 20
05:31:09.450514 ioctl(7, 0xc0186201, 0xbef86ac0) = 0
05:31:09.451817 ioctl(7, 0xc0186201, 0xbef86c10) = 0
05:31:09.524328 writev(4, [{"\4", 1}, {"ServiceManager\0", 15}, {"ServiceManager: addService(SMS, 0x15988)\n\0", 42}], 3) = 58
05:31:09.526862 futex(0x134ac, FUTEX_WAKE, 2147483647) = 0
05:31:09.527847 getpriority(PRIO_PROCESS, 0) = 20
05:31:09.528758 ioctl(7, 0xc0186201, 0xbef86ac0) = 0
05:31:09.529847 ioctl(7, 0xc0186201, 0xbef86c10) = 0

strace 或其他工具是否已经提供了此功能,或者我是否需要更改源代码才能实现此功能?

最佳答案

系统调用被定义为内核空间和用户空间之间的边界,因此那里的任何递归都发生在内核内部并且无法被拦截。

strace 的工作方式是作为调试器附加到进程,让它自由运行,除非触发系统调用,此时会打印参数和返回值。它不知道内核内部发生了什么。

关于linux - 跟踪 : How to ascertain if a system call has called another system call?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5339593/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com