12 #if defined(__linux) || defined(__APPLE__) || defined(__sun) 13 #define BOOST_HAVE_EXECINFO 14 #define BOOST_HAVE_DLADDR 18 #define BOOST_HAVE_ABI_CXA_DEMANGLE 21 #ifdef BOOST_HAVE_EXECINFO 25 #ifdef BOOST_HAVE_ABI_CXA_DEMANGLE 29 #ifdef BOOST_HAVE_DLADDR 38 #if defined(BOOST_MSVC) 47 namespace stack_trace {
48 #if defined(BOOST_HAVE_EXECINFO) 50 int trace(
void **array,
int n)
52 return :: backtrace(array,n);
55 #elif defined(BOOST_MSVC) 57 int trace(
void **array,
int n)
61 return RtlCaptureStackBackTrace(0,n,array,0);
73 #if defined(BOOST_HAVE_DLADDR) && defined(BOOST_HAVE_ABI_CXA_DEMANGLE) 79 std::ostringstream res;
80 res.imbue(std::locale::classic());
83 if(dladdr(ptr,&info) == 0) {
89 char *demangled = abi::__cxa_demangle(info.dli_sname,0,0,&status);
95 res << info.dli_sname;
102 unsigned offset = (
char *)ptr - (
char *)info.dli_saddr;
103 res << std::hex <<
" + 0x" << offset ;
106 res <<
" in " << info.dli_fname;
111 std::string
get_symbols(
void *
const *addresses,
int size)
114 for(
int i=0;i<size;i++) {
123 void write_symbols(
void *
const *addresses,
int size,std::ostream &out)
125 for(
int i=0;i<size;i++) {
134 #elif defined(BOOST_HAVE_EXECINFO) 137 char ** ptr = backtrace_symbols(&address,1);
140 return std::string();
141 std::string res = ptr[0];
152 std::string
get_symbols(
void *
const *address,
int size)
154 char ** ptr = backtrace_symbols(address,size);
157 return std::string();
159 for(
int i=0;i<size;i++) {
174 void write_symbols(
void *
const *addresses,
int size,std::ostream &out)
176 char ** ptr = backtrace_symbols(addresses,size);
180 for(
int i=0;i<size;i++)
181 out << ptr[i] <<
'\n';
192 #elif defined(BOOST_MSVC) 196 bool syms_ready =
false;
201 hProcess = GetCurrentProcess();
202 SymSetOptions(SYMOPT_DEFERRED_LOADS);
204 if (SymInitialize(hProcess, NULL, TRUE))
215 return std::string();
217 std::ostringstream ss;
220 DWORD64 dwDisplacement = 0;
221 DWORD64 dwAddress = (DWORD64)ptr;
223 std::vector<char> buffer(
sizeof(SYMBOL_INFO) + MAX_SYM_NAME);
224 PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)&buffer.front();
226 pSymbol->SizeOfStruct =
sizeof(SYMBOL_INFO);
227 pSymbol->MaxNameLen = MAX_SYM_NAME;
229 if (SymFromAddr(hProcess, dwAddress, &dwDisplacement, pSymbol))
231 ss <<
": " << pSymbol->Name << std::hex <<
" +0x" << dwDisplacement;
241 std::string
get_symbols(
void *
const *addresses,
int size)
244 for(
int i=0;i<size;i++) {
253 void write_symbols(
void *
const *addresses,
int size,std::ostream &out)
255 for(
int i=0;i<size;i++) {
269 return std::string();
270 std::ostringstream res;
271 res.imbue(std::locale::classic());
279 return std::string();
280 std::ostringstream res;
281 res.imbue(std::locale::classic());
288 for(
int i=0;i<size;i++) {
290 out << addresses[i]<<
'\n';
std::string get_symbols(void *const *ptrs, int size)
void write_symbols(void *const *addresses, int size, std::ostream &out)
std::string get_symbol(void *ptr)