24 #include <NTL/version.h> 25 #include <NTL/tools.h> 35 #if defined(__OPTIMIZE__) && defined(CALL_GDB) 39 #ifdef TIME_WITH_SYS_TIME 41 #ifdef HAVE_SYS_TIME_H 45 #ifdef HAVE_SYS_TIME_H 51 #ifdef HAVE_SYS_TIMES_H 52 #include <sys/times.h> 59 static void debug (
int);
127 if (retval == SIG_ERR)
129 fprintf(stderr,
"Unable to init signal %d ... exiting...\n", sig);
136 struct sigaction new_action,old_action;
137 memset(&new_action, 0,
sizeof(
struct sigaction));
140 new_action.sa_handler = signal_handler;
142 sigemptyset (&new_action.sa_mask);
144 new_action.sa_flags = SA_RESTART;
146 int r=si_sigaction (sig, &new_action, &old_action);
150 fprintf(stderr,
"Unable to init signal %d ... exiting...\n", sig);
159 #if defined(__linux__) && defined(__i386) 160 #if !defined(HAVE_SIGCONTEXT) && !defined(HAVE_ASM_SIGCONTEXT_H) 165 struct sigcontext_struct {
166 unsigned short gs, __gsh;
167 unsigned short fs, __fsh;
168 unsigned short es, __esh;
169 unsigned short ds, __dsh;
178 unsigned long trapno;
181 unsigned short cs, __csh;
182 unsigned long eflags;
183 unsigned long esp_at_signal;
184 unsigned short ss, __ssh;
186 unsigned long oldmask;
190 #define HAVE_SIGSTRUCT 191 typedef struct sigcontext_struct sigcontext;
194 #if defined(__linux__) && defined(__amd64) 195 #define HAVE_SIGSTRUCT 199 #if defined(HAVE_SIGSTRUCT) 214 fprintf(stderr,
"Segment fault/Bus error occurred at %lx because of %lx (r:%d)\n" 215 "please inform the authors\n",
227 fputs(
"trying to restart...\n",stderr);
247 void sigsegv_handler(
int sig,
int code,
struct sigcontext *scp,
char *addr)
249 fprintf(stderr,
"Singular : signal %d, code %d (v: %d):\n",
251 if ((sig!=SIGINT)&&(sig!=SIGABRT))
254 fprintf(stderr,
"Segment fault/Bus error occurred at %x (r:%d)\n" 255 "please inform the authors\n",
262 fputs(
"trying to restart...\n",stderr);
281 fprintf(stderr,
"Singular : signal %d (v: %d):\n",
286 fprintf(stderr,
"Segment fault/Bus error occurred (r:%d)\n" 287 "please inform the authors\n",
294 fputs(
"trying to restart...\n",stderr);
317 char default_opt=
' ';
319 && ((
char*)(
feOptSpec[FE_OPT_CNTRLC].value))[0])
320 { default_opt=((
char*)(
feOptSpec[FE_OPT_CNTRLC].value))[0]; }
330 else if (default_opt!=
' ')
336 fprintf(stderr,
"// ** Interrupt at cmd:`%s` in line:'%s'\n",
340 fputs(
"abort after this command(a), abort immediately(r), print backtrace(b), continue(c) or quit Singular(q) ?",stderr);
341 fflush(stderr);fflush(stdin);
358 fputs(
"** Warning: Singular should be restarted as soon as possible **\n",stderr);
367 fputs(
"** tried too often, try another possibility **\n",stderr);
380 while (c != EOF && c !=
'\n') c = fgetc(stdin);
405 # ifndef __OPTIMIZE__ 417 char * args[4] = { (
char*)
"gdb", (
char*)
"Singular",
NULL,
NULL };
423 sprintf (buf,
"%d", getpid ());
433 fputs (
"\n\nquit with \"p si_stop_stack_trace_x=0\"\n\n\n",stderr);
437 fputs (
"stack_trace\n",stderr);
447 perror (
"could not fork");
457 execvp (args[0], args);
458 perror (
"exec failed");
471 int sel,
index, state;
475 if ((pipe (in_fd) == -1) || (pipe (out_fd) == -1))
477 perror (
"could open pipe");
484 si_close (0); si_dup2 (in_fd[0],0);
485 si_close (1); si_dup2 (out_fd[1],1);
486 si_close (2); si_dup2 (out_fd[1],2);
488 execvp (args[0], args);
489 perror (
"exec failed");
494 perror (
"could not fork");
499 FD_SET (out_fd[0], &fdset);
501 si_write (in_fd[1],
"backtrace\n", 10);
502 si_write (in_fd[1],
"p si_stop_stack_trace_x = 0\n", 28);
503 si_write (in_fd[1],
"quit\n", 5);
514 sel = si_select (FD_SETSIZE, &readset,
NULL,
NULL, &tv);
518 if ((sel > 0) && (FD_ISSET (out_fd[0], &readset)))
520 if (si_read (out_fd[0], &c, 1))
534 if ((c ==
'\n') || (c ==
'\r'))
537 fputs (buffer,stderr);
553 si_close (out_fd[0]);
554 si_close (out_fd[1]);
565 #if (((NTL_MAJOR_VERSION==9)&&(NTL_MINOR_VERSION>=3))||(NTL_MAJOR_VERSION>=10))
const CanonicalForm int s
This file provides miscellaneous functionality.
static void * feOptValue(feOptIndex opt)
void WerrorS(const char *s)
BOOLEAN singular_in_batchmode
volatile int si_stop_stack_trace_x
volatile BOOLEAN do_shutdown
Voice * feInitStdin(Voice *pp)
static void debug_stop(char *const *args)
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)
void init_signals()
init signal handlers and error handling for libraries: NTL, factory
static void stack_trace(char *const *args)
#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
void(* factoryError)(const char *s)