I run a program with LD_PRELOADing a specific library. Like this.
LD_PRELOAD=./my.so ./my_program
How do I run this program with gdb
?
I run a program with LD_PRELOADing a specific library. Like this.
LD_PRELOAD=./my.so ./my_program
How do I run this program with gdb
?
You can supply
env
as an exec-wrapper on the command line using the-iex
flag:You can basically do it the same way, just add
gdb
before the program name:You can check the environment variables using:
In the rare case you actually need to change it inside gdb, e.g. when debugging a
dlopen()
, you ca do that:Oh, wait, it doesn't work for me with gdb 7.6.2! The library doesn't get loaded, that means none of the answer here are entirely correct, at least with current tools.
Here is a way to run everything (with arguments and environment) as one command:
Example:
The keen observer will notice that
env
serves here as an exec wrapper (like Alexey Romanov's answer).Posting because we ran into a case where
set environment
didn't work:From GDB documentation:
Do the following.