From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3781 invoked by alias); 28 Sep 2003 22:25:12 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 3773 invoked from network); 28 Sep 2003 22:25:12 -0000 Received: from unknown (HELO concert.shout.net) (204.253.184.25) by sources.redhat.com with SMTP; 28 Sep 2003 22:25:12 -0000 Received: from duracef.shout.net (duracef.shout.net [204.253.184.12]) by concert.shout.net (8.12.10/8.12.10) with ESMTP id h8SMP90U025648; Sun, 28 Sep 2003 17:25:09 -0500 Received: from duracef.shout.net (localhost [127.0.0.1]) by duracef.shout.net (8.12.10/8.12.9) with ESMTP id h8SMP9Vd026650; Sun, 28 Sep 2003 17:25:09 -0500 Received: (from mec@localhost) by duracef.shout.net (8.12.10/8.12.9/Submit) id h8SMP9Rf026649; Sun, 28 Sep 2003 18:25:09 -0400 Date: Sun, 28 Sep 2003 22:35:00 -0000 From: Michael Elizabeth Chastain Message-Id: <200309282225.h8SMP9Rf026649@duracef.shout.net> To: aurelien.chanudet@enst.fr, gdb@sources.redhat.com Subject: Re: process attaching gdb to itself X-SW-Source: 2003-09/txt/msg00353.txt.bz2 Hello, char cmd [256]; sprintf (cmd, "gdb attach %d", getpid ()); system (cmd); 'system' waits for the program that it calls to finish. Thus, your program is waiting for gdb to finish before it does anything. Try the appended program which uses raw fork/exec. It works for me on red hat linux 8, native i686-pc-linux-gnu. If you try to do this in production code then you are likely to run into a blizzard of race conditions, error cases, and signal handling problems. If you are doing this as a learning experience, that's great -- read up on 'man fork' and 'man execlp', and check out a book on Linux systems programming. Michael C GDB QA Guy === #include int main () { int pid = fork (); if (pid == -1) { /* error */ fprintf (stderr, "fork error\n"); exit (2); } if (pid != 0) { /* parent process */ char spid [256]; sprintf (spid, "%d", pid); execlp ("gdb", "gdb", "a.out", spid, NULL); /* execlp returns only if error */ fprintf (stderr, "execlp error\n"); _exit (2); } /* child process */ sleep (5); printf ("hello hacker\n"); return 0; }