From 3e15bceda1caf57a898ed98e147a6bc176d8b1fb Mon Sep 17 00:00:00 2001 From: John Darrington Date: Thu, 16 Nov 2006 12:47:22 +0000 Subject: [PATCH] Apply patch #5561. Connect debugger on error. --- src/ui/ChangeLog | 4 +++ src/ui/automake.mk | 2 ++ src/ui/debugger.c | 67 +++++++++++++++++++++++++++++++++++++++ src/ui/debugger.h | 29 +++++++++++++++++ src/ui/terminal/ChangeLog | 4 +++ src/ui/terminal/main.c | 6 +++- 6 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 src/ui/debugger.c create mode 100644 src/ui/debugger.h diff --git a/src/ui/ChangeLog b/src/ui/ChangeLog index f4a37513..2397ee41 100644 --- a/src/ui/ChangeLog +++ b/src/ui/ChangeLog @@ -1,3 +1,7 @@ +Thu Nov 16 20:44:58 WST 2006 John Darrington + + * debugger.c debugger.h New files. + Mon Jul 17 18:22:18 WST 2006 John Darrington * flexifile.c flexifile.h: New files. Implementations of casefiles. diff --git a/src/ui/automake.mk b/src/ui/automake.mk index 5bf78620..f2d56bad 100644 --- a/src/ui/automake.mk +++ b/src/ui/automake.mk @@ -9,5 +9,7 @@ endif noinst_LIBRARIES += src/ui/libuicommon.a src_ui_libuicommon_a_SOURCES = \ + src/ui/debugger.c \ + src/ui/debugger.h \ src/ui/flexifile.c \ src/ui/flexifile.h diff --git a/src/ui/debugger.c b/src/ui/debugger.c new file mode 100644 index 00000000..49f23415 --- /dev/null +++ b/src/ui/debugger.c @@ -0,0 +1,67 @@ +/* PSPP - computes sample statistics. + Copyright (C) 2006 Free Software Foundation, Inc. + Written by John Darrington + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. */ + +#include + +#include +#include +#include +#include +#include +#include + + +#include "debugger.h" + +/* Fork, start gdb and connect to the parent process. + If that happens successfully, then this function does not return, + but exits with EXIT_FAILURE. Otherwise it returns. + */ + +void +connect_debugger (void) +{ + char pidstr[20]; + pid_t pid; + + snprintf (pidstr, 20, "%d", getpid ()); + pid = fork (); + if ( pid == -1 ) + { + perror ("Cannot fork"); + return ; + } + if ( pid == 0 ) + { + /* child */ + execlp ("gdb", "gdb", "-p", pidstr, NULL); + perror ("Cannot exec debugger"); + exit (EXIT_FAILURE); + } + else + { + int status; + wait (&status); + if ( EXIT_SUCCESS != WEXITSTATUS (status) ) + return ; + } + + exit (EXIT_FAILURE); +} + diff --git a/src/ui/debugger.h b/src/ui/debugger.h new file mode 100644 index 00000000..8476ff0c --- /dev/null +++ b/src/ui/debugger.h @@ -0,0 +1,29 @@ +/* PSPP - computes sample statistics. + Copyright (C) 2006 Free Software Foundation, Inc. + Written by John Darrington + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. */ + +#ifndef DEBUGGER_H +#define DEBUGGER_H + + +/* Fork, start gdb and connect to the parent process. + Exit with EXIT_FAILURE. + */ +void connect_debugger (void) ; + +#endif diff --git a/src/ui/terminal/ChangeLog b/src/ui/terminal/ChangeLog index 4bc7b361..98ce96c7 100644 --- a/src/ui/terminal/ChangeLog +++ b/src/ui/terminal/ChangeLog @@ -1,3 +1,7 @@ +Thu Nov 16 20:46:35 WST 2006 John Darrington + + * main.c: Connect debugger on errors. + Tue Nov 7 20:54:32 WST 2006 John Darrington * command-line.c msg-ui.c msg-ui.h main.c: Added an -e diff --git a/src/ui/terminal/main.c b/src/ui/terminal/main.c index a99f580d..5e9a605b 100644 --- a/src/ui/terminal/main.c +++ b/src/ui/terminal/main.c @@ -22,6 +22,7 @@ #include #include +#include #include "command-line.h" #include "msg-ui.h" #include "progname.h" @@ -108,7 +109,7 @@ main (int argc, char **argv) { int result = cmd_parse (the_lexer, the_dataset, proc_has_source (the_dataset) - ? CMD_STATE_DATA : CMD_STATE_INITIAL); + ? CMD_STATE_DATA : CMD_STATE_INITIAL); if (result == CMD_EOF || result == CMD_FINISH) break; if (result == CMD_CASCADING_FAILURE && !getl_is_interactive ()) @@ -153,6 +154,9 @@ fpu_init (void) void bug_handler(int sig) { +#if DEBUGGING + connect_debugger (); +#endif switch (sig) { case SIGABRT: -- 2.30.2