Multithreaded ptrace application

I have a debugger application called hyper-ptrace. It launches user_appl3that is multi-threaded with NPTL.

The main hyper-ptrace loop:

wait3(&status, FLAGS, &u);
// find a pid of child, which has a signal
switch (signal = WSTOPSIG(status))
{
  case SIGTRAP:
    do_some_analysis_of_the_child(pid, &status) // up to several ms
    break;
}
ptrace(PTRACE_CONT, pid); // discard signal, user_appl3 doesn't know anything 
                          //about this SIGTRAP

SIGTRAP is generated for user_appl3 using hardware at a certain periodic interval for each thread and delivered to some thread. The interval can be 100..1 ms or even less. This is a kind of clock with an interrupt processor. Each thread runs only on its own processor (attached to affinity).

So there is question1 :

If thread1 receives TRAP and the debugger enters do_some_analysis_of_the_child, (therefore, the debugger does not execute wait3for the second thread), and after a while thread2 also receives TRAP, what will the Linux kernel do?

-: thread1 , , . thread2 (?). thread2 , , TRAP 2, . ?

: question2:

hyper-ptrace, ? , . .

. , .

!

+3
1

, . , ptracing , wait().

- .

, ( ) , , SIGSTOP PID SIGCONT, :

wait3(&status, FLAGS, &u);

if (WIFSTOPPED(status))
    kill(pid, SIGSTOP);  /* Signal entire child process to stop */

switch (signal = WSTOPSIG(status))
{
  case SIGTRAP:
    do_some_analysis_of_the_child(pid, &status) // up to several ms
    break;
}

ptrace(PTRACE_CONT, pid, 0, 0); // discard signal, user_appl3 doesn't know anything about this SIGTRAP
kill(pid, SIGCONT);  /* Signal entire child process to resume */
+5

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


All Articles