source: git/libpolys/reporter/dError.cc @ 80f8f6c

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