source: git/libpolys/reporter/dError.cc @ 6ac003

spielwiese
Last change on this file since 6ac003 was e0c0a7, checked in by Hans Schoenemann <hannes@…>, 11 years ago
fix: debug stuff (do not inline dErrorBreak)
  • 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 i, j, k, ret, status; char **ptr; char *demangledName; char *s; char *ss;
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  ptr = backtrace_symbols( buffer, ret ); // execinfo.h
76
77  for (i = 0; i < ret; i++)
78  {
79    status = -1;
80
81    s = ptr[i];
82//    fprintf (stderr, " #%02d: %s\n", i, s);
83   
84    ss = index(s, '(');
85    ss[0] = 0;
86    fprintf (stderr, " #%02d: '%s': ", i, s);
87    ss[0] = '('; s = ss + 1;
88
89    ss = index(s, '+');
90   
91    if ( ss != NULL )
92    {
93      ss[0] = 0;
94      demangledName = abi::__cxa_demangle( s, NULL, NULL, &status ); // cxxabi.h!
95      if( status == 0 && demangledName != NULL )
96        fprintf (stderr, " '%s'", (demangledName[0] != 0)? demangledName: s);
97      else
98        fprintf (stderr, " '%s'", s);
99       
100      malloc_free( demangledName );
101      ss[0] = '+';
102      s = ss + 1;
103    }
104   
105    ss = index(s, ')');
106    if( s != ss)
107    {
108      ss[0] = 0;
109      fprintf (stderr, " + %s", s);
110      ss[0] = ')';
111    }
112
113    fprintf (stderr, " %s\n", ss + 2);
114  }
115  malloc_free (ptr);
116#endif
117
118#undef SIZE
119#endif
120 
121  dErrorBreak();
122#else
123  fprintf(stderr, "\n// !!! YOU HAVE FOUND A BUG IN SINGULAR::Spielwiese.");
124  fprintf(stderr, "// !!! Please, email the input\n// and the following error message to singular@mathematik.uni-kl.de")
125  vfprintf(stderr, fmt, ap);
126#endif
127  return 0;
128}
129
130}
131
132#endif
133 
134#ifndef MAKE_DISTRIBUTION
135// dummy procedure for setting a breakpoint
136// within the debugger
137void dErrorBreak()
138{}
139#endif
Note: See TracBrowser for help on using the repository browser.