加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

附加到进程后,如何检查tracee是否在系统调用中?

发布时间:2020-12-13 19:36:15 所属栏目:Linux 来源:网络整理
导读:根据the ptrace manual page: Syscall-enter-stop and syscall-exit-stop are indistinguishable from each other by the tracer. The tracer needs to keep track of the sequence of ptrace-stops in order to not misinterpret syscall-enter- stop as s

根据the ptrace manual page:

Syscall-enter-stop and syscall-exit-stop are indistinguishable from
each other by the tracer. The tracer needs to keep track of the
sequence of ptrace-stops in order to not misinterpret syscall-enter-
stop as syscall-exit-stop or vice versa.

当我使用PTRACE_ATTACH附加到进程时,如何知道tracee当前是否在系统调用中?换句话说,如果我使用PTRACE_SYSCALL重新启动tracee,我怎么知道下一个系统调用停止是syscall-enter-stop还是syscall-exit-stop?

最佳答案

When I attach to a process using PTRACE_ATTACH,how do I know whether the tracee is currently in a syscall or not?

使用PTRACE_ATTACH连接到进程时,将向tracee发送STOP信号.

STOP信号在执行用户空间代码时,进入系统调用时生效,同时在内核中“慢速”系统调用中阻塞,以及从系统调用返回用户空间时生效.

通过检查指令指针和指令指针周围的指令,您通常可以确定进程是否正在执行用户空间代码,但这是关于它的.

但是,因为停止点基本上是随机的,所以您可以等待进程停止,然后使用PTRACE_SINGLESTEP单步执行每个线程,直到指令指针发生变化.然后你知道线程正在执行用户空间代码.

或者,如果单步执行导致线程长时间阻塞,则意味着线程正在执行阻塞的慢速系统调用.

Put differently,if I restart the tracee using PTRACE_SYSCALL,how do I know whether the next syscall-stop is a syscall-enter-stop or a syscall-exit-stop?

你没有,除非你知道tracee停止的状态.如上所述,您可以通过单步执行代码来执行此操作,直到指令指针发生更改.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读