我在我的函数中使用了backtrace()函数,如下所示:
string newFunction()
{
void *array[5002];
// get void*'s for all entries on the stack
size_t size
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;
}
在调试构建案例中使用上述函数我遇到内存故障。 valgrind报告显示以下日志:
==31045== Invalid read of size 8
==31045== at 0x358D208806: ??? (in /lib64/libgcc_s-4.1.2-20080825.so.1)
==31045== by 0x358D208933: _Unwind_Backtrace (in /lib64/libgcc_s-4.1.2-20080825.so.1)
==31045== by 0x3588AE6357: backtrace (in /lib64/libc-2.5.so)
==31045== by 0xF2A1F99: (anonymous namespace)::newFunction() (myFIle.cpp:63)
所以任何解决上述内存故障的建议。提前谢谢。