source: git/libpolys/reporter/dError.cc @ 98223c

jengelh-datetimespielwiese
Last change on this file since 98223c was 98223c, checked in by Oleksandr Motsak <motsak@…>, 11 years ago
added C++ demangling and more debug output
  • 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 *  Version: $Id$
10 *******************************************************************/
11#ifndef DERROR_C
12#define DERROR_C
13
14#include <stdarg.h>
15#include <stdio.h>
16#include <stdlib.h>
17#include <strings.h>
18
19#include "config.h"
20
21static inline void malloc_free( void * ptr )
22{
23  free(ptr);
24}
25
26#define HAVE_EXECINFO
27#define HAVE_CXXABI
28
29#ifdef HAVE_EXECINFO
30#include <execinfo.h>
31#include <unistd.h>
32#endif
33
34#ifdef HAVE_CXXABI
35#include <cxxabi.h>
36#endif
37
38
39#include <reporter/reporter.h>
40#ifdef HAVE_CONFIG_H
41#include <omalloc/omalloc.h>
42#endif
43
44#ifndef MAKE_DISTRIBUTION
45// dummy procedure for setting a breakpoint
46// within the debugger
47void dErrorBreak()
48{}
49#endif
50
51#ifdef __cplusplus
52extern "C" 
53{
54#endif
55
56int dReportError(const char* fmt, ...)
57{
58#ifdef HAVE_EXECINFO
59#define SIZE 50
60  void *buffer[SIZE+1]; int i, j, k, ret, status; char **ptr; char *demangledName; char *s; char *ss;
61#endif
62
63  va_list ap;
64  va_start(ap, fmt);
65#ifndef MAKE_DISTRIBUTION
66  fprintf(stderr, "\n// ***dError: ");
67  vfprintf(stderr, fmt, ap);
68#if 0
69    if !defined(OM_NDEBUG) && defined(HAVE_CONFIG_H)
70#endif
71#if  defined(HAVE_CONFIG_H)
72  fprintf(stderr, " occured at: \n");
73  omPrintCurrentBackTraceMax(stderr, 8);
74#endif
75
76#ifdef HAVE_EXECINFO
77  ret = backtrace( buffer, SIZE );
78  fprintf(stderr, "\nExecinfo backtrace (with %zd stack frames): \n", ret);
79 
80#ifndef HAVE_CXXABI
81  backtrace_symbols_fd(buffer, ret, STDERR_FILENO);
82#else
83  ptr = backtrace_symbols( buffer, ret );
84
85  for (i = 0; i < ret; i++)
86  {
87    status = -1;
88
89    s = ptr[i];
90//    fprintf (stderr, " #%02d: %s\n", i, s);
91   
92    ss = index(s, '(');
93    ss[0] = 0;
94    fprintf (stderr, " #%02d: '%s': ", i, s);
95    ss[0] = '('; s = ss + 1;
96
97    ss = index(s, '+');
98   
99    if ( ss != NULL )
100    {
101      ss[0] = 0;
102      demangledName = abi::__cxa_demangle( s, NULL, NULL, &status );
103      if( status == 0 && demangledName != NULL )
104        fprintf (stderr, " '%s'", (demangledName[0] != 0)? demangledName: s);
105      else
106        fprintf (stderr, " '%s'", s);
107       
108      malloc_free( demangledName );
109      ss[0] = '+';
110      s = ss + 1;
111    }
112   
113    ss = index(s, ')');
114    if( s != ss)
115    {
116      ss[0] = 0;
117      fprintf (stderr, " + %s", s);
118      ss[0] = ')';
119    }
120
121    fprintf (stderr, " %s\n", ss + 2);
122  }
123  malloc_free (ptr);
124#endif
125
126#undef SIZE
127#endif
128 
129  dErrorBreak();
130#else
131  fprintf(stderr, "\n// !!! YOU HAVE FOUND A BUG IN SINGULAR.");
132  fprintf(stderr, "// !!! Please, email the input\n// and the following error message to singular@mathematik.uni-kl.de")
133  vfprintf(stderr, fmt, ap);
134#endif
135  return 0;
136}
137
138
139
140#ifdef __cplusplus
141}
142#endif
143
144#endif
145 
146
147
148 
149 
150 
Note: See TracBrowser for help on using the repository browser.