使 gdb 从特定路径加载共享库 [英] make gdb load a shared library from a specific path
问题描述
我在执行应用程序时获得了一个核心,我保存了可执行文件、核心文件和应用程序在 /tmp
中使用的共享库,以便以后检查它们.然后我修改了库,重建它并再次启动可执行文件.现在,当我尝试调试核心时,gdb 正在从其原始路径加载共享库,而不是从我保存原始库的目录 /tmp
加载.
I got a core while executing an application and I saved the executable, the corefile and a shared library which the application use in /tmp
to check them later. I then modified the library, rebuilt it and started the executable again.
Now when I am trying to debug the core, gdb is loading the shared library from its original path and not from the directory /tmp
where I saved the original library.
例如,原始路径是 /opt/mydir/lib/libmylib.so.0
.gdb 正在加载这个共享库,而我希望它加载 /tmp/libmylib.so.0
.该应用程序还使用 /usr/lib
和 /lib
目录中的一些标准库,因此我不希望更改这些路径.只想更改/opt/mydir/lib/
-> /tmp
.我该怎么做?
For example, the original path was /opt/mydir/lib/libmylib.so.0
.
gdb is loading this shared library, while I want it to load /tmp/libmylib.so.0
.
The application also uses some standard libraries which are in /usr/lib
and /lib
directories so I don't want these paths to get changed. Just want to change /opt/mydir/lib/
-> /tmp
. How can I do that?
推荐答案
最简单的解决方案是暂时恢复/opt/mydir/lib/libmylib.so.0
到崩溃时使用的副本(即现在在 /tmp
中的副本),分析核心,然后恢复新版本.
The simplest solution is to temporarily restore /opt/mydir/lib/libmylib.so.0
to the copy that was used at crash time (i.e. the one now in /tmp
), analyse the core, then restore back the new version.
如果您不想这样做,set solib-search-path
和 set sysroot
是 你的朋友.
If you don't want to do that, set solib-search-path
and set sysroot
are your friends.
请注意,您必须在加载 core
之前设置两者.这个序列应该有效:
Note that you must set both before loading the core
. This sequence should work:
(gdb) set sysroot /no/such/file
(gdb) set solib-search-path /tmp:/usr/lib:/lib
(gdb) core /tmp/core
这篇关于使 gdb 从特定路径加载共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!