Is there a way to view the contents of the register of one thread from another thread within the same process?

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

I want to use stream A to pause stream B, check the values ​​of register B / the contents of the stack, and then transfer some of this information from stream B to stream C (via stream A).

According to this from Linus Torvalds, syscall ptracewill not work here because the threads are in the same process.

Is there any other way to do this?

Update: this one is discussed why it does not work; I would like to know if there is a workaround that is not related to creating a child process.

+4
source share
1 answer

Perhaps you can get around this using a signal. Select another unused signal, for example SIGUSR1, and set a signal handler for it using a member sa_sigaction struct sigactionand specifying a flag SA_SIGINFO. Block the signal in each stream, except for the stream of interest (stream B).

If you want to study stream B, send it a stream-directed signal with pthread_kill(). Then the signal handler lights up, and its third argument will be a pointer to the structure ucontext_t. An element of uc_mcontextthis structure is a machine-dependent structure mcontext_tthat will contain register values ​​at the point at which the stream was interrupted.

Then you just need to create a safe way to pass these values ​​to stream A.

+2

Source: https://habr.com/ru/post/1615820/


All Articles