aboutsummaryrefslogtreecommitdiff
path: root/src/exceptionbase.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2008-03-24 21:17:48 +0000
committerMike Buland <eichlan@xagasoft.com>2008-03-24 21:17:48 +0000
commit37f43e6004b979a48aa99609264d12511023a956 (patch)
tree21adf6f645bfb2e3cf23e778635a54ba013aa6b2 /src/exceptionbase.cpp
parent68f4dfa0e2996211a9439809df07e36614618a63 (diff)
downloadlibbu++-37f43e6004b979a48aa99609264d12511023a956.tar.gz
libbu++-37f43e6004b979a48aa99609264d12511023a956.tar.bz2
libbu++-37f43e6004b979a48aa99609264d12511023a956.tar.xz
libbu++-37f43e6004b979a48aa99609264d12511023a956.zip
Removed the backtrace stuff, it had some bugs, and shouldn't be here all the
time anyway. Recompile everything.
Diffstat (limited to 'src/exceptionbase.cpp')
-rw-r--r--src/exceptionbase.cpp68
1 files changed, 0 insertions, 68 deletions
diff --git a/src/exceptionbase.cpp b/src/exceptionbase.cpp
index 6e5ae10..6d019af 100644
--- a/src/exceptionbase.cpp
+++ b/src/exceptionbase.cpp
@@ -11,70 +11,42 @@
11Bu::ExceptionBase::ExceptionBase( const char *lpFormat, ... ) throw() : 11Bu::ExceptionBase::ExceptionBase( const char *lpFormat, ... ) throw() :
12 nErrorCode( 0 ), 12 nErrorCode( 0 ),
13 sWhat( NULL ) 13 sWhat( NULL )
14#ifdef LIBBU_EXCEPTION_BACKTRACE
15 , sBT( NULL )
16#endif
17{ 14{
18 va_list ap; 15 va_list ap;
19 16
20 va_start(ap, lpFormat); 17 va_start(ap, lpFormat);
21 setWhat( lpFormat, ap ); 18 setWhat( lpFormat, ap );
22 va_end(ap); 19 va_end(ap);
23#ifdef LIBBU_EXCEPTION_BACKTRACE
24 createBacktrace();
25#endif
26} 20}
27 21
28Bu::ExceptionBase::ExceptionBase( int nCode, const char *lpFormat, ... ) throw() : 22Bu::ExceptionBase::ExceptionBase( int nCode, const char *lpFormat, ... ) throw() :
29 nErrorCode( nCode ), 23 nErrorCode( nCode ),
30 sWhat( NULL ) 24 sWhat( NULL )
31#ifdef LIBBU_EXCEPTION_BACKTRACE
32 , sBT( NULL )
33#endif
34{ 25{
35 va_list ap; 26 va_list ap;
36 27
37 va_start(ap, lpFormat); 28 va_start(ap, lpFormat);
38 setWhat( lpFormat, ap ); 29 setWhat( lpFormat, ap );
39 va_end(ap); 30 va_end(ap);
40#ifdef LIBBU_EXCEPTION_BACKTRACE
41 createBacktrace();
42#endif
43} 31}
44 32
45Bu::ExceptionBase::ExceptionBase( int nCode ) throw() : 33Bu::ExceptionBase::ExceptionBase( int nCode ) throw() :
46 nErrorCode( nCode ), 34 nErrorCode( nCode ),
47 sWhat( NULL ) 35 sWhat( NULL )
48#ifdef LIBBU_EXCEPTION_BACKTRACE
49 , sBT( NULL )
50#endif
51{ 36{
52#ifdef LIBBU_EXCEPTION_BACKTRACE
53 createBacktrace();
54#endif
55} 37}
56 38
57Bu::ExceptionBase::ExceptionBase( const ExceptionBase &e ) throw () : 39Bu::ExceptionBase::ExceptionBase( const ExceptionBase &e ) throw () :
58 nErrorCode( e.nErrorCode ), 40 nErrorCode( e.nErrorCode ),
59 sWhat( NULL ) 41 sWhat( NULL )
60#ifdef LIBBU_EXCEPTION_BACKTRACE
61 , sBT( NULL )
62#endif
63{ 42{
64 setWhat( e.sWhat ); 43 setWhat( e.sWhat );
65#ifdef LIBBU_EXCEPTION_BACKTRACE
66 createBacktrace();
67#endif
68} 44}
69 45
70Bu::ExceptionBase::~ExceptionBase() throw() 46Bu::ExceptionBase::~ExceptionBase() throw()
71{ 47{
72 delete[] sWhat; 48 delete[] sWhat;
73 sWhat = NULL; 49 sWhat = NULL;
74#ifdef LIBBU_EXCEPTION_BACKTRACE
75 delete[] sBT;
76 sBT = NULL;
77#endif
78} 50}
79 51
80void Bu::ExceptionBase::setWhat( const char *lpFormat, va_list &vargs ) 52void Bu::ExceptionBase::setWhat( const char *lpFormat, va_list &vargs )
@@ -107,43 +79,3 @@ int Bu::ExceptionBase::getErrorCode()
107 return nErrorCode; 79 return nErrorCode;
108} 80}
109 81
110#ifdef LIBBU_EXCEPTION_BACKTRACE
111const char *Bu::ExceptionBase::getBacktrace() const throw()
112{
113 return sBT;
114}
115
116#include "bu/fstring.h"
117#include <execinfo.h>
118
119void Bu::ExceptionBase::createBacktrace()
120{
121 void *array[1000];
122 size_t size;
123 char **strings;
124 size_t i;
125
126 size = backtrace (array, 1000);
127 strings = backtrace_symbols (array, size);
128
129 Bu::FString s;
130 s.format("Obtained %zd stack frames.\n", size );
131
132 for (i = 0; i < size; i++)
133 {
134 s += strings[i];
135 s += "\n";
136 }
137
138 free (strings);
139
140 sBT = new char[s.getSize()+1];
141 strcpy( sBT, s.getStr() );
142}
143
144#else
145const char *Bu::ExceptionBase::getBacktrace() const throw()
146{
147 return "Backtrace support is not compiled in.\n";
148}
149#endif