[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20110810173953.GB19981@redhat.com>
Date: Wed, 10 Aug 2011 19:39:53 +0200
From: Oleg Nesterov <oleg@...hat.com>
To: samir baid <samirbaid@...il.com>
Cc: tj@...nel.org, jan.kratochvil@...hat.com, vda.linux@...glemail.com,
linux-kernel@...r.kernel.org
Subject: Re: Question regarding ptrace
I just noticed we discuss this offlist.
We hate the private discussions ;) lets add lkml. Perhaps you
found a kernel bug...
On 08/10, Oleg Nesterov wrote:
>
> On 08/10, samir baid wrote:
> >
> > Here is a
> > brief description of the code -
>
> Oops. it is not that brief ;) I simply do not understand it, may be you
> can show the code... But please try to simplify it as much as possible
> to remove the unnecessary details,
>
> > Running the above programs -
> > 1. Ran Tracee.
> > 2. Ran Tracer with the PID.
> > 3. Ran command - kill -s 30 <tracee pid>
> >
> > My understanding was, after i did step 3 above, tracer should get a signal
> > stop with signal 30. And then i perform a signal injection to tracee. What i
> > wanted to acheive was, once injected the signal to the tracee i wanted to
> > single step it at the instruction level.
>
> This should work, the tracee should enter the handler. For example, see
> the test-case below.
>
> Oleg.
>
> #include <stdio.h>
> #include <unistd.h>
> #include <signal.h>
> #include <sys/ptrace.h>
> #include <sys/wait.h>
> #include <sys/user.h>
> #include <stddef.h>
> #include <assert.h>
>
> void sigh(int sig)
> {
> }
>
> void *getip(int pid)
> {
> return (void*)ptrace(PTRACE_PEEKUSER, pid,
> offsetof(struct user, regs.rip), 0);
> }
>
> int main(void)
> {
> int pid;
>
> signal(30, sigh);
>
> pid = fork();
> if (!pid) {
> assert(ptrace(PTRACE_TRACEME, 0,0,0) == 0);
>
> kill(getpid(), SIGSTOP);
>
> return 0;
> }
>
> assert(wait(NULL) == pid);
>
> assert(ptrace(PTRACE_SINGLESTEP, pid, 0, 30) == 0);
> assert(wait(NULL) == pid);
>
> assert(sigh == getip(pid));
>
> kill(SIGKILL, pid);
> return 0;
> }
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists