有没有办法在同一进程中的另一个线程查看一个线程的寄存器的内容? [英] Is there a way to view the register contents of one thread from another thread within the same process?

查看:545
本文介绍了有没有办法在同一进程中的另一个线程查看一个线程的寄存器的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有一个包含三个线程的过程:A,B和C

Let's say I have a process that contains three threads: A, B, and C.

我想用线程A暂停线程B,检查线程B的寄存器值/堆栈的内容,然后再喂一些从线程B信息成线C(通过线程A)。

I want to use thread A to pause thread B, examine thread B's register values/stack contents, and then feed some of that information from thread B into thread C (via thread A).

根据从Linus Torvalds公司,在 ptrace的这个职位因为线程是同一过程中系统调用不会在这里工作。

According to this post from Linus Torvalds, the ptrace syscall won't work here because the threads are within the same process.

有没有实现这一点的另一种方式?

Is there another way of accomplishing this?

更新:这个问题讨论的为什么的没有关系'T工作;我想知道,如果一个变通的存在,不涉及创建子进程。

Update: this question discusses why it doesn't work; I'd like to know if a work-around exists that doesn't involve creating a child process.

推荐答案

您可能能够解决此使用的信号。选择一个其他未使用的信号,如: SIGUSR1 ,并使用<$ C $的 sa_sigaction 成员安装信号处理程序,它C>结构的sigaction 并指定 SA_SIGINFO 标记。块每一个线程的信号,除了利息(线程B)的主题。

You might be able to work around this using a signal. Pick an otherwise unused signal, eg SIGUSR1 and install a signal handler for it using the sa_sigaction member of struct sigaction and specifying the SA_SIGINFO flag. Block the signal in every thread except the thread of interest (thread B).

当您要检查线程B,使用发送线程导向信号,它 pthread_kill()。然后,信号处理程序将火,它的第三个参数将指向一个 ucontext_t 结构。这种结构的 uc_mcontext 成员是依赖于机器的 mcontext_t 结构,其中将包含在该点的寄存器值是线程被中断。

When you want to examine thread B, send a thread-directed signal to it using pthread_kill(). The signal handler will then fire, and its third argument will be a pointer to a ucontext_t structure. The uc_mcontext member of this structure is a machine-dependent mcontext_t structure, which will contain the register values at the point that the thread was interrupted.

您那么就需要设计一种安全的方式来传递这些值回线程A

You then just need to devise a safe way to pass these values back to thread A.

这篇关于有没有办法在同一进程中的另一个线程查看一个线程的寄存器的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆