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