简体   繁体   中英

GDB Loading the incorrect library

I have two different version of a library let's say libxyz.so

at two different location

1) /home/maverick/dev/libxyz.so ( development Version)
2) /home/maverick/prod/libxyz.so ( Production Version )

I have a setup that compile my program and link with appropriate version of the library depending on LD_LIBRARY_PATH. for example If I want to link my program with dev version of libxyz.so i change my LD_LIBRARY_PATH to add /home/maverick/dev and if I want to link with prod version I change LD_LIBRARY_PATH to add /home/maverick/prod instead.

I compiled my program by linking with dev version and the output of

ldd MyProg

is

libxyz.so => /home/maverick/dev/libxyz.so

If i run the program it loads the libxyz.so from

/home/maverick/dev/libxyz.so

and runs fine. it this point my LD_LIBRARY_PATH includes /home/maverick/dev not /home/maverick/prod

but when I try to debug this program through GDB

gdb MyProg

it loads the libxyz.so from location

/home/maverick/prod/libxyz.so

I have trouble making GDB load the correct version of the library during debug. So till now what I am doing is first launch the program (that load the dev version) and attach gdb to that PID this way its works fine. but if it run like

gdb MyProg 

it dosen't

I tried every thing to fix this like setting up sysroot, solib-search-path in GDB but nothing is working. if fact when I set up sysroot to point to the debug version of the library gdb gave some message like

.dynamic section for XXX is not at the expected address

any suggestion would be appreciated.

I have trouble making GDB load the correct version of the library during debug.

Let me guess: you are using tcsh , right?

The problem most likely comes from yoour ~/.cshrc resetting LD_LIBRARY_PATH to /home/maverick/prod .

When you run the program in GDB, it executes $SHELL -c your-program [args...] (so as to allow you to use I/O redirection).

Solution: don't touch environment in your .cshrc for non-interactive shell, eg start it with:

if ($?prompt  ==  0) exit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM