In GDB you can set the environmental variables for a process using set exec-wrapper env 'MYENVVAR=...'
. This works great, but I'm not sure how to set multiple ones - is there some sort of delimiter you have to use? I'd like to set both LD_PRELOAD
and LD_LIBRARY_PATH
for a process. How would I do this?
Asked
Active
Viewed 1,664 times
2

false_azure
- 1,333
- 4
- 25
- 46
1 Answers
6
You can use
set exec-wrapper env VAR1=val1 VAR2=val2
to set multiple environment variables. The values should be appropriately quoted for your shell, so putting single quotes around them would be a good idea.
In slightly more detail:
The set exec-wrapper
command sets a string variable to contain the rest of the command line.
When it comes time to run your executable, gdb
does something like the following pseudo-code:
shell_cmd = "exec ";
if (exec_wrapper)
shell_cmd += exec_wrapper + " ";
shell_cmd += quote_shell_metacharacters(exec_file);
execl(getenv("SHELL"), "sh", "-c", shell_cmd, (char *)0);
So, exec-wrapper
can be any command line that makes sense when preceded by "exec "
in your shell.

Mark Plotnick
- 9,598
- 1
- 24
- 40
-
Thanks, very thorough answer! – false_azure Dec 16 '14 at 19:33