You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My app can run with libmemory_profiler.so very well but it crashes when it throws an exception.
GCC : 7.4.0
Compile : g++ -Wall -Wextra -g -ggdb -O0 test.cpp -pthread
Run : sudo LD_PRELOAD=./libmemory_profiler.so ./a.out
Code : (I don't know how to make the code pretty, it looks suck.)
#include<unistd.h>
#include<stdio.h>
#include<sys/syscall.h>
#include<array>
#include<vector>
#include<thread>
#include<random>usingnamespacestd;// Init random generator
mt19937 rand_generator(chrono::high_resolution_clock::now().time_since_epoch().count());
uniform_int_distribution<int> dist(100,1000);
classA {
public:A() {
data_.push_back(0);
data_.push_back(1);
data_.push_back(2);
}
private:
vector<int> data_;
};
// Set a global value and it may alloca memory before main()
A a;
voidThreadEntry() {
while(true) {
char*p = newchar[128];
*p += 1;
try {
if(0 == dist(rand_generator) % 2) {
//throw "Throw a exception"; //crashes when it runsdelete [] p;
}
} catch (constchar* msg) {
printf("catch exception [%s]\n", msg);
}
this_thread::sleep_for(chrono::milliseconds(10));
}
}
intmain() {
array<thread, 1> thread_pool;
for(auto &th : thread_pool)
th = thread(ThreadEntry);
for(auto &th : thread_pool)
th.join();
}
Backtrace:
(gdb) bt
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1 0x00007ffff6cca801 in __GI_abort () at abort.c:79
#2 0x00007ffff753e957 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3 0x00007ffff7544ab6 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4 0x00007ffff7544af1 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5 0x00007ffff7544d24 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6 0x00005555555551c9 in ThreadEntry () at test.cpp:42
#7 0x00005555555563b3 in std::__invoke_impl<void, void (*)()> (__f=@0x55555576e098: 0x55555555514a <ThreadEntry()>) at /usr/include/c++/7/bits/invoke.h:60
#8 0x0000555555555dd1 in std::__invoke<void (*)()> (__fn=@0x55555576e098: 0x55555555514a <ThreadEntry()>) at /usr/include/c++/7/bits/invoke.h:95
#9 0x000055555555764a in std::thread::_Invoker<std::tuple<void (*)()> >::_M_invoke<0ul> (this=0x55555576e098) at /usr/include/c++/7/thread:234
#10 0x0000555555557606 in std::thread::_Invoker<std::tuple<void (*)()> >::operator() (this=0x55555576e098) at /usr/include/c++/7/thread:243
#11 0x00005555555575d6 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)()> > >::_M_run (this=0x55555576e090) at /usr/include/c++/7/thread:186
#12 0x00007ffff756f66f in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#13 0x00007ffff70826db in start_thread (arg=0x7fffeffff700) at pthread_create.c:463
#14 0x00007ffff6dab88f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
The text was updated successfully, but these errors were encountered:
Hmm... interesting. It looks like the newer versions of libstdc++ have _Unwind_RaiseException statically linked... This is problematic. I'll have to think about how to work around this.
In the meantime you can turn off the shadow stack-based unwinding by doing this:
export MEMORY_PROFILER_USE_SHADOW_STACK=0
and then run the profiler. It will be slower, but it should work until I'll fix this properly.
My app can run with libmemory_profiler.so very well but it crashes when it throws an exception.
GCC : 7.4.0
Compile : g++ -Wall -Wextra -g -ggdb -O0 test.cpp -pthread
Run : sudo LD_PRELOAD=./libmemory_profiler.so ./a.out
Code : (I don't know how to make the code pretty, it looks suck.)
Backtrace:
The text was updated successfully, but these errors were encountered: