aengelke / instrew

A high performance LLVM-based dynamic binary instrumentation framework
GNU Lesser General Public License v2.1
239 stars 38 forks source link

Instrew can't be debugged by GDB #5

Closed younghojan closed 9 months ago

younghojan commented 1 year ago

Hi there!

I'm currently debugging Instrew using GDB, trying to figure out how Instrew actually works and get more details when client and server are running.

But once GDB goes to fexecve(memfd, const_cast<char* const*>(&exec_args[0]), environ);(server/connection.cc: 165), GDB just collapses and doesn't know where to continue.

After I retrieved and read a lot, I realized maybe int memfd = memfd_create("instrew_stub", MFD_CLOEXEC);(server/connection.cc: 142) should be to blame. I guess it is the anonymous file(instrew-client in a byte stream form) created by memfd_create() made GDB lost, for GDB can't find it on hard drive. If I change fexecve(memfd, const_cast<char* const*>(&exec_args[0]), environ);(server/connection.cc: 165) to

int client_fd = open("./build/client/instrew-client", O_RDONLY);
fexecve(client_fd, const_cast<char *const *>(&exec_args[0]), environ);

or

execve("./build/client/instrew-client", const_cast<char *const *>(&exec_args[0]), environ);

then GDB is OK to continue to debug the client process.

Is my guess correct? Hopes if dear developer or someone could give some insights.