使gdb从特定路径加载共享库 [英] make gdb load a shared library from a specific path
问题描述
在执行应用程序时我得到了一个核心,我保存了应用程序在 / tmp
中使用的可执行文件,核心文件和共享库,以便稍后检查它们。然后我修改了库,重新构建了它并再次启动了可执行文件。
现在,当我尝试调试内核时,gdb从其原始路径加载共享库,而不是从保存原始库的目录 / tmp
中加载。
例如,原始路径是 /opt/mydir/lib/libmylib.so.0
。
gdb正在加载这个共享库,而我希望它加载 /tmp/libmylib.so.0
。
应用程序还使用一些标准库,它们位于 / usr / lib
和 / lib
目录中,所以我不希望这些路径被改变。只需要更改 / opt / mydir / lib /
- > / tmp
。我该怎么做?
最简单的解决方案是临时恢复 /opt/mydir/lib/libmylib.so.0
添加到在崩溃时使用的副本(即现在位于 / tmp
),分析核心,然后恢复新版本。
如果你不想这样做, set solib-search-path
和 set sysroot
是你的朋友。
请注意,您必须在加载核心
之前设置。这个序列应该可以工作:
(gdb)set sysroot / no / such / file
(gdb)set solib- search-path / tmp:/ usr / lib:/ lib
(gdb)core / tmp / core
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.
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?
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.
If you don't want to do that, set solib-search-path
and set sysroot
are your friends.
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屋!