Master the fundamental concepts of debugging mastery through this focused micro-challenge.
LD_PRELOAD is a Linux mechanism that loads a specified shared library before all others, allowing you to intercept and wrap dynamic library functions without modifying the original program.
Set the environment variable before running a program:
cLoading…
Your interceptor defines a function with the same signature as the target (for example malloc), calls the real version via dlsym(RTLD_NEXT, "malloc"), and adds custom logging or counting.
Common use cases:
malloc/free to detect leaksopen/read/writeYou will document how LD_PRELOAD can intercept malloc and free calls to add logging. This technique is widely used in debugging, testing, and security research to observe program behavior without source code access.
Compile your interceptor as a shared library with -shared -fPIC and link -ldl. Export a malloc wrapper that logs the size and caller address, then forwards to the real malloc via dlsym. This pattern appears in debugging tools like Valgrind's interceptors and in security research to monitor API usage without recompiling the target. The interceptor must be thread-safe if the target uses pthreads.
Write a C program that documents and demonstrates how LD_PRELOAD can intercept malloc and free calls to add logging.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github