22 #include <NTL/version.h> 23 #include <NTL/tools.h> 33 #if defined(__OPTIMIZE__) && defined(CALL_GDB) 37 #ifdef TIME_WITH_SYS_TIME 39 #ifdef HAVE_SYS_TIME_H 43 #ifdef HAVE_SYS_TIME_H 49 #ifdef HAVE_SYS_TIMES_H 50 #include <sys/times.h> 57 static void debug (
int);
125 if (retval == SIG_ERR)
127 fprintf(stderr,
"Unable to init signal %d ... exiting...\n", sig);
134 struct sigaction new_action,old_action;
135 memset(&new_action, 0,
sizeof(
struct sigaction));
138 new_action.sa_handler = signal_handler;
140 sigemptyset (&new_action.sa_mask);
142 new_action.sa_flags = SA_RESTART;
144 int r=si_sigaction (sig, &new_action, &old_action);
148 fprintf(stderr,
"Unable to init signal %d ... exiting...\n", sig);
157 #if defined(__linux__) && defined(__i386) 158 #if !defined(HAVE_SIGCONTEXT) && !defined(HAVE_ASM_SIGCONTEXT_H) 163 struct sigcontext_struct {
164 unsigned short gs, __gsh;
165 unsigned short fs, __fsh;
166 unsigned short es, __esh;
167 unsigned short ds, __dsh;
176 unsigned long trapno;
179 unsigned short cs, __csh;
180 unsigned long eflags;
181 unsigned long esp_at_signal;
182 unsigned short ss, __ssh;
184 unsigned long oldmask;
188 #define HAVE_SIGSTRUCT 189 typedef struct sigcontext_struct sigcontext;
192 #if defined(__linux__) && defined(__amd64) 193 #define HAVE_SIGSTRUCT 197 #if defined(HAVE_SIGSTRUCT) 212 fprintf(stderr,
"Segment fault/Bus error occurred at %lx because of %lx (r:%d)\n" 213 "please inform the authors\n",
225 fputs(
"trying to restart...\n",stderr);
245 void sigsegv_handler(
int sig,
int code,
struct sigcontext *scp,
char *addr)
247 fprintf(stderr,
"Singular : signal %d, code %d (v: %d):\n",
249 if ((sig!=SIGINT)&&(sig!=SIGABRT))
252 fprintf(stderr,
"Segment fault/Bus error occurred at %x (r:%d)\n" 253 "please inform the authors\n",
260 fputs(
"trying to restart...\n",stderr);
279 fprintf(stderr,
"Singular : signal %d (v: %d):\n",
284 fprintf(stderr,
"Segment fault/Bus error occurred (r:%d)\n" 285 "please inform the authors\n",
292 fputs(
"trying to restart...\n",stderr);
315 char default_opt=
' ';
317 && ((
char*)(
feOptSpec[FE_OPT_CNTRLC].value))[0])
318 { default_opt=((
char*)(
feOptSpec[FE_OPT_CNTRLC].value))[0]; }
328 else if (default_opt!=
' ')
334 fprintf(stderr,
"// ** Interrupt at cmd:`%s` in line:'%s'\n",
338 fputs(
"abort after this command(a), abort immediately(r), print backtrace(b), continue(c) or quit Singular(q) ?",stderr);
339 fflush(stderr);fflush(stdin);
356 fputs(
"** Warning: Singular should be restarted as soon as possible **\n",stderr);
365 fputs(
"** tried too often, try another possibility **\n",stderr);
378 while (c != EOF && c !=
'\n') c = fgetc(stdin);
403 # ifndef __OPTIMIZE__ 415 char * args[4] = { (
char*)
"gdb", (
char*)
"Singular",
NULL,
NULL };
421 sprintf (buf,
"%d", getpid ());
431 fputs (
"\n\nquit with \"p si_stop_stack_trace_x=0\"\n\n\n",stderr);
435 fputs (
"stack_trace\n",stderr);
445 perror (
"could not fork");
455 execvp (args[0], args);
456 perror (
"exec failed");
469 int sel,
index, state;
473 if ((pipe (in_fd) == -1) || (pipe (out_fd) == -1))
475 perror (
"could open pipe");
482 si_close (0); si_dup2 (in_fd[0],0);
483 si_close (1); si_dup2 (out_fd[1],1);
484 si_close (2); si_dup2 (out_fd[1],2);
486 execvp (args[0], args);
487 perror (
"exec failed");
492 perror (
"could not fork");
497 FD_SET (out_fd[0], &fdset);
499 si_write (in_fd[1],
"backtrace\n", 10);
500 si_write (in_fd[1],
"p si_stop_stack_trace_x = 0\n", 28);
501 si_write (in_fd[1],
"quit\n", 5);
512 sel = si_select (FD_SETSIZE, &readset,
NULL,
NULL, &tv);
516 if ((sel > 0) && (FD_ISSET (out_fd[0], &readset)))
518 if (si_read (out_fd[0], &c, 1))
532 if ((c ==
'\n') || (c ==
'\r'))
535 fputs (buffer,stderr);
551 si_close (out_fd[0]);
552 si_close (out_fd[1]);
563 #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)