From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6043 invoked by alias); 28 Sep 2003 22:35:35 -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 6036 invoked from network); 28 Sep 2003 22:35:34 -0000 Received: from unknown (HELO localhost.redhat.com) (65.49.0.121) by sources.redhat.com with SMTP; 28 Sep 2003 22:35:34 -0000 Received: from redhat.com (localhost [127.0.0.1]) by localhost.redhat.com (Postfix) with ESMTP id 036DB2B89; Sun, 28 Sep 2003 18:35:24 -0400 (EDT) Message-ID: <3F77622C.8090403@redhat.com> Date: Sun, 28 Sep 2003 22:45:00 -0000 From: Andrew Cagney User-Agent: Mozilla/5.0 (X11; U; NetBSD macppc; en-US; rv:1.0.2) Gecko/20030820 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Michael Elizabeth Chastain , aurelien.chanudet@enst.fr Cc: gdb@sources.redhat.com Subject: Re: process attaching gdb to itself References: <200309282225.h8SMP9Rf026649@duracef.shout.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2003-09/txt/msg00354.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. Is the kernel Linux? JeffJ and I just discovered that: $ sleep 1000 ^Z PID 1234 suspended $ gdb sleep 1234 ... (gdb) works on BSD but fails on GNU/Linux. When doing an attach, BSD always generates something for wait4 to consume. GNU/Linux does not, leaving GDB stuck in wait4 :-( Andrew