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

spielwiese
Last change on this file since a44bcf was 6909cfb, checked in by Yue Ren <ren@…>, 11 years ago
fix: -Wunused-variable warnings
  • 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#include "config.h"
19
20static inline void malloc_free( void * ptr )
21{
22  free(ptr);
23}
24
25#ifdef HAVE_EXECINFO_H
26#include <execinfo.h>
27#endif
28
29#ifdef HAVE_UNISTD_H
30#include <unistd.h>
31#endif
32
33#ifdef HAVE_GCC_ABI_DEMANGLE
34#include <cxxabi.h>
35#endif
36
37
38#include <reporter/reporter.h>
39
40#ifdef HAVE_CONFIG_H
41#include <omalloc/omalloc.h>
42#endif
43
44
45extern "C" 
46{
47
48int dReportError(const char* fmt, ...)
49{
50#ifdef HAVE_EXECINFO_H
51#define SIZE 50
52  void *buffer[SIZE+1]; int ret; 
53#endif
54
55  va_list ap;
56  va_start(ap, fmt);
57#ifndef MAKE_DISTRIBUTION
58  fprintf(stderr, "\n// ***dError: ");
59  vfprintf(stderr, fmt, ap);
60#if 0
61    if !defined(OM_NDEBUG) && defined(HAVE_CONFIG_H)
62#endif
63#if  defined(HAVE_CONFIG_H)
64  fprintf(stderr, " occured at: \n");
65  omPrintCurrentBackTraceMax(stderr, 8);
66#endif
67
68#ifdef HAVE_EXECINFO_H
69  ret = backtrace( buffer, SIZE ); // execinfo.h
70  fprintf(stderr, "\nExecinfo backtrace (with %zd stack frames): \n", ret);
71 
72#ifndef HAVE_GCC_ABI_DEMANGLE
73  backtrace_symbols_fd(buffer, ret, STDERR_FILENO); // execinfo.h
74#else
75  char **ptr = backtrace_symbols( buffer, ret ); // execinfo.h
76
77  int status;
78  char *demangledName;
79  char *s; 
80  char *ss;
81  for (int i = 0; i < ret; i++)
82  {
83    status = -1;
84
85    s = ptr[i];
86//    fprintf (stderr, " #%02d: %s\n", i, s);
87   
88    ss = index(s, '(');
89    ss[0] = 0;
90    fprintf (stderr, " #%02d: '%s': ", i, s);
91    ss[0] = '('; s = ss + 1;
92
93    ss = index(s, '+');
94   
95    if ( ss != NULL )
96    {
97      ss[0] = 0;
98      demangledName = abi::__cxa_demangle( s, NULL, NULL, &status ); // cxxabi.h!
99      if( status == 0 && demangledName != NULL )
100        fprintf (stderr, " '%s'", (demangledName[0] != 0)? demangledName: s);
101      else
102        fprintf (stderr, " '%s'", s);
103       
104      malloc_free( demangledName );
105      ss[0] = '+';
106      s = ss + 1;
107    }
108   
109    ss = index(s, ')');
110    if( s != ss)
111    {
112      ss[0] = 0;
113      fprintf (stderr, " + %s", s);
114      ss[0] = ')';
115    }
116
117    fprintf (stderr, " %s\n", ss + 2);
118  }
119  malloc_free (ptr);
120#endif
121
122#undef SIZE
123#endif
124 
125  dErrorBreak();
126#else
127  fprintf(stderr, "\n// !!! YOU HAVE FOUND A BUG IN SINGULAR::Spielwiese.");
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
141void dErrorBreak()
142{}
143#endif
Note: See TracBrowser for help on using the repository browser.