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 (
char *
const*args);
132 if (retval == SIG_ERR)
134 fprintf(stderr,
"Unable to init signal %d ... exiting...\n", sig);
141 struct sigaction new_action,old_action;
142 memset(&new_action, 0,
sizeof(
struct sigaction));
145 new_action.sa_handler = signal_handler;
147 sigemptyset (&new_action.sa_mask);
149 new_action.sa_flags = SA_RESTART;
151 int r=si_sigaction (sig, &new_action, &old_action);
155 fprintf(stderr,
"Unable to init signal %d ... exiting...\n", sig);
164 #if defined(__linux__) && defined(__i386) 165 #if !defined(HAVE_SIGCONTEXT) && !defined(HAVE_ASM_SIGCONTEXT_H) 170 struct sigcontext_struct {
171 unsigned short gs, __gsh;
172 unsigned short fs, __fsh;
173 unsigned short es, __esh;
174 unsigned short ds, __dsh;
183 unsigned long trapno;
186 unsigned short cs, __csh;
187 unsigned long eflags;
188 unsigned long esp_at_signal;
189 unsigned short ss, __ssh;
191 unsigned long oldmask;
195 #define HAVE_SIGSTRUCT 196 typedef struct sigcontext_struct sigcontext;
199 #if defined(__linux__) && defined(__amd64) 200 #define HAVE_SIGSTRUCT 204 #if defined(HAVE_SIGSTRUCT) 219 fprintf(stderr,
"Segment fault/Bus error occurred at %lx because of %lx (r:%d)\n" 220 "please inform the authors\n",
232 fputs(
"trying to restart...\n",stderr);
241 else debug(INTERACTIVE);
252 void sigsegv_handler(
int sig,
int code,
struct sigcontext *scp,
char *addr)
254 fprintf(stderr,
"Singular : signal %d, code %d (v: %d):\n",
256 if ((sig!=SIGINT)&&(sig!=SIGABRT))
259 fprintf(stderr,
"Segment fault/Bus error occurred at %x (r:%d)\n" 260 "please inform the authors\n",
267 fputs(
"trying to restart...\n",stderr);
273 if (sig!=SIGINT) debug(STACK_TRACE);
286 fprintf(stderr,
"Singular : signal %d (v: %d):\n",
291 fprintf(stderr,
"Segment fault/Bus error occurred (r:%d)\n" 292 "please inform the authors\n",
299 fputs(
"trying to restart...\n",stderr);
306 if (sig!=SIGINT) debug(STACK_TRACE);
324 char default_opt=
' ';
326 && ((
char*)(
feOptSpec[FE_OPT_CNTRLC].value))[0])
327 { default_opt=((
char*)(
feOptSpec[FE_OPT_CNTRLC].value))[0]; }
337 else if (default_opt!=
' ')
343 fprintf(stderr,
"// ** Interrupt at cmd:`%s` in line:'%s'\n",
347 fputs(
"abort after this command(a), abort immediately(r), print backtrace(b), continue(c) or quit Singular(q) ?",stderr);
348 fflush(stderr);fflush(stdin);
365 fputs(
"** Warning: Singular should be restarted as soon as possible **\n",stderr);
374 fputs(
"** tried too often, try another possibility **\n",stderr);
387 while (c != EOF && c !=
'\n') c = fgetc(stdin);
413 # ifndef __OPTIMIZE__ 414 volatile int si_stop_stack_trace_x;
416 static void debug (
int method)
425 char * args[4] = { (
char*)
"gdb", (
char*)
"Singular",
NULL,
NULL };
431 sprintf (
buf,
"%d", getpid ());
441 fputs (
"\n\nquit with \"p si_stop_stack_trace_x=0\"\n\n\n",stderr);
445 fputs (
"stack_trace\n",stderr);
455 perror (
"could not fork");
459 si_stop_stack_trace_x = 1;
460 while (si_stop_stack_trace_x) ;
463 static void debug_stop (
char *
const*args)
465 execvp (args[0], args);
466 perror (
"exec failed");
471 static void stack_trace (
char *
const*args)
479 int sel,
index, state;
483 if ((pipe (in_fd) == -1) || (pipe (out_fd) == -1))
485 perror (
"could open pipe");
492 si_close (0); si_dup2 (in_fd[0],0);
493 si_close (1); si_dup2 (out_fd[1],1);
494 si_close (2); si_dup2 (out_fd[1],2);
496 execvp (args[0], args);
497 perror (
"exec failed");
502 perror (
"could not fork");
507 FD_SET (out_fd[0], &fdset);
509 si_write (in_fd[1],
"backtrace\n", 10);
510 si_write (in_fd[1],
"p si_stop_stack_trace_x = 0\n", 28);
511 si_write (in_fd[1],
"quit\n", 5);
522 sel = si_select (FD_SETSIZE, &readset,
NULL,
NULL, &tv);
526 if ((sel > 0) && (FD_ISSET (out_fd[0], &readset)))
528 if (si_read (out_fd[0], &c, 1))
542 if ((c ==
'\n') || (c ==
'\r'))
545 fputs (buffer,stderr);
555 else if (si_stop_stack_trace_x==0)
561 si_close (out_fd[0]);
562 si_close (out_fd[1]);
const CanonicalForm int s
This file provides miscellaneous functionality.
static void * feOptValue(feOptIndex opt)
void WerrorS(const char *s)
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