source: git/libpolys/reporter/dError.cc @ ba5e9e

spielwiese
Last change on this file since ba5e9e was ba5e9e, checked in by Oleksandr Motsak <motsak@…>, 11 years ago
Changed configure-scripts to generate individual public config files for each package: resources, libpolys, singular (main) fix: sources should include correct corresponding config headers.
  • Property mode set to 100644
File size: 2.9 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#ifdef HAVE_EXECINFO_H
71  ret = backtrace( buffer, SIZE ); // execinfo.h
72  fprintf(stderr, "\nExecinfo backtrace (with %zd stack frames): \n", ret);
73 
74#ifndef HAVE_GCC_ABI_DEMANGLE
75  backtrace_symbols_fd(buffer, ret, STDERR_FILENO); // execinfo.h
76#else
77  char **ptr = backtrace_symbols( buffer, ret ); // execinfo.h
78
79  int status;
80  char *demangledName;
81  char *s; 
82  char *ss;
83  for (int i = 0; i < ret; i++)
84  {
85    status = -1;
86
87    s = ptr[i];
88//    fprintf (stderr, " #%02d: %s\n", i, s);
89   
90    ss = index(s, '(');
91    ss[0] = 0;
92    fprintf (stderr, " #%02d: '%s': ", i, s);
93    ss[0] = '('; s = ss + 1;
94
95    ss = index(s, '+');
96   
97    if ( ss != NULL )
98    {
99      ss[0] = 0;
100      demangledName = abi::__cxa_demangle( s, NULL, NULL, &status ); // cxxabi.h!
101      if( status == 0 && demangledName != NULL )
102        fprintf (stderr, " '%s'", (demangledName[0] != 0)? demangledName: s);
103      else
104        fprintf (stderr, " '%s'", s);
105       
106      malloc_free( demangledName );
107      ss[0] = '+';
108      s = ss + 1;
109    }
110   
111    ss = index(s, ')');
112    if( s != ss)
113    {
114      ss[0] = 0;
115      fprintf (stderr, " + %s", s);
116      ss[0] = ')';
117    }
118
119    fprintf (stderr, " %s\n", ss + 2);
120  }
121  malloc_free (ptr);
122#endif
123
124#undef SIZE
125#endif
126 
127  dErrorBreak();
128#else
129  fprintf(stderr, "\n// !!! YOU HAVE FOUND A BUG IN SINGULAR::Spielwiese.");
130  fprintf(stderr, "// !!! Please, email the input\n// and the following error message to singular@mathematik.uni-kl.de")
131  vfprintf(stderr, fmt, ap);
132#endif
133  return 0;
134}
135
136}
137
138#endif
139 
140#ifndef MAKE_DISTRIBUTION
141// dummy procedure for setting a breakpoint
142// within the debugger
143void dErrorBreak()
144{}
145#endif
Note: See TracBrowser for help on using the repository browser.