I’m running a program that uses LD PRELOAD to load a certain library. This is something I like.
How can I use gdb to run this program?
Asked by MetallicPriest
Do the following.
gdb your_program (gdb) set environment LD_PRELOAD ./yourso.so (gdb) start
Answered by MetallicPriest
Posting because we ran into a case where set environment didn’t work:
From GDB documentation:
Answered by Alexey Romanov
Here’s how to run everything in one command (with parameters and environment):
gdb --args env LD_PRELOAD=/usr/local/lib/libstderred.so ls -l
The astute observer will see that, like Alexey Romanov’s answer, env is used as an exec wrapper here.
Answered by user2394284
Using the -iex switch, you can pass env as an exec-wrapper on the command line:
gdb -iex "set exec-wrapper env LD_PRELOAD=./my.so" ./my_program
Answered by ecatmur
I’m using gdbserver with VS Code, and the simplest way to get started is to wrap your program in a shell:
gdbserver :8888 sh -c 'LD_PRELOAD=/libtest.so your_prog'
Answered by BubbleQuote
Post is based on https://stackoverflow.com/questions/10448254/how-to-use-gdb-with-ld-preload