My Project
dError.cc
Go to the documentation of this file.
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 "reporter/reporter.h"
16
17#include <stdarg.h>
18#include <stdio.h>
19#include <stdlib.h>
20#include <strings.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
40extern "C"
41{
42
43int dReportError(const char* fmt, ...)
44{
45#if 0
46#ifdef HAVE_EXECINFO_H
47#define SIZE 50
48 void *buffer[SIZE+1]; int ret;
49#endif
50#endif
51
52 va_list ap;
53 va_start(ap, fmt);
54#ifndef MAKE_DISTRIBUTION
55 fprintf(stderr, "\n// ***dError: ");
56 vfprintf(stderr, fmt, ap);
57#if !defined(OM_NDEBUG)
58 #ifdef omPrintCurrentBackTraceMax
59 fprintf(stderr, " occurred at: \n");
61 #endif
62#endif
63
64#if 0
65#ifdef HAVE_EXECINFO_H
66 ret = backtrace( buffer, SIZE ); // execinfo.h
67 fprintf(stderr, "\nExecinfo backtrace (with %zd stack frames): \n", ret);
68
69#ifndef HAVE_GCC_ABI_DEMANGLE
70 backtrace_symbols_fd(buffer, ret, STDERR_FILENO); // execinfo.h
71#else
72 char **ptr = backtrace_symbols( buffer, ret ); // execinfo.h
73
74 int status;
75 char *demangledName;
76 char *s;
77 char *ss;
78 for (int i = 0; i < ret; i++)
79 {
80 status = -1;
81
82 s = ptr[i];
83// fprintf (stderr, " #%02d: %s\n", i, s);
84
85 ss = index(s, '(');
86 ss[0] = 0;
87 fprintf (stderr, " #%02d: '%s': ", i, s);
88 ss[0] = '('; s = ss + 1;
89
90 ss = index(s, '+');
91
92 if ( ss != NULL )
93 {
94 ss[0] = 0;
95 demangledName = abi::__cxa_demangle( s, NULL, NULL, &status ); // cxxabi.h!
96 if( status == 0 && demangledName != NULL )
97 fprintf (stderr, " '%s'", (demangledName[0] != 0)? demangledName: s);
98 else
99 fprintf (stderr, " '%s'", s);
100
101 malloc_free( demangledName );
102 ss[0] = '+';
103 s = ss + 1;
104 }
105
106 ss = index(s, ')');
107 if( s != ss)
108 {
109 ss[0] = 0;
110 fprintf (stderr, " + %s", s);
111 ss[0] = ')';
112 }
113
114 fprintf (stderr, " %s\n", ss + 2);
115 }
116 malloc_free (ptr);
117#endif
118#endif
119
120#undef SIZE
121#endif
122
123 dErrorBreak();
124#else
125 fprintf(stderr, "\n// !!! YOU HAVE FOUND A BUG IN SINGULAR.");
126 fprintf(stderr, "// !!! Please, email the input\n// and the following error message to singular@mathematik.uni-kl.de")
127 vfprintf(stderr, fmt, ap);
128#endif
129 return 0;
130}
131
132}
133
134#endif
135
136#ifndef MAKE_DISTRIBUTION
137// dummy procedure for setting a breakpoint
138// within the debugger
140{}
141#endif
All the auxiliary stuff.
int i
Definition: cfEzgcd.cc:132
static void malloc_free(void *ptr)
Definition: dError.cc:22
void dErrorBreak()
Definition: dError.cc:139
int dReportError(const char *fmt,...)
Definition: dError.cc:43
const CanonicalForm int s
Definition: facAbsFact.cc:51
Definition: ap.h:40
#define free
Definition: omAllocFunc.c:14
#define NULL
Definition: omList.c:12
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:592
int * status
Definition: si_signals.h:51
#define omPrintCurrentBackTraceMax(A, B)
Definition: xalloc.h:265