Inferno
0.2
|
00001 #include "standard.hpp" 00002 #include "trace.hpp" 00003 #include <stdarg.h> 00004 #include <cxxabi.h> 00005 00006 string SSPrintf(const char *fmt, ...) 00007 { 00008 char cs[256]; 00009 00010 va_list vl; 00011 va_start( vl, fmt ); 00012 vsnprintf( cs, sizeof(cs), fmt, vl ); 00013 va_end( vl ); 00014 00015 return string(cs); 00016 } 00017 00018 void CommonTest() 00019 { 00020 // Test the FOREACH macro in case it's our dodgy home made one 00021 deque<int> d; 00022 deque<int> *pd = &d; 00023 d.push_back(100); 00024 d.push_back(101); 00025 d.push_back(102); 00026 d.push_back(103); 00027 deque<int> r; 00028 FOREACH( int i, *pd ) 00029 r.push_back(i); 00030 ASSERT( r.size() == 4 ); 00031 ASSERT( r[0] == 100 ); 00032 ASSERT( r[1] == 101 ); 00033 ASSERT( r[2] == 102 ); 00034 ASSERT( r[3] == 103 ); 00035 } 00036 00037 string Traceable::GetName() const 00038 { 00039 return CPPFilt( typeid( *this ).name() ); 00040 } 00041 00042 string Traceable::GetAddr() const 00043 { 00044 return SSPrintf("@%p", this); 00045 } 00046 00047 Traceable::operator string() const 00048 { 00049 return GetName() + GetAddr(); // name plus pointer 00050 } 00051 00052 string Traceable::CPPFilt( string s ) 00053 { 00054 int status; 00055 char *ps; 00056 // Use GCC extension to demangle based on the present ABI 00057 ps = abi::__cxa_demangle(s.c_str(), 0, 0, &status); 00058 s = ps; 00059 free(ps); // as ordained 00060 return s; 00061 } 00062