source: git/libpolys/reporter/dError.cc @ 0acf3e

spielwiese
Last change on this file since 0acf3e was fbdfd4, checked in by Hans Schoenemann <hannes@…>, 11 years ago
fix: enforce integer coeffs in rational functions
  • Property mode set to 100644
File size: 3.0 KB
Line 
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 <stdarg.h>
14#include <stdio.h>
15#include <stdlib.h>
16#include <strings.h>
17
18#ifdef HAVE_CONFIG_H
19#include "libpolysconfig.h"
20#endif /* HAVE_CONFIG_H */
21
22static inline void malloc_free( void * ptr )
23{
24  free(ptr);
25}
26
27#ifdef HAVE_EXECINFO_H
28#include <execinfo.h>
29#endif
30
31#ifdef HAVE_UNISTD_H
32#include <unistd.h>
33#endif
34
35#ifdef HAVE_GCC_ABI_DEMANGLE
36#include <cxxabi.h>
37#endif
38
39
40#include <reporter/reporter.h>
41
42#ifdef HAVE_CONFIG_H
43#include <omalloc/omalloc.h>
44#endif
45
46
47extern "C" 
48{
49
50int dReportError(const char* fmt, ...)
51{
52#ifdef HAVE_EXECINFO_H
53#define SIZE 50
54  void *buffer[SIZE+1]; int ret; 
55#endif
56
57  va_list ap;
58  va_start(ap, fmt);
59#ifndef MAKE_DISTRIBUTION
60  fprintf(stderr, "\n// ***dError: ");
61  vfprintf(stderr, fmt, ap);
62#if 0
63    if !defined(OM_NDEBUG) && defined(HAVE_CONFIG_H)
64#endif
65#if  defined(HAVE_CONFIG_H)
66  fprintf(stderr, " occured at: \n");
67  omPrintCurrentBackTraceMax(stderr, 8);
68#endif
69
70#if 0
71#ifdef HAVE_EXECINFO_H
72  ret = backtrace( buffer, SIZE ); // execinfo.h
73  fprintf(stderr, "\nExecinfo backtrace (with %zd stack frames): \n", ret);
74 
75#ifndef HAVE_GCC_ABI_DEMANGLE
76  backtrace_symbols_fd(buffer, ret, STDERR_FILENO); // execinfo.h
77#else
78  char **ptr = backtrace_symbols( buffer, ret ); // execinfo.h
79
80  int status;
81  char *demangledName;
82  char *s;
83  char *ss;
84  for (int i = 0; i < ret; i++)
85  {
86    status = -1;
87
88    s = ptr[i];
89//    fprintf (stderr, " #%02d: %s\n", i, s);
90   
91    ss = index(s, '(');
92    ss[0] = 0;
93    fprintf (stderr, " #%02d: '%s': ", i, s);
94    ss[0] = '('; s = ss + 1;
95
96    ss = index(s, '+');
97   
98    if ( ss != NULL )
99    {
100      ss[0] = 0;
101      demangledName = abi::__cxa_demangle( s, NULL, NULL, &status ); // cxxabi.h!
102      if( status == 0 && demangledName != NULL )
103        fprintf (stderr, " '%s'", (demangledName[0] != 0)? demangledName: s);
104      else
105        fprintf (stderr, " '%s'", s);
106       
107      malloc_free( demangledName );
108      ss[0] = '+';
109      s = ss + 1;
110    }
111   
112    ss = index(s, ')');
113    if( s != ss)
114    {
115      ss[0] = 0;
116      fprintf (stderr, " + %s", s);
117      ss[0] = ')';
118    }
119
120    fprintf (stderr, " %s\n", ss + 2);
121  }
122  malloc_free (ptr);
123#endif
124#endif
125
126#undef SIZE
127#endif
128 
129  dErrorBreak();
130#else
131  fprintf(stderr, "\n// !!! YOU HAVE FOUND A BUG IN SINGULAR::Spielwiese.");
132  fprintf(stderr, "// !!! Please, email the input\n// and the following error message to singular@mathematik.uni-kl.de")
133  vfprintf(stderr, fmt, ap);
134#endif
135  return 0;
136}
137
138}
139
140#endif
141 
142#ifndef MAKE_DISTRIBUTION
143// dummy procedure for setting a breakpoint
144// within the debugger
145void dErrorBreak()
146{}
147#endif
Note: See TracBrowser for help on using the repository browser.