source: git/libpolys/reporter/dError.cc

spielwiese
Last change on this file was b270e37, checked in by Hans Schoenemann <hannes@…>, 22 months ago
moved distrib.h to libpolys/misc for dError.cc
  • Property mode set to 100644
File size: 2.8 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 "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
23static 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
41extern "C"
42{
43
44int 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
140void dErrorBreak()
141{}
142#endif
Note: See TracBrowser for help on using the repository browser.