I have to get the backtrace in c++ function and store it into a string as follows:
string myFunction()
{
void *array[5002];
// get void*'s for all entries on the stack
size_t size = backtrace(array, 5000);
char** trace = backtrace_symbols(array, size);
string stackTrace;
for(size_t index=0; index<size; ++index)
{
stackTrace += trace[index];
}
return stackTrace;
}
with above use of code i am getting memory fault.
backtrace with gdb of above error is follows
?? () from /lib64/libgcc_s.so.1
0x000000359be08934 in _Unwind_Backtrace () from /lib64/libgcc_s.so.1
0x00000035976e6358 in backtrace () from /lib64/libc.so.6
0x00002aaaab7afaec in (anonymous namespace)::myFunction() at fileName.cpp
Any sugestion to resolve this?
Thanks in Advace.
You need to add the
-rdynamiccompiler flag to gcc/g++: