Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Michael Veksler <veksler@il.ibm.com>
To: Robin Rowe <rower@MovieEditor.com>
Cc: gdb <gdb@sources.redhat.com>
Subject: # Re: Just-in-time debugging on Linux
Date: Sun, 09 Jun 2002 01:30:00 -0000	[thread overview]
Message-ID: <3D0312BB.7080701@il.ibm.com> (raw)

/References/: <007a01c20e82$daf93e20$0301a8c0@rowboat 
<http://sources.redhat.com/ml/gdb/2002-06/msg00063.html>> 
<20020608172614.GA16912@redhat.com 
<http://sources.redhat.com/ml/gdb/2002-06/msg00064.html>>

 > 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 <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <signal.h>
#include <stdio.h>

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;
}



             reply	other threads:[~2002-06-09  8:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-09  1:30 Michael Veksler [this message]
2002-06-09  1:57 ` Robin Rowe
2002-06-09  2:36   ` phi
2002-06-10  9:25     ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3D0312BB.7080701@il.ibm.com \
    --to=veksler@il.ibm.com \
    --cc=gdb@sources.redhat.com \
    --cc=rower@MovieEditor.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox