Date: Sat, 16 Jan 2010 13:02:54 +0200 From: Ali Polatel <alip@exherbo.org> To: freebsd-questions@freebsd.org Subject: A question about ptrace Message-ID: <20100116110254.GA6142@harikalardiyari>
next in thread | raw e-mail | index | archive | help
--17pEHd4RhPHOinZp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable I'm trying to port a program using ptrace from Linux to FreeBSD. For this reason I'm trying to understand how ptrace on FreeBSD works. Below is a sample program I've written which fork()'s and executes "true" after calling PT_TRACE_ME. Having read the manual page of ptrace I assume the printf() in parent should print SIGTRAP but it gives: "Segmentation fault: 11" Can someone help me figure out the problem? TIA. #include <assert.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/ptrace.h> #include <sys/wait.h> #include <unistd.h> int main(void) { int status; pid_t pid; char *const myargv[] =3D { "true", NULL }; pid =3D fork(); if (0 > pid) abort(); else if (!pid) { ptrace(PT_TRACE_ME, 0, 0, 0); execvp(myargv[0], myargv); } else { assert(0 < waitpid(pid, &status, 0)); assert(WIFSTOPPED(status)); assert(0 =3D=3D ptrace(PT_TO_SCE, pid, 0, 0)); assert(0 < waitpid(pid, &status, 0)); assert(WIFSTOPPED(status)); printf("%s\n", strsignal(WSTOPSIG(status))); ptrace(PT_KILL, pid, 0, 0); return 0; } } --=20 Regards, Ali Polatel --17pEHd4RhPHOinZp Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) iEYEABECAAYFAktRnN4ACgkQQU4yORhF8iDB8ACgzjVd/JyWvmT9gHW79NhU9mLW CHQAoKAEmQcbPpXQQAqJQvq6Drse3jPk =I4An -----END PGP SIGNATURE----- --17pEHd4RhPHOinZp--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100116110254.GA6142>