Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a process be stopped via a systemtap probe so gdb can be attached?

We have a multi-process application where debugging a specific child process is proving difficult. Due to messaging timeouts between the processes we don't have time to attach gdb to the target child, so I was wondering if I can stop a process via an systemtap probe?

A simple probe should, I think, be needed, eg.:

probe process("exeName").mark("STOP_HERE")
{
    force_sig(SIGSTOP, current);
}

Unfortunately, the above's not compiling ... any ideas?


I'm not a systemtap expert, so this isn't probably the best solution, but here's my crude solution for anyone interested:

#!/bin/stap -g

global gdbRunning = 0;

probe process(@1).mark(@2)
{
    raise(%{ SIGSTOP %});

    gdbCmd = sprintf("cgdb -- -q -ex 'thread find %d' %s %d", tid(), @1, pid());

    if (gdbRunning == 0)
    {
        gdbRunning = 1;
        printf("STOP PID %d TID %d [%s]\n", pid(), tid(), gdbCmd);
        system(gdbCmd);
    }
    else
    {
        printf("STOP PID %d TID %d\n", pid(), tid());
    }
}
like image 604
mrtimdog Avatar asked Dec 10 '13 10:12

mrtimdog


People also ask

How do I detach a process in GDB?

When you have finished debugging the attached process, you can use the detach command to release it from GDB control. Detaching the process continues its execution. After the detach command, that process and GDB become completely independent once more, and you are ready to attach another process or start one with run .

How do I find GDB?

If you just want to know whether the application is running under GDB for debugging purposes, the simplest solution on Linux is to readlink("/proc/<ppid>/exe") , and search the result for "gdb" .


1 Answers

See man function::raise(3stap), new as of systemtap 2.3 (2013-07-25).

stap -g -e 'probe WHATEVER { raise(%{ SIGSTOP %}) }'

You need guru mode to let your script use this function.

like image 98
fche Avatar answered Sep 28 '22 05:09

fche