* # Re: Just-in-time debugging on Linux
@ 2002-06-09 1:30 Michael Veksler
2002-06-09 1:57 ` Robin Rowe
0 siblings, 1 reply; 5+ messages in thread
From: Michael Veksler @ 2002-06-09 1:30 UTC (permalink / raw)
To: Robin Rowe; +Cc: gdb
/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;
}
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: Just-in-time debugging on Linux
2002-06-09 1:30 # Re: Just-in-time debugging on Linux Michael Veksler
@ 2002-06-09 1:57 ` Robin Rowe
2002-06-09 2:36 ` phi
0 siblings, 1 reply; 5+ messages in thread
From: Robin Rowe @ 2002-06-09 1:57 UTC (permalink / raw)
To: gdb
Michael,
> signal(SIGSEGV, crash_handler); /* This is the most common crash */
This is an interesting approach, but I want to trap unmodified programs.
Thanks,
Robin
---------------------------------------------------------------------------
www.OpenSourceProgrammers.org
www.LinuxMovies.org
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Just-in-time debugging on Linux
2002-06-09 1:57 ` Robin Rowe
@ 2002-06-09 2:36 ` phi
2002-06-10 9:25 ` Tom Tromey
0 siblings, 1 reply; 5+ messages in thread
From: phi @ 2002-06-09 2:36 UTC (permalink / raw)
To: Robin Rowe; +Cc: gdb
Robin Rowe wrote:
>
> Michael,
>
> > signal(SIGSEGV, crash_handler); /* This is the most common crash */
>
> This is an interesting approach, but I want to trap unmodified programs.
>
Then wrap them up in a script
rename prog xyz into xyz.ori this doesn't modify the prog?
then implement the script xyz that does
xyz::
#! your shell
gdb xyz.ori $@
and have you gdbinit (or other ways) to catch the signal you want.
At xyz invocation we start gdb wich start xyz.ori wich will catch the signal
and let you see.
==================
If you really don't want to rename xyz.ori then have the script xyz earlier in
your PATH and make the script invoke the xyz from its original path
Phi
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Just-in-time debugging on Linux
2002-06-09 2:36 ` phi
@ 2002-06-10 9:25 ` Tom Tromey
0 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2002-06-10 9:25 UTC (permalink / raw)
To: phi; +Cc: Robin Rowe, gdb
>>>>> "phi" == phi <phi@hpfrcu81.france.hp.com> writes:
phi> Then wrap them up in a script
phi> rename prog xyz into xyz.ori this doesn't modify the prog?
phi> then implement the script xyz that does
phi> xyz::
phi> #! your shell
phi> gdb xyz.ori $@
This doesn't really work. One problem is that the inferior won't
start running automatically. The other problem is that I/O
redirections get hosed (I think).
I do think this would be a useful feature for gdb. I've wanted it for
a number of years now, but haven't had the time to implement it.
Incidentally your script is missing a `--args'.
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* Just-in-time debugging
@ 2002-06-07 17:24 Robin Rowe
2002-06-08 10:26 ` Christopher Faylor
0 siblings, 1 reply; 5+ messages in thread
From: Robin Rowe @ 2002-06-07 17:24 UTC (permalink / raw)
To: gdb
Hi. Can I configure gdb so that it will launch automatically in response to
a core dump?
Thanks,
Robin
---------------------------------------------------------------------------
www.OpenSourceProgrammers.org
www.LinuxMovies.org
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-06-10 16:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-09 1:30 # Re: Just-in-time debugging on Linux Michael Veksler
2002-06-09 1:57 ` Robin Rowe
2002-06-09 2:36 ` phi
2002-06-10 9:25 ` Tom Tromey
-- strict thread matches above, loose matches on Subject: below --
2002-06-07 17:24 Just-in-time debugging Robin Rowe
2002-06-08 10:26 ` Christopher Faylor
2002-06-08 23:17 ` Just-in-time debugging on Linux Robin Rowe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox