user2601195
user2601195

Reputation: 171

GDB resetting LD_LIBRARY_PATH

Running GDB 7.4-2012.02 on Ubuntu and am experiencing weird behavior that I can't duplicate on other platforms.

bash$ export LD_LIBRARY_PATH=my_path
bash$ export LD_LIBRARY_PATH2=my_path2
bash$ gdb
GNU gdb (Ubuntu/Linaro 7.4-2012.02-0ubuntu2) 7.4-2012.02
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>.
(gdb) shell echo $LD_LIBRARY_PATH

(gdb) shell echo $LD_LIBRARY_PATH2
my_path2

As can be seen, GDB is resetting LD_LIBRARY_PATH but none of the other exported variables. Why is it doing this? Is there some setting I don't know about which causes this? My ~/.gdbinit is empty and the behavior persists even when using gdb -n.

Additionally, after exiting back to the login shell:

bash$ echo $LD_LIBRARY_PATH
my_path
bash$ $SHELL -c 'echo $LD_LIBRARY_PATH'
my_path
bash$ $SHELL
hi from .bashrc
bash$ echo $LD_LIBRARY_PATH
my_path

So I don't think my startup scripts are the issue.

Upvotes: 4

Views: 5387

Answers (1)

Employed Russian
Employed Russian

Reputation: 213859

So I don't think my startup scripts are the issue.

Yes, they are the issue (I know for a fact that GDB does not mess with your LD_LIBRARY_PATH environment).

Update:

Startup scripts were not the issue after all.

After some debugging, user2601195 discovered that the following variables were all getting unset: GCONV_PATH, GETCONF_DIR, HOSTALIASES, LD_AUDIT, LD_DEBUG, LD_DEBUG_OUTPUT, LD_DYNAMIC_WEAK, LD_LIBRARY_PATH, LD_ORIGIN_PATH, LD_PRELOAD

These are environment variables that glibc considers insecure, and unsets for setuid binaries. It turned out that in fact the gdb being invoked was suid-root:

-rwsr-sr-x 1 root root 5975928 Mar 15 2012 /usr/bin/gdb

which explains the problem.

Upvotes: 6

Related Questions