source: git/libpolys/reporter/dError.cc @ 56bce6

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