My Project
dError.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 /***************************************************************
5  * File: dError.cc
6  * Purpose: implementation for debug error handling
7  * Author: obachman (Olaf Bachmann)
8  * Created: 9/00
9  *******************************************************************/
10 #ifndef DERROR_C
11 #define DERROR_C
12 
13 #include "misc/auxiliary.h"
14 #include "misc/distrib.h"
15 
16 #include "reporter/reporter.h"
17 
18 #include <stdarg.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <strings.h>
22 
23 static inline void malloc_free( void * ptr )
24 {
25  free(ptr);
26 }
27 
28 #ifdef HAVE_EXECINFO_H
29 #include <execinfo.h>
30 #endif
31 
32 #ifdef HAVE_UNISTD_H
33 #include <unistd.h>
34 #endif
35 
36 #ifdef HAVE_GCC_ABI_DEMANGLE
37 #include <cxxabi.h>
38 #endif
39 
40 
41 extern "C"
42 {
43 
44 int dReportError(const char* fmt, ...)
45 {
46 #if 0
47 #ifdef HAVE_EXECINFO_H
48 #define SIZE 50
49  void *buffer[SIZE+1]; int ret;
50 #endif
51 #endif
52 
53  va_list ap;
54  va_start(ap, fmt);
55 #ifndef MAKE_DISTRIBUTION
56  fprintf(stderr, "\n// ***dError: ");
57  vfprintf(stderr, fmt, ap);
58 #if !defined(OM_NDEBUG)
59  #ifdef omPrintCurrentBackTraceMax
60  fprintf(stderr, " occurred at: \n");
61  omPrintCurrentBackTraceMax(stderr, 8);
62  #endif
63 #endif
64 
65 #if 0
66 #ifdef HAVE_EXECINFO_H
67  ret = backtrace( buffer, SIZE ); // execinfo.h
68  fprintf(stderr, "\nExecinfo backtrace (with %zd stack frames): \n", ret);
69 
70 #ifndef HAVE_GCC_ABI_DEMANGLE
71  backtrace_symbols_fd(buffer, ret, STDERR_FILENO); // execinfo.h
72 #else
73  char **ptr = backtrace_symbols( buffer, ret ); // execinfo.h
74 
75  int status;
76  char *demangledName;
77  char *s;
78  char *ss;
79  for (int i = 0; i < ret; i++)
80  {
81  status = -1;
82 
83  s = ptr[i];
84 // fprintf (stderr, " #%02d: %s\n", i, s);
85 
86  ss = index(s, '(');
87  ss[0] = 0;
88  fprintf (stderr, " #%02d: '%s': ", i, s);
89  ss[0] = '('; s = ss + 1;
90 
91  ss = index(s, '+');
92 
93  if ( ss != NULL )
94  {
95  ss[0] = 0;
96  demangledName = abi::__cxa_demangle( s, NULL, NULL, &status ); // cxxabi.h!
97  if( status == 0 && demangledName != NULL )
98  fprintf (stderr, " '%s'", (demangledName[0] != 0)? demangledName: s);
99  else
100  fprintf (stderr, " '%s'", s);
101 
102  malloc_free( demangledName );
103  ss[0] = '+';
104  s = ss + 1;
105  }
106 
107  ss = index(s, ')');
108  if( s != ss)
109  {
110  ss[0] = 0;
111  fprintf (stderr, " + %s", s);
112  ss[0] = ')';
113  }
114 
115  fprintf (stderr, " %s\n", ss + 2);
116  }
117  malloc_free (ptr);
118 #endif
119 #endif
120 
121 #undef SIZE
122 #endif
123 
124  dErrorBreak();
125 #else
126  fprintf(stderr, "\n// !!! YOU HAVE FOUND A BUG IN SINGULAR.");
127  fprintf(stderr, "// !!! Please, email the input\n// and the following error message to singular@mathematik.uni-kl.de");
128  vfprintf(stderr, fmt, ap);
129 #endif
130  return 0;
131 }
132 
133 }
134 
135 #endif
136 
137 #ifndef MAKE_DISTRIBUTION
138 // dummy procedure for setting a breakpoint
139 // within the debugger
141 {}
142 #endif
All the auxiliary stuff.
int i
Definition: cfEzgcd.cc:132
static void malloc_free(void *ptr)
Definition: dError.cc:23
void dErrorBreak()
Definition: dError.cc:140
int dReportError(const char *fmt,...)
Definition: dError.cc:44
const CanonicalForm int s
Definition: facAbsFact.cc:51
Definition: ap.h:40
#define free
Definition: omAllocFunc.c:14
#define NULL
Definition: omList.c:12
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:592
int * status
Definition: si_signals.h:51
#define omPrintCurrentBackTraceMax(A, B)
Definition: xalloc.h:265