12 #include <sys/types.h>
34 #if defined(__OPTIMIZE__) && defined(CALL_GDB)
40 #include <sys/types.h>
42 #ifdef TIME_WITH_SYS_TIME
44 #ifdef HAVE_SYS_TIME_H
48 #ifdef HAVE_SYS_TIME_H
54 #ifdef HAVE_SYS_TIMES_H
55 #include <sys/times.h>
62 static void debug (
int);
63 static void debug_stop (
char *
const*args);
66 static void stack_trace_sigchld (
int);
67 static void stack_trace (
char *
const*args);
133 if (retval == SIG_ERR)
135 fprintf(stderr,
"Unable to init signal %d ... exiting...\n", sig);
142 struct sigaction new_action,old_action;
143 memset(&new_action, 0,
sizeof(
struct sigaction));
146 new_action.sa_handler = signal_handler;
148 sigemptyset (&new_action.sa_mask);
150 new_action.sa_flags = SA_RESTART;
152 int r=si_sigaction (sig, &new_action, &old_action);
156 fprintf(stderr,
"Unable to init signal %d ... exiting...\n", sig);
165 #if defined(__linux__) && defined(__i386)
166 #if !defined(HAVE_SIGCONTEXT) && !defined(HAVE_ASM_SIGCONTEXT_H)
171 struct sigcontext_struct {
172 unsigned short gs, __gsh;
173 unsigned short fs, __fsh;
174 unsigned short es, __esh;
175 unsigned short ds, __dsh;
184 unsigned long trapno;
187 unsigned short cs, __csh;
188 unsigned long eflags;
189 unsigned long esp_at_signal;
190 unsigned short ss, __ssh;
192 unsigned long oldmask;
196 #define HAVE_SIGSTRUCT
197 typedef struct sigcontext_struct sigcontext;
200 #if defined(__linux__) && defined(__amd64)
201 #define HAVE_SIGSTRUCT
205 #if defined(HAVE_SIGSTRUCT)
220 fprintf(stderr,
"Segment fault/Bus error occurred at %lx because of %lx (r:%d)\n"
221 "please inform the authors\n",
233 fprintf(stderr,
"trying to restart...\n");
242 else debug(INTERACTIVE);
253 void sigsegv_handler(
int sig,
int code,
struct sigcontext *scp,
char *addr)
255 fprintf(stderr,
"Singular : signal %d, code %d (v: %d):\n",
257 if ((sig!=SIGINT)&&(sig!=SIGABRT))
260 fprintf(stderr,
"Segment fault/Bus error occurred at %x (r:%d)\n"
261 "please inform the authors\n",
268 fprintf(stderr,
"trying to restart...\n");
274 if (sig!=SIGINT) debug(STACK_TRACE);
287 fprintf(stderr,
"Singular : signal %d (v: %d):\n",
292 fprintf(stderr,
"Segment fault/Bus error occurred (r:%d)\n"
293 "please inform the authors\n",
300 fprintf(stderr,
"trying to restart...\n");
307 if (sig!=SIGINT) debug(STACK_TRACE);
325 char default_opt=
' ';
327 && ((
char*)(
feOptSpec[FE_OPT_CNTRLC].value))[0])
328 { default_opt=((
char*)(
feOptSpec[FE_OPT_CNTRLC].value))[0]; }
338 else if (default_opt!=
' ')
344 fprintf(stderr,
"// ** Interrupt at cmd:`%s` in line:'%s'\n",
348 fputs(
"abort after this command(a), abort immediately(r), print backtrace(b), continue(c) or quit Singular(q) ?",stderr);
349 fflush(stderr);fflush(stdin);
363 if (sigint_handler_cnt<3)
365 sigint_handler_cnt++;
366 fputs(
"** Warning: Singular should be restarted as soon as possible **\n",stderr);
375 fputs(
"** tried too often, try another possibility **\n",stderr);
388 while (c != EOF && c !=
'\n') c = fgetc(stdin);
414 # ifndef __OPTIMIZE__
415 volatile int si_stop_stack_trace_x;
417 static void debug (
int method)
426 char * args[4] = { (
char*)
"gdb", (
char*)
"Singular",
NULL,
NULL };
432 sprintf (buf,
"%d", getpid ());
442 fprintf (stderr,
"\n\nquit with \"p si_stop_stack_trace_x=0\"\n\n\n");
446 fprintf (stderr,
"stack_trace\n");
456 perror (
"could not fork");
460 si_stop_stack_trace_x = 1;
461 while (si_stop_stack_trace_x) ;
464 static void debug_stop (
char *
const*args)
466 execvp (args[0], args);
467 perror (
"exec failed");
472 static void stack_trace (
char *
const*args)
480 int sel,
index, state;
484 if ((pipe (in_fd) == -1) || (pipe (out_fd) == -1))
486 perror (
"could open pipe");
493 si_close (0); si_dup2 (in_fd[0],0);
494 si_close (1); si_dup2 (out_fd[1],1);
495 si_close (2); si_dup2 (out_fd[1],2);
497 execvp (args[0], args);
498 perror (
"exec failed");
503 perror (
"could not fork");
508 FD_SET (out_fd[0], &fdset);
510 si_write (in_fd[1],
"backtrace\n", 10);
511 si_write (in_fd[1],
"p si_stop_stack_trace_x = 0\n", 28);
512 si_write (in_fd[1],
"quit\n", 5);
523 sel = si_select (FD_SETSIZE, &readset,
NULL,
NULL, &tv);
527 if ((sel > 0) && (FD_ISSET (out_fd[0], &readset)))
529 if (si_read (out_fd[0], &c, 1))
543 if ((c ==
'\n') || (c ==
'\r'))
546 fprintf (stderr,
"%s", buffer);
556 else if (si_stop_stack_trace_x==0)
562 si_close (out_fd[0]);
563 si_close (out_fd[1]);
const CanonicalForm int s
This file provides miscellaneous functionality.
static void * feOptValue(feOptIndex opt)
void WerrorS(const char *s)
int int kStrategy strat if(h==NULL) return NULL
BOOLEAN singular_in_batchmode
volatile BOOLEAN do_shutdown
Voice * feInitStdin(Voice *pp)
int status int void * buf
void sigsegv_handler(int sig)
si_hdl_typ si_set_signal(int sig, si_hdl_typ signal_handler)
meta function for binding a signal to an handler
struct fe_option feOptSpec[]
static int index(p_Length length, p_Ord ord)
const char * Tok2Cmdname(int tok)
#define si_siginterrupt(arg1, arg2)
volatile int defer_shutdown
int dReportError(const char *fmt,...)
BOOLEAN slClose(si_link l)
void sig_chld_hdl(int)
additional default signal handler