public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: samir baid <samirbaid@gmail.com>
Cc: tj@kernel.org, jan.kratochvil@redhat.com,
	vda.linux@googlemail.com, linux-kernel@vger.kernel.org
Subject: Re: Question regarding ptrace
Date: Wed, 10 Aug 2011 19:39:53 +0200	[thread overview]
Message-ID: <20110810173953.GB19981@redhat.com> (raw)
In-Reply-To: <20110810173851.GA19981@redhat.com>

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;
> }


           reply	other threads:[~2011-08-10 17:42 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <20110810173851.GA19981@redhat.com>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110810173953.GB19981@redhat.com \
    --to=oleg@redhat.com \
    --cc=jan.kratochvil@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=samirbaid@gmail.com \
    --cc=tj@kernel.org \
    --cc=vda.linux@googlemail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox