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[] = { "true", NULL };
pid = 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 == 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;
}
}
--
Regards,
Ali Polatel
pgpstnH78DWR1.pgp
Description: PGP signature
