11 #define _XOPEN_SOURCE_EXTENDED
33 #include <sys/types.h>
40 #if defined(__OPTIMIZE__) && defined(CALL_GDB)
46 #include <sys/types.h>
48 #ifdef TIME_WITH_SYS_TIME
50 #ifdef HAVE_SYS_TIME_H
54 #ifdef HAVE_SYS_TIME_H
60 #ifdef HAVE_SYS_TIMES_H
61 #include <sys/times.h>
68 static void debug (
int);
69 static void debug_stop (
char *
const*args);
72 static void stack_trace_sigchld (
int);
73 static void stack_trace (
char *
const*args);
139 if (retval == SIG_ERR)
141 fprintf(stderr,
"Unable to init signal %d ... exiting...\n", sig);
148 struct sigaction new_action,old_action;
149 memset(&new_action, 0,
sizeof(
struct sigaction));
152 new_action.sa_handler = signal_handler;
154 sigemptyset (&new_action.sa_mask);
156 new_action.sa_flags = SA_RESTART;
158 int r=si_sigaction (sig, &new_action, &old_action);
162 fprintf(stderr,
"Unable to init signal %d ... exiting...\n", sig);
171 #if defined(__linux__) && defined(__i386)
172 #if !defined(HAVE_SIGCONTEXT) && !defined(HAVE_ASM_SIGCONTEXT_H)
177 struct sigcontext_struct {
178 unsigned short gs, __gsh;
179 unsigned short fs, __fsh;
180 unsigned short es, __esh;
181 unsigned short ds, __dsh;
190 unsigned long trapno;
193 unsigned short cs, __csh;
194 unsigned long eflags;
195 unsigned long esp_at_signal;
196 unsigned short ss, __ssh;
198 unsigned long oldmask;
202 #define HAVE_SIGSTRUCT
203 typedef struct sigcontext_struct sigcontext;
206 #if defined(__linux__) && defined(__amd64)
207 #define HAVE_SIGSTRUCT
211 #if defined(HAVE_SIGSTRUCT)
226 fprintf(stderr,
"Segment fault/Bus error occurred at %lx because of %lx (r:%d)\n"
227 "please inform the authors\n",
239 fprintf(stderr,
"trying to restart...\n");
248 else debug(INTERACTIVE);
259 void sigsegv_handler(
int sig,
int code,
struct sigcontext *scp,
char *addr)
261 fprintf(stderr,
"Singular : signal %d, code %d (v: %d):\n",
263 if ((sig!=SIGINT)&&(sig!=SIGABRT))
266 fprintf(stderr,
"Segment fault/Bus error occurred at %x (r:%d)\n"
267 "please inform the authors\n",
274 fprintf(stderr,
"trying to restart...\n");
280 if (sig!=SIGINT) debug(STACK_TRACE);
293 fprintf(stderr,
"Singular : signal %d (v: %d):\n",
298 fprintf(stderr,
"Segment fault/Bus error occurred (r:%d)\n"
299 "please inform the authors\n",
306 fprintf(stderr,
"trying to restart...\n");
313 if (sig!=SIGINT) debug(STACK_TRACE);
331 char default_opt=
' ';
333 && ((
char*)(
feOptSpec[FE_OPT_CNTRLC].value))[0])
334 { default_opt=((
char*)(
feOptSpec[FE_OPT_CNTRLC].value))[0]; }
344 else if (default_opt!=
' ')
350 fprintf(stderr,
"// ** Interrupt at cmd:`%s` in line:'%s'\n",
354 fputs(
"abort after this command(a), abort immediately(r), print backtrace(b), continue(c) or quit Singular(q) ?",stderr);fflush(stderr);
368 if (sigint_handler_cnt<3)
370 sigint_handler_cnt++;
371 fputs(
"** Warning: Singular should be restarted as soon as possible **\n",stderr);
377 fputs(
"** tried too often, try another possibility **\n",stderr);
390 while (c != EOF && c !=
'\n') c = fgetc(stdin);
416 # ifndef __OPTIMIZE__
417 volatile int si_stop_stack_trace_x;
419 static void debug (
int method)
428 char * args[4] = { (
char*)
"gdb", (
char*)
"Singular",
NULL,
NULL };
434 sprintf (buf,
"%d", getpid ());
444 fprintf (stderr,
"\n\nquit with \"p si_stop_stack_trace_x=0\"\n\n\n");
448 fprintf (stderr,
"stack_trace\n");
458 perror (
"could not fork");
462 si_stop_stack_trace_x = 1;
463 while (si_stop_stack_trace_x) ;
466 static void debug_stop (
char *
const*args)
468 execvp (args[0], args);
469 perror (
"exec failed");
474 static void stack_trace (
char *
const*args)
482 int sel,
index, state;
486 if ((pipe (in_fd) == -1) || (pipe (out_fd) == -1))
488 perror (
"could open pipe");
495 si_close (0); si_dup2 (in_fd[0],0);
496 si_close (1); si_dup2 (out_fd[1],1);
497 si_close (2); si_dup2 (out_fd[1],2);
499 execvp (args[0], args);
500 perror (
"exec failed");
505 perror (
"could not fork");
510 FD_SET (out_fd[0], &fdset);
512 si_write (in_fd[1],
"backtrace\n", 10);
513 si_write (in_fd[1],
"p si_stop_stack_trace_x = 0\n", 28);
514 si_write (in_fd[1],
"quit\n", 5);
525 sel = si_select (FD_SETSIZE, &readset,
NULL,
NULL, &tv);
529 if ((sel > 0) && (FD_ISSET (out_fd[0], &readset)))
531 if (si_read (out_fd[0], &c, 1))
545 if ((c ==
'\n') || (c ==
'\r'))
548 fprintf (stderr,
"%s", buffer);
558 else if (si_stop_stack_trace_x==0)
564 si_close (out_fd[0]);
565 si_close (out_fd[1]);
const const intvec const intvec const ring _currRing const const intvec const intvec const ring _currRing int
const CanonicalForm int s
This file provides miscellaneous functionality.
static void * feOptValue(feOptIndex opt)
void sig_chld_hdl(int sig)
additional default signal handler
void WerrorS(const char *s)
int int kStrategy strat if(h==NULL) return NULL
BOOLEAN singular_in_batchmode
volatile BOOLEAN do_shutdown
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)