public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
From: Stephane Eranian <eranian@hpl.hp.com>
To: linux-ia64@vger.kernel.org
Subject: ptrace problem in 2.6.9
Date: Fri, 22 Oct 2004 17:05:57 +0000	[thread overview]
Message-ID: <20041022170557.GW19372@frankl.hpl.hp.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 501 bytes --]

Hi Roland,

I have some problems with the recent modifications to the
Ptrace infrastructure in 2.6.9 release. Basically I have
the smiple test program attached to this E-mail and it
hangs in 2.6.9 but not in 2.6.9-rc4. Somehow the first
waitpid() does not return. It is not clear to me why.
Is there something Ineed to change in the call itself?
I am running all of this on a 2-way IA-64 machine with
2.6.9. I have not tried on x86. 

I would appreciate your thoughts on this.

Thanks.

-- 
-Stephane

[-- Attachment #2: test_ptrace.c --]
[-- Type: text/plain, Size: 1693 bytes --]

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <sys/wait.h>
#include <sys/ptrace.h>

static int p[2];

int
child(void)
{
	int ret;
	char c;

	printf("child %d started\n", getpid());
	ret = read(p[0], &c, 1);
	if (ret != 1) {
		perror("read");
		return -1;
	}
	return 0;
}

int
do_test(int argc, char **argv)
{
	int ret, status;
	pid_t pid;
	char c;

	ret = pipe(p);
	if (ret) {
		perror("pipe");
		return -1;
	}

	pid = fork();
	switch(pid) {
		case 0: close(p[1]); exit(child());

		case -1: perror("fork"); return -1;

		default: close(p[0]);
			 sleep(5);
			 /*
			  * stop child
			  */
			 ret = ptrace(PTRACE_ATTACH, pid, NULL, NULL);
			 if (ret) {
				 perror("ptrace_attach");
				 goto abort;
			 }
			 printf("issued ptrace attach ret=%d\n", ret);

			 /*
			  * wait for child stop
			  */
			 ret = waitpid(pid, &status, WUNTRACED);
			 if (ret != pid) {
				 perror("waitpid");
				 goto abort;
			 }
			 printf("got process stopped\n");

			 if (WIFEXITED(status)) {
				printf("child has exited\n");
				goto abort;
			 }

			 /*
			  * detach and resume execution
			  */
			 ptrace(PTRACE_DETACH, pid, NULL, NULL);

			 /*
			  * signal child can proceed
			  */
			 ret = write(p[1], &c, 1);
			 if (ret != 1) {
				 perror("write");
				 kill(pid, SIGKILL);
				 return -1;
			 }

			/* wait for child exit */
			 ret = waitpid(pid, &status, 0);
			 if (ret == -1) {
				perror("final waitpid");
			 }
	}
	return ret == -1 || WEXITSTATUS(status) != 0? -1: 0;
abort:
	 kill(pid, SIGKILL);
	 return -1;
}

int
main(int argc, char **argv)
{
	return do_test(argc, argv);
}

             reply	other threads:[~2004-10-22 17:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-22 17:05 Stephane Eranian [this message]
2004-10-23  4:53 ` ptrace problem in 2.6.9 Roland McGrath
2004-10-23  8:25 ` David Mosberger
2004-10-25  7:51 ` David Mosberger
2004-10-25  8:04 ` Stephane Eranian

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=20041022170557.GW19372@frankl.hpl.hp.com \
    --to=eranian@hpl.hp.com \
    --cc=linux-ia64@vger.kernel.org \
    /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