bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

PTRACE & -O2


From: Frank Cornelis
Subject: PTRACE & -O2
Date: Sat, 19 Oct 2002 13:48:38 +0200 (MEST)

Hi,

When I compile the following program using
        gcc -o test test.c
and I run it everything is OK, but when I
compile using -O2, it __sometimes__ hangs.
        GCC version: 2.96
        GLIBC: libc-2.2.5.so
        OS: Linux RedHat 7.3 i386
Anyone a clue on this?
I really need this to work correctly.

Can be reached at address@hidden

Thanks in advance,
Frank.

--------------------- test.c ----------------------------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ptrace.h>
#include <asm/user.h>
#include <sys/wait.h>
#include <sched.h>

#define STACK_SIZE (1024*64)

static int child_func(void *param);
static int go = 0;

int main()
{
        int status, pid;
        char *stack;
        stack = malloc(STACK_SIZE);
        pid = clone(child_func, stack + STACK_SIZE, SIGCHLD | CLONE_VM,
                        NULL);
        ptrace(PTRACE_ATTACH, pid, NULL, NULL);
        waitpid(pid, &status, 0);
        go = 1;
        while (1) {
                ptrace(PTRACE_SYSCALL, pid, NULL, NULL);
                waitpid(pid, &status, 0);
                if (WIFEXITED(status))
                        exit(0);
                if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP)
                        printf("syscall: %d (EAX: %d)\n",
                                        (int)ptrace(PTRACE_PEEKUSER, pid,
                                        ORIG_EAX * 4, NULL),
                                        (int)ptrace(PTRACE_PEEKUSER, pid,
                                        EAX * 4, NULL));
        }
}

static int child_func(void *param)
{
        while (!go) ;
        getpid();
        getppid();
        return 0;
}






reply via email to

[Prev in Thread] Current Thread [Next in Thread]