I have the following setup that I try to debug. I could not find anything using the search, so I hope that someone here is able to guide me how I can do the following:
I have a binary that is executed (./binary) and also a local version of glibc that was manipulated on an assembly level (./libc_patched). This patched library now contains a dynamic call to an own written shared library (./shared.so).
So, what I do now is something similar to:
$ LD_LIBRARY_PATH="./path/to/libc_patched:/path/to/shared" LD_PRELOAD="/path/to/libasan.so path/to/libc_patched" ./binary
Now, my problem is that libasan throws an error that something went wrong with malloc (either a free on a not malloc()-ed address, or that the malloc-free pairs do not match.
The binaries are compiled with the flags "-g", "-fsanitize=address" and libasan is linked to the binary. My glibC version is 2.28 and I'm working on a fresh install of Debian10.
What I try to do now: I want to debug where the error occurs using gdb. But I cannot find a way to start gdb using the global libc (unpatched) but executing the "to-be-debugged binary" with the patched libc. So basically the follwing:
$ gdb "LD_LIBRARY_PATH="./path/to/libc_patched:/path/to/shared" LD_PRELOAD="/path/to/libasan.so path/to/libc_patched" ./binary"
Is something like this possible? As I have an error in my patched libc I cannot reliably start gdb with it. Thanks for any hints!