27 #include <NTL/version.h>
28 #include <NTL/tools.h>
38 #if defined(__OPTIMIZE__) && defined(CALL_GDB)
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);
130 if (retval == SIG_ERR)
132 fprintf(stderr,
"Unable to init signal %d ... exiting...\n", sig);
139 struct sigaction new_action,old_action;
140 memset(&new_action, 0,
sizeof(
struct sigaction));
143 new_action.sa_handler = signal_handler;
145 sigemptyset (&new_action.sa_mask);
147 new_action.sa_flags = SA_RESTART;
149 int r=si_sigaction (sig, &new_action, &old_action);
153 fprintf(stderr,
"Unable to init signal %d ... exiting...\n", sig);
162 #if defined(__linux__) && (defined(__i386) || defined(__amd64))
177 fprintf(stderr,
"Segment fault/Bus error occurred at %lx because of %lx (r:%d)\n"
178 "please inform the authors\n",
190 fputs(
"trying to restart...\n",stderr);
210 void sigsegv_handler(
int sig,
int code,
struct sigcontext *scp,
char *addr)
212 fprintf(stderr,
"Singular : signal %d, code %d (v: %d):\n",
214 if ((sig!=SIGINT)&&(sig!=SIGABRT))
217 fprintf(stderr,
"Segment fault/Bus error occurred at %x (r:%d)\n"
218 "please inform the authors\n",
225 fputs(
"trying to restart...\n",stderr);
244 fprintf(stderr,
"Singular : signal %d (v: %d):\n",
249 fprintf(stderr,
"Segment fault/Bus error occurred (r:%d)\n"
250 "please inform the authors\n",
257 fputs(
"trying to restart...\n",stderr);
280 char default_opt=
' ';
282 && ((
char*)(
feOptSpec[FE_OPT_CNTRLC].value))[0])
283 { default_opt=((
char*)(
feOptSpec[FE_OPT_CNTRLC].value))[0]; }
293 else if (default_opt!=
' ')
299 fprintf(stderr,
"// ** Interrupt at cmd:`%s` in line:'%s'\n",
303 fputs(
"abort after this command(a), abort immediately(r), print backtrace(b), continue(c) or quit Singular(q) ?",stderr);
304 fflush(stderr);fflush(stdin);
321 fputs(
"** Warning: Singular should be restarted as soon as possible **\n",stderr);
330 fputs(
"** tried too often, try another possibility **\n",stderr);
343 while (c != EOF && c !=
'\n') c = fgetc(stdin);
368 # ifndef __OPTIMIZE__
391 char * args[4] = { (
char*)
"gdb", (
char*)
"Singular",
NULL,
NULL };
397 sprintf (
buf,
"%d", getpid ());
407 fputs (
"\n\nquit with \"p si_stop_stack_trace_x=0\"\n\n\n",stderr);
411 fputs (
"stack_trace\n",stderr);
421 perror (
"could not fork");
431 execvp (args[0], args);
432 perror (
"exec failed");
445 int sel,
index, state;
449 if ((pipe (in_fd) == -1) || (pipe (out_fd) == -1))
451 perror (
"could open pipe");
458 si_close (0); si_dup2 (in_fd[0],0);
459 si_close (1); si_dup2 (out_fd[1],1);
460 si_close (2); si_dup2 (out_fd[1],2);
462 execvp (args[0], args);
463 perror (
"exec failed");
468 perror (
"could not fork");
473 FD_SET (out_fd[0], &fdset);
475 si_write (in_fd[1],
"backtrace\n", 10);
476 si_write (in_fd[1],
"p si_stop_stack_trace_x = 0\n", 28);
477 si_write (in_fd[1],
"quit\n", 5);
488 sel = si_select (FD_SETSIZE, &readset,
NULL,
NULL, &tv);
492 if ((sel > 0) && (FD_ISSET (out_fd[0], &readset)))
494 if (si_read (out_fd[0], &c, 1))
508 if ((c ==
'\n') || (c ==
'\r'))
511 fputs (buffer,stderr);
527 si_close (out_fd[0]);
528 si_close (out_fd[1]);
539 #if (((NTL_MAJOR_VERSION==9)&&(NTL_MINOR_VERSION>=3))||(NTL_MAJOR_VERSION>=10))
VAR jmp_buf si_start_jmpbuf
static void stack_trace(char *const *args)
VAR BOOLEAN singular_in_batchmode
si_hdl_typ si_set_signal(int sig, si_hdl_typ signal_handler)
meta function for binding a signal to an handler
VAR volatile int si_stop_stack_trace_x
VAR volatile BOOLEAN do_shutdown
VAR volatile int defer_shutdown
VAR int sigint_handler_cnt
void sigsegv_handler(int sig)
static void debug_stop(char *const *args)
void init_signals()
init signal handlers and error handling for libraries: NTL, factory
const CanonicalForm int s
void WerrorS(const char *s)
static void * feOptValue(feOptIndex opt)
EXTERN_VAR struct fe_option feOptSpec[]
VAR char my_yylinebuf[80]
VAR BOOLEAN fe_is_raw_tty
Voice * feInitStdin(Voice *pp)
const char * Tok2Cmdname(int tok)
This file provides miscellaneous functionality.
int dReportError(const char *fmt,...)
static int index(p_Length length, p_Ord ord)
int status int void * buf
#define si_siginterrupt(arg1, arg2)
BOOLEAN slClose(si_link l)
void sig_chld_hdl(int)
additional default signal handler