From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32165 invoked by alias); 9 Jun 2002 08:30:31 -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 32158 invoked from network); 9 Jun 2002 08:30:27 -0000 Received: from unknown (HELO d12lmsgate.de.ibm.com) (195.212.91.199) by sources.redhat.com with SMTP; 9 Jun 2002 08:30:27 -0000 Received: from d12relay01.de.ibm.com (d12relay01.de.ibm.com [9.165.215.22]) by d12lmsgate.de.ibm.com (8.12.3/8.12.3) with ESMTP id g598UIeE041364; Sun, 9 Jun 2002 10:30:18 +0200 Received: from il.ibm.com (ps73-34.haifa.ibm.com [9.148.12.51]) by d12relay01.de.ibm.com (8.11.1m3/NCO/VER6.1) with ESMTP id g598UEq101544; Sun, 9 Jun 2002 10:30:18 +0200 Message-ID: <3D0312BB.7080701@il.ibm.com> Date: Sun, 09 Jun 2002 01:30:00 -0000 From: Michael Veksler Reply-To: veksler@il.ibm.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0rc3) Gecko/20020523 X-Accept-Language: en, pdf, he MIME-Version: 1.0 To: Robin Rowe CC: gdb Subject: # Re: Just-in-time debugging on Linux Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2002-06/txt/msg00069.txt.bz2 /References/: <007a01c20e82$daf93e20$0301a8c0@rowboat > <20020608172614.GA16912@redhat.com > > Christopher, > > > On windows you'd do: > > > > set cygwin=error_start=x:/path/to/gdb.exe > > Thanks lots, but I meant Linux. Does anyone know the trick to launch gdb > automatically there? > > Robin Try the following code: #include #include #include #include #include static char* exec_name=""; static void crash_handler(int sig) { int status=0; int pid; char * gdb_array[]={"gdb", exec_name, "PID", NULL}; char pid_str[40]; sprintf(pid_str, "%d%c", getpid(), '\0'); gdb_array[2]= pid_str; pid= fork(); if (pid < 0) /* error */ abort(); else if (pid) /* parent */ { sleep(60); /* Give GDB time to attach */ _exit(1); /* you can skip this line by telling gdb to "return" */ } else /* child */ execvp("gdb", gdb_array); } void register_gdb() { signal(SIGQUIT, crash_handler); /* Normally got from Ctrl-\ */ signal(SIGILL, crash_handler); signal(SIGTRAP, crash_handler); signal(SIGABRT, crash_handler); signal(SIGFPE, crash_handler); signal(SIGBUS, crash_handler); signal(SIGSEGV, crash_handler); /* This is the most common crash */ signal(SIGSYS, crash_handler); } void crash_segv() { int *p=0; *p=1; } int main(int argc, char *argv[]) { exec_name=argv[0]; register_gdb(); crash_segv(); return 0; }